fix(wifi): Disallow DPP and WPS concurrency

This commit is contained in:
Kapil Gupta
2023-11-01 19:09:58 +05:30
parent 139a0054c7
commit c121908ddd
3 changed files with 37 additions and 14 deletions

View File

@@ -4,13 +4,13 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "esp_dpp_i.h"
#include "esp_dpp.h" #include "esp_dpp.h"
#include "esp_wpa.h" #include "esp_wpa.h"
#include "esp_timer.h" #include "esp_timer.h"
#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_dpp_i.h"
#ifdef CONFIG_DPP #ifdef CONFIG_DPP
static TaskHandle_t s_dpp_task_hdl = NULL; static TaskHandle_t s_dpp_task_hdl = NULL;
@@ -32,6 +32,7 @@ struct action_rx_param {
u32 vendor_data_len; u32 vendor_data_len;
struct ieee80211_action *action_frm; struct ieee80211_action *action_frm;
}; };
extern bool is_wps_enabled(void);
static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data) static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data)
{ {
@@ -631,6 +632,13 @@ void esp_supp_dpp_stop_listen(void)
esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_CANCEL, 0, 0, NULL); esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_CANCEL, 0, 0, NULL);
} }
#ifdef CONFIG_WPA_DPP_SUPPORT
bool is_dpp_enabled(void)
{
return (s_dpp_ctx.dpp_global ? true : false);
}
#endif
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;
@@ -638,6 +646,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,16 +1,8 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ESP_DPP_I_H #ifndef ESP_DPP_I_H
#define ESP_DPP_I_H #define ESP_DPP_I_H
@@ -65,4 +57,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_WPA_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

@@ -14,6 +14,7 @@
#include "common/ieee802_11_defs.h" #include "common/ieee802_11_defs.h"
#include "crypto/dh_group5.h" #include "crypto/dh_group5.h"
#include "wps/wps_i.h" #include "wps/wps_i.h"
#include "esp_dpp_i.h"
#include "wps/wps_dev_attr.h" #include "wps/wps_dev_attr.h"
#include "eap_peer/eap_defs.h" #include "eap_peer/eap_defs.h"
#include "eap_peer/eap_common.h" #include "eap_peer/eap_common.h"
@@ -2134,6 +2135,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;
@@ -2150,6 +2156,10 @@ int wifi_wps_enable_internal(const esp_wps_config_t *config)
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) {