Merge branch 'bugfix/fix_bluedroid_static_random_conn_rpa_v5.4' into 'release/v5.4'

fix(ble/bluedroid): skip identity conversion for static random direct connect (5.4)

See merge request espressif/esp-idf!50083
This commit is contained in:
Island
2026-06-30 10:24:53 +08:00
18 changed files with 273 additions and 88 deletions
@@ -2393,7 +2393,7 @@ void btm_read_channel_map_complete(UINT8 *p)
memcpy(results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
}
} else {
results.status = BTM_ERR_PROCESSING;
results.status = BTM_HCI_ERROR | results.hci_status;
BTM_TRACE_ERROR("BTM Channel Map Read Failed: hci status 0x%02x", results.hci_status);
}
@@ -2989,26 +2989,47 @@ uint8_t btm_ble_scan_active_count(void)
return count;
}
#if (BLE_INCLUDED == TRUE)
#if (SMP_INCLUDED == TRUE)
extern bool btc_config_has_section(const char *section);
#endif
uint8_t btm_ble_sec_dev_record_count(void)
{
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
list_node_t *p_node = NULL;
uint8_t count = 0;
/* First look for the non-paired devices for the oldest entry */
for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
p_dev_rec = list_node(p_node);
#if (SMP_INCLUDED == TRUE)
if (p_dev_rec && (p_dev_rec->sec_flags & BTM_SEC_IN_USE) && (p_dev_rec->ble.key_type != BTM_LE_KEY_NONE)) {
BTM_TRACE_DEBUG("%s BLE security device #%d: bd_addr=%02X:%02X:%02X:%02X:%02X:%02X",
#else
if (p_dev_rec && (p_dev_rec->sec_flags & BTM_SEC_IN_USE)) {
#endif
#if (SMP_INCLUDED == TRUE)
/* Check if device exists in NVS */
char bdstr[18] = {0};
bdaddr_to_string((bt_bdaddr_t *)p_dev_rec->bd_addr, bdstr, sizeof(bdstr));
BTM_TRACE_WARNING("%s device #%d: "MACSTR", key_type=0x%02x (PENC:%d PID:%d PCSRK:%d LENC:%d LID:%d LCSRK:%d), in_nvs=%d",
__func__,
count,
p_dev_rec->bd_addr[0],
p_dev_rec->bd_addr[1],
p_dev_rec->bd_addr[2],
p_dev_rec->bd_addr[3],
p_dev_rec->bd_addr[4],
p_dev_rec->bd_addr[5]);
MAC2STR(p_dev_rec->bd_addr),
p_dev_rec->ble.key_type,
(p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) ? 1 : 0,
(p_dev_rec->ble.key_type & BTM_LE_KEY_PID) ? 1 : 0,
(p_dev_rec->ble.key_type & BTM_LE_KEY_PCSRK) ? 1 : 0,
(p_dev_rec->ble.key_type & BTM_LE_KEY_LENC) ? 1 : 0,
(p_dev_rec->ble.key_type & BTM_LE_KEY_LID) ? 1 : 0,
(p_dev_rec->ble.key_type & BTM_LE_KEY_LCSRK) ? 1 : 0,
btc_config_has_section(bdstr));
#else
BTM_TRACE_WARNING("%s device #%d: "MACSTR,
__func__,
count,
MAC2STR(p_dev_rec->bd_addr));
#endif
count++;
}
}
@@ -269,6 +269,13 @@ tBTM_STATUS BTM_BleSetExtendedAdvParams(UINT8 instance, tBTM_BLE_GAP_EXT_ADV_PAR
extend_adv_cb.inst[instance].legacy_pdu = false;
}
if (params->type & (BTM_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED |
BTM_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)) {
extend_adv_cb.inst[instance].directed = true;
} else {
extend_adv_cb.inst[instance].directed = false;
}
#if (CONTROLLER_RPA_LIST_ENABLE == FALSE)
// if own_addr_type == BLE_ADDR_PUBLIC_ID or BLE_ADDR_RANDOM_ID,
if((params->own_addr_type == BLE_ADDR_PUBLIC_ID || params->own_addr_type == BLE_ADDR_RANDOM_ID) && BTM_GetLocalResolvablePrivateAddr(rand_addr)) {
@@ -1117,15 +1117,17 @@ tBTM_STATUS BTM_BleStartAdvWithParams(UINT16 adv_int_min, UINT16 adv_int_max, UI
tBTM_STATUS status = BTM_SUCCESS;
/* update adv params */
if (btsnd_hcic_ble_write_adv_params (adv_int_min,
UINT8 hci_status = btsnd_hcic_ble_write_adv_params (adv_int_min,
adv_int_max,
adv_type,
own_bda_type,
p_dir_bda->type,
p_dir_bda->bda,
chnl_map,
p_cb->afp) != HCI_SUCCESS) {
status = BTM_NO_RESOURCES;
p_cb->afp);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
status = btm_ble_status_from_hci(hci_status);
}
osi_mutex_unlock(&btm_lock);
@@ -1175,13 +1177,13 @@ tBTM_STATUS BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
(scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS) &&
(scan_duplicate_filter < BTM_BLE_SCAN_DUPLICATE_MAX) && (scan_window <= scan_interval)) {
if ((btsnd_hcic_ble_set_scan_params(scan_mode, (UINT16)scan_interval,
(UINT16)scan_window,
addr_type_own,
scan_filter_policy)) != HCI_SUCCESS) {
ret = BTM_ILLEGAL_VALUE;
BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d\n",
scan_interval, scan_window);
UINT8 hci_status = btsnd_hcic_ble_set_scan_params(scan_mode, (UINT16)scan_interval,
(UINT16)scan_window,
addr_type_own,
scan_filter_policy);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
ret = btm_ble_status_from_hci(hci_status);
} else {
p_cb->scan_type = scan_mode;
p_cb->scan_interval = scan_interval;
@@ -1232,8 +1234,10 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
BTM_TRACE_WARNING("%s, Partial data write into ADV", __func__);
}
if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data) != HCI_SUCCESS) {
ret = BTM_ILLEGAL_VALUE;
UINT8 hci_status = btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
ret = btm_ble_status_from_hci(hci_status);
btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE;
} else {
ret = BTM_SUCCESS;
@@ -1265,8 +1269,10 @@ tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_le
tBTM_STATUS ret = BTM_SUCCESS;
osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT);
if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)raw_scan_rsp_len, p_raw_scan_rsp) != HCI_SUCCESS) {
ret = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_scan_rsp_data((UINT8)raw_scan_rsp_len, p_raw_scan_rsp);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
ret = btm_ble_status_from_hci(hci_status);
}
osi_mutex_unlock(&btm_lock);
@@ -1377,9 +1383,11 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
p_cb_data->data_mask &= ~mask;
if ((btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data),
p_cb_data->ad_data)) != HCI_SUCCESS) {
ret = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data),
p_cb_data->ad_data);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
ret = btm_ble_status_from_hci(hci_status);
}
osi_mutex_unlock(&btm_lock);
return ret;
@@ -1400,8 +1408,10 @@ tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len)
{
tBTM_STATUS ret = BTM_SUCCESS;
osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT);
if ((btsnd_hcic_ble_set_adv_data((UINT8)raw_adv_len, p_raw_adv)) != HCI_SUCCESS) {
ret = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_adv_data((UINT8)raw_adv_len, p_raw_adv);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
ret = btm_ble_status_from_hci(hci_status);
}
osi_mutex_unlock(&btm_lock);
@@ -2065,15 +2075,17 @@ tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode)
#endif // #if (BLE_42_ADV_EN == TRUE)
/* update adv params */
if (btsnd_hcic_ble_write_adv_params (adv_int_min,
UINT8 hci_status = btsnd_hcic_ble_write_adv_params (adv_int_min,
adv_int_max,
evt_type,
own_addr_type,
init_addr_type,
p_addr_ptr,
p_cb->adv_chnl_map,
p_cb->afp) != HCI_SUCCESS) {
status = BTM_NO_RESOURCES;
p_cb->afp);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
status = btm_ble_status_from_hci(hci_status);
} else {
p_cb->evt_type = evt_type;
p_cb->adv_addr_type = own_addr_type;
@@ -2163,15 +2175,17 @@ tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode)
btm_ble_stop_adv();
#endif // #if (BLE_42_ADV_EN == TRUE)
if (btsnd_hcic_ble_write_adv_params (adv_int_min,
UINT8 hci_status = btsnd_hcic_ble_write_adv_params (adv_int_min,
adv_int_max,
evt_type,
own_addr_type,
peer_addr_type,
p_addr_ptr,
p_cb->adv_chnl_map,
p_cb->afp) != HCI_SUCCESS) {
status = BTM_NO_RESOURCES;
p_cb->afp);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
status = btm_ble_status_from_hci(hci_status);
} else {
p_cb->evt_type = evt_type;
p_cb->adv_addr_type = own_addr_type;
@@ -3241,8 +3255,10 @@ tBTM_STATUS btm_ble_start_scan(void)
p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE;
}
/* start scan, disable duplicate filtering */
if ((btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) != HCI_SUCCESS) {
status = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
status = btm_ble_status_from_hci(hci_status);
} else {
btm_cb.ble_ctr_cb.inq_var.state |= BTM_BLE_SCANNING;
#if (BLE_TOPOLOGY_CHECK == TRUE)
@@ -3312,8 +3328,10 @@ static tBTM_STATUS btm_ble_stop_discover(void)
/* Clear the inquiry callback if set */
btm_cb.ble_ctr_cb.inq_var.state &= ~BTM_BLE_SCANNING;
/* stop discovery now */
if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE) != HCI_SUCCESS) {
status = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
status = btm_ble_status_from_hci(hci_status);
}
#if (BLE_TOPOLOGY_CHECK == TRUE)
/* reset status */
@@ -3428,8 +3446,10 @@ tBTM_STATUS btm_ble_start_adv(void)
#if (BLE_TOPOLOGY_CHECK == TRUE)
btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type);
#endif // (BLE_TOPOLOGY_CHECK == TRUE)
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE) != HCI_SUCCESS) {
rt = BTM_NO_RESOURCES;
UINT8 hci_status = btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE);
if (hci_status != HCI_SUCCESS) {
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
rt = btm_ble_status_from_hci(hci_status);
p_cb->state = temp_state;
p_cb->adv_mode = adv_mode;
#if (BLE_TOPOLOGY_CHECK == TRUE)
@@ -3472,7 +3492,8 @@ tBTM_STATUS btm_ble_stop_adv(void)
/* clear all adv states */
btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK);
#endif // (BLE_TOPOLOGY_CHECK == TRUE)
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE) != HCI_SUCCESS) {
UINT8 hci_status = btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE);
if (hci_status != HCI_SUCCESS) {
// reset state
p_cb->fast_adv_on = temp_fast_adv_on;
p_cb->adv_mode = temp_adv_mode;
@@ -3481,7 +3502,8 @@ tBTM_STATUS btm_ble_stop_adv(void)
#if (BLE_TOPOLOGY_CHECK == TRUE)
btm_ble_set_topology_mask (temp_mask);
#endif // (BLE_TOPOLOGY_CHECK == TRUE)
rt = BTM_NO_RESOURCES;
BTM_BLE_TRACE_HCI_CMD_FAIL(__func__, hci_status);
rt = btm_ble_status_from_hci(hci_status);
}
if(rt != HCI_SUCCESS) {
p_cb->adv_mode = temp_adv_mode;
@@ -1327,12 +1327,8 @@ void btm_ble_set_channels_complete (UINT8 *p)
case HCI_SUCCESS:
cb_params.set_channels.status = BTM_SUCCESS;
break;
case HCI_ERR_UNSUPPORTED_VALUE:
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
cb_params.set_channels.status = BTM_ILLEGAL_VALUE;
break;
default:
cb_params.set_channels.status = BTM_ERR_PROCESSING;
cb_params.set_channels.status = BTM_HCI_ERROR | cb_params.set_channels.hci_status;
break;
}
BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_CHANNELS_COMPLETE_EVT, &cb_params);
@@ -628,6 +628,14 @@ void btm_ble_cs_subevt_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT *subevt_res
void btm_ble_cs_subevt_continue_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT *subevt_continue_result);
#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE)
static inline tBTM_STATUS btm_ble_status_from_hci(UINT8 hci_status)
{
return (hci_status == HCI_SUCCESS) ? BTM_SUCCESS : (tBTM_STATUS)(BTM_HCI_ERROR | hci_status);
}
#define BTM_BLE_TRACE_HCI_CMD_FAIL(func, hci_status) \
BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = 0x%x", (func), (hci_status))
/*
#ifdef __cplusplus