diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index dde650827c..3af8ca90cf 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -260,6 +260,19 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task +config BT_LE_CONTROLLER_LOG_ENABLED + bool "Controller log enable" + default n + help + Enable controller log module + +config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode + config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index c314a8a8bb..6d83e3bee1 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -110,12 +110,20 @@ struct ext_funcs_t { uint32_t magic; }; +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* External functions or variables ************************************************************************ */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int ble_controller_init(esp_bt_controller_config_t *cfg); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create); +extern int ble_log_deinit_async(void); +extern void ble_log_async_output_dump_all(bool output); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int ble_controller_deinit(void); extern int ble_controller_enable(uint8_t mode); extern int ble_controller_disable(void); @@ -179,6 +187,9 @@ static void esp_reset_rpa_moudle(void); static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** */ @@ -371,6 +382,23 @@ static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer return rc; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) +{ + if (!end) { + for (int i = 0; i < len; i++) { + ets_printf("%02x,", addr[i]); + } + + } else { + for (int i = 0; i < len; i++) { + ets_printf("%02x,", addr[i]); + } + ets_printf("\n"); + } +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_UART static void hci_uart_start_tx_wrapper(int uart_no) { @@ -807,6 +835,20 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto free_controller; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + interface_func_t bt_controller_log_interface; + bt_controller_log_interface = esp_bt_controller_log_interface; +#if CONFIG_BT_LE_CONTROLLER_LOG_DUMP_ONLY + ret = ble_log_init_async(bt_controller_log_interface, false); +#else + ret = ble_log_init_async(bt_controller_log_interface, true); +#endif // CONFIG_BT_CONTROLLER_LOG_DUMP + if (ret != ESP_OK) { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret); + goto free_controller; + } +#endif // CONFIG_BT_CONTROLLER_LOG_ENABLED + ble_controller_scan_duplicate_config(); ret = controller_sleep_init(); @@ -826,6 +868,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) free_controller: controller_sleep_deinit(); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + ble_log_deinit_async(); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED ble_controller_deinit(); esp_btbb_disable(); esp_phy_disable(); @@ -864,6 +909,9 @@ esp_err_t esp_bt_controller_deinit(void) modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_module_disable(PERIPH_BT_MODULE); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + ble_log_deinit_async(); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED ble_controller_deinit(); #if CONFIG_BT_NIMBLE_ENABLED @@ -1143,6 +1191,13 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po return (esp_power_level_t)tx_level; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_async_output_dump_all(output); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED == true) #define BLE_SM_KEY_ERR 0x17 diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 7d8d7463d4..454a054bf9 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -260,6 +260,19 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task +config BT_LE_CONTROLLER_LOG_ENABLED + bool "Controller log enable" + default n + help + Enable controller log module + +config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode + config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 75bcd995e9..5550ffe969 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -107,12 +107,19 @@ struct ext_funcs_t { uint32_t magic; }; - +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* External functions or variables ************************************************************************ */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int ble_controller_init(esp_bt_controller_config_t *cfg); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create); +extern int ble_log_deinit_async(void); +extern void ble_log_async_output_dump_all(bool output); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int ble_controller_deinit(void); extern int ble_controller_enable(uint8_t mode); extern int ble_controller_disable(void); @@ -176,6 +183,9 @@ static void esp_reset_rpa_moudle(void); static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** */ @@ -364,6 +374,23 @@ static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer return rc; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) +{ + if (!end) { + for (int i = 0; i < len; i++) { + ets_printf("%02x,", addr[i]); + } + + } else { + for (int i = 0; i < len; i++) { + ets_printf("%02x,", addr[i]); + } + ets_printf("\n"); + } +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_UART static void hci_uart_start_tx_wrapper(int uart_no) { @@ -788,6 +815,20 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto free_controller; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + interface_func_t bt_controller_log_interface; + bt_controller_log_interface = esp_bt_controller_log_interface; +#if CONFIG_BT_LE_CONTROLLER_LOG_DUMP_ONLY + ret = ble_log_init_async(bt_controller_log_interface, false); +#else + ret = ble_log_init_async(bt_controller_log_interface, true); +#endif // CONFIG_BT_CONTROLLER_LOG_DUMP + if (ret != ESP_OK) { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret); + goto free_controller; + } +#endif // CONFIG_BT_CONTROLLER_LOG_ENABLED + ble_controller_scan_duplicate_config(); ret = controller_sleep_init(); @@ -808,6 +849,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) free_controller: controller_sleep_deinit(); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + ble_log_deinit_async(); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED ble_controller_deinit(); esp_btbb_disable(); esp_phy_disable(); @@ -844,6 +888,9 @@ esp_err_t esp_bt_controller_deinit(void) modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_module_disable(PERIPH_BT_MODULE); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + ble_log_deinit_async(); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED ble_controller_deinit(); #if CONFIG_BT_NIMBLE_ENABLED @@ -1123,6 +1170,13 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po return (esp_power_level_t)tx_level; } +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_async_output_dump_all(output); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED == true) #define BLE_SM_KEY_ERR 0x17 diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index ddd61e9a27..d785de0a7c 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit ddd61e9a276926496437665dd217cba2850db6b9 +Subproject commit d785de0a7c46d9badcd73bc83c2e5cb78f7054b2 diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index b207a7da7a..35bd3cd735 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit b207a7da7a9758dbccea0dba1023fd36c47b3e65 +Subproject commit 35bd3cd7352014d303a96c46d8ea8446ea0a9a54 diff --git a/components/bt/include/esp32c6/include/esp_bt.h b/components/bt/include/esp32c6/include/esp_bt.h index 929d73c4bc..25a3f7bb5e 100644 --- a/components/bt/include/esp32c6/include/esp_bt.h +++ b/components/bt/include/esp32c6/include/esp_bt.h @@ -76,9 +76,6 @@ typedef enum { * @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm). */ typedef enum { - ESP_PWR_LVL_N24 = 0, /*!< Corresponding to -24dbm */ - ESP_PWR_LVL_N21 = 1, /*!< Corresponding to -21dbm */ - ESP_PWR_LVL_N18 = 2, /*!< Corresponding to -18dbm */ ESP_PWR_LVL_N15 = 3, /*!< Corresponding to -15dbm */ ESP_PWR_LVL_N12 = 4, /*!< Corresponding to -12dbm */ ESP_PWR_LVL_N9 = 5, /*!< Corresponding to -9dbm */ @@ -91,7 +88,7 @@ typedef enum { ESP_PWR_LVL_P12 = 12, /*!< Corresponding to +12dbm */ ESP_PWR_LVL_P15 = 13, /*!< Corresponding to +15dbm */ ESP_PWR_LVL_P18 = 14, /*!< Corresponding to +18dbm */ - ESP_PWR_LVL_P21 = 15, /*!< Corresponding to +21dbm */ + ESP_PWR_LVL_P20 = 15, /*!< Corresponding to +20dbm */ ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */ } esp_power_level_t; @@ -367,6 +364,14 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode); /* Returns random static address or -1 if not present */ extern int esp_ble_hw_get_static_addr(esp_ble_addr_t *addr); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +/** @brief esp_ble_controller_log_dump_all + * dump all controller log information cached in buffer + * @param output : true for log dump, false will be no effect + */ +void esp_ble_controller_log_dump_all(bool output); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #ifdef __cplusplus } #endif diff --git a/components/bt/include/esp32h2/include/esp_bt.h b/components/bt/include/esp32h2/include/esp_bt.h index 4b3c4af323..67909c9a42 100644 --- a/components/bt/include/esp32h2/include/esp_bt.h +++ b/components/bt/include/esp32h2/include/esp_bt.h @@ -368,6 +368,14 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode); /* Returns random static address or -1 if not present */ extern int esp_ble_hw_get_static_addr(esp_ble_addr_t *addr); +#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +/** @brief esp_ble_controller_log_dump_all + * dump all controller log information cached in buffer + * @param output : true for log dump, false will be no effect + */ +void esp_ble_controller_log_dump_all(bool output); +#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED + #ifdef __cplusplus } #endif