Merge branch 'bugfix/fix_some_ble_bugs_v5.1' into 'release/v5.1'

Fixed some BLE bugs (backport v5.1)

See merge request espressif/esp-idf!25776
This commit is contained in:
Jiang Jiang Jian 2023-09-08 10:19:40 +08:00
commit ab7ad8a848
32 changed files with 349 additions and 91 deletions

View File

@ -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.

View File

@ -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;

@ -1 +1 @@
Subproject commit b438f60a295183e7c67eb42ae05f4580f4b1ced0
Subproject commit 0cfac1b21ebc995e8e9aa040ab1ab29deee4f580

View File

@ -1150,3 +1150,17 @@ config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
default n
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
default n
help
This enable BLE high duty advertising interval feature

View File

@ -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
*/
@ -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;
@ -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)
@ -1298,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)) {
@ -1322,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)) {
@ -1346,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)) {

View File

@ -125,18 +125,20 @@ 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 */
#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 {
@ -166,10 +168,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

View File

@ -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
*/
@ -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
@ -2107,6 +2116,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 +2145,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 +2170,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

View File

@ -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.

View File

@ -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.

View File

@ -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);
}
/*******************************************************************************
@ -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)

View File

@ -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");

View File

@ -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 {

View File

@ -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)

View File

@ -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);

View File

@ -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");

View File

@ -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
*/
@ -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)
@ -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;

View File

@ -137,6 +137,18 @@
#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
#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

View File

@ -198,6 +198,18 @@
#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
#define BLE_HIGH_DUTY_ADV_INTERVAL FALSE
#endif
#if (UC_BT_BLE_RPA_SUPPORTED == TRUE)
#define CONTROLLER_RPA_LIST_ENABLE TRUE
#else

View File

@ -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;

View File

@ -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);
}
@ -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;
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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
@ -2663,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);

View File

@ -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) */
/*******************************************************************************

View File

@ -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

View File

@ -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){

View File

@ -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;

View File

@ -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
*/

View File

@ -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;
/**

View File

@ -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
};

View File

@ -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;
}

View File

@ -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;
}