Merge branch 'bugfix/dpp_sync_issue' into 'master'

fix(esp_wifi): Fixed DPP concurrency issue

Closes WIFIBUG-1229

See merge request espressif/esp-idf!38832
This commit is contained in:
Jiang Jiang Jian
2025-06-05 19:49:44 +08:00
7 changed files with 209 additions and 83 deletions

View File

@@ -1116,6 +1116,9 @@ typedef enum {
WIFI_EVENT_AP_WRONG_PASSWORD, /**< a station tried to connect with wrong password */
WIFI_EVENT_STA_BEACON_OFFSET_UNSTABLE, /**< Station sampled beacon offset unstable */
WIFI_EVENT_DPP_URI_READY, /**< DPP URI is ready through Bootstrapping */
WIFI_EVENT_DPP_CFG_RECVD, /**< Config received via DPP Authentication */
WIFI_EVENT_DPP_FAILED, /**< DPP failed */
WIFI_EVENT_MAX, /**< Invalid Wi-Fi event ID */
} wifi_event_t;
@@ -1520,6 +1523,22 @@ typedef struct {
float beacon_success_rate; /**< Received beacon success rate */
} wifi_event_sta_beacon_offset_unstable_t;
/** Argument structure for WIFI_EVENT_DPP_URI_READY event */
typedef struct {
uint32_t uri_data_len; /**< URI data length including null termination */
char uri[]; /**< URI data */
} wifi_event_dpp_uri_ready_t;
/** Argument structure for WIFI_EVENT_DPP_CFG_RECVD event */
typedef struct {
wifi_config_t wifi_cfg; /**< Received WIFI config in DPP */
} wifi_event_dpp_config_received_t;
/** Argument structure for WIFI_EVENT_DPP_FAIL event */
typedef struct {
int failure_reason; /**< Failure reason */
} wifi_event_dpp_failed_t;
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -55,7 +55,10 @@ typedef void (*esp_supp_dpp_event_cb_t)(esp_supp_dpp_event_t evt, void *data);
*
* Starts DPP Supplicant and initializes related Data Structures.
*
* @param evt_cb Callback function to receive DPP related events
* @note The `evt_cb` parameter is deprecated and will be ignored in future IDF versions.
* Directly register for WiFi events to get DPP events.
*
* @param evt_cb (Deprecated) Callback function to receive DPP related events
*
* return
* - ESP_OK: Success

View File

@@ -19,6 +19,7 @@
#include "esp_wps_i.h"
#include "rsn_supp/wpa.h"
#include "rsn_supp/pmksa_cache.h"
#include <stdatomic.h>
#ifdef CONFIG_DPP
@@ -31,8 +32,11 @@ struct action_rx_param {
};
static void *s_dpp_api_lock = NULL;
static void *s_dpp_event_group = NULL;
static bool s_dpp_listen_in_progress;
#define DPP_ROC_EVENT_HANDLED BIT0
static atomic_bool roc_in_progress;
static struct esp_dpp_context_t s_dpp_ctx;
static int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel);
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
@@ -41,6 +45,7 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data);
static void roc_status_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data);
static void dpp_listen_next_channel(void *data, void *user_ctx);
static esp_err_t dpp_api_lock(void)
{
if (!s_dpp_api_lock) {
@@ -65,7 +70,30 @@ static esp_err_t dpp_api_unlock(void)
return ESP_OK;
}
static uint8_t esp_dpp_deinit_auth(void)
static void dpp_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
if (!s_dpp_ctx.dpp_event_cb) {
return;
}
switch (event_id) {
case WIFI_EVENT_DPP_URI_READY:
wifi_event_dpp_uri_ready_t *event = (wifi_event_dpp_uri_ready_t *) event_data;
s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_URI_READY, (void *)(event->uri));
break;
case WIFI_EVENT_DPP_CFG_RECVD:
s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_CFG_RECVD, (wifi_config_t *)event_data);
break;
case WIFI_EVENT_DPP_FAILED:
s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_FAIL, (void *)event_data);
break;
default:
break;
}
return;
}
static uint8_t dpp_deinit_auth(void)
{
if (s_dpp_ctx.dpp_auth) {
dpp_auth_deinit(s_dpp_ctx.dpp_auth);
@@ -75,24 +103,38 @@ static uint8_t esp_dpp_deinit_auth(void)
return ESP_OK;
}
static void listen_stop_handler(void *data, void *user_ctx)
static int listen_stop_handler(void *data, void *user_ctx)
{
wifi_roc_req_t req = {0};
s_dpp_listen_in_progress = false;
wpa_printf(MSG_DEBUG, "DPP: Stoping ROC");
req.ifx = WIFI_IF_STA;
req.type = WIFI_ROC_CANCEL;
eloop_cancel_timeout(dpp_listen_next_channel, NULL, NULL);
s_dpp_ctx.dpp_listen_ongoing = false;
esp_wifi_remain_on_channel(&req);
return 0;
}
static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data)
static void dpp_stop(void)
{
if (s_dpp_ctx.dpp_auth) {
esp_dpp_deinit_auth();
dpp_deinit_auth();
listen_stop_handler(NULL, NULL);
}
s_dpp_ctx.dpp_event_cb(evt, data);
}
static void dpp_abort_with_failure(uint32_t failure_reason)
{
/* Stop DPP*/
dpp_stop();
/* Send event to APP */
wifi_event_dpp_failed_t event = {0};
event.failure_reason = failure_reason;
esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_FAILED, &event, sizeof(event), OS_BLOCK);
}
static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx)
@@ -103,7 +145,7 @@ static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx)
wpa_printf(MSG_INFO,
"DPP: Terminate authentication exchange due to Auth Confirm timeout");
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_AUTH_TIMEOUT);
dpp_abort_with_failure(ESP_ERR_DPP_AUTH_TIMEOUT);
}
esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len,
@@ -129,7 +171,7 @@ esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint3
if (ESP_OK != esp_wifi_action_tx_req(req)) {
wpa_printf(MSG_ERROR, "DPP: Failed to perform offchannel operation");
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE);
dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE);
os_free(req);
return ESP_FAIL;
}
@@ -231,7 +273,7 @@ static void gas_query_timeout(void *eloop_data, void *user_ctx)
wpabuf_free(auth->conf_req);
auth->conf_req = NULL;
}
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_CONF_TIMEOUT);
dpp_abort_with_failure(ESP_ERR_DPP_CONF_TIMEOUT);
}
static int gas_query_req_tx(struct dpp_authentication *auth)
@@ -244,7 +286,7 @@ static int gas_query_req_tx(struct dpp_authentication *auth)
supp_op_classes);
if (!buf) {
wpa_printf(MSG_ERROR, "DPP: No configuration request data available");
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE);
dpp_abort_with_failure(ESP_ERR_DPP_FAILURE);
return ESP_FAIL;
}
@@ -292,10 +334,15 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth,
wpa_printf(MSG_INFO, DPP_EVENT_CONNECTOR "%s",
conf->connector);
}
if (s_dpp_listen_in_progress) {
if (atomic_load(&roc_in_progress)) {
listen_stop_handler(NULL, NULL);
}
esp_dpp_call_cb(ESP_SUPP_DPP_CFG_RECVD, wifi_cfg);
/* deinit AUTH since authentication is done */
dpp_deinit_auth();
wifi_event_dpp_config_received_t event = {0};
event.wifi_cfg = s_dpp_ctx.wifi_cfg;
esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD, &event, sizeof(event), OS_BLOCK);
return 0;
}
@@ -548,7 +595,7 @@ static void esp_dpp_rx_action(void *data, void *user_ctx)
(size_t)(public_action->v.pa_vendor_spec.vendor_data -
(u8 *)rx_param->action_frm);
if (s_dpp_listen_in_progress) {
if (atomic_load(&roc_in_progress)) {
listen_stop_handler(NULL, NULL);
}
@@ -570,11 +617,11 @@ static void esp_dpp_rx_action(void *data, void *user_ctx)
os_free(rx_param);
if (ret != ESP_OK) {
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE);
dpp_abort_with_failure(ESP_ERR_DPP_FAILURE);
}
}
void esp_dpp_listen_next_channel(void *data, void *user_ctx)
static void dpp_listen_next_channel(void *data, void *user_ctx)
{
struct dpp_bootstrap_params_t *p = &s_dpp_ctx.bootstrap_params;
static int counter;
@@ -582,10 +629,14 @@ void esp_dpp_listen_next_channel(void *data, void *user_ctx)
esp_err_t ret = 0;
wifi_roc_req_t req = {0};
if (!s_dpp_ctx.dpp_listen_ongoing) {
return;
}
if (p->num_chan <= 0) {
wpa_printf(MSG_ERROR, "Listen channel not set");
return;
}
channel = p->chan_list[counter++ % p->num_chan];
wpa_printf(MSG_DEBUG, "DPP: Starting ROC on channel %d", channel);
@@ -600,12 +651,14 @@ void esp_dpp_listen_next_channel(void *data, void *user_ctx)
wpa_printf(MSG_ERROR, "Failed ROC. error : 0x%x", ret);
return;
}
os_event_group_clear_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED);
}
static void esp_dpp_bootstrap_gen(void *data, void *user_ctx)
{
char *command = data;
const char *uri;
uint32_t len;
s_dpp_ctx.id = dpp_bootstrap_gen(s_dpp_ctx.dpp_global, command);
@@ -618,7 +671,17 @@ static void esp_dpp_bootstrap_gen(void *data, void *user_ctx)
}
uri = dpp_bootstrap_get_uri(s_dpp_ctx.dpp_global, s_dpp_ctx.id);
esp_dpp_call_cb(ESP_SUPP_DPP_URI_READY, (void *)uri);
wifi_event_dpp_uri_ready_t *event;
len = sizeof(*event) + os_strlen(uri) + 1;
event = os_malloc(len);
if (!event) {
return;
}
event->uri_data_len = os_strlen(uri);
os_memcpy(event->uri, uri, event->uri_data_len);
event->uri[event->uri_data_len++] = '\0';
esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY, event, len, OS_BLOCK);
os_free(event);
os_free(command);
dpp_api_lock();
s_dpp_ctx.bootstrap_done = true;
@@ -638,6 +701,14 @@ static int esp_dpp_deinit(void *data, void *user_ctx)
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
&roc_status_handler);
if (s_dpp_ctx.dpp_event_cb) {
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY,
&dpp_event_handler);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD,
&dpp_event_handler);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_FAILED,
&dpp_event_handler);
}
if (params->info) {
os_free(params->info);
params->info = NULL;
@@ -653,6 +724,11 @@ static int esp_dpp_deinit(void *data, void *user_ctx)
}
s_dpp_ctx.dpp_init_done = false;
s_dpp_ctx.bootstrap_done = false;
s_dpp_ctx.dpp_event_cb = NULL;
if (s_dpp_event_group) {
os_event_group_delete(s_dpp_event_group);
s_dpp_event_group = NULL;
}
return 0;
}
@@ -698,7 +774,7 @@ static void esp_dpp_auth_resp_retry(void *eloop_ctx, void *timeout_ctx)
auth->auth_resp_tries++;
if (auth->auth_resp_tries >= max_tries) {
wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE);
dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE);
return;
}
@@ -724,29 +800,30 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base,
return;
}
if (!auth) {
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE);
wpa_printf(MSG_DEBUG, "Auth already deinitialized, return");
return;
}
if (auth->waiting_auth_conf) {
eloop_cancel_timeout(esp_dpp_auth_resp_retry_timeout, NULL, NULL);
if (evt->status) {
if (evt->status == WIFI_ACTION_TX_FAILED) {
/* failed to send auth response frame */
eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL);
eloop_register_timeout(1, 0, esp_dpp_auth_resp_retry, NULL, NULL);
} else {
} else if (evt->status == WIFI_ACTION_TX_DONE) {
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);
}
} else if (auth->auth_success) {
if (evt->status) {
if (evt->status == WIFI_ACTION_TX_FAILED) {
/* failed to send gas query frame, retry logic needed? */
wpa_printf(MSG_WARNING, "DPP: failed to send GAS query frame");
esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE);
} else {
dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE);
} else if (evt->status == WIFI_ACTION_TX_DONE) {
eloop_cancel_timeout(gas_query_timeout, NULL, auth);
eloop_register_timeout(ESP_GAS_TIMEOUT_SECS, 0, gas_query_timeout, NULL, auth);
}
}
atomic_store(&roc_in_progress, true);
}
static void roc_status_handler(void *arg, esp_event_base_t event_base,
@@ -754,9 +831,13 @@ static void roc_status_handler(void *arg, esp_event_base_t event_base,
{
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) {
eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL);
if (evt->context == (uint32_t)s_action_rx_cb) {
eloop_cancel_timeout(dpp_listen_next_channel, NULL, NULL);
eloop_register_timeout(0, 0, dpp_listen_next_channel, NULL, NULL);
}
atomic_store(&roc_in_progress, false);
os_event_group_set_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED);
}
static char *esp_dpp_parse_chan_list(const char *chan_list)
@@ -916,6 +997,12 @@ fail:
return ret;
}
static void dpp_listen_start(void *ctx, void *data)
{
s_dpp_ctx.dpp_listen_ongoing = true;
dpp_listen_next_channel(NULL, NULL);
}
esp_err_t esp_supp_dpp_start_listen(void)
{
int ret = dpp_api_lock();
@@ -933,18 +1020,24 @@ esp_err_t esp_supp_dpp_start_listen(void)
wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started");
return ESP_ERR_INVALID_STATE;
}
wpa_printf(MSG_DEBUG, "DPP: Starting ROC");
/* cancel previous ROC if ongoing */
esp_supp_dpp_stop_listen();
s_dpp_listen_in_progress = true;
eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL);
/* Give ample time to set the bit, timeout is necessary when ROC is not running previously */
os_event_group_wait_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED, 0, 0, os_task_ms_to_tick(100));
wpa_printf(MSG_DEBUG, "DPP: Starting ROC");
eloop_register_timeout(0, 0, dpp_listen_start, NULL, NULL);
return 0;
}
esp_err_t esp_supp_dpp_stop_listen(void)
{
eloop_register_timeout(0, 0, listen_stop_handler, NULL, NULL);
int ret = eloop_register_timeout_blocking(listen_stop_handler, NULL, NULL);
if (ret) {
return ESP_FAIL;
}
return ESP_OK;
}
@@ -980,14 +1073,22 @@ static int esp_dpp_init(void *eloop_data, void *user_ctx)
goto init_fail;
}
s_dpp_listen_in_progress = false;
s_dpp_ctx.dpp_event_cb = cb;
if (cb) {
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY,
&dpp_event_handler, NULL);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD,
&dpp_event_handler, NULL);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_FAILED,
&dpp_event_handler, NULL);
}
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS,
&tx_status_handler, NULL);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
&roc_status_handler, NULL);
s_dpp_event_group = os_event_group_create();
wpa_printf(MSG_INFO, "DPP: dpp init done");
s_dpp_ctx.dpp_init_done = true;

View File

@@ -40,6 +40,7 @@ struct esp_dpp_context_t {
int id;
bool dpp_init_done;
bool bootstrap_done;
bool dpp_listen_ongoing;
};
#ifdef CONFIG_TESTING_OPTIONS

View File

@@ -376,7 +376,7 @@ extern const wifi_osi_funcs_t *wifi_funcs;
#define os_timer_get_time(void) wifi_funcs->_esp_timer_get_time(void)
#define os_event_group_create(void) wifi_funcs->_event_group_create(void)
#define os_event_group_delete(void) wifi_funcs->_event_group_delete(void)
#define os_event_group_delete(a) wifi_funcs->_event_group_delete((a))
#define os_event_group_wait_bits(a, b, c, d, e) wifi_funcs->_event_group_wait_bits((a), (b), (c), (d), (e))
#define os_event_group_clear_bits(a, b) wifi_funcs->_event_group_clear_bits((a), (b))
#define os_event_group_set_bits(a, b) wifi_funcs->_event_group_set_bits((a), (b))

View File

@@ -54,21 +54,56 @@ static EventGroupHandle_t s_dpp_event_group;
static void event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
ESP_ERROR_CHECK(esp_supp_dpp_start_listen());
ESP_LOGI(TAG, "Started listening for DPP Authentication");
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
if (s_retry_num < WIFI_MAX_RETRY_NUM) {
esp_wifi_connect();
s_retry_num++;
ESP_LOGI(TAG, "retry to connect to the AP");
} else {
xEventGroupSetBits(s_dpp_event_group, DPP_CONNECT_FAIL_BIT);
}
ESP_LOGI(TAG, "connect to the AP fail");
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) {
if (event_base == WIFI_EVENT) {
switch (event_id) {
case WIFI_EVENT_STA_START:
ESP_ERROR_CHECK(esp_supp_dpp_start_listen());
ESP_LOGI(TAG, "Started listening for DPP Authentication");
break;
case WIFI_EVENT_STA_DISCONNECTED:
if (s_retry_num < WIFI_MAX_RETRY_NUM) {
esp_wifi_connect();
s_retry_num++;
ESP_LOGI(TAG, "Disconnect event, retry to connect to the AP");
} else {
xEventGroupSetBits(s_dpp_event_group, DPP_CONNECT_FAIL_BIT);
}
break;
case WIFI_EVENT_STA_CONNECTED:
ESP_LOGI(TAG, "Successfully connected to the AP ssid : %s ", s_dpp_wifi_config.sta.ssid);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
break;
case WIFI_EVENT_DPP_URI_READY:
wifi_event_dpp_uri_ready_t *uri_data = event_data;
if (uri_data != NULL) {
esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT();
ESP_LOGI(TAG, "Scan below QR Code to configure the enrollee:");
esp_qrcode_generate(&cfg, (const char *)uri_data->uri);
}
break;
case WIFI_EVENT_DPP_CFG_RECVD:
wifi_event_dpp_config_received_t *config = event_data;
memcpy(&s_dpp_wifi_config, &config->wifi_cfg, sizeof(s_dpp_wifi_config));
s_retry_num = 0;
esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config);
esp_wifi_connect();
break;
case WIFI_EVENT_DPP_FAILED:
wifi_event_dpp_failed_t *dpp_failure = event_data;
if (s_retry_num < 5) {
ESP_LOGI(TAG, "DPP Auth failed (Reason: %s), retry...", esp_err_to_name((int)dpp_failure->failure_reason));
ESP_ERROR_CHECK(esp_supp_dpp_start_listen());
s_retry_num++;
} else {
xEventGroupSetBits(s_dpp_event_group, DPP_AUTH_FAIL_BIT);
}
break;
default:
break;
}
}
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
s_retry_num = 0;
@@ -76,37 +111,6 @@ static void event_handler(void *arg, esp_event_base_t event_base,
}
}
void dpp_enrollee_event_cb(esp_supp_dpp_event_t event, void *data)
{
switch (event) {
case ESP_SUPP_DPP_URI_READY:
if (data != NULL) {
esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT();
ESP_LOGI(TAG, "Scan below QR Code to configure the enrollee:");
esp_qrcode_generate(&cfg, (const char *)data);
}
break;
case ESP_SUPP_DPP_CFG_RECVD:
memcpy(&s_dpp_wifi_config, data, sizeof(s_dpp_wifi_config));
s_retry_num = 0;
esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config);
esp_wifi_connect();
break;
case ESP_SUPP_DPP_FAIL:
if (s_retry_num < 5) {
ESP_LOGI(TAG, "DPP Auth failed (Reason: %s), retry...", esp_err_to_name((int)data));
ESP_ERROR_CHECK(esp_supp_dpp_start_listen());
s_retry_num++;
} else {
xEventGroupSetBits(s_dpp_event_group, DPP_AUTH_FAIL_BIT);
}
break;
default:
break;
}
}
esp_err_t dpp_enrollee_bootstrap(void)
{
esp_err_t ret;
@@ -157,7 +161,7 @@ void dpp_enrollee_init(void)
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(NULL));
ESP_ERROR_CHECK(dpp_enrollee_bootstrap());
ESP_ERROR_CHECK(esp_wifi_start());
@@ -172,8 +176,6 @@ void dpp_enrollee_init(void)
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */
if (bits & DPP_CONNECTED_BIT) {
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
s_dpp_wifi_config.sta.ssid, s_dpp_wifi_config.sta.password);
} else if (bits & DPP_CONNECT_FAIL_BIT) {
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
s_dpp_wifi_config.sta.ssid, s_dpp_wifi_config.sta.password);