From 52a0a10ef4df22a410a8e5968b1ca418ffb3c206 Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Sun, 30 Jul 2023 19:52:53 +0800 Subject: [PATCH 01/11] fix(bt/bluedroid): Fix address check when using NRPA as random device address --- .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 15 +++++++++++++-- .../bluedroid/stack/btm/include/btm_ble_int.h | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 04268a0e83..60b4f36623 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -1049,17 +1049,28 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * #else uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb) { + tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + if((*own_bda_type == BLE_ADDR_RANDOM) || (*own_bda_type == BLE_ADDR_RANDOM_ID)) { - if((btm_cb.ble_ctr_cb.addr_mgnt_cb.exist_addr_bit & BTM_BLE_GAP_ADDR_BIT_RANDOM) != BTM_BLE_GAP_ADDR_BIT_RANDOM) { + if((p_cb->exist_addr_bit & BTM_BLE_GAP_ADDR_BIT_RANDOM) != BTM_BLE_GAP_ADDR_BIT_RANDOM) { BTM_TRACE_ERROR("No random address yet, please set random address and try\n"); if(cb) { (* cb)(HCI_ERR_ESP_VENDOR_FAIL); } return BTM_ILLEGAL_VALUE; } + + // If a device is using RPA, it shall also have an Identity Address + if ((*own_bda_type == BLE_ADDR_RANDOM_ID) && BTM_BLE_IS_NON_RESLVE_BDA(p_cb->static_rand_addr)) { + BTM_TRACE_ERROR("No identity address yet, please set static random address and try\n"); + if (cb) { + (* cb)(HCI_ERR_ESP_VENDOR_FAIL); + } + return BTM_ILLEGAL_VALUE; + } } - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type = *own_bda_type; + p_cb->own_addr_type = *own_bda_type; return BTM_SUCCESS; } diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h index fe297bec9e..2f864b04ec 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h @@ -84,8 +84,10 @@ typedef UINT8 tBTM_BLE_SEC_REQ_ACT; #define BLE_STATIC_PRIVATE_MSB_MASK 0x3f -#define BLE_RESOLVE_ADDR_MSB 0x40 /* most significant bit, bit7, bit6 is 01 to be resolvable random */ +#define BLE_NON_RESOLVE_ADDR_MSB 0x00 /* most significant bit, bit7, bit6 is 00 to be non-resolvable random */ +#define BLE_RESOLVE_ADDR_MSB 0x40 /* most significant bit, bit7, bit6 is 01 to be resolvable random */ #define BLE_RESOLVE_ADDR_MASK 0xc0 /* bit 6, and bit7 */ +#define BTM_BLE_IS_NON_RESLVE_BDA(x) ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_NON_RESOLVE_ADDR_MSB) #define BTM_BLE_IS_RESOLVE_BDA(x) ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB) /* LE scan activity bit mask, continue with LE inquiry bits */ From 35af1c03e2530488a83fbd0b37b1a264fc10cf8c Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Tue, 1 Aug 2023 11:56:39 +0800 Subject: [PATCH 02/11] feat(bt/bluedroid): Support high duty adv interval setting --- components/bt/host/bluedroid/Kconfig.in | 7 +++++++ .../common/include/common/bluedroid_user_config.h | 6 ++++++ .../bt/host/bluedroid/common/include/common/bt_target.h | 6 ++++++ .../bt/host/bluedroid/stack/include/stack/btm_ble_api.h | 8 ++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 9d28c585df..bc4051e4d7 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1150,3 +1150,10 @@ config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER default n help This enables BLE periodic advertising sync transfer feature + +config BT_BLE_HIGH_DUTY_ADV_INTERVAL + bool "Enable BLE high duty advertising interval feature" + depends on BT_BLUEDROID_ENABLED + default n + help + This enable BLE high duty advertising interval feature diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index 9920b91b61..bf655540a3 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -137,6 +137,12 @@ #define UC_BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE #endif +#ifdef CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL +#define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL +#else +#define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL FALSE +#endif + //GATTS #ifdef CONFIG_BT_GATTS_ENABLE #define UC_BT_GATTS_ENABLE CONFIG_BT_GATTS_ENABLE diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index 93fe980a5d..d1d44dc382 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -198,6 +198,12 @@ #define BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE #endif +#if (UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL == TRUE) +#define BLE_HIGH_DUTY_ADV_INTERVAL TRUE +#else +#define BLE_HIGH_DUTY_ADV_INTERVAL FALSE +#endif + #if (UC_BT_BLE_RPA_SUPPORTED == TRUE) #define CONTROLLER_RPA_LIST_ENABLE TRUE #else diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 1e93242cd8..6e509f0e99 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -105,8 +105,12 @@ typedef UINT8 tBTM_BLE_SFP; #endif /* adv parameter boundary values */ -#define BTM_BLE_ADV_INT_MIN 0x0020 -#define BTM_BLE_ADV_INT_MAX 0x4000 +#if BLE_HIGH_DUTY_ADV_INTERVAL +#define BTM_BLE_ADV_INT_MIN 0x0008 /* 5ms */ +#else +#define BTM_BLE_ADV_INT_MIN 0x0020 /* 20ms */ +#endif +#define BTM_BLE_ADV_INT_MAX 0x4000 /* 10240ms */ /* Full scan boundary values */ #define BTM_BLE_ADV_SCAN_FULL_MIN 0x00 From 9df464d7bbd3471d7ad0511ce6da1eef45d0f2d6 Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Tue, 15 Aug 2023 19:41:50 +0800 Subject: [PATCH 03/11] fix(bt/bluedroid): Fixed GATTC cache address save when list is full --- .../bt/host/bluedroid/bta/gatt/bta_gattc_co.c | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_co.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_co.c index 01b107cee9..3d5394fb1e 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_co.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_co.c @@ -139,7 +139,7 @@ static bool cacheOpen(BD_ADDR bda, bool to_save, UINT8 *index) return ((status == ESP_OK) ? true : false); } -static void cacheReset(BD_ADDR bda) +static void cacheReset(BD_ADDR bda, BOOLEAN update) { char fname[255] = {0}; getFilename(fname, bda); @@ -177,9 +177,16 @@ static void cacheReset(BD_ADDR bda) for(UINT8 i = index; i < (num - 1); i++) { memcpy(&cache_env->cache_addr[i], &cache_env->cache_addr[i+1], sizeof(cache_addr_info_t)); } + //clear the last cache when delete a addr + memset(&cache_env->cache_addr[num-1], 0, sizeof(cache_addr_info_t)); //reduced the number address counter also cache_env->num_addr--; + //don't need to update addr list to nvs flash + if (!update) { + return; + } + //update addr list to nvs flash if(cache_env->num_addr > 0) { //update @@ -376,7 +383,7 @@ void bta_gattc_co_cache_close(BD_ADDR server_bda, UINT16 conn_id) *******************************************************************************/ void bta_gattc_co_cache_reset(BD_ADDR server_bda) { - cacheReset(server_bda); + cacheReset(server_bda, TRUE); } void bta_gattc_co_cache_addr_init(void) @@ -520,26 +527,29 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key) UINT8 index = 0; UINT8 new_index = cache_env->num_addr; UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); - // check the address list has the same hash key or not - if (bta_gattc_co_find_hash_in_cache(hash_key) != INVALID_ADDR_NUM) { - APPL_TRACE_DEBUG("%s(), the hash key already in the cache list.", __func__); - if ((index = bta_gattc_co_find_addr_in_cache(bd_addr)) != INVALID_ADDR_NUM) { - APPL_TRACE_DEBUG("%s(), the hash bd_addr already in the cache list, index = %x", __func__, index); - //if the bd_addr already in the address list, update the hash key in it. - memcpy(cache_env->cache_addr[index].addr, bd_addr, sizeof(BD_ADDR)); - memcpy(cache_env->cache_addr[index].hash_key, hash_key, sizeof(hash_key_t)); - } else { - //if the bd_addr didn't in the address list, added the bd_addr to the last of the address list. - memcpy(cache_env->cache_addr[new_index].hash_key, hash_key, sizeof(hash_key_t)); - memcpy(cache_env->cache_addr[new_index].addr, bd_addr, sizeof(BD_ADDR)); - cache_env->num_addr++; - } + if (p_buf == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return; + } + // check the address list has the same address or not + // for the same address, it's hash key may be change due to service change + if ((index = bta_gattc_co_find_addr_in_cache(bd_addr)) != INVALID_ADDR_NUM) { + APPL_TRACE_DEBUG("%s the bd_addr already in the cache list, index = %x", __func__, index); + //if the bd_addr already in the address list, update the hash key in it. + memcpy(cache_env->cache_addr[index].addr, bd_addr, sizeof(BD_ADDR)); + memcpy(cache_env->cache_addr[index].hash_key, hash_key, sizeof(hash_key_t)); } else { - APPL_TRACE_DEBUG("%s(), num = %d", __func__, new_index + 1); + if (cache_env->num_addr >= MAX_DEVICE_IN_CACHE) { + APPL_TRACE_WARNING("%s cache list full and remove the oldest addr info", __func__); + cacheReset(cache_env->cache_addr[0].addr, FALSE); + } + new_index = cache_env->num_addr; + assert(new_index < MAX_DEVICE_IN_CACHE); memcpy(cache_env->cache_addr[new_index].addr, bd_addr, sizeof(BD_ADDR)); memcpy(cache_env->cache_addr[new_index].hash_key, hash_key, sizeof(hash_key_t)); cache_env->num_addr++; + APPL_TRACE_DEBUG("%s(), num = %d", __func__, cache_env->num_addr); } nvs_handle_t *fp = &cache_env->addr_fp; @@ -567,10 +577,10 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key) APPL_TRACE_ERROR("%s, Line = %d, nvs flash open fail, err_code = %x", __func__, __LINE__, err_code); } } + //free the buffer after used. osi_free(p_buf); return; - } BOOLEAN bta_gattc_co_cache_new_assoc_list(BD_ADDR src_addr, UINT8 index) From 985f6a4892358a07d303e93f6870591255685b3b Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Wed, 12 Apr 2023 11:13:15 +0800 Subject: [PATCH 04/11] fix(bt/bluedroid): Fixed BLE disconnect event report when disconnecting --- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 2 +- .../bluedroid/stack/include/stack/l2c_api.h | 13 ++++++++ .../bt/host/bluedroid/stack/l2cap/l2c_api.c | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 21bb638aff..f185b1ce8f 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5099,7 +5099,7 @@ void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_disconnect (tBTA_DM_MSG *p_data) { - L2CA_RemoveFixedChnl(L2CAP_ATT_CID, p_data->ble_disconnect.remote_bda); + L2CA_BleDisconnect(p_data->ble_disconnect.remote_bda); } /******************************************************************************* diff --git a/components/bt/host/bluedroid/stack/include/stack/l2c_api.h b/components/bt/host/bluedroid/stack/include/stack/l2c_api.h index 03d185e7bc..b985b641e8 100644 --- a/components/bt/host/bluedroid/stack/include/stack/l2c_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/l2c_api.h @@ -1215,6 +1215,19 @@ extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable); ** *******************************************************************************/ extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function L2CA_BleDisconnect +** +** Description This function use to disconnect LE connection. +** +** Parameters BD Address of remote +** +** Returns TRUE if disconnect successfully. +** +*******************************************************************************/ +extern BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda); #endif /* (BLE_INCLUDED == TRUE) */ /******************************************************************************* diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_api.c b/components/bt/host/bluedroid/stack/l2cap/l2c_api.c index 7c282db09e..f88d58956b 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_api.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_api.c @@ -1949,6 +1949,36 @@ BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda) return (TRUE); } +#if BLE_INCLUDED == TRUE +BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda) +{ + tL2C_LCB *p_lcb; + tGATT_TCB *p_tcb; + + p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); + if (p_lcb == NULL) { + return FALSE; + } + + if (p_lcb->link_state != LST_CONNECTED) { + return FALSE; + } + + p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST; + p_lcb->link_state = LST_DISCONNECTING; + btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER); + + p_tcb = gatt_find_tcb_by_addr(rem_bda, BT_TRANSPORT_LE); + if (p_tcb == NULL) { + return FALSE; + } + + gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); + + return TRUE; +} +#endif + /******************************************************************************* ** ** Function L2CA_SetFixedChannelTout From cc9c5b78b9641eb888f6e1bf902d84beb990624c Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Fri, 25 Aug 2023 20:22:03 +0800 Subject: [PATCH 05/11] feat(bt/bluedroid): Support periodic adv adi feature --- components/bt/host/bluedroid/Kconfig.in | 7 ++++ .../bt/host/bluedroid/api/esp_gap_ble_api.c | 21 +++++++++++- .../api/include/api/esp_gap_ble_api.h | 34 ++++++++++++++++++- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 3 +- .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 5 +-- .../bluedroid/bta/dm/include/bta_dm_int.h | 3 +- .../host/bluedroid/bta/include/bta/bta_api.h | 4 +-- .../btc/profile/std/gap/btc_gap_ble.c | 7 ++-- .../btc/profile/std/include/btc_gap_ble.h | 4 ++- .../include/common/bluedroid_user_config.h | 6 ++++ .../common/include/common/bt_target.h | 6 ++++ .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 15 ++++++-- .../stack/include/stack/btm_ble_api.h | 4 +-- .../peroidic_adv/main/periodic_adv_demo.c | 17 +++++++++- .../Periodic_adv_Example_Walkthrough.md | 21 +++++++++--- 15 files changed, 135 insertions(+), 22 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index bc4051e4d7..8e2ca0b08f 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1151,6 +1151,13 @@ config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER help This enables BLE periodic advertising sync transfer feature +config BT_BLE_FEAT_PERIODIC_ADV_ENH + bool "Enable periodic adv enhancements(adi support)" + depends on (BT_BLUEDROID_ENABLED && BT_BLE_50_FEATURES_SUPPORTED && SOC_ESP_NIMBLE_CONTROLLER) + default n + help + Enable the periodic advertising enhancements + config BT_BLE_HIGH_DUTY_ADV_INTERVAL bool "Enable BLE high duty advertising interval feature" depends on BT_BLUEDROID_ENABLED 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 d2a9685ad4..96658e8cb1 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1052,8 +1052,13 @@ esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_ga } +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) +esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length, + const uint8_t *data, bool only_update_did) +#else esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length, const uint8_t *data) +#endif { btc_msg_t msg; btc_ble_5_gap_args_t arg; @@ -1067,13 +1072,22 @@ esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t le arg.periodic_adv_cfg_data.instance = instance; arg.periodic_adv_cfg_data.len = length; arg.periodic_adv_cfg_data.data = (uint8_t *)data; +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) + arg.periodic_adv_cfg_data.only_update_did = only_update_did; +#else + arg.periodic_adv_cfg_data.only_update_did = false; +#endif return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy, btc_gap_ble_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) +esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance,bool include_adi) +#else esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance) +#endif { btc_msg_t msg; btc_ble_5_gap_args_t arg; @@ -1084,6 +1098,11 @@ esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance) msg.pid = BTC_PID_GAP_BLE; msg.act = BTC_GAP_BLE_PERIODIC_ADV_START; + #if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) + arg.periodic_adv_start.include_adi = include_adi; + #else + arg.periodic_adv_start.include_adi = false; + #endif arg.periodic_adv_start.instance = instance; return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) 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 ad5ffce586..b5e97f1dca 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-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -2107,6 +2107,22 @@ esp_err_t esp_ble_gap_ext_adv_set_clear(void); */ esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_gap_periodic_adv_params_t *params); +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) +/** +* @brief This function is used to set the data used in periodic advertising PDUs. +* +* @param[in] instance : identifies the advertising set whose periodic advertising parameters are being configured. +* @param[in] length : the length of periodic data +* @param[in] data : periodic data information +* @param[in] only_update_did : If true, only the Advertising DID of the periodic advertising will be updated, and the length and data parameters will be ignored. +* +* @return - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length, + const uint8_t *data, bool only_update_did); +#else /** * @brief This function is used to set the data used in periodic advertising PDUs. * @@ -2120,6 +2136,21 @@ esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_ga */ esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length, const uint8_t *data); +#endif + +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) +/** +* @brief This function is used to request the Controller to enable the periodic advertising for the advertising set specified +* +* @param[in] instance : Used to identify an advertising set +* @param[in] include_adi : If true, the ADI (Advertising Data Info) field will be included in AUX_SYNC_IND PDUs +* +* @return - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance,bool include_adi); +#else /** * @brief This function is used to request the Controller to enable the periodic advertising for the advertising set specified * @@ -2130,6 +2161,7 @@ esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t le * */ esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance); +#endif /** * @brief This function is used to request the Controller to disable the periodic advertising for the advertising set specified diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index f185b1ce8f..9d0f8a6d60 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5721,7 +5721,8 @@ void bta_dm_ble_gap_periodic_adv_cfg_data_raw(tBTA_DM_MSG *p_data) BTM_BlePeriodicAdvCfgDataRaw(p_data->ble_cfg_periodic_adv_data.instance, p_data->ble_cfg_periodic_adv_data.length, - p_data->ble_cfg_periodic_adv_data.data); + p_data->ble_cfg_periodic_adv_data.data, + p_data->ble_cfg_periodic_adv_data.only_update_did); } void bta_dm_ble_gap_periodic_adv_enable(tBTA_DM_MSG *p_data) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index ea5d4f6593..a393ce2168 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -2933,7 +2933,7 @@ void BTA_DmBleGapPeriodicAdvSetParams(UINT8 instance, } void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length, - const UINT8 *data) + const UINT8 *data,bool only_update_did) { tBTA_DM_API_CFG_PERIODIC_ADV_DATA *p_msg; APPL_TRACE_API("%s, Periodic ADV config data raw.", __func__); @@ -2945,6 +2945,7 @@ void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length, p_msg->data = (UINT8 *)(p_msg + 1); memcpy(p_msg->data, data, length); p_msg->data = length != 0 ? (UINT8 *)(p_msg + 1) : NULL; + p_msg->only_update_did = only_update_did; //start sent the msg to the bta system control moudle bta_sys_sendmsg(p_msg); } else { @@ -2953,7 +2954,7 @@ void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length, } -void BTA_DmBleGapPeriodicAdvEnable(BOOLEAN enable, UINT8 instance) +void BTA_DmBleGapPeriodicAdvEnable(UINT8 enable, UINT8 instance) { tBTA_DM_API_ENABLE_PERIODIC_ADV *p_msg; APPL_TRACE_API("%s, Periodic ADV %s.", __func__, enable ? "start" : "stop"); diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index 862d5cff25..dcb9453693 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -969,12 +969,13 @@ typedef struct { UINT8 instance; UINT16 length; UINT8 *data; + BOOLEAN only_update_did; } tBTA_DM_API_CFG_PERIODIC_ADV_DATA; typedef struct { BT_HDR hdr; UINT8 instance; - BOOLEAN enable; + UINT8 enable; } tBTA_DM_API_ENABLE_PERIODIC_ADV; typedef struct { diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index f49708073d..694b50916d 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -2998,9 +2998,9 @@ extern void BTA_DmBleGapPeriodicAdvSetParams(UINT8 instance, tBTA_DM_BLE_Periodic_Adv_Params *params); extern void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length, - const UINT8 *data); + const UINT8 *data,BOOLEAN only_update_did); -extern void BTA_DmBleGapPeriodicAdvEnable(BOOLEAN enable, UINT8 instance); +extern void BTA_DmBleGapPeriodicAdvEnable(UINT8 enable, UINT8 instance); extern void BTA_DmBleGapPeriodicAdvCreateSync(tBTA_DM_BLE_Periodic_Sync_Params *params); diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 376a8a6fe2..7c33072b01 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1908,11 +1908,12 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) BTC_TRACE_DEBUG("BTC_GAP_BLE_CFG_PERIODIC_ADV_DATA_RAW"); BTA_DmBleGapPeriodicAdvCfgDataRaw(arg_5->periodic_adv_cfg_data.instance, arg_5->periodic_adv_cfg_data.len, - (const UINT8 *)arg_5->periodic_adv_cfg_data.data); + (const UINT8 *)arg_5->periodic_adv_cfg_data.data, + arg_5->periodic_adv_cfg_data.only_update_did); break; case BTC_GAP_BLE_PERIODIC_ADV_START: BTC_TRACE_DEBUG("BTC_GAP_BLE_PERIODIC_ADV_START"); - BTA_DmBleGapPeriodicAdvEnable(TRUE, arg_5->periodic_adv_start.instance); + BTA_DmBleGapPeriodicAdvEnable(((arg_5->periodic_adv_start.include_adi)<<1)|0x01, arg_5->periodic_adv_start.instance); break; case BTC_GAP_BLE_PERIODIC_ADV_STOP: BTC_TRACE_DEBUG("BTC_GAP_BLE_PERIODIC_ADV_STOP"); diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index 357e6729cb..f01e85e57d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -296,9 +296,11 @@ typedef union { uint8_t instance; uint16_t len; uint8_t *data; + bool only_update_did; } periodic_adv_cfg_data; struct periodic_adv_start_args { + bool include_adi; uint8_t instance; } periodic_adv_start; diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index bf655540a3..f00308d441 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -137,6 +137,12 @@ #define UC_BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE #endif +#ifdef CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH +#define UC_BT_BLE_FEAT_PERIODIC_ADV_ENH CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH +#else +#define UC_BT_BLE_FEAT_PERIODIC_ADV_ENH FALSE +#endif + #ifdef CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #else diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index d1d44dc382..69a909ce64 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -198,6 +198,12 @@ #define BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE #endif +#if (UC_BT_BLE_FEAT_PERIODIC_ADV_ENH == TRUE) +#define BLE_FEAT_PERIODIC_ADV_ENH TRUE +#else +#define BLE_FEAT_PERIODIC_ADV_ENH FALSE +#endif + #if (UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL == TRUE) #define BLE_HIGH_DUTY_ADV_INTERVAL TRUE #else diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index 331657af2d..30016993f4 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -693,7 +693,7 @@ end: return status; } -tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data) +tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data,BOOLEAN only_update_did) { tBTM_STATUS status = BTM_SUCCESS; tHCI_STATUS err = HCI_SUCCESS; @@ -701,6 +701,13 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data UINT8 operation = 0; UINT16 data_offset = 0; tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + if (only_update_did) + { + len = 0; + data = NULL; + rem_len = 0; + operation = BTM_BLE_ADV_DATA_OP_UNCHANGED_DATA; + } if ((status = btm_ble_ext_adv_set_data_validate(instance, len, data)) != BTM_SUCCESS) { BTM_TRACE_ERROR("%s, invalid extend adv data.", __func__); @@ -711,7 +718,9 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data UINT8 send_data_len = (rem_len > BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX) ? BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX : rem_len; if (len <= BTM_BLE_EXT_ADV_DATA_LEN_MAX) { - operation = BTM_BLE_ADV_DATA_OP_COMPLETE; + if (!only_update_did) { + operation = BTM_BLE_ADV_DATA_OP_COMPLETE; + } } else { if (rem_len == len) { operation = BTM_BLE_ADV_DATA_OP_FIRST_FRAG; @@ -737,7 +746,7 @@ end: return status; } -tBTM_STATUS BTM_BlePeriodicAdvEnable(UINT8 instance, BOOLEAN enable) +tBTM_STATUS BTM_BlePeriodicAdvEnable(UINT8 instance, UINT8 enable) { tBTM_STATUS status = BTM_SUCCESS; tHCI_STATUS err = HCI_SUCCESS; diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 6e509f0e99..07fc0ee965 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -2667,9 +2667,9 @@ tBTM_STATUS BTM_BleExtAdvSetClear(void); tBTM_STATUS BTM_BlePeriodicAdvSetParams(UINT8 instance, tBTM_BLE_Periodic_Adv_Params *params); -tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data); +tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data, BOOLEAN only_update_did); -tBTM_STATUS BTM_BlePeriodicAdvEnable(UINT8 instance, BOOLEAN enable); +tBTM_STATUS BTM_BlePeriodicAdvEnable(UINT8 instance, UINT8 enable); tBTM_STATUS BTM_BlePeriodicAdvCreateSync(tBTM_BLE_Periodic_Sync_Params *params); diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c index 60f497e719..d0b79d17a6 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -191,9 +191,24 @@ void app_main(void) // start all adv FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_start(NUM_EXT_ADV, &ext_adv[0]), test_sem); + // set periodic adv param FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_set_params(EXT_ADV_HANDLE, &periodic_adv_params), test_sem); + +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) + // set periodic adv raw data + FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, sizeof(periodic_adv_raw_data), &periodic_adv_raw_data[0], false), test_sem); + // start periodic adv, include the ADI field in AUX_SYNC_IND PDUs + FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_start(EXT_ADV_HANDLE, true), test_sem); + while (1) { + vTaskDelay(2000 / portTICK_PERIOD_MS); + // just update the Advertising DID of the periodic advertising, unchanged data + FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, 0, NULL, true), test_sem); + } +#else + // set periodic adv raw data FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, sizeof(periodic_adv_raw_data), &periodic_adv_raw_data[0]), test_sem); FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_start(EXT_ADV_HANDLE), test_sem); +#endif return; } diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md index ad843f80d1..4b5ea8a562 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md @@ -94,12 +94,25 @@ a_2m), &raw_ext_adv_data_2m[0]), test_sem); // start all adv FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_start(NUM_EXT_ADV, &ext_adv[0]), test_sem); + + // set periodic adv param + FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_set_params(EXT_ADV_HANDLE, &periodic_adv_params), test_sem); - FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_set_params(EXT_ADV_HANDLE, &periodic_adv_params), - test_sem); - FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, sizeof(periodic_a -dv_raw_data), &periodic_adv_raw_data[0]), test_sem); +#if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH) + // set periodic adv raw data + FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, sizeof(periodic_adv_raw_data), &periodic_adv_raw_data[0], false), test_sem); + // start periodic adv, include the ADI field in AUX_SYNC_IND PDUs + FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_start(EXT_ADV_HANDLE, true), test_sem); + while (1) { + vTaskDelay(2000 / portTICK_PERIOD_MS); + // just update the Advertising DID of the periodic advertising, unchanged data + FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, 0, NULL, true), test_sem); + } +#else + // set periodic adv raw data + FUNC_SEND_WAIT_SEM(esp_ble_gap_config_periodic_adv_data_raw(EXT_ADV_HANDLE, sizeof(periodic_adv_raw_data), &periodic_adv_raw_data[0]), test_sem); FUNC_SEND_WAIT_SEM(esp_ble_gap_periodic_adv_start(EXT_ADV_HANDLE), test_sem); +#endif return; } From 98f59569b0133efbe958c4325a659516df74edef Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Mon, 21 Aug 2023 17:11:32 +0800 Subject: [PATCH 06/11] docs(bt): Update comment in ble --- .../bluedroid/api/include/api/esp_bt_defs.h | 8 ++++---- .../api/include/api/esp_gap_ble_api.h | 19 ++++++++++++++----- .../bluedroid/api/include/api/esp_gattc_api.h | 1 + .../bluedroid/api/include/api/esp_gatts_api.h | 1 + .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 2 +- .../bluedroid/stack/btm/btm_ble_privacy.c | 1 - .../ble/gatt_server/main/gatts_demo.c | 9 +++++---- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h index d157884edc..7bfad55c35 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h @@ -166,10 +166,10 @@ typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; /// BLE device address type typedef enum { - BLE_ADDR_TYPE_PUBLIC = 0x00, - BLE_ADDR_TYPE_RANDOM = 0x01, - BLE_ADDR_TYPE_RPA_PUBLIC = 0x02, - BLE_ADDR_TYPE_RPA_RANDOM = 0x03, + BLE_ADDR_TYPE_PUBLIC = 0x00, /*!< Public Device Address */ + BLE_ADDR_TYPE_RANDOM = 0x01, /*!< Random Device Address. To set this address, use the function esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr) */ + BLE_ADDR_TYPE_RPA_PUBLIC = 0x02, /*!< Resolvable Private Address (RPA) with public identity address */ + BLE_ADDR_TYPE_RPA_RANDOM = 0x03, /*!< Resolvable Private Address (RPA) with random identity address. To set this address, use the function esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr) */ } esp_ble_addr_type_t; /// white list address type 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 b5e97f1dca..d09613c99e 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 @@ -133,7 +133,7 @@ typedef enum { ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */ ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */ ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ - ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ + ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw scan response data set complete, the event comes */ ESP_GAP_BLE_ADV_START_COMPLETE_EVT, /*!< When start advertising complete, the event comes */ ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, /*!< When start scan complete, the event comes */ //BLE_INCLUDED @@ -1501,9 +1501,17 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params); esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length); /** - * @brief This function sets the static Random Address and Non-Resolvable Private Address for the application + * @brief This function allows configuring either a Non-Resolvable Private Address or a Static Random Address * - * @param[in] rand_addr: the random address which should be setting + * @param[in] rand_addr: The address to be configured. Refer to the table below for possible address subtypes: + * + * | address [47:46] | Address Type | + * |-----------------|--------------------------| + * | 0b00 | Non-Resolvable Private | + * | | Address | + * |-----------------|--------------------------| + * | 0b11 | Static Random Address | + * |-----------------|--------------------------| * * @return * - ESP_OK : success @@ -1525,7 +1533,7 @@ esp_err_t esp_ble_gap_clear_rand_addr(void); /** - * @brief Enable/disable privacy on the local device + * @brief Enable/disable privacy (including address resolution) on the local device * * @param[in] privacy_enable - enable/disable privacy on remote device. * @@ -1606,6 +1614,7 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE) /** * @brief Set device name to the local device + * Note: This API don't affect the advertising data * * @param[in] name - device name. * @@ -1654,7 +1663,7 @@ uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *leng * @brief This function is called to set raw advertising data. User need to fill * ADV data by self. * - * @param[in] raw_data : raw advertising data + * @param[in] raw_data : raw advertising data with the format: [Length 1][Data Type 1][Data 1][Length 2][Data Type 2][Data 2] ... * @param[in] raw_data_len : raw advertising data length , less than 31 bytes * * @return 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 0cd4f312aa..9a95577a5e 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 @@ -359,6 +359,7 @@ esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id); * @brief This function is called to get service from local cache. * This function report service search result by a callback * event, and followed by a service search complete event. + * Note: 128-bit base UUID will automatically be converted to a 16-bit UUID in the search results. Other types of UUID remain unchanged. * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id: connection ID. 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 67195369ac..f6e0ca46a1 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 @@ -464,6 +464,7 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle); /** * @brief Send indicate or notify to GATT client. * Set param need_confirm as false will send notification, otherwise indication. + * Note: the size of indicate or notify data need less than MTU size,see "esp_ble_gattc_send_mtu_req". * * @param[in] gatts_if: GATT server access interface * @param[in] conn_id - connection id to indicate. diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 60b4f36623..2ce4488e38 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -1000,7 +1000,7 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * memcpy(btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.resolvale_addr, BD_ADDR_LEN); btsnd_hcic_ble_set_random_addr(btm_cb.ble_ctr_cb.addr_mgnt_cb.resolvale_addr); }else { - BTM_TRACE_ERROR ("No random address yet, please set random address and try\n"); + BTM_TRACE_ERROR ("No random address yet, please set random address using API \"esp_ble_gap_set_rand_addr\" and retry\n"); if(cb) { (* cb)(HCI_ERR_ESP_VENDOR_FAIL); } diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c index 617e598171..6f15dd2d3f 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c @@ -402,7 +402,6 @@ void btm_ble_set_addr_resolution_enable_complete(UINT8 *p, UINT16 evt_len) tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; if (!(random_cb && random_cb->set_local_privacy_cback)) { - BTM_TRACE_ERROR("no set local privacy callback found"); return; } diff --git a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c index 2b422b3858..19d7eb56b7 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -74,10 +74,11 @@ static uint8_t adv_config_done = 0; #ifdef CONFIG_SET_RAW_ADV_DATA static uint8_t raw_adv_data[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd + 0x02, 0x01, 0x06, // Length 2, Data Type 1 (Flags), Data 1 (LE General Discoverable Mode, BR/EDR Not Supported) + 0x02, 0x0a, 0xeb, // Length 2, Data Type 10 (TX power leve), Data 2 (-21) + 0x03, 0x03, 0xab, 0xcd, // Length 3, Data Type 3 (Complete 16-bit Service UUIDs), Data 3 (UUID) }; -static uint8_t raw_scan_rsp_data[] = { +static uint8_t raw_scan_rsp_data[] = { // Length 15, Data Type 9 (Complete Local Name), Data 1 (ESP_GATTS_DEMO) 0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44, 0x45, 0x4d, 0x4f }; From e3c5c4fb7bb326e96403ab0584ac5d5ebcd9a5e5 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Tue, 22 Aug 2023 19:38:01 +0800 Subject: [PATCH 07/11] fix(bt): Fix bug while calculating block cipher using aes-128 --- components/bt/host/bluedroid/stack/smp/smp_cmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/stack/smp/smp_cmac.c b/components/bt/host/bluedroid/stack/smp/smp_cmac.c index 391f538353..e47c56b71f 100644 --- a/components/bt/host/bluedroid/stack/smp/smp_cmac.c +++ b/components/bt/host/bluedroid/stack/smp/smp_cmac.c @@ -133,7 +133,7 @@ static void cmac_aes_cleanup(void) static BOOLEAN cmac_aes_k_calculate(BT_OCTET16 key, UINT8 *p_signature, UINT16 tlen) { tSMP_ENC output; - UINT8 i = 1, err = 0; + UINT16 i = 1, err = 0; UINT8 x[16] = {0}; UINT8 *p_mac; From 0f6a7ac7b148c336762496305342f0fbadbc9f6d Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Mon, 21 Aug 2023 20:14:58 +0800 Subject: [PATCH 08/11] fix(bt): Fix bugs about updating connect param --- components/bt/host/bluedroid/api/esp_gap_ble_api.c | 10 +++++----- .../bt/host/bluedroid/api/include/api/esp_bt_defs.h | 4 +--- .../bluedroid/btc/profile/std/include/btc_gap_ble.h | 2 +- components/bt/host/bluedroid/stack/l2cap/l2c_ble.c | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) 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 96658e8cb1..68dba6bdf9 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -138,7 +138,7 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params) if (ESP_BLE_IS_VALID_PARAM(params->min_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(params->max_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(params->timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && - (params->latency <= ESP_BLE_CONN_LATENCY_MAX || params->latency == ESP_BLE_CONN_PARAM_UNDEF) && + (params->latency <= ESP_BLE_CONN_LATENCY_MAX) && ((params->timeout * 10) >= ((1 + params->latency) * ((params->max_int * 5) >> 1))) && params->min_int <= params->max_int) { msg.sig = BTC_SIG_API_CALL; @@ -354,7 +354,7 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, if (ESP_BLE_IS_VALID_PARAM(min_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(max_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(supervision_tout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && - (slave_latency <= ESP_BLE_CONN_LATENCY_MAX || slave_latency == ESP_BLE_CONN_PARAM_UNDEF) && + (slave_latency <= ESP_BLE_CONN_LATENCY_MAX) && ((supervision_tout * 10) >= ((1 + slave_latency) * ((max_conn_int * 5) >> 1))) && min_conn_int <= max_conn_int) { msg.sig = BTC_SIG_API_CALL; @@ -1317,7 +1317,7 @@ esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr, if (ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && - (phy_1m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_1m_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) && + (phy_1m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) && ((phy_1m_conn_params->supervision_timeout * 10) >= ((1 + phy_1m_conn_params->latency) * ((phy_1m_conn_params->interval_max * 5) >> 1))) && (phy_1m_conn_params->interval_min <= phy_1m_conn_params->interval_max)) { @@ -1341,7 +1341,7 @@ esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr, if (ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && - (phy_2m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_2m_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) && + (phy_2m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) && ((phy_2m_conn_params->supervision_timeout * 10) >= ((1 + phy_2m_conn_params->latency) * ((phy_2m_conn_params->interval_max * 5) >> 1))) && (phy_2m_conn_params->interval_min <= phy_2m_conn_params->interval_max)) { @@ -1365,7 +1365,7 @@ esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr, if (ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && - (phy_coded_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_coded_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) && + (phy_coded_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) && ((phy_coded_conn_params->supervision_timeout * 10) >= ((1 + phy_coded_conn_params->latency) * ((phy_coded_conn_params->interval_max * 5) >> 1))) && (phy_coded_conn_params->interval_min <= phy_coded_conn_params->interval_max)) { diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h index 7bfad55c35..7e0df27bd7 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h @@ -132,11 +132,9 @@ typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */ #define ESP_BLE_CONN_LATENCY_MAX 499 /*!< relate to ESP_BLE_CONN_LATENCY_MAX in stack/btm_ble_api.h */ #define ESP_BLE_CONN_SUP_TOUT_MIN 0x000A /*!< relate to BTM_BLE_CONN_SUP_TOUT_MIN in stack/btm_ble_api.h */ #define ESP_BLE_CONN_SUP_TOUT_MAX 0x0C80 /*!< relate to ESP_BLE_CONN_SUP_TOUT_MAX in stack/btm_ble_api.h */ -#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ /* relate to ESP_BLE_CONN_PARAM_UNDEF in stack/btm_ble_api.h */ -#define ESP_BLE_SCAN_PARAM_UNDEF 0xffffffff /* relate to ESP_BLE_SCAN_PARAM_UNDEF in stack/btm_ble_api.h */ /// Check the param is valid or not -#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) +#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) ) /// UUID type typedef struct { diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index f01e85e57d..38594b7783 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -18,7 +18,7 @@ extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr; #define gl_bta_scan_rsp_data (*gl_bta_scan_rsp_data_ptr) #endif -#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) +#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max))) typedef enum { #if (BLE_42_FEATURE_SUPPORT == TRUE) diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c index 8d9f510f55..ecfb4bc795 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c @@ -1429,7 +1429,7 @@ UINT32 CalConnectParamTimeout(tL2C_LCB *p_lcb) UINT32 timeout = 6; if (p_lcb != NULL){ //1.25 * conn_int *(1+ latency) *32 - timeout = (40 * ( 1 + p_lcb->current_used_conn_latency) * p_lcb->current_used_conn_interval + 1000) / 1000; + timeout = (40 * ( 1 + p_lcb->current_used_conn_latency) * p_lcb->current_used_conn_interval + 1.25 * p_lcb->waiting_update_conn_max_interval + 1000) / 1000; if (timeout < 1){ timeout = 1; }else if (timeout > 120){ From 5b7fcd80d211af7c6eeb9c69e2dfd6c8e2bb190b Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Fri, 7 Jul 2023 19:50:24 +0800 Subject: [PATCH 09/11] Update bt lib for ESP32-C3 and ESP32-S3(ff6efe7) - fix(bt/controller): Fixed PHY enable and disable - feat(bt/controller): Support DAA and LBT mode for BLE CCA --- components/bt/controller/esp32c3/Kconfig.in | 24 ++++++++--- components/bt/controller/esp32c3/bt.c | 43 ++++++++++++++----- components/bt/controller/lib_esp32c3_family | 2 +- .../bt/include/esp32c3/include/esp_bt.h | 10 ++++- 4 files changed, 61 insertions(+), 18 deletions(-) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index 98274a2236..aa0446dcc3 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -78,15 +78,29 @@ config BT_CTRL_ADV_DUP_FILT_MAX help The maxinum number of suplicate scan filter -config BT_CTRL_HW_CCA - bool "HW CCA check enable" - default n +choice BT_BLE_CCA_MODE + prompt "BLE CCA mode" + default BT_BLE_CCA_MODE_NONE help - It enables HW CCA feature in controller + Define BT BLE CCA mode + + config BT_BLE_CCA_MODE_NONE + bool "NONE" + config BT_BLE_CCA_MODE_HW + bool "Hardware" + config BT_BLE_CCA_MODE_SW + bool "Software" +endchoice + +config BT_BLE_CCA_MODE + int + default 0 if BT_BLE_CCA_MODE_NONE + default 1 if BT_BLE_CCA_MODE_HW + default 2 if BT_BLE_CCA_MODE_SW config BT_CTRL_HW_CCA_VAL int "CCA threshold value" - range 20 60 + range 20 100 default 20 help It is the threshold value of HW CCA, if the value is 30, it means CCA threshold is -30 dBm. diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index db9c2fbf1c..d9c9618da4 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -112,7 +112,7 @@ do{\ } while(0) #define OSI_FUNCS_TIME_BLOCKING 0xffffffff -#define OSI_VERSION 0x00010006 +#define OSI_VERSION 0x00010007 #define OSI_MAGIC_VALUE 0xFADEBEAD /* Types definition @@ -193,6 +193,8 @@ struct osi_funcs_t { void (* _esp_hw_power_down)(void); void (* _esp_hw_power_up)(void); void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem); + void (* _ets_delay_us)(uint32_t us); + void (* _btdm_rom_table_ready)(void); }; @@ -251,6 +253,8 @@ extern void esp_mac_bb_power_up(void); extern void ets_backup_dma_copy(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); #endif +extern void btdm_cca_feature_enable(void); + extern uint32_t _bt_bss_start; extern uint32_t _bt_bss_end; extern uint32_t _btdm_bss_start; @@ -310,6 +314,7 @@ static void interrupt_off_wrapper(int intr_num); static void btdm_hw_mac_power_up_wrapper(void); static void btdm_hw_mac_power_down_wrapper(void); static void btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); +static void btdm_funcs_table_ready_wrapper(void); static void btdm_slp_tmr_callback(void *arg); @@ -374,6 +379,8 @@ static const struct osi_funcs_t osi_funcs_ro = { ._esp_hw_power_down = btdm_hw_mac_power_down_wrapper, ._esp_hw_power_up = btdm_hw_mac_power_up_wrapper, ._ets_backup_dma_copy = btdm_backup_dma_copy_wrapper, + ._ets_delay_us = esp_rom_delay_us, + ._btdm_rom_table_ready = btdm_funcs_table_ready_wrapper, }; static DRAM_ATTR struct osi_funcs_t *osi_funcs_p; @@ -871,6 +878,13 @@ static void async_wakeup_request_end(int event) return; } +static void btdm_funcs_table_ready_wrapper(void) +{ +#if BT_BLE_CCA_MODE == 2 + btdm_cca_feature_enable(); +#endif +} + static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) { #if CONFIG_SW_COEXIST_ENABLE @@ -1299,14 +1313,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) periph_module_enable(PERIPH_BT_MODULE); periph_module_reset(PERIPH_BT_MODULE); - esp_phy_enable(); - s_lp_stat.phy_enabled = 1; - if (btdm_controller_init(cfg) != 0) { err = ESP_ERR_NO_MEM; goto error; } - coex_pti_v2(); btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; @@ -1336,11 +1346,6 @@ static void bt_controller_deinit_internal(void) { periph_module_disable(PERIPH_BT_MODULE); - if (s_lp_stat.phy_enabled) { - esp_phy_disable(); - s_lp_stat.phy_enabled = 0; - } - // deinit low power control resources do { @@ -1434,6 +1439,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_ERR_INVALID_ARG; } + /* Enable PHY when enabling controller to reduce power dissipation after controller init + * Notice the init order: esp_phy_enable() -> bt_bb_v2_init_cmplx() -> coex_pti_v2() + */ + esp_phy_enable(); + s_lp_stat.phy_enabled = 1; + #if CONFIG_SW_COEXIST_ENABLE coex_enable(); #endif @@ -1458,6 +1469,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) goto error; } + coex_pti_v2(); + btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED; return ret; @@ -1480,6 +1493,10 @@ error: #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif + if (s_lp_stat.phy_enabled) { + esp_phy_disable(); + s_lp_stat.phy_enabled = 0; + } return ret; } @@ -1498,6 +1515,10 @@ esp_err_t esp_bt_controller_disable(void) #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif + if (s_lp_stat.phy_enabled) { + esp_phy_disable(); + s_lp_stat.phy_enabled = 0; + } btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index b438f60a29..040cd0eafd 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit b438f60a295183e7c67eb42ae05f4580f4b1ced0 +Subproject commit 040cd0eafd8c6ee52bc7f7d5d633c9dc1b99bba2 diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 8ac68e06ec..a7e17f4aa1 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -19,7 +19,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02302140 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02307120 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -169,6 +169,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #endif // (CONFIG_BT_BLUEDROID_ENABLED) || (CONFIG_BT_NIMBLE_ENABLED) #endif // (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) || (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT) +#if defined(CONFIG_BT_BLE_CCA_MODE) +#define BT_BLE_CCA_MODE (CONFIG_BT_BLE_CCA_MODE) +#else +#define BT_BLE_CCA_MODE (0) +#endif + #define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1)) #define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0) @@ -214,6 +220,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ .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, \ } #else @@ -284,6 +291,7 @@ typedef struct { uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */ 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 */ } esp_bt_controller_config_t; /** From c315a246e65be557923045880da40de741d15c0f Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Thu, 10 Aug 2023 21:59:11 +0800 Subject: [PATCH 10/11] Update bt lib for ESP32-C3 and ESP32-S3(59725b5) - Support BLE RX error packet count record - Fixed adv random delay when adv interval is less than 20ms - Fixed adv random address setting when owner address type is public --- components/bt/controller/lib_esp32c3_family | 2 +- components/bt/host/bluedroid/api/include/api/esp_bt_defs.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index 040cd0eafd..0cfac1b21e 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit 040cd0eafd8c6ee52bc7f7d5d633c9dc1b99bba2 +Subproject commit 0cfac1b21ebc995e8e9aa040ab1ab29deee4f580 diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h index 7e0df27bd7..1941901417 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h @@ -125,7 +125,11 @@ typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */ /// Default GATT interface id #define ESP_DEFAULT_GATT_IF 0xff +#if BLE_HIGH_DUTY_ADV_INTERVAL +#define ESP_BLE_PRIM_ADV_INT_MIN 0x000008 /*!< Minimum advertising interval for undirected and low duty cycle directed advertising */ +#else #define ESP_BLE_PRIM_ADV_INT_MIN 0x000020 /*!< Minimum advertising interval for undirected and low duty cycle directed advertising */ +#endif #define ESP_BLE_PRIM_ADV_INT_MAX 0xFFFFFF /*!< Maximum advertising interval for undirected and low duty cycle directed advertising */ #define ESP_BLE_CONN_INT_MIN 0x0006 /*!< relate to BTM_BLE_CONN_INT_MIN in stack/btm_ble_api.h */ #define ESP_BLE_CONN_INT_MAX 0x0C80 /*!< relate to BTM_BLE_CONN_INT_MAX in stack/btm_ble_api.h */ From 38742811073337d11aa4a3fd9c486219da4000c1 Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Thu, 10 Aug 2023 22:06:24 +0800 Subject: [PATCH 11/11] update esp32 bt-lib (7b24543) - Support BLE RX error packet count record - Fixed instant setting for LLC procedures with instants - Fixed adv random delay when adv interval is less than 20ms --- components/bt/include/esp32/include/esp_bt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/include/esp32/include/esp_bt.h b/components/bt/include/esp32/include/esp_bt.h index f048ff37e6..6b7ef15752 100644 --- a/components/bt/include/esp32/include/esp_bt.h +++ b/components/bt/include/esp32/include/esp_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */