Skip to content

Commit 76723c0

Browse files
kapilkedawatespressif-bot
authored andcommitted
fix(esp_wifi): Fixed DPP concurrency issue
1 parent 92883fb commit 76723c0

File tree

1 file changed

+16
-9
lines changed
  • components/wpa_supplicant/esp_supplicant/src

1 file changed

+16
-9
lines changed

components/wpa_supplicant/esp_supplicant/src/esp_dpp.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "esp_wps_i.h"
2020
#include "rsn_supp/wpa.h"
2121
#include "rsn_supp/pmksa_cache.h"
22+
#include <stdatomic.h>
2223

2324
#ifdef CONFIG_DPP
2425

@@ -32,7 +33,7 @@ struct action_rx_param {
3233

3334
static void *s_dpp_api_lock = NULL;
3435

35-
static bool s_dpp_listen_in_progress;
36+
static atomic_bool s_dpp_listen_in_progress;
3637
static struct esp_dpp_context_t s_dpp_ctx;
3738
static int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel);
3839
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
@@ -75,15 +76,17 @@ static uint8_t esp_dpp_deinit_auth(void)
7576
return ESP_OK;
7677
}
7778

78-
static void listen_stop_handler(void *data, void *user_ctx)
79+
static int listen_stop_handler(void *data, void *user_ctx)
7980
{
8081
wifi_roc_req_t req = {0};
8182

82-
s_dpp_listen_in_progress = false;
83+
atomic_store(&s_dpp_listen_in_progress, false);
8384
req.ifx = WIFI_IF_STA;
8485
req.type = WIFI_ROC_CANCEL;
8586

8687
esp_wifi_remain_on_channel(&req);
88+
89+
return 0;
8790
}
8891

8992
static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data)
@@ -292,7 +295,7 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth,
292295
wpa_printf(MSG_INFO, DPP_EVENT_CONNECTOR "%s",
293296
conf->connector);
294297
}
295-
if (s_dpp_listen_in_progress) {
298+
if (atomic_load(&s_dpp_listen_in_progress)) {
296299
listen_stop_handler(NULL, NULL);
297300
}
298301
esp_dpp_call_cb(ESP_SUPP_DPP_CFG_RECVD, wifi_cfg);
@@ -548,7 +551,7 @@ static void esp_dpp_rx_action(void *data, void *user_ctx)
548551
(size_t)(public_action->v.pa_vendor_spec.vendor_data -
549552
(u8 *)rx_param->action_frm);
550553

551-
if (s_dpp_listen_in_progress) {
554+
if (atomic_load(&s_dpp_listen_in_progress)) {
552555
listen_stop_handler(NULL, NULL);
553556
}
554557

@@ -754,7 +757,7 @@ static void roc_status_handler(void *arg, esp_event_base_t event_base,
754757
{
755758
wifi_event_roc_done_t *evt = (wifi_event_roc_done_t *)event_data;
756759

757-
if (s_dpp_listen_in_progress && evt->context == (uint32_t)s_action_rx_cb) {
760+
if (atomic_load(&s_dpp_listen_in_progress) && evt->context == (uint32_t)s_action_rx_cb) {
758761
eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL);
759762
}
760763
}
@@ -937,14 +940,18 @@ esp_err_t esp_supp_dpp_start_listen(void)
937940

938941
/* cancel previous ROC if ongoing */
939942
esp_supp_dpp_stop_listen();
940-
s_dpp_listen_in_progress = true;
943+
atomic_store(&s_dpp_listen_in_progress, true);
941944
eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL);
942945
return 0;
943946
}
944947

945948
esp_err_t esp_supp_dpp_stop_listen(void)
946949
{
947-
eloop_register_timeout(0, 0, listen_stop_handler, NULL, NULL);
950+
int ret = eloop_register_timeout_blocking(listen_stop_handler, NULL, NULL);
951+
952+
if (ret) {
953+
return ESP_FAIL;
954+
}
948955
return ESP_OK;
949956
}
950957

@@ -980,7 +987,7 @@ static int esp_dpp_init(void *eloop_data, void *user_ctx)
980987
goto init_fail;
981988
}
982989

983-
s_dpp_listen_in_progress = false;
990+
atomic_store(&s_dpp_listen_in_progress, false);
984991
s_dpp_ctx.dpp_event_cb = cb;
985992

986993
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS,

0 commit comments

Comments
 (0)