[PATCH] ft: defer PTK installation for unassociated AP clients

Giuseppe Piscitelli ooonea at gmail.com
Fri Nov 13 05:11:08 PST 2026


Andrea, thanks for testing. Here is the same patch without the line
wrapping that broke the archived copy.

mac80211 rejects an ordinary FT PTK before the driver station is
associated. hostapd retries after association, but the early request
produces a key-add error for each transition.

Honor the FT station preparation callback before installing the PTK.
For drivers exposing full AP client state, defer ordinary FT keys until
association. Preserve PMF station cleanup and early installation for EPP
peers, which need the key for encrypted association frames. Keep early
installation when the callback is absent.

Tested eight hwsim FT-SAE roams with required PMF, including OTA and
over-DS, with bidirectional traffic after every roam. Key-add errors
changed from eight to zero. A backport on OpenWrt 25.12.6 with ath11k
also completed a real FT roam with PMF and bidirectional traffic,
without the key-add error observed with the original build.

Signed-off-by: Giuseppe Piscitelli <ooonea at gmail.com>
Assisted-by: OpenAI Codex
---
 src/ap/wpa_auth.h      |  1 +
 src/ap/wpa_auth_ft.c   | 13 +++----------
 src/ap/wpa_auth_glue.c |  8 +++++++-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/ap/wpa_auth.h b/src/ap/wpa_auth.h
index 25ffae8..daf8b83 100644
--- a/src/ap/wpa_auth.h
+++ b/src/ap/wpa_auth.h
@@ -425,6 +425,7 @@ struct wpa_auth_callbacks {
 				   const u8 *eapol, size_t eapol_len);
 #ifdef CONFIG_IEEE80211R_AP
 	struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
+	/* Nonzero defers PTK installation until the post-association retry. */
 	int (*add_sta_ft)(void *ctx, const u8 *sta_addr);
 	int (*set_vlan)(void *ctx, const u8 *sta_addr,
 			struct vlan_description *vlan);
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
index e12f2ad..2a4065c 100644
--- a/src/ap/wpa_auth_ft.c
+++ b/src/ap/wpa_auth_ft.c
@@ -2871,7 +2871,7 @@ static inline int wpa_auth_add_sta_ft(struct
wpa_authenticator *wpa_auth,
 				      const u8 *addr)
 {
 	if (!wpa_auth->cb->add_sta_ft)
-		return -1;
+		return 0;
 	return wpa_auth->cb->add_sta_ft(wpa_auth->cb_ctx, addr);
 }

@@ -2898,15 +2898,8 @@ void wpa_ft_install_ptk(struct
wpa_state_machine *sm, int retry)
 		return;
 	}

-	if (!retry)
-		wpa_auth_add_sta_ft(sm->wpa_auth, sm->addr);
-
-	/* FIX: add STA entry to kernel/driver here? The set_key will fail
-	 * most likely without this.. At the moment, STA entry is added only
-	 * after association has been completed. This function will be called
-	 * again after association to get the PTK configured, but that could be
-	 * optimized by adding the STA entry earlier.
-	 */
+	if (!retry && wpa_auth_add_sta_ft(sm->wpa_auth, sm->addr))
+		return;
 	if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, sm->keyidx_active,
 			     sm->PTK.tk, klen, KEY_FLAG_PAIRWISE_RX_TX))
 		return;
diff --git a/src/ap/wpa_auth_glue.c b/src/ap/wpa_auth_glue.c
index 9da2e6d..b29597a 100644
--- a/src/ap/wpa_auth_glue.c
+++ b/src/ap/wpa_auth_glue.c
@@ -1329,9 +1329,15 @@ static int hostapd_wpa_auth_add_sta_ft(void
*ctx, const u8 *sta_addr)
 		 * previous association. */
 		wpa_printf(MSG_DEBUG,
 			   "FT: Remove and re-add driver STA entry after successful FT
authentication");
-		return ap_sta_re_add(hapd, sta);
+		if (ap_sta_re_add(hapd, sta))
+			return -1;
 	}

+	/* EPP needs the key before the encrypted association exchange. */
+	if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
+	    !(sta->flags & WLAN_STA_ASSOC) && !ap_sta_is_epp(sta))
+		return 1;
+
 	return 0;
 }

base-commit: 6d3d778451a9329085eab5777386db0b78d56987
-- 
2.54.0



On Fri, 13 Nov 2026 00:02:53 +0100, Andrea Covelli <andcov23 at gmail.com> wrote:
> On Sun, 18 Oct 2026, Giuseppe Piscitelli wrote:
> > mac80211 rejects an ordinary FT PTK before the driver station is
> > associated. hostapd retries after association, but the early request
> > produces a key-add error for each transition.
>
> I tested this patch on an mt76 AP, as a backport to the hostapd version
> that OpenWrt 25.12.6 ships.
>
> Setup:
> - Cudy WR3000 v1 (MT7981, mt7915e driver), OpenWrt 25.12.6, kernel
>   6.12.112, unmodified mac80211 (backports 6.18.55)
> - hostapd 2025-08-26 (ca266cc2) with OpenWrt's patches, mbedTLS build
> - This patch with the ap_sta_is_epp() condition left out, because that
>   hostapd version has no EPP support. Otherwise unchanged.
> - FT-PSK (WPA2), FT over the air, PMF disabled
>
> Result, about 2 h 50 min after boot:
> - 12 FT reassociations to this AP, from 6 clients
> - no "nl80211: kernel reports: key addition failed"
> - no other hostapd error in the log
>
> For comparison, the OpenWrt pull request below reports the error on
> 10 of 10 FT roams with a stock OpenWrt build.
>
> This does not cover PMF, so it does not reach the ap_sta_re_add()
> branch. It does not cover FT over the DS or EPP either.
>
> Checks that did not involve a radio:
> - hostapd builds with -Werror with the patch on 831364bf, and in the
>   form above on ca266cc2.
> - I ran hostapd_wpa_auth_add_sta_ft(), ap_sta_re_add() and
>   wpa_ft_install_ptk() against a driver stub that refuses a pairwise
>   key for a station that is not associated. No case makes a refused
>   set_key, including the PMF re-add, and the key is configured once,
>   at the retry after association. Mesh, a driver without full AP
>   client state, and EPP stations keep the early attempt.
>
> One practical point: the mail is line-wrapped in four places, so
> git am rejects it as archived. With those lines rejoined it applies to
> its base commit and gives the blob IDs named in the mail. A resend
> without the wrapping would make it easier to apply.
>
> I have suggested that OpenWrt carry this patch:
> https://github.com/openwrt/openwrt/pull/26652#issuecomment-6838107906
>
> Tested-by: Andrea Covelli <andcov23 at gmail.com> # mt7915e, FT-PSK, no PMF



More information about the Hostap mailing list