Skip to content

Commit

Permalink
Merge branch 'feat/support_bleqabr24_1539_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
feat(bt/bluedroid): Added config for saving BLE bonding keys to NVS (v5.0)

See merge request espressif/esp-idf!35600
  • Loading branch information
Isl2017 committed Dec 16, 2024
2 parents 265569f + 87475cd commit 57ef4c4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,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
Expand Down
13 changes: 9 additions & 4 deletions components/bt/host/bluedroid/btc/core/btc_dm.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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 ;
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;
}
bt_bdaddr_t bd_addr;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions components/bt/host/bluedroid/btc/core/btc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ uint32_t btc_get_ble_status(void)
{
uint32_t status = BTC_BLE_STATUS_IDLE;

if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
BTC_TRACE_ERROR("%s Bluedroid not enabled", __func__);
return status;
}

#if (BLE_INCLUDED == TRUE)
// Number of active advertising
extern uint8_t btm_ble_adv_active_count(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,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 */
Expand Down

0 comments on commit 57ef4c4

Please sign in to comment.