From da22d36fc1140288d308607b397092b313194b56 Mon Sep 17 00:00:00 2001 From: jgujarathi Date: Wed, 10 Jan 2024 09:24:54 +0530 Subject: [PATCH] fix(esp_wifi): Formatting calls to ROC API to match new prototype - Making necessary changes to DPP module and offchannel tests to reflect the changes made to ROC API. --- .../esp_wifi/include/esp_wifi_types_generic.h | 19 ++++--- .../esp_supplicant/src/esp_dpp.c | 50 ++++++++++++------- .../test_apps/main/test_offchannel.c | 40 +++++++++++---- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi_types_generic.h b/components/esp_wifi/include/esp_wifi_types_generic.h index e955153d63..5d18ca383a 100644 --- a/components/esp_wifi/include/esp_wifi_types_generic.h +++ b/components/esp_wifi/include/esp_wifi_types_generic.h @@ -41,12 +41,15 @@ typedef enum { WIFI_IF_MAX /**< Maximum number of interfaces */ } wifi_interface_t; -#define WIFI_OFFCHAN_TX_REQ 1 /**< Request off-channel transmission */ -#define WIFI_OFFCHAN_TX_CANCEL 0 /**< Cancel off-channel transmission */ - -#define WIFI_ROC_REQ 1 /**< Request remain on channel */ -#define WIFI_ROC_CANCEL 0 /**< Cancel remain on channel */ +enum { + WIFI_OFFCHAN_TX_CANCEL, /**< Cancel off-channel transmission */ + WIFI_OFFCHAN_TX_REQ, /**< Request off-channel transmission */ +}; +enum { + WIFI_ROC_CANCEL, /**< Cancel remain on channel */ + WIFI_ROC_REQ, /**< Request remain on channel */ +}; /** * @brief Wi-Fi country policy */ @@ -793,7 +796,7 @@ typedef enum { * */ typedef void (* wifi_action_roc_done_cb_t)(uint32_t context, uint8_t op_id, - wifi_roc_done_status_t status); + wifi_roc_done_status_t status); /** * @brief Remain on Channel request @@ -804,6 +807,7 @@ typedef struct { wifi_interface_t ifx; /**< WiFi interface to send request to */ uint8_t type; /**< ROC operation type */ uint8_t channel; /**< Channel on which to perform ROC Operation */ + wifi_second_chan_t sec_channel; /**< Secondary channel */ uint32_t wait_time_ms; /**< Duration to wait for on target channel */ wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive any response */ uint8_t op_id; /**< ID of this specific ROC operation provided by wifi driver */ @@ -1253,8 +1257,9 @@ typedef struct { */ typedef struct { uint32_t context; /**< Context to identify the initiator of the request */ - wifi_roc_done_status_t status; /**< API request Identifier provided in ROC req */ + wifi_roc_done_status_t status; /**< ROC status */ uint8_t op_id; /**< ID of the corresponding ROC operation */ + uint8_t channel; /**< Channel provided in tx request */ } wifi_event_roc_done_t; /** diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c index 840d88a6ea..8eb43cc1db 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c @@ -28,7 +28,7 @@ static void *s_dpp_api_lock = NULL; static bool s_dpp_listen_in_progress; static struct esp_dpp_context_t s_dpp_ctx; static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action; - +static uint8_t s_current_tx_op_id; #define DPP_API_LOCK() os_mutex_lock(s_dpp_api_lock) #define DPP_API_UNLOCK() os_mutex_unlock(s_dpp_api_lock) @@ -124,6 +124,8 @@ esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint3 return ESP_FAIL; } + wpa_printf(MSG_DEBUG, "Sent DPP action frame %d", req->op_id); + s_current_tx_op_id = req->op_id; os_free(req); return ESP_OK; } @@ -560,21 +562,27 @@ static void esp_dpp_task(void *pvParameters) case SIG_DPP_LISTEN_NEXT_CHANNEL: { struct dpp_bootstrap_params_t *p = &s_dpp_ctx.bootstrap_params; static int counter; - int channel; esp_err_t ret = 0; if (p->num_chan <= 0) { wpa_printf(MSG_ERROR, "Listen channel not set"); break; } - channel = p->chan_list[counter++ % p->num_chan]; - wpa_printf(MSG_DEBUG, "Listening on channel=%d", channel); - ret = esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel, - BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb); + + wifi_roc_req_t req = {0}; + req.ifx = WIFI_IF_STA; + req.type = WIFI_ROC_REQ; + req.channel = p->chan_list[counter++ % p->num_chan]; + req.wait_time_ms = BOOTSTRAP_ROC_WAIT_TIME; + req.rx_cb = s_action_rx_cb; + req.done_cb = NULL; + wpa_printf(MSG_DEBUG, "Listening on channel=%d", req.channel); + ret = esp_wifi_remain_on_channel(&req); if (ret != ESP_OK) { wpa_printf(MSG_ERROR, "Failed ROC. error : 0x%x", ret); break; } + wpa_printf(MSG_DEBUG, "Started DPP listen operation %d", req.op_id); s_dpp_listen_in_progress = true; } break; @@ -656,21 +664,22 @@ static void offchan_event_handler(void *arg, esp_event_base_t event_base, if (event_id == WIFI_EVENT_ACTION_TX_STATUS) { wifi_event_action_tx_status_t *evt = (wifi_event_action_tx_status_t *)event_data; - wpa_printf(MSG_DEBUG, "Mgmt Tx Status - %d, Cookie - 0x%x", - evt->status, (uint32_t)evt->context); + if (evt->op_id == s_current_tx_op_id) { + wpa_printf(MSG_DEBUG, "Mgmt Tx Status - %d, Context - 0x%x Operation ID : %d", + evt->status, (uint32_t)evt->context, evt->op_id); - 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(); + if (evt->status == WIFI_ACTION_TX_FAILED) { + 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); } - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); } - } else if (event_id == WIFI_EVENT_ROC_DONE) { wifi_event_roc_done_t *evt = (wifi_event_roc_done_t *)event_data; - - if (s_dpp_listen_in_progress && evt->context == (uint32_t)s_action_rx_cb) { + /*@TODO : Decide flow for when ROC fails*/ + if (s_dpp_listen_in_progress && evt->context == (uint32_t)s_action_rx_cb && evt->status == WIFI_ROC_DONE) { esp_dpp_post_evt(SIG_DPP_LISTEN_NEXT_CHANNEL, 0); } } @@ -856,7 +865,14 @@ esp_err_t esp_supp_dpp_start_listen(void) esp_err_t esp_supp_dpp_stop_listen(void) { s_dpp_listen_in_progress = false; - return esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL); + wifi_roc_req_t req = {0}; + req.ifx = WIFI_IF_STA; + req.type = WIFI_ROC_CANCEL; + esp_err_t ret = esp_wifi_remain_on_channel(&req); + if (ret != ESP_OK) { + wpa_printf(MSG_ERROR, "DPP: ROC cancel failed"); + } + return ret; } bool is_dpp_enabled(void) diff --git a/components/wpa_supplicant/test_apps/main/test_offchannel.c b/components/wpa_supplicant/test_apps/main/test_offchannel.c index 9e5ef6f5bc..f8043e8a10 100644 --- a/components/wpa_supplicant/test_apps/main/test_offchannel.c +++ b/components/wpa_supplicant/test_apps/main/test_offchannel.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: Unlicense OR CC0-1.0 * @@ -54,7 +54,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, wifi_event_action_tx_status_t *evt = (wifi_event_action_tx_status_t *)event_data; - if (evt->status == 0) { + if (evt->status == WIFI_ACTION_TX_DONE) { ESP_LOGI(TAG, "Action Tx Successful"); } } @@ -147,7 +147,7 @@ void esp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len, os_free(req); } -/* Test that foreground Scan doesn't pre-empt ROC & vice versa */ +/* Test that foreground Scan doesn't preempt ROC & vice versa */ TEST_CASE("Test scan and ROC simultaneously", "[Offchan]") { wifi_action_rx_cb_t rx_cb = dummy_rx_action; @@ -158,8 +158,16 @@ TEST_CASE("Test scan and ROC simultaneously", "[Offchan]") xEventGroupWaitBits(wifi_event, WIFI_START_EVENT, 1, 0, 5000 / portTICK_PERIOD_MS); - TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, - 100, rx_cb)); + wifi_roc_req_t req = {0}; + req.ifx = WIFI_IF_STA; + req.type = WIFI_ROC_REQ; + req.channel = TEST_LISTEN_CHANNEL; + req.wait_time_ms = 100; + req.rx_cb = rx_cb; + req.done_cb = NULL; + + TEST_ESP_OK(esp_wifi_remain_on_channel(&req)); + ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false)); bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT, pdTRUE, pdFALSE, 5000 / portTICK_PERIOD_MS); @@ -167,8 +175,9 @@ TEST_CASE("Test scan and ROC simultaneously", "[Offchan]") vTaskDelay(1000 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false)); - TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, - 100, rx_cb)); + + TEST_ESP_OK(esp_wifi_remain_on_channel(&req)); + bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT, pdTRUE, pdFALSE, 5000 / portTICK_PERIOD_MS); TEST_ASSERT_TRUE(bits == WIFI_SCAN_DONE_EVENT); @@ -228,13 +237,24 @@ static void test_wifi_roc(void) sprintf(mac_str, MACSTR, MAC2STR(mac)); unity_send_signal_param("Listener mac", mac_str); - TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, - 10000, rx_cb)); + wifi_roc_req_t req = {0}; + req.ifx = WIFI_IF_STA; + req.type = WIFI_ROC_REQ; + req.channel = TEST_LISTEN_CHANNEL; + req.wait_time_ms = 10000; + req.rx_cb = rx_cb; + req.done_cb = NULL; + TEST_ESP_OK(esp_wifi_remain_on_channel(&req)); + bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_ACTION_RX_EVENT, pdTRUE, pdFALSE, portMAX_DELAY); /* Confirm that Frame has been received successfully */ if (bits == WIFI_ACTION_RX_EVENT) { - TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL)); + wifi_roc_req_t req = {0}; + req.ifx = WIFI_IF_STA; + req.type = WIFI_ROC_CANCEL; + TEST_ESP_OK(esp_wifi_remain_on_channel(&req)); + vTaskDelay(1000 / portTICK_PERIOD_MS); stop_wifi(); } else {