From ef9a42b43808bc41f296156a9605e7be435cad41 Mon Sep 17 00:00:00 2001 From: Aditi Date: Thu, 14 Nov 2024 16:11:25 +0530 Subject: [PATCH] fix(wpa_supplicant): Remove the btm_rrm task from supplicant This commit removes btm_rrm_t task and CONFIG_SUPPLICANT_TASK from wpa_supplicant and make the functions work in wifi task's context. --- components/wpa_supplicant/CMakeLists.txt | 6 +- .../esp_supplicant/src/esp_common.c | 172 +----------------- .../esp_supplicant/src/esp_common_i.h | 16 +- .../esp_supplicant/src/esp_scan.c | 9 +- 4 files changed, 12 insertions(+), 191 deletions(-) diff --git a/components/wpa_supplicant/CMakeLists.txt b/components/wpa_supplicant/CMakeLists.txt index baeb6f550f..6ed400c72f 100644 --- a/components/wpa_supplicant/CMakeLists.txt +++ b/components/wpa_supplicant/CMakeLists.txt @@ -286,13 +286,13 @@ if(CONFIG_ESP_WIFI_DPP_SUPPORT) target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_DPP) endif() if(CONFIG_ESP_WIFI_11KV_SUPPORT) - target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_SUPPLICANT_TASK CONFIG_WNM CONFIG_RRM CONFIG_IEEE80211KV) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WNM CONFIG_RRM CONFIG_IEEE80211KV) endif() if(CONFIG_ESP_WIFI_RRM_SUPPORT) - target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_SUPPLICANT_TASK CONFIG_RRM) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_RRM) endif() if(CONFIG_ESP_WIFI_WNM_SUPPORT) - target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_SUPPLICANT_TASK CONFIG_WNM) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WNM) endif() if(CONFIG_ESP_WIFI_11R_SUPPORT) target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_IEEE80211R) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index a38b9775b0..3b2c7b2518 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -23,6 +23,7 @@ #include "rsn_supp/wpa_i.h" #include "rsn_supp/wpa.h" #include "esp_private/wifi.h" +#include "eloop.h" /* Utility Functions */ esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6]) @@ -36,40 +37,7 @@ esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6]) struct wpa_supplicant g_wpa_supp; #if defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) - -#ifdef CONFIG_SUPPLICANT_TASK -static void *s_supplicant_task_hdl = NULL; -static void *s_supplicant_evt_queue = NULL; -static void *s_supplicant_api_lock = NULL; -static bool s_supplicant_task_init_done; -#define SUPPLICANT_API_LOCK() os_mutex_lock(s_supplicant_api_lock) -#define SUPPLICANT_API_UNLOCK() os_mutex_unlock(s_supplicant_api_lock) -#define SUPPLICANT_TASK_STACK_SIZE (6144 + TASK_STACK_SIZE_ADD) - -static int handle_action_frm(u8 *frame, size_t len, - u8 *sender, int8_t rssi, u8 channel) -{ - struct ieee_mgmt_frame *frm = os_malloc(sizeof(struct ieee_mgmt_frame) + len); - - if (!frm) { - wpa_printf(MSG_ERROR, "memory allocation failed"); - return -1; - } - - os_memcpy(frm->sender, sender, ETH_ALEN); - frm->len = len; - frm->channel = channel; - frm->rssi = rssi; - - os_memcpy(frm->payload, frame, len); - if (esp_supplicant_post_evt(SIG_SUPPLICANT_RX_ACTION, (u32)frm) != 0) { - os_free(frm); - return -1; - } - - return 0; -} -#endif /* CONFIG_SUPPLICANT_TASK */ +static int mgmt_rx_action(u8 *frame, size_t len, u8 *sender, int8_t rssi, u8 channel); #if defined(CONFIG_RRM) static void handle_rrm_frame(struct wpa_supplicant *wpa_s, u8 *sender, @@ -117,53 +85,7 @@ static int mgmt_rx_action(u8 *frame, size_t len, u8 *sender, int8_t rssi, u8 cha return 0; } -#ifdef CONFIG_SUPPLICANT_TASK -static void btm_rrm_task(void *pvParameters) -{ - supplicant_event_t evt; - bool task_del = false; - - while(1) { - if (os_queue_recv(s_supplicant_evt_queue, &evt, OS_BLOCK) != TRUE) - continue; - - /* event validation failed */ - if (evt.id >= SIG_SUPPLICANT_MAX) { - continue; - } - - switch (evt.id) { - case SIG_SUPPLICANT_RX_ACTION: - { - struct ieee_mgmt_frame *frm = (struct ieee_mgmt_frame *)evt.data; - mgmt_rx_action(frm->payload, frm->len, frm->sender, frm->rssi, frm->channel); - os_free(frm); - break; - } - - case SIG_SUPPLICANT_SCAN_DONE: - esp_supplicant_handle_scan_done_evt(); - break; - case SIG_SUPPLICANT_DEL_TASK: - task_del = true; - break; - default: - break; - } - - if (task_del) - break; - } - - os_queue_delete(s_supplicant_evt_queue); - s_supplicant_evt_queue = NULL; - - /* At this point, we completed */ - os_task_delete(NULL); -} -#endif /* CONFIG_SUPPLICANT_TASK */ - -static void clear_bssid_flag(struct wpa_supplicant *wpa_s) +static void clear_bssid_flag_and_channel(struct wpa_supplicant *wpa_s) { wifi_config_t *config; @@ -298,11 +220,7 @@ static int ieee80211_handle_rx_frm(u8 type, u8 *frame, size_t len, u8 *sender, break; #if defined(CONFIG_IEEE80211KV) case WLAN_FC_STYPE_ACTION: -#ifdef CONFIG_SUPPLICANT_TASK - ret = handle_action_frm(frame, len, sender, rssi, channel); -#else /* CONFIG_SUPPLICANT_TASK */ - ret = mgmt_rx_action(frame, len, sender, rssi, channel); -#endif /* CONFIG_SUPPLICANT_TASK */ + mgmt_rx_action(frame, len, sender, rssi, channel); break; #endif /* defined(CONFIG_IEEE80211KV) */ default: @@ -347,33 +265,7 @@ int esp_supplicant_common_init(struct wpa_funcs *wpa_cb) int ret = 0; #if defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) -#ifdef CONFIG_SUPPLICANT_TASK - if (!s_supplicant_api_lock) { - s_supplicant_api_lock = os_recursive_mutex_create(); - } - - if (!s_supplicant_api_lock) { - wpa_printf(MSG_ERROR, "%s: failed to create Supplicant API lock", __func__); - ret = -1; - goto err; - } - - s_supplicant_evt_queue = os_queue_create(3, sizeof(supplicant_event_t)); - - if (!s_supplicant_evt_queue) { - wpa_printf(MSG_ERROR, "%s: failed to create Supplicant event queue", __func__); - ret = -1; - goto err; - } - ret = os_task_create(btm_rrm_task, "btm_rrm_t", SUPPLICANT_TASK_STACK_SIZE, NULL, 2, &s_supplicant_task_hdl); - if (ret != TRUE) { - wpa_printf(MSG_ERROR, "btm: failed to create task"); - ret = -1; - goto err; - } - s_supplicant_task_init_done = true; -#endif /* CONFIG_SUPPLICANT_TASK */ -#if defined(CONFIG_RRM) +#ifdef CONFIG_RRM wpas_rrm_reset(wpa_s); wpas_clear_beacon_rep_data(wpa_s); #endif /* defined(CONFIG_RRM) */ @@ -416,26 +308,6 @@ void esp_supplicant_common_deinit(void) esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype); } #if defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) -#ifdef CONFIG_SUPPLICANT_TASK - /* We have failed to create task, delete queue and exit */ - if (!s_supplicant_task_hdl) { - if (s_supplicant_evt_queue) { - os_queue_delete(s_supplicant_evt_queue); - s_supplicant_evt_queue = NULL; - } - if (s_supplicant_api_lock) { - os_mutex_delete(s_supplicant_api_lock); - s_supplicant_api_lock = NULL; - } - } else if (esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) { - /* failed to post delete event, just delete event queue and exit */ - if (s_supplicant_evt_queue) { - os_queue_delete(s_supplicant_evt_queue); - s_supplicant_evt_queue = NULL; - } - } - s_supplicant_task_init_done = false; -#endif /* CONFIG_SUPPLICANT_TASK */ #endif /* defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) */ } @@ -463,8 +335,8 @@ void supplicant_sta_conn_handler(uint8_t *bssid) void supplicant_sta_disconn_handler(void) { - struct wpa_sm *sm = &gWpaSm; #if defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) + struct wpa_sm *sm = &gWpaSm; struct wpa_supplicant *wpa_s = &g_wpa_supp; #if defined(CONFIG_RRM) @@ -773,11 +645,6 @@ static size_t add_mdie(uint8_t *bssid, uint8_t *ie, size_t len) return mdie_len; } -<<<<<<< HEAD - -#ifdef CONFIG_IEEE80211R -======= ->>>>>>> 9cce89fea9e... fix(wpa_supplicant): Add two separate flags for RRM and WNM int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md, const u8 *ies, size_t ies_len, bool auth_ie) { @@ -847,33 +714,6 @@ int wpa_drv_send_action(struct wpa_supplicant *wpa_s, return ret; } -#ifdef CONFIG_SUPPLICANT_TASK -int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data) -{ - supplicant_event_t evt; - evt.id = evt_id; - evt.data = data; - - /* Make sure lock exists before taking it */ - SUPPLICANT_API_LOCK(); - - /* Make sure no event can be sent when deletion event is sent or task not initialized */ - if (!s_supplicant_task_init_done) { - SUPPLICANT_API_UNLOCK(); - return -1; - } - - if (os_queue_send(s_supplicant_evt_queue, &evt, os_task_ms_to_tick(10)) != TRUE) { - SUPPLICANT_API_UNLOCK(); - return -1; - } - if (evt_id == SIG_SUPPLICANT_DEL_TASK) { - s_supplicant_task_init_done = false; - } - SUPPLICANT_API_UNLOCK(); - return 0; -} -#endif /* CONFIG_SUPPLICANT_TASK */ #else /* defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) */ void esp_set_scan_ie(void) { } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h index 94b67c34d8..3539ddcace 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,20 +21,6 @@ struct ieee_mgmt_frame { u8 payload[0]; }; -int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data); - -typedef struct { - uint32_t id; - uint32_t data; -} supplicant_event_t; - -enum SIG_SUPPLICANT { - SIG_SUPPLICANT_RX_ACTION, - SIG_SUPPLICANT_SCAN_DONE, - SIG_SUPPLICANT_DEL_TASK, - SIG_SUPPLICANT_MAX, -}; - void esp_get_tx_power(uint8_t *tx_power); #ifdef CONFIG_MBO bool mbo_bss_profile_match(u8 *bssid); diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_scan.c b/components/wpa_supplicant/esp_supplicant/src/esp_scan.c index 762e51431b..4ff1a4f7e7 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_scan.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_scan.c @@ -22,6 +22,7 @@ #include "common/wnm_sta.h" #include "esp_scan_i.h" #include "esp_common_i.h" +#include "eloop.h" extern struct wpa_supplicant g_wpa_supp; @@ -35,13 +36,7 @@ static void scan_done_event_handler(void *arg, ETS_STATUS status) wpa_s->type &= ~(1 << WLAN_FC_STYPE_BEACON) & ~(1 << WLAN_FC_STYPE_PROBE_RESP); esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype); } -#ifdef CONFIG_SUPPLICANT_TASK - if (esp_supplicant_post_evt(SIG_SUPPLICANT_SCAN_DONE, 0) != 0) { - wpa_printf(MSG_ERROR, "Posting of scan done failed!"); - } -#else - esp_supplicant_handle_scan_done_evt(); -#endif /*CONFIG_SUPPLICANT_TASK*/ + esp_supplicant_handle_scan_done_evt(); } #if defined(CONFIG_WNM)