Skip to content

Commit

Permalink
Merge branch 'bugfix/change_default_tx_power_on_c3_and_s3' into 'master'
Browse files Browse the repository at this point in the history
Change BLE default TX power on ESP32C3 and ESP32S3

Closes BT-2867, IDFGH-8459, IDFGH-8318, and IDFGH-7439

See merge request espressif/esp-idf!20543
  • Loading branch information
Weijian-Espressif committed Nov 17, 2022
2 parents 3247cd0 + b2a17e9 commit 4a3319d
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 9,895 deletions.
10 changes: 9 additions & 1 deletion components/bt/controller/esp32c3/Kconfig.in
Expand Up @@ -134,7 +134,7 @@ config BT_CTRL_RX_ANTENNA_INDEX_EFF

choice BT_CTRL_DFT_TX_POWER_LEVEL
prompt "BLE default Tx power level"
default BT_CTRL_DFT_TX_POWER_LEVEL_P3
default BT_CTRL_DFT_TX_POWER_LEVEL_P9
help
Specify default Tx power level

Expand Down Expand Up @@ -413,3 +413,11 @@ config BT_CTRL_CODED_AGC_RECORRECT_EN
default n
help
Enable coded phy AGC recorrect

config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
bool "Disable active scan backoff"
default n
help
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.
10 changes: 9 additions & 1 deletion components/bt/controller/esp32s3/Kconfig.in
Expand Up @@ -149,7 +149,7 @@ config BT_CTRL_RX_ANTENNA_INDEX_EFF

choice BT_CTRL_DFT_TX_POWER_LEVEL
prompt "BLE default Tx power level"
default BT_CTRL_DFT_TX_POWER_LEVEL_P3
default BT_CTRL_DFT_TX_POWER_LEVEL_P9
help
Specify default Tx power level

Expand Down Expand Up @@ -429,3 +429,11 @@ config BT_CTRL_CODED_AGC_RECORRECT_EN
default n
help
Enable coded phy AGC recorrect

config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
bool "Disable active scan backoff"
default n
help
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.
2 changes: 1 addition & 1 deletion components/bt/controller/lib_esp32c3_family
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Expand Up @@ -666,6 +666,7 @@ void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value)
if ((p_msg = (tBTA_DM_API_OOB_REPLY *) osi_malloc(sizeof(tBTA_DM_API_OOB_REPLY))) != NULL) {
p_msg->hdr.event = BTA_DM_API_OOB_REPLY_EVT;
if(p_value == NULL || len > BT_OCTET16_LEN) {
osi_free(p_msg);
return;
}
memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
Expand Down
29 changes: 5 additions & 24 deletions components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c
Expand Up @@ -1107,12 +1107,6 @@ void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)

/* read fail */
if (status != BTA_GATT_OK) {
/* Dequeue the data, if it was enqueued */
if (p_clcb->p_q_cmd == p_data) {
p_clcb->p_q_cmd = NULL;
bta_gattc_pop_command_to_send(p_clcb);
}

bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_READ, status, NULL);
}
}
Expand Down Expand Up @@ -1142,12 +1136,6 @@ void bta_gattc_read_by_type(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)

/* read fail */
if (status != BTA_GATT_OK) {
/* Dequeue the data, if it was enqueued */
if (p_clcb->p_q_cmd == p_data) {
p_clcb->p_q_cmd = NULL;
bta_gattc_pop_command_to_send(p_clcb);
}

bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_READ, status, NULL);
}
}
Expand Down Expand Up @@ -1178,12 +1166,6 @@ void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)

/* read fail */
if (status != BTA_GATT_OK) {
/* Dequeue the data, if it was enqueued */
if (p_clcb->p_q_cmd == p_data) {
p_clcb->p_q_cmd = NULL;
bta_gattc_pop_command_to_send(p_clcb);
}

bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_READ, status, NULL);
}
}
Expand Down Expand Up @@ -1220,13 +1202,12 @@ void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)

/* write fail */
if (status != BTA_GATT_OK) {
/* Dequeue the data, if it was enqueued */
if (p_clcb->p_q_cmd == p_data) {
p_clcb->p_q_cmd = NULL;
bta_gattc_pop_command_to_send(p_clcb);
}

bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_WRITE, status, NULL);
tGATT_CL_COMPLETE cl_data = {0};
cl_data.handle = p_data->api_write.handle;
memcpy(&cl_data.att_value, &attr, sizeof(tGATT_VALUE));

bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_WRITE, status, &cl_data);
}
}
/*******************************************************************************
Expand Down
8 changes: 7 additions & 1 deletion components/bt/host/bluedroid/bta/gatt/bta_gattc_cache.c
Expand Up @@ -285,6 +285,12 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
p_srvc_cb->p_srvc_cache = list_new(service_free);
}

if(!p_srvc_cb->p_srvc_cache) {
APPL_TRACE_WARNING("%s(), no resource.", __func__);
osi_free(p_new_srvc);
return BTA_GATT_NO_RESOURCES;
}

if(is_primary) {
list_append(p_srvc_cb->p_srvc_cache, p_new_srvc);
} else {
Expand Down Expand Up @@ -549,7 +555,7 @@ void bta_gattc_update_include_service(const list_t *services) {
}
for (list_node_t *sn = list_begin(services); sn != list_end(services); sn = list_next(sn)) {
tBTA_GATTC_SERVICE *service = list_node(sn);
if(!service && list_is_empty(service->included_svc)) break;
if(!service || !service->included_svc || list_is_empty(service->included_svc)) break;
for (list_node_t *sn = list_begin(service->included_svc); sn != list_end(service->included_svc); sn = list_next(sn)) {
tBTA_GATTC_INCLUDED_SVC *include_service = list_node(sn);
if(include_service && !include_service->included_service) {
Expand Down
5 changes: 5 additions & 0 deletions components/bt/host/bluedroid/bta/gatt/bta_gattc_co.c
Expand Up @@ -583,13 +583,18 @@ BOOLEAN bta_gattc_co_cache_append_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add
UINT8 addr_index = 0;
cache_addr_info_t *addr_info;
UINT8 *p_assoc_buf = osi_malloc(sizeof(BD_ADDR));
if(!p_assoc_buf) {
return FALSE;
}
memcpy(p_assoc_buf, assoc_addr, sizeof(BD_ADDR));
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) {
addr_info = &cache_env->cache_addr[addr_index];
if (addr_info->assoc_addr == NULL) {
addr_info->assoc_addr =list_new(NULL);
}
return list_append(addr_info->assoc_addr, p_assoc_buf);
} else {
osi_free(p_assoc_buf);
}

return FALSE;
Expand Down
12 changes: 12 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_sec.c
Expand Up @@ -3170,6 +3170,10 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT
}
}

if(!p_dev_rec) {
return;
}

/* If this is a bonding procedure can disconnect the link now */
if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)
&& (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) {
Expand Down Expand Up @@ -3953,6 +3957,10 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status)
}
}

if(!p_dev_rec) {
return;
}

p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;

#if (CLASSIC_BT_INCLUDED == TRUE)
Expand Down Expand Up @@ -4796,6 +4804,10 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t
}
}

if(!p_dev_rec) {
return;
}

/* We will save link key only if the user authorized it - BTE report link key in all cases */
#ifdef BRCM_NONE_BTE
if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/stack/gatt/gatt_db.c
Expand Up @@ -976,7 +976,7 @@ tGATT_STATUS gatts_write_attr_value_by_handle(tGATT_SVC_DB *p_db,
memcpy(p_attr->p_value->attr_val.attr_val + offset, p_value, len);
p_attr->p_value->attr_val.attr_len = len + offset;
return GATT_SUCCESS;
} else if (p_attr->p_value->attr_val.attr_max_len < offset + len){
} else if (p_attr->p_value && p_attr->p_value->attr_val.attr_max_len < offset + len){
GATT_TRACE_DEBUG("Remote device try to write with a length larger then attribute's max length\n");
return GATT_INVALID_ATTR_LEN;
} else if ((p_attr->p_value == NULL) || (p_attr->p_value->attr_val.attr_val == NULL)){
Expand Down
10 changes: 9 additions & 1 deletion components/bt/include/esp32c3/include/esp_bt.h
Expand Up @@ -18,7 +18,7 @@ extern "C" {
#endif

#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
#define ESP_BT_CTRL_CONFIG_VERSION 0x02112280
#define ESP_BT_CTRL_CONFIG_VERSION 0x02209230

#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
#define ESP_BT_HCI_TL_VERSION 0x00010000
Expand Down Expand Up @@ -141,6 +141,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#define BT_CTRL_CODED_AGC_RECORRECT 0
#endif

#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#else
#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0
#endif

#define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1))


Expand Down Expand Up @@ -181,6 +187,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \
.hw_recorrect_en = AGC_RECORRECT_EN, \
.cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \
.scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \
}

#else
Expand Down Expand Up @@ -248,6 +255,7 @@ typedef struct {
uint8_t slave_ce_len_min;
uint8_t hw_recorrect_en;
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
} esp_bt_controller_config_t;

/**
Expand Down
10 changes: 9 additions & 1 deletion components/bt/include/esp32s3/include/esp_bt.h
Expand Up @@ -18,7 +18,7 @@ extern "C" {
#endif

#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
#define ESP_BT_CTRL_CONFIG_VERSION 0x02112280
#define ESP_BT_CTRL_CONFIG_VERSION 0x02209230

#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
#define ESP_BT_HCI_TL_VERSION 0x00010000
Expand Down Expand Up @@ -129,6 +129,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
#endif

#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#else
#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0
#endif

#ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN
#define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN
#else
Expand Down Expand Up @@ -180,6 +186,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \
.hw_recorrect_en = AGC_RECORRECT_EN, \
.cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \
.scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \
}

#else
Expand Down Expand Up @@ -247,6 +254,7 @@ typedef struct {
uint8_t slave_ce_len_min; /*!< slave minimum ce length*/
uint8_t hw_recorrect_en;
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
} esp_bt_controller_config_t;

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand Down Expand Up @@ -625,8 +625,6 @@ void app_main(void)
}
ESP_ERROR_CHECK( ret );

ESP_ERROR_CHECK(nvs_flash_erase());

ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
Expand Down
@@ -1,5 +1,6 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_GATTC_WRITE_THROUGHPUT=y
CONFIG_BT_ENABLED=y
CONFIG_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_GATTC_WRITE_THROUGHPUT=n
Expand Up @@ -3,7 +3,6 @@
#
CONFIG_IDF_TARGET="esp32c2"
CONFIG_BT_ENABLED=y
CONFIG_GATTC_WRITE_THROUGHPUT=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_LE_50_FEATURE_SUPPORT is not set
Expand Down
Expand Up @@ -2,7 +2,6 @@
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32c3"
CONFIG_GATTC_WRITE_THROUGHPUT=y
CONFIG_BT_ENABLED=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
Expand Up @@ -2,7 +2,6 @@
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32h4"
CONFIG_GATTC_WRITE_THROUGHPUT=y
CONFIG_BT_ENABLED=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
Expand Down
Expand Up @@ -2,7 +2,6 @@
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_GATTC_WRITE_THROUGHPUT=y
CONFIG_BT_ENABLED=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
@@ -1,7 +1,6 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_EXAMPLE_SET_RAW_ADV_DATA=y
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=n
CONFIG_BT_ENABLED=y
Expand Up @@ -2,9 +2,6 @@
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32c2"
CONFIG_EXAMPLE_SET_RAW_ADV_DATA=y
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=y
CONFIG_BT_ENABLED=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
Expand Down
Expand Up @@ -3,8 +3,5 @@
#
CONFIG_IDF_TARGET="esp32c3"
CONFIG_BT_ENABLED=y
CONFIG_EXAMPLE_SET_RAW_ADV_DATA=y
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
Expand Up @@ -3,9 +3,6 @@
#
CONFIG_IDF_TARGET="esp32h4"
CONFIG_BT_ENABLED=y
CONFIG_EXAMPLE_SET_RAW_ADV_DATA=y
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_LE_50_FEATURE_SUPPORT is not set
Expand Down
Expand Up @@ -3,8 +3,5 @@
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_BT_ENABLED=y
CONFIG_EXAMPLE_SET_RAW_ADV_DATA=y
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
@@ -1,6 +1,4 @@
# Override some defaults so BT stack is enabled
# by default in this example
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n

0 comments on commit 4a3319d

Please sign in to comment.