Skip to content

Commit a8d3b48

Browse files
committed
Merge branch 'bugfix/fix_find_the_oldest_device' into 'master'
Bugfix/fix find the oldest device Closes BCI-542 See merge request espressif/esp-idf!40464
2 parents cfca522 + b6dc79a commit a8d3b48

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

components/bt/host/bluedroid/stack/btm/btm_acl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,8 +2519,7 @@ tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
25192519
} else /* otherwise can disconnect right away */
25202520
#endif
25212521
{
2522-
if (hci_handle != 0xFFFF && p_dev_rec &&
2523-
p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) {
2522+
if (hci_handle != 0xFFFF && (( p_dev_rec && p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) || (!p_dev_rec))) {
25242523
if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER)) {
25252524
status = BTM_NO_RESOURCES;
25262525
}

components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
#define BTM_BLE_META_READ_IRK_LEN 2
5151
#define BTM_BLE_META_ADD_WL_ATTR_LEN 9
5252

53+
#if CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
54+
static bool is_deleting_zero_addr;
55+
#endif // CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
5356
/*******************************************************************************
5457
** Functions implemented controller based privacy using Resolving List
5558
*******************************************************************************/
@@ -343,8 +346,21 @@ void btm_ble_remove_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len)
343346
btm_cb.ble_ctr_cb.resolving_list_avail_size++;
344347
}
345348
} else {
346-
BTM_TRACE_ERROR("%s remove resolving list error 0x%x", __func__, status);
349+
#if CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
350+
if (!is_deleting_zero_addr)
351+
#endif // CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
352+
{
353+
/* It's expected for some controllers to return error when deleting {0,0,0,0,0,0}, ignore that case */
354+
BTM_TRACE_ERROR("%s remove resolving list error, status = 0x%02x", __func__, status);
355+
}
356+
}
357+
358+
#if CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
359+
/* Clear zero address deletion flag regardless of outcome */
360+
if (is_deleting_zero_addr) {
361+
is_deleting_zero_addr = false;
347362
}
363+
#endif // CONTROLLER_RPA_LIST_ENABLE && BLE_SMP_ID_RESET_ENABLE
348364
}
349365

350366
/*******************************************************************************
@@ -1139,6 +1155,7 @@ void btm_ble_resolving_list_cleanup(void)
11391155

11401156
}
11411157

1158+
#if (CONTROLLER_RPA_LIST_ENABLE == TRUE)
11421159
void btm_ble_add_default_entry_to_resolving_list(void)
11431160
{
11441161
/*
@@ -1151,9 +1168,17 @@ void btm_ble_add_default_entry_to_resolving_list(void)
11511168
BD_ADDR peer_addr = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
11521169
BT_OCTET16 peer_irk = {0x0};
11531170

1171+
#if (BLE_SMP_ID_RESET_ENABLE == TRUE)
11541172
// Remove the existing entry in resolving list When resetting the device identity
11551173
btsnd_hcic_ble_rm_device_resolving_list(BLE_ADDR_PUBLIC, peer_addr);
11561174

1175+
is_deleting_zero_addr = true;
1176+
1177+
btm_ble_enq_resolving_list_pending(peer_addr, BTM_BLE_META_REMOVE_IRK_ENTRY);
1178+
#endif // (BLE_SMP_ID_RESET_ENABLE == TRUE)
11571179
btsnd_hcic_ble_add_device_resolving_list (BLE_ADDR_PUBLIC, peer_addr, peer_irk, btm_cb.devcb.id_keys.irk);
1180+
1181+
btm_ble_enq_resolving_list_pending(peer_addr, BTM_BLE_META_ADD_IRK_ENTRY);
11581182
}
1183+
#endif // (CONTROLLER_RPA_LIST_ENABLE == TRUE)
11591184
#endif

components/bt/host/bluedroid/stack/btm/btm_dev.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
368368
}
369369
if (!new_entry_found) {
370370
p_dev_rec = btm_find_oldest_dev();
371+
#if (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)
372+
// If device record exists and contains identity key, remove it from resolving list
373+
if (p_dev_rec && (p_dev_rec->ble.key_type & SMP_SEC_KEY_TYPE_ID)) {
374+
btm_ble_resolving_list_remove_dev(p_dev_rec);
375+
}
376+
#endif // (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)
371377
} else {
372378
/* if the old device entry not present go with new entry */
373379
if (old_entry_found) {
@@ -675,6 +681,7 @@ tBTM_SEC_DEV_REC *btm_find_oldest_dev (void)
675681

676682
/* All devices are paired; find the oldest */
677683
for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
684+
p_dev_rec = list_node(p_node);
678685
if ((p_dev_rec->sec_flags & BTM_SEC_IN_USE) == 0) {
679686
continue;
680687
}

components/bt/host/bluedroid/stack/btm/btm_sec.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ BOOLEAN BTM_GetSecurityFlags (BD_ADDR bd_addr, UINT8 *p_sec_flags)
342342
*p_sec_flags = (UINT8) p_dev_rec->sec_flags;
343343
return (TRUE);
344344
}
345-
BTM_TRACE_ERROR ("BTM_GetSecurityFlags false");
345+
346+
BTM_TRACE_ERROR("%s: BTM_GetSecurityFlags failed for device [%02X:%02X:%02X:%02X:%02X:%02X]",
347+
__func__,
348+
bd_addr[0], bd_addr[1], bd_addr[2],
349+
bd_addr[3], bd_addr[4], bd_addr[5]);
350+
346351
return (FALSE);
347352
}
348353

@@ -369,7 +374,12 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 *p_sec_flags,
369374

370375
return (TRUE);
371376
}
372-
BTM_TRACE_ERROR ("BTM_GetSecurityFlags false\n");
377+
378+
BTM_TRACE_ERROR("%s: BTM_GetSecurityFlags failed for device [%02X:%02X:%02X:%02X:%02X:%02X]",
379+
__func__,
380+
bd_addr[0], bd_addr[1], bd_addr[2],
381+
bd_addr[3], bd_addr[4], bd_addr[5]);
382+
373383
return (FALSE);
374384
}
375385

0 commit comments

Comments
 (0)