From aeff03bac4ea7a96acb1b74f37a5f56752a3bb8c Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 18 Feb 2025 11:46:07 +0800 Subject: [PATCH] feat(ble): implement ble capture info user handler on ESP32-C6 and ESP32-H2 --- components/bt/controller/esp32c6/Kconfig.in | 8 +++++-- components/bt/controller/esp32c6/bt.c | 26 +++++++++++++++++++++ components/bt/controller/esp32h2/Kconfig.in | 8 +++++-- components/bt/controller/esp32h2/bt.c | 26 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 230fbb08f5..77ad51cf02 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -424,6 +424,10 @@ menu "Controller debug features" config BT_LE_ERROR_SIM_ENABLED bool "Enable controller features for internal testing" default n + + config BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + bool "When ACL disconnects abnormally, assertion processing is performed(Experimental)" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE @@ -782,14 +786,14 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX The value of upperlimitmax needs to be a power of 2. config BT_LE_CTRL_CHAN_ASS_EN - bool "Enable channel assessment" + bool "Enable channel assessment(Experimental)" default n help If this option is enabled, The Controller will records the communication quality for each channel and then start a timer to check and update the channel map every 4 seconds. config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX - bool "Enable aux packet when ext adv data length is zero" + bool "Enable aux packet when ext adv data length is zero(Experimental)" default y help When this option is enabled, auxiliary packets will be present in the events of diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 983764e767..5af71a487b 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -115,6 +115,7 @@ typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int r_ble_controller_init(esp_bt_controller_config_t *cfg); +extern void esp_ble_controller_info_capture(uint32_t cycle_times); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); @@ -1659,3 +1660,28 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv) #endif // CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC #endif // (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) + +int IRAM_ATTR +ble_capture_info_user_handler(uint8_t type, uint32_t reason) +{ + int i; + + switch(type) { + case 0: + for (i = 0; i < 2; i++) { + esp_ble_controller_info_capture(0x010101); + } + + break; +#if CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + case 1: + if ((reason == 0x08) || (reason == 0x3d) || (reason == 0x28)) { + osi_assert_wrapper(__LINE__,__func__, type, reason); + } + break; +#endif // CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + default: + break; + } + return 0; +} diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 8aaed93f0e..92299131fe 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -415,6 +415,10 @@ menu "Controller debug features" config BT_LE_ERROR_SIM_ENABLED bool "Enable controller features for internal testing" default n + + config BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + bool "When ACL disconnects abnormally, assertion processing is performed(Experimental)" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE @@ -783,14 +787,14 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX The value of upperlimitmax needs to be a power of 2. config BT_LE_CTRL_CHAN_ASS_EN - bool "Enable channel assessment" + bool "Enable channel assessment(Experimental)" default n help If this option is enabled, The Controller will records the communication quality for each channel and then start a timer to check and update the channel map every 4 seconds. config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX - bool "Enable aux packet when ext adv data length is zero" + bool "Enable aux packet when ext adv data length is zero(Experimental)" default y help When this option is enabled, auxiliary packets will be present in the events of diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 9a7e115a97..cc4220d163 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -110,6 +110,7 @@ typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int r_ble_controller_init(esp_bt_controller_config_t *cfg); +extern void esp_ble_controller_info_capture(uint32_t cycle_times); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); @@ -1632,3 +1633,28 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv) #endif // CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC #endif // (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) + +int IRAM_ATTR +ble_capture_info_user_handler(uint8_t type, uint32_t reason) +{ + int i; + + switch(type) { + case 0: + for (i = 0; i < 2; i++) { + esp_ble_controller_info_capture(0x010101); + } + + break; +#if CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + case 1: + if ((reason == 0x08) || (reason == 0x3d) || (reason == 0x28)) { + osi_assert_wrapper(__LINE__,__func__, type, reason); + } + break; +#endif // CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + default: + break; + } + return 0; +}