Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_ble_channel_map_update_v5.3' into 'release/v…
Browse files Browse the repository at this point in the history
…5.3'

fix(bt): Update bt lib for ESP32-C3 and ESP32-S3(f583012) (v5.3)

See merge request espressif/esp-idf!32581
  • Loading branch information
Isl2017 committed Sep 6, 2024
2 parents ddda4cc + 7741d58 commit dfbbbab
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 72 deletions.
118 changes: 93 additions & 25 deletions components/bt/controller/esp32c3/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ do{\
#define OSI_VERSION 0x00010009
#define OSI_MAGIC_VALUE 0xFADEBEAD

#define BLE_PWR_HDL_INVL 0xFFFF

/* Types definition
************************************************************************
*/
Expand Down Expand Up @@ -254,8 +256,8 @@ extern bool API_vhci_host_check_send_available(void);
extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len);
extern int API_vhci_host_register_callback(const vhci_host_callback_t *callback);
/* TX power */
extern int ble_txpwr_set(int power_type, int power_level);
extern int ble_txpwr_get(int power_type);
extern int ble_txpwr_set(int power_type, uint16_t handle, int power_level);
extern int ble_txpwr_get(int power_type, uint16_t handle);

extern uint16_t l2c_ble_link_get_tx_buf_num(void);
extern void coex_pti_v2(void);
Expand Down Expand Up @@ -1674,16 +1676,89 @@ esp_bt_controller_status_t esp_bt_controller_get_status(void)
return btdm_controller_status;
}

static int enh_power_type_get(esp_ble_power_type_t power_type)
{
switch (power_type) {
case ESP_BLE_PWR_TYPE_ADV:
return ESP_BLE_ENHANCED_PWR_TYPE_ADV;
case ESP_BLE_PWR_TYPE_SCAN:
return ESP_BLE_ENHANCED_PWR_TYPE_SCAN;
case ESP_BLE_PWR_TYPE_CONN_HDL0:
case ESP_BLE_PWR_TYPE_CONN_HDL1:
case ESP_BLE_PWR_TYPE_CONN_HDL2:
case ESP_BLE_PWR_TYPE_CONN_HDL3:
case ESP_BLE_PWR_TYPE_CONN_HDL4:
case ESP_BLE_PWR_TYPE_CONN_HDL5:
case ESP_BLE_PWR_TYPE_CONN_HDL6:
case ESP_BLE_PWR_TYPE_CONN_HDL7:
case ESP_BLE_PWR_TYPE_CONN_HDL8:
return ESP_BLE_ENHANCED_PWR_TYPE_CONN;
case ESP_BLE_PWR_TYPE_DEFAULT:
return ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT;
default:
break;
}

return power_type;
}

/* extra functions */
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level)
{
esp_err_t stat = ESP_FAIL;
uint16_t handle = BLE_PWR_HDL_INVL;
int enh_pwr_type = enh_power_type_get(power_type);

if (power_type > ESP_BLE_PWR_TYPE_DEFAULT) {
return ESP_ERR_NOT_SUPPORTED;
}

if (enh_pwr_type == ESP_BLE_ENHANCED_PWR_TYPE_CONN) {
handle = power_type;
}

if (ble_txpwr_set(enh_pwr_type, handle, power_level) == 0) {
stat = ESP_OK;
}

return stat;
}

esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type)
{
esp_power_level_t lvl;
uint16_t handle = BLE_PWR_HDL_INVL;
int enh_pwr_type = enh_power_type_get(power_type);

if (power_type > ESP_BLE_PWR_TYPE_DEFAULT) {
return ESP_PWR_LVL_INVALID;
}

if (enh_pwr_type == ESP_BLE_ENHANCED_PWR_TYPE_CONN) {
handle = power_type;
}

lvl = (esp_power_level_t)ble_txpwr_get(power_type, handle);

return lvl;
}

esp_err_t esp_ble_tx_power_set_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle,
esp_power_level_t power_level)
{
esp_err_t stat = ESP_FAIL;

switch (power_type) {
case ESP_BLE_PWR_TYPE_ADV:
case ESP_BLE_PWR_TYPE_SCAN:
case ESP_BLE_PWR_TYPE_DEFAULT:
if (ble_txpwr_set(power_type, power_level) == 0) {
case ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT:
case ESP_BLE_ENHANCED_PWR_TYPE_SCAN:
case ESP_BLE_ENHANCED_PWR_TYPE_INIT:
if (ble_txpwr_set(power_type, BLE_PWR_HDL_INVL, power_level) == 0) {
stat = ESP_OK;
}
break;
case ESP_BLE_ENHANCED_PWR_TYPE_ADV:
case ESP_BLE_ENHANCED_PWR_TYPE_CONN:
if (ble_txpwr_set(power_type, handle, power_level) == 0) {
stat = ESP_OK;
}
break;
Expand All @@ -1695,33 +1770,26 @@ esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_
return stat;
}

esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type)
esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type,
uint16_t handle)
{
esp_power_level_t lvl;
int tx_level = 0;

switch (power_type) {
case ESP_BLE_PWR_TYPE_ADV:
case ESP_BLE_PWR_TYPE_SCAN:
lvl = (esp_power_level_t)ble_txpwr_get(power_type);
case ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT:
case ESP_BLE_ENHANCED_PWR_TYPE_SCAN:
case ESP_BLE_ENHANCED_PWR_TYPE_INIT:
tx_level = ble_txpwr_get(power_type, BLE_PWR_HDL_INVL);
break;
case ESP_BLE_PWR_TYPE_CONN_HDL0:
case ESP_BLE_PWR_TYPE_CONN_HDL1:
case ESP_BLE_PWR_TYPE_CONN_HDL2:
case ESP_BLE_PWR_TYPE_CONN_HDL3:
case ESP_BLE_PWR_TYPE_CONN_HDL4:
case ESP_BLE_PWR_TYPE_CONN_HDL5:
case ESP_BLE_PWR_TYPE_CONN_HDL6:
case ESP_BLE_PWR_TYPE_CONN_HDL7:
case ESP_BLE_PWR_TYPE_CONN_HDL8:
case ESP_BLE_PWR_TYPE_DEFAULT:
lvl = (esp_power_level_t)ble_txpwr_get(ESP_BLE_PWR_TYPE_DEFAULT);
case ESP_BLE_ENHANCED_PWR_TYPE_ADV:
case ESP_BLE_ENHANCED_PWR_TYPE_CONN:
tx_level = ble_txpwr_get(power_type, handle);
break;
default:
lvl = ESP_PWR_LVL_INVALID;
break;
return ESP_PWR_LVL_INVALID;
}

return lvl;
return (esp_power_level_t)tx_level;
}

esp_err_t esp_bt_sleep_enable (void)
Expand Down
2 changes: 1 addition & 1 deletion components/bt/controller/lib_esp32c3_family
11 changes: 6 additions & 5 deletions components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ typedef struct
{
esp_bd_addr_t bd_addr; /*!< peer address */
esp_ble_bond_key_info_t bond_key; /*!< the bond key information */
esp_ble_addr_type_t bd_addr_type; /*!< peer address type */
} esp_ble_bond_dev_t; /*!< the ble bond device type */


Expand Down Expand Up @@ -1179,13 +1180,13 @@ typedef union {
struct ble_update_conn_params_evt_param {
esp_bt_status_t status; /*!< Indicate update connection parameters success status */
esp_bd_addr_t bda; /*!< Bluetooth device address */
uint16_t min_int; /*!< Min connection interval */
uint16_t max_int; /*!< Max connection interval */
uint16_t min_int; /*!< Minimum connection interval. If the master initiates the connection parameter update, this value is not applicable for the slave and will be set to zero. */
uint16_t max_int; /*!< Maximum connection interval. If the master initiates the connection parameter update, this value is not applicable for the slave and will be set to zero. */
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
uint16_t conn_int; /*!< Current connection interval */
uint16_t conn_int; /*!< Current connection interval in milliseconds, calculated as N × 1.25 ms */
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec */
} update_conn_params; /*!< Event parameter of ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
This value is calculated as N × 10 ms */
} update_conn_params; /*!< Event parameter for ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
/**
* @brief ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT
*/
Expand Down
13 changes: 11 additions & 2 deletions components/bt/host/bluedroid/btc/core/btc_ble_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#if (SMP_INCLUDED == TRUE)

//the maximum nubmer of bonded devices
//the maximum number of bonded devices
#define BONED_DEVICES_MAX_COUNT (BTM_SEC_MAX_DEVICE_RECORDS)

static void _btc_storage_save(void)
Expand Down Expand Up @@ -58,7 +58,7 @@ static void _btc_storage_save(void)
addr_section_count ++;
iter = btc_config_section_next(iter);
}
/*exceeded the maximum nubmer of bonded devices, delete them */
/*exceeded the maximum number of bonded devices, delete them */
if (need_remove_iter) {
while(need_remove_iter != btc_config_section_end()) {
const char *need_remove_section = btc_config_section_name(need_remove_iter);
Expand Down Expand Up @@ -954,6 +954,7 @@ bt_status_t _btc_storage_in_fetch_bonded_ble_device(const char *remote_bd_addr,
bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev, int dev_num)
{
bt_bdaddr_t bd_addr;
int addr_t;
char buffer[sizeof(tBTM_LE_KEY_VALUE)] = {0};

btc_config_lock();
Expand All @@ -975,6 +976,14 @@ bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev

string_to_bdaddr(name, &bd_addr);
memcpy(bond_dev->bd_addr, bd_addr.address, sizeof(bt_bdaddr_t));
//get address type
if (_btc_storage_get_remote_addr_type((bt_bdaddr_t *)bond_dev->bd_addr, &addr_t) == BT_STATUS_SUCCESS) {
bond_dev->bd_addr_type = (uint8_t) addr_t;
} else {
// Set an invalid address type
bond_dev->bd_addr_type = 0xFF;
BTC_TRACE_ERROR("%s, %s get address type fail", __func__, name);
}
//resolve the peer device long term key
if (_btc_storage_get_ble_bonding_key(&bd_addr, BTM_LE_KEY_PENC, buffer, sizeof(tBTM_LE_PENC_KEYS)) == BT_STATUS_SUCCESS) {
bond_dev->bond_key.key_mask |= ESP_BLE_ENC_KEY_MASK;
Expand Down
31 changes: 31 additions & 0 deletions components/bt/include/esp32c3/include/esp_bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ typedef enum {
ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */
} esp_power_level_t;

/**
* @brief The enhanced type of which tx power, could set Advertising/Connection/Default and etc.
*/
typedef enum {
ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT = 0,
ESP_BLE_ENHANCED_PWR_TYPE_ADV,
ESP_BLE_ENHANCED_PWR_TYPE_SCAN,
ESP_BLE_ENHANCED_PWR_TYPE_INIT,
ESP_BLE_ENHANCED_PWR_TYPE_CONN,
ESP_BLE_ENHANCED_PWR_TYPE_MAX,
} esp_ble_enhanced_power_type_t;

/**
* @brief Set BLE TX power
* Connection Tx power should only be set after connection created.
Expand All @@ -407,6 +419,25 @@ esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_
*/
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);

/**
* @brief ENHANCED API for Setting BLE TX power
* Connection Tx power should only be set after connection created.
* @param power_type : The enhanced type of which tx power, could set Advertising/Connection/Default and etc.
* @param handle : The handle of Advertising or Connection and the value 0 for other enhanced power types.
* @param power_level: Power level(index) corresponding to absolute value(dbm)
* @return ESP_OK - success, other - failed
*/
esp_err_t esp_ble_tx_power_set_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle, esp_power_level_t power_level);

/**
* @brief ENHANCED API of Getting BLE TX power
* Connection Tx power should only be get after connection created.
* @param power_type : The enhanced type of which tx power, could set Advertising/Connection/Default and etc
* @param handle : The handle of Advertising or Connection and the value 0 for other enhanced power types.
* @return >= 0 - Power level, < 0 - Invalid
*/
esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle);

/**
* @brief Initialize BT controller to allocate task and other resource.
* This function should be called only once, before any other BT functions are called.
Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ r_btdm_task_recycle = 0x40000c1c;
r_hci_register_vendor_desc_tab = 0x40000d9c;
r_ke_task_schedule = 0x40000e80;
r_llc_hci_command_handler = 0x40000ef0;
r_llc_loc_ch_map_proc_continue = 0x40000f5c;
r_llc_loc_con_upd_proc_continue = 0x40000f60;
r_llc_loc_phy_upd_proc_continue = 0x40000f78;
r_llc_rem_con_upd_proc_continue = 0x40000fb4;
Expand Down
1 change: 0 additions & 1 deletion components/esp_rom/esp32c3/ld/esp32c3.rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@ r_llc_llcp_send = 0x40000f4c;
r_llc_llcp_state_set = 0x40000f50;
r_llc_llcp_trans_timer_set = 0x40000f54;
r_llc_llcp_tx_check = 0x40000f58;
r_llc_loc_ch_map_proc_continue = 0x40000f5c;
r_llc_loc_con_upd_proc_err_cb = 0x40000f64;
r_llc_loc_dl_upd_proc_continue = 0x40000f68;
r_llc_loc_encrypt_proc_continue = 0x40000f6c;
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rom/esp32s3/ld/esp32s3.rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ r_llc_llcp_send = 0x40003dc8;
r_llc_llcp_state_set = 0x40003dd4;
r_llc_llcp_trans_timer_set = 0x40003de0;
r_llc_llcp_tx_check = 0x40003dec;
r_llc_loc_ch_map_proc_continue = 0x40003df8;
/* r_llc_loc_ch_map_proc_continue = 0x40003df8; */
r_llc_loc_con_upd_proc_err_cb = 0x40003e10;
r_llc_loc_dl_upd_proc_continue = 0x40003e1c;
r_llc_loc_encrypt_proc_continue = 0x40003e28;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
EXAMPLE_DEBUG(EXAMPLE_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
EXAMPLE_DEBUG(EXAMPLE_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
ESP_LOGI(GATTC_TAG, "stop adv successfully");
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTC_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTC_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTS_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTS_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
ESP_LOGI(GATTC_TAG, "stop adv successfully");
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTC_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTC_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTS_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTS_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,8 @@ The `esp_ble_gap_update_conn_params()` function triggers a GAP event `ESP_GAP_BL

```c
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTS_TAG, "update connection params status = %d, min_int = %d, max_int = %d,
conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTS_TAG, "update connection params status = %d, conn_int = %d,latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTS_TABLE_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
uint8_t adv_name_len = 0;
switch (event) {
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
ESP_LOGI(GATTC_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
ESP_LOGI(GATTC_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
param->update_conn_params.status,
param->update_conn_params.min_int,
param->update_conn_params.max_int,
param->update_conn_params.conn_int,
param->update_conn_params.latency,
param->update_conn_params.timeout);
Expand Down
Loading

0 comments on commit dfbbbab

Please sign in to comment.