Merge branch 'bugfix/fix_ble_some_bugs_20221219_v4.4' into 'release/v4.4'

backport some BLE bugs 20221219 (backport v4.4)

See merge request espressif/esp-idf!21709
This commit is contained in:
Jiang Jiang Jian 2023-02-03 13:50:26 +08:00
commit 320894986d
11 changed files with 168 additions and 189 deletions

View File

@ -353,6 +353,22 @@ config BTDM_SCAN_DUPL_CACHE_SIZE
Maximum number of devices which can be recorded in scan duplicate filter.
When the maximum amount of device in the filter is reached, the cache will be refreshed.
config BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD
int "Duplicate scan list refresh period (seconds)"
depends on BTDM_BLE_SCAN_DUPL
range 0 1000
default 0
help
If the period value is non-zero, the controller will periodically clear the device information
stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared
until the scanning is disabled. Duplicate advertisements for this period should not be sent to the
Host in advertising report events.
There are two scenarios where the ADV packet will be repeatedly reported:
1. The duplicate scan cache is full, the controller will delete the oldest device information and
add new device information.
2. When the refresh period is up, the controller will clear all device information and start filtering
again.
config BTDM_BLE_MESH_SCAN_DUPL_EN
bool "Special duplicate scan mechanism for BLE Mesh scan"
depends on BTDM_BLE_SCAN_DUPL

View File

@ -324,6 +324,7 @@ static void *customer_queue_create_hlevel_wrapper(uint32_t queue_len, uint32_t i
#endif /* CONFIG_BTDM_CTRL_HLI */
static void IRAM_ATTR interrupt_l3_disable(void);
static void IRAM_ATTR interrupt_l3_restore(void);
static void bt_controller_deinit_internal(void);
/* Local variable definition
***************************************************************************
@ -1575,26 +1576,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ESP_OK;
error:
#ifdef CONFIG_PM_ENABLE
if (!s_btdm_allow_light_sleep) {
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
}
if (s_btdm_slp_tmr != NULL) {
esp_timer_delete(s_btdm_slp_tmr);
s_btdm_slp_tmr = NULL;
}
#endif
if (s_wakeup_req_sem) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
bt_controller_deinit_internal();
return err;
}
@ -1606,6 +1590,13 @@ esp_err_t esp_bt_controller_deinit(void)
btdm_controller_deinit();
bt_controller_deinit_internal();
return ESP_OK;
}
static void bt_controller_deinit_internal(void)
{
periph_module_disable(PERIPH_BT_MODULE);
#ifdef CONFIG_PM_ENABLE
@ -1627,11 +1618,16 @@ esp_err_t esp_bt_controller_deinit(void)
s_pm_lock_acquired = false;
#endif
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
free(osi_funcs_p);
osi_funcs_p = NULL;
if (s_wakeup_req_sem) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
if (osi_funcs_p) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
@ -1641,8 +1637,6 @@ esp_err_t esp_bt_controller_deinit(void)
esp_bt_power_domain_off();
esp_phy_modem_deinit();
return ESP_OK;
}
static void bt_controller_shutdown(void* arg)

View File

@ -280,6 +280,22 @@ config BT_CTRL_SCAN_DUPL_CACHE_SIZE
Maximum number of devices which can be recorded in scan duplicate filter.
When the maximum amount of device in the filter is reached, the cache will be refreshed.
config BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
int "Duplicate scan list refresh period (seconds)"
depends on BT_CTRL_BLE_SCAN_DUPL
range 0 1000
default 0
help
If the period value is non-zero, the controller will periodically clear the device information
stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared
until the scanning is disabled. Duplicate advertisements for this period should not be sent to the
Host in advertising report events.
There are two scenarios where the ADV packet will be repeatedly reported:
1. The duplicate scan cache is full, the controller will delete the oldest device information and
add new device information.
2. When the refresh period is up, the controller will clear all device information and start filtering
again.
config BT_CTRL_BLE_MESH_SCAN_DUPL_EN
bool "Special duplicate scan mechanism for BLE Mesh scan"
depends on BT_CTRL_BLE_SCAN_DUPL

View File

@ -313,6 +313,8 @@ static void btdm_slp_tmr_callback(void *arg);
static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end);
static void bt_controller_deinit_internal(void);
/* Local variable definition
***************************************************************************
*/
@ -1271,73 +1273,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ESP_OK;
error:
if (s_lp_stat.phy_enabled) {
esp_phy_disable();
s_lp_stat.phy_enabled = 0;
}
do {
// deinit low power control resources
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
}
bt_controller_deinit_internal();
#endif
if (s_lp_cntl.wakeup_timer_required && s_btdm_slp_tmr != NULL) {
esp_timer_delete(s_btdm_slp_tmr);
s_btdm_slp_tmr = NULL;
}
#if CONFIG_MAC_BB_PD
if (s_lp_cntl.mac_bb_pd) {
btdm_deep_sleep_mem_deinit();
s_lp_cntl.mac_bb_pd = 0;
}
#endif
if (s_lp_cntl.enable) {
btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR);
if (s_wakeup_req_sem != NULL) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
}
if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP
if (s_lp_cntl.main_xtal_pu) {
ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF));
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
#if CONFIG_SW_COEXIST_ENABLE
coex_update_lpclk_interval();
#endif
}
btdm_lpcycle_us = 0;
} while (0);
#if CONFIG_MAC_BB_PD
esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb);
esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb);
#endif
if (osi_funcs_p != NULL) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}
return err;
}
@ -1348,31 +1286,47 @@ esp_err_t esp_bt_controller_deinit(void)
}
btdm_controller_deinit();
bt_controller_deinit_internal();
return ESP_OK;
}
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;
} else {
assert(0);
}
// deinit low power control resources
do {
#if CONFIG_MAC_BB_PD
btdm_deep_sleep_mem_deinit();
if (s_lp_cntl.mac_bb_pd) {
btdm_deep_sleep_mem_deinit();
s_lp_cntl.mac_bb_pd = 0;
}
#endif
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
}
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
#endif
if (s_lp_cntl.wakeup_timer_required) {
if (s_lp_stat.wakeup_timer_started) {
esp_timer_stop(s_btdm_slp_tmr);
@ -1384,10 +1338,12 @@ esp_err_t esp_bt_controller_deinit(void)
if (s_lp_cntl.enable) {
btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR);
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
if (s_wakeup_req_sem != NULL) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
}
if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP
if (s_lp_cntl.main_xtal_pu) {
@ -1416,11 +1372,12 @@ esp_err_t esp_bt_controller_deinit(void)
#endif
esp_phy_modem_deinit();
free(osi_funcs_p);
osi_funcs_p = NULL;
if (osi_funcs_p != NULL) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
return ESP_OK;
}
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)

View File

@ -297,6 +297,22 @@ config BT_CTRL_SCAN_DUPL_CACHE_SIZE
Maximum number of devices which can be recorded in scan duplicate filter.
When the maximum amount of device in the filter is reached, the cache will be refreshed.
config BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
int "Duplicate scan list refresh period (seconds)"
depends on BT_CTRL_BLE_SCAN_DUPL
range 0 1000
default 0
help
If the period value is non-zero, the controller will periodically clear the device information
stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared
until the scanning is disabled. Duplicate advertisements for this period should not be sent to the
Host in advertising report events.
There are two scenarios where the ADV packet will be repeatedly reported:
1. The duplicate scan cache is full, the controller will delete the oldest device information and
add new device information.
2. When the refresh period is up, the controller will clear all device information and start filtering
again.
config BT_CTRL_BLE_MESH_SCAN_DUPL_EN
bool "Special duplicate scan mechanism for BLE Mesh scan"
depends on BT_CTRL_BLE_SCAN_DUPL

View File

@ -317,6 +317,8 @@ static void btdm_slp_tmr_callback(void *arg);
static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end);
static void bt_controller_deinit_internal(void);
/* Local variable definition
***************************************************************************
*/
@ -1317,73 +1319,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ESP_OK;
error:
if (s_lp_stat.phy_enabled) {
esp_phy_disable();
s_lp_stat.phy_enabled = 0;
}
do {
// deinit low power control resources
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
}
bt_controller_deinit_internal();
#endif
if (s_lp_cntl.wakeup_timer_required && s_btdm_slp_tmr != NULL) {
esp_timer_delete(s_btdm_slp_tmr);
s_btdm_slp_tmr = NULL;
}
#if CONFIG_MAC_BB_PD
if (s_lp_cntl.mac_bb_pd) {
btdm_deep_sleep_mem_deinit();
s_lp_cntl.mac_bb_pd = 0;
}
#endif
if (s_lp_cntl.enable) {
btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR);
if (s_wakeup_req_sem != NULL) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
}
if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP
if (s_lp_cntl.main_xtal_pu) {
ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF));
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
#if CONFIG_SW_COEXIST_ENABLE
coex_update_lpclk_interval();
#endif
}
btdm_lpcycle_us = 0;
} while (0);
#if CONFIG_MAC_BB_PD
esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb);
esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb);
#endif
if (osi_funcs_p != NULL) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}
return err;
}
@ -1394,31 +1332,47 @@ esp_err_t esp_bt_controller_deinit(void)
}
btdm_controller_deinit();
bt_controller_deinit_internal();
return ESP_OK;
}
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;
} else {
assert(0);
}
// deinit low power control resources
do {
#if CONFIG_MAC_BB_PD
btdm_deep_sleep_mem_deinit();
if (s_lp_cntl.mac_bb_pd) {
btdm_deep_sleep_mem_deinit();
s_lp_cntl.mac_bb_pd = 0;
}
#endif
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
}
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
s_lp_stat.pm_lock_released = 0;
#endif
if (s_lp_cntl.wakeup_timer_required) {
if (s_lp_stat.wakeup_timer_started) {
esp_timer_stop(s_btdm_slp_tmr);
@ -1430,9 +1384,10 @@ esp_err_t esp_bt_controller_deinit(void)
if (s_lp_cntl.enable) {
btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR);
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
if (s_wakeup_req_sem != NULL) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
}
if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
@ -1463,11 +1418,12 @@ esp_err_t esp_bt_controller_deinit(void)
#endif
esp_phy_modem_deinit();
free(osi_funcs_p);
osi_funcs_p = NULL;
if (osi_funcs_p != NULL) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
return ESP_OK;
}
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)

@ -1 +1 @@
Subproject commit dbaeb136cacf8c7d071f838c1053f90299f57720
Subproject commit d4a224c5d682d6b5a76542c6918b6a59dd0b2f8c

@ -1 +1 @@
Subproject commit 79152b519023f26462498f3ef8805cff2a80e193
Subproject commit bba9af9259e0999ef246426d31a793fe0a3ff4db

View File

@ -50,7 +50,7 @@ extern "C" {
#endif //CONFIG_BT_ENABLED
#define ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL 0x20200622
#define ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL 0x20221207
/**
* @brief Bluetooth mode for controller enable/disable
@ -128,6 +128,12 @@ the adv packet will be discarded until the memory is restored. */
#define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
#endif
#ifdef CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD
#define SCAN_DUPL_CACHE_REFRESH_PERIOD CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD
#else
#define SCAN_DUPL_CACHE_REFRESH_PERIOD 0
#endif
#if defined(CONFIG_BTDM_CTRL_MODE_BLE_ONLY)
#define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_BLE
#elif defined(CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY)
@ -183,6 +189,7 @@ the adv packet will be discarded until the memory is restored. */
.pcm_role = CONFIG_BTDM_CTRL_PCM_ROLE_EFF, \
.pcm_polar = CONFIG_BTDM_CTRL_PCM_POLAR_EFF, \
.hli = BTDM_CTRL_HLI, \
.dup_list_refresh_period = SCAN_DUPL_CACHE_REFRESH_PERIOD, \
.magic = ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL, \
}
@ -225,6 +232,7 @@ typedef struct {
uint8_t pcm_role; /*!< PCM role (master & slave)*/
uint8_t pcm_polar; /*!< PCM polar trig (falling clk edge & rising clk edge) */
bool hli; /*!< Using high level interrupt or not */
uint16_t dup_list_refresh_period; /*!< Duplicate scan list refresh period */
uint32_t magic; /*!< Magic number */
} esp_bt_controller_config_t;

View File

@ -19,7 +19,7 @@ extern "C" {
#endif
#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
#define ESP_BT_CTRL_CONFIG_VERSION 0x02209230
#define ESP_BT_CTRL_CONFIG_VERSION 0x02212090
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
#define ESP_BT_HCI_TL_VERSION 0x00010000
@ -130,6 +130,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
#endif
#ifndef CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
#define DUPL_SCAN_CACHE_REFRESH_PERIOD 0
#else
#define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
#endif
#ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN
#define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN
#else
@ -189,6 +195,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.hw_recorrect_en = AGC_RECORRECT_EN, \
.cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \
.scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \
.dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \
}
#else
@ -257,6 +264,7 @@ typedef struct {
uint8_t hw_recorrect_en;
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */
} esp_bt_controller_config_t;
/**

View File

@ -19,7 +19,7 @@ extern "C" {
#endif
#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
#define ESP_BT_CTRL_CONFIG_VERSION 0x02209230
#define ESP_BT_CTRL_CONFIG_VERSION 0x02212090
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
#define ESP_BT_HCI_TL_VERSION 0x00010000
@ -130,6 +130,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
#endif
#ifndef CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
#define DUPL_SCAN_CACHE_REFRESH_PERIOD 0
#else
#define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
#endif
#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
#else
@ -188,6 +194,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.hw_recorrect_en = AGC_RECORRECT_EN, \
.cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \
.scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \
.dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \
}
#else
@ -256,6 +263,7 @@ typedef struct {
uint8_t hw_recorrect_en;
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */
} esp_bt_controller_config_t;
/**