2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #ifndef CONFIG_NATIVE_WINDOWS
13 #include "utils/common.h"
14 #include "utils/eloop.h"
15 #include "crypto/crypto.h"
16 #include "crypto/sha256.h"
17 #include "crypto/sha384.h"
18 #include "crypto/sha512.h"
19 #include "crypto/random.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
22 #include "common/wpa_ctrl.h"
23 #include "common/sae.h"
24 #include "common/dpp.h"
25 #include "common/ocv.h"
26 #include "radius/radius.h"
27 #include "radius/radius_client.h"
33 #include "ieee802_11_auth.h"
35 #include "ieee802_1x.h"
37 #include "pmksa_cache_auth.h"
40 #include "accounting.h"
41 #include "ap_config.h"
43 #include "p2p_hostapd.h"
44 #include "ap_drv_ops.h"
46 #include "hw_features.h"
47 #include "ieee802_11.h"
53 #include "dpp_hostapd.h"
54 #include "gas_query_ap.h"
58 static struct wpabuf
*
59 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
60 struct sta_info
*sta
, u16
*resp
,
61 struct rsn_pmksa_cache_entry
*pmksa
,
62 struct wpabuf
*erp_resp
,
63 const u8
*msk
, size_t msk_len
,
65 #endif /* CONFIG_FILS */
66 static void handle_auth(struct hostapd_data
*hapd
,
67 const struct ieee80211_mgmt
*mgmt
, size_t len
,
68 int rssi
, int from_queue
);
71 u8
* hostapd_eid_multi_ap(struct hostapd_data
*hapd
, u8
*eid
)
75 if (!hapd
->conf
->multi_ap
)
77 if (hapd
->conf
->multi_ap
& BACKHAUL_BSS
)
78 multi_ap_val
|= MULTI_AP_BACKHAUL_BSS
;
79 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
80 multi_ap_val
|= MULTI_AP_FRONTHAUL_BSS
;
82 return eid
+ add_multi_ap_ie(eid
, 9, multi_ap_val
);
86 u8
* hostapd_eid_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
91 if (hapd
->iface
->current_rates
== NULL
)
94 *pos
++ = WLAN_EID_SUPP_RATES
;
95 num
= hapd
->iface
->num_rates
;
96 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
98 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
101 /* rest of the rates are encoded in Extended supported
107 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
;
110 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
111 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
116 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&& count
< 8) {
118 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
121 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&& count
< 8) {
123 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
130 u8
* hostapd_eid_ext_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
135 if (hapd
->iface
->current_rates
== NULL
)
138 num
= hapd
->iface
->num_rates
;
139 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
141 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
147 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
149 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
+ 8;
153 continue; /* already in SuppRates IE */
154 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
155 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
160 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
) {
163 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
166 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
) {
169 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
176 u16
hostapd_own_capab_info(struct hostapd_data
*hapd
)
178 int capab
= WLAN_CAPABILITY_ESS
;
183 /* Check if any of configured channels require DFS */
184 dfs
= hostapd_is_dfs_required(hapd
->iface
);
186 wpa_printf(MSG_WARNING
, "Failed to check if DFS is required; ret=%d",
191 if (hapd
->iface
->num_sta_no_short_preamble
== 0 &&
192 hapd
->iconf
->preamble
== SHORT_PREAMBLE
)
193 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
195 privacy
= hapd
->conf
->ssid
.wep
.keys_set
;
197 if (hapd
->conf
->ieee802_1x
&&
198 (hapd
->conf
->default_wep_key_len
||
199 hapd
->conf
->individual_wep_key_len
))
206 if (hapd
->conf
->osen
)
208 #endif /* CONFIG_HS20 */
211 capab
|= WLAN_CAPABILITY_PRIVACY
;
213 if (hapd
->iface
->current_mode
&&
214 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
&&
215 hapd
->iface
->num_sta_no_short_slot_time
== 0)
216 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
219 * Currently, Spectrum Management capability bit is set when directly
220 * requested in configuration by spectrum_mgmt_required or when AP is
221 * running on DFS channel.
222 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
224 if (hapd
->iface
->current_mode
&&
225 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211A
&&
226 (hapd
->iconf
->spectrum_mgmt_required
|| dfs
))
227 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
229 for (i
= 0; i
< RRM_CAPABILITIES_IE_LEN
; i
++) {
230 if (hapd
->conf
->radio_measurements
[i
]) {
231 capab
|= IEEE80211_CAP_RRM
;
240 #ifndef CONFIG_NO_RC4
241 static u16
auth_shared_key(struct hostapd_data
*hapd
, struct sta_info
*sta
,
242 u16 auth_transaction
, const u8
*challenge
,
245 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
247 "authentication (shared key, transaction %d)",
250 if (auth_transaction
== 1) {
251 if (!sta
->challenge
) {
252 /* Generate a pseudo-random challenge */
255 sta
->challenge
= os_zalloc(WLAN_AUTH_CHALLENGE_LEN
);
256 if (sta
->challenge
== NULL
)
257 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
259 if (os_get_random(key
, sizeof(key
)) < 0) {
260 os_free(sta
->challenge
);
261 sta
->challenge
= NULL
;
262 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
265 rc4_skip(key
, sizeof(key
), 0,
266 sta
->challenge
, WLAN_AUTH_CHALLENGE_LEN
);
271 if (auth_transaction
!= 3)
272 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
275 if (!iswep
|| !sta
->challenge
|| !challenge
||
276 os_memcmp_const(sta
->challenge
, challenge
,
277 WLAN_AUTH_CHALLENGE_LEN
)) {
278 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
280 "shared key authentication - invalid "
281 "challenge-response");
282 return WLAN_STATUS_CHALLENGE_FAIL
;
285 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
287 "authentication OK (shared key)");
288 sta
->flags
|= WLAN_STA_AUTH
;
289 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
290 os_free(sta
->challenge
);
291 sta
->challenge
= NULL
;
295 #endif /* CONFIG_NO_RC4 */
298 static int send_auth_reply(struct hostapd_data
*hapd
,
299 const u8
*dst
, const u8
*bssid
,
300 u16 auth_alg
, u16 auth_transaction
, u16 resp
,
301 const u8
*ies
, size_t ies_len
, const char *dbg
)
303 struct ieee80211_mgmt
*reply
;
306 int reply_res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
308 rlen
= IEEE80211_HDRLEN
+ sizeof(reply
->u
.auth
) + ies_len
;
309 buf
= os_zalloc(rlen
);
313 reply
= (struct ieee80211_mgmt
*) buf
;
314 reply
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
316 os_memcpy(reply
->da
, dst
, ETH_ALEN
);
317 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
318 os_memcpy(reply
->bssid
, bssid
, ETH_ALEN
);
320 reply
->u
.auth
.auth_alg
= host_to_le16(auth_alg
);
321 reply
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
322 reply
->u
.auth
.status_code
= host_to_le16(resp
);
325 os_memcpy(reply
->u
.auth
.variable
, ies
, ies_len
);
327 wpa_printf(MSG_DEBUG
, "authentication reply: STA=" MACSTR
328 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
329 MAC2STR(dst
), auth_alg
, auth_transaction
,
330 resp
, (unsigned long) ies_len
, dbg
);
331 if (hostapd_drv_send_mlme(hapd
, reply
, rlen
, 0) < 0)
332 wpa_printf(MSG_INFO
, "send_auth_reply: send failed");
334 reply_res
= WLAN_STATUS_SUCCESS
;
342 #ifdef CONFIG_IEEE80211R_AP
343 static void handle_auth_ft_finish(void *ctx
, const u8
*dst
, const u8
*bssid
,
344 u16 auth_transaction
, u16 status
,
345 const u8
*ies
, size_t ies_len
)
347 struct hostapd_data
*hapd
= ctx
;
348 struct sta_info
*sta
;
351 reply_res
= send_auth_reply(hapd
, dst
, bssid
, WLAN_AUTH_FT
,
352 auth_transaction
, status
, ies
, ies_len
,
355 sta
= ap_get_sta(hapd
, dst
);
359 if (sta
->added_unassoc
&& (reply_res
!= WLAN_STATUS_SUCCESS
||
360 status
!= WLAN_STATUS_SUCCESS
)) {
361 hostapd_drv_sta_remove(hapd
, sta
->addr
);
362 sta
->added_unassoc
= 0;
366 if (status
!= WLAN_STATUS_SUCCESS
)
369 hostapd_logger(hapd
, dst
, HOSTAPD_MODULE_IEEE80211
,
370 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FT)");
371 sta
->flags
|= WLAN_STA_AUTH
;
372 mlme_authenticate_indication(hapd
, sta
);
374 #endif /* CONFIG_IEEE80211R_AP */
379 static void sae_set_state(struct sta_info
*sta
, enum sae_state state
,
382 wpa_printf(MSG_DEBUG
, "SAE: State %s -> %s for peer " MACSTR
" (%s)",
383 sae_state_txt(sta
->sae
->state
), sae_state_txt(state
),
384 MAC2STR(sta
->addr
), reason
);
385 sta
->sae
->state
= state
;
389 static struct wpabuf
* auth_build_sae_commit(struct hostapd_data
*hapd
,
390 struct sta_info
*sta
, int update
)
393 const char *password
= NULL
;
394 struct sae_password_entry
*pw
;
395 const char *rx_id
= NULL
;
398 rx_id
= sta
->sae
->tmp
->pw_id
;
400 for (pw
= hapd
->conf
->sae_passwords
; pw
; pw
= pw
->next
) {
401 if (!is_broadcast_ether_addr(pw
->peer_addr
) &&
402 os_memcmp(pw
->peer_addr
, sta
->addr
, ETH_ALEN
) != 0)
404 if ((rx_id
&& !pw
->identifier
) || (!rx_id
&& pw
->identifier
))
406 if (rx_id
&& pw
->identifier
&&
407 os_strcmp(rx_id
, pw
->identifier
) != 0)
409 password
= pw
->password
;
413 password
= hapd
->conf
->ssid
.wpa_passphrase
;
415 wpa_printf(MSG_DEBUG
, "SAE: No password available");
420 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
421 (u8
*) password
, os_strlen(password
), rx_id
,
423 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
427 if (pw
&& pw
->vlan_id
) {
428 if (!sta
->sae
->tmp
) {
430 "SAE: No temporary data allocated - cannot store VLAN ID");
433 sta
->sae
->tmp
->vlan_id
= pw
->vlan_id
;
436 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
+
437 (rx_id
? 3 + os_strlen(rx_id
) : 0));
440 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
441 sta
->sae
->tmp
->anti_clogging_token
: NULL
, rx_id
);
447 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
448 struct sta_info
*sta
)
452 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
456 sae_write_confirm(sta
->sae
, buf
);
462 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
463 struct sta_info
*sta
,
464 const u8
*bssid
, int update
)
469 data
= auth_build_sae_commit(hapd
, sta
, update
);
470 if (!data
&& sta
->sae
->tmp
&& sta
->sae
->tmp
->pw_id
)
471 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
;
473 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
475 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
476 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
477 wpabuf_len(data
), "sae-send-commit");
485 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
486 struct sta_info
*sta
,
492 data
= auth_build_sae_confirm(hapd
, sta
);
494 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
496 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
497 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
498 wpabuf_len(data
), "sae-send-confirm");
506 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
508 struct sta_info
*sta
;
509 unsigned int open
= 0;
511 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
514 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
517 if (sta
->sae
->state
!= SAE_COMMITTED
&&
518 sta
->sae
->state
!= SAE_CONFIRMED
)
521 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
525 /* In addition to already existing open SAE sessions, check whether
526 * there are enough pending commit messages in the processing queue to
527 * potentially result in too many open sessions. */
528 if (open
+ dl_list_len(&hapd
->sae_commit_queue
) >=
529 hapd
->conf
->sae_anti_clogging_threshold
)
536 static u8
sae_token_hash(struct hostapd_data
*hapd
, const u8
*addr
)
538 u8 hash
[SHA256_MAC_LEN
];
540 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
541 addr
, ETH_ALEN
, hash
);
546 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
547 const u8
*token
, size_t token_len
)
549 u8 mac
[SHA256_MAC_LEN
];
555 if (token_len
!= SHA256_MAC_LEN
)
557 idx
= sae_token_hash(hapd
, addr
);
558 token_idx
= hapd
->sae_pending_token_idx
[idx
];
559 if (token_idx
== 0 || token_idx
!= WPA_GET_BE16(token
)) {
560 wpa_printf(MSG_DEBUG
, "SAE: Invalid anti-clogging token from "
561 MACSTR
" - token_idx 0x%04x, expected 0x%04x",
562 MAC2STR(addr
), WPA_GET_BE16(token
), token_idx
);
570 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
571 2, addrs
, len
, mac
) < 0 ||
572 os_memcmp_const(token
+ 2, &mac
[2], SHA256_MAC_LEN
- 2) != 0)
575 hapd
->sae_pending_token_idx
[idx
] = 0; /* invalidate used token */
581 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
582 int group
, const u8
*addr
)
586 struct os_reltime now
;
593 os_get_reltime(&now
);
594 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
595 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60) ||
596 hapd
->sae_token_idx
== 0xffff) {
597 if (random_get_bytes(hapd
->sae_token_key
,
598 sizeof(hapd
->sae_token_key
)) < 0)
600 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
601 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
602 hapd
->last_sae_token_key_update
= now
;
603 hapd
->sae_token_idx
= 0;
604 os_memset(hapd
->sae_pending_token_idx
, 0,
605 sizeof(hapd
->sae_pending_token_idx
));
608 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
612 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
614 p_idx
= sae_token_hash(hapd
, addr
);
615 token_idx
= hapd
->sae_pending_token_idx
[p_idx
];
617 hapd
->sae_token_idx
++;
618 token_idx
= hapd
->sae_token_idx
;
619 hapd
->sae_pending_token_idx
[p_idx
] = token_idx
;
621 WPA_PUT_BE16(idx
, token_idx
);
622 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
626 len
[1] = sizeof(idx
);
627 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
628 2, addrs
, len
, token
) < 0) {
632 WPA_PUT_BE16(token
, token_idx
);
638 static int sae_check_big_sync(struct hostapd_data
*hapd
, struct sta_info
*sta
)
640 if (sta
->sae
->sync
> hapd
->conf
->sae_sync
) {
641 sae_set_state(sta
, SAE_NOTHING
, "Sync > dot11RSNASAESync");
649 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
651 struct hostapd_data
*hapd
= eloop_ctx
;
652 struct sta_info
*sta
= eloop_data
;
655 if (sae_check_big_sync(hapd
, sta
))
658 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
659 " (sync=%d state=%s)",
660 MAC2STR(sta
->addr
), sta
->sae
->sync
,
661 sae_state_txt(sta
->sae
->state
));
663 switch (sta
->sae
->state
) {
665 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
666 eloop_register_timeout(0,
667 hapd
->dot11RSNASAERetransPeriod
* 1000,
668 auth_sae_retransmit_timer
, hapd
, sta
);
671 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
672 eloop_register_timeout(0,
673 hapd
->dot11RSNASAERetransPeriod
* 1000,
674 auth_sae_retransmit_timer
, hapd
, sta
);
681 if (ret
!= WLAN_STATUS_SUCCESS
)
682 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
686 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
688 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
692 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
693 struct sta_info
*sta
)
695 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
698 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
699 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
700 auth_sae_retransmit_timer
, hapd
, sta
);
704 static void sae_sme_send_external_auth_status(struct hostapd_data
*hapd
,
705 struct sta_info
*sta
, u16 status
)
707 struct external_auth params
;
709 os_memset(¶ms
, 0, sizeof(params
));
710 params
.status
= status
;
711 params
.bssid
= sta
->addr
;
712 if (status
== WLAN_STATUS_SUCCESS
&& sta
->sae
)
713 params
.pmkid
= sta
->sae
->pmkid
;
715 hostapd_drv_send_external_auth_status(hapd
, ¶ms
);
719 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
721 #ifndef CONFIG_NO_VLAN
722 struct vlan_description vlan_desc
;
724 if (sta
->sae
->tmp
&& sta
->sae
->tmp
->vlan_id
> 0) {
725 wpa_printf(MSG_DEBUG
, "SAE: Assign STA " MACSTR
727 MAC2STR(sta
->addr
), sta
->sae
->tmp
->vlan_id
);
729 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
730 vlan_desc
.notempty
= 1;
731 vlan_desc
.untagged
= sta
->sae
->tmp
->vlan_id
;
732 if (!hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
734 "Invalid VLAN ID %d in sae_password",
735 sta
->sae
->tmp
->vlan_id
);
739 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0 ||
740 ap_sta_bind_vlan(hapd
, sta
) < 0) {
742 "Failed to assign VLAN ID %d from sae_password to "
743 MACSTR
, sta
->sae
->tmp
->vlan_id
,
748 #endif /* CONFIG_NO_VLAN */
750 sta
->flags
|= WLAN_STA_AUTH
;
751 sta
->auth_alg
= WLAN_AUTH_SAE
;
752 mlme_authenticate_indication(hapd
, sta
);
753 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
754 sae_set_state(sta
, SAE_ACCEPTED
, "Accept Confirm");
755 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
756 sta
->sae
->pmk
, sta
->sae
->pmkid
);
757 sae_sme_send_external_auth_status(hapd
, sta
, WLAN_STATUS_SUCCESS
);
761 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
762 const u8
*bssid
, u8 auth_transaction
, int allow_reuse
,
769 if (auth_transaction
!= 1 && auth_transaction
!= 2)
770 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
772 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
773 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
775 switch (sta
->sae
->state
) {
777 if (auth_transaction
== 1) {
778 ret
= auth_sae_send_commit(hapd
, sta
, bssid
,
782 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
784 if (sae_process_commit(sta
->sae
) < 0)
785 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
788 * In mesh case, both Commit and Confirm can be sent
789 * immediately. In infrastructure BSS, only a single
790 * Authentication frame (Commit) is expected from the AP
791 * here and the second one (Confirm) will be sent once
792 * the STA has sent its second Authentication frame
795 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
797 * Send both Commit and Confirm immediately
798 * based on SAE finite state machine
799 * Nothing -> Confirm transition.
801 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
804 sae_set_state(sta
, SAE_CONFIRMED
,
805 "Sent Confirm (mesh)");
808 * For infrastructure BSS, send only the Commit
809 * message now to get alternating sequence of
810 * Authentication frames between the AP and STA.
811 * Confirm will be sent in
812 * Committed -> Confirmed/Accepted transition
813 * when receiving Confirm from STA.
817 sae_set_retransmit_timer(hapd
, sta
);
819 hostapd_logger(hapd
, sta
->addr
,
820 HOSTAPD_MODULE_IEEE80211
,
822 "SAE confirm before commit");
826 sae_clear_retransmit_timer(hapd
, sta
);
827 if (auth_transaction
== 1) {
828 if (sae_process_commit(sta
->sae
) < 0)
829 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
831 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
834 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
836 sae_set_retransmit_timer(hapd
, sta
);
837 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
839 * In mesh case, follow SAE finite state machine and
840 * send Commit now, if sync count allows.
842 if (sae_check_big_sync(hapd
, sta
))
843 return WLAN_STATUS_SUCCESS
;
846 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
850 sae_set_retransmit_timer(hapd
, sta
);
853 * For instructure BSS, send the postponed Confirm from
854 * Nothing -> Confirmed transition that was reduced to
855 * Nothing -> Committed above.
857 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
861 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
864 * Since this was triggered on Confirm RX, run another
865 * step to get to Accepted without waiting for
868 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
,
873 sae_clear_retransmit_timer(hapd
, sta
);
874 if (auth_transaction
== 1) {
875 if (sae_check_big_sync(hapd
, sta
))
876 return WLAN_STATUS_SUCCESS
;
879 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
883 if (sae_process_commit(sta
->sae
) < 0)
884 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
886 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
890 sae_set_retransmit_timer(hapd
, sta
);
892 sta
->sae
->send_confirm
= 0xffff;
893 sae_accept_sta(hapd
, sta
);
897 if (auth_transaction
== 1 &&
898 (hapd
->conf
->mesh
& MESH_ENABLED
)) {
899 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
900 ") doing reauthentication",
902 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
903 ap_free_sta(hapd
, sta
);
905 } else if (auth_transaction
== 1) {
906 wpa_printf(MSG_DEBUG
, "SAE: Start reauthentication");
907 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
910 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
912 if (sae_process_commit(sta
->sae
) < 0)
913 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
915 sae_set_retransmit_timer(hapd
, sta
);
917 if (sae_check_big_sync(hapd
, sta
))
918 return WLAN_STATUS_SUCCESS
;
921 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
922 sae_clear_temp_data(sta
->sae
);
928 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
930 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
932 return WLAN_STATUS_SUCCESS
;
936 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
938 struct sae_data
*sae
= sta
->sae
;
939 int i
, *groups
= hapd
->conf
->sae_groups
;
940 int default_groups
[] = { 19, 0 };
942 if (sae
->state
!= SAE_COMMITTED
)
945 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
948 groups
= default_groups
;
949 for (i
= 0; groups
[i
] > 0; i
++) {
950 if (sae
->group
== groups
[i
])
954 if (groups
[i
] <= 0) {
955 wpa_printf(MSG_DEBUG
,
956 "SAE: Previously selected group not found from the current configuration");
962 if (groups
[i
] <= 0) {
963 wpa_printf(MSG_DEBUG
,
964 "SAE: No alternative group enabled");
968 if (sae_set_group(sae
, groups
[i
]) < 0)
973 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
977 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
978 const struct ieee80211_mgmt
*mgmt
, size_t len
,
979 u16 auth_transaction
, u16 status_code
)
981 int resp
= WLAN_STATUS_SUCCESS
;
982 struct wpabuf
*data
= NULL
;
983 int *groups
= hapd
->conf
->sae_groups
;
984 int default_groups
[] = { 19, 0 };
989 groups
= default_groups
;
991 #ifdef CONFIG_TESTING_OPTIONS
992 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
993 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
994 pos
= mgmt
->u
.auth
.variable
;
995 end
= ((const u8
*) mgmt
) + len
;
996 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
997 auth_transaction
, resp
, pos
, end
- pos
,
998 "auth-sae-reflection-attack");
1002 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
1003 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
1004 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1005 auth_transaction
, resp
,
1006 wpabuf_head(hapd
->conf
->sae_commit_override
),
1007 wpabuf_len(hapd
->conf
->sae_commit_override
),
1008 "sae-commit-override");
1011 #endif /* CONFIG_TESTING_OPTIONS */
1013 if (auth_transaction
!= 1 ||
1014 status_code
!= WLAN_STATUS_SUCCESS
) {
1018 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
1023 sae_set_state(sta
, SAE_NOTHING
, "Init");
1027 if (sta
->mesh_sae_pmksa_caching
) {
1028 wpa_printf(MSG_DEBUG
,
1029 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1030 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
1031 sta
->mesh_sae_pmksa_caching
= 0;
1034 if (auth_transaction
== 1) {
1035 const u8
*token
= NULL
;
1036 size_t token_len
= 0;
1037 int allow_reuse
= 0;
1039 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1040 HOSTAPD_LEVEL_DEBUG
,
1041 "start SAE authentication (RX commit, status=%u (%s))",
1042 status_code
, status2str(status_code
));
1044 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1045 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1047 pos
= mgmt
->u
.auth
.variable
;
1048 end
= ((const u8
*) mgmt
) + len
;
1049 if (pos
+ sizeof(le16
) > end
) {
1050 wpa_printf(MSG_ERROR
,
1051 "SAE: Too short anti-clogging token request");
1052 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1055 resp
= sae_group_allowed(sta
->sae
, groups
,
1057 if (resp
!= WLAN_STATUS_SUCCESS
) {
1058 wpa_printf(MSG_ERROR
,
1059 "SAE: Invalid group in anti-clogging token request");
1062 pos
+= sizeof(le16
);
1064 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
1065 sta
->sae
->tmp
->anti_clogging_token
=
1066 wpabuf_alloc_copy(pos
, end
- pos
);
1067 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
1068 wpa_printf(MSG_ERROR
,
1069 "SAE: Failed to alloc for anti-clogging token");
1070 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1075 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1076 * is 76, a new Commit Message shall be constructed
1077 * with the Anti-Clogging Token from the received
1078 * Authentication frame, and the commit-scalar and
1079 * COMMIT-ELEMENT previously sent.
1081 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
1082 if (resp
!= WLAN_STATUS_SUCCESS
) {
1083 wpa_printf(MSG_ERROR
,
1084 "SAE: Failed to send commit message");
1087 sae_set_state(sta
, SAE_COMMITTED
,
1088 "Sent Commit (anti-clogging token case in mesh)");
1090 sae_set_retransmit_timer(hapd
, sta
);
1094 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1096 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1098 wpa_printf(MSG_DEBUG
,
1099 "SAE: Peer did not accept our SAE group");
1100 sae_pick_next_group(hapd
, sta
);
1104 if (status_code
!= WLAN_STATUS_SUCCESS
)
1107 if (!(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1108 sta
->sae
->state
== SAE_COMMITTED
) {
1109 /* This is needed in the infrastructure BSS case to
1110 * address a sequence where a STA entry may remain in
1111 * hostapd across two attempts to do SAE authentication
1112 * by the same STA. The second attempt may end up trying
1113 * to use a different group and that would not be
1114 * allowed if we remain in Committed state with the
1115 * previously set parameters. */
1116 pos
= mgmt
->u
.auth
.variable
;
1117 end
= ((const u8
*) mgmt
) + len
;
1118 if (end
- pos
>= (int) sizeof(le16
) &&
1119 sae_group_allowed(sta
->sae
, groups
,
1120 WPA_GET_LE16(pos
)) ==
1121 WLAN_STATUS_SUCCESS
) {
1122 /* Do not waste resources deriving the same PWE
1123 * again since the same group is reused. */
1124 sae_set_state(sta
, SAE_NOTHING
,
1125 "Allow previous PWE to be reused");
1128 sae_set_state(sta
, SAE_NOTHING
,
1129 "Clear existing state to allow restart");
1130 sae_clear_data(sta
->sae
);
1134 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
1135 ((const u8
*) mgmt
) + len
-
1136 mgmt
->u
.auth
.variable
, &token
,
1137 &token_len
, groups
);
1138 if (resp
== SAE_SILENTLY_DISCARD
) {
1139 wpa_printf(MSG_DEBUG
,
1140 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
1141 MAC2STR(sta
->addr
));
1145 if (resp
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1146 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1147 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1148 MACSTR
, MAC2STR(sta
->addr
));
1149 sae_clear_retransmit_timer(hapd
, sta
);
1150 sae_set_state(sta
, SAE_NOTHING
,
1151 "Unknown Password Identifier");
1155 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
1157 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
1158 "incorrect token from " MACSTR
,
1159 MAC2STR(sta
->addr
));
1160 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1164 if (resp
!= WLAN_STATUS_SUCCESS
)
1167 if (!token
&& use_sae_anti_clogging(hapd
) && !allow_reuse
) {
1168 wpa_printf(MSG_DEBUG
,
1169 "SAE: Request anti-clogging token from "
1170 MACSTR
, MAC2STR(sta
->addr
));
1171 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
1173 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
1174 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1175 sae_set_state(sta
, SAE_NOTHING
,
1176 "Request anti-clogging token case in mesh");
1180 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1181 allow_reuse
, &sta_removed
);
1182 } else if (auth_transaction
== 2) {
1183 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1184 HOSTAPD_LEVEL_DEBUG
,
1185 "SAE authentication (RX confirm, status=%u (%s))",
1186 status_code
, status2str(status_code
));
1187 if (status_code
!= WLAN_STATUS_SUCCESS
)
1189 if (sta
->sae
->state
>= SAE_CONFIRMED
||
1190 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
1193 u16 peer_send_confirm
;
1195 var
= mgmt
->u
.auth
.variable
;
1196 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
1198 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1202 peer_send_confirm
= WPA_GET_LE16(var
);
1204 if (sta
->sae
->state
== SAE_ACCEPTED
&&
1205 (peer_send_confirm
<= sta
->sae
->rc
||
1206 peer_send_confirm
== 0xffff)) {
1207 wpa_printf(MSG_DEBUG
,
1208 "SAE: Silently ignore unexpected Confirm from peer "
1210 " (peer-send-confirm=%u Rc=%u)",
1212 peer_send_confirm
, sta
->sae
->rc
);
1216 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
1217 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1220 sta
->sae
->rc
= peer_send_confirm
;
1222 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
, 0,
1225 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1226 HOSTAPD_LEVEL_DEBUG
,
1227 "unexpected SAE authentication transaction %u (status=%u (%s))",
1228 auth_transaction
, status_code
,
1229 status2str(status_code
));
1230 if (status_code
!= WLAN_STATUS_SUCCESS
)
1232 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1236 if (!sta_removed
&& resp
!= WLAN_STATUS_SUCCESS
) {
1237 pos
= mgmt
->u
.auth
.variable
;
1238 end
= ((const u8
*) mgmt
) + len
;
1240 /* Copy the Finite Cyclic Group field from the request if we
1241 * rejected it as unsupported group. */
1242 if (resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1243 !data
&& end
- pos
>= 2)
1244 data
= wpabuf_alloc_copy(pos
, 2);
1246 sae_sme_send_external_auth_status(hapd
, sta
, resp
);
1247 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1248 auth_transaction
, resp
,
1249 data
? wpabuf_head(data
) : (u8
*) "",
1250 data
? wpabuf_len(data
) : 0, "auth-sae");
1254 if (!sta_removed
&& sta
->added_unassoc
&&
1255 (resp
!= WLAN_STATUS_SUCCESS
||
1256 status_code
!= WLAN_STATUS_SUCCESS
)) {
1257 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1258 sta
->added_unassoc
= 0;
1265 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1266 * @hapd: BSS data for the device initiating the authentication
1267 * @sta: the peer to which commit authentication frame is sent
1269 * This function implements Init event handling (IEEE Std 802.11-2012,
1270 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1271 * sta->sae structure should be initialized appropriately via a call to
1272 * sae_prepare_commit().
1274 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1278 if (!sta
->sae
|| !sta
->sae
->tmp
)
1281 if (sta
->sae
->state
!= SAE_NOTHING
)
1284 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1288 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1290 sae_set_retransmit_timer(hapd
, sta
);
1296 void auth_sae_process_commit(void *eloop_ctx
, void *user_ctx
)
1298 struct hostapd_data
*hapd
= eloop_ctx
;
1299 struct hostapd_sae_commit_queue
*q
;
1300 unsigned int queue_len
;
1302 q
= dl_list_first(&hapd
->sae_commit_queue
,
1303 struct hostapd_sae_commit_queue
, list
);
1306 wpa_printf(MSG_DEBUG
,
1307 "SAE: Process next available message from queue");
1308 dl_list_del(&q
->list
);
1309 handle_auth(hapd
, (const struct ieee80211_mgmt
*) q
->msg
, q
->len
,
1313 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1315 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1316 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1321 static void auth_sae_queue(struct hostapd_data
*hapd
,
1322 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1325 struct hostapd_sae_commit_queue
*q
, *q2
;
1326 unsigned int queue_len
;
1327 const struct ieee80211_mgmt
*mgmt2
;
1329 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1330 if (queue_len
>= 15) {
1331 wpa_printf(MSG_DEBUG
,
1332 "SAE: No more room in message queue - drop the new frame from "
1333 MACSTR
, MAC2STR(mgmt
->sa
));
1337 wpa_printf(MSG_DEBUG
, "SAE: Queue Authentication message from "
1338 MACSTR
" for processing (queue_len %u)", MAC2STR(mgmt
->sa
),
1340 q
= os_zalloc(sizeof(*q
) + len
);
1345 os_memcpy(q
->msg
, mgmt
, len
);
1347 /* Check whether there is already a queued Authentication frame from the
1348 * same station with the same transaction number and if so, replace that
1349 * queue entry with the new one. This avoids issues with a peer that
1350 * sends multiple times (e.g., due to frequent SAE retries). There is no
1351 * point in us trying to process the old attempts after a new one has
1352 * obsoleted them. */
1353 dl_list_for_each(q2
, &hapd
->sae_commit_queue
,
1354 struct hostapd_sae_commit_queue
, list
) {
1355 mgmt2
= (const struct ieee80211_mgmt
*) q2
->msg
;
1356 if (os_memcmp(mgmt
->sa
, mgmt2
->sa
, ETH_ALEN
) == 0 &&
1357 mgmt
->u
.auth
.auth_transaction
==
1358 mgmt2
->u
.auth
.auth_transaction
) {
1359 wpa_printf(MSG_DEBUG
,
1360 "SAE: Replace queued message from same STA with same transaction number");
1361 dl_list_add(&q2
->list
, &q
->list
);
1362 dl_list_del(&q2
->list
);
1368 /* No pending identical entry, so add to the end of the queue */
1369 dl_list_add_tail(&hapd
->sae_commit_queue
, &q
->list
);
1372 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1374 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1379 static int auth_sae_queued_addr(struct hostapd_data
*hapd
, const u8
*addr
)
1381 struct hostapd_sae_commit_queue
*q
;
1382 const struct ieee80211_mgmt
*mgmt
;
1384 dl_list_for_each(q
, &hapd
->sae_commit_queue
,
1385 struct hostapd_sae_commit_queue
, list
) {
1386 mgmt
= (const struct ieee80211_mgmt
*) q
->msg
;
1387 if (os_memcmp(addr
, mgmt
->sa
, ETH_ALEN
) == 0)
1394 #endif /* CONFIG_SAE */
1397 static u16
wpa_res_to_status_code(int res
)
1399 if (res
== WPA_INVALID_GROUP
)
1400 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1401 if (res
== WPA_INVALID_PAIRWISE
)
1402 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1403 if (res
== WPA_INVALID_AKMP
)
1404 return WLAN_STATUS_AKMP_NOT_VALID
;
1405 if (res
== WPA_ALLOC_FAIL
)
1406 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1407 #ifdef CONFIG_IEEE80211W
1408 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1409 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1410 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1411 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1412 #endif /* CONFIG_IEEE80211W */
1413 if (res
== WPA_INVALID_MDIE
)
1414 return WLAN_STATUS_INVALID_MDIE
;
1415 if (res
== WPA_INVALID_PMKID
)
1416 return WLAN_STATUS_INVALID_PMKID
;
1417 if (res
!= WPA_IE_OK
)
1418 return WLAN_STATUS_INVALID_IE
;
1419 return WLAN_STATUS_SUCCESS
;
1425 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1426 struct sta_info
*sta
, u16 resp
,
1427 struct wpabuf
*data
, int pub
);
1429 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1430 const u8
*pos
, size_t len
, u16 auth_alg
,
1431 u16 auth_transaction
, u16 status_code
,
1432 void (*cb
)(struct hostapd_data
*hapd
,
1433 struct sta_info
*sta
, u16 resp
,
1434 struct wpabuf
*data
, int pub
))
1436 u16 resp
= WLAN_STATUS_SUCCESS
;
1438 struct ieee802_11_elems elems
;
1440 struct wpa_ie_data rsn
;
1441 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1443 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1448 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1452 #ifdef CONFIG_FILS_SK_PFS
1453 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1458 /* Using FILS PFS */
1460 /* Finite Cyclic Group */
1461 if (end
- pos
< 2) {
1462 wpa_printf(MSG_DEBUG
,
1463 "FILS: No room for Finite Cyclic Group");
1464 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1467 group
= WPA_GET_LE16(pos
);
1469 if (group
!= hapd
->conf
->fils_dh_group
) {
1470 wpa_printf(MSG_DEBUG
,
1471 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1472 group
, hapd
->conf
->fils_dh_group
);
1473 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1477 crypto_ecdh_deinit(sta
->fils_ecdh
);
1478 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1479 if (!sta
->fils_ecdh
) {
1480 wpa_printf(MSG_INFO
,
1481 "FILS: Could not initialize ECDH with group %d",
1483 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1487 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1489 wpa_printf(MSG_DEBUG
,
1490 "FILS: Failed to derive ECDH public key");
1491 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1494 elem_len
= wpabuf_len(pub
);
1498 if ((size_t) (end
- pos
) < elem_len
) {
1499 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1500 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1504 wpabuf_free(sta
->fils_g_sta
);
1505 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1506 wpabuf_clear_free(sta
->fils_dh_ss
);
1507 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1509 if (!sta
->fils_dh_ss
) {
1510 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1511 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1514 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1517 crypto_ecdh_deinit(sta
->fils_ecdh
);
1518 sta
->fils_ecdh
= NULL
;
1519 wpabuf_clear_free(sta
->fils_dh_ss
);
1520 sta
->fils_dh_ss
= NULL
;
1522 #endif /* CONFIG_FILS_SK_PFS */
1524 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1525 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1526 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1527 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1532 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1533 elems
.rsn_ie
, elems
.rsn_ie_len
);
1534 if (!elems
.rsn_ie
||
1535 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1537 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1538 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1543 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1546 wpa_printf(MSG_DEBUG
,
1547 "FILS: Failed to initialize RSN state machine");
1548 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1552 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1554 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1555 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1556 resp
= wpa_res_to_status_code(res
);
1557 if (resp
!= WLAN_STATUS_SUCCESS
)
1560 if (!elems
.fils_nonce
) {
1561 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1562 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1565 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1567 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1570 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1574 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1575 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1578 num
= rsn
.num_pmkid
;
1580 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1581 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1585 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1594 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1595 wpa_printf(MSG_DEBUG
,
1596 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1597 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1601 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1604 if (!elems
.fils_session
) {
1605 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1606 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1609 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1611 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1613 /* FILS Wrapped Data */
1614 if (elems
.fils_wrapped_data
) {
1615 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1616 elems
.fils_wrapped_data
,
1617 elems
.fils_wrapped_data_len
);
1619 #ifndef CONFIG_NO_RADIUS
1620 if (!sta
->eapol_sm
) {
1622 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1624 wpa_printf(MSG_DEBUG
,
1625 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1626 ieee802_1x_encapsulate_radius(
1627 hapd
, sta
, elems
.fils_wrapped_data
,
1628 elems
.fils_wrapped_data_len
);
1629 sta
->fils_pending_cb
= cb
;
1630 wpa_printf(MSG_DEBUG
,
1631 "FILS: Will send Authentication frame once the response from authentication server is available");
1632 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1633 /* Calculate pending PMKID here so that we do not need
1634 * to maintain a copy of the EAP-Initiate/Reauth
1636 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1637 elems
.fils_wrapped_data
,
1638 elems
.fils_wrapped_data_len
,
1639 sta
->fils_erp_pmkid
) == 0)
1640 sta
->fils_erp_pmkid_set
= 1;
1642 #else /* CONFIG_NO_RADIUS */
1643 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1645 #endif /* CONFIG_NO_RADIUS */
1651 struct wpabuf
*data
;
1654 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1657 wpa_printf(MSG_DEBUG
,
1658 "%s: prepare_auth_resp_fils() returned failure",
1662 cb(hapd
, sta
, resp
, data
, pub
);
1667 static struct wpabuf
*
1668 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1669 struct sta_info
*sta
, u16
*resp
,
1670 struct rsn_pmksa_cache_entry
*pmksa
,
1671 struct wpabuf
*erp_resp
,
1672 const u8
*msk
, size_t msk_len
,
1675 u8 fils_nonce
[FILS_NONCE_LEN
];
1677 struct wpabuf
*data
= NULL
;
1680 const u8
*pmk
= NULL
;
1682 u8 pmk_buf
[PMK_LEN_MAX
];
1683 struct wpabuf
*pub
= NULL
;
1685 if (*resp
!= WLAN_STATUS_SUCCESS
)
1688 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1690 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1695 /* Add PMKID of the selected PMKSA into RSNE */
1696 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1698 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1702 os_memcpy(ie_buf
, ie
, ielen
);
1703 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1704 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1710 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1711 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1714 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1715 fils_nonce
, FILS_NONCE_LEN
);
1717 #ifdef CONFIG_FILS_SK_PFS
1718 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1719 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1721 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1725 #endif /* CONFIG_FILS_SK_PFS */
1727 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1729 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1734 #ifdef CONFIG_FILS_SK_PFS
1736 /* Finite Cyclic Group */
1737 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1740 wpabuf_put_buf(data
, pub
);
1742 #endif /* CONFIG_FILS_SK_PFS */
1745 wpabuf_put_data(data
, ie
, ielen
);
1747 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1749 #ifdef CONFIG_IEEE80211R_AP
1750 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1751 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1753 int use_sha384
= wpa_key_mgmt_sha384(
1754 wpa_auth_sta_key_mgmt(sta
->wpa_sm
));
1756 res
= wpa_auth_write_fte(hapd
->wpa_auth
, use_sha384
,
1757 wpabuf_put(data
, 0),
1758 wpabuf_tailroom(data
));
1760 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1763 wpabuf_put(data
, res
);
1765 #endif /* CONFIG_IEEE80211R_AP */
1768 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1769 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1770 /* Element ID Extension */
1771 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1772 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1775 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1776 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1777 /* Element ID Extension */
1778 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1779 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1781 /* FILS Wrapped Data */
1782 if (!pmksa
&& erp_resp
) {
1783 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1784 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1785 /* Element ID Extension */
1786 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1787 wpabuf_put_buf(data
, erp_resp
);
1789 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1790 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1792 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1794 wpabuf_len(sta
->fils_dh_ss
) : 0,
1795 pmk_buf
, &pmk_len
)) {
1796 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1797 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1804 /* Don't use DHss in PTK derivation if PMKSA caching is not
1806 wpabuf_clear_free(sta
->fils_dh_ss
);
1807 sta
->fils_dh_ss
= NULL
;
1809 if (sta
->fils_erp_pmkid_set
) {
1810 /* TODO: get PMKLifetime from WPA parameters */
1811 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1812 int session_timeout
;
1814 session_timeout
= dot11RSNAConfigPMKLifetime
;
1815 if (sta
->session_timeout_set
) {
1816 struct os_reltime now
, diff
;
1818 os_get_reltime(&now
);
1819 os_reltime_sub(&sta
->session_timeout
, &now
,
1821 session_timeout
= diff
.sec
;
1824 sta
->fils_erp_pmkid_set
= 0;
1825 wpa_auth_add_fils_pmk_pmkid(sta
->wpa_sm
, pmk
, pmk_len
,
1826 sta
->fils_erp_pmkid
);
1827 if (!hapd
->conf
->disable_pmksa_caching
&&
1828 wpa_auth_pmksa_add2(
1829 hapd
->wpa_auth
, sta
->addr
,
1831 sta
->fils_erp_pmkid
,
1833 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1834 wpa_printf(MSG_ERROR
,
1835 "FILS: Failed to add PMKSA cache entry based on ERP");
1840 pmk_len
= pmksa
->pmk_len
;
1844 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1845 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1851 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1852 sta
->fils_snonce
, fils_nonce
,
1854 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1856 wpabuf_len(sta
->fils_dh_ss
) : 0,
1857 sta
->fils_g_sta
, pub
) < 0) {
1858 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1866 *is_pub
= pub
!= NULL
;
1869 wpabuf_clear_free(sta
->fils_dh_ss
);
1870 sta
->fils_dh_ss
= NULL
;
1871 #ifdef CONFIG_FILS_SK_PFS
1872 crypto_ecdh_deinit(sta
->fils_ecdh
);
1873 sta
->fils_ecdh
= NULL
;
1874 #endif /* CONFIG_FILS_SK_PFS */
1879 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1880 struct sta_info
*sta
, u16 resp
,
1881 struct wpabuf
*data
, int pub
)
1886 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1887 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1888 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1889 data
? wpabuf_head(data
) : (u8
*) "",
1890 data
? wpabuf_len(data
) : 0, "auth-fils-finish");
1893 if (resp
== WLAN_STATUS_SUCCESS
) {
1894 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1895 HOSTAPD_LEVEL_DEBUG
,
1896 "authentication OK (FILS)");
1897 sta
->flags
|= WLAN_STA_AUTH
;
1898 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1899 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1900 mlme_authenticate_indication(hapd
, sta
);
1905 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
1906 struct sta_info
*sta
, int success
,
1907 struct wpabuf
*erp_resp
,
1908 const u8
*msk
, size_t msk_len
)
1910 struct wpabuf
*data
;
1914 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1916 if (!sta
->fils_pending_cb
)
1918 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
1919 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
1920 msk
, msk_len
, &pub
);
1922 wpa_printf(MSG_DEBUG
,
1923 "%s: prepare_auth_resp_fils() returned failure",
1926 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
1929 #endif /* CONFIG_FILS */
1933 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
1934 const u8
*msg
, size_t len
, u32
*session_timeout
,
1935 u32
*acct_interim_interval
,
1936 struct vlan_description
*vlan_id
,
1937 struct hostapd_sta_wpa_psk_short
**psk
,
1938 char **identity
, char **radius_cui
, int is_probe_req
)
1942 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
1943 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
1944 session_timeout
, acct_interim_interval
,
1945 vlan_id
, psk
, identity
, radius_cui
,
1948 if (res
== HOSTAPD_ACL_REJECT
) {
1950 wpa_printf(MSG_DEBUG
,
1952 " not allowed to authenticate",
1954 return HOSTAPD_ACL_REJECT
;
1957 if (res
== HOSTAPD_ACL_PENDING
) {
1958 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
1959 " waiting for an external authentication",
1961 /* Authentication code will re-send the authentication frame
1962 * after it has received (and cached) information from the
1963 * external source. */
1964 return HOSTAPD_ACL_PENDING
;
1972 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1973 int res
, u32 session_timeout
,
1974 u32 acct_interim_interval
,
1975 struct vlan_description
*vlan_id
,
1976 struct hostapd_sta_wpa_psk_short
**psk
,
1977 char **identity
, char **radius_cui
)
1979 if (vlan_id
->notempty
&&
1980 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
1981 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1983 "Invalid VLAN %d%s received from RADIUS server",
1985 vlan_id
->tagged
[0] ? "+" : "");
1988 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
1991 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1992 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
1994 hostapd_free_psk_list(sta
->psk
);
1995 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
2002 os_free(sta
->identity
);
2003 sta
->identity
= *identity
;
2006 os_free(sta
->radius_cui
);
2007 sta
->radius_cui
= *radius_cui
;
2010 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
2011 sta
->acct_interim_interval
= acct_interim_interval
;
2012 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
) {
2013 sta
->session_timeout_set
= 1;
2014 os_get_reltime(&sta
->session_timeout
);
2015 sta
->session_timeout
.sec
+= session_timeout
;
2016 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
2018 sta
->session_timeout_set
= 0;
2019 ap_sta_no_session_timeout(hapd
, sta
);
2026 static void handle_auth(struct hostapd_data
*hapd
,
2027 const struct ieee80211_mgmt
*mgmt
, size_t len
,
2028 int rssi
, int from_queue
)
2030 u16 auth_alg
, auth_transaction
, status_code
;
2031 u16 resp
= WLAN_STATUS_SUCCESS
;
2032 struct sta_info
*sta
= NULL
;
2035 const u8
*challenge
= NULL
;
2036 u32 session_timeout
, acct_interim_interval
;
2037 struct vlan_description vlan_id
;
2038 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
2039 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
2040 size_t resp_ies_len
= 0;
2041 char *identity
= NULL
;
2042 char *radius_cui
= NULL
;
2045 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
2046 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
2047 (unsigned long) len
);
2051 #ifdef CONFIG_TESTING_OPTIONS
2052 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
2053 drand48() < hapd
->iconf
->ignore_auth_probability
) {
2054 wpa_printf(MSG_INFO
,
2055 "TESTING: ignoring auth frame from " MACSTR
,
2059 #endif /* CONFIG_TESTING_OPTIONS */
2061 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
2062 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
2063 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
2064 fc
= le_to_host16(mgmt
->frame_control
);
2065 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
2067 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
2068 2 + WLAN_AUTH_CHALLENGE_LEN
&&
2069 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
2070 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
2071 challenge
= &mgmt
->u
.auth
.variable
[2];
2073 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
2074 "auth_transaction=%d status_code=%d wep=%d%s "
2075 "seq_ctrl=0x%x%s%s",
2076 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
2077 status_code
, !!(fc
& WLAN_FC_ISWEP
),
2078 challenge
? " challenge" : "",
2079 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "",
2080 from_queue
? " (from queue)" : "");
2082 #ifdef CONFIG_NO_RC4
2083 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
2084 wpa_printf(MSG_INFO
,
2085 "Unsupported authentication algorithm (%d)",
2087 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2090 #endif /* CONFIG_NO_RC4 */
2092 if (hapd
->tkip_countermeasures
) {
2093 wpa_printf(MSG_DEBUG
,
2094 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2095 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2099 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
2100 auth_alg
== WLAN_AUTH_OPEN
) ||
2101 #ifdef CONFIG_IEEE80211R_AP
2102 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
2103 auth_alg
== WLAN_AUTH_FT
) ||
2104 #endif /* CONFIG_IEEE80211R_AP */
2106 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
2107 auth_alg
== WLAN_AUTH_SAE
) ||
2108 #endif /* CONFIG_SAE */
2110 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2111 auth_alg
== WLAN_AUTH_FILS_SK
) ||
2112 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2113 hapd
->conf
->fils_dh_group
&&
2114 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
2115 #endif /* CONFIG_FILS */
2116 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
2117 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
2118 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
2120 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2124 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
2125 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
2126 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
2128 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
2132 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
2133 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
2135 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2139 if (hapd
->conf
->no_auth_if_seen_on
) {
2140 struct hostapd_data
*other
;
2142 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
2143 hapd
->conf
->no_auth_if_seen_on
);
2147 u8 op_class
, channel
, phytype
;
2149 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
2150 MACSTR
" since STA has been seen on %s",
2151 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
2152 hapd
->conf
->no_auth_if_seen_on
);
2154 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
2156 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
2158 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
2160 info
= 0; /* TODO: BSSID Information */
2161 WPA_PUT_LE32(pos
, info
);
2163 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
2164 phytype
= 8; /* dmg */
2165 else if (other
->iconf
->ieee80211ac
)
2166 phytype
= 9; /* vht */
2167 else if (other
->iconf
->ieee80211n
)
2168 phytype
= 7; /* ht */
2169 else if (other
->iconf
->hw_mode
==
2170 HOSTAPD_MODE_IEEE80211A
)
2171 phytype
= 4; /* ofdm */
2172 else if (other
->iconf
->hw_mode
==
2173 HOSTAPD_MODE_IEEE80211G
)
2174 phytype
= 6; /* erp */
2176 phytype
= 5; /* hrdsss */
2177 if (ieee80211_freq_to_channel_ext(
2178 hostapd_hw_get_freq(other
,
2179 other
->iconf
->channel
),
2180 other
->iconf
->secondary_channel
,
2181 other
->iconf
->ieee80211ac
,
2182 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
2184 channel
= other
->iconf
->channel
;
2189 resp_ies_len
= pos
- &resp_ies
[0];
2194 res
= ieee802_11_allowed_address(
2195 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
2196 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
,
2198 if (res
== HOSTAPD_ACL_REJECT
) {
2199 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
2200 "Ignore Authentication frame from " MACSTR
2201 " due to ACL reject", MAC2STR(mgmt
->sa
));
2202 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2205 if (res
== HOSTAPD_ACL_PENDING
)
2209 if (auth_alg
== WLAN_AUTH_SAE
&& !from_queue
&&
2210 (auth_transaction
== 1 ||
2211 (auth_transaction
== 2 && auth_sae_queued_addr(hapd
, mgmt
->sa
)))) {
2212 /* Handle SAE Authentication commit message through a queue to
2213 * provide more control for postponing the needed heavy
2214 * processing under a possible DoS attack scenario. In addition,
2215 * queue SAE Authentication confirm message if there happens to
2216 * be a queued commit message from the same peer. This is needed
2217 * to avoid reordering Authentication frames within the same
2219 auth_sae_queue(hapd
, mgmt
, len
, rssi
);
2222 #endif /* CONFIG_SAE */
2224 sta
= ap_get_sta(hapd
, mgmt
->sa
);
2226 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2227 sta
->ft_over_ds
= 0;
2228 if ((fc
& WLAN_FC_RETRY
) &&
2229 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
2230 sta
->last_seq_ctrl
== seq_ctrl
&&
2231 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
2232 hostapd_logger(hapd
, sta
->addr
,
2233 HOSTAPD_MODULE_IEEE80211
,
2234 HOSTAPD_LEVEL_DEBUG
,
2235 "Drop repeated authentication frame seq_ctrl=0x%x",
2240 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
2241 sta
->plink_state
== PLINK_BLOCKED
) {
2242 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2243 " is blocked - drop Authentication frame",
2247 #endif /* CONFIG_MESH */
2250 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
2251 /* if the mesh peer is not available, we don't do auth.
2253 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2254 " not yet known - drop Authentication frame",
2257 * Save a copy of the frame so that it can be processed
2258 * if a new peer entry is added shortly after this.
2260 wpabuf_free(hapd
->mesh_pending_auth
);
2261 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
2262 os_get_reltime(&hapd
->mesh_pending_auth_time
);
2265 #endif /* CONFIG_MESH */
2267 sta
= ap_sta_add(hapd
, mgmt
->sa
);
2269 wpa_printf(MSG_DEBUG
, "ap_sta_add() failed");
2270 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2274 sta
->last_seq_ctrl
= seq_ctrl
;
2275 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
2277 sta
->auth_rssi
= rssi
;
2278 #endif /* CONFIG_MBO */
2280 res
= ieee802_11_set_radius_info(
2281 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
2282 &vlan_id
, &psk
, &identity
, &radius_cui
);
2284 wpa_printf(MSG_DEBUG
, "ieee802_11_set_radius_info() failed");
2285 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2289 sta
->flags
&= ~WLAN_STA_PREAUTH
;
2290 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
2293 * If the driver supports full AP client state, add a station to the
2294 * driver before sending authentication reply to make sure the driver
2295 * has resources, and not to go through the entire authentication and
2296 * association handshake, and fail it at the end.
2298 * If this is not the first transaction, in a multi-step authentication
2299 * algorithm, the station already exists in the driver
2300 * (sta->added_unassoc = 1) so skip it.
2302 * In mesh mode, the station was already added to the driver when the
2303 * NEW_PEER_CANDIDATE event is received.
2305 * If PMF was negotiated for the existing association, skip this to
2306 * avoid dropping the STA entry and the associated keys. This is needed
2307 * to allow the original connection work until the attempt can complete
2308 * (re)association, so that unprotected Authentication frame cannot be
2309 * used to bypass PMF protection.
2311 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
2312 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
2313 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
2314 !(sta
->added_unassoc
)) {
2316 * If a station that is already associated to the AP, is trying
2317 * to authenticate again, remove the STA entry, in order to make
2318 * sure the STA PS state gets cleared and configuration gets
2319 * updated. To handle this, station's added_unassoc flag is
2320 * cleared once the station has completed association.
2322 ap_sta_set_authorized(hapd
, sta
, 0);
2323 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2324 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
2325 WLAN_STA_AUTHORIZED
);
2327 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0, NULL
, 0, 0,
2328 NULL
, NULL
, sta
->flags
, 0, 0, 0, 0)) {
2329 hostapd_logger(hapd
, sta
->addr
,
2330 HOSTAPD_MODULE_IEEE80211
,
2331 HOSTAPD_LEVEL_NOTICE
,
2332 "Could not add STA to kernel driver");
2333 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2337 sta
->added_unassoc
= 1;
2341 case WLAN_AUTH_OPEN
:
2342 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2343 HOSTAPD_LEVEL_DEBUG
,
2344 "authentication OK (open system)");
2345 sta
->flags
|= WLAN_STA_AUTH
;
2346 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2347 sta
->auth_alg
= WLAN_AUTH_OPEN
;
2348 mlme_authenticate_indication(hapd
, sta
);
2350 #ifndef CONFIG_NO_RC4
2351 case WLAN_AUTH_SHARED_KEY
:
2352 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
2353 fc
& WLAN_FC_ISWEP
);
2355 wpa_printf(MSG_DEBUG
,
2356 "auth_shared_key() failed: status=%d", resp
);
2357 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2358 mlme_authenticate_indication(hapd
, sta
);
2359 if (sta
->challenge
&& auth_transaction
== 1) {
2360 resp_ies
[0] = WLAN_EID_CHALLENGE
;
2361 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
2362 os_memcpy(resp_ies
+ 2, sta
->challenge
,
2363 WLAN_AUTH_CHALLENGE_LEN
);
2364 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
2367 #endif /* CONFIG_NO_RC4 */
2368 #ifdef CONFIG_IEEE80211R_AP
2370 sta
->auth_alg
= WLAN_AUTH_FT
;
2371 if (sta
->wpa_sm
== NULL
)
2372 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2374 if (sta
->wpa_sm
== NULL
) {
2375 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
2377 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2380 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
2381 auth_transaction
, mgmt
->u
.auth
.variable
,
2382 len
- IEEE80211_HDRLEN
-
2383 sizeof(mgmt
->u
.auth
),
2384 handle_auth_ft_finish
, hapd
);
2385 /* handle_auth_ft_finish() callback will complete auth. */
2387 #endif /* CONFIG_IEEE80211R_AP */
2391 if (status_code
== WLAN_STATUS_SUCCESS
&&
2392 hapd
->conf
->mesh
& MESH_ENABLED
) {
2393 if (sta
->wpa_sm
== NULL
)
2395 wpa_auth_sta_init(hapd
->wpa_auth
,
2397 if (sta
->wpa_sm
== NULL
) {
2398 wpa_printf(MSG_DEBUG
,
2399 "SAE: Failed to initialize WPA state machine");
2400 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2404 #endif /* CONFIG_MESH */
2405 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2408 #endif /* CONFIG_SAE */
2410 case WLAN_AUTH_FILS_SK
:
2411 case WLAN_AUTH_FILS_SK_PFS
:
2412 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2413 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2414 auth_alg
, auth_transaction
, status_code
,
2415 handle_auth_fils_finish
);
2417 #endif /* CONFIG_FILS */
2422 os_free(radius_cui
);
2423 hostapd_free_psk_list(psk
);
2425 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2426 auth_transaction
+ 1, resp
, resp_ies
,
2427 resp_ies_len
, "handle-auth");
2429 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2430 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2431 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2432 sta
->added_unassoc
= 0;
2437 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2441 /* get a unique AID */
2443 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2450 for (i
= 0; i
< AID_WORDS
; i
++) {
2451 if (hapd
->sta_aid
[i
] == (u32
) -1)
2453 for (j
= 0; j
< 32; j
++) {
2454 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2462 aid
= i
* 32 + j
+ 1;
2467 hapd
->sta_aid
[i
] |= BIT(j
);
2468 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2473 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2474 const u8
*ssid_ie
, size_t ssid_ie_len
)
2476 if (ssid_ie
== NULL
)
2477 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2479 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2480 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2481 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2483 "Station tried to associate with unknown SSID "
2484 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2485 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2488 return WLAN_STATUS_SUCCESS
;
2492 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2493 const u8
*wmm_ie
, size_t wmm_ie_len
)
2495 sta
->flags
&= ~WLAN_STA_WMM
;
2497 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2498 struct wmm_information_element
*wmm
;
2500 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2501 hostapd_logger(hapd
, sta
->addr
,
2503 HOSTAPD_LEVEL_DEBUG
,
2504 "invalid WMM element in association "
2506 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2509 sta
->flags
|= WLAN_STA_WMM
;
2510 wmm
= (struct wmm_information_element
*) wmm_ie
;
2511 sta
->qosinfo
= wmm
->qos_info
;
2513 return WLAN_STATUS_SUCCESS
;
2516 static u16
check_multi_ap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2517 const u8
*multi_ap_ie
, size_t multi_ap_len
)
2519 u8 multi_ap_value
= 0;
2521 sta
->flags
&= ~WLAN_STA_MULTI_AP
;
2523 if (!hapd
->conf
->multi_ap
)
2524 return WLAN_STATUS_SUCCESS
;
2527 const u8
*multi_ap_subelem
;
2529 multi_ap_subelem
= get_ie(multi_ap_ie
+ 4,
2531 MULTI_AP_SUB_ELEM_TYPE
);
2532 if (multi_ap_subelem
&& multi_ap_subelem
[1] == 1) {
2533 multi_ap_value
= multi_ap_subelem
[2];
2535 hostapd_logger(hapd
, sta
->addr
,
2536 HOSTAPD_MODULE_IEEE80211
,
2538 "Multi-AP IE has missing or invalid Multi-AP subelement");
2539 return WLAN_STATUS_INVALID_IE
;
2543 if (multi_ap_value
&& multi_ap_value
!= MULTI_AP_BACKHAUL_STA
)
2544 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2546 "Multi-AP IE with unexpected value 0x%02x",
2549 if (!(multi_ap_value
& MULTI_AP_BACKHAUL_STA
)) {
2550 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
2551 return WLAN_STATUS_SUCCESS
;
2553 hostapd_logger(hapd
, sta
->addr
,
2554 HOSTAPD_MODULE_IEEE80211
,
2556 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2557 return WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
2560 if (!(hapd
->conf
->multi_ap
& BACKHAUL_BSS
))
2561 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2562 HOSTAPD_LEVEL_DEBUG
,
2563 "Backhaul STA tries to associate with fronthaul-only BSS");
2565 sta
->flags
|= WLAN_STA_MULTI_AP
;
2566 return WLAN_STATUS_SUCCESS
;
2570 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2571 struct ieee802_11_elems
*elems
)
2573 /* Supported rates not used in IEEE 802.11ad/DMG */
2574 if (hapd
->iface
->current_mode
&&
2575 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2576 return WLAN_STATUS_SUCCESS
;
2578 if (!elems
->supp_rates
) {
2579 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2580 HOSTAPD_LEVEL_DEBUG
,
2581 "No supported rates element in AssocReq");
2582 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2585 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2586 sizeof(sta
->supported_rates
)) {
2587 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2588 HOSTAPD_LEVEL_DEBUG
,
2589 "Invalid supported rates element length %d+%d",
2590 elems
->supp_rates_len
,
2591 elems
->ext_supp_rates_len
);
2592 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2595 sta
->supported_rates_len
= merge_byte_arrays(
2596 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2597 elems
->supp_rates
, elems
->supp_rates_len
,
2598 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2600 return WLAN_STATUS_SUCCESS
;
2604 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2605 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2607 #ifdef CONFIG_INTERWORKING
2608 /* check for QoS Map support */
2609 if (ext_capab_ie_len
>= 5) {
2610 if (ext_capab_ie
[4] & 0x01)
2611 sta
->qos_map_enabled
= 1;
2613 #endif /* CONFIG_INTERWORKING */
2615 if (ext_capab_ie_len
> 0) {
2616 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2617 os_free(sta
->ext_capability
);
2618 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2619 if (sta
->ext_capability
) {
2620 sta
->ext_capability
[0] = ext_capab_ie_len
;
2621 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2626 return WLAN_STATUS_SUCCESS
;
2632 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2635 int *groups
= hapd
->conf
->owe_groups
;
2637 if (group
!= 19 && group
!= 20 && group
!= 21)
2643 for (i
= 0; groups
[i
] > 0; i
++) {
2644 if (groups
[i
] == group
)
2652 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2653 struct sta_info
*sta
, const u8
*owe_dh
,
2656 struct wpabuf
*secret
, *pub
, *hkey
;
2658 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2659 const char *info
= "OWE Key Generation";
2663 size_t hash_len
, prime_len
;
2665 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2666 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2667 return WLAN_STATUS_SUCCESS
;
2670 group
= WPA_GET_LE16(owe_dh
);
2671 if (!owe_group_supported(hapd
, group
)) {
2672 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2673 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2677 else if (group
== 20)
2679 else if (group
== 21)
2682 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2684 crypto_ecdh_deinit(sta
->owe_ecdh
);
2685 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2687 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2688 sta
->owe_group
= group
;
2690 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2692 secret
= wpabuf_zeropad(secret
, prime_len
);
2694 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2695 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2697 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2699 /* prk = HKDF-extract(C | A | group, z) */
2701 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2703 wpabuf_clear_free(secret
);
2704 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2707 /* PMKID = Truncate-128(Hash(C | A)) */
2708 addr
[0] = owe_dh
+ 2;
2709 len
[0] = owe_dh_len
- 2;
2710 addr
[1] = wpabuf_head(pub
);
2711 len
[1] = wpabuf_len(pub
);
2713 res
= sha256_vector(2, addr
, len
, pmkid
);
2714 hash_len
= SHA256_MAC_LEN
;
2715 } else if (group
== 20) {
2716 res
= sha384_vector(2, addr
, len
, pmkid
);
2717 hash_len
= SHA384_MAC_LEN
;
2718 } else if (group
== 21) {
2719 res
= sha512_vector(2, addr
, len
, pmkid
);
2720 hash_len
= SHA512_MAC_LEN
;
2723 wpabuf_clear_free(secret
);
2724 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2726 pub
= wpabuf_zeropad(pub
, prime_len
);
2727 if (res
< 0 || !pub
) {
2729 wpabuf_clear_free(secret
);
2730 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2733 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2736 wpabuf_clear_free(secret
);
2737 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2740 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2741 wpabuf_put_buf(hkey
, pub
); /* A */
2743 wpabuf_put_le16(hkey
, group
); /* group */
2745 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2746 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2747 else if (group
== 20)
2748 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2749 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2750 else if (group
== 21)
2751 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2752 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2753 wpabuf_clear_free(hkey
);
2754 wpabuf_clear_free(secret
);
2756 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2758 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2760 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2762 os_free(sta
->owe_pmk
);
2763 sta
->owe_pmk
= os_malloc(hash_len
);
2764 if (!sta
->owe_pmk
) {
2765 os_memset(prk
, 0, SHA512_MAC_LEN
);
2766 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2770 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2771 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2772 else if (group
== 20)
2773 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2774 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2775 else if (group
== 21)
2776 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2777 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2778 os_memset(prk
, 0, SHA512_MAC_LEN
);
2780 os_free(sta
->owe_pmk
);
2781 sta
->owe_pmk
= NULL
;
2782 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2784 sta
->owe_pmk_len
= hash_len
;
2786 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2787 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2788 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2789 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2791 return WLAN_STATUS_SUCCESS
;
2794 #endif /* CONFIG_OWE */
2797 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2798 const u8
*ies
, size_t ies_len
, int reassoc
)
2800 struct ieee802_11_elems elems
;
2804 const u8
*p2p_dev_addr
= NULL
;
2806 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2807 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2808 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
2809 "association request");
2810 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2813 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
2814 if (resp
!= WLAN_STATUS_SUCCESS
)
2816 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
2817 if (resp
!= WLAN_STATUS_SUCCESS
)
2819 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
2820 if (resp
!= WLAN_STATUS_SUCCESS
)
2822 resp
= copy_supp_rates(hapd
, sta
, &elems
);
2823 if (resp
!= WLAN_STATUS_SUCCESS
)
2826 resp
= check_multi_ap(hapd
, sta
, elems
.multi_ap
, elems
.multi_ap_len
);
2827 if (resp
!= WLAN_STATUS_SUCCESS
)
2830 #ifdef CONFIG_IEEE80211N
2831 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
2832 if (resp
!= WLAN_STATUS_SUCCESS
)
2834 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
2835 !(sta
->flags
& WLAN_STA_HT
)) {
2836 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2837 HOSTAPD_LEVEL_INFO
, "Station does not support "
2838 "mandatory HT PHY - reject association");
2839 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
2841 #endif /* CONFIG_IEEE80211N */
2843 #ifdef CONFIG_IEEE80211AC
2844 if (hapd
->iconf
->ieee80211ac
) {
2845 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
2846 if (resp
!= WLAN_STATUS_SUCCESS
)
2849 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
2850 if (resp
!= WLAN_STATUS_SUCCESS
)
2854 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
2855 !(sta
->flags
& WLAN_STA_VHT
)) {
2856 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2857 HOSTAPD_LEVEL_INFO
, "Station does not support "
2858 "mandatory VHT PHY - reject association");
2859 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
2862 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
2863 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
2864 elems
.vendor_vht_len
);
2865 if (resp
!= WLAN_STATUS_SUCCESS
)
2868 #endif /* CONFIG_IEEE80211AC */
2872 wpabuf_free(sta
->p2p_ie
);
2873 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2874 P2P_IE_VENDOR_TYPE
);
2876 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
2878 wpabuf_free(sta
->p2p_ie
);
2881 #endif /* CONFIG_P2P */
2883 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
2884 wpa_ie
= elems
.rsn_ie
;
2885 wpa_ie_len
= elems
.rsn_ie_len
;
2886 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
2888 wpa_ie
= elems
.wpa_ie
;
2889 wpa_ie_len
= elems
.wpa_ie_len
;
2896 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
2897 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
2898 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
2899 "Request - assume WPS is used");
2900 sta
->flags
|= WLAN_STA_WPS
;
2901 wpabuf_free(sta
->wps_ie
);
2902 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2903 WPS_IE_VENDOR_TYPE
);
2904 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
2905 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
2906 sta
->flags
|= WLAN_STA_WPS2
;
2910 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
2911 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
2912 "(Re)Association Request - reject");
2913 return WLAN_STATUS_INVALID_IE
;
2915 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
2916 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
2917 "(Re)Association Request - possible WPS use");
2918 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
2920 #endif /* CONFIG_WPS */
2921 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
2922 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2924 "No WPA/RSN IE in association request");
2925 return WLAN_STATUS_INVALID_IE
;
2928 if (hapd
->conf
->wpa
&& wpa_ie
) {
2932 if (sta
->wpa_sm
== NULL
)
2933 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2936 if (sta
->wpa_sm
== NULL
) {
2937 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2939 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2941 wpa_auth_set_auth_alg(sta
->wpa_sm
, sta
->auth_alg
);
2942 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2945 elems
.mdie
, elems
.mdie_len
,
2946 elems
.owe_dh
, elems
.owe_dh_len
);
2947 resp
= wpa_res_to_status_code(res
);
2948 if (resp
!= WLAN_STATUS_SUCCESS
)
2950 #ifdef CONFIG_IEEE80211W
2951 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
2952 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
2953 !sta
->sa_query_timed_out
&&
2954 sta
->sa_query_count
> 0)
2955 ap_check_sa_query_timeout(hapd
, sta
);
2956 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
2957 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
2958 !sta
->sa_query_timed_out
&&
2959 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
2961 * STA has already been associated with MFP and SA
2962 * Query timeout has not been reached. Reject the
2963 * association attempt temporarily and start SA Query,
2964 * if one is not pending.
2967 if (sta
->sa_query_count
== 0)
2968 ap_sta_start_sa_query(hapd
, sta
);
2970 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
2973 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
2974 sta
->flags
|= WLAN_STA_MFP
;
2976 sta
->flags
&= ~WLAN_STA_MFP
;
2977 #endif /* CONFIG_IEEE80211W */
2979 #ifdef CONFIG_IEEE80211R_AP
2980 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
2982 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
2983 "to use association (not "
2984 "re-association) with FT auth_alg",
2985 MAC2STR(sta
->addr
));
2986 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2989 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
2991 if (resp
!= WLAN_STATUS_SUCCESS
)
2994 #endif /* CONFIG_IEEE80211R_AP */
2997 if (wpa_auth_uses_sae(sta
->wpa_sm
) && sta
->sae
&&
2998 sta
->sae
->state
== SAE_ACCEPTED
)
2999 wpa_auth_add_sae_pmkid(sta
->wpa_sm
, sta
->sae
->pmkid
);
3001 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3002 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
3003 struct rsn_pmksa_cache_entry
*sa
;
3004 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
3005 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
3006 wpa_printf(MSG_DEBUG
,
3007 "SAE: No PMKSA cache entry found for "
3008 MACSTR
, MAC2STR(sta
->addr
));
3009 return WLAN_STATUS_INVALID_PMKID
;
3011 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
3012 " using PMKSA caching", MAC2STR(sta
->addr
));
3013 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3014 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
3015 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
3016 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
3017 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
3018 "SAE AKM after non-SAE auth_alg %u",
3019 MAC2STR(sta
->addr
), sta
->auth_alg
);
3020 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
3022 #endif /* CONFIG_SAE */
3025 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3026 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
3028 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
3030 if (resp
!= WLAN_STATUS_SUCCESS
)
3033 #endif /* CONFIG_OWE */
3036 dpp_pfs_free(sta
->dpp_pfs
);
3037 sta
->dpp_pfs
= NULL
;
3039 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3040 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
3041 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
3043 sta
->dpp_pfs
= dpp_pfs_init(
3044 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
3045 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
3046 if (!sta
->dpp_pfs
) {
3047 wpa_printf(MSG_DEBUG
,
3048 "DPP: Could not initialize PFS");
3049 /* Try to continue without PFS */
3053 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
3054 elems
.owe_dh_len
) < 0) {
3055 dpp_pfs_free(sta
->dpp_pfs
);
3056 sta
->dpp_pfs
= NULL
;
3057 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3061 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
3062 sta
->dpp_pfs
->secret
: NULL
);
3064 #endif /* CONFIG_DPP2 */
3066 #ifdef CONFIG_IEEE80211N
3067 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
3068 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
3069 hostapd_logger(hapd
, sta
->addr
,
3070 HOSTAPD_MODULE_IEEE80211
,
3072 "Station tried to use TKIP with HT "
3074 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
3076 #endif /* CONFIG_IEEE80211N */
3078 } else if (hapd
->conf
->osen
) {
3079 if (elems
.osen
== NULL
) {
3081 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3083 "No HS 2.0 OSEN element in association request");
3084 return WLAN_STATUS_INVALID_IE
;
3087 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
3088 if (sta
->wpa_sm
== NULL
)
3089 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3091 if (sta
->wpa_sm
== NULL
) {
3092 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3094 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3096 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
3097 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
3098 return WLAN_STATUS_INVALID_IE
;
3099 #endif /* CONFIG_HS20 */
3101 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
3104 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
3105 #endif /* CONFIG_P2P */
3108 wpabuf_free(sta
->hs20_ie
);
3109 if (elems
.hs20
&& elems
.hs20_len
> 4) {
3112 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
3113 elems
.hs20_len
- 4);
3114 release
= ((elems
.hs20
[4] >> 4) & 0x0f) + 1;
3115 if (release
>= 2 && !wpa_auth_uses_mfp(sta
->wpa_sm
)) {
3116 wpa_printf(MSG_DEBUG
,
3117 "HS 2.0: PMF not negotiated by release %d station "
3118 MACSTR
, release
, MAC2STR(sta
->addr
));
3119 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
3122 sta
->hs20_ie
= NULL
;
3125 wpabuf_free(sta
->roaming_consortium
);
3126 if (elems
.roaming_cons_sel
)
3127 sta
->roaming_consortium
= wpabuf_alloc_copy(
3128 elems
.roaming_cons_sel
+ 4,
3129 elems
.roaming_cons_sel_len
- 4);
3131 sta
->roaming_consortium
= NULL
;
3132 #endif /* CONFIG_HS20 */
3135 wpabuf_free(sta
->mb_ies
);
3136 if (hapd
->iface
->fst
)
3137 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
3140 #endif /* CONFIG_FST */
3143 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
3145 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
3146 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
3147 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3148 wpa_printf(MSG_INFO
,
3149 "MBO: Reject WPA2 association without PMF");
3150 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3152 #endif /* CONFIG_MBO */
3154 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3155 if (wpa_auth_uses_ocv(sta
->wpa_sm
) &&
3156 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3157 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3158 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)) {
3159 struct wpa_channel_info ci
;
3163 if (hostapd_drv_channel_info(hapd
, &ci
) != 0) {
3164 wpa_printf(MSG_WARNING
,
3165 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3166 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3169 if (get_sta_tx_parameters(sta
->wpa_sm
,
3170 channel_width_to_int(ci
.chanwidth
),
3171 ci
.seg1_idx
, &tx_chanwidth
,
3173 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3175 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
3176 tx_chanwidth
, tx_seg1_idx
) != 0) {
3177 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
3178 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3181 #endif /* CONFIG_FILS && CONFIG_OCV */
3183 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
3184 elems
.supp_op_classes_len
);
3186 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
3187 elems
.rrm_enabled
&&
3188 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
3189 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
3190 sizeof(sta
->rrm_enabled_capa
));
3192 if (elems
.power_capab
) {
3193 sta
->min_tx_power
= elems
.power_capab
[0];
3194 sta
->max_tx_power
= elems
.power_capab
[1];
3195 sta
->power_capab
= 1;
3197 sta
->power_capab
= 0;
3200 return WLAN_STATUS_SUCCESS
;
3204 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
3208 struct ieee80211_mgmt reply
;
3210 os_memset(&reply
, 0, sizeof(reply
));
3211 reply
.frame_control
=
3212 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
3213 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
3214 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
3215 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
3217 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
3218 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
3220 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
3221 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
3226 static int add_associated_sta(struct hostapd_data
*hapd
,
3227 struct sta_info
*sta
, int reassoc
)
3229 struct ieee80211_ht_capabilities ht_cap
;
3230 struct ieee80211_vht_capabilities vht_cap
;
3234 * Remove the STA entry to ensure the STA PS state gets cleared and
3235 * configuration gets updated. This is relevant for cases, such as
3236 * FT-over-the-DS, where a station re-associates back to the same AP but
3237 * skips the authentication flow, or if working with a driver that
3238 * does not support full AP client state.
3240 * Skip this if the STA has already completed FT reassociation and the
3241 * TK has been configured since the TX/RX PN must not be reset to 0 for
3244 * FT-over-the-DS has a special case where the STA entry (and as such,
3245 * the TK) has not yet been configured to the driver depending on which
3246 * driver interface is used. For that case, allow add-STA operation to
3247 * be used (instead of set-STA). This is needed to allow mac80211-based
3248 * drivers to accept the STA parameter configuration. Since this is
3249 * after a new FT-over-DS exchange, a new TK has been derived, so key
3250 * reinstallation is not a concern for this case.
3252 wpa_printf(MSG_DEBUG
, "Add associated STA " MACSTR
3253 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3254 MAC2STR(sta
->addr
), sta
->added_unassoc
, sta
->auth_alg
,
3255 sta
->ft_over_ds
, reassoc
,
3256 !!(sta
->flags
& WLAN_STA_AUTHORIZED
),
3257 wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
),
3258 wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
));
3260 if (!sta
->added_unassoc
&&
3261 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3262 (reassoc
&& sta
->ft_over_ds
&& sta
->auth_alg
== WLAN_AUTH_FT
) ||
3263 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
3264 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
3265 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3266 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
3269 /* Do not allow the FT-over-DS exception to be used more than
3270 * once per authentication exchange to guarantee a new TK is
3272 sta
->ft_over_ds
= 0;
3275 #ifdef CONFIG_IEEE80211N
3276 if (sta
->flags
& WLAN_STA_HT
)
3277 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
3278 #endif /* CONFIG_IEEE80211N */
3279 #ifdef CONFIG_IEEE80211AC
3280 if (sta
->flags
& WLAN_STA_VHT
)
3281 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
3282 #endif /* CONFIG_IEEE80211AC */
3285 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3286 * will be set when the ACK frame for the (Re)Association Response frame
3287 * is processed (TX status driver event).
3289 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
3290 sta
->supported_rates
, sta
->supported_rates_len
,
3291 sta
->listen_interval
,
3292 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
3293 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
3294 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
3295 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
3297 hostapd_logger(hapd
, sta
->addr
,
3298 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
3299 "Could not %s STA to kernel driver",
3300 set
? "set" : "add");
3302 if (sta
->added_unassoc
) {
3303 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3304 sta
->added_unassoc
= 0;
3310 sta
->added_unassoc
= 0;
3316 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3317 const u8
*addr
, u16 status_code
, int reassoc
,
3318 const u8
*ies
, size_t ies_len
, int rssi
)
3323 struct ieee80211_mgmt
*reply
;
3325 u16 res
= WLAN_STATUS_SUCCESS
;
3327 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
3329 if (sta
&& sta
->fils_hlp_resp
)
3330 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
3333 #endif /* CONFIG_FILS */
3335 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3337 #endif /* CONFIG_OWE */
3339 if (sta
&& sta
->dpp_pfs
)
3340 buflen
+= 5 + sta
->dpp_pfs
->curve
->prime_len
;
3341 #endif /* CONFIG_DPP2 */
3342 buf
= os_zalloc(buflen
);
3344 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3347 reply
= (struct ieee80211_mgmt
*) buf
;
3348 reply
->frame_control
=
3349 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3350 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
3351 WLAN_FC_STYPE_ASSOC_RESP
));
3352 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
3353 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
3354 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3356 send_len
= IEEE80211_HDRLEN
;
3357 send_len
+= sizeof(reply
->u
.assoc_resp
);
3358 reply
->u
.assoc_resp
.capab_info
=
3359 host_to_le16(hostapd_own_capab_info(hapd
));
3360 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
3362 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
3364 /* Supported rates */
3365 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
3366 /* Extended supported rates */
3367 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
3370 if (status_code
== WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
3372 int delta
= hapd
->iconf
->rssi_reject_assoc_rssi
- rssi
;
3374 p
= hostapd_eid_mbo_rssi_assoc_rej(hapd
, p
, buf
+ buflen
- p
,
3377 #endif /* CONFIG_MBO */
3379 #ifdef CONFIG_IEEE80211R_AP
3380 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
3381 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3382 * Transition Information, RSN, [RIC Response] */
3383 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
3385 sta
->auth_alg
, ies
, ies_len
);
3387 wpa_printf(MSG_DEBUG
,
3388 "FT: Failed to write AssocResp IEs");
3389 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3393 #endif /* CONFIG_IEEE80211R_AP */
3395 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3396 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3397 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3398 sta
->auth_alg
== WLAN_AUTH_FILS_PK
))
3399 p
= wpa_auth_write_assoc_resp_fils(sta
->wpa_sm
, p
,
3402 #endif /* CONFIG_FILS */
3405 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3406 (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3407 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
3410 #endif /* CONFIG_OWE */
3412 #ifdef CONFIG_IEEE80211W
3413 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
3414 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
3415 #endif /* CONFIG_IEEE80211W */
3417 #ifdef CONFIG_IEEE80211N
3418 p
= hostapd_eid_ht_capabilities(hapd
, p
);
3419 p
= hostapd_eid_ht_operation(hapd
, p
);
3420 #endif /* CONFIG_IEEE80211N */
3422 #ifdef CONFIG_IEEE80211AC
3423 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
) {
3424 u32 nsts
= 0, sta_nsts
;
3426 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
3427 struct ieee80211_vht_capabilities
*capa
;
3429 nsts
= (hapd
->iface
->conf
->vht_capab
>>
3430 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3431 capa
= sta
->vht_capabilities
;
3432 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
3433 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3435 if (nsts
< sta_nsts
)
3440 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
3441 p
= hostapd_eid_vht_operation(hapd
, p
);
3443 #endif /* CONFIG_IEEE80211AC */
3445 p
= hostapd_eid_ext_capab(hapd
, p
);
3446 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
3447 if (sta
&& sta
->qos_map_enabled
)
3448 p
= hostapd_eid_qos_map_set(hapd
, p
);
3451 if (hapd
->iface
->fst_ies
) {
3452 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
3453 wpabuf_len(hapd
->iface
->fst_ies
));
3454 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
3456 #endif /* CONFIG_FST */
3459 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3460 sta
&& sta
->owe_ecdh
&& status_code
== WLAN_STATUS_SUCCESS
&&
3461 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
3464 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3466 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3469 /* OWE Diffie-Hellman Parameter element */
3470 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3471 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3472 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3473 WPA_PUT_LE16(p
, sta
->owe_group
);
3475 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
3476 p
+= wpabuf_len(pub
);
3479 #endif /* CONFIG_OWE */
3482 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3483 sta
&& sta
->dpp_pfs
&& status_code
== WLAN_STATUS_SUCCESS
&&
3484 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
) {
3485 os_memcpy(p
, wpabuf_head(sta
->dpp_pfs
->ie
),
3486 wpabuf_len(sta
->dpp_pfs
->ie
));
3487 p
+= wpabuf_len(sta
->dpp_pfs
->ie
);
3489 #endif /* CONFIG_DPP2 */
3491 #ifdef CONFIG_IEEE80211AC
3492 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
3493 p
= hostapd_eid_vendor_vht(hapd
, p
);
3494 #endif /* CONFIG_IEEE80211AC */
3496 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
3497 p
= hostapd_eid_wmm(hapd
, p
);
3501 ((sta
->flags
& WLAN_STA_WPS
) ||
3502 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
3503 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
3505 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
3506 p
+= wpabuf_len(wps
);
3510 #endif /* CONFIG_WPS */
3512 if (sta
&& (sta
->flags
& WLAN_STA_MULTI_AP
))
3513 p
= hostapd_eid_multi_ap(hapd
, p
);
3516 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
3517 struct wpabuf
*p2p_resp_ie
;
3518 enum p2p_status_code status
;
3519 switch (status_code
) {
3520 case WLAN_STATUS_SUCCESS
:
3521 status
= P2P_SC_SUCCESS
;
3523 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
3524 status
= P2P_SC_FAIL_LIMIT_REACHED
;
3527 status
= P2P_SC_FAIL_INVALID_PARAMS
;
3530 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
3532 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
3533 wpabuf_len(p2p_resp_ie
));
3534 p
+= wpabuf_len(p2p_resp_ie
);
3535 wpabuf_free(p2p_resp_ie
);
3538 #endif /* CONFIG_P2P */
3540 #ifdef CONFIG_P2P_MANAGER
3541 if (hapd
->conf
->p2p
& P2P_MANAGE
)
3542 p
= hostapd_eid_p2p_manage(hapd
, p
);
3543 #endif /* CONFIG_P2P_MANAGER */
3545 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
3547 if (hapd
->conf
->assocresp_elements
&&
3548 (size_t) (buf
+ buflen
- p
) >=
3549 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
3550 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
3551 wpabuf_len(hapd
->conf
->assocresp_elements
));
3552 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
3555 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
3559 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3560 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3561 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
3562 status_code
== WLAN_STATUS_SUCCESS
) {
3563 struct ieee802_11_elems elems
;
3565 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
3566 ParseFailed
|| !elems
.fils_session
) {
3567 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3572 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3573 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
3574 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
3575 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
3576 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
3578 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
3579 buflen
, sta
->fils_hlp_resp
);
3581 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3585 #endif /* CONFIG_FILS */
3587 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
3588 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
3590 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3600 u8
* owe_assoc_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3601 const u8
*owe_dh
, u8 owe_dh_len
,
3602 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
3604 #ifdef CONFIG_TESTING_OPTIONS
3605 if (hapd
->conf
->own_ie_override
) {
3606 wpa_printf(MSG_DEBUG
, "OWE: Using IE override");
3607 *reason
= WLAN_STATUS_SUCCESS
;
3608 return wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3609 owe_buf_len
, NULL
, 0);
3611 #endif /* CONFIG_TESTING_OPTIONS */
3613 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
3614 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
3615 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3616 owe_buf_len
, NULL
, 0);
3617 *reason
= WLAN_STATUS_SUCCESS
;
3621 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3622 if (*reason
!= WLAN_STATUS_SUCCESS
)
3625 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3626 owe_buf_len
, NULL
, 0);
3628 if (sta
->owe_ecdh
&& owe_buf
) {
3631 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3633 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3637 /* OWE Diffie-Hellman Parameter element */
3638 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3639 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3640 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3642 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3644 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3645 owe_buf
+= wpabuf_len(pub
);
3651 #endif /* CONFIG_OWE */
3656 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3660 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3661 MAC2STR(sta
->addr
));
3662 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3663 if (!sta
->fils_pending_assoc_req
)
3665 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3666 sta
->fils_pending_assoc_is_reassoc
,
3667 sta
->fils_pending_assoc_req
,
3668 sta
->fils_pending_assoc_req_len
, 0);
3669 os_free(sta
->fils_pending_assoc_req
);
3670 sta
->fils_pending_assoc_req
= NULL
;
3671 sta
->fils_pending_assoc_req_len
= 0;
3672 wpabuf_free(sta
->fils_hlp_resp
);
3673 sta
->fils_hlp_resp
= NULL
;
3674 wpabuf_free(sta
->hlp_dhcp_discover
);
3675 sta
->hlp_dhcp_discover
= NULL
;
3678 * Remove the station in case transmission of a success response fails.
3679 * At this point the station was already added associated to the driver.
3681 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3682 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3686 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3688 struct hostapd_data
*hapd
= eloop_ctx
;
3689 struct sta_info
*sta
= eloop_data
;
3691 wpa_printf(MSG_DEBUG
,
3692 "FILS: HLP response timeout - continue with association response for "
3693 MACSTR
, MAC2STR(sta
->addr
));
3694 if (sta
->fils_drv_assoc_finish
)
3695 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3697 fils_hlp_finish_assoc(hapd
, sta
);
3700 #endif /* CONFIG_FILS */
3703 static void handle_assoc(struct hostapd_data
*hapd
,
3704 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3705 int reassoc
, int rssi
)
3707 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3708 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3711 struct sta_info
*sta
;
3713 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3714 char *identity
= NULL
;
3715 char *radius_cui
= NULL
;
3717 int delay_assoc
= 0;
3718 #endif /* CONFIG_FILS */
3720 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3721 sizeof(mgmt
->u
.assoc_req
))) {
3722 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3723 reassoc
, (unsigned long) len
);
3727 #ifdef CONFIG_TESTING_OPTIONS
3729 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3730 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3731 wpa_printf(MSG_INFO
,
3732 "TESTING: ignoring reassoc request from "
3733 MACSTR
, MAC2STR(mgmt
->sa
));
3737 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3738 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3739 wpa_printf(MSG_INFO
,
3740 "TESTING: ignoring assoc request from "
3741 MACSTR
, MAC2STR(mgmt
->sa
));
3745 #endif /* CONFIG_TESTING_OPTIONS */
3747 fc
= le_to_host16(mgmt
->frame_control
);
3748 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3751 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
3752 listen_interval
= le_to_host16(
3753 mgmt
->u
.reassoc_req
.listen_interval
);
3754 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
3755 " capab_info=0x%02x listen_interval=%d current_ap="
3756 MACSTR
" seq_ctrl=0x%x%s",
3757 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3758 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
3759 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3760 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
3761 pos
= mgmt
->u
.reassoc_req
.variable
;
3763 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
3764 listen_interval
= le_to_host16(
3765 mgmt
->u
.assoc_req
.listen_interval
);
3766 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
3767 " capab_info=0x%02x listen_interval=%d "
3769 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3770 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3771 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
3772 pos
= mgmt
->u
.assoc_req
.variable
;
3775 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3776 #ifdef CONFIG_IEEE80211R_AP
3777 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
3778 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3779 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
3780 "prior to authentication since it is using "
3781 "over-the-DS FT", MAC2STR(mgmt
->sa
));
3784 * Mark station as authenticated, to avoid adding station
3785 * entry in the driver as associated and not authenticated
3787 sta
->flags
|= WLAN_STA_AUTH
;
3789 #endif /* CONFIG_IEEE80211R_AP */
3790 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3791 if (hapd
->iface
->current_mode
&&
3792 hapd
->iface
->current_mode
->mode
==
3793 HOSTAPD_MODE_IEEE80211AD
) {
3795 u32 session_timeout
, acct_interim_interval
;
3796 struct vlan_description vlan_id
;
3798 acl_res
= ieee802_11_allowed_address(
3799 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
3800 &session_timeout
, &acct_interim_interval
,
3801 &vlan_id
, &psk
, &identity
, &radius_cui
, 0);
3802 if (acl_res
== HOSTAPD_ACL_REJECT
) {
3803 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
3804 "Ignore Association Request frame from "
3805 MACSTR
" due to ACL reject",
3807 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3810 if (acl_res
== HOSTAPD_ACL_PENDING
)
3813 /* DMG/IEEE 802.11ad does not use authentication.
3814 * Allocate sta entry upon association. */
3815 sta
= ap_sta_add(hapd
, mgmt
->sa
);
3817 hostapd_logger(hapd
, mgmt
->sa
,
3818 HOSTAPD_MODULE_IEEE80211
,
3820 "Failed to add STA");
3821 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3825 acl_res
= ieee802_11_set_radius_info(
3826 hapd
, sta
, acl_res
, session_timeout
,
3827 acct_interim_interval
, &vlan_id
, &psk
,
3828 &identity
, &radius_cui
);
3830 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3834 hostapd_logger(hapd
, sta
->addr
,
3835 HOSTAPD_MODULE_IEEE80211
,
3836 HOSTAPD_LEVEL_DEBUG
,
3837 "Skip authentication for DMG/IEEE 802.11ad");
3838 sta
->flags
|= WLAN_STA_AUTH
;
3839 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
3840 sta
->auth_alg
= WLAN_AUTH_OPEN
;
3842 hostapd_logger(hapd
, mgmt
->sa
,
3843 HOSTAPD_MODULE_IEEE80211
,
3845 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3846 sta
? sta
->aid
: -1,
3847 sta
? sta
->flags
: 0);
3848 send_deauth(hapd
, mgmt
->sa
,
3849 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
3854 if ((fc
& WLAN_FC_RETRY
) &&
3855 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3856 sta
->last_seq_ctrl
== seq_ctrl
&&
3857 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3858 WLAN_FC_STYPE_ASSOC_REQ
)) {
3859 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3860 HOSTAPD_LEVEL_DEBUG
,
3861 "Drop repeated association frame seq_ctrl=0x%x",
3865 sta
->last_seq_ctrl
= seq_ctrl
;
3866 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3867 WLAN_FC_STYPE_ASSOC_REQ
;
3869 if (hapd
->tkip_countermeasures
) {
3870 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3874 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
3875 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3876 HOSTAPD_LEVEL_DEBUG
,
3877 "Too large Listen Interval (%d)",
3879 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
3884 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
3885 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3889 if (hapd
->iconf
->rssi_reject_assoc_rssi
&& rssi
&&
3890 rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
&&
3891 (sta
->auth_rssi
== 0 ||
3892 sta
->auth_rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
)) {
3893 resp
= WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
;
3896 #endif /* CONFIG_MBO */
3899 * sta->capability is used in check_assoc_ies() for RRM enabled
3900 * capability element.
3902 sta
->capability
= capab_info
;
3905 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3906 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3907 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3910 /* The end of the payload is encrypted. Need to decrypt it
3911 * before parsing. */
3913 tmp
= os_memdup(pos
, left
);
3915 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3919 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
3922 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3928 #endif /* CONFIG_FILS */
3930 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3932 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
3933 if (resp
!= WLAN_STATUS_SUCCESS
)
3936 if (hostapd_get_aid(hapd
, sta
) < 0) {
3937 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3938 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
3939 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3943 sta
->listen_interval
= listen_interval
;
3945 if (hapd
->iface
->current_mode
&&
3946 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
3947 sta
->flags
|= WLAN_STA_NONERP
;
3948 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
3949 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
3950 sta
->flags
&= ~WLAN_STA_NONERP
;
3954 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
3955 sta
->nonerp_set
= 1;
3956 hapd
->iface
->num_sta_non_erp
++;
3957 if (hapd
->iface
->num_sta_non_erp
== 1)
3958 ieee802_11_set_beacons(hapd
->iface
);
3961 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
3962 !sta
->no_short_slot_time_set
) {
3963 sta
->no_short_slot_time_set
= 1;
3964 hapd
->iface
->num_sta_no_short_slot_time
++;
3965 if (hapd
->iface
->current_mode
&&
3966 hapd
->iface
->current_mode
->mode
==
3967 HOSTAPD_MODE_IEEE80211G
&&
3968 hapd
->iface
->num_sta_no_short_slot_time
== 1)
3969 ieee802_11_set_beacons(hapd
->iface
);
3972 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3973 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
3975 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
3977 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
3978 !sta
->no_short_preamble_set
) {
3979 sta
->no_short_preamble_set
= 1;
3980 hapd
->iface
->num_sta_no_short_preamble
++;
3981 if (hapd
->iface
->current_mode
&&
3982 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
3983 && hapd
->iface
->num_sta_no_short_preamble
== 1)
3984 ieee802_11_set_beacons(hapd
->iface
);
3987 #ifdef CONFIG_IEEE80211N
3988 update_ht_state(hapd
, sta
);
3989 #endif /* CONFIG_IEEE80211N */
3991 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3992 HOSTAPD_LEVEL_DEBUG
,
3993 "association OK (aid %d)", sta
->aid
);
3994 /* Station will be marked associated, after it acknowledges AssocResp
3996 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
3998 #ifdef CONFIG_IEEE80211W
3999 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
4000 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
4001 "SA Query procedure", reassoc
? "re" : "");
4002 /* TODO: Send a protected Disassociate frame to the STA using
4003 * the old key and Reason Code "Previous Authentication no
4004 * longer valid". Make sure this is only sent protected since
4005 * unprotected frame would be received by the STA that is now
4006 * trying to associate.
4009 #endif /* CONFIG_IEEE80211W */
4011 /* Make sure that the previously registered inactivity timer will not
4012 * remove the STA immediately. */
4013 sta
->timeout_next
= STA_NULLFUNC
;
4015 #ifdef CONFIG_TAXONOMY
4016 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
4017 #endif /* CONFIG_TAXONOMY */
4019 sta
->pending_wds_enable
= 0;
4022 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4023 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4024 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4025 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
4028 #endif /* CONFIG_FILS */
4032 os_free(radius_cui
);
4033 hostapd_free_psk_list(psk
);
4036 * In case of a successful response, add the station to the driver.
4037 * Otherwise, the kernel may ignore Data frames before we process the
4038 * ACK frame (TX status). In case of a failure, this station will be
4041 * Note that this is not compliant with the IEEE 802.11 standard that
4042 * states that a non-AP station should transition into the
4043 * authenticated/associated state only after the station acknowledges
4044 * the (Re)Association Response frame. However, still do this as:
4046 * 1. In case the station does not acknowledge the (Re)Association
4047 * Response frame, it will be removed.
4048 * 2. Data frames will be dropped in the kernel until the station is
4049 * set into authorized state, and there are no significant known
4050 * issues with processing other non-Data Class 3 frames during this
4053 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&&
4054 add_associated_sta(hapd
, sta
, reassoc
))
4055 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4058 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
&&
4059 eloop_is_timeout_registered(fils_hlp_timeout
, hapd
, sta
) &&
4060 sta
->fils_pending_assoc_req
) {
4061 /* Do not reschedule fils_hlp_timeout in case the station
4062 * retransmits (Re)Association Request frame while waiting for
4063 * the previously started FILS HLP wait, so that the timeout can
4064 * be determined from the first pending attempt. */
4065 wpa_printf(MSG_DEBUG
,
4066 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4067 MACSTR
, MAC2STR(sta
->addr
));
4072 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4073 os_free(sta
->fils_pending_assoc_req
);
4074 sta
->fils_pending_assoc_req
= NULL
;
4075 sta
->fils_pending_assoc_req_len
= 0;
4076 wpabuf_free(sta
->fils_hlp_resp
);
4077 sta
->fils_hlp_resp
= NULL
;
4079 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
4080 sta
->fils_pending_assoc_req
= tmp
;
4081 sta
->fils_pending_assoc_req_len
= left
;
4082 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
4083 sta
->fils_drv_assoc_finish
= 0;
4084 wpa_printf(MSG_DEBUG
,
4085 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4086 MACSTR
, MAC2STR(sta
->addr
));
4087 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4088 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
4089 fils_hlp_timeout
, hapd
, sta
);
4092 #endif /* CONFIG_FILS */
4094 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
4099 * Remove the station in case tranmission of a success response fails
4100 * (the STA was added associated to the driver) or if the station was
4101 * previously added unassociated.
4103 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
4104 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
4105 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4106 sta
->added_unassoc
= 0;
4111 static void handle_disassoc(struct hostapd_data
*hapd
,
4112 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4114 struct sta_info
*sta
;
4116 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
4117 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
4118 (unsigned long) len
);
4122 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
4124 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4126 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4128 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
4133 ap_sta_set_authorized(hapd
, sta
, 0);
4134 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4135 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
4136 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
4137 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4138 HOSTAPD_LEVEL_INFO
, "disassociated");
4139 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4140 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4141 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4143 accounting_sta_stop(hapd
, sta
);
4144 ieee802_1x_free_station(hapd
, sta
);
4146 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
4147 ap_sta_ip6addr_del(hapd
, sta
);
4148 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4149 sta
->added_unassoc
= 0;
4151 if (sta
->timeout_next
== STA_NULLFUNC
||
4152 sta
->timeout_next
== STA_DISASSOC
) {
4153 sta
->timeout_next
= STA_DEAUTH
;
4154 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
4155 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
4159 mlme_disassociate_indication(
4160 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4162 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4163 * disassociation. */
4164 if (hapd
->iface
->current_mode
&&
4165 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
4166 sta
->flags
&= ~WLAN_STA_AUTH
;
4167 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4168 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4169 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4170 ap_free_sta(hapd
, sta
);
4175 static void handle_deauth(struct hostapd_data
*hapd
,
4176 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4178 struct sta_info
*sta
;
4180 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
4181 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
4182 "payload (len=%lu)", (unsigned long) len
);
4186 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
4188 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
4190 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4192 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
4193 "to deauthenticate, but it is not authenticated",
4198 ap_sta_set_authorized(hapd
, sta
, 0);
4199 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4200 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
4201 WLAN_STA_ASSOC_REQ_OK
);
4202 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4203 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4204 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4205 mlme_deauthenticate_indication(
4206 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
4207 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4208 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4209 ap_free_sta(hapd
, sta
);
4213 static void handle_beacon(struct hostapd_data
*hapd
,
4214 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4215 struct hostapd_frame_info
*fi
)
4217 struct ieee802_11_elems elems
;
4219 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
4220 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
4221 (unsigned long) len
);
4225 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
4226 len
- (IEEE80211_HDRLEN
+
4227 sizeof(mgmt
->u
.beacon
)), &elems
,
4230 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
4234 #ifdef CONFIG_IEEE80211W
4235 static int robust_action_frame(u8 category
)
4237 return category
!= WLAN_ACTION_PUBLIC
&&
4238 category
!= WLAN_ACTION_HT
;
4240 #endif /* CONFIG_IEEE80211W */
4243 static int handle_action(struct hostapd_data
*hapd
,
4244 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4247 struct sta_info
*sta
;
4248 u8
*action __maybe_unused
;
4250 if (len
< IEEE80211_HDRLEN
+ 2 + 1) {
4251 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4252 HOSTAPD_LEVEL_DEBUG
,
4253 "handle_action - too short payload (len=%lu)",
4254 (unsigned long) len
);
4258 action
= (u8
*) &mgmt
->u
.action
.u
;
4259 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
4260 " da " MACSTR
" len %d freq %u",
4261 mgmt
->u
.action
.category
, *action
,
4262 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) len
, freq
);
4264 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4266 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
4267 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
4268 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
4269 "frame (category=%u) from unassociated STA " MACSTR
,
4270 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
4274 #ifdef CONFIG_IEEE80211W
4275 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
4276 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
4277 robust_action_frame(mgmt
->u
.action
.category
)) {
4278 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4279 HOSTAPD_LEVEL_DEBUG
,
4280 "Dropped unprotected Robust Action frame from "
4284 #endif /* CONFIG_IEEE80211W */
4287 u16 fc
= le_to_host16(mgmt
->frame_control
);
4288 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4290 if ((fc
& WLAN_FC_RETRY
) &&
4291 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4292 sta
->last_seq_ctrl
== seq_ctrl
&&
4293 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
4294 hostapd_logger(hapd
, sta
->addr
,
4295 HOSTAPD_MODULE_IEEE80211
,
4296 HOSTAPD_LEVEL_DEBUG
,
4297 "Drop repeated action frame seq_ctrl=0x%x",
4302 sta
->last_seq_ctrl
= seq_ctrl
;
4303 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
4306 switch (mgmt
->u
.action
.category
) {
4307 #ifdef CONFIG_IEEE80211R_AP
4308 case WLAN_ACTION_FT
:
4310 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
4311 len
- IEEE80211_HDRLEN
))
4314 #endif /* CONFIG_IEEE80211R_AP */
4315 case WLAN_ACTION_WMM
:
4316 hostapd_wmm_action(hapd
, mgmt
, len
);
4318 #ifdef CONFIG_IEEE80211W
4319 case WLAN_ACTION_SA_QUERY
:
4320 ieee802_11_sa_query_action(hapd
, mgmt
, len
);
4322 #endif /* CONFIG_IEEE80211W */
4323 #ifdef CONFIG_WNM_AP
4324 case WLAN_ACTION_WNM
:
4325 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
4327 #endif /* CONFIG_WNM_AP */
4329 case WLAN_ACTION_FST
:
4330 if (hapd
->iface
->fst
)
4331 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
4333 wpa_printf(MSG_DEBUG
,
4334 "FST: Ignore FST Action frame - no FST attached");
4336 #endif /* CONFIG_FST */
4337 case WLAN_ACTION_PUBLIC
:
4338 case WLAN_ACTION_PROTECTED_DUAL
:
4339 #ifdef CONFIG_IEEE80211N
4340 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4341 mgmt
->u
.action
.u
.public_action
.action
==
4342 WLAN_PA_20_40_BSS_COEX
) {
4343 hostapd_2040_coex_action(hapd
, mgmt
, len
);
4346 #endif /* CONFIG_IEEE80211N */
4348 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4349 mgmt
->u
.action
.u
.vs_public_action
.action
==
4350 WLAN_PA_VENDOR_SPECIFIC
&&
4351 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4353 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4355 const u8
*pos
, *end
;
4357 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
4358 end
= ((const u8
*) mgmt
) + len
;
4359 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
4363 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4364 (mgmt
->u
.action
.u
.public_action
.action
==
4365 WLAN_PA_GAS_INITIAL_RESP
||
4366 mgmt
->u
.action
.u
.public_action
.action
==
4367 WLAN_PA_GAS_COMEBACK_RESP
)) {
4368 const u8
*pos
, *end
;
4370 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
4371 end
= ((const u8
*) mgmt
) + len
;
4372 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
4373 mgmt
->u
.action
.category
,
4374 pos
, end
- pos
, hapd
->iface
->freq
);
4377 #endif /* CONFIG_DPP */
4378 if (hapd
->public_action_cb
) {
4379 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
4383 if (hapd
->public_action_cb2
) {
4384 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
4388 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
4391 case WLAN_ACTION_VENDOR_SPECIFIC
:
4392 if (hapd
->vendor_action_cb
) {
4393 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
4395 hapd
->iface
->freq
) == 0)
4399 case WLAN_ACTION_RADIO_MEASUREMENT
:
4400 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
4404 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4405 HOSTAPD_LEVEL_DEBUG
,
4406 "handle_action - unknown action category %d or invalid "
4408 mgmt
->u
.action
.category
);
4409 if (!is_multicast_ether_addr(mgmt
->da
) &&
4410 !(mgmt
->u
.action
.category
& 0x80) &&
4411 !is_multicast_ether_addr(mgmt
->sa
)) {
4412 struct ieee80211_mgmt
*resp
;
4415 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4416 * Return the Action frame to the source without change
4417 * except that MSB of the Category set to 1.
4419 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
4420 "frame back to sender");
4421 resp
= os_memdup(mgmt
, len
);
4424 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
4425 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
4426 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
4427 resp
->u
.action
.category
|= 0x80;
4429 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
4430 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
4441 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4442 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4444 * @buf: management frame data (starting from IEEE 802.11 header)
4445 * @len: length of frame data in octets
4446 * @fi: meta data about received frame (signal level, etc.)
4448 * Process all incoming IEEE 802.11 management frames. This will be called for
4449 * each frame received from the kernel driver through wlan#ap interface. In
4450 * addition, it can be called to re-inserted pending frames (e.g., when using
4451 * external RADIUS server as an MAC ACL).
4453 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4454 struct hostapd_frame_info
*fi
)
4456 struct ieee80211_mgmt
*mgmt
;
4460 int ssi_signal
= fi
? fi
->ssi_signal
: 0;
4468 freq
= hapd
->iface
->freq
;
4470 mgmt
= (struct ieee80211_mgmt
*) buf
;
4471 fc
= le_to_host16(mgmt
->frame_control
);
4472 stype
= WLAN_FC_GET_STYPE(fc
);
4474 if (stype
== WLAN_FC_STYPE_BEACON
) {
4475 handle_beacon(hapd
, mgmt
, len
, fi
);
4479 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
4481 /* Invitation responses can be sent with the peer MAC as BSSID */
4482 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
4483 stype
== WLAN_FC_STYPE_ACTION
) &&
4484 #endif /* CONFIG_P2P */
4486 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
4487 #endif /* CONFIG_MESH */
4488 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4489 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
4490 MAC2STR(mgmt
->bssid
));
4495 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
4496 handle_probe_req(hapd
, mgmt
, len
, ssi_signal
);
4500 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
4501 stype
!= WLAN_FC_STYPE_ACTION
) &&
4502 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4503 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4504 HOSTAPD_LEVEL_DEBUG
,
4505 "MGMT: DA=" MACSTR
" not our address",
4510 if (hapd
->iconf
->track_sta_max_num
)
4511 sta_track_add(hapd
->iface
, mgmt
->sa
, ssi_signal
);
4514 case WLAN_FC_STYPE_AUTH
:
4515 wpa_printf(MSG_DEBUG
, "mgmt::auth");
4516 handle_auth(hapd
, mgmt
, len
, ssi_signal
, 0);
4519 case WLAN_FC_STYPE_ASSOC_REQ
:
4520 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
4521 handle_assoc(hapd
, mgmt
, len
, 0, ssi_signal
);
4524 case WLAN_FC_STYPE_REASSOC_REQ
:
4525 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
4526 handle_assoc(hapd
, mgmt
, len
, 1, ssi_signal
);
4529 case WLAN_FC_STYPE_DISASSOC
:
4530 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
4531 handle_disassoc(hapd
, mgmt
, len
);
4534 case WLAN_FC_STYPE_DEAUTH
:
4535 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
4536 handle_deauth(hapd
, mgmt
, len
);
4539 case WLAN_FC_STYPE_ACTION
:
4540 wpa_printf(MSG_DEBUG
, "mgmt::action");
4541 ret
= handle_action(hapd
, mgmt
, len
, freq
);
4544 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4545 HOSTAPD_LEVEL_DEBUG
,
4546 "unknown mgmt frame subtype %d", stype
);
4554 static void handle_auth_cb(struct hostapd_data
*hapd
,
4555 const struct ieee80211_mgmt
*mgmt
,
4558 u16 auth_alg
, auth_transaction
, status_code
;
4559 struct sta_info
*sta
;
4561 sta
= ap_get_sta(hapd
, mgmt
->da
);
4563 wpa_printf(MSG_DEBUG
, "handle_auth_cb: STA " MACSTR
4569 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4570 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4571 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
4574 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4575 HOSTAPD_LEVEL_NOTICE
,
4576 "did not acknowledge authentication response");
4580 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
4581 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
4582 (unsigned long) len
);
4586 if (status_code
== WLAN_STATUS_SUCCESS
&&
4587 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
4588 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
4589 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4590 HOSTAPD_LEVEL_INFO
, "authenticated");
4591 sta
->flags
|= WLAN_STA_AUTH
;
4592 if (sta
->added_unassoc
)
4593 hostapd_set_sta_flags(hapd
, sta
);
4598 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
4599 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4600 sta
->added_unassoc
= 0;
4605 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
4606 struct sta_info
*sta
,
4610 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
4612 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
4615 for (i
= 0; i
< 4; i
++) {
4616 if (ssid
->wep
.key
[i
] &&
4617 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
4618 i
== ssid
->wep
.idx
, NULL
, 0,
4619 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
4620 wpa_printf(MSG_WARNING
,
4621 "Could not set WEP keys for WDS interface; %s",
4629 static void handle_assoc_cb(struct hostapd_data
*hapd
,
4630 const struct ieee80211_mgmt
*mgmt
,
4631 size_t len
, int reassoc
, int ok
)
4634 struct sta_info
*sta
;
4637 sta
= ap_get_sta(hapd
, mgmt
->da
);
4639 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4644 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4645 sizeof(mgmt
->u
.assoc_resp
))) {
4646 wpa_printf(MSG_INFO
,
4647 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4648 reassoc
, (unsigned long) len
);
4649 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4654 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4656 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4659 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4660 HOSTAPD_LEVEL_DEBUG
,
4661 "did not acknowledge association response");
4662 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4663 /* The STA is added only in case of SUCCESS */
4664 if (status
== WLAN_STATUS_SUCCESS
)
4665 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4670 if (status
!= WLAN_STATUS_SUCCESS
)
4673 /* Stop previous accounting session, if one is started, and allocate
4674 * new session id for the new session. */
4675 accounting_sta_stop(hapd
, sta
);
4677 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4679 "associated (aid %d)",
4682 if (sta
->flags
& WLAN_STA_ASSOC
)
4684 sta
->flags
|= WLAN_STA_ASSOC
;
4685 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4686 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4687 !hapd
->conf
->osen
) ||
4688 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4689 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4690 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4691 sta
->auth_alg
== WLAN_AUTH_FT
) {
4693 * Open, static WEP, FT protocol, or FILS; no separate
4694 * authorization step.
4696 ap_sta_set_authorized(hapd
, sta
, 1);
4700 mlme_reassociate_indication(hapd
, sta
);
4702 mlme_associate_indication(hapd
, sta
);
4704 #ifdef CONFIG_IEEE80211W
4705 sta
->sa_query_timed_out
= 0;
4706 #endif /* CONFIG_IEEE80211W */
4708 if (sta
->eapol_sm
== NULL
) {
4710 * This STA does not use RADIUS server for EAP authentication,
4711 * so bind it to the selected VLAN interface now, since the
4712 * interface selection is not going to change anymore.
4714 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4716 } else if (sta
->vlan_id
) {
4717 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4718 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4722 hostapd_set_sta_flags(hapd
, sta
);
4724 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4725 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4726 MACSTR
" based on pending request",
4727 MAC2STR(sta
->addr
));
4728 sta
->pending_wds_enable
= 0;
4729 sta
->flags
|= WLAN_STA_WDS
;
4732 if (sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_MULTI_AP
)) {
4734 char ifname_wds
[IFNAMSIZ
+ 1];
4736 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4738 MAC2STR(sta
->addr
), sta
->aid
);
4739 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
4742 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
4745 if (sta
->auth_alg
== WLAN_AUTH_FT
)
4746 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
4748 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
4749 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
4750 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
4753 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4754 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4755 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
4756 fils_set_tk(sta
->wpa_sm
) < 0) {
4757 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
4758 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
4759 WLAN_REASON_UNSPECIFIED
);
4762 #endif /* CONFIG_FILS */
4764 if (sta
->pending_eapol_rx
) {
4765 struct os_reltime now
, age
;
4767 os_get_reltime(&now
);
4768 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
4769 if (age
.sec
== 0 && age
.usec
< 200000) {
4770 wpa_printf(MSG_DEBUG
,
4771 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
4772 MAC2STR(sta
->addr
));
4775 wpabuf_head(sta
->pending_eapol_rx
->buf
),
4776 wpabuf_len(sta
->pending_eapol_rx
->buf
));
4778 wpabuf_free(sta
->pending_eapol_rx
->buf
);
4779 os_free(sta
->pending_eapol_rx
);
4780 sta
->pending_eapol_rx
= NULL
;
4785 static void handle_deauth_cb(struct hostapd_data
*hapd
,
4786 const struct ieee80211_mgmt
*mgmt
,
4789 struct sta_info
*sta
;
4790 if (is_multicast_ether_addr(mgmt
->da
))
4792 sta
= ap_get_sta(hapd
, mgmt
->da
);
4794 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
4795 " not found", MAC2STR(mgmt
->da
));
4799 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
4800 MAC2STR(sta
->addr
));
4802 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4803 "deauth", MAC2STR(sta
->addr
));
4805 ap_sta_deauth_cb(hapd
, sta
);
4809 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
4810 const struct ieee80211_mgmt
*mgmt
,
4813 struct sta_info
*sta
;
4814 if (is_multicast_ether_addr(mgmt
->da
))
4816 sta
= ap_get_sta(hapd
, mgmt
->da
);
4818 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
4819 " not found", MAC2STR(mgmt
->da
));
4823 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
4824 MAC2STR(sta
->addr
));
4826 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4827 "disassoc", MAC2STR(sta
->addr
));
4829 ap_sta_disassoc_cb(hapd
, sta
);
4833 static void handle_action_cb(struct hostapd_data
*hapd
,
4834 const struct ieee80211_mgmt
*mgmt
,
4837 struct sta_info
*sta
;
4838 const struct rrm_measurement_report_element
*report
;
4840 if (is_multicast_ether_addr(mgmt
->da
))
4843 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4844 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4845 mgmt
->u
.action
.u
.vs_public_action
.action
==
4846 WLAN_PA_VENDOR_SPECIFIC
&&
4847 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4849 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4851 const u8
*pos
, *end
;
4853 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
4854 end
= ((const u8
*) mgmt
) + len
;
4855 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
4858 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4859 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4860 (mgmt
->u
.action
.u
.public_action
.action
==
4861 WLAN_PA_GAS_INITIAL_REQ
||
4862 mgmt
->u
.action
.u
.public_action
.action
==
4863 WLAN_PA_GAS_COMEBACK_REQ
)) {
4864 const u8
*pos
, *end
;
4866 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
4867 end
= ((const u8
*) mgmt
) + len
;
4868 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
4871 #endif /* CONFIG_DPP */
4872 sta
= ap_get_sta(hapd
, mgmt
->da
);
4874 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
4875 " not found", MAC2STR(mgmt
->da
));
4879 if (len
< 24 + 5 + sizeof(*report
))
4881 report
= (const struct rrm_measurement_report_element
*)
4882 &mgmt
->u
.action
.u
.rrm
.variable
[2];
4883 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4884 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
4885 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
4887 report
->type
== MEASURE_TYPE_BEACON
)
4888 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
4893 * ieee802_11_mgmt_cb - Process management frame TX status callback
4894 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4896 * @buf: management frame data (starting from IEEE 802.11 header)
4897 * @len: length of frame data in octets
4898 * @stype: management frame subtype from frame control field
4899 * @ok: Whether the frame was ACK'ed
4901 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4904 const struct ieee80211_mgmt
*mgmt
;
4905 mgmt
= (const struct ieee80211_mgmt
*) buf
;
4907 #ifdef CONFIG_TESTING_OPTIONS
4908 if (hapd
->ext_mgmt_frame_handling
) {
4909 size_t hex_len
= 2 * len
+ 1;
4910 char *hex
= os_malloc(hex_len
);
4913 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
4914 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
4915 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4921 #endif /* CONFIG_TESTING_OPTIONS */
4924 case WLAN_FC_STYPE_AUTH
:
4925 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
4926 handle_auth_cb(hapd
, mgmt
, len
, ok
);
4928 case WLAN_FC_STYPE_ASSOC_RESP
:
4929 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
4930 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
4932 case WLAN_FC_STYPE_REASSOC_RESP
:
4933 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
4934 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
4936 case WLAN_FC_STYPE_PROBE_RESP
:
4937 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
4939 case WLAN_FC_STYPE_DEAUTH
:
4940 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
4941 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
4943 case WLAN_FC_STYPE_DISASSOC
:
4944 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
4945 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
4947 case WLAN_FC_STYPE_ACTION
:
4948 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
4949 handle_action_cb(hapd
, mgmt
, len
, ok
);
4952 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
4958 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
4965 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
4966 char *buf
, size_t buflen
)
4973 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
4974 const u8
*buf
, size_t len
, int ack
)
4976 struct sta_info
*sta
;
4977 struct hostapd_iface
*iface
= hapd
->iface
;
4979 sta
= ap_get_sta(hapd
, addr
);
4980 if (sta
== NULL
&& iface
->num_bss
> 1) {
4982 for (j
= 0; j
< iface
->num_bss
; j
++) {
4983 hapd
= iface
->bss
[j
];
4984 sta
= ap_get_sta(hapd
, addr
);
4989 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
4991 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
4992 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
4993 "activity poll", MAC2STR(sta
->addr
),
4994 ack
? "ACKed" : "did not ACK");
4996 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4999 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
5003 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
5004 const u8
*data
, size_t len
, int ack
)
5006 struct sta_info
*sta
;
5007 struct hostapd_iface
*iface
= hapd
->iface
;
5009 sta
= ap_get_sta(hapd
, dst
);
5010 if (sta
== NULL
&& iface
->num_bss
> 1) {
5012 for (j
= 0; j
< iface
->num_bss
; j
++) {
5013 hapd
= iface
->bss
[j
];
5014 sta
= ap_get_sta(hapd
, dst
);
5019 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
5020 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
5021 MACSTR
" that is not currently associated",
5026 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
5030 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
5032 struct sta_info
*sta
;
5033 struct hostapd_iface
*iface
= hapd
->iface
;
5035 sta
= ap_get_sta(hapd
, addr
);
5036 if (sta
== NULL
&& iface
->num_bss
> 1) {
5038 for (j
= 0; j
< iface
->num_bss
; j
++) {
5039 hapd
= iface
->bss
[j
];
5040 sta
= ap_get_sta(hapd
, addr
);
5047 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
5048 MAC2STR(sta
->addr
));
5049 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
5052 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
5053 "activity poll", MAC2STR(sta
->addr
));
5054 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5058 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
5061 struct sta_info
*sta
;
5063 sta
= ap_get_sta(hapd
, src
);
5065 ((sta
->flags
& WLAN_STA_ASSOC
) ||
5066 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
5067 if (!hapd
->conf
->wds_sta
)
5070 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
5071 WLAN_STA_ASSOC_REQ_OK
) {
5072 wpa_printf(MSG_DEBUG
,
5073 "Postpone 4-address WDS mode enabling for STA "
5074 MACSTR
" since TX status for AssocResp is not yet known",
5075 MAC2STR(sta
->addr
));
5076 sta
->pending_wds_enable
= 1;
5080 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
5082 char ifname_wds
[IFNAMSIZ
+ 1];
5084 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
5085 "STA " MACSTR
" (aid %u)",
5086 MAC2STR(sta
->addr
), sta
->aid
);
5087 sta
->flags
|= WLAN_STA_WDS
;
5088 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
5089 sta
->addr
, sta
->aid
, 1);
5091 hostapd_set_wds_encryption(hapd
, sta
,
5097 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
5098 MACSTR
, MAC2STR(src
));
5099 if (is_multicast_ether_addr(src
)) {
5100 /* Broadcast bit set in SA?! Ignore the frame silently. */
5104 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
5105 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
5106 "already been sent, but no TX status yet known - "
5107 "ignore Class 3 frame issue with " MACSTR
,
5112 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
5113 hostapd_drv_sta_disassoc(
5115 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5117 hostapd_drv_sta_deauth(
5119 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5123 #endif /* CONFIG_NATIVE_WINDOWS */