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 "common/wpa_common.h"
27 #include "radius/radius.h"
28 #include "radius/radius_client.h"
34 #include "ieee802_11_auth.h"
36 #include "ieee802_1x.h"
38 #include "pmksa_cache_auth.h"
41 #include "accounting.h"
42 #include "ap_config.h"
44 #include "p2p_hostapd.h"
45 #include "ap_drv_ops.h"
47 #include "hw_features.h"
48 #include "ieee802_11.h"
54 #include "dpp_hostapd.h"
55 #include "gas_query_ap.h"
59 static struct wpabuf
*
60 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
61 struct sta_info
*sta
, u16
*resp
,
62 struct rsn_pmksa_cache_entry
*pmksa
,
63 struct wpabuf
*erp_resp
,
64 const u8
*msk
, size_t msk_len
,
66 #endif /* CONFIG_FILS */
67 static void handle_auth(struct hostapd_data
*hapd
,
68 const struct ieee80211_mgmt
*mgmt
, size_t len
,
69 int rssi
, int from_queue
);
72 u8
* hostapd_eid_multi_ap(struct hostapd_data
*hapd
, u8
*eid
)
76 if (!hapd
->conf
->multi_ap
)
78 if (hapd
->conf
->multi_ap
& BACKHAUL_BSS
)
79 multi_ap_val
|= MULTI_AP_BACKHAUL_BSS
;
80 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
81 multi_ap_val
|= MULTI_AP_FRONTHAUL_BSS
;
83 return eid
+ add_multi_ap_ie(eid
, 9, multi_ap_val
);
87 u8
* hostapd_eid_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
92 if (hapd
->iface
->current_rates
== NULL
)
95 *pos
++ = WLAN_EID_SUPP_RATES
;
96 num
= hapd
->iface
->num_rates
;
97 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
99 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
101 if (hapd
->conf
->sae_pwe
== 1)
104 /* rest of the rates are encoded in Extended supported
110 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
;
113 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
114 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
119 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&& count
< 8) {
121 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
124 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&& count
< 8) {
126 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
129 if (hapd
->conf
->sae_pwe
== 1 && count
< 8) {
131 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY
;
138 u8
* hostapd_eid_ext_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
143 if (hapd
->iface
->current_rates
== NULL
)
146 num
= hapd
->iface
->num_rates
;
147 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
149 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
151 if (hapd
->conf
->sae_pwe
== 1)
157 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
159 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
+ 8;
163 continue; /* already in SuppRates IE */
164 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
165 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
170 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
) {
173 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
176 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
) {
179 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
182 if (hapd
->conf
->sae_pwe
== 1) {
185 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY
;
192 u16
hostapd_own_capab_info(struct hostapd_data
*hapd
)
194 int capab
= WLAN_CAPABILITY_ESS
;
199 /* Check if any of configured channels require DFS */
200 dfs
= hostapd_is_dfs_required(hapd
->iface
);
202 wpa_printf(MSG_WARNING
, "Failed to check if DFS is required; ret=%d",
207 if (hapd
->iface
->num_sta_no_short_preamble
== 0 &&
208 hapd
->iconf
->preamble
== SHORT_PREAMBLE
)
209 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
211 privacy
= hapd
->conf
->ssid
.wep
.keys_set
;
213 if (hapd
->conf
->ieee802_1x
&&
214 (hapd
->conf
->default_wep_key_len
||
215 hapd
->conf
->individual_wep_key_len
))
222 if (hapd
->conf
->osen
)
224 #endif /* CONFIG_HS20 */
227 capab
|= WLAN_CAPABILITY_PRIVACY
;
229 if (hapd
->iface
->current_mode
&&
230 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
&&
231 hapd
->iface
->num_sta_no_short_slot_time
== 0)
232 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
235 * Currently, Spectrum Management capability bit is set when directly
236 * requested in configuration by spectrum_mgmt_required or when AP is
237 * running on DFS channel.
238 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
240 if (hapd
->iface
->current_mode
&&
241 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211A
&&
242 (hapd
->iconf
->spectrum_mgmt_required
|| dfs
))
243 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
245 for (i
= 0; i
< RRM_CAPABILITIES_IE_LEN
; i
++) {
246 if (hapd
->conf
->radio_measurements
[i
]) {
247 capab
|= IEEE80211_CAP_RRM
;
256 #ifndef CONFIG_NO_RC4
257 static u16
auth_shared_key(struct hostapd_data
*hapd
, struct sta_info
*sta
,
258 u16 auth_transaction
, const u8
*challenge
,
261 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
263 "authentication (shared key, transaction %d)",
266 if (auth_transaction
== 1) {
267 if (!sta
->challenge
) {
268 /* Generate a pseudo-random challenge */
271 sta
->challenge
= os_zalloc(WLAN_AUTH_CHALLENGE_LEN
);
272 if (sta
->challenge
== NULL
)
273 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
275 if (os_get_random(key
, sizeof(key
)) < 0) {
276 os_free(sta
->challenge
);
277 sta
->challenge
= NULL
;
278 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
281 rc4_skip(key
, sizeof(key
), 0,
282 sta
->challenge
, WLAN_AUTH_CHALLENGE_LEN
);
287 if (auth_transaction
!= 3)
288 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
291 if (!iswep
|| !sta
->challenge
|| !challenge
||
292 os_memcmp_const(sta
->challenge
, challenge
,
293 WLAN_AUTH_CHALLENGE_LEN
)) {
294 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
296 "shared key authentication - invalid "
297 "challenge-response");
298 return WLAN_STATUS_CHALLENGE_FAIL
;
301 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
303 "authentication OK (shared key)");
304 sta
->flags
|= WLAN_STA_AUTH
;
305 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
306 os_free(sta
->challenge
);
307 sta
->challenge
= NULL
;
311 #endif /* CONFIG_NO_RC4 */
314 static int send_auth_reply(struct hostapd_data
*hapd
,
315 const u8
*dst
, const u8
*bssid
,
316 u16 auth_alg
, u16 auth_transaction
, u16 resp
,
317 const u8
*ies
, size_t ies_len
, const char *dbg
)
319 struct ieee80211_mgmt
*reply
;
322 int reply_res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
324 rlen
= IEEE80211_HDRLEN
+ sizeof(reply
->u
.auth
) + ies_len
;
325 buf
= os_zalloc(rlen
);
329 reply
= (struct ieee80211_mgmt
*) buf
;
330 reply
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
332 os_memcpy(reply
->da
, dst
, ETH_ALEN
);
333 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
334 os_memcpy(reply
->bssid
, bssid
, ETH_ALEN
);
336 reply
->u
.auth
.auth_alg
= host_to_le16(auth_alg
);
337 reply
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
338 reply
->u
.auth
.status_code
= host_to_le16(resp
);
341 os_memcpy(reply
->u
.auth
.variable
, ies
, ies_len
);
343 wpa_printf(MSG_DEBUG
, "authentication reply: STA=" MACSTR
344 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
345 MAC2STR(dst
), auth_alg
, auth_transaction
,
346 resp
, (unsigned long) ies_len
, dbg
);
347 if (hostapd_drv_send_mlme(hapd
, reply
, rlen
, 0) < 0)
348 wpa_printf(MSG_INFO
, "send_auth_reply: send failed");
350 reply_res
= WLAN_STATUS_SUCCESS
;
358 #ifdef CONFIG_IEEE80211R_AP
359 static void handle_auth_ft_finish(void *ctx
, const u8
*dst
, const u8
*bssid
,
360 u16 auth_transaction
, u16 status
,
361 const u8
*ies
, size_t ies_len
)
363 struct hostapd_data
*hapd
= ctx
;
364 struct sta_info
*sta
;
367 reply_res
= send_auth_reply(hapd
, dst
, bssid
, WLAN_AUTH_FT
,
368 auth_transaction
, status
, ies
, ies_len
,
371 sta
= ap_get_sta(hapd
, dst
);
375 if (sta
->added_unassoc
&& (reply_res
!= WLAN_STATUS_SUCCESS
||
376 status
!= WLAN_STATUS_SUCCESS
)) {
377 hostapd_drv_sta_remove(hapd
, sta
->addr
);
378 sta
->added_unassoc
= 0;
382 if (status
!= WLAN_STATUS_SUCCESS
)
385 hostapd_logger(hapd
, dst
, HOSTAPD_MODULE_IEEE80211
,
386 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FT)");
387 sta
->flags
|= WLAN_STA_AUTH
;
388 mlme_authenticate_indication(hapd
, sta
);
390 #endif /* CONFIG_IEEE80211R_AP */
395 static void sae_set_state(struct sta_info
*sta
, enum sae_state state
,
398 wpa_printf(MSG_DEBUG
, "SAE: State %s -> %s for peer " MACSTR
" (%s)",
399 sae_state_txt(sta
->sae
->state
), sae_state_txt(state
),
400 MAC2STR(sta
->addr
), reason
);
401 sta
->sae
->state
= state
;
405 static struct wpabuf
* auth_build_sae_commit(struct hostapd_data
*hapd
,
406 struct sta_info
*sta
, int update
)
409 const char *password
= NULL
;
410 struct sae_password_entry
*pw
;
411 const char *rx_id
= NULL
;
413 struct sae_pt
*pt
= NULL
;
416 rx_id
= sta
->sae
->tmp
->pw_id
;
417 use_pt
= sta
->sae
->tmp
->h2e
;
420 for (pw
= hapd
->conf
->sae_passwords
; pw
; pw
= pw
->next
) {
421 if (!is_broadcast_ether_addr(pw
->peer_addr
) &&
422 os_memcmp(pw
->peer_addr
, sta
->addr
, ETH_ALEN
) != 0)
424 if ((rx_id
&& !pw
->identifier
) || (!rx_id
&& pw
->identifier
))
426 if (rx_id
&& pw
->identifier
&&
427 os_strcmp(rx_id
, pw
->identifier
) != 0)
429 password
= pw
->password
;
434 password
= hapd
->conf
->ssid
.wpa_passphrase
;
435 pt
= hapd
->conf
->ssid
.pt
;
437 if (!password
|| (use_pt
&& !pt
)) {
438 wpa_printf(MSG_DEBUG
, "SAE: No password available");
442 if (update
&& use_pt
&&
443 sae_prepare_commit_pt(sta
->sae
, pt
, hapd
->own_addr
, sta
->addr
,
447 if (update
&& !use_pt
&&
448 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
449 (u8
*) password
, os_strlen(password
), rx_id
,
451 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
455 if (pw
&& pw
->vlan_id
) {
456 if (!sta
->sae
->tmp
) {
458 "SAE: No temporary data allocated - cannot store VLAN ID");
461 sta
->sae
->tmp
->vlan_id
= pw
->vlan_id
;
464 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
+
465 (rx_id
? 3 + os_strlen(rx_id
) : 0));
468 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
469 sta
->sae
->tmp
->anti_clogging_token
: NULL
, rx_id
);
475 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
476 struct sta_info
*sta
)
480 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
484 sae_write_confirm(sta
->sae
, buf
);
490 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
491 struct sta_info
*sta
,
492 const u8
*bssid
, int update
)
498 data
= auth_build_sae_commit(hapd
, sta
, update
);
499 if (!data
&& sta
->sae
->tmp
&& sta
->sae
->tmp
->pw_id
)
500 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
;
502 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
504 status
= (sta
->sae
->tmp
&& sta
->sae
->tmp
->h2e
) ?
505 WLAN_STATUS_SAE_HASH_TO_ELEMENT
: WLAN_STATUS_SUCCESS
;
506 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
507 status
, wpabuf_head(data
),
508 wpabuf_len(data
), "sae-send-commit");
516 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
517 struct sta_info
*sta
,
523 data
= auth_build_sae_confirm(hapd
, sta
);
525 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
527 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
528 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
529 wpabuf_len(data
), "sae-send-confirm");
537 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
539 struct sta_info
*sta
;
540 unsigned int open
= 0;
542 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
545 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
548 if (sta
->sae
->state
!= SAE_COMMITTED
&&
549 sta
->sae
->state
!= SAE_CONFIRMED
)
552 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
556 /* In addition to already existing open SAE sessions, check whether
557 * there are enough pending commit messages in the processing queue to
558 * potentially result in too many open sessions. */
559 if (open
+ dl_list_len(&hapd
->sae_commit_queue
) >=
560 hapd
->conf
->sae_anti_clogging_threshold
)
567 static u8
sae_token_hash(struct hostapd_data
*hapd
, const u8
*addr
)
569 u8 hash
[SHA256_MAC_LEN
];
571 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
572 addr
, ETH_ALEN
, hash
);
577 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
578 const u8
*token
, size_t token_len
)
580 u8 mac
[SHA256_MAC_LEN
];
586 if (token_len
!= SHA256_MAC_LEN
)
588 idx
= sae_token_hash(hapd
, addr
);
589 token_idx
= hapd
->sae_pending_token_idx
[idx
];
590 if (token_idx
== 0 || token_idx
!= WPA_GET_BE16(token
)) {
591 wpa_printf(MSG_DEBUG
, "SAE: Invalid anti-clogging token from "
592 MACSTR
" - token_idx 0x%04x, expected 0x%04x",
593 MAC2STR(addr
), WPA_GET_BE16(token
), token_idx
);
601 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
602 2, addrs
, len
, mac
) < 0 ||
603 os_memcmp_const(token
+ 2, &mac
[2], SHA256_MAC_LEN
- 2) != 0)
606 hapd
->sae_pending_token_idx
[idx
] = 0; /* invalidate used token */
612 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
613 int group
, const u8
*addr
)
617 struct os_reltime now
;
624 os_get_reltime(&now
);
625 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
626 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60) ||
627 hapd
->sae_token_idx
== 0xffff) {
628 if (random_get_bytes(hapd
->sae_token_key
,
629 sizeof(hapd
->sae_token_key
)) < 0)
631 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
632 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
633 hapd
->last_sae_token_key_update
= now
;
634 hapd
->sae_token_idx
= 0;
635 os_memset(hapd
->sae_pending_token_idx
, 0,
636 sizeof(hapd
->sae_pending_token_idx
));
639 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
643 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
645 p_idx
= sae_token_hash(hapd
, addr
);
646 token_idx
= hapd
->sae_pending_token_idx
[p_idx
];
648 hapd
->sae_token_idx
++;
649 token_idx
= hapd
->sae_token_idx
;
650 hapd
->sae_pending_token_idx
[p_idx
] = token_idx
;
652 WPA_PUT_BE16(idx
, token_idx
);
653 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
657 len
[1] = sizeof(idx
);
658 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
659 2, addrs
, len
, token
) < 0) {
663 WPA_PUT_BE16(token
, token_idx
);
669 static int sae_check_big_sync(struct hostapd_data
*hapd
, struct sta_info
*sta
)
671 if (sta
->sae
->sync
> hapd
->conf
->sae_sync
) {
672 sae_set_state(sta
, SAE_NOTHING
, "Sync > dot11RSNASAESync");
680 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
682 struct hostapd_data
*hapd
= eloop_ctx
;
683 struct sta_info
*sta
= eloop_data
;
686 if (sae_check_big_sync(hapd
, sta
))
689 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
690 " (sync=%d state=%s)",
691 MAC2STR(sta
->addr
), sta
->sae
->sync
,
692 sae_state_txt(sta
->sae
->state
));
694 switch (sta
->sae
->state
) {
696 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
697 eloop_register_timeout(0,
698 hapd
->dot11RSNASAERetransPeriod
* 1000,
699 auth_sae_retransmit_timer
, hapd
, sta
);
702 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
703 eloop_register_timeout(0,
704 hapd
->dot11RSNASAERetransPeriod
* 1000,
705 auth_sae_retransmit_timer
, hapd
, sta
);
712 if (ret
!= WLAN_STATUS_SUCCESS
)
713 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
717 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
719 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
723 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
724 struct sta_info
*sta
)
726 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
729 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
730 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
731 auth_sae_retransmit_timer
, hapd
, sta
);
735 static void sae_sme_send_external_auth_status(struct hostapd_data
*hapd
,
736 struct sta_info
*sta
, u16 status
)
738 struct external_auth params
;
740 os_memset(¶ms
, 0, sizeof(params
));
741 params
.status
= status
;
742 params
.bssid
= sta
->addr
;
743 if (status
== WLAN_STATUS_SUCCESS
&& sta
->sae
&&
744 !hapd
->conf
->disable_pmksa_caching
)
745 params
.pmkid
= sta
->sae
->pmkid
;
747 hostapd_drv_send_external_auth_status(hapd
, ¶ms
);
751 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
753 #ifndef CONFIG_NO_VLAN
754 struct vlan_description vlan_desc
;
756 if (sta
->sae
->tmp
&& sta
->sae
->tmp
->vlan_id
> 0) {
757 wpa_printf(MSG_DEBUG
, "SAE: Assign STA " MACSTR
759 MAC2STR(sta
->addr
), sta
->sae
->tmp
->vlan_id
);
761 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
762 vlan_desc
.notempty
= 1;
763 vlan_desc
.untagged
= sta
->sae
->tmp
->vlan_id
;
764 if (!hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
766 "Invalid VLAN ID %d in sae_password",
767 sta
->sae
->tmp
->vlan_id
);
771 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0 ||
772 ap_sta_bind_vlan(hapd
, sta
) < 0) {
774 "Failed to assign VLAN ID %d from sae_password to "
775 MACSTR
, sta
->sae
->tmp
->vlan_id
,
780 #endif /* CONFIG_NO_VLAN */
782 sta
->flags
|= WLAN_STA_AUTH
;
783 sta
->auth_alg
= WLAN_AUTH_SAE
;
784 mlme_authenticate_indication(hapd
, sta
);
785 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
786 sae_set_state(sta
, SAE_ACCEPTED
, "Accept Confirm");
787 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
788 sta
->sae
->pmk
, sta
->sae
->pmkid
);
789 sae_sme_send_external_auth_status(hapd
, sta
, WLAN_STATUS_SUCCESS
);
793 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
794 const u8
*bssid
, u16 auth_transaction
, u16 status_code
,
795 int allow_reuse
, int *sta_removed
)
801 if (auth_transaction
!= 1 && auth_transaction
!= 2)
802 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
804 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
805 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
807 switch (sta
->sae
->state
) {
809 if (auth_transaction
== 1) {
811 sta
->sae
->tmp
->h2e
= status_code
==
812 WLAN_STATUS_SAE_HASH_TO_ELEMENT
;
813 ret
= auth_sae_send_commit(hapd
, sta
, bssid
,
817 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
819 if (sae_process_commit(sta
->sae
) < 0)
820 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
823 * In mesh case, both Commit and Confirm are sent
824 * immediately. In infrastructure BSS, by default, only
825 * a single Authentication frame (Commit) is expected
826 * from the AP here and the second one (Confirm) will
827 * be sent once the STA has sent its second
828 * Authentication frame (Confirm). This behavior can be
829 * overridden with explicit configuration so that the
830 * infrastructure BSS case sends both frames together.
832 if ((hapd
->conf
->mesh
& MESH_ENABLED
) ||
833 hapd
->conf
->sae_confirm_immediate
) {
835 * Send both Commit and Confirm immediately
836 * based on SAE finite state machine
837 * Nothing -> Confirm transition.
839 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
842 sae_set_state(sta
, SAE_CONFIRMED
,
843 "Sent Confirm (mesh)");
846 * For infrastructure BSS, send only the Commit
847 * message now to get alternating sequence of
848 * Authentication frames between the AP and STA.
849 * Confirm will be sent in
850 * Committed -> Confirmed/Accepted transition
851 * when receiving Confirm from STA.
855 sae_set_retransmit_timer(hapd
, sta
);
857 hostapd_logger(hapd
, sta
->addr
,
858 HOSTAPD_MODULE_IEEE80211
,
860 "SAE confirm before commit");
864 sae_clear_retransmit_timer(hapd
, sta
);
865 if (auth_transaction
== 1) {
866 if (sae_process_commit(sta
->sae
) < 0)
867 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
869 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
872 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
874 sae_set_retransmit_timer(hapd
, sta
);
875 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
877 * In mesh case, follow SAE finite state machine and
878 * send Commit now, if sync count allows.
880 if (sae_check_big_sync(hapd
, sta
))
881 return WLAN_STATUS_SUCCESS
;
884 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
888 sae_set_retransmit_timer(hapd
, sta
);
891 * For instructure BSS, send the postponed Confirm from
892 * Nothing -> Confirmed transition that was reduced to
893 * Nothing -> Committed above.
895 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
899 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
902 * Since this was triggered on Confirm RX, run another
903 * step to get to Accepted without waiting for
906 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
,
907 WLAN_STATUS_SUCCESS
, 0, sta_removed
);
911 sae_clear_retransmit_timer(hapd
, sta
);
912 if (auth_transaction
== 1) {
913 if (sae_check_big_sync(hapd
, sta
))
914 return WLAN_STATUS_SUCCESS
;
917 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
921 if (sae_process_commit(sta
->sae
) < 0)
922 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
924 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
928 sae_set_retransmit_timer(hapd
, sta
);
930 sta
->sae
->send_confirm
= 0xffff;
931 sae_accept_sta(hapd
, sta
);
935 if (auth_transaction
== 1 &&
936 (hapd
->conf
->mesh
& MESH_ENABLED
)) {
937 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
938 ") doing reauthentication",
940 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
941 ap_free_sta(hapd
, sta
);
943 } else if (auth_transaction
== 1) {
944 wpa_printf(MSG_DEBUG
, "SAE: Start reauthentication");
945 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
948 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
950 if (sae_process_commit(sta
->sae
) < 0)
951 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
953 sae_set_retransmit_timer(hapd
, sta
);
955 if (sae_check_big_sync(hapd
, sta
))
956 return WLAN_STATUS_SUCCESS
;
959 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
960 sae_clear_temp_data(sta
->sae
);
966 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
968 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
970 return WLAN_STATUS_SUCCESS
;
974 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
976 struct sae_data
*sae
= sta
->sae
;
977 int i
, *groups
= hapd
->conf
->sae_groups
;
978 int default_groups
[] = { 19, 0 };
980 if (sae
->state
!= SAE_COMMITTED
)
983 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
986 groups
= default_groups
;
987 for (i
= 0; groups
[i
] > 0; i
++) {
988 if (sae
->group
== groups
[i
])
992 if (groups
[i
] <= 0) {
993 wpa_printf(MSG_DEBUG
,
994 "SAE: Previously selected group not found from the current configuration");
1000 if (groups
[i
] <= 0) {
1001 wpa_printf(MSG_DEBUG
,
1002 "SAE: No alternative group enabled");
1006 if (sae_set_group(sae
, groups
[i
]) < 0)
1011 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
1015 static int sae_status_success(struct hostapd_data
*hapd
, u16 status_code
)
1017 return (hapd
->conf
->sae_pwe
== 0 &&
1018 status_code
== WLAN_STATUS_SUCCESS
) ||
1019 (hapd
->conf
->sae_pwe
== 1 &&
1020 status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
) ||
1021 (hapd
->conf
->sae_pwe
== 2 &&
1022 (status_code
== WLAN_STATUS_SUCCESS
||
1023 status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
));
1027 static int sae_is_group_enabled(struct hostapd_data
*hapd
, int group
)
1029 int *groups
= hapd
->conf
->sae_groups
;
1030 int default_groups
[] = { 19, 0 };
1034 groups
= default_groups
;
1036 for (i
= 0; groups
[i
] > 0; i
++) {
1037 if (groups
[i
] == group
)
1045 static int check_sae_rejected_groups(struct hostapd_data
*hapd
,
1046 const struct wpabuf
*groups
)
1054 pos
= wpabuf_head(groups
);
1055 count
= wpabuf_len(groups
) / 2;
1056 for (i
= 0; i
< count
; i
++) {
1060 group
= WPA_GET_LE16(pos
);
1062 enabled
= sae_is_group_enabled(hapd
, group
);
1063 wpa_printf(MSG_DEBUG
, "SAE: Rejected group %u is %s",
1064 group
, enabled
? "enabled" : "disabled");
1073 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1074 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1075 u16 auth_transaction
, u16 status_code
)
1077 int resp
= WLAN_STATUS_SUCCESS
;
1078 struct wpabuf
*data
= NULL
;
1079 int *groups
= hapd
->conf
->sae_groups
;
1080 int default_groups
[] = { 19, 0 };
1081 const u8
*pos
, *end
;
1082 int sta_removed
= 0;
1085 groups
= default_groups
;
1087 #ifdef CONFIG_TESTING_OPTIONS
1088 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
1089 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
1090 pos
= mgmt
->u
.auth
.variable
;
1091 end
= ((const u8
*) mgmt
) + len
;
1092 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1093 auth_transaction
, resp
, pos
, end
- pos
,
1094 "auth-sae-reflection-attack");
1098 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
1099 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
1100 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1101 auth_transaction
, resp
,
1102 wpabuf_head(hapd
->conf
->sae_commit_override
),
1103 wpabuf_len(hapd
->conf
->sae_commit_override
),
1104 "sae-commit-override");
1107 #endif /* CONFIG_TESTING_OPTIONS */
1109 if (auth_transaction
!= 1 ||
1110 !sae_status_success(hapd
, status_code
)) {
1114 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
1119 sae_set_state(sta
, SAE_NOTHING
, "Init");
1123 if (sta
->mesh_sae_pmksa_caching
) {
1124 wpa_printf(MSG_DEBUG
,
1125 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1126 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
1127 sta
->mesh_sae_pmksa_caching
= 0;
1130 if (auth_transaction
== 1) {
1131 const u8
*token
= NULL
;
1132 size_t token_len
= 0;
1133 int allow_reuse
= 0;
1135 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1136 HOSTAPD_LEVEL_DEBUG
,
1137 "start SAE authentication (RX commit, status=%u (%s))",
1138 status_code
, status2str(status_code
));
1140 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1141 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1143 pos
= mgmt
->u
.auth
.variable
;
1144 end
= ((const u8
*) mgmt
) + len
;
1145 if (pos
+ sizeof(le16
) > end
) {
1146 wpa_printf(MSG_ERROR
,
1147 "SAE: Too short anti-clogging token request");
1148 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1151 resp
= sae_group_allowed(sta
->sae
, groups
,
1153 if (resp
!= WLAN_STATUS_SUCCESS
) {
1154 wpa_printf(MSG_ERROR
,
1155 "SAE: Invalid group in anti-clogging token request");
1158 pos
+= sizeof(le16
);
1160 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
1161 sta
->sae
->tmp
->anti_clogging_token
=
1162 wpabuf_alloc_copy(pos
, end
- pos
);
1163 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
1164 wpa_printf(MSG_ERROR
,
1165 "SAE: Failed to alloc for anti-clogging token");
1166 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1171 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1172 * is 76, a new Commit Message shall be constructed
1173 * with the Anti-Clogging Token from the received
1174 * Authentication frame, and the commit-scalar and
1175 * COMMIT-ELEMENT previously sent.
1177 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
1178 if (resp
!= WLAN_STATUS_SUCCESS
) {
1179 wpa_printf(MSG_ERROR
,
1180 "SAE: Failed to send commit message");
1183 sae_set_state(sta
, SAE_COMMITTED
,
1184 "Sent Commit (anti-clogging token case in mesh)");
1186 sae_set_retransmit_timer(hapd
, sta
);
1190 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1192 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1194 wpa_printf(MSG_DEBUG
,
1195 "SAE: Peer did not accept our SAE group");
1196 sae_pick_next_group(hapd
, sta
);
1200 if (!sae_status_success(hapd
, status_code
))
1203 if (!(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1204 sta
->sae
->state
== SAE_COMMITTED
) {
1205 /* This is needed in the infrastructure BSS case to
1206 * address a sequence where a STA entry may remain in
1207 * hostapd across two attempts to do SAE authentication
1208 * by the same STA. The second attempt may end up trying
1209 * to use a different group and that would not be
1210 * allowed if we remain in Committed state with the
1211 * previously set parameters. */
1212 pos
= mgmt
->u
.auth
.variable
;
1213 end
= ((const u8
*) mgmt
) + len
;
1214 if (end
- pos
>= (int) sizeof(le16
) &&
1215 sae_group_allowed(sta
->sae
, groups
,
1216 WPA_GET_LE16(pos
)) ==
1217 WLAN_STATUS_SUCCESS
) {
1218 /* Do not waste resources deriving the same PWE
1219 * again since the same group is reused. */
1220 sae_set_state(sta
, SAE_NOTHING
,
1221 "Allow previous PWE to be reused");
1224 sae_set_state(sta
, SAE_NOTHING
,
1225 "Clear existing state to allow restart");
1226 sae_clear_data(sta
->sae
);
1230 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
1231 ((const u8
*) mgmt
) + len
-
1232 mgmt
->u
.auth
.variable
, &token
,
1233 &token_len
, groups
, status_code
==
1234 WLAN_STATUS_SAE_HASH_TO_ELEMENT
);
1235 if (resp
== SAE_SILENTLY_DISCARD
) {
1236 wpa_printf(MSG_DEBUG
,
1237 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
1238 MAC2STR(sta
->addr
));
1242 if (resp
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1243 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1244 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1245 MACSTR
, MAC2STR(sta
->addr
));
1246 sae_clear_retransmit_timer(hapd
, sta
);
1247 sae_set_state(sta
, SAE_NOTHING
,
1248 "Unknown Password Identifier");
1252 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
1254 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
1255 "incorrect token from " MACSTR
,
1256 MAC2STR(sta
->addr
));
1257 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1261 if (resp
!= WLAN_STATUS_SUCCESS
)
1264 if (sta
->sae
->tmp
&&
1265 check_sae_rejected_groups(
1266 hapd
, sta
->sae
->tmp
->peer_rejected_groups
) < 0) {
1267 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1271 if (!token
&& use_sae_anti_clogging(hapd
) && !allow_reuse
) {
1272 wpa_printf(MSG_DEBUG
,
1273 "SAE: Request anti-clogging token from "
1274 MACSTR
, MAC2STR(sta
->addr
));
1275 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
1277 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
1278 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1279 sae_set_state(sta
, SAE_NOTHING
,
1280 "Request anti-clogging token case in mesh");
1284 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1285 status_code
, allow_reuse
, &sta_removed
);
1286 } else if (auth_transaction
== 2) {
1287 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1288 HOSTAPD_LEVEL_DEBUG
,
1289 "SAE authentication (RX confirm, status=%u (%s))",
1290 status_code
, status2str(status_code
));
1291 if (status_code
!= WLAN_STATUS_SUCCESS
)
1293 if (sta
->sae
->state
>= SAE_CONFIRMED
||
1294 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
1297 u16 peer_send_confirm
;
1299 var
= mgmt
->u
.auth
.variable
;
1300 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
1302 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1306 peer_send_confirm
= WPA_GET_LE16(var
);
1308 if (sta
->sae
->state
== SAE_ACCEPTED
&&
1309 (peer_send_confirm
<= sta
->sae
->rc
||
1310 peer_send_confirm
== 0xffff)) {
1311 wpa_printf(MSG_DEBUG
,
1312 "SAE: Silently ignore unexpected Confirm from peer "
1314 " (peer-send-confirm=%u Rc=%u)",
1316 peer_send_confirm
, sta
->sae
->rc
);
1320 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
1321 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1324 sta
->sae
->rc
= peer_send_confirm
;
1326 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1327 status_code
, 0, &sta_removed
);
1329 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1330 HOSTAPD_LEVEL_DEBUG
,
1331 "unexpected SAE authentication transaction %u (status=%u (%s))",
1332 auth_transaction
, status_code
,
1333 status2str(status_code
));
1334 if (status_code
!= WLAN_STATUS_SUCCESS
)
1336 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1340 if (!sta_removed
&& resp
!= WLAN_STATUS_SUCCESS
) {
1341 pos
= mgmt
->u
.auth
.variable
;
1342 end
= ((const u8
*) mgmt
) + len
;
1344 /* Copy the Finite Cyclic Group field from the request if we
1345 * rejected it as unsupported group. */
1346 if (resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1347 !data
&& end
- pos
>= 2)
1348 data
= wpabuf_alloc_copy(pos
, 2);
1350 sae_sme_send_external_auth_status(hapd
, sta
, resp
);
1351 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1352 auth_transaction
, resp
,
1353 data
? wpabuf_head(data
) : (u8
*) "",
1354 data
? wpabuf_len(data
) : 0, "auth-sae");
1358 if (!sta_removed
&& sta
->added_unassoc
&&
1359 (resp
!= WLAN_STATUS_SUCCESS
||
1360 status_code
!= WLAN_STATUS_SUCCESS
)) {
1361 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1362 sta
->added_unassoc
= 0;
1369 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1370 * @hapd: BSS data for the device initiating the authentication
1371 * @sta: the peer to which commit authentication frame is sent
1373 * This function implements Init event handling (IEEE Std 802.11-2012,
1374 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1375 * sta->sae structure should be initialized appropriately via a call to
1376 * sae_prepare_commit().
1378 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1382 if (!sta
->sae
|| !sta
->sae
->tmp
)
1385 if (sta
->sae
->state
!= SAE_NOTHING
)
1388 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1392 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1394 sae_set_retransmit_timer(hapd
, sta
);
1400 void auth_sae_process_commit(void *eloop_ctx
, void *user_ctx
)
1402 struct hostapd_data
*hapd
= eloop_ctx
;
1403 struct hostapd_sae_commit_queue
*q
;
1404 unsigned int queue_len
;
1406 q
= dl_list_first(&hapd
->sae_commit_queue
,
1407 struct hostapd_sae_commit_queue
, list
);
1410 wpa_printf(MSG_DEBUG
,
1411 "SAE: Process next available message from queue");
1412 dl_list_del(&q
->list
);
1413 handle_auth(hapd
, (const struct ieee80211_mgmt
*) q
->msg
, q
->len
,
1417 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1419 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1420 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1425 static void auth_sae_queue(struct hostapd_data
*hapd
,
1426 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1429 struct hostapd_sae_commit_queue
*q
, *q2
;
1430 unsigned int queue_len
;
1431 const struct ieee80211_mgmt
*mgmt2
;
1433 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1434 if (queue_len
>= 15) {
1435 wpa_printf(MSG_DEBUG
,
1436 "SAE: No more room in message queue - drop the new frame from "
1437 MACSTR
, MAC2STR(mgmt
->sa
));
1441 wpa_printf(MSG_DEBUG
, "SAE: Queue Authentication message from "
1442 MACSTR
" for processing (queue_len %u)", MAC2STR(mgmt
->sa
),
1444 q
= os_zalloc(sizeof(*q
) + len
);
1449 os_memcpy(q
->msg
, mgmt
, len
);
1451 /* Check whether there is already a queued Authentication frame from the
1452 * same station with the same transaction number and if so, replace that
1453 * queue entry with the new one. This avoids issues with a peer that
1454 * sends multiple times (e.g., due to frequent SAE retries). There is no
1455 * point in us trying to process the old attempts after a new one has
1456 * obsoleted them. */
1457 dl_list_for_each(q2
, &hapd
->sae_commit_queue
,
1458 struct hostapd_sae_commit_queue
, list
) {
1459 mgmt2
= (const struct ieee80211_mgmt
*) q2
->msg
;
1460 if (os_memcmp(mgmt
->sa
, mgmt2
->sa
, ETH_ALEN
) == 0 &&
1461 mgmt
->u
.auth
.auth_transaction
==
1462 mgmt2
->u
.auth
.auth_transaction
) {
1463 wpa_printf(MSG_DEBUG
,
1464 "SAE: Replace queued message from same STA with same transaction number");
1465 dl_list_add(&q2
->list
, &q
->list
);
1466 dl_list_del(&q2
->list
);
1472 /* No pending identical entry, so add to the end of the queue */
1473 dl_list_add_tail(&hapd
->sae_commit_queue
, &q
->list
);
1476 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1478 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1483 static int auth_sae_queued_addr(struct hostapd_data
*hapd
, const u8
*addr
)
1485 struct hostapd_sae_commit_queue
*q
;
1486 const struct ieee80211_mgmt
*mgmt
;
1488 dl_list_for_each(q
, &hapd
->sae_commit_queue
,
1489 struct hostapd_sae_commit_queue
, list
) {
1490 mgmt
= (const struct ieee80211_mgmt
*) q
->msg
;
1491 if (os_memcmp(addr
, mgmt
->sa
, ETH_ALEN
) == 0)
1498 #endif /* CONFIG_SAE */
1501 static u16
wpa_res_to_status_code(int res
)
1503 if (res
== WPA_INVALID_GROUP
)
1504 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1505 if (res
== WPA_INVALID_PAIRWISE
)
1506 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1507 if (res
== WPA_INVALID_AKMP
)
1508 return WLAN_STATUS_AKMP_NOT_VALID
;
1509 if (res
== WPA_ALLOC_FAIL
)
1510 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1511 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1512 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1513 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1514 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1515 if (res
== WPA_INVALID_MDIE
)
1516 return WLAN_STATUS_INVALID_MDIE
;
1517 if (res
== WPA_INVALID_PMKID
)
1518 return WLAN_STATUS_INVALID_PMKID
;
1519 if (res
!= WPA_IE_OK
)
1520 return WLAN_STATUS_INVALID_IE
;
1521 return WLAN_STATUS_SUCCESS
;
1527 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1528 struct sta_info
*sta
, u16 resp
,
1529 struct wpabuf
*data
, int pub
);
1531 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1532 const u8
*pos
, size_t len
, u16 auth_alg
,
1533 u16 auth_transaction
, u16 status_code
,
1534 void (*cb
)(struct hostapd_data
*hapd
,
1535 struct sta_info
*sta
, u16 resp
,
1536 struct wpabuf
*data
, int pub
))
1538 u16 resp
= WLAN_STATUS_SUCCESS
;
1540 struct ieee802_11_elems elems
;
1542 struct wpa_ie_data rsn
;
1543 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1545 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1550 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1554 #ifdef CONFIG_FILS_SK_PFS
1555 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1560 /* Using FILS PFS */
1562 /* Finite Cyclic Group */
1563 if (end
- pos
< 2) {
1564 wpa_printf(MSG_DEBUG
,
1565 "FILS: No room for Finite Cyclic Group");
1566 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1569 group
= WPA_GET_LE16(pos
);
1571 if (group
!= hapd
->conf
->fils_dh_group
) {
1572 wpa_printf(MSG_DEBUG
,
1573 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1574 group
, hapd
->conf
->fils_dh_group
);
1575 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1579 crypto_ecdh_deinit(sta
->fils_ecdh
);
1580 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1581 if (!sta
->fils_ecdh
) {
1582 wpa_printf(MSG_INFO
,
1583 "FILS: Could not initialize ECDH with group %d",
1585 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1589 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1591 wpa_printf(MSG_DEBUG
,
1592 "FILS: Failed to derive ECDH public key");
1593 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1596 elem_len
= wpabuf_len(pub
);
1600 if ((size_t) (end
- pos
) < elem_len
) {
1601 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1602 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1606 wpabuf_free(sta
->fils_g_sta
);
1607 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1608 wpabuf_clear_free(sta
->fils_dh_ss
);
1609 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1611 if (!sta
->fils_dh_ss
) {
1612 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1613 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1616 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1619 crypto_ecdh_deinit(sta
->fils_ecdh
);
1620 sta
->fils_ecdh
= NULL
;
1621 wpabuf_clear_free(sta
->fils_dh_ss
);
1622 sta
->fils_dh_ss
= NULL
;
1624 #endif /* CONFIG_FILS_SK_PFS */
1626 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1627 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1628 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1629 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1634 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1635 elems
.rsn_ie
, elems
.rsn_ie_len
);
1636 if (!elems
.rsn_ie
||
1637 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1639 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1640 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1645 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1648 wpa_printf(MSG_DEBUG
,
1649 "FILS: Failed to initialize RSN state machine");
1650 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1654 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1656 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1657 elems
.rsnxe
? elems
.rsnxe
- 2 : NULL
,
1658 elems
.rsnxe
? elems
.rsnxe_len
+ 2 : 0,
1659 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1660 resp
= wpa_res_to_status_code(res
);
1661 if (resp
!= WLAN_STATUS_SUCCESS
)
1664 if (!elems
.fils_nonce
) {
1665 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1666 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1669 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1671 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1674 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1678 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1679 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1682 num
= rsn
.num_pmkid
;
1684 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1685 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1689 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1698 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1699 wpa_printf(MSG_DEBUG
,
1700 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1701 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1705 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1708 if (!elems
.fils_session
) {
1709 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1710 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1713 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1715 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1717 /* FILS Wrapped Data */
1718 if (elems
.fils_wrapped_data
) {
1719 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1720 elems
.fils_wrapped_data
,
1721 elems
.fils_wrapped_data_len
);
1723 #ifndef CONFIG_NO_RADIUS
1724 if (!sta
->eapol_sm
) {
1726 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1728 wpa_printf(MSG_DEBUG
,
1729 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1730 ieee802_1x_encapsulate_radius(
1731 hapd
, sta
, elems
.fils_wrapped_data
,
1732 elems
.fils_wrapped_data_len
);
1733 sta
->fils_pending_cb
= cb
;
1734 wpa_printf(MSG_DEBUG
,
1735 "FILS: Will send Authentication frame once the response from authentication server is available");
1736 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1737 /* Calculate pending PMKID here so that we do not need
1738 * to maintain a copy of the EAP-Initiate/Reauth
1740 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1741 elems
.fils_wrapped_data
,
1742 elems
.fils_wrapped_data_len
,
1743 sta
->fils_erp_pmkid
) == 0)
1744 sta
->fils_erp_pmkid_set
= 1;
1746 #else /* CONFIG_NO_RADIUS */
1747 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1749 #endif /* CONFIG_NO_RADIUS */
1755 struct wpabuf
*data
;
1758 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1761 wpa_printf(MSG_DEBUG
,
1762 "%s: prepare_auth_resp_fils() returned failure",
1766 cb(hapd
, sta
, resp
, data
, pub
);
1771 static struct wpabuf
*
1772 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1773 struct sta_info
*sta
, u16
*resp
,
1774 struct rsn_pmksa_cache_entry
*pmksa
,
1775 struct wpabuf
*erp_resp
,
1776 const u8
*msk
, size_t msk_len
,
1779 u8 fils_nonce
[FILS_NONCE_LEN
];
1781 struct wpabuf
*data
= NULL
;
1784 const u8
*pmk
= NULL
;
1786 u8 pmk_buf
[PMK_LEN_MAX
];
1787 struct wpabuf
*pub
= NULL
;
1789 if (*resp
!= WLAN_STATUS_SUCCESS
)
1792 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1794 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1799 /* Add PMKID of the selected PMKSA into RSNE */
1800 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1802 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1806 os_memcpy(ie_buf
, ie
, ielen
);
1807 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1808 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1814 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1815 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1818 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1819 fils_nonce
, FILS_NONCE_LEN
);
1821 #ifdef CONFIG_FILS_SK_PFS
1822 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1823 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1825 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1829 #endif /* CONFIG_FILS_SK_PFS */
1831 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1833 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1838 #ifdef CONFIG_FILS_SK_PFS
1840 /* Finite Cyclic Group */
1841 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1844 wpabuf_put_buf(data
, pub
);
1846 #endif /* CONFIG_FILS_SK_PFS */
1849 wpabuf_put_data(data
, ie
, ielen
);
1851 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1853 #ifdef CONFIG_IEEE80211R_AP
1854 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1855 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1857 int use_sha384
= wpa_key_mgmt_sha384(
1858 wpa_auth_sta_key_mgmt(sta
->wpa_sm
));
1860 res
= wpa_auth_write_fte(hapd
->wpa_auth
, use_sha384
,
1861 wpabuf_put(data
, 0),
1862 wpabuf_tailroom(data
));
1864 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1867 wpabuf_put(data
, res
);
1869 #endif /* CONFIG_IEEE80211R_AP */
1872 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1873 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1874 /* Element ID Extension */
1875 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1876 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1879 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1880 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1881 /* Element ID Extension */
1882 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1883 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1885 /* FILS Wrapped Data */
1886 if (!pmksa
&& erp_resp
) {
1887 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1888 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1889 /* Element ID Extension */
1890 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1891 wpabuf_put_buf(data
, erp_resp
);
1893 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1894 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1896 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1898 wpabuf_len(sta
->fils_dh_ss
) : 0,
1899 pmk_buf
, &pmk_len
)) {
1900 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1901 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1908 /* Don't use DHss in PTK derivation if PMKSA caching is not
1910 wpabuf_clear_free(sta
->fils_dh_ss
);
1911 sta
->fils_dh_ss
= NULL
;
1913 if (sta
->fils_erp_pmkid_set
) {
1914 /* TODO: get PMKLifetime from WPA parameters */
1915 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1916 int session_timeout
;
1918 session_timeout
= dot11RSNAConfigPMKLifetime
;
1919 if (sta
->session_timeout_set
) {
1920 struct os_reltime now
, diff
;
1922 os_get_reltime(&now
);
1923 os_reltime_sub(&sta
->session_timeout
, &now
,
1925 session_timeout
= diff
.sec
;
1928 sta
->fils_erp_pmkid_set
= 0;
1929 wpa_auth_add_fils_pmk_pmkid(sta
->wpa_sm
, pmk
, pmk_len
,
1930 sta
->fils_erp_pmkid
);
1931 if (!hapd
->conf
->disable_pmksa_caching
&&
1932 wpa_auth_pmksa_add2(
1933 hapd
->wpa_auth
, sta
->addr
,
1935 sta
->fils_erp_pmkid
,
1937 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1938 wpa_printf(MSG_ERROR
,
1939 "FILS: Failed to add PMKSA cache entry based on ERP");
1944 pmk_len
= pmksa
->pmk_len
;
1948 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1949 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1955 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1956 sta
->fils_snonce
, fils_nonce
,
1958 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1960 wpabuf_len(sta
->fils_dh_ss
) : 0,
1961 sta
->fils_g_sta
, pub
) < 0) {
1962 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1970 *is_pub
= pub
!= NULL
;
1973 wpabuf_clear_free(sta
->fils_dh_ss
);
1974 sta
->fils_dh_ss
= NULL
;
1975 #ifdef CONFIG_FILS_SK_PFS
1976 crypto_ecdh_deinit(sta
->fils_ecdh
);
1977 sta
->fils_ecdh
= NULL
;
1978 #endif /* CONFIG_FILS_SK_PFS */
1983 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1984 struct sta_info
*sta
, u16 resp
,
1985 struct wpabuf
*data
, int pub
)
1990 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1991 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1992 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1993 data
? wpabuf_head(data
) : (u8
*) "",
1994 data
? wpabuf_len(data
) : 0, "auth-fils-finish");
1997 if (resp
== WLAN_STATUS_SUCCESS
) {
1998 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1999 HOSTAPD_LEVEL_DEBUG
,
2000 "authentication OK (FILS)");
2001 sta
->flags
|= WLAN_STA_AUTH
;
2002 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2003 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
2004 mlme_authenticate_indication(hapd
, sta
);
2009 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
2010 struct sta_info
*sta
, int success
,
2011 struct wpabuf
*erp_resp
,
2012 const u8
*msk
, size_t msk_len
)
2014 struct wpabuf
*data
;
2018 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2020 if (!sta
->fils_pending_cb
)
2022 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
2023 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
2024 msk
, msk_len
, &pub
);
2026 wpa_printf(MSG_DEBUG
,
2027 "%s: prepare_auth_resp_fils() returned failure",
2030 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
2033 #endif /* CONFIG_FILS */
2037 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
2038 const u8
*msg
, size_t len
, u32
*session_timeout
,
2039 u32
*acct_interim_interval
,
2040 struct vlan_description
*vlan_id
,
2041 struct hostapd_sta_wpa_psk_short
**psk
,
2042 char **identity
, char **radius_cui
, int is_probe_req
)
2046 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
2047 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
2048 session_timeout
, acct_interim_interval
,
2049 vlan_id
, psk
, identity
, radius_cui
,
2052 if (res
== HOSTAPD_ACL_REJECT
) {
2054 wpa_printf(MSG_DEBUG
,
2056 " not allowed to authenticate",
2058 return HOSTAPD_ACL_REJECT
;
2061 if (res
== HOSTAPD_ACL_PENDING
) {
2062 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
2063 " waiting for an external authentication",
2065 /* Authentication code will re-send the authentication frame
2066 * after it has received (and cached) information from the
2067 * external source. */
2068 return HOSTAPD_ACL_PENDING
;
2076 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2077 int res
, u32 session_timeout
,
2078 u32 acct_interim_interval
,
2079 struct vlan_description
*vlan_id
,
2080 struct hostapd_sta_wpa_psk_short
**psk
,
2081 char **identity
, char **radius_cui
)
2083 if (vlan_id
->notempty
&&
2084 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
2085 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2087 "Invalid VLAN %d%s received from RADIUS server",
2089 vlan_id
->tagged
[0] ? "+" : "");
2092 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
2095 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2096 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
2098 hostapd_free_psk_list(sta
->psk
);
2099 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
2106 os_free(sta
->identity
);
2107 sta
->identity
= *identity
;
2110 os_free(sta
->radius_cui
);
2111 sta
->radius_cui
= *radius_cui
;
2114 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
2115 sta
->acct_interim_interval
= acct_interim_interval
;
2116 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
) {
2117 sta
->session_timeout_set
= 1;
2118 os_get_reltime(&sta
->session_timeout
);
2119 sta
->session_timeout
.sec
+= session_timeout
;
2120 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
2122 sta
->session_timeout_set
= 0;
2123 ap_sta_no_session_timeout(hapd
, sta
);
2130 static void handle_auth(struct hostapd_data
*hapd
,
2131 const struct ieee80211_mgmt
*mgmt
, size_t len
,
2132 int rssi
, int from_queue
)
2134 u16 auth_alg
, auth_transaction
, status_code
;
2135 u16 resp
= WLAN_STATUS_SUCCESS
;
2136 struct sta_info
*sta
= NULL
;
2139 const u8
*challenge
= NULL
;
2140 u32 session_timeout
, acct_interim_interval
;
2141 struct vlan_description vlan_id
;
2142 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
2143 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
2144 size_t resp_ies_len
= 0;
2145 char *identity
= NULL
;
2146 char *radius_cui
= NULL
;
2149 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
2150 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
2151 (unsigned long) len
);
2155 #ifdef CONFIG_TESTING_OPTIONS
2156 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
2157 drand48() < hapd
->iconf
->ignore_auth_probability
) {
2158 wpa_printf(MSG_INFO
,
2159 "TESTING: ignoring auth frame from " MACSTR
,
2163 #endif /* CONFIG_TESTING_OPTIONS */
2165 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
2166 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
2167 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
2168 fc
= le_to_host16(mgmt
->frame_control
);
2169 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
2171 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
2172 2 + WLAN_AUTH_CHALLENGE_LEN
&&
2173 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
2174 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
2175 challenge
= &mgmt
->u
.auth
.variable
[2];
2177 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
2178 "auth_transaction=%d status_code=%d wep=%d%s "
2179 "seq_ctrl=0x%x%s%s",
2180 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
2181 status_code
, !!(fc
& WLAN_FC_ISWEP
),
2182 challenge
? " challenge" : "",
2183 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "",
2184 from_queue
? " (from queue)" : "");
2186 #ifdef CONFIG_NO_RC4
2187 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
2188 wpa_printf(MSG_INFO
,
2189 "Unsupported authentication algorithm (%d)",
2191 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2194 #endif /* CONFIG_NO_RC4 */
2196 if (hapd
->tkip_countermeasures
) {
2197 wpa_printf(MSG_DEBUG
,
2198 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2199 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2203 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
2204 auth_alg
== WLAN_AUTH_OPEN
) ||
2205 #ifdef CONFIG_IEEE80211R_AP
2206 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
2207 auth_alg
== WLAN_AUTH_FT
) ||
2208 #endif /* CONFIG_IEEE80211R_AP */
2210 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
2211 auth_alg
== WLAN_AUTH_SAE
) ||
2212 #endif /* CONFIG_SAE */
2214 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2215 auth_alg
== WLAN_AUTH_FILS_SK
) ||
2216 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2217 hapd
->conf
->fils_dh_group
&&
2218 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
2219 #endif /* CONFIG_FILS */
2220 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
2221 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
2222 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
2224 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2228 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
2229 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
2230 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
2232 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
2236 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
2237 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
2239 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2243 if (hapd
->conf
->no_auth_if_seen_on
) {
2244 struct hostapd_data
*other
;
2246 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
2247 hapd
->conf
->no_auth_if_seen_on
);
2251 u8 op_class
, channel
, phytype
;
2253 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
2254 MACSTR
" since STA has been seen on %s",
2255 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
2256 hapd
->conf
->no_auth_if_seen_on
);
2258 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
2260 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
2262 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
2264 info
= 0; /* TODO: BSSID Information */
2265 WPA_PUT_LE32(pos
, info
);
2267 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
2268 phytype
= 8; /* dmg */
2269 else if (other
->iconf
->ieee80211ac
)
2270 phytype
= 9; /* vht */
2271 else if (other
->iconf
->ieee80211n
)
2272 phytype
= 7; /* ht */
2273 else if (other
->iconf
->hw_mode
==
2274 HOSTAPD_MODE_IEEE80211A
)
2275 phytype
= 4; /* ofdm */
2276 else if (other
->iconf
->hw_mode
==
2277 HOSTAPD_MODE_IEEE80211G
)
2278 phytype
= 6; /* erp */
2280 phytype
= 5; /* hrdsss */
2281 if (ieee80211_freq_to_channel_ext(
2282 hostapd_hw_get_freq(other
,
2283 other
->iconf
->channel
),
2284 other
->iconf
->secondary_channel
,
2285 other
->iconf
->ieee80211ac
,
2286 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
2288 channel
= other
->iconf
->channel
;
2293 resp_ies_len
= pos
- &resp_ies
[0];
2298 res
= ieee802_11_allowed_address(
2299 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
2300 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
,
2302 if (res
== HOSTAPD_ACL_REJECT
) {
2303 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
2304 "Ignore Authentication frame from " MACSTR
2305 " due to ACL reject", MAC2STR(mgmt
->sa
));
2306 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2309 if (res
== HOSTAPD_ACL_PENDING
)
2313 if (auth_alg
== WLAN_AUTH_SAE
&& !from_queue
&&
2314 (auth_transaction
== 1 ||
2315 (auth_transaction
== 2 && auth_sae_queued_addr(hapd
, mgmt
->sa
)))) {
2316 /* Handle SAE Authentication commit message through a queue to
2317 * provide more control for postponing the needed heavy
2318 * processing under a possible DoS attack scenario. In addition,
2319 * queue SAE Authentication confirm message if there happens to
2320 * be a queued commit message from the same peer. This is needed
2321 * to avoid reordering Authentication frames within the same
2323 auth_sae_queue(hapd
, mgmt
, len
, rssi
);
2326 #endif /* CONFIG_SAE */
2328 sta
= ap_get_sta(hapd
, mgmt
->sa
);
2330 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2331 sta
->ft_over_ds
= 0;
2332 if ((fc
& WLAN_FC_RETRY
) &&
2333 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
2334 sta
->last_seq_ctrl
== seq_ctrl
&&
2335 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
2336 hostapd_logger(hapd
, sta
->addr
,
2337 HOSTAPD_MODULE_IEEE80211
,
2338 HOSTAPD_LEVEL_DEBUG
,
2339 "Drop repeated authentication frame seq_ctrl=0x%x",
2344 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
2345 sta
->plink_state
== PLINK_BLOCKED
) {
2346 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2347 " is blocked - drop Authentication frame",
2351 #endif /* CONFIG_MESH */
2354 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
2355 /* if the mesh peer is not available, we don't do auth.
2357 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2358 " not yet known - drop Authentication frame",
2361 * Save a copy of the frame so that it can be processed
2362 * if a new peer entry is added shortly after this.
2364 wpabuf_free(hapd
->mesh_pending_auth
);
2365 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
2366 os_get_reltime(&hapd
->mesh_pending_auth_time
);
2369 #endif /* CONFIG_MESH */
2371 sta
= ap_sta_add(hapd
, mgmt
->sa
);
2373 wpa_printf(MSG_DEBUG
, "ap_sta_add() failed");
2374 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2378 sta
->last_seq_ctrl
= seq_ctrl
;
2379 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
2381 sta
->auth_rssi
= rssi
;
2382 #endif /* CONFIG_MBO */
2384 res
= ieee802_11_set_radius_info(
2385 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
2386 &vlan_id
, &psk
, &identity
, &radius_cui
);
2388 wpa_printf(MSG_DEBUG
, "ieee802_11_set_radius_info() failed");
2389 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2393 sta
->flags
&= ~WLAN_STA_PREAUTH
;
2394 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
2397 * If the driver supports full AP client state, add a station to the
2398 * driver before sending authentication reply to make sure the driver
2399 * has resources, and not to go through the entire authentication and
2400 * association handshake, and fail it at the end.
2402 * If this is not the first transaction, in a multi-step authentication
2403 * algorithm, the station already exists in the driver
2404 * (sta->added_unassoc = 1) so skip it.
2406 * In mesh mode, the station was already added to the driver when the
2407 * NEW_PEER_CANDIDATE event is received.
2409 * If PMF was negotiated for the existing association, skip this to
2410 * avoid dropping the STA entry and the associated keys. This is needed
2411 * to allow the original connection work until the attempt can complete
2412 * (re)association, so that unprotected Authentication frame cannot be
2413 * used to bypass PMF protection.
2415 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
2416 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
2417 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
2418 !(sta
->added_unassoc
)) {
2420 * If a station that is already associated to the AP, is trying
2421 * to authenticate again, remove the STA entry, in order to make
2422 * sure the STA PS state gets cleared and configuration gets
2423 * updated. To handle this, station's added_unassoc flag is
2424 * cleared once the station has completed association.
2426 ap_sta_set_authorized(hapd
, sta
, 0);
2427 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2428 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
2429 WLAN_STA_AUTHORIZED
);
2431 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0,
2432 sta
->supported_rates
,
2433 sta
->supported_rates_len
,
2434 0, NULL
, NULL
, NULL
, 0,
2435 sta
->flags
, 0, 0, 0, 0)) {
2436 hostapd_logger(hapd
, sta
->addr
,
2437 HOSTAPD_MODULE_IEEE80211
,
2438 HOSTAPD_LEVEL_NOTICE
,
2439 "Could not add STA to kernel driver");
2440 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2444 sta
->added_unassoc
= 1;
2448 case WLAN_AUTH_OPEN
:
2449 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2450 HOSTAPD_LEVEL_DEBUG
,
2451 "authentication OK (open system)");
2452 sta
->flags
|= WLAN_STA_AUTH
;
2453 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2454 sta
->auth_alg
= WLAN_AUTH_OPEN
;
2455 mlme_authenticate_indication(hapd
, sta
);
2457 #ifndef CONFIG_NO_RC4
2458 case WLAN_AUTH_SHARED_KEY
:
2459 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
2460 fc
& WLAN_FC_ISWEP
);
2462 wpa_printf(MSG_DEBUG
,
2463 "auth_shared_key() failed: status=%d", resp
);
2464 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2465 mlme_authenticate_indication(hapd
, sta
);
2466 if (sta
->challenge
&& auth_transaction
== 1) {
2467 resp_ies
[0] = WLAN_EID_CHALLENGE
;
2468 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
2469 os_memcpy(resp_ies
+ 2, sta
->challenge
,
2470 WLAN_AUTH_CHALLENGE_LEN
);
2471 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
2474 #endif /* CONFIG_NO_RC4 */
2475 #ifdef CONFIG_IEEE80211R_AP
2477 sta
->auth_alg
= WLAN_AUTH_FT
;
2478 if (sta
->wpa_sm
== NULL
)
2479 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2481 if (sta
->wpa_sm
== NULL
) {
2482 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
2484 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2487 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
2488 auth_transaction
, mgmt
->u
.auth
.variable
,
2489 len
- IEEE80211_HDRLEN
-
2490 sizeof(mgmt
->u
.auth
),
2491 handle_auth_ft_finish
, hapd
);
2492 /* handle_auth_ft_finish() callback will complete auth. */
2494 #endif /* CONFIG_IEEE80211R_AP */
2498 if (status_code
== WLAN_STATUS_SUCCESS
&&
2499 hapd
->conf
->mesh
& MESH_ENABLED
) {
2500 if (sta
->wpa_sm
== NULL
)
2502 wpa_auth_sta_init(hapd
->wpa_auth
,
2504 if (sta
->wpa_sm
== NULL
) {
2505 wpa_printf(MSG_DEBUG
,
2506 "SAE: Failed to initialize WPA state machine");
2507 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2511 #endif /* CONFIG_MESH */
2512 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2515 #endif /* CONFIG_SAE */
2517 case WLAN_AUTH_FILS_SK
:
2518 case WLAN_AUTH_FILS_SK_PFS
:
2519 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2520 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2521 auth_alg
, auth_transaction
, status_code
,
2522 handle_auth_fils_finish
);
2524 #endif /* CONFIG_FILS */
2529 os_free(radius_cui
);
2530 hostapd_free_psk_list(psk
);
2532 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2533 auth_transaction
+ 1, resp
, resp_ies
,
2534 resp_ies_len
, "handle-auth");
2536 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2537 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2538 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2539 sta
->added_unassoc
= 0;
2544 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2548 /* get a unique AID */
2550 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2557 for (i
= 0; i
< AID_WORDS
; i
++) {
2558 if (hapd
->sta_aid
[i
] == (u32
) -1)
2560 for (j
= 0; j
< 32; j
++) {
2561 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2569 aid
= i
* 32 + j
+ 1;
2574 hapd
->sta_aid
[i
] |= BIT(j
);
2575 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2580 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2581 const u8
*ssid_ie
, size_t ssid_ie_len
)
2583 if (ssid_ie
== NULL
)
2584 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2586 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2587 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2588 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2590 "Station tried to associate with unknown SSID "
2591 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2592 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2595 return WLAN_STATUS_SUCCESS
;
2599 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2600 const u8
*wmm_ie
, size_t wmm_ie_len
)
2602 sta
->flags
&= ~WLAN_STA_WMM
;
2604 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2605 struct wmm_information_element
*wmm
;
2607 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2608 hostapd_logger(hapd
, sta
->addr
,
2610 HOSTAPD_LEVEL_DEBUG
,
2611 "invalid WMM element in association "
2613 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2616 sta
->flags
|= WLAN_STA_WMM
;
2617 wmm
= (struct wmm_information_element
*) wmm_ie
;
2618 sta
->qosinfo
= wmm
->qos_info
;
2620 return WLAN_STATUS_SUCCESS
;
2623 static u16
check_multi_ap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2624 const u8
*multi_ap_ie
, size_t multi_ap_len
)
2626 u8 multi_ap_value
= 0;
2628 sta
->flags
&= ~WLAN_STA_MULTI_AP
;
2630 if (!hapd
->conf
->multi_ap
)
2631 return WLAN_STATUS_SUCCESS
;
2634 const u8
*multi_ap_subelem
;
2636 multi_ap_subelem
= get_ie(multi_ap_ie
+ 4,
2638 MULTI_AP_SUB_ELEM_TYPE
);
2639 if (multi_ap_subelem
&& multi_ap_subelem
[1] == 1) {
2640 multi_ap_value
= multi_ap_subelem
[2];
2642 hostapd_logger(hapd
, sta
->addr
,
2643 HOSTAPD_MODULE_IEEE80211
,
2645 "Multi-AP IE has missing or invalid Multi-AP subelement");
2646 return WLAN_STATUS_INVALID_IE
;
2650 if (multi_ap_value
&& multi_ap_value
!= MULTI_AP_BACKHAUL_STA
)
2651 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2653 "Multi-AP IE with unexpected value 0x%02x",
2656 if (!(multi_ap_value
& MULTI_AP_BACKHAUL_STA
)) {
2657 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
2658 return WLAN_STATUS_SUCCESS
;
2660 hostapd_logger(hapd
, sta
->addr
,
2661 HOSTAPD_MODULE_IEEE80211
,
2663 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2664 return WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
2667 if (!(hapd
->conf
->multi_ap
& BACKHAUL_BSS
))
2668 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2669 HOSTAPD_LEVEL_DEBUG
,
2670 "Backhaul STA tries to associate with fronthaul-only BSS");
2672 sta
->flags
|= WLAN_STA_MULTI_AP
;
2673 return WLAN_STATUS_SUCCESS
;
2677 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2678 struct ieee802_11_elems
*elems
)
2680 /* Supported rates not used in IEEE 802.11ad/DMG */
2681 if (hapd
->iface
->current_mode
&&
2682 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2683 return WLAN_STATUS_SUCCESS
;
2685 if (!elems
->supp_rates
) {
2686 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2687 HOSTAPD_LEVEL_DEBUG
,
2688 "No supported rates element in AssocReq");
2689 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2692 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2693 sizeof(sta
->supported_rates
)) {
2694 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2695 HOSTAPD_LEVEL_DEBUG
,
2696 "Invalid supported rates element length %d+%d",
2697 elems
->supp_rates_len
,
2698 elems
->ext_supp_rates_len
);
2699 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2702 sta
->supported_rates_len
= merge_byte_arrays(
2703 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2704 elems
->supp_rates
, elems
->supp_rates_len
,
2705 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2707 return WLAN_STATUS_SUCCESS
;
2711 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2712 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2714 #ifdef CONFIG_INTERWORKING
2715 /* check for QoS Map support */
2716 if (ext_capab_ie_len
>= 5) {
2717 if (ext_capab_ie
[4] & 0x01)
2718 sta
->qos_map_enabled
= 1;
2720 #endif /* CONFIG_INTERWORKING */
2722 if (ext_capab_ie_len
> 0) {
2723 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2724 os_free(sta
->ext_capability
);
2725 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2726 if (sta
->ext_capability
) {
2727 sta
->ext_capability
[0] = ext_capab_ie_len
;
2728 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2733 return WLAN_STATUS_SUCCESS
;
2739 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2742 int *groups
= hapd
->conf
->owe_groups
;
2744 if (group
!= 19 && group
!= 20 && group
!= 21)
2750 for (i
= 0; groups
[i
] > 0; i
++) {
2751 if (groups
[i
] == group
)
2759 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2760 struct sta_info
*sta
, const u8
*owe_dh
,
2763 struct wpabuf
*secret
, *pub
, *hkey
;
2765 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2766 const char *info
= "OWE Key Generation";
2770 size_t hash_len
, prime_len
;
2772 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2773 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2774 return WLAN_STATUS_SUCCESS
;
2777 group
= WPA_GET_LE16(owe_dh
);
2778 if (!owe_group_supported(hapd
, group
)) {
2779 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2780 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2784 else if (group
== 20)
2786 else if (group
== 21)
2789 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2791 crypto_ecdh_deinit(sta
->owe_ecdh
);
2792 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2794 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2795 sta
->owe_group
= group
;
2797 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2799 secret
= wpabuf_zeropad(secret
, prime_len
);
2801 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2802 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2804 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2806 /* prk = HKDF-extract(C | A | group, z) */
2808 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2810 wpabuf_clear_free(secret
);
2811 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2814 /* PMKID = Truncate-128(Hash(C | A)) */
2815 addr
[0] = owe_dh
+ 2;
2816 len
[0] = owe_dh_len
- 2;
2817 addr
[1] = wpabuf_head(pub
);
2818 len
[1] = wpabuf_len(pub
);
2820 res
= sha256_vector(2, addr
, len
, pmkid
);
2821 hash_len
= SHA256_MAC_LEN
;
2822 } else if (group
== 20) {
2823 res
= sha384_vector(2, addr
, len
, pmkid
);
2824 hash_len
= SHA384_MAC_LEN
;
2825 } else if (group
== 21) {
2826 res
= sha512_vector(2, addr
, len
, pmkid
);
2827 hash_len
= SHA512_MAC_LEN
;
2830 wpabuf_clear_free(secret
);
2831 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2833 pub
= wpabuf_zeropad(pub
, prime_len
);
2834 if (res
< 0 || !pub
) {
2836 wpabuf_clear_free(secret
);
2837 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2840 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2843 wpabuf_clear_free(secret
);
2844 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2847 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2848 wpabuf_put_buf(hkey
, pub
); /* A */
2850 wpabuf_put_le16(hkey
, group
); /* group */
2852 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2853 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2854 else if (group
== 20)
2855 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2856 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2857 else if (group
== 21)
2858 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2859 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2860 wpabuf_clear_free(hkey
);
2861 wpabuf_clear_free(secret
);
2863 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2865 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2867 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2869 os_free(sta
->owe_pmk
);
2870 sta
->owe_pmk
= os_malloc(hash_len
);
2871 if (!sta
->owe_pmk
) {
2872 os_memset(prk
, 0, SHA512_MAC_LEN
);
2873 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2877 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2878 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2879 else if (group
== 20)
2880 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2881 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2882 else if (group
== 21)
2883 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2884 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2885 os_memset(prk
, 0, SHA512_MAC_LEN
);
2887 os_free(sta
->owe_pmk
);
2888 sta
->owe_pmk
= NULL
;
2889 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2891 sta
->owe_pmk_len
= hash_len
;
2893 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2894 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2895 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2896 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2898 return WLAN_STATUS_SUCCESS
;
2902 u16
owe_validate_request(struct hostapd_data
*hapd
, const u8
*peer
,
2903 const u8
*rsn_ie
, size_t rsn_ie_len
,
2904 const u8
*owe_dh
, size_t owe_dh_len
)
2906 struct wpa_ie_data data
;
2909 if (!rsn_ie
|| rsn_ie_len
< 2) {
2910 wpa_printf(MSG_DEBUG
, "OWE: Invalid RSNE from " MACSTR
,
2912 return WLAN_STATUS_INVALID_IE
;
2917 res
= wpa_parse_wpa_ie_rsn(rsn_ie
, rsn_ie_len
, &data
);
2919 wpa_printf(MSG_DEBUG
, "Failed to parse RSNE from " MACSTR
2920 " (res=%d)", MAC2STR(peer
), res
);
2921 wpa_hexdump(MSG_DEBUG
, "RSNE", rsn_ie
, rsn_ie_len
);
2922 return wpa_res_to_status_code(res
);
2924 if (!(data
.key_mgmt
& WPA_KEY_MGMT_OWE
)) {
2925 wpa_printf(MSG_DEBUG
,
2926 "OWE: Unexpected key mgmt 0x%x from " MACSTR
,
2927 (unsigned int) data
.key_mgmt
, MAC2STR(peer
));
2928 return WLAN_STATUS_AKMP_NOT_VALID
;
2931 wpa_printf(MSG_DEBUG
,
2932 "OWE: No Diffie-Hellman Parameter element from "
2933 MACSTR
, MAC2STR(peer
));
2934 return WLAN_STATUS_AKMP_NOT_VALID
;
2937 return WLAN_STATUS_SUCCESS
;
2941 u16
owe_process_rsn_ie(struct hostapd_data
*hapd
,
2942 struct sta_info
*sta
,
2943 const u8
*rsn_ie
, size_t rsn_ie_len
,
2944 const u8
*owe_dh
, size_t owe_dh_len
)
2947 u8
*owe_buf
, ie
[256 * 2];
2951 if (!rsn_ie
|| rsn_ie_len
< 2) {
2952 wpa_printf(MSG_DEBUG
, "OWE: No RSNE in (Re)AssocReq");
2953 status
= WLAN_STATUS_INVALID_IE
;
2958 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
2961 wpa_printf(MSG_WARNING
,
2962 "OWE: Failed to initialize WPA state machine");
2963 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2968 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2969 hapd
->iface
->freq
, rsn_ie
, rsn_ie_len
,
2970 NULL
, 0, NULL
, 0, owe_dh
, owe_dh_len
);
2971 status
= wpa_res_to_status_code(res
);
2972 if (status
!= WLAN_STATUS_SUCCESS
)
2974 status
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
2975 if (status
!= WLAN_STATUS_SUCCESS
)
2977 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, ie
, sizeof(ie
),
2980 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2984 if (sta
->owe_ecdh
) {
2987 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2989 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2993 /* OWE Diffie-Hellman Parameter element */
2994 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
2995 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
2996 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
2998 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3000 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3001 owe_buf
+= wpabuf_len(pub
);
3003 sta
->external_dh_updated
= 1;
3005 ie_len
= owe_buf
- ie
;
3008 wpa_printf(MSG_DEBUG
, "OWE: Update status %d, ie len %d for peer "
3009 MACSTR
, status
, (unsigned int) ie_len
,
3010 MAC2STR(sta
->addr
));
3011 hostapd_drv_update_dh_ie(hapd
, sta
->addr
, status
,
3012 status
== WLAN_STATUS_SUCCESS
? ie
: NULL
,
3018 #endif /* CONFIG_OWE */
3021 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3022 const u8
*ies
, size_t ies_len
, int reassoc
)
3024 struct ieee802_11_elems elems
;
3028 const u8
*p2p_dev_addr
= NULL
;
3030 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
3031 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3032 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
3033 "association request");
3034 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3037 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
3038 if (resp
!= WLAN_STATUS_SUCCESS
)
3040 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
3041 if (resp
!= WLAN_STATUS_SUCCESS
)
3043 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
3044 if (resp
!= WLAN_STATUS_SUCCESS
)
3046 resp
= copy_supp_rates(hapd
, sta
, &elems
);
3047 if (resp
!= WLAN_STATUS_SUCCESS
)
3050 resp
= check_multi_ap(hapd
, sta
, elems
.multi_ap
, elems
.multi_ap_len
);
3051 if (resp
!= WLAN_STATUS_SUCCESS
)
3054 #ifdef CONFIG_IEEE80211N
3055 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
3056 if (resp
!= WLAN_STATUS_SUCCESS
)
3058 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
3059 !(sta
->flags
& WLAN_STA_HT
)) {
3060 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3061 HOSTAPD_LEVEL_INFO
, "Station does not support "
3062 "mandatory HT PHY - reject association");
3063 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
3065 #endif /* CONFIG_IEEE80211N */
3067 #ifdef CONFIG_IEEE80211AC
3068 if (hapd
->iconf
->ieee80211ac
) {
3069 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
3070 if (resp
!= WLAN_STATUS_SUCCESS
)
3073 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
3074 if (resp
!= WLAN_STATUS_SUCCESS
)
3078 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
3079 !(sta
->flags
& WLAN_STA_VHT
)) {
3080 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3081 HOSTAPD_LEVEL_INFO
, "Station does not support "
3082 "mandatory VHT PHY - reject association");
3083 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
3086 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
3087 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
3088 elems
.vendor_vht_len
);
3089 if (resp
!= WLAN_STATUS_SUCCESS
)
3092 #endif /* CONFIG_IEEE80211AC */
3093 #ifdef CONFIG_IEEE80211AX
3094 if (hapd
->iconf
->ieee80211ax
) {
3095 resp
= copy_sta_he_capab(hapd
, sta
, IEEE80211_MODE_AP
,
3096 elems
.he_capabilities
,
3097 elems
.he_capabilities_len
);
3098 if (resp
!= WLAN_STATUS_SUCCESS
)
3101 #endif /* CONFIG_IEEE80211AX */
3105 wpabuf_free(sta
->p2p_ie
);
3106 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3107 P2P_IE_VENDOR_TYPE
);
3109 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
3111 wpabuf_free(sta
->p2p_ie
);
3114 #endif /* CONFIG_P2P */
3116 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
3117 wpa_ie
= elems
.rsn_ie
;
3118 wpa_ie_len
= elems
.rsn_ie_len
;
3119 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
3121 wpa_ie
= elems
.wpa_ie
;
3122 wpa_ie_len
= elems
.wpa_ie_len
;
3129 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
3130 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
3131 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
3132 "Request - assume WPS is used");
3133 sta
->flags
|= WLAN_STA_WPS
;
3134 wpabuf_free(sta
->wps_ie
);
3135 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3136 WPS_IE_VENDOR_TYPE
);
3137 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
3138 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
3139 sta
->flags
|= WLAN_STA_WPS2
;
3143 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
3144 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
3145 "(Re)Association Request - reject");
3146 return WLAN_STATUS_INVALID_IE
;
3148 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
3149 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
3150 "(Re)Association Request - possible WPS use");
3151 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
3153 #endif /* CONFIG_WPS */
3154 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
3155 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3157 "No WPA/RSN IE in association request");
3158 return WLAN_STATUS_INVALID_IE
;
3161 if (hapd
->conf
->wpa
&& wpa_ie
) {
3165 if (sta
->wpa_sm
== NULL
)
3166 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3169 if (sta
->wpa_sm
== NULL
) {
3170 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3172 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3174 wpa_auth_set_auth_alg(sta
->wpa_sm
, sta
->auth_alg
);
3175 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
3178 elems
.rsnxe
? elems
.rsnxe
- 2 : NULL
,
3179 elems
.rsnxe
? elems
.rsnxe_len
+ 2 : 0,
3180 elems
.mdie
, elems
.mdie_len
,
3181 elems
.owe_dh
, elems
.owe_dh_len
);
3182 resp
= wpa_res_to_status_code(res
);
3183 if (resp
!= WLAN_STATUS_SUCCESS
)
3185 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3186 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3187 !sta
->sa_query_timed_out
&&
3188 sta
->sa_query_count
> 0)
3189 ap_check_sa_query_timeout(hapd
, sta
);
3190 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3191 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3192 !sta
->sa_query_timed_out
&&
3193 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
3195 * STA has already been associated with MFP and SA
3196 * Query timeout has not been reached. Reject the
3197 * association attempt temporarily and start SA Query,
3198 * if one is not pending.
3201 if (sta
->sa_query_count
== 0)
3202 ap_sta_start_sa_query(hapd
, sta
);
3204 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
3207 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
3208 sta
->flags
|= WLAN_STA_MFP
;
3210 sta
->flags
&= ~WLAN_STA_MFP
;
3212 #ifdef CONFIG_IEEE80211R_AP
3213 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
3215 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
3216 "to use association (not "
3217 "re-association) with FT auth_alg",
3218 MAC2STR(sta
->addr
));
3219 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3222 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
3224 if (resp
!= WLAN_STATUS_SUCCESS
)
3227 #endif /* CONFIG_IEEE80211R_AP */
3230 if (wpa_auth_uses_sae(sta
->wpa_sm
) && sta
->sae
&&
3231 sta
->sae
->state
== SAE_ACCEPTED
)
3232 wpa_auth_add_sae_pmkid(sta
->wpa_sm
, sta
->sae
->pmkid
);
3234 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3235 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
3236 struct rsn_pmksa_cache_entry
*sa
;
3237 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
3238 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
3239 wpa_printf(MSG_DEBUG
,
3240 "SAE: No PMKSA cache entry found for "
3241 MACSTR
, MAC2STR(sta
->addr
));
3242 return WLAN_STATUS_INVALID_PMKID
;
3244 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
3245 " using PMKSA caching", MAC2STR(sta
->addr
));
3246 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3247 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
3248 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
3249 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
3250 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
3251 "SAE AKM after non-SAE auth_alg %u",
3252 MAC2STR(sta
->addr
), sta
->auth_alg
);
3253 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
3255 #endif /* CONFIG_SAE */
3258 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3259 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
3261 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
3263 if (resp
!= WLAN_STATUS_SUCCESS
)
3266 #endif /* CONFIG_OWE */
3269 dpp_pfs_free(sta
->dpp_pfs
);
3270 sta
->dpp_pfs
= NULL
;
3272 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3273 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
3274 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
3276 sta
->dpp_pfs
= dpp_pfs_init(
3277 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
3278 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
3279 if (!sta
->dpp_pfs
) {
3280 wpa_printf(MSG_DEBUG
,
3281 "DPP: Could not initialize PFS");
3282 /* Try to continue without PFS */
3286 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
3287 elems
.owe_dh_len
) < 0) {
3288 dpp_pfs_free(sta
->dpp_pfs
);
3289 sta
->dpp_pfs
= NULL
;
3290 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3294 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
3295 sta
->dpp_pfs
->secret
: NULL
);
3297 #endif /* CONFIG_DPP2 */
3299 #ifdef CONFIG_IEEE80211N
3300 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
3301 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
3302 hostapd_logger(hapd
, sta
->addr
,
3303 HOSTAPD_MODULE_IEEE80211
,
3305 "Station tried to use TKIP with HT "
3307 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
3309 #endif /* CONFIG_IEEE80211N */
3311 } else if (hapd
->conf
->osen
) {
3312 if (elems
.osen
== NULL
) {
3314 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3316 "No HS 2.0 OSEN element in association request");
3317 return WLAN_STATUS_INVALID_IE
;
3320 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
3321 if (sta
->wpa_sm
== NULL
)
3322 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3324 if (sta
->wpa_sm
== NULL
) {
3325 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3327 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3329 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
3330 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
3331 return WLAN_STATUS_INVALID_IE
;
3332 #endif /* CONFIG_HS20 */
3334 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
3337 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
3338 #endif /* CONFIG_P2P */
3341 wpabuf_free(sta
->hs20_ie
);
3342 if (elems
.hs20
&& elems
.hs20_len
> 4) {
3345 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
3346 elems
.hs20_len
- 4);
3347 release
= ((elems
.hs20
[4] >> 4) & 0x0f) + 1;
3348 if (release
>= 2 && !wpa_auth_uses_mfp(sta
->wpa_sm
) &&
3349 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3350 wpa_printf(MSG_DEBUG
,
3351 "HS 2.0: PMF not negotiated by release %d station "
3352 MACSTR
, release
, MAC2STR(sta
->addr
));
3353 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
3356 sta
->hs20_ie
= NULL
;
3359 wpabuf_free(sta
->roaming_consortium
);
3360 if (elems
.roaming_cons_sel
)
3361 sta
->roaming_consortium
= wpabuf_alloc_copy(
3362 elems
.roaming_cons_sel
+ 4,
3363 elems
.roaming_cons_sel_len
- 4);
3365 sta
->roaming_consortium
= NULL
;
3366 #endif /* CONFIG_HS20 */
3369 wpabuf_free(sta
->mb_ies
);
3370 if (hapd
->iface
->fst
)
3371 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
3374 #endif /* CONFIG_FST */
3377 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
3379 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
3380 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
3381 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3382 wpa_printf(MSG_INFO
,
3383 "MBO: Reject WPA2 association without PMF");
3384 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3386 #endif /* CONFIG_MBO */
3388 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3389 if (wpa_auth_uses_ocv(sta
->wpa_sm
) &&
3390 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3391 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3392 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)) {
3393 struct wpa_channel_info ci
;
3397 if (hostapd_drv_channel_info(hapd
, &ci
) != 0) {
3398 wpa_printf(MSG_WARNING
,
3399 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3400 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3403 if (get_sta_tx_parameters(sta
->wpa_sm
,
3404 channel_width_to_int(ci
.chanwidth
),
3405 ci
.seg1_idx
, &tx_chanwidth
,
3407 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3409 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
3410 tx_chanwidth
, tx_seg1_idx
) != 0) {
3411 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
3412 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3415 #endif /* CONFIG_FILS && CONFIG_OCV */
3417 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
3418 elems
.supp_op_classes_len
);
3420 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
3421 elems
.rrm_enabled
&&
3422 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
3423 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
3424 sizeof(sta
->rrm_enabled_capa
));
3426 if (elems
.power_capab
) {
3427 sta
->min_tx_power
= elems
.power_capab
[0];
3428 sta
->max_tx_power
= elems
.power_capab
[1];
3429 sta
->power_capab
= 1;
3431 sta
->power_capab
= 0;
3434 return WLAN_STATUS_SUCCESS
;
3438 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
3442 struct ieee80211_mgmt reply
;
3444 os_memset(&reply
, 0, sizeof(reply
));
3445 reply
.frame_control
=
3446 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
3447 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
3448 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
3449 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
3451 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
3452 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
3454 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
3455 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
3460 static int add_associated_sta(struct hostapd_data
*hapd
,
3461 struct sta_info
*sta
, int reassoc
)
3463 struct ieee80211_ht_capabilities ht_cap
;
3464 struct ieee80211_vht_capabilities vht_cap
;
3465 struct ieee80211_he_capabilities he_cap
;
3469 * Remove the STA entry to ensure the STA PS state gets cleared and
3470 * configuration gets updated. This is relevant for cases, such as
3471 * FT-over-the-DS, where a station re-associates back to the same AP but
3472 * skips the authentication flow, or if working with a driver that
3473 * does not support full AP client state.
3475 * Skip this if the STA has already completed FT reassociation and the
3476 * TK has been configured since the TX/RX PN must not be reset to 0 for
3479 * FT-over-the-DS has a special case where the STA entry (and as such,
3480 * the TK) has not yet been configured to the driver depending on which
3481 * driver interface is used. For that case, allow add-STA operation to
3482 * be used (instead of set-STA). This is needed to allow mac80211-based
3483 * drivers to accept the STA parameter configuration. Since this is
3484 * after a new FT-over-DS exchange, a new TK has been derived, so key
3485 * reinstallation is not a concern for this case.
3487 wpa_printf(MSG_DEBUG
, "Add associated STA " MACSTR
3488 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3489 MAC2STR(sta
->addr
), sta
->added_unassoc
, sta
->auth_alg
,
3490 sta
->ft_over_ds
, reassoc
,
3491 !!(sta
->flags
& WLAN_STA_AUTHORIZED
),
3492 wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
),
3493 wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
));
3495 if (!sta
->added_unassoc
&&
3496 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3497 (reassoc
&& sta
->ft_over_ds
&& sta
->auth_alg
== WLAN_AUTH_FT
) ||
3498 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
3499 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
3500 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3501 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
3504 /* Do not allow the FT-over-DS exception to be used more than
3505 * once per authentication exchange to guarantee a new TK is
3507 sta
->ft_over_ds
= 0;
3510 #ifdef CONFIG_IEEE80211N
3511 if (sta
->flags
& WLAN_STA_HT
)
3512 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
3513 #endif /* CONFIG_IEEE80211N */
3514 #ifdef CONFIG_IEEE80211AC
3515 if (sta
->flags
& WLAN_STA_VHT
)
3516 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
3517 #endif /* CONFIG_IEEE80211AC */
3518 #ifdef CONFIG_IEEE80211AX
3519 if (sta
->flags
& WLAN_STA_HE
) {
3520 hostapd_get_he_capab(hapd
, sta
->he_capab
, &he_cap
,
3523 #endif /* CONFIG_IEEE80211AX */
3526 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3527 * will be set when the ACK frame for the (Re)Association Response frame
3528 * is processed (TX status driver event).
3530 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
3531 sta
->supported_rates
, sta
->supported_rates_len
,
3532 sta
->listen_interval
,
3533 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
3534 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
3535 sta
->flags
& WLAN_STA_HE
? &he_cap
: NULL
,
3536 sta
->flags
& WLAN_STA_HE
? sta
->he_capab_len
: 0,
3537 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
3538 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
3540 hostapd_logger(hapd
, sta
->addr
,
3541 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
3542 "Could not %s STA to kernel driver",
3543 set
? "set" : "add");
3545 if (sta
->added_unassoc
) {
3546 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3547 sta
->added_unassoc
= 0;
3553 sta
->added_unassoc
= 0;
3559 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3560 const u8
*addr
, u16 status_code
, int reassoc
,
3561 const u8
*ies
, size_t ies_len
, int rssi
)
3566 struct ieee80211_mgmt
*reply
;
3568 u16 res
= WLAN_STATUS_SUCCESS
;
3570 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
3572 if (sta
&& sta
->fils_hlp_resp
)
3573 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
3576 #endif /* CONFIG_FILS */
3578 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3580 #endif /* CONFIG_OWE */
3582 if (sta
&& sta
->dpp_pfs
)
3583 buflen
+= 5 + sta
->dpp_pfs
->curve
->prime_len
;
3584 #endif /* CONFIG_DPP2 */
3585 buf
= os_zalloc(buflen
);
3587 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3590 reply
= (struct ieee80211_mgmt
*) buf
;
3591 reply
->frame_control
=
3592 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3593 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
3594 WLAN_FC_STYPE_ASSOC_RESP
));
3595 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
3596 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
3597 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3599 send_len
= IEEE80211_HDRLEN
;
3600 send_len
+= sizeof(reply
->u
.assoc_resp
);
3601 reply
->u
.assoc_resp
.capab_info
=
3602 host_to_le16(hostapd_own_capab_info(hapd
));
3603 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
3605 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
3607 /* Supported rates */
3608 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
3609 /* Extended supported rates */
3610 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
3613 if (status_code
== WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
3615 int delta
= hapd
->iconf
->rssi_reject_assoc_rssi
- rssi
;
3617 p
= hostapd_eid_mbo_rssi_assoc_rej(hapd
, p
, buf
+ buflen
- p
,
3620 #endif /* CONFIG_MBO */
3622 #ifdef CONFIG_IEEE80211R_AP
3623 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
3624 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3625 * Transition Information, RSN, [RIC Response] */
3626 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
3628 sta
->auth_alg
, ies
, ies_len
);
3630 wpa_printf(MSG_DEBUG
,
3631 "FT: Failed to write AssocResp IEs");
3632 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3636 #endif /* CONFIG_IEEE80211R_AP */
3638 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3639 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3640 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3641 sta
->auth_alg
== WLAN_AUTH_FILS_PK
))
3642 p
= wpa_auth_write_assoc_resp_fils(sta
->wpa_sm
, p
,
3645 #endif /* CONFIG_FILS */
3648 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3649 (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3650 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
3653 #endif /* CONFIG_OWE */
3655 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
3656 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
3658 #ifdef CONFIG_IEEE80211N
3659 p
= hostapd_eid_ht_capabilities(hapd
, p
);
3660 p
= hostapd_eid_ht_operation(hapd
, p
);
3661 #endif /* CONFIG_IEEE80211N */
3663 #ifdef CONFIG_IEEE80211AC
3664 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
&&
3665 !is_6ghz_op_class(hapd
->iconf
->op_class
)) {
3666 u32 nsts
= 0, sta_nsts
;
3668 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
3669 struct ieee80211_vht_capabilities
*capa
;
3671 nsts
= (hapd
->iface
->conf
->vht_capab
>>
3672 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3673 capa
= sta
->vht_capabilities
;
3674 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
3675 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3677 if (nsts
< sta_nsts
)
3682 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
3683 p
= hostapd_eid_vht_operation(hapd
, p
);
3685 #endif /* CONFIG_IEEE80211AC */
3687 #ifdef CONFIG_IEEE80211AX
3688 if (hapd
->iconf
->ieee80211ax
) {
3689 p
= hostapd_eid_he_capab(hapd
, p
, IEEE80211_MODE_AP
);
3690 p
= hostapd_eid_he_operation(hapd
, p
);
3691 p
= hostapd_eid_spatial_reuse(hapd
, p
);
3692 p
= hostapd_eid_he_mu_edca_parameter_set(hapd
, p
);
3694 #endif /* CONFIG_IEEE80211AX */
3696 p
= hostapd_eid_ext_capab(hapd
, p
);
3697 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
3698 if (sta
&& sta
->qos_map_enabled
)
3699 p
= hostapd_eid_qos_map_set(hapd
, p
);
3702 if (hapd
->iface
->fst_ies
) {
3703 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
3704 wpabuf_len(hapd
->iface
->fst_ies
));
3705 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
3707 #endif /* CONFIG_FST */
3710 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3711 sta
&& sta
->owe_ecdh
&& status_code
== WLAN_STATUS_SUCCESS
&&
3712 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
3715 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3717 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3720 /* OWE Diffie-Hellman Parameter element */
3721 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3722 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3723 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3724 WPA_PUT_LE16(p
, sta
->owe_group
);
3726 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
3727 p
+= wpabuf_len(pub
);
3730 #endif /* CONFIG_OWE */
3733 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3734 sta
&& sta
->dpp_pfs
&& status_code
== WLAN_STATUS_SUCCESS
&&
3735 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
) {
3736 os_memcpy(p
, wpabuf_head(sta
->dpp_pfs
->ie
),
3737 wpabuf_len(sta
->dpp_pfs
->ie
));
3738 p
+= wpabuf_len(sta
->dpp_pfs
->ie
);
3740 #endif /* CONFIG_DPP2 */
3742 #ifdef CONFIG_IEEE80211AC
3743 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
3744 p
= hostapd_eid_vendor_vht(hapd
, p
);
3745 #endif /* CONFIG_IEEE80211AC */
3747 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
3748 p
= hostapd_eid_wmm(hapd
, p
);
3752 ((sta
->flags
& WLAN_STA_WPS
) ||
3753 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
3754 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
3756 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
3757 p
+= wpabuf_len(wps
);
3761 #endif /* CONFIG_WPS */
3763 if (sta
&& (sta
->flags
& WLAN_STA_MULTI_AP
))
3764 p
= hostapd_eid_multi_ap(hapd
, p
);
3767 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
3768 struct wpabuf
*p2p_resp_ie
;
3769 enum p2p_status_code status
;
3770 switch (status_code
) {
3771 case WLAN_STATUS_SUCCESS
:
3772 status
= P2P_SC_SUCCESS
;
3774 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
3775 status
= P2P_SC_FAIL_LIMIT_REACHED
;
3778 status
= P2P_SC_FAIL_INVALID_PARAMS
;
3781 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
3783 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
3784 wpabuf_len(p2p_resp_ie
));
3785 p
+= wpabuf_len(p2p_resp_ie
);
3786 wpabuf_free(p2p_resp_ie
);
3789 #endif /* CONFIG_P2P */
3791 #ifdef CONFIG_P2P_MANAGER
3792 if (hapd
->conf
->p2p
& P2P_MANAGE
)
3793 p
= hostapd_eid_p2p_manage(hapd
, p
);
3794 #endif /* CONFIG_P2P_MANAGER */
3796 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
3798 if (hapd
->conf
->assocresp_elements
&&
3799 (size_t) (buf
+ buflen
- p
) >=
3800 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
3801 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
3802 wpabuf_len(hapd
->conf
->assocresp_elements
));
3803 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
3806 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
3810 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3811 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3812 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
3813 status_code
== WLAN_STATUS_SUCCESS
) {
3814 struct ieee802_11_elems elems
;
3816 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
3817 ParseFailed
|| !elems
.fils_session
) {
3818 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3823 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3824 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
3825 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
3826 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
3827 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
3829 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
3830 buflen
, sta
->fils_hlp_resp
);
3832 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3836 #endif /* CONFIG_FILS */
3838 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
3839 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
3841 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3851 u8
* owe_assoc_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3852 const u8
*owe_dh
, u8 owe_dh_len
,
3853 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
3855 #ifdef CONFIG_TESTING_OPTIONS
3856 if (hapd
->conf
->own_ie_override
) {
3857 wpa_printf(MSG_DEBUG
, "OWE: Using IE override");
3858 *reason
= WLAN_STATUS_SUCCESS
;
3859 return wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3860 owe_buf_len
, NULL
, 0);
3862 #endif /* CONFIG_TESTING_OPTIONS */
3864 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
3865 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
3866 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3867 owe_buf_len
, NULL
, 0);
3868 *reason
= WLAN_STATUS_SUCCESS
;
3872 if (sta
->owe_pmk
&& sta
->external_dh_updated
) {
3873 wpa_printf(MSG_DEBUG
, "OWE: Using previously derived PMK");
3874 *reason
= WLAN_STATUS_SUCCESS
;
3878 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3879 if (*reason
!= WLAN_STATUS_SUCCESS
)
3882 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3883 owe_buf_len
, NULL
, 0);
3885 if (sta
->owe_ecdh
&& owe_buf
) {
3888 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3890 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3894 /* OWE Diffie-Hellman Parameter element */
3895 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3896 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3897 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3899 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3901 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3902 owe_buf
+= wpabuf_len(pub
);
3908 #endif /* CONFIG_OWE */
3913 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3917 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3918 MAC2STR(sta
->addr
));
3919 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3920 if (!sta
->fils_pending_assoc_req
)
3922 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3923 sta
->fils_pending_assoc_is_reassoc
,
3924 sta
->fils_pending_assoc_req
,
3925 sta
->fils_pending_assoc_req_len
, 0);
3926 os_free(sta
->fils_pending_assoc_req
);
3927 sta
->fils_pending_assoc_req
= NULL
;
3928 sta
->fils_pending_assoc_req_len
= 0;
3929 wpabuf_free(sta
->fils_hlp_resp
);
3930 sta
->fils_hlp_resp
= NULL
;
3931 wpabuf_free(sta
->hlp_dhcp_discover
);
3932 sta
->hlp_dhcp_discover
= NULL
;
3935 * Remove the station in case transmission of a success response fails.
3936 * At this point the station was already added associated to the driver.
3938 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3939 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3943 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3945 struct hostapd_data
*hapd
= eloop_ctx
;
3946 struct sta_info
*sta
= eloop_data
;
3948 wpa_printf(MSG_DEBUG
,
3949 "FILS: HLP response timeout - continue with association response for "
3950 MACSTR
, MAC2STR(sta
->addr
));
3951 if (sta
->fils_drv_assoc_finish
)
3952 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3954 fils_hlp_finish_assoc(hapd
, sta
);
3957 #endif /* CONFIG_FILS */
3960 static void handle_assoc(struct hostapd_data
*hapd
,
3961 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3962 int reassoc
, int rssi
)
3964 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3965 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3968 struct sta_info
*sta
;
3970 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3971 char *identity
= NULL
;
3972 char *radius_cui
= NULL
;
3974 int delay_assoc
= 0;
3975 #endif /* CONFIG_FILS */
3977 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3978 sizeof(mgmt
->u
.assoc_req
))) {
3979 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3980 reassoc
, (unsigned long) len
);
3984 #ifdef CONFIG_TESTING_OPTIONS
3986 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3987 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3988 wpa_printf(MSG_INFO
,
3989 "TESTING: ignoring reassoc request from "
3990 MACSTR
, MAC2STR(mgmt
->sa
));
3994 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3995 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3996 wpa_printf(MSG_INFO
,
3997 "TESTING: ignoring assoc request from "
3998 MACSTR
, MAC2STR(mgmt
->sa
));
4002 #endif /* CONFIG_TESTING_OPTIONS */
4004 fc
= le_to_host16(mgmt
->frame_control
);
4005 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4008 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
4009 listen_interval
= le_to_host16(
4010 mgmt
->u
.reassoc_req
.listen_interval
);
4011 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
4012 " capab_info=0x%02x listen_interval=%d current_ap="
4013 MACSTR
" seq_ctrl=0x%x%s",
4014 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
4015 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
4016 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
4017 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
4018 pos
= mgmt
->u
.reassoc_req
.variable
;
4020 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
4021 listen_interval
= le_to_host16(
4022 mgmt
->u
.assoc_req
.listen_interval
);
4023 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
4024 " capab_info=0x%02x listen_interval=%d "
4026 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
4027 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
4028 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
4029 pos
= mgmt
->u
.assoc_req
.variable
;
4032 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4033 #ifdef CONFIG_IEEE80211R_AP
4034 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
4035 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
4036 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
4037 "prior to authentication since it is using "
4038 "over-the-DS FT", MAC2STR(mgmt
->sa
));
4041 * Mark station as authenticated, to avoid adding station
4042 * entry in the driver as associated and not authenticated
4044 sta
->flags
|= WLAN_STA_AUTH
;
4046 #endif /* CONFIG_IEEE80211R_AP */
4047 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
4048 if (hapd
->iface
->current_mode
&&
4049 hapd
->iface
->current_mode
->mode
==
4050 HOSTAPD_MODE_IEEE80211AD
) {
4052 u32 session_timeout
, acct_interim_interval
;
4053 struct vlan_description vlan_id
;
4055 acl_res
= ieee802_11_allowed_address(
4056 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
4057 &session_timeout
, &acct_interim_interval
,
4058 &vlan_id
, &psk
, &identity
, &radius_cui
, 0);
4059 if (acl_res
== HOSTAPD_ACL_REJECT
) {
4060 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
4061 "Ignore Association Request frame from "
4062 MACSTR
" due to ACL reject",
4064 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4067 if (acl_res
== HOSTAPD_ACL_PENDING
)
4070 /* DMG/IEEE 802.11ad does not use authentication.
4071 * Allocate sta entry upon association. */
4072 sta
= ap_sta_add(hapd
, mgmt
->sa
);
4074 hostapd_logger(hapd
, mgmt
->sa
,
4075 HOSTAPD_MODULE_IEEE80211
,
4077 "Failed to add STA");
4078 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4082 acl_res
= ieee802_11_set_radius_info(
4083 hapd
, sta
, acl_res
, session_timeout
,
4084 acct_interim_interval
, &vlan_id
, &psk
,
4085 &identity
, &radius_cui
);
4087 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4091 hostapd_logger(hapd
, sta
->addr
,
4092 HOSTAPD_MODULE_IEEE80211
,
4093 HOSTAPD_LEVEL_DEBUG
,
4094 "Skip authentication for DMG/IEEE 802.11ad");
4095 sta
->flags
|= WLAN_STA_AUTH
;
4096 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
4097 sta
->auth_alg
= WLAN_AUTH_OPEN
;
4099 hostapd_logger(hapd
, mgmt
->sa
,
4100 HOSTAPD_MODULE_IEEE80211
,
4102 "Station tried to associate before authentication (aid=%d flags=0x%x)",
4103 sta
? sta
->aid
: -1,
4104 sta
? sta
->flags
: 0);
4105 send_deauth(hapd
, mgmt
->sa
,
4106 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
4111 if ((fc
& WLAN_FC_RETRY
) &&
4112 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4113 sta
->last_seq_ctrl
== seq_ctrl
&&
4114 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4115 WLAN_FC_STYPE_ASSOC_REQ
)) {
4116 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4117 HOSTAPD_LEVEL_DEBUG
,
4118 "Drop repeated association frame seq_ctrl=0x%x",
4122 sta
->last_seq_ctrl
= seq_ctrl
;
4123 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4124 WLAN_FC_STYPE_ASSOC_REQ
;
4126 if (hapd
->tkip_countermeasures
) {
4127 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4131 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
4132 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4133 HOSTAPD_LEVEL_DEBUG
,
4134 "Too large Listen Interval (%d)",
4136 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
4141 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
4142 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4146 if (hapd
->iconf
->rssi_reject_assoc_rssi
&& rssi
&&
4147 rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
&&
4148 (sta
->auth_rssi
== 0 ||
4149 sta
->auth_rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
)) {
4150 resp
= WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
;
4153 #endif /* CONFIG_MBO */
4156 * sta->capability is used in check_assoc_ies() for RRM enabled
4157 * capability element.
4159 sta
->capability
= capab_info
;
4162 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4163 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4164 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4167 /* The end of the payload is encrypted. Need to decrypt it
4168 * before parsing. */
4170 tmp
= os_memdup(pos
, left
);
4172 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4176 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
4179 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4185 #endif /* CONFIG_FILS */
4187 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
4189 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
4190 if (resp
!= WLAN_STATUS_SUCCESS
)
4193 if (hostapd_get_aid(hapd
, sta
) < 0) {
4194 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4195 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
4196 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4200 sta
->listen_interval
= listen_interval
;
4202 if (hapd
->iface
->current_mode
&&
4203 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
4204 sta
->flags
|= WLAN_STA_NONERP
;
4205 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
4206 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
4207 sta
->flags
&= ~WLAN_STA_NONERP
;
4211 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
4212 sta
->nonerp_set
= 1;
4213 hapd
->iface
->num_sta_non_erp
++;
4214 if (hapd
->iface
->num_sta_non_erp
== 1)
4215 ieee802_11_set_beacons(hapd
->iface
);
4218 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
4219 !sta
->no_short_slot_time_set
) {
4220 sta
->no_short_slot_time_set
= 1;
4221 hapd
->iface
->num_sta_no_short_slot_time
++;
4222 if (hapd
->iface
->current_mode
&&
4223 hapd
->iface
->current_mode
->mode
==
4224 HOSTAPD_MODE_IEEE80211G
&&
4225 hapd
->iface
->num_sta_no_short_slot_time
== 1)
4226 ieee802_11_set_beacons(hapd
->iface
);
4229 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
4230 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
4232 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
4234 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
4235 !sta
->no_short_preamble_set
) {
4236 sta
->no_short_preamble_set
= 1;
4237 hapd
->iface
->num_sta_no_short_preamble
++;
4238 if (hapd
->iface
->current_mode
&&
4239 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
4240 && hapd
->iface
->num_sta_no_short_preamble
== 1)
4241 ieee802_11_set_beacons(hapd
->iface
);
4244 #ifdef CONFIG_IEEE80211N
4245 update_ht_state(hapd
, sta
);
4246 #endif /* CONFIG_IEEE80211N */
4248 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4249 HOSTAPD_LEVEL_DEBUG
,
4250 "association OK (aid %d)", sta
->aid
);
4251 /* Station will be marked associated, after it acknowledges AssocResp
4253 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
4255 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
4256 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
4257 "SA Query procedure", reassoc
? "re" : "");
4258 /* TODO: Send a protected Disassociate frame to the STA using
4259 * the old key and Reason Code "Previous Authentication no
4260 * longer valid". Make sure this is only sent protected since
4261 * unprotected frame would be received by the STA that is now
4262 * trying to associate.
4266 /* Make sure that the previously registered inactivity timer will not
4267 * remove the STA immediately. */
4268 sta
->timeout_next
= STA_NULLFUNC
;
4270 #ifdef CONFIG_TAXONOMY
4271 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
4272 #endif /* CONFIG_TAXONOMY */
4274 sta
->pending_wds_enable
= 0;
4277 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4278 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4279 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4280 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
4283 #endif /* CONFIG_FILS */
4287 os_free(radius_cui
);
4288 hostapd_free_psk_list(psk
);
4291 * In case of a successful response, add the station to the driver.
4292 * Otherwise, the kernel may ignore Data frames before we process the
4293 * ACK frame (TX status). In case of a failure, this station will be
4296 * Note that this is not compliant with the IEEE 802.11 standard that
4297 * states that a non-AP station should transition into the
4298 * authenticated/associated state only after the station acknowledges
4299 * the (Re)Association Response frame. However, still do this as:
4301 * 1. In case the station does not acknowledge the (Re)Association
4302 * Response frame, it will be removed.
4303 * 2. Data frames will be dropped in the kernel until the station is
4304 * set into authorized state, and there are no significant known
4305 * issues with processing other non-Data Class 3 frames during this
4308 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&&
4309 add_associated_sta(hapd
, sta
, reassoc
))
4310 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4313 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
&&
4314 eloop_is_timeout_registered(fils_hlp_timeout
, hapd
, sta
) &&
4315 sta
->fils_pending_assoc_req
) {
4316 /* Do not reschedule fils_hlp_timeout in case the station
4317 * retransmits (Re)Association Request frame while waiting for
4318 * the previously started FILS HLP wait, so that the timeout can
4319 * be determined from the first pending attempt. */
4320 wpa_printf(MSG_DEBUG
,
4321 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4322 MACSTR
, MAC2STR(sta
->addr
));
4327 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4328 os_free(sta
->fils_pending_assoc_req
);
4329 sta
->fils_pending_assoc_req
= NULL
;
4330 sta
->fils_pending_assoc_req_len
= 0;
4331 wpabuf_free(sta
->fils_hlp_resp
);
4332 sta
->fils_hlp_resp
= NULL
;
4334 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
4335 sta
->fils_pending_assoc_req
= tmp
;
4336 sta
->fils_pending_assoc_req_len
= left
;
4337 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
4338 sta
->fils_drv_assoc_finish
= 0;
4339 wpa_printf(MSG_DEBUG
,
4340 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4341 MACSTR
, MAC2STR(sta
->addr
));
4342 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4343 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
4344 fils_hlp_timeout
, hapd
, sta
);
4347 #endif /* CONFIG_FILS */
4349 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
4354 * Remove the station in case tranmission of a success response fails
4355 * (the STA was added associated to the driver) or if the station was
4356 * previously added unassociated.
4358 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
4359 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
4360 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4361 sta
->added_unassoc
= 0;
4366 static void handle_disassoc(struct hostapd_data
*hapd
,
4367 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4369 struct sta_info
*sta
;
4371 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
4372 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
4373 (unsigned long) len
);
4377 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
4379 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4381 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4383 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
4388 ap_sta_set_authorized(hapd
, sta
, 0);
4389 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4390 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
4391 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
4392 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4393 HOSTAPD_LEVEL_INFO
, "disassociated");
4394 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4395 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4396 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4398 accounting_sta_stop(hapd
, sta
);
4399 ieee802_1x_free_station(hapd
, sta
);
4401 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
4402 ap_sta_ip6addr_del(hapd
, sta
);
4403 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4404 sta
->added_unassoc
= 0;
4406 if (sta
->timeout_next
== STA_NULLFUNC
||
4407 sta
->timeout_next
== STA_DISASSOC
) {
4408 sta
->timeout_next
= STA_DEAUTH
;
4409 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
4410 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
4414 mlme_disassociate_indication(
4415 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4417 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4418 * disassociation. */
4419 if (hapd
->iface
->current_mode
&&
4420 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
4421 sta
->flags
&= ~WLAN_STA_AUTH
;
4422 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4423 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4424 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4425 ap_free_sta(hapd
, sta
);
4430 static void handle_deauth(struct hostapd_data
*hapd
,
4431 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4433 struct sta_info
*sta
;
4435 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
4436 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
4437 "payload (len=%lu)", (unsigned long) len
);
4441 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
4443 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
4445 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4447 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
4448 "to deauthenticate, but it is not authenticated",
4453 ap_sta_set_authorized(hapd
, sta
, 0);
4454 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4455 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
4456 WLAN_STA_ASSOC_REQ_OK
);
4457 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4458 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4459 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4460 mlme_deauthenticate_indication(
4461 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
4462 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4463 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4464 ap_free_sta(hapd
, sta
);
4468 static void handle_beacon(struct hostapd_data
*hapd
,
4469 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4470 struct hostapd_frame_info
*fi
)
4472 struct ieee802_11_elems elems
;
4474 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
4475 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
4476 (unsigned long) len
);
4480 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
4481 len
- (IEEE80211_HDRLEN
+
4482 sizeof(mgmt
->u
.beacon
)), &elems
,
4485 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
4489 static int robust_action_frame(u8 category
)
4491 return category
!= WLAN_ACTION_PUBLIC
&&
4492 category
!= WLAN_ACTION_HT
;
4496 static int handle_action(struct hostapd_data
*hapd
,
4497 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4500 struct sta_info
*sta
;
4501 u8
*action __maybe_unused
;
4503 if (len
< IEEE80211_HDRLEN
+ 2 + 1) {
4504 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4505 HOSTAPD_LEVEL_DEBUG
,
4506 "handle_action - too short payload (len=%lu)",
4507 (unsigned long) len
);
4511 action
= (u8
*) &mgmt
->u
.action
.u
;
4512 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
4513 " da " MACSTR
" len %d freq %u",
4514 mgmt
->u
.action
.category
, *action
,
4515 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) len
, freq
);
4517 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4519 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
4520 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
4521 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
4522 "frame (category=%u) from unassociated STA " MACSTR
,
4523 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
4527 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
4528 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
4529 robust_action_frame(mgmt
->u
.action
.category
)) {
4530 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4531 HOSTAPD_LEVEL_DEBUG
,
4532 "Dropped unprotected Robust Action frame from "
4538 u16 fc
= le_to_host16(mgmt
->frame_control
);
4539 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4541 if ((fc
& WLAN_FC_RETRY
) &&
4542 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4543 sta
->last_seq_ctrl
== seq_ctrl
&&
4544 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
4545 hostapd_logger(hapd
, sta
->addr
,
4546 HOSTAPD_MODULE_IEEE80211
,
4547 HOSTAPD_LEVEL_DEBUG
,
4548 "Drop repeated action frame seq_ctrl=0x%x",
4553 sta
->last_seq_ctrl
= seq_ctrl
;
4554 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
4557 switch (mgmt
->u
.action
.category
) {
4558 #ifdef CONFIG_IEEE80211R_AP
4559 case WLAN_ACTION_FT
:
4561 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
4562 len
- IEEE80211_HDRLEN
))
4565 #endif /* CONFIG_IEEE80211R_AP */
4566 case WLAN_ACTION_WMM
:
4567 hostapd_wmm_action(hapd
, mgmt
, len
);
4569 case WLAN_ACTION_SA_QUERY
:
4570 ieee802_11_sa_query_action(hapd
, mgmt
, len
);
4572 #ifdef CONFIG_WNM_AP
4573 case WLAN_ACTION_WNM
:
4574 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
4576 #endif /* CONFIG_WNM_AP */
4578 case WLAN_ACTION_FST
:
4579 if (hapd
->iface
->fst
)
4580 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
4582 wpa_printf(MSG_DEBUG
,
4583 "FST: Ignore FST Action frame - no FST attached");
4585 #endif /* CONFIG_FST */
4586 case WLAN_ACTION_PUBLIC
:
4587 case WLAN_ACTION_PROTECTED_DUAL
:
4588 #ifdef CONFIG_IEEE80211N
4589 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4590 mgmt
->u
.action
.u
.public_action
.action
==
4591 WLAN_PA_20_40_BSS_COEX
) {
4592 hostapd_2040_coex_action(hapd
, mgmt
, len
);
4595 #endif /* CONFIG_IEEE80211N */
4597 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4598 mgmt
->u
.action
.u
.vs_public_action
.action
==
4599 WLAN_PA_VENDOR_SPECIFIC
&&
4600 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4602 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4604 const u8
*pos
, *end
;
4606 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
4607 end
= ((const u8
*) mgmt
) + len
;
4608 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
4612 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4613 (mgmt
->u
.action
.u
.public_action
.action
==
4614 WLAN_PA_GAS_INITIAL_RESP
||
4615 mgmt
->u
.action
.u
.public_action
.action
==
4616 WLAN_PA_GAS_COMEBACK_RESP
)) {
4617 const u8
*pos
, *end
;
4619 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
4620 end
= ((const u8
*) mgmt
) + len
;
4621 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
4622 mgmt
->u
.action
.category
,
4623 pos
, end
- pos
, hapd
->iface
->freq
);
4626 #endif /* CONFIG_DPP */
4627 if (hapd
->public_action_cb
) {
4628 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
4632 if (hapd
->public_action_cb2
) {
4633 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
4637 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
4640 case WLAN_ACTION_VENDOR_SPECIFIC
:
4641 if (hapd
->vendor_action_cb
) {
4642 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
4644 hapd
->iface
->freq
) == 0)
4648 case WLAN_ACTION_RADIO_MEASUREMENT
:
4649 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
4653 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4654 HOSTAPD_LEVEL_DEBUG
,
4655 "handle_action - unknown action category %d or invalid "
4657 mgmt
->u
.action
.category
);
4658 if (!is_multicast_ether_addr(mgmt
->da
) &&
4659 !(mgmt
->u
.action
.category
& 0x80) &&
4660 !is_multicast_ether_addr(mgmt
->sa
)) {
4661 struct ieee80211_mgmt
*resp
;
4664 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4665 * Return the Action frame to the source without change
4666 * except that MSB of the Category set to 1.
4668 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
4669 "frame back to sender");
4670 resp
= os_memdup(mgmt
, len
);
4673 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
4674 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
4675 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
4676 resp
->u
.action
.category
|= 0x80;
4678 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
4679 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
4690 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4691 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4693 * @buf: management frame data (starting from IEEE 802.11 header)
4694 * @len: length of frame data in octets
4695 * @fi: meta data about received frame (signal level, etc.)
4697 * Process all incoming IEEE 802.11 management frames. This will be called for
4698 * each frame received from the kernel driver through wlan#ap interface. In
4699 * addition, it can be called to re-inserted pending frames (e.g., when using
4700 * external RADIUS server as an MAC ACL).
4702 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4703 struct hostapd_frame_info
*fi
)
4705 struct ieee80211_mgmt
*mgmt
;
4709 int ssi_signal
= fi
? fi
->ssi_signal
: 0;
4717 freq
= hapd
->iface
->freq
;
4719 mgmt
= (struct ieee80211_mgmt
*) buf
;
4720 fc
= le_to_host16(mgmt
->frame_control
);
4721 stype
= WLAN_FC_GET_STYPE(fc
);
4723 if (is_multicast_ether_addr(mgmt
->sa
) ||
4724 is_zero_ether_addr(mgmt
->sa
) ||
4725 os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
4726 /* Do not process any frames with unexpected/invalid SA so that
4727 * we do not add any state for unexpected STA addresses or end
4728 * up sending out frames to unexpected destination. */
4729 wpa_printf(MSG_DEBUG
, "MGMT: Invalid SA=" MACSTR
4730 " in received frame - ignore this frame silently",
4735 if (stype
== WLAN_FC_STYPE_BEACON
) {
4736 handle_beacon(hapd
, mgmt
, len
, fi
);
4740 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
4742 /* Invitation responses can be sent with the peer MAC as BSSID */
4743 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
4744 stype
== WLAN_FC_STYPE_ACTION
) &&
4745 #endif /* CONFIG_P2P */
4747 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
4748 #endif /* CONFIG_MESH */
4749 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4750 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
4751 MAC2STR(mgmt
->bssid
));
4756 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
4757 handle_probe_req(hapd
, mgmt
, len
, ssi_signal
);
4761 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
4762 stype
!= WLAN_FC_STYPE_ACTION
) &&
4763 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4764 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4765 HOSTAPD_LEVEL_DEBUG
,
4766 "MGMT: DA=" MACSTR
" not our address",
4771 if (hapd
->iconf
->track_sta_max_num
)
4772 sta_track_add(hapd
->iface
, mgmt
->sa
, ssi_signal
);
4775 case WLAN_FC_STYPE_AUTH
:
4776 wpa_printf(MSG_DEBUG
, "mgmt::auth");
4777 handle_auth(hapd
, mgmt
, len
, ssi_signal
, 0);
4780 case WLAN_FC_STYPE_ASSOC_REQ
:
4781 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
4782 handle_assoc(hapd
, mgmt
, len
, 0, ssi_signal
);
4785 case WLAN_FC_STYPE_REASSOC_REQ
:
4786 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
4787 handle_assoc(hapd
, mgmt
, len
, 1, ssi_signal
);
4790 case WLAN_FC_STYPE_DISASSOC
:
4791 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
4792 handle_disassoc(hapd
, mgmt
, len
);
4795 case WLAN_FC_STYPE_DEAUTH
:
4796 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
4797 handle_deauth(hapd
, mgmt
, len
);
4800 case WLAN_FC_STYPE_ACTION
:
4801 wpa_printf(MSG_DEBUG
, "mgmt::action");
4802 ret
= handle_action(hapd
, mgmt
, len
, freq
);
4805 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4806 HOSTAPD_LEVEL_DEBUG
,
4807 "unknown mgmt frame subtype %d", stype
);
4815 static void handle_auth_cb(struct hostapd_data
*hapd
,
4816 const struct ieee80211_mgmt
*mgmt
,
4819 u16 auth_alg
, auth_transaction
, status_code
;
4820 struct sta_info
*sta
;
4822 sta
= ap_get_sta(hapd
, mgmt
->da
);
4824 wpa_printf(MSG_DEBUG
, "handle_auth_cb: STA " MACSTR
4830 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4831 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4832 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
4835 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4836 HOSTAPD_LEVEL_NOTICE
,
4837 "did not acknowledge authentication response");
4841 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
4842 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
4843 (unsigned long) len
);
4847 if (status_code
== WLAN_STATUS_SUCCESS
&&
4848 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
4849 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
4850 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4851 HOSTAPD_LEVEL_INFO
, "authenticated");
4852 sta
->flags
|= WLAN_STA_AUTH
;
4853 if (sta
->added_unassoc
)
4854 hostapd_set_sta_flags(hapd
, sta
);
4859 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
4860 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4861 sta
->added_unassoc
= 0;
4866 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
4867 struct sta_info
*sta
,
4871 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
4873 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
4876 for (i
= 0; i
< 4; i
++) {
4877 if (ssid
->wep
.key
[i
] &&
4878 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
4879 i
== ssid
->wep
.idx
, NULL
, 0,
4880 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
4881 wpa_printf(MSG_WARNING
,
4882 "Could not set WEP keys for WDS interface; %s",
4890 static void handle_assoc_cb(struct hostapd_data
*hapd
,
4891 const struct ieee80211_mgmt
*mgmt
,
4892 size_t len
, int reassoc
, int ok
)
4895 struct sta_info
*sta
;
4898 sta
= ap_get_sta(hapd
, mgmt
->da
);
4900 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4905 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4906 sizeof(mgmt
->u
.assoc_resp
))) {
4907 wpa_printf(MSG_INFO
,
4908 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4909 reassoc
, (unsigned long) len
);
4910 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4915 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4917 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4920 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4921 HOSTAPD_LEVEL_DEBUG
,
4922 "did not acknowledge association response");
4923 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4924 /* The STA is added only in case of SUCCESS */
4925 if (status
== WLAN_STATUS_SUCCESS
)
4926 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4931 if (status
!= WLAN_STATUS_SUCCESS
)
4934 /* Stop previous accounting session, if one is started, and allocate
4935 * new session id for the new session. */
4936 accounting_sta_stop(hapd
, sta
);
4938 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4940 "associated (aid %d)",
4943 if (sta
->flags
& WLAN_STA_ASSOC
)
4945 sta
->flags
|= WLAN_STA_ASSOC
;
4946 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4947 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4948 !hapd
->conf
->osen
) ||
4949 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4950 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4951 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4952 sta
->auth_alg
== WLAN_AUTH_FT
) {
4954 * Open, static WEP, FT protocol, or FILS; no separate
4955 * authorization step.
4957 ap_sta_set_authorized(hapd
, sta
, 1);
4961 mlme_reassociate_indication(hapd
, sta
);
4963 mlme_associate_indication(hapd
, sta
);
4965 sta
->sa_query_timed_out
= 0;
4967 if (sta
->eapol_sm
== NULL
) {
4969 * This STA does not use RADIUS server for EAP authentication,
4970 * so bind it to the selected VLAN interface now, since the
4971 * interface selection is not going to change anymore.
4973 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4975 } else if (sta
->vlan_id
) {
4976 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4977 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4981 hostapd_set_sta_flags(hapd
, sta
);
4983 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4984 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4985 MACSTR
" based on pending request",
4986 MAC2STR(sta
->addr
));
4987 sta
->pending_wds_enable
= 0;
4988 sta
->flags
|= WLAN_STA_WDS
;
4991 if (sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_MULTI_AP
)) {
4993 char ifname_wds
[IFNAMSIZ
+ 1];
4995 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4997 MAC2STR(sta
->addr
), sta
->aid
);
4998 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
5001 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
5004 if (sta
->auth_alg
== WLAN_AUTH_FT
)
5005 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
5007 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
5008 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
5009 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
5012 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
5013 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
5014 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
5015 fils_set_tk(sta
->wpa_sm
) < 0) {
5016 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
5017 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
5018 WLAN_REASON_UNSPECIFIED
);
5021 #endif /* CONFIG_FILS */
5023 if (sta
->pending_eapol_rx
) {
5024 struct os_reltime now
, age
;
5026 os_get_reltime(&now
);
5027 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
5028 if (age
.sec
== 0 && age
.usec
< 200000) {
5029 wpa_printf(MSG_DEBUG
,
5030 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
5031 MAC2STR(sta
->addr
));
5034 wpabuf_head(sta
->pending_eapol_rx
->buf
),
5035 wpabuf_len(sta
->pending_eapol_rx
->buf
));
5037 wpabuf_free(sta
->pending_eapol_rx
->buf
);
5038 os_free(sta
->pending_eapol_rx
);
5039 sta
->pending_eapol_rx
= NULL
;
5044 static void handle_deauth_cb(struct hostapd_data
*hapd
,
5045 const struct ieee80211_mgmt
*mgmt
,
5048 struct sta_info
*sta
;
5049 if (is_multicast_ether_addr(mgmt
->da
))
5051 sta
= ap_get_sta(hapd
, mgmt
->da
);
5053 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
5054 " not found", MAC2STR(mgmt
->da
));
5058 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
5059 MAC2STR(sta
->addr
));
5061 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
5062 "deauth", MAC2STR(sta
->addr
));
5064 ap_sta_deauth_cb(hapd
, sta
);
5068 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
5069 const struct ieee80211_mgmt
*mgmt
,
5072 struct sta_info
*sta
;
5073 if (is_multicast_ether_addr(mgmt
->da
))
5075 sta
= ap_get_sta(hapd
, mgmt
->da
);
5077 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
5078 " not found", MAC2STR(mgmt
->da
));
5082 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
5083 MAC2STR(sta
->addr
));
5085 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
5086 "disassoc", MAC2STR(sta
->addr
));
5088 ap_sta_disassoc_cb(hapd
, sta
);
5092 static void handle_action_cb(struct hostapd_data
*hapd
,
5093 const struct ieee80211_mgmt
*mgmt
,
5096 struct sta_info
*sta
;
5097 const struct rrm_measurement_report_element
*report
;
5099 if (is_multicast_ether_addr(mgmt
->da
))
5102 if (len
>= IEEE80211_HDRLEN
+ 6 &&
5103 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5104 mgmt
->u
.action
.u
.vs_public_action
.action
==
5105 WLAN_PA_VENDOR_SPECIFIC
&&
5106 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
5108 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
5110 const u8
*pos
, *end
;
5112 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
5113 end
= ((const u8
*) mgmt
) + len
;
5114 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
5117 if (len
>= IEEE80211_HDRLEN
+ 2 &&
5118 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5119 (mgmt
->u
.action
.u
.public_action
.action
==
5120 WLAN_PA_GAS_INITIAL_REQ
||
5121 mgmt
->u
.action
.u
.public_action
.action
==
5122 WLAN_PA_GAS_COMEBACK_REQ
)) {
5123 const u8
*pos
, *end
;
5125 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
5126 end
= ((const u8
*) mgmt
) + len
;
5127 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
5130 #endif /* CONFIG_DPP */
5131 sta
= ap_get_sta(hapd
, mgmt
->da
);
5133 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
5134 " not found", MAC2STR(mgmt
->da
));
5138 if (len
< 24 + 5 + sizeof(*report
))
5140 report
= (const struct rrm_measurement_report_element
*)
5141 &mgmt
->u
.action
.u
.rrm
.variable
[2];
5142 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
5143 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
5144 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
5146 report
->type
== MEASURE_TYPE_BEACON
)
5147 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
5152 * ieee802_11_mgmt_cb - Process management frame TX status callback
5153 * @hapd: hostapd BSS data structure (the BSS from which the management frame
5155 * @buf: management frame data (starting from IEEE 802.11 header)
5156 * @len: length of frame data in octets
5157 * @stype: management frame subtype from frame control field
5158 * @ok: Whether the frame was ACK'ed
5160 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
5163 const struct ieee80211_mgmt
*mgmt
;
5164 mgmt
= (const struct ieee80211_mgmt
*) buf
;
5166 #ifdef CONFIG_TESTING_OPTIONS
5167 if (hapd
->ext_mgmt_frame_handling
) {
5168 size_t hex_len
= 2 * len
+ 1;
5169 char *hex
= os_malloc(hex_len
);
5172 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
5173 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
5174 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
5180 #endif /* CONFIG_TESTING_OPTIONS */
5183 case WLAN_FC_STYPE_AUTH
:
5184 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
5185 handle_auth_cb(hapd
, mgmt
, len
, ok
);
5187 case WLAN_FC_STYPE_ASSOC_RESP
:
5188 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
5189 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
5191 case WLAN_FC_STYPE_REASSOC_RESP
:
5192 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
5193 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
5195 case WLAN_FC_STYPE_PROBE_RESP
:
5196 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
5198 case WLAN_FC_STYPE_DEAUTH
:
5199 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
5200 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
5202 case WLAN_FC_STYPE_DISASSOC
:
5203 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
5204 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
5206 case WLAN_FC_STYPE_ACTION
:
5207 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
5208 handle_action_cb(hapd
, mgmt
, len
, ok
);
5211 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
5217 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
5224 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
5225 char *buf
, size_t buflen
)
5232 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
5233 const u8
*buf
, size_t len
, int ack
)
5235 struct sta_info
*sta
;
5236 struct hostapd_iface
*iface
= hapd
->iface
;
5238 sta
= ap_get_sta(hapd
, addr
);
5239 if (sta
== NULL
&& iface
->num_bss
> 1) {
5241 for (j
= 0; j
< iface
->num_bss
; j
++) {
5242 hapd
= iface
->bss
[j
];
5243 sta
= ap_get_sta(hapd
, addr
);
5248 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
5250 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
5251 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
5252 "activity poll", MAC2STR(sta
->addr
),
5253 ack
? "ACKed" : "did not ACK");
5255 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5258 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
5262 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
5263 const u8
*data
, size_t len
, int ack
)
5265 struct sta_info
*sta
;
5266 struct hostapd_iface
*iface
= hapd
->iface
;
5268 sta
= ap_get_sta(hapd
, dst
);
5269 if (sta
== NULL
&& iface
->num_bss
> 1) {
5271 for (j
= 0; j
< iface
->num_bss
; j
++) {
5272 hapd
= iface
->bss
[j
];
5273 sta
= ap_get_sta(hapd
, dst
);
5278 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
5279 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
5280 MACSTR
" that is not currently associated",
5285 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
5289 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
5291 struct sta_info
*sta
;
5292 struct hostapd_iface
*iface
= hapd
->iface
;
5294 sta
= ap_get_sta(hapd
, addr
);
5295 if (sta
== NULL
&& iface
->num_bss
> 1) {
5297 for (j
= 0; j
< iface
->num_bss
; j
++) {
5298 hapd
= iface
->bss
[j
];
5299 sta
= ap_get_sta(hapd
, addr
);
5306 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
5307 MAC2STR(sta
->addr
));
5308 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
5311 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
5312 "activity poll", MAC2STR(sta
->addr
));
5313 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5317 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
5320 struct sta_info
*sta
;
5322 sta
= ap_get_sta(hapd
, src
);
5324 ((sta
->flags
& WLAN_STA_ASSOC
) ||
5325 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
5326 if (!hapd
->conf
->wds_sta
)
5329 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
5330 WLAN_STA_ASSOC_REQ_OK
) {
5331 wpa_printf(MSG_DEBUG
,
5332 "Postpone 4-address WDS mode enabling for STA "
5333 MACSTR
" since TX status for AssocResp is not yet known",
5334 MAC2STR(sta
->addr
));
5335 sta
->pending_wds_enable
= 1;
5339 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
5341 char ifname_wds
[IFNAMSIZ
+ 1];
5343 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
5344 "STA " MACSTR
" (aid %u)",
5345 MAC2STR(sta
->addr
), sta
->aid
);
5346 sta
->flags
|= WLAN_STA_WDS
;
5347 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
5348 sta
->addr
, sta
->aid
, 1);
5350 hostapd_set_wds_encryption(hapd
, sta
,
5356 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
5357 MACSTR
, MAC2STR(src
));
5358 if (is_multicast_ether_addr(src
) || is_zero_ether_addr(src
) ||
5359 os_memcmp(src
, hapd
->own_addr
, ETH_ALEN
) == 0) {
5360 /* Broadcast bit set in SA or unexpected SA?! Ignore the frame
5365 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
5366 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
5367 "already been sent, but no TX status yet known - "
5368 "ignore Class 3 frame issue with " MACSTR
,
5373 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
5374 hostapd_drv_sta_disassoc(
5376 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5378 hostapd_drv_sta_deauth(
5380 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5384 #endif /* CONFIG_NATIVE_WINDOWS */