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 "radius/radius.h"
25 #include "radius/radius_client.h"
31 #include "ieee802_11_auth.h"
33 #include "ieee802_1x.h"
35 #include "pmksa_cache_auth.h"
38 #include "accounting.h"
39 #include "ap_config.h"
41 #include "p2p_hostapd.h"
42 #include "ap_drv_ops.h"
44 #include "hw_features.h"
45 #include "ieee802_11.h"
51 #include "dpp_hostapd.h"
52 #include "gas_query_ap.h"
56 static struct wpabuf
*
57 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
58 struct sta_info
*sta
, u16
*resp
,
59 struct rsn_pmksa_cache_entry
*pmksa
,
60 struct wpabuf
*erp_resp
,
61 const u8
*msk
, size_t msk_len
,
63 #endif /* CONFIG_FILS */
65 u8
* hostapd_eid_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
70 if (hapd
->iface
->current_rates
== NULL
)
73 *pos
++ = WLAN_EID_SUPP_RATES
;
74 num
= hapd
->iface
->num_rates
;
75 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
77 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
80 /* rest of the rates are encoded in Extended supported
86 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
;
89 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
90 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
95 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&& count
< 8) {
97 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
100 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&& count
< 8) {
102 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
109 u8
* hostapd_eid_ext_supp_rates(struct hostapd_data
*hapd
, u8
*eid
)
114 if (hapd
->iface
->current_rates
== NULL
)
117 num
= hapd
->iface
->num_rates
;
118 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
)
120 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
)
126 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
128 for (i
= 0, count
= 0; i
< hapd
->iface
->num_rates
&& count
< num
+ 8;
132 continue; /* already in SuppRates IE */
133 *pos
= hapd
->iface
->current_rates
[i
].rate
/ 5;
134 if (hapd
->iface
->current_rates
[i
].flags
& HOSTAPD_RATE_BASIC
)
139 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
) {
142 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
;
145 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
) {
148 *pos
++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
;
155 u16
hostapd_own_capab_info(struct hostapd_data
*hapd
)
157 int capab
= WLAN_CAPABILITY_ESS
;
162 /* Check if any of configured channels require DFS */
163 dfs
= hostapd_is_dfs_required(hapd
->iface
);
165 wpa_printf(MSG_WARNING
, "Failed to check if DFS is required; ret=%d",
170 if (hapd
->iface
->num_sta_no_short_preamble
== 0 &&
171 hapd
->iconf
->preamble
== SHORT_PREAMBLE
)
172 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
174 privacy
= hapd
->conf
->ssid
.wep
.keys_set
;
176 if (hapd
->conf
->ieee802_1x
&&
177 (hapd
->conf
->default_wep_key_len
||
178 hapd
->conf
->individual_wep_key_len
))
185 if (hapd
->conf
->osen
)
187 #endif /* CONFIG_HS20 */
190 capab
|= WLAN_CAPABILITY_PRIVACY
;
192 if (hapd
->iface
->current_mode
&&
193 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
&&
194 hapd
->iface
->num_sta_no_short_slot_time
== 0)
195 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
198 * Currently, Spectrum Management capability bit is set when directly
199 * requested in configuration by spectrum_mgmt_required or when AP is
200 * running on DFS channel.
201 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
203 if (hapd
->iface
->current_mode
&&
204 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211A
&&
205 (hapd
->iconf
->spectrum_mgmt_required
|| dfs
))
206 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
208 for (i
= 0; i
< RRM_CAPABILITIES_IE_LEN
; i
++) {
209 if (hapd
->conf
->radio_measurements
[i
]) {
210 capab
|= IEEE80211_CAP_RRM
;
219 #ifndef CONFIG_NO_RC4
220 static u16
auth_shared_key(struct hostapd_data
*hapd
, struct sta_info
*sta
,
221 u16 auth_transaction
, const u8
*challenge
,
224 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
226 "authentication (shared key, transaction %d)",
229 if (auth_transaction
== 1) {
230 if (!sta
->challenge
) {
231 /* Generate a pseudo-random challenge */
234 sta
->challenge
= os_zalloc(WLAN_AUTH_CHALLENGE_LEN
);
235 if (sta
->challenge
== NULL
)
236 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
238 if (os_get_random(key
, sizeof(key
)) < 0) {
239 os_free(sta
->challenge
);
240 sta
->challenge
= NULL
;
241 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
244 rc4_skip(key
, sizeof(key
), 0,
245 sta
->challenge
, WLAN_AUTH_CHALLENGE_LEN
);
250 if (auth_transaction
!= 3)
251 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
254 if (!iswep
|| !sta
->challenge
|| !challenge
||
255 os_memcmp_const(sta
->challenge
, challenge
,
256 WLAN_AUTH_CHALLENGE_LEN
)) {
257 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
259 "shared key authentication - invalid "
260 "challenge-response");
261 return WLAN_STATUS_CHALLENGE_FAIL
;
264 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
266 "authentication OK (shared key)");
267 sta
->flags
|= WLAN_STA_AUTH
;
268 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
269 os_free(sta
->challenge
);
270 sta
->challenge
= NULL
;
274 #endif /* CONFIG_NO_RC4 */
277 static int send_auth_reply(struct hostapd_data
*hapd
,
278 const u8
*dst
, const u8
*bssid
,
279 u16 auth_alg
, u16 auth_transaction
, u16 resp
,
280 const u8
*ies
, size_t ies_len
)
282 struct ieee80211_mgmt
*reply
;
285 int reply_res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
287 rlen
= IEEE80211_HDRLEN
+ sizeof(reply
->u
.auth
) + ies_len
;
288 buf
= os_zalloc(rlen
);
292 reply
= (struct ieee80211_mgmt
*) buf
;
293 reply
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
295 os_memcpy(reply
->da
, dst
, ETH_ALEN
);
296 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
297 os_memcpy(reply
->bssid
, bssid
, ETH_ALEN
);
299 reply
->u
.auth
.auth_alg
= host_to_le16(auth_alg
);
300 reply
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
301 reply
->u
.auth
.status_code
= host_to_le16(resp
);
304 os_memcpy(reply
->u
.auth
.variable
, ies
, ies_len
);
306 wpa_printf(MSG_DEBUG
, "authentication reply: STA=" MACSTR
307 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
308 MAC2STR(dst
), auth_alg
, auth_transaction
,
309 resp
, (unsigned long) ies_len
);
310 if (hostapd_drv_send_mlme(hapd
, reply
, rlen
, 0) < 0)
311 wpa_printf(MSG_INFO
, "send_auth_reply: send failed");
313 reply_res
= WLAN_STATUS_SUCCESS
;
321 #ifdef CONFIG_IEEE80211R_AP
322 static void handle_auth_ft_finish(void *ctx
, const u8
*dst
, const u8
*bssid
,
323 u16 auth_transaction
, u16 status
,
324 const u8
*ies
, size_t ies_len
)
326 struct hostapd_data
*hapd
= ctx
;
327 struct sta_info
*sta
;
330 reply_res
= send_auth_reply(hapd
, dst
, bssid
, WLAN_AUTH_FT
,
331 auth_transaction
, status
, ies
, ies_len
);
333 sta
= ap_get_sta(hapd
, dst
);
337 if (sta
->added_unassoc
&& (reply_res
!= WLAN_STATUS_SUCCESS
||
338 status
!= WLAN_STATUS_SUCCESS
)) {
339 hostapd_drv_sta_remove(hapd
, sta
->addr
);
340 sta
->added_unassoc
= 0;
344 if (status
!= WLAN_STATUS_SUCCESS
)
347 hostapd_logger(hapd
, dst
, HOSTAPD_MODULE_IEEE80211
,
348 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FT)");
349 sta
->flags
|= WLAN_STA_AUTH
;
350 mlme_authenticate_indication(hapd
, sta
);
352 #endif /* CONFIG_IEEE80211R_AP */
357 static void sae_set_state(struct sta_info
*sta
, enum sae_state state
,
360 wpa_printf(MSG_DEBUG
, "SAE: State %s -> %s for peer " MACSTR
" (%s)",
361 sae_state_txt(sta
->sae
->state
), sae_state_txt(state
),
362 MAC2STR(sta
->addr
), reason
);
363 sta
->sae
->state
= state
;
367 static struct wpabuf
* auth_build_sae_commit(struct hostapd_data
*hapd
,
368 struct sta_info
*sta
, int update
)
371 const char *password
;
373 password
= hapd
->conf
->sae_password
;
375 password
= hapd
->conf
->ssid
.wpa_passphrase
;
377 wpa_printf(MSG_DEBUG
, "SAE: No password available");
382 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
383 (u8
*) password
, os_strlen(password
),
385 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
389 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
);
392 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
393 sta
->sae
->tmp
->anti_clogging_token
: NULL
);
399 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
400 struct sta_info
*sta
)
404 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
408 sae_write_confirm(sta
->sae
, buf
);
414 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
415 struct sta_info
*sta
,
416 const u8
*bssid
, int update
)
421 data
= auth_build_sae_commit(hapd
, sta
, update
);
423 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
425 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
426 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
435 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
436 struct sta_info
*sta
,
442 data
= auth_build_sae_confirm(hapd
, sta
);
444 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
446 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
447 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
456 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
458 struct sta_info
*sta
;
459 unsigned int open
= 0;
461 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
464 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
467 if (sta
->sae
->state
!= SAE_COMMITTED
&&
468 sta
->sae
->state
!= SAE_CONFIRMED
)
471 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
479 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
480 const u8
*token
, size_t token_len
)
482 u8 mac
[SHA256_MAC_LEN
];
484 if (token_len
!= SHA256_MAC_LEN
)
486 if (hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
487 addr
, ETH_ALEN
, mac
) < 0 ||
488 os_memcmp_const(token
, mac
, SHA256_MAC_LEN
) != 0)
495 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
496 int group
, const u8
*addr
)
500 struct os_reltime now
;
502 os_get_reltime(&now
);
503 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
504 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60)) {
505 if (random_get_bytes(hapd
->sae_token_key
,
506 sizeof(hapd
->sae_token_key
)) < 0)
508 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
509 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
510 hapd
->last_sae_token_key_update
= now
;
513 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
517 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
519 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
520 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
521 addr
, ETH_ALEN
, token
);
527 static int sae_check_big_sync(struct hostapd_data
*hapd
, struct sta_info
*sta
)
529 if (sta
->sae
->sync
> hapd
->conf
->sae_sync
) {
530 sae_set_state(sta
, SAE_NOTHING
, "Sync > dot11RSNASAESync");
538 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
540 struct hostapd_data
*hapd
= eloop_ctx
;
541 struct sta_info
*sta
= eloop_data
;
544 if (sae_check_big_sync(hapd
, sta
))
547 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
548 " (sync=%d state=%s)",
549 MAC2STR(sta
->addr
), sta
->sae
->sync
,
550 sae_state_txt(sta
->sae
->state
));
552 switch (sta
->sae
->state
) {
554 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
555 eloop_register_timeout(0,
556 hapd
->dot11RSNASAERetransPeriod
* 1000,
557 auth_sae_retransmit_timer
, hapd
, sta
);
560 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
561 eloop_register_timeout(0,
562 hapd
->dot11RSNASAERetransPeriod
* 1000,
563 auth_sae_retransmit_timer
, hapd
, sta
);
570 if (ret
!= WLAN_STATUS_SUCCESS
)
571 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
575 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
577 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
581 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
582 struct sta_info
*sta
)
584 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
587 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
588 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
589 auth_sae_retransmit_timer
, hapd
, sta
);
593 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
595 sta
->flags
|= WLAN_STA_AUTH
;
596 sta
->auth_alg
= WLAN_AUTH_SAE
;
597 mlme_authenticate_indication(hapd
, sta
);
598 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
599 sae_set_state(sta
, SAE_ACCEPTED
, "Accept Confirm");
600 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
601 sta
->sae
->pmk
, sta
->sae
->pmkid
);
605 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
606 const u8
*bssid
, u8 auth_transaction
)
610 if (auth_transaction
!= 1 && auth_transaction
!= 2)
611 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
613 wpa_printf(MSG_DEBUG
, "SAE: Peer " MACSTR
" state=%s auth_trans=%u",
614 MAC2STR(sta
->addr
), sae_state_txt(sta
->sae
->state
),
616 switch (sta
->sae
->state
) {
618 if (auth_transaction
== 1) {
619 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
622 sae_set_state(sta
, SAE_COMMITTED
, "Sent Commit");
624 if (sae_process_commit(sta
->sae
) < 0)
625 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
628 * In mesh case, both Commit and Confirm can be sent
629 * immediately. In infrastructure BSS, only a single
630 * Authentication frame (Commit) is expected from the AP
631 * here and the second one (Confirm) will be sent once
632 * the STA has sent its second Authentication frame
635 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
637 * Send both Commit and Confirm immediately
638 * based on SAE finite state machine
639 * Nothing -> Confirm transition.
641 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
644 sae_set_state(sta
, SAE_CONFIRMED
,
645 "Sent Confirm (mesh)");
648 * For infrastructure BSS, send only the Commit
649 * message now to get alternating sequence of
650 * Authentication frames between the AP and STA.
651 * Confirm will be sent in
652 * Committed -> Confirmed/Accepted transition
653 * when receiving Confirm from STA.
657 sae_set_retransmit_timer(hapd
, sta
);
659 hostapd_logger(hapd
, sta
->addr
,
660 HOSTAPD_MODULE_IEEE80211
,
662 "SAE confirm before commit");
666 sae_clear_retransmit_timer(hapd
, sta
);
667 if (auth_transaction
== 1) {
668 if (sae_process_commit(sta
->sae
) < 0)
669 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
671 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
674 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
676 sae_set_retransmit_timer(hapd
, sta
);
677 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
679 * In mesh case, follow SAE finite state machine and
680 * send Commit now, if sync count allows.
682 if (sae_check_big_sync(hapd
, sta
))
683 return WLAN_STATUS_SUCCESS
;
686 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
690 sae_set_retransmit_timer(hapd
, sta
);
693 * For instructure BSS, send the postponed Confirm from
694 * Nothing -> Confirmed transition that was reduced to
695 * Nothing -> Committed above.
697 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
701 sae_set_state(sta
, SAE_CONFIRMED
, "Sent Confirm");
704 * Since this was triggered on Confirm RX, run another
705 * step to get to Accepted without waiting for
708 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
);
712 sae_clear_retransmit_timer(hapd
, sta
);
713 if (auth_transaction
== 1) {
714 if (sae_check_big_sync(hapd
, sta
))
715 return WLAN_STATUS_SUCCESS
;
718 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
722 if (sae_process_commit(sta
->sae
) < 0)
723 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
725 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
729 sae_set_retransmit_timer(hapd
, sta
);
731 sta
->sae
->send_confirm
= 0xffff;
732 sae_accept_sta(hapd
, sta
);
736 if (auth_transaction
== 1) {
737 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
738 ") doing reauthentication",
740 ap_free_sta(hapd
, sta
);
741 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
743 if (sae_check_big_sync(hapd
, sta
))
744 return WLAN_STATUS_SUCCESS
;
747 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
748 sae_clear_temp_data(sta
->sae
);
754 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
756 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
758 return WLAN_STATUS_SUCCESS
;
762 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
764 struct sae_data
*sae
= sta
->sae
;
765 int i
, *groups
= hapd
->conf
->sae_groups
;
767 if (sae
->state
!= SAE_COMMITTED
)
770 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
772 for (i
= 0; groups
&& groups
[i
] > 0; i
++) {
773 if (sae
->group
== groups
[i
])
777 if (!groups
|| groups
[i
] <= 0) {
778 wpa_printf(MSG_DEBUG
,
779 "SAE: Previously selected group not found from the current configuration");
785 if (groups
[i
] <= 0) {
786 wpa_printf(MSG_DEBUG
,
787 "SAE: No alternative group enabled");
791 if (sae_set_group(sae
, groups
[i
]) < 0)
796 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
800 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
801 const struct ieee80211_mgmt
*mgmt
, size_t len
,
802 u16 auth_transaction
, u16 status_code
)
804 int resp
= WLAN_STATUS_SUCCESS
;
805 struct wpabuf
*data
= NULL
;
807 #ifdef CONFIG_TESTING_OPTIONS
808 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
811 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
812 pos
= mgmt
->u
.auth
.variable
;
813 end
= ((const u8
*) mgmt
) + len
;
814 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
815 auth_transaction
, resp
, pos
, end
- pos
);
819 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
820 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
821 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
822 auth_transaction
, resp
,
823 wpabuf_head(hapd
->conf
->sae_commit_override
),
824 wpabuf_len(hapd
->conf
->sae_commit_override
));
827 #endif /* CONFIG_TESTING_OPTIONS */
829 if (auth_transaction
!= 1 ||
830 status_code
!= WLAN_STATUS_SUCCESS
) {
834 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
839 sae_set_state(sta
, SAE_NOTHING
, "Init");
843 if (sta
->mesh_sae_pmksa_caching
) {
844 wpa_printf(MSG_DEBUG
,
845 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
846 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
847 sta
->mesh_sae_pmksa_caching
= 0;
850 if (auth_transaction
== 1) {
851 const u8
*token
= NULL
, *pos
, *end
;
852 size_t token_len
= 0;
853 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
855 "start SAE authentication (RX commit, status=%u)",
858 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
859 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
861 pos
= mgmt
->u
.auth
.variable
;
862 end
= ((const u8
*) mgmt
) + len
;
863 if (pos
+ sizeof(le16
) > end
) {
864 wpa_printf(MSG_ERROR
,
865 "SAE: Too short anti-clogging token request");
866 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
869 resp
= sae_group_allowed(sta
->sae
,
870 hapd
->conf
->sae_groups
,
872 if (resp
!= WLAN_STATUS_SUCCESS
) {
873 wpa_printf(MSG_ERROR
,
874 "SAE: Invalid group in anti-clogging token request");
879 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
880 sta
->sae
->tmp
->anti_clogging_token
=
881 wpabuf_alloc_copy(pos
, end
- pos
);
882 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
883 wpa_printf(MSG_ERROR
,
884 "SAE: Failed to alloc for anti-clogging token");
885 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
890 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
891 * is 76, a new Commit Message shall be constructed
892 * with the Anti-Clogging Token from the received
893 * Authentication frame, and the commit-scalar and
894 * COMMIT-ELEMENT previously sent.
896 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
897 if (resp
!= WLAN_STATUS_SUCCESS
) {
898 wpa_printf(MSG_ERROR
,
899 "SAE: Failed to send commit message");
902 sae_set_state(sta
, SAE_COMMITTED
,
903 "Sent Commit (anti-clogging token case in mesh)");
905 sae_set_retransmit_timer(hapd
, sta
);
909 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
911 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
913 wpa_printf(MSG_DEBUG
,
914 "SAE: Peer did not accept our SAE group");
915 sae_pick_next_group(hapd
, sta
);
919 if (status_code
!= WLAN_STATUS_SUCCESS
)
922 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
923 ((const u8
*) mgmt
) + len
-
924 mgmt
->u
.auth
.variable
, &token
,
925 &token_len
, hapd
->conf
->sae_groups
);
926 if (resp
== SAE_SILENTLY_DISCARD
) {
927 wpa_printf(MSG_DEBUG
,
928 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
932 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
934 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
935 "incorrect token from " MACSTR
,
937 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
941 if (resp
!= WLAN_STATUS_SUCCESS
)
944 if (!token
&& use_sae_anti_clogging(hapd
)) {
945 wpa_printf(MSG_DEBUG
,
946 "SAE: Request anti-clogging token from "
947 MACSTR
, MAC2STR(sta
->addr
));
948 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
950 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
951 if (hapd
->conf
->mesh
& MESH_ENABLED
)
952 sae_set_state(sta
, SAE_NOTHING
,
953 "Request anti-clogging token case in mesh");
957 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
);
958 } else if (auth_transaction
== 2) {
959 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
961 "SAE authentication (RX confirm, status=%u)",
963 if (status_code
!= WLAN_STATUS_SUCCESS
)
965 if (sta
->sae
->state
>= SAE_CONFIRMED
||
966 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
969 u16 peer_send_confirm
;
971 var
= mgmt
->u
.auth
.variable
;
972 var_len
= ((u8
*) mgmt
) + len
- mgmt
->u
.auth
.variable
;
974 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
978 peer_send_confirm
= WPA_GET_LE16(var
);
980 if (sta
->sae
->state
== SAE_ACCEPTED
&&
981 (peer_send_confirm
<= sta
->sae
->rc
||
982 peer_send_confirm
== 0xffff)) {
983 wpa_printf(MSG_DEBUG
,
984 "SAE: Silently ignore unexpected Confirm from peer "
986 " (peer-send-confirm=%u Rc=%u)",
988 peer_send_confirm
, sta
->sae
->rc
);
992 if (sae_check_confirm(sta
->sae
, var
, var_len
) < 0) {
993 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
996 sta
->sae
->rc
= peer_send_confirm
;
998 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
);
1000 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1001 HOSTAPD_LEVEL_DEBUG
,
1002 "unexpected SAE authentication transaction %u (status=%u)",
1003 auth_transaction
, status_code
);
1004 if (status_code
!= WLAN_STATUS_SUCCESS
)
1006 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1010 if (resp
!= WLAN_STATUS_SUCCESS
) {
1011 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
1012 auth_transaction
, resp
,
1013 data
? wpabuf_head(data
) : (u8
*) "",
1014 data
? wpabuf_len(data
) : 0);
1018 if (sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
1019 status_code
!= WLAN_STATUS_SUCCESS
)) {
1020 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1021 sta
->added_unassoc
= 0;
1028 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1029 * @hapd: BSS data for the device initiating the authentication
1030 * @sta: the peer to which commit authentication frame is sent
1032 * This function implements Init event handling (IEEE Std 802.11-2012,
1033 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1034 * sta->sae structure should be initialized appropriately via a call to
1035 * sae_prepare_commit().
1037 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1041 if (!sta
->sae
|| !sta
->sae
->tmp
)
1044 if (sta
->sae
->state
!= SAE_NOTHING
)
1047 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1051 sae_set_state(sta
, SAE_COMMITTED
, "Init and sent commit");
1053 sae_set_retransmit_timer(hapd
, sta
);
1058 #endif /* CONFIG_SAE */
1061 static u16
wpa_res_to_status_code(int res
)
1063 if (res
== WPA_INVALID_GROUP
)
1064 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1065 if (res
== WPA_INVALID_PAIRWISE
)
1066 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1067 if (res
== WPA_INVALID_AKMP
)
1068 return WLAN_STATUS_AKMP_NOT_VALID
;
1069 if (res
== WPA_ALLOC_FAIL
)
1070 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1071 #ifdef CONFIG_IEEE80211W
1072 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1073 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1074 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1075 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
1076 #endif /* CONFIG_IEEE80211W */
1077 if (res
== WPA_INVALID_MDIE
)
1078 return WLAN_STATUS_INVALID_MDIE
;
1079 if (res
== WPA_INVALID_PMKID
)
1080 return WLAN_STATUS_INVALID_PMKID
;
1081 if (res
!= WPA_IE_OK
)
1082 return WLAN_STATUS_INVALID_IE
;
1083 return WLAN_STATUS_SUCCESS
;
1089 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1090 struct sta_info
*sta
, u16 resp
,
1091 struct wpabuf
*data
, int pub
);
1093 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1094 const u8
*pos
, size_t len
, u16 auth_alg
,
1095 u16 auth_transaction
, u16 status_code
,
1096 void (*cb
)(struct hostapd_data
*hapd
,
1097 struct sta_info
*sta
, u16 resp
,
1098 struct wpabuf
*data
, int pub
))
1100 u16 resp
= WLAN_STATUS_SUCCESS
;
1102 struct ieee802_11_elems elems
;
1104 struct wpa_ie_data rsn
;
1105 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1107 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1112 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1116 #ifdef CONFIG_FILS_SK_PFS
1117 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1122 /* Using FILS PFS */
1124 /* Finite Cyclic Group */
1125 if (end
- pos
< 2) {
1126 wpa_printf(MSG_DEBUG
,
1127 "FILS: No room for Finite Cyclic Group");
1128 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1131 group
= WPA_GET_LE16(pos
);
1133 if (group
!= hapd
->conf
->fils_dh_group
) {
1134 wpa_printf(MSG_DEBUG
,
1135 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1136 group
, hapd
->conf
->fils_dh_group
);
1137 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1141 crypto_ecdh_deinit(sta
->fils_ecdh
);
1142 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1143 if (!sta
->fils_ecdh
) {
1144 wpa_printf(MSG_INFO
,
1145 "FILS: Could not initialize ECDH with group %d",
1147 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1151 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1153 wpa_printf(MSG_DEBUG
,
1154 "FILS: Failed to derive ECDH public key");
1155 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1158 elem_len
= wpabuf_len(pub
);
1162 if ((size_t) (end
- pos
) < elem_len
) {
1163 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1164 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1168 wpabuf_free(sta
->fils_g_sta
);
1169 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1170 wpabuf_clear_free(sta
->fils_dh_ss
);
1171 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1173 if (!sta
->fils_dh_ss
) {
1174 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1175 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1178 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1181 crypto_ecdh_deinit(sta
->fils_ecdh
);
1182 sta
->fils_ecdh
= NULL
;
1183 wpabuf_clear_free(sta
->fils_dh_ss
);
1184 sta
->fils_dh_ss
= NULL
;
1186 #endif /* CONFIG_FILS_SK_PFS */
1188 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1189 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1190 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1191 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1196 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1197 elems
.rsn_ie
, elems
.rsn_ie_len
);
1198 if (!elems
.rsn_ie
||
1199 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1201 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1202 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1207 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1210 wpa_printf(MSG_DEBUG
,
1211 "FILS: Failed to initialize RSN state machine");
1212 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1216 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1217 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1218 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1219 resp
= wpa_res_to_status_code(res
);
1220 if (resp
!= WLAN_STATUS_SUCCESS
)
1223 if (!elems
.fils_nonce
) {
1224 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1225 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1228 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1230 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1233 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1237 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1238 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1241 num
= rsn
.num_pmkid
;
1243 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1244 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1248 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1257 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1258 wpa_printf(MSG_DEBUG
,
1259 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1260 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1264 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1267 if (!elems
.fils_session
) {
1268 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1269 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1272 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1274 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1276 /* FILS Wrapped Data */
1277 if (elems
.fils_wrapped_data
) {
1278 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1279 elems
.fils_wrapped_data
,
1280 elems
.fils_wrapped_data_len
);
1282 #ifndef CONFIG_NO_RADIUS
1283 if (!sta
->eapol_sm
) {
1285 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1287 wpa_printf(MSG_DEBUG
,
1288 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1289 ieee802_1x_encapsulate_radius(
1290 hapd
, sta
, elems
.fils_wrapped_data
,
1291 elems
.fils_wrapped_data_len
);
1292 sta
->fils_pending_cb
= cb
;
1293 wpa_printf(MSG_DEBUG
,
1294 "FILS: Will send Authentication frame once the response from authentication server is available");
1295 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1296 /* Calculate pending PMKID here so that we do not need
1297 * to maintain a copy of the EAP-Initiate/Reauth
1299 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1300 elems
.fils_wrapped_data
,
1301 elems
.fils_wrapped_data_len
,
1302 sta
->fils_erp_pmkid
) == 0)
1303 sta
->fils_erp_pmkid_set
= 1;
1305 #else /* CONFIG_NO_RADIUS */
1306 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1308 #endif /* CONFIG_NO_RADIUS */
1314 struct wpabuf
*data
;
1317 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1320 wpa_printf(MSG_DEBUG
,
1321 "%s: prepare_auth_resp_fils() returned failure",
1325 cb(hapd
, sta
, resp
, data
, pub
);
1330 static struct wpabuf
*
1331 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1332 struct sta_info
*sta
, u16
*resp
,
1333 struct rsn_pmksa_cache_entry
*pmksa
,
1334 struct wpabuf
*erp_resp
,
1335 const u8
*msk
, size_t msk_len
,
1338 u8 fils_nonce
[FILS_NONCE_LEN
];
1340 struct wpabuf
*data
= NULL
;
1343 const u8
*pmk
= NULL
;
1345 u8 pmk_buf
[PMK_LEN_MAX
];
1346 struct wpabuf
*pub
= NULL
;
1348 if (*resp
!= WLAN_STATUS_SUCCESS
)
1351 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1353 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1358 /* Add PMKID of the selected PMKSA into RSNE */
1359 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1361 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1365 os_memcpy(ie_buf
, ie
, ielen
);
1366 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1367 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1373 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1374 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1377 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1378 fils_nonce
, FILS_NONCE_LEN
);
1380 #ifdef CONFIG_FILS_SK_PFS
1381 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1382 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1384 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1388 #endif /* CONFIG_FILS_SK_PFS */
1390 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1392 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1397 #ifdef CONFIG_FILS_SK_PFS
1399 /* Finite Cyclic Group */
1400 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1403 wpabuf_put_buf(data
, pub
);
1405 #endif /* CONFIG_FILS_SK_PFS */
1408 wpabuf_put_data(data
, ie
, ielen
);
1410 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1412 #ifdef CONFIG_IEEE80211R_AP
1413 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1414 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1417 res
= wpa_auth_write_fte(hapd
->wpa_auth
, wpabuf_put(data
, 0),
1418 wpabuf_tailroom(data
));
1420 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1423 wpabuf_put(data
, res
);
1425 #endif /* CONFIG_IEEE80211R_AP */
1428 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1429 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1430 /* Element ID Extension */
1431 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1432 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1435 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1436 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1437 /* Element ID Extension */
1438 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1439 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1441 /* FILS Wrapped Data */
1442 if (!pmksa
&& erp_resp
) {
1443 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1444 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1445 /* Element ID Extension */
1446 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1447 wpabuf_put_buf(data
, erp_resp
);
1449 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1450 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1452 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1454 wpabuf_len(sta
->fils_dh_ss
) : 0,
1455 pmk_buf
, &pmk_len
)) {
1456 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1457 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1464 /* Don't use DHss in PTK derivation if PMKSA caching is not
1466 wpabuf_clear_free(sta
->fils_dh_ss
);
1467 sta
->fils_dh_ss
= NULL
;
1469 if (sta
->fils_erp_pmkid_set
) {
1470 /* TODO: get PMKLifetime from WPA parameters */
1471 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1473 sta
->fils_erp_pmkid_set
= 0;
1474 if (wpa_auth_pmksa_add2(
1475 hapd
->wpa_auth
, sta
->addr
,
1477 sta
->fils_erp_pmkid
,
1478 sta
->session_timeout_set
?
1479 sta
->session_timeout
:
1480 dot11RSNAConfigPMKLifetime
,
1481 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1482 wpa_printf(MSG_ERROR
,
1483 "FILS: Failed to add PMKSA cache entry based on ERP");
1488 pmk_len
= pmksa
->pmk_len
;
1492 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1493 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1499 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1500 sta
->fils_snonce
, fils_nonce
,
1502 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1504 wpabuf_len(sta
->fils_dh_ss
) : 0,
1505 sta
->fils_g_sta
, pub
) < 0) {
1506 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1514 *is_pub
= pub
!= NULL
;
1517 wpabuf_clear_free(sta
->fils_dh_ss
);
1518 sta
->fils_dh_ss
= NULL
;
1519 #ifdef CONFIG_FILS_SK_PFS
1520 crypto_ecdh_deinit(sta
->fils_ecdh
);
1521 sta
->fils_ecdh
= NULL
;
1522 #endif /* CONFIG_FILS_SK_PFS */
1527 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1528 struct sta_info
*sta
, u16 resp
,
1529 struct wpabuf
*data
, int pub
)
1534 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1535 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1536 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1537 data
? wpabuf_head(data
) : (u8
*) "",
1538 data
? wpabuf_len(data
) : 0);
1541 if (resp
== WLAN_STATUS_SUCCESS
) {
1542 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1543 HOSTAPD_LEVEL_DEBUG
,
1544 "authentication OK (FILS)");
1545 sta
->flags
|= WLAN_STA_AUTH
;
1546 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1547 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1548 mlme_authenticate_indication(hapd
, sta
);
1553 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
1554 struct sta_info
*sta
, int success
,
1555 struct wpabuf
*erp_resp
,
1556 const u8
*msk
, size_t msk_len
)
1558 struct wpabuf
*data
;
1562 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1564 if (!sta
->fils_pending_cb
)
1566 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
1567 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
1568 msk
, msk_len
, &pub
);
1570 wpa_printf(MSG_DEBUG
,
1571 "%s: prepare_auth_resp_fils() returned failure",
1574 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
1577 #endif /* CONFIG_FILS */
1581 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
1582 const u8
*msg
, size_t len
, u32
*session_timeout
,
1583 u32
*acct_interim_interval
,
1584 struct vlan_description
*vlan_id
,
1585 struct hostapd_sta_wpa_psk_short
**psk
,
1586 char **identity
, char **radius_cui
)
1590 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
1591 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
1592 session_timeout
, acct_interim_interval
,
1593 vlan_id
, psk
, identity
, radius_cui
);
1595 if (res
== HOSTAPD_ACL_REJECT
) {
1596 wpa_printf(MSG_INFO
,
1597 "Station " MACSTR
" not allowed to authenticate",
1599 return HOSTAPD_ACL_REJECT
;
1602 if (res
== HOSTAPD_ACL_PENDING
) {
1603 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
1604 " waiting for an external authentication",
1606 /* Authentication code will re-send the authentication frame
1607 * after it has received (and cached) information from the
1608 * external source. */
1609 return HOSTAPD_ACL_PENDING
;
1617 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1618 int res
, u32 session_timeout
,
1619 u32 acct_interim_interval
,
1620 struct vlan_description
*vlan_id
,
1621 struct hostapd_sta_wpa_psk_short
**psk
,
1622 char **identity
, char **radius_cui
)
1624 if (vlan_id
->notempty
&&
1625 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
1626 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1628 "Invalid VLAN %d%s received from RADIUS server",
1630 vlan_id
->tagged
[0] ? "+" : "");
1633 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
1636 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1637 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
1639 hostapd_free_psk_list(sta
->psk
);
1640 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
1647 sta
->identity
= *identity
;
1649 sta
->radius_cui
= *radius_cui
;
1652 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
1653 sta
->acct_interim_interval
= acct_interim_interval
;
1654 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
)
1655 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1657 ap_sta_no_session_timeout(hapd
, sta
);
1663 static void handle_auth(struct hostapd_data
*hapd
,
1664 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1666 u16 auth_alg
, auth_transaction
, status_code
;
1667 u16 resp
= WLAN_STATUS_SUCCESS
;
1668 struct sta_info
*sta
= NULL
;
1671 const u8
*challenge
= NULL
;
1672 u32 session_timeout
, acct_interim_interval
;
1673 struct vlan_description vlan_id
;
1674 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
1675 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
1676 size_t resp_ies_len
= 0;
1677 char *identity
= NULL
;
1678 char *radius_cui
= NULL
;
1681 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
1682 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
1683 (unsigned long) len
);
1687 #ifdef CONFIG_TESTING_OPTIONS
1688 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
1689 drand48() < hapd
->iconf
->ignore_auth_probability
) {
1690 wpa_printf(MSG_INFO
,
1691 "TESTING: ignoring auth frame from " MACSTR
,
1695 #endif /* CONFIG_TESTING_OPTIONS */
1697 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1698 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1699 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1700 fc
= le_to_host16(mgmt
->frame_control
);
1701 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
1703 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
1704 2 + WLAN_AUTH_CHALLENGE_LEN
&&
1705 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
1706 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
1707 challenge
= &mgmt
->u
.auth
.variable
[2];
1709 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
1710 "auth_transaction=%d status_code=%d wep=%d%s "
1712 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
1713 status_code
, !!(fc
& WLAN_FC_ISWEP
),
1714 challenge
? " challenge" : "",
1715 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
1717 #ifdef CONFIG_NO_RC4
1718 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
1719 wpa_printf(MSG_INFO
,
1720 "Unsupported authentication algorithm (%d)",
1722 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1725 #endif /* CONFIG_NO_RC4 */
1727 if (hapd
->tkip_countermeasures
) {
1728 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1732 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
1733 auth_alg
== WLAN_AUTH_OPEN
) ||
1734 #ifdef CONFIG_IEEE80211R_AP
1735 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
1736 auth_alg
== WLAN_AUTH_FT
) ||
1737 #endif /* CONFIG_IEEE80211R_AP */
1739 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
1740 auth_alg
== WLAN_AUTH_SAE
) ||
1741 #endif /* CONFIG_SAE */
1743 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
1744 auth_alg
== WLAN_AUTH_FILS_SK
) ||
1745 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
1746 hapd
->conf
->fils_dh_group
&&
1747 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
1748 #endif /* CONFIG_FILS */
1749 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
1750 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
1751 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
1753 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1757 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
1758 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
1759 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
1761 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1765 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
1766 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
1768 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1772 if (hapd
->conf
->no_auth_if_seen_on
) {
1773 struct hostapd_data
*other
;
1775 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
1776 hapd
->conf
->no_auth_if_seen_on
);
1780 u8 op_class
, channel
, phytype
;
1782 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
1783 MACSTR
" since STA has been seen on %s",
1784 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
1785 hapd
->conf
->no_auth_if_seen_on
);
1787 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
1789 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
1791 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
1793 info
= 0; /* TODO: BSSID Information */
1794 WPA_PUT_LE32(pos
, info
);
1796 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
1797 phytype
= 8; /* dmg */
1798 else if (other
->iconf
->ieee80211ac
)
1799 phytype
= 9; /* vht */
1800 else if (other
->iconf
->ieee80211n
)
1801 phytype
= 7; /* ht */
1802 else if (other
->iconf
->hw_mode
==
1803 HOSTAPD_MODE_IEEE80211A
)
1804 phytype
= 4; /* ofdm */
1805 else if (other
->iconf
->hw_mode
==
1806 HOSTAPD_MODE_IEEE80211G
)
1807 phytype
= 6; /* erp */
1809 phytype
= 5; /* hrdsss */
1810 if (ieee80211_freq_to_channel_ext(
1811 hostapd_hw_get_freq(other
,
1812 other
->iconf
->channel
),
1813 other
->iconf
->secondary_channel
,
1814 other
->iconf
->ieee80211ac
,
1815 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
1817 channel
= other
->iconf
->channel
;
1822 resp_ies_len
= pos
- &resp_ies
[0];
1827 res
= ieee802_11_allowed_address(
1828 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
1829 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
);
1830 if (res
== HOSTAPD_ACL_REJECT
) {
1831 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1834 if (res
== HOSTAPD_ACL_PENDING
)
1837 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1839 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1840 if ((fc
& WLAN_FC_RETRY
) &&
1841 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
1842 sta
->last_seq_ctrl
== seq_ctrl
&&
1843 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
1844 hostapd_logger(hapd
, sta
->addr
,
1845 HOSTAPD_MODULE_IEEE80211
,
1846 HOSTAPD_LEVEL_DEBUG
,
1847 "Drop repeated authentication frame seq_ctrl=0x%x",
1852 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1853 sta
->plink_state
== PLINK_BLOCKED
) {
1854 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
1855 " is blocked - drop Authentication frame",
1859 #endif /* CONFIG_MESH */
1862 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
1863 /* if the mesh peer is not available, we don't do auth.
1865 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
1866 " not yet known - drop Authentication frame",
1869 * Save a copy of the frame so that it can be processed
1870 * if a new peer entry is added shortly after this.
1872 wpabuf_free(hapd
->mesh_pending_auth
);
1873 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
1874 os_get_reltime(&hapd
->mesh_pending_auth_time
);
1877 #endif /* CONFIG_MESH */
1879 sta
= ap_sta_add(hapd
, mgmt
->sa
);
1881 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1885 sta
->last_seq_ctrl
= seq_ctrl
;
1886 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
1888 res
= ieee802_11_set_radius_info(
1889 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
1890 &vlan_id
, &psk
, &identity
, &radius_cui
);
1892 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1896 sta
->flags
&= ~WLAN_STA_PREAUTH
;
1897 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
1900 * If the driver supports full AP client state, add a station to the
1901 * driver before sending authentication reply to make sure the driver
1902 * has resources, and not to go through the entire authentication and
1903 * association handshake, and fail it at the end.
1905 * If this is not the first transaction, in a multi-step authentication
1906 * algorithm, the station already exists in the driver
1907 * (sta->added_unassoc = 1) so skip it.
1909 * In mesh mode, the station was already added to the driver when the
1910 * NEW_PEER_CANDIDATE event is received.
1912 * If PMF was negotiated for the existing association, skip this to
1913 * avoid dropping the STA entry and the associated keys. This is needed
1914 * to allow the original connection work until the attempt can complete
1915 * (re)association, so that unprotected Authentication frame cannot be
1916 * used to bypass PMF protection.
1918 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
1919 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
1920 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1921 !(sta
->added_unassoc
)) {
1923 * If a station that is already associated to the AP, is trying
1924 * to authenticate again, remove the STA entry, in order to make
1925 * sure the STA PS state gets cleared and configuration gets
1926 * updated. To handle this, station's added_unassoc flag is
1927 * cleared once the station has completed association.
1929 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1930 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
1931 WLAN_STA_AUTHORIZED
);
1933 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0, NULL
, 0, 0,
1934 NULL
, NULL
, sta
->flags
, 0, 0, 0, 0)) {
1935 hostapd_logger(hapd
, sta
->addr
,
1936 HOSTAPD_MODULE_IEEE80211
,
1937 HOSTAPD_LEVEL_NOTICE
,
1938 "Could not add STA to kernel driver");
1939 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1943 sta
->added_unassoc
= 1;
1947 case WLAN_AUTH_OPEN
:
1948 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1949 HOSTAPD_LEVEL_DEBUG
,
1950 "authentication OK (open system)");
1951 sta
->flags
|= WLAN_STA_AUTH
;
1952 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1953 sta
->auth_alg
= WLAN_AUTH_OPEN
;
1954 mlme_authenticate_indication(hapd
, sta
);
1956 #ifndef CONFIG_NO_RC4
1957 case WLAN_AUTH_SHARED_KEY
:
1958 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
1959 fc
& WLAN_FC_ISWEP
);
1960 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
1961 mlme_authenticate_indication(hapd
, sta
);
1962 if (sta
->challenge
&& auth_transaction
== 1) {
1963 resp_ies
[0] = WLAN_EID_CHALLENGE
;
1964 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
1965 os_memcpy(resp_ies
+ 2, sta
->challenge
,
1966 WLAN_AUTH_CHALLENGE_LEN
);
1967 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
1970 #endif /* CONFIG_NO_RC4 */
1971 #ifdef CONFIG_IEEE80211R_AP
1973 sta
->auth_alg
= WLAN_AUTH_FT
;
1974 if (sta
->wpa_sm
== NULL
)
1975 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
1977 if (sta
->wpa_sm
== NULL
) {
1978 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
1980 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1983 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
1984 auth_transaction
, mgmt
->u
.auth
.variable
,
1985 len
- IEEE80211_HDRLEN
-
1986 sizeof(mgmt
->u
.auth
),
1987 handle_auth_ft_finish
, hapd
);
1988 /* handle_auth_ft_finish() callback will complete auth. */
1990 #endif /* CONFIG_IEEE80211R_AP */
1994 if (status_code
== WLAN_STATUS_SUCCESS
&&
1995 hapd
->conf
->mesh
& MESH_ENABLED
) {
1996 if (sta
->wpa_sm
== NULL
)
1998 wpa_auth_sta_init(hapd
->wpa_auth
,
2000 if (sta
->wpa_sm
== NULL
) {
2001 wpa_printf(MSG_DEBUG
,
2002 "SAE: Failed to initialize WPA state machine");
2003 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2007 #endif /* CONFIG_MESH */
2008 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
2011 #endif /* CONFIG_SAE */
2013 case WLAN_AUTH_FILS_SK
:
2014 case WLAN_AUTH_FILS_SK_PFS
:
2015 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
2016 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
2017 auth_alg
, auth_transaction
, status_code
,
2018 handle_auth_fils_finish
);
2020 #endif /* CONFIG_FILS */
2025 os_free(radius_cui
);
2026 hostapd_free_psk_list(psk
);
2028 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
2029 auth_transaction
+ 1, resp
, resp_ies
,
2032 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
2033 reply_res
!= WLAN_STATUS_SUCCESS
)) {
2034 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2035 sta
->added_unassoc
= 0;
2040 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2044 /* get a unique AID */
2046 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2053 for (i
= 0; i
< AID_WORDS
; i
++) {
2054 if (hapd
->sta_aid
[i
] == (u32
) -1)
2056 for (j
= 0; j
< 32; j
++) {
2057 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2065 aid
= i
* 32 + j
+ 1;
2070 hapd
->sta_aid
[i
] |= BIT(j
);
2071 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2076 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2077 const u8
*ssid_ie
, size_t ssid_ie_len
)
2079 if (ssid_ie
== NULL
)
2080 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2082 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2083 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2084 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2086 "Station tried to associate with unknown SSID "
2087 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2088 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2091 return WLAN_STATUS_SUCCESS
;
2095 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2096 const u8
*wmm_ie
, size_t wmm_ie_len
)
2098 sta
->flags
&= ~WLAN_STA_WMM
;
2100 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2101 struct wmm_information_element
*wmm
;
2103 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2104 hostapd_logger(hapd
, sta
->addr
,
2106 HOSTAPD_LEVEL_DEBUG
,
2107 "invalid WMM element in association "
2109 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2112 sta
->flags
|= WLAN_STA_WMM
;
2113 wmm
= (struct wmm_information_element
*) wmm_ie
;
2114 sta
->qosinfo
= wmm
->qos_info
;
2116 return WLAN_STATUS_SUCCESS
;
2120 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2121 struct ieee802_11_elems
*elems
)
2123 /* Supported rates not used in IEEE 802.11ad/DMG */
2124 if (hapd
->iface
->current_mode
&&
2125 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2126 return WLAN_STATUS_SUCCESS
;
2128 if (!elems
->supp_rates
) {
2129 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2130 HOSTAPD_LEVEL_DEBUG
,
2131 "No supported rates element in AssocReq");
2132 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2135 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2136 sizeof(sta
->supported_rates
)) {
2137 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2138 HOSTAPD_LEVEL_DEBUG
,
2139 "Invalid supported rates element length %d+%d",
2140 elems
->supp_rates_len
,
2141 elems
->ext_supp_rates_len
);
2142 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2145 sta
->supported_rates_len
= merge_byte_arrays(
2146 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2147 elems
->supp_rates
, elems
->supp_rates_len
,
2148 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2150 return WLAN_STATUS_SUCCESS
;
2154 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2155 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2157 #ifdef CONFIG_INTERWORKING
2158 /* check for QoS Map support */
2159 if (ext_capab_ie_len
>= 5) {
2160 if (ext_capab_ie
[4] & 0x01)
2161 sta
->qos_map_enabled
= 1;
2163 #endif /* CONFIG_INTERWORKING */
2165 if (ext_capab_ie_len
> 0) {
2166 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2167 os_free(sta
->ext_capability
);
2168 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2169 if (sta
->ext_capability
) {
2170 sta
->ext_capability
[0] = ext_capab_ie_len
;
2171 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2176 return WLAN_STATUS_SUCCESS
;
2182 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2185 int *groups
= hapd
->conf
->owe_groups
;
2187 if (group
!= 19 && group
!= 20 && group
!= 21)
2193 for (i
= 0; groups
[i
] > 0; i
++) {
2194 if (groups
[i
] == group
)
2202 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2203 struct sta_info
*sta
, const u8
*owe_dh
,
2206 struct wpabuf
*secret
, *pub
, *hkey
;
2208 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2209 const char *info
= "OWE Key Generation";
2213 size_t hash_len
, prime_len
;
2215 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2216 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2217 return WLAN_STATUS_SUCCESS
;
2220 group
= WPA_GET_LE16(owe_dh
);
2221 if (!owe_group_supported(hapd
, group
)) {
2222 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2223 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2227 else if (group
== 20)
2229 else if (group
== 21)
2232 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2234 crypto_ecdh_deinit(sta
->owe_ecdh
);
2235 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2237 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2238 sta
->owe_group
= group
;
2240 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2242 secret
= wpabuf_zeropad(secret
, prime_len
);
2244 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2245 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2247 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2249 /* prk = HKDF-extract(C | A | group, z) */
2251 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2253 wpabuf_clear_free(secret
);
2254 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2257 /* PMKID = Truncate-128(Hash(C | A)) */
2258 addr
[0] = owe_dh
+ 2;
2259 len
[0] = owe_dh_len
- 2;
2260 addr
[1] = wpabuf_head(pub
);
2261 len
[1] = wpabuf_len(pub
);
2263 res
= sha256_vector(2, addr
, len
, pmkid
);
2264 hash_len
= SHA256_MAC_LEN
;
2265 } else if (group
== 20) {
2266 res
= sha384_vector(2, addr
, len
, pmkid
);
2267 hash_len
= SHA384_MAC_LEN
;
2268 } else if (group
== 21) {
2269 res
= sha512_vector(2, addr
, len
, pmkid
);
2270 hash_len
= SHA512_MAC_LEN
;
2273 wpabuf_clear_free(secret
);
2274 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2276 pub
= wpabuf_zeropad(pub
, prime_len
);
2277 if (res
< 0 || !pub
) {
2279 wpabuf_clear_free(secret
);
2280 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2283 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2286 wpabuf_clear_free(secret
);
2287 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2290 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2291 wpabuf_put_buf(hkey
, pub
); /* A */
2293 wpabuf_put_le16(hkey
, group
); /* group */
2295 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2296 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2297 else if (group
== 20)
2298 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2299 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2300 else if (group
== 21)
2301 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2302 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2303 wpabuf_clear_free(hkey
);
2304 wpabuf_clear_free(secret
);
2306 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2308 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2310 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2312 os_free(sta
->owe_pmk
);
2313 sta
->owe_pmk
= os_malloc(hash_len
);
2314 if (!sta
->owe_pmk
) {
2315 os_memset(prk
, 0, SHA512_MAC_LEN
);
2316 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2320 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2321 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2322 else if (group
== 20)
2323 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2324 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2325 else if (group
== 21)
2326 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2327 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2328 os_memset(prk
, 0, SHA512_MAC_LEN
);
2330 os_free(sta
->owe_pmk
);
2331 sta
->owe_pmk
= NULL
;
2332 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2334 sta
->owe_pmk_len
= hash_len
;
2336 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2337 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2338 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2339 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2341 return WLAN_STATUS_SUCCESS
;
2344 #endif /* CONFIG_OWE */
2347 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2348 const u8
*ies
, size_t ies_len
, int reassoc
)
2350 struct ieee802_11_elems elems
;
2354 const u8
*p2p_dev_addr
= NULL
;
2356 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2357 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2358 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
2359 "association request");
2360 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2363 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
2364 if (resp
!= WLAN_STATUS_SUCCESS
)
2366 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
2367 if (resp
!= WLAN_STATUS_SUCCESS
)
2369 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
2370 if (resp
!= WLAN_STATUS_SUCCESS
)
2372 resp
= copy_supp_rates(hapd
, sta
, &elems
);
2373 if (resp
!= WLAN_STATUS_SUCCESS
)
2375 #ifdef CONFIG_IEEE80211N
2376 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
2377 if (resp
!= WLAN_STATUS_SUCCESS
)
2379 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
2380 !(sta
->flags
& WLAN_STA_HT
)) {
2381 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2382 HOSTAPD_LEVEL_INFO
, "Station does not support "
2383 "mandatory HT PHY - reject association");
2384 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
2386 #endif /* CONFIG_IEEE80211N */
2388 #ifdef CONFIG_IEEE80211AC
2389 if (hapd
->iconf
->ieee80211ac
) {
2390 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
2391 if (resp
!= WLAN_STATUS_SUCCESS
)
2394 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
2395 if (resp
!= WLAN_STATUS_SUCCESS
)
2399 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
2400 !(sta
->flags
& WLAN_STA_VHT
)) {
2401 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2402 HOSTAPD_LEVEL_INFO
, "Station does not support "
2403 "mandatory VHT PHY - reject association");
2404 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
2407 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
2408 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
2409 elems
.vendor_vht_len
);
2410 if (resp
!= WLAN_STATUS_SUCCESS
)
2413 #endif /* CONFIG_IEEE80211AC */
2417 wpabuf_free(sta
->p2p_ie
);
2418 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2419 P2P_IE_VENDOR_TYPE
);
2421 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
2423 wpabuf_free(sta
->p2p_ie
);
2426 #endif /* CONFIG_P2P */
2428 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
2429 wpa_ie
= elems
.rsn_ie
;
2430 wpa_ie_len
= elems
.rsn_ie_len
;
2431 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
2433 wpa_ie
= elems
.wpa_ie
;
2434 wpa_ie_len
= elems
.wpa_ie_len
;
2441 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
2442 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
2443 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
2444 "Request - assume WPS is used");
2445 sta
->flags
|= WLAN_STA_WPS
;
2446 wpabuf_free(sta
->wps_ie
);
2447 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2448 WPS_IE_VENDOR_TYPE
);
2449 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
2450 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
2451 sta
->flags
|= WLAN_STA_WPS2
;
2455 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
2456 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
2457 "(Re)Association Request - reject");
2458 return WLAN_STATUS_INVALID_IE
;
2460 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
2461 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
2462 "(Re)Association Request - possible WPS use");
2463 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
2465 #endif /* CONFIG_WPS */
2466 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
2467 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2469 "No WPA/RSN IE in association request");
2470 return WLAN_STATUS_INVALID_IE
;
2473 if (hapd
->conf
->wpa
&& wpa_ie
) {
2477 if (sta
->wpa_sm
== NULL
)
2478 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2481 if (sta
->wpa_sm
== NULL
) {
2482 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2484 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2486 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2488 elems
.mdie
, elems
.mdie_len
,
2489 elems
.owe_dh
, elems
.owe_dh_len
);
2490 resp
= wpa_res_to_status_code(res
);
2491 if (resp
!= WLAN_STATUS_SUCCESS
)
2493 #ifdef CONFIG_IEEE80211W
2494 if ((sta
->flags
& WLAN_STA_MFP
) && !sta
->sa_query_timed_out
&&
2495 sta
->sa_query_count
> 0)
2496 ap_check_sa_query_timeout(hapd
, sta
);
2497 if ((sta
->flags
& WLAN_STA_MFP
) && !sta
->sa_query_timed_out
&&
2498 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
2500 * STA has already been associated with MFP and SA
2501 * Query timeout has not been reached. Reject the
2502 * association attempt temporarily and start SA Query,
2503 * if one is not pending.
2506 if (sta
->sa_query_count
== 0)
2507 ap_sta_start_sa_query(hapd
, sta
);
2509 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
2512 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
2513 sta
->flags
|= WLAN_STA_MFP
;
2515 sta
->flags
&= ~WLAN_STA_MFP
;
2516 #endif /* CONFIG_IEEE80211W */
2518 #ifdef CONFIG_IEEE80211R_AP
2519 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
2521 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
2522 "to use association (not "
2523 "re-association) with FT auth_alg",
2524 MAC2STR(sta
->addr
));
2525 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2528 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
2530 if (resp
!= WLAN_STATUS_SUCCESS
)
2533 #endif /* CONFIG_IEEE80211R_AP */
2536 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
2537 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
2538 struct rsn_pmksa_cache_entry
*sa
;
2539 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
2540 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
2541 wpa_printf(MSG_DEBUG
,
2542 "SAE: No PMKSA cache entry found for "
2543 MACSTR
, MAC2STR(sta
->addr
));
2544 return WLAN_STATUS_INVALID_PMKID
;
2546 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
2547 " using PMKSA caching", MAC2STR(sta
->addr
));
2548 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
2549 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
2550 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
2551 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
2552 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
2553 "SAE AKM after non-SAE auth_alg %u",
2554 MAC2STR(sta
->addr
), sta
->auth_alg
);
2555 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2557 #endif /* CONFIG_SAE */
2560 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
2561 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
2563 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
2565 if (resp
!= WLAN_STATUS_SUCCESS
)
2568 #endif /* CONFIG_OWE */
2570 #ifdef CONFIG_IEEE80211N
2571 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
2572 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
2573 hostapd_logger(hapd
, sta
->addr
,
2574 HOSTAPD_MODULE_IEEE80211
,
2576 "Station tried to use TKIP with HT "
2578 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
2580 #endif /* CONFIG_IEEE80211N */
2582 } else if (hapd
->conf
->osen
) {
2583 if (elems
.osen
== NULL
) {
2585 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2587 "No HS 2.0 OSEN element in association request");
2588 return WLAN_STATUS_INVALID_IE
;
2591 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
2592 if (sta
->wpa_sm
== NULL
)
2593 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2595 if (sta
->wpa_sm
== NULL
) {
2596 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2598 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2600 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
2601 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
2602 return WLAN_STATUS_INVALID_IE
;
2603 #endif /* CONFIG_HS20 */
2605 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
2608 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
2609 #endif /* CONFIG_P2P */
2612 wpabuf_free(sta
->hs20_ie
);
2613 if (elems
.hs20
&& elems
.hs20_len
> 4) {
2614 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
2615 elems
.hs20_len
- 4);
2617 sta
->hs20_ie
= NULL
;
2618 #endif /* CONFIG_HS20 */
2621 wpabuf_free(sta
->mb_ies
);
2622 if (hapd
->iface
->fst
)
2623 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
2626 #endif /* CONFIG_FST */
2629 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
2631 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
2632 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
2633 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
2634 wpa_printf(MSG_INFO
,
2635 "MBO: Reject WPA2 association without PMF");
2636 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2638 #endif /* CONFIG_MBO */
2640 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
2641 elems
.supp_op_classes_len
);
2643 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
2644 elems
.rrm_enabled
&&
2645 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
2646 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
2647 sizeof(sta
->rrm_enabled_capa
));
2649 if (elems
.power_capab
) {
2650 sta
->min_tx_power
= elems
.power_capab
[0];
2651 sta
->max_tx_power
= elems
.power_capab
[1];
2652 sta
->power_capab
= 1;
2654 sta
->power_capab
= 0;
2657 return WLAN_STATUS_SUCCESS
;
2661 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
2665 struct ieee80211_mgmt reply
;
2667 os_memset(&reply
, 0, sizeof(reply
));
2668 reply
.frame_control
=
2669 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
2670 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
2671 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
2672 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
2674 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
2675 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
2677 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
2678 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
2683 static int add_associated_sta(struct hostapd_data
*hapd
,
2684 struct sta_info
*sta
)
2686 struct ieee80211_ht_capabilities ht_cap
;
2687 struct ieee80211_vht_capabilities vht_cap
;
2691 * Remove the STA entry to ensure the STA PS state gets cleared and
2692 * configuration gets updated. This is relevant for cases, such as
2693 * FT-over-the-DS, where a station re-associates back to the same AP but
2694 * skips the authentication flow, or if working with a driver that
2695 * does not support full AP client state.
2697 * Skip this if the STA has already completed FT reassociation and the
2698 * TK has been configured since the TX/RX PN must not be reset to 0 for
2701 if (!sta
->added_unassoc
&&
2702 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
2703 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
2704 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
2705 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2706 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
2710 #ifdef CONFIG_IEEE80211N
2711 if (sta
->flags
& WLAN_STA_HT
)
2712 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
2713 #endif /* CONFIG_IEEE80211N */
2714 #ifdef CONFIG_IEEE80211AC
2715 if (sta
->flags
& WLAN_STA_VHT
)
2716 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
2717 #endif /* CONFIG_IEEE80211AC */
2720 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
2721 * will be set when the ACK frame for the (Re)Association Response frame
2722 * is processed (TX status driver event).
2724 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
2725 sta
->supported_rates
, sta
->supported_rates_len
,
2726 sta
->listen_interval
,
2727 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
2728 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
2729 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
2730 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
2732 hostapd_logger(hapd
, sta
->addr
,
2733 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
2734 "Could not %s STA to kernel driver",
2735 set
? "set" : "add");
2737 if (sta
->added_unassoc
) {
2738 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2739 sta
->added_unassoc
= 0;
2745 sta
->added_unassoc
= 0;
2751 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2752 const u8
*addr
, u16 status_code
, int reassoc
,
2753 const u8
*ies
, size_t ies_len
)
2758 struct ieee80211_mgmt
*reply
;
2760 u16 res
= WLAN_STATUS_SUCCESS
;
2762 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
2764 if (sta
&& sta
->fils_hlp_resp
)
2765 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
2766 #endif /* CONFIG_FILS */
2768 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
2770 #endif /* CONFIG_OWE */
2771 buf
= os_zalloc(buflen
);
2773 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2776 reply
= (struct ieee80211_mgmt
*) buf
;
2777 reply
->frame_control
=
2778 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2779 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
2780 WLAN_FC_STYPE_ASSOC_RESP
));
2781 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
2782 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
2783 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
2785 send_len
= IEEE80211_HDRLEN
;
2786 send_len
+= sizeof(reply
->u
.assoc_resp
);
2787 reply
->u
.assoc_resp
.capab_info
=
2788 host_to_le16(hostapd_own_capab_info(hapd
));
2789 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
2791 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
2793 /* Supported rates */
2794 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
2795 /* Extended supported rates */
2796 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
2798 #ifdef CONFIG_IEEE80211R_AP
2799 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
2800 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
2801 * Transition Information, RSN, [RIC Response] */
2802 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
2804 sta
->auth_alg
, ies
, ies_len
);
2806 #endif /* CONFIG_IEEE80211R_AP */
2809 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
2810 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
2813 #endif /* CONFIG_OWE */
2815 #ifdef CONFIG_IEEE80211W
2816 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
2817 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
2818 #endif /* CONFIG_IEEE80211W */
2820 #ifdef CONFIG_IEEE80211N
2821 p
= hostapd_eid_ht_capabilities(hapd
, p
);
2822 p
= hostapd_eid_ht_operation(hapd
, p
);
2823 #endif /* CONFIG_IEEE80211N */
2825 #ifdef CONFIG_IEEE80211AC
2826 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
) {
2827 u32 nsts
= 0, sta_nsts
;
2829 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
2830 struct ieee80211_vht_capabilities
*capa
;
2832 nsts
= (hapd
->iface
->conf
->vht_capab
>>
2833 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
2834 capa
= sta
->vht_capabilities
;
2835 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
2836 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
2838 if (nsts
< sta_nsts
)
2843 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
2844 p
= hostapd_eid_vht_operation(hapd
, p
);
2846 #endif /* CONFIG_IEEE80211AC */
2848 p
= hostapd_eid_ext_capab(hapd
, p
);
2849 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
2850 if (sta
&& sta
->qos_map_enabled
)
2851 p
= hostapd_eid_qos_map_set(hapd
, p
);
2854 if (hapd
->iface
->fst_ies
) {
2855 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
2856 wpabuf_len(hapd
->iface
->fst_ies
));
2857 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
2859 #endif /* CONFIG_FST */
2861 #ifdef CONFIG_IEEE80211AC
2862 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
2863 p
= hostapd_eid_vendor_vht(hapd
, p
);
2864 #endif /* CONFIG_IEEE80211AC */
2866 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
2867 p
= hostapd_eid_wmm(hapd
, p
);
2871 ((sta
->flags
& WLAN_STA_WPS
) ||
2872 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
2873 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
2875 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
2876 p
+= wpabuf_len(wps
);
2880 #endif /* CONFIG_WPS */
2883 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
2884 struct wpabuf
*p2p_resp_ie
;
2885 enum p2p_status_code status
;
2886 switch (status_code
) {
2887 case WLAN_STATUS_SUCCESS
:
2888 status
= P2P_SC_SUCCESS
;
2890 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
2891 status
= P2P_SC_FAIL_LIMIT_REACHED
;
2894 status
= P2P_SC_FAIL_INVALID_PARAMS
;
2897 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
2899 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
2900 wpabuf_len(p2p_resp_ie
));
2901 p
+= wpabuf_len(p2p_resp_ie
);
2902 wpabuf_free(p2p_resp_ie
);
2905 #endif /* CONFIG_P2P */
2907 #ifdef CONFIG_P2P_MANAGER
2908 if (hapd
->conf
->p2p
& P2P_MANAGE
)
2909 p
= hostapd_eid_p2p_manage(hapd
, p
);
2910 #endif /* CONFIG_P2P_MANAGER */
2912 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
2914 if (hapd
->conf
->assocresp_elements
&&
2915 (size_t) (buf
+ buflen
- p
) >=
2916 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
2917 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
2918 wpabuf_len(hapd
->conf
->assocresp_elements
));
2919 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
2922 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
2926 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
2927 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
2928 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
2929 status_code
== WLAN_STATUS_SUCCESS
) {
2930 struct ieee802_11_elems elems
;
2932 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
2933 ParseFailed
|| !elems
.fils_session
) {
2934 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2939 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
2940 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
2941 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
2942 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
2943 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
2945 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
2946 buflen
, sta
->fils_hlp_resp
);
2948 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2952 #endif /* CONFIG_FILS */
2955 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
2956 sta
&& sta
->owe_ecdh
&&
2957 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
2960 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2962 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2965 /* OWE Diffie-Hellman Parameter element */
2966 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
2967 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
2968 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
2969 WPA_PUT_LE16(p
, sta
->owe_group
);
2971 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
2972 p
+= wpabuf_len(pub
);
2973 send_len
+= 3 + 2 + wpabuf_len(pub
);
2976 #endif /* CONFIG_OWE */
2978 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
2979 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
2981 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2991 u8
* owe_auth_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2992 const u8
*owe_dh
, u8 owe_dh_len
,
2993 u8
*owe_buf
, size_t owe_buf_len
, u16
*reason
)
2997 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2998 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2999 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3000 owe_buf_len
, NULL
, 0);
3001 *reason
= WLAN_STATUS_SUCCESS
;
3005 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
3006 if (*reason
!= WLAN_STATUS_SUCCESS
)
3008 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
3010 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3014 owe_buf
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, owe_buf
,
3015 owe_buf_len
, NULL
, 0);
3017 /* OWE Diffie-Hellman Parameter element */
3018 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
3019 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
3020 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
3021 WPA_PUT_LE16(owe_buf
, sta
->owe_group
);
3023 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
3024 owe_buf
+= wpabuf_len(pub
);
3026 *reason
= WLAN_STATUS_SUCCESS
;
3029 #endif /* CONFIG_OWE */
3034 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
3038 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
3039 MAC2STR(sta
->addr
));
3040 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3041 if (!sta
->fils_pending_assoc_req
)
3043 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
3044 sta
->fils_pending_assoc_is_reassoc
,
3045 sta
->fils_pending_assoc_req
,
3046 sta
->fils_pending_assoc_req_len
);
3047 os_free(sta
->fils_pending_assoc_req
);
3048 sta
->fils_pending_assoc_req
= NULL
;
3049 sta
->fils_pending_assoc_req_len
= 0;
3050 wpabuf_free(sta
->fils_hlp_resp
);
3051 sta
->fils_hlp_resp
= NULL
;
3052 wpabuf_free(sta
->hlp_dhcp_discover
);
3053 sta
->hlp_dhcp_discover
= NULL
;
3056 * Remove the station in case transmission of a success response fails.
3057 * At this point the station was already added associated to the driver.
3059 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3060 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3064 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3066 struct hostapd_data
*hapd
= eloop_ctx
;
3067 struct sta_info
*sta
= eloop_data
;
3069 wpa_printf(MSG_DEBUG
,
3070 "FILS: HLP response timeout - continue with association response for "
3071 MACSTR
, MAC2STR(sta
->addr
));
3072 if (sta
->fils_drv_assoc_finish
)
3073 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3075 fils_hlp_finish_assoc(hapd
, sta
);
3078 #endif /* CONFIG_FILS */
3081 static void handle_assoc(struct hostapd_data
*hapd
,
3082 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3085 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3086 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3089 struct sta_info
*sta
;
3091 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3092 char *identity
= NULL
;
3093 char *radius_cui
= NULL
;
3095 int delay_assoc
= 0;
3096 #endif /* CONFIG_FILS */
3098 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3099 sizeof(mgmt
->u
.assoc_req
))) {
3100 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3101 reassoc
, (unsigned long) len
);
3105 #ifdef CONFIG_TESTING_OPTIONS
3107 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3108 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3109 wpa_printf(MSG_INFO
,
3110 "TESTING: ignoring reassoc request from "
3111 MACSTR
, MAC2STR(mgmt
->sa
));
3115 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3116 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3117 wpa_printf(MSG_INFO
,
3118 "TESTING: ignoring assoc request from "
3119 MACSTR
, MAC2STR(mgmt
->sa
));
3123 #endif /* CONFIG_TESTING_OPTIONS */
3125 fc
= le_to_host16(mgmt
->frame_control
);
3126 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3129 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
3130 listen_interval
= le_to_host16(
3131 mgmt
->u
.reassoc_req
.listen_interval
);
3132 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
3133 " capab_info=0x%02x listen_interval=%d current_ap="
3134 MACSTR
" seq_ctrl=0x%x%s",
3135 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3136 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
3137 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3138 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
3139 pos
= mgmt
->u
.reassoc_req
.variable
;
3141 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
3142 listen_interval
= le_to_host16(
3143 mgmt
->u
.assoc_req
.listen_interval
);
3144 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
3145 " capab_info=0x%02x listen_interval=%d "
3147 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3148 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3149 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
3150 pos
= mgmt
->u
.assoc_req
.variable
;
3153 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3154 #ifdef CONFIG_IEEE80211R_AP
3155 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
3156 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3157 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
3158 "prior to authentication since it is using "
3159 "over-the-DS FT", MAC2STR(mgmt
->sa
));
3162 * Mark station as authenticated, to avoid adding station
3163 * entry in the driver as associated and not authenticated
3165 sta
->flags
|= WLAN_STA_AUTH
;
3167 #endif /* CONFIG_IEEE80211R_AP */
3168 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3169 if (hapd
->iface
->current_mode
&&
3170 hapd
->iface
->current_mode
->mode
==
3171 HOSTAPD_MODE_IEEE80211AD
) {
3173 u32 session_timeout
, acct_interim_interval
;
3174 struct vlan_description vlan_id
;
3176 acl_res
= ieee802_11_allowed_address(
3177 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
3178 &session_timeout
, &acct_interim_interval
,
3179 &vlan_id
, &psk
, &identity
, &radius_cui
);
3180 if (acl_res
== HOSTAPD_ACL_REJECT
) {
3181 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3184 if (acl_res
== HOSTAPD_ACL_PENDING
)
3187 /* DMG/IEEE 802.11ad does not use authentication.
3188 * Allocate sta entry upon association. */
3189 sta
= ap_sta_add(hapd
, mgmt
->sa
);
3191 hostapd_logger(hapd
, mgmt
->sa
,
3192 HOSTAPD_MODULE_IEEE80211
,
3194 "Failed to add STA");
3195 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3199 acl_res
= ieee802_11_set_radius_info(
3200 hapd
, sta
, acl_res
, session_timeout
,
3201 acct_interim_interval
, &vlan_id
, &psk
,
3202 &identity
, &radius_cui
);
3204 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3208 hostapd_logger(hapd
, sta
->addr
,
3209 HOSTAPD_MODULE_IEEE80211
,
3210 HOSTAPD_LEVEL_DEBUG
,
3211 "Skip authentication for DMG/IEEE 802.11ad");
3212 sta
->flags
|= WLAN_STA_AUTH
;
3213 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
3214 sta
->auth_alg
= WLAN_AUTH_OPEN
;
3216 hostapd_logger(hapd
, mgmt
->sa
,
3217 HOSTAPD_MODULE_IEEE80211
,
3219 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3220 sta
? sta
->aid
: -1,
3221 sta
? sta
->flags
: 0);
3222 send_deauth(hapd
, mgmt
->sa
,
3223 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
3228 if ((fc
& WLAN_FC_RETRY
) &&
3229 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3230 sta
->last_seq_ctrl
== seq_ctrl
&&
3231 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3232 WLAN_FC_STYPE_ASSOC_REQ
)) {
3233 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3234 HOSTAPD_LEVEL_DEBUG
,
3235 "Drop repeated association frame seq_ctrl=0x%x",
3239 sta
->last_seq_ctrl
= seq_ctrl
;
3240 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3241 WLAN_FC_STYPE_ASSOC_REQ
;
3243 if (hapd
->tkip_countermeasures
) {
3244 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3248 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
3249 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3250 HOSTAPD_LEVEL_DEBUG
,
3251 "Too large Listen Interval (%d)",
3253 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
3258 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
3259 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3262 #endif /* CONFIG_MBO */
3265 * sta->capability is used in check_assoc_ies() for RRM enabled
3266 * capability element.
3268 sta
->capability
= capab_info
;
3271 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3272 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3273 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3276 /* The end of the payload is encrypted. Need to decrypt it
3277 * before parsing. */
3279 tmp
= os_memdup(pos
, left
);
3281 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3285 res
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
3288 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3294 #endif /* CONFIG_FILS */
3296 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3298 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
3299 if (resp
!= WLAN_STATUS_SUCCESS
)
3302 if (hostapd_get_aid(hapd
, sta
) < 0) {
3303 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3304 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
3305 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3309 sta
->listen_interval
= listen_interval
;
3311 if (hapd
->iface
->current_mode
&&
3312 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
3313 sta
->flags
|= WLAN_STA_NONERP
;
3314 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
3315 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
3316 sta
->flags
&= ~WLAN_STA_NONERP
;
3320 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
3321 sta
->nonerp_set
= 1;
3322 hapd
->iface
->num_sta_non_erp
++;
3323 if (hapd
->iface
->num_sta_non_erp
== 1)
3324 ieee802_11_set_beacons(hapd
->iface
);
3327 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
3328 !sta
->no_short_slot_time_set
) {
3329 sta
->no_short_slot_time_set
= 1;
3330 hapd
->iface
->num_sta_no_short_slot_time
++;
3331 if (hapd
->iface
->current_mode
&&
3332 hapd
->iface
->current_mode
->mode
==
3333 HOSTAPD_MODE_IEEE80211G
&&
3334 hapd
->iface
->num_sta_no_short_slot_time
== 1)
3335 ieee802_11_set_beacons(hapd
->iface
);
3338 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3339 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
3341 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
3343 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
3344 !sta
->no_short_preamble_set
) {
3345 sta
->no_short_preamble_set
= 1;
3346 hapd
->iface
->num_sta_no_short_preamble
++;
3347 if (hapd
->iface
->current_mode
&&
3348 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
3349 && hapd
->iface
->num_sta_no_short_preamble
== 1)
3350 ieee802_11_set_beacons(hapd
->iface
);
3353 #ifdef CONFIG_IEEE80211N
3354 update_ht_state(hapd
, sta
);
3355 #endif /* CONFIG_IEEE80211N */
3357 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3358 HOSTAPD_LEVEL_DEBUG
,
3359 "association OK (aid %d)", sta
->aid
);
3360 /* Station will be marked associated, after it acknowledges AssocResp
3362 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
3364 #ifdef CONFIG_IEEE80211W
3365 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
3366 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
3367 "SA Query procedure", reassoc
? "re" : "");
3368 /* TODO: Send a protected Disassociate frame to the STA using
3369 * the old key and Reason Code "Previous Authentication no
3370 * longer valid". Make sure this is only sent protected since
3371 * unprotected frame would be received by the STA that is now
3372 * trying to associate.
3375 #endif /* CONFIG_IEEE80211W */
3377 /* Make sure that the previously registered inactivity timer will not
3378 * remove the STA immediately. */
3379 sta
->timeout_next
= STA_NULLFUNC
;
3381 #ifdef CONFIG_TAXONOMY
3382 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
3383 #endif /* CONFIG_TAXONOMY */
3385 sta
->pending_wds_enable
= 0;
3388 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3389 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3390 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3391 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
3394 #endif /* CONFIG_FILS */
3398 os_free(radius_cui
);
3399 hostapd_free_psk_list(psk
);
3402 * In case of a successful response, add the station to the driver.
3403 * Otherwise, the kernel may ignore Data frames before we process the
3404 * ACK frame (TX status). In case of a failure, this station will be
3407 * Note that this is not compliant with the IEEE 802.11 standard that
3408 * states that a non-AP station should transition into the
3409 * authenticated/associated state only after the station acknowledges
3410 * the (Re)Association Response frame. However, still do this as:
3412 * 1. In case the station does not acknowledge the (Re)Association
3413 * Response frame, it will be removed.
3414 * 2. Data frames will be dropped in the kernel until the station is
3415 * set into authorized state, and there are no significant known
3416 * issues with processing other non-Data Class 3 frames during this
3419 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&& add_associated_sta(hapd
, sta
))
3420 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3424 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3425 os_free(sta
->fils_pending_assoc_req
);
3426 sta
->fils_pending_assoc_req
= NULL
;
3427 sta
->fils_pending_assoc_req_len
= 0;
3428 wpabuf_free(sta
->fils_hlp_resp
);
3429 sta
->fils_hlp_resp
= NULL
;
3431 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
3432 sta
->fils_pending_assoc_req
= tmp
;
3433 sta
->fils_pending_assoc_req_len
= left
;
3434 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
3435 sta
->fils_drv_assoc_finish
= 0;
3436 wpa_printf(MSG_DEBUG
,
3437 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
3438 MACSTR
, MAC2STR(sta
->addr
));
3439 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3440 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
3441 fils_hlp_timeout
, hapd
, sta
);
3444 #endif /* CONFIG_FILS */
3446 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
3451 * Remove the station in case tranmission of a success response fails
3452 * (the STA was added associated to the driver) or if the station was
3453 * previously added unassociated.
3455 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
3456 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
3457 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3458 sta
->added_unassoc
= 0;
3463 static void handle_disassoc(struct hostapd_data
*hapd
,
3464 const struct ieee80211_mgmt
*mgmt
, size_t len
)
3466 struct sta_info
*sta
;
3468 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
3469 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
3470 (unsigned long) len
);
3474 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
3476 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
3478 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3480 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
3485 ap_sta_set_authorized(hapd
, sta
, 0);
3486 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
3487 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
3488 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
3489 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3490 HOSTAPD_LEVEL_INFO
, "disassociated");
3491 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
3492 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
3493 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
3495 accounting_sta_stop(hapd
, sta
);
3496 ieee802_1x_free_station(hapd
, sta
);
3498 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
3499 ap_sta_ip6addr_del(hapd
, sta
);
3500 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3501 sta
->added_unassoc
= 0;
3503 if (sta
->timeout_next
== STA_NULLFUNC
||
3504 sta
->timeout_next
== STA_DISASSOC
) {
3505 sta
->timeout_next
= STA_DEAUTH
;
3506 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
3507 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
3511 mlme_disassociate_indication(
3512 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
3514 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
3515 * disassociation. */
3516 if (hapd
->iface
->current_mode
&&
3517 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
3518 sta
->flags
&= ~WLAN_STA_AUTH
;
3519 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
3520 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3521 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
3522 ap_free_sta(hapd
, sta
);
3527 static void handle_deauth(struct hostapd_data
*hapd
,
3528 const struct ieee80211_mgmt
*mgmt
, size_t len
)
3530 struct sta_info
*sta
;
3532 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
3533 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
3534 "payload (len=%lu)", (unsigned long) len
);
3538 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
3540 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
3542 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3544 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
3545 "to deauthenticate, but it is not authenticated",
3550 ap_sta_set_authorized(hapd
, sta
, 0);
3551 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
3552 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
3553 WLAN_STA_ASSOC_REQ_OK
);
3554 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
3555 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3556 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
3557 mlme_deauthenticate_indication(
3558 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
3559 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
3560 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
3561 ap_free_sta(hapd
, sta
);
3565 static void handle_beacon(struct hostapd_data
*hapd
,
3566 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3567 struct hostapd_frame_info
*fi
)
3569 struct ieee802_11_elems elems
;
3571 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
3572 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
3573 (unsigned long) len
);
3577 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
3578 len
- (IEEE80211_HDRLEN
+
3579 sizeof(mgmt
->u
.beacon
)), &elems
,
3582 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
3586 #ifdef CONFIG_IEEE80211W
3588 static int hostapd_sa_query_action(struct hostapd_data
*hapd
,
3589 const struct ieee80211_mgmt
*mgmt
,
3594 end
= mgmt
->u
.action
.u
.sa_query_resp
.trans_id
+
3595 WLAN_SA_QUERY_TR_ID_LEN
;
3596 if (((u8
*) mgmt
) + len
< end
) {
3597 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Too short SA Query Action "
3598 "frame (len=%lu)", (unsigned long) len
);
3602 ieee802_11_sa_query_action(hapd
, mgmt
->sa
,
3603 mgmt
->u
.action
.u
.sa_query_resp
.action
,
3604 mgmt
->u
.action
.u
.sa_query_resp
.trans_id
);
3609 static int robust_action_frame(u8 category
)
3611 return category
!= WLAN_ACTION_PUBLIC
&&
3612 category
!= WLAN_ACTION_HT
;
3614 #endif /* CONFIG_IEEE80211W */
3617 static int handle_action(struct hostapd_data
*hapd
,
3618 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3621 struct sta_info
*sta
;
3622 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3624 if (len
< IEEE80211_HDRLEN
+ 1) {
3625 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3626 HOSTAPD_LEVEL_DEBUG
,
3627 "handle_action - too short payload (len=%lu)",
3628 (unsigned long) len
);
3632 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
3633 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
3634 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
3635 "frame (category=%u) from unassociated STA " MACSTR
,
3636 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
3640 #ifdef CONFIG_IEEE80211W
3641 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
3642 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
3643 robust_action_frame(mgmt
->u
.action
.category
)) {
3644 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3645 HOSTAPD_LEVEL_DEBUG
,
3646 "Dropped unprotected Robust Action frame from "
3650 #endif /* CONFIG_IEEE80211W */
3653 u16 fc
= le_to_host16(mgmt
->frame_control
);
3654 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3656 if ((fc
& WLAN_FC_RETRY
) &&
3657 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3658 sta
->last_seq_ctrl
== seq_ctrl
&&
3659 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
3660 hostapd_logger(hapd
, sta
->addr
,
3661 HOSTAPD_MODULE_IEEE80211
,
3662 HOSTAPD_LEVEL_DEBUG
,
3663 "Drop repeated action frame seq_ctrl=0x%x",
3668 sta
->last_seq_ctrl
= seq_ctrl
;
3669 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
3672 switch (mgmt
->u
.action
.category
) {
3673 #ifdef CONFIG_IEEE80211R_AP
3674 case WLAN_ACTION_FT
:
3676 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
3677 len
- IEEE80211_HDRLEN
))
3680 #endif /* CONFIG_IEEE80211R_AP */
3681 case WLAN_ACTION_WMM
:
3682 hostapd_wmm_action(hapd
, mgmt
, len
);
3684 #ifdef CONFIG_IEEE80211W
3685 case WLAN_ACTION_SA_QUERY
:
3686 return hostapd_sa_query_action(hapd
, mgmt
, len
);
3687 #endif /* CONFIG_IEEE80211W */
3688 #ifdef CONFIG_WNM_AP
3689 case WLAN_ACTION_WNM
:
3690 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
3692 #endif /* CONFIG_WNM_AP */
3694 case WLAN_ACTION_FST
:
3695 if (hapd
->iface
->fst
)
3696 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
3698 wpa_printf(MSG_DEBUG
,
3699 "FST: Ignore FST Action frame - no FST attached");
3701 #endif /* CONFIG_FST */
3702 case WLAN_ACTION_PUBLIC
:
3703 case WLAN_ACTION_PROTECTED_DUAL
:
3704 #ifdef CONFIG_IEEE80211N
3705 if (len
>= IEEE80211_HDRLEN
+ 2 &&
3706 mgmt
->u
.action
.u
.public_action
.action
==
3707 WLAN_PA_20_40_BSS_COEX
) {
3708 wpa_printf(MSG_DEBUG
,
3709 "HT20/40 coex mgmt frame received from STA "
3710 MACSTR
, MAC2STR(mgmt
->sa
));
3711 hostapd_2040_coex_action(hapd
, mgmt
, len
);
3714 #endif /* CONFIG_IEEE80211N */
3716 if (len
>= IEEE80211_HDRLEN
+ 6 &&
3717 mgmt
->u
.action
.u
.vs_public_action
.action
==
3718 WLAN_PA_VENDOR_SPECIFIC
&&
3719 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
3721 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
3723 const u8
*pos
, *end
;
3725 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
3726 end
= ((const u8
*) mgmt
) + len
;
3727 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
3731 if (len
>= IEEE80211_HDRLEN
+ 2 &&
3732 (mgmt
->u
.action
.u
.public_action
.action
==
3733 WLAN_PA_GAS_INITIAL_RESP
||
3734 mgmt
->u
.action
.u
.public_action
.action
==
3735 WLAN_PA_GAS_COMEBACK_RESP
)) {
3736 const u8
*pos
, *end
;
3738 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
3739 end
= ((const u8
*) mgmt
) + len
;
3740 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
3741 mgmt
->u
.action
.category
,
3742 pos
, end
- pos
, hapd
->iface
->freq
);
3745 #endif /* CONFIG_DPP */
3746 if (hapd
->public_action_cb
) {
3747 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
3751 if (hapd
->public_action_cb2
) {
3752 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
3756 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
3759 case WLAN_ACTION_VENDOR_SPECIFIC
:
3760 if (hapd
->vendor_action_cb
) {
3761 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
3763 hapd
->iface
->freq
) == 0)
3767 case WLAN_ACTION_RADIO_MEASUREMENT
:
3768 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
3772 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3773 HOSTAPD_LEVEL_DEBUG
,
3774 "handle_action - unknown action category %d or invalid "
3776 mgmt
->u
.action
.category
);
3777 if (!is_multicast_ether_addr(mgmt
->da
) &&
3778 !(mgmt
->u
.action
.category
& 0x80) &&
3779 !is_multicast_ether_addr(mgmt
->sa
)) {
3780 struct ieee80211_mgmt
*resp
;
3783 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
3784 * Return the Action frame to the source without change
3785 * except that MSB of the Category set to 1.
3787 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
3788 "frame back to sender");
3789 resp
= os_memdup(mgmt
, len
);
3792 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
3793 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
3794 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3795 resp
->u
.action
.category
|= 0x80;
3797 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
3798 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
3809 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
3810 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
3812 * @buf: management frame data (starting from IEEE 802.11 header)
3813 * @len: length of frame data in octets
3814 * @fi: meta data about received frame (signal level, etc.)
3816 * Process all incoming IEEE 802.11 management frames. This will be called for
3817 * each frame received from the kernel driver through wlan#ap interface. In
3818 * addition, it can be called to re-inserted pending frames (e.g., when using
3819 * external RADIUS server as an MAC ACL).
3821 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
3822 struct hostapd_frame_info
*fi
)
3824 struct ieee80211_mgmt
*mgmt
;
3835 freq
= hapd
->iface
->freq
;
3837 mgmt
= (struct ieee80211_mgmt
*) buf
;
3838 fc
= le_to_host16(mgmt
->frame_control
);
3839 stype
= WLAN_FC_GET_STYPE(fc
);
3841 if (stype
== WLAN_FC_STYPE_BEACON
) {
3842 handle_beacon(hapd
, mgmt
, len
, fi
);
3846 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
3848 /* Invitation responses can be sent with the peer MAC as BSSID */
3849 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
3850 stype
== WLAN_FC_STYPE_ACTION
) &&
3851 #endif /* CONFIG_P2P */
3853 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
3854 #endif /* CONFIG_MESH */
3855 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
3856 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
3857 MAC2STR(mgmt
->bssid
));
3862 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
3863 handle_probe_req(hapd
, mgmt
, len
, fi
->ssi_signal
);
3867 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
3868 stype
!= WLAN_FC_STYPE_ACTION
) &&
3869 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
3870 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3871 HOSTAPD_LEVEL_DEBUG
,
3872 "MGMT: DA=" MACSTR
" not our address",
3877 if (hapd
->iconf
->track_sta_max_num
)
3878 sta_track_add(hapd
->iface
, mgmt
->sa
, fi
->ssi_signal
);
3881 case WLAN_FC_STYPE_AUTH
:
3882 wpa_printf(MSG_DEBUG
, "mgmt::auth");
3883 handle_auth(hapd
, mgmt
, len
);
3886 case WLAN_FC_STYPE_ASSOC_REQ
:
3887 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
3888 handle_assoc(hapd
, mgmt
, len
, 0);
3891 case WLAN_FC_STYPE_REASSOC_REQ
:
3892 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
3893 handle_assoc(hapd
, mgmt
, len
, 1);
3896 case WLAN_FC_STYPE_DISASSOC
:
3897 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
3898 handle_disassoc(hapd
, mgmt
, len
);
3901 case WLAN_FC_STYPE_DEAUTH
:
3902 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
3903 handle_deauth(hapd
, mgmt
, len
);
3906 case WLAN_FC_STYPE_ACTION
:
3907 wpa_printf(MSG_DEBUG
, "mgmt::action");
3908 ret
= handle_action(hapd
, mgmt
, len
, freq
);
3911 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3912 HOSTAPD_LEVEL_DEBUG
,
3913 "unknown mgmt frame subtype %d", stype
);
3921 static void handle_auth_cb(struct hostapd_data
*hapd
,
3922 const struct ieee80211_mgmt
*mgmt
,
3925 u16 auth_alg
, auth_transaction
, status_code
;
3926 struct sta_info
*sta
;
3928 sta
= ap_get_sta(hapd
, mgmt
->da
);
3930 wpa_printf(MSG_INFO
, "handle_auth_cb: STA " MACSTR
" not found",
3935 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3936 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3937 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
3940 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
3941 HOSTAPD_LEVEL_NOTICE
,
3942 "did not acknowledge authentication response");
3946 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
3947 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
3948 (unsigned long) len
);
3952 if (status_code
== WLAN_STATUS_SUCCESS
&&
3953 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
3954 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
3955 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3956 HOSTAPD_LEVEL_INFO
, "authenticated");
3957 sta
->flags
|= WLAN_STA_AUTH
;
3958 if (sta
->added_unassoc
)
3959 hostapd_set_sta_flags(hapd
, sta
);
3964 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
3965 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3966 sta
->added_unassoc
= 0;
3971 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
3972 struct sta_info
*sta
,
3976 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
3978 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
3981 for (i
= 0; i
< 4; i
++) {
3982 if (ssid
->wep
.key
[i
] &&
3983 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
3984 i
== ssid
->wep
.idx
, NULL
, 0,
3985 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
3986 wpa_printf(MSG_WARNING
,
3987 "Could not set WEP keys for WDS interface; %s",
3995 static void handle_assoc_cb(struct hostapd_data
*hapd
,
3996 const struct ieee80211_mgmt
*mgmt
,
3997 size_t len
, int reassoc
, int ok
)
4000 struct sta_info
*sta
;
4003 sta
= ap_get_sta(hapd
, mgmt
->da
);
4005 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
4010 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
4011 sizeof(mgmt
->u
.assoc_resp
))) {
4012 wpa_printf(MSG_INFO
,
4013 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4014 reassoc
, (unsigned long) len
);
4015 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4020 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
4022 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
4025 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
4026 HOSTAPD_LEVEL_DEBUG
,
4027 "did not acknowledge association response");
4028 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
4029 /* The STA is added only in case of SUCCESS */
4030 if (status
== WLAN_STATUS_SUCCESS
)
4031 hostapd_drv_sta_remove(hapd
, sta
->addr
);
4036 if (status
!= WLAN_STATUS_SUCCESS
)
4039 /* Stop previous accounting session, if one is started, and allocate
4040 * new session id for the new session. */
4041 accounting_sta_stop(hapd
, sta
);
4043 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
4045 "associated (aid %d)",
4048 if (sta
->flags
& WLAN_STA_ASSOC
)
4050 sta
->flags
|= WLAN_STA_ASSOC
;
4051 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
4052 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
4053 !hapd
->conf
->osen
) ||
4054 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4055 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4056 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
4057 sta
->auth_alg
== WLAN_AUTH_FT
) {
4059 * Open, static WEP, FT protocol, or FILS; no separate
4060 * authorization step.
4062 ap_sta_set_authorized(hapd
, sta
, 1);
4066 mlme_reassociate_indication(hapd
, sta
);
4068 mlme_associate_indication(hapd
, sta
);
4070 #ifdef CONFIG_IEEE80211W
4071 sta
->sa_query_timed_out
= 0;
4072 #endif /* CONFIG_IEEE80211W */
4074 if (sta
->eapol_sm
== NULL
) {
4076 * This STA does not use RADIUS server for EAP authentication,
4077 * so bind it to the selected VLAN interface now, since the
4078 * interface selection is not going to change anymore.
4080 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4082 } else if (sta
->vlan_id
) {
4083 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4084 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4088 hostapd_set_sta_flags(hapd
, sta
);
4090 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4091 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4092 MACSTR
" based on pending request",
4093 MAC2STR(sta
->addr
));
4094 sta
->pending_wds_enable
= 0;
4095 sta
->flags
|= WLAN_STA_WDS
;
4098 if (sta
->flags
& WLAN_STA_WDS
) {
4100 char ifname_wds
[IFNAMSIZ
+ 1];
4102 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4104 MAC2STR(sta
->addr
), sta
->aid
);
4105 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
4108 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
4111 if (sta
->auth_alg
== WLAN_AUTH_FT
)
4112 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
4114 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
4115 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
4116 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
4119 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4120 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4121 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
4122 fils_set_tk(sta
->wpa_sm
) < 0) {
4123 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
4124 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
4125 WLAN_REASON_UNSPECIFIED
);
4128 #endif /* CONFIG_FILS */
4130 if (sta
->pending_eapol_rx
) {
4131 struct os_reltime now
, age
;
4133 os_get_reltime(&now
);
4134 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
4135 if (age
.sec
== 0 && age
.usec
< 200000) {
4136 wpa_printf(MSG_DEBUG
,
4137 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
4138 MAC2STR(sta
->addr
));
4141 wpabuf_head(sta
->pending_eapol_rx
->buf
),
4142 wpabuf_len(sta
->pending_eapol_rx
->buf
));
4144 wpabuf_free(sta
->pending_eapol_rx
->buf
);
4145 os_free(sta
->pending_eapol_rx
);
4146 sta
->pending_eapol_rx
= NULL
;
4151 static void handle_deauth_cb(struct hostapd_data
*hapd
,
4152 const struct ieee80211_mgmt
*mgmt
,
4155 struct sta_info
*sta
;
4156 if (is_multicast_ether_addr(mgmt
->da
))
4158 sta
= ap_get_sta(hapd
, mgmt
->da
);
4160 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
4161 " not found", MAC2STR(mgmt
->da
));
4165 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
4166 MAC2STR(sta
->addr
));
4168 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4169 "deauth", MAC2STR(sta
->addr
));
4171 ap_sta_deauth_cb(hapd
, sta
);
4175 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
4176 const struct ieee80211_mgmt
*mgmt
,
4179 struct sta_info
*sta
;
4180 if (is_multicast_ether_addr(mgmt
->da
))
4182 sta
= ap_get_sta(hapd
, mgmt
->da
);
4184 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
4185 " not found", MAC2STR(mgmt
->da
));
4189 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
4190 MAC2STR(sta
->addr
));
4192 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4193 "disassoc", MAC2STR(sta
->addr
));
4195 ap_sta_disassoc_cb(hapd
, sta
);
4199 static void handle_action_cb(struct hostapd_data
*hapd
,
4200 const struct ieee80211_mgmt
*mgmt
,
4203 struct sta_info
*sta
;
4204 const struct rrm_measurement_report_element
*report
;
4206 if (is_multicast_ether_addr(mgmt
->da
))
4209 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4210 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4211 mgmt
->u
.action
.u
.vs_public_action
.action
==
4212 WLAN_PA_VENDOR_SPECIFIC
&&
4213 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4215 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4217 const u8
*pos
, *end
;
4219 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
4220 end
= ((const u8
*) mgmt
) + len
;
4221 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
4224 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4225 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4226 (mgmt
->u
.action
.u
.public_action
.action
==
4227 WLAN_PA_GAS_INITIAL_REQ
||
4228 mgmt
->u
.action
.u
.public_action
.action
==
4229 WLAN_PA_GAS_COMEBACK_REQ
)) {
4230 const u8
*pos
, *end
;
4232 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
4233 end
= ((const u8
*) mgmt
) + len
;
4234 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
4237 #endif /* CONFIG_DPP */
4238 sta
= ap_get_sta(hapd
, mgmt
->da
);
4240 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
4241 " not found", MAC2STR(mgmt
->da
));
4245 if (len
< 24 + 5 + sizeof(*report
))
4247 report
= (const struct rrm_measurement_report_element
*)
4248 &mgmt
->u
.action
.u
.rrm
.variable
[2];
4249 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4250 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
4251 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
4253 report
->type
== MEASURE_TYPE_BEACON
)
4254 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
4259 * ieee802_11_mgmt_cb - Process management frame TX status callback
4260 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4262 * @buf: management frame data (starting from IEEE 802.11 header)
4263 * @len: length of frame data in octets
4264 * @stype: management frame subtype from frame control field
4265 * @ok: Whether the frame was ACK'ed
4267 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4270 const struct ieee80211_mgmt
*mgmt
;
4271 mgmt
= (const struct ieee80211_mgmt
*) buf
;
4273 #ifdef CONFIG_TESTING_OPTIONS
4274 if (hapd
->ext_mgmt_frame_handling
) {
4275 size_t hex_len
= 2 * len
+ 1;
4276 char *hex
= os_malloc(hex_len
);
4279 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
4280 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
4281 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4287 #endif /* CONFIG_TESTING_OPTIONS */
4290 case WLAN_FC_STYPE_AUTH
:
4291 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
4292 handle_auth_cb(hapd
, mgmt
, len
, ok
);
4294 case WLAN_FC_STYPE_ASSOC_RESP
:
4295 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
4296 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
4298 case WLAN_FC_STYPE_REASSOC_RESP
:
4299 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
4300 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
4302 case WLAN_FC_STYPE_PROBE_RESP
:
4303 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
4305 case WLAN_FC_STYPE_DEAUTH
:
4306 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
4307 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
4309 case WLAN_FC_STYPE_DISASSOC
:
4310 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
4311 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
4313 case WLAN_FC_STYPE_ACTION
:
4314 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
4315 handle_action_cb(hapd
, mgmt
, len
, ok
);
4318 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
4324 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
4331 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
4332 char *buf
, size_t buflen
)
4339 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
4340 const u8
*buf
, size_t len
, int ack
)
4342 struct sta_info
*sta
;
4343 struct hostapd_iface
*iface
= hapd
->iface
;
4345 sta
= ap_get_sta(hapd
, addr
);
4346 if (sta
== NULL
&& iface
->num_bss
> 1) {
4348 for (j
= 0; j
< iface
->num_bss
; j
++) {
4349 hapd
= iface
->bss
[j
];
4350 sta
= ap_get_sta(hapd
, addr
);
4355 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
4357 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
4358 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
4359 "activity poll", MAC2STR(sta
->addr
),
4360 ack
? "ACKed" : "did not ACK");
4362 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4365 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
4369 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
4370 const u8
*data
, size_t len
, int ack
)
4372 struct sta_info
*sta
;
4373 struct hostapd_iface
*iface
= hapd
->iface
;
4375 sta
= ap_get_sta(hapd
, dst
);
4376 if (sta
== NULL
&& iface
->num_bss
> 1) {
4378 for (j
= 0; j
< iface
->num_bss
; j
++) {
4379 hapd
= iface
->bss
[j
];
4380 sta
= ap_get_sta(hapd
, dst
);
4385 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
4386 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
4387 MACSTR
" that is not currently associated",
4392 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
4396 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
4398 struct sta_info
*sta
;
4399 struct hostapd_iface
*iface
= hapd
->iface
;
4401 sta
= ap_get_sta(hapd
, addr
);
4402 if (sta
== NULL
&& iface
->num_bss
> 1) {
4404 for (j
= 0; j
< iface
->num_bss
; j
++) {
4405 hapd
= iface
->bss
[j
];
4406 sta
= ap_get_sta(hapd
, addr
);
4413 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
4414 MAC2STR(sta
->addr
));
4415 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
4418 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
4419 "activity poll", MAC2STR(sta
->addr
));
4420 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4424 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
4427 struct sta_info
*sta
;
4429 sta
= ap_get_sta(hapd
, src
);
4431 ((sta
->flags
& WLAN_STA_ASSOC
) ||
4432 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
4433 if (!hapd
->conf
->wds_sta
)
4436 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
4437 WLAN_STA_ASSOC_REQ_OK
) {
4438 wpa_printf(MSG_DEBUG
,
4439 "Postpone 4-address WDS mode enabling for STA "
4440 MACSTR
" since TX status for AssocResp is not yet known",
4441 MAC2STR(sta
->addr
));
4442 sta
->pending_wds_enable
= 1;
4446 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
4448 char ifname_wds
[IFNAMSIZ
+ 1];
4450 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
4451 "STA " MACSTR
" (aid %u)",
4452 MAC2STR(sta
->addr
), sta
->aid
);
4453 sta
->flags
|= WLAN_STA_WDS
;
4454 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
4455 sta
->addr
, sta
->aid
, 1);
4457 hostapd_set_wds_encryption(hapd
, sta
,
4463 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
4464 MACSTR
, MAC2STR(src
));
4465 if (is_multicast_ether_addr(src
)) {
4466 /* Broadcast bit set in SA?! Ignore the frame silently. */
4470 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
4471 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
4472 "already been sent, but no TX status yet known - "
4473 "ignore Class 3 frame issue with " MACSTR
,
4478 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
4479 hostapd_drv_sta_disassoc(
4481 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
4483 hostapd_drv_sta_deauth(
4485 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
4489 #endif /* CONFIG_NATIVE_WINDOWS */