[PATCH 17/55] AP: Add MIC to the second FT message with association frame encryption

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:16 PST 2026


With Association frame encryption, the FTE in the second FT message
carries a MIC computed with the new PTK-KCK over the FTO and FTR MAC
addresses, the FTR's RSNE and RSNXE, and the frame body. Set it when
the frame is sent.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/ap/ieee802_11.c  | 17 +++++++++++++++++
 src/ap/wpa_auth.h    |  2 ++
 src/ap/wpa_auth_ft.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)

diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 86a532c5f479..94dcfd8994ee 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -991,6 +991,23 @@ static int send_auth_reply(struct hostapd_data *hapd, struct sta_info *sta,
 		   " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
 		   MAC2STR(dst), auth_alg, auth_transaction,
 		   resp, (unsigned long) ies_len, dbg);
+
+#if defined(CONFIG_IEEE80211R_AP) && defined(CONFIG_ENC_ASSOC)
+	if (auth_alg == WLAN_AUTH_FT && resp == WLAN_STATUS_SUCCESS) {
+		struct sta_info *ft_sta = sta ? sta : ap_get_sta(hapd, dst);
+
+		if (ft_sta &&
+		    wpa_ft_msg2_set_mic(ft_sta->wpa_sm,
+					(u8 *)&reply->u.auth.auth_alg,
+					rlen - IEEE80211_HDRLEN) < 0) {
+			wpa_printf(MSG_DEBUG, "FT: Failed to set FTE MIC");
+
+			os_free(buf);
+			return -1;
+		}
+	}
+#endif /* CONFIG_IEEE80211R_AP && CONFIG_ENC_ASSOC */
+
 #ifdef CONFIG_TESTING_OPTIONS
 #ifdef CONFIG_SAE
 	if (hapd->conf->sae_confirm_immediate == 2 &&
diff --git a/src/ap/wpa_auth.h b/src/ap/wpa_auth.h
index eb14e943d798..ad57fe483dd1 100644
--- a/src/ap/wpa_auth.h
+++ b/src/ap/wpa_auth.h
@@ -604,6 +604,8 @@ void wpa_ft_process_auth(struct wpa_state_machine *sm,
 bool wpa_ft_auth_uses_enc_assoc(const struct wpa_authenticator *wpa_auth,
 				const u8 *ies, size_t ies_len);
 bool wpa_auth_sta_ft_enc_assoc(struct wpa_state_machine *sm);
+int wpa_ft_msg2_set_mic(struct wpa_state_machine *sm, u8 *body,
+			size_t body_len);
 int wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
 			    size_t ies_len);
 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
index 83e40f2392db..c2b9aef3593d 100644
--- a/src/ap/wpa_auth_ft.c
+++ b/src/ap/wpa_auth_ft.c
@@ -3862,6 +3862,51 @@ bool wpa_auth_sta_ft_enc_assoc(struct wpa_state_machine *sm)
 #endif /* CONFIG_ENC_ASSOC */
 }
 
+#ifdef CONFIG_ENC_ASSOC
+
+/**
+ * wpa_ft_msg2_set_mic - Set the FTE MIC of the second FT protocol message
+ * @sm: Pointer to WPA state machine data
+ * @body: Frame Body of the Authentication frame (from the Authentication
+ *	Algorithm Number field)
+ * @body_len: Length of the Frame Body
+ * Returns: 0 on success, -1 on failure
+ */
+int wpa_ft_msg2_set_mic(struct wpa_state_machine *sm, u8 *body,
+			size_t body_len)
+{
+	struct wpa_authenticator *wpa_auth;
+	const u8 *rsne, *rsnxe, *ies;
+	u8 *fte, *mic;
+	size_t ies_len;
+
+	if (!sm || !sm->ft_enc_assoc || body_len < 6)
+		return 0;
+
+	wpa_auth = sm->wpa_auth;
+
+	ies = body + 6;
+	ies_len = body_len - 6;
+	fte = (u8 *)get_ie(ies, ies_len, WLAN_EID_FAST_BSS_TRANSITION);
+	if (!fte || fte[1] < 2 + sm->PTK.kck_len)
+		return -1;
+
+	/* MIC follows the 2-octet MIC Control field */
+	mic = fte + 2 + 2;
+	os_memset(mic, 0, sm->PTK.kck_len);
+
+	rsne = get_ie(wpa_auth->wpa_ie, wpa_auth->wpa_ie_len, WLAN_EID_RSN);
+	rsnxe = get_ie(wpa_auth->wpa_ie, wpa_auth->wpa_ie_len, WLAN_EID_RSNX);
+	if (!rsne || !rsnxe)
+		return -1;
+
+	return wpa_ft_msg2_mic(sm->wpa_key_mgmt, sm->PTK.kck,
+			       sm->PTK.kck_len, sm->addr, wpa_auth->addr,
+			       rsne, 2 + rsne[1], rsnxe, 2 + rsnxe[1],
+			       body, body_len, mic);
+}
+
+#endif /* CONFIG_ENC_ASSOC */
 
 void wpa_ft_process_auth(struct wpa_state_machine *sm,
 			 u16 auth_transaction, const u8 *ies, size_t ies_len,
-- 
2.55.0




More information about the Hostap mailing list