Skip to content

Commit 548ad60

Browse files
committed
Merge branch 'bugfix/fix_ble_aa_zero_c3_s3_v5.0' into 'release/v5.0'
fix(bt/ble): Update esp32c3/s3 libbtdm_app.a (555b0a2) (v5.0) See merge request espressif/esp-idf!35688
2 parents 1ce40e1 + 7f7efac commit 548ad60

File tree

12 files changed

+67
-33
lines changed

12 files changed

+67
-33
lines changed

components/bt/controller/esp32c3/Kconfig.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,10 @@ config BT_CTRL_BLE_SCAN
543543
depends on BT_CTRL_RUN_IN_FLASH_ONLY
544544
bool "Enable BLE scan feature"
545545
default y
546+
config BT_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
547+
bool "Enable enhanced Access Address check in CONNECT_IND"
548+
default n
549+
help
550+
Enabling this option will add stricter verification of the Access Address in the CONNECT_IND PDU.
551+
This improves security by ensuring that only connection requests with valid Access Addresses are accepted.
552+
If disabled, only basic checks are applied, improving compatibility.

components/bt/controller/esp32c3/bt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ extern void ets_backup_dma_copy(uint32_t reg, uint32_t mem_addr, uint32_t num, b
274274
#endif
275275

276276
extern void btdm_cca_feature_enable(void);
277+
extern void btdm_aa_check_enhance_enable(void);
277278

278279
extern uint32_t _bt_bss_start;
279280
extern uint32_t _bt_bss_end;
@@ -990,6 +991,9 @@ static void btdm_funcs_table_ready_wrapper(void)
990991
#if BT_BLE_CCA_MODE == 2
991992
btdm_cca_feature_enable();
992993
#endif
994+
#if BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED
995+
btdm_aa_check_enhance_enable();
996+
#endif
993997
}
994998

995999
bool bt_async_wakeup_request(void)

components/bt/include/esp32c3/include/esp_bt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
287287
#define BT_CTRL_BLE_SCAN (1)
288288
#endif // (BT_CTRL_RUN_IN_FLASH_ONLY == 1)
289289

290+
#ifdef CONFIG_BT_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
291+
#define BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED CONFIG_BT_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
292+
#else
293+
#define BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED 0
294+
#endif
295+
290296
#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
291297
.magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL, \
292298
.version = ESP_BT_CTRL_CONFIG_VERSION, \
@@ -332,6 +338,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
332338
.qa_test = BT_CTRL_BLE_TEST, \
333339
.master_en = BT_CTRL_BLE_MASTER, \
334340
.scan_en = BT_CTRL_BLE_SCAN, \
341+
.ble_aa_check = BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED, \
335342
}
336343

337344
#else
@@ -413,6 +420,7 @@ typedef struct {
413420
bool qa_test; /*!< Controller QA test feature is enabled or not */
414421
bool master_en; /*!< Controller master feature is enabled or not */
415422
bool scan_en; /*!< Controller scan feature is enabled or not */
423+
bool ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */
416424
} esp_bt_controller_config_t;
417425

418426
/**

examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
353353

354354
if (adv_name != NULL) {
355355
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
356+
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
357+
// It is recommended to change the default device name to ensure it is unique.
356358
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
357359
if (connect == false) {
358360
connect = true;

examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called eve
365365
ESP_LOGI(GATTC_TAG, "\n");
366366
if (adv_name != NULL) {
367367
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
368-
ESP_LOGI(GATTC_TAG, "searched device %s\n", remote_device_name);
368+
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
369+
// It is recommended to change the default device name to ensure it is unique.
370+
ESP_LOGI(GATTC_TAG, "searched device %s", remote_device_name);
369371
if (connect == false) {
370372
connect = true;
371373
ESP_LOGI(GATTC_TAG, "connect to the remote device.");

examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
452452
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
453453
if (adv_name != NULL) {
454454
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
455+
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
456+
// It is recommended to change the default device name to ensure it is unique.
455457
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
456458
if (connect == false) {
457459
connect = true;

examples/bluetooth/bluedroid/ble_50/ble50_security_client/main/ble50_sec_gattc_demo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
487487
ESP_BLE_AD_TYPE_NAME_CMPL,
488488
&adv_name_len);
489489
if (!connect && strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
490+
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
491+
// It is recommended to change the default device name to ensure it is unique.
490492
connect = true;
491493
esp_ble_gap_stop_ext_scan();
492494
ESP_LOGI(GATTC_TAG, "Device found "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->ext_adv_report.params.addr));

examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747

4848
static SemaphoreHandle_t test_sem = NULL;
4949

50-
uint8_t addr_1m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x01};
51-
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
52-
uint8_t addr_legacy[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x03};
53-
uint8_t addr_coded[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x04};
54-
5550
esp_ble_gap_ext_adv_params_t ext_adv_params_1M = {
5651
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
5752
.interval_min = 0x30,
@@ -235,26 +230,39 @@ void app_main(void)
235230
return;
236231
}
237232

238-
vTaskDelay(200 / portTICK_PERIOD_MS);
233+
// create static random address
234+
esp_bd_addr_t addr_1m;
235+
esp_bd_addr_t addr_2m;
236+
esp_bd_addr_t addr_legacy;
237+
esp_bd_addr_t addr_coded;
238+
esp_ble_gap_addr_create_static(addr_1m);
239+
esp_ble_gap_addr_create_static(addr_2m);
240+
esp_ble_gap_addr_create_static(addr_legacy);
241+
esp_ble_gap_addr_create_static(addr_coded);
239242

240243
test_sem = xSemaphoreCreateBinary();
244+
241245
// 1M phy extend adv, Connectable advertising
246+
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_1m, ESP_BD_ADDR_LEN);
242247
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(0, &ext_adv_params_1M), test_sem);
243248
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(0, addr_1m), test_sem);
244249
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(0, sizeof(raw_adv_data_1m), &raw_adv_data_1m[0]), test_sem);
245250

246251
// 2M phy extend adv, Scannable advertising
252+
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_2m, ESP_BD_ADDR_LEN);
247253
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(1, &ext_adv_params_2M), test_sem);
248254
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(1, addr_2m), test_sem);
249255
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(1, sizeof(raw_scan_rsp_data_2m), raw_scan_rsp_data_2m), test_sem);
250256

251257
// 1M phy legacy adv, ADV_IND
258+
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_legacy, ESP_BD_ADDR_LEN);
252259
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(2, &legacy_adv_params), test_sem);
253260
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(2, addr_legacy), test_sem);
254261
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(2, sizeof(legacy_adv_data), &legacy_adv_data[0]), test_sem);
255262
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(2, sizeof(legacy_scan_rsp_data), &legacy_scan_rsp_data[0]), test_sem);
256263

257264
// coded phy extend adv, Scannable advertising
265+
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_coded, ESP_BD_ADDR_LEN);
258266
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(3, &ext_adv_params_coded), test_sem);
259267
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(3, addr_coded), test_sem);
260268
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(3, sizeof(raw_scan_rsp_data_coded), &raw_scan_rsp_data_coded[0]), test_sem);

examples/bluetooth/bluedroid/ble_50/periodic_adv/main/periodic_adv_demo.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@
5656

5757
static SemaphoreHandle_t test_sem = NULL;
5858

59-
60-
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
61-
6259
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
6360
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED,
6461
.interval_min = 0x30,
@@ -81,18 +78,16 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
8178
};
8279

8380
static uint8_t periodic_adv_raw_data[] = {
84-
0x02, 0x01, 0x06,
85-
0x02, 0x0a, 0xeb,
86-
0x03, 0x03, 0xab, 0xcd,
87-
0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I',
88-
'C', '_', 'A', 'D', 'V'
81+
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
82+
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
83+
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xab, 0xcd,
84+
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V'
8985
};
9086

9187
static uint8_t raw_ext_adv_data_2m[] = {
92-
0x02, 0x01, 0x06,
93-
0x02, 0x0a, 0xeb,
94-
0x13, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
95-
'D', 'V', '_', '8', '0', 'M', 'S'
88+
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
89+
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
90+
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V'
9691
};
9792

9893
static esp_ble_gap_ext_adv_t ext_adv[1] = {
@@ -194,12 +189,16 @@ void app_main(void)
194189
return;
195190
}
196191

197-
vTaskDelay(200 / portTICK_PERIOD_MS);
192+
// create static random address
193+
esp_bd_addr_t rand_addr;
194+
esp_ble_gap_addr_create_static(rand_addr);
198195

199196
test_sem = xSemaphoreCreateBinary();
200-
// 2M phy extend adv, Connectable advertising
197+
198+
// 2M phy extend adv, Non-Connectable and Non-Scannable Undirected advertising
199+
ESP_LOG_BUFFER_HEX(LOG_TAG, rand_addr, ESP_BD_ADDR_LEN);
201200
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(EXT_ADV_HANDLE, &ext_adv_params_2M), test_sem);
202-
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(EXT_ADV_HANDLE, addr_2m), test_sem);
201+
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(EXT_ADV_HANDLE, rand_addr), test_sem);
203202
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(EXT_ADV_HANDLE, sizeof(raw_ext_adv_data_2m), &raw_ext_adv_data_2m[0]), test_sem);
204203

205204
// start all adv

examples/bluetooth/bluedroid/ble_50/periodic_adv/tutorial/Periodic_adv_Example_Walkthrough.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ Ext adv raw data:
215215
216216
```c
217217
static uint8_t raw_ext_adv_data_2m[] = {
218-
0x02, 0x01, 0x06,
219-
0x02, 0x0a, 0xeb,
220-
0x13, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
221-
'D', 'V', '_', '8', '0', 'M', 'S'
218+
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
219+
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
220+
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V'
222221
};
223222
```
224223

@@ -235,11 +234,10 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
235234

236235
```c
237236
static uint8_t periodic_adv_raw_data[] = {
238-
0x02, 0x01, 0x06,
239-
0x02, 0x0a, 0xeb,
240-
0x03, 0x03, 0xab, 0xcd,
241-
0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I',
242-
'C', '_', 'A', 'D', 'V'
237+
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
238+
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
239+
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xab, 0xcd,
240+
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V'
243241
};
244242
```
245243

examples/bluetooth/bluedroid/ble_50/periodic_sync/main/periodic_sync_demo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#define EXT_SCAN_DURATION 0
4949
#define EXT_SCAN_PERIOD 0
5050

51-
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_MULTI_ADV_80MS";
51+
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_EXTENDED_ADV";
5252
static SemaphoreHandle_t test_sem = NULL;
5353

5454
static esp_ble_ext_scan_params_t ext_scan_params = {
@@ -114,6 +114,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
114114
ESP_BLE_AD_TYPE_NAME_CMPL,
115115
&adv_name_len);
116116
if ((adv_name != NULL) && (memcmp(adv_name, remote_device_name, adv_name_len) == 0) && !periodic_sync) {
117+
// Note: If there are multiple devices with the same device name, the device may sync to an unintended one.
118+
// It is recommended to change the default device name to ensure it is unique.
117119
periodic_sync = true;
118120
char adv_temp_name[30] = {'0'};
119121
memcpy(adv_temp_name, adv_name, adv_name_len);

0 commit comments

Comments
 (0)