Skip to content

Commit 57ef4c4

Browse files
committed
Merge branch 'feat/support_bleqabr24_1539_v5.0' into 'release/v5.0'
feat(bt/bluedroid): Added config for saving BLE bonding keys to NVS (v5.0) See merge request espressif/esp-idf!35600
2 parents 265569f + 87475cd commit 57ef4c4

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

components/bt/host/bluedroid/Kconfig.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ config BT_BLE_SMP_ID_RESET_ENABLE
305305
of a previously paired peer to be used to determine whether a device
306306
with which it previously shared an IRK is within range.
307307

308+
config BT_BLE_SMP_BOND_NVS_FLASH
309+
bool "Save SMP bonding keys to nvs flash"
310+
depends on BT_BLE_SMP_ENABLE
311+
default y
312+
help
313+
This select can save SMP bonding keys to nvs flash
314+
308315
config BT_STACK_NO_LOG
309316
bool "Disable BT debug logs (minimize bin size)"
310317
depends on BT_BLUEDROID_ENABLED

components/bt/host/bluedroid/btc/core/btc_dm.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -182,11 +182,12 @@ static void btc_dm_remove_ble_bonding_keys(void)
182182
btc_storage_remove_ble_bonding_keys(&bd_addr);
183183
}
184184

185+
#if BLE_SMP_BOND_NVS_FLASH
185186
static void btc_dm_save_ble_bonding_keys(void)
186187
{
187188
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 ||
188-
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)) {
189-
return ;
189+
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)) {
190+
return;
190191
}
191192
bt_bdaddr_t bd_addr;
192193

@@ -244,13 +245,13 @@ static void btc_dm_save_ble_bonding_keys(void)
244245
btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = false;
245246
}
246247
}
248+
#endif
247249

248250
static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
249251
{
250252
/* Save link key, if not temporary */
251253
BTC_TRACE_DEBUG("%s, status = %d", __func__, p_auth_cmpl->success);
252254
bt_status_t status = BT_STATUS_FAIL;
253-
int addr_type;
254255
bt_bdaddr_t bdaddr;
255256
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
256257
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)
266267
return;
267268
}
268269

270+
#if BLE_SMP_BOND_NVS_FLASH
271+
int addr_type;
272+
269273
if (btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd) {
270274
// delete unused section in NVS
271275
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)
276280
}
277281
btc_storage_set_ble_dev_auth_mode(&bdaddr, p_auth_cmpl->auth_mode, true);
278282
btc_dm_save_ble_bonding_keys();
283+
#endif
279284
} else {
280285
/*Map the HCI fail reason to bt status */
281286
switch (p_auth_cmpl->fail_reason) {

components/bt/host/bluedroid/btc/core/btc_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ uint32_t btc_get_ble_status(void)
122122
{
123123
uint32_t status = BTC_BLE_STATUS_IDLE;
124124

125+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
126+
BTC_TRACE_ERROR("%s Bluedroid not enabled", __func__);
127+
return status;
128+
}
129+
125130
#if (BLE_INCLUDED == TRUE)
126131
// Number of active advertising
127132
extern uint8_t btm_ble_adv_active_count(void);

components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@
222222
#define UC_BT_BLE_SMP_ID_RESET_ENABLE FALSE
223223
#endif
224224

225+
#ifdef CONFIG_BT_BLE_SMP_BOND_NVS_FLASH
226+
#define UC_BT_BLE_SMP_BOND_NVS_FLASH CONFIG_BT_BLE_SMP_BOND_NVS_FLASH
227+
#else
228+
#define UC_BT_BLE_SMP_BOND_NVS_FLASH FALSE
229+
#endif
230+
225231
//Device Name Maximum Length
226232
#ifdef CONFIG_BT_MAX_DEVICE_NAME_LEN
227233
#define UC_MAX_LOC_BD_NAME_LEN CONFIG_BT_MAX_DEVICE_NAME_LEN

components/bt/host/bluedroid/common/include/common/bt_target.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@
288288
#define BLE_SMP_ID_RESET_ENABLE FALSE
289289
#endif
290290

291+
#if (UC_BT_BLE_SMP_BOND_NVS_FLASH)
292+
#define BLE_SMP_BOND_NVS_FLASH TRUE
293+
#else
294+
#define BLE_SMP_BOND_NVS_FLASH FALSE
295+
#endif
296+
291297
#ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
292298
#define BLE_ADV_REPORT_FLOW_CONTROL (UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP && BLE_INCLUDED)
293299
#endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */

0 commit comments

Comments
 (0)