feat(bt/bluedroid): Added config for saving BLE bonding keys to NVS

(cherry picked from commit 6d1160b2e61a3e782699cb14fb0f70c05b121b30)

Co-authored-by: chenjianhua <chenjianhua@espressif.com>
This commit is contained in:
Chen Jian Hua 2024-12-12 12:33:29 +08:00
parent 24c98125dc
commit d28072b4d5
4 changed files with 28 additions and 4 deletions

View File

@ -304,6 +304,13 @@ config BT_BLE_SMP_ID_RESET_ENABLE
of a previously paired peer to be used to determine whether a device
with which it previously shared an IRK is within range.
config BT_BLE_SMP_BOND_NVS_FLASH
bool "Save SMP bonding keys to nvs flash"
depends on BT_BLE_SMP_ENABLE
default y
help
This select can save SMP bonding keys to nvs flash
config BT_STACK_NO_LOG
bool "Disable BT debug logs (minimize bin size)"
depends on BT_BLUEDROID_ENABLED

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -182,11 +182,12 @@ static void btc_dm_remove_ble_bonding_keys(void)
btc_storage_remove_ble_bonding_keys(&bd_addr);
}
#if BLE_SMP_BOND_NVS_FLASH
static void btc_dm_save_ble_bonding_keys(void)
{
if (!(btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd ||
btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd)) {
return ;
return;
}
bt_bdaddr_t bd_addr;
@ -244,13 +245,13 @@ static void btc_dm_save_ble_bonding_keys(void)
btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = false;
}
}
#endif
static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
{
/* Save link key, if not temporary */
BTC_TRACE_DEBUG("%s, status = %d", __func__, p_auth_cmpl->success);
bt_status_t status = BT_STATUS_FAIL;
int addr_type;
bt_bdaddr_t bdaddr;
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
bdcpy(btc_dm_cb.pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
@ -266,6 +267,9 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
return;
}
#if BLE_SMP_BOND_NVS_FLASH
int addr_type;
if (btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd) {
// delete unused section in NVS
btc_storage_remove_unused_sections(p_auth_cmpl->bd_addr, &btc_dm_cb.pairing_cb.ble.pid_key);
@ -276,6 +280,7 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
}
btc_storage_set_ble_dev_auth_mode(&bdaddr, p_auth_cmpl->auth_mode, true);
btc_dm_save_ble_bonding_keys();
#endif
} else {
/*Map the HCI fail reason to bt status */
switch (p_auth_cmpl->fail_reason) {

View File

@ -215,6 +215,12 @@
#define UC_BT_BLE_SMP_ID_RESET_ENABLE FALSE
#endif
#ifdef CONFIG_BT_BLE_SMP_BOND_NVS_FLASH
#define UC_BT_BLE_SMP_BOND_NVS_FLASH CONFIG_BT_BLE_SMP_BOND_NVS_FLASH
#else
#define UC_BT_BLE_SMP_BOND_NVS_FLASH FALSE
#endif
//Device Name Maximum Length
#ifdef CONFIG_BT_MAX_DEVICE_NAME_LEN
#define UC_MAX_LOC_BD_NAME_LEN CONFIG_BT_MAX_DEVICE_NAME_LEN

View File

@ -296,6 +296,12 @@
#define BLE_SMP_ID_RESET_ENABLE FALSE
#endif
#if (UC_BT_BLE_SMP_BOND_NVS_FLASH)
#define BLE_SMP_BOND_NVS_FLASH TRUE
#else
#define BLE_SMP_BOND_NVS_FLASH FALSE
#endif
#ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#define BLE_ADV_REPORT_FLOW_CONTROL (UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP && BLE_INCLUDED)
#endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */