fix(ble/bluedroid): Fixed BLE incorrect device record count issue

(cherry picked from commit 9bfd9c5340a14a264380935e8f2fb55d2feb7b8a)

Co-authored-by: zhanghaipeng <zhanghaipeng@espressif.com>
This commit is contained in:
Zhang Hai Peng
2025-11-21 17:53:22 +08:00
parent d66ebb86d2
commit a3ff4beeb3
3 changed files with 10 additions and 10 deletions
@@ -16,7 +16,7 @@
#if (SMP_INCLUDED == TRUE)
//the maximum number of bonded devices
#define BONED_DEVICES_MAX_COUNT (BTM_SEC_MAX_DEVICE_RECORDS)
#define BONED_DEVICES_MAX_COUNT (BTM_SEC_MAX_BONDS)
static void _btc_storage_save(void)
{
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -40,7 +40,7 @@ bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
/* device not in bond list and exceed the maximum number of bonded devices, delete the inactive bonded device */
if (btc_storage_get_num_all_bond_devices() >= BTM_SEC_MAX_DEVICE_RECORDS && !btc_config_has_section(bdstr)) {
if (btc_storage_get_num_all_bond_devices() >= BTM_SEC_MAX_BONDS && !btc_config_has_section(bdstr)) {
const btc_config_section_iter_t *iter = btc_config_section_begin();
const btc_config_section_iter_t *remove_iter = iter;
/* find the first device(the last node) */
@@ -57,7 +57,7 @@ bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
// delete config info
if (btc_config_remove_section(remove_section)) {
BTC_TRACE_WARNING("exceeded the maximum nubmer of bonded devices, delete the first device info : %02x:%02x:%02x:%02x:%02x:%02x",
BTC_TRACE_WARNING("exceeded the maximum number of bonded devices, delete the first device info : %02x:%02x:%02x:%02x:%02x:%02x",
bd_addr.address[0], bd_addr.address[1], bd_addr.address[2], bd_addr.address[3], bd_addr.address[4], bd_addr.address[5]);
}
}
@@ -141,8 +141,8 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
continue;
}
dev_cnt ++;
/* if the number of device stored in nvs not exceed to BTM_SEC_MAX_DEVICE_RECORDS, load it */
if (dev_cnt <= BTM_SEC_MAX_DEVICE_RECORDS) {
/* if the number of device stored in nvs not exceed to BTM_SEC_MAX_BONDS, load it */
if (dev_cnt <= BTM_SEC_MAX_BONDS) {
if (btc_config_exist(name, BTC_STORAGE_LINK_KEY_TYPE_STR) && btc_config_exist(name, BTC_STORAGE_PIN_LENGTH_STR) &&
btc_config_exist(name, BTC_STORAGE_SC_SUPPORT) && btc_config_exist(name, BTC_STORAGE_LINK_KEY_STR)) {
/* load bt device */
@@ -1132,11 +1132,11 @@
/* The number of security records for peer devices. 15 AS Default*/
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
#if (UC_BT_SMP_MAX_BONDS < UC_BT_ACL_CONNECTIONS)
#define BTM_SEC_MAX_DEVICE_RECORDS UC_BT_ACL_CONNECTIONS
#else
#define BTM_SEC_MAX_DEVICE_RECORDS UC_BT_SMP_MAX_BONDS
#define BTM_SEC_MAX_DEVICE_RECORDS (UC_BT_SMP_MAX_BONDS + UC_BT_ACL_CONNECTIONS)
#endif
#ifndef BTM_SEC_MAX_BONDS
#define BTM_SEC_MAX_BONDS UC_BT_SMP_MAX_BONDS
#endif
#if BTA_SDP_INCLUDED