fix(wifi): Disallow DPP and WPS concurrency

This commit is contained in:
Kapil Gupta 2023-11-01 19:09:58 +05:30
parent ccc6a5713a
commit 69704efd5d
4 changed files with 32 additions and 2 deletions

View File

@ -14,6 +14,7 @@
#include "esp_event.h" #include "esp_event.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "common/ieee802_11_defs.h" #include "common/ieee802_11_defs.h"
#include "esp_wps_i.h"
#ifdef CONFIG_DPP #ifdef CONFIG_DPP
static void *s_dpp_task_hdl = NULL; static void *s_dpp_task_hdl = NULL;
@ -609,6 +610,11 @@ void esp_supp_dpp_stop_listen(void)
esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL); esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL);
} }
bool is_dpp_enabled(void)
{
return (s_dpp_ctx.dpp_global ? true : false);
}
esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb) esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
{ {
wifi_mode_t mode = 0; wifi_mode_t mode = 0;
@ -616,6 +622,11 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
wpa_printf(MSG_ERROR, "DPP: failed to init as not in station mode."); wpa_printf(MSG_ERROR, "DPP: failed to init as not in station mode.");
return ESP_FAIL; return ESP_FAIL;
} }
if (is_wps_enabled()) {
wpa_printf(MSG_ERROR, "DPP: failed to init since WPS is enabled");
return ESP_FAIL;
}
if (s_dpp_ctx.dpp_global) { if (s_dpp_ctx.dpp_global) {
wpa_printf(MSG_ERROR, "DPP: failed to init as init already done."); wpa_printf(MSG_ERROR, "DPP: failed to init as init already done.");
return ESP_FAIL; return ESP_FAIL;

View File

@ -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 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -55,4 +55,12 @@ struct esp_dpp_context_t {
int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel); int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel);
#ifdef CONFIG_ESP_WIFI_DPP_SUPPORT
bool is_dpp_enabled(void);
#else
static inline bool is_dpp_enabled(void)
{
return false;
}
#endif
#endif /* ESP_DPP_I_H */ #endif /* ESP_DPP_I_H */

View File

@ -26,6 +26,7 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_private/wifi.h" #include "esp_private/wifi.h"
#include "esp_wps_i.h" #include "esp_wps_i.h"
#include "esp_dpp_i.h"
#include "esp_wps.h" #include "esp_wps.h"
#include "eap_common/eap_wsc_common.h" #include "eap_common/eap_wsc_common.h"
#include "esp_wpas_glue.h" #include "esp_wpas_glue.h"
@ -1863,6 +1864,11 @@ int esp_wifi_wps_enable(const esp_wps_config_t *config)
#endif #endif
} }
bool is_wps_enabled(void)
{
return s_wps_enabled;
}
int wifi_wps_enable_internal(const esp_wps_config_t *config) int wifi_wps_enable_internal(const esp_wps_config_t *config)
{ {
int ret = 0; int ret = 0;
@ -1873,7 +1879,10 @@ int wifi_wps_enable_internal(const esp_wps_config_t *config)
wpa_printf(MSG_ERROR, "wps enable: invalid wps type"); wpa_printf(MSG_ERROR, "wps enable: invalid wps type");
return ESP_ERR_WIFI_WPS_TYPE; return ESP_ERR_WIFI_WPS_TYPE;
} }
if (is_dpp_enabled()) {
wpa_printf(MSG_ERROR, "wps enabled failed since DPP is initialized");
return ESP_FAIL;
}
wpa_printf(MSG_DEBUG, "Set factory information."); wpa_printf(MSG_DEBUG, "Set factory information.");
ret = wps_set_factory_info(config); ret = wps_set_factory_info(config);
if (ret != 0) { if (ret != 0) {

View File

@ -125,5 +125,7 @@ static inline int wps_set_status(uint32_t status)
{ {
return esp_wifi_set_wps_status_internal(status); return esp_wifi_set_wps_status_internal(status);
} }
bool is_wps_enabled(void);
int wps_init_cfg_pin(struct wps_config *cfg); int wps_init_cfg_pin(struct wps_config *cfg);
void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx); void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx);