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
;
414 rx_id
= sta
->sae
->tmp
->pw_id
;
416 for (pw
= hapd
->conf
->sae_passwords
; pw
; pw
= pw
->next
) {
417 if (!is_broadcast_ether_addr(pw
->peer_addr
) &&
418 os_memcmp(pw
->peer_addr
, sta
->addr
, ETH_ALEN
) != 0)
420 if ((rx_id
&& !pw
->identifier
) || (!rx_id
&& pw
->identifier
))
422 if (rx_id
&& pw
->identifier
&&
423 os_strcmp(rx_id
, pw
->identifier
) != 0)
425 password
= pw
->password
;
429 password
= hapd
->conf
->ssid
.wpa_passphrase
;
431 wpa_printf(MSG_DEBUG
, "SAE: No password available");
436 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
437 (u8
*) password
, os_strlen(password
), rx_id
,
439 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
443 if (pw
&& pw
->vlan_id
) {
444 if (!sta
->sae
->tmp
) {
446 "SAE: No temporary data allocated - cannot store VLAN ID");
449 sta
->sae
->tmp
->vlan_id
= pw
->vlan_id
;
452 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
+
453 (rx_id
? 3 + os_strlen(rx_id
) : 0));
456 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
457 sta
->sae
->tmp
->anti_clogging_token
: NULL
, rx_id
);
463 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
464 struct sta_info
*sta
)
468 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
472 sae_write_confirm(sta
->sae
, buf
);
478 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
479 struct sta_info
*sta
,
480 const u8
*bssid
, int update
)
485 data
= auth_build_sae_commit(hapd
, sta
, update
);
486 if (!data
&& sta
->sae
->tmp
&& sta
->sae
->tmp
->pw_id
)
487 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
;
489 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
491 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
492 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
493 wpabuf_len(data
), "sae-send-commit");
501 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
502 struct sta_info
*sta
,
508 data
= auth_build_sae_confirm(hapd
, sta
);
510 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
512 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
513 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
514 wpabuf_len(data
), "sae-send-confirm");
522 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
524 struct sta_info
*sta
;
525 unsigned int open
= 0;
527 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
530 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
533 if (sta
->sae
->state
!= SAE_COMMITTED
&&
534 sta
->sae
->state
!= SAE_CONFIRMED
)
537 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
541 /* In addition to already existing open SAE sessions, check whether
542 * there are enough pending commit messages in the processing queue to
543 * potentially result in too many open sessions. */
544 if (open
+ dl_list_len(&hapd
->sae_commit_queue
) >=
545 hapd
->conf
->sae_anti_clogging_threshold
)
552 static u8
sae_token_hash(struct hostapd_data
*hapd
, const u8
*addr
)
554 u8 hash
[SHA256_MAC_LEN
];
556 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
557 addr
, ETH_ALEN
, hash
);
562 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
563 const u8
*token
, size_t token_len
)
565 u8 mac
[SHA256_MAC_LEN
];
571 if (token_len
!= SHA256_MAC_LEN
)
573 idx
= sae_token_hash(hapd
, addr
);
574 token_idx
= hapd
->sae_pending_token_idx
[idx
];
575 if (token_idx
== 0 || token_idx
!= WPA_GET_BE16(token
)) {
576 wpa_printf(MSG_DEBUG
, "SAE: Invalid anti-clogging token from "
577 MACSTR
" - token_idx 0x%04x, expected 0x%04x",
578 MAC2STR(addr
), WPA_GET_BE16(token
), token_idx
);
586 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
587 2, addrs
, len
, mac
) < 0 ||
588 os_memcmp_const(token
+ 2, &mac
[2], SHA256_MAC_LEN
- 2) != 0)
591 hapd
->sae_pending_token_idx
[idx
] = 0; /* invalidate used token */
597 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
598 int group
, const u8
*addr
)
602 struct os_reltime now
;
609 os_get_reltime(&now
);
610 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
611 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60) ||
612 hapd
->sae_token_idx
== 0xffff) {
613 if (random_get_bytes(hapd
->sae_token_key
,
614 sizeof(hapd
->sae_token_key
)) < 0)
616 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
617 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
618 hapd
->last_sae_token_key_update
= now
;
619 hapd
->sae_token_idx
= 0;
620 os_memset(hapd
->sae_pending_token_idx
, 0,
621 sizeof(hapd
->sae_pending_token_idx
));
624 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
628 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
630 p_idx
= sae_token_hash(hapd
, addr
);
631 token_idx
= hapd
->sae_pending_token_idx
[p_idx
];
633 hapd
->sae_token_idx
++;
634 token_idx
= hapd
->sae_token_idx
;
635 hapd
->sae_pending_token_idx
[p_idx
] = token_idx
;
637 WPA_PUT_BE16(idx
, token_idx
);
638 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
642 len
[1] = sizeof(idx
);
643 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
644 2, addrs
, len
, token
) < 0) {
648 WPA_PUT_BE16(token
, token_idx
);
654 static int sae_check_big_sync(struct hostapd_data
*hapd
, struct sta_info
*sta
)
656 if (sta
->sae
->sync
> hapd
->conf
->sae_sync
) {
657 sae_set_state(sta
, SAE_NOTHING
, "Sync > dot11RSNASAESync");
665 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
667 struct hostapd_data
*hapd
= eloop_ctx
;
668 struct sta_info
*sta
= eloop_data
;
671 if (sae_check_big_sync(hapd
, sta
))
674 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
675 " (sync=%d state=%s)",
676 MAC2STR(sta
->addr
), sta
->sae
->sync
,
677 sae_state_txt(sta
->sae
->state
));
679 switch (sta
->sae
->state
) {
681 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
682 eloop_register_timeout(0,
683 hapd
->dot11RSNASAERetransPeriod
* 1000,
684 auth_sae_retransmit_timer
, hapd
, sta
);
687 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
688 eloop_register_timeout(0,
689 hapd
->dot11RSNASAERetransPeriod
* 1000,
690 auth_sae_retransmit_timer
, hapd
, sta
);
697 if (ret
!= WLAN_STATUS_SUCCESS
)
698 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
702 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
704 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
708 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
709 struct sta_info
*sta
)
711 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
714 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
715 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
716 auth_sae_retransmit_timer
, hapd
, sta
);
720 static void sae_sme_send_external_auth_status(struct hostapd_data
*hapd
,
721 struct sta_info
*sta
, u16 status
)
723 struct external_auth params
;
725 os_memset(¶ms
, 0, sizeof(params
));
726 params
.status
= status
;
727 params
.bssid
= sta
->addr
;
728 if (status
== WLAN_STATUS_SUCCESS
&& sta
->sae
&&
729 !hapd
->conf
->disable_pmksa_caching
)
730 params
.pmkid
= sta
->sae
->pmkid
;
732 hostapd_drv_send_external_auth_status(hapd
, ¶ms
);
736 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
738 #ifndef CONFIG_NO_VLAN
739 struct vlan_description vlan_desc
;
741 if (sta
->sae
->tmp
&& sta
->sae
->tmp
->vlan_id
> 0) {
742 wpa_printf(MSG_DEBUG
, "SAE: Assign STA " MACSTR
744 MAC2STR(sta
->addr
), sta
->sae
->tmp
->vlan_id
);
746 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
747 vlan_desc
.notempty
= 1;
748 vlan_desc
.untagged
= sta
->sae
->tmp
->vlan_id
;
749 if (!hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
751 "Invalid VLAN ID %d in sae_password",
752 sta
->sae
->tmp
->vlan_id
);
756 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0 ||
757 ap_sta_bind_vlan(hapd
, sta
) < 0) {
759 "Failed to assign VLAN ID %d from sae_password to "
760 MACSTR
, sta
->sae
->tmp
->vlan_id
,
765 #endif /* CONFIG_NO_VLAN */
767 sta
->flags
|= WLAN_STA_AUTH
;
768 sta
->auth_alg
= WLAN_AUTH_SAE
;
769 mlme_authenticate_indication(hapd
, sta
);
770 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
771 sae_set_state(sta
, SAE_ACCEPTED
, "Accept Confirm");
772 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
773 sta
->sae
->pmk
, sta
->sae
->pmkid
);
774 sae_sme_send_external_auth_status(hapd
, sta
, WLAN_STATUS_SUCCESS
);
778 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
779 const u8
*bssid
, u8 auth_transaction
, int allow_reuse
,
786 if (auth_transaction
!= 1 && auth_transaction
!= 2)
787 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
789 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
790 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
792 switch (sta
->sae
->state
) {
794 if (auth_transaction
== 1) {
795 ret
= auth_sae_send_commit(hapd
, sta
, bssid
,
799 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
801 if (sae_process_commit(sta
->sae
) < 0)
802 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
805 * In mesh case, both Commit and Confirm are sent
806 * immediately. In infrastructure BSS, by default, only
807 * a single Authentication frame (Commit) is expected
808 * from the AP here and the second one (Confirm) will
809 * be sent once the STA has sent its second
810 * Authentication frame (Confirm). This behavior can be
811 * overridden with explicit configuration so that the
812 * infrastructure BSS case sends both frames together.
814 if ((hapd
->conf
->mesh
& MESH_ENABLED
) ||
815 hapd
->conf
->sae_confirm_immediate
) {
817 * Send both Commit and Confirm immediately
818 * based on SAE finite state machine
819 * Nothing -> Confirm transition.
821 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
824 sae_set_state(sta
, SAE_CONFIRMED
,
825 "Sent Confirm (mesh)");
828 * For infrastructure BSS, send only the Commit
829 * message now to get alternating sequence of
830 * Authentication frames between the AP and STA.
831 * Confirm will be sent in
832 * Committed -> Confirmed/Accepted transition
833 * when receiving Confirm from STA.
837 sae_set_retransmit_timer(hapd
, sta
);
839 hostapd_logger(hapd
, sta
->addr
,
840 HOSTAPD_MODULE_IEEE80211
,
842 "SAE confirm before commit");
846 sae_clear_retransmit_timer(hapd
, sta
);
847 if (auth_transaction
== 1) {
848 if (sae_process_commit(sta
->sae
) < 0)
849 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
851 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
854 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
856 sae_set_retransmit_timer(hapd
, sta
);
857 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
859 * In mesh case, follow SAE finite state machine and
860 * send Commit now, if sync count allows.
862 if (sae_check_big_sync(hapd
, sta
))
863 return WLAN_STATUS_SUCCESS
;
866 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
870 sae_set_retransmit_timer(hapd
, sta
);
873 * For instructure BSS, send the postponed Confirm from
874 * Nothing -> Confirmed transition that was reduced to
875 * Nothing -> Committed above.
877 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
881 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
884 * Since this was triggered on Confirm RX, run another
885 * step to get to Accepted without waiting for
888 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
,
893 sae_clear_retransmit_timer(hapd
, sta
);
894 if (auth_transaction
== 1) {
895 if (sae_check_big_sync(hapd
, sta
))
896 return WLAN_STATUS_SUCCESS
;
899 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
903 if (sae_process_commit(sta
->sae
) < 0)
904 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
906 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
910 sae_set_retransmit_timer(hapd
, sta
);
912 sta
->sae
->send_confirm
= 0xffff;
913 sae_accept_sta(hapd
, sta
);
917 if (auth_transaction
== 1 &&
918 (hapd
->conf
->mesh
& MESH_ENABLED
)) {
919 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
920 ") doing reauthentication",
922 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
923 ap_free_sta(hapd
, sta
);
925 } else if (auth_transaction
== 1) {
926 wpa_printf(MSG_DEBUG
, "SAE: Start reauthentication");
927 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
930 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
932 if (sae_process_commit(sta
->sae
) < 0)
933 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
935 sae_set_retransmit_timer(hapd
, sta
);
937 if (sae_check_big_sync(hapd
, sta
))
938 return WLAN_STATUS_SUCCESS
;
941 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
942 sae_clear_temp_data(sta
->sae
);
948 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
950 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
952 return WLAN_STATUS_SUCCESS
;
956 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
958 struct sae_data
*sae
= sta
->sae
;
959 int i
, *groups
= hapd
->conf
->sae_groups
;
960 int default_groups
[] = { 19, 0 };
962 if (sae
->state
!= SAE_COMMITTED
)
965 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
968 groups
= default_groups
;
969 for (i
= 0; groups
[i
] > 0; i
++) {
970 if (sae
->group
== groups
[i
])
974 if (groups
[i
] <= 0) {
975 wpa_printf(MSG_DEBUG
,
976 "SAE: Previously selected group not found from the current configuration");
982 if (groups
[i
] <= 0) {
983 wpa_printf(MSG_DEBUG
,
984 "SAE: No alternative group enabled");
988 if (sae_set_group(sae
, groups
[i
]) < 0)
993 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
997 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
998 const struct ieee80211_mgmt
*mgmt
, size_t len
,
999 u16 auth_transaction
, u16 status_code
)
1001 int resp
= WLAN_STATUS_SUCCESS
;
1002 struct wpabuf
*data
= NULL
;
1003 int *groups
= hapd
->conf
->sae_groups
;
1004 int default_groups
[] = { 19, 0 };
1005 const u8
*pos
, *end
;
1006 int sta_removed
= 0;
1009 groups
= default_groups
;
1011 #ifdef CONFIG_TESTING_OPTIONS
1012 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
1013 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
1014 pos
= mgmt
->u
.auth
.variable
;
1015 end
= ((const u8
*) mgmt
) + len
;
1016 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1017 auth_transaction
, resp
, pos
, end
- pos
,
1018 "auth-sae-reflection-attack");
1022 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
1023 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
1024 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1025 auth_transaction
, resp
,
1026 wpabuf_head(hapd
->conf
->sae_commit_override
),
1027 wpabuf_len(hapd
->conf
->sae_commit_override
),
1028 "sae-commit-override");
1031 #endif /* CONFIG_TESTING_OPTIONS */
1033 if (auth_transaction
!= 1 ||
1034 status_code
!= WLAN_STATUS_SUCCESS
) {
1038 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
1043 sae_set_state(sta
, SAE_NOTHING
, "Init");
1047 if (sta
->mesh_sae_pmksa_caching
) {
1048 wpa_printf(MSG_DEBUG
,
1049 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1050 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
1051 sta
->mesh_sae_pmksa_caching
= 0;
1054 if (auth_transaction
== 1) {
1055 const u8
*token
= NULL
;
1056 size_t token_len
= 0;
1057 int allow_reuse
= 0;
1059 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1060 HOSTAPD_LEVEL_DEBUG
,
1061 "start SAE authentication (RX commit, status=%u (%s))",
1062 status_code
, status2str(status_code
));
1064 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1065 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1067 pos
= mgmt
->u
.auth
.variable
;
1068 end
= ((const u8
*) mgmt
) + len
;
1069 if (pos
+ sizeof(le16
) > end
) {
1070 wpa_printf(MSG_ERROR
,
1071 "SAE: Too short anti-clogging token request");
1072 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1075 resp
= sae_group_allowed(sta
->sae
, groups
,
1077 if (resp
!= WLAN_STATUS_SUCCESS
) {
1078 wpa_printf(MSG_ERROR
,
1079 "SAE: Invalid group in anti-clogging token request");
1082 pos
+= sizeof(le16
);
1084 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
1085 sta
->sae
->tmp
->anti_clogging_token
=
1086 wpabuf_alloc_copy(pos
, end
- pos
);
1087 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
1088 wpa_printf(MSG_ERROR
,
1089 "SAE: Failed to alloc for anti-clogging token");
1090 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1095 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1096 * is 76, a new Commit Message shall be constructed
1097 * with the Anti-Clogging Token from the received
1098 * Authentication frame, and the commit-scalar and
1099 * COMMIT-ELEMENT previously sent.
1101 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
1102 if (resp
!= WLAN_STATUS_SUCCESS
) {
1103 wpa_printf(MSG_ERROR
,
1104 "SAE: Failed to send commit message");
1107 sae_set_state(sta
, SAE_COMMITTED
,
1108 "Sent Commit (anti-clogging token case in mesh)");
1110 sae_set_retransmit_timer(hapd
, sta
);
1114 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1116 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1118 wpa_printf(MSG_DEBUG
,
1119 "SAE: Peer did not accept our SAE group");
1120 sae_pick_next_group(hapd
, sta
);
1124 if (status_code
!= WLAN_STATUS_SUCCESS
)
1127 if (!(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1128 sta
->sae
->state
== SAE_COMMITTED
) {
1129 /* This is needed in the infrastructure BSS case to
1130 * address a sequence where a STA entry may remain in
1131 * hostapd across two attempts to do SAE authentication
1132 * by the same STA. The second attempt may end up trying
1133 * to use a different group and that would not be
1134 * allowed if we remain in Committed state with the
1135 * previously set parameters. */
1136 pos
= mgmt
->u
.auth
.variable
;
1137 end
= ((const u8
*) mgmt
) + len
;
1138 if (end
- pos
>= (int) sizeof(le16
) &&
1139 sae_group_allowed(sta
->sae
, groups
,
1140 WPA_GET_LE16(pos
)) ==
1141 WLAN_STATUS_SUCCESS
) {
1142 /* Do not waste resources deriving the same PWE
1143 * again since the same group is reused. */
1144 sae_set_state(sta
, SAE_NOTHING
,
1145 "Allow previous PWE to be reused");
1148 sae_set_state(sta
, SAE_NOTHING
,
1149 "Clear existing state to allow restart");
1150 sae_clear_data(sta
->sae
);
1154 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
1155 ((const u8
*) mgmt
) + len
-
1156 mgmt
->u
.auth
.variable
, &token
,
1157 &token_len
, groups
, status_code
==
1158 WLAN_STATUS_SAE_HASH_TO_ELEMENT
);
1159 if (resp
== SAE_SILENTLY_DISCARD
) {
1160 wpa_printf(MSG_DEBUG
,
1161 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
1162 MAC2STR(sta
->addr
));
1166 if (resp
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1167 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1168 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1169 MACSTR
, MAC2STR(sta
->addr
));
1170 sae_clear_retransmit_timer(hapd
, sta
);
1171 sae_set_state(sta
, SAE_NOTHING
,
1172 "Unknown Password Identifier");
1176 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
1178 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
1179 "incorrect token from " MACSTR
,
1180 MAC2STR(sta
->addr
));
1181 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1185 if (resp
!= WLAN_STATUS_SUCCESS
)
1188 if (!token
&& use_sae_anti_clogging(hapd
) && !allow_reuse
) {
1189 wpa_printf(MSG_DEBUG
,
1190 "SAE: Request anti-clogging token from "
1191 MACSTR
, MAC2STR(sta
->addr
));
1192 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
1194 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
1195 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1196 sae_set_state(sta
, SAE_NOTHING
,
1197 "Request anti-clogging token case in mesh");
1201 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1202 allow_reuse
, &sta_removed
);
1203 } else if (auth_transaction
== 2) {
1204 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1205 HOSTAPD_LEVEL_DEBUG
,
1206 "SAE authentication (RX confirm, status=%u (%s))",
1207 status_code
, status2str(status_code
));
1208 if (status_code
!= WLAN_STATUS_SUCCESS
)
1210 if (sta
->sae
->state
>= SAE_CONFIRMED
||
1211 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
1214 u16 peer_send_confirm
;
1216 var
= mgmt
->u
.auth
.variable
;
1217 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
1219 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1223 peer_send_confirm
= WPA_GET_LE16(var
);
1225 if (sta
->sae
->state
== SAE_ACCEPTED
&&
1226 (peer_send_confirm
<= sta
->sae
->rc
||
1227 peer_send_confirm
== 0xffff)) {
1228 wpa_printf(MSG_DEBUG
,
1229 "SAE: Silently ignore unexpected Confirm from peer "
1231 " (peer-send-confirm=%u Rc=%u)",
1233 peer_send_confirm
, sta
->sae
->rc
);
1237 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
1238 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1241 sta
->sae
->rc
= peer_send_confirm
;
1243 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
, 0,
1246 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1247 HOSTAPD_LEVEL_DEBUG
,
1248 "unexpected SAE authentication transaction %u (status=%u (%s))",
1249 auth_transaction
, status_code
,
1250 status2str(status_code
));
1251 if (status_code
!= WLAN_STATUS_SUCCESS
)
1253 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1257 if (!sta_removed
&& resp
!= WLAN_STATUS_SUCCESS
) {
1258 pos
= mgmt
->u
.auth
.variable
;
1259 end
= ((const u8
*) mgmt
) + len
;
1261 /* Copy the Finite Cyclic Group field from the request if we
1262 * rejected it as unsupported group. */
1263 if (resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1264 !data
&& end
- pos
>= 2)
1265 data
= wpabuf_alloc_copy(pos
, 2);
1267 sae_sme_send_external_auth_status(hapd
, sta
, resp
);
1268 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1269 auth_transaction
, resp
,
1270 data
? wpabuf_head(data
) : (u8
*) "",
1271 data
? wpabuf_len(data
) : 0, "auth-sae");
1275 if (!sta_removed
&& sta
->added_unassoc
&&
1276 (resp
!= WLAN_STATUS_SUCCESS
||
1277 status_code
!= WLAN_STATUS_SUCCESS
)) {
1278 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1279 sta
->added_unassoc
= 0;
1286 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1287 * @hapd: BSS data for the device initiating the authentication
1288 * @sta: the peer to which commit authentication frame is sent
1290 * This function implements Init event handling (IEEE Std 802.11-2012,
1291 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1292 * sta->sae structure should be initialized appropriately via a call to
1293 * sae_prepare_commit().
1295 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1299 if (!sta
->sae
|| !sta
->sae
->tmp
)
1302 if (sta
->sae
->state
!= SAE_NOTHING
)
1305 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1309 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1311 sae_set_retransmit_timer(hapd
, sta
);
1317 void auth_sae_process_commit(void *eloop_ctx
, void *user_ctx
)
1319 struct hostapd_data
*hapd
= eloop_ctx
;
1320 struct hostapd_sae_commit_queue
*q
;
1321 unsigned int queue_len
;
1323 q
= dl_list_first(&hapd
->sae_commit_queue
,
1324 struct hostapd_sae_commit_queue
, list
);
1327 wpa_printf(MSG_DEBUG
,
1328 "SAE: Process next available message from queue");
1329 dl_list_del(&q
->list
);
1330 handle_auth(hapd
, (const struct ieee80211_mgmt
*) q
->msg
, q
->len
,
1334 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1336 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1337 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1342 static void auth_sae_queue(struct hostapd_data
*hapd
,
1343 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1346 struct hostapd_sae_commit_queue
*q
, *q2
;
1347 unsigned int queue_len
;
1348 const struct ieee80211_mgmt
*mgmt2
;
1350 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1351 if (queue_len
>= 15) {
1352 wpa_printf(MSG_DEBUG
,
1353 "SAE: No more room in message queue - drop the new frame from "
1354 MACSTR
, MAC2STR(mgmt
->sa
));
1358 wpa_printf(MSG_DEBUG
, "SAE: Queue Authentication message from "
1359 MACSTR
" for processing (queue_len %u)", MAC2STR(mgmt
->sa
),
1361 q
= os_zalloc(sizeof(*q
) + len
);
1366 os_memcpy(q
->msg
, mgmt
, len
);
1368 /* Check whether there is already a queued Authentication frame from the
1369 * same station with the same transaction number and if so, replace that
1370 * queue entry with the new one. This avoids issues with a peer that
1371 * sends multiple times (e.g., due to frequent SAE retries). There is no
1372 * point in us trying to process the old attempts after a new one has
1373 * obsoleted them. */
1374 dl_list_for_each(q2
, &hapd
->sae_commit_queue
,
1375 struct hostapd_sae_commit_queue
, list
) {
1376 mgmt2
= (const struct ieee80211_mgmt
*) q2
->msg
;
1377 if (os_memcmp(mgmt
->sa
, mgmt2
->sa
, ETH_ALEN
) == 0 &&
1378 mgmt
->u
.auth
.auth_transaction
==
1379 mgmt2
->u
.auth
.auth_transaction
) {
1380 wpa_printf(MSG_DEBUG
,
1381 "SAE: Replace queued message from same STA with same transaction number");
1382 dl_list_add(&q2
->list
, &q
->list
);
1383 dl_list_del(&q2
->list
);
1389 /* No pending identical entry, so add to the end of the queue */
1390 dl_list_add_tail(&hapd
->sae_commit_queue
, &q
->list
);
1393 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1395 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1400 static int auth_sae_queued_addr(struct hostapd_data
*hapd
, const u8
*addr
)
1402 struct hostapd_sae_commit_queue
*q
;
1403 const struct ieee80211_mgmt
*mgmt
;
1405 dl_list_for_each(q
, &hapd
->sae_commit_queue
,
1406 struct hostapd_sae_commit_queue
, list
) {
1407 mgmt
= (const struct ieee80211_mgmt
*) q
->msg
;
1408 if (os_memcmp(addr
, mgmt
->sa
, ETH_ALEN
) == 0)
1415 #endif /* CONFIG_SAE */
1418 static u16
wpa_res_to_status_code(int res
)
1420 if (res
== WPA_INVALID_GROUP
)
1421 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1422 if (res
== WPA_INVALID_PAIRWISE
)
1423 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1424 if (res
== WPA_INVALID_AKMP
)
1425 return WLAN_STATUS_AKMP_NOT_VALID
;
1426 if (res
== WPA_ALLOC_FAIL
)
1427 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1428 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1429 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1430 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1431 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1432 if (res
== WPA_INVALID_MDIE
)
1433 return WLAN_STATUS_INVALID_MDIE
;
1434 if (res
== WPA_INVALID_PMKID
)
1435 return WLAN_STATUS_INVALID_PMKID
;
1436 if (res
!= WPA_IE_OK
)
1437 return WLAN_STATUS_INVALID_IE
;
1438 return WLAN_STATUS_SUCCESS
;
1444 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1445 struct sta_info
*sta
, u16 resp
,
1446 struct wpabuf
*data
, int pub
);
1448 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1449 const u8
*pos
, size_t len
, u16 auth_alg
,
1450 u16 auth_transaction
, u16 status_code
,
1451 void (*cb
)(struct hostapd_data
*hapd
,
1452 struct sta_info
*sta
, u16 resp
,
1453 struct wpabuf
*data
, int pub
))
1455 u16 resp
= WLAN_STATUS_SUCCESS
;
1457 struct ieee802_11_elems elems
;
1459 struct wpa_ie_data rsn
;
1460 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1462 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1467 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1471 #ifdef CONFIG_FILS_SK_PFS
1472 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1477 /* Using FILS PFS */
1479 /* Finite Cyclic Group */
1480 if (end
- pos
< 2) {
1481 wpa_printf(MSG_DEBUG
,
1482 "FILS: No room for Finite Cyclic Group");
1483 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1486 group
= WPA_GET_LE16(pos
);
1488 if (group
!= hapd
->conf
->fils_dh_group
) {
1489 wpa_printf(MSG_DEBUG
,
1490 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1491 group
, hapd
->conf
->fils_dh_group
);
1492 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1496 crypto_ecdh_deinit(sta
->fils_ecdh
);
1497 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1498 if (!sta
->fils_ecdh
) {
1499 wpa_printf(MSG_INFO
,
1500 "FILS: Could not initialize ECDH with group %d",
1502 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1506 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1508 wpa_printf(MSG_DEBUG
,
1509 "FILS: Failed to derive ECDH public key");
1510 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1513 elem_len
= wpabuf_len(pub
);
1517 if ((size_t) (end
- pos
) < elem_len
) {
1518 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1519 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1523 wpabuf_free(sta
->fils_g_sta
);
1524 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1525 wpabuf_clear_free(sta
->fils_dh_ss
);
1526 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1528 if (!sta
->fils_dh_ss
) {
1529 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1530 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1533 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1536 crypto_ecdh_deinit(sta
->fils_ecdh
);
1537 sta
->fils_ecdh
= NULL
;
1538 wpabuf_clear_free(sta
->fils_dh_ss
);
1539 sta
->fils_dh_ss
= NULL
;
1541 #endif /* CONFIG_FILS_SK_PFS */
1543 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1544 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1545 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1546 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1551 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1552 elems
.rsn_ie
, elems
.rsn_ie_len
);
1553 if (!elems
.rsn_ie
||
1554 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1556 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1557 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1562 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1565 wpa_printf(MSG_DEBUG
,
1566 "FILS: Failed to initialize RSN state machine");
1567 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1571 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1573 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1574 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1575 resp
= wpa_res_to_status_code(res
);
1576 if (resp
!= WLAN_STATUS_SUCCESS
)
1579 if (!elems
.fils_nonce
) {
1580 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1581 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1584 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1586 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1589 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1593 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1594 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1597 num
= rsn
.num_pmkid
;
1599 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1600 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1604 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1613 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1614 wpa_printf(MSG_DEBUG
,
1615 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1616 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1620 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1623 if (!elems
.fils_session
) {
1624 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1625 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1628 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1630 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1632 /* FILS Wrapped Data */
1633 if (elems
.fils_wrapped_data
) {
1634 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1635 elems
.fils_wrapped_data
,
1636 elems
.fils_wrapped_data_len
);
1638 #ifndef CONFIG_NO_RADIUS
1639 if (!sta
->eapol_sm
) {
1641 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1643 wpa_printf(MSG_DEBUG
,
1644 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1645 ieee802_1x_encapsulate_radius(
1646 hapd
, sta
, elems
.fils_wrapped_data
,
1647 elems
.fils_wrapped_data_len
);
1648 sta
->fils_pending_cb
= cb
;
1649 wpa_printf(MSG_DEBUG
,
1650 "FILS: Will send Authentication frame once the response from authentication server is available");
1651 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1652 /* Calculate pending PMKID here so that we do not need
1653 * to maintain a copy of the EAP-Initiate/Reauth
1655 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1656 elems
.fils_wrapped_data
,
1657 elems
.fils_wrapped_data_len
,
1658 sta
->fils_erp_pmkid
) == 0)
1659 sta
->fils_erp_pmkid_set
= 1;
1661 #else /* CONFIG_NO_RADIUS */
1662 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1664 #endif /* CONFIG_NO_RADIUS */
1670 struct wpabuf
*data
;
1673 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1676 wpa_printf(MSG_DEBUG
,
1677 "%s: prepare_auth_resp_fils() returned failure",
1681 cb(hapd
, sta
, resp
, data
, pub
);
1686 static struct wpabuf
*
1687 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1688 struct sta_info
*sta
, u16
*resp
,
1689 struct rsn_pmksa_cache_entry
*pmksa
,
1690 struct wpabuf
*erp_resp
,
1691 const u8
*msk
, size_t msk_len
,
1694 u8 fils_nonce
[FILS_NONCE_LEN
];
1696 struct wpabuf
*data
= NULL
;
1699 const u8
*pmk
= NULL
;
1701 u8 pmk_buf
[PMK_LEN_MAX
];
1702 struct wpabuf
*pub
= NULL
;
1704 if (*resp
!= WLAN_STATUS_SUCCESS
)
1707 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1709 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1714 /* Add PMKID of the selected PMKSA into RSNE */
1715 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1717 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1721 os_memcpy(ie_buf
, ie
, ielen
);
1722 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1723 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1729 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1730 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1733 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1734 fils_nonce
, FILS_NONCE_LEN
);
1736 #ifdef CONFIG_FILS_SK_PFS
1737 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1738 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1740 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1744 #endif /* CONFIG_FILS_SK_PFS */
1746 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1748 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1753 #ifdef CONFIG_FILS_SK_PFS
1755 /* Finite Cyclic Group */
1756 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1759 wpabuf_put_buf(data
, pub
);
1761 #endif /* CONFIG_FILS_SK_PFS */
1764 wpabuf_put_data(data
, ie
, ielen
);
1766 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1768 #ifdef CONFIG_IEEE80211R_AP
1769 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1770 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1772 int use_sha384
= wpa_key_mgmt_sha384(
1773 wpa_auth_sta_key_mgmt(sta
->wpa_sm
));
1775 res
= wpa_auth_write_fte(hapd
->wpa_auth
, use_sha384
,
1776 wpabuf_put(data
, 0),
1777 wpabuf_tailroom(data
));
1779 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1782 wpabuf_put(data
, res
);
1784 #endif /* CONFIG_IEEE80211R_AP */
1787 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1788 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1789 /* Element ID Extension */
1790 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1791 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1794 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1795 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1796 /* Element ID Extension */
1797 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1798 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1800 /* FILS Wrapped Data */
1801 if (!pmksa
&& erp_resp
) {
1802 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1803 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1804 /* Element ID Extension */
1805 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1806 wpabuf_put_buf(data
, erp_resp
);
1808 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1809 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1811 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1813 wpabuf_len(sta
->fils_dh_ss
) : 0,
1814 pmk_buf
, &pmk_len
)) {
1815 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1816 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1823 /* Don't use DHss in PTK derivation if PMKSA caching is not
1825 wpabuf_clear_free(sta
->fils_dh_ss
);
1826 sta
->fils_dh_ss
= NULL
;
1828 if (sta
->fils_erp_pmkid_set
) {
1829 /* TODO: get PMKLifetime from WPA parameters */
1830 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1831 int session_timeout
;
1833 session_timeout
= dot11RSNAConfigPMKLifetime
;
1834 if (sta
->session_timeout_set
) {
1835 struct os_reltime now
, diff
;
1837 os_get_reltime(&now
);
1838 os_reltime_sub(&sta
->session_timeout
, &now
,
1840 session_timeout
= diff
.sec
;
1843 sta
->fils_erp_pmkid_set
= 0;
1844 wpa_auth_add_fils_pmk_pmkid(sta
->wpa_sm
, pmk
, pmk_len
,
1845 sta
->fils_erp_pmkid
);
1846 if (!hapd
->conf
->disable_pmksa_caching
&&
1847 wpa_auth_pmksa_add2(
1848 hapd
->wpa_auth
, sta
->addr
,
1850 sta
->fils_erp_pmkid
,
1852 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1853 wpa_printf(MSG_ERROR
,
1854 "FILS: Failed to add PMKSA cache entry based on ERP");
1859 pmk_len
= pmksa
->pmk_len
;
1863 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1864 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1870 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1871 sta
->fils_snonce
, fils_nonce
,
1873 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1875 wpabuf_len(sta
->fils_dh_ss
) : 0,
1876 sta
->fils_g_sta
, pub
) < 0) {
1877 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1885 *is_pub
= pub
!= NULL
;
1888 wpabuf_clear_free(sta
->fils_dh_ss
);
1889 sta
->fils_dh_ss
= NULL
;
1890 #ifdef CONFIG_FILS_SK_PFS
1891 crypto_ecdh_deinit(sta
->fils_ecdh
);
1892 sta
->fils_ecdh
= NULL
;
1893 #endif /* CONFIG_FILS_SK_PFS */
1898 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1899 struct sta_info
*sta
, u16 resp
,
1900 struct wpabuf
*data
, int pub
)
1905 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1906 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1907 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1908 data
? wpabuf_head(data
) : (u8
*) "",
1909 data
? wpabuf_len(data
) : 0, "auth-fils-finish");
1912 if (resp
== WLAN_STATUS_SUCCESS
) {
1913 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1914 HOSTAPD_LEVEL_DEBUG
,
1915 "authentication OK (FILS)");
1916 sta
->flags
|= WLAN_STA_AUTH
;
1917 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1918 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1919 mlme_authenticate_indication(hapd
, sta
);
1924 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
1925 struct sta_info
*sta
, int success
,
1926 struct wpabuf
*erp_resp
,
1927 const u8
*msk
, size_t msk_len
)
1929 struct wpabuf
*data
;
1933 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1935 if (!sta
->fils_pending_cb
)
1937 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
1938 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
1939 msk
, msk_len
, &pub
);
1941 wpa_printf(MSG_DEBUG
,
1942 "%s: prepare_auth_resp_fils() returned failure",
1945 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
1948 #endif /* CONFIG_FILS */
1952 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
1953 const u8
*msg
, size_t len
, u32
*session_timeout
,
1954 u32
*acct_interim_interval
,
1955 struct vlan_description
*vlan_id
,
1956 struct hostapd_sta_wpa_psk_short
**psk
,
1957 char **identity
, char **radius_cui
, int is_probe_req
)
1961 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
1962 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
1963 session_timeout
, acct_interim_interval
,
1964 vlan_id
, psk
, identity
, radius_cui
,
1967 if (res
== HOSTAPD_ACL_REJECT
) {
1969 wpa_printf(MSG_DEBUG
,
1971 " not allowed to authenticate",
1973 return HOSTAPD_ACL_REJECT
;
1976 if (res
== HOSTAPD_ACL_PENDING
) {
1977 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
1978 " waiting for an external authentication",
1980 /* Authentication code will re-send the authentication frame
1981 * after it has received (and cached) information from the
1982 * external source. */
1983 return HOSTAPD_ACL_PENDING
;
1991 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1992 int res
, u32 session_timeout
,
1993 u32 acct_interim_interval
,
1994 struct vlan_description
*vlan_id
,
1995 struct hostapd_sta_wpa_psk_short
**psk
,
1996 char **identity
, char **radius_cui
)
1998 if (vlan_id
->notempty
&&
1999 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
2000 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2002 "Invalid VLAN %d%s received from RADIUS server",
2004 vlan_id
->tagged
[0] ? "+" : "");
2007 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
2010 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2011 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
2013 hostapd_free_psk_list(sta
->psk
);
2014 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
2021 os_free(sta
->identity
);
2022 sta
->identity
= *identity
;
2025 os_free(sta
->radius_cui
);
2026 sta
->radius_cui
= *radius_cui
;
2029 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
2030 sta
->acct_interim_interval
= acct_interim_interval
;
2031 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
) {
2032 sta
->session_timeout_set
= 1;
2033 os_get_reltime(&sta
->session_timeout
);
2034 sta
->session_timeout
.sec
+= session_timeout
;
2035 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
2037 sta
->session_timeout_set
= 0;
2038 ap_sta_no_session_timeout(hapd
, sta
);
2045 static void handle_auth(struct hostapd_data
*hapd
,
2046 const struct ieee80211_mgmt
*mgmt
, size_t len
,
2047 int rssi
, int from_queue
)
2049 u16 auth_alg
, auth_transaction
, status_code
;
2050 u16 resp
= WLAN_STATUS_SUCCESS
;
2051 struct sta_info
*sta
= NULL
;
2054 const u8
*challenge
= NULL
;
2055 u32 session_timeout
, acct_interim_interval
;
2056 struct vlan_description vlan_id
;
2057 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
2058 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
2059 size_t resp_ies_len
= 0;
2060 char *identity
= NULL
;
2061 char *radius_cui
= NULL
;
2064 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
2065 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
2066 (unsigned long) len
);
2070 #ifdef CONFIG_TESTING_OPTIONS
2071 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
2072 drand48() < hapd
->iconf
->ignore_auth_probability
) {
2073 wpa_printf(MSG_INFO
,
2074 "TESTING: ignoring auth frame from " MACSTR
,
2078 #endif /* CONFIG_TESTING_OPTIONS */
2080 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
2081 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
2082 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
2083 fc
= le_to_host16(mgmt
->frame_control
);
2084 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
2086 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
2087 2 + WLAN_AUTH_CHALLENGE_LEN
&&
2088 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
2089 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
2090 challenge
= &mgmt
->u
.auth
.variable
[2];
2092 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
2093 "auth_transaction=%d status_code=%d wep=%d%s "
2094 "seq_ctrl=0x%x%s%s",
2095 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
2096 status_code
, !!(fc
& WLAN_FC_ISWEP
),
2097 challenge
? " challenge" : "",
2098 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "",
2099 from_queue
? " (from queue)" : "");
2101 #ifdef CONFIG_NO_RC4
2102 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
2103 wpa_printf(MSG_INFO
,
2104 "Unsupported authentication algorithm (%d)",
2106 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2109 #endif /* CONFIG_NO_RC4 */
2111 if (hapd
->tkip_countermeasures
) {
2112 wpa_printf(MSG_DEBUG
,
2113 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2114 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2118 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
2119 auth_alg
== WLAN_AUTH_OPEN
) ||
2120 #ifdef CONFIG_IEEE80211R_AP
2121 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
2122 auth_alg
== WLAN_AUTH_FT
) ||
2123 #endif /* CONFIG_IEEE80211R_AP */
2125 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
2126 auth_alg
== WLAN_AUTH_SAE
) ||
2127 #endif /* CONFIG_SAE */
2129 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2130 auth_alg
== WLAN_AUTH_FILS_SK
) ||
2131 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2132 hapd
->conf
->fils_dh_group
&&
2133 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
2134 #endif /* CONFIG_FILS */
2135 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
2136 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
2137 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
2139 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2143 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
2144 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
2145 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
2147 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
2151 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
2152 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
2154 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2158 if (hapd
->conf
->no_auth_if_seen_on
) {
2159 struct hostapd_data
*other
;
2161 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
2162 hapd
->conf
->no_auth_if_seen_on
);
2166 u8 op_class
, channel
, phytype
;
2168 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
2169 MACSTR
" since STA has been seen on %s",
2170 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
2171 hapd
->conf
->no_auth_if_seen_on
);
2173 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
2175 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
2177 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
2179 info
= 0; /* TODO: BSSID Information */
2180 WPA_PUT_LE32(pos
, info
);
2182 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
2183 phytype
= 8; /* dmg */
2184 else if (other
->iconf
->ieee80211ac
)
2185 phytype
= 9; /* vht */
2186 else if (other
->iconf
->ieee80211n
)
2187 phytype
= 7; /* ht */
2188 else if (other
->iconf
->hw_mode
==
2189 HOSTAPD_MODE_IEEE80211A
)
2190 phytype
= 4; /* ofdm */
2191 else if (other
->iconf
->hw_mode
==
2192 HOSTAPD_MODE_IEEE80211G
)
2193 phytype
= 6; /* erp */
2195 phytype
= 5; /* hrdsss */
2196 if (ieee80211_freq_to_channel_ext(
2197 hostapd_hw_get_freq(other
,
2198 other
->iconf
->channel
),
2199 other
->iconf
->secondary_channel
,
2200 other
->iconf
->ieee80211ac
,
2201 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
2203 channel
= other
->iconf
->channel
;
2208 resp_ies_len
= pos
- &resp_ies
[0];
2213 res
= ieee802_11_allowed_address(
2214 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
2215 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
,
2217 if (res
== HOSTAPD_ACL_REJECT
) {
2218 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
2219 "Ignore Authentication frame from " MACSTR
2220 " due to ACL reject", MAC2STR(mgmt
->sa
));
2221 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2224 if (res
== HOSTAPD_ACL_PENDING
)
2228 if (auth_alg
== WLAN_AUTH_SAE
&& !from_queue
&&
2229 (auth_transaction
== 1 ||
2230 (auth_transaction
== 2 && auth_sae_queued_addr(hapd
, mgmt
->sa
)))) {
2231 /* Handle SAE Authentication commit message through a queue to
2232 * provide more control for postponing the needed heavy
2233 * processing under a possible DoS attack scenario. In addition,
2234 * queue SAE Authentication confirm message if there happens to
2235 * be a queued commit message from the same peer. This is needed
2236 * to avoid reordering Authentication frames within the same
2238 auth_sae_queue(hapd
, mgmt
, len
, rssi
);
2241 #endif /* CONFIG_SAE */
2243 sta
= ap_get_sta(hapd
, mgmt
->sa
);
2245 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2246 sta
->ft_over_ds
= 0;
2247 if ((fc
& WLAN_FC_RETRY
) &&
2248 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
2249 sta
->last_seq_ctrl
== seq_ctrl
&&
2250 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
2251 hostapd_logger(hapd
, sta
->addr
,
2252 HOSTAPD_MODULE_IEEE80211
,
2253 HOSTAPD_LEVEL_DEBUG
,
2254 "Drop repeated authentication frame seq_ctrl=0x%x",
2259 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
2260 sta
->plink_state
== PLINK_BLOCKED
) {
2261 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2262 " is blocked - drop Authentication frame",
2266 #endif /* CONFIG_MESH */
2269 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
2270 /* if the mesh peer is not available, we don't do auth.
2272 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2273 " not yet known - drop Authentication frame",
2276 * Save a copy of the frame so that it can be processed
2277 * if a new peer entry is added shortly after this.
2279 wpabuf_free(hapd
->mesh_pending_auth
);
2280 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
2281 os_get_reltime(&hapd
->mesh_pending_auth_time
);
2284 #endif /* CONFIG_MESH */
2286 sta
= ap_sta_add(hapd
, mgmt
->sa
);
2288 wpa_printf(MSG_DEBUG
, "ap_sta_add() failed");
2289 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2293 sta
->last_seq_ctrl
= seq_ctrl
;
2294 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
2296 sta
->auth_rssi
= rssi
;
2297 #endif /* CONFIG_MBO */
2299 res
= ieee802_11_set_radius_info(
2300 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
2301 &vlan_id
, &psk
, &identity
, &radius_cui
);
2303 wpa_printf(MSG_DEBUG
, "ieee802_11_set_radius_info() failed");
2304 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2308 sta
->flags
&= ~WLAN_STA_PREAUTH
;
2309 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
2312 * If the driver supports full AP client state, add a station to the
2313 * driver before sending authentication reply to make sure the driver
2314 * has resources, and not to go through the entire authentication and
2315 * association handshake, and fail it at the end.
2317 * If this is not the first transaction, in a multi-step authentication
2318 * algorithm, the station already exists in the driver
2319 * (sta->added_unassoc = 1) so skip it.
2321 * In mesh mode, the station was already added to the driver when the
2322 * NEW_PEER_CANDIDATE event is received.
2324 * If PMF was negotiated for the existing association, skip this to
2325 * avoid dropping the STA entry and the associated keys. This is needed
2326 * to allow the original connection work until the attempt can complete
2327 * (re)association, so that unprotected Authentication frame cannot be
2328 * used to bypass PMF protection.
2330 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
2331 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
2332 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
2333 !(sta
->added_unassoc
)) {
2335 * If a station that is already associated to the AP, is trying
2336 * to authenticate again, remove the STA entry, in order to make
2337 * sure the STA PS state gets cleared and configuration gets
2338 * updated. To handle this, station's added_unassoc flag is
2339 * cleared once the station has completed association.
2341 ap_sta_set_authorized(hapd
, sta
, 0);
2342 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2343 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
2344 WLAN_STA_AUTHORIZED
);
2346 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0,
2347 sta
->supported_rates
,
2348 sta
->supported_rates_len
,
2349 0, NULL
, NULL
, NULL
, 0,
2350 sta
->flags
, 0, 0, 0, 0)) {
2351 hostapd_logger(hapd
, sta
->addr
,
2352 HOSTAPD_MODULE_IEEE80211
,
2353 HOSTAPD_LEVEL_NOTICE
,
2354 "Could not add STA to kernel driver");
2355 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2359 sta
->added_unassoc
= 1;
2363 case WLAN_AUTH_OPEN
:
2364 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2365 HOSTAPD_LEVEL_DEBUG
,
2366 "authentication OK (open system)");
2367 sta
->flags
|= WLAN_STA_AUTH
;
2368 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2369 sta
->auth_alg
= WLAN_AUTH_OPEN
;
2370 mlme_authenticate_indication(hapd
, sta
);
2372 #ifndef CONFIG_NO_RC4
2373 case WLAN_AUTH_SHARED_KEY
:
2374 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
2375 fc
& WLAN_FC_ISWEP
);
2377 wpa_printf(MSG_DEBUG
,
2378 "auth_shared_key() failed: status=%d", resp
);
2379 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2380 mlme_authenticate_indication(hapd
, sta
);
2381 if (sta
->challenge
&& auth_transaction
== 1) {
2382 resp_ies
[0] = WLAN_EID_CHALLENGE
;
2383 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
2384 os_memcpy(resp_ies
+ 2, sta
->challenge
,
2385 WLAN_AUTH_CHALLENGE_LEN
);
2386 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
2389 #endif /* CONFIG_NO_RC4 */
2390 #ifdef CONFIG_IEEE80211R_AP
2392 sta
->auth_alg
= WLAN_AUTH_FT
;
2393 if (sta
->wpa_sm
== NULL
)
2394 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2396 if (sta
->wpa_sm
== NULL
) {
2397 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
2399 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2402 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
2403 auth_transaction
, mgmt
->u
.auth
.variable
,
2404 len
- IEEE80211_HDRLEN
-
2405 sizeof(mgmt
->u
.auth
),
2406 handle_auth_ft_finish
, hapd
);
2407 /* handle_auth_ft_finish() callback will complete auth. */
2409 #endif /* CONFIG_IEEE80211R_AP */
2413 if (status_code
== WLAN_STATUS_SUCCESS
&&
2414 hapd
->conf
->mesh
& MESH_ENABLED
) {
2415 if (sta
->wpa_sm
== NULL
)
2417 wpa_auth_sta_init(hapd
->wpa_auth
,
2419 if (sta
->wpa_sm
== NULL
) {
2420 wpa_printf(MSG_DEBUG
,
2421 "SAE: Failed to initialize WPA state machine");
2422 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2426 #endif /* CONFIG_MESH */
2427 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2430 #endif /* CONFIG_SAE */
2432 case WLAN_AUTH_FILS_SK
:
2433 case WLAN_AUTH_FILS_SK_PFS
:
2434 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2435 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2436 auth_alg
, auth_transaction
, status_code
,
2437 handle_auth_fils_finish
);
2439 #endif /* CONFIG_FILS */
2444 os_free(radius_cui
);
2445 hostapd_free_psk_list(psk
);
2447 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2448 auth_transaction
+ 1, resp
, resp_ies
,
2449 resp_ies_len
, "handle-auth");
2451 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2452 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2453 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2454 sta
->added_unassoc
= 0;
2459 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2463 /* get a unique AID */
2465 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2472 for (i
= 0; i
< AID_WORDS
; i
++) {
2473 if (hapd
->sta_aid
[i
] == (u32
) -1)
2475 for (j
= 0; j
< 32; j
++) {
2476 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2484 aid
= i
* 32 + j
+ 1;
2489 hapd
->sta_aid
[i
] |= BIT(j
);
2490 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2495 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2496 const u8
*ssid_ie
, size_t ssid_ie_len
)
2498 if (ssid_ie
== NULL
)
2499 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2501 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2502 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2503 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2505 "Station tried to associate with unknown SSID "
2506 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2507 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2510 return WLAN_STATUS_SUCCESS
;
2514 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2515 const u8
*wmm_ie
, size_t wmm_ie_len
)
2517 sta
->flags
&= ~WLAN_STA_WMM
;
2519 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2520 struct wmm_information_element
*wmm
;
2522 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2523 hostapd_logger(hapd
, sta
->addr
,
2525 HOSTAPD_LEVEL_DEBUG
,
2526 "invalid WMM element in association "
2528 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2531 sta
->flags
|= WLAN_STA_WMM
;
2532 wmm
= (struct wmm_information_element
*) wmm_ie
;
2533 sta
->qosinfo
= wmm
->qos_info
;
2535 return WLAN_STATUS_SUCCESS
;
2538 static u16
check_multi_ap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2539 const u8
*multi_ap_ie
, size_t multi_ap_len
)
2541 u8 multi_ap_value
= 0;
2543 sta
->flags
&= ~WLAN_STA_MULTI_AP
;
2545 if (!hapd
->conf
->multi_ap
)
2546 return WLAN_STATUS_SUCCESS
;
2549 const u8
*multi_ap_subelem
;
2551 multi_ap_subelem
= get_ie(multi_ap_ie
+ 4,
2553 MULTI_AP_SUB_ELEM_TYPE
);
2554 if (multi_ap_subelem
&& multi_ap_subelem
[1] == 1) {
2555 multi_ap_value
= multi_ap_subelem
[2];
2557 hostapd_logger(hapd
, sta
->addr
,
2558 HOSTAPD_MODULE_IEEE80211
,
2560 "Multi-AP IE has missing or invalid Multi-AP subelement");
2561 return WLAN_STATUS_INVALID_IE
;
2565 if (multi_ap_value
&& multi_ap_value
!= MULTI_AP_BACKHAUL_STA
)
2566 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2568 "Multi-AP IE with unexpected value 0x%02x",
2571 if (!(multi_ap_value
& MULTI_AP_BACKHAUL_STA
)) {
2572 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
2573 return WLAN_STATUS_SUCCESS
;
2575 hostapd_logger(hapd
, sta
->addr
,
2576 HOSTAPD_MODULE_IEEE80211
,
2578 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2579 return WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
2582 if (!(hapd
->conf
->multi_ap
& BACKHAUL_BSS
))
2583 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2584 HOSTAPD_LEVEL_DEBUG
,
2585 "Backhaul STA tries to associate with fronthaul-only BSS");
2587 sta
->flags
|= WLAN_STA_MULTI_AP
;
2588 return WLAN_STATUS_SUCCESS
;
2592 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2593 struct ieee802_11_elems
*elems
)
2595 /* Supported rates not used in IEEE 802.11ad/DMG */
2596 if (hapd
->iface
->current_mode
&&
2597 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2598 return WLAN_STATUS_SUCCESS
;
2600 if (!elems
->supp_rates
) {
2601 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2602 HOSTAPD_LEVEL_DEBUG
,
2603 "No supported rates element in AssocReq");
2604 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2607 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2608 sizeof(sta
->supported_rates
)) {
2609 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2610 HOSTAPD_LEVEL_DEBUG
,
2611 "Invalid supported rates element length %d+%d",
2612 elems
->supp_rates_len
,
2613 elems
->ext_supp_rates_len
);
2614 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2617 sta
->supported_rates_len
= merge_byte_arrays(
2618 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2619 elems
->supp_rates
, elems
->supp_rates_len
,
2620 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2622 return WLAN_STATUS_SUCCESS
;
2626 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2627 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2629 #ifdef CONFIG_INTERWORKING
2630 /* check for QoS Map support */
2631 if (ext_capab_ie_len
>= 5) {
2632 if (ext_capab_ie
[4] & 0x01)
2633 sta
->qos_map_enabled
= 1;
2635 #endif /* CONFIG_INTERWORKING */
2637 if (ext_capab_ie_len
> 0) {
2638 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2639 os_free(sta
->ext_capability
);
2640 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2641 if (sta
->ext_capability
) {
2642 sta
->ext_capability
[0] = ext_capab_ie_len
;
2643 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2648 return WLAN_STATUS_SUCCESS
;
2654 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2657 int *groups
= hapd
->conf
->owe_groups
;
2659 if (group
!= 19 && group
!= 20 && group
!= 21)
2665 for (i
= 0; groups
[i
] > 0; i
++) {
2666 if (groups
[i
] == group
)
2674 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2675 struct sta_info
*sta
, const u8
*owe_dh
,
2678 struct wpabuf
*secret
, *pub
, *hkey
;
2680 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2681 const char *info
= "OWE Key Generation";
2685 size_t hash_len
, prime_len
;
2687 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2688 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2689 return WLAN_STATUS_SUCCESS
;
2692 group
= WPA_GET_LE16(owe_dh
);
2693 if (!owe_group_supported(hapd
, group
)) {
2694 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2695 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2699 else if (group
== 20)
2701 else if (group
== 21)
2704 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2706 crypto_ecdh_deinit(sta
->owe_ecdh
);
2707 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2709 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2710 sta
->owe_group
= group
;
2712 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2714 secret
= wpabuf_zeropad(secret
, prime_len
);
2716 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2717 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2719 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2721 /* prk = HKDF-extract(C | A | group, z) */
2723 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2725 wpabuf_clear_free(secret
);
2726 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2729 /* PMKID = Truncate-128(Hash(C | A)) */
2730 addr
[0] = owe_dh
+ 2;
2731 len
[0] = owe_dh_len
- 2;
2732 addr
[1] = wpabuf_head(pub
);
2733 len
[1] = wpabuf_len(pub
);
2735 res
= sha256_vector(2, addr
, len
, pmkid
);
2736 hash_len
= SHA256_MAC_LEN
;
2737 } else if (group
== 20) {
2738 res
= sha384_vector(2, addr
, len
, pmkid
);
2739 hash_len
= SHA384_MAC_LEN
;
2740 } else if (group
== 21) {
2741 res
= sha512_vector(2, addr
, len
, pmkid
);
2742 hash_len
= SHA512_MAC_LEN
;
2745 wpabuf_clear_free(secret
);
2746 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2748 pub
= wpabuf_zeropad(pub
, prime_len
);
2749 if (res
< 0 || !pub
) {
2751 wpabuf_clear_free(secret
);
2752 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2755 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2758 wpabuf_clear_free(secret
);
2759 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2762 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2763 wpabuf_put_buf(hkey
, pub
); /* A */
2765 wpabuf_put_le16(hkey
, group
); /* group */
2767 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2768 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2769 else if (group
== 20)
2770 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2771 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2772 else if (group
== 21)
2773 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2774 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2775 wpabuf_clear_free(hkey
);
2776 wpabuf_clear_free(secret
);
2778 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2780 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2782 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2784 os_free(sta
->owe_pmk
);
2785 sta
->owe_pmk
= os_malloc(hash_len
);
2786 if (!sta
->owe_pmk
) {
2787 os_memset(prk
, 0, SHA512_MAC_LEN
);
2788 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2792 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2793 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2794 else if (group
== 20)
2795 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2796 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2797 else if (group
== 21)
2798 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2799 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2800 os_memset(prk
, 0, SHA512_MAC_LEN
);
2802 os_free(sta
->owe_pmk
);
2803 sta
->owe_pmk
= NULL
;
2804 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2806 sta
->owe_pmk_len
= hash_len
;
2808 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2809 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2810 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2811 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2813 return WLAN_STATUS_SUCCESS
;
2817 u16
owe_validate_request(struct hostapd_data
*hapd
, const u8
*peer
,
2818 const u8
*rsn_ie
, size_t rsn_ie_len
,
2819 const u8
*owe_dh
, size_t owe_dh_len
)
2821 struct wpa_ie_data data
;
2824 if (!rsn_ie
|| rsn_ie_len
< 2) {
2825 wpa_printf(MSG_DEBUG
, "OWE: Invalid RSNE from " MACSTR
,
2827 return WLAN_STATUS_INVALID_IE
;
2832 res
= wpa_parse_wpa_ie_rsn(rsn_ie
, rsn_ie_len
, &data
);
2834 wpa_printf(MSG_DEBUG
, "Failed to parse RSNE from " MACSTR
2835 " (res=%d)", MAC2STR(peer
), res
);
2836 wpa_hexdump(MSG_DEBUG
, "RSNE", rsn_ie
, rsn_ie_len
);
2837 return wpa_res_to_status_code(res
);
2839 if (!(data
.key_mgmt
& WPA_KEY_MGMT_OWE
)) {
2840 wpa_printf(MSG_DEBUG
,
2841 "OWE: Unexpected key mgmt 0x%x from " MACSTR
,
2842 (unsigned int) data
.key_mgmt
, MAC2STR(peer
));
2843 return WLAN_STATUS_AKMP_NOT_VALID
;
2846 wpa_printf(MSG_DEBUG
,
2847 "OWE: No Diffie-Hellman Parameter element from "
2848 MACSTR
, MAC2STR(peer
));
2849 return WLAN_STATUS_AKMP_NOT_VALID
;
2852 return WLAN_STATUS_SUCCESS
;
2856 u16
owe_process_rsn_ie(struct hostapd_data
*hapd
,
2857 struct sta_info
*sta
,
2858 const u8
*rsn_ie
, size_t rsn_ie_len
,
2859 const u8
*owe_dh
, size_t owe_dh_len
)
2862 u8
*owe_buf
, ie
[256 * 2];
2866 if (!rsn_ie
|| rsn_ie_len
< 2) {
2867 wpa_printf(MSG_DEBUG
, "OWE: No RSNE in (Re)AssocReq");
2868 status
= WLAN_STATUS_INVALID_IE
;
2873 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
2876 wpa_printf(MSG_WARNING
,
2877 "OWE: Failed to initialize WPA state machine");
2878 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2883 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2884 hapd
->iface
->freq
, rsn_ie
, rsn_ie_len
,
2885 NULL
, 0, owe_dh
, owe_dh_len
);
2886 status
= wpa_res_to_status_code(res
);
2887 if (status
!= WLAN_STATUS_SUCCESS
)
2889 status
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
2890 if (status
!= WLAN_STATUS_SUCCESS
)
2892 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, ie
, sizeof(ie
),
2895 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2899 if (sta
->owe_ecdh
) {
2902 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2904 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2908 /* OWE Diffie-Hellman Parameter element */
2909 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
2910 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
2911 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
2913 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
2915 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
2916 owe_buf
+= wpabuf_len(pub
);
2918 sta
->external_dh_updated
= 1;
2920 ie_len
= owe_buf
- ie
;
2923 wpa_printf(MSG_DEBUG
, "OWE: Update status %d, ie len %d for peer "
2924 MACSTR
, status
, (unsigned int) ie_len
,
2925 MAC2STR(sta
->addr
));
2926 hostapd_drv_update_dh_ie(hapd
, sta
->addr
, status
,
2927 status
== WLAN_STATUS_SUCCESS
? ie
: NULL
,
2933 #endif /* CONFIG_OWE */
2936 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2937 const u8
*ies
, size_t ies_len
, int reassoc
)
2939 struct ieee802_11_elems elems
;
2943 const u8
*p2p_dev_addr
= NULL
;
2945 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2946 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2947 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
2948 "association request");
2949 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2952 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
2953 if (resp
!= WLAN_STATUS_SUCCESS
)
2955 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
2956 if (resp
!= WLAN_STATUS_SUCCESS
)
2958 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
2959 if (resp
!= WLAN_STATUS_SUCCESS
)
2961 resp
= copy_supp_rates(hapd
, sta
, &elems
);
2962 if (resp
!= WLAN_STATUS_SUCCESS
)
2965 resp
= check_multi_ap(hapd
, sta
, elems
.multi_ap
, elems
.multi_ap_len
);
2966 if (resp
!= WLAN_STATUS_SUCCESS
)
2969 #ifdef CONFIG_IEEE80211N
2970 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
2971 if (resp
!= WLAN_STATUS_SUCCESS
)
2973 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
2974 !(sta
->flags
& WLAN_STA_HT
)) {
2975 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2976 HOSTAPD_LEVEL_INFO
, "Station does not support "
2977 "mandatory HT PHY - reject association");
2978 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
2980 #endif /* CONFIG_IEEE80211N */
2982 #ifdef CONFIG_IEEE80211AC
2983 if (hapd
->iconf
->ieee80211ac
) {
2984 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
2985 if (resp
!= WLAN_STATUS_SUCCESS
)
2988 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
2989 if (resp
!= WLAN_STATUS_SUCCESS
)
2993 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
2994 !(sta
->flags
& WLAN_STA_VHT
)) {
2995 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2996 HOSTAPD_LEVEL_INFO
, "Station does not support "
2997 "mandatory VHT PHY - reject association");
2998 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
3001 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
3002 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
3003 elems
.vendor_vht_len
);
3004 if (resp
!= WLAN_STATUS_SUCCESS
)
3007 #endif /* CONFIG_IEEE80211AC */
3008 #ifdef CONFIG_IEEE80211AX
3009 if (hapd
->iconf
->ieee80211ax
) {
3010 resp
= copy_sta_he_capab(hapd
, sta
, IEEE80211_MODE_AP
,
3011 elems
.he_capabilities
,
3012 elems
.he_capabilities_len
);
3013 if (resp
!= WLAN_STATUS_SUCCESS
)
3016 #endif /* CONFIG_IEEE80211AX */
3020 wpabuf_free(sta
->p2p_ie
);
3021 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3022 P2P_IE_VENDOR_TYPE
);
3024 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
3026 wpabuf_free(sta
->p2p_ie
);
3029 #endif /* CONFIG_P2P */
3031 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
3032 wpa_ie
= elems
.rsn_ie
;
3033 wpa_ie_len
= elems
.rsn_ie_len
;
3034 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
3036 wpa_ie
= elems
.wpa_ie
;
3037 wpa_ie_len
= elems
.wpa_ie_len
;
3044 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
3045 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
3046 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
3047 "Request - assume WPS is used");
3048 sta
->flags
|= WLAN_STA_WPS
;
3049 wpabuf_free(sta
->wps_ie
);
3050 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3051 WPS_IE_VENDOR_TYPE
);
3052 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
3053 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
3054 sta
->flags
|= WLAN_STA_WPS2
;
3058 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
3059 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
3060 "(Re)Association Request - reject");
3061 return WLAN_STATUS_INVALID_IE
;
3063 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
3064 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
3065 "(Re)Association Request - possible WPS use");
3066 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
3068 #endif /* CONFIG_WPS */
3069 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
3070 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3072 "No WPA/RSN IE in association request");
3073 return WLAN_STATUS_INVALID_IE
;
3076 if (hapd
->conf
->wpa
&& wpa_ie
) {
3080 if (sta
->wpa_sm
== NULL
)
3081 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3084 if (sta
->wpa_sm
== NULL
) {
3085 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3087 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3089 wpa_auth_set_auth_alg(sta
->wpa_sm
, sta
->auth_alg
);
3090 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
3093 elems
.mdie
, elems
.mdie_len
,
3094 elems
.owe_dh
, elems
.owe_dh_len
);
3095 resp
= wpa_res_to_status_code(res
);
3096 if (resp
!= WLAN_STATUS_SUCCESS
)
3098 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3099 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3100 !sta
->sa_query_timed_out
&&
3101 sta
->sa_query_count
> 0)
3102 ap_check_sa_query_timeout(hapd
, sta
);
3103 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3104 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3105 !sta
->sa_query_timed_out
&&
3106 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
3108 * STA has already been associated with MFP and SA
3109 * Query timeout has not been reached. Reject the
3110 * association attempt temporarily and start SA Query,
3111 * if one is not pending.
3114 if (sta
->sa_query_count
== 0)
3115 ap_sta_start_sa_query(hapd
, sta
);
3117 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
3120 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
3121 sta
->flags
|= WLAN_STA_MFP
;
3123 sta
->flags
&= ~WLAN_STA_MFP
;
3125 #ifdef CONFIG_IEEE80211R_AP
3126 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
3128 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
3129 "to use association (not "
3130 "re-association) with FT auth_alg",
3131 MAC2STR(sta
->addr
));
3132 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3135 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
3137 if (resp
!= WLAN_STATUS_SUCCESS
)
3140 #endif /* CONFIG_IEEE80211R_AP */
3143 if (wpa_auth_uses_sae(sta
->wpa_sm
) && sta
->sae
&&
3144 sta
->sae
->state
== SAE_ACCEPTED
)
3145 wpa_auth_add_sae_pmkid(sta
->wpa_sm
, sta
->sae
->pmkid
);
3147 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3148 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
3149 struct rsn_pmksa_cache_entry
*sa
;
3150 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
3151 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
3152 wpa_printf(MSG_DEBUG
,
3153 "SAE: No PMKSA cache entry found for "
3154 MACSTR
, MAC2STR(sta
->addr
));
3155 return WLAN_STATUS_INVALID_PMKID
;
3157 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
3158 " using PMKSA caching", MAC2STR(sta
->addr
));
3159 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3160 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
3161 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
3162 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
3163 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
3164 "SAE AKM after non-SAE auth_alg %u",
3165 MAC2STR(sta
->addr
), sta
->auth_alg
);
3166 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
3168 #endif /* CONFIG_SAE */
3171 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3172 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
3174 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
3176 if (resp
!= WLAN_STATUS_SUCCESS
)
3179 #endif /* CONFIG_OWE */
3182 dpp_pfs_free(sta
->dpp_pfs
);
3183 sta
->dpp_pfs
= NULL
;
3185 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3186 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
3187 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
3189 sta
->dpp_pfs
= dpp_pfs_init(
3190 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
3191 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
3192 if (!sta
->dpp_pfs
) {
3193 wpa_printf(MSG_DEBUG
,
3194 "DPP: Could not initialize PFS");
3195 /* Try to continue without PFS */
3199 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
3200 elems
.owe_dh_len
) < 0) {
3201 dpp_pfs_free(sta
->dpp_pfs
);
3202 sta
->dpp_pfs
= NULL
;
3203 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3207 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
3208 sta
->dpp_pfs
->secret
: NULL
);
3210 #endif /* CONFIG_DPP2 */
3212 #ifdef CONFIG_IEEE80211N
3213 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
3214 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
3215 hostapd_logger(hapd
, sta
->addr
,
3216 HOSTAPD_MODULE_IEEE80211
,
3218 "Station tried to use TKIP with HT "
3220 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
3222 #endif /* CONFIG_IEEE80211N */
3224 } else if (hapd
->conf
->osen
) {
3225 if (elems
.osen
== NULL
) {
3227 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3229 "No HS 2.0 OSEN element in association request");
3230 return WLAN_STATUS_INVALID_IE
;
3233 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
3234 if (sta
->wpa_sm
== NULL
)
3235 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3237 if (sta
->wpa_sm
== NULL
) {
3238 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3240 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3242 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
3243 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
3244 return WLAN_STATUS_INVALID_IE
;
3245 #endif /* CONFIG_HS20 */
3247 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
3250 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
3251 #endif /* CONFIG_P2P */
3254 wpabuf_free(sta
->hs20_ie
);
3255 if (elems
.hs20
&& elems
.hs20_len
> 4) {
3258 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
3259 elems
.hs20_len
- 4);
3260 release
= ((elems
.hs20
[4] >> 4) & 0x0f) + 1;
3261 if (release
>= 2 && !wpa_auth_uses_mfp(sta
->wpa_sm
) &&
3262 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3263 wpa_printf(MSG_DEBUG
,
3264 "HS 2.0: PMF not negotiated by release %d station "
3265 MACSTR
, release
, MAC2STR(sta
->addr
));
3266 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
3269 sta
->hs20_ie
= NULL
;
3272 wpabuf_free(sta
->roaming_consortium
);
3273 if (elems
.roaming_cons_sel
)
3274 sta
->roaming_consortium
= wpabuf_alloc_copy(
3275 elems
.roaming_cons_sel
+ 4,
3276 elems
.roaming_cons_sel_len
- 4);
3278 sta
->roaming_consortium
= NULL
;
3279 #endif /* CONFIG_HS20 */
3282 wpabuf_free(sta
->mb_ies
);
3283 if (hapd
->iface
->fst
)
3284 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
3287 #endif /* CONFIG_FST */
3290 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
3292 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
3293 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
3294 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3295 wpa_printf(MSG_INFO
,
3296 "MBO: Reject WPA2 association without PMF");
3297 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3299 #endif /* CONFIG_MBO */
3301 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3302 if (wpa_auth_uses_ocv(sta
->wpa_sm
) &&
3303 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3304 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3305 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)) {
3306 struct wpa_channel_info ci
;
3310 if (hostapd_drv_channel_info(hapd
, &ci
) != 0) {
3311 wpa_printf(MSG_WARNING
,
3312 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3313 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3316 if (get_sta_tx_parameters(sta
->wpa_sm
,
3317 channel_width_to_int(ci
.chanwidth
),
3318 ci
.seg1_idx
, &tx_chanwidth
,
3320 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3322 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
3323 tx_chanwidth
, tx_seg1_idx
) != 0) {
3324 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
3325 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3328 #endif /* CONFIG_FILS && CONFIG_OCV */
3330 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
3331 elems
.supp_op_classes_len
);
3333 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
3334 elems
.rrm_enabled
&&
3335 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
3336 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
3337 sizeof(sta
->rrm_enabled_capa
));
3339 if (elems
.power_capab
) {
3340 sta
->min_tx_power
= elems
.power_capab
[0];
3341 sta
->max_tx_power
= elems
.power_capab
[1];
3342 sta
->power_capab
= 1;
3344 sta
->power_capab
= 0;
3347 return WLAN_STATUS_SUCCESS
;
3351 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
3355 struct ieee80211_mgmt reply
;
3357 os_memset(&reply
, 0, sizeof(reply
));
3358 reply
.frame_control
=
3359 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
3360 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
3361 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
3362 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
3364 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
3365 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
3367 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
3368 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
3373 static int add_associated_sta(struct hostapd_data
*hapd
,
3374 struct sta_info
*sta
, int reassoc
)
3376 struct ieee80211_ht_capabilities ht_cap
;
3377 struct ieee80211_vht_capabilities vht_cap
;
3378 struct ieee80211_he_capabilities he_cap
;
3382 * Remove the STA entry to ensure the STA PS state gets cleared and
3383 * configuration gets updated. This is relevant for cases, such as
3384 * FT-over-the-DS, where a station re-associates back to the same AP but
3385 * skips the authentication flow, or if working with a driver that
3386 * does not support full AP client state.
3388 * Skip this if the STA has already completed FT reassociation and the
3389 * TK has been configured since the TX/RX PN must not be reset to 0 for
3392 * FT-over-the-DS has a special case where the STA entry (and as such,
3393 * the TK) has not yet been configured to the driver depending on which
3394 * driver interface is used. For that case, allow add-STA operation to
3395 * be used (instead of set-STA). This is needed to allow mac80211-based
3396 * drivers to accept the STA parameter configuration. Since this is
3397 * after a new FT-over-DS exchange, a new TK has been derived, so key
3398 * reinstallation is not a concern for this case.
3400 wpa_printf(MSG_DEBUG
, "Add associated STA " MACSTR
3401 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3402 MAC2STR(sta
->addr
), sta
->added_unassoc
, sta
->auth_alg
,
3403 sta
->ft_over_ds
, reassoc
,
3404 !!(sta
->flags
& WLAN_STA_AUTHORIZED
),
3405 wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
),
3406 wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
));
3408 if (!sta
->added_unassoc
&&
3409 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3410 (reassoc
&& sta
->ft_over_ds
&& sta
->auth_alg
== WLAN_AUTH_FT
) ||
3411 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
3412 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
3413 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3414 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
3417 /* Do not allow the FT-over-DS exception to be used more than
3418 * once per authentication exchange to guarantee a new TK is
3420 sta
->ft_over_ds
= 0;
3423 #ifdef CONFIG_IEEE80211N
3424 if (sta
->flags
& WLAN_STA_HT
)
3425 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
3426 #endif /* CONFIG_IEEE80211N */
3427 #ifdef CONFIG_IEEE80211AC
3428 if (sta
->flags
& WLAN_STA_VHT
)
3429 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
3430 #endif /* CONFIG_IEEE80211AC */
3431 #ifdef CONFIG_IEEE80211AX
3432 if (sta
->flags
& WLAN_STA_HE
) {
3433 hostapd_get_he_capab(hapd
, sta
->he_capab
, &he_cap
,
3436 #endif /* CONFIG_IEEE80211AX */
3439 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3440 * will be set when the ACK frame for the (Re)Association Response frame
3441 * is processed (TX status driver event).
3443 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
3444 sta
->supported_rates
, sta
->supported_rates_len
,
3445 sta
->listen_interval
,
3446 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
3447 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
3448 sta
->flags
& WLAN_STA_HE
? &he_cap
: NULL
,
3449 sta
->flags
& WLAN_STA_HE
? sta
->he_capab_len
: 0,
3450 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
3451 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
3453 hostapd_logger(hapd
, sta
->addr
,
3454 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
3455 "Could not %s STA to kernel driver",
3456 set
? "set" : "add");
3458 if (sta
->added_unassoc
) {
3459 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3460 sta
->added_unassoc
= 0;
3466 sta
->added_unassoc
= 0;
3472 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3473 const u8
*addr
, u16 status_code
, int reassoc
,
3474 const u8
*ies
, size_t ies_len
, int rssi
)
3479 struct ieee80211_mgmt
*reply
;
3481 u16 res
= WLAN_STATUS_SUCCESS
;
3483 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
3485 if (sta
&& sta
->fils_hlp_resp
)
3486 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
3489 #endif /* CONFIG_FILS */
3491 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3493 #endif /* CONFIG_OWE */
3495 if (sta
&& sta
->dpp_pfs
)
3496 buflen
+= 5 + sta
->dpp_pfs
->curve
->prime_len
;
3497 #endif /* CONFIG_DPP2 */
3498 buf
= os_zalloc(buflen
);
3500 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3503 reply
= (struct ieee80211_mgmt
*) buf
;
3504 reply
->frame_control
=
3505 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3506 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
3507 WLAN_FC_STYPE_ASSOC_RESP
));
3508 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
3509 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
3510 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3512 send_len
= IEEE80211_HDRLEN
;
3513 send_len
+= sizeof(reply
->u
.assoc_resp
);
3514 reply
->u
.assoc_resp
.capab_info
=
3515 host_to_le16(hostapd_own_capab_info(hapd
));
3516 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
3518 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
3520 /* Supported rates */
3521 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
3522 /* Extended supported rates */
3523 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
3526 if (status_code
== WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
3528 int delta
= hapd
->iconf
->rssi_reject_assoc_rssi
- rssi
;
3530 p
= hostapd_eid_mbo_rssi_assoc_rej(hapd
, p
, buf
+ buflen
- p
,
3533 #endif /* CONFIG_MBO */
3535 #ifdef CONFIG_IEEE80211R_AP
3536 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
3537 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3538 * Transition Information, RSN, [RIC Response] */
3539 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
3541 sta
->auth_alg
, ies
, ies_len
);
3543 wpa_printf(MSG_DEBUG
,
3544 "FT: Failed to write AssocResp IEs");
3545 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3549 #endif /* CONFIG_IEEE80211R_AP */
3551 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3552 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3553 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3554 sta
->auth_alg
== WLAN_AUTH_FILS_PK
))
3555 p
= wpa_auth_write_assoc_resp_fils(sta
->wpa_sm
, p
,
3558 #endif /* CONFIG_FILS */
3561 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3562 (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3563 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
3566 #endif /* CONFIG_OWE */
3568 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
3569 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
3571 #ifdef CONFIG_IEEE80211N
3572 p
= hostapd_eid_ht_capabilities(hapd
, p
);
3573 p
= hostapd_eid_ht_operation(hapd
, p
);
3574 #endif /* CONFIG_IEEE80211N */
3576 #ifdef CONFIG_IEEE80211AC
3577 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
) {
3578 u32 nsts
= 0, sta_nsts
;
3580 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
3581 struct ieee80211_vht_capabilities
*capa
;
3583 nsts
= (hapd
->iface
->conf
->vht_capab
>>
3584 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3585 capa
= sta
->vht_capabilities
;
3586 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
3587 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3589 if (nsts
< sta_nsts
)
3594 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
3595 p
= hostapd_eid_vht_operation(hapd
, p
);
3597 #endif /* CONFIG_IEEE80211AC */
3599 #ifdef CONFIG_IEEE80211AX
3600 if (hapd
->iconf
->ieee80211ax
) {
3601 p
= hostapd_eid_he_capab(hapd
, p
, IEEE80211_MODE_AP
);
3602 p
= hostapd_eid_he_operation(hapd
, p
);
3603 p
= hostapd_eid_spatial_reuse(hapd
, p
);
3604 p
= hostapd_eid_he_mu_edca_parameter_set(hapd
, p
);
3606 #endif /* CONFIG_IEEE80211AX */
3608 p
= hostapd_eid_ext_capab(hapd
, p
);
3609 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
3610 if (sta
&& sta
->qos_map_enabled
)
3611 p
= hostapd_eid_qos_map_set(hapd
, p
);
3614 if (hapd
->iface
->fst_ies
) {
3615 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
3616 wpabuf_len(hapd
->iface
->fst_ies
));
3617 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
3619 #endif /* CONFIG_FST */
3622 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3623 sta
&& sta
->owe_ecdh
&& status_code
== WLAN_STATUS_SUCCESS
&&
3624 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
3627 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3629 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3632 /* OWE Diffie-Hellman Parameter element */
3633 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3634 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3635 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3636 WPA_PUT_LE16(p
, sta
->owe_group
);
3638 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
3639 p
+= wpabuf_len(pub
);
3642 #endif /* CONFIG_OWE */
3645 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3646 sta
&& sta
->dpp_pfs
&& status_code
== WLAN_STATUS_SUCCESS
&&
3647 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
) {
3648 os_memcpy(p
, wpabuf_head(sta
->dpp_pfs
->ie
),
3649 wpabuf_len(sta
->dpp_pfs
->ie
));
3650 p
+= wpabuf_len(sta
->dpp_pfs
->ie
);
3652 #endif /* CONFIG_DPP2 */
3654 #ifdef CONFIG_IEEE80211AC
3655 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
3656 p
= hostapd_eid_vendor_vht(hapd
, p
);
3657 #endif /* CONFIG_IEEE80211AC */
3659 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
3660 p
= hostapd_eid_wmm(hapd
, p
);
3664 ((sta
->flags
& WLAN_STA_WPS
) ||
3665 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
3666 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
3668 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
3669 p
+= wpabuf_len(wps
);
3673 #endif /* CONFIG_WPS */
3675 if (sta
&& (sta
->flags
& WLAN_STA_MULTI_AP
))
3676 p
= hostapd_eid_multi_ap(hapd
, p
);
3679 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
3680 struct wpabuf
*p2p_resp_ie
;
3681 enum p2p_status_code status
;
3682 switch (status_code
) {
3683 case WLAN_STATUS_SUCCESS
:
3684 status
= P2P_SC_SUCCESS
;
3686 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
3687 status
= P2P_SC_FAIL_LIMIT_REACHED
;
3690 status
= P2P_SC_FAIL_INVALID_PARAMS
;
3693 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
3695 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
3696 wpabuf_len(p2p_resp_ie
));
3697 p
+= wpabuf_len(p2p_resp_ie
);
3698 wpabuf_free(p2p_resp_ie
);
3701 #endif /* CONFIG_P2P */
3703 #ifdef CONFIG_P2P_MANAGER
3704 if (hapd
->conf
->p2p
& P2P_MANAGE
)
3705 p
= hostapd_eid_p2p_manage(hapd
, p
);
3706 #endif /* CONFIG_P2P_MANAGER */
3708 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
3710 if (hapd
->conf
->assocresp_elements
&&
3711 (size_t) (buf
+ buflen
- p
) >=
3712 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
3713 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
3714 wpabuf_len(hapd
->conf
->assocresp_elements
));
3715 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
3718 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
3722 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3723 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3724 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
3725 status_code
== WLAN_STATUS_SUCCESS
) {
3726 struct ieee802_11_elems elems
;
3728 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
3729 ParseFailed
|| !elems
.fils_session
) {
3730 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3735 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3736 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
3737 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
3738 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
3739 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
3741 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
3742 buflen
, sta
->fils_hlp_resp
);
3744 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3748 #endif /* CONFIG_FILS */
3750 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
3751 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
3753 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3763 u8
* owe_assoc_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3764 const u8
*owe_dh
, u8 owe_dh_len
,
3765 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
3767 #ifdef CONFIG_TESTING_OPTIONS
3768 if (hapd
->conf
->own_ie_override
) {
3769 wpa_printf(MSG_DEBUG
, "OWE: Using IE override");
3770 *reason
= WLAN_STATUS_SUCCESS
;
3771 return wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3772 owe_buf_len
, NULL
, 0);
3774 #endif /* CONFIG_TESTING_OPTIONS */
3776 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
3777 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
3778 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3779 owe_buf_len
, NULL
, 0);
3780 *reason
= WLAN_STATUS_SUCCESS
;
3784 if (sta
->owe_pmk
&& sta
->external_dh_updated
) {
3785 wpa_printf(MSG_DEBUG
, "OWE: Using previously derived PMK");
3786 *reason
= WLAN_STATUS_SUCCESS
;
3790 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3791 if (*reason
!= WLAN_STATUS_SUCCESS
)
3794 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3795 owe_buf_len
, NULL
, 0);
3797 if (sta
->owe_ecdh
&& owe_buf
) {
3800 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3802 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3806 /* OWE Diffie-Hellman Parameter element */
3807 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3808 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3809 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3811 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3813 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3814 owe_buf
+= wpabuf_len(pub
);
3820 #endif /* CONFIG_OWE */
3825 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3829 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3830 MAC2STR(sta
->addr
));
3831 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3832 if (!sta
->fils_pending_assoc_req
)
3834 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3835 sta
->fils_pending_assoc_is_reassoc
,
3836 sta
->fils_pending_assoc_req
,
3837 sta
->fils_pending_assoc_req_len
, 0);
3838 os_free(sta
->fils_pending_assoc_req
);
3839 sta
->fils_pending_assoc_req
= NULL
;
3840 sta
->fils_pending_assoc_req_len
= 0;
3841 wpabuf_free(sta
->fils_hlp_resp
);
3842 sta
->fils_hlp_resp
= NULL
;
3843 wpabuf_free(sta
->hlp_dhcp_discover
);
3844 sta
->hlp_dhcp_discover
= NULL
;
3847 * Remove the station in case transmission of a success response fails.
3848 * At this point the station was already added associated to the driver.
3850 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3851 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3855 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3857 struct hostapd_data
*hapd
= eloop_ctx
;
3858 struct sta_info
*sta
= eloop_data
;
3860 wpa_printf(MSG_DEBUG
,
3861 "FILS: HLP response timeout - continue with association response for "
3862 MACSTR
, MAC2STR(sta
->addr
));
3863 if (sta
->fils_drv_assoc_finish
)
3864 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3866 fils_hlp_finish_assoc(hapd
, sta
);
3869 #endif /* CONFIG_FILS */
3872 static void handle_assoc(struct hostapd_data
*hapd
,
3873 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3874 int reassoc
, int rssi
)
3876 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3877 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3880 struct sta_info
*sta
;
3882 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3883 char *identity
= NULL
;
3884 char *radius_cui
= NULL
;
3886 int delay_assoc
= 0;
3887 #endif /* CONFIG_FILS */
3889 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3890 sizeof(mgmt
->u
.assoc_req
))) {
3891 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3892 reassoc
, (unsigned long) len
);
3896 #ifdef CONFIG_TESTING_OPTIONS
3898 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3899 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3900 wpa_printf(MSG_INFO
,
3901 "TESTING: ignoring reassoc request from "
3902 MACSTR
, MAC2STR(mgmt
->sa
));
3906 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3907 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3908 wpa_printf(MSG_INFO
,
3909 "TESTING: ignoring assoc request from "
3910 MACSTR
, MAC2STR(mgmt
->sa
));
3914 #endif /* CONFIG_TESTING_OPTIONS */
3916 fc
= le_to_host16(mgmt
->frame_control
);
3917 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3920 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
3921 listen_interval
= le_to_host16(
3922 mgmt
->u
.reassoc_req
.listen_interval
);
3923 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
3924 " capab_info=0x%02x listen_interval=%d current_ap="
3925 MACSTR
" seq_ctrl=0x%x%s",
3926 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3927 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
3928 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3929 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
3930 pos
= mgmt
->u
.reassoc_req
.variable
;
3932 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
3933 listen_interval
= le_to_host16(
3934 mgmt
->u
.assoc_req
.listen_interval
);
3935 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
3936 " capab_info=0x%02x listen_interval=%d "
3938 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3939 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3940 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
3941 pos
= mgmt
->u
.assoc_req
.variable
;
3944 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3945 #ifdef CONFIG_IEEE80211R_AP
3946 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
3947 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3948 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
3949 "prior to authentication since it is using "
3950 "over-the-DS FT", MAC2STR(mgmt
->sa
));
3953 * Mark station as authenticated, to avoid adding station
3954 * entry in the driver as associated and not authenticated
3956 sta
->flags
|= WLAN_STA_AUTH
;
3958 #endif /* CONFIG_IEEE80211R_AP */
3959 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3960 if (hapd
->iface
->current_mode
&&
3961 hapd
->iface
->current_mode
->mode
==
3962 HOSTAPD_MODE_IEEE80211AD
) {
3964 u32 session_timeout
, acct_interim_interval
;
3965 struct vlan_description vlan_id
;
3967 acl_res
= ieee802_11_allowed_address(
3968 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
3969 &session_timeout
, &acct_interim_interval
,
3970 &vlan_id
, &psk
, &identity
, &radius_cui
, 0);
3971 if (acl_res
== HOSTAPD_ACL_REJECT
) {
3972 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
3973 "Ignore Association Request frame from "
3974 MACSTR
" due to ACL reject",
3976 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3979 if (acl_res
== HOSTAPD_ACL_PENDING
)
3982 /* DMG/IEEE 802.11ad does not use authentication.
3983 * Allocate sta entry upon association. */
3984 sta
= ap_sta_add(hapd
, mgmt
->sa
);
3986 hostapd_logger(hapd
, mgmt
->sa
,
3987 HOSTAPD_MODULE_IEEE80211
,
3989 "Failed to add STA");
3990 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3994 acl_res
= ieee802_11_set_radius_info(
3995 hapd
, sta
, acl_res
, session_timeout
,
3996 acct_interim_interval
, &vlan_id
, &psk
,
3997 &identity
, &radius_cui
);
3999 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4003 hostapd_logger(hapd
, sta
->addr
,
4004 HOSTAPD_MODULE_IEEE80211
,
4005 HOSTAPD_LEVEL_DEBUG
,
4006 "Skip authentication for DMG/IEEE 802.11ad");
4007 sta
->flags
|= WLAN_STA_AUTH
;
4008 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
4009 sta
->auth_alg
= WLAN_AUTH_OPEN
;
4011 hostapd_logger(hapd
, mgmt
->sa
,
4012 HOSTAPD_MODULE_IEEE80211
,
4014 "Station tried to associate before authentication (aid=%d flags=0x%x)",
4015 sta
? sta
->aid
: -1,
4016 sta
? sta
->flags
: 0);
4017 send_deauth(hapd
, mgmt
->sa
,
4018 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
4023 if ((fc
& WLAN_FC_RETRY
) &&
4024 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4025 sta
->last_seq_ctrl
== seq_ctrl
&&
4026 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4027 WLAN_FC_STYPE_ASSOC_REQ
)) {
4028 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4029 HOSTAPD_LEVEL_DEBUG
,
4030 "Drop repeated association frame seq_ctrl=0x%x",
4034 sta
->last_seq_ctrl
= seq_ctrl
;
4035 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4036 WLAN_FC_STYPE_ASSOC_REQ
;
4038 if (hapd
->tkip_countermeasures
) {
4039 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4043 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
4044 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4045 HOSTAPD_LEVEL_DEBUG
,
4046 "Too large Listen Interval (%d)",
4048 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
4053 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
4054 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4058 if (hapd
->iconf
->rssi_reject_assoc_rssi
&& rssi
&&
4059 rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
&&
4060 (sta
->auth_rssi
== 0 ||
4061 sta
->auth_rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
)) {
4062 resp
= WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
;
4065 #endif /* CONFIG_MBO */
4068 * sta->capability is used in check_assoc_ies() for RRM enabled
4069 * capability element.
4071 sta
->capability
= capab_info
;
4074 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4075 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4076 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4079 /* The end of the payload is encrypted. Need to decrypt it
4080 * before parsing. */
4082 tmp
= os_memdup(pos
, left
);
4084 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4088 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
4091 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4097 #endif /* CONFIG_FILS */
4099 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
4101 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
4102 if (resp
!= WLAN_STATUS_SUCCESS
)
4105 if (hostapd_get_aid(hapd
, sta
) < 0) {
4106 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4107 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
4108 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4112 sta
->listen_interval
= listen_interval
;
4114 if (hapd
->iface
->current_mode
&&
4115 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
4116 sta
->flags
|= WLAN_STA_NONERP
;
4117 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
4118 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
4119 sta
->flags
&= ~WLAN_STA_NONERP
;
4123 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
4124 sta
->nonerp_set
= 1;
4125 hapd
->iface
->num_sta_non_erp
++;
4126 if (hapd
->iface
->num_sta_non_erp
== 1)
4127 ieee802_11_set_beacons(hapd
->iface
);
4130 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
4131 !sta
->no_short_slot_time_set
) {
4132 sta
->no_short_slot_time_set
= 1;
4133 hapd
->iface
->num_sta_no_short_slot_time
++;
4134 if (hapd
->iface
->current_mode
&&
4135 hapd
->iface
->current_mode
->mode
==
4136 HOSTAPD_MODE_IEEE80211G
&&
4137 hapd
->iface
->num_sta_no_short_slot_time
== 1)
4138 ieee802_11_set_beacons(hapd
->iface
);
4141 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
4142 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
4144 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
4146 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
4147 !sta
->no_short_preamble_set
) {
4148 sta
->no_short_preamble_set
= 1;
4149 hapd
->iface
->num_sta_no_short_preamble
++;
4150 if (hapd
->iface
->current_mode
&&
4151 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
4152 && hapd
->iface
->num_sta_no_short_preamble
== 1)
4153 ieee802_11_set_beacons(hapd
->iface
);
4156 #ifdef CONFIG_IEEE80211N
4157 update_ht_state(hapd
, sta
);
4158 #endif /* CONFIG_IEEE80211N */
4160 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4161 HOSTAPD_LEVEL_DEBUG
,
4162 "association OK (aid %d)", sta
->aid
);
4163 /* Station will be marked associated, after it acknowledges AssocResp
4165 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
4167 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
4168 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
4169 "SA Query procedure", reassoc
? "re" : "");
4170 /* TODO: Send a protected Disassociate frame to the STA using
4171 * the old key and Reason Code "Previous Authentication no
4172 * longer valid". Make sure this is only sent protected since
4173 * unprotected frame would be received by the STA that is now
4174 * trying to associate.
4178 /* Make sure that the previously registered inactivity timer will not
4179 * remove the STA immediately. */
4180 sta
->timeout_next
= STA_NULLFUNC
;
4182 #ifdef CONFIG_TAXONOMY
4183 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
4184 #endif /* CONFIG_TAXONOMY */
4186 sta
->pending_wds_enable
= 0;
4189 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4190 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4191 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4192 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
4195 #endif /* CONFIG_FILS */
4199 os_free(radius_cui
);
4200 hostapd_free_psk_list(psk
);
4203 * In case of a successful response, add the station to the driver.
4204 * Otherwise, the kernel may ignore Data frames before we process the
4205 * ACK frame (TX status). In case of a failure, this station will be
4208 * Note that this is not compliant with the IEEE 802.11 standard that
4209 * states that a non-AP station should transition into the
4210 * authenticated/associated state only after the station acknowledges
4211 * the (Re)Association Response frame. However, still do this as:
4213 * 1. In case the station does not acknowledge the (Re)Association
4214 * Response frame, it will be removed.
4215 * 2. Data frames will be dropped in the kernel until the station is
4216 * set into authorized state, and there are no significant known
4217 * issues with processing other non-Data Class 3 frames during this
4220 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&&
4221 add_associated_sta(hapd
, sta
, reassoc
))
4222 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4225 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
&&
4226 eloop_is_timeout_registered(fils_hlp_timeout
, hapd
, sta
) &&
4227 sta
->fils_pending_assoc_req
) {
4228 /* Do not reschedule fils_hlp_timeout in case the station
4229 * retransmits (Re)Association Request frame while waiting for
4230 * the previously started FILS HLP wait, so that the timeout can
4231 * be determined from the first pending attempt. */
4232 wpa_printf(MSG_DEBUG
,
4233 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4234 MACSTR
, MAC2STR(sta
->addr
));
4239 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4240 os_free(sta
->fils_pending_assoc_req
);
4241 sta
->fils_pending_assoc_req
= NULL
;
4242 sta
->fils_pending_assoc_req_len
= 0;
4243 wpabuf_free(sta
->fils_hlp_resp
);
4244 sta
->fils_hlp_resp
= NULL
;
4246 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
4247 sta
->fils_pending_assoc_req
= tmp
;
4248 sta
->fils_pending_assoc_req_len
= left
;
4249 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
4250 sta
->fils_drv_assoc_finish
= 0;
4251 wpa_printf(MSG_DEBUG
,
4252 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4253 MACSTR
, MAC2STR(sta
->addr
));
4254 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4255 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
4256 fils_hlp_timeout
, hapd
, sta
);
4259 #endif /* CONFIG_FILS */
4261 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
4266 * Remove the station in case tranmission of a success response fails
4267 * (the STA was added associated to the driver) or if the station was
4268 * previously added unassociated.
4270 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
4271 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
4272 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4273 sta
->added_unassoc
= 0;
4278 static void handle_disassoc(struct hostapd_data
*hapd
,
4279 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4281 struct sta_info
*sta
;
4283 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
4284 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
4285 (unsigned long) len
);
4289 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
4291 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4293 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4295 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
4300 ap_sta_set_authorized(hapd
, sta
, 0);
4301 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4302 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
4303 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
4304 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4305 HOSTAPD_LEVEL_INFO
, "disassociated");
4306 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4307 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4308 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4310 accounting_sta_stop(hapd
, sta
);
4311 ieee802_1x_free_station(hapd
, sta
);
4313 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
4314 ap_sta_ip6addr_del(hapd
, sta
);
4315 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4316 sta
->added_unassoc
= 0;
4318 if (sta
->timeout_next
== STA_NULLFUNC
||
4319 sta
->timeout_next
== STA_DISASSOC
) {
4320 sta
->timeout_next
= STA_DEAUTH
;
4321 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
4322 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
4326 mlme_disassociate_indication(
4327 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4329 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4330 * disassociation. */
4331 if (hapd
->iface
->current_mode
&&
4332 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
4333 sta
->flags
&= ~WLAN_STA_AUTH
;
4334 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4335 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4336 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4337 ap_free_sta(hapd
, sta
);
4342 static void handle_deauth(struct hostapd_data
*hapd
,
4343 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4345 struct sta_info
*sta
;
4347 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
4348 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
4349 "payload (len=%lu)", (unsigned long) len
);
4353 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
4355 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
4357 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4359 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
4360 "to deauthenticate, but it is not authenticated",
4365 ap_sta_set_authorized(hapd
, sta
, 0);
4366 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4367 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
4368 WLAN_STA_ASSOC_REQ_OK
);
4369 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4370 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4371 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4372 mlme_deauthenticate_indication(
4373 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
4374 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4375 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4376 ap_free_sta(hapd
, sta
);
4380 static void handle_beacon(struct hostapd_data
*hapd
,
4381 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4382 struct hostapd_frame_info
*fi
)
4384 struct ieee802_11_elems elems
;
4386 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
4387 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
4388 (unsigned long) len
);
4392 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
4393 len
- (IEEE80211_HDRLEN
+
4394 sizeof(mgmt
->u
.beacon
)), &elems
,
4397 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
4401 static int robust_action_frame(u8 category
)
4403 return category
!= WLAN_ACTION_PUBLIC
&&
4404 category
!= WLAN_ACTION_HT
;
4408 static int handle_action(struct hostapd_data
*hapd
,
4409 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4412 struct sta_info
*sta
;
4413 u8
*action __maybe_unused
;
4415 if (len
< IEEE80211_HDRLEN
+ 2 + 1) {
4416 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4417 HOSTAPD_LEVEL_DEBUG
,
4418 "handle_action - too short payload (len=%lu)",
4419 (unsigned long) len
);
4423 action
= (u8
*) &mgmt
->u
.action
.u
;
4424 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
4425 " da " MACSTR
" len %d freq %u",
4426 mgmt
->u
.action
.category
, *action
,
4427 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) len
, freq
);
4429 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4431 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
4432 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
4433 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
4434 "frame (category=%u) from unassociated STA " MACSTR
,
4435 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
4439 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
4440 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
4441 robust_action_frame(mgmt
->u
.action
.category
)) {
4442 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4443 HOSTAPD_LEVEL_DEBUG
,
4444 "Dropped unprotected Robust Action frame from "
4450 u16 fc
= le_to_host16(mgmt
->frame_control
);
4451 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4453 if ((fc
& WLAN_FC_RETRY
) &&
4454 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4455 sta
->last_seq_ctrl
== seq_ctrl
&&
4456 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
4457 hostapd_logger(hapd
, sta
->addr
,
4458 HOSTAPD_MODULE_IEEE80211
,
4459 HOSTAPD_LEVEL_DEBUG
,
4460 "Drop repeated action frame seq_ctrl=0x%x",
4465 sta
->last_seq_ctrl
= seq_ctrl
;
4466 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
4469 switch (mgmt
->u
.action
.category
) {
4470 #ifdef CONFIG_IEEE80211R_AP
4471 case WLAN_ACTION_FT
:
4473 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
4474 len
- IEEE80211_HDRLEN
))
4477 #endif /* CONFIG_IEEE80211R_AP */
4478 case WLAN_ACTION_WMM
:
4479 hostapd_wmm_action(hapd
, mgmt
, len
);
4481 case WLAN_ACTION_SA_QUERY
:
4482 ieee802_11_sa_query_action(hapd
, mgmt
, len
);
4484 #ifdef CONFIG_WNM_AP
4485 case WLAN_ACTION_WNM
:
4486 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
4488 #endif /* CONFIG_WNM_AP */
4490 case WLAN_ACTION_FST
:
4491 if (hapd
->iface
->fst
)
4492 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
4494 wpa_printf(MSG_DEBUG
,
4495 "FST: Ignore FST Action frame - no FST attached");
4497 #endif /* CONFIG_FST */
4498 case WLAN_ACTION_PUBLIC
:
4499 case WLAN_ACTION_PROTECTED_DUAL
:
4500 #ifdef CONFIG_IEEE80211N
4501 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4502 mgmt
->u
.action
.u
.public_action
.action
==
4503 WLAN_PA_20_40_BSS_COEX
) {
4504 hostapd_2040_coex_action(hapd
, mgmt
, len
);
4507 #endif /* CONFIG_IEEE80211N */
4509 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4510 mgmt
->u
.action
.u
.vs_public_action
.action
==
4511 WLAN_PA_VENDOR_SPECIFIC
&&
4512 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4514 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4516 const u8
*pos
, *end
;
4518 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
4519 end
= ((const u8
*) mgmt
) + len
;
4520 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
4524 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4525 (mgmt
->u
.action
.u
.public_action
.action
==
4526 WLAN_PA_GAS_INITIAL_RESP
||
4527 mgmt
->u
.action
.u
.public_action
.action
==
4528 WLAN_PA_GAS_COMEBACK_RESP
)) {
4529 const u8
*pos
, *end
;
4531 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
4532 end
= ((const u8
*) mgmt
) + len
;
4533 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
4534 mgmt
->u
.action
.category
,
4535 pos
, end
- pos
, hapd
->iface
->freq
);
4538 #endif /* CONFIG_DPP */
4539 if (hapd
->public_action_cb
) {
4540 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
4544 if (hapd
->public_action_cb2
) {
4545 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
4549 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
4552 case WLAN_ACTION_VENDOR_SPECIFIC
:
4553 if (hapd
->vendor_action_cb
) {
4554 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
4556 hapd
->iface
->freq
) == 0)
4560 case WLAN_ACTION_RADIO_MEASUREMENT
:
4561 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
4565 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4566 HOSTAPD_LEVEL_DEBUG
,
4567 "handle_action - unknown action category %d or invalid "
4569 mgmt
->u
.action
.category
);
4570 if (!is_multicast_ether_addr(mgmt
->da
) &&
4571 !(mgmt
->u
.action
.category
& 0x80) &&
4572 !is_multicast_ether_addr(mgmt
->sa
)) {
4573 struct ieee80211_mgmt
*resp
;
4576 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4577 * Return the Action frame to the source without change
4578 * except that MSB of the Category set to 1.
4580 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
4581 "frame back to sender");
4582 resp
= os_memdup(mgmt
, len
);
4585 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
4586 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
4587 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
4588 resp
->u
.action
.category
|= 0x80;
4590 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
4591 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
4602 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4603 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4605 * @buf: management frame data (starting from IEEE 802.11 header)
4606 * @len: length of frame data in octets
4607 * @fi: meta data about received frame (signal level, etc.)
4609 * Process all incoming IEEE 802.11 management frames. This will be called for
4610 * each frame received from the kernel driver through wlan#ap interface. In
4611 * addition, it can be called to re-inserted pending frames (e.g., when using
4612 * external RADIUS server as an MAC ACL).
4614 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4615 struct hostapd_frame_info
*fi
)
4617 struct ieee80211_mgmt
*mgmt
;
4621 int ssi_signal
= fi
? fi
->ssi_signal
: 0;
4629 freq
= hapd
->iface
->freq
;
4631 mgmt
= (struct ieee80211_mgmt
*) buf
;
4632 fc
= le_to_host16(mgmt
->frame_control
);
4633 stype
= WLAN_FC_GET_STYPE(fc
);
4635 if (is_multicast_ether_addr(mgmt
->sa
) ||
4636 is_zero_ether_addr(mgmt
->sa
) ||
4637 os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
4638 /* Do not process any frames with unexpected/invalid SA so that
4639 * we do not add any state for unexpected STA addresses or end
4640 * up sending out frames to unexpected destination. */
4641 wpa_printf(MSG_DEBUG
, "MGMT: Invalid SA=" MACSTR
4642 " in received frame - ignore this frame silently",
4647 if (stype
== WLAN_FC_STYPE_BEACON
) {
4648 handle_beacon(hapd
, mgmt
, len
, fi
);
4652 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
4654 /* Invitation responses can be sent with the peer MAC as BSSID */
4655 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
4656 stype
== WLAN_FC_STYPE_ACTION
) &&
4657 #endif /* CONFIG_P2P */
4659 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
4660 #endif /* CONFIG_MESH */
4661 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4662 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
4663 MAC2STR(mgmt
->bssid
));
4668 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
4669 handle_probe_req(hapd
, mgmt
, len
, ssi_signal
);
4673 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
4674 stype
!= WLAN_FC_STYPE_ACTION
) &&
4675 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4676 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4677 HOSTAPD_LEVEL_DEBUG
,
4678 "MGMT: DA=" MACSTR
" not our address",
4683 if (hapd
->iconf
->track_sta_max_num
)
4684 sta_track_add(hapd
->iface
, mgmt
->sa
, ssi_signal
);
4687 case WLAN_FC_STYPE_AUTH
:
4688 wpa_printf(MSG_DEBUG
, "mgmt::auth");
4689 handle_auth(hapd
, mgmt
, len
, ssi_signal
, 0);
4692 case WLAN_FC_STYPE_ASSOC_REQ
:
4693 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
4694 handle_assoc(hapd
, mgmt
, len
, 0, ssi_signal
);
4697 case WLAN_FC_STYPE_REASSOC_REQ
:
4698 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
4699 handle_assoc(hapd
, mgmt
, len
, 1, ssi_signal
);
4702 case WLAN_FC_STYPE_DISASSOC
:
4703 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
4704 handle_disassoc(hapd
, mgmt
, len
);
4707 case WLAN_FC_STYPE_DEAUTH
:
4708 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
4709 handle_deauth(hapd
, mgmt
, len
);
4712 case WLAN_FC_STYPE_ACTION
:
4713 wpa_printf(MSG_DEBUG
, "mgmt::action");
4714 ret
= handle_action(hapd
, mgmt
, len
, freq
);
4717 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4718 HOSTAPD_LEVEL_DEBUG
,
4719 "unknown mgmt frame subtype %d", stype
);
4727 static void handle_auth_cb(struct hostapd_data
*hapd
,
4728 const struct ieee80211_mgmt
*mgmt
,
4731 u16 auth_alg
, auth_transaction
, status_code
;
4732 struct sta_info
*sta
;
4734 sta
= ap_get_sta(hapd
, mgmt
->da
);
4736 wpa_printf(MSG_DEBUG
, "handle_auth_cb: STA " MACSTR
4742 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4743 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4744 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
4747 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4748 HOSTAPD_LEVEL_NOTICE
,
4749 "did not acknowledge authentication response");
4753 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
4754 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
4755 (unsigned long) len
);
4759 if (status_code
== WLAN_STATUS_SUCCESS
&&
4760 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
4761 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
4762 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4763 HOSTAPD_LEVEL_INFO
, "authenticated");
4764 sta
->flags
|= WLAN_STA_AUTH
;
4765 if (sta
->added_unassoc
)
4766 hostapd_set_sta_flags(hapd
, sta
);
4771 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
4772 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4773 sta
->added_unassoc
= 0;
4778 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
4779 struct sta_info
*sta
,
4783 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
4785 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
4788 for (i
= 0; i
< 4; i
++) {
4789 if (ssid
->wep
.key
[i
] &&
4790 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
4791 i
== ssid
->wep
.idx
, NULL
, 0,
4792 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
4793 wpa_printf(MSG_WARNING
,
4794 "Could not set WEP keys for WDS interface; %s",
4802 static void handle_assoc_cb(struct hostapd_data
*hapd
,
4803 const struct ieee80211_mgmt
*mgmt
,
4804 size_t len
, int reassoc
, int ok
)
4807 struct sta_info
*sta
;
4810 sta
= ap_get_sta(hapd
, mgmt
->da
);
4812 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4817 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4818 sizeof(mgmt
->u
.assoc_resp
))) {
4819 wpa_printf(MSG_INFO
,
4820 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4821 reassoc
, (unsigned long) len
);
4822 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4827 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4829 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4832 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4833 HOSTAPD_LEVEL_DEBUG
,
4834 "did not acknowledge association response");
4835 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4836 /* The STA is added only in case of SUCCESS */
4837 if (status
== WLAN_STATUS_SUCCESS
)
4838 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4843 if (status
!= WLAN_STATUS_SUCCESS
)
4846 /* Stop previous accounting session, if one is started, and allocate
4847 * new session id for the new session. */
4848 accounting_sta_stop(hapd
, sta
);
4850 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4852 "associated (aid %d)",
4855 if (sta
->flags
& WLAN_STA_ASSOC
)
4857 sta
->flags
|= WLAN_STA_ASSOC
;
4858 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4859 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4860 !hapd
->conf
->osen
) ||
4861 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4862 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4863 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4864 sta
->auth_alg
== WLAN_AUTH_FT
) {
4866 * Open, static WEP, FT protocol, or FILS; no separate
4867 * authorization step.
4869 ap_sta_set_authorized(hapd
, sta
, 1);
4873 mlme_reassociate_indication(hapd
, sta
);
4875 mlme_associate_indication(hapd
, sta
);
4877 sta
->sa_query_timed_out
= 0;
4879 if (sta
->eapol_sm
== NULL
) {
4881 * This STA does not use RADIUS server for EAP authentication,
4882 * so bind it to the selected VLAN interface now, since the
4883 * interface selection is not going to change anymore.
4885 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4887 } else if (sta
->vlan_id
) {
4888 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4889 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4893 hostapd_set_sta_flags(hapd
, sta
);
4895 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4896 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4897 MACSTR
" based on pending request",
4898 MAC2STR(sta
->addr
));
4899 sta
->pending_wds_enable
= 0;
4900 sta
->flags
|= WLAN_STA_WDS
;
4903 if (sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_MULTI_AP
)) {
4905 char ifname_wds
[IFNAMSIZ
+ 1];
4907 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4909 MAC2STR(sta
->addr
), sta
->aid
);
4910 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
4913 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
4916 if (sta
->auth_alg
== WLAN_AUTH_FT
)
4917 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
4919 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
4920 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
4921 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
4924 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4925 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4926 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
4927 fils_set_tk(sta
->wpa_sm
) < 0) {
4928 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
4929 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
4930 WLAN_REASON_UNSPECIFIED
);
4933 #endif /* CONFIG_FILS */
4935 if (sta
->pending_eapol_rx
) {
4936 struct os_reltime now
, age
;
4938 os_get_reltime(&now
);
4939 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
4940 if (age
.sec
== 0 && age
.usec
< 200000) {
4941 wpa_printf(MSG_DEBUG
,
4942 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
4943 MAC2STR(sta
->addr
));
4946 wpabuf_head(sta
->pending_eapol_rx
->buf
),
4947 wpabuf_len(sta
->pending_eapol_rx
->buf
));
4949 wpabuf_free(sta
->pending_eapol_rx
->buf
);
4950 os_free(sta
->pending_eapol_rx
);
4951 sta
->pending_eapol_rx
= NULL
;
4956 static void handle_deauth_cb(struct hostapd_data
*hapd
,
4957 const struct ieee80211_mgmt
*mgmt
,
4960 struct sta_info
*sta
;
4961 if (is_multicast_ether_addr(mgmt
->da
))
4963 sta
= ap_get_sta(hapd
, mgmt
->da
);
4965 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
4966 " not found", MAC2STR(mgmt
->da
));
4970 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
4971 MAC2STR(sta
->addr
));
4973 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4974 "deauth", MAC2STR(sta
->addr
));
4976 ap_sta_deauth_cb(hapd
, sta
);
4980 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
4981 const struct ieee80211_mgmt
*mgmt
,
4984 struct sta_info
*sta
;
4985 if (is_multicast_ether_addr(mgmt
->da
))
4987 sta
= ap_get_sta(hapd
, mgmt
->da
);
4989 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
4990 " not found", MAC2STR(mgmt
->da
));
4994 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
4995 MAC2STR(sta
->addr
));
4997 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4998 "disassoc", MAC2STR(sta
->addr
));
5000 ap_sta_disassoc_cb(hapd
, sta
);
5004 static void handle_action_cb(struct hostapd_data
*hapd
,
5005 const struct ieee80211_mgmt
*mgmt
,
5008 struct sta_info
*sta
;
5009 const struct rrm_measurement_report_element
*report
;
5011 if (is_multicast_ether_addr(mgmt
->da
))
5014 if (len
>= IEEE80211_HDRLEN
+ 6 &&
5015 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5016 mgmt
->u
.action
.u
.vs_public_action
.action
==
5017 WLAN_PA_VENDOR_SPECIFIC
&&
5018 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
5020 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
5022 const u8
*pos
, *end
;
5024 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
5025 end
= ((const u8
*) mgmt
) + len
;
5026 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
5029 if (len
>= IEEE80211_HDRLEN
+ 2 &&
5030 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5031 (mgmt
->u
.action
.u
.public_action
.action
==
5032 WLAN_PA_GAS_INITIAL_REQ
||
5033 mgmt
->u
.action
.u
.public_action
.action
==
5034 WLAN_PA_GAS_COMEBACK_REQ
)) {
5035 const u8
*pos
, *end
;
5037 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
5038 end
= ((const u8
*) mgmt
) + len
;
5039 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
5042 #endif /* CONFIG_DPP */
5043 sta
= ap_get_sta(hapd
, mgmt
->da
);
5045 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
5046 " not found", MAC2STR(mgmt
->da
));
5050 if (len
< 24 + 5 + sizeof(*report
))
5052 report
= (const struct rrm_measurement_report_element
*)
5053 &mgmt
->u
.action
.u
.rrm
.variable
[2];
5054 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
5055 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
5056 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
5058 report
->type
== MEASURE_TYPE_BEACON
)
5059 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
5064 * ieee802_11_mgmt_cb - Process management frame TX status callback
5065 * @hapd: hostapd BSS data structure (the BSS from which the management frame
5067 * @buf: management frame data (starting from IEEE 802.11 header)
5068 * @len: length of frame data in octets
5069 * @stype: management frame subtype from frame control field
5070 * @ok: Whether the frame was ACK'ed
5072 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
5075 const struct ieee80211_mgmt
*mgmt
;
5076 mgmt
= (const struct ieee80211_mgmt
*) buf
;
5078 #ifdef CONFIG_TESTING_OPTIONS
5079 if (hapd
->ext_mgmt_frame_handling
) {
5080 size_t hex_len
= 2 * len
+ 1;
5081 char *hex
= os_malloc(hex_len
);
5084 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
5085 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
5086 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
5092 #endif /* CONFIG_TESTING_OPTIONS */
5095 case WLAN_FC_STYPE_AUTH
:
5096 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
5097 handle_auth_cb(hapd
, mgmt
, len
, ok
);
5099 case WLAN_FC_STYPE_ASSOC_RESP
:
5100 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
5101 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
5103 case WLAN_FC_STYPE_REASSOC_RESP
:
5104 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
5105 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
5107 case WLAN_FC_STYPE_PROBE_RESP
:
5108 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
5110 case WLAN_FC_STYPE_DEAUTH
:
5111 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
5112 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
5114 case WLAN_FC_STYPE_DISASSOC
:
5115 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
5116 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
5118 case WLAN_FC_STYPE_ACTION
:
5119 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
5120 handle_action_cb(hapd
, mgmt
, len
, ok
);
5123 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
5129 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
5136 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
5137 char *buf
, size_t buflen
)
5144 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
5145 const u8
*buf
, size_t len
, int ack
)
5147 struct sta_info
*sta
;
5148 struct hostapd_iface
*iface
= hapd
->iface
;
5150 sta
= ap_get_sta(hapd
, addr
);
5151 if (sta
== NULL
&& iface
->num_bss
> 1) {
5153 for (j
= 0; j
< iface
->num_bss
; j
++) {
5154 hapd
= iface
->bss
[j
];
5155 sta
= ap_get_sta(hapd
, addr
);
5160 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
5162 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
5163 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
5164 "activity poll", MAC2STR(sta
->addr
),
5165 ack
? "ACKed" : "did not ACK");
5167 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5170 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
5174 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
5175 const u8
*data
, size_t len
, int ack
)
5177 struct sta_info
*sta
;
5178 struct hostapd_iface
*iface
= hapd
->iface
;
5180 sta
= ap_get_sta(hapd
, dst
);
5181 if (sta
== NULL
&& iface
->num_bss
> 1) {
5183 for (j
= 0; j
< iface
->num_bss
; j
++) {
5184 hapd
= iface
->bss
[j
];
5185 sta
= ap_get_sta(hapd
, dst
);
5190 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
5191 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
5192 MACSTR
" that is not currently associated",
5197 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
5201 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
5203 struct sta_info
*sta
;
5204 struct hostapd_iface
*iface
= hapd
->iface
;
5206 sta
= ap_get_sta(hapd
, addr
);
5207 if (sta
== NULL
&& iface
->num_bss
> 1) {
5209 for (j
= 0; j
< iface
->num_bss
; j
++) {
5210 hapd
= iface
->bss
[j
];
5211 sta
= ap_get_sta(hapd
, addr
);
5218 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
5219 MAC2STR(sta
->addr
));
5220 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
5223 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
5224 "activity poll", MAC2STR(sta
->addr
));
5225 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5229 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
5232 struct sta_info
*sta
;
5234 sta
= ap_get_sta(hapd
, src
);
5236 ((sta
->flags
& WLAN_STA_ASSOC
) ||
5237 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
5238 if (!hapd
->conf
->wds_sta
)
5241 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
5242 WLAN_STA_ASSOC_REQ_OK
) {
5243 wpa_printf(MSG_DEBUG
,
5244 "Postpone 4-address WDS mode enabling for STA "
5245 MACSTR
" since TX status for AssocResp is not yet known",
5246 MAC2STR(sta
->addr
));
5247 sta
->pending_wds_enable
= 1;
5251 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
5253 char ifname_wds
[IFNAMSIZ
+ 1];
5255 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
5256 "STA " MACSTR
" (aid %u)",
5257 MAC2STR(sta
->addr
), sta
->aid
);
5258 sta
->flags
|= WLAN_STA_WDS
;
5259 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
5260 sta
->addr
, sta
->aid
, 1);
5262 hostapd_set_wds_encryption(hapd
, sta
,
5268 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
5269 MACSTR
, MAC2STR(src
));
5270 if (is_multicast_ether_addr(src
) || is_zero_ether_addr(src
) ||
5271 os_memcmp(src
, hapd
->own_addr
, ETH_ALEN
) == 0) {
5272 /* Broadcast bit set in SA or unexpected SA?! Ignore the frame
5277 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
5278 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
5279 "already been sent, but no TX status yet known - "
5280 "ignore Class 3 frame issue with " MACSTR
,
5285 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
5286 hostapd_drv_sta_disassoc(
5288 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5290 hostapd_drv_sta_deauth(
5292 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5296 #endif /* CONFIG_NATIVE_WINDOWS */