From 00b839ca66f2727045e0813bc5f0d85e7496f39c Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Sat, 20 Jan 2024 16:42:54 +0800 Subject: [PATCH 1/8] fix(ble/bluedroid): Fix BLE background connection log level --- components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c index 74158e930f..2265e28293 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c @@ -679,7 +679,7 @@ BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda #if (!CONFIG_BT_STACK_NO_LOG) char bdstr[18] = {0}; #endif - APPL_TRACE_ERROR("%s unable to find the bg connection mask for: %s", __func__, + APPL_TRACE_WARNING("%s unable to find the bg connection mask for: %s", __func__, bdaddr_to_string((bt_bdaddr_t *)remote_bda_ptr, bdstr, sizeof(bdstr))); } return FALSE; From b447216f8adcd9bfd9edf99837cab8183a90fc1e Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Sat, 20 Jan 2024 16:35:38 +0800 Subject: [PATCH 2/8] fix(ble/bluedroid): Fix dangling pointer issue in deletion of bonded devices --- components/bt/host/bluedroid/btc/core/btc_ble_storage.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/btc/core/btc_ble_storage.c b/components/bt/host/bluedroid/btc/core/btc_ble_storage.c index 4d01a0947f..314c567756 100644 --- a/components/bt/host/bluedroid/btc/core/btc_ble_storage.c +++ b/components/bt/host/bluedroid/btc/core/btc_ble_storage.c @@ -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 */ @@ -71,8 +71,10 @@ static void _btc_storage_save(void) BTA_DmRemoveDevice(bd_addr.address, BT_TRANSPORT_LE); BTA_DmRemoveDevice(bd_addr.address, BT_TRANSPORT_BR_EDR); //delete config info - if(btc_config_remove_section(need_remove_section)) { - BTIF_TRACE_WARNING("exceeded the maximum nubmer of bonded devices, delete the last device info : %s", need_remove_section); + if (btc_config_remove_section(need_remove_section)) { + // The need_remove_section has been freed + BTIF_TRACE_WARNING("Exceeded the maximum number of bonded devices. Deleting the last device info: %02x:%02x:%02x:%02x:%02x:%02x", + bd_addr.address[0], bd_addr.address[1], bd_addr.address[2], bd_addr.address[3], bd_addr.address[4], bd_addr.address[5]); } } } From a3759a122e85ad2ddaffc18c7f3ec1961a649d9c Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Tue, 9 Jan 2024 18:54:42 +0800 Subject: [PATCH 3/8] docs(ble/bluedroid): Optimize documentation for BLE duplicate scan --- components/bt/controller/esp32/Kconfig.in | 2 +- .../host/bluedroid/api/include/api/esp_gap_ble_api.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/bt/controller/esp32/Kconfig.in b/components/bt/controller/esp32/Kconfig.in index f31094116c..2d7cbf857d 100644 --- a/components/bt/controller/esp32/Kconfig.in +++ b/components/bt/controller/esp32/Kconfig.in @@ -356,7 +356,7 @@ config BTDM_SCAN_DUPL_CACHE_SIZE default 100 help Maximum number of devices which can be recorded in scan duplicate filter. - When the maximum amount of device in the filter is reached, the cache will be refreshed. + When the maximum amount of device in the filter is reached, the oldest device will be refreshed. config BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD int "Duplicate scan list refresh period (seconds)" diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index d17125acf2..245a3a24cc 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -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 */ @@ -419,7 +419,10 @@ typedef enum { typedef enum { BLE_SCAN_DUPLICATE_DISABLE = 0x0, /*!< the Link Layer should generate advertising reports to the host for each packet received */ BLE_SCAN_DUPLICATE_ENABLE = 0x1, /*!< the Link Layer should filter out duplicate advertising reports to the Host */ - BLE_SCAN_DUPLICATE_MAX = 0x2, /*!< 0x02 – 0xFF, Reserved for future use */ + #if (BLE_50_FEATURE_SUPPORT == TRUE) + BLE_SCAN_DUPLICATE_ENABLE_RESET, /*!< Duplicate filtering enabled, reset for each scan period, only supported in BLE 5.0. */ + #endif + BLE_SCAN_DUPLICATE_MAX /*!< Reserved for future use. */ } esp_ble_scan_duplicate_t; #if (BLE_42_FEATURE_SUPPORT == TRUE) /// Ble scan parameters @@ -2219,8 +2222,9 @@ esp_err_t esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t *param /** * @brief This function is used to enable scanning. * -* @param[in] duration : Scan duration -* @param[in] period : Time interval from when the Controller started its last Scan Duration until it begins the subsequent Scan Duration. +* @param[in] duration Scan duration time, where Time = N * 10 ms. Range: 0x0001 to 0xFFFF. +* @param[in] period Time interval from when the Controller started its last Scan Duration until it begins the subsequent Scan Duration. +* Time = N * 1.28 sec. Range: 0x0001 to 0xFFFF. * * @return - ESP_OK : success * - other : failed From b9caeb45592b557e4004b700ec14d0dba00dbce8 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Tue, 9 Jan 2024 16:45:49 +0800 Subject: [PATCH 4/8] feat(ble/bluedroid): Add getter for BLE GATTC calllback --- components/bt/host/bluedroid/api/esp_gattc_api.c | 7 ++++++- .../bt/host/bluedroid/api/include/api/esp_gattc_api.h | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/api/esp_gattc_api.c b/components/bt/host/bluedroid/api/esp_gattc_api.c index 44d932d512..5f078b2809 100644 --- a/components/bt/host/bluedroid/api/esp_gattc_api.c +++ b/components/bt/host/bluedroid/api/esp_gattc_api.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -29,6 +29,11 @@ esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback) return ESP_OK; } +esp_gattc_cb_t esp_ble_gattc_get_callback(void) +{ + return (esp_gattc_cb_t) btc_profile_cb_get(BTC_PID_GATTC); +} + esp_err_t esp_ble_gattc_app_register(uint16_t app_id) { btc_msg_t msg = {0}; diff --git a/components/bt/host/bluedroid/api/include/api/esp_gattc_api.h b/components/bt/host/bluedroid/api/include/api/esp_gattc_api.h index 9a95577a5e..13bf16a328 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gattc_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gattc_api.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -273,6 +273,15 @@ typedef void (* esp_gattc_cb_t)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_ */ esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback); +/** + * @brief This function is called to get the current application callbacks + * with BTA GATTC module. + * + * @return + * - esp_gattC_cb_t : current callback + * + */ +esp_gattc_cb_t esp_ble_gattc_get_callback(void); /** * @brief This function is called to register application callbacks From 46253edd6a2cde0a0c32dcf3c0de98f76b2e3747 Mon Sep 17 00:00:00 2001 From: Zeke Gustafson Date: Mon, 11 Sep 2023 16:23:12 -0500 Subject: [PATCH 5/8] feat(ble/bluedroid): Add getter for BLE GATTS callback --- components/bt/host/bluedroid/api/esp_gatts_api.c | 5 +++++ .../bt/host/bluedroid/api/include/api/esp_gatts_api.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/components/bt/host/bluedroid/api/esp_gatts_api.c b/components/bt/host/bluedroid/api/esp_gatts_api.c index 17b8cac7bd..66fa5c6617 100644 --- a/components/bt/host/bluedroid/api/esp_gatts_api.c +++ b/components/bt/host/bluedroid/api/esp_gatts_api.c @@ -29,6 +29,11 @@ esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback) return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL); } +esp_gatts_cb_t esp_ble_gatts_get_callback(void) +{ + return (esp_gatts_cb_t) btc_profile_cb_get(BTC_PID_GATTS); +} + esp_err_t esp_ble_gatts_app_register(uint16_t app_id) { btc_msg_t msg = {0}; diff --git a/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h b/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h index f6e0ca46a1..0eb7ddd98b 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h @@ -295,6 +295,16 @@ typedef void (* esp_gatts_cb_t)(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ */ esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback); +/** + * @brief This function is called to get the current application callbacks + * with BTA GATTS module. + * + * @return + * - esp_gatts_cb_t : current callback + * + */ +esp_gatts_cb_t esp_ble_gatts_get_callback(void); + /** * @brief This function is called to register application identifier * From 570cc22bdc148384d8bf2ebe698da532ff2ec9ee Mon Sep 17 00:00:00 2001 From: Zeke Gustafson Date: Fri, 15 Dec 2023 16:22:14 -0600 Subject: [PATCH 6/8] feat(ble/bluedroid): Add getter for BLE GAP callback --- components/bt/host/bluedroid/api/esp_gap_ble_api.c | 5 +++++ .../bt/host/bluedroid/api/include/api/esp_gap_ble_api.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index c9e6391543..9cc9394f9d 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -22,6 +22,11 @@ esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback) return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL); } +esp_gap_ble_cb_t esp_ble_gap_get_callback(void) +{ + return (esp_gap_ble_cb_t) btc_profile_cb_get(BTC_PID_GAP_BLE); +} + #if (BLE_42_FEATURE_SUPPORT == TRUE) esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data) { diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index 245a3a24cc..f72885a9fd 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -1423,6 +1423,15 @@ typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p */ esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback); +/** + * @brief This function is called to get the current gap callback + * + * @return + * - esp_gap_ble_cb_t : callback function + * + */ +esp_gap_ble_cb_t esp_ble_gap_get_callback(void); + #if (BLE_42_FEATURE_SUPPORT == TRUE) /** * @brief This function is called to override the BTA default ADV parameters. From e37dcaa92ffba4ee0af1e1858ae5ff4861b51dce Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Tue, 5 Dec 2023 20:30:22 +0800 Subject: [PATCH 7/8] fix(bt/bluedroid): Fix BLE malloc internal wrapper fail --- components/bt/controller/esp32c3/bt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index eb7fd1b10b..97ea53ca37 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -681,7 +681,7 @@ static bool IRAM_ATTR is_in_isr_wrapper(void) static void *malloc_internal_wrapper(size_t size) { - void *p = heap_caps_malloc(size, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA); + void *p = heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA); if(p == NULL) { ESP_LOGE(BT_LOG_TAG, "Malloc failed"); } From ca056b198fd6ea4ee7039235c705a8de758a56d7 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Fri, 12 Jan 2024 16:14:57 +0800 Subject: [PATCH 8/8] feat(bt/bluedroid): Support ext adv aux option --- components/bt/controller/esp32c3/Kconfig.in | 8 ++++++++ components/bt/controller/lib_esp32c3_family | 2 +- components/bt/include/esp32c3/include/esp_bt.h | 12 ++++++++++-- components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index e3784e5bed..8e9ddecf0d 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -467,3 +467,11 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX Disable active scan backoff. The bluetooth spec requires that scanners should run a backoff procedure to minimize collision of scan request PDUs from nultiple scanners. If scan backoff is disabled, in active scanning, scan request PDU will be sent every time when HW receives scannable ADV PDU. + +config BT_BLE_ADV_DATA_LENGTH_ZERO_AUX + bool "Enable aux packet when ext adv data length is zero" + default n + help + When this option is enabled, auxiliary packets will be present in the events of + 'Non-Connectable and Non-Scannable' regardless of whether the advertising length is 0. + If this option is not enabled, auxiliary packets will only be present when the advertising length is not 0. diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index 393ac4c33b..9d40b3bc0a 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit 393ac4c33b419226aac9d1e8f1b5d553b7f3bc97 +Subproject commit 9d40b3bc0ac38d72b66fe0f612a8dda64c7330d7 diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 7376ac8397..64760fc62c 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -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 */ @@ -19,7 +19,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02307120 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02401120 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -188,6 +188,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #define BT_BLE_CCA_MODE (0) #endif +#if defined(CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX) +#define BT_BLE_ADV_DATA_LENGTH_ZERO_AUX (CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX) +#else +#define BT_BLE_ADV_DATA_LENGTH_ZERO_AUX (0) +#endif + #define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1) | (BT_CTRL_AGC_RECORRECT_NEW << 2)) #define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0) @@ -234,6 +240,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \ .ble_50_feat_supp = BT_CTRL_50_FEATURE_SUPPORT, \ .ble_cca_mode = BT_BLE_CCA_MODE, \ + .ble_data_lenth_zero_aux = BT_BLE_ADV_DATA_LENGTH_ZERO_AUX, \ } #else @@ -305,6 +312,7 @@ typedef struct { uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */ bool ble_50_feat_supp; /*!< BLE 5.0 feature support */ uint8_t ble_cca_mode; /*!< BLE CCA mode */ + uint8_t ble_data_lenth_zero_aux; /*!< Config ext adv aux option*/ } esp_bt_controller_config_t; /** diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld index 323a03fc0a..0120bbcbbb 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld @@ -207,7 +207,6 @@ r_lld_adv_ext_chain_scannable_construct = 0x40001b58; r_lld_scan_process_pkt_rx = 0x40001280; r_llm_le_features_get = 0x400013b0; -r_lld_adv_ext_chain_none_construct = 0x40001b50; /* ble functions rename */ r_lld_init_start_hack = 0x400011a4; @@ -220,6 +219,7 @@ r_lld_res_list_rem = 0x40004680; r_lld_adv_start_hook = 0x40001c80; r_lld_con_evt_start_cbk_eco = 0x40001d1c; r_lld_con_tx_prog_new_packet = 0x40001b74; +r_lld_adv_ext_chain_none_construct = 0x40001b50; */