From 2a2251487b8327af4d4359e9e4b7f03e2e932800 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Tue, 18 Jul 2023 18:09:26 +0800 Subject: [PATCH 1/3] ble update: bugfix for esp32c6 and esp32h2 --- components/bt/controller/esp32c6/Kconfig.in | 13 +++++ components/bt/controller/esp32c6/bt.c | 55 ++++++++++++++++++ components/bt/controller/esp32h2/Kconfig.in | 13 +++++ components/bt/controller/esp32h2/bt.c | 56 ++++++++++++++++++- .../bt/controller/lib_esp32c6/esp32c6-bt-lib | 2 +- .../bt/controller/lib_esp32h2/esp32h2-bt-lib | 2 +- .../bt/include/esp32c6/include/esp_bt.h | 13 +++-- .../bt/include/esp32h2/include/esp_bt.h | 8 +++ 8 files changed, 155 insertions(+), 7 deletions(-) diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 4732abb74ada..e0b6addba8d8 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 58d9dd8a3165..001db9ff2708 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) { @@ -806,6 +834,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(); @@ -825,6 +867,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(); @@ -863,6 +908,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 @@ -1142,6 +1190,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 b836ff7c6f11..9d0d4b7bb4c7 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 320ede06ea83..8ce4d6422d09 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 ddd61e9a2769..d785de0a7c46 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 b207a7da7a97..35bd3cd73520 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 929d73c4bc9f..25a3f7bb5eec 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 4b3c4af32390..67909c9a4282 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 From 3ece525e26a7813ce8d82deacc19f9d8bd695952 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Mon, 24 Jul 2023 10:51:08 +0800 Subject: [PATCH 2/3] ble update for doc: bugfix for esp32c6 and esp32h2 --- components/bt/controller/esp32c6/bt.c | 2 +- components/bt/controller/esp32h2/bt.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 001db9ff2708..e9ef174fe62e 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -389,7 +389,7 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b 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]); diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 8ce4d6422d09..edc590dedc3c 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -381,14 +381,14 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b 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 From c291b026516c73f27d3891ac020ff2c0e7113383 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Mon, 24 Jul 2023 16:18:20 +0800 Subject: [PATCH 3/3] esp_rom_printf --- components/bt/controller/esp32c6/bt.c | 6 +++--- components/bt/controller/esp32h2/bt.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index e9ef174fe62e..65851b84c369 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -387,14 +387,14 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b { if (!end) { for (int i = 0; i < len; i++) { - ets_printf("%02x,", addr[i]); + esp_rom_printf("%02x,", addr[i]); } } else { for (int i = 0; i < len; i++) { - ets_printf("%02x,", addr[i]); + esp_rom_printf("%02x,", addr[i]); } - ets_printf("\n"); + esp_rom_printf("\n"); } } #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index edc590dedc3c..5b3b8f2fa6c9 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -379,14 +379,14 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b { if (!end) { for (int i = 0; i < len; i++) { - ets_printf("%02x,", addr[i]); + esp_rom_printf("%02x,", addr[i]); } } else { for (int i = 0; i < len; i++) { - ets_printf("%02x,", addr[i]); + esp_rom_printf("%02x,", addr[i]); } - ets_printf("\n"); + esp_rom_printf("\n"); } } #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED