From 11289ffe866c9b243d61c4eeb40693b7c28b1b96 Mon Sep 17 00:00:00 2001 From: Shen Weilong Date: Mon, 17 Mar 2025 18:11:31 +0800 Subject: [PATCH] feat(ble/controller): Added memory boundary check for ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 4 ++ components/bt/controller/esp32c5/ble.c | 52 +++++++++++++++++++ components/bt/controller/esp32c5/esp_bt_cfg.h | 6 +++ .../bt/controller/lib_esp32c5/esp32c5-bt-lib | 2 +- .../bt/include/esp32c5/include/esp_bt.h | 2 + 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 5058bf0fb3..fbd1269355 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -402,6 +402,10 @@ menu "Controller debug features" default n help Retain scene with GDB to capture info, requires disabling WDT (CONFIG_ESP_INT_WDT, CONFIG_ESP_TASK_WDT_EN). + + config BT_LE_PTR_CHECK_ENABLED + bool "Enable boundary check for internal memory" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE diff --git a/components/bt/controller/esp32c5/ble.c b/components/bt/controller/esp32c5/ble.c index 3aca469ee1..caa8d85543 100644 --- a/components/bt/controller/esp32c5/ble.c +++ b/components/bt/controller/esp32c5/ble.c @@ -7,6 +7,7 @@ #include "sdkconfig.h" #include "esp_bt_cfg.h" +#include "esp_bit_defs.h" /* External functions or variables ************************************************************************ @@ -28,9 +29,50 @@ int conn_errorSim_enable(void); void conn_errorSim_disable(void); #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void adv_stack_enableClearLegacyAdvVsCmd(bool en); +void scan_stack_enableAdvFlowCtrlVsCmd(bool en); +void advFilter_stack_enableDupExcListVsCmd(bool en); +void arr_stack_enableMultiConnVsCmd(bool en); +void pcl_stack_enableSetRssiThreshVsCmd(bool en); +void chanSel_stack_enableSetCsaVsCmd(bool en); +void log_stack_enableLogsRelatedVsCmd(bool en); +void hci_stack_enableSetVsEvtMaskVsCmd(bool en); +void winWiden_stack_enableSetConstPeerScaVsCmd(bool en); + +void adv_stack_enableScanReqRxdVsEvent(bool en); +void conn_stack_enableChanMapUpdCompVsEvent(bool en); +void sleep_stack_enableWakeupVsEvent(bool en); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + /* Local functions definition *************************************************************************** */ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void ble_stack_enableVsCmds(bool en) +{ + adv_stack_enableClearLegacyAdvVsCmd(en); + advFilter_stack_enableDupExcListVsCmd(en); + scan_stack_enableAdvFlowCtrlVsCmd(en); + arr_stack_enableMultiConnVsCmd(en); + pcl_stack_enableSetRssiThreshVsCmd(en); + chanSel_stack_enableSetCsaVsCmd(en); + log_stack_enableLogsRelatedVsCmd(en); + hci_stack_enableSetVsEvtMaskVsCmd(en); + winWiden_stack_enableSetConstPeerScaVsCmd(en); +} + +void ble_stack_enableVsEvents(bool en) +{ + adv_stack_enableScanReqRxdVsEvent(en); + conn_stack_enableChanMapUpdCompVsEvent(en); + +#if CONFIG_BT_LE_SLEEP_ENABLE + sleep_stack_enableWakeupVsEvent(en); +#endif // CONFIG_BT_LE_SLEEP_ENABLE +} +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + int ble_stack_initEnv(void) { int rc; @@ -90,11 +132,21 @@ int ble_stack_enable(void) #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED #endif // DEFAULT_BT_LE_MAX_CONNECTIONS +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsCmds(true); + ble_stack_enableVsEvents(true); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + return 0; } void ble_stack_disable(void) { +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsEvents(false); + ble_stack_enableVsCmds(false); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + #if DEFAULT_BT_LE_MAX_CONNECTIONS #if CONFIG_BT_LE_ERROR_SIM_ENABLED conn_errorSim_disable(); diff --git a/components/bt/controller/esp32c5/esp_bt_cfg.h b/components/bt/controller/esp32c5/esp_bt_cfg.h index 3d8edd55de..6621c28cb4 100644 --- a/components/bt/controller/esp32c5/esp_bt_cfg.h +++ b/components/bt/controller/esp32c5/esp_bt_cfg.h @@ -204,6 +204,12 @@ extern "C" { #define DEFAULT_BT_LE_VHCI_ENABLED (0) #endif +#ifdef CONFIG_BT_LE_PTR_CHECK_ENABLED +#define DEFAULT_BT_LE_PTR_CHECK_ENABLED (CONFIG_BT_LE_PTR_CHECK_ENABLED) +#else +#define DEFAULT_BT_LE_PTR_CHECK_ENABLED (0) +#endif + #ifdef CONFIG_BT_LE_SLEEP_ENABLE #define NIMBLE_SLEEP_ENABLE CONFIG_BT_LE_SLEEP_ENABLE #else diff --git a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib index b4d27797cd..4ff56a052a 160000 --- a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib +++ b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib @@ -1 +1 @@ -Subproject commit b4d27797cdfa3b21e44c2bdfdf3a09c48f7700be +Subproject commit 4ff56a052ab888be3b4abe548f86052fa314d10c diff --git a/components/bt/include/esp32c5/include/esp_bt.h b/components/bt/include/esp32c5/include/esp_bt.h index d045553168..ec292a573d 100644 --- a/components/bt/include/esp32c5/include/esp_bt.h +++ b/components/bt/include/esp32c5/include/esp_bt.h @@ -225,6 +225,7 @@ typedef struct { - 0 - Disable (default) - 1 - Enable */ uint8_t vhci_enabled; /*!< VHCI mode is enabled */ + uint8_t ptr_check_enabled; /*!< Enable boundary check for internal memory. */ uint32_t config_magic; /*!< Magic number for configuration validation */ } esp_bt_controller_config_t; @@ -279,6 +280,7 @@ typedef struct { .ble_chan_ass_en = DEFAULT_BT_LE_CTRL_CHAN_ASS_EN, \ .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .vhci_enabled = DEFAULT_BT_LE_VHCI_ENABLED, \ + .ptr_check_enabled = DEFAULT_BT_LE_PTR_CHECK_ENABLED, \ .config_magic = CONFIG_MAGIC, \ }