Merge branch 'fix/some_issue_s31' into 'master'

fix(bt/controller): fixed several controller issues

Closes BTQABR2023-689, BTQABR2023-683, BTQABR2023-679, CBI-1964, CBI-1986, CBI-1996, CBI-2015, CBI-2019, CBI-2024, CBI-2025, CBI-2061, and BT-4370

See merge request espressif/esp-idf!48860
This commit is contained in:
Wang Meng Yang
2026-06-01 19:53:12 +08:00
8 changed files with 88 additions and 46 deletions
@@ -167,6 +167,12 @@ config BT_CTRL_BR_EDR_CPB_RX_EN
help
Enable BR/EDR Connectionless Peripheral Broadcast Receive
config BT_CTRL_BR_EDR_HOLD_EN
bool "Enable BR/EDR Hold Mode"
default n
help
Enable BR/EDR Hold Mode
config BT_CTRL_BR_EDR_LK_STORE_EN
bool "Enable BR/EDR controller link key storage"
default n
@@ -197,14 +203,14 @@ menu "TX Power Level settings"
config BT_CTRL_BR_EDR_TX_PWR_ACL_MIN
int "Default minimum TX power level for ACL"
default -13
range -15 20
range -24 12
help
Minimum BR/EDR transmission power level for ACL.
config BT_CTRL_BR_EDR_TX_PWR_ACL_MAX
int "Default maximum TX power level for ACL"
default 4
range -15 20
range -24 12
help
Maximum BR/EDR transmission power level for ACL.
@@ -212,28 +218,28 @@ menu "TX Power Level settings"
int "Default TX power level for APB"
depends on BT_CTRL_BR_EDR_APB_EN
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for APB.
config BT_CTRL_BR_EDR_TX_PWR_PAGE
int "Default TX power level for Page"
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for Page.
config BT_CTRL_BR_EDR_TX_PWR_PSCAN
int "Default TX power level for Page Scan"
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for Page Scan.
config BT_CTRL_BR_EDR_TX_PWR_ISCAN
int "Default TX power level for Inquiry Scan"
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for Inquiry Scan.
@@ -241,7 +247,7 @@ menu "TX Power Level settings"
int "Default TX power level for CPB"
depends on BT_CTRL_BR_EDR_CPB_TX_EN
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for CPB.
@@ -249,7 +255,7 @@ menu "TX Power Level settings"
int "Default TX power level for Synchronization Train"
depends on BT_CTRL_BR_EDR_CPB_TX_EN
default 4
range -15 20
range -24 12
help
BR/EDR transmission power level for Synchronization Train.
endmenu
@@ -59,6 +59,12 @@ extern "C" {
#define UC_BR_EDR_APB_EXT_PCA_EN 0
#endif
#if defined(CONFIG_BT_CTRL_BR_EDR_HOLD_EN) && CONFIG_BT_CTRL_BR_EDR_HOLD_EN
#define UC_BR_EDR_HOLD_EN 1
#else
#define UC_BR_EDR_HOLD_EN 0
#endif
#if defined(CONFIG_BT_CTRL_BR_EDR_LK_STORE_EN) && CONFIG_BT_CTRL_BR_EDR_LK_STORE_EN
#define UC_BR_EDR_LK_STORE_EN 1
#else
@@ -110,6 +110,7 @@ extern int bredr_ctrl_feat_sync_en(void);
extern int bredr_ctrl_feat_apb_en(void);
extern int bredr_ctrl_feat_bcst_enc_en(void);
extern int bredr_ctrl_feat_pca_en(void);
extern int bredr_ctrl_feat_hold_en(void);
extern int bredr_ctrl_feat_cpb_rx_en(void);
extern int bredr_ctrl_feat_cpb_tx_en(void);
extern int bredr_ctrl_feat_dtm_en(void);
@@ -626,6 +627,14 @@ static int bredr_ctrl_setup_callback(void)
}
#endif /* UC_BR_EDR_APB_EXT_PCA_EN */
#if UC_BR_EDR_HOLD_EN
ret = bredr_ctrl_feat_hold_en();
if (ret != 0) {
ESP_LOGE(BREDR_LOG_TAG, "bredr_ctrl_feat_hold_en failed, ret:%d", ret);
break;
}
#endif /* UC_BR_EDR_HOLD_EN */
#if UC_BR_EDR_CPB_RX_LINK_NB
ret = bredr_ctrl_feat_cpb_rx_en();
if (ret != 0) {
@@ -17,7 +17,11 @@ wr_btdm_external_bb_get_tx_pwr_table(uint8_t *length, uint8_t modem_cfg)
assert(length != NULL);
assert (modem_cfg <= 2);
// TODO: replace with bt_bb_tx_pwr_table_get when all the targets(h4, s31, etc) support this API
return bt_bb_get_tx_pwr_table(length);
if (modem_cfg == 2) { // BREDR
return bt_bb_tx_pwr_table_get(length, modem_cfg);
} else {
return bt_bb_get_tx_pwr_table(length);
}
}
/*
@@ -113,6 +113,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
{
int rc;
uint16_t conn_handle = 0;
uint16_t handle_flags = 0;
rc = hci_h4_ib_pull_min_len(h4sm, ib);
if (rc) {
@@ -132,7 +133,19 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
h4sm->exp_len = h4sm->hdr[2] + 3;
break;
case HCI_H4_ACL:
conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
handle_flags = btdm_get_le16(&h4sm->hdr[0]);
conn_handle = handle_flags & HCI_INTERNAL_CONN_MASK;
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) || HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
h4sm->exp_len = btdm_get_le16(&h4sm->hdr[2]) + 4;
h4sm->pkt = h4sm->allocs->bredr_acl(conn_handle);
if (!h4sm->pkt) {
return -1;
}
memcpy(h4sm->pkt->data, h4sm->hdr, h4sm->len);
break;
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
#if UC_BT_CTRL_BLE_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
h4sm->om = h4sm->allocs->acl();
@@ -147,17 +160,6 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
break;
}
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
h4sm->exp_len = btdm_get_le16(&h4sm->hdr[2]) + 4;
h4sm->pkt = h4sm->allocs->bredr_acl(conn_handle);
if (!h4sm->pkt) {
return -1;
}
memcpy(h4sm->pkt->data, h4sm->hdr, h4sm->len);
break;
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
return -1;
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
case HCI_H4_SYNC:
@@ -226,6 +228,7 @@ hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
struct hci_h4_input_buffer *ib)
{
uint16_t len;
uint16_t handle_flags = 0;
len = min(ib->len, h4sm->exp_len - h4sm->len);
switch (h4sm->pkt_type) {
@@ -246,9 +249,10 @@ hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
}
break;
case HCI_H4_ACL:
uint16_t conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
handle_flags = btdm_get_le16(&h4sm->hdr[0]);
uint16_t conn_handle = handle_flags & HCI_INTERNAL_CONN_MASK;
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
if (HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) || HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
memcpy(&h4sm->pkt->data[h4sm->len], ib->buf, len);
break;
}
@@ -285,11 +289,24 @@ hci_h4_sm_completed(struct hci_h4_sm *h4sm)
{
int rc;
uint8_t data_source = 0xFF;
uint16_t handle_flags = 0;
uint16_t conn_handle = 0;
switch (h4sm->pkt_type) {
#if CONFIG_BT_CONTROLLER_ENABLED
case HCI_H4_ACL:
uint16_t conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
handle_flags = btdm_get_le16(&h4sm->hdr[0]);
conn_handle = handle_flags & HCI_INTERNAL_CONN_MASK;
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) || HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
if (h4sm->buf) {
rc = h4sm->frame_cb(h4sm->pkt_type, (void *)h4sm->buf, h4sm->len, HCI_DRIVER_BREDR_ACL);
HCI_TRANS_ASSERT(rc == 0, rc, 0);
h4sm->buf = NULL;
}
break;
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
#if UC_BT_CTRL_BLE_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
if (h4sm->om) {
@@ -299,15 +316,6 @@ hci_h4_sm_completed(struct hci_h4_sm *h4sm)
}
}
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
if (h4sm->buf) {
rc = h4sm->frame_cb(h4sm->pkt_type, (void *)h4sm->buf, h4sm->len, HCI_DRIVER_BREDR_ACL);
HCI_TRANS_ASSERT(rc == 0, rc, 0);
h4sm->buf = NULL;
}
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
break;
case HCI_H4_CMD:
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -364,6 +372,9 @@ hci_h4_sm_completed(struct hci_h4_sm *h4sm)
static int
hci_h4_sm_free_buf(struct hci_h4_sm *h4sm)
{
uint16_t handle_flags = 0;
uint16_t conn_handle = 0;
switch (h4sm->pkt_type) {
case HCI_H4_CMD:
if (h4sm->buf) {
@@ -380,20 +391,21 @@ hci_h4_sm_free_buf(struct hci_h4_sm *h4sm)
break;
#endif // (!CONFIG_BT_CONTROLLER_ENABLED)
case HCI_H4_ACL:
uint16_t conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
if (HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
#if UC_BT_CTRL_BLE_IS_ENABLE
if (h4sm->om) {
h4sm->frees->acl(h4sm->om);
h4sm->om = NULL;
}
#endif
} else {
handle_flags = btdm_get_le16(&h4sm->hdr[0]);
conn_handle = handle_flags & HCI_INTERNAL_CONN_MASK;
if (HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) || HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (h4sm->pkt) {
h4sm->frees->bredr_acl(h4sm->pkt);
h4sm->pkt = NULL;
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
} else {
#if UC_BT_CTRL_BLE_IS_ENABLE
if (h4sm->om) {
h4sm->frees->acl(h4sm->om);
h4sm->om = NULL;
}
#endif
}
break;
@@ -180,6 +180,7 @@ hci_driver_vhci_host_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_
{
uint16_t pkt_len;
uint16_t conn_handle;
uint16_t handle_flags = 0;
hci_driver_packet_t *pkt = NULL;
uint8_t data_source = 0xFF;
@@ -194,9 +195,12 @@ hci_driver_vhci_host_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_
break;
case HCI_DRIVER_TYPE_ACL:
conn_handle = btdm_get_le16(&data[1]) & HCI_INTERNAL_CONN_MASK;
handle_flags = btdm_get_le16(&data[1]);
conn_handle = handle_flags & HCI_INTERNAL_CONN_MASK;
bool is_bredr = HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) ||
HCI_INTERNAL_CONN_IS_BREDR(conn_handle);
#if UC_BT_CTRL_BLE_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
if (!is_bredr && HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
struct ble_mbuf *om = ble_msys_get_pkthdr(pkt_len, ESP_HCI_INTERNAL_ACL_MBUF_LEADINGSPCAE);
assert(om);
assert(ble_mbuf_append(om, &data[1], length - 1) == 0);
@@ -205,7 +209,7 @@ hci_driver_vhci_host_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_
}
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (HCI_INTERNAL_CONN_IS_BREDR(conn_handle)) {
if (is_bredr) {
pkt = btdm_hci_trans_buf_alloc(data_type, conn_handle);
assert(pkt);
memcpy(pkt->data, &data[1], pkt_len);
@@ -130,6 +130,7 @@ typedef int (*btdm_hci_trans_tx_func_t)(hci_driver_packet_t *pkt);
#define HCI_INTERNAL_CONN_IS_BREDR(conn_handle) (conn_handle & 0x0800)
#define HCI_INTERNAL_CONN_IS_BREDR_ACL(conn_handle) ((conn_handle & 0x0800) && (conn_handle & 0x000f))
#define HCI_INTERNAL_CONN_IS_BREDR_SYNC(conn_handle) ((conn_handle & 0x0800) && (conn_handle & 0x00f0))
#define HCI_INTERNAL_ACL_IS_BREDR_BCAST(handle_flags) (((handle_flags) >> 14 & 0x03) == 0x01)
int r_btdm_hci_trans_register_tx(btdm_hci_trans_tx_func_t *tx_func, bool async);