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
)
766 if (auth_transaction
!= 1 && auth_transaction
!= 2)
767 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
769 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
770 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
772 switch (sta
->sae
->state
) {
774 if (auth_transaction
== 1) {
775 ret
= auth_sae_send_commit(hapd
, sta
, bssid
,
779 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
781 if (sae_process_commit(sta
->sae
) < 0)
782 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
785 * In mesh case, both Commit and Confirm can be sent
786 * immediately. In infrastructure BSS, only a single
787 * Authentication frame (Commit) is expected from the AP
788 * here and the second one (Confirm) will be sent once
789 * the STA has sent its second Authentication frame
792 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
794 * Send both Commit and Confirm immediately
795 * based on SAE finite state machine
796 * Nothing -> Confirm transition.
798 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
801 sae_set_state(sta
, SAE_CONFIRMED
,
802 "Sent Confirm (mesh)");
805 * For infrastructure BSS, send only the Commit
806 * message now to get alternating sequence of
807 * Authentication frames between the AP and STA.
808 * Confirm will be sent in
809 * Committed -> Confirmed/Accepted transition
810 * when receiving Confirm from STA.
814 sae_set_retransmit_timer(hapd
, sta
);
816 hostapd_logger(hapd
, sta
->addr
,
817 HOSTAPD_MODULE_IEEE80211
,
819 "SAE confirm before commit");
823 sae_clear_retransmit_timer(hapd
, sta
);
824 if (auth_transaction
== 1) {
825 if (sae_process_commit(sta
->sae
) < 0)
826 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
828 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
831 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
833 sae_set_retransmit_timer(hapd
, sta
);
834 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
836 * In mesh case, follow SAE finite state machine and
837 * send Commit now, if sync count allows.
839 if (sae_check_big_sync(hapd
, sta
))
840 return WLAN_STATUS_SUCCESS
;
843 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
847 sae_set_retransmit_timer(hapd
, sta
);
850 * For instructure BSS, send the postponed Confirm from
851 * Nothing -> Confirmed transition that was reduced to
852 * Nothing -> Committed above.
854 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
858 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
861 * Since this was triggered on Confirm RX, run another
862 * step to get to Accepted without waiting for
865 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
,
870 sae_clear_retransmit_timer(hapd
, sta
);
871 if (auth_transaction
== 1) {
872 if (sae_check_big_sync(hapd
, sta
))
873 return WLAN_STATUS_SUCCESS
;
876 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
880 if (sae_process_commit(sta
->sae
) < 0)
881 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
883 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
887 sae_set_retransmit_timer(hapd
, sta
);
889 sta
->sae
->send_confirm
= 0xffff;
890 sae_accept_sta(hapd
, sta
);
894 if (auth_transaction
== 1 &&
895 (hapd
->conf
->mesh
& MESH_ENABLED
)) {
896 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
897 ") doing reauthentication",
899 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
900 ap_free_sta(hapd
, sta
);
901 } else if (auth_transaction
== 1) {
902 wpa_printf(MSG_DEBUG
, "SAE: Start reauthentication");
903 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
906 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
908 if (sae_process_commit(sta
->sae
) < 0)
909 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
911 sae_set_retransmit_timer(hapd
, sta
);
913 if (sae_check_big_sync(hapd
, sta
))
914 return WLAN_STATUS_SUCCESS
;
917 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
918 sae_clear_temp_data(sta
->sae
);
924 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
926 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
928 return WLAN_STATUS_SUCCESS
;
932 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
934 struct sae_data
*sae
= sta
->sae
;
935 int i
, *groups
= hapd
->conf
->sae_groups
;
936 int default_groups
[] = { 19, 0 };
938 if (sae
->state
!= SAE_COMMITTED
)
941 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
944 groups
= default_groups
;
945 for (i
= 0; groups
[i
] > 0; i
++) {
946 if (sae
->group
== groups
[i
])
950 if (groups
[i
] <= 0) {
951 wpa_printf(MSG_DEBUG
,
952 "SAE: Previously selected group not found from the current configuration");
958 if (groups
[i
] <= 0) {
959 wpa_printf(MSG_DEBUG
,
960 "SAE: No alternative group enabled");
964 if (sae_set_group(sae
, groups
[i
]) < 0)
969 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
973 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
974 const struct ieee80211_mgmt
*mgmt
, size_t len
,
975 u16 auth_transaction
, u16 status_code
)
977 int resp
= WLAN_STATUS_SUCCESS
;
978 struct wpabuf
*data
= NULL
;
979 int *groups
= hapd
->conf
->sae_groups
;
980 int default_groups
[] = { 19, 0 };
984 groups
= default_groups
;
986 #ifdef CONFIG_TESTING_OPTIONS
987 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
988 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
989 pos
= mgmt
->u
.auth
.variable
;
990 end
= ((const u8
*) mgmt
) + len
;
991 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
992 auth_transaction
, resp
, pos
, end
- pos
,
993 "auth-sae-reflection-attack");
997 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
998 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
999 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1000 auth_transaction
, resp
,
1001 wpabuf_head(hapd
->conf
->sae_commit_override
),
1002 wpabuf_len(hapd
->conf
->sae_commit_override
),
1003 "sae-commit-override");
1006 #endif /* CONFIG_TESTING_OPTIONS */
1008 if (auth_transaction
!= 1 ||
1009 status_code
!= WLAN_STATUS_SUCCESS
) {
1013 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
1018 sae_set_state(sta
, SAE_NOTHING
, "Init");
1022 if (sta
->mesh_sae_pmksa_caching
) {
1023 wpa_printf(MSG_DEBUG
,
1024 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1025 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
1026 sta
->mesh_sae_pmksa_caching
= 0;
1029 if (auth_transaction
== 1) {
1030 const u8
*token
= NULL
;
1031 size_t token_len
= 0;
1032 int allow_reuse
= 0;
1034 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1035 HOSTAPD_LEVEL_DEBUG
,
1036 "start SAE authentication (RX commit, status=%u)",
1039 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1040 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1042 pos
= mgmt
->u
.auth
.variable
;
1043 end
= ((const u8
*) mgmt
) + len
;
1044 if (pos
+ sizeof(le16
) > end
) {
1045 wpa_printf(MSG_ERROR
,
1046 "SAE: Too short anti-clogging token request");
1047 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1050 resp
= sae_group_allowed(sta
->sae
, groups
,
1052 if (resp
!= WLAN_STATUS_SUCCESS
) {
1053 wpa_printf(MSG_ERROR
,
1054 "SAE: Invalid group in anti-clogging token request");
1057 pos
+= sizeof(le16
);
1059 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
1060 sta
->sae
->tmp
->anti_clogging_token
=
1061 wpabuf_alloc_copy(pos
, end
- pos
);
1062 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
1063 wpa_printf(MSG_ERROR
,
1064 "SAE: Failed to alloc for anti-clogging token");
1065 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1070 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1071 * is 76, a new Commit Message shall be constructed
1072 * with the Anti-Clogging Token from the received
1073 * Authentication frame, and the commit-scalar and
1074 * COMMIT-ELEMENT previously sent.
1076 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
1077 if (resp
!= WLAN_STATUS_SUCCESS
) {
1078 wpa_printf(MSG_ERROR
,
1079 "SAE: Failed to send commit message");
1082 sae_set_state(sta
, SAE_COMMITTED
,
1083 "Sent Commit (anti-clogging token case in mesh)");
1085 sae_set_retransmit_timer(hapd
, sta
);
1089 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1091 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1093 wpa_printf(MSG_DEBUG
,
1094 "SAE: Peer did not accept our SAE group");
1095 sae_pick_next_group(hapd
, sta
);
1099 if (status_code
!= WLAN_STATUS_SUCCESS
)
1102 if (!(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1103 sta
->sae
->state
== SAE_COMMITTED
) {
1104 /* This is needed in the infrastructure BSS case to
1105 * address a sequence where a STA entry may remain in
1106 * hostapd across two attempts to do SAE authentication
1107 * by the same STA. The second attempt may end up trying
1108 * to use a different group and that would not be
1109 * allowed if we remain in Committed state with the
1110 * previously set parameters. */
1111 pos
= mgmt
->u
.auth
.variable
;
1112 end
= ((const u8
*) mgmt
) + len
;
1113 if (end
- pos
>= (int) sizeof(le16
) &&
1114 sae_group_allowed(sta
->sae
, groups
,
1115 WPA_GET_LE16(pos
)) ==
1116 WLAN_STATUS_SUCCESS
) {
1117 /* Do not waste resources deriving the same PWE
1118 * again since the same group is reused. */
1119 sae_set_state(sta
, SAE_NOTHING
,
1120 "Allow previous PWE to be reused");
1123 sae_set_state(sta
, SAE_NOTHING
,
1124 "Clear existing state to allow restart");
1125 sae_clear_data(sta
->sae
);
1129 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
1130 ((const u8
*) mgmt
) + len
-
1131 mgmt
->u
.auth
.variable
, &token
,
1132 &token_len
, groups
);
1133 if (resp
== SAE_SILENTLY_DISCARD
) {
1134 wpa_printf(MSG_DEBUG
,
1135 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
1136 MAC2STR(sta
->addr
));
1140 if (resp
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1141 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1142 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1143 MACSTR
, MAC2STR(sta
->addr
));
1144 sae_clear_retransmit_timer(hapd
, sta
);
1145 sae_set_state(sta
, SAE_NOTHING
,
1146 "Unknown Password Identifier");
1150 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
1152 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
1153 "incorrect token from " MACSTR
,
1154 MAC2STR(sta
->addr
));
1155 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1159 if (resp
!= WLAN_STATUS_SUCCESS
)
1162 if (!token
&& use_sae_anti_clogging(hapd
) && !allow_reuse
) {
1163 wpa_printf(MSG_DEBUG
,
1164 "SAE: Request anti-clogging token from "
1165 MACSTR
, MAC2STR(sta
->addr
));
1166 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
1168 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
1169 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1170 sae_set_state(sta
, SAE_NOTHING
,
1171 "Request anti-clogging token case in mesh");
1175 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1177 } else if (auth_transaction
== 2) {
1178 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1179 HOSTAPD_LEVEL_DEBUG
,
1180 "SAE authentication (RX confirm, status=%u)",
1182 if (status_code
!= WLAN_STATUS_SUCCESS
)
1184 if (sta
->sae
->state
>= SAE_CONFIRMED
||
1185 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
1188 u16 peer_send_confirm
;
1190 var
= mgmt
->u
.auth
.variable
;
1191 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
1193 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1197 peer_send_confirm
= WPA_GET_LE16(var
);
1199 if (sta
->sae
->state
== SAE_ACCEPTED
&&
1200 (peer_send_confirm
<= sta
->sae
->rc
||
1201 peer_send_confirm
== 0xffff)) {
1202 wpa_printf(MSG_DEBUG
,
1203 "SAE: Silently ignore unexpected Confirm from peer "
1205 " (peer-send-confirm=%u Rc=%u)",
1207 peer_send_confirm
, sta
->sae
->rc
);
1211 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
1212 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1215 sta
->sae
->rc
= peer_send_confirm
;
1217 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
, 0);
1219 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1220 HOSTAPD_LEVEL_DEBUG
,
1221 "unexpected SAE authentication transaction %u (status=%u)",
1222 auth_transaction
, status_code
);
1223 if (status_code
!= WLAN_STATUS_SUCCESS
)
1225 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1229 if (resp
!= WLAN_STATUS_SUCCESS
) {
1230 pos
= mgmt
->u
.auth
.variable
;
1231 end
= ((const u8
*) mgmt
) + len
;
1233 /* Copy the Finite Cyclic Group field from the request if we
1234 * rejected it as unsupported group. */
1235 if (resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1236 !data
&& end
- pos
>= 2)
1237 data
= wpabuf_alloc_copy(pos
, 2);
1239 sae_sme_send_external_auth_status(hapd
, sta
, resp
);
1240 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1241 auth_transaction
, resp
,
1242 data
? wpabuf_head(data
) : (u8
*) "",
1243 data
? wpabuf_len(data
) : 0, "auth-sae");
1247 if (sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
1248 status_code
!= WLAN_STATUS_SUCCESS
)) {
1249 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1250 sta
->added_unassoc
= 0;
1257 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1258 * @hapd: BSS data for the device initiating the authentication
1259 * @sta: the peer to which commit authentication frame is sent
1261 * This function implements Init event handling (IEEE Std 802.11-2012,
1262 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1263 * sta->sae structure should be initialized appropriately via a call to
1264 * sae_prepare_commit().
1266 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1270 if (!sta
->sae
|| !sta
->sae
->tmp
)
1273 if (sta
->sae
->state
!= SAE_NOTHING
)
1276 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1280 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1282 sae_set_retransmit_timer(hapd
, sta
);
1288 void auth_sae_process_commit(void *eloop_ctx
, void *user_ctx
)
1290 struct hostapd_data
*hapd
= eloop_ctx
;
1291 struct hostapd_sae_commit_queue
*q
;
1292 unsigned int queue_len
;
1294 q
= dl_list_first(&hapd
->sae_commit_queue
,
1295 struct hostapd_sae_commit_queue
, list
);
1298 wpa_printf(MSG_DEBUG
,
1299 "SAE: Process next available message from queue");
1300 dl_list_del(&q
->list
);
1301 handle_auth(hapd
, (const struct ieee80211_mgmt
*) q
->msg
, q
->len
,
1305 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1307 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1308 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1313 static void auth_sae_queue(struct hostapd_data
*hapd
,
1314 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1317 struct hostapd_sae_commit_queue
*q
, *q2
;
1318 unsigned int queue_len
;
1319 const struct ieee80211_mgmt
*mgmt2
;
1321 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1322 if (queue_len
>= 15) {
1323 wpa_printf(MSG_DEBUG
,
1324 "SAE: No more room in message queue - drop the new frame from "
1325 MACSTR
, MAC2STR(mgmt
->sa
));
1329 wpa_printf(MSG_DEBUG
, "SAE: Queue Authentication message from "
1330 MACSTR
" for processing (queue_len %u)", MAC2STR(mgmt
->sa
),
1332 q
= os_zalloc(sizeof(*q
) + len
);
1337 os_memcpy(q
->msg
, mgmt
, len
);
1339 /* Check whether there is already a queued Authentication frame from the
1340 * same station with the same transaction number and if so, replace that
1341 * queue entry with the new one. This avoids issues with a peer that
1342 * sends multiple times (e.g., due to frequent SAE retries). There is no
1343 * point in us trying to process the old attempts after a new one has
1344 * obsoleted them. */
1345 dl_list_for_each(q2
, &hapd
->sae_commit_queue
,
1346 struct hostapd_sae_commit_queue
, list
) {
1347 mgmt2
= (const struct ieee80211_mgmt
*) q2
->msg
;
1348 if (os_memcmp(mgmt
->sa
, mgmt2
->sa
, ETH_ALEN
) == 0 &&
1349 mgmt
->u
.auth
.auth_transaction
==
1350 mgmt2
->u
.auth
.auth_transaction
) {
1351 wpa_printf(MSG_DEBUG
,
1352 "SAE: Replace queued message from same STA with same transaction number");
1353 dl_list_add(&q2
->list
, &q
->list
);
1354 dl_list_del(&q2
->list
);
1360 /* No pending identical entry, so add to the end of the queue */
1361 dl_list_add_tail(&hapd
->sae_commit_queue
, &q
->list
);
1364 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1366 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1371 static int auth_sae_queued_addr(struct hostapd_data
*hapd
, const u8
*addr
)
1373 struct hostapd_sae_commit_queue
*q
;
1374 const struct ieee80211_mgmt
*mgmt
;
1376 dl_list_for_each(q
, &hapd
->sae_commit_queue
,
1377 struct hostapd_sae_commit_queue
, list
) {
1378 mgmt
= (const struct ieee80211_mgmt
*) q
->msg
;
1379 if (os_memcmp(addr
, mgmt
->sa
, ETH_ALEN
) == 0)
1386 #endif /* CONFIG_SAE */
1389 static u16
wpa_res_to_status_code(int res
)
1391 if (res
== WPA_INVALID_GROUP
)
1392 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1393 if (res
== WPA_INVALID_PAIRWISE
)
1394 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1395 if (res
== WPA_INVALID_AKMP
)
1396 return WLAN_STATUS_AKMP_NOT_VALID
;
1397 if (res
== WPA_ALLOC_FAIL
)
1398 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1399 #ifdef CONFIG_IEEE80211W
1400 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1401 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1402 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1403 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1404 #endif /* CONFIG_IEEE80211W */
1405 if (res
== WPA_INVALID_MDIE
)
1406 return WLAN_STATUS_INVALID_MDIE
;
1407 if (res
== WPA_INVALID_PMKID
)
1408 return WLAN_STATUS_INVALID_PMKID
;
1409 if (res
!= WPA_IE_OK
)
1410 return WLAN_STATUS_INVALID_IE
;
1411 return WLAN_STATUS_SUCCESS
;
1417 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1418 struct sta_info
*sta
, u16 resp
,
1419 struct wpabuf
*data
, int pub
);
1421 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1422 const u8
*pos
, size_t len
, u16 auth_alg
,
1423 u16 auth_transaction
, u16 status_code
,
1424 void (*cb
)(struct hostapd_data
*hapd
,
1425 struct sta_info
*sta
, u16 resp
,
1426 struct wpabuf
*data
, int pub
))
1428 u16 resp
= WLAN_STATUS_SUCCESS
;
1430 struct ieee802_11_elems elems
;
1432 struct wpa_ie_data rsn
;
1433 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1435 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1440 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1444 #ifdef CONFIG_FILS_SK_PFS
1445 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1450 /* Using FILS PFS */
1452 /* Finite Cyclic Group */
1453 if (end
- pos
< 2) {
1454 wpa_printf(MSG_DEBUG
,
1455 "FILS: No room for Finite Cyclic Group");
1456 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1459 group
= WPA_GET_LE16(pos
);
1461 if (group
!= hapd
->conf
->fils_dh_group
) {
1462 wpa_printf(MSG_DEBUG
,
1463 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1464 group
, hapd
->conf
->fils_dh_group
);
1465 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1469 crypto_ecdh_deinit(sta
->fils_ecdh
);
1470 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1471 if (!sta
->fils_ecdh
) {
1472 wpa_printf(MSG_INFO
,
1473 "FILS: Could not initialize ECDH with group %d",
1475 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1479 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1481 wpa_printf(MSG_DEBUG
,
1482 "FILS: Failed to derive ECDH public key");
1483 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1486 elem_len
= wpabuf_len(pub
);
1490 if ((size_t) (end
- pos
) < elem_len
) {
1491 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1492 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1496 wpabuf_free(sta
->fils_g_sta
);
1497 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1498 wpabuf_clear_free(sta
->fils_dh_ss
);
1499 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1501 if (!sta
->fils_dh_ss
) {
1502 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1503 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1506 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1509 crypto_ecdh_deinit(sta
->fils_ecdh
);
1510 sta
->fils_ecdh
= NULL
;
1511 wpabuf_clear_free(sta
->fils_dh_ss
);
1512 sta
->fils_dh_ss
= NULL
;
1514 #endif /* CONFIG_FILS_SK_PFS */
1516 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1517 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1518 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1519 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1524 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1525 elems
.rsn_ie
, elems
.rsn_ie_len
);
1526 if (!elems
.rsn_ie
||
1527 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1529 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1530 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1535 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1538 wpa_printf(MSG_DEBUG
,
1539 "FILS: Failed to initialize RSN state machine");
1540 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1544 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1546 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1547 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1548 resp
= wpa_res_to_status_code(res
);
1549 if (resp
!= WLAN_STATUS_SUCCESS
)
1552 if (!elems
.fils_nonce
) {
1553 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1554 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1557 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1559 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1562 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1566 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1567 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1570 num
= rsn
.num_pmkid
;
1572 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1573 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1577 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1586 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1587 wpa_printf(MSG_DEBUG
,
1588 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1589 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1593 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1596 if (!elems
.fils_session
) {
1597 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1598 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1601 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1603 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1605 /* FILS Wrapped Data */
1606 if (elems
.fils_wrapped_data
) {
1607 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1608 elems
.fils_wrapped_data
,
1609 elems
.fils_wrapped_data_len
);
1611 #ifndef CONFIG_NO_RADIUS
1612 if (!sta
->eapol_sm
) {
1614 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1616 wpa_printf(MSG_DEBUG
,
1617 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1618 ieee802_1x_encapsulate_radius(
1619 hapd
, sta
, elems
.fils_wrapped_data
,
1620 elems
.fils_wrapped_data_len
);
1621 sta
->fils_pending_cb
= cb
;
1622 wpa_printf(MSG_DEBUG
,
1623 "FILS: Will send Authentication frame once the response from authentication server is available");
1624 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1625 /* Calculate pending PMKID here so that we do not need
1626 * to maintain a copy of the EAP-Initiate/Reauth
1628 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1629 elems
.fils_wrapped_data
,
1630 elems
.fils_wrapped_data_len
,
1631 sta
->fils_erp_pmkid
) == 0)
1632 sta
->fils_erp_pmkid_set
= 1;
1634 #else /* CONFIG_NO_RADIUS */
1635 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1637 #endif /* CONFIG_NO_RADIUS */
1643 struct wpabuf
*data
;
1646 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1649 wpa_printf(MSG_DEBUG
,
1650 "%s: prepare_auth_resp_fils() returned failure",
1654 cb(hapd
, sta
, resp
, data
, pub
);
1659 static struct wpabuf
*
1660 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1661 struct sta_info
*sta
, u16
*resp
,
1662 struct rsn_pmksa_cache_entry
*pmksa
,
1663 struct wpabuf
*erp_resp
,
1664 const u8
*msk
, size_t msk_len
,
1667 u8 fils_nonce
[FILS_NONCE_LEN
];
1669 struct wpabuf
*data
= NULL
;
1672 const u8
*pmk
= NULL
;
1674 u8 pmk_buf
[PMK_LEN_MAX
];
1675 struct wpabuf
*pub
= NULL
;
1677 if (*resp
!= WLAN_STATUS_SUCCESS
)
1680 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1682 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1687 /* Add PMKID of the selected PMKSA into RSNE */
1688 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1690 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1694 os_memcpy(ie_buf
, ie
, ielen
);
1695 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1696 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1702 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1703 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1706 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1707 fils_nonce
, FILS_NONCE_LEN
);
1709 #ifdef CONFIG_FILS_SK_PFS
1710 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1711 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1713 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1717 #endif /* CONFIG_FILS_SK_PFS */
1719 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1721 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1726 #ifdef CONFIG_FILS_SK_PFS
1728 /* Finite Cyclic Group */
1729 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1732 wpabuf_put_buf(data
, pub
);
1734 #endif /* CONFIG_FILS_SK_PFS */
1737 wpabuf_put_data(data
, ie
, ielen
);
1739 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1741 #ifdef CONFIG_IEEE80211R_AP
1742 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1743 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1745 int use_sha384
= wpa_key_mgmt_sha384(
1746 wpa_auth_sta_key_mgmt(sta
->wpa_sm
));
1748 res
= wpa_auth_write_fte(hapd
->wpa_auth
, use_sha384
,
1749 wpabuf_put(data
, 0),
1750 wpabuf_tailroom(data
));
1752 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1755 wpabuf_put(data
, res
);
1757 #endif /* CONFIG_IEEE80211R_AP */
1760 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1761 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1762 /* Element ID Extension */
1763 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1764 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1767 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1768 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1769 /* Element ID Extension */
1770 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1771 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1773 /* FILS Wrapped Data */
1774 if (!pmksa
&& erp_resp
) {
1775 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1776 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1777 /* Element ID Extension */
1778 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1779 wpabuf_put_buf(data
, erp_resp
);
1781 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1782 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1784 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1786 wpabuf_len(sta
->fils_dh_ss
) : 0,
1787 pmk_buf
, &pmk_len
)) {
1788 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1789 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1796 /* Don't use DHss in PTK derivation if PMKSA caching is not
1798 wpabuf_clear_free(sta
->fils_dh_ss
);
1799 sta
->fils_dh_ss
= NULL
;
1801 if (sta
->fils_erp_pmkid_set
) {
1802 /* TODO: get PMKLifetime from WPA parameters */
1803 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1804 int session_timeout
;
1806 session_timeout
= dot11RSNAConfigPMKLifetime
;
1807 if (sta
->session_timeout_set
) {
1808 struct os_reltime now
, diff
;
1810 os_get_reltime(&now
);
1811 os_reltime_sub(&sta
->session_timeout
, &now
,
1813 session_timeout
= diff
.sec
;
1816 sta
->fils_erp_pmkid_set
= 0;
1817 if (!hapd
->conf
->disable_pmksa_caching
&&
1818 wpa_auth_pmksa_add2(
1819 hapd
->wpa_auth
, sta
->addr
,
1821 sta
->fils_erp_pmkid
,
1823 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1824 wpa_printf(MSG_ERROR
,
1825 "FILS: Failed to add PMKSA cache entry based on ERP");
1830 pmk_len
= pmksa
->pmk_len
;
1834 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1835 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1841 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1842 sta
->fils_snonce
, fils_nonce
,
1844 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1846 wpabuf_len(sta
->fils_dh_ss
) : 0,
1847 sta
->fils_g_sta
, pub
) < 0) {
1848 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1856 *is_pub
= pub
!= NULL
;
1859 wpabuf_clear_free(sta
->fils_dh_ss
);
1860 sta
->fils_dh_ss
= NULL
;
1861 #ifdef CONFIG_FILS_SK_PFS
1862 crypto_ecdh_deinit(sta
->fils_ecdh
);
1863 sta
->fils_ecdh
= NULL
;
1864 #endif /* CONFIG_FILS_SK_PFS */
1869 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1870 struct sta_info
*sta
, u16 resp
,
1871 struct wpabuf
*data
, int pub
)
1876 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1877 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1878 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1879 data
? wpabuf_head(data
) : (u8
*) "",
1880 data
? wpabuf_len(data
) : 0, "auth-fils-finish");
1883 if (resp
== WLAN_STATUS_SUCCESS
) {
1884 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1885 HOSTAPD_LEVEL_DEBUG
,
1886 "authentication OK (FILS)");
1887 sta
->flags
|= WLAN_STA_AUTH
;
1888 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1889 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1890 mlme_authenticate_indication(hapd
, sta
);
1895 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
1896 struct sta_info
*sta
, int success
,
1897 struct wpabuf
*erp_resp
,
1898 const u8
*msk
, size_t msk_len
)
1900 struct wpabuf
*data
;
1904 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1906 if (!sta
->fils_pending_cb
)
1908 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
1909 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
1910 msk
, msk_len
, &pub
);
1912 wpa_printf(MSG_DEBUG
,
1913 "%s: prepare_auth_resp_fils() returned failure",
1916 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
1919 #endif /* CONFIG_FILS */
1923 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
1924 const u8
*msg
, size_t len
, u32
*session_timeout
,
1925 u32
*acct_interim_interval
,
1926 struct vlan_description
*vlan_id
,
1927 struct hostapd_sta_wpa_psk_short
**psk
,
1928 char **identity
, char **radius_cui
, int is_probe_req
)
1932 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
1933 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
1934 session_timeout
, acct_interim_interval
,
1935 vlan_id
, psk
, identity
, radius_cui
,
1938 if (res
== HOSTAPD_ACL_REJECT
) {
1940 wpa_printf(MSG_DEBUG
,
1942 " not allowed to authenticate",
1944 return HOSTAPD_ACL_REJECT
;
1947 if (res
== HOSTAPD_ACL_PENDING
) {
1948 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
1949 " waiting for an external authentication",
1951 /* Authentication code will re-send the authentication frame
1952 * after it has received (and cached) information from the
1953 * external source. */
1954 return HOSTAPD_ACL_PENDING
;
1962 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1963 int res
, u32 session_timeout
,
1964 u32 acct_interim_interval
,
1965 struct vlan_description
*vlan_id
,
1966 struct hostapd_sta_wpa_psk_short
**psk
,
1967 char **identity
, char **radius_cui
)
1969 if (vlan_id
->notempty
&&
1970 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
1971 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1973 "Invalid VLAN %d%s received from RADIUS server",
1975 vlan_id
->tagged
[0] ? "+" : "");
1978 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
1981 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1982 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
1984 hostapd_free_psk_list(sta
->psk
);
1985 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
1992 os_free(sta
->identity
);
1993 sta
->identity
= *identity
;
1996 os_free(sta
->radius_cui
);
1997 sta
->radius_cui
= *radius_cui
;
2000 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
2001 sta
->acct_interim_interval
= acct_interim_interval
;
2002 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
) {
2003 sta
->session_timeout_set
= 1;
2004 os_get_reltime(&sta
->session_timeout
);
2005 sta
->session_timeout
.sec
+= session_timeout
;
2006 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
2008 sta
->session_timeout_set
= 0;
2009 ap_sta_no_session_timeout(hapd
, sta
);
2016 static void handle_auth(struct hostapd_data
*hapd
,
2017 const struct ieee80211_mgmt
*mgmt
, size_t len
,
2018 int rssi
, int from_queue
)
2020 u16 auth_alg
, auth_transaction
, status_code
;
2021 u16 resp
= WLAN_STATUS_SUCCESS
;
2022 struct sta_info
*sta
= NULL
;
2025 const u8
*challenge
= NULL
;
2026 u32 session_timeout
, acct_interim_interval
;
2027 struct vlan_description vlan_id
;
2028 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
2029 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
2030 size_t resp_ies_len
= 0;
2031 char *identity
= NULL
;
2032 char *radius_cui
= NULL
;
2035 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
2036 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
2037 (unsigned long) len
);
2041 #ifdef CONFIG_TESTING_OPTIONS
2042 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
2043 drand48() < hapd
->iconf
->ignore_auth_probability
) {
2044 wpa_printf(MSG_INFO
,
2045 "TESTING: ignoring auth frame from " MACSTR
,
2049 #endif /* CONFIG_TESTING_OPTIONS */
2051 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
2052 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
2053 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
2054 fc
= le_to_host16(mgmt
->frame_control
);
2055 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
2057 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
2058 2 + WLAN_AUTH_CHALLENGE_LEN
&&
2059 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
2060 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
2061 challenge
= &mgmt
->u
.auth
.variable
[2];
2063 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
2064 "auth_transaction=%d status_code=%d wep=%d%s "
2065 "seq_ctrl=0x%x%s%s",
2066 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
2067 status_code
, !!(fc
& WLAN_FC_ISWEP
),
2068 challenge
? " challenge" : "",
2069 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "",
2070 from_queue
? " (from queue)" : "");
2072 #ifdef CONFIG_NO_RC4
2073 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
2074 wpa_printf(MSG_INFO
,
2075 "Unsupported authentication algorithm (%d)",
2077 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2080 #endif /* CONFIG_NO_RC4 */
2082 if (hapd
->tkip_countermeasures
) {
2083 wpa_printf(MSG_DEBUG
,
2084 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2085 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2089 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
2090 auth_alg
== WLAN_AUTH_OPEN
) ||
2091 #ifdef CONFIG_IEEE80211R_AP
2092 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
2093 auth_alg
== WLAN_AUTH_FT
) ||
2094 #endif /* CONFIG_IEEE80211R_AP */
2096 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
2097 auth_alg
== WLAN_AUTH_SAE
) ||
2098 #endif /* CONFIG_SAE */
2100 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2101 auth_alg
== WLAN_AUTH_FILS_SK
) ||
2102 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2103 hapd
->conf
->fils_dh_group
&&
2104 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
2105 #endif /* CONFIG_FILS */
2106 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
2107 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
2108 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
2110 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2114 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
2115 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
2116 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
2118 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
2122 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
2123 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
2125 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2129 if (hapd
->conf
->no_auth_if_seen_on
) {
2130 struct hostapd_data
*other
;
2132 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
2133 hapd
->conf
->no_auth_if_seen_on
);
2137 u8 op_class
, channel
, phytype
;
2139 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
2140 MACSTR
" since STA has been seen on %s",
2141 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
2142 hapd
->conf
->no_auth_if_seen_on
);
2144 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
2146 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
2148 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
2150 info
= 0; /* TODO: BSSID Information */
2151 WPA_PUT_LE32(pos
, info
);
2153 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
2154 phytype
= 8; /* dmg */
2155 else if (other
->iconf
->ieee80211ac
)
2156 phytype
= 9; /* vht */
2157 else if (other
->iconf
->ieee80211n
)
2158 phytype
= 7; /* ht */
2159 else if (other
->iconf
->hw_mode
==
2160 HOSTAPD_MODE_IEEE80211A
)
2161 phytype
= 4; /* ofdm */
2162 else if (other
->iconf
->hw_mode
==
2163 HOSTAPD_MODE_IEEE80211G
)
2164 phytype
= 6; /* erp */
2166 phytype
= 5; /* hrdsss */
2167 if (ieee80211_freq_to_channel_ext(
2168 hostapd_hw_get_freq(other
,
2169 other
->iconf
->channel
),
2170 other
->iconf
->secondary_channel
,
2171 other
->iconf
->ieee80211ac
,
2172 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
2174 channel
= other
->iconf
->channel
;
2179 resp_ies_len
= pos
- &resp_ies
[0];
2184 res
= ieee802_11_allowed_address(
2185 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
2186 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
,
2188 if (res
== HOSTAPD_ACL_REJECT
) {
2189 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
2190 "Ignore Authentication frame from " MACSTR
2191 " due to ACL reject", MAC2STR(mgmt
->sa
));
2192 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2195 if (res
== HOSTAPD_ACL_PENDING
)
2199 if (auth_alg
== WLAN_AUTH_SAE
&& !from_queue
&&
2200 (auth_transaction
== 1 ||
2201 (auth_transaction
== 2 && auth_sae_queued_addr(hapd
, mgmt
->sa
)))) {
2202 /* Handle SAE Authentication commit message through a queue to
2203 * provide more control for postponing the needed heavy
2204 * processing under a possible DoS attack scenario. In addition,
2205 * queue SAE Authentication confirm message if there happens to
2206 * be a queued commit message from the same peer. This is needed
2207 * to avoid reordering Authentication frames within the same
2209 auth_sae_queue(hapd
, mgmt
, len
, rssi
);
2212 #endif /* CONFIG_SAE */
2214 sta
= ap_get_sta(hapd
, mgmt
->sa
);
2216 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2217 sta
->ft_over_ds
= 0;
2218 if ((fc
& WLAN_FC_RETRY
) &&
2219 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
2220 sta
->last_seq_ctrl
== seq_ctrl
&&
2221 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
2222 hostapd_logger(hapd
, sta
->addr
,
2223 HOSTAPD_MODULE_IEEE80211
,
2224 HOSTAPD_LEVEL_DEBUG
,
2225 "Drop repeated authentication frame seq_ctrl=0x%x",
2230 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
2231 sta
->plink_state
== PLINK_BLOCKED
) {
2232 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2233 " is blocked - drop Authentication frame",
2237 #endif /* CONFIG_MESH */
2240 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
2241 /* if the mesh peer is not available, we don't do auth.
2243 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2244 " not yet known - drop Authentication frame",
2247 * Save a copy of the frame so that it can be processed
2248 * if a new peer entry is added shortly after this.
2250 wpabuf_free(hapd
->mesh_pending_auth
);
2251 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
2252 os_get_reltime(&hapd
->mesh_pending_auth_time
);
2255 #endif /* CONFIG_MESH */
2257 sta
= ap_sta_add(hapd
, mgmt
->sa
);
2259 wpa_printf(MSG_DEBUG
, "ap_sta_add() failed");
2260 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2264 sta
->last_seq_ctrl
= seq_ctrl
;
2265 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
2267 sta
->auth_rssi
= rssi
;
2268 #endif /* CONFIG_MBO */
2270 res
= ieee802_11_set_radius_info(
2271 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
2272 &vlan_id
, &psk
, &identity
, &radius_cui
);
2274 wpa_printf(MSG_DEBUG
, "ieee802_11_set_radius_info() failed");
2275 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2279 sta
->flags
&= ~WLAN_STA_PREAUTH
;
2280 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
2283 * If the driver supports full AP client state, add a station to the
2284 * driver before sending authentication reply to make sure the driver
2285 * has resources, and not to go through the entire authentication and
2286 * association handshake, and fail it at the end.
2288 * If this is not the first transaction, in a multi-step authentication
2289 * algorithm, the station already exists in the driver
2290 * (sta->added_unassoc = 1) so skip it.
2292 * In mesh mode, the station was already added to the driver when the
2293 * NEW_PEER_CANDIDATE event is received.
2295 * If PMF was negotiated for the existing association, skip this to
2296 * avoid dropping the STA entry and the associated keys. This is needed
2297 * to allow the original connection work until the attempt can complete
2298 * (re)association, so that unprotected Authentication frame cannot be
2299 * used to bypass PMF protection.
2301 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
2302 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
2303 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
2304 !(sta
->added_unassoc
)) {
2306 * If a station that is already associated to the AP, is trying
2307 * to authenticate again, remove the STA entry, in order to make
2308 * sure the STA PS state gets cleared and configuration gets
2309 * updated. To handle this, station's added_unassoc flag is
2310 * cleared once the station has completed association.
2312 ap_sta_set_authorized(hapd
, sta
, 0);
2313 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2314 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
2315 WLAN_STA_AUTHORIZED
);
2317 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0, NULL
, 0, 0,
2318 NULL
, NULL
, sta
->flags
, 0, 0, 0, 0)) {
2319 hostapd_logger(hapd
, sta
->addr
,
2320 HOSTAPD_MODULE_IEEE80211
,
2321 HOSTAPD_LEVEL_NOTICE
,
2322 "Could not add STA to kernel driver");
2323 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2327 sta
->added_unassoc
= 1;
2331 case WLAN_AUTH_OPEN
:
2332 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2333 HOSTAPD_LEVEL_DEBUG
,
2334 "authentication OK (open system)");
2335 sta
->flags
|= WLAN_STA_AUTH
;
2336 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2337 sta
->auth_alg
= WLAN_AUTH_OPEN
;
2338 mlme_authenticate_indication(hapd
, sta
);
2340 #ifndef CONFIG_NO_RC4
2341 case WLAN_AUTH_SHARED_KEY
:
2342 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
2343 fc
& WLAN_FC_ISWEP
);
2345 wpa_printf(MSG_DEBUG
,
2346 "auth_shared_key() failed: status=%d", resp
);
2347 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2348 mlme_authenticate_indication(hapd
, sta
);
2349 if (sta
->challenge
&& auth_transaction
== 1) {
2350 resp_ies
[0] = WLAN_EID_CHALLENGE
;
2351 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
2352 os_memcpy(resp_ies
+ 2, sta
->challenge
,
2353 WLAN_AUTH_CHALLENGE_LEN
);
2354 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
2357 #endif /* CONFIG_NO_RC4 */
2358 #ifdef CONFIG_IEEE80211R_AP
2360 sta
->auth_alg
= WLAN_AUTH_FT
;
2361 if (sta
->wpa_sm
== NULL
)
2362 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2364 if (sta
->wpa_sm
== NULL
) {
2365 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
2367 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2370 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
2371 auth_transaction
, mgmt
->u
.auth
.variable
,
2372 len
- IEEE80211_HDRLEN
-
2373 sizeof(mgmt
->u
.auth
),
2374 handle_auth_ft_finish
, hapd
);
2375 /* handle_auth_ft_finish() callback will complete auth. */
2377 #endif /* CONFIG_IEEE80211R_AP */
2381 if (status_code
== WLAN_STATUS_SUCCESS
&&
2382 hapd
->conf
->mesh
& MESH_ENABLED
) {
2383 if (sta
->wpa_sm
== NULL
)
2385 wpa_auth_sta_init(hapd
->wpa_auth
,
2387 if (sta
->wpa_sm
== NULL
) {
2388 wpa_printf(MSG_DEBUG
,
2389 "SAE: Failed to initialize WPA state machine");
2390 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2394 #endif /* CONFIG_MESH */
2395 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2398 #endif /* CONFIG_SAE */
2400 case WLAN_AUTH_FILS_SK
:
2401 case WLAN_AUTH_FILS_SK_PFS
:
2402 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2403 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2404 auth_alg
, auth_transaction
, status_code
,
2405 handle_auth_fils_finish
);
2407 #endif /* CONFIG_FILS */
2412 os_free(radius_cui
);
2413 hostapd_free_psk_list(psk
);
2415 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2416 auth_transaction
+ 1, resp
, resp_ies
,
2417 resp_ies_len
, "handle-auth");
2419 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2420 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2421 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2422 sta
->added_unassoc
= 0;
2427 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2431 /* get a unique AID */
2433 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2440 for (i
= 0; i
< AID_WORDS
; i
++) {
2441 if (hapd
->sta_aid
[i
] == (u32
) -1)
2443 for (j
= 0; j
< 32; j
++) {
2444 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2452 aid
= i
* 32 + j
+ 1;
2457 hapd
->sta_aid
[i
] |= BIT(j
);
2458 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2463 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2464 const u8
*ssid_ie
, size_t ssid_ie_len
)
2466 if (ssid_ie
== NULL
)
2467 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2469 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2470 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2471 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2473 "Station tried to associate with unknown SSID "
2474 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2475 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2478 return WLAN_STATUS_SUCCESS
;
2482 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2483 const u8
*wmm_ie
, size_t wmm_ie_len
)
2485 sta
->flags
&= ~WLAN_STA_WMM
;
2487 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2488 struct wmm_information_element
*wmm
;
2490 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2491 hostapd_logger(hapd
, sta
->addr
,
2493 HOSTAPD_LEVEL_DEBUG
,
2494 "invalid WMM element in association "
2496 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2499 sta
->flags
|= WLAN_STA_WMM
;
2500 wmm
= (struct wmm_information_element
*) wmm_ie
;
2501 sta
->qosinfo
= wmm
->qos_info
;
2503 return WLAN_STATUS_SUCCESS
;
2506 static u16
check_multi_ap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2507 const u8
*multi_ap_ie
, size_t multi_ap_len
)
2509 u8 multi_ap_value
= 0;
2511 sta
->flags
&= ~WLAN_STA_MULTI_AP
;
2513 if (!hapd
->conf
->multi_ap
)
2514 return WLAN_STATUS_SUCCESS
;
2517 const u8
*multi_ap_subelem
;
2519 multi_ap_subelem
= get_ie(multi_ap_ie
+ 4,
2521 MULTI_AP_SUB_ELEM_TYPE
);
2522 if (multi_ap_subelem
&& multi_ap_subelem
[1] == 1) {
2523 multi_ap_value
= multi_ap_subelem
[2];
2525 hostapd_logger(hapd
, sta
->addr
,
2526 HOSTAPD_MODULE_IEEE80211
,
2528 "Multi-AP IE has missing or invalid Multi-AP subelement");
2529 return WLAN_STATUS_INVALID_IE
;
2533 if (multi_ap_value
&& multi_ap_value
!= MULTI_AP_BACKHAUL_STA
)
2534 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2536 "Multi-AP IE with unexpected value 0x%02x",
2539 if (!(multi_ap_value
& MULTI_AP_BACKHAUL_STA
)) {
2540 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
2541 return WLAN_STATUS_SUCCESS
;
2543 hostapd_logger(hapd
, sta
->addr
,
2544 HOSTAPD_MODULE_IEEE80211
,
2546 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2547 return WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
2550 if (!(hapd
->conf
->multi_ap
& BACKHAUL_BSS
))
2551 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2552 HOSTAPD_LEVEL_DEBUG
,
2553 "Backhaul STA tries to associate with fronthaul-only BSS");
2555 sta
->flags
|= WLAN_STA_MULTI_AP
;
2556 return WLAN_STATUS_SUCCESS
;
2560 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2561 struct ieee802_11_elems
*elems
)
2563 /* Supported rates not used in IEEE 802.11ad/DMG */
2564 if (hapd
->iface
->current_mode
&&
2565 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2566 return WLAN_STATUS_SUCCESS
;
2568 if (!elems
->supp_rates
) {
2569 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2570 HOSTAPD_LEVEL_DEBUG
,
2571 "No supported rates element in AssocReq");
2572 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2575 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2576 sizeof(sta
->supported_rates
)) {
2577 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2578 HOSTAPD_LEVEL_DEBUG
,
2579 "Invalid supported rates element length %d+%d",
2580 elems
->supp_rates_len
,
2581 elems
->ext_supp_rates_len
);
2582 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2585 sta
->supported_rates_len
= merge_byte_arrays(
2586 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2587 elems
->supp_rates
, elems
->supp_rates_len
,
2588 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2590 return WLAN_STATUS_SUCCESS
;
2594 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2595 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2597 #ifdef CONFIG_INTERWORKING
2598 /* check for QoS Map support */
2599 if (ext_capab_ie_len
>= 5) {
2600 if (ext_capab_ie
[4] & 0x01)
2601 sta
->qos_map_enabled
= 1;
2603 #endif /* CONFIG_INTERWORKING */
2605 if (ext_capab_ie_len
> 0) {
2606 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2607 os_free(sta
->ext_capability
);
2608 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2609 if (sta
->ext_capability
) {
2610 sta
->ext_capability
[0] = ext_capab_ie_len
;
2611 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2616 return WLAN_STATUS_SUCCESS
;
2622 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2625 int *groups
= hapd
->conf
->owe_groups
;
2627 if (group
!= 19 && group
!= 20 && group
!= 21)
2633 for (i
= 0; groups
[i
] > 0; i
++) {
2634 if (groups
[i
] == group
)
2642 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2643 struct sta_info
*sta
, const u8
*owe_dh
,
2646 struct wpabuf
*secret
, *pub
, *hkey
;
2648 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2649 const char *info
= "OWE Key Generation";
2653 size_t hash_len
, prime_len
;
2655 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2656 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2657 return WLAN_STATUS_SUCCESS
;
2660 group
= WPA_GET_LE16(owe_dh
);
2661 if (!owe_group_supported(hapd
, group
)) {
2662 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2663 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2667 else if (group
== 20)
2669 else if (group
== 21)
2672 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2674 crypto_ecdh_deinit(sta
->owe_ecdh
);
2675 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2677 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2678 sta
->owe_group
= group
;
2680 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2682 secret
= wpabuf_zeropad(secret
, prime_len
);
2684 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2685 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2687 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2689 /* prk = HKDF-extract(C | A | group, z) */
2691 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2693 wpabuf_clear_free(secret
);
2694 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2697 /* PMKID = Truncate-128(Hash(C | A)) */
2698 addr
[0] = owe_dh
+ 2;
2699 len
[0] = owe_dh_len
- 2;
2700 addr
[1] = wpabuf_head(pub
);
2701 len
[1] = wpabuf_len(pub
);
2703 res
= sha256_vector(2, addr
, len
, pmkid
);
2704 hash_len
= SHA256_MAC_LEN
;
2705 } else if (group
== 20) {
2706 res
= sha384_vector(2, addr
, len
, pmkid
);
2707 hash_len
= SHA384_MAC_LEN
;
2708 } else if (group
== 21) {
2709 res
= sha512_vector(2, addr
, len
, pmkid
);
2710 hash_len
= SHA512_MAC_LEN
;
2713 wpabuf_clear_free(secret
);
2714 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2716 pub
= wpabuf_zeropad(pub
, prime_len
);
2717 if (res
< 0 || !pub
) {
2719 wpabuf_clear_free(secret
);
2720 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2723 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2726 wpabuf_clear_free(secret
);
2727 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2730 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2731 wpabuf_put_buf(hkey
, pub
); /* A */
2733 wpabuf_put_le16(hkey
, group
); /* group */
2735 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2736 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2737 else if (group
== 20)
2738 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2739 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2740 else if (group
== 21)
2741 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2742 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2743 wpabuf_clear_free(hkey
);
2744 wpabuf_clear_free(secret
);
2746 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2748 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2750 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2752 os_free(sta
->owe_pmk
);
2753 sta
->owe_pmk
= os_malloc(hash_len
);
2754 if (!sta
->owe_pmk
) {
2755 os_memset(prk
, 0, SHA512_MAC_LEN
);
2756 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2760 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2761 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2762 else if (group
== 20)
2763 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2764 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2765 else if (group
== 21)
2766 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2767 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2768 os_memset(prk
, 0, SHA512_MAC_LEN
);
2770 os_free(sta
->owe_pmk
);
2771 sta
->owe_pmk
= NULL
;
2772 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2774 sta
->owe_pmk_len
= hash_len
;
2776 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2777 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2778 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2779 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2781 return WLAN_STATUS_SUCCESS
;
2784 #endif /* CONFIG_OWE */
2787 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2788 const u8
*ies
, size_t ies_len
, int reassoc
)
2790 struct ieee802_11_elems elems
;
2794 const u8
*p2p_dev_addr
= NULL
;
2796 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2797 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2798 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
2799 "association request");
2800 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2803 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
2804 if (resp
!= WLAN_STATUS_SUCCESS
)
2806 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
2807 if (resp
!= WLAN_STATUS_SUCCESS
)
2809 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
2810 if (resp
!= WLAN_STATUS_SUCCESS
)
2812 resp
= copy_supp_rates(hapd
, sta
, &elems
);
2813 if (resp
!= WLAN_STATUS_SUCCESS
)
2816 resp
= check_multi_ap(hapd
, sta
, elems
.multi_ap
, elems
.multi_ap_len
);
2817 if (resp
!= WLAN_STATUS_SUCCESS
)
2820 #ifdef CONFIG_IEEE80211N
2821 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
2822 if (resp
!= WLAN_STATUS_SUCCESS
)
2824 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
2825 !(sta
->flags
& WLAN_STA_HT
)) {
2826 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2827 HOSTAPD_LEVEL_INFO
, "Station does not support "
2828 "mandatory HT PHY - reject association");
2829 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
2831 #endif /* CONFIG_IEEE80211N */
2833 #ifdef CONFIG_IEEE80211AC
2834 if (hapd
->iconf
->ieee80211ac
) {
2835 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
2836 if (resp
!= WLAN_STATUS_SUCCESS
)
2839 resp
= copy_sta_vht_oper(hapd
, sta
, elems
.vht_operation
);
2840 if (resp
!= WLAN_STATUS_SUCCESS
)
2843 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
2844 if (resp
!= WLAN_STATUS_SUCCESS
)
2848 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
2849 !(sta
->flags
& WLAN_STA_VHT
)) {
2850 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2851 HOSTAPD_LEVEL_INFO
, "Station does not support "
2852 "mandatory VHT PHY - reject association");
2853 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
2856 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
2857 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
2858 elems
.vendor_vht_len
);
2859 if (resp
!= WLAN_STATUS_SUCCESS
)
2862 #endif /* CONFIG_IEEE80211AC */
2866 wpabuf_free(sta
->p2p_ie
);
2867 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2868 P2P_IE_VENDOR_TYPE
);
2870 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
2872 wpabuf_free(sta
->p2p_ie
);
2875 #endif /* CONFIG_P2P */
2877 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
2878 wpa_ie
= elems
.rsn_ie
;
2879 wpa_ie_len
= elems
.rsn_ie_len
;
2880 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
2882 wpa_ie
= elems
.wpa_ie
;
2883 wpa_ie_len
= elems
.wpa_ie_len
;
2890 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
2891 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
2892 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
2893 "Request - assume WPS is used");
2894 sta
->flags
|= WLAN_STA_WPS
;
2895 wpabuf_free(sta
->wps_ie
);
2896 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2897 WPS_IE_VENDOR_TYPE
);
2898 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
2899 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
2900 sta
->flags
|= WLAN_STA_WPS2
;
2904 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
2905 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
2906 "(Re)Association Request - reject");
2907 return WLAN_STATUS_INVALID_IE
;
2909 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
2910 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
2911 "(Re)Association Request - possible WPS use");
2912 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
2914 #endif /* CONFIG_WPS */
2915 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
2916 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2918 "No WPA/RSN IE in association request");
2919 return WLAN_STATUS_INVALID_IE
;
2922 if (hapd
->conf
->wpa
&& wpa_ie
) {
2926 if (sta
->wpa_sm
== NULL
)
2927 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2930 if (sta
->wpa_sm
== NULL
) {
2931 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2933 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2935 wpa_auth_set_auth_alg(sta
->wpa_sm
, sta
->auth_alg
);
2936 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2939 elems
.mdie
, elems
.mdie_len
,
2940 elems
.owe_dh
, elems
.owe_dh_len
);
2941 resp
= wpa_res_to_status_code(res
);
2942 if (resp
!= WLAN_STATUS_SUCCESS
)
2944 #ifdef CONFIG_IEEE80211W
2945 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
2946 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
2947 !sta
->sa_query_timed_out
&&
2948 sta
->sa_query_count
> 0)
2949 ap_check_sa_query_timeout(hapd
, sta
);
2950 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
2951 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
2952 !sta
->sa_query_timed_out
&&
2953 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
2955 * STA has already been associated with MFP and SA
2956 * Query timeout has not been reached. Reject the
2957 * association attempt temporarily and start SA Query,
2958 * if one is not pending.
2961 if (sta
->sa_query_count
== 0)
2962 ap_sta_start_sa_query(hapd
, sta
);
2964 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
2967 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
2968 sta
->flags
|= WLAN_STA_MFP
;
2970 sta
->flags
&= ~WLAN_STA_MFP
;
2971 #endif /* CONFIG_IEEE80211W */
2973 #ifdef CONFIG_IEEE80211R_AP
2974 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
2976 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
2977 "to use association (not "
2978 "re-association) with FT auth_alg",
2979 MAC2STR(sta
->addr
));
2980 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2983 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
2985 if (resp
!= WLAN_STATUS_SUCCESS
)
2988 #endif /* CONFIG_IEEE80211R_AP */
2991 if (wpa_auth_uses_sae(sta
->wpa_sm
) && sta
->sae
&&
2992 sta
->sae
->state
== SAE_ACCEPTED
)
2993 wpa_auth_add_sae_pmkid(sta
->wpa_sm
, sta
->sae
->pmkid
);
2995 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
2996 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
2997 struct rsn_pmksa_cache_entry
*sa
;
2998 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
2999 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
3000 wpa_printf(MSG_DEBUG
,
3001 "SAE: No PMKSA cache entry found for "
3002 MACSTR
, MAC2STR(sta
->addr
));
3003 return WLAN_STATUS_INVALID_PMKID
;
3005 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
3006 " using PMKSA caching", MAC2STR(sta
->addr
));
3007 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3008 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
3009 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
3010 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
3011 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
3012 "SAE AKM after non-SAE auth_alg %u",
3013 MAC2STR(sta
->addr
), sta
->auth_alg
);
3014 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
3016 #endif /* CONFIG_SAE */
3019 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3020 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
3022 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
3024 if (resp
!= WLAN_STATUS_SUCCESS
)
3027 #endif /* CONFIG_OWE */
3030 dpp_pfs_free(sta
->dpp_pfs
);
3031 sta
->dpp_pfs
= NULL
;
3033 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3034 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
3035 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
3037 sta
->dpp_pfs
= dpp_pfs_init(
3038 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
3039 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
3040 if (!sta
->dpp_pfs
) {
3041 wpa_printf(MSG_DEBUG
,
3042 "DPP: Could not initialize PFS");
3043 /* Try to continue without PFS */
3047 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
3048 elems
.owe_dh_len
) < 0) {
3049 dpp_pfs_free(sta
->dpp_pfs
);
3050 sta
->dpp_pfs
= NULL
;
3051 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3055 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
3056 sta
->dpp_pfs
->secret
: NULL
);
3058 #endif /* CONFIG_DPP2 */
3060 #ifdef CONFIG_IEEE80211N
3061 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
3062 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
3063 hostapd_logger(hapd
, sta
->addr
,
3064 HOSTAPD_MODULE_IEEE80211
,
3066 "Station tried to use TKIP with HT "
3068 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
3070 #endif /* CONFIG_IEEE80211N */
3072 } else if (hapd
->conf
->osen
) {
3073 if (elems
.osen
== NULL
) {
3075 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3077 "No HS 2.0 OSEN element in association request");
3078 return WLAN_STATUS_INVALID_IE
;
3081 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
3082 if (sta
->wpa_sm
== NULL
)
3083 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3085 if (sta
->wpa_sm
== NULL
) {
3086 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3088 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3090 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
3091 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
3092 return WLAN_STATUS_INVALID_IE
;
3093 #endif /* CONFIG_HS20 */
3095 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
3098 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
3099 #endif /* CONFIG_P2P */
3102 wpabuf_free(sta
->hs20_ie
);
3103 if (elems
.hs20
&& elems
.hs20_len
> 4) {
3106 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
3107 elems
.hs20_len
- 4);
3108 release
= ((elems
.hs20
[4] >> 4) & 0x0f) + 1;
3109 if (release
>= 2 && !wpa_auth_uses_mfp(sta
->wpa_sm
)) {
3110 wpa_printf(MSG_DEBUG
,
3111 "HS 2.0: PMF not negotiated by release %d station "
3112 MACSTR
, release
, MAC2STR(sta
->addr
));
3113 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
3116 sta
->hs20_ie
= NULL
;
3119 wpabuf_free(sta
->roaming_consortium
);
3120 if (elems
.roaming_cons_sel
)
3121 sta
->roaming_consortium
= wpabuf_alloc_copy(
3122 elems
.roaming_cons_sel
+ 4,
3123 elems
.roaming_cons_sel_len
- 4);
3125 sta
->roaming_consortium
= NULL
;
3126 #endif /* CONFIG_HS20 */
3129 wpabuf_free(sta
->mb_ies
);
3130 if (hapd
->iface
->fst
)
3131 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
3134 #endif /* CONFIG_FST */
3137 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
3139 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
3140 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
3141 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3142 wpa_printf(MSG_INFO
,
3143 "MBO: Reject WPA2 association without PMF");
3144 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3146 #endif /* CONFIG_MBO */
3148 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3149 if (wpa_auth_uses_ocv(sta
->wpa_sm
) &&
3150 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3151 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3152 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)) {
3153 struct wpa_channel_info ci
;
3157 if (hostapd_drv_channel_info(hapd
, &ci
) != 0) {
3158 wpa_printf(MSG_WARNING
,
3159 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3160 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3163 if (get_sta_tx_parameters(sta
->wpa_sm
,
3164 channel_width_to_int(ci
.chanwidth
),
3165 ci
.seg1_idx
, &tx_chanwidth
,
3167 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3169 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
3170 tx_chanwidth
, tx_seg1_idx
) != 0) {
3171 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
3172 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3175 #endif /* CONFIG_FILS && CONFIG_OCV */
3177 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
3178 elems
.supp_op_classes_len
);
3180 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
3181 elems
.rrm_enabled
&&
3182 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
3183 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
3184 sizeof(sta
->rrm_enabled_capa
));
3186 if (elems
.power_capab
) {
3187 sta
->min_tx_power
= elems
.power_capab
[0];
3188 sta
->max_tx_power
= elems
.power_capab
[1];
3189 sta
->power_capab
= 1;
3191 sta
->power_capab
= 0;
3194 return WLAN_STATUS_SUCCESS
;
3198 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
3202 struct ieee80211_mgmt reply
;
3204 os_memset(&reply
, 0, sizeof(reply
));
3205 reply
.frame_control
=
3206 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
3207 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
3208 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
3209 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
3211 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
3212 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
3214 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
3215 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
3220 static int add_associated_sta(struct hostapd_data
*hapd
,
3221 struct sta_info
*sta
, int reassoc
)
3223 struct ieee80211_ht_capabilities ht_cap
;
3224 struct ieee80211_vht_capabilities vht_cap
;
3228 * Remove the STA entry to ensure the STA PS state gets cleared and
3229 * configuration gets updated. This is relevant for cases, such as
3230 * FT-over-the-DS, where a station re-associates back to the same AP but
3231 * skips the authentication flow, or if working with a driver that
3232 * does not support full AP client state.
3234 * Skip this if the STA has already completed FT reassociation and the
3235 * TK has been configured since the TX/RX PN must not be reset to 0 for
3238 * FT-over-the-DS has a special case where the STA entry (and as such,
3239 * the TK) has not yet been configured to the driver depending on which
3240 * driver interface is used. For that case, allow add-STA operation to
3241 * be used (instead of set-STA). This is needed to allow mac80211-based
3242 * drivers to accept the STA parameter configuration. Since this is
3243 * after a new FT-over-DS exchange, a new TK has been derived, so key
3244 * reinstallation is not a concern for this case.
3246 wpa_printf(MSG_DEBUG
, "Add associated STA " MACSTR
3247 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3248 MAC2STR(sta
->addr
), sta
->added_unassoc
, sta
->auth_alg
,
3249 sta
->ft_over_ds
, reassoc
,
3250 !!(sta
->flags
& WLAN_STA_AUTHORIZED
),
3251 wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
),
3252 wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
));
3254 if (!sta
->added_unassoc
&&
3255 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3256 (reassoc
&& sta
->ft_over_ds
&& sta
->auth_alg
== WLAN_AUTH_FT
) ||
3257 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
3258 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
3259 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3260 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
3263 /* Do not allow the FT-over-DS exception to be used more than
3264 * once per authentication exchange to guarantee a new TK is
3266 sta
->ft_over_ds
= 0;
3269 #ifdef CONFIG_IEEE80211N
3270 if (sta
->flags
& WLAN_STA_HT
)
3271 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
3272 #endif /* CONFIG_IEEE80211N */
3273 #ifdef CONFIG_IEEE80211AC
3274 if (sta
->flags
& WLAN_STA_VHT
)
3275 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
3276 #endif /* CONFIG_IEEE80211AC */
3279 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3280 * will be set when the ACK frame for the (Re)Association Response frame
3281 * is processed (TX status driver event).
3283 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
3284 sta
->supported_rates
, sta
->supported_rates_len
,
3285 sta
->listen_interval
,
3286 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
3287 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
3288 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
3289 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
3291 hostapd_logger(hapd
, sta
->addr
,
3292 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
3293 "Could not %s STA to kernel driver",
3294 set
? "set" : "add");
3296 if (sta
->added_unassoc
) {
3297 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3298 sta
->added_unassoc
= 0;
3304 sta
->added_unassoc
= 0;
3310 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3311 const u8
*addr
, u16 status_code
, int reassoc
,
3312 const u8
*ies
, size_t ies_len
, int rssi
)
3317 struct ieee80211_mgmt
*reply
;
3319 u16 res
= WLAN_STATUS_SUCCESS
;
3321 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
3323 if (sta
&& sta
->fils_hlp_resp
)
3324 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
3325 #endif /* CONFIG_FILS */
3327 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3329 #endif /* CONFIG_OWE */
3331 if (sta
&& sta
->dpp_pfs
)
3332 buflen
+= 5 + sta
->dpp_pfs
->curve
->prime_len
;
3333 #endif /* CONFIG_DPP2 */
3334 buf
= os_zalloc(buflen
);
3336 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3339 reply
= (struct ieee80211_mgmt
*) buf
;
3340 reply
->frame_control
=
3341 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3342 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
3343 WLAN_FC_STYPE_ASSOC_RESP
));
3344 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
3345 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
3346 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3348 send_len
= IEEE80211_HDRLEN
;
3349 send_len
+= sizeof(reply
->u
.assoc_resp
);
3350 reply
->u
.assoc_resp
.capab_info
=
3351 host_to_le16(hostapd_own_capab_info(hapd
));
3352 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
3354 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
3356 /* Supported rates */
3357 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
3358 /* Extended supported rates */
3359 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
3362 if (status_code
== WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
3364 int delta
= hapd
->iconf
->rssi_reject_assoc_rssi
- rssi
;
3366 p
= hostapd_eid_mbo_rssi_assoc_rej(hapd
, p
, buf
+ buflen
- p
,
3369 #endif /* CONFIG_MBO */
3371 #ifdef CONFIG_IEEE80211R_AP
3372 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
3373 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3374 * Transition Information, RSN, [RIC Response] */
3375 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
3377 sta
->auth_alg
, ies
, ies_len
);
3379 wpa_printf(MSG_DEBUG
,
3380 "FT: Failed to write AssocResp IEs");
3381 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3385 #endif /* CONFIG_IEEE80211R_AP */
3388 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3389 (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3390 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
3393 #endif /* CONFIG_OWE */
3395 #ifdef CONFIG_IEEE80211W
3396 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
3397 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
3398 #endif /* CONFIG_IEEE80211W */
3400 #ifdef CONFIG_IEEE80211N
3401 p
= hostapd_eid_ht_capabilities(hapd
, p
);
3402 p
= hostapd_eid_ht_operation(hapd
, p
);
3403 #endif /* CONFIG_IEEE80211N */
3405 #ifdef CONFIG_IEEE80211AC
3406 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
) {
3407 u32 nsts
= 0, sta_nsts
;
3409 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
3410 struct ieee80211_vht_capabilities
*capa
;
3412 nsts
= (hapd
->iface
->conf
->vht_capab
>>
3413 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3414 capa
= sta
->vht_capabilities
;
3415 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
3416 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3418 if (nsts
< sta_nsts
)
3423 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
3424 p
= hostapd_eid_vht_operation(hapd
, p
);
3426 #endif /* CONFIG_IEEE80211AC */
3428 p
= hostapd_eid_ext_capab(hapd
, p
);
3429 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
3430 if (sta
&& sta
->qos_map_enabled
)
3431 p
= hostapd_eid_qos_map_set(hapd
, p
);
3434 if (hapd
->iface
->fst_ies
) {
3435 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
3436 wpabuf_len(hapd
->iface
->fst_ies
));
3437 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
3439 #endif /* CONFIG_FST */
3442 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3443 sta
&& sta
->owe_ecdh
&& status_code
== WLAN_STATUS_SUCCESS
&&
3444 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
3447 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3449 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3452 /* OWE Diffie-Hellman Parameter element */
3453 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3454 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3455 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3456 WPA_PUT_LE16(p
, sta
->owe_group
);
3458 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
3459 p
+= wpabuf_len(pub
);
3462 #endif /* CONFIG_OWE */
3465 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3466 sta
&& sta
->dpp_pfs
&& status_code
== WLAN_STATUS_SUCCESS
&&
3467 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
) {
3468 os_memcpy(p
, wpabuf_head(sta
->dpp_pfs
->ie
),
3469 wpabuf_len(sta
->dpp_pfs
->ie
));
3470 p
+= wpabuf_len(sta
->dpp_pfs
->ie
);
3472 #endif /* CONFIG_DPP2 */
3474 #ifdef CONFIG_IEEE80211AC
3475 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
3476 p
= hostapd_eid_vendor_vht(hapd
, p
);
3477 #endif /* CONFIG_IEEE80211AC */
3479 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
3480 p
= hostapd_eid_wmm(hapd
, p
);
3484 ((sta
->flags
& WLAN_STA_WPS
) ||
3485 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
3486 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
3488 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
3489 p
+= wpabuf_len(wps
);
3493 #endif /* CONFIG_WPS */
3495 if (sta
&& (sta
->flags
& WLAN_STA_MULTI_AP
))
3496 p
= hostapd_eid_multi_ap(hapd
, p
);
3499 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
3500 struct wpabuf
*p2p_resp_ie
;
3501 enum p2p_status_code status
;
3502 switch (status_code
) {
3503 case WLAN_STATUS_SUCCESS
:
3504 status
= P2P_SC_SUCCESS
;
3506 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
3507 status
= P2P_SC_FAIL_LIMIT_REACHED
;
3510 status
= P2P_SC_FAIL_INVALID_PARAMS
;
3513 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
3515 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
3516 wpabuf_len(p2p_resp_ie
));
3517 p
+= wpabuf_len(p2p_resp_ie
);
3518 wpabuf_free(p2p_resp_ie
);
3521 #endif /* CONFIG_P2P */
3523 #ifdef CONFIG_P2P_MANAGER
3524 if (hapd
->conf
->p2p
& P2P_MANAGE
)
3525 p
= hostapd_eid_p2p_manage(hapd
, p
);
3526 #endif /* CONFIG_P2P_MANAGER */
3528 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
3530 if (hapd
->conf
->assocresp_elements
&&
3531 (size_t) (buf
+ buflen
- p
) >=
3532 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
3533 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
3534 wpabuf_len(hapd
->conf
->assocresp_elements
));
3535 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
3538 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
3542 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3543 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3544 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
3545 status_code
== WLAN_STATUS_SUCCESS
) {
3546 struct ieee802_11_elems elems
;
3548 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
3549 ParseFailed
|| !elems
.fils_session
) {
3550 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3555 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3556 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
3557 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
3558 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
3559 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
3561 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
3562 buflen
, sta
->fils_hlp_resp
);
3564 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3568 #endif /* CONFIG_FILS */
3570 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
3571 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
3573 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3583 u8
* owe_assoc_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3584 const u8
*owe_dh
, u8 owe_dh_len
,
3585 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
3587 #ifdef CONFIG_TESTING_OPTIONS
3588 if (hapd
->conf
->own_ie_override
) {
3589 wpa_printf(MSG_DEBUG
, "OWE: Using IE override");
3590 *reason
= WLAN_STATUS_SUCCESS
;
3591 return wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3592 owe_buf_len
, NULL
, 0);
3594 #endif /* CONFIG_TESTING_OPTIONS */
3596 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
3597 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
3598 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3599 owe_buf_len
, NULL
, 0);
3600 *reason
= WLAN_STATUS_SUCCESS
;
3604 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3605 if (*reason
!= WLAN_STATUS_SUCCESS
)
3608 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3609 owe_buf_len
, NULL
, 0);
3611 if (sta
->owe_ecdh
&& owe_buf
) {
3614 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3616 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3620 /* OWE Diffie-Hellman Parameter element */
3621 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3622 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3623 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3625 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3627 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3628 owe_buf
+= wpabuf_len(pub
);
3634 #endif /* CONFIG_OWE */
3639 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3643 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3644 MAC2STR(sta
->addr
));
3645 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3646 if (!sta
->fils_pending_assoc_req
)
3648 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3649 sta
->fils_pending_assoc_is_reassoc
,
3650 sta
->fils_pending_assoc_req
,
3651 sta
->fils_pending_assoc_req_len
, 0);
3652 os_free(sta
->fils_pending_assoc_req
);
3653 sta
->fils_pending_assoc_req
= NULL
;
3654 sta
->fils_pending_assoc_req_len
= 0;
3655 wpabuf_free(sta
->fils_hlp_resp
);
3656 sta
->fils_hlp_resp
= NULL
;
3657 wpabuf_free(sta
->hlp_dhcp_discover
);
3658 sta
->hlp_dhcp_discover
= NULL
;
3661 * Remove the station in case transmission of a success response fails.
3662 * At this point the station was already added associated to the driver.
3664 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3665 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3669 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3671 struct hostapd_data
*hapd
= eloop_ctx
;
3672 struct sta_info
*sta
= eloop_data
;
3674 wpa_printf(MSG_DEBUG
,
3675 "FILS: HLP response timeout - continue with association response for "
3676 MACSTR
, MAC2STR(sta
->addr
));
3677 if (sta
->fils_drv_assoc_finish
)
3678 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3680 fils_hlp_finish_assoc(hapd
, sta
);
3683 #endif /* CONFIG_FILS */
3686 static void handle_assoc(struct hostapd_data
*hapd
,
3687 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3688 int reassoc
, int rssi
)
3690 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3691 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3694 struct sta_info
*sta
;
3696 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3697 char *identity
= NULL
;
3698 char *radius_cui
= NULL
;
3700 int delay_assoc
= 0;
3701 #endif /* CONFIG_FILS */
3703 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3704 sizeof(mgmt
->u
.assoc_req
))) {
3705 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3706 reassoc
, (unsigned long) len
);
3710 #ifdef CONFIG_TESTING_OPTIONS
3712 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3713 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3714 wpa_printf(MSG_INFO
,
3715 "TESTING: ignoring reassoc request from "
3716 MACSTR
, MAC2STR(mgmt
->sa
));
3720 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3721 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3722 wpa_printf(MSG_INFO
,
3723 "TESTING: ignoring assoc request from "
3724 MACSTR
, MAC2STR(mgmt
->sa
));
3728 #endif /* CONFIG_TESTING_OPTIONS */
3730 fc
= le_to_host16(mgmt
->frame_control
);
3731 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3734 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
3735 listen_interval
= le_to_host16(
3736 mgmt
->u
.reassoc_req
.listen_interval
);
3737 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
3738 " capab_info=0x%02x listen_interval=%d current_ap="
3739 MACSTR
" seq_ctrl=0x%x%s",
3740 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3741 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
3742 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3743 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
3744 pos
= mgmt
->u
.reassoc_req
.variable
;
3746 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
3747 listen_interval
= le_to_host16(
3748 mgmt
->u
.assoc_req
.listen_interval
);
3749 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
3750 " capab_info=0x%02x listen_interval=%d "
3752 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3753 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3754 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
3755 pos
= mgmt
->u
.assoc_req
.variable
;
3758 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3759 #ifdef CONFIG_IEEE80211R_AP
3760 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
3761 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3762 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
3763 "prior to authentication since it is using "
3764 "over-the-DS FT", MAC2STR(mgmt
->sa
));
3767 * Mark station as authenticated, to avoid adding station
3768 * entry in the driver as associated and not authenticated
3770 sta
->flags
|= WLAN_STA_AUTH
;
3772 #endif /* CONFIG_IEEE80211R_AP */
3773 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3774 if (hapd
->iface
->current_mode
&&
3775 hapd
->iface
->current_mode
->mode
==
3776 HOSTAPD_MODE_IEEE80211AD
) {
3778 u32 session_timeout
, acct_interim_interval
;
3779 struct vlan_description vlan_id
;
3781 acl_res
= ieee802_11_allowed_address(
3782 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
3783 &session_timeout
, &acct_interim_interval
,
3784 &vlan_id
, &psk
, &identity
, &radius_cui
, 0);
3785 if (acl_res
== HOSTAPD_ACL_REJECT
) {
3786 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
3787 "Ignore Association Request frame from "
3788 MACSTR
" due to ACL reject",
3790 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3793 if (acl_res
== HOSTAPD_ACL_PENDING
)
3796 /* DMG/IEEE 802.11ad does not use authentication.
3797 * Allocate sta entry upon association. */
3798 sta
= ap_sta_add(hapd
, mgmt
->sa
);
3800 hostapd_logger(hapd
, mgmt
->sa
,
3801 HOSTAPD_MODULE_IEEE80211
,
3803 "Failed to add STA");
3804 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3808 acl_res
= ieee802_11_set_radius_info(
3809 hapd
, sta
, acl_res
, session_timeout
,
3810 acct_interim_interval
, &vlan_id
, &psk
,
3811 &identity
, &radius_cui
);
3813 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3817 hostapd_logger(hapd
, sta
->addr
,
3818 HOSTAPD_MODULE_IEEE80211
,
3819 HOSTAPD_LEVEL_DEBUG
,
3820 "Skip authentication for DMG/IEEE 802.11ad");
3821 sta
->flags
|= WLAN_STA_AUTH
;
3822 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
3823 sta
->auth_alg
= WLAN_AUTH_OPEN
;
3825 hostapd_logger(hapd
, mgmt
->sa
,
3826 HOSTAPD_MODULE_IEEE80211
,
3828 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3829 sta
? sta
->aid
: -1,
3830 sta
? sta
->flags
: 0);
3831 send_deauth(hapd
, mgmt
->sa
,
3832 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
3837 if ((fc
& WLAN_FC_RETRY
) &&
3838 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3839 sta
->last_seq_ctrl
== seq_ctrl
&&
3840 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3841 WLAN_FC_STYPE_ASSOC_REQ
)) {
3842 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3843 HOSTAPD_LEVEL_DEBUG
,
3844 "Drop repeated association frame seq_ctrl=0x%x",
3848 sta
->last_seq_ctrl
= seq_ctrl
;
3849 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3850 WLAN_FC_STYPE_ASSOC_REQ
;
3852 if (hapd
->tkip_countermeasures
) {
3853 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3857 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
3858 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3859 HOSTAPD_LEVEL_DEBUG
,
3860 "Too large Listen Interval (%d)",
3862 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
3867 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
3868 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3872 if (hapd
->iconf
->rssi_reject_assoc_rssi
&& rssi
&&
3873 rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
&&
3874 (sta
->auth_rssi
== 0 ||
3875 sta
->auth_rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
)) {
3876 resp
= WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
;
3879 #endif /* CONFIG_MBO */
3882 * sta->capability is used in check_assoc_ies() for RRM enabled
3883 * capability element.
3885 sta
->capability
= capab_info
;
3888 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3889 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3890 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3893 /* The end of the payload is encrypted. Need to decrypt it
3894 * before parsing. */
3896 tmp
= os_memdup(pos
, left
);
3898 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3902 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
3905 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3911 #endif /* CONFIG_FILS */
3913 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3915 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
3916 if (resp
!= WLAN_STATUS_SUCCESS
)
3919 if (hostapd_get_aid(hapd
, sta
) < 0) {
3920 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3921 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
3922 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3926 sta
->listen_interval
= listen_interval
;
3928 if (hapd
->iface
->current_mode
&&
3929 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
3930 sta
->flags
|= WLAN_STA_NONERP
;
3931 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
3932 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
3933 sta
->flags
&= ~WLAN_STA_NONERP
;
3937 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
3938 sta
->nonerp_set
= 1;
3939 hapd
->iface
->num_sta_non_erp
++;
3940 if (hapd
->iface
->num_sta_non_erp
== 1)
3941 ieee802_11_set_beacons(hapd
->iface
);
3944 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
3945 !sta
->no_short_slot_time_set
) {
3946 sta
->no_short_slot_time_set
= 1;
3947 hapd
->iface
->num_sta_no_short_slot_time
++;
3948 if (hapd
->iface
->current_mode
&&
3949 hapd
->iface
->current_mode
->mode
==
3950 HOSTAPD_MODE_IEEE80211G
&&
3951 hapd
->iface
->num_sta_no_short_slot_time
== 1)
3952 ieee802_11_set_beacons(hapd
->iface
);
3955 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3956 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
3958 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
3960 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
3961 !sta
->no_short_preamble_set
) {
3962 sta
->no_short_preamble_set
= 1;
3963 hapd
->iface
->num_sta_no_short_preamble
++;
3964 if (hapd
->iface
->current_mode
&&
3965 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
3966 && hapd
->iface
->num_sta_no_short_preamble
== 1)
3967 ieee802_11_set_beacons(hapd
->iface
);
3970 #ifdef CONFIG_IEEE80211N
3971 update_ht_state(hapd
, sta
);
3972 #endif /* CONFIG_IEEE80211N */
3974 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3975 HOSTAPD_LEVEL_DEBUG
,
3976 "association OK (aid %d)", sta
->aid
);
3977 /* Station will be marked associated, after it acknowledges AssocResp
3979 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
3981 #ifdef CONFIG_IEEE80211W
3982 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
3983 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
3984 "SA Query procedure", reassoc
? "re" : "");
3985 /* TODO: Send a protected Disassociate frame to the STA using
3986 * the old key and Reason Code "Previous Authentication no
3987 * longer valid". Make sure this is only sent protected since
3988 * unprotected frame would be received by the STA that is now
3989 * trying to associate.
3992 #endif /* CONFIG_IEEE80211W */
3994 /* Make sure that the previously registered inactivity timer will not
3995 * remove the STA immediately. */
3996 sta
->timeout_next
= STA_NULLFUNC
;
3998 #ifdef CONFIG_TAXONOMY
3999 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
4000 #endif /* CONFIG_TAXONOMY */
4002 sta
->pending_wds_enable
= 0;
4005 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4006 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4007 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4008 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
4011 #endif /* CONFIG_FILS */
4015 os_free(radius_cui
);
4016 hostapd_free_psk_list(psk
);
4019 * In case of a successful response, add the station to the driver.
4020 * Otherwise, the kernel may ignore Data frames before we process the
4021 * ACK frame (TX status). In case of a failure, this station will be
4024 * Note that this is not compliant with the IEEE 802.11 standard that
4025 * states that a non-AP station should transition into the
4026 * authenticated/associated state only after the station acknowledges
4027 * the (Re)Association Response frame. However, still do this as:
4029 * 1. In case the station does not acknowledge the (Re)Association
4030 * Response frame, it will be removed.
4031 * 2. Data frames will be dropped in the kernel until the station is
4032 * set into authorized state, and there are no significant known
4033 * issues with processing other non-Data Class 3 frames during this
4036 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&&
4037 add_associated_sta(hapd
, sta
, reassoc
))
4038 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4041 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
&&
4042 eloop_is_timeout_registered(fils_hlp_timeout
, hapd
, sta
) &&
4043 sta
->fils_pending_assoc_req
) {
4044 /* Do not reschedule fils_hlp_timeout in case the station
4045 * retransmits (Re)Association Request frame while waiting for
4046 * the previously started FILS HLP wait, so that the timeout can
4047 * be determined from the first pending attempt. */
4048 wpa_printf(MSG_DEBUG
,
4049 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4050 MACSTR
, MAC2STR(sta
->addr
));
4055 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4056 os_free(sta
->fils_pending_assoc_req
);
4057 sta
->fils_pending_assoc_req
= NULL
;
4058 sta
->fils_pending_assoc_req_len
= 0;
4059 wpabuf_free(sta
->fils_hlp_resp
);
4060 sta
->fils_hlp_resp
= NULL
;
4062 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
4063 sta
->fils_pending_assoc_req
= tmp
;
4064 sta
->fils_pending_assoc_req_len
= left
;
4065 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
4066 sta
->fils_drv_assoc_finish
= 0;
4067 wpa_printf(MSG_DEBUG
,
4068 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4069 MACSTR
, MAC2STR(sta
->addr
));
4070 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4071 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
4072 fils_hlp_timeout
, hapd
, sta
);
4075 #endif /* CONFIG_FILS */
4077 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
4082 * Remove the station in case tranmission of a success response fails
4083 * (the STA was added associated to the driver) or if the station was
4084 * previously added unassociated.
4086 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
4087 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
4088 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4089 sta
->added_unassoc
= 0;
4094 static void handle_disassoc(struct hostapd_data
*hapd
,
4095 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4097 struct sta_info
*sta
;
4099 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
4100 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
4101 (unsigned long) len
);
4105 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
4107 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4109 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4111 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
4116 ap_sta_set_authorized(hapd
, sta
, 0);
4117 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4118 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
4119 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
4120 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4121 HOSTAPD_LEVEL_INFO
, "disassociated");
4122 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4123 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4124 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4126 accounting_sta_stop(hapd
, sta
);
4127 ieee802_1x_free_station(hapd
, sta
);
4129 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
4130 ap_sta_ip6addr_del(hapd
, sta
);
4131 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4132 sta
->added_unassoc
= 0;
4134 if (sta
->timeout_next
== STA_NULLFUNC
||
4135 sta
->timeout_next
== STA_DISASSOC
) {
4136 sta
->timeout_next
= STA_DEAUTH
;
4137 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
4138 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
4142 mlme_disassociate_indication(
4143 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4145 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4146 * disassociation. */
4147 if (hapd
->iface
->current_mode
&&
4148 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
4149 sta
->flags
&= ~WLAN_STA_AUTH
;
4150 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4151 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4152 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4153 ap_free_sta(hapd
, sta
);
4158 static void handle_deauth(struct hostapd_data
*hapd
,
4159 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4161 struct sta_info
*sta
;
4163 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
4164 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
4165 "payload (len=%lu)", (unsigned long) len
);
4169 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
4171 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
4173 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4175 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
4176 "to deauthenticate, but it is not authenticated",
4181 ap_sta_set_authorized(hapd
, sta
, 0);
4182 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4183 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
4184 WLAN_STA_ASSOC_REQ_OK
);
4185 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4186 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4187 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4188 mlme_deauthenticate_indication(
4189 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
4190 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4191 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4192 ap_free_sta(hapd
, sta
);
4196 static void handle_beacon(struct hostapd_data
*hapd
,
4197 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4198 struct hostapd_frame_info
*fi
)
4200 struct ieee802_11_elems elems
;
4202 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
4203 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
4204 (unsigned long) len
);
4208 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
4209 len
- (IEEE80211_HDRLEN
+
4210 sizeof(mgmt
->u
.beacon
)), &elems
,
4213 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
4217 #ifdef CONFIG_IEEE80211W
4218 static int robust_action_frame(u8 category
)
4220 return category
!= WLAN_ACTION_PUBLIC
&&
4221 category
!= WLAN_ACTION_HT
;
4223 #endif /* CONFIG_IEEE80211W */
4226 static int handle_action(struct hostapd_data
*hapd
,
4227 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4230 struct sta_info
*sta
;
4231 u8
*action __maybe_unused
;
4233 if (len
< IEEE80211_HDRLEN
+ 2 + 1) {
4234 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4235 HOSTAPD_LEVEL_DEBUG
,
4236 "handle_action - too short payload (len=%lu)",
4237 (unsigned long) len
);
4241 action
= (u8
*) &mgmt
->u
.action
.u
;
4242 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
4243 " da " MACSTR
" len %d freq %u",
4244 mgmt
->u
.action
.category
, *action
,
4245 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) len
, freq
);
4247 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4249 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
4250 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
4251 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
4252 "frame (category=%u) from unassociated STA " MACSTR
,
4253 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
4257 #ifdef CONFIG_IEEE80211W
4258 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
4259 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
4260 robust_action_frame(mgmt
->u
.action
.category
)) {
4261 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4262 HOSTAPD_LEVEL_DEBUG
,
4263 "Dropped unprotected Robust Action frame from "
4267 #endif /* CONFIG_IEEE80211W */
4270 u16 fc
= le_to_host16(mgmt
->frame_control
);
4271 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4273 if ((fc
& WLAN_FC_RETRY
) &&
4274 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4275 sta
->last_seq_ctrl
== seq_ctrl
&&
4276 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
4277 hostapd_logger(hapd
, sta
->addr
,
4278 HOSTAPD_MODULE_IEEE80211
,
4279 HOSTAPD_LEVEL_DEBUG
,
4280 "Drop repeated action frame seq_ctrl=0x%x",
4285 sta
->last_seq_ctrl
= seq_ctrl
;
4286 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
4289 switch (mgmt
->u
.action
.category
) {
4290 #ifdef CONFIG_IEEE80211R_AP
4291 case WLAN_ACTION_FT
:
4293 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
4294 len
- IEEE80211_HDRLEN
))
4297 #endif /* CONFIG_IEEE80211R_AP */
4298 case WLAN_ACTION_WMM
:
4299 hostapd_wmm_action(hapd
, mgmt
, len
);
4301 #ifdef CONFIG_IEEE80211W
4302 case WLAN_ACTION_SA_QUERY
:
4303 ieee802_11_sa_query_action(hapd
, mgmt
, len
);
4305 #endif /* CONFIG_IEEE80211W */
4306 #ifdef CONFIG_WNM_AP
4307 case WLAN_ACTION_WNM
:
4308 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
4310 #endif /* CONFIG_WNM_AP */
4312 case WLAN_ACTION_FST
:
4313 if (hapd
->iface
->fst
)
4314 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
4316 wpa_printf(MSG_DEBUG
,
4317 "FST: Ignore FST Action frame - no FST attached");
4319 #endif /* CONFIG_FST */
4320 case WLAN_ACTION_PUBLIC
:
4321 case WLAN_ACTION_PROTECTED_DUAL
:
4322 #ifdef CONFIG_IEEE80211N
4323 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4324 mgmt
->u
.action
.u
.public_action
.action
==
4325 WLAN_PA_20_40_BSS_COEX
) {
4326 hostapd_2040_coex_action(hapd
, mgmt
, len
);
4329 #endif /* CONFIG_IEEE80211N */
4331 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4332 mgmt
->u
.action
.u
.vs_public_action
.action
==
4333 WLAN_PA_VENDOR_SPECIFIC
&&
4334 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4336 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4338 const u8
*pos
, *end
;
4340 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
4341 end
= ((const u8
*) mgmt
) + len
;
4342 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
4346 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4347 (mgmt
->u
.action
.u
.public_action
.action
==
4348 WLAN_PA_GAS_INITIAL_RESP
||
4349 mgmt
->u
.action
.u
.public_action
.action
==
4350 WLAN_PA_GAS_COMEBACK_RESP
)) {
4351 const u8
*pos
, *end
;
4353 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
4354 end
= ((const u8
*) mgmt
) + len
;
4355 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
4356 mgmt
->u
.action
.category
,
4357 pos
, end
- pos
, hapd
->iface
->freq
);
4360 #endif /* CONFIG_DPP */
4361 if (hapd
->public_action_cb
) {
4362 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
4366 if (hapd
->public_action_cb2
) {
4367 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
4371 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
4374 case WLAN_ACTION_VENDOR_SPECIFIC
:
4375 if (hapd
->vendor_action_cb
) {
4376 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
4378 hapd
->iface
->freq
) == 0)
4382 case WLAN_ACTION_RADIO_MEASUREMENT
:
4383 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
4387 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4388 HOSTAPD_LEVEL_DEBUG
,
4389 "handle_action - unknown action category %d or invalid "
4391 mgmt
->u
.action
.category
);
4392 if (!is_multicast_ether_addr(mgmt
->da
) &&
4393 !(mgmt
->u
.action
.category
& 0x80) &&
4394 !is_multicast_ether_addr(mgmt
->sa
)) {
4395 struct ieee80211_mgmt
*resp
;
4398 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4399 * Return the Action frame to the source without change
4400 * except that MSB of the Category set to 1.
4402 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
4403 "frame back to sender");
4404 resp
= os_memdup(mgmt
, len
);
4407 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
4408 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
4409 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
4410 resp
->u
.action
.category
|= 0x80;
4412 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
4413 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
4424 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4425 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4427 * @buf: management frame data (starting from IEEE 802.11 header)
4428 * @len: length of frame data in octets
4429 * @fi: meta data about received frame (signal level, etc.)
4431 * Process all incoming IEEE 802.11 management frames. This will be called for
4432 * each frame received from the kernel driver through wlan#ap interface. In
4433 * addition, it can be called to re-inserted pending frames (e.g., when using
4434 * external RADIUS server as an MAC ACL).
4436 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4437 struct hostapd_frame_info
*fi
)
4439 struct ieee80211_mgmt
*mgmt
;
4443 int ssi_signal
= fi
? fi
->ssi_signal
: 0;
4451 freq
= hapd
->iface
->freq
;
4453 mgmt
= (struct ieee80211_mgmt
*) buf
;
4454 fc
= le_to_host16(mgmt
->frame_control
);
4455 stype
= WLAN_FC_GET_STYPE(fc
);
4457 if (stype
== WLAN_FC_STYPE_BEACON
) {
4458 handle_beacon(hapd
, mgmt
, len
, fi
);
4462 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
4464 /* Invitation responses can be sent with the peer MAC as BSSID */
4465 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
4466 stype
== WLAN_FC_STYPE_ACTION
) &&
4467 #endif /* CONFIG_P2P */
4469 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
4470 #endif /* CONFIG_MESH */
4471 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4472 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
4473 MAC2STR(mgmt
->bssid
));
4478 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
4479 handle_probe_req(hapd
, mgmt
, len
, ssi_signal
);
4483 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
4484 stype
!= WLAN_FC_STYPE_ACTION
) &&
4485 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4486 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4487 HOSTAPD_LEVEL_DEBUG
,
4488 "MGMT: DA=" MACSTR
" not our address",
4493 if (hapd
->iconf
->track_sta_max_num
)
4494 sta_track_add(hapd
->iface
, mgmt
->sa
, ssi_signal
);
4497 case WLAN_FC_STYPE_AUTH
:
4498 wpa_printf(MSG_DEBUG
, "mgmt::auth");
4499 handle_auth(hapd
, mgmt
, len
, ssi_signal
, 0);
4502 case WLAN_FC_STYPE_ASSOC_REQ
:
4503 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
4504 handle_assoc(hapd
, mgmt
, len
, 0, ssi_signal
);
4507 case WLAN_FC_STYPE_REASSOC_REQ
:
4508 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
4509 handle_assoc(hapd
, mgmt
, len
, 1, ssi_signal
);
4512 case WLAN_FC_STYPE_DISASSOC
:
4513 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
4514 handle_disassoc(hapd
, mgmt
, len
);
4517 case WLAN_FC_STYPE_DEAUTH
:
4518 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
4519 handle_deauth(hapd
, mgmt
, len
);
4522 case WLAN_FC_STYPE_ACTION
:
4523 wpa_printf(MSG_DEBUG
, "mgmt::action");
4524 ret
= handle_action(hapd
, mgmt
, len
, freq
);
4527 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4528 HOSTAPD_LEVEL_DEBUG
,
4529 "unknown mgmt frame subtype %d", stype
);
4537 static void handle_auth_cb(struct hostapd_data
*hapd
,
4538 const struct ieee80211_mgmt
*mgmt
,
4541 u16 auth_alg
, auth_transaction
, status_code
;
4542 struct sta_info
*sta
;
4544 sta
= ap_get_sta(hapd
, mgmt
->da
);
4546 wpa_printf(MSG_DEBUG
, "handle_auth_cb: STA " MACSTR
4552 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4553 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4554 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
4557 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4558 HOSTAPD_LEVEL_NOTICE
,
4559 "did not acknowledge authentication response");
4563 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
4564 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
4565 (unsigned long) len
);
4569 if (status_code
== WLAN_STATUS_SUCCESS
&&
4570 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
4571 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
4572 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4573 HOSTAPD_LEVEL_INFO
, "authenticated");
4574 sta
->flags
|= WLAN_STA_AUTH
;
4575 if (sta
->added_unassoc
)
4576 hostapd_set_sta_flags(hapd
, sta
);
4581 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
4582 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4583 sta
->added_unassoc
= 0;
4588 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
4589 struct sta_info
*sta
,
4593 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
4595 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
4598 for (i
= 0; i
< 4; i
++) {
4599 if (ssid
->wep
.key
[i
] &&
4600 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
4601 i
== ssid
->wep
.idx
, NULL
, 0,
4602 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
4603 wpa_printf(MSG_WARNING
,
4604 "Could not set WEP keys for WDS interface; %s",
4612 static void handle_assoc_cb(struct hostapd_data
*hapd
,
4613 const struct ieee80211_mgmt
*mgmt
,
4614 size_t len
, int reassoc
, int ok
)
4617 struct sta_info
*sta
;
4620 sta
= ap_get_sta(hapd
, mgmt
->da
);
4622 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4627 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4628 sizeof(mgmt
->u
.assoc_resp
))) {
4629 wpa_printf(MSG_INFO
,
4630 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4631 reassoc
, (unsigned long) len
);
4632 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4637 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4639 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4642 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4643 HOSTAPD_LEVEL_DEBUG
,
4644 "did not acknowledge association response");
4645 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4646 /* The STA is added only in case of SUCCESS */
4647 if (status
== WLAN_STATUS_SUCCESS
)
4648 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4653 if (status
!= WLAN_STATUS_SUCCESS
)
4656 /* Stop previous accounting session, if one is started, and allocate
4657 * new session id for the new session. */
4658 accounting_sta_stop(hapd
, sta
);
4660 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4662 "associated (aid %d)",
4665 if (sta
->flags
& WLAN_STA_ASSOC
)
4667 sta
->flags
|= WLAN_STA_ASSOC
;
4668 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4669 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4670 !hapd
->conf
->osen
) ||
4671 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4672 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4673 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4674 sta
->auth_alg
== WLAN_AUTH_FT
) {
4676 * Open, static WEP, FT protocol, or FILS; no separate
4677 * authorization step.
4679 ap_sta_set_authorized(hapd
, sta
, 1);
4683 mlme_reassociate_indication(hapd
, sta
);
4685 mlme_associate_indication(hapd
, sta
);
4687 #ifdef CONFIG_IEEE80211W
4688 sta
->sa_query_timed_out
= 0;
4689 #endif /* CONFIG_IEEE80211W */
4691 if (sta
->eapol_sm
== NULL
) {
4693 * This STA does not use RADIUS server for EAP authentication,
4694 * so bind it to the selected VLAN interface now, since the
4695 * interface selection is not going to change anymore.
4697 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4699 } else if (sta
->vlan_id
) {
4700 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4701 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4705 hostapd_set_sta_flags(hapd
, sta
);
4707 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4708 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4709 MACSTR
" based on pending request",
4710 MAC2STR(sta
->addr
));
4711 sta
->pending_wds_enable
= 0;
4712 sta
->flags
|= WLAN_STA_WDS
;
4715 if (sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_MULTI_AP
)) {
4717 char ifname_wds
[IFNAMSIZ
+ 1];
4719 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4721 MAC2STR(sta
->addr
), sta
->aid
);
4722 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
4725 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
4728 if (sta
->auth_alg
== WLAN_AUTH_FT
)
4729 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
4731 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
4732 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
4733 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
4736 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4737 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4738 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
4739 fils_set_tk(sta
->wpa_sm
) < 0) {
4740 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
4741 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
4742 WLAN_REASON_UNSPECIFIED
);
4745 #endif /* CONFIG_FILS */
4747 if (sta
->pending_eapol_rx
) {
4748 struct os_reltime now
, age
;
4750 os_get_reltime(&now
);
4751 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
4752 if (age
.sec
== 0 && age
.usec
< 200000) {
4753 wpa_printf(MSG_DEBUG
,
4754 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
4755 MAC2STR(sta
->addr
));
4758 wpabuf_head(sta
->pending_eapol_rx
->buf
),
4759 wpabuf_len(sta
->pending_eapol_rx
->buf
));
4761 wpabuf_free(sta
->pending_eapol_rx
->buf
);
4762 os_free(sta
->pending_eapol_rx
);
4763 sta
->pending_eapol_rx
= NULL
;
4768 static void handle_deauth_cb(struct hostapd_data
*hapd
,
4769 const struct ieee80211_mgmt
*mgmt
,
4772 struct sta_info
*sta
;
4773 if (is_multicast_ether_addr(mgmt
->da
))
4775 sta
= ap_get_sta(hapd
, mgmt
->da
);
4777 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
4778 " not found", MAC2STR(mgmt
->da
));
4782 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
4783 MAC2STR(sta
->addr
));
4785 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4786 "deauth", MAC2STR(sta
->addr
));
4788 ap_sta_deauth_cb(hapd
, sta
);
4792 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
4793 const struct ieee80211_mgmt
*mgmt
,
4796 struct sta_info
*sta
;
4797 if (is_multicast_ether_addr(mgmt
->da
))
4799 sta
= ap_get_sta(hapd
, mgmt
->da
);
4801 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
4802 " not found", MAC2STR(mgmt
->da
));
4806 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
4807 MAC2STR(sta
->addr
));
4809 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4810 "disassoc", MAC2STR(sta
->addr
));
4812 ap_sta_disassoc_cb(hapd
, sta
);
4816 static void handle_action_cb(struct hostapd_data
*hapd
,
4817 const struct ieee80211_mgmt
*mgmt
,
4820 struct sta_info
*sta
;
4821 const struct rrm_measurement_report_element
*report
;
4823 if (is_multicast_ether_addr(mgmt
->da
))
4826 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4827 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4828 mgmt
->u
.action
.u
.vs_public_action
.action
==
4829 WLAN_PA_VENDOR_SPECIFIC
&&
4830 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4832 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4834 const u8
*pos
, *end
;
4836 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
4837 end
= ((const u8
*) mgmt
) + len
;
4838 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
4841 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4842 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4843 (mgmt
->u
.action
.u
.public_action
.action
==
4844 WLAN_PA_GAS_INITIAL_REQ
||
4845 mgmt
->u
.action
.u
.public_action
.action
==
4846 WLAN_PA_GAS_COMEBACK_REQ
)) {
4847 const u8
*pos
, *end
;
4849 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
4850 end
= ((const u8
*) mgmt
) + len
;
4851 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
4854 #endif /* CONFIG_DPP */
4855 sta
= ap_get_sta(hapd
, mgmt
->da
);
4857 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
4858 " not found", MAC2STR(mgmt
->da
));
4862 if (len
< 24 + 5 + sizeof(*report
))
4864 report
= (const struct rrm_measurement_report_element
*)
4865 &mgmt
->u
.action
.u
.rrm
.variable
[2];
4866 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4867 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
4868 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
4870 report
->type
== MEASURE_TYPE_BEACON
)
4871 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
4876 * ieee802_11_mgmt_cb - Process management frame TX status callback
4877 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4879 * @buf: management frame data (starting from IEEE 802.11 header)
4880 * @len: length of frame data in octets
4881 * @stype: management frame subtype from frame control field
4882 * @ok: Whether the frame was ACK'ed
4884 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4887 const struct ieee80211_mgmt
*mgmt
;
4888 mgmt
= (const struct ieee80211_mgmt
*) buf
;
4890 #ifdef CONFIG_TESTING_OPTIONS
4891 if (hapd
->ext_mgmt_frame_handling
) {
4892 size_t hex_len
= 2 * len
+ 1;
4893 char *hex
= os_malloc(hex_len
);
4896 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
4897 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
4898 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4904 #endif /* CONFIG_TESTING_OPTIONS */
4907 case WLAN_FC_STYPE_AUTH
:
4908 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
4909 handle_auth_cb(hapd
, mgmt
, len
, ok
);
4911 case WLAN_FC_STYPE_ASSOC_RESP
:
4912 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
4913 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
4915 case WLAN_FC_STYPE_REASSOC_RESP
:
4916 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
4917 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
4919 case WLAN_FC_STYPE_PROBE_RESP
:
4920 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
4922 case WLAN_FC_STYPE_DEAUTH
:
4923 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
4924 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
4926 case WLAN_FC_STYPE_DISASSOC
:
4927 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
4928 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
4930 case WLAN_FC_STYPE_ACTION
:
4931 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
4932 handle_action_cb(hapd
, mgmt
, len
, ok
);
4935 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
4941 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
4948 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
4949 char *buf
, size_t buflen
)
4956 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
4957 const u8
*buf
, size_t len
, int ack
)
4959 struct sta_info
*sta
;
4960 struct hostapd_iface
*iface
= hapd
->iface
;
4962 sta
= ap_get_sta(hapd
, addr
);
4963 if (sta
== NULL
&& iface
->num_bss
> 1) {
4965 for (j
= 0; j
< iface
->num_bss
; j
++) {
4966 hapd
= iface
->bss
[j
];
4967 sta
= ap_get_sta(hapd
, addr
);
4972 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
4974 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
4975 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
4976 "activity poll", MAC2STR(sta
->addr
),
4977 ack
? "ACKed" : "did not ACK");
4979 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4982 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
4986 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
4987 const u8
*data
, size_t len
, int ack
)
4989 struct sta_info
*sta
;
4990 struct hostapd_iface
*iface
= hapd
->iface
;
4992 sta
= ap_get_sta(hapd
, dst
);
4993 if (sta
== NULL
&& iface
->num_bss
> 1) {
4995 for (j
= 0; j
< iface
->num_bss
; j
++) {
4996 hapd
= iface
->bss
[j
];
4997 sta
= ap_get_sta(hapd
, dst
);
5002 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
5003 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
5004 MACSTR
" that is not currently associated",
5009 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
5013 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
5015 struct sta_info
*sta
;
5016 struct hostapd_iface
*iface
= hapd
->iface
;
5018 sta
= ap_get_sta(hapd
, addr
);
5019 if (sta
== NULL
&& iface
->num_bss
> 1) {
5021 for (j
= 0; j
< iface
->num_bss
; j
++) {
5022 hapd
= iface
->bss
[j
];
5023 sta
= ap_get_sta(hapd
, addr
);
5030 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
5031 MAC2STR(sta
->addr
));
5032 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
5035 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
5036 "activity poll", MAC2STR(sta
->addr
));
5037 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5041 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
5044 struct sta_info
*sta
;
5046 sta
= ap_get_sta(hapd
, src
);
5048 ((sta
->flags
& WLAN_STA_ASSOC
) ||
5049 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
5050 if (!hapd
->conf
->wds_sta
)
5053 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
5054 WLAN_STA_ASSOC_REQ_OK
) {
5055 wpa_printf(MSG_DEBUG
,
5056 "Postpone 4-address WDS mode enabling for STA "
5057 MACSTR
" since TX status for AssocResp is not yet known",
5058 MAC2STR(sta
->addr
));
5059 sta
->pending_wds_enable
= 1;
5063 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
5065 char ifname_wds
[IFNAMSIZ
+ 1];
5067 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
5068 "STA " MACSTR
" (aid %u)",
5069 MAC2STR(sta
->addr
), sta
->aid
);
5070 sta
->flags
|= WLAN_STA_WDS
;
5071 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
5072 sta
->addr
, sta
->aid
, 1);
5074 hostapd_set_wds_encryption(hapd
, sta
,
5080 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
5081 MACSTR
, MAC2STR(src
));
5082 if (is_multicast_ether_addr(src
)) {
5083 /* Broadcast bit set in SA?! Ignore the frame silently. */
5087 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
5088 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
5089 "already been sent, but no TX status yet known - "
5090 "ignore Class 3 frame issue with " MACSTR
,
5095 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
5096 hostapd_drv_sta_disassoc(
5098 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5100 hostapd_drv_sta_deauth(
5102 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5106 #endif /* CONFIG_NATIVE_WINDOWS */