[PATCH 1/3] hostapd: Add sa_query_timeout_deauth_class2 testing option

Andrei Otcheretianski andrei.otcheretianski at intel.com
Thu Nov 26 08:59:02 PST 2026


From: Daniel Gabay <daniel.gabay at intel.com>

When an MFP station disconnects without deauthenticating and
attempts to reassociate, the AP initiates SA Query to verify
the existing session. If SA Query times out and the station
sends another association request, the AP normally allows the
reassociation.

Add a testing option to instead respond with an unprotected
Deauthentication frame (reason 6: Class 2 frame from
nonauthenticated STA). This verifies the STA correctly handles
the deauth by reconnecting via full authentication.

Add hwsim test to cover this scenario.

Signed-off-by: Daniel Gabay <daniel.gabay at intel.com>
---
 hostapd/config_file.c      |  2 ++
 hostapd/ctrl_iface.c       |  2 ++
 src/ap/ap_config.h         |  1 +
 src/ap/ieee802_11.c        | 23 ++++++++++++++++++---
 tests/hwsim/test_ap_pmf.py | 41 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index aa5122957f..f197790d36 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -4634,6 +4634,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
 		bss->eapol_key_reserved_random = atoi(pos);
 	} else if (os_strcmp(buf, "test_assoc_comeback_type") == 0) {
 		bss->test_assoc_comeback_type = atoi(pos);
+	} else if (os_strcmp(buf, "sa_query_timeout_deauth_class2") == 0) {
+		bss->sa_query_timeout_deauth_class2 = atoi(pos);
 	} else if (os_strcmp(buf, "presp_elements") == 0) {
 		if (parse_wpabuf_hex(line, buf, &bss->presp_elements, pos))
 			return 1;
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index c53827e29f..a4873db499 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -1377,6 +1377,8 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
 		wpa_printf(MSG_DEBUG,
 			   "TESTING: association_response_status_code=%d",
 			   hapd->conf->association_response_status_code);
+	} else if (os_strcasecmp(cmd, "sa_query_timeout_deauth_class2") == 0) {
+		hapd->conf->sa_query_timeout_deauth_class2 = atoi(value);
 	} else if (os_strcasecmp(cmd, "force_backlog_bytes") == 0) {
 		hapd->force_backlog_bytes = atoi(value);
 #ifdef CONFIG_DPP
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index b8179818ea..7e6359d2cb 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -733,6 +733,7 @@ struct hostapd_bss_config {
 	bool eapol_m3_no_encrypt;
 	bool eapol_key_reserved_random;
 	int test_assoc_comeback_type;
+	int sa_query_timeout_deauth_class2;
 	struct wpabuf *presp_elements;
 	int association_response_status_code;
 
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 736b1bda34..02cc55b528 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -8036,7 +8036,7 @@ int hostapd_process_assoc_ml_info(struct hostapd_data *hapd,
 
 
 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
-			u16 reason_code)
+			u16 reason_code, int no_encrypt)
 {
 	int send_len;
 	struct ieee80211_mgmt reply;
@@ -8051,7 +8051,8 @@ static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
 	send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
 	reply.u.deauth.reason_code = host_to_le16(reason_code);
 
-	if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0, NULL, 0, 0) < 0)
+	if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0,
+				  NULL, 0, no_encrypt) < 0)
 		wpa_printf(MSG_INFO, "Failed to send deauth: %s",
 			   strerror(errno));
 }
@@ -8994,7 +8995,8 @@ static void handle_assoc(struct hostapd_data *hapd,
 				       sta ? sta->aid : -1,
 				       sta ? sta->flags : 0);
 			send_deauth(hapd, mgmt->sa,
-				    WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
+				    WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA,
+				    0);
 			return;
 		}
 	}
@@ -9164,6 +9166,21 @@ static void handle_assoc(struct hostapd_data *hapd,
 	sta->flags |= WLAN_STA_ASSOC_REQ_OK;
 
 	if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
+#ifdef CONFIG_TESTING_OPTIONS
+		/* Send an unprotected Deauthentication frame with reason
+		 * CLASS2_FRAME_FROM_NONAUTH_STA upon receiving an
+		 * association request from a STA whose SA Query has
+		 * timed out, instead of allowing reassociation.
+		 */
+		if (hapd->conf->sa_query_timeout_deauth_class2) {
+			hapd->conf->sa_query_timeout_deauth_class2 = 0;
+			send_deauth(hapd, mgmt->sa,
+				    WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA,
+				    1);
+			hostapd_drv_sta_remove(hapd, sta->addr);
+			return;
+		}
+#endif /* CONFIG_TESTING_OPTIONS */
 		wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
 			   "SA Query procedure", reassoc ? "re" : "");
 		/* TODO: Send a protected Disassociate frame to the STA using
diff --git a/tests/hwsim/test_ap_pmf.py b/tests/hwsim/test_ap_pmf.py
index 06e93d4d25..b670ee35d4 100644
--- a/tests/hwsim/test_ap_pmf.py
+++ b/tests/hwsim/test_ap_pmf.py
@@ -1811,3 +1811,44 @@ def test_ap_pmf_eapol_logoff(dev, apdev):
     ev = dev[0].wait_disconnected(timeout=1)
     if "reason=23" not in ev:
         raise Exception("Unexpected disconnection reason: " + ev)
+
+def test_ap_pmf_deauth_class2_after_sa_query_timeout(dev, apdev):
+    """AP sends unprotected deauth (reason 6) to reassociating STA after SA query timeout"""
+    ssid = "deauth-class2"
+    params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
+    params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
+    params["ieee80211w"] = "2"
+    params["sa_query_timeout_deauth_class2"] = "1"
+    hapd = hostapd.add_ap(apdev[0], params)
+    Wlantest.setup(hapd)
+    wt = Wlantest()
+    wt.flush()
+    wt.add_passphrase("12345678")
+
+    dev[0].connect(ssid, psk="12345678", ieee80211w="2",
+                   key_mgmt="WPA-PSK-SHA256", proto="WPA2",
+                   scan_freq="2412")
+    hapd.wait_sta(wait_4way_hs=True)
+
+    # drop SA locally without notifying the AP
+    if "OK" not in dev[0].request("DROP_SA"):
+        raise Exception("DROP_SA failed")
+
+    # 1. STA tries to connect (auth + assoc)
+    # 2. AP sees assoc from MFP STA with stale session and starts SA Query
+    # 3. AP does not receive SA Query response and times out
+    # 4. STA sends another assoc req; AP responds with unprotected deauth
+    #    reason 6 since the STA is no longer authenticated
+    # 5. STA accepts the deauth, clears the session, and reconnects (auth + assoc)
+    dev[0].request("REASSOCIATE")
+    ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=30)
+    if ev is None:
+        raise Exception("Deauth after SA Query timeout not received")
+    if "reason=6" not in ev:
+        raise Exception("Unexpected reason code: " + ev)
+    dev[0].wait_connected(timeout=30)
+    hapd.wait_4way_hs()
+    hwsim_utils.test_connectivity(dev[0], hapd)
+    if wt.get_sta_counter("reassocresp_comeback", apdev[0]['bssid'],
+                          dev[0].own_addr()) < 1:
+        raise Exception("AP did not use association comeback")
-- 
2.56.1




More information about the Hostap mailing list