mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
feat(nimble): Add support to allow connection during scanning
This commit is contained in:
@ -685,3 +685,9 @@ config BT_NIMBLE_MAX_EADS
|
|||||||
depends on BT_NIMBLE_ENABLED && BT_NIMBLE_ENC_ADV_DATA
|
depends on BT_NIMBLE_ENABLED && BT_NIMBLE_ENC_ADV_DATA
|
||||||
help
|
help
|
||||||
Defines maximum number of encrypted advertising data key material to save
|
Defines maximum number of encrypted advertising data key material to save
|
||||||
|
|
||||||
|
config BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
|
||||||
|
bool "Allow Connections with scanning in progress"
|
||||||
|
depends on BT_NIMBLE_ENABLED && (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3)
|
||||||
|
help
|
||||||
|
This enables support for user to initiate a new connection with scan in progress
|
||||||
|
Submodule components/bt/host/nimble/nimble updated: be490ecbb4...2fbd46dfed
@ -1664,5 +1664,12 @@
|
|||||||
#else
|
#else
|
||||||
#define MYNEWT_VAL_BLE_HCI_VS (0)
|
#define MYNEWT_VAL_BLE_HCI_VS (0)
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN
|
||||||
|
#ifdef CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
|
||||||
|
#define MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN
|
||||||
|
#else
|
||||||
|
#define MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN (0)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -358,12 +358,14 @@ enc_adv_data_cent_connect_if_interesting(void *disc)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
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)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* 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)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case BLE_GAP_EVENT_EXT_DISC:
|
case BLE_GAP_EVENT_EXT_DISC:
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
ext_print_adv_report(&event->disc);
|
ext_print_adv_report(&event->disc);
|
||||||
|
|
||||||
enc_adv_data_cent_connect_if_interesting(&event->disc);
|
enc_adv_data_cent_connect_if_interesting(&event->disc);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -189,7 +189,7 @@ err:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs three GATT operations against the specified peer:
|
* Performs three GATT operations against the specified peer:
|
||||||
* 1. Reads the HTP temparature type characteristic.
|
* 1. Reads the HTP temperature type characteristic.
|
||||||
* 2. After read is completed, writes the HTP temperature measurement interval characteristic.
|
* 2. After read is completed, writes the HTP temperature measurement interval characteristic.
|
||||||
* 3. After write is completed, subscribes to notifications for the HTP intermediate temperature
|
* 3. After write is completed, subscribes to notifications for the HTP intermediate temperature
|
||||||
* and temperature measurement characteristic.
|
* and temperature measurement characteristic.
|
||||||
@ -205,12 +205,12 @@ ble_htp_cent_read_write_subscribe(const struct peer *peer)
|
|||||||
const struct peer_chr *chr;
|
const struct peer_chr *chr;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Read the Temparature Type characteristic. */
|
/* Read the Temperature Type characteristic. */
|
||||||
chr = peer_chr_find_uuid(peer,
|
chr = peer_chr_find_uuid(peer,
|
||||||
BLE_UUID16_DECLARE(BLE_SVC_HTP_UUID16),
|
BLE_UUID16_DECLARE(BLE_SVC_HTP_UUID16),
|
||||||
BLE_UUID16_DECLARE(BLE_SVC_HTP_CHR_UUID16_TEMP_TYPE));
|
BLE_UUID16_DECLARE(BLE_SVC_HTP_CHR_UUID16_TEMP_TYPE));
|
||||||
if (chr == NULL) {
|
if (chr == NULL) {
|
||||||
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Temparature Type"
|
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Temperature Type"
|
||||||
" characteristic\n");
|
" characteristic\n");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -418,12 +418,14 @@ ble_htp_cent_connect_if_interesting(void *disc)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
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)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* 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)
|
|||||||
|
|
||||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||||
case BLE_GAP_EVENT_EXT_DISC:
|
case BLE_GAP_EVENT_EXT_DISC:
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
ext_print_adv_report(&event->disc);
|
ext_print_adv_report(&event->disc);
|
||||||
|
|
||||||
ble_htp_cent_connect_if_interesting(&event->disc);
|
ble_htp_cent_connect_if_interesting(&event->disc);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -77,7 +77,7 @@ blecent_l2cap_coc_send_data(struct ble_l2cap_chan *chan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After connetion is established on GAP layer, service discovery is performed. On
|
* After connection is established on GAP layer, service discovery is performed. On
|
||||||
* it's completion, this API is called for making a connection is on L2CAP layer.
|
* it's completion, this API is called for making a connection is on L2CAP layer.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
@ -340,12 +340,14 @@ blecent_connect_if_interesting(void *disc)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||||
@ -403,7 +405,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* Try to connect to the advertiser if it looks interesting. */
|
||||||
@ -470,7 +472,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
|
|
||||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||||
case BLE_GAP_EVENT_EXT_DISC:
|
case BLE_GAP_EVENT_EXT_DISC:
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
ext_print_adv_report(&event->disc);
|
ext_print_adv_report(&event->disc);
|
||||||
|
|
||||||
blecent_connect_if_interesting(&event->disc);
|
blecent_connect_if_interesting(&event->disc);
|
||||||
|
@ -288,12 +288,14 @@ blecent_connect_if_interesting(void *disc)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||||
@ -438,7 +440,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case BLE_GAP_EVENT_EXT_DISC:
|
case BLE_GAP_EVENT_EXT_DISC:
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
ext_print_adv_report(&event->disc);
|
ext_print_adv_report(&event->disc);
|
||||||
|
|
||||||
blecent_connect_if_interesting(&event->disc);
|
blecent_connect_if_interesting(&event->disc);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -164,12 +164,14 @@ ble_spp_client_connect_if_interesting(const struct ble_gap_disc_desc *disc)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||||
@ -221,7 +223,7 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* Try to connect to the advertiser if it looks interesting. */
|
||||||
@ -347,7 +349,7 @@ void ble_client_uart_task(void *pvParameters)
|
|||||||
//Waiting for UART event.
|
//Waiting for UART event.
|
||||||
if (xQueueReceive(spp_common_uart_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
if (xQueueReceive(spp_common_uart_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
//Event of UART receving data
|
//Event of UART receiving data
|
||||||
case UART_DATA:
|
case UART_DATA:
|
||||||
if (event.size) {
|
if (event.size) {
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** The UUID of the service containing the subscribable characterstic ***/
|
/*** The UUID of the service containing the subscribable characteristic ***/
|
||||||
static const ble_uuid_t * remote_svc_uuid =
|
static const ble_uuid_t * remote_svc_uuid =
|
||||||
BLE_UUID128_DECLARE(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
|
BLE_UUID128_DECLARE(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
|
||||||
0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
|
0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
|
||||||
@ -203,7 +203,7 @@ blecent_custom_gatt_operations(const struct peer* peer)
|
|||||||
remote_chr_uuid,
|
remote_chr_uuid,
|
||||||
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
|
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
|
||||||
if (dsc == NULL) {
|
if (dsc == NULL) {
|
||||||
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the subscribable characterstic\n");
|
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the subscribable characteristic\n");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,12 +601,14 @@ blecent_connect_if_interesting(void *disc)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||||
@ -682,7 +684,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* Try to connect to the advertiser if it looks interesting. */
|
||||||
@ -820,7 +822,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
|
|
||||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||||
case BLE_GAP_EVENT_EXT_DISC:
|
case BLE_GAP_EVENT_EXT_DISC:
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
ext_print_adv_report(&event->disc);
|
ext_print_adv_report(&event->disc);
|
||||||
|
|
||||||
blecent_connect_if_interesting(&event->disc);
|
blecent_connect_if_interesting(&event->disc);
|
||||||
|
@ -471,12 +471,14 @@ blecent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||||
/* Scanning must be stopped before a connection can be initiated. */
|
/* Scanning must be stopped before a connection can be initiated. */
|
||||||
rc = ble_gap_disc_cancel();
|
rc = ble_gap_disc_cancel();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Figure out address to use for connect (no privacy for now) */
|
/* Figure out address to use for connect (no privacy for now) */
|
||||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||||
@ -529,7 +531,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An advertisment report was received during GAP discovery. */
|
/* An advertisement report was received during GAP discovery. */
|
||||||
print_adv_fields(&fields);
|
print_adv_fields(&fields);
|
||||||
|
|
||||||
/* Try to connect to the advertiser if it looks interesting. */
|
/* Try to connect to the advertiser if it looks interesting. */
|
||||||
|
Reference in New Issue
Block a user