Skip to content

Commit dbce23f

Browse files
committed
Merge branch 'feat/allow_connect_during_scan' into 'master'
feat(nimble): Add support to allow connection during scanning Closes BLERP-903 See merge request espressif/esp-idf!32509
2 parents d2cfb78 + f03c3ed commit dbce23f

File tree

13 files changed

+61
-27
lines changed

13 files changed

+61
-27
lines changed

components/bt/host/nimble/Kconfig.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ config BT_NIMBLE_HIGH_DUTY_ADV_ITVL
940940
help
941941
This enable BLE high duty advertising interval feature
942942

943+
config BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
944+
bool "Allow Connections with scanning in progress"
945+
depends on BT_NIMBLE_ENABLED && (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3)
946+
help
947+
This enables support for user to initiate a new connection with scan in progress
948+
943949
config BT_NIMBLE_HOST_QUEUE_CONG_CHECK
944950
bool "BLE queue congestion check"
945951
depends on BT_NIMBLE_ENABLED

components/bt/host/nimble/nimble

components/bt/host/nimble/port/include/esp_nimble_cfg.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,14 @@
18441844
#endif
18451845
#endif
18461846

1847+
#ifndef MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN
1848+
#ifdef CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
1849+
#define MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
1850+
#else
1851+
#define MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN (0)
1852+
#endif
1853+
#endif
1854+
18471855
#if CONFIG_BT_CONTROLLER_DISABLED && CONFIG_BT_NIMBLE_TRANSPORT_UART
18481856
#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PORT
18491857
#define MYNEWT_VAL_BLE_TRANSPORT_UART_PORT CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT

examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -303,12 +303,14 @@ ble_cts_cent_connect_if_interesting(void *disc)
303303
}
304304
#endif
305305

306+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
306307
/* Scanning must be stopped before a connection can be initiated. */
307308
rc = ble_gap_disc_cancel();
308309
if (rc != 0) {
309310
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
310311
return;
311312
}
313+
#endif
312314

313315
/* Figure out address to use for connect (no privacy for now) */
314316
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -364,7 +366,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
364366
return 0;
365367
}
366368

367-
/* An advertisment report was received during GAP discovery. */
369+
/* An advertisement report was received during GAP discovery. */
368370
print_adv_fields(&fields);
369371

370372
/* Try to connect to the advertiser if it looks interesting. */
@@ -482,7 +484,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
482484

483485
#if CONFIG_EXAMPLE_EXTENDED_ADV
484486
case BLE_GAP_EVENT_EXT_DISC:
485-
/* An advertisment report was received during GAP discovery. */
487+
/* An advertisement report was received during GAP discovery. */
486488
ext_print_adv_report(&event->disc);
487489

488490
ble_cts_cent_connect_if_interesting(&event->disc);

examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -358,12 +358,14 @@ enc_adv_data_cent_connect_if_interesting(void *disc)
358358
return;
359359
}
360360

361+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
361362
/* Scanning must be stopped before a connection can be initiated. */
362363
rc = ble_gap_disc_cancel();
363364
if (rc != 0) {
364365
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
365366
return;
366367
}
368+
#endif
367369

368370
/* Figure out address to use for connect (no privacy for now) */
369371
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -416,7 +418,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg)
416418
return 0;
417419
}
418420

419-
/* An advertisment report was received during GAP discovery. */
421+
/* An advertisement report was received during GAP discovery. */
420422
print_adv_fields(&fields);
421423

422424
/* Try to connect to the advertiser if it looks interesting. */
@@ -514,7 +516,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg)
514516
return 0;
515517

516518
case BLE_GAP_EVENT_EXT_DISC:
517-
/* An advertisment report was received during GAP discovery. */
519+
/* An advertisement report was received during GAP discovery. */
518520
ext_print_adv_report(&event->disc);
519521

520522
enc_adv_data_cent_connect_if_interesting(&event->disc);

examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -189,7 +189,7 @@ ble_htp_cent_on_read(uint16_t conn_handle,
189189

190190
/**
191191
* Performs three GATT operations against the specified peer:
192-
* 1. Reads the HTP temparature type characteristic.
192+
* 1. Reads the HTP temperature type characteristic.
193193
* 2. After read is completed, writes the HTP temperature measurement interval characteristic.
194194
* 3. After write is completed, subscribes to notifications for the HTP intermediate temperature
195195
* and temperature measurement characteristic.
@@ -205,12 +205,12 @@ ble_htp_cent_read_write_subscribe(const struct peer *peer)
205205
const struct peer_chr *chr;
206206
int rc;
207207

208-
/* Read the Temparature Type characteristic. */
208+
/* Read the Temperature Type characteristic. */
209209
chr = peer_chr_find_uuid(peer,
210210
BLE_UUID16_DECLARE(BLE_SVC_HTP_UUID16),
211211
BLE_UUID16_DECLARE(BLE_SVC_HTP_CHR_UUID16_TEMP_TYPE));
212212
if (chr == NULL) {
213-
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Temparature Type"
213+
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Temperature Type"
214214
" characteristic\n");
215215
goto err;
216216
}
@@ -418,12 +418,14 @@ ble_htp_cent_connect_if_interesting(void *disc)
418418
}
419419
#endif
420420

421+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
421422
/* Scanning must be stopped before a connection can be initiated. */
422423
rc = ble_gap_disc_cancel();
423424
if (rc != 0) {
424425
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
425426
return;
426427
}
428+
#endif
427429

428430
/* Figure out address to use for connect (no privacy for now) */
429431
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -479,7 +481,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
479481
return 0;
480482
}
481483

482-
/* An advertisment report was received during GAP discovery. */
484+
/* An advertisement report was received during GAP discovery. */
483485
print_adv_fields(&fields);
484486

485487
/* Try to connect to the advertiser if it looks interesting. */
@@ -613,7 +615,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
613615

614616
#if CONFIG_EXAMPLE_EXTENDED_ADV
615617
case BLE_GAP_EVENT_EXT_DISC:
616-
/* An advertisment report was received during GAP discovery. */
618+
/* An advertisement report was received during GAP discovery. */
617619
ext_print_adv_report(&event->disc);
618620

619621
ble_htp_cent_connect_if_interesting(&event->disc);

examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -77,7 +77,7 @@ blecent_l2cap_coc_send_data(struct ble_l2cap_chan *chan)
7777
}
7878

7979
/**
80-
* After connetion is established on GAP layer, service discovery is performed. On
80+
* After connection is established on GAP layer, service discovery is performed. On
8181
* it's completion, this API is called for making a connection is on L2CAP layer.
8282
*/
8383
static void
@@ -340,12 +340,14 @@ blecent_connect_if_interesting(void *disc)
340340
}
341341
#endif
342342

343+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
343344
/* Scanning must be stopped before a connection can be initiated. */
344345
rc = ble_gap_disc_cancel();
345346
if (rc != 0) {
346347
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
347348
return;
348349
}
350+
#endif
349351

350352
/* Figure out address to use for connect (no privacy for now) */
351353
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -403,7 +405,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
403405
return 0;
404406
}
405407

406-
/* An advertisment report was received during GAP discovery. */
408+
/* An advertisement report was received during GAP discovery. */
407409
print_adv_fields(&fields);
408410

409411
/* Try to connect to the advertiser if it looks interesting. */
@@ -470,7 +472,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
470472

471473
#if CONFIG_EXAMPLE_EXTENDED_ADV
472474
case BLE_GAP_EVENT_EXT_DISC:
473-
/* An advertisment report was received during GAP discovery. */
475+
/* An advertisement report was received during GAP discovery. */
474476
ext_print_adv_report(&event->disc);
475477

476478
blecent_connect_if_interesting(&event->disc);

examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg)
8585
case BLE_GAP_EVENT_EXT_DISC:
8686
rc = ble_hs_adv_parse_fields(&fields, event->ext_disc.data, event->ext_disc.length_data);
8787

88-
/* An advertisment report was received during GAP discovery. */
88+
/* An advertisement report was received during GAP discovery. */
8989
if ((rc == 0) && fields.name && (fields.name_len >= strlen(BLE_PEER_NAME)) &&
9090
!strncmp((const char *)fields.name, BLE_PEER_NAME, strlen(BLE_PEER_NAME))) {
9191
ble_cent_connect(&event->ext_disc);
@@ -319,12 +319,14 @@ ble_cent_connect(void *disc)
319319
return;
320320
}
321321

322+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
322323
/* Scanning must be stopped before a connection can be initiated. */
323324
rc = ble_gap_disc_cancel();
324325
if (rc != 0) {
325326
ESP_LOGE(TAG, "Failed to cancel scan; rc=%d\n", rc);
326327
return;
327328
}
329+
#endif
328330

329331
/* We won't connect to the same device. Change our static random address to simulate
330332
* multi-connection with only one central and one peripheral.

examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ blecent_connect_if_interesting(void *disc)
288288
return;
289289
}
290290

291+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
291292
/* Scanning must be stopped before a connection can be initiated. */
292293
rc = ble_gap_disc_cancel();
293294
if (rc != 0) {
294295
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
295296
return;
296297
}
298+
#endif
297299

298300
/* Figure out address to use for connect (no privacy for now) */
299301
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -438,7 +440,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
438440
return 0;
439441

440442
case BLE_GAP_EVENT_EXT_DISC:
441-
/* An advertisment report was received during GAP discovery. */
443+
/* An advertisement report was received during GAP discovery. */
442444
ext_print_adv_report(&event->disc);
443445

444446
blecent_connect_if_interesting(&event->disc);

examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -25,7 +25,7 @@ static struct ble_prox_cent_link_lost_peer disconn_peer[MYNEWT_VAL(BLE_MAX_CONNE
2525
/* Note: Path loss is calculated using formula : threshold - RSSI value
2626
* by default threshold is kept -128 as per the spec
2727
* high_threshold and low_threshold are hardcoded after testing and noting
28-
* RSSI values when distance betweeen devices are less and more.
28+
* RSSI values when distance between devices are less and more.
2929
*/
3030
static int8_t high_threshold = -70;
3131
static int8_t low_threshold = -100;
@@ -335,12 +335,14 @@ ble_prox_cent_connect_if_interesting(void *disc)
335335
}
336336
#endif
337337

338+
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
338339
/* Scanning must be stopped before a connection can be initiated. */
339340
rc = ble_gap_disc_cancel();
340341
if (rc != 0) {
341342
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
342343
return;
343344
}
345+
#endif
344346

345347
/* Figure out address to use for connect (no privacy for now) */
346348
rc = ble_hs_id_infer_auto(0, &own_addr_type);
@@ -396,7 +398,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
396398
return 0;
397399
}
398400

399-
/* An advertisment report was received during GAP discovery. */
401+
/* An advertisement report was received during GAP discovery. */
400402
print_adv_fields(&fields);
401403

402404
/* Try to connect to the advertiser if it looks interesting. */
@@ -561,7 +563,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
561563

562564
#if CONFIG_EXAMPLE_EXTENDED_ADV
563565
case BLE_GAP_EVENT_EXT_DISC:
564-
/* An advertisment report was received during GAP discovery. */
566+
/* An advertisement report was received during GAP discovery. */
565567
ext_print_adv_report(&event->disc);
566568

567569
ble_prox_cent_connect_if_interesting(&event->disc);

0 commit comments

Comments
 (0)