From c80ed51aacc26cea3a773b5b3ea8f9fc6b267098 Mon Sep 17 00:00:00 2001 From: Sarvesh Bodakhe Date: Wed, 5 Mar 2025 15:09:46 +0530 Subject: [PATCH] fix(wifi): Resolved WPS connectivity issue with pre-connected stations This fixes the issue where station was not able connect using WPS if it was already in connected state. wifi_wps_scan_done() issues an esp_wifi_disconnect() before calling esp_wifi_connect() to associate with the newly discovered AP. This behavior incorrectly triggered a failure event (WIFI_EVENT_STA_WPS_ER_FAILED) even though the disconnection was part of the normal WPS flow. This commit prevents sending the false failure event, ensuring expected WPS behavior. --- components/wpa_supplicant/esp_supplicant/src/esp_wps.c | 8 ++++++-- components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c index ae5eb4dbc7..41fdf0ab3c 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -877,9 +877,11 @@ int wps_finish(void) return ret; } +/* This will get executed in the wifi task's context */ static void wps_sm_notify_deauth(void) { - if (gWpsSm && gWpsSm->wps->state != WPS_FINISHED) { + if (gWpsSm && gWpsSm->wps->state != WPS_FINISHED && + !gWpsSm->intermediate_disconnect) { wps_stop_process(WPS_FAIL_REASON_RECV_DEAUTH); } } @@ -1644,7 +1646,9 @@ wifi_wps_scan_done(void *arg, ETS_STATUS status) sm->discover_ssid_cnt = 0; if (wps_get_status() == WPS_STATUS_PENDING) { + sm->intermediate_disconnect = true; esp_wifi_disconnect(); + sm->intermediate_disconnect = false; os_memcpy(wifi_config.sta.bssid, sm->bssid, ETH_ALEN); os_memcpy(wifi_config.sta.ssid, (char *)sm->creds[0].ssid, sm->creds[0].ssid_len); diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h index 8d41ff3693..887e9968f8 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h @@ -84,6 +84,7 @@ struct wps_sm { bool wps_pbc_overlap; struct discard_ap_list_t dis_ap_list[WPS_MAX_DIS_AP_NUM]; u8 discard_ap_cnt; + bool intermediate_disconnect; }; #define API_MUTEX_TAKE() do {\