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
,
410 const char *password
= NULL
;
411 struct sae_password_entry
*pw
;
412 const char *rx_id
= NULL
;
414 struct sae_pt
*pt
= NULL
;
417 rx_id
= sta
->sae
->tmp
->pw_id
;
418 use_pt
= sta
->sae
->tmp
->h2e
;
421 if (status_code
== WLAN_STATUS_SUCCESS
)
423 else if (status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
)
426 for (pw
= hapd
->conf
->sae_passwords
; pw
; pw
= pw
->next
) {
427 if (!is_broadcast_ether_addr(pw
->peer_addr
) &&
428 os_memcmp(pw
->peer_addr
, sta
->addr
, ETH_ALEN
) != 0)
430 if ((rx_id
&& !pw
->identifier
) || (!rx_id
&& pw
->identifier
))
432 if (rx_id
&& pw
->identifier
&&
433 os_strcmp(rx_id
, pw
->identifier
) != 0)
435 password
= pw
->password
;
440 password
= hapd
->conf
->ssid
.wpa_passphrase
;
441 pt
= hapd
->conf
->ssid
.pt
;
443 if (!password
|| (use_pt
&& !pt
)) {
444 wpa_printf(MSG_DEBUG
, "SAE: No password available");
448 if (update
&& use_pt
&&
449 sae_prepare_commit_pt(sta
->sae
, pt
, hapd
->own_addr
, sta
->addr
,
453 if (update
&& !use_pt
&&
454 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
455 (u8
*) password
, os_strlen(password
), rx_id
,
457 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
461 if (pw
&& pw
->vlan_id
) {
462 if (!sta
->sae
->tmp
) {
464 "SAE: No temporary data allocated - cannot store VLAN ID");
467 sta
->sae
->tmp
->vlan_id
= pw
->vlan_id
;
470 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
+
471 (rx_id
? 3 + os_strlen(rx_id
) : 0));
474 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
475 sta
->sae
->tmp
->anti_clogging_token
: NULL
, rx_id
);
481 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
482 struct sta_info
*sta
)
486 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
490 sae_write_confirm(sta
->sae
, buf
);
496 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
497 struct sta_info
*sta
,
498 const u8
*bssid
, int update
, int status_code
)
504 data
= auth_build_sae_commit(hapd
, sta
, update
, status_code
);
505 if (!data
&& sta
->sae
->tmp
&& sta
->sae
->tmp
->pw_id
)
506 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
;
508 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
510 status
= (sta
->sae
->tmp
&& sta
->sae
->tmp
->h2e
) ?
511 WLAN_STATUS_SAE_HASH_TO_ELEMENT
: WLAN_STATUS_SUCCESS
;
512 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
513 status
, wpabuf_head(data
),
514 wpabuf_len(data
), "sae-send-commit");
522 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
523 struct sta_info
*sta
,
529 data
= auth_build_sae_confirm(hapd
, sta
);
531 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
533 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
534 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
535 wpabuf_len(data
), "sae-send-confirm");
543 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
545 struct sta_info
*sta
;
546 unsigned int open
= 0;
548 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
551 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
554 if (sta
->sae
->state
!= SAE_COMMITTED
&&
555 sta
->sae
->state
!= SAE_CONFIRMED
)
558 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
562 /* In addition to already existing open SAE sessions, check whether
563 * there are enough pending commit messages in the processing queue to
564 * potentially result in too many open sessions. */
565 if (open
+ dl_list_len(&hapd
->sae_commit_queue
) >=
566 hapd
->conf
->sae_anti_clogging_threshold
)
573 static u8
sae_token_hash(struct hostapd_data
*hapd
, const u8
*addr
)
575 u8 hash
[SHA256_MAC_LEN
];
577 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
578 addr
, ETH_ALEN
, hash
);
583 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
584 const u8
*token
, size_t token_len
)
586 u8 mac
[SHA256_MAC_LEN
];
592 if (token_len
!= SHA256_MAC_LEN
)
594 idx
= sae_token_hash(hapd
, addr
);
595 token_idx
= hapd
->sae_pending_token_idx
[idx
];
596 if (token_idx
== 0 || token_idx
!= WPA_GET_BE16(token
)) {
597 wpa_printf(MSG_DEBUG
, "SAE: Invalid anti-clogging token from "
598 MACSTR
" - token_idx 0x%04x, expected 0x%04x",
599 MAC2STR(addr
), WPA_GET_BE16(token
), token_idx
);
607 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
608 2, addrs
, len
, mac
) < 0 ||
609 os_memcmp_const(token
+ 2, &mac
[2], SHA256_MAC_LEN
- 2) != 0)
612 hapd
->sae_pending_token_idx
[idx
] = 0; /* invalidate used token */
618 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
619 int group
, const u8
*addr
)
623 struct os_reltime now
;
630 os_get_reltime(&now
);
631 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
632 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60) ||
633 hapd
->sae_token_idx
== 0xffff) {
634 if (random_get_bytes(hapd
->sae_token_key
,
635 sizeof(hapd
->sae_token_key
)) < 0)
637 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
638 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
639 hapd
->last_sae_token_key_update
= now
;
640 hapd
->sae_token_idx
= 0;
641 os_memset(hapd
->sae_pending_token_idx
, 0,
642 sizeof(hapd
->sae_pending_token_idx
));
645 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
649 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
651 p_idx
= sae_token_hash(hapd
, addr
);
652 token_idx
= hapd
->sae_pending_token_idx
[p_idx
];
654 hapd
->sae_token_idx
++;
655 token_idx
= hapd
->sae_token_idx
;
656 hapd
->sae_pending_token_idx
[p_idx
] = token_idx
;
658 WPA_PUT_BE16(idx
, token_idx
);
659 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
663 len
[1] = sizeof(idx
);
664 if (hmac_sha256_vector(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
665 2, addrs
, len
, token
) < 0) {
669 WPA_PUT_BE16(token
, token_idx
);
675 static int sae_check_big_sync(struct hostapd_data
*hapd
, struct sta_info
*sta
)
677 if (sta
->sae
->sync
> hapd
->conf
->sae_sync
) {
678 sae_set_state(sta
, SAE_NOTHING
, "Sync > dot11RSNASAESync");
686 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
688 struct hostapd_data
*hapd
= eloop_ctx
;
689 struct sta_info
*sta
= eloop_data
;
692 if (sae_check_big_sync(hapd
, sta
))
695 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
696 " (sync=%d state=%s)",
697 MAC2STR(sta
->addr
), sta
->sae
->sync
,
698 sae_state_txt(sta
->sae
->state
));
700 switch (sta
->sae
->state
) {
702 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0, -1);
703 eloop_register_timeout(0,
704 hapd
->dot11RSNASAERetransPeriod
* 1000,
705 auth_sae_retransmit_timer
, hapd
, sta
);
708 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
709 eloop_register_timeout(0,
710 hapd
->dot11RSNASAERetransPeriod
* 1000,
711 auth_sae_retransmit_timer
, hapd
, sta
);
718 if (ret
!= WLAN_STATUS_SUCCESS
)
719 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
723 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
725 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
729 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
730 struct sta_info
*sta
)
732 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
735 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
736 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
737 auth_sae_retransmit_timer
, hapd
, sta
);
741 static void sae_sme_send_external_auth_status(struct hostapd_data
*hapd
,
742 struct sta_info
*sta
, u16 status
)
744 struct external_auth params
;
746 os_memset(¶ms
, 0, sizeof(params
));
747 params
.status
= status
;
748 params
.bssid
= sta
->addr
;
749 if (status
== WLAN_STATUS_SUCCESS
&& sta
->sae
&&
750 !hapd
->conf
->disable_pmksa_caching
)
751 params
.pmkid
= sta
->sae
->pmkid
;
753 hostapd_drv_send_external_auth_status(hapd
, ¶ms
);
757 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
759 #ifndef CONFIG_NO_VLAN
760 struct vlan_description vlan_desc
;
762 if (sta
->sae
->tmp
&& sta
->sae
->tmp
->vlan_id
> 0) {
763 wpa_printf(MSG_DEBUG
, "SAE: Assign STA " MACSTR
765 MAC2STR(sta
->addr
), sta
->sae
->tmp
->vlan_id
);
767 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
768 vlan_desc
.notempty
= 1;
769 vlan_desc
.untagged
= sta
->sae
->tmp
->vlan_id
;
770 if (!hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
772 "Invalid VLAN ID %d in sae_password",
773 sta
->sae
->tmp
->vlan_id
);
777 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0 ||
778 ap_sta_bind_vlan(hapd
, sta
) < 0) {
780 "Failed to assign VLAN ID %d from sae_password to "
781 MACSTR
, sta
->sae
->tmp
->vlan_id
,
786 #endif /* CONFIG_NO_VLAN */
788 sta
->flags
|= WLAN_STA_AUTH
;
789 sta
->auth_alg
= WLAN_AUTH_SAE
;
790 mlme_authenticate_indication(hapd
, sta
);
791 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
792 sae_set_state(sta
, SAE_ACCEPTED
, "Accept Confirm");
793 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
794 sta
->sae
->pmk
, sta
->sae
->pmkid
);
795 sae_sme_send_external_auth_status(hapd
, sta
, WLAN_STATUS_SUCCESS
);
799 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
800 const u8
*bssid
, u16 auth_transaction
, u16 status_code
,
801 int allow_reuse
, int *sta_removed
)
807 if (auth_transaction
!= 1 && auth_transaction
!= 2)
808 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
810 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
811 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
813 switch (sta
->sae
->state
) {
815 if (auth_transaction
== 1) {
817 sta
->sae
->tmp
->h2e
= status_code
==
818 WLAN_STATUS_SAE_HASH_TO_ELEMENT
;
819 ret
= auth_sae_send_commit(hapd
, sta
, bssid
,
820 !allow_reuse
, status_code
);
823 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
825 if (sae_process_commit(sta
->sae
) < 0)
826 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
829 * In mesh case, both Commit and Confirm are sent
830 * immediately. In infrastructure BSS, by default, only
831 * a single Authentication frame (Commit) is expected
832 * from the AP here and the second one (Confirm) will
833 * be sent once the STA has sent its second
834 * Authentication frame (Confirm). This behavior can be
835 * overridden with explicit configuration so that the
836 * infrastructure BSS case sends both frames together.
838 if ((hapd
->conf
->mesh
& MESH_ENABLED
) ||
839 hapd
->conf
->sae_confirm_immediate
) {
841 * Send both Commit and Confirm immediately
842 * based on SAE finite state machine
843 * Nothing -> Confirm transition.
845 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
848 sae_set_state(sta
, SAE_CONFIRMED
,
849 "Sent Confirm (mesh)");
852 * For infrastructure BSS, send only the Commit
853 * message now to get alternating sequence of
854 * Authentication frames between the AP and STA.
855 * Confirm will be sent in
856 * Committed -> Confirmed/Accepted transition
857 * when receiving Confirm from STA.
861 sae_set_retransmit_timer(hapd
, sta
);
863 hostapd_logger(hapd
, sta
->addr
,
864 HOSTAPD_MODULE_IEEE80211
,
866 "SAE confirm before commit");
870 sae_clear_retransmit_timer(hapd
, sta
);
871 if (auth_transaction
== 1) {
872 if (sae_process_commit(sta
->sae
) < 0)
873 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
875 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
878 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
880 sae_set_retransmit_timer(hapd
, sta
);
881 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
883 * In mesh case, follow SAE finite state machine and
884 * send Commit now, if sync count allows.
886 if (sae_check_big_sync(hapd
, sta
))
887 return WLAN_STATUS_SUCCESS
;
890 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0,
895 sae_set_retransmit_timer(hapd
, sta
);
898 * For instructure BSS, send the postponed Confirm from
899 * Nothing -> Confirmed transition that was reduced to
900 * Nothing -> Committed above.
902 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
906 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
909 * Since this was triggered on Confirm RX, run another
910 * step to get to Accepted without waiting for
913 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
,
914 WLAN_STATUS_SUCCESS
, 0, sta_removed
);
918 sae_clear_retransmit_timer(hapd
, sta
);
919 if (auth_transaction
== 1) {
920 if (sae_check_big_sync(hapd
, sta
))
921 return WLAN_STATUS_SUCCESS
;
924 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1,
929 if (sae_process_commit(sta
->sae
) < 0)
930 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
932 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
936 sae_set_retransmit_timer(hapd
, sta
);
938 sta
->sae
->send_confirm
= 0xffff;
939 sae_accept_sta(hapd
, sta
);
943 if (auth_transaction
== 1 &&
944 (hapd
->conf
->mesh
& MESH_ENABLED
)) {
945 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
946 ") doing reauthentication",
948 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
949 ap_free_sta(hapd
, sta
);
951 } else if (auth_transaction
== 1) {
952 wpa_printf(MSG_DEBUG
, "SAE: Start reauthentication");
953 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1,
957 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
959 if (sae_process_commit(sta
->sae
) < 0)
960 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
962 sae_set_retransmit_timer(hapd
, sta
);
964 if (sae_check_big_sync(hapd
, sta
))
965 return WLAN_STATUS_SUCCESS
;
968 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
969 sae_clear_temp_data(sta
->sae
);
975 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
977 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
979 return WLAN_STATUS_SUCCESS
;
983 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
985 struct sae_data
*sae
= sta
->sae
;
986 int i
, *groups
= hapd
->conf
->sae_groups
;
987 int default_groups
[] = { 19, 0 };
989 if (sae
->state
!= SAE_COMMITTED
)
992 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
995 groups
= default_groups
;
996 for (i
= 0; groups
[i
] > 0; i
++) {
997 if (sae
->group
== groups
[i
])
1001 if (groups
[i
] <= 0) {
1002 wpa_printf(MSG_DEBUG
,
1003 "SAE: Previously selected group not found from the current configuration");
1009 if (groups
[i
] <= 0) {
1010 wpa_printf(MSG_DEBUG
,
1011 "SAE: No alternative group enabled");
1015 if (sae_set_group(sae
, groups
[i
]) < 0)
1020 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
1024 static int sae_status_success(struct hostapd_data
*hapd
, u16 status_code
)
1026 return (hapd
->conf
->sae_pwe
== 0 &&
1027 status_code
== WLAN_STATUS_SUCCESS
) ||
1028 (hapd
->conf
->sae_pwe
== 1 &&
1029 status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
) ||
1030 (hapd
->conf
->sae_pwe
== 2 &&
1031 (status_code
== WLAN_STATUS_SUCCESS
||
1032 status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
));
1036 static int sae_is_group_enabled(struct hostapd_data
*hapd
, int group
)
1038 int *groups
= hapd
->conf
->sae_groups
;
1039 int default_groups
[] = { 19, 0 };
1043 groups
= default_groups
;
1045 for (i
= 0; groups
[i
] > 0; i
++) {
1046 if (groups
[i
] == group
)
1054 static int check_sae_rejected_groups(struct hostapd_data
*hapd
,
1055 const struct wpabuf
*groups
)
1063 pos
= wpabuf_head(groups
);
1064 count
= wpabuf_len(groups
) / 2;
1065 for (i
= 0; i
< count
; i
++) {
1069 group
= WPA_GET_LE16(pos
);
1071 enabled
= sae_is_group_enabled(hapd
, group
);
1072 wpa_printf(MSG_DEBUG
, "SAE: Rejected group %u is %s",
1073 group
, enabled
? "enabled" : "disabled");
1082 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1083 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1084 u16 auth_transaction
, u16 status_code
)
1086 int resp
= WLAN_STATUS_SUCCESS
;
1087 struct wpabuf
*data
= NULL
;
1088 int *groups
= hapd
->conf
->sae_groups
;
1089 int default_groups
[] = { 19, 0 };
1090 const u8
*pos
, *end
;
1091 int sta_removed
= 0;
1094 groups
= default_groups
;
1096 #ifdef CONFIG_TESTING_OPTIONS
1097 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
1098 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
1099 pos
= mgmt
->u
.auth
.variable
;
1100 end
= ((const u8
*) mgmt
) + len
;
1101 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1102 auth_transaction
, resp
, pos
, end
- pos
,
1103 "auth-sae-reflection-attack");
1107 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
1108 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
1109 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1110 auth_transaction
, resp
,
1111 wpabuf_head(hapd
->conf
->sae_commit_override
),
1112 wpabuf_len(hapd
->conf
->sae_commit_override
),
1113 "sae-commit-override");
1116 #endif /* CONFIG_TESTING_OPTIONS */
1118 if (auth_transaction
!= 1 ||
1119 !sae_status_success(hapd
, status_code
)) {
1123 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
1128 sae_set_state(sta
, SAE_NOTHING
, "Init");
1132 if (sta
->mesh_sae_pmksa_caching
) {
1133 wpa_printf(MSG_DEBUG
,
1134 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1135 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
1136 sta
->mesh_sae_pmksa_caching
= 0;
1139 if (auth_transaction
== 1) {
1140 const u8
*token
= NULL
;
1141 size_t token_len
= 0;
1142 int allow_reuse
= 0;
1144 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1145 HOSTAPD_LEVEL_DEBUG
,
1146 "start SAE authentication (RX commit, status=%u (%s))",
1147 status_code
, status2str(status_code
));
1149 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1150 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1152 pos
= mgmt
->u
.auth
.variable
;
1153 end
= ((const u8
*) mgmt
) + len
;
1154 if (pos
+ sizeof(le16
) > end
) {
1155 wpa_printf(MSG_ERROR
,
1156 "SAE: Too short anti-clogging token request");
1157 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1160 resp
= sae_group_allowed(sta
->sae
, groups
,
1162 if (resp
!= WLAN_STATUS_SUCCESS
) {
1163 wpa_printf(MSG_ERROR
,
1164 "SAE: Invalid group in anti-clogging token request");
1167 pos
+= sizeof(le16
);
1169 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
1170 sta
->sae
->tmp
->anti_clogging_token
=
1171 wpabuf_alloc_copy(pos
, end
- pos
);
1172 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
1173 wpa_printf(MSG_ERROR
,
1174 "SAE: Failed to alloc for anti-clogging token");
1175 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1180 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1181 * is 76, a new Commit Message shall be constructed
1182 * with the Anti-Clogging Token from the received
1183 * Authentication frame, and the commit-scalar and
1184 * COMMIT-ELEMENT previously sent.
1186 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0,
1188 if (resp
!= WLAN_STATUS_SUCCESS
) {
1189 wpa_printf(MSG_ERROR
,
1190 "SAE: Failed to send commit message");
1193 sae_set_state(sta
, SAE_COMMITTED
,
1194 "Sent Commit (anti-clogging token case in mesh)");
1196 sae_set_retransmit_timer(hapd
, sta
);
1200 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1202 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1204 wpa_printf(MSG_DEBUG
,
1205 "SAE: Peer did not accept our SAE group");
1206 sae_pick_next_group(hapd
, sta
);
1210 if (!sae_status_success(hapd
, status_code
))
1213 if (!(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1214 sta
->sae
->state
== SAE_COMMITTED
) {
1215 /* This is needed in the infrastructure BSS case to
1216 * address a sequence where a STA entry may remain in
1217 * hostapd across two attempts to do SAE authentication
1218 * by the same STA. The second attempt may end up trying
1219 * to use a different group and that would not be
1220 * allowed if we remain in Committed state with the
1221 * previously set parameters. */
1222 pos
= mgmt
->u
.auth
.variable
;
1223 end
= ((const u8
*) mgmt
) + len
;
1224 if (end
- pos
>= (int) sizeof(le16
) &&
1225 sae_group_allowed(sta
->sae
, groups
,
1226 WPA_GET_LE16(pos
)) ==
1227 WLAN_STATUS_SUCCESS
) {
1228 /* Do not waste resources deriving the same PWE
1229 * again since the same group is reused. */
1230 sae_set_state(sta
, SAE_NOTHING
,
1231 "Allow previous PWE to be reused");
1234 sae_set_state(sta
, SAE_NOTHING
,
1235 "Clear existing state to allow restart");
1236 sae_clear_data(sta
->sae
);
1240 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
1241 ((const u8
*) mgmt
) + len
-
1242 mgmt
->u
.auth
.variable
, &token
,
1243 &token_len
, groups
, status_code
==
1244 WLAN_STATUS_SAE_HASH_TO_ELEMENT
);
1245 if (resp
== SAE_SILENTLY_DISCARD
) {
1246 wpa_printf(MSG_DEBUG
,
1247 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
1248 MAC2STR(sta
->addr
));
1252 if (resp
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1253 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1254 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1255 MACSTR
, MAC2STR(sta
->addr
));
1256 sae_clear_retransmit_timer(hapd
, sta
);
1257 sae_set_state(sta
, SAE_NOTHING
,
1258 "Unknown Password Identifier");
1262 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
1264 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
1265 "incorrect token from " MACSTR
,
1266 MAC2STR(sta
->addr
));
1267 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1271 if (resp
!= WLAN_STATUS_SUCCESS
)
1274 if (sta
->sae
->tmp
&&
1275 check_sae_rejected_groups(
1276 hapd
, sta
->sae
->tmp
->peer_rejected_groups
) < 0) {
1277 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1281 if (!token
&& use_sae_anti_clogging(hapd
) && !allow_reuse
) {
1282 wpa_printf(MSG_DEBUG
,
1283 "SAE: Request anti-clogging token from "
1284 MACSTR
, MAC2STR(sta
->addr
));
1285 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
1287 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
1288 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1289 sae_set_state(sta
, SAE_NOTHING
,
1290 "Request anti-clogging token case in mesh");
1294 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1295 status_code
, allow_reuse
, &sta_removed
);
1296 } else if (auth_transaction
== 2) {
1297 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1298 HOSTAPD_LEVEL_DEBUG
,
1299 "SAE authentication (RX confirm, status=%u (%s))",
1300 status_code
, status2str(status_code
));
1301 if (status_code
!= WLAN_STATUS_SUCCESS
)
1303 if (sta
->sae
->state
>= SAE_CONFIRMED
||
1304 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
1307 u16 peer_send_confirm
;
1309 var
= mgmt
->u
.auth
.variable
;
1310 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
1312 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1316 peer_send_confirm
= WPA_GET_LE16(var
);
1318 if (sta
->sae
->state
== SAE_ACCEPTED
&&
1319 (peer_send_confirm
<= sta
->sae
->rc
||
1320 peer_send_confirm
== 0xffff)) {
1321 wpa_printf(MSG_DEBUG
,
1322 "SAE: Silently ignore unexpected Confirm from peer "
1324 " (peer-send-confirm=%u Rc=%u)",
1326 peer_send_confirm
, sta
->sae
->rc
);
1330 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
1331 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1334 sta
->sae
->rc
= peer_send_confirm
;
1336 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
,
1337 status_code
, 0, &sta_removed
);
1339 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1340 HOSTAPD_LEVEL_DEBUG
,
1341 "unexpected SAE authentication transaction %u (status=%u (%s))",
1342 auth_transaction
, status_code
,
1343 status2str(status_code
));
1344 if (status_code
!= WLAN_STATUS_SUCCESS
)
1346 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1350 if (!sta_removed
&& resp
!= WLAN_STATUS_SUCCESS
) {
1351 pos
= mgmt
->u
.auth
.variable
;
1352 end
= ((const u8
*) mgmt
) + len
;
1354 /* Copy the Finite Cyclic Group field from the request if we
1355 * rejected it as unsupported group. */
1356 if (resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1357 !data
&& end
- pos
>= 2)
1358 data
= wpabuf_alloc_copy(pos
, 2);
1360 sae_sme_send_external_auth_status(hapd
, sta
, resp
);
1361 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1362 auth_transaction
, resp
,
1363 data
? wpabuf_head(data
) : (u8
*) "",
1364 data
? wpabuf_len(data
) : 0, "auth-sae");
1368 if (!sta_removed
&& sta
->added_unassoc
&&
1369 (resp
!= WLAN_STATUS_SUCCESS
||
1370 status_code
!= WLAN_STATUS_SUCCESS
)) {
1371 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1372 sta
->added_unassoc
= 0;
1379 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1380 * @hapd: BSS data for the device initiating the authentication
1381 * @sta: the peer to which commit authentication frame is sent
1383 * This function implements Init event handling (IEEE Std 802.11-2012,
1384 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1385 * sta->sae structure should be initialized appropriately via a call to
1386 * sae_prepare_commit().
1388 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1392 if (!sta
->sae
|| !sta
->sae
->tmp
)
1395 if (sta
->sae
->state
!= SAE_NOTHING
)
1398 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0, -1);
1402 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1404 sae_set_retransmit_timer(hapd
, sta
);
1410 void auth_sae_process_commit(void *eloop_ctx
, void *user_ctx
)
1412 struct hostapd_data
*hapd
= eloop_ctx
;
1413 struct hostapd_sae_commit_queue
*q
;
1414 unsigned int queue_len
;
1416 q
= dl_list_first(&hapd
->sae_commit_queue
,
1417 struct hostapd_sae_commit_queue
, list
);
1420 wpa_printf(MSG_DEBUG
,
1421 "SAE: Process next available message from queue");
1422 dl_list_del(&q
->list
);
1423 handle_auth(hapd
, (const struct ieee80211_mgmt
*) q
->msg
, q
->len
,
1427 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1429 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1430 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1435 static void auth_sae_queue(struct hostapd_data
*hapd
,
1436 const struct ieee80211_mgmt
*mgmt
, size_t len
,
1439 struct hostapd_sae_commit_queue
*q
, *q2
;
1440 unsigned int queue_len
;
1441 const struct ieee80211_mgmt
*mgmt2
;
1443 queue_len
= dl_list_len(&hapd
->sae_commit_queue
);
1444 if (queue_len
>= 15) {
1445 wpa_printf(MSG_DEBUG
,
1446 "SAE: No more room in message queue - drop the new frame from "
1447 MACSTR
, MAC2STR(mgmt
->sa
));
1451 wpa_printf(MSG_DEBUG
, "SAE: Queue Authentication message from "
1452 MACSTR
" for processing (queue_len %u)", MAC2STR(mgmt
->sa
),
1454 q
= os_zalloc(sizeof(*q
) + len
);
1459 os_memcpy(q
->msg
, mgmt
, len
);
1461 /* Check whether there is already a queued Authentication frame from the
1462 * same station with the same transaction number and if so, replace that
1463 * queue entry with the new one. This avoids issues with a peer that
1464 * sends multiple times (e.g., due to frequent SAE retries). There is no
1465 * point in us trying to process the old attempts after a new one has
1466 * obsoleted them. */
1467 dl_list_for_each(q2
, &hapd
->sae_commit_queue
,
1468 struct hostapd_sae_commit_queue
, list
) {
1469 mgmt2
= (const struct ieee80211_mgmt
*) q2
->msg
;
1470 if (os_memcmp(mgmt
->sa
, mgmt2
->sa
, ETH_ALEN
) == 0 &&
1471 mgmt
->u
.auth
.auth_transaction
==
1472 mgmt2
->u
.auth
.auth_transaction
) {
1473 wpa_printf(MSG_DEBUG
,
1474 "SAE: Replace queued message from same STA with same transaction number");
1475 dl_list_add(&q2
->list
, &q
->list
);
1476 dl_list_del(&q2
->list
);
1482 /* No pending identical entry, so add to the end of the queue */
1483 dl_list_add_tail(&hapd
->sae_commit_queue
, &q
->list
);
1486 if (eloop_is_timeout_registered(auth_sae_process_commit
, hapd
, NULL
))
1488 eloop_register_timeout(0, queue_len
* 10000, auth_sae_process_commit
,
1493 static int auth_sae_queued_addr(struct hostapd_data
*hapd
, const u8
*addr
)
1495 struct hostapd_sae_commit_queue
*q
;
1496 const struct ieee80211_mgmt
*mgmt
;
1498 dl_list_for_each(q
, &hapd
->sae_commit_queue
,
1499 struct hostapd_sae_commit_queue
, list
) {
1500 mgmt
= (const struct ieee80211_mgmt
*) q
->msg
;
1501 if (os_memcmp(addr
, mgmt
->sa
, ETH_ALEN
) == 0)
1508 #endif /* CONFIG_SAE */
1511 static u16
wpa_res_to_status_code(int res
)
1513 if (res
== WPA_INVALID_GROUP
)
1514 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1515 if (res
== WPA_INVALID_PAIRWISE
)
1516 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1517 if (res
== WPA_INVALID_AKMP
)
1518 return WLAN_STATUS_AKMP_NOT_VALID
;
1519 if (res
== WPA_ALLOC_FAIL
)
1520 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1521 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1522 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1523 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1524 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1525 if (res
== WPA_INVALID_MDIE
)
1526 return WLAN_STATUS_INVALID_MDIE
;
1527 if (res
== WPA_INVALID_PMKID
)
1528 return WLAN_STATUS_INVALID_PMKID
;
1529 if (res
!= WPA_IE_OK
)
1530 return WLAN_STATUS_INVALID_IE
;
1531 return WLAN_STATUS_SUCCESS
;
1537 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1538 struct sta_info
*sta
, u16 resp
,
1539 struct wpabuf
*data
, int pub
);
1541 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1542 const u8
*pos
, size_t len
, u16 auth_alg
,
1543 u16 auth_transaction
, u16 status_code
,
1544 void (*cb
)(struct hostapd_data
*hapd
,
1545 struct sta_info
*sta
, u16 resp
,
1546 struct wpabuf
*data
, int pub
))
1548 u16 resp
= WLAN_STATUS_SUCCESS
;
1550 struct ieee802_11_elems elems
;
1552 struct wpa_ie_data rsn
;
1553 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1555 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1560 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1564 #ifdef CONFIG_FILS_SK_PFS
1565 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1570 /* Using FILS PFS */
1572 /* Finite Cyclic Group */
1573 if (end
- pos
< 2) {
1574 wpa_printf(MSG_DEBUG
,
1575 "FILS: No room for Finite Cyclic Group");
1576 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1579 group
= WPA_GET_LE16(pos
);
1581 if (group
!= hapd
->conf
->fils_dh_group
) {
1582 wpa_printf(MSG_DEBUG
,
1583 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1584 group
, hapd
->conf
->fils_dh_group
);
1585 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1589 crypto_ecdh_deinit(sta
->fils_ecdh
);
1590 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1591 if (!sta
->fils_ecdh
) {
1592 wpa_printf(MSG_INFO
,
1593 "FILS: Could not initialize ECDH with group %d",
1595 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1599 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1601 wpa_printf(MSG_DEBUG
,
1602 "FILS: Failed to derive ECDH public key");
1603 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1606 elem_len
= wpabuf_len(pub
);
1610 if ((size_t) (end
- pos
) < elem_len
) {
1611 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1612 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1616 wpabuf_free(sta
->fils_g_sta
);
1617 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1618 wpabuf_clear_free(sta
->fils_dh_ss
);
1619 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1621 if (!sta
->fils_dh_ss
) {
1622 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1623 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1626 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1629 crypto_ecdh_deinit(sta
->fils_ecdh
);
1630 sta
->fils_ecdh
= NULL
;
1631 wpabuf_clear_free(sta
->fils_dh_ss
);
1632 sta
->fils_dh_ss
= NULL
;
1634 #endif /* CONFIG_FILS_SK_PFS */
1636 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1637 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1638 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1639 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1644 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1645 elems
.rsn_ie
, elems
.rsn_ie_len
);
1646 if (!elems
.rsn_ie
||
1647 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1649 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1650 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1655 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1658 wpa_printf(MSG_DEBUG
,
1659 "FILS: Failed to initialize RSN state machine");
1660 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1664 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1666 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1667 elems
.rsnxe
? elems
.rsnxe
- 2 : NULL
,
1668 elems
.rsnxe
? elems
.rsnxe_len
+ 2 : 0,
1669 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1670 resp
= wpa_res_to_status_code(res
);
1671 if (resp
!= WLAN_STATUS_SUCCESS
)
1674 if (!elems
.fils_nonce
) {
1675 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1676 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1679 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1681 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1684 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1688 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1689 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1692 num
= rsn
.num_pmkid
;
1694 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1695 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1699 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1708 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1709 wpa_printf(MSG_DEBUG
,
1710 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1711 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1715 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1718 if (!elems
.fils_session
) {
1719 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1720 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1723 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1725 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1727 /* FILS Wrapped Data */
1728 if (elems
.fils_wrapped_data
) {
1729 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1730 elems
.fils_wrapped_data
,
1731 elems
.fils_wrapped_data_len
);
1733 #ifndef CONFIG_NO_RADIUS
1734 if (!sta
->eapol_sm
) {
1736 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1738 wpa_printf(MSG_DEBUG
,
1739 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1740 ieee802_1x_encapsulate_radius(
1741 hapd
, sta
, elems
.fils_wrapped_data
,
1742 elems
.fils_wrapped_data_len
);
1743 sta
->fils_pending_cb
= cb
;
1744 wpa_printf(MSG_DEBUG
,
1745 "FILS: Will send Authentication frame once the response from authentication server is available");
1746 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1747 /* Calculate pending PMKID here so that we do not need
1748 * to maintain a copy of the EAP-Initiate/Reauth
1750 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1751 elems
.fils_wrapped_data
,
1752 elems
.fils_wrapped_data_len
,
1753 sta
->fils_erp_pmkid
) == 0)
1754 sta
->fils_erp_pmkid_set
= 1;
1756 #else /* CONFIG_NO_RADIUS */
1757 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1759 #endif /* CONFIG_NO_RADIUS */
1765 struct wpabuf
*data
;
1768 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1771 wpa_printf(MSG_DEBUG
,
1772 "%s: prepare_auth_resp_fils() returned failure",
1776 cb(hapd
, sta
, resp
, data
, pub
);
1781 static struct wpabuf
*
1782 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1783 struct sta_info
*sta
, u16
*resp
,
1784 struct rsn_pmksa_cache_entry
*pmksa
,
1785 struct wpabuf
*erp_resp
,
1786 const u8
*msk
, size_t msk_len
,
1789 u8 fils_nonce
[FILS_NONCE_LEN
];
1791 struct wpabuf
*data
= NULL
;
1794 const u8
*pmk
= NULL
;
1796 u8 pmk_buf
[PMK_LEN_MAX
];
1797 struct wpabuf
*pub
= NULL
;
1799 if (*resp
!= WLAN_STATUS_SUCCESS
)
1802 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1804 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1809 /* Add PMKID of the selected PMKSA into RSNE */
1810 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1812 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1816 os_memcpy(ie_buf
, ie
, ielen
);
1817 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1818 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1824 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1825 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1828 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1829 fils_nonce
, FILS_NONCE_LEN
);
1831 #ifdef CONFIG_FILS_SK_PFS
1832 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1833 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1835 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1839 #endif /* CONFIG_FILS_SK_PFS */
1841 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1843 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1848 #ifdef CONFIG_FILS_SK_PFS
1850 /* Finite Cyclic Group */
1851 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1854 wpabuf_put_buf(data
, pub
);
1856 #endif /* CONFIG_FILS_SK_PFS */
1859 wpabuf_put_data(data
, ie
, ielen
);
1861 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1863 #ifdef CONFIG_IEEE80211R_AP
1864 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1865 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1867 int use_sha384
= wpa_key_mgmt_sha384(
1868 wpa_auth_sta_key_mgmt(sta
->wpa_sm
));
1870 res
= wpa_auth_write_fte(hapd
->wpa_auth
, use_sha384
,
1871 wpabuf_put(data
, 0),
1872 wpabuf_tailroom(data
));
1874 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1877 wpabuf_put(data
, res
);
1879 #endif /* CONFIG_IEEE80211R_AP */
1882 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1883 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1884 /* Element ID Extension */
1885 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1886 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1889 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1890 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1891 /* Element ID Extension */
1892 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1893 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1895 /* FILS Wrapped Data */
1896 if (!pmksa
&& erp_resp
) {
1897 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1898 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1899 /* Element ID Extension */
1900 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1901 wpabuf_put_buf(data
, erp_resp
);
1903 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1904 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1906 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1908 wpabuf_len(sta
->fils_dh_ss
) : 0,
1909 pmk_buf
, &pmk_len
)) {
1910 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1911 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1918 /* Don't use DHss in PTK derivation if PMKSA caching is not
1920 wpabuf_clear_free(sta
->fils_dh_ss
);
1921 sta
->fils_dh_ss
= NULL
;
1923 if (sta
->fils_erp_pmkid_set
) {
1924 /* TODO: get PMKLifetime from WPA parameters */
1925 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1926 int session_timeout
;
1928 session_timeout
= dot11RSNAConfigPMKLifetime
;
1929 if (sta
->session_timeout_set
) {
1930 struct os_reltime now
, diff
;
1932 os_get_reltime(&now
);
1933 os_reltime_sub(&sta
->session_timeout
, &now
,
1935 session_timeout
= diff
.sec
;
1938 sta
->fils_erp_pmkid_set
= 0;
1939 wpa_auth_add_fils_pmk_pmkid(sta
->wpa_sm
, pmk
, pmk_len
,
1940 sta
->fils_erp_pmkid
);
1941 if (!hapd
->conf
->disable_pmksa_caching
&&
1942 wpa_auth_pmksa_add2(
1943 hapd
->wpa_auth
, sta
->addr
,
1945 sta
->fils_erp_pmkid
,
1947 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1948 wpa_printf(MSG_ERROR
,
1949 "FILS: Failed to add PMKSA cache entry based on ERP");
1954 pmk_len
= pmksa
->pmk_len
;
1958 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1959 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1965 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1966 sta
->fils_snonce
, fils_nonce
,
1968 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1970 wpabuf_len(sta
->fils_dh_ss
) : 0,
1971 sta
->fils_g_sta
, pub
) < 0) {
1972 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1980 *is_pub
= pub
!= NULL
;
1983 wpabuf_clear_free(sta
->fils_dh_ss
);
1984 sta
->fils_dh_ss
= NULL
;
1985 #ifdef CONFIG_FILS_SK_PFS
1986 crypto_ecdh_deinit(sta
->fils_ecdh
);
1987 sta
->fils_ecdh
= NULL
;
1988 #endif /* CONFIG_FILS_SK_PFS */
1993 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1994 struct sta_info
*sta
, u16 resp
,
1995 struct wpabuf
*data
, int pub
)
2000 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
2001 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
2002 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
2003 data
? wpabuf_head(data
) : (u8
*) "",
2004 data
? wpabuf_len(data
) : 0, "auth-fils-finish");
2007 if (resp
== WLAN_STATUS_SUCCESS
) {
2008 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2009 HOSTAPD_LEVEL_DEBUG
,
2010 "authentication OK (FILS)");
2011 sta
->flags
|= WLAN_STA_AUTH
;
2012 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2013 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
2014 mlme_authenticate_indication(hapd
, sta
);
2019 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
2020 struct sta_info
*sta
, int success
,
2021 struct wpabuf
*erp_resp
,
2022 const u8
*msk
, size_t msk_len
)
2024 struct wpabuf
*data
;
2028 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2030 if (!sta
->fils_pending_cb
)
2032 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
2033 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
2034 msk
, msk_len
, &pub
);
2036 wpa_printf(MSG_DEBUG
,
2037 "%s: prepare_auth_resp_fils() returned failure",
2040 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
2043 #endif /* CONFIG_FILS */
2047 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
2048 const u8
*msg
, size_t len
, u32
*session_timeout
,
2049 u32
*acct_interim_interval
,
2050 struct vlan_description
*vlan_id
,
2051 struct hostapd_sta_wpa_psk_short
**psk
,
2052 char **identity
, char **radius_cui
, int is_probe_req
)
2056 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
2057 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
2058 session_timeout
, acct_interim_interval
,
2059 vlan_id
, psk
, identity
, radius_cui
,
2062 if (res
== HOSTAPD_ACL_REJECT
) {
2064 wpa_printf(MSG_DEBUG
,
2066 " not allowed to authenticate",
2068 return HOSTAPD_ACL_REJECT
;
2071 if (res
== HOSTAPD_ACL_PENDING
) {
2072 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
2073 " waiting for an external authentication",
2075 /* Authentication code will re-send the authentication frame
2076 * after it has received (and cached) information from the
2077 * external source. */
2078 return HOSTAPD_ACL_PENDING
;
2086 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2087 int res
, u32 session_timeout
,
2088 u32 acct_interim_interval
,
2089 struct vlan_description
*vlan_id
,
2090 struct hostapd_sta_wpa_psk_short
**psk
,
2091 char **identity
, char **radius_cui
)
2093 if (vlan_id
->notempty
&&
2094 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
2095 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2097 "Invalid VLAN %d%s received from RADIUS server",
2099 vlan_id
->tagged
[0] ? "+" : "");
2102 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
2105 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
2106 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
2108 hostapd_free_psk_list(sta
->psk
);
2109 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
2116 os_free(sta
->identity
);
2117 sta
->identity
= *identity
;
2120 os_free(sta
->radius_cui
);
2121 sta
->radius_cui
= *radius_cui
;
2124 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
2125 sta
->acct_interim_interval
= acct_interim_interval
;
2126 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
) {
2127 sta
->session_timeout_set
= 1;
2128 os_get_reltime(&sta
->session_timeout
);
2129 sta
->session_timeout
.sec
+= session_timeout
;
2130 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
2132 sta
->session_timeout_set
= 0;
2133 ap_sta_no_session_timeout(hapd
, sta
);
2140 static void handle_auth(struct hostapd_data
*hapd
,
2141 const struct ieee80211_mgmt
*mgmt
, size_t len
,
2142 int rssi
, int from_queue
)
2144 u16 auth_alg
, auth_transaction
, status_code
;
2145 u16 resp
= WLAN_STATUS_SUCCESS
;
2146 struct sta_info
*sta
= NULL
;
2149 const u8
*challenge
= NULL
;
2150 u32 session_timeout
, acct_interim_interval
;
2151 struct vlan_description vlan_id
;
2152 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
2153 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
2154 size_t resp_ies_len
= 0;
2155 char *identity
= NULL
;
2156 char *radius_cui
= NULL
;
2159 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
2160 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
2161 (unsigned long) len
);
2165 #ifdef CONFIG_TESTING_OPTIONS
2166 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
2167 drand48() < hapd
->iconf
->ignore_auth_probability
) {
2168 wpa_printf(MSG_INFO
,
2169 "TESTING: ignoring auth frame from " MACSTR
,
2173 #endif /* CONFIG_TESTING_OPTIONS */
2175 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
2176 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
2177 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
2178 fc
= le_to_host16(mgmt
->frame_control
);
2179 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
2181 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
2182 2 + WLAN_AUTH_CHALLENGE_LEN
&&
2183 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
2184 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
2185 challenge
= &mgmt
->u
.auth
.variable
[2];
2187 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
2188 "auth_transaction=%d status_code=%d wep=%d%s "
2189 "seq_ctrl=0x%x%s%s",
2190 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
2191 status_code
, !!(fc
& WLAN_FC_ISWEP
),
2192 challenge
? " challenge" : "",
2193 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "",
2194 from_queue
? " (from queue)" : "");
2196 #ifdef CONFIG_NO_RC4
2197 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
2198 wpa_printf(MSG_INFO
,
2199 "Unsupported authentication algorithm (%d)",
2201 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2204 #endif /* CONFIG_NO_RC4 */
2206 if (hapd
->tkip_countermeasures
) {
2207 wpa_printf(MSG_DEBUG
,
2208 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2209 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2213 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
2214 auth_alg
== WLAN_AUTH_OPEN
) ||
2215 #ifdef CONFIG_IEEE80211R_AP
2216 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
2217 auth_alg
== WLAN_AUTH_FT
) ||
2218 #endif /* CONFIG_IEEE80211R_AP */
2220 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
2221 auth_alg
== WLAN_AUTH_SAE
) ||
2222 #endif /* CONFIG_SAE */
2224 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2225 auth_alg
== WLAN_AUTH_FILS_SK
) ||
2226 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
2227 hapd
->conf
->fils_dh_group
&&
2228 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
2229 #endif /* CONFIG_FILS */
2230 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
2231 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
2232 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
2234 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2238 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
2239 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
2240 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
2242 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
2246 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
2247 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
2249 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2253 if (hapd
->conf
->no_auth_if_seen_on
) {
2254 struct hostapd_data
*other
;
2256 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
2257 hapd
->conf
->no_auth_if_seen_on
);
2261 u8 op_class
, channel
, phytype
;
2263 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
2264 MACSTR
" since STA has been seen on %s",
2265 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
2266 hapd
->conf
->no_auth_if_seen_on
);
2268 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
2270 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
2272 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
2274 info
= 0; /* TODO: BSSID Information */
2275 WPA_PUT_LE32(pos
, info
);
2277 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
2278 phytype
= 8; /* dmg */
2279 else if (other
->iconf
->ieee80211ac
)
2280 phytype
= 9; /* vht */
2281 else if (other
->iconf
->ieee80211n
)
2282 phytype
= 7; /* ht */
2283 else if (other
->iconf
->hw_mode
==
2284 HOSTAPD_MODE_IEEE80211A
)
2285 phytype
= 4; /* ofdm */
2286 else if (other
->iconf
->hw_mode
==
2287 HOSTAPD_MODE_IEEE80211G
)
2288 phytype
= 6; /* erp */
2290 phytype
= 5; /* hrdsss */
2291 if (ieee80211_freq_to_channel_ext(
2292 hostapd_hw_get_freq(other
,
2293 other
->iconf
->channel
),
2294 other
->iconf
->secondary_channel
,
2295 other
->iconf
->ieee80211ac
,
2296 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
2298 channel
= other
->iconf
->channel
;
2303 resp_ies_len
= pos
- &resp_ies
[0];
2308 res
= ieee802_11_allowed_address(
2309 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
2310 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
,
2312 if (res
== HOSTAPD_ACL_REJECT
) {
2313 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
2314 "Ignore Authentication frame from " MACSTR
2315 " due to ACL reject", MAC2STR(mgmt
->sa
));
2316 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2319 if (res
== HOSTAPD_ACL_PENDING
)
2323 if (auth_alg
== WLAN_AUTH_SAE
&& !from_queue
&&
2324 (auth_transaction
== 1 ||
2325 (auth_transaction
== 2 && auth_sae_queued_addr(hapd
, mgmt
->sa
)))) {
2326 /* Handle SAE Authentication commit message through a queue to
2327 * provide more control for postponing the needed heavy
2328 * processing under a possible DoS attack scenario. In addition,
2329 * queue SAE Authentication confirm message if there happens to
2330 * be a queued commit message from the same peer. This is needed
2331 * to avoid reordering Authentication frames within the same
2333 auth_sae_queue(hapd
, mgmt
, len
, rssi
);
2336 #endif /* CONFIG_SAE */
2338 sta
= ap_get_sta(hapd
, mgmt
->sa
);
2340 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
2341 sta
->ft_over_ds
= 0;
2342 if ((fc
& WLAN_FC_RETRY
) &&
2343 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
2344 sta
->last_seq_ctrl
== seq_ctrl
&&
2345 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
2346 hostapd_logger(hapd
, sta
->addr
,
2347 HOSTAPD_MODULE_IEEE80211
,
2348 HOSTAPD_LEVEL_DEBUG
,
2349 "Drop repeated authentication frame seq_ctrl=0x%x",
2354 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
2355 sta
->plink_state
== PLINK_BLOCKED
) {
2356 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2357 " is blocked - drop Authentication frame",
2361 #endif /* CONFIG_MESH */
2364 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
2365 /* if the mesh peer is not available, we don't do auth.
2367 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
2368 " not yet known - drop Authentication frame",
2371 * Save a copy of the frame so that it can be processed
2372 * if a new peer entry is added shortly after this.
2374 wpabuf_free(hapd
->mesh_pending_auth
);
2375 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
2376 os_get_reltime(&hapd
->mesh_pending_auth_time
);
2379 #endif /* CONFIG_MESH */
2381 sta
= ap_sta_add(hapd
, mgmt
->sa
);
2383 wpa_printf(MSG_DEBUG
, "ap_sta_add() failed");
2384 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2388 sta
->last_seq_ctrl
= seq_ctrl
;
2389 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
2391 sta
->auth_rssi
= rssi
;
2392 #endif /* CONFIG_MBO */
2394 res
= ieee802_11_set_radius_info(
2395 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
2396 &vlan_id
, &psk
, &identity
, &radius_cui
);
2398 wpa_printf(MSG_DEBUG
, "ieee802_11_set_radius_info() failed");
2399 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2403 sta
->flags
&= ~WLAN_STA_PREAUTH
;
2404 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
2407 * If the driver supports full AP client state, add a station to the
2408 * driver before sending authentication reply to make sure the driver
2409 * has resources, and not to go through the entire authentication and
2410 * association handshake, and fail it at the end.
2412 * If this is not the first transaction, in a multi-step authentication
2413 * algorithm, the station already exists in the driver
2414 * (sta->added_unassoc = 1) so skip it.
2416 * In mesh mode, the station was already added to the driver when the
2417 * NEW_PEER_CANDIDATE event is received.
2419 * If PMF was negotiated for the existing association, skip this to
2420 * avoid dropping the STA entry and the associated keys. This is needed
2421 * to allow the original connection work until the attempt can complete
2422 * (re)association, so that unprotected Authentication frame cannot be
2423 * used to bypass PMF protection.
2425 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
2426 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
2427 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
2428 !(sta
->added_unassoc
)) {
2430 * If a station that is already associated to the AP, is trying
2431 * to authenticate again, remove the STA entry, in order to make
2432 * sure the STA PS state gets cleared and configuration gets
2433 * updated. To handle this, station's added_unassoc flag is
2434 * cleared once the station has completed association.
2436 ap_sta_set_authorized(hapd
, sta
, 0);
2437 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2438 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
2439 WLAN_STA_AUTHORIZED
);
2441 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0,
2442 sta
->supported_rates
,
2443 sta
->supported_rates_len
,
2444 0, NULL
, NULL
, NULL
, 0,
2445 sta
->flags
, 0, 0, 0, 0)) {
2446 hostapd_logger(hapd
, sta
->addr
,
2447 HOSTAPD_MODULE_IEEE80211
,
2448 HOSTAPD_LEVEL_NOTICE
,
2449 "Could not add STA to kernel driver");
2450 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
2454 sta
->added_unassoc
= 1;
2458 case WLAN_AUTH_OPEN
:
2459 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2460 HOSTAPD_LEVEL_DEBUG
,
2461 "authentication OK (open system)");
2462 sta
->flags
|= WLAN_STA_AUTH
;
2463 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
2464 sta
->auth_alg
= WLAN_AUTH_OPEN
;
2465 mlme_authenticate_indication(hapd
, sta
);
2467 #ifndef CONFIG_NO_RC4
2468 case WLAN_AUTH_SHARED_KEY
:
2469 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
2470 fc
& WLAN_FC_ISWEP
);
2472 wpa_printf(MSG_DEBUG
,
2473 "auth_shared_key() failed: status=%d", resp
);
2474 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2475 mlme_authenticate_indication(hapd
, sta
);
2476 if (sta
->challenge
&& auth_transaction
== 1) {
2477 resp_ies
[0] = WLAN_EID_CHALLENGE
;
2478 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
2479 os_memcpy(resp_ies
+ 2, sta
->challenge
,
2480 WLAN_AUTH_CHALLENGE_LEN
);
2481 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
2484 #endif /* CONFIG_NO_RC4 */
2485 #ifdef CONFIG_IEEE80211R_AP
2487 sta
->auth_alg
= WLAN_AUTH_FT
;
2488 if (sta
->wpa_sm
== NULL
)
2489 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2491 if (sta
->wpa_sm
== NULL
) {
2492 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
2494 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2497 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
2498 auth_transaction
, mgmt
->u
.auth
.variable
,
2499 len
- IEEE80211_HDRLEN
-
2500 sizeof(mgmt
->u
.auth
),
2501 handle_auth_ft_finish
, hapd
);
2502 /* handle_auth_ft_finish() callback will complete auth. */
2504 #endif /* CONFIG_IEEE80211R_AP */
2508 if (status_code
== WLAN_STATUS_SUCCESS
&&
2509 hapd
->conf
->mesh
& MESH_ENABLED
) {
2510 if (sta
->wpa_sm
== NULL
)
2512 wpa_auth_sta_init(hapd
->wpa_auth
,
2514 if (sta
->wpa_sm
== NULL
) {
2515 wpa_printf(MSG_DEBUG
,
2516 "SAE: Failed to initialize WPA state machine");
2517 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2521 #endif /* CONFIG_MESH */
2522 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2525 #endif /* CONFIG_SAE */
2527 case WLAN_AUTH_FILS_SK
:
2528 case WLAN_AUTH_FILS_SK_PFS
:
2529 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2530 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2531 auth_alg
, auth_transaction
, status_code
,
2532 handle_auth_fils_finish
);
2534 #endif /* CONFIG_FILS */
2539 os_free(radius_cui
);
2540 hostapd_free_psk_list(psk
);
2542 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2543 auth_transaction
+ 1, resp
, resp_ies
,
2544 resp_ies_len
, "handle-auth");
2546 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2547 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2548 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2549 sta
->added_unassoc
= 0;
2554 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2558 /* get a unique AID */
2560 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2567 for (i
= 0; i
< AID_WORDS
; i
++) {
2568 if (hapd
->sta_aid
[i
] == (u32
) -1)
2570 for (j
= 0; j
< 32; j
++) {
2571 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2579 aid
= i
* 32 + j
+ 1;
2584 hapd
->sta_aid
[i
] |= BIT(j
);
2585 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2590 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2591 const u8
*ssid_ie
, size_t ssid_ie_len
)
2593 if (ssid_ie
== NULL
)
2594 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2596 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2597 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2598 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2600 "Station tried to associate with unknown SSID "
2601 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2602 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2605 return WLAN_STATUS_SUCCESS
;
2609 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2610 const u8
*wmm_ie
, size_t wmm_ie_len
)
2612 sta
->flags
&= ~WLAN_STA_WMM
;
2614 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2615 struct wmm_information_element
*wmm
;
2617 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2618 hostapd_logger(hapd
, sta
->addr
,
2620 HOSTAPD_LEVEL_DEBUG
,
2621 "invalid WMM element in association "
2623 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2626 sta
->flags
|= WLAN_STA_WMM
;
2627 wmm
= (struct wmm_information_element
*) wmm_ie
;
2628 sta
->qosinfo
= wmm
->qos_info
;
2630 return WLAN_STATUS_SUCCESS
;
2633 static u16
check_multi_ap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2634 const u8
*multi_ap_ie
, size_t multi_ap_len
)
2636 u8 multi_ap_value
= 0;
2638 sta
->flags
&= ~WLAN_STA_MULTI_AP
;
2640 if (!hapd
->conf
->multi_ap
)
2641 return WLAN_STATUS_SUCCESS
;
2644 const u8
*multi_ap_subelem
;
2646 multi_ap_subelem
= get_ie(multi_ap_ie
+ 4,
2648 MULTI_AP_SUB_ELEM_TYPE
);
2649 if (multi_ap_subelem
&& multi_ap_subelem
[1] == 1) {
2650 multi_ap_value
= multi_ap_subelem
[2];
2652 hostapd_logger(hapd
, sta
->addr
,
2653 HOSTAPD_MODULE_IEEE80211
,
2655 "Multi-AP IE has missing or invalid Multi-AP subelement");
2656 return WLAN_STATUS_INVALID_IE
;
2660 if (multi_ap_value
&& multi_ap_value
!= MULTI_AP_BACKHAUL_STA
)
2661 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2663 "Multi-AP IE with unexpected value 0x%02x",
2666 if (!(multi_ap_value
& MULTI_AP_BACKHAUL_STA
)) {
2667 if (hapd
->conf
->multi_ap
& FRONTHAUL_BSS
)
2668 return WLAN_STATUS_SUCCESS
;
2670 hostapd_logger(hapd
, sta
->addr
,
2671 HOSTAPD_MODULE_IEEE80211
,
2673 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2674 return WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
2677 if (!(hapd
->conf
->multi_ap
& BACKHAUL_BSS
))
2678 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2679 HOSTAPD_LEVEL_DEBUG
,
2680 "Backhaul STA tries to associate with fronthaul-only BSS");
2682 sta
->flags
|= WLAN_STA_MULTI_AP
;
2683 return WLAN_STATUS_SUCCESS
;
2687 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2688 struct ieee802_11_elems
*elems
)
2690 /* Supported rates not used in IEEE 802.11ad/DMG */
2691 if (hapd
->iface
->current_mode
&&
2692 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2693 return WLAN_STATUS_SUCCESS
;
2695 if (!elems
->supp_rates
) {
2696 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2697 HOSTAPD_LEVEL_DEBUG
,
2698 "No supported rates element in AssocReq");
2699 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2702 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2703 sizeof(sta
->supported_rates
)) {
2704 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2705 HOSTAPD_LEVEL_DEBUG
,
2706 "Invalid supported rates element length %d+%d",
2707 elems
->supp_rates_len
,
2708 elems
->ext_supp_rates_len
);
2709 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2712 sta
->supported_rates_len
= merge_byte_arrays(
2713 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2714 elems
->supp_rates
, elems
->supp_rates_len
,
2715 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2717 return WLAN_STATUS_SUCCESS
;
2721 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2722 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2724 #ifdef CONFIG_INTERWORKING
2725 /* check for QoS Map support */
2726 if (ext_capab_ie_len
>= 5) {
2727 if (ext_capab_ie
[4] & 0x01)
2728 sta
->qos_map_enabled
= 1;
2730 #endif /* CONFIG_INTERWORKING */
2732 if (ext_capab_ie_len
> 0) {
2733 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2734 os_free(sta
->ext_capability
);
2735 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2736 if (sta
->ext_capability
) {
2737 sta
->ext_capability
[0] = ext_capab_ie_len
;
2738 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2743 return WLAN_STATUS_SUCCESS
;
2749 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2752 int *groups
= hapd
->conf
->owe_groups
;
2754 if (group
!= 19 && group
!= 20 && group
!= 21)
2760 for (i
= 0; groups
[i
] > 0; i
++) {
2761 if (groups
[i
] == group
)
2769 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2770 struct sta_info
*sta
, const u8
*owe_dh
,
2773 struct wpabuf
*secret
, *pub
, *hkey
;
2775 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2776 const char *info
= "OWE Key Generation";
2780 size_t hash_len
, prime_len
;
2782 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2783 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2784 return WLAN_STATUS_SUCCESS
;
2787 group
= WPA_GET_LE16(owe_dh
);
2788 if (!owe_group_supported(hapd
, group
)) {
2789 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2790 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2794 else if (group
== 20)
2796 else if (group
== 21)
2799 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2801 crypto_ecdh_deinit(sta
->owe_ecdh
);
2802 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2804 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2805 sta
->owe_group
= group
;
2807 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2809 secret
= wpabuf_zeropad(secret
, prime_len
);
2811 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2812 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2814 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2816 /* prk = HKDF-extract(C | A | group, z) */
2818 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2820 wpabuf_clear_free(secret
);
2821 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2824 /* PMKID = Truncate-128(Hash(C | A)) */
2825 addr
[0] = owe_dh
+ 2;
2826 len
[0] = owe_dh_len
- 2;
2827 addr
[1] = wpabuf_head(pub
);
2828 len
[1] = wpabuf_len(pub
);
2830 res
= sha256_vector(2, addr
, len
, pmkid
);
2831 hash_len
= SHA256_MAC_LEN
;
2832 } else if (group
== 20) {
2833 res
= sha384_vector(2, addr
, len
, pmkid
);
2834 hash_len
= SHA384_MAC_LEN
;
2835 } else if (group
== 21) {
2836 res
= sha512_vector(2, addr
, len
, pmkid
);
2837 hash_len
= SHA512_MAC_LEN
;
2840 wpabuf_clear_free(secret
);
2841 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2843 pub
= wpabuf_zeropad(pub
, prime_len
);
2844 if (res
< 0 || !pub
) {
2846 wpabuf_clear_free(secret
);
2847 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2850 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2853 wpabuf_clear_free(secret
);
2854 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2857 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2858 wpabuf_put_buf(hkey
, pub
); /* A */
2860 wpabuf_put_le16(hkey
, group
); /* group */
2862 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2863 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2864 else if (group
== 20)
2865 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2866 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2867 else if (group
== 21)
2868 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2869 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2870 wpabuf_clear_free(hkey
);
2871 wpabuf_clear_free(secret
);
2873 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2875 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2877 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2879 os_free(sta
->owe_pmk
);
2880 sta
->owe_pmk
= os_malloc(hash_len
);
2881 if (!sta
->owe_pmk
) {
2882 os_memset(prk
, 0, SHA512_MAC_LEN
);
2883 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2887 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2888 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2889 else if (group
== 20)
2890 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2891 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2892 else if (group
== 21)
2893 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2894 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2895 os_memset(prk
, 0, SHA512_MAC_LEN
);
2897 os_free(sta
->owe_pmk
);
2898 sta
->owe_pmk
= NULL
;
2899 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2901 sta
->owe_pmk_len
= hash_len
;
2903 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2904 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2905 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2906 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2908 return WLAN_STATUS_SUCCESS
;
2912 u16
owe_validate_request(struct hostapd_data
*hapd
, const u8
*peer
,
2913 const u8
*rsn_ie
, size_t rsn_ie_len
,
2914 const u8
*owe_dh
, size_t owe_dh_len
)
2916 struct wpa_ie_data data
;
2919 if (!rsn_ie
|| rsn_ie_len
< 2) {
2920 wpa_printf(MSG_DEBUG
, "OWE: Invalid RSNE from " MACSTR
,
2922 return WLAN_STATUS_INVALID_IE
;
2927 res
= wpa_parse_wpa_ie_rsn(rsn_ie
, rsn_ie_len
, &data
);
2929 wpa_printf(MSG_DEBUG
, "Failed to parse RSNE from " MACSTR
2930 " (res=%d)", MAC2STR(peer
), res
);
2931 wpa_hexdump(MSG_DEBUG
, "RSNE", rsn_ie
, rsn_ie_len
);
2932 return wpa_res_to_status_code(res
);
2934 if (!(data
.key_mgmt
& WPA_KEY_MGMT_OWE
)) {
2935 wpa_printf(MSG_DEBUG
,
2936 "OWE: Unexpected key mgmt 0x%x from " MACSTR
,
2937 (unsigned int) data
.key_mgmt
, MAC2STR(peer
));
2938 return WLAN_STATUS_AKMP_NOT_VALID
;
2941 wpa_printf(MSG_DEBUG
,
2942 "OWE: No Diffie-Hellman Parameter element from "
2943 MACSTR
, MAC2STR(peer
));
2944 return WLAN_STATUS_AKMP_NOT_VALID
;
2947 return WLAN_STATUS_SUCCESS
;
2951 u16
owe_process_rsn_ie(struct hostapd_data
*hapd
,
2952 struct sta_info
*sta
,
2953 const u8
*rsn_ie
, size_t rsn_ie_len
,
2954 const u8
*owe_dh
, size_t owe_dh_len
)
2957 u8
*owe_buf
, ie
[256 * 2];
2961 if (!rsn_ie
|| rsn_ie_len
< 2) {
2962 wpa_printf(MSG_DEBUG
, "OWE: No RSNE in (Re)AssocReq");
2963 status
= WLAN_STATUS_INVALID_IE
;
2968 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
2971 wpa_printf(MSG_WARNING
,
2972 "OWE: Failed to initialize WPA state machine");
2973 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2978 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2979 hapd
->iface
->freq
, rsn_ie
, rsn_ie_len
,
2980 NULL
, 0, NULL
, 0, owe_dh
, owe_dh_len
);
2981 status
= wpa_res_to_status_code(res
);
2982 if (status
!= WLAN_STATUS_SUCCESS
)
2984 status
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
2985 if (status
!= WLAN_STATUS_SUCCESS
)
2987 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, ie
, sizeof(ie
),
2990 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2994 if (sta
->owe_ecdh
) {
2997 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2999 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3003 /* OWE Diffie-Hellman Parameter element */
3004 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3005 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3006 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3008 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3010 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3011 owe_buf
+= wpabuf_len(pub
);
3013 sta
->external_dh_updated
= 1;
3015 ie_len
= owe_buf
- ie
;
3018 wpa_printf(MSG_DEBUG
, "OWE: Update status %d, ie len %d for peer "
3019 MACSTR
, status
, (unsigned int) ie_len
,
3020 MAC2STR(sta
->addr
));
3021 hostapd_drv_update_dh_ie(hapd
, sta
->addr
, status
,
3022 status
== WLAN_STATUS_SUCCESS
? ie
: NULL
,
3028 #endif /* CONFIG_OWE */
3031 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3032 const u8
*ies
, size_t ies_len
, int reassoc
)
3034 struct ieee802_11_elems elems
;
3038 const u8
*p2p_dev_addr
= NULL
;
3040 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
3041 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3042 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
3043 "association request");
3044 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3047 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
3048 if (resp
!= WLAN_STATUS_SUCCESS
)
3050 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
3051 if (resp
!= WLAN_STATUS_SUCCESS
)
3053 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
3054 if (resp
!= WLAN_STATUS_SUCCESS
)
3056 resp
= copy_supp_rates(hapd
, sta
, &elems
);
3057 if (resp
!= WLAN_STATUS_SUCCESS
)
3060 resp
= check_multi_ap(hapd
, sta
, elems
.multi_ap
, elems
.multi_ap_len
);
3061 if (resp
!= WLAN_STATUS_SUCCESS
)
3064 #ifdef CONFIG_IEEE80211N
3065 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
3066 if (resp
!= WLAN_STATUS_SUCCESS
)
3068 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
3069 !(sta
->flags
& WLAN_STA_HT
)) {
3070 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3071 HOSTAPD_LEVEL_INFO
, "Station does not support "
3072 "mandatory HT PHY - reject association");
3073 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
3075 #endif /* CONFIG_IEEE80211N */
3077 #ifdef CONFIG_IEEE80211AC
3078 if (hapd
->iconf
->ieee80211ac
) {
3079 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
3080 if (resp
!= WLAN_STATUS_SUCCESS
)
3083 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
3084 if (resp
!= WLAN_STATUS_SUCCESS
)
3088 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
3089 !(sta
->flags
& WLAN_STA_VHT
)) {
3090 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3091 HOSTAPD_LEVEL_INFO
, "Station does not support "
3092 "mandatory VHT PHY - reject association");
3093 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
3096 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
3097 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
3098 elems
.vendor_vht_len
);
3099 if (resp
!= WLAN_STATUS_SUCCESS
)
3102 #endif /* CONFIG_IEEE80211AC */
3103 #ifdef CONFIG_IEEE80211AX
3104 if (hapd
->iconf
->ieee80211ax
) {
3105 resp
= copy_sta_he_capab(hapd
, sta
, IEEE80211_MODE_AP
,
3106 elems
.he_capabilities
,
3107 elems
.he_capabilities_len
);
3108 if (resp
!= WLAN_STATUS_SUCCESS
)
3111 #endif /* CONFIG_IEEE80211AX */
3115 wpabuf_free(sta
->p2p_ie
);
3116 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3117 P2P_IE_VENDOR_TYPE
);
3119 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
3121 wpabuf_free(sta
->p2p_ie
);
3124 #endif /* CONFIG_P2P */
3126 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
3127 wpa_ie
= elems
.rsn_ie
;
3128 wpa_ie_len
= elems
.rsn_ie_len
;
3129 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
3131 wpa_ie
= elems
.wpa_ie
;
3132 wpa_ie_len
= elems
.wpa_ie_len
;
3139 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
3140 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
3141 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
3142 "Request - assume WPS is used");
3143 sta
->flags
|= WLAN_STA_WPS
;
3144 wpabuf_free(sta
->wps_ie
);
3145 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
3146 WPS_IE_VENDOR_TYPE
);
3147 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
3148 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
3149 sta
->flags
|= WLAN_STA_WPS2
;
3153 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
3154 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
3155 "(Re)Association Request - reject");
3156 return WLAN_STATUS_INVALID_IE
;
3158 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
3159 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
3160 "(Re)Association Request - possible WPS use");
3161 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
3163 #endif /* CONFIG_WPS */
3164 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
3165 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3167 "No WPA/RSN IE in association request");
3168 return WLAN_STATUS_INVALID_IE
;
3171 if (hapd
->conf
->wpa
&& wpa_ie
) {
3175 if (sta
->wpa_sm
== NULL
)
3176 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3179 if (sta
->wpa_sm
== NULL
) {
3180 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3182 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3184 wpa_auth_set_auth_alg(sta
->wpa_sm
, sta
->auth_alg
);
3185 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
3188 elems
.rsnxe
? elems
.rsnxe
- 2 : NULL
,
3189 elems
.rsnxe
? elems
.rsnxe_len
+ 2 : 0,
3190 elems
.mdie
, elems
.mdie_len
,
3191 elems
.owe_dh
, elems
.owe_dh_len
);
3192 resp
= wpa_res_to_status_code(res
);
3193 if (resp
!= WLAN_STATUS_SUCCESS
)
3195 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3196 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3197 !sta
->sa_query_timed_out
&&
3198 sta
->sa_query_count
> 0)
3199 ap_check_sa_query_timeout(hapd
, sta
);
3200 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
3201 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
3202 !sta
->sa_query_timed_out
&&
3203 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
3205 * STA has already been associated with MFP and SA
3206 * Query timeout has not been reached. Reject the
3207 * association attempt temporarily and start SA Query,
3208 * if one is not pending.
3211 if (sta
->sa_query_count
== 0)
3212 ap_sta_start_sa_query(hapd
, sta
);
3214 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
3217 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
3218 sta
->flags
|= WLAN_STA_MFP
;
3220 sta
->flags
&= ~WLAN_STA_MFP
;
3222 #ifdef CONFIG_IEEE80211R_AP
3223 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
3225 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
3226 "to use association (not "
3227 "re-association) with FT auth_alg",
3228 MAC2STR(sta
->addr
));
3229 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3232 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
3234 if (resp
!= WLAN_STATUS_SUCCESS
)
3237 #endif /* CONFIG_IEEE80211R_AP */
3240 if (wpa_auth_uses_sae(sta
->wpa_sm
) && sta
->sae
&&
3241 sta
->sae
->state
== SAE_ACCEPTED
)
3242 wpa_auth_add_sae_pmkid(sta
->wpa_sm
, sta
->sae
->pmkid
);
3244 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3245 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
3246 struct rsn_pmksa_cache_entry
*sa
;
3247 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
3248 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
3249 wpa_printf(MSG_DEBUG
,
3250 "SAE: No PMKSA cache entry found for "
3251 MACSTR
, MAC2STR(sta
->addr
));
3252 return WLAN_STATUS_INVALID_PMKID
;
3254 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
3255 " using PMKSA caching", MAC2STR(sta
->addr
));
3256 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
3257 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
3258 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
3259 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
3260 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
3261 "SAE AKM after non-SAE auth_alg %u",
3262 MAC2STR(sta
->addr
), sta
->auth_alg
);
3263 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
3266 if (hapd
->conf
->sae_pwe
== 2 &&
3267 sta
->auth_alg
== WLAN_AUTH_SAE
&&
3268 sta
->sae
&& sta
->sae
->tmp
&& !sta
->sae
->tmp
->h2e
&&
3269 elems
.rsnxe
&& elems
.rsnxe_len
>= 1 &&
3270 (elems
.rsnxe
[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E
))) {
3271 wpa_printf(MSG_INFO
, "SAE: " MACSTR
3272 " indicates support for SAE H2E, but did not use it",
3273 MAC2STR(sta
->addr
));
3274 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3276 #endif /* CONFIG_SAE */
3279 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3280 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
3282 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
3284 if (resp
!= WLAN_STATUS_SUCCESS
)
3287 #endif /* CONFIG_OWE */
3290 dpp_pfs_free(sta
->dpp_pfs
);
3291 sta
->dpp_pfs
= NULL
;
3293 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3294 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
3295 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
3297 sta
->dpp_pfs
= dpp_pfs_init(
3298 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
3299 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
3300 if (!sta
->dpp_pfs
) {
3301 wpa_printf(MSG_DEBUG
,
3302 "DPP: Could not initialize PFS");
3303 /* Try to continue without PFS */
3307 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
3308 elems
.owe_dh_len
) < 0) {
3309 dpp_pfs_free(sta
->dpp_pfs
);
3310 sta
->dpp_pfs
= NULL
;
3311 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3315 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
3316 sta
->dpp_pfs
->secret
: NULL
);
3318 #endif /* CONFIG_DPP2 */
3320 #ifdef CONFIG_IEEE80211N
3321 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
3322 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
3323 hostapd_logger(hapd
, sta
->addr
,
3324 HOSTAPD_MODULE_IEEE80211
,
3326 "Station tried to use TKIP with HT "
3328 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
3330 #endif /* CONFIG_IEEE80211N */
3332 } else if (hapd
->conf
->osen
) {
3333 if (elems
.osen
== NULL
) {
3335 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3337 "No HS 2.0 OSEN element in association request");
3338 return WLAN_STATUS_INVALID_IE
;
3341 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
3342 if (sta
->wpa_sm
== NULL
)
3343 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
3345 if (sta
->wpa_sm
== NULL
) {
3346 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
3348 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3350 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
3351 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
3352 return WLAN_STATUS_INVALID_IE
;
3353 #endif /* CONFIG_HS20 */
3355 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
3358 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
3359 #endif /* CONFIG_P2P */
3362 wpabuf_free(sta
->hs20_ie
);
3363 if (elems
.hs20
&& elems
.hs20_len
> 4) {
3366 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
3367 elems
.hs20_len
- 4);
3368 release
= ((elems
.hs20
[4] >> 4) & 0x0f) + 1;
3369 if (release
>= 2 && !wpa_auth_uses_mfp(sta
->wpa_sm
) &&
3370 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3371 wpa_printf(MSG_DEBUG
,
3372 "HS 2.0: PMF not negotiated by release %d station "
3373 MACSTR
, release
, MAC2STR(sta
->addr
));
3374 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
3377 sta
->hs20_ie
= NULL
;
3380 wpabuf_free(sta
->roaming_consortium
);
3381 if (elems
.roaming_cons_sel
)
3382 sta
->roaming_consortium
= wpabuf_alloc_copy(
3383 elems
.roaming_cons_sel
+ 4,
3384 elems
.roaming_cons_sel_len
- 4);
3386 sta
->roaming_consortium
= NULL
;
3387 #endif /* CONFIG_HS20 */
3390 wpabuf_free(sta
->mb_ies
);
3391 if (hapd
->iface
->fst
)
3392 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
3395 #endif /* CONFIG_FST */
3398 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
3400 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
3401 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
3402 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3403 wpa_printf(MSG_INFO
,
3404 "MBO: Reject WPA2 association without PMF");
3405 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3407 #endif /* CONFIG_MBO */
3409 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3410 if (wpa_auth_uses_ocv(sta
->wpa_sm
) &&
3411 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3412 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3413 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)) {
3414 struct wpa_channel_info ci
;
3418 if (hostapd_drv_channel_info(hapd
, &ci
) != 0) {
3419 wpa_printf(MSG_WARNING
,
3420 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3421 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3424 if (get_sta_tx_parameters(sta
->wpa_sm
,
3425 channel_width_to_int(ci
.chanwidth
),
3426 ci
.seg1_idx
, &tx_chanwidth
,
3428 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3430 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
3431 tx_chanwidth
, tx_seg1_idx
) != 0) {
3432 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
3433 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3436 #endif /* CONFIG_FILS && CONFIG_OCV */
3438 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
3439 elems
.supp_op_classes_len
);
3441 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
3442 elems
.rrm_enabled
&&
3443 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
3444 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
3445 sizeof(sta
->rrm_enabled_capa
));
3447 if (elems
.power_capab
) {
3448 sta
->min_tx_power
= elems
.power_capab
[0];
3449 sta
->max_tx_power
= elems
.power_capab
[1];
3450 sta
->power_capab
= 1;
3452 sta
->power_capab
= 0;
3455 return WLAN_STATUS_SUCCESS
;
3459 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
3463 struct ieee80211_mgmt reply
;
3465 os_memset(&reply
, 0, sizeof(reply
));
3466 reply
.frame_control
=
3467 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
3468 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
3469 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
3470 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
3472 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
3473 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
3475 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
3476 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
3481 static int add_associated_sta(struct hostapd_data
*hapd
,
3482 struct sta_info
*sta
, int reassoc
)
3484 struct ieee80211_ht_capabilities ht_cap
;
3485 struct ieee80211_vht_capabilities vht_cap
;
3486 struct ieee80211_he_capabilities he_cap
;
3490 * Remove the STA entry to ensure the STA PS state gets cleared and
3491 * configuration gets updated. This is relevant for cases, such as
3492 * FT-over-the-DS, where a station re-associates back to the same AP but
3493 * skips the authentication flow, or if working with a driver that
3494 * does not support full AP client state.
3496 * Skip this if the STA has already completed FT reassociation and the
3497 * TK has been configured since the TX/RX PN must not be reset to 0 for
3500 * FT-over-the-DS has a special case where the STA entry (and as such,
3501 * the TK) has not yet been configured to the driver depending on which
3502 * driver interface is used. For that case, allow add-STA operation to
3503 * be used (instead of set-STA). This is needed to allow mac80211-based
3504 * drivers to accept the STA parameter configuration. Since this is
3505 * after a new FT-over-DS exchange, a new TK has been derived, so key
3506 * reinstallation is not a concern for this case.
3508 wpa_printf(MSG_DEBUG
, "Add associated STA " MACSTR
3509 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3510 MAC2STR(sta
->addr
), sta
->added_unassoc
, sta
->auth_alg
,
3511 sta
->ft_over_ds
, reassoc
,
3512 !!(sta
->flags
& WLAN_STA_AUTHORIZED
),
3513 wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
),
3514 wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
));
3516 if (!sta
->added_unassoc
&&
3517 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3518 (reassoc
&& sta
->ft_over_ds
&& sta
->auth_alg
== WLAN_AUTH_FT
) ||
3519 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
3520 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
3521 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3522 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
3525 /* Do not allow the FT-over-DS exception to be used more than
3526 * once per authentication exchange to guarantee a new TK is
3528 sta
->ft_over_ds
= 0;
3531 #ifdef CONFIG_IEEE80211N
3532 if (sta
->flags
& WLAN_STA_HT
)
3533 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
3534 #endif /* CONFIG_IEEE80211N */
3535 #ifdef CONFIG_IEEE80211AC
3536 if (sta
->flags
& WLAN_STA_VHT
)
3537 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
3538 #endif /* CONFIG_IEEE80211AC */
3539 #ifdef CONFIG_IEEE80211AX
3540 if (sta
->flags
& WLAN_STA_HE
) {
3541 hostapd_get_he_capab(hapd
, sta
->he_capab
, &he_cap
,
3544 #endif /* CONFIG_IEEE80211AX */
3547 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3548 * will be set when the ACK frame for the (Re)Association Response frame
3549 * is processed (TX status driver event).
3551 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
3552 sta
->supported_rates
, sta
->supported_rates_len
,
3553 sta
->listen_interval
,
3554 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
3555 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
3556 sta
->flags
& WLAN_STA_HE
? &he_cap
: NULL
,
3557 sta
->flags
& WLAN_STA_HE
? sta
->he_capab_len
: 0,
3558 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
3559 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
3561 hostapd_logger(hapd
, sta
->addr
,
3562 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
3563 "Could not %s STA to kernel driver",
3564 set
? "set" : "add");
3566 if (sta
->added_unassoc
) {
3567 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3568 sta
->added_unassoc
= 0;
3574 sta
->added_unassoc
= 0;
3580 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3581 const u8
*addr
, u16 status_code
, int reassoc
,
3582 const u8
*ies
, size_t ies_len
, int rssi
)
3587 struct ieee80211_mgmt
*reply
;
3589 u16 res
= WLAN_STATUS_SUCCESS
;
3591 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
3593 if (sta
&& sta
->fils_hlp_resp
)
3594 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
3597 #endif /* CONFIG_FILS */
3599 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3601 #endif /* CONFIG_OWE */
3603 if (sta
&& sta
->dpp_pfs
)
3604 buflen
+= 5 + sta
->dpp_pfs
->curve
->prime_len
;
3605 #endif /* CONFIG_DPP2 */
3606 buf
= os_zalloc(buflen
);
3608 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3611 reply
= (struct ieee80211_mgmt
*) buf
;
3612 reply
->frame_control
=
3613 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3614 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
3615 WLAN_FC_STYPE_ASSOC_RESP
));
3616 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
3617 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
3618 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3620 send_len
= IEEE80211_HDRLEN
;
3621 send_len
+= sizeof(reply
->u
.assoc_resp
);
3622 reply
->u
.assoc_resp
.capab_info
=
3623 host_to_le16(hostapd_own_capab_info(hapd
));
3624 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
3626 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
3628 /* Supported rates */
3629 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
3630 /* Extended supported rates */
3631 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
3634 if (status_code
== WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
3636 int delta
= hapd
->iconf
->rssi_reject_assoc_rssi
- rssi
;
3638 p
= hostapd_eid_mbo_rssi_assoc_rej(hapd
, p
, buf
+ buflen
- p
,
3641 #endif /* CONFIG_MBO */
3643 #ifdef CONFIG_IEEE80211R_AP
3644 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
3645 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3646 * Transition Information, RSN, [RIC Response] */
3647 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
3649 sta
->auth_alg
, ies
, ies_len
);
3651 wpa_printf(MSG_DEBUG
,
3652 "FT: Failed to write AssocResp IEs");
3653 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3657 #endif /* CONFIG_IEEE80211R_AP */
3659 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3660 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3661 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3662 sta
->auth_alg
== WLAN_AUTH_FILS_PK
))
3663 p
= wpa_auth_write_assoc_resp_fils(sta
->wpa_sm
, p
,
3666 #endif /* CONFIG_FILS */
3669 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
&&
3670 (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
3671 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
3674 #endif /* CONFIG_OWE */
3676 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
3677 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
3679 #ifdef CONFIG_IEEE80211N
3680 p
= hostapd_eid_ht_capabilities(hapd
, p
);
3681 p
= hostapd_eid_ht_operation(hapd
, p
);
3682 #endif /* CONFIG_IEEE80211N */
3684 #ifdef CONFIG_IEEE80211AC
3685 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
&&
3686 !is_6ghz_op_class(hapd
->iconf
->op_class
)) {
3687 u32 nsts
= 0, sta_nsts
;
3689 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
3690 struct ieee80211_vht_capabilities
*capa
;
3692 nsts
= (hapd
->iface
->conf
->vht_capab
>>
3693 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3694 capa
= sta
->vht_capabilities
;
3695 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
3696 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
3698 if (nsts
< sta_nsts
)
3703 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
3704 p
= hostapd_eid_vht_operation(hapd
, p
);
3706 #endif /* CONFIG_IEEE80211AC */
3708 #ifdef CONFIG_IEEE80211AX
3709 if (hapd
->iconf
->ieee80211ax
) {
3710 p
= hostapd_eid_he_capab(hapd
, p
, IEEE80211_MODE_AP
);
3711 p
= hostapd_eid_he_operation(hapd
, p
);
3712 p
= hostapd_eid_spatial_reuse(hapd
, p
);
3713 p
= hostapd_eid_he_mu_edca_parameter_set(hapd
, p
);
3715 #endif /* CONFIG_IEEE80211AX */
3717 p
= hostapd_eid_ext_capab(hapd
, p
);
3718 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
3719 if (sta
&& sta
->qos_map_enabled
)
3720 p
= hostapd_eid_qos_map_set(hapd
, p
);
3723 if (hapd
->iface
->fst_ies
) {
3724 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
3725 wpabuf_len(hapd
->iface
->fst_ies
));
3726 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
3728 #endif /* CONFIG_FST */
3730 p
= hostapd_eid_rsnxe(hapd
, p
, buf
+ buflen
- p
);
3733 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
3734 sta
&& sta
->owe_ecdh
&& status_code
== WLAN_STATUS_SUCCESS
&&
3735 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
3738 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3740 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3743 /* OWE Diffie-Hellman Parameter element */
3744 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3745 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3746 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3747 WPA_PUT_LE16(p
, sta
->owe_group
);
3749 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
3750 p
+= wpabuf_len(pub
);
3753 #endif /* CONFIG_OWE */
3756 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
3757 sta
&& sta
->dpp_pfs
&& status_code
== WLAN_STATUS_SUCCESS
&&
3758 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
) {
3759 os_memcpy(p
, wpabuf_head(sta
->dpp_pfs
->ie
),
3760 wpabuf_len(sta
->dpp_pfs
->ie
));
3761 p
+= wpabuf_len(sta
->dpp_pfs
->ie
);
3763 #endif /* CONFIG_DPP2 */
3765 #ifdef CONFIG_IEEE80211AC
3766 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
3767 p
= hostapd_eid_vendor_vht(hapd
, p
);
3768 #endif /* CONFIG_IEEE80211AC */
3770 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
3771 p
= hostapd_eid_wmm(hapd
, p
);
3775 ((sta
->flags
& WLAN_STA_WPS
) ||
3776 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
3777 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
3779 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
3780 p
+= wpabuf_len(wps
);
3784 #endif /* CONFIG_WPS */
3786 if (sta
&& (sta
->flags
& WLAN_STA_MULTI_AP
))
3787 p
= hostapd_eid_multi_ap(hapd
, p
);
3790 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
3791 struct wpabuf
*p2p_resp_ie
;
3792 enum p2p_status_code status
;
3793 switch (status_code
) {
3794 case WLAN_STATUS_SUCCESS
:
3795 status
= P2P_SC_SUCCESS
;
3797 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
3798 status
= P2P_SC_FAIL_LIMIT_REACHED
;
3801 status
= P2P_SC_FAIL_INVALID_PARAMS
;
3804 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
3806 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
3807 wpabuf_len(p2p_resp_ie
));
3808 p
+= wpabuf_len(p2p_resp_ie
);
3809 wpabuf_free(p2p_resp_ie
);
3812 #endif /* CONFIG_P2P */
3814 #ifdef CONFIG_P2P_MANAGER
3815 if (hapd
->conf
->p2p
& P2P_MANAGE
)
3816 p
= hostapd_eid_p2p_manage(hapd
, p
);
3817 #endif /* CONFIG_P2P_MANAGER */
3819 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
3821 if (hapd
->conf
->assocresp_elements
&&
3822 (size_t) (buf
+ buflen
- p
) >=
3823 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
3824 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
3825 wpabuf_len(hapd
->conf
->assocresp_elements
));
3826 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
3829 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
3833 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3834 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3835 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
3836 status_code
== WLAN_STATUS_SUCCESS
) {
3837 struct ieee802_11_elems elems
;
3839 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
3840 ParseFailed
|| !elems
.fils_session
) {
3841 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3846 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
3847 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
3848 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
3849 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
3850 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
3852 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
3853 buflen
, sta
->fils_hlp_resp
);
3855 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3859 #endif /* CONFIG_FILS */
3861 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
3862 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
3864 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3874 u8
* owe_assoc_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
3875 const u8
*owe_dh
, u8 owe_dh_len
,
3876 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
3878 #ifdef CONFIG_TESTING_OPTIONS
3879 if (hapd
->conf
->own_ie_override
) {
3880 wpa_printf(MSG_DEBUG
, "OWE: Using IE override");
3881 *reason
= WLAN_STATUS_SUCCESS
;
3882 return wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3883 owe_buf_len
, NULL
, 0);
3885 #endif /* CONFIG_TESTING_OPTIONS */
3887 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
3888 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
3889 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3890 owe_buf_len
, NULL
, 0);
3891 *reason
= WLAN_STATUS_SUCCESS
;
3895 if (sta
->owe_pmk
&& sta
->external_dh_updated
) {
3896 wpa_printf(MSG_DEBUG
, "OWE: Using previously derived PMK");
3897 *reason
= WLAN_STATUS_SUCCESS
;
3901 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3902 if (*reason
!= WLAN_STATUS_SUCCESS
)
3905 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3906 owe_buf_len
, NULL
, 0);
3908 if (sta
->owe_ecdh
&& owe_buf
) {
3911 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3913 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3917 /* OWE Diffie-Hellman Parameter element */
3918 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3919 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3920 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension
3922 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3924 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3925 owe_buf
+= wpabuf_len(pub
);
3931 #endif /* CONFIG_OWE */
3936 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3940 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3941 MAC2STR(sta
->addr
));
3942 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3943 if (!sta
->fils_pending_assoc_req
)
3945 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3946 sta
->fils_pending_assoc_is_reassoc
,
3947 sta
->fils_pending_assoc_req
,
3948 sta
->fils_pending_assoc_req_len
, 0);
3949 os_free(sta
->fils_pending_assoc_req
);
3950 sta
->fils_pending_assoc_req
= NULL
;
3951 sta
->fils_pending_assoc_req_len
= 0;
3952 wpabuf_free(sta
->fils_hlp_resp
);
3953 sta
->fils_hlp_resp
= NULL
;
3954 wpabuf_free(sta
->hlp_dhcp_discover
);
3955 sta
->hlp_dhcp_discover
= NULL
;
3958 * Remove the station in case transmission of a success response fails.
3959 * At this point the station was already added associated to the driver.
3961 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3962 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3966 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3968 struct hostapd_data
*hapd
= eloop_ctx
;
3969 struct sta_info
*sta
= eloop_data
;
3971 wpa_printf(MSG_DEBUG
,
3972 "FILS: HLP response timeout - continue with association response for "
3973 MACSTR
, MAC2STR(sta
->addr
));
3974 if (sta
->fils_drv_assoc_finish
)
3975 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3977 fils_hlp_finish_assoc(hapd
, sta
);
3980 #endif /* CONFIG_FILS */
3983 static void handle_assoc(struct hostapd_data
*hapd
,
3984 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3985 int reassoc
, int rssi
)
3987 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3988 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3991 struct sta_info
*sta
;
3993 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3994 char *identity
= NULL
;
3995 char *radius_cui
= NULL
;
3997 int delay_assoc
= 0;
3998 #endif /* CONFIG_FILS */
4000 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
4001 sizeof(mgmt
->u
.assoc_req
))) {
4002 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
4003 reassoc
, (unsigned long) len
);
4007 #ifdef CONFIG_TESTING_OPTIONS
4009 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
4010 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
4011 wpa_printf(MSG_INFO
,
4012 "TESTING: ignoring reassoc request from "
4013 MACSTR
, MAC2STR(mgmt
->sa
));
4017 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
4018 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
4019 wpa_printf(MSG_INFO
,
4020 "TESTING: ignoring assoc request from "
4021 MACSTR
, MAC2STR(mgmt
->sa
));
4025 #endif /* CONFIG_TESTING_OPTIONS */
4027 fc
= le_to_host16(mgmt
->frame_control
);
4028 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4031 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
4032 listen_interval
= le_to_host16(
4033 mgmt
->u
.reassoc_req
.listen_interval
);
4034 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
4035 " capab_info=0x%02x listen_interval=%d current_ap="
4036 MACSTR
" seq_ctrl=0x%x%s",
4037 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
4038 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
4039 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
4040 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
4041 pos
= mgmt
->u
.reassoc_req
.variable
;
4043 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
4044 listen_interval
= le_to_host16(
4045 mgmt
->u
.assoc_req
.listen_interval
);
4046 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
4047 " capab_info=0x%02x listen_interval=%d "
4049 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
4050 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
4051 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
4052 pos
= mgmt
->u
.assoc_req
.variable
;
4055 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4056 #ifdef CONFIG_IEEE80211R_AP
4057 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
4058 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
4059 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
4060 "prior to authentication since it is using "
4061 "over-the-DS FT", MAC2STR(mgmt
->sa
));
4064 * Mark station as authenticated, to avoid adding station
4065 * entry in the driver as associated and not authenticated
4067 sta
->flags
|= WLAN_STA_AUTH
;
4069 #endif /* CONFIG_IEEE80211R_AP */
4070 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
4071 if (hapd
->iface
->current_mode
&&
4072 hapd
->iface
->current_mode
->mode
==
4073 HOSTAPD_MODE_IEEE80211AD
) {
4075 u32 session_timeout
, acct_interim_interval
;
4076 struct vlan_description vlan_id
;
4078 acl_res
= ieee802_11_allowed_address(
4079 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
4080 &session_timeout
, &acct_interim_interval
,
4081 &vlan_id
, &psk
, &identity
, &radius_cui
, 0);
4082 if (acl_res
== HOSTAPD_ACL_REJECT
) {
4083 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
4084 "Ignore Association Request frame from "
4085 MACSTR
" due to ACL reject",
4087 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4090 if (acl_res
== HOSTAPD_ACL_PENDING
)
4093 /* DMG/IEEE 802.11ad does not use authentication.
4094 * Allocate sta entry upon association. */
4095 sta
= ap_sta_add(hapd
, mgmt
->sa
);
4097 hostapd_logger(hapd
, mgmt
->sa
,
4098 HOSTAPD_MODULE_IEEE80211
,
4100 "Failed to add STA");
4101 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4105 acl_res
= ieee802_11_set_radius_info(
4106 hapd
, sta
, acl_res
, session_timeout
,
4107 acct_interim_interval
, &vlan_id
, &psk
,
4108 &identity
, &radius_cui
);
4110 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4114 hostapd_logger(hapd
, sta
->addr
,
4115 HOSTAPD_MODULE_IEEE80211
,
4116 HOSTAPD_LEVEL_DEBUG
,
4117 "Skip authentication for DMG/IEEE 802.11ad");
4118 sta
->flags
|= WLAN_STA_AUTH
;
4119 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
4120 sta
->auth_alg
= WLAN_AUTH_OPEN
;
4122 hostapd_logger(hapd
, mgmt
->sa
,
4123 HOSTAPD_MODULE_IEEE80211
,
4125 "Station tried to associate before authentication (aid=%d flags=0x%x)",
4126 sta
? sta
->aid
: -1,
4127 sta
? sta
->flags
: 0);
4128 send_deauth(hapd
, mgmt
->sa
,
4129 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
4134 if ((fc
& WLAN_FC_RETRY
) &&
4135 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4136 sta
->last_seq_ctrl
== seq_ctrl
&&
4137 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4138 WLAN_FC_STYPE_ASSOC_REQ
)) {
4139 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4140 HOSTAPD_LEVEL_DEBUG
,
4141 "Drop repeated association frame seq_ctrl=0x%x",
4145 sta
->last_seq_ctrl
= seq_ctrl
;
4146 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
4147 WLAN_FC_STYPE_ASSOC_REQ
;
4149 if (hapd
->tkip_countermeasures
) {
4150 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4154 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
4155 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4156 HOSTAPD_LEVEL_DEBUG
,
4157 "Too large Listen Interval (%d)",
4159 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
4164 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
4165 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4169 if (hapd
->iconf
->rssi_reject_assoc_rssi
&& rssi
&&
4170 rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
&&
4171 (sta
->auth_rssi
== 0 ||
4172 sta
->auth_rssi
< hapd
->iconf
->rssi_reject_assoc_rssi
)) {
4173 resp
= WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
;
4176 #endif /* CONFIG_MBO */
4179 * sta->capability is used in check_assoc_ies() for RRM enabled
4180 * capability element.
4182 sta
->capability
= capab_info
;
4185 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4186 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4187 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4190 /* The end of the payload is encrypted. Need to decrypt it
4191 * before parsing. */
4193 tmp
= os_memdup(pos
, left
);
4195 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4199 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
4202 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
4208 #endif /* CONFIG_FILS */
4210 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
4212 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
4213 if (resp
!= WLAN_STATUS_SUCCESS
)
4216 if (hostapd_get_aid(hapd
, sta
) < 0) {
4217 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4218 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
4219 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4223 sta
->listen_interval
= listen_interval
;
4225 if (hapd
->iface
->current_mode
&&
4226 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
4227 sta
->flags
|= WLAN_STA_NONERP
;
4228 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
4229 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
4230 sta
->flags
&= ~WLAN_STA_NONERP
;
4234 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
4235 sta
->nonerp_set
= 1;
4236 hapd
->iface
->num_sta_non_erp
++;
4237 if (hapd
->iface
->num_sta_non_erp
== 1)
4238 ieee802_11_set_beacons(hapd
->iface
);
4241 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
4242 !sta
->no_short_slot_time_set
) {
4243 sta
->no_short_slot_time_set
= 1;
4244 hapd
->iface
->num_sta_no_short_slot_time
++;
4245 if (hapd
->iface
->current_mode
&&
4246 hapd
->iface
->current_mode
->mode
==
4247 HOSTAPD_MODE_IEEE80211G
&&
4248 hapd
->iface
->num_sta_no_short_slot_time
== 1)
4249 ieee802_11_set_beacons(hapd
->iface
);
4252 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
4253 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
4255 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
4257 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
4258 !sta
->no_short_preamble_set
) {
4259 sta
->no_short_preamble_set
= 1;
4260 hapd
->iface
->num_sta_no_short_preamble
++;
4261 if (hapd
->iface
->current_mode
&&
4262 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
4263 && hapd
->iface
->num_sta_no_short_preamble
== 1)
4264 ieee802_11_set_beacons(hapd
->iface
);
4267 #ifdef CONFIG_IEEE80211N
4268 update_ht_state(hapd
, sta
);
4269 #endif /* CONFIG_IEEE80211N */
4271 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4272 HOSTAPD_LEVEL_DEBUG
,
4273 "association OK (aid %d)", sta
->aid
);
4274 /* Station will be marked associated, after it acknowledges AssocResp
4276 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
4278 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
4279 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
4280 "SA Query procedure", reassoc
? "re" : "");
4281 /* TODO: Send a protected Disassociate frame to the STA using
4282 * the old key and Reason Code "Previous Authentication no
4283 * longer valid". Make sure this is only sent protected since
4284 * unprotected frame would be received by the STA that is now
4285 * trying to associate.
4289 /* Make sure that the previously registered inactivity timer will not
4290 * remove the STA immediately. */
4291 sta
->timeout_next
= STA_NULLFUNC
;
4293 #ifdef CONFIG_TAXONOMY
4294 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
4295 #endif /* CONFIG_TAXONOMY */
4297 sta
->pending_wds_enable
= 0;
4300 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4301 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4302 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
4303 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
4306 #endif /* CONFIG_FILS */
4310 os_free(radius_cui
);
4311 hostapd_free_psk_list(psk
);
4314 * In case of a successful response, add the station to the driver.
4315 * Otherwise, the kernel may ignore Data frames before we process the
4316 * ACK frame (TX status). In case of a failure, this station will be
4319 * Note that this is not compliant with the IEEE 802.11 standard that
4320 * states that a non-AP station should transition into the
4321 * authenticated/associated state only after the station acknowledges
4322 * the (Re)Association Response frame. However, still do this as:
4324 * 1. In case the station does not acknowledge the (Re)Association
4325 * Response frame, it will be removed.
4326 * 2. Data frames will be dropped in the kernel until the station is
4327 * set into authorized state, and there are no significant known
4328 * issues with processing other non-Data Class 3 frames during this
4331 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&&
4332 add_associated_sta(hapd
, sta
, reassoc
))
4333 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
4336 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
&&
4337 eloop_is_timeout_registered(fils_hlp_timeout
, hapd
, sta
) &&
4338 sta
->fils_pending_assoc_req
) {
4339 /* Do not reschedule fils_hlp_timeout in case the station
4340 * retransmits (Re)Association Request frame while waiting for
4341 * the previously started FILS HLP wait, so that the timeout can
4342 * be determined from the first pending attempt. */
4343 wpa_printf(MSG_DEBUG
,
4344 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4345 MACSTR
, MAC2STR(sta
->addr
));
4350 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4351 os_free(sta
->fils_pending_assoc_req
);
4352 sta
->fils_pending_assoc_req
= NULL
;
4353 sta
->fils_pending_assoc_req_len
= 0;
4354 wpabuf_free(sta
->fils_hlp_resp
);
4355 sta
->fils_hlp_resp
= NULL
;
4357 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
4358 sta
->fils_pending_assoc_req
= tmp
;
4359 sta
->fils_pending_assoc_req_len
= left
;
4360 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
4361 sta
->fils_drv_assoc_finish
= 0;
4362 wpa_printf(MSG_DEBUG
,
4363 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4364 MACSTR
, MAC2STR(sta
->addr
));
4365 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
4366 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
4367 fils_hlp_timeout
, hapd
, sta
);
4370 #endif /* CONFIG_FILS */
4372 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
4377 * Remove the station in case tranmission of a success response fails
4378 * (the STA was added associated to the driver) or if the station was
4379 * previously added unassociated.
4381 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
4382 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
4383 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4384 sta
->added_unassoc
= 0;
4389 static void handle_disassoc(struct hostapd_data
*hapd
,
4390 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4392 struct sta_info
*sta
;
4394 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
4395 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
4396 (unsigned long) len
);
4400 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
4402 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4404 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4406 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
4411 ap_sta_set_authorized(hapd
, sta
, 0);
4412 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4413 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
4414 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
4415 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4416 HOSTAPD_LEVEL_INFO
, "disassociated");
4417 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4418 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4419 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4421 accounting_sta_stop(hapd
, sta
);
4422 ieee802_1x_free_station(hapd
, sta
);
4424 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
4425 ap_sta_ip6addr_del(hapd
, sta
);
4426 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4427 sta
->added_unassoc
= 0;
4429 if (sta
->timeout_next
== STA_NULLFUNC
||
4430 sta
->timeout_next
== STA_DISASSOC
) {
4431 sta
->timeout_next
= STA_DEAUTH
;
4432 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
4433 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
4437 mlme_disassociate_indication(
4438 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
4440 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4441 * disassociation. */
4442 if (hapd
->iface
->current_mode
&&
4443 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
4444 sta
->flags
&= ~WLAN_STA_AUTH
;
4445 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4446 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4447 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4448 ap_free_sta(hapd
, sta
);
4453 static void handle_deauth(struct hostapd_data
*hapd
,
4454 const struct ieee80211_mgmt
*mgmt
, size_t len
)
4456 struct sta_info
*sta
;
4458 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
4459 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
4460 "payload (len=%lu)", (unsigned long) len
);
4464 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
4466 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
4468 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4470 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
4471 "to deauthenticate, but it is not authenticated",
4476 ap_sta_set_authorized(hapd
, sta
, 0);
4477 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
4478 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
4479 WLAN_STA_ASSOC_REQ_OK
);
4480 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
4481 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4482 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
4483 mlme_deauthenticate_indication(
4484 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
4485 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
4486 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
4487 ap_free_sta(hapd
, sta
);
4491 static void handle_beacon(struct hostapd_data
*hapd
,
4492 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4493 struct hostapd_frame_info
*fi
)
4495 struct ieee802_11_elems elems
;
4497 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
4498 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
4499 (unsigned long) len
);
4503 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
4504 len
- (IEEE80211_HDRLEN
+
4505 sizeof(mgmt
->u
.beacon
)), &elems
,
4508 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
4512 static int robust_action_frame(u8 category
)
4514 return category
!= WLAN_ACTION_PUBLIC
&&
4515 category
!= WLAN_ACTION_HT
;
4519 static int handle_action(struct hostapd_data
*hapd
,
4520 const struct ieee80211_mgmt
*mgmt
, size_t len
,
4523 struct sta_info
*sta
;
4524 u8
*action __maybe_unused
;
4526 if (len
< IEEE80211_HDRLEN
+ 2 + 1) {
4527 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4528 HOSTAPD_LEVEL_DEBUG
,
4529 "handle_action - too short payload (len=%lu)",
4530 (unsigned long) len
);
4534 action
= (u8
*) &mgmt
->u
.action
.u
;
4535 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
4536 " da " MACSTR
" len %d freq %u",
4537 mgmt
->u
.action
.category
, *action
,
4538 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) len
, freq
);
4540 sta
= ap_get_sta(hapd
, mgmt
->sa
);
4542 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
4543 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
4544 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
4545 "frame (category=%u) from unassociated STA " MACSTR
,
4546 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
4550 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
4551 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
4552 robust_action_frame(mgmt
->u
.action
.category
)) {
4553 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4554 HOSTAPD_LEVEL_DEBUG
,
4555 "Dropped unprotected Robust Action frame from "
4561 u16 fc
= le_to_host16(mgmt
->frame_control
);
4562 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
4564 if ((fc
& WLAN_FC_RETRY
) &&
4565 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
4566 sta
->last_seq_ctrl
== seq_ctrl
&&
4567 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
4568 hostapd_logger(hapd
, sta
->addr
,
4569 HOSTAPD_MODULE_IEEE80211
,
4570 HOSTAPD_LEVEL_DEBUG
,
4571 "Drop repeated action frame seq_ctrl=0x%x",
4576 sta
->last_seq_ctrl
= seq_ctrl
;
4577 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
4580 switch (mgmt
->u
.action
.category
) {
4581 #ifdef CONFIG_IEEE80211R_AP
4582 case WLAN_ACTION_FT
:
4584 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
4585 len
- IEEE80211_HDRLEN
))
4588 #endif /* CONFIG_IEEE80211R_AP */
4589 case WLAN_ACTION_WMM
:
4590 hostapd_wmm_action(hapd
, mgmt
, len
);
4592 case WLAN_ACTION_SA_QUERY
:
4593 ieee802_11_sa_query_action(hapd
, mgmt
, len
);
4595 #ifdef CONFIG_WNM_AP
4596 case WLAN_ACTION_WNM
:
4597 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
4599 #endif /* CONFIG_WNM_AP */
4601 case WLAN_ACTION_FST
:
4602 if (hapd
->iface
->fst
)
4603 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
4605 wpa_printf(MSG_DEBUG
,
4606 "FST: Ignore FST Action frame - no FST attached");
4608 #endif /* CONFIG_FST */
4609 case WLAN_ACTION_PUBLIC
:
4610 case WLAN_ACTION_PROTECTED_DUAL
:
4611 #ifdef CONFIG_IEEE80211N
4612 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4613 mgmt
->u
.action
.u
.public_action
.action
==
4614 WLAN_PA_20_40_BSS_COEX
) {
4615 hostapd_2040_coex_action(hapd
, mgmt
, len
);
4618 #endif /* CONFIG_IEEE80211N */
4620 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4621 mgmt
->u
.action
.u
.vs_public_action
.action
==
4622 WLAN_PA_VENDOR_SPECIFIC
&&
4623 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4625 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4627 const u8
*pos
, *end
;
4629 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
4630 end
= ((const u8
*) mgmt
) + len
;
4631 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
4635 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4636 (mgmt
->u
.action
.u
.public_action
.action
==
4637 WLAN_PA_GAS_INITIAL_RESP
||
4638 mgmt
->u
.action
.u
.public_action
.action
==
4639 WLAN_PA_GAS_COMEBACK_RESP
)) {
4640 const u8
*pos
, *end
;
4642 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
4643 end
= ((const u8
*) mgmt
) + len
;
4644 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
4645 mgmt
->u
.action
.category
,
4646 pos
, end
- pos
, hapd
->iface
->freq
);
4649 #endif /* CONFIG_DPP */
4650 if (hapd
->public_action_cb
) {
4651 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
4655 if (hapd
->public_action_cb2
) {
4656 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
4660 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
4663 case WLAN_ACTION_VENDOR_SPECIFIC
:
4664 if (hapd
->vendor_action_cb
) {
4665 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
4667 hapd
->iface
->freq
) == 0)
4671 case WLAN_ACTION_RADIO_MEASUREMENT
:
4672 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
4676 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4677 HOSTAPD_LEVEL_DEBUG
,
4678 "handle_action - unknown action category %d or invalid "
4680 mgmt
->u
.action
.category
);
4681 if (!is_multicast_ether_addr(mgmt
->da
) &&
4682 !(mgmt
->u
.action
.category
& 0x80) &&
4683 !is_multicast_ether_addr(mgmt
->sa
)) {
4684 struct ieee80211_mgmt
*resp
;
4687 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4688 * Return the Action frame to the source without change
4689 * except that MSB of the Category set to 1.
4691 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
4692 "frame back to sender");
4693 resp
= os_memdup(mgmt
, len
);
4696 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
4697 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
4698 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
4699 resp
->u
.action
.category
|= 0x80;
4701 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
4702 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
4713 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4714 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4716 * @buf: management frame data (starting from IEEE 802.11 header)
4717 * @len: length of frame data in octets
4718 * @fi: meta data about received frame (signal level, etc.)
4720 * Process all incoming IEEE 802.11 management frames. This will be called for
4721 * each frame received from the kernel driver through wlan#ap interface. In
4722 * addition, it can be called to re-inserted pending frames (e.g., when using
4723 * external RADIUS server as an MAC ACL).
4725 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4726 struct hostapd_frame_info
*fi
)
4728 struct ieee80211_mgmt
*mgmt
;
4732 int ssi_signal
= fi
? fi
->ssi_signal
: 0;
4740 freq
= hapd
->iface
->freq
;
4742 mgmt
= (struct ieee80211_mgmt
*) buf
;
4743 fc
= le_to_host16(mgmt
->frame_control
);
4744 stype
= WLAN_FC_GET_STYPE(fc
);
4746 if (is_multicast_ether_addr(mgmt
->sa
) ||
4747 is_zero_ether_addr(mgmt
->sa
) ||
4748 os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
4749 /* Do not process any frames with unexpected/invalid SA so that
4750 * we do not add any state for unexpected STA addresses or end
4751 * up sending out frames to unexpected destination. */
4752 wpa_printf(MSG_DEBUG
, "MGMT: Invalid SA=" MACSTR
4753 " in received frame - ignore this frame silently",
4758 if (stype
== WLAN_FC_STYPE_BEACON
) {
4759 handle_beacon(hapd
, mgmt
, len
, fi
);
4763 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
4765 /* Invitation responses can be sent with the peer MAC as BSSID */
4766 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
4767 stype
== WLAN_FC_STYPE_ACTION
) &&
4768 #endif /* CONFIG_P2P */
4770 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
4771 #endif /* CONFIG_MESH */
4772 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4773 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
4774 MAC2STR(mgmt
->bssid
));
4779 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
4780 handle_probe_req(hapd
, mgmt
, len
, ssi_signal
);
4784 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
4785 stype
!= WLAN_FC_STYPE_ACTION
) &&
4786 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
4787 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4788 HOSTAPD_LEVEL_DEBUG
,
4789 "MGMT: DA=" MACSTR
" not our address",
4794 if (hapd
->iconf
->track_sta_max_num
)
4795 sta_track_add(hapd
->iface
, mgmt
->sa
, ssi_signal
);
4798 case WLAN_FC_STYPE_AUTH
:
4799 wpa_printf(MSG_DEBUG
, "mgmt::auth");
4800 handle_auth(hapd
, mgmt
, len
, ssi_signal
, 0);
4803 case WLAN_FC_STYPE_ASSOC_REQ
:
4804 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
4805 handle_assoc(hapd
, mgmt
, len
, 0, ssi_signal
);
4808 case WLAN_FC_STYPE_REASSOC_REQ
:
4809 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
4810 handle_assoc(hapd
, mgmt
, len
, 1, ssi_signal
);
4813 case WLAN_FC_STYPE_DISASSOC
:
4814 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
4815 handle_disassoc(hapd
, mgmt
, len
);
4818 case WLAN_FC_STYPE_DEAUTH
:
4819 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
4820 handle_deauth(hapd
, mgmt
, len
);
4823 case WLAN_FC_STYPE_ACTION
:
4824 wpa_printf(MSG_DEBUG
, "mgmt::action");
4825 ret
= handle_action(hapd
, mgmt
, len
, freq
);
4828 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
4829 HOSTAPD_LEVEL_DEBUG
,
4830 "unknown mgmt frame subtype %d", stype
);
4838 static void handle_auth_cb(struct hostapd_data
*hapd
,
4839 const struct ieee80211_mgmt
*mgmt
,
4842 u16 auth_alg
, auth_transaction
, status_code
;
4843 struct sta_info
*sta
;
4845 sta
= ap_get_sta(hapd
, mgmt
->da
);
4847 wpa_printf(MSG_DEBUG
, "handle_auth_cb: STA " MACSTR
4853 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4854 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4855 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
4858 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4859 HOSTAPD_LEVEL_NOTICE
,
4860 "did not acknowledge authentication response");
4864 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
4865 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
4866 (unsigned long) len
);
4870 if (status_code
== WLAN_STATUS_SUCCESS
&&
4871 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
4872 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
4873 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4874 HOSTAPD_LEVEL_INFO
, "authenticated");
4875 sta
->flags
|= WLAN_STA_AUTH
;
4876 if (sta
->added_unassoc
)
4877 hostapd_set_sta_flags(hapd
, sta
);
4882 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
4883 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4884 sta
->added_unassoc
= 0;
4889 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
4890 struct sta_info
*sta
,
4894 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
4896 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
4899 for (i
= 0; i
< 4; i
++) {
4900 if (ssid
->wep
.key
[i
] &&
4901 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
4902 i
== ssid
->wep
.idx
, NULL
, 0,
4903 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
4904 wpa_printf(MSG_WARNING
,
4905 "Could not set WEP keys for WDS interface; %s",
4913 static void handle_assoc_cb(struct hostapd_data
*hapd
,
4914 const struct ieee80211_mgmt
*mgmt
,
4915 size_t len
, int reassoc
, int ok
)
4918 struct sta_info
*sta
;
4921 sta
= ap_get_sta(hapd
, mgmt
->da
);
4923 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4928 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4929 sizeof(mgmt
->u
.assoc_resp
))) {
4930 wpa_printf(MSG_INFO
,
4931 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4932 reassoc
, (unsigned long) len
);
4933 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4938 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4940 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4943 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4944 HOSTAPD_LEVEL_DEBUG
,
4945 "did not acknowledge association response");
4946 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4947 /* The STA is added only in case of SUCCESS */
4948 if (status
== WLAN_STATUS_SUCCESS
)
4949 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4954 if (status
!= WLAN_STATUS_SUCCESS
)
4957 /* Stop previous accounting session, if one is started, and allocate
4958 * new session id for the new session. */
4959 accounting_sta_stop(hapd
, sta
);
4961 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4963 "associated (aid %d)",
4966 if (sta
->flags
& WLAN_STA_ASSOC
)
4968 sta
->flags
|= WLAN_STA_ASSOC
;
4969 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4970 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4971 !hapd
->conf
->osen
) ||
4972 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4973 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4974 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4975 sta
->auth_alg
== WLAN_AUTH_FT
) {
4977 * Open, static WEP, FT protocol, or FILS; no separate
4978 * authorization step.
4980 ap_sta_set_authorized(hapd
, sta
, 1);
4984 mlme_reassociate_indication(hapd
, sta
);
4986 mlme_associate_indication(hapd
, sta
);
4988 sta
->sa_query_timed_out
= 0;
4990 if (sta
->eapol_sm
== NULL
) {
4992 * This STA does not use RADIUS server for EAP authentication,
4993 * so bind it to the selected VLAN interface now, since the
4994 * interface selection is not going to change anymore.
4996 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4998 } else if (sta
->vlan_id
) {
4999 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
5000 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
5004 hostapd_set_sta_flags(hapd
, sta
);
5006 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
5007 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
5008 MACSTR
" based on pending request",
5009 MAC2STR(sta
->addr
));
5010 sta
->pending_wds_enable
= 0;
5011 sta
->flags
|= WLAN_STA_WDS
;
5014 if (sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_MULTI_AP
)) {
5016 char ifname_wds
[IFNAMSIZ
+ 1];
5018 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
5020 MAC2STR(sta
->addr
), sta
->aid
);
5021 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
5024 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
5027 if (sta
->auth_alg
== WLAN_AUTH_FT
)
5028 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
5030 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
5031 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
5032 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
5035 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
5036 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
5037 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
5038 fils_set_tk(sta
->wpa_sm
) < 0) {
5039 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
5040 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
5041 WLAN_REASON_UNSPECIFIED
);
5044 #endif /* CONFIG_FILS */
5046 if (sta
->pending_eapol_rx
) {
5047 struct os_reltime now
, age
;
5049 os_get_reltime(&now
);
5050 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
5051 if (age
.sec
== 0 && age
.usec
< 200000) {
5052 wpa_printf(MSG_DEBUG
,
5053 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
5054 MAC2STR(sta
->addr
));
5057 wpabuf_head(sta
->pending_eapol_rx
->buf
),
5058 wpabuf_len(sta
->pending_eapol_rx
->buf
));
5060 wpabuf_free(sta
->pending_eapol_rx
->buf
);
5061 os_free(sta
->pending_eapol_rx
);
5062 sta
->pending_eapol_rx
= NULL
;
5067 static void handle_deauth_cb(struct hostapd_data
*hapd
,
5068 const struct ieee80211_mgmt
*mgmt
,
5071 struct sta_info
*sta
;
5072 if (is_multicast_ether_addr(mgmt
->da
))
5074 sta
= ap_get_sta(hapd
, mgmt
->da
);
5076 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
5077 " not found", MAC2STR(mgmt
->da
));
5081 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
5082 MAC2STR(sta
->addr
));
5084 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
5085 "deauth", MAC2STR(sta
->addr
));
5087 ap_sta_deauth_cb(hapd
, sta
);
5091 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
5092 const struct ieee80211_mgmt
*mgmt
,
5095 struct sta_info
*sta
;
5096 if (is_multicast_ether_addr(mgmt
->da
))
5098 sta
= ap_get_sta(hapd
, mgmt
->da
);
5100 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
5101 " not found", MAC2STR(mgmt
->da
));
5105 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
5106 MAC2STR(sta
->addr
));
5108 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
5109 "disassoc", MAC2STR(sta
->addr
));
5111 ap_sta_disassoc_cb(hapd
, sta
);
5115 static void handle_action_cb(struct hostapd_data
*hapd
,
5116 const struct ieee80211_mgmt
*mgmt
,
5119 struct sta_info
*sta
;
5120 const struct rrm_measurement_report_element
*report
;
5122 if (is_multicast_ether_addr(mgmt
->da
))
5125 if (len
>= IEEE80211_HDRLEN
+ 6 &&
5126 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5127 mgmt
->u
.action
.u
.vs_public_action
.action
==
5128 WLAN_PA_VENDOR_SPECIFIC
&&
5129 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
5131 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
5133 const u8
*pos
, *end
;
5135 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
5136 end
= ((const u8
*) mgmt
) + len
;
5137 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
5140 if (len
>= IEEE80211_HDRLEN
+ 2 &&
5141 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
5142 (mgmt
->u
.action
.u
.public_action
.action
==
5143 WLAN_PA_GAS_INITIAL_REQ
||
5144 mgmt
->u
.action
.u
.public_action
.action
==
5145 WLAN_PA_GAS_COMEBACK_REQ
)) {
5146 const u8
*pos
, *end
;
5148 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
5149 end
= ((const u8
*) mgmt
) + len
;
5150 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
5153 #endif /* CONFIG_DPP */
5154 sta
= ap_get_sta(hapd
, mgmt
->da
);
5156 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
5157 " not found", MAC2STR(mgmt
->da
));
5161 if (len
< 24 + 5 + sizeof(*report
))
5163 report
= (const struct rrm_measurement_report_element
*)
5164 &mgmt
->u
.action
.u
.rrm
.variable
[2];
5165 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
5166 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
5167 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
5169 report
->type
== MEASURE_TYPE_BEACON
)
5170 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
5175 * ieee802_11_mgmt_cb - Process management frame TX status callback
5176 * @hapd: hostapd BSS data structure (the BSS from which the management frame
5178 * @buf: management frame data (starting from IEEE 802.11 header)
5179 * @len: length of frame data in octets
5180 * @stype: management frame subtype from frame control field
5181 * @ok: Whether the frame was ACK'ed
5183 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
5186 const struct ieee80211_mgmt
*mgmt
;
5187 mgmt
= (const struct ieee80211_mgmt
*) buf
;
5189 #ifdef CONFIG_TESTING_OPTIONS
5190 if (hapd
->ext_mgmt_frame_handling
) {
5191 size_t hex_len
= 2 * len
+ 1;
5192 char *hex
= os_malloc(hex_len
);
5195 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
5196 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
5197 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
5203 #endif /* CONFIG_TESTING_OPTIONS */
5206 case WLAN_FC_STYPE_AUTH
:
5207 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
5208 handle_auth_cb(hapd
, mgmt
, len
, ok
);
5210 case WLAN_FC_STYPE_ASSOC_RESP
:
5211 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
5212 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
5214 case WLAN_FC_STYPE_REASSOC_RESP
:
5215 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
5216 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
5218 case WLAN_FC_STYPE_PROBE_RESP
:
5219 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
5221 case WLAN_FC_STYPE_DEAUTH
:
5222 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
5223 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
5225 case WLAN_FC_STYPE_DISASSOC
:
5226 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
5227 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
5229 case WLAN_FC_STYPE_ACTION
:
5230 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
5231 handle_action_cb(hapd
, mgmt
, len
, ok
);
5234 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
5240 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
5247 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
5248 char *buf
, size_t buflen
)
5255 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
5256 const u8
*buf
, size_t len
, int ack
)
5258 struct sta_info
*sta
;
5259 struct hostapd_iface
*iface
= hapd
->iface
;
5261 sta
= ap_get_sta(hapd
, addr
);
5262 if (sta
== NULL
&& iface
->num_bss
> 1) {
5264 for (j
= 0; j
< iface
->num_bss
; j
++) {
5265 hapd
= iface
->bss
[j
];
5266 sta
= ap_get_sta(hapd
, addr
);
5271 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
5273 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
5274 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
5275 "activity poll", MAC2STR(sta
->addr
),
5276 ack
? "ACKed" : "did not ACK");
5278 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5281 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
5285 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
5286 const u8
*data
, size_t len
, int ack
)
5288 struct sta_info
*sta
;
5289 struct hostapd_iface
*iface
= hapd
->iface
;
5291 sta
= ap_get_sta(hapd
, dst
);
5292 if (sta
== NULL
&& iface
->num_bss
> 1) {
5294 for (j
= 0; j
< iface
->num_bss
; j
++) {
5295 hapd
= iface
->bss
[j
];
5296 sta
= ap_get_sta(hapd
, dst
);
5301 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
5302 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
5303 MACSTR
" that is not currently associated",
5308 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
5312 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
5314 struct sta_info
*sta
;
5315 struct hostapd_iface
*iface
= hapd
->iface
;
5317 sta
= ap_get_sta(hapd
, addr
);
5318 if (sta
== NULL
&& iface
->num_bss
> 1) {
5320 for (j
= 0; j
< iface
->num_bss
; j
++) {
5321 hapd
= iface
->bss
[j
];
5322 sta
= ap_get_sta(hapd
, addr
);
5329 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
5330 MAC2STR(sta
->addr
));
5331 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
5334 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
5335 "activity poll", MAC2STR(sta
->addr
));
5336 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
5340 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
5343 struct sta_info
*sta
;
5345 sta
= ap_get_sta(hapd
, src
);
5347 ((sta
->flags
& WLAN_STA_ASSOC
) ||
5348 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
5349 if (!hapd
->conf
->wds_sta
)
5352 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
5353 WLAN_STA_ASSOC_REQ_OK
) {
5354 wpa_printf(MSG_DEBUG
,
5355 "Postpone 4-address WDS mode enabling for STA "
5356 MACSTR
" since TX status for AssocResp is not yet known",
5357 MAC2STR(sta
->addr
));
5358 sta
->pending_wds_enable
= 1;
5362 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
5364 char ifname_wds
[IFNAMSIZ
+ 1];
5366 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
5367 "STA " MACSTR
" (aid %u)",
5368 MAC2STR(sta
->addr
), sta
->aid
);
5369 sta
->flags
|= WLAN_STA_WDS
;
5370 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
5371 sta
->addr
, sta
->aid
, 1);
5373 hostapd_set_wds_encryption(hapd
, sta
,
5379 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
5380 MACSTR
, MAC2STR(src
));
5381 if (is_multicast_ether_addr(src
) || is_zero_ether_addr(src
) ||
5382 os_memcmp(src
, hapd
->own_addr
, ETH_ALEN
) == 0) {
5383 /* Broadcast bit set in SA or unexpected SA?! Ignore the frame
5388 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
5389 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
5390 "already been sent, but no TX status yet known - "
5391 "ignore Class 3 frame issue with " MACSTR
,
5396 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
5397 hostapd_drv_sta_disassoc(
5399 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5401 hostapd_drv_sta_deauth(
5403 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
5407 #endif /* CONFIG_NATIVE_WINDOWS */