kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/dpp_config_memset_v4.4' into 'release/v4.4'
Wi-Fi: Fixed some DPP issues (v4.4) See merge request espressif/esp-idf!27194pull/12720/head
commit
93b64fd6d6
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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;
|
||||||
|
@ -19,7 +19,7 @@ static void *s_dpp_api_lock = NULL;
|
||||||
|
|
||||||
static bool s_dpp_stop_listening;
|
static bool s_dpp_stop_listening;
|
||||||
static int s_dpp_auth_retries;
|
static int s_dpp_auth_retries;
|
||||||
struct esp_dpp_context_t s_dpp_ctx;
|
static struct esp_dpp_context_t s_dpp_ctx;
|
||||||
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
|
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
|
||||||
|
|
||||||
#define DPP_API_LOCK() xSemaphoreTakeRecursive(s_dpp_api_lock, portMAX_DELAY)
|
#define DPP_API_LOCK() xSemaphoreTakeRecursive(s_dpp_api_lock, portMAX_DELAY)
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -176,6 +177,7 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth,
|
||||||
{
|
{
|
||||||
wifi_config_t *wifi_cfg = &s_dpp_ctx.wifi_cfg;
|
wifi_config_t *wifi_cfg = &s_dpp_ctx.wifi_cfg;
|
||||||
|
|
||||||
|
os_memset(wifi_cfg, 0, sizeof(wifi_config_t));
|
||||||
if (conf->ssid_len) {
|
if (conf->ssid_len) {
|
||||||
os_memcpy(wifi_cfg->sta.ssid, conf->ssid, conf->ssid_len);
|
os_memcpy(wifi_cfg->sta.ssid, conf->ssid, conf->ssid_len);
|
||||||
}
|
}
|
||||||
|
@ -378,6 +380,10 @@ static void esp_dpp_task(void *pvParameters )
|
||||||
static int counter;
|
static int counter;
|
||||||
int channel;
|
int channel;
|
||||||
|
|
||||||
|
if (p->num_chan <= 0) {
|
||||||
|
wpa_printf(MSG_ERROR, "Listen channel not set");
|
||||||
|
break;
|
||||||
|
}
|
||||||
channel = p->chan_list[counter++ % p->num_chan];
|
channel = p->chan_list[counter++ % p->num_chan];
|
||||||
esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel,
|
esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel,
|
||||||
BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb);
|
BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb);
|
||||||
|
@ -518,6 +524,10 @@ esp_err_t
|
||||||
esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
||||||
const char *key, const char *uri_info)
|
const char *key, const char *uri_info)
|
||||||
{
|
{
|
||||||
|
if (!s_dpp_ctx.dpp_global) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to bootstrap as dpp not initialized.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
||||||
char *uri_chan_list = esp_dpp_parse_chan_list(chan_list);
|
char *uri_chan_list = esp_dpp_parse_chan_list(chan_list);
|
||||||
char *command = os_zalloc(1200);
|
char *command = os_zalloc(1200);
|
||||||
|
@ -603,6 +613,11 @@ fail:
|
||||||
|
|
||||||
esp_err_t esp_supp_dpp_start_listen(void)
|
esp_err_t esp_supp_dpp_start_listen(void)
|
||||||
{
|
{
|
||||||
|
if (!s_dpp_ctx.dpp_global || s_dpp_ctx.id < 1) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to start listen as dpp not initialized or bootstrapped.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (esp_wifi_get_user_init_flag_internal() == 0) {
|
if (esp_wifi_get_user_init_flag_internal() == 0) {
|
||||||
wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started");
|
wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started");
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
@ -618,8 +633,29 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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;
|
||||||
|
if (esp_wifi_get_mode(&mode) || ((mode != WIFI_MODE_STA) && (mode != WIFI_MODE_APSTA))) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to init as not in station mode.");
|
||||||
|
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) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to init as init already done.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
struct dpp_global_config cfg = {0};
|
struct dpp_global_config cfg = {0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -658,7 +694,6 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
|
||||||
void esp_supp_dpp_deinit(void)
|
void esp_supp_dpp_deinit(void)
|
||||||
{
|
{
|
||||||
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
||||||
|
|
||||||
if (params->info) {
|
if (params->info) {
|
||||||
os_free(params->info);
|
os_free(params->info);
|
||||||
params->info = NULL;
|
params->info = NULL;
|
||||||
|
@ -673,7 +708,10 @@ void esp_supp_dpp_deinit(void)
|
||||||
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
|
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
|
||||||
&offchan_event_handler);
|
&offchan_event_handler);
|
||||||
s_dpp_auth_retries = 0;
|
s_dpp_auth_retries = 0;
|
||||||
dpp_global_deinit(s_dpp_ctx.dpp_global);
|
if (s_dpp_ctx.dpp_global) {
|
||||||
esp_dpp_post_evt(SIG_DPP_DEL_TASK, 0);
|
dpp_global_deinit(s_dpp_ctx.dpp_global);
|
||||||
|
s_dpp_ctx.dpp_global = NULL;
|
||||||
|
esp_dpp_post_evt(SIG_DPP_DEL_TASK, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -2147,6 +2148,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;
|
||||||
|
@ -2163,6 +2169,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) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct dpp_global {
|
||||||
static const struct dpp_curve_params dpp_curves[] = {
|
static const struct dpp_curve_params dpp_curves[] = {
|
||||||
/* The mandatory to support and the default NIST P-256 curve needs to
|
/* The mandatory to support and the default NIST P-256 curve needs to
|
||||||
* be the first entry on this list. */
|
* be the first entry on this list. */
|
||||||
{ "sec256r1", 32, 32, 16, 32, "P-256", 19, "ES256" },
|
{ "secp256r1", 32, 32, 16, 32, "P-256", 19, "ES256" },
|
||||||
{ "secp384r1", 48, 48, 24, 48, "P-384", 20, "ES384" },
|
{ "secp384r1", 48, 48, 24, 48, "P-384", 20, "ES384" },
|
||||||
{ "secp521r1", 64, 64, 32, 66, "P-521", 21, "ES512" },
|
{ "secp521r1", 64, 64, 32, 66, "P-521", 21, "ES512" },
|
||||||
{ "brainpoolP256r1", 32, 32, 16, 32, "BP-256", 28, "BS256" },
|
{ "brainpoolP256r1", 32, 32, 16, 32, "BP-256", 28, "BS256" },
|
||||||
|
@ -4669,7 +4669,8 @@ static struct crypto_key * dpp_parse_jwk(struct json_token *jwk,
|
||||||
{
|
{
|
||||||
struct json_token *token;
|
struct json_token *token;
|
||||||
const struct dpp_curve_params *curve;
|
const struct dpp_curve_params *curve;
|
||||||
struct wpabuf *x = NULL, *y = NULL, *a = NULL;
|
struct wpabuf *x = NULL, *y = NULL;
|
||||||
|
unsigned char *a = NULL;
|
||||||
struct crypto_ec_group *group;
|
struct crypto_ec_group *group;
|
||||||
struct crypto_key *pkey = NULL;
|
struct crypto_key *pkey = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -4731,17 +4732,19 @@ static struct crypto_key * dpp_parse_jwk(struct json_token *jwk,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = wpabuf_len(x);
|
len = wpabuf_len(x) + wpabuf_len(y);
|
||||||
a = wpabuf_concat(x, y);
|
a = os_zalloc(len);
|
||||||
pkey = crypto_ec_set_pubkey_point(group, wpabuf_head(a),
|
os_memcpy(a, wpabuf_head(x), wpabuf_len(x));
|
||||||
len);
|
os_memcpy(a + wpabuf_len(x), wpabuf_head(y), wpabuf_len(y));
|
||||||
|
pkey = crypto_ec_set_pubkey_point(group, a, len);
|
||||||
|
|
||||||
crypto_ec_deinit((struct crypto_ec *)group);
|
crypto_ec_deinit((struct crypto_ec *)group);
|
||||||
*key_curve = curve;
|
*key_curve = curve;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
wpabuf_free(a);
|
|
||||||
wpabuf_free(x);
|
wpabuf_free(x);
|
||||||
wpabuf_free(y);
|
wpabuf_free(y);
|
||||||
|
os_free(a);
|
||||||
|
|
||||||
return pkey;
|
return pkey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,12 +119,12 @@ void dpp_enrollee_init(void)
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
||||||
/* Currently only supported method is QR Code */
|
/* Currently only supported method is QR Code */
|
||||||
ESP_ERROR_CHECK(esp_supp_dpp_bootstrap_gen(EXAMPLE_DPP_LISTEN_CHANNEL_LIST, DPP_BOOTSTRAP_QR_CODE,
|
ESP_ERROR_CHECK(esp_supp_dpp_bootstrap_gen(EXAMPLE_DPP_LISTEN_CHANNEL_LIST, DPP_BOOTSTRAP_QR_CODE,
|
||||||
EXAMPLE_DPP_BOOTSTRAPPING_KEY, EXAMPLE_DPP_DEVICE_INFO));
|
EXAMPLE_DPP_BOOTSTRAPPING_KEY, EXAMPLE_DPP_DEVICE_INFO));
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
|
||||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||||
|
|
Ładowanie…
Reference in New Issue