From 34795220d2daee060ee92c77e614f5151315deeb Mon Sep 17 00:00:00 2001 From: jgujarathi Date: Tue, 28 Nov 2023 07:52:35 +0530 Subject: [PATCH] fix(wpa_supplicant): Add support for a dpp authentication timeout - Adds support for a 1 second dpp authentication timeout. --- components/esp_common/src/esp_err_to_name.c | 3 +++ .../esp_supplicant/include/esp_dpp.h | 6 +++-- .../esp_supplicant/src/esp_dpp.c | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/components/esp_common/src/esp_err_to_name.c b/components/esp_common/src/esp_err_to_name.c index 0635439a3a..69fe53fb1f 100644 --- a/components/esp_common/src/esp_err_to_name.c +++ b/components/esp_common/src/esp_err_to_name.c @@ -467,6 +467,9 @@ static const esp_err_msg_t esp_err_msg_table[] = { # endif # ifdef ESP_ERR_DPP_INVALID_ATTR ERR_TBL_IT(ESP_ERR_DPP_INVALID_ATTR), /* 12441 0x3099 Encountered invalid DPP Attribute */ +# endif +# ifdef ESP_ERR_DPP_AUTH_TIMEOUT + ERR_TBL_IT(ESP_ERR_DPP_AUTH_TIMEOUT), /* 12442 0x309a DPP Auth response was not recieved in time */ # endif // components/esp_common/include/esp_err.h # ifdef ESP_ERR_MESH_BASE diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h index f932c327ff..6bcd846ef3 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,10 +15,12 @@ extern "C" { #endif +#define ESP_DPP_AUTH_TIMEOUT_SECS 1 + #define ESP_ERR_DPP_FAILURE (ESP_ERR_WIFI_BASE + 151) /*!< Generic failure during DPP Operation */ #define ESP_ERR_DPP_TX_FAILURE (ESP_ERR_WIFI_BASE + 152) /*!< DPP Frame Tx failed OR not Acked */ #define ESP_ERR_DPP_INVALID_ATTR (ESP_ERR_WIFI_BASE + 153) /*!< Encountered invalid DPP Attribute */ - +#define ESP_ERR_DPP_AUTH_TIMEOUT (ESP_ERR_WIFI_BASE + 154) /*!< DPP Auth response was not recieved in time */ /** @brief Types of Bootstrap Methods for DPP. */ typedef enum dpp_bootstrap_type { DPP_BOOTSTRAP_QR_CODE, /**< QR Code Method */ diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c index 8f1e71bbcf..83ef62caa2 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c @@ -6,6 +6,7 @@ #include "utils/includes.h" #include "utils/common.h" +#include "utils/eloop.h" #include "common/defs.h" #include "esp_dpp_i.h" @@ -36,6 +37,7 @@ struct action_rx_param { struct ieee80211_action *action_frm; }; + static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data) { dpp_event_t *evt = os_zalloc(sizeof(dpp_event_t)); @@ -79,6 +81,20 @@ static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data) s_dpp_ctx.dpp_event_cb(evt, data); } +static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx) +{ + if (!s_dpp_ctx.dpp_auth || !s_dpp_ctx.dpp_auth->waiting_auth_conf) + return; + + 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); +} + void esp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len, uint8_t channel, uint32_t wait_time_ms) { @@ -155,6 +171,9 @@ static void esp_dpp_rx_auth_req(struct action_rx_param *rx_param, uint8_t *dpp_d esp_send_action_frame(rx_param->sa, wpabuf_head(s_dpp_ctx.dpp_auth->resp_msg), wpabuf_len(s_dpp_ctx.dpp_auth->resp_msg), rx_param->channel, OFFCHAN_TX_WAIT_TIME); + eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL,NULL); + eloop_register_timeout(ESP_DPP_AUTH_TIMEOUT_SECS, 0, esp_dpp_auth_conf_wait_timeout,NULL, NULL); + return; fail: esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)rc); @@ -239,6 +258,8 @@ static void esp_dpp_rx_auth_conf(struct action_rx_param *rx_param, uint8_t *dpp_ goto fail; } + eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); + if (dpp_auth_conf_rx(auth, (const u8 *)&public_action->v, dpp_data, len) < 0) { wpa_printf(MSG_DEBUG, "DPP: Authentication failed"); @@ -362,6 +383,7 @@ static void esp_dpp_task(void *pvParameters ) switch (evt->id) { case SIG_DPP_DEL_TASK: struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params; + eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); if (params->info) { os_free(params->info); params->info = NULL; @@ -485,6 +507,7 @@ static void offchan_event_handler(void *arg, esp_event_base_t event_base, evt->status, (uint32_t)evt->context); if (evt->status) { + eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); }