From 7310ab3589e00bcd8fa1220c982f8f5db07aeedf Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 18 Mar 2024 15:57:46 +0530 Subject: [PATCH 01/18] fix(nimble): Handle auto connection flag for extended connect --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 3705a21d499c..2059a808526b 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 3705a21d499cc9b8f584e8468ff7e82cc5452a4c +Subproject commit 2059a808526b08660d089e31d7929646d8bdd33e From 50ea662fe0645330f843a0867dd4d641582fff8e Mon Sep 17 00:00:00 2001 From: cjin Date: Wed, 20 Mar 2024 12:01:35 +0800 Subject: [PATCH 02/18] fix(ble): fix ci ble powe save test addresss error --- examples/bluetooth/nimble/blecent/main/main.c | 22 +++++++++++++++++++ .../bluetooth/nimble/blecent/sdkconfig.ci | 2 +- .../blecent/sdkconfig.ci.esp32c2_xtal26m | 2 +- .../bluetooth/nimble/power_save/main/main.c | 21 ++++++++++++++++++ .../bluetooth/nimble/power_save/sdkconfig.ci | 2 +- .../power_save/sdkconfig.ci.esp32c2_xtal26m | 2 +- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 8e7222b9136f..ef62105893e4 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -28,6 +28,26 @@ #include "services/gap/ble_svc_gap.h" #include "blecent.h" +#if CONFIG_EXAMPLE_USE_CI_ADDRESS +#ifdef CONFIG_IDF_TARGET_ESP32 +#define TEST_CI_ADDRESS_CHIP_OFFSET (0) +#elif CONFIG_IDF_TARGET_ESP32C2 +#define TEST_CI_ADDRESS_CHIP_OFFSET (1) +#elif CONFIG_IDF_TARGET_ESP32C3 +#define TEST_CI_ADDRESS_CHIP_OFFSET (2) +#elif CONFIG_IDF_TARGET_ESP32C6 +#define TEST_CI_ADDRESS_CHIP_OFFSET (3) +#elif CONFIG_IDF_TARGET_ESP32C5 +#define TEST_CI_ADDRESS_CHIP_OFFSET (4) +#elif CONFIG_IDF_TARGET_ESP32H2 +#define TEST_CI_ADDRESS_CHIP_OFFSET (5) +#elif CONFIG_IDF_TARGET_ESP32P4 +#define TEST_CI_ADDRESS_CHIP_OFFSET (6) +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TEST_CI_ADDRESS_CHIP_OFFSET (7) +#endif +#endif + /*** The UUID of the service containing the subscribable characterstic ***/ static const ble_uuid_t * remote_svc_uuid = BLE_UUID128_DECLARE(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12, @@ -474,6 +494,7 @@ ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc) addr_offset = (uint32_t *)&peer_addr[1]; *addr_offset = atoi(CONFIG_EXAMPLE_PEER_ADDR); peer_addr[5] = 0xC3; + peer_addr[0] = TEST_CI_ADDRESS_CHIP_OFFSET; #endif // !CONFIG_EXAMPLE_USE_CI_ADDRESS if (memcmp(peer_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) { return 0; @@ -537,6 +558,7 @@ blecent_should_connect(const struct ble_gap_disc_desc *disc) addr_offset = (uint32_t *)&peer_addr[1]; *addr_offset = atoi(CONFIG_EXAMPLE_PEER_ADDR); peer_addr[5] = 0xC3; + peer_addr[0] = TEST_CI_ADDRESS_CHIP_OFFSET; #endif // !CONFIG_EXAMPLE_USE_CI_ADDRESS if (memcmp(peer_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) { return 0; diff --git a/examples/bluetooth/nimble/blecent/sdkconfig.ci b/examples/bluetooth/nimble/blecent/sdkconfig.ci index ac6390187d87..8c7c3144decf 100644 --- a/examples/bluetooth/nimble/blecent/sdkconfig.ci +++ b/examples/bluetooth/nimble/blecent/sdkconfig.ci @@ -1,2 +1,2 @@ CONFIG_EXAMPLE_USE_CI_ADDRESS=y -CONFIG_EXAMPLE_PEER_ADDR="${CI_JOB_ID}" +CONFIG_EXAMPLE_PEER_ADDR="${CI_PIPELINE_ID}" diff --git a/examples/bluetooth/nimble/blecent/sdkconfig.ci.esp32c2_xtal26m b/examples/bluetooth/nimble/blecent/sdkconfig.ci.esp32c2_xtal26m index c82bb2469224..91a180954c06 100644 --- a/examples/bluetooth/nimble/blecent/sdkconfig.ci.esp32c2_xtal26m +++ b/examples/bluetooth/nimble/blecent/sdkconfig.ci.esp32c2_xtal26m @@ -1,4 +1,4 @@ CONFIG_IDF_TARGET="esp32c2" CONFIG_XTAL_FREQ_26=y CONFIG_EXAMPLE_USE_CI_ADDRESS=y -CONFIG_EXAMPLE_PEER_ADDR="${CI_JOB_ID}" +CONFIG_EXAMPLE_PEER_ADDR="${CI_PIPELINE_ID}" diff --git a/examples/bluetooth/nimble/power_save/main/main.c b/examples/bluetooth/nimble/power_save/main/main.c index 422a0a092d63..3e1a5acc28a0 100644 --- a/examples/bluetooth/nimble/power_save/main/main.c +++ b/examples/bluetooth/nimble/power_save/main/main.c @@ -17,6 +17,26 @@ #include "services/gap/ble_svc_gap.h" #include "bleprph.h" +#if CONFIG_EXAMPLE_USE_CI_ADDRESS +#ifdef CONFIG_IDF_TARGET_ESP32 +#define TEST_CI_ADDRESS_CHIP_OFFSET (0) +#elif CONFIG_IDF_TARGET_ESP32C2 +#define TEST_CI_ADDRESS_CHIP_OFFSET (1) +#elif CONFIG_IDF_TARGET_ESP32C3 +#define TEST_CI_ADDRESS_CHIP_OFFSET (2) +#elif CONFIG_IDF_TARGET_ESP32C6 +#define TEST_CI_ADDRESS_CHIP_OFFSET (3) +#elif CONFIG_IDF_TARGET_ESP32C5 +#define TEST_CI_ADDRESS_CHIP_OFFSET (4) +#elif CONFIG_IDF_TARGET_ESP32H2 +#define TEST_CI_ADDRESS_CHIP_OFFSET (5) +#elif CONFIG_IDF_TARGET_ESP32P4 +#define TEST_CI_ADDRESS_CHIP_OFFSET (6) +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TEST_CI_ADDRESS_CHIP_OFFSET (7) +#endif +#endif + #if CONFIG_EXAMPLE_EXTENDED_ADV static uint8_t ext_adv_pattern_1[] = { 0x02, 0x01, 0x06, @@ -468,6 +488,7 @@ bleprph_on_sync(void) uint32_t *offset = (uint32_t *)&addr[1]; *offset = atoi(CONFIG_EXAMPLE_CI_ADDRESS_OFFSET); addr[5] = 0xC3; + addr[0] = TEST_CI_ADDRESS_CHIP_OFFSET; rc = ble_hs_id_set_rnd(addr); assert(rc == 0); } diff --git a/examples/bluetooth/nimble/power_save/sdkconfig.ci b/examples/bluetooth/nimble/power_save/sdkconfig.ci index a466b75320e1..3fa8fb844c6d 100644 --- a/examples/bluetooth/nimble/power_save/sdkconfig.ci +++ b/examples/bluetooth/nimble/power_save/sdkconfig.ci @@ -2,4 +2,4 @@ # Test Config # CONFIG_EXAMPLE_USE_CI_ADDRESS=y -CONFIG_EXAMPLE_CI_ADDRESS_OFFSET="${CI_JOB_ID}" +CONFIG_EXAMPLE_CI_ADDRESS_OFFSET="${CI_PIPELINE_ID}" diff --git a/examples/bluetooth/nimble/power_save/sdkconfig.ci.esp32c2_xtal26m b/examples/bluetooth/nimble/power_save/sdkconfig.ci.esp32c2_xtal26m index 69cdde9cd5eb..4c6f1bd53371 100644 --- a/examples/bluetooth/nimble/power_save/sdkconfig.ci.esp32c2_xtal26m +++ b/examples/bluetooth/nimble/power_save/sdkconfig.ci.esp32c2_xtal26m @@ -4,4 +4,4 @@ CONFIG_XTAL_FREQ_26=y # Test Config # CONFIG_EXAMPLE_USE_CI_ADDRESS=y -CONFIG_EXAMPLE_CI_ADDRESS_OFFSET="${CI_JOB_ID}" +CONFIG_EXAMPLE_CI_ADDRESS_OFFSET="${CI_PIPELINE_ID}" From 1830bc4d296f101b04333bb93404c14e147ae511 Mon Sep 17 00:00:00 2001 From: jgujarathi Date: Mon, 4 Mar 2024 12:08:51 +0530 Subject: [PATCH 03/18] fix(wpa_supplicant): Ensure dpp auth structure is deinited in dpp task context - Ensure that the dpp auth data gets deinited only in DPP task context to ensure that there are no concurrency issues in usage of DPP auth data. --- .../esp_supplicant/src/esp_dpp.c | 30 ++++++++++++++----- .../esp_supplicant/src/esp_dpp_i.h | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c index 83ef62caa224..3ece743f01b9 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -63,20 +63,31 @@ static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data) if (evt_id != SIG_DPP_DEL_TASK) { DPP_API_UNLOCK(); } + wpa_printf(MSG_DEBUG,"DPP: Sent event %d to DPP task", evt_id); return ret; end: if (evt) { os_free(evt); } + wpa_printf(MSG_ERROR,"DPP: Failed to send event %d to DPP task", evt_id); return ret; } +static uint8_t esp_dpp_deinit_auth(void) +{ + esp_err_t ret = esp_dpp_post_evt(SIG_DPP_DEINIT_AUTH, 0); + if (ESP_OK != ret) { + wpa_printf(MSG_ERROR, "Failed to post DPP auth deinit to DPP Task(status=%d)", ret); + return ret; + } + return ESP_OK; +} + static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data) { if ( evt == ESP_SUPP_DPP_FAIL && s_dpp_ctx.dpp_auth) { - dpp_auth_deinit(s_dpp_ctx.dpp_auth); - s_dpp_ctx.dpp_auth = NULL; + esp_dpp_deinit_auth(); } s_dpp_ctx.dpp_event_cb(evt, data); } @@ -88,10 +99,6 @@ static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx) wpa_printf(MSG_DEBUG, "DPP: Terminate authentication exchange due to Auth Confirm timeout"); - if (s_dpp_ctx.dpp_auth) { - dpp_auth_deinit(s_dpp_ctx.dpp_auth); - s_dpp_ctx.dpp_auth = NULL; - } esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_AUTH_TIMEOUT); } @@ -438,6 +445,15 @@ static void esp_dpp_task(void *pvParameters ) } break; + case SIG_DPP_DEINIT_AUTH: { + if (s_dpp_ctx.dpp_auth) { + dpp_auth_deinit(s_dpp_ctx.dpp_auth); + s_dpp_ctx.dpp_auth = NULL; + } + wpa_printf(MSG_DEBUG, "DPP auth deinintialized"); + } + break; + default: break; } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h index 2e97d1aa39c5..1208eba63aa8 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h @@ -23,6 +23,7 @@ enum SIG_DPP { SIG_DPP_RX_ACTION, SIG_DPP_LISTEN_NEXT_CHANNEL, SIG_DPP_DEL_TASK, + SIG_DPP_DEINIT_AUTH, SIG_DPP_MAX, }; From 6115e2500ae119fa3c532bc92229d58bcc3f5c9c Mon Sep 17 00:00:00 2001 From: jgujarathi Date: Mon, 4 Mar 2024 15:41:44 +0530 Subject: [PATCH 04/18] fix(wpa_supplicant): Cancel offchannel listen operations before sending dpp fail - Ensure that offchannel listening operations are cancelled before sending dpp fail events --- components/wpa_supplicant/esp_supplicant/src/esp_dpp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c index 3ece743f01b9..330d78a3159d 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c @@ -234,8 +234,9 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth, wpa_printf(MSG_INFO, DPP_EVENT_CONNECTOR "%s", conf->connector); } - s_dpp_listen_in_progress = true; - esp_wifi_action_tx_req(WIFI_OFFCHAN_TX_CANCEL, 0, 0, NULL); + if (s_dpp_listen_in_progress) { + esp_supp_dpp_stop_listen(); + } esp_dpp_call_cb(ESP_SUPP_DPP_CFG_RECVD, wifi_cfg); return 0; @@ -524,6 +525,9 @@ static void offchan_event_handler(void *arg, esp_event_base_t event_base, if (evt->status) { eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); + if (s_dpp_listen_in_progress) { + esp_supp_dpp_stop_listen(); + } esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); } From 413bcd8fcdf507e3ba3df7c64289b44bc25fefc1 Mon Sep 17 00:00:00 2001 From: Nachiket Kukade Date: Tue, 26 Mar 2024 11:45:25 +0530 Subject: [PATCH 05/18] feat(esp_wifi): Refactor and improve FTM code Enable FTM Responder mode for ESP32C6. Update wifi libs with below - 1. Break FTM State Machine code into separate functions 2. Use dynamic allocation for FTM session to save memory 3. Add API to get FTM report instead of event based mechanism 4. Add FTM Request retry and comeback support --- components/esp_wifi/include/esp_wifi.h | 20 +++++ components/esp_wifi/include/esp_wifi_types.h | 11 ++- components/esp_wifi/lib | 2 +- components/esp_wifi/src/wifi_init.c | 15 +++- .../esp32c6/include/soc/Kconfig.soc_caps.in | 2 +- components/soc/esp32c6/include/soc/soc_caps.h | 2 +- docs/en/api-guides/wifi.rst | 8 +- examples/wifi/ftm/README.md | 4 +- examples/wifi/ftm/main/ftm_main.c | 90 +++++++++++++------ 9 files changed, 116 insertions(+), 38 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index a268ad8ada77..27c71fa6957a 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1294,6 +1294,26 @@ esp_err_t esp_wifi_ftm_end_session(void); */ esp_err_t esp_wifi_ftm_resp_set_offset(int16_t offset_cm); +/** + * @brief Get FTM measurements report copied into a user provided buffer. + * + * @attention 1. To get the FTM report, user first needs to allocate a buffer of size + * (sizeof(wifi_ftm_report_entry_t) * num_entries) where the API will fill up to num_entries + * valid FTM measurements in the buffer. Total number of entries can be found in the event + * WIFI_EVENT_FTM_REPORT as ftm_report_num_entries + * @attention 2. The internal FTM report is freed upon use of this API which means the API can only be used + * once afer every FTM session initiated + * @attention 3. Passing the buffer as NULL merely frees the FTM report + * + * @param report Pointer to the buffer for receiving the FTM report + * @param num_entries Number of FTM report entries to be filled in the report + * + * @return + * - ESP_OK: succeed + * - others: failed + */ +esp_err_t esp_wifi_ftm_get_report(wifi_ftm_report_entry_t *report, uint8_t num_entries); + /** * @brief Enable or disable 11b rate of specified interface * diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index 62aca03a4eed..a6688cab4ec0 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -661,7 +661,9 @@ typedef struct { uint8_t resp_mac[6]; /**< MAC address of the FTM Responder */ uint8_t channel; /**< Primary channel of the FTM Responder */ uint8_t frm_count; /**< No. of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0(No pref), 16, 24, 32, 64) */ - uint16_t burst_period; /**< Requested time period between consecutive FTM bursts in 100's of milliseconds (0 - No pref) */ + uint16_t burst_period; /**< Requested period between FTM bursts in 100's of milliseconds (allowed values 0(No pref) - 100) */ + bool use_get_report_api; /**< True - Using esp_wifi_ftm_get_report to get FTM report, False - Using ftm_report_data from + WIFI_EVENT_FTM_REPORT to get FTM report */ } wifi_ftm_initiator_cfg_t; /** @@ -1015,6 +1017,8 @@ typedef enum { FTM_STATUS_CONF_REJECTED, /**< Peer rejected FTM configuration in FTM Request */ FTM_STATUS_NO_RESPONSE, /**< Peer did not respond to FTM Requests */ FTM_STATUS_FAIL, /**< Unknown error during FTM exchange */ + FTM_STATUS_NO_VALID_MSMT, /**< FTM session did not result in any valid measurements */ + FTM_STATUS_USER_TERM, /**< User triggered termination */ } wifi_ftm_status_t; /** Argument structure for */ @@ -1035,7 +1039,8 @@ typedef struct { uint32_t rtt_raw; /**< Raw average Round-Trip-Time with peer in Nano-Seconds */ uint32_t rtt_est; /**< Estimated Round-Trip-Time with peer in Nano-Seconds */ uint32_t dist_est; /**< Estimated one-way distance in Centi-Meters */ - wifi_ftm_report_entry_t *ftm_report_data; /**< Pointer to FTM Report with multiple entries, should be freed after use */ + wifi_ftm_report_entry_t *ftm_report_data; /**< Pointer to FTM Report, should be freed after use. Note: Highly recommended + to use API esp_wifi_ftm_get_report to get the report instead of using this */ uint8_t ftm_report_num_entries; /**< Number of entries in the FTM Report data */ } wifi_event_ftm_report_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 25e4696bc346..bb386048d34c 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 25e4696bc346576c48d76f9e0c7cf1e6d3de909e +Subproject commit bb386048d34c44dbb2295d33b78540ecb8560f8e diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 73b11acf9abf..4d4e741643bc 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -25,6 +25,9 @@ #ifdef CONFIG_ESP_WIFI_NAN_ENABLE #include "apps_private/wifi_apps_private.h" #endif +#ifdef CONFIG_ESP_WIFI_FTM_ENABLE +#include "esp_chip_info.h" +#endif static bool s_wifi_inited = false; @@ -318,6 +321,13 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) #endif esp_wifi_set_log_level(); esp_wifi_power_domain_on(); +#ifdef CONFIG_ESP_WIFI_FTM_ENABLE + esp_chip_info_t info = {0}; + esp_chip_info(&info); + if (info.model == CHIP_ESP32C6 && info.revision <= 1) { + ((wifi_init_config_t *)config)->feature_caps &= ~(CONFIG_FEATURE_FTM_INITIATOR_BIT); + } +#endif result = esp_wifi_init_internal(config); if (result == ESP_OK) { #if CONFIG_MAC_BB_PD @@ -395,9 +405,10 @@ void wifi_apb80m_release(void) #endif //CONFIG_PM_ENABLE #ifndef CONFIG_ESP_WIFI_FTM_ENABLE -void ieee80211_ftm_attach(void) +esp_err_t ieee80211_ftm_attach(void) { /* Do not remove, stub to overwrite weak link in Wi-Fi Lib */ + return ESP_OK; } #endif diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 20ab5acbc19e..de9120b45afb 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1325,7 +1325,7 @@ config SOC_WIFI_HW_TSF config SOC_WIFI_FTM_SUPPORT bool - default n + default y config SOC_WIFI_GCMP_SUPPORT bool diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index e44aa04ae421..a5263b81682f 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -544,7 +544,7 @@ /*------------------------------------ WI-FI CAPS ------------------------------------*/ #define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */ -#define SOC_WIFI_FTM_SUPPORT (0) /*!< Support FTM */ +#define SOC_WIFI_FTM_SUPPORT (1) /*!< Support FTM */ #define SOC_WIFI_GCMP_SUPPORT (1) /*!< Support GCMP(GCMP128 and GCMP256) */ #define SOC_WIFI_WAPI_SUPPORT (1) /*!< Support WAPI */ #define SOC_WIFI_CSI_SUPPORT (1) /*!< Support CSI */ diff --git a/docs/en/api-guides/wifi.rst b/docs/en/api-guides/wifi.rst index 9c1b4d0fe853..da04682d99e5 100644 --- a/docs/en/api-guides/wifi.rst +++ b/docs/en/api-guides/wifi.rst @@ -1745,7 +1745,13 @@ A config option :ref:`CONFIG_ESP_WIFI_11R_SUPPORT` and configuration parameter : - {IDF_TARGET_NAME} as FTM Initiator in station mode. - {IDF_TARGET_NAME} as FTM Responder in AP mode. - Distance measurement using RTT is not accurate, and factors such as RF interference, multi-path travel, antenna orientation, and lack of calibration increase these inaccuracies. For better results, it is suggested to perform FTM between two ESP32 chip series devices (except ESP32-C2) as station and AP. +.. only:: esp32c6 + + {IDF_TARGET_NAME} ECO1 and older versions do not support FTM Initiator mode. + +.. attention:: + + Distance measurement using RTT is not accurate, and factors such as RF interference, multi-path travel, antenna orientation, and lack of calibration increase these inaccuracies. For better results, it is suggested to perform FTM between two ESP32 chip series devices as station and AP. Refer to ESP-IDF example :idf_file:`examples/wifi/ftm/README.md` for steps on how to set up and perform FTM. diff --git a/examples/wifi/ftm/README.md b/examples/wifi/ftm/README.md index d585ee76a159..1928681dfce0 100644 --- a/examples/wifi/ftm/README.md +++ b/examples/wifi/ftm/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | -| ----------------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | -------- | # FTM Example diff --git a/examples/wifi/ftm/main/ftm_main.c b/examples/wifi/ftm/main/ftm_main.c index bc8e27fada82..29f783e66c55 100644 --- a/examples/wifi/ftm/main/ftm_main.c +++ b/examples/wifi/ftm/main/ftm_main.c @@ -70,6 +70,8 @@ wifi_config_t g_ap_config = { #define ETH_ALEN 6 #define MAX_CONNECT_RETRY_ATTEMPTS 5 +#define DEFAULT_WAIT_TIME_MS (10 * 1000) +#define MAX_FTM_BURSTS 8 #define DEFAULT_AP_CHANNEL 1 #define DEFAULT_AP_BANDWIDTH 20 @@ -85,7 +87,6 @@ static const int DISCONNECTED_BIT = BIT1; static EventGroupHandle_t s_ftm_event_group; static const int FTM_REPORT_BIT = BIT0; static const int FTM_FAILURE_BIT = BIT1; -static wifi_ftm_report_entry_t *s_ftm_report; static uint8_t s_ftm_report_num_entries; static uint32_t s_rtt_est, s_dist_est; static bool s_ap_started; @@ -137,10 +138,12 @@ static void event_handler(void *arg, esp_event_base_t event_base, s_rtt_est = event->rtt_est; s_dist_est = event->dist_est; - s_ftm_report = event->ftm_report_data; s_ftm_report_num_entries = event->ftm_report_num_entries; if (event->status == FTM_STATUS_SUCCESS) { xEventGroupSetBits(s_ftm_event_group, FTM_REPORT_BIT); + } else if (event->status == FTM_STATUS_USER_TERM) { + /* Do Nothing */ + ESP_LOGI(TAG_STA, "User terminated FTM procedure"); } else { ESP_LOGI(TAG_STA, "FTM procedure with Peer("MACSTR") failed! (Status - %d)", MAC2STR(event->peer_mac), event->status); @@ -153,21 +156,38 @@ static void event_handler(void *arg, esp_event_base_t event_base, } } -static void ftm_process_report(void) +static void ftm_print_report(void) { int i; char *log = NULL; + wifi_ftm_report_entry_t *ftm_report = NULL; - if (s_ftm_report_num_entries == 0) + if (s_ftm_report_num_entries == 0) { + /* FTM Failure case */ return; + } - if (!g_report_lvl) - return; + if (!g_report_lvl) { + /* No need to print, just free the internal FTM report */ + esp_wifi_ftm_get_report(NULL, 0); + goto exit; + } + + ftm_report = malloc(sizeof(wifi_ftm_report_entry_t) * s_ftm_report_num_entries); + if (!ftm_report) { + ESP_LOGE(TAG_STA, "Failed to alloc buffer for FTM report"); + goto exit; + } + bzero(ftm_report, sizeof(wifi_ftm_report_entry_t) * s_ftm_report_num_entries); + if (ESP_OK != esp_wifi_ftm_get_report(ftm_report, s_ftm_report_num_entries)) { + ESP_LOGE(TAG_STA, "Could not get FTM report"); + goto exit; + } log = malloc(200); if (!log) { ESP_LOGE(TAG_STA, "Failed to alloc buffer for FTM report"); - return; + goto exit; } bzero(log, 200); @@ -181,24 +201,32 @@ static void ftm_process_report(void) bzero(log, 200); if (g_report_lvl & BIT0) { - log_ptr += sprintf(log_ptr, "%6d|", s_ftm_report[i].dlog_token); + log_ptr += sprintf(log_ptr, "%6d|", ftm_report[i].dlog_token); } if (g_report_lvl & BIT1) { - if (s_ftm_report[i].rtt != UINT32_MAX) - log_ptr += sprintf(log_ptr, "%7" PRIi32 " |", s_ftm_report[i].rtt); + if (ftm_report[i].rtt != UINT32_MAX) + log_ptr += sprintf(log_ptr, "%7" PRIi32 " |", ftm_report[i].rtt); else log_ptr += sprintf(log_ptr, " INVALID |"); } if (g_report_lvl & BIT2) { - log_ptr += sprintf(log_ptr, "%14llu |%14llu |%14llu |%14llu |", s_ftm_report[i].t1, - s_ftm_report[i].t2, s_ftm_report[i].t3, s_ftm_report[i].t4); + log_ptr += sprintf(log_ptr, "%14llu |%14llu |%14llu |%14llu |", ftm_report[i].t1, + ftm_report[i].t2, ftm_report[i].t3, ftm_report[i].t4); } if (g_report_lvl & BIT3) { - log_ptr += sprintf(log_ptr, "%6d |", s_ftm_report[i].rssi); + log_ptr += sprintf(log_ptr, "%6d |", ftm_report[i].rssi); } ESP_LOGI(TAG_STA, "|%s", log); } - free(log); + +exit: + if (log) { + free(log); + } + if (ftm_report) { + free(ftm_report); + } + s_ftm_report_num_entries = 0; } void initialise_wifi(void) @@ -245,7 +273,7 @@ static bool wifi_cmd_sta_join(const char *ssid, const char *pass) s_reconnect = false; xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT); ESP_ERROR_CHECK( esp_wifi_disconnect() ); - xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portTICK_PERIOD_MS); + xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portMAX_DELAY); } s_reconnect = true; @@ -271,7 +299,7 @@ static int wifi_cmd_sta(int argc, char **argv) s_reconnect = false; xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT); esp_wifi_disconnect(); - xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portTICK_PERIOD_MS); + xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portMAX_DELAY); return 0; } @@ -461,11 +489,13 @@ static int wifi_cmd_ftm(int argc, char **argv) { int nerrors = arg_parse(argc, argv, (void **) &ftm_args); wifi_ap_record_t *ap_record; + uint32_t wait_time_ms = DEFAULT_WAIT_TIME_MS; EventBits_t bits; wifi_ftm_initiator_cfg_t ftmi_cfg = { .frm_count = 32, .burst_period = 2, + .use_get_report_api = true, }; if (nerrors != 0) { @@ -509,11 +539,11 @@ static int wifi_cmd_ftm(int argc, char **argv) } if (ftm_args.burst_period->count != 0) { - if (ftm_args.burst_period->ival[0] >= 2 && - ftm_args.burst_period->ival[0] < 256) { + if (ftm_args.burst_period->ival[0] >= 0 && + ftm_args.burst_period->ival[0] <= 100) { ftmi_cfg.burst_period = ftm_args.burst_period->ival[0]; } else { - ESP_LOGE(TAG_STA, "Invalid Burst Period! Valid range is 2-255"); + ESP_LOGE(TAG_STA, "Invalid Burst Period! Valid range is 0-100"); return 0; } } @@ -526,18 +556,24 @@ static int wifi_cmd_ftm(int argc, char **argv) return 0; } + if (ftmi_cfg.burst_period) { + /* Wait at least double the duration of maximum FTM bursts */ + wait_time_ms = (ftmi_cfg.burst_period * 100) * (MAX_FTM_BURSTS * 2); + } bits = xEventGroupWaitBits(s_ftm_event_group, FTM_REPORT_BIT | FTM_FAILURE_BIT, - pdTRUE, pdFALSE, portMAX_DELAY); - /* Processing data from FTM session */ - ftm_process_report(); - free(s_ftm_report); - s_ftm_report = NULL; - s_ftm_report_num_entries = 0; + pdTRUE, pdFALSE, wait_time_ms / portTICK_PERIOD_MS); if (bits & FTM_REPORT_BIT) { + /* Print detailed data from FTM session */ + ftm_print_report(); ESP_LOGI(TAG_STA, "Estimated RTT - %" PRId32 " nSec, Estimated Distance - %" PRId32 ".%02" PRId32 " meters", s_rtt_est, s_dist_est / 100, s_dist_est % 100); + } else if (bits & FTM_FAILURE_BIT) { + /* FTM Failure case */ + ESP_LOGE(TAG_STA, "FTM procedure failed!"); } else { - /* Failure case */ + /* Timeout, end session gracefully */ + ESP_LOGE(TAG_STA, "FTM procedure timed out!"); + esp_wifi_ftm_end_session(); } return 0; @@ -632,7 +668,7 @@ void register_wifi(void) ftm_args.initiator = arg_lit0("I", "ftm_initiator", "FTM Initiator mode"); ftm_args.ssid = arg_str0("s", "ssid", "SSID", "SSID of AP"); ftm_args.frm_count = arg_int0("c", "frm_count", "<0/8/16/24/32/64>", "FTM frames to be exchanged (0: No preference)"); - ftm_args.burst_period = arg_int0("p", "burst_period", "<2-255 (x 100 mSec)>", "Periodicity of FTM bursts in 100's of miliseconds (0: No preference)"); + ftm_args.burst_period = arg_int0("p", "burst_period", "<0-100 (x 100 mSec)>", "Periodicity of FTM bursts in 100's of miliseconds (0: No preference)"); /* FTM Responder commands */ ftm_args.responder = arg_lit0("R", "ftm_responder", "FTM Responder mode"); ftm_args.enable = arg_lit0("e", "enable", "Restart SoftAP with FTM enabled"); From ccc8fb8f650b5e8b8a52c86656b01515d3dbb6f3 Mon Sep 17 00:00:00 2001 From: sparker <54767129+sparkertim@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:02:57 +0800 Subject: [PATCH 06/18] fix(wifi/example): Fix dpp example init error Set wifi mode before calling esp_supp_dpp_init. Closes https://github.com/espressif/esp-idf/pull/12769 Signed-off-by: Shreyas Sheth --- .../wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c b/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c index 76a8fee4079c..166d66a591c6 100644 --- a/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c +++ b/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c @@ -155,9 +155,9 @@ void dpp_enrollee_init(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb)); ESP_ERROR_CHECK(dpp_enrollee_bootstrap()); - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_start()); /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum From b531376a623157de64ef6463b804dfb7cc39d78d Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Fri, 22 Mar 2024 18:46:23 +0200 Subject: [PATCH 07/18] fix(esp_timer): Force to go light sleep ignoring ESP_ERR_SLEEP_REJECT --- .../esp_timer/test_apps/main/test_esp_timer.c | 18 +++++++++++++++++- .../main/test_esp_timer_light_sleep.c | 18 ++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/components/esp_timer/test_apps/main/test_esp_timer.c b/components/esp_timer/test_apps/main/test_esp_timer.c index 55a380ea0da6..9f11a3937641 100644 --- a/components/esp_timer/test_apps/main/test_esp_timer.c +++ b/components/esp_timer/test_apps/main/test_esp_timer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -84,6 +84,7 @@ TEST_CASE("esp_timer orders timers correctly", "[esp_timer]") } fclose(stream); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static const int test_time_sec = 10; @@ -160,6 +161,7 @@ TEST_CASE("esp_timer produces correct delay", "[esp_timer]") TEST_ESP_OK( esp_timer_dump(stdout) ); esp_timer_delete(timer1); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } // no, we can't make this a const size_t (ยง6.7.5.2) @@ -218,6 +220,7 @@ TEST_CASE("periodic esp_timer produces correct delays", "[esp_timer]") TEST_ESP_OK( esp_timer_delete(timer1) ); vSemaphoreDelete(args.done); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #undef NUM_INTERVALS @@ -342,6 +345,7 @@ TEST_CASE("multiple timers are ordered correctly", "[esp_timer]") TEST_ESP_OK( esp_timer_delete(args1.timer) ); TEST_ESP_OK( esp_timer_delete(args2.timer) ); TEST_ESP_OK( esp_timer_delete(args3.timer) ); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #undef N @@ -384,6 +388,7 @@ TEST_CASE("esp_timer for very short intervals", "[esp_timer]") vSemaphoreDelete(semaphore); TEST_ESP_OK(esp_timer_delete(timer1)); TEST_ESP_OK(esp_timer_delete(timer2)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } TEST_CASE("esp_timer_get_time call takes less than 1us", "[esp_timer]") @@ -633,6 +638,7 @@ TEST_CASE("after esp_timer_impl_advance, timers run when expected", "[esp_timer] ref_clock_deinit(); TEST_ESP_OK(esp_timer_delete(timer)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static esp_timer_handle_t timer1; @@ -670,6 +676,7 @@ TEST_CASE("Can start/stop timer from ISR context", "[esp_timer]") esp_deregister_freertos_tick_hook(test_tick_hook); TEST_ESP_OK( esp_timer_delete(timer1) ); vSemaphoreDelete(sem); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #if !defined(CONFIG_FREERTOS_UNICORE) && SOC_DPORT_WORKAROUND @@ -861,6 +868,7 @@ TEST_CASE("Test a latency between a call of callback and real event", "[esp_time TEST_ESP_OK(esp_timer_dump(stdout)); TEST_ESP_OK(esp_timer_stop(periodic_timer)); TEST_ESP_OK(esp_timer_delete(periodic_timer)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static void test_timer_triggered(void* timer1_trig) @@ -909,6 +917,7 @@ TEST_CASE("periodic esp_timer can be restarted", "[esp_timer]") TEST_ESP_OK( esp_timer_stop(timer1) ); TEST_ESP_OK( esp_timer_delete(timer1) ); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } TEST_CASE("one-shot esp_timer can be restarted", "[esp_timer]") @@ -943,6 +952,7 @@ TEST_CASE("one-shot esp_timer can be restarted", "[esp_timer]") TEST_ASSERT_EQUAL(0, timer_trig); TEST_ESP_OK( esp_timer_delete(timer1) ); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } @@ -1002,6 +1012,7 @@ TEST_CASE("Test ESP_TIMER_ISR dispatch method", "[esp_timer]") TEST_ESP_OK(esp_timer_delete(periodic_timer2)); printf("timers deleted\n"); TEST_ESP_OK(esp_timer_dump(stdout)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static void dump_task(void* arg) @@ -1062,6 +1073,7 @@ TEST_CASE("Test ESP_TIMER_ISR dispatch method is not blocked", "[esp_timer]") TEST_ESP_OK(esp_timer_delete(periodic_timer1)); TEST_ESP_OK(esp_timer_delete(periodic_timer2)); printf("timer deleted\n"); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static void isr_callback1(void* arg) @@ -1121,6 +1133,7 @@ TEST_CASE("Test ESP_TIMER_ISR, stop API cleans alarm reg if TASK timer list is e TEST_ESP_OK(esp_timer_delete(timer2)); vSemaphoreDelete(done); printf("timer deleted\n"); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } static void isr_callback2(void* arg) @@ -1176,6 +1189,7 @@ TEST_CASE("Test ESP_TIMER_ISR, stop API cleans alarm reg if ISR timer list is em TEST_ESP_OK(esp_timer_delete(timer2)); vSemaphoreDelete(done); printf("timer deleted\n"); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #ifndef CONFIG_FREERTOS_UNICORE @@ -1214,6 +1228,7 @@ TEST_CASE("Test that CPU1 can handle esp_timer ISR even when CPU0 is blocked", " TEST_ESP_OK(esp_timer_dump(stdout)); TEST_ASSERT_INT_WITHIN(3, 10, data); TEST_ESP_OK(esp_timer_delete(timer)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #endif // not CONFIG_FREERTOS_UNICORE @@ -1283,6 +1298,7 @@ TEST_CASE("Test ISR dispatch callbacks are not blocked even if TASK callbacks ta TEST_ESP_OK(esp_timer_stop(isr_timer_handle)); TEST_ESP_OK(esp_timer_delete(task_timer_handle)); TEST_ESP_OK(esp_timer_delete(isr_timer_handle)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #endif // CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD diff --git a/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c b/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c index b1b1545e6f93..edd10638a01e 100644 --- a/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c +++ b/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c @@ -8,6 +8,8 @@ #include #include #include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" #include "esp_timer.h" #include "unity.h" #include "esp_rom_sys.h" @@ -35,22 +37,26 @@ TEST_CASE("Test the periodic timer does not handle lost events during light slee int period_cb_ms = 10; int interval_ms = 50; - TEST_ESP_OK(esp_timer_start_periodic(periodic_timer, period_cb_ms * 1000)); - TEST_ESP_OK(esp_sleep_enable_timer_wakeup(interval_ms * 1000)); printf("Run light sleep\n"); printf("count_calls should be around = %d\n", interval_ms / period_cb_ms); + TEST_ESP_OK(esp_sleep_enable_timer_wakeup(interval_ms * 1000)); + TEST_ESP_OK(esp_timer_start_periodic(periodic_timer, period_cb_ms * 1000)); for (int i = 0; i < 3; i++) { - count_calls = 0; - TEST_ESP_OK(esp_light_sleep_start()); + do { + count_calls = 0; + } while (esp_light_sleep_start() != ESP_OK); esp_rom_delay_us(interval_ms * 1000); - printf("count_calls = %d\n", count_calls); - TEST_ASSERT_INT_WITHIN(2, interval_ms / period_cb_ms, count_calls); + vTaskDelay(1); // wait for the esp_timer task to start on another core processing period_timer after sleep + int saved_count_calls = count_calls; + printf("count_calls = %d\n", saved_count_calls); TEST_ESP_OK(esp_timer_dump(stdout)); + TEST_ASSERT_INT_WITHIN(2, interval_ms / period_cb_ms, saved_count_calls); } TEST_ESP_OK(esp_timer_stop(periodic_timer)); // times_skipped is about 12 (4 from each sleep time). TEST_ESP_OK(esp_timer_dump(stdout)); TEST_ESP_OK(esp_timer_delete(periodic_timer)); + vTaskDelay(3); // wait for the esp_timer task to delete all timers } #endif //#!TEMPORARY_DISABLED_FOR_TARGETS(ESP32P4) From 7c15d88e75981fcf4ad76228d46442389a954249 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 29 Feb 2024 11:10:11 +0800 Subject: [PATCH 08/18] change(bt/bluedroid): Use BTC util to convert HCI status to ESP status --- components/bt/host/bluedroid/btc/core/btc_dm.c | 5 +++-- components/bt/host/bluedroid/btc/core/btc_util.c | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/btc/core/btc_dm.c b/components/bt/host/bluedroid/btc/core/btc_dm.c index b0afdad8bd20..a19b618db9f4 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dm.c +++ b/components/bt/host/bluedroid/btc/core/btc_dm.c @@ -10,6 +10,7 @@ #include "btc/btc_common.h" #include "btc/btc_dm.h" #include "btc/btc_main.h" +#include "btc/btc_util.h" #include "common/bt_trace.h" #include "common/bt_target.h" #include "btc/btc_storage.h" @@ -717,14 +718,14 @@ static void btc_dm_acl_link_stat(tBTA_DM_ACL_LINK_STAT *p_acl_link_stat) switch (p_acl_link_stat->event) { case BTA_ACL_LINK_STAT_CONN_CMPL: { event = ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT; - param.acl_conn_cmpl_stat.stat = p_acl_link_stat->link_act.conn_cmpl.status | ESP_BT_STATUS_BASE_FOR_HCI_ERR; + param.acl_conn_cmpl_stat.stat = btc_hci_to_esp_status(p_acl_link_stat->link_act.conn_cmpl.status); param.acl_conn_cmpl_stat.handle = p_acl_link_stat->link_act.conn_cmpl.handle; memcpy(param.acl_conn_cmpl_stat.bda, p_acl_link_stat->link_act.conn_cmpl.bd_addr, ESP_BD_ADDR_LEN); break; } case BTA_ACL_LINK_STAT_DISCONN_CMPL: { event = ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT; - param.acl_disconn_cmpl_stat.reason = p_acl_link_stat->link_act.disconn_cmpl.reason | ESP_BT_STATUS_BASE_FOR_HCI_ERR; + param.acl_disconn_cmpl_stat.reason = btc_hci_to_esp_status(p_acl_link_stat->link_act.disconn_cmpl.reason); param.acl_disconn_cmpl_stat.handle = p_acl_link_stat->link_act.disconn_cmpl.handle; memcpy(param.acl_disconn_cmpl_stat.bda, p_acl_link_stat->link_act.disconn_cmpl.bd_addr, ESP_BD_ADDR_LEN); break; diff --git a/components/bt/host/bluedroid/btc/core/btc_util.c b/components/bt/host/bluedroid/btc/core/btc_util.c index 9818e7064bd2..5e29aba8be83 100644 --- a/components/bt/host/bluedroid/btc/core/btc_util.c +++ b/components/bt/host/bluedroid/btc/core/btc_util.c @@ -338,8 +338,11 @@ esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status) case HCI_ERR_ILLEGAL_PARAMETER_FMT: esp_status = ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT; break; + case HCI_ERR_UNSUPPORTED_VALUE: + esp_status = ESP_BT_STATUS_UNSUPPORTED; + break; default: - esp_status = ESP_BT_STATUS_FAIL; + esp_status = hci_status | ESP_BT_STATUS_BASE_FOR_HCI_ERR; break; } From 044ead90ce41a78be2bc3efe1bb78195132e7258 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 27 Mar 2024 19:17:58 +0530 Subject: [PATCH 09/18] fix(nimble): Handle missing free in application --- examples/bluetooth/nimble/ble_spp/spp_server/main/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c index 7618bc03d733..86aa7fe9f8b6 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c @@ -367,7 +367,7 @@ void ble_server_uart_task(void *pvParameters) /* Check if client has subscribed to notifications */ if (conn_handle_subs[i]) { struct os_mbuf *txom; - txom = ble_hs_mbuf_from_flat(ntf, sizeof(ntf)); + txom = ble_hs_mbuf_from_flat(ntf, event.size); rc = ble_gatts_notify_custom(i, ble_spp_svc_gatt_read_val_handle, txom); if (rc == 0) { @@ -377,6 +377,8 @@ void ble_server_uart_task(void *pvParameters) } } } + + free(ntf); } break; default: From b86dd75df5275f52462910ba1a091fa25d5b5697 Mon Sep 17 00:00:00 2001 From: linruihao Date: Wed, 27 Mar 2024 19:06:34 +0800 Subject: [PATCH 10/18] fix(bt): fixed cmakelist error on c2 Closes https://github.com/espressif/esp-idf/issues/13451 --- components/bt/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index bf74d08ab366..63f7b1e9c550 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -84,9 +84,6 @@ if(CONFIG_BT_ENABLED) elseif(CONFIG_IDF_TARGET_ESP32S3) list(APPEND srcs "controller/esp32c3/bt.c") - elseif(CONFIG_IDF_TARGET_ESP32C2) - list(APPEND srcs "controller/esp32c2/bt.c") - elseif(CONFIG_IDF_TARGET_ESP32C2) set(ldfragments "linker.lf.esp32c2") list(APPEND srcs "controller/esp32c2/bt.c") From 8e694cddcc79dd56ff92b6cd3880f5795800a58f Mon Sep 17 00:00:00 2001 From: Sarvesh Bodakhe Date: Thu, 28 Mar 2024 11:38:32 +0530 Subject: [PATCH 11/18] feat(esp_wifi): Add support for WPA3 transition disable and more updates 1. Add support for SAE-PK and WPA3-Enterprise transition disable 2. Add support to handle OWE transition disable indication from AP 2. Update Wi-Fi WPA3 authmodes as per WPA Specification v3.3: - Merge 'WIFI_AUTH_WPA3_EXT_PSK' and 'WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE' into 'WIFI_AUTH_WPA3_PSK' as per specification. 4. refactor: Backport common changes in scan/connect path from 90cc6158 - 90cc6158 adds support for Network Introduction Protocl in DPP --- components/esp_wifi/include/esp_wifi_types.h | 4 +-- components/esp_wifi/lib | 2 +- .../esp_supplicant/src/esp_wifi_driver.h | 5 +++- .../esp_supplicant/src/esp_wpa3.c | 2 +- .../esp_supplicant/src/esp_wpa_main.c | 3 ++- .../esp_supplicant/src/esp_wpas_glue.c | 27 +++++++++++++++++-- .../wpa_supplicant/src/common/wpa_common.h | 3 +++ examples/wifi/scan/main/scan.c | 6 ----- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index a6688cab4ec0..95108b3e2188 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -56,7 +56,7 @@ typedef struct { } wifi_country_t; /* Strength of authmodes */ -/* OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA3_PSK = WPA2_WPA3_PSK < WPA3_EXT_PSK = WPA3_EXT_PSK_MIXED_MODE */ +/* OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA3_PSK = WPA2_WPA3_PSK */ typedef enum { WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */ WIFI_AUTH_WEP, /**< authenticate mode : WEP */ @@ -70,8 +70,6 @@ typedef enum { WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */ WIFI_AUTH_OWE, /**< authenticate mode : OWE */ WIFI_AUTH_WPA3_ENT_192, /**< authenticate mode : WPA3_ENT_SUITE_B_192_BIT */ - WIFI_AUTH_WPA3_EXT_PSK, /**< authenticate mode : WPA3_PSK_EXT_KEY */ - WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE, /**< authenticate mode: WPA3_PSK + WPA3_PSK_EXT_KEY */ WIFI_AUTH_MAX } wifi_auth_mode_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index bb386048d34c..00ffcf8882a8 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit bb386048d34c44dbb2295d33b78540ecb8560f8e +Subproject commit 00ffcf8882a8fc8882a7957649877f619bfda5bb diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h b/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h index 0837ef1f0b5d..481589c01ee6 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h @@ -290,12 +290,15 @@ bool esp_wifi_is_ft_enabled_internal(uint8_t if_index); uint8_t esp_wifi_sta_get_config_sae_pk_internal(void); void esp_wifi_sta_disable_sae_pk_internal(void); void esp_wifi_sta_disable_wpa2_authmode_internal(void); +void esp_wifi_sta_disable_owe_trans_internal(void); uint8_t esp_wifi_ap_get_max_sta_conn(void); uint8_t esp_wifi_get_config_sae_pwe_h2e_internal(uint8_t ifx); bool esp_wifi_ap_notify_node_sae_auth_done(uint8_t *mac); bool esp_wifi_ap_is_sta_sae_reauth_node(uint8_t *mac); uint8_t* esp_wifi_sta_get_sae_identifier_internal(void); bool esp_wifi_eb_tx_status_success_internal(void *eb); -uint8_t* esp_wifi_sta_get_rsnxe(void); +uint8_t* esp_wifi_sta_get_rsnxe(u8 *bssid); +esp_err_t esp_wifi_sta_connect_internal(const uint8_t *bssid); +void esp_wifi_enable_sae_pk_only_mode_internal(void); #endif /* _ESP_WIFI_DRIVER_H_ */ diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c index 139bfaafddac..a0e7ba4d1627 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c @@ -43,7 +43,7 @@ static esp_err_t wpa3_build_sae_commit(u8 *bssid, size_t *sae_msg_len) use_pt = 1; } - rsnxe = esp_wifi_sta_get_rsnxe(); + rsnxe = esp_wifi_sta_get_rsnxe(bssid); if (rsnxe && rsnxe[1] >= 1) { rsnxe_capa = rsnxe[2]; } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c index 5f20db0c428a..7c55024fc407 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c @@ -213,7 +213,8 @@ int wpa_sta_connect(uint8_t *bssid) esp_set_assoc_ie((uint8_t *)bssid, NULL, 0, false); } - return 0; + ret = esp_wifi_sta_connect_internal(bssid); + return ret; } void wpa_config_done(void) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c index 16f8916f1540..189c7aa9654f 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -93,13 +93,36 @@ int hostapd_send_eapol(const u8 *source, const u8 *sta_addr, } +static void disable_wpa_wpa2(void) +{ + esp_wifi_sta_disable_wpa2_authmode_internal(); +} + void wpa_supplicant_transition_disable(struct wpa_sm *sm, u8 bitmap) { wpa_printf(MSG_DEBUG, "TRANSITION_DISABLE %02x", bitmap); if ((bitmap & TRANSITION_DISABLE_WPA3_PERSONAL) && wpa_key_mgmt_sae(sm->key_mgmt)) { - esp_wifi_sta_disable_wpa2_authmode_internal(); + disable_wpa_wpa2(); + } + + if ((bitmap & TRANSITION_DISABLE_SAE_PK) && + wpa_key_mgmt_sae(sm->key_mgmt)) { + wpa_printf(MSG_INFO, + "SAE-PK: SAE authentication without PK disabled based on AP notification"); + disable_wpa_wpa2(); + esp_wifi_enable_sae_pk_only_mode_internal(); + } + + if ((bitmap & TRANSITION_DISABLE_WPA3_ENTERPRISE) && + wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt)) { + disable_wpa_wpa2(); + } + + if ((bitmap & TRANSITION_DISABLE_ENHANCED_OPEN) && + wpa_key_mgmt_owe(sm->key_mgmt)) { + esp_wifi_sta_disable_owe_trans_internal(); } } diff --git a/components/wpa_supplicant/src/common/wpa_common.h b/components/wpa_supplicant/src/common/wpa_common.h index 78148c7eb104..996ad40c5708 100644 --- a/components/wpa_supplicant/src/common/wpa_common.h +++ b/components/wpa_supplicant/src/common/wpa_common.h @@ -326,6 +326,9 @@ struct rsn_rdie { /* WFA Transition Disable KDE (using OUI_WFA) */ /* Transition Disable Bitmap bits */ #define TRANSITION_DISABLE_WPA3_PERSONAL BIT(0) +#define TRANSITION_DISABLE_SAE_PK BIT(1) +#define TRANSITION_DISABLE_WPA3_ENTERPRISE BIT(2) +#define TRANSITION_DISABLE_ENHANCED_OPEN BIT(3) #ifdef CONFIG_IEEE80211R int wpa_ft_mic(const u8 *kck, size_t kck_len, const u8 *sta_addr, diff --git a/examples/wifi/scan/main/scan.c b/examples/wifi/scan/main/scan.c index 14b6935b5d46..02a738836633 100644 --- a/examples/wifi/scan/main/scan.c +++ b/examples/wifi/scan/main/scan.c @@ -55,12 +55,6 @@ static void print_auth_mode(int authmode) case WIFI_AUTH_WPA3_ENT_192: ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_ENT_192"); break; - case WIFI_AUTH_WPA3_EXT_PSK: - ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_EXT_PSK"); - break; - case WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE: - ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE"); - break; default: ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_UNKNOWN"); break; From 31883c9a647cad3d49ec5113eaf347bcd85f9749 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Fri, 8 Mar 2024 21:47:46 +0800 Subject: [PATCH 12/18] feat(freertos): Add application task tag support This commit enables support for application task tag. - Added CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG option - Added basic unit test --- components/freertos/Kconfig | 7 ++++ .../config/include/freertos/FreeRTOSConfig.h | 4 +++ .../freertos/kernel/tasks/test_app_task_tag.c | 35 +++++++++++++++++++ .../freertos/sdkconfig.ci.freertos_options | 1 + 4 files changed, 47 insertions(+) create mode 100644 components/freertos/test_apps/freertos/kernel/tasks/test_app_task_tag.c diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index e9d4e309411b..c631aad641bd 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -293,6 +293,13 @@ menu "FreeRTOS" esp_pm_dump_locks, if the proportion of rejected sleeps is too high, please increase this value to improve scheduling efficiency + config FREERTOS_USE_APPLICATION_TASK_TAG + bool "configUSE_APPLICATION_TASK_TAG" + default n + help + Enables task tagging functionality and its associated API (see configUSE_APPLICATION_TASK_TAG + documentation for more details). + endmenu # Kernel menu "Port" diff --git a/components/freertos/config/include/freertos/FreeRTOSConfig.h b/components/freertos/config/include/freertos/FreeRTOSConfig.h index a36a4bedbf65..076e15345d83 100644 --- a/components/freertos/config/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/config/include/freertos/FreeRTOSConfig.h @@ -251,6 +251,10 @@ #endif /* CONFIG_FREERTOS_SMP */ #endif /* def __ASSEMBLER__ */ +#if CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG + #define configUSE_APPLICATION_TASK_TAG 1 +#endif // CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG + /* ----------------------------------------------- Amazon SMP FreeRTOS ------------------------------------------------- * - All Amazon SMP FreeRTOS specific configurations * ------------------------------------------------------------------------------------------------------------------ */ diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_app_task_tag.c b/components/freertos/test_apps/freertos/kernel/tasks/test_app_task_tag.c new file mode 100644 index 000000000000..3322a41270cf --- /dev/null +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_app_task_tag.c @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "unity.h" +#include "test_utils.h" + +#if CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG + +static BaseType_t tag_cb(void *arg) +{ + BaseType_t *tag_cb_called = (BaseType_t *)arg; + *tag_cb_called = pdTRUE; + return pdTRUE; +} + +TEST_CASE("Test application task tag", "[freertos]") +{ + BaseType_t tag_cb_called = pdFALSE; + + // Set the app task tag for current task + vTaskSetApplicationTaskTag(NULL, tag_cb); + // Check app task tag is correct + TEST_ASSERT_EQUAL(tag_cb, xTaskGetApplicationTaskTag(NULL)); + // Test the app task tag by calling it + TEST_ASSERT_EQUAL(pdTRUE, xTaskCallApplicationTaskHook(NULL, (void *)&tag_cb_called)); + TEST_ASSERT_EQUAL(pdTRUE, tag_cb_called); +} + +#endif // CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG diff --git a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options index 9e1213bd6582..5e6e3571a27f 100644 --- a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options +++ b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options @@ -19,3 +19,4 @@ CONFIG_FREERTOS_FPU_IN_ISR=y CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 CONFIG_FREERTOS_USE_TICK_HOOK=y CONFIG_FREERTOS_USE_IDLE_HOOK=y +CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG=y From 0f852fcd5f996167be93b1230829222ce72fc45f Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Fri, 1 Mar 2024 12:26:08 +0800 Subject: [PATCH 13/18] fix(espcoredump): Reconfigure the stack guard when using custom coredump stack --- .../port/riscv/esp_core_dump_port_impl.h | 7 ++++- components/espcoredump/src/core_dump_common.c | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/components/espcoredump/include_core_dump/port/riscv/esp_core_dump_port_impl.h b/components/espcoredump/include_core_dump/port/riscv/esp_core_dump_port_impl.h index 154c5a28e679..d8be12233c08 100644 --- a/components/espcoredump/include_core_dump/port/riscv/esp_core_dump_port_impl.h +++ b/components/espcoredump/include_core_dump/port/riscv/esp_core_dump_port_impl.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,6 +11,7 @@ * @brief Core dump port interface implementation for RISC-V. */ +#include "sdkconfig.h" #include "esp_core_dump_types.h" #include "esp_app_format.h" @@ -24,6 +25,10 @@ extern "C" { */ typedef struct { uint32_t sp; +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD + uint32_t sp_min; + uint32_t sp_max; +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD } core_dump_stack_context_t; /** diff --git a/components/espcoredump/src/core_dump_common.c b/components/espcoredump/src/core_dump_common.c index a1c6aff38963..6e3b24f96bea 100644 --- a/components/espcoredump/src/core_dump_common.c +++ b/components/espcoredump/src/core_dump_common.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,9 @@ #include "esp_rom_sys.h" #include "esp_core_dump_port.h" #include "esp_core_dump_common.h" +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD +#include "esp_private/hw_stack_guard.h" +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD const static char TAG[] __attribute__((unused)) = "esp_core_dump_common"; @@ -72,12 +75,25 @@ FORCE_INLINE_ATTR void esp_core_dump_setup_stack(void) //esp_cpu_clear_watchpoint(1); //esp_cpu_set_watchpoint(1, s_coredump_stack, 1, ESP_WATCHPOINT_STORE); +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD + /* Save the current area we are watching to restore it later */ + esp_hw_stack_guard_get_bounds(&s_stack_context.sp_min, &s_stack_context.sp_max); + /* Since the stack is going to change, make sure we disable protection or an exception would be triggered */ + esp_hw_stack_guard_monitor_stop(); +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD + /* Replace the stack pointer depending on the architecture, but save the * current stack pointer, in order to be able too restore it later. * This function must be inlined. */ esp_core_dump_replace_sp(s_core_dump_sp, &s_stack_context); ESP_COREDUMP_LOGI("Backing up stack @ %p and use core dump stack @ %p", s_stack_context.sp, esp_cpu_get_sp()); + +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD + /* Re-enable the stack guard to check if the stack is big enough for coredump generation */ + esp_hw_stack_guard_set_bounds((uint32_t) s_coredump_stack, (uint32_t) s_core_dump_sp); + esp_hw_stack_guard_monitor_start(); +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD } /** @@ -112,10 +128,18 @@ FORCE_INLINE_ATTR void esp_core_dump_report_stack_usage(void) /* Restore the stack pointer. */ ESP_COREDUMP_LOGI("Restoring stack @ %p", s_stack_context.sp); +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD + esp_hw_stack_guard_monitor_stop(); +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD esp_core_dump_restore_sp(&s_stack_context); +#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD + /* Monitor the same stack area that was set before replacing the stack pointer */ + esp_hw_stack_guard_set_bounds(s_stack_context.sp_min, s_stack_context.sp_max); + esp_hw_stack_guard_monitor_start(); +#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD } -#else // CONFIG_ESP_COREDUMP_STACK_SIZE > 0 +#else // CONFIG_ESP_COREDUMP_STACK_SIZE == 0 /* Here, we are not going to use a custom stack for coredump. Make sure the current configuration doesn't require one. */ #if CONFIG_ESP_COREDUMP_USE_STACK_SIZE From 2da016575fb46e092c5020c0536ab1ba69096f20 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Tue, 27 Feb 2024 16:22:42 +0800 Subject: [PATCH 14/18] fix(bt/bluedorid): Fixed no event when removing an invalid SDP record --- .../bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c b/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c index 143ae336ea6a..f93e10f2e551 100644 --- a/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c +++ b/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1034,14 +1034,16 @@ static void btc_sdp_remove_record(btc_sdp_args_t *arg) } else { BTC_TRACE_ERROR("%s SDP record with handle %d not found", __func__, arg->remove_record.record_handle); - return; + ret = ESP_SDP_NO_CREATE_RECORD; + break; } /* Get the Record handle, and free the slot */ /* The application layer record_handle is equivalent to the id of the btc layer */ int slot = get_sdp_slot_id_by_handle(arg->remove_record.record_handle); if (slot < 0) { - return; + ret = ESP_SDP_NO_CREATE_RECORD; + break; } handle = free_sdp_slot(slot); From dfeeaf386e1f38477051eadf2a3a765e407d4fca Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Tue, 27 Feb 2024 17:14:13 +0800 Subject: [PATCH 15/18] fix(bt/bluedorid): Fixed crash caused by using illegal pointer --- components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c b/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c index f93e10f2e551..6eaf6cfb52bf 100644 --- a/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c +++ b/components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c @@ -285,8 +285,8 @@ static int free_sdp_slot(int id) // Record have already been freed handle = -1; } - osi_free(slot); - slot = NULL; + osi_free(sdp_local_param.sdp_slots[id]); + sdp_local_param.sdp_slots[id] = NULL; return handle; } From cc1323774667641a7e55ca3c549ef7be684f30b4 Mon Sep 17 00:00:00 2001 From: liuning Date: Thu, 28 Mar 2024 21:19:27 +0800 Subject: [PATCH 16/18] fix(wifi): fix coex ld issue --- components/esp_rom/esp32c2/ld/esp32c2.rom.ld | 4 ++-- components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld | 2 +- components/esp_rom/esp32c3/ld/esp32c3.rom.ld | 2 +- components/esp_rom/esp32c6/ld/esp32c6.rom.coexist.ld | 4 ++-- components/esp_rom/esp32s3/ld/esp32s3.rom.ld | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index e1e7ae7d0f43..b3bdcf9ffe49 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -1975,12 +1975,12 @@ esp_coex_rom_version_get = 0x40002168; coex_bt_release = 0x4000216c; coex_bt_request = 0x40002170; coex_core_ble_conn_dyn_prio_get = 0x40002174; -coex_core_event_duration_get = 0x40002178; +/*coex_core_event_duration_get = 0x40002178;*/ coex_core_pti_get = 0x4000217c; coex_core_release = 0x40002180; coex_core_request = 0x40002184; coex_core_status_get = 0x40002188; -coex_core_timer_idx_get = 0x4000218c; +/*coex_core_timer_idx_get = 0x4000218c;*/ coex_event_duration_get = 0x40002190; coex_hw_timer_disable = 0x40002194; coex_hw_timer_enable = 0x40002198; diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld index 0c1d5c191ab7..ec2ce18a0a0e 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld @@ -39,7 +39,7 @@ ppMapWaitTxq = 0x40001810; /*sta_input = 0x40001870;*/ ieee80211_crypto_decap = 0x4000189c; ieee80211_decap = 0x400018a0; -coex_core_timer_idx_get = 0x400018d0; +/*coex_core_timer_idx_get = 0x400018d0;*/ rom1_chip_i2c_readReg = 0x40001924; rom1_chip_i2c_writeReg = 0x40001928; rom_index_to_txbbgain = 0x40001964; diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 0d86b315ad17..d855e454a991 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -1760,7 +1760,7 @@ esp_coex_rom_version_get = 0x400018ac; coex_bt_release = 0x400018b0; coex_bt_request = 0x400018b4; coex_core_ble_conn_dyn_prio_get = 0x400018b8; -coex_core_event_duration_get = 0x400018bc; +/*coex_core_event_duration_get = 0x400018bc;*/ coex_core_pti_get = 0x400018c0; coex_core_release = 0x400018c4; coex_core_request = 0x400018c8; diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.coexist.ld b/components/esp_rom/esp32c6/ld/esp32c6.rom.coexist.ld index cec4b9f6e84f..5ff011973e23 100644 --- a/components/esp_rom/esp32c6/ld/esp32c6.rom.coexist.ld +++ b/components/esp_rom/esp32c6/ld/esp32c6.rom.coexist.ld @@ -22,12 +22,12 @@ esp_coex_rom_version_get = 0x40000afc; coex_bt_release = 0x40000b00; coex_bt_request = 0x40000b04; coex_core_ble_conn_dyn_prio_get = 0x40000b08; -coex_core_event_duration_get = 0x40000b0c; +/*coex_core_event_duration_get = 0x40000b0c;*/ coex_core_pti_get = 0x40000b10; coex_core_release = 0x40000b14; coex_core_request = 0x40000b18; coex_core_status_get = 0x40000b1c; -coex_core_timer_idx_get = 0x40000b20; +/*coex_core_timer_idx_get = 0x40000b20;*/ coex_event_duration_get = 0x40000b24; coex_hw_timer_disable = 0x40000b28; coex_hw_timer_enable = 0x40000b2c; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index b8cb6f39f8bb..48b615d00581 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -2069,7 +2069,7 @@ esp_coex_rom_version_get = 0x40005b68; coex_bt_release = 0x40005b74; coex_bt_request = 0x40005b80; coex_core_ble_conn_dyn_prio_get = 0x40005b8c; -coex_core_event_duration_get = 0x40005b98; +/*coex_core_event_duration_get = 0x40005b98;*/ coex_core_pti_get = 0x40005ba4; coex_core_release = 0x40005bb0; coex_core_request = 0x40005bbc; From 8d494a8d033905c3f08d390c39fddd3b1ce95032 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Mon, 1 Apr 2024 13:15:57 +0530 Subject: [PATCH 17/18] Revert "fix(esp_http_client): Call event_handler after header value is received" This reverts commit 04ac8e43dbaf37e42452fef034606ae3f04e644b. Fixes https://github.com/espressif/esp-idf/issues/13497 Fixes https://github.com/espressif/esp-idf/issues/13097 --- components/esp_http_client/esp_http_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 7000916719b0..edd24427a78e 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -238,6 +238,7 @@ static int http_on_header_event(esp_http_client_handle_t client) static int http_on_header_field(http_parser *parser, const char *at, size_t length) { esp_http_client_t *client = parser->data; + http_on_header_event(client); http_utils_append_string(&client->current_header_key, at, length); return 0; @@ -258,7 +259,6 @@ static int http_on_header_value(http_parser *parser, const char *at, size_t leng http_utils_append_string(&client->auth_header, at, length); } http_utils_append_string(&client->current_header_value, at, length); - http_on_header_event(client); return 0; } From 06d18ca0d62e8dfadf002c045339a5ba433c3fbe Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 29 Mar 2024 21:15:41 +0530 Subject: [PATCH 18/18] fix(nimble): Change reconnection scheme --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 2059a808526b..e8b9e5610a1f 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 2059a808526b08660d089e31d7929646d8bdd33e +Subproject commit e8b9e5610a1f9e11d4caf750d1964fe7ec3252c5