From 2dc272e88fa96a9913afc19f40831b56d9d57ac7 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 3 Apr 2026 11:26:19 +0530 Subject: [PATCH] fix(wifi): ignore disconnect events outside WPS handshake phase in wps wifi_station_wps_start() calls esp_wifi_disconnect() to leave a previously connected AP before scanning for WPS registrars. When the STA is already connected, the async disconnect event triggers wps_sm_notify_deauth() which incorrectly treats it as a handshake failure, disabling WPS entirely. Guard wps_handle_failure() so it only fires when wps_get_status() is WPS_STATUS_PENDING, i.e. the STA has found a WPS AP and is actively in the M1-M8 exchange. --- .../wpa_supplicant/esp_supplicant/src/esp_wps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c index d316c32013..400c159e47 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-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -913,6 +913,16 @@ static void wps_sm_notify_deauth(void) { if (gWpsSm && gWpsSm->wps->state != WPS_FINISHED && !gWpsSm->intermediate_disconnect) { + /* wifi_station_wps_start() calls esp_wifi_disconnect() to leave the + * previously connected AP before scanning. That synchronous disconnect + * callback must not be treated as a WPS handshake failure. Only act + * on deauths received while actually negotiating (STATUS_PENDING). */ + if (wps_get_status() != WPS_STATUS_PENDING) { + wpa_printf(MSG_DEBUG, "WPS: Ignoring disconnect, not in WPS-handshake phase (status=%d)", + wps_get_status()); + return; + } + wpa_printf(MSG_ERROR, "WPS: Deauthenticated during handshake"); wps_stop_process(WPS_FAIL_REASON_RECV_DEAUTH); } }