From 5fc5016981981e30157b2be0162900e894b80039 Mon Sep 17 00:00:00 2001 From: xiewenxiang Date: Thu, 23 Dec 2021 17:30:31 +0800 Subject: [PATCH 1/2] component/bt: fix periodic adv parameters detection issue --- .../bt/host/bluedroid/hci/hci_packet_parser.c | 3 ++- .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/bt/host/bluedroid/hci/hci_packet_parser.c b/components/bt/host/bluedroid/hci/hci_packet_parser.c index ba756f0bba..885153764e 100644 --- a/components/bt/host/bluedroid/hci/hci_packet_parser.c +++ b/components/bt/host/bluedroid/hci/hci_packet_parser.c @@ -209,7 +209,8 @@ static void parse_ble_read_adv_max_len_response( { uint8_t *stream = read_command_complete_header(response, HCI_BLE_RD_MAX_ADV_DATA_LEN, 1 /* bytes after */); - STREAM_TO_UINT8(*adv_max_len_ptr, stream); + // Size: 2 Octets ; Value: 0x001F – 0x0672 ; Maximum supported advertising data length + STREAM_TO_UINT16(*adv_max_len_ptr, stream); osi_free(response); } 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 e6df9b0761..b5d6491f04 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,23 +693,16 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data { tBTM_STATUS status = BTM_SUCCESS; tHCI_STATUS err = HCI_SUCCESS; - uint16_t rem_len; + uint16_t rem_len = len; UINT8 operation = 0; UINT16 data_offset = 0; tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; if ((status = btm_ble_ext_adv_set_data_validate(instance, len, data)) != BTM_SUCCESS) { BTM_TRACE_ERROR("%s, invalid extend adv data.", __func__); + goto end; } - if (len > controller_get_interface()->ble_get_ext_adv_data_max_len()) { - BTM_TRACE_ERROR("%s, The adv data len(%d) is longer then the controller adv max len(%d)", - __func__, len, controller_get_interface()->ble_get_ext_adv_data_max_len()); - status = BTM_ILLEGAL_VALUE; - } - - rem_len = len; - do { UINT8 send_data_len = (rem_len > BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX) ? BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX : rem_len; @@ -733,8 +726,8 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data data_offset += send_data_len; } while(rem_len); +end: cb_params.status = status; - BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_PERIODIC_ADV_DATA_SET_COMPLETE_EVT, &cb_params); return status; @@ -1112,6 +1105,12 @@ static tBTM_STATUS btm_ble_ext_adv_set_data_validate(UINT8 instance, UINT16 len, BTM_TRACE_ERROR("%s, for the legacy adv, the adv data length can't exceed 31. line %d", __func__, __LINE__); return BTM_ILLEGAL_VALUE; } + } else { + if (len > controller_get_interface()->ble_get_ext_adv_data_max_len()) { + BTM_TRACE_ERROR("%s, The adv data len(%d) is longer then the controller adv max len(%d)", + __func__, len, controller_get_interface()->ble_get_ext_adv_data_max_len()); + return BTM_ILLEGAL_VALUE; + } } return BTM_SUCCESS; From bf6b3ec0a8662b1aa330a8f53e01a425f59a003e Mon Sep 17 00:00:00 2001 From: xiewenxiang Date: Tue, 28 Dec 2021 15:11:54 +0800 Subject: [PATCH 2/2] component/bt: Support set HW CCA threshold value --- components/bt/controller/esp32c3/Kconfig.in | 7 +++++++ components/bt/controller/esp32s3/Kconfig.in | 7 +++++++ components/bt/controller/lib_esp32c3_family | 2 +- components/bt/include/esp32c3/include/esp_bt.h | 4 +++- components/bt/include/esp32s3/include/esp_bt.h | 4 +++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index c30f80bc45..caa0d65328 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -66,6 +66,13 @@ config BT_CTRL_HW_CCA help It enables HW CCA feature in controller +config BT_CTRL_HW_CCA_VAL + int "CCA threshold value" + range 20 60 + default 20 + help + It is the threshold value of HW CCA, if the value is 30, it means CCA threshold is -30 dBm. + config BT_CTRL_HW_CCA_EFF int default 1 if BT_CTRL_HW_CCA diff --git a/components/bt/controller/esp32s3/Kconfig.in b/components/bt/controller/esp32s3/Kconfig.in index 359dac7b54..03eb095249 100644 --- a/components/bt/controller/esp32s3/Kconfig.in +++ b/components/bt/controller/esp32s3/Kconfig.in @@ -81,6 +81,13 @@ config BT_CTRL_HW_CCA help It enables HW CCA feature in controller +config BT_CTRL_HW_CCA_VAL + int "CCA threshold value" + range 20 60 + default 20 + help + It is the threshold value of HW CCA, if the value is 30, it means CCA threshold is -30 dBm. + config BT_CTRL_HW_CCA_EFF int default 1 if BT_CTRL_HW_CCA diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index 86145c1845..a3f7d7ffa2 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit 86145c184578f9061d2d0efb30fefa20a91a75e9 +Subproject commit a3f7d7ffa2b261b1415042d8b7cd457cc2b4b1de diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 0e13ee90fa..2c1af6580e 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -18,7 +18,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02104270 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02112280 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -178,6 +178,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .hw_target_code = BLE_HW_TARGET_CODE_ESP32C3_CHIP_ECO0, \ .slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \ .hw_recorrect_en = AGC_RECORRECT_EN, \ + .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ }; #else @@ -244,6 +245,7 @@ typedef struct { uint32_t hw_target_code; /*!< hardware target */ uint8_t slave_ce_len_min; uint8_t hw_recorrect_en; + uint8_t cca_thresh; /*!< cca threshold*/ } esp_bt_controller_config_t; /** diff --git a/components/bt/include/esp32s3/include/esp_bt.h b/components/bt/include/esp32s3/include/esp_bt.h index df9a4a2b79..efdc6ee63a 100644 --- a/components/bt/include/esp32s3/include/esp_bt.h +++ b/components/bt/include/esp32s3/include/esp_bt.h @@ -18,7 +18,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02104270 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02112280 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -177,6 +177,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .hw_target_code = BLE_HW_TARGET_CODE_ESP32S3_CHIP_ECO0, \ .slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \ .hw_recorrect_en = AGC_RECORRECT_EN, \ + .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ }; #else @@ -243,6 +244,7 @@ typedef struct { uint32_t hw_target_code; /*!< hardware target */ uint8_t slave_ce_len_min; /*!< slave minimum ce length*/ uint8_t hw_recorrect_en; + uint8_t cca_thresh; /*!< cca threshold*/ } esp_bt_controller_config_t; /**