From c8534e9ad7cb5565400b3a4bac6a55e038f515dd Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 27 May 2025 15:13:29 +0800 Subject: [PATCH 1/2] fix(ble/bluedroid): Fixed clear BLE device recored (cherry picked from commit 21391a45fd4252c41818451da5cbe81338c633b5) Co-authored-by: zhanghaipeng --- components/bt/host/bluedroid/btc/core/btc_main.c | 6 +++--- components/bt/host/bluedroid/btc/include/btc/btc_main.h | 2 +- components/bt/host/bluedroid/stack/btm/btm_ble.c | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/bt/host/bluedroid/btc/core/btc_main.c b/components/bt/host/bluedroid/btc/core/btc_main.c index 5fe01627fc..cb92ff9bea 100644 --- a/components/bt/host/bluedroid/btc/core/btc_main.c +++ b/components/bt/host/bluedroid/btc/core/btc_main.c @@ -154,9 +154,9 @@ uint32_t btc_get_ble_status(void) #if (SMP_INCLUDED == TRUE) // Number of recorded devices - extern uint8_t btm_ble_sec_dev_active_count(void); - if (btm_ble_sec_dev_active_count()) { - status |= BIT(BTC_BLE_STATUS_KEYS); + extern uint8_t btm_ble_sec_dev_record_count(void); + if (btm_ble_sec_dev_record_count()) { + status |= BIT(BTC_BLE_STATUS_DEVICE_REC); } // Number of saved bonded devices diff --git a/components/bt/host/bluedroid/btc/include/btc/btc_main.h b/components/bt/host/bluedroid/btc/include/btc/btc_main.h index e9b6f5ba2a..4cc7784141 100644 --- a/components/bt/host/bluedroid/btc/include/btc/btc_main.h +++ b/components/bt/host/bluedroid/btc/include/btc/btc_main.h @@ -34,7 +34,7 @@ typedef enum { BTC_BLE_STATUS_EXT_ADV, // Extended advertising exist BTC_BLE_STATUS_SCAN, // Scanning exist BTC_BLE_STATUS_CONN, // Connection exist - BTC_BLE_STATUS_KEYS, // Device keys record exist + BTC_BLE_STATUS_DEVICE_REC, // Device record exist BTC_BLE_STATUS_BOND, // Bond info exist BTC_BLE_STATUS_GATTC_CACHE, // GATTC cache exist BTC_BLE_STATUS_GATTC_APP, // GATTC application exist diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble.c b/components/bt/host/bluedroid/stack/btm/btm_ble.c index 2d5e826f20..20fa61efe3 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble.c @@ -2941,7 +2941,7 @@ uint8_t btm_ble_scan_active_count(void) } #if (SMP_INCLUDED == TRUE) -uint8_t btm_ble_sec_dev_active_count(void) +uint8_t btm_ble_sec_dev_record_count(void) { tBTM_SEC_DEV_REC *p_dev_rec = NULL; list_node_t *p_node = NULL; @@ -2957,6 +2957,12 @@ uint8_t btm_ble_sec_dev_active_count(void) return count; } + +void btm_ble_clear_sec_dev_record(void) +{ + /* only used when connection is closed */ + if(btm_cb.p_sec_dev_rec_list) list_clear(btm_cb.p_sec_dev_rec_list); +} #endif #if (BLE_PRIVACY_SPT == TRUE) From 9a3192a8a4a960d3787011ab8fce42bf86e8e001 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 27 May 2025 15:13:27 +0800 Subject: [PATCH 2/2] fix(ble/bluedroid): Fixed issue with deleting link key when classic Bluetooth is not used (cherry picked from commit 7c16bce827002efa68c80860e018841133cb4c08) Co-authored-by: zhanghaipeng --- components/bt/host/bluedroid/stack/btm/btm_dev.c | 2 ++ components/bt/host/bluedroid/stack/btm/btm_devctl.c | 2 ++ components/bt/host/bluedroid/stack/btm/btm_sec.c | 2 +- components/bt/host/bluedroid/stack/btm/include/btm_int.h | 2 ++ components/bt/host/bluedroid/stack/btu/btu_hcif.c | 3 ++- components/bt/host/bluedroid/stack/include/stack/btm_api.h | 2 ++ 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/stack/btm/btm_dev.c b/components/bt/host/bluedroid/stack/btm/btm_dev.c index 5a337342a9..0a8a202eab 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_dev.c +++ b/components/bt/host/bluedroid/stack/btm/btm_dev.c @@ -186,8 +186,10 @@ BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport) } if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL) { +#if (CLASSIC_BT_INCLUDED == TRUE) /* Tell controller to get rid of the link key, if it has one stored */ BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL); +#endif // (CLASSIC_BT_INCLUDED == TRUE) btm_sec_free_dev(p_dev_rec, transport); } diff --git a/components/bt/host/bluedroid/stack/btm/btm_devctl.c b/components/bt/host/bluedroid/stack/btm/btm_devctl.c index a069b01319..e7bfc0740a 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_devctl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_devctl.c @@ -952,6 +952,7 @@ tBTM_STATUS BTM_EnableTestMode(void) } } +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function BTM_DeleteStoredLinkKey @@ -1026,6 +1027,7 @@ void btm_delete_stored_link_key_complete (UINT8 *p) } } +#endif // (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function btm_report_device_status diff --git a/components/bt/host/bluedroid/stack/btm/btm_sec.c b/components/bt/host/bluedroid/stack/btm/btm_sec.c index 990adf979f..38a24ddad1 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/host/bluedroid/stack/btm/btm_sec.c @@ -1001,12 +1001,12 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, return (BTM_SUCCESS); } +#if (CLASSIC_BT_INCLUDED == TRUE) /* Tell controller to get rid of the link key if it has one stored */ if ((BTM_DeleteStoredLinkKey (bd_addr, NULL)) != BTM_SUCCESS) { return (BTM_NO_RESOURCES); } -#if (CLASSIC_BT_INCLUDED == TRUE) /* Save the PIN code if we got a valid one */ if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) { btm_cb.pin_code_len = pin_len; diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index 5ac435c580..ed89f78ed4 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -1146,7 +1146,9 @@ void btm_vsc_complete (UINT8 *p, UINT16 cc_opcode, UINT16 evt_len, tBTM_CMPL_CB *p_vsc_cplt_cback); void btm_inq_db_reset (void); void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len); +#if (CLASSIC_BT_INCLUDED == TRUE) void btm_delete_stored_link_key_complete (UINT8 *p); +#endif // (CLASSIC_BT_INCLUDED == TRUE) void btm_report_device_status (tBTM_DEV_STATUS status); void btm_set_afh_channels_complete (UINT8 *p); void btm_ble_set_channels_complete (UINT8 *p); diff --git a/components/bt/host/bluedroid/stack/btu/btu_hcif.c b/components/bt/host/bluedroid/stack/btu/btu_hcif.c index e5d602fbc7..7e7b63cac7 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/host/bluedroid/stack/btu/btu_hcif.c @@ -960,10 +960,11 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l case HCI_SET_EVENT_FILTER: btm_event_filter_complete (p); break; - +#if (CLASSIC_BT_INCLUDED == TRUE) case HCI_DELETE_STORED_LINK_KEY: btm_delete_stored_link_key_complete (p); break; +#endif // (CLASSIC_BT_INCLUDED == TRUE) case HCI_READ_LOCAL_NAME: btm_read_local_name_complete (p, evt_len); diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 4d2a9ab4f3..cde94b587f 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -3942,6 +3942,7 @@ tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, UINT16 max_lat, //extern UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport); +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function BTM_DeleteStoredLinkKey @@ -3957,6 +3958,7 @@ UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport); *******************************************************************************/ //extern tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb); +#endif // (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* **