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 #define dot11RSNASAESync 5 /* attempts */
360 static struct wpabuf
* auth_build_sae_commit(struct hostapd_data
*hapd
,
361 struct sta_info
*sta
, int update
)
364 const char *password
;
366 password
= hapd
->conf
->sae_password
;
368 password
= hapd
->conf
->ssid
.wpa_passphrase
;
370 wpa_printf(MSG_DEBUG
, "SAE: No password available");
375 sae_prepare_commit(hapd
->own_addr
, sta
->addr
,
376 (u8
*) password
, os_strlen(password
),
378 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
382 buf
= wpabuf_alloc(SAE_COMMIT_MAX_LEN
);
385 sae_write_commit(sta
->sae
, buf
, sta
->sae
->tmp
?
386 sta
->sae
->tmp
->anti_clogging_token
: NULL
);
392 static struct wpabuf
* auth_build_sae_confirm(struct hostapd_data
*hapd
,
393 struct sta_info
*sta
)
397 buf
= wpabuf_alloc(SAE_CONFIRM_MAX_LEN
);
401 sae_write_confirm(sta
->sae
, buf
);
407 static int auth_sae_send_commit(struct hostapd_data
*hapd
,
408 struct sta_info
*sta
,
409 const u8
*bssid
, int update
)
414 data
= auth_build_sae_commit(hapd
, sta
, update
);
416 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
418 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 1,
419 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
428 static int auth_sae_send_confirm(struct hostapd_data
*hapd
,
429 struct sta_info
*sta
,
435 data
= auth_build_sae_confirm(hapd
, sta
);
437 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
439 reply_res
= send_auth_reply(hapd
, sta
->addr
, bssid
, WLAN_AUTH_SAE
, 2,
440 WLAN_STATUS_SUCCESS
, wpabuf_head(data
),
449 static int use_sae_anti_clogging(struct hostapd_data
*hapd
)
451 struct sta_info
*sta
;
452 unsigned int open
= 0;
454 if (hapd
->conf
->sae_anti_clogging_threshold
== 0)
457 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
460 if (sta
->sae
->state
!= SAE_COMMITTED
&&
461 sta
->sae
->state
!= SAE_CONFIRMED
)
464 if (open
>= hapd
->conf
->sae_anti_clogging_threshold
)
472 static int check_sae_token(struct hostapd_data
*hapd
, const u8
*addr
,
473 const u8
*token
, size_t token_len
)
475 u8 mac
[SHA256_MAC_LEN
];
477 if (token_len
!= SHA256_MAC_LEN
)
479 if (hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
480 addr
, ETH_ALEN
, mac
) < 0 ||
481 os_memcmp_const(token
, mac
, SHA256_MAC_LEN
) != 0)
488 static struct wpabuf
* auth_build_token_req(struct hostapd_data
*hapd
,
489 int group
, const u8
*addr
)
493 struct os_reltime now
;
495 os_get_reltime(&now
);
496 if (!os_reltime_initialized(&hapd
->last_sae_token_key_update
) ||
497 os_reltime_expired(&now
, &hapd
->last_sae_token_key_update
, 60)) {
498 if (random_get_bytes(hapd
->sae_token_key
,
499 sizeof(hapd
->sae_token_key
)) < 0)
501 wpa_hexdump(MSG_DEBUG
, "SAE: Updated token key",
502 hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
));
503 hapd
->last_sae_token_key_update
= now
;
506 buf
= wpabuf_alloc(sizeof(le16
) + SHA256_MAC_LEN
);
510 wpabuf_put_le16(buf
, group
); /* Finite Cyclic Group */
512 token
= wpabuf_put(buf
, SHA256_MAC_LEN
);
513 hmac_sha256(hapd
->sae_token_key
, sizeof(hapd
->sae_token_key
),
514 addr
, ETH_ALEN
, token
);
520 static int sae_check_big_sync(struct sta_info
*sta
)
522 if (sta
->sae
->sync
> dot11RSNASAESync
) {
523 sta
->sae
->state
= SAE_NOTHING
;
531 static void auth_sae_retransmit_timer(void *eloop_ctx
, void *eloop_data
)
533 struct hostapd_data
*hapd
= eloop_ctx
;
534 struct sta_info
*sta
= eloop_data
;
537 if (sae_check_big_sync(sta
))
540 wpa_printf(MSG_DEBUG
, "SAE: Auth SAE retransmit timer for " MACSTR
541 " (sync=%d state=%d)",
542 MAC2STR(sta
->addr
), sta
->sae
->sync
, sta
->sae
->state
);
544 switch (sta
->sae
->state
) {
546 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
547 eloop_register_timeout(0,
548 hapd
->dot11RSNASAERetransPeriod
* 1000,
549 auth_sae_retransmit_timer
, hapd
, sta
);
552 ret
= auth_sae_send_confirm(hapd
, sta
, hapd
->own_addr
);
553 eloop_register_timeout(0,
554 hapd
->dot11RSNASAERetransPeriod
* 1000,
555 auth_sae_retransmit_timer
, hapd
, sta
);
562 if (ret
!= WLAN_STATUS_SUCCESS
)
563 wpa_printf(MSG_INFO
, "SAE: Failed to retransmit: ret=%d", ret
);
567 void sae_clear_retransmit_timer(struct hostapd_data
*hapd
, struct sta_info
*sta
)
569 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
573 static void sae_set_retransmit_timer(struct hostapd_data
*hapd
,
574 struct sta_info
*sta
)
576 if (!(hapd
->conf
->mesh
& MESH_ENABLED
))
579 eloop_cancel_timeout(auth_sae_retransmit_timer
, hapd
, sta
);
580 eloop_register_timeout(0, hapd
->dot11RSNASAERetransPeriod
* 1000,
581 auth_sae_retransmit_timer
, hapd
, sta
);
585 void sae_accept_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
587 sta
->flags
|= WLAN_STA_AUTH
;
588 sta
->auth_alg
= WLAN_AUTH_SAE
;
589 mlme_authenticate_indication(hapd
, sta
);
590 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
591 sta
->sae
->state
= SAE_ACCEPTED
;
592 wpa_auth_pmksa_add_sae(hapd
->wpa_auth
, sta
->addr
,
593 sta
->sae
->pmk
, sta
->sae
->pmkid
);
597 static int sae_sm_step(struct hostapd_data
*hapd
, struct sta_info
*sta
,
598 const u8
*bssid
, u8 auth_transaction
)
602 if (auth_transaction
!= 1 && auth_transaction
!= 2)
603 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
605 switch (sta
->sae
->state
) {
607 if (auth_transaction
== 1) {
608 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
611 sta
->sae
->state
= SAE_COMMITTED
;
613 if (sae_process_commit(sta
->sae
) < 0)
614 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
617 * In mesh case, both Commit and Confirm can be sent
618 * immediately. In infrastructure BSS, only a single
619 * Authentication frame (Commit) is expected from the AP
620 * here and the second one (Confirm) will be sent once
621 * the STA has sent its second Authentication frame
624 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
626 * Send both Commit and Confirm immediately
627 * based on SAE finite state machine
628 * Nothing -> Confirm transition.
630 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
633 sta
->sae
->state
= SAE_CONFIRMED
;
636 * For infrastructure BSS, send only the Commit
637 * message now to get alternating sequence of
638 * Authentication frames between the AP and STA.
639 * Confirm will be sent in
640 * Committed -> Confirmed/Accepted transition
641 * when receiving Confirm from STA.
645 sae_set_retransmit_timer(hapd
, sta
);
647 hostapd_logger(hapd
, sta
->addr
,
648 HOSTAPD_MODULE_IEEE80211
,
650 "SAE confirm before commit");
654 sae_clear_retransmit_timer(hapd
, sta
);
655 if (auth_transaction
== 1) {
656 if (sae_process_commit(sta
->sae
) < 0)
657 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
659 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
662 sta
->sae
->state
= SAE_CONFIRMED
;
664 sae_set_retransmit_timer(hapd
, sta
);
665 } else if (hapd
->conf
->mesh
& MESH_ENABLED
) {
667 * In mesh case, follow SAE finite state machine and
668 * send Commit now, if sync count allows.
670 if (sae_check_big_sync(sta
))
671 return WLAN_STATUS_SUCCESS
;
674 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 0);
678 sae_set_retransmit_timer(hapd
, sta
);
681 * For instructure BSS, send the postponed Confirm from
682 * Nothing -> Confirmed transition that was reduced to
683 * Nothing -> Committed above.
685 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
689 sta
->sae
->state
= SAE_CONFIRMED
;
692 * Since this was triggered on Confirm RX, run another
693 * step to get to Accepted without waiting for
696 return sae_sm_step(hapd
, sta
, bssid
, auth_transaction
);
700 sae_clear_retransmit_timer(hapd
, sta
);
701 if (auth_transaction
== 1) {
702 if (sae_check_big_sync(sta
))
703 return WLAN_STATUS_SUCCESS
;
706 ret
= auth_sae_send_commit(hapd
, sta
, bssid
, 1);
710 if (sae_process_commit(sta
->sae
) < 0)
711 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
713 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
717 sae_set_retransmit_timer(hapd
, sta
);
719 sae_accept_sta(hapd
, sta
);
723 if (auth_transaction
== 1) {
724 wpa_printf(MSG_DEBUG
, "SAE: remove the STA (" MACSTR
725 ") doing reauthentication",
727 ap_free_sta(hapd
, sta
);
728 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
730 if (sae_check_big_sync(sta
))
731 return WLAN_STATUS_SUCCESS
;
734 ret
= auth_sae_send_confirm(hapd
, sta
, bssid
);
735 sae_clear_temp_data(sta
->sae
);
741 wpa_printf(MSG_ERROR
, "SAE: invalid state %d",
743 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
745 return WLAN_STATUS_SUCCESS
;
749 static void sae_pick_next_group(struct hostapd_data
*hapd
, struct sta_info
*sta
)
751 struct sae_data
*sae
= sta
->sae
;
752 int i
, *groups
= hapd
->conf
->sae_groups
;
754 if (sae
->state
!= SAE_COMMITTED
)
757 wpa_printf(MSG_DEBUG
, "SAE: Previously selected group: %d", sae
->group
);
759 for (i
= 0; groups
&& groups
[i
] > 0; i
++) {
760 if (sae
->group
== groups
[i
])
764 if (!groups
|| groups
[i
] <= 0) {
765 wpa_printf(MSG_DEBUG
,
766 "SAE: Previously selected group not found from the current configuration");
772 if (groups
[i
] <= 0) {
773 wpa_printf(MSG_DEBUG
,
774 "SAE: No alternative group enabled");
778 if (sae_set_group(sae
, groups
[i
]) < 0)
783 wpa_printf(MSG_DEBUG
, "SAE: Selected new group: %d", groups
[i
]);
787 static void handle_auth_sae(struct hostapd_data
*hapd
, struct sta_info
*sta
,
788 const struct ieee80211_mgmt
*mgmt
, size_t len
,
789 u16 auth_transaction
, u16 status_code
)
791 int resp
= WLAN_STATUS_SUCCESS
;
792 struct wpabuf
*data
= NULL
;
794 #ifdef CONFIG_TESTING_OPTIONS
795 if (hapd
->conf
->sae_reflection_attack
&& auth_transaction
== 1) {
798 wpa_printf(MSG_DEBUG
, "SAE: TESTING - reflection attack");
799 pos
= mgmt
->u
.auth
.variable
;
800 end
= ((const u8
*) mgmt
) + len
;
801 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
802 auth_transaction
, resp
, pos
, end
- pos
);
806 if (hapd
->conf
->sae_commit_override
&& auth_transaction
== 1) {
807 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
808 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
809 auth_transaction
, resp
,
810 wpabuf_head(hapd
->conf
->sae_commit_override
),
811 wpabuf_len(hapd
->conf
->sae_commit_override
));
814 #endif /* CONFIG_TESTING_OPTIONS */
816 if (auth_transaction
!= 1 ||
817 status_code
!= WLAN_STATUS_SUCCESS
) {
821 sta
->sae
= os_zalloc(sizeof(*sta
->sae
));
826 sta
->sae
->state
= SAE_NOTHING
;
830 if (sta
->mesh_sae_pmksa_caching
) {
831 wpa_printf(MSG_DEBUG
,
832 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
833 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
834 sta
->mesh_sae_pmksa_caching
= 0;
837 if (auth_transaction
== 1) {
838 const u8
*token
= NULL
, *pos
, *end
;
839 size_t token_len
= 0;
840 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
842 "start SAE authentication (RX commit, status=%u)",
845 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
846 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
848 pos
= mgmt
->u
.auth
.variable
;
849 end
= ((const u8
*) mgmt
) + len
;
850 if (pos
+ sizeof(le16
) > end
) {
851 wpa_printf(MSG_ERROR
,
852 "SAE: Too short anti-clogging token request");
853 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
856 resp
= sae_group_allowed(sta
->sae
,
857 hapd
->conf
->sae_groups
,
859 if (resp
!= WLAN_STATUS_SUCCESS
) {
860 wpa_printf(MSG_ERROR
,
861 "SAE: Invalid group in anti-clogging token request");
866 wpabuf_free(sta
->sae
->tmp
->anti_clogging_token
);
867 sta
->sae
->tmp
->anti_clogging_token
=
868 wpabuf_alloc_copy(pos
, end
- pos
);
869 if (sta
->sae
->tmp
->anti_clogging_token
== NULL
) {
870 wpa_printf(MSG_ERROR
,
871 "SAE: Failed to alloc for anti-clogging token");
872 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
877 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
878 * is 76, a new Commit Message shall be constructed
879 * with the Anti-Clogging Token from the received
880 * Authentication frame, and the commit-scalar and
881 * COMMIT-ELEMENT previously sent.
883 resp
= auth_sae_send_commit(hapd
, sta
, mgmt
->bssid
, 0);
884 if (resp
!= WLAN_STATUS_SUCCESS
) {
885 wpa_printf(MSG_ERROR
,
886 "SAE: Failed to send commit message");
889 sta
->sae
->state
= SAE_COMMITTED
;
891 sae_set_retransmit_timer(hapd
, sta
);
895 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
897 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
899 wpa_printf(MSG_DEBUG
,
900 "SAE: Peer did not accept our SAE group");
901 sae_pick_next_group(hapd
, sta
);
905 if (status_code
!= WLAN_STATUS_SUCCESS
)
908 resp
= sae_parse_commit(sta
->sae
, mgmt
->u
.auth
.variable
,
909 ((const u8
*) mgmt
) + len
-
910 mgmt
->u
.auth
.variable
, &token
,
911 &token_len
, hapd
->conf
->sae_groups
);
912 if (resp
== SAE_SILENTLY_DISCARD
) {
913 wpa_printf(MSG_DEBUG
,
914 "SAE: Drop commit message from " MACSTR
" due to reflection attack",
918 if (token
&& check_sae_token(hapd
, sta
->addr
, token
, token_len
)
920 wpa_printf(MSG_DEBUG
, "SAE: Drop commit message with "
921 "incorrect token from " MACSTR
,
923 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
927 if (resp
!= WLAN_STATUS_SUCCESS
)
930 if (!token
&& use_sae_anti_clogging(hapd
)) {
931 wpa_printf(MSG_DEBUG
,
932 "SAE: Request anti-clogging token from "
933 MACSTR
, MAC2STR(sta
->addr
));
934 data
= auth_build_token_req(hapd
, sta
->sae
->group
,
936 resp
= WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
;
937 if (hapd
->conf
->mesh
& MESH_ENABLED
)
938 sta
->sae
->state
= SAE_NOTHING
;
942 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
);
943 } else if (auth_transaction
== 2) {
944 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
946 "SAE authentication (RX confirm, status=%u)",
948 if (status_code
!= WLAN_STATUS_SUCCESS
)
950 if (sta
->sae
->state
>= SAE_CONFIRMED
||
951 !(hapd
->conf
->mesh
& MESH_ENABLED
)) {
952 if (sae_check_confirm(sta
->sae
, mgmt
->u
.auth
.variable
,
953 ((u8
*) mgmt
) + len
-
954 mgmt
->u
.auth
.variable
) < 0) {
955 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
959 resp
= sae_sm_step(hapd
, sta
, mgmt
->bssid
, auth_transaction
);
961 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
963 "unexpected SAE authentication transaction %u (status=%u)",
964 auth_transaction
, status_code
);
965 if (status_code
!= WLAN_STATUS_SUCCESS
)
967 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
971 if (resp
!= WLAN_STATUS_SUCCESS
) {
972 send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, WLAN_AUTH_SAE
,
973 auth_transaction
, resp
,
974 data
? wpabuf_head(data
) : (u8
*) "",
975 data
? wpabuf_len(data
) : 0);
979 if (sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
980 status_code
!= WLAN_STATUS_SUCCESS
)) {
981 hostapd_drv_sta_remove(hapd
, sta
->addr
);
982 sta
->added_unassoc
= 0;
989 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
990 * @hapd: BSS data for the device initiating the authentication
991 * @sta: the peer to which commit authentication frame is sent
993 * This function implements Init event handling (IEEE Std 802.11-2012,
994 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
995 * sta->sae structure should be initialized appropriately via a call to
996 * sae_prepare_commit().
998 int auth_sae_init_committed(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1002 if (!sta
->sae
|| !sta
->sae
->tmp
)
1005 if (sta
->sae
->state
!= SAE_NOTHING
)
1008 ret
= auth_sae_send_commit(hapd
, sta
, hapd
->own_addr
, 0);
1012 sta
->sae
->state
= SAE_COMMITTED
;
1014 sae_set_retransmit_timer(hapd
, sta
);
1019 #endif /* CONFIG_SAE */
1022 static u16
wpa_res_to_status_code(int res
)
1024 if (res
== WPA_INVALID_GROUP
)
1025 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
1026 if (res
== WPA_INVALID_PAIRWISE
)
1027 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
1028 if (res
== WPA_INVALID_AKMP
)
1029 return WLAN_STATUS_AKMP_NOT_VALID
;
1030 if (res
== WPA_ALLOC_FAIL
)
1031 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1032 #ifdef CONFIG_IEEE80211W
1033 if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
)
1034 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1035 if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
)
1036 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION
;
1037 #endif /* CONFIG_IEEE80211W */
1038 if (res
== WPA_INVALID_MDIE
)
1039 return WLAN_STATUS_INVALID_MDIE
;
1040 if (res
== WPA_INVALID_PMKID
)
1041 return WLAN_STATUS_INVALID_PMKID
;
1042 if (res
!= WPA_IE_OK
)
1043 return WLAN_STATUS_INVALID_IE
;
1044 return WLAN_STATUS_SUCCESS
;
1050 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1051 struct sta_info
*sta
, u16 resp
,
1052 struct wpabuf
*data
, int pub
);
1054 void handle_auth_fils(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1055 const u8
*pos
, size_t len
, u16 auth_alg
,
1056 u16 auth_transaction
, u16 status_code
,
1057 void (*cb
)(struct hostapd_data
*hapd
,
1058 struct sta_info
*sta
, u16 resp
,
1059 struct wpabuf
*data
, int pub
))
1061 u16 resp
= WLAN_STATUS_SUCCESS
;
1063 struct ieee802_11_elems elems
;
1065 struct wpa_ie_data rsn
;
1066 struct rsn_pmksa_cache_entry
*pmksa
= NULL
;
1068 if (auth_transaction
!= 1 || status_code
!= WLAN_STATUS_SUCCESS
)
1073 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
1077 #ifdef CONFIG_FILS_SK_PFS
1078 if (auth_alg
== WLAN_AUTH_FILS_SK_PFS
) {
1083 /* Using FILS PFS */
1085 /* Finite Cyclic Group */
1086 if (end
- pos
< 2) {
1087 wpa_printf(MSG_DEBUG
,
1088 "FILS: No room for Finite Cyclic Group");
1089 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1092 group
= WPA_GET_LE16(pos
);
1094 if (group
!= hapd
->conf
->fils_dh_group
) {
1095 wpa_printf(MSG_DEBUG
,
1096 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1097 group
, hapd
->conf
->fils_dh_group
);
1098 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1102 crypto_ecdh_deinit(sta
->fils_ecdh
);
1103 sta
->fils_ecdh
= crypto_ecdh_init(group
);
1104 if (!sta
->fils_ecdh
) {
1105 wpa_printf(MSG_INFO
,
1106 "FILS: Could not initialize ECDH with group %d",
1108 resp
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
1112 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1114 wpa_printf(MSG_DEBUG
,
1115 "FILS: Failed to derive ECDH public key");
1116 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1119 elem_len
= wpabuf_len(pub
);
1123 if ((size_t) (end
- pos
) < elem_len
) {
1124 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
1125 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1129 wpabuf_free(sta
->fils_g_sta
);
1130 sta
->fils_g_sta
= wpabuf_alloc_copy(pos
, elem_len
);
1131 wpabuf_clear_free(sta
->fils_dh_ss
);
1132 sta
->fils_dh_ss
= crypto_ecdh_set_peerkey(sta
->fils_ecdh
, 1,
1134 if (!sta
->fils_dh_ss
) {
1135 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
1136 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1139 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", sta
->fils_dh_ss
);
1142 crypto_ecdh_deinit(sta
->fils_ecdh
);
1143 sta
->fils_ecdh
= NULL
;
1144 wpabuf_clear_free(sta
->fils_dh_ss
);
1145 sta
->fils_dh_ss
= NULL
;
1147 #endif /* CONFIG_FILS_SK_PFS */
1149 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
1150 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
1151 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
1152 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1157 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element",
1158 elems
.rsn_ie
, elems
.rsn_ie_len
);
1159 if (!elems
.rsn_ie
||
1160 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1162 wpa_printf(MSG_DEBUG
, "FILS: No valid RSN element");
1163 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1168 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
,
1171 wpa_printf(MSG_DEBUG
,
1172 "FILS: Failed to initialize RSN state machine");
1173 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1177 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
1178 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
1179 elems
.mdie
, elems
.mdie_len
, NULL
, 0);
1180 resp
= wpa_res_to_status_code(res
);
1181 if (resp
!= WLAN_STATUS_SUCCESS
)
1184 if (!elems
.fils_nonce
) {
1185 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
1186 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1189 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce", elems
.fils_nonce
,
1191 os_memcpy(sta
->fils_snonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
1194 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
1198 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
1199 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
1202 num
= rsn
.num_pmkid
;
1204 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", pmkid
, PMKID_LEN
);
1205 pmksa
= wpa_auth_pmksa_get(hapd
->wpa_auth
, sta
->addr
,
1209 pmksa
= wpa_auth_pmksa_get_fils_cache_id(hapd
->wpa_auth
,
1218 if (pmksa
&& wpa_auth_sta_key_mgmt(sta
->wpa_sm
) != pmksa
->akmp
) {
1219 wpa_printf(MSG_DEBUG
,
1220 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1221 wpa_auth_sta_key_mgmt(sta
->wpa_sm
), pmksa
->akmp
);
1225 wpa_printf(MSG_DEBUG
, "FILS: Found matching PMKSA cache entry");
1228 if (!elems
.fils_session
) {
1229 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
1230 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1233 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
1235 os_memcpy(sta
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
);
1237 /* FILS Wrapped Data */
1238 if (elems
.fils_wrapped_data
) {
1239 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
1240 elems
.fils_wrapped_data
,
1241 elems
.fils_wrapped_data_len
);
1243 #ifndef CONFIG_NO_RADIUS
1244 if (!sta
->eapol_sm
) {
1246 ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1248 wpa_printf(MSG_DEBUG
,
1249 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1250 ieee802_1x_encapsulate_radius(
1251 hapd
, sta
, elems
.fils_wrapped_data
,
1252 elems
.fils_wrapped_data_len
);
1253 sta
->fils_pending_cb
= cb
;
1254 wpa_printf(MSG_DEBUG
,
1255 "FILS: Will send Authentication frame once the response from authentication server is available");
1256 sta
->flags
|= WLAN_STA_PENDING_FILS_ERP
;
1257 /* Calculate pending PMKID here so that we do not need
1258 * to maintain a copy of the EAP-Initiate/Reauth
1260 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1261 elems
.fils_wrapped_data
,
1262 elems
.fils_wrapped_data_len
,
1263 sta
->fils_erp_pmkid
) == 0)
1264 sta
->fils_erp_pmkid_set
= 1;
1266 #else /* CONFIG_NO_RADIUS */
1267 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1269 #endif /* CONFIG_NO_RADIUS */
1275 struct wpabuf
*data
;
1278 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, pmksa
, NULL
,
1281 wpa_printf(MSG_DEBUG
,
1282 "%s: prepare_auth_resp_fils() returned failure",
1286 cb(hapd
, sta
, resp
, data
, pub
);
1291 static struct wpabuf
*
1292 prepare_auth_resp_fils(struct hostapd_data
*hapd
,
1293 struct sta_info
*sta
, u16
*resp
,
1294 struct rsn_pmksa_cache_entry
*pmksa
,
1295 struct wpabuf
*erp_resp
,
1296 const u8
*msk
, size_t msk_len
,
1299 u8 fils_nonce
[FILS_NONCE_LEN
];
1301 struct wpabuf
*data
= NULL
;
1304 const u8
*pmk
= NULL
;
1306 u8 pmk_buf
[PMK_LEN_MAX
];
1307 struct wpabuf
*pub
= NULL
;
1309 if (*resp
!= WLAN_STATUS_SUCCESS
)
1312 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
1314 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1319 /* Add PMKID of the selected PMKSA into RSNE */
1320 ie_buf
= os_malloc(ielen
+ 2 + 2 + PMKID_LEN
);
1322 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1326 os_memcpy(ie_buf
, ie
, ielen
);
1327 if (wpa_insert_pmkid(ie_buf
, &ielen
, pmksa
->pmkid
) < 0) {
1328 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1334 if (random_get_bytes(fils_nonce
, FILS_NONCE_LEN
) < 0) {
1335 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1338 wpa_hexdump(MSG_DEBUG
, "RSN: Generated FILS Nonce",
1339 fils_nonce
, FILS_NONCE_LEN
);
1341 #ifdef CONFIG_FILS_SK_PFS
1342 if (sta
->fils_dh_ss
&& sta
->fils_ecdh
) {
1343 pub
= crypto_ecdh_get_pubkey(sta
->fils_ecdh
, 1);
1345 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1349 #endif /* CONFIG_FILS_SK_PFS */
1351 data
= wpabuf_alloc(1000 + ielen
+ (pub
? wpabuf_len(pub
) : 0));
1353 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1358 #ifdef CONFIG_FILS_SK_PFS
1360 /* Finite Cyclic Group */
1361 wpabuf_put_le16(data
, hapd
->conf
->fils_dh_group
);
1364 wpabuf_put_buf(data
, pub
);
1366 #endif /* CONFIG_FILS_SK_PFS */
1369 wpabuf_put_data(data
, ie
, ielen
);
1371 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1373 #ifdef CONFIG_IEEE80211R_AP
1374 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) {
1375 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1378 res
= wpa_auth_write_fte(hapd
->wpa_auth
, wpabuf_put(data
, 0),
1379 wpabuf_tailroom(data
));
1381 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1384 wpabuf_put(data
, res
);
1386 #endif /* CONFIG_IEEE80211R_AP */
1389 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1390 wpabuf_put_u8(data
, 1 + FILS_NONCE_LEN
); /* Length */
1391 /* Element ID Extension */
1392 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_NONCE
);
1393 wpabuf_put_data(data
, fils_nonce
, FILS_NONCE_LEN
);
1396 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1397 wpabuf_put_u8(data
, 1 + FILS_SESSION_LEN
); /* Length */
1398 /* Element ID Extension */
1399 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_SESSION
);
1400 wpabuf_put_data(data
, sta
->fils_session
, FILS_SESSION_LEN
);
1402 /* FILS Wrapped Data */
1403 if (!pmksa
&& erp_resp
) {
1404 wpabuf_put_u8(data
, WLAN_EID_EXTENSION
); /* Element ID */
1405 wpabuf_put_u8(data
, 1 + wpabuf_len(erp_resp
)); /* Length */
1406 /* Element ID Extension */
1407 wpabuf_put_u8(data
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
1408 wpabuf_put_buf(data
, erp_resp
);
1410 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
),
1411 msk
, msk_len
, sta
->fils_snonce
, fils_nonce
,
1413 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1415 wpabuf_len(sta
->fils_dh_ss
) : 0,
1416 pmk_buf
, &pmk_len
)) {
1417 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PMK");
1418 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1425 /* Don't use DHss in PTK derivation if PMKSA caching is not
1427 wpabuf_clear_free(sta
->fils_dh_ss
);
1428 sta
->fils_dh_ss
= NULL
;
1430 if (sta
->fils_erp_pmkid_set
) {
1431 /* TODO: get PMKLifetime from WPA parameters */
1432 unsigned int dot11RSNAConfigPMKLifetime
= 43200;
1434 sta
->fils_erp_pmkid_set
= 0;
1435 if (wpa_auth_pmksa_add2(
1436 hapd
->wpa_auth
, sta
->addr
,
1438 sta
->fils_erp_pmkid
,
1439 sta
->session_timeout_set
?
1440 sta
->session_timeout
:
1441 dot11RSNAConfigPMKLifetime
,
1442 wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) < 0) {
1443 wpa_printf(MSG_ERROR
,
1444 "FILS: Failed to add PMKSA cache entry based on ERP");
1449 pmk_len
= pmksa
->pmk_len
;
1453 wpa_printf(MSG_DEBUG
, "FILS: No PMK available");
1454 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1460 if (fils_auth_pmk_to_ptk(sta
->wpa_sm
, pmk
, pmk_len
,
1461 sta
->fils_snonce
, fils_nonce
,
1463 wpabuf_head(sta
->fils_dh_ss
) : NULL
,
1465 wpabuf_len(sta
->fils_dh_ss
) : 0,
1466 sta
->fils_g_sta
, pub
) < 0) {
1467 *resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1475 *is_pub
= pub
!= NULL
;
1478 wpabuf_clear_free(sta
->fils_dh_ss
);
1479 sta
->fils_dh_ss
= NULL
;
1480 #ifdef CONFIG_FILS_SK_PFS
1481 crypto_ecdh_deinit(sta
->fils_ecdh
);
1482 sta
->fils_ecdh
= NULL
;
1483 #endif /* CONFIG_FILS_SK_PFS */
1488 static void handle_auth_fils_finish(struct hostapd_data
*hapd
,
1489 struct sta_info
*sta
, u16 resp
,
1490 struct wpabuf
*data
, int pub
)
1495 resp
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) ?
1496 WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1497 send_auth_reply(hapd
, sta
->addr
, hapd
->own_addr
, auth_alg
, 2, resp
,
1498 data
? wpabuf_head(data
) : (u8
*) "",
1499 data
? wpabuf_len(data
) : 0);
1502 if (resp
== WLAN_STATUS_SUCCESS
) {
1503 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1504 HOSTAPD_LEVEL_DEBUG
,
1505 "authentication OK (FILS)");
1506 sta
->flags
|= WLAN_STA_AUTH
;
1507 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1508 sta
->auth_alg
= pub
? WLAN_AUTH_FILS_SK_PFS
: WLAN_AUTH_FILS_SK
;
1509 mlme_authenticate_indication(hapd
, sta
);
1514 void ieee802_11_finish_fils_auth(struct hostapd_data
*hapd
,
1515 struct sta_info
*sta
, int success
,
1516 struct wpabuf
*erp_resp
,
1517 const u8
*msk
, size_t msk_len
)
1519 struct wpabuf
*data
;
1523 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1525 if (!sta
->fils_pending_cb
)
1527 resp
= success
? WLAN_STATUS_SUCCESS
: WLAN_STATUS_UNSPECIFIED_FAILURE
;
1528 data
= prepare_auth_resp_fils(hapd
, sta
, &resp
, NULL
, erp_resp
,
1529 msk
, msk_len
, &pub
);
1531 wpa_printf(MSG_DEBUG
,
1532 "%s: prepare_auth_resp_fils() returned failure",
1535 sta
->fils_pending_cb(hapd
, sta
, resp
, data
, pub
);
1538 #endif /* CONFIG_FILS */
1542 ieee802_11_allowed_address(struct hostapd_data
*hapd
, const u8
*addr
,
1543 const u8
*msg
, size_t len
, u32
*session_timeout
,
1544 u32
*acct_interim_interval
,
1545 struct vlan_description
*vlan_id
,
1546 struct hostapd_sta_wpa_psk_short
**psk
,
1547 char **identity
, char **radius_cui
)
1551 os_memset(vlan_id
, 0, sizeof(*vlan_id
));
1552 res
= hostapd_allowed_address(hapd
, addr
, msg
, len
,
1553 session_timeout
, acct_interim_interval
,
1554 vlan_id
, psk
, identity
, radius_cui
);
1556 if (res
== HOSTAPD_ACL_REJECT
) {
1557 wpa_printf(MSG_INFO
,
1558 "Station " MACSTR
" not allowed to authenticate",
1560 return HOSTAPD_ACL_REJECT
;
1563 if (res
== HOSTAPD_ACL_PENDING
) {
1564 wpa_printf(MSG_DEBUG
, "Authentication frame from " MACSTR
1565 " waiting for an external authentication",
1567 /* Authentication code will re-send the authentication frame
1568 * after it has received (and cached) information from the
1569 * external source. */
1570 return HOSTAPD_ACL_PENDING
;
1578 ieee802_11_set_radius_info(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1579 int res
, u32 session_timeout
,
1580 u32 acct_interim_interval
,
1581 struct vlan_description
*vlan_id
,
1582 struct hostapd_sta_wpa_psk_short
**psk
,
1583 char **identity
, char **radius_cui
)
1585 if (vlan_id
->notempty
&&
1586 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan_id
)) {
1587 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1589 "Invalid VLAN %d%s received from RADIUS server",
1591 vlan_id
->tagged
[0] ? "+" : "");
1594 if (ap_sta_set_vlan(hapd
, sta
, vlan_id
) < 0)
1597 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1598 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
1600 hostapd_free_psk_list(sta
->psk
);
1601 if (hapd
->conf
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
) {
1608 sta
->identity
= *identity
;
1610 sta
->radius_cui
= *radius_cui
;
1613 if (hapd
->conf
->acct_interim_interval
== 0 && acct_interim_interval
)
1614 sta
->acct_interim_interval
= acct_interim_interval
;
1615 if (res
== HOSTAPD_ACL_ACCEPT_TIMEOUT
)
1616 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1618 ap_sta_no_session_timeout(hapd
, sta
);
1624 static void handle_auth(struct hostapd_data
*hapd
,
1625 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1627 u16 auth_alg
, auth_transaction
, status_code
;
1628 u16 resp
= WLAN_STATUS_SUCCESS
;
1629 struct sta_info
*sta
= NULL
;
1632 const u8
*challenge
= NULL
;
1633 u32 session_timeout
, acct_interim_interval
;
1634 struct vlan_description vlan_id
;
1635 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
1636 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
1637 size_t resp_ies_len
= 0;
1638 char *identity
= NULL
;
1639 char *radius_cui
= NULL
;
1642 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
1643 wpa_printf(MSG_INFO
, "handle_auth - too short payload (len=%lu)",
1644 (unsigned long) len
);
1648 #ifdef CONFIG_TESTING_OPTIONS
1649 if (hapd
->iconf
->ignore_auth_probability
> 0.0 &&
1650 drand48() < hapd
->iconf
->ignore_auth_probability
) {
1651 wpa_printf(MSG_INFO
,
1652 "TESTING: ignoring auth frame from " MACSTR
,
1656 #endif /* CONFIG_TESTING_OPTIONS */
1658 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1659 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1660 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1661 fc
= le_to_host16(mgmt
->frame_control
);
1662 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
1664 if (len
>= IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
) +
1665 2 + WLAN_AUTH_CHALLENGE_LEN
&&
1666 mgmt
->u
.auth
.variable
[0] == WLAN_EID_CHALLENGE
&&
1667 mgmt
->u
.auth
.variable
[1] == WLAN_AUTH_CHALLENGE_LEN
)
1668 challenge
= &mgmt
->u
.auth
.variable
[2];
1670 wpa_printf(MSG_DEBUG
, "authentication: STA=" MACSTR
" auth_alg=%d "
1671 "auth_transaction=%d status_code=%d wep=%d%s "
1673 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
,
1674 status_code
, !!(fc
& WLAN_FC_ISWEP
),
1675 challenge
? " challenge" : "",
1676 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
1678 #ifdef CONFIG_NO_RC4
1679 if (auth_alg
== WLAN_AUTH_SHARED_KEY
) {
1680 wpa_printf(MSG_INFO
,
1681 "Unsupported authentication algorithm (%d)",
1683 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1686 #endif /* CONFIG_NO_RC4 */
1688 if (hapd
->tkip_countermeasures
) {
1689 resp
= WLAN_REASON_MICHAEL_MIC_FAILURE
;
1693 if (!(((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_OPEN
) &&
1694 auth_alg
== WLAN_AUTH_OPEN
) ||
1695 #ifdef CONFIG_IEEE80211R_AP
1696 (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
1697 auth_alg
== WLAN_AUTH_FT
) ||
1698 #endif /* CONFIG_IEEE80211R_AP */
1700 (hapd
->conf
->wpa
&& wpa_key_mgmt_sae(hapd
->conf
->wpa_key_mgmt
) &&
1701 auth_alg
== WLAN_AUTH_SAE
) ||
1702 #endif /* CONFIG_SAE */
1704 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
1705 auth_alg
== WLAN_AUTH_FILS_SK
) ||
1706 (hapd
->conf
->wpa
&& wpa_key_mgmt_fils(hapd
->conf
->wpa_key_mgmt
) &&
1707 hapd
->conf
->fils_dh_group
&&
1708 auth_alg
== WLAN_AUTH_FILS_SK_PFS
) ||
1709 #endif /* CONFIG_FILS */
1710 ((hapd
->conf
->auth_algs
& WPA_AUTH_ALG_SHARED
) &&
1711 auth_alg
== WLAN_AUTH_SHARED_KEY
))) {
1712 wpa_printf(MSG_INFO
, "Unsupported authentication algorithm (%d)",
1714 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1718 if (!(auth_transaction
== 1 || auth_alg
== WLAN_AUTH_SAE
||
1719 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 3))) {
1720 wpa_printf(MSG_INFO
, "Unknown authentication transaction number (%d)",
1722 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1726 if (os_memcmp(mgmt
->sa
, hapd
->own_addr
, ETH_ALEN
) == 0) {
1727 wpa_printf(MSG_INFO
, "Station " MACSTR
" not allowed to authenticate",
1729 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1733 if (hapd
->conf
->no_auth_if_seen_on
) {
1734 struct hostapd_data
*other
;
1736 other
= sta_track_seen_on(hapd
->iface
, mgmt
->sa
,
1737 hapd
->conf
->no_auth_if_seen_on
);
1741 u8 op_class
, channel
, phytype
;
1743 wpa_printf(MSG_DEBUG
, "%s: Reject authentication from "
1744 MACSTR
" since STA has been seen on %s",
1745 hapd
->conf
->iface
, MAC2STR(mgmt
->sa
),
1746 hapd
->conf
->no_auth_if_seen_on
);
1748 resp
= WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION
;
1750 *pos
++ = WLAN_EID_NEIGHBOR_REPORT
;
1752 os_memcpy(pos
, other
->own_addr
, ETH_ALEN
);
1754 info
= 0; /* TODO: BSSID Information */
1755 WPA_PUT_LE32(pos
, info
);
1757 if (other
->iconf
->hw_mode
== HOSTAPD_MODE_IEEE80211AD
)
1758 phytype
= 8; /* dmg */
1759 else if (other
->iconf
->ieee80211ac
)
1760 phytype
= 9; /* vht */
1761 else if (other
->iconf
->ieee80211n
)
1762 phytype
= 7; /* ht */
1763 else if (other
->iconf
->hw_mode
==
1764 HOSTAPD_MODE_IEEE80211A
)
1765 phytype
= 4; /* ofdm */
1766 else if (other
->iconf
->hw_mode
==
1767 HOSTAPD_MODE_IEEE80211G
)
1768 phytype
= 6; /* erp */
1770 phytype
= 5; /* hrdsss */
1771 if (ieee80211_freq_to_channel_ext(
1772 hostapd_hw_get_freq(other
,
1773 other
->iconf
->channel
),
1774 other
->iconf
->secondary_channel
,
1775 other
->iconf
->ieee80211ac
,
1776 &op_class
, &channel
) == NUM_HOSTAPD_MODES
) {
1778 channel
= other
->iconf
->channel
;
1783 resp_ies_len
= pos
- &resp_ies
[0];
1788 res
= ieee802_11_allowed_address(
1789 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
, &session_timeout
,
1790 &acct_interim_interval
, &vlan_id
, &psk
, &identity
, &radius_cui
);
1791 if (res
== HOSTAPD_ACL_REJECT
) {
1792 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1795 if (res
== HOSTAPD_ACL_PENDING
)
1798 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1800 sta
->flags
&= ~WLAN_STA_PENDING_FILS_ERP
;
1801 if ((fc
& WLAN_FC_RETRY
) &&
1802 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
1803 sta
->last_seq_ctrl
== seq_ctrl
&&
1804 sta
->last_subtype
== WLAN_FC_STYPE_AUTH
) {
1805 hostapd_logger(hapd
, sta
->addr
,
1806 HOSTAPD_MODULE_IEEE80211
,
1807 HOSTAPD_LEVEL_DEBUG
,
1808 "Drop repeated authentication frame seq_ctrl=0x%x",
1813 if ((hapd
->conf
->mesh
& MESH_ENABLED
) &&
1814 sta
->plink_state
== PLINK_BLOCKED
) {
1815 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
1816 " is blocked - drop Authentication frame",
1820 #endif /* CONFIG_MESH */
1823 if (hapd
->conf
->mesh
& MESH_ENABLED
) {
1824 /* if the mesh peer is not available, we don't do auth.
1826 wpa_printf(MSG_DEBUG
, "Mesh peer " MACSTR
1827 " not yet known - drop Authentication frame",
1830 * Save a copy of the frame so that it can be processed
1831 * if a new peer entry is added shortly after this.
1833 wpabuf_free(hapd
->mesh_pending_auth
);
1834 hapd
->mesh_pending_auth
= wpabuf_alloc_copy(mgmt
, len
);
1835 os_get_reltime(&hapd
->mesh_pending_auth_time
);
1838 #endif /* CONFIG_MESH */
1840 sta
= ap_sta_add(hapd
, mgmt
->sa
);
1842 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1846 sta
->last_seq_ctrl
= seq_ctrl
;
1847 sta
->last_subtype
= WLAN_FC_STYPE_AUTH
;
1849 res
= ieee802_11_set_radius_info(
1850 hapd
, sta
, res
, session_timeout
, acct_interim_interval
,
1851 &vlan_id
, &psk
, &identity
, &radius_cui
);
1853 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1857 sta
->flags
&= ~WLAN_STA_PREAUTH
;
1858 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
1861 * If the driver supports full AP client state, add a station to the
1862 * driver before sending authentication reply to make sure the driver
1863 * has resources, and not to go through the entire authentication and
1864 * association handshake, and fail it at the end.
1866 * If this is not the first transaction, in a multi-step authentication
1867 * algorithm, the station already exists in the driver
1868 * (sta->added_unassoc = 1) so skip it.
1870 * In mesh mode, the station was already added to the driver when the
1871 * NEW_PEER_CANDIDATE event is received.
1873 * If PMF was negotiated for the existing association, skip this to
1874 * avoid dropping the STA entry and the associated keys. This is needed
1875 * to allow the original connection work until the attempt can complete
1876 * (re)association, so that unprotected Authentication frame cannot be
1877 * used to bypass PMF protection.
1879 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
1880 (!(sta
->flags
& WLAN_STA_MFP
) || !ap_sta_is_authorized(sta
)) &&
1881 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
1882 !(sta
->added_unassoc
)) {
1884 * If a station that is already associated to the AP, is trying
1885 * to authenticate again, remove the STA entry, in order to make
1886 * sure the STA PS state gets cleared and configuration gets
1887 * updated. To handle this, station's added_unassoc flag is
1888 * cleared once the station has completed association.
1890 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1891 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_AUTH
|
1892 WLAN_STA_AUTHORIZED
);
1894 if (hostapd_sta_add(hapd
, sta
->addr
, 0, 0, NULL
, 0, 0,
1895 NULL
, NULL
, sta
->flags
, 0, 0, 0, 0)) {
1896 hostapd_logger(hapd
, sta
->addr
,
1897 HOSTAPD_MODULE_IEEE80211
,
1898 HOSTAPD_LEVEL_NOTICE
,
1899 "Could not add STA to kernel driver");
1900 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1904 sta
->added_unassoc
= 1;
1908 case WLAN_AUTH_OPEN
:
1909 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1910 HOSTAPD_LEVEL_DEBUG
,
1911 "authentication OK (open system)");
1912 sta
->flags
|= WLAN_STA_AUTH
;
1913 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1914 sta
->auth_alg
= WLAN_AUTH_OPEN
;
1915 mlme_authenticate_indication(hapd
, sta
);
1917 #ifndef CONFIG_NO_RC4
1918 case WLAN_AUTH_SHARED_KEY
:
1919 resp
= auth_shared_key(hapd
, sta
, auth_transaction
, challenge
,
1920 fc
& WLAN_FC_ISWEP
);
1921 sta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
1922 mlme_authenticate_indication(hapd
, sta
);
1923 if (sta
->challenge
&& auth_transaction
== 1) {
1924 resp_ies
[0] = WLAN_EID_CHALLENGE
;
1925 resp_ies
[1] = WLAN_AUTH_CHALLENGE_LEN
;
1926 os_memcpy(resp_ies
+ 2, sta
->challenge
,
1927 WLAN_AUTH_CHALLENGE_LEN
);
1928 resp_ies_len
= 2 + WLAN_AUTH_CHALLENGE_LEN
;
1931 #endif /* CONFIG_NO_RC4 */
1932 #ifdef CONFIG_IEEE80211R_AP
1934 sta
->auth_alg
= WLAN_AUTH_FT
;
1935 if (sta
->wpa_sm
== NULL
)
1936 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
1938 if (sta
->wpa_sm
== NULL
) {
1939 wpa_printf(MSG_DEBUG
, "FT: Failed to initialize WPA "
1941 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1944 wpa_ft_process_auth(sta
->wpa_sm
, mgmt
->bssid
,
1945 auth_transaction
, mgmt
->u
.auth
.variable
,
1946 len
- IEEE80211_HDRLEN
-
1947 sizeof(mgmt
->u
.auth
),
1948 handle_auth_ft_finish
, hapd
);
1949 /* handle_auth_ft_finish() callback will complete auth. */
1951 #endif /* CONFIG_IEEE80211R_AP */
1955 if (status_code
== WLAN_STATUS_SUCCESS
&&
1956 hapd
->conf
->mesh
& MESH_ENABLED
) {
1957 if (sta
->wpa_sm
== NULL
)
1959 wpa_auth_sta_init(hapd
->wpa_auth
,
1961 if (sta
->wpa_sm
== NULL
) {
1962 wpa_printf(MSG_DEBUG
,
1963 "SAE: Failed to initialize WPA state machine");
1964 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1968 #endif /* CONFIG_MESH */
1969 handle_auth_sae(hapd
, sta
, mgmt
, len
, auth_transaction
,
1972 #endif /* CONFIG_SAE */
1974 case WLAN_AUTH_FILS_SK
:
1975 case WLAN_AUTH_FILS_SK_PFS
:
1976 handle_auth_fils(hapd
, sta
, mgmt
->u
.auth
.variable
,
1977 len
- IEEE80211_HDRLEN
- sizeof(mgmt
->u
.auth
),
1978 auth_alg
, auth_transaction
, status_code
,
1979 handle_auth_fils_finish
);
1981 #endif /* CONFIG_FILS */
1986 os_free(radius_cui
);
1987 hostapd_free_psk_list(psk
);
1989 reply_res
= send_auth_reply(hapd
, mgmt
->sa
, mgmt
->bssid
, auth_alg
,
1990 auth_transaction
+ 1, resp
, resp_ies
,
1993 if (sta
&& sta
->added_unassoc
&& (resp
!= WLAN_STATUS_SUCCESS
||
1994 reply_res
!= WLAN_STATUS_SUCCESS
)) {
1995 hostapd_drv_sta_remove(hapd
, sta
->addr
);
1996 sta
->added_unassoc
= 0;
2001 int hostapd_get_aid(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2005 /* get a unique AID */
2007 wpa_printf(MSG_DEBUG
, " old AID %d", sta
->aid
);
2014 for (i
= 0; i
< AID_WORDS
; i
++) {
2015 if (hapd
->sta_aid
[i
] == (u32
) -1)
2017 for (j
= 0; j
< 32; j
++) {
2018 if (!(hapd
->sta_aid
[i
] & BIT(j
)))
2026 aid
= i
* 32 + j
+ 1;
2031 hapd
->sta_aid
[i
] |= BIT(j
);
2032 wpa_printf(MSG_DEBUG
, " new AID %d", sta
->aid
);
2037 static u16
check_ssid(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2038 const u8
*ssid_ie
, size_t ssid_ie_len
)
2040 if (ssid_ie
== NULL
)
2041 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2043 if (ssid_ie_len
!= hapd
->conf
->ssid
.ssid_len
||
2044 os_memcmp(ssid_ie
, hapd
->conf
->ssid
.ssid
, ssid_ie_len
) != 0) {
2045 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2047 "Station tried to associate with unknown SSID "
2048 "'%s'", wpa_ssid_txt(ssid_ie
, ssid_ie_len
));
2049 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2052 return WLAN_STATUS_SUCCESS
;
2056 static u16
check_wmm(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2057 const u8
*wmm_ie
, size_t wmm_ie_len
)
2059 sta
->flags
&= ~WLAN_STA_WMM
;
2061 if (wmm_ie
&& hapd
->conf
->wmm_enabled
) {
2062 struct wmm_information_element
*wmm
;
2064 if (!hostapd_eid_wmm_valid(hapd
, wmm_ie
, wmm_ie_len
)) {
2065 hostapd_logger(hapd
, sta
->addr
,
2067 HOSTAPD_LEVEL_DEBUG
,
2068 "invalid WMM element in association "
2070 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2073 sta
->flags
|= WLAN_STA_WMM
;
2074 wmm
= (struct wmm_information_element
*) wmm_ie
;
2075 sta
->qosinfo
= wmm
->qos_info
;
2077 return WLAN_STATUS_SUCCESS
;
2081 static u16
copy_supp_rates(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2082 struct ieee802_11_elems
*elems
)
2084 /* Supported rates not used in IEEE 802.11ad/DMG */
2085 if (hapd
->iface
->current_mode
&&
2086 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
)
2087 return WLAN_STATUS_SUCCESS
;
2089 if (!elems
->supp_rates
) {
2090 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2091 HOSTAPD_LEVEL_DEBUG
,
2092 "No supported rates element in AssocReq");
2093 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2096 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
2097 sizeof(sta
->supported_rates
)) {
2098 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2099 HOSTAPD_LEVEL_DEBUG
,
2100 "Invalid supported rates element length %d+%d",
2101 elems
->supp_rates_len
,
2102 elems
->ext_supp_rates_len
);
2103 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2106 sta
->supported_rates_len
= merge_byte_arrays(
2107 sta
->supported_rates
, sizeof(sta
->supported_rates
),
2108 elems
->supp_rates
, elems
->supp_rates_len
,
2109 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
2111 return WLAN_STATUS_SUCCESS
;
2115 static u16
check_ext_capab(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2116 const u8
*ext_capab_ie
, size_t ext_capab_ie_len
)
2118 #ifdef CONFIG_INTERWORKING
2119 /* check for QoS Map support */
2120 if (ext_capab_ie_len
>= 5) {
2121 if (ext_capab_ie
[4] & 0x01)
2122 sta
->qos_map_enabled
= 1;
2124 #endif /* CONFIG_INTERWORKING */
2126 if (ext_capab_ie_len
> 0) {
2127 sta
->ecsa_supported
= !!(ext_capab_ie
[0] & BIT(2));
2128 os_free(sta
->ext_capability
);
2129 sta
->ext_capability
= os_malloc(1 + ext_capab_ie_len
);
2130 if (sta
->ext_capability
) {
2131 sta
->ext_capability
[0] = ext_capab_ie_len
;
2132 os_memcpy(sta
->ext_capability
+ 1, ext_capab_ie
,
2137 return WLAN_STATUS_SUCCESS
;
2143 static int owe_group_supported(struct hostapd_data
*hapd
, u16 group
)
2146 int *groups
= hapd
->conf
->owe_groups
;
2148 if (group
!= 19 && group
!= 20 && group
!= 21)
2154 for (i
= 0; groups
[i
] > 0; i
++) {
2155 if (groups
[i
] == group
)
2163 static u16
owe_process_assoc_req(struct hostapd_data
*hapd
,
2164 struct sta_info
*sta
, const u8
*owe_dh
,
2167 struct wpabuf
*secret
, *pub
, *hkey
;
2169 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
2170 const char *info
= "OWE Key Generation";
2174 size_t hash_len
, prime_len
;
2176 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
)) {
2177 wpa_printf(MSG_DEBUG
, "OWE: Using PMKSA caching");
2178 return WLAN_STATUS_SUCCESS
;
2181 group
= WPA_GET_LE16(owe_dh
);
2182 if (!owe_group_supported(hapd
, group
)) {
2183 wpa_printf(MSG_DEBUG
, "OWE: Unsupported DH group %u", group
);
2184 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2188 else if (group
== 20)
2190 else if (group
== 21)
2193 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2195 crypto_ecdh_deinit(sta
->owe_ecdh
);
2196 sta
->owe_ecdh
= crypto_ecdh_init(group
);
2198 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
2199 sta
->owe_group
= group
;
2201 secret
= crypto_ecdh_set_peerkey(sta
->owe_ecdh
, 0, owe_dh
+ 2,
2203 secret
= wpabuf_zeropad(secret
, prime_len
);
2205 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
2206 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2208 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
2210 /* prk = HKDF-extract(C | A | group, z) */
2212 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2214 wpabuf_clear_free(secret
);
2215 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2218 /* PMKID = Truncate-128(Hash(C | A)) */
2219 addr
[0] = owe_dh
+ 2;
2220 len
[0] = owe_dh_len
- 2;
2221 addr
[1] = wpabuf_head(pub
);
2222 len
[1] = wpabuf_len(pub
);
2224 res
= sha256_vector(2, addr
, len
, pmkid
);
2225 hash_len
= SHA256_MAC_LEN
;
2226 } else if (group
== 20) {
2227 res
= sha384_vector(2, addr
, len
, pmkid
);
2228 hash_len
= SHA384_MAC_LEN
;
2229 } else if (group
== 21) {
2230 res
= sha512_vector(2, addr
, len
, pmkid
);
2231 hash_len
= SHA512_MAC_LEN
;
2234 wpabuf_clear_free(secret
);
2235 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2237 pub
= wpabuf_zeropad(pub
, prime_len
);
2238 if (res
< 0 || !pub
) {
2240 wpabuf_clear_free(secret
);
2241 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2244 hkey
= wpabuf_alloc(owe_dh_len
- 2 + wpabuf_len(pub
) + 2);
2247 wpabuf_clear_free(secret
);
2248 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2251 wpabuf_put_data(hkey
, owe_dh
+ 2, owe_dh_len
- 2); /* C */
2252 wpabuf_put_buf(hkey
, pub
); /* A */
2254 wpabuf_put_le16(hkey
, group
); /* group */
2256 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
2257 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2258 else if (group
== 20)
2259 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
2260 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2261 else if (group
== 21)
2262 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
2263 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
2264 wpabuf_clear_free(hkey
);
2265 wpabuf_clear_free(secret
);
2267 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2269 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
2271 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2273 os_free(sta
->owe_pmk
);
2274 sta
->owe_pmk
= os_malloc(hash_len
);
2275 if (!sta
->owe_pmk
) {
2276 os_memset(prk
, 0, SHA512_MAC_LEN
);
2277 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2281 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2282 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2283 else if (group
== 20)
2284 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2285 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2286 else if (group
== 21)
2287 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
2288 os_strlen(info
), sta
->owe_pmk
, hash_len
);
2289 os_memset(prk
, 0, SHA512_MAC_LEN
);
2291 os_free(sta
->owe_pmk
);
2292 sta
->owe_pmk
= NULL
;
2293 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2295 sta
->owe_pmk_len
= hash_len
;
2297 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sta
->owe_pmk
, sta
->owe_pmk_len
);
2298 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
2299 wpa_auth_pmksa_add2(hapd
->wpa_auth
, sta
->addr
, sta
->owe_pmk
,
2300 sta
->owe_pmk_len
, pmkid
, 0, WPA_KEY_MGMT_OWE
);
2302 return WLAN_STATUS_SUCCESS
;
2305 #endif /* CONFIG_OWE */
2308 static u16
check_assoc_ies(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2309 const u8
*ies
, size_t ies_len
, int reassoc
)
2311 struct ieee802_11_elems elems
;
2315 const u8
*p2p_dev_addr
= NULL
;
2317 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2318 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2319 HOSTAPD_LEVEL_INFO
, "Station sent an invalid "
2320 "association request");
2321 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2324 resp
= check_ssid(hapd
, sta
, elems
.ssid
, elems
.ssid_len
);
2325 if (resp
!= WLAN_STATUS_SUCCESS
)
2327 resp
= check_wmm(hapd
, sta
, elems
.wmm
, elems
.wmm_len
);
2328 if (resp
!= WLAN_STATUS_SUCCESS
)
2330 resp
= check_ext_capab(hapd
, sta
, elems
.ext_capab
, elems
.ext_capab_len
);
2331 if (resp
!= WLAN_STATUS_SUCCESS
)
2333 resp
= copy_supp_rates(hapd
, sta
, &elems
);
2334 if (resp
!= WLAN_STATUS_SUCCESS
)
2336 #ifdef CONFIG_IEEE80211N
2337 resp
= copy_sta_ht_capab(hapd
, sta
, elems
.ht_capabilities
);
2338 if (resp
!= WLAN_STATUS_SUCCESS
)
2340 if (hapd
->iconf
->ieee80211n
&& hapd
->iconf
->require_ht
&&
2341 !(sta
->flags
& WLAN_STA_HT
)) {
2342 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2343 HOSTAPD_LEVEL_INFO
, "Station does not support "
2344 "mandatory HT PHY - reject association");
2345 return WLAN_STATUS_ASSOC_DENIED_NO_HT
;
2347 #endif /* CONFIG_IEEE80211N */
2349 #ifdef CONFIG_IEEE80211AC
2350 if (hapd
->iconf
->ieee80211ac
) {
2351 resp
= copy_sta_vht_capab(hapd
, sta
, elems
.vht_capabilities
);
2352 if (resp
!= WLAN_STATUS_SUCCESS
)
2355 resp
= set_sta_vht_opmode(hapd
, sta
, elems
.vht_opmode_notif
);
2356 if (resp
!= WLAN_STATUS_SUCCESS
)
2360 if (hapd
->iconf
->ieee80211ac
&& hapd
->iconf
->require_vht
&&
2361 !(sta
->flags
& WLAN_STA_VHT
)) {
2362 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2363 HOSTAPD_LEVEL_INFO
, "Station does not support "
2364 "mandatory VHT PHY - reject association");
2365 return WLAN_STATUS_ASSOC_DENIED_NO_VHT
;
2368 if (hapd
->conf
->vendor_vht
&& !elems
.vht_capabilities
) {
2369 resp
= copy_sta_vendor_vht(hapd
, sta
, elems
.vendor_vht
,
2370 elems
.vendor_vht_len
);
2371 if (resp
!= WLAN_STATUS_SUCCESS
)
2374 #endif /* CONFIG_IEEE80211AC */
2378 wpabuf_free(sta
->p2p_ie
);
2379 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2380 P2P_IE_VENDOR_TYPE
);
2382 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
2384 wpabuf_free(sta
->p2p_ie
);
2387 #endif /* CONFIG_P2P */
2389 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && elems
.rsn_ie
) {
2390 wpa_ie
= elems
.rsn_ie
;
2391 wpa_ie_len
= elems
.rsn_ie_len
;
2392 } else if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) &&
2394 wpa_ie
= elems
.wpa_ie
;
2395 wpa_ie_len
= elems
.wpa_ie_len
;
2402 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
2403 if (hapd
->conf
->wps_state
&& elems
.wps_ie
) {
2404 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)Association "
2405 "Request - assume WPS is used");
2406 sta
->flags
|= WLAN_STA_WPS
;
2407 wpabuf_free(sta
->wps_ie
);
2408 sta
->wps_ie
= ieee802_11_vendor_ie_concat(ies
, ies_len
,
2409 WPS_IE_VENDOR_TYPE
);
2410 if (sta
->wps_ie
&& wps_is_20(sta
->wps_ie
)) {
2411 wpa_printf(MSG_DEBUG
, "WPS: STA supports WPS 2.0");
2412 sta
->flags
|= WLAN_STA_WPS2
;
2416 if (sta
->wps_ie
&& wps_validate_assoc_req(sta
->wps_ie
) < 0) {
2417 wpa_printf(MSG_DEBUG
, "WPS: Invalid WPS IE in "
2418 "(Re)Association Request - reject");
2419 return WLAN_STATUS_INVALID_IE
;
2421 } else if (hapd
->conf
->wps_state
&& wpa_ie
== NULL
) {
2422 wpa_printf(MSG_DEBUG
, "STA did not include WPA/RSN IE in "
2423 "(Re)Association Request - possible WPS use");
2424 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
2426 #endif /* CONFIG_WPS */
2427 if (hapd
->conf
->wpa
&& wpa_ie
== NULL
) {
2428 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2430 "No WPA/RSN IE in association request");
2431 return WLAN_STATUS_INVALID_IE
;
2434 if (hapd
->conf
->wpa
&& wpa_ie
) {
2438 if (sta
->wpa_sm
== NULL
)
2439 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2442 if (sta
->wpa_sm
== NULL
) {
2443 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2445 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2447 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
2449 elems
.mdie
, elems
.mdie_len
,
2450 elems
.owe_dh
, elems
.owe_dh_len
);
2451 resp
= wpa_res_to_status_code(res
);
2452 if (resp
!= WLAN_STATUS_SUCCESS
)
2454 #ifdef CONFIG_IEEE80211W
2455 if ((sta
->flags
& WLAN_STA_MFP
) && !sta
->sa_query_timed_out
&&
2456 sta
->sa_query_count
> 0)
2457 ap_check_sa_query_timeout(hapd
, sta
);
2458 if ((sta
->flags
& WLAN_STA_MFP
) && !sta
->sa_query_timed_out
&&
2459 (!reassoc
|| sta
->auth_alg
!= WLAN_AUTH_FT
)) {
2461 * STA has already been associated with MFP and SA
2462 * Query timeout has not been reached. Reject the
2463 * association attempt temporarily and start SA Query,
2464 * if one is not pending.
2467 if (sta
->sa_query_count
== 0)
2468 ap_sta_start_sa_query(hapd
, sta
);
2470 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
2473 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
2474 sta
->flags
|= WLAN_STA_MFP
;
2476 sta
->flags
&= ~WLAN_STA_MFP
;
2477 #endif /* CONFIG_IEEE80211W */
2479 #ifdef CONFIG_IEEE80211R_AP
2480 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
2482 wpa_printf(MSG_DEBUG
, "FT: " MACSTR
" tried "
2483 "to use association (not "
2484 "re-association) with FT auth_alg",
2485 MAC2STR(sta
->addr
));
2486 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2489 resp
= wpa_ft_validate_reassoc(sta
->wpa_sm
, ies
,
2491 if (resp
!= WLAN_STATUS_SUCCESS
)
2494 #endif /* CONFIG_IEEE80211R_AP */
2497 if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
2498 sta
->auth_alg
== WLAN_AUTH_OPEN
) {
2499 struct rsn_pmksa_cache_entry
*sa
;
2500 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
2501 if (!sa
|| sa
->akmp
!= WPA_KEY_MGMT_SAE
) {
2502 wpa_printf(MSG_DEBUG
,
2503 "SAE: No PMKSA cache entry found for "
2504 MACSTR
, MAC2STR(sta
->addr
));
2505 return WLAN_STATUS_INVALID_PMKID
;
2507 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
2508 " using PMKSA caching", MAC2STR(sta
->addr
));
2509 } else if (wpa_auth_uses_sae(sta
->wpa_sm
) &&
2510 sta
->auth_alg
!= WLAN_AUTH_SAE
&&
2511 !(sta
->auth_alg
== WLAN_AUTH_FT
&&
2512 wpa_auth_uses_ft_sae(sta
->wpa_sm
))) {
2513 wpa_printf(MSG_DEBUG
, "SAE: " MACSTR
" tried to use "
2514 "SAE AKM after non-SAE auth_alg %u",
2515 MAC2STR(sta
->addr
), sta
->auth_alg
);
2516 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
2518 #endif /* CONFIG_SAE */
2521 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
2522 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
2524 resp
= owe_process_assoc_req(hapd
, sta
, elems
.owe_dh
,
2526 if (resp
!= WLAN_STATUS_SUCCESS
)
2529 #endif /* CONFIG_OWE */
2531 #ifdef CONFIG_IEEE80211N
2532 if ((sta
->flags
& (WLAN_STA_HT
| WLAN_STA_VHT
)) &&
2533 wpa_auth_get_pairwise(sta
->wpa_sm
) == WPA_CIPHER_TKIP
) {
2534 hostapd_logger(hapd
, sta
->addr
,
2535 HOSTAPD_MODULE_IEEE80211
,
2537 "Station tried to use TKIP with HT "
2539 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
2541 #endif /* CONFIG_IEEE80211N */
2543 } else if (hapd
->conf
->osen
) {
2544 if (elems
.osen
== NULL
) {
2546 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
2548 "No HS 2.0 OSEN element in association request");
2549 return WLAN_STATUS_INVALID_IE
;
2552 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
2553 if (sta
->wpa_sm
== NULL
)
2554 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
2556 if (sta
->wpa_sm
== NULL
) {
2557 wpa_printf(MSG_WARNING
, "Failed to initialize WPA "
2559 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2561 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
2562 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
2563 return WLAN_STATUS_INVALID_IE
;
2564 #endif /* CONFIG_HS20 */
2566 wpa_auth_sta_no_wpa(sta
->wpa_sm
);
2569 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
, ies
, ies_len
);
2570 #endif /* CONFIG_P2P */
2573 wpabuf_free(sta
->hs20_ie
);
2574 if (elems
.hs20
&& elems
.hs20_len
> 4) {
2575 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
2576 elems
.hs20_len
- 4);
2578 sta
->hs20_ie
= NULL
;
2579 #endif /* CONFIG_HS20 */
2582 wpabuf_free(sta
->mb_ies
);
2583 if (hapd
->iface
->fst
)
2584 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
2587 #endif /* CONFIG_FST */
2590 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
2592 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
2593 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
2594 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
2595 wpa_printf(MSG_INFO
,
2596 "MBO: Reject WPA2 association without PMF");
2597 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2599 #endif /* CONFIG_MBO */
2601 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
2602 elems
.supp_op_classes_len
);
2604 if ((sta
->capability
& WLAN_CAPABILITY_RADIO_MEASUREMENT
) &&
2605 elems
.rrm_enabled
&&
2606 elems
.rrm_enabled_len
>= sizeof(sta
->rrm_enabled_capa
))
2607 os_memcpy(sta
->rrm_enabled_capa
, elems
.rrm_enabled
,
2608 sizeof(sta
->rrm_enabled_capa
));
2610 if (elems
.power_capab
) {
2611 sta
->min_tx_power
= elems
.power_capab
[0];
2612 sta
->max_tx_power
= elems
.power_capab
[1];
2613 sta
->power_capab
= 1;
2615 sta
->power_capab
= 0;
2618 return WLAN_STATUS_SUCCESS
;
2622 static void send_deauth(struct hostapd_data
*hapd
, const u8
*addr
,
2626 struct ieee80211_mgmt reply
;
2628 os_memset(&reply
, 0, sizeof(reply
));
2629 reply
.frame_control
=
2630 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_DEAUTH
);
2631 os_memcpy(reply
.da
, addr
, ETH_ALEN
);
2632 os_memcpy(reply
.sa
, hapd
->own_addr
, ETH_ALEN
);
2633 os_memcpy(reply
.bssid
, hapd
->own_addr
, ETH_ALEN
);
2635 send_len
= IEEE80211_HDRLEN
+ sizeof(reply
.u
.deauth
);
2636 reply
.u
.deauth
.reason_code
= host_to_le16(reason_code
);
2638 if (hostapd_drv_send_mlme(hapd
, &reply
, send_len
, 0) < 0)
2639 wpa_printf(MSG_INFO
, "Failed to send deauth: %s",
2644 static int add_associated_sta(struct hostapd_data
*hapd
,
2645 struct sta_info
*sta
)
2647 struct ieee80211_ht_capabilities ht_cap
;
2648 struct ieee80211_vht_capabilities vht_cap
;
2652 * Remove the STA entry to ensure the STA PS state gets cleared and
2653 * configuration gets updated. This is relevant for cases, such as
2654 * FT-over-the-DS, where a station re-associates back to the same AP but
2655 * skips the authentication flow, or if working with a driver that
2656 * does not support full AP client state.
2658 * Skip this if the STA has already completed FT reassociation and the
2659 * TK has been configured since the TX/RX PN must not be reset to 0 for
2662 if (!sta
->added_unassoc
&&
2663 (!(sta
->flags
& WLAN_STA_AUTHORIZED
) ||
2664 (!wpa_auth_sta_ft_tk_already_set(sta
->wpa_sm
) &&
2665 !wpa_auth_sta_fils_tk_already_set(sta
->wpa_sm
)))) {
2666 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2667 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DRV_STA_REMOVED
);
2671 #ifdef CONFIG_IEEE80211N
2672 if (sta
->flags
& WLAN_STA_HT
)
2673 hostapd_get_ht_capab(hapd
, sta
->ht_capabilities
, &ht_cap
);
2674 #endif /* CONFIG_IEEE80211N */
2675 #ifdef CONFIG_IEEE80211AC
2676 if (sta
->flags
& WLAN_STA_VHT
)
2677 hostapd_get_vht_capab(hapd
, sta
->vht_capabilities
, &vht_cap
);
2678 #endif /* CONFIG_IEEE80211AC */
2681 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
2682 * will be set when the ACK frame for the (Re)Association Response frame
2683 * is processed (TX status driver event).
2685 if (hostapd_sta_add(hapd
, sta
->addr
, sta
->aid
, sta
->capability
,
2686 sta
->supported_rates
, sta
->supported_rates_len
,
2687 sta
->listen_interval
,
2688 sta
->flags
& WLAN_STA_HT
? &ht_cap
: NULL
,
2689 sta
->flags
& WLAN_STA_VHT
? &vht_cap
: NULL
,
2690 sta
->flags
| WLAN_STA_ASSOC
, sta
->qosinfo
,
2691 sta
->vht_opmode
, sta
->p2p_ie
? 1 : 0,
2693 hostapd_logger(hapd
, sta
->addr
,
2694 HOSTAPD_MODULE_IEEE80211
, HOSTAPD_LEVEL_NOTICE
,
2695 "Could not %s STA to kernel driver",
2696 set
? "set" : "add");
2698 if (sta
->added_unassoc
) {
2699 hostapd_drv_sta_remove(hapd
, sta
->addr
);
2700 sta
->added_unassoc
= 0;
2706 sta
->added_unassoc
= 0;
2712 static u16
send_assoc_resp(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2713 const u8
*addr
, u16 status_code
, int reassoc
,
2714 const u8
*ies
, size_t ies_len
)
2719 struct ieee80211_mgmt
*reply
;
2721 u16 res
= WLAN_STATUS_SUCCESS
;
2723 buflen
= sizeof(struct ieee80211_mgmt
) + 1024;
2725 if (sta
&& sta
->fils_hlp_resp
)
2726 buflen
+= wpabuf_len(sta
->fils_hlp_resp
);
2727 #endif /* CONFIG_FILS */
2729 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
2731 #endif /* CONFIG_OWE */
2732 buf
= os_zalloc(buflen
);
2734 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2737 reply
= (struct ieee80211_mgmt
*) buf
;
2738 reply
->frame_control
=
2739 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2740 (reassoc
? WLAN_FC_STYPE_REASSOC_RESP
:
2741 WLAN_FC_STYPE_ASSOC_RESP
));
2742 os_memcpy(reply
->da
, addr
, ETH_ALEN
);
2743 os_memcpy(reply
->sa
, hapd
->own_addr
, ETH_ALEN
);
2744 os_memcpy(reply
->bssid
, hapd
->own_addr
, ETH_ALEN
);
2746 send_len
= IEEE80211_HDRLEN
;
2747 send_len
+= sizeof(reply
->u
.assoc_resp
);
2748 reply
->u
.assoc_resp
.capab_info
=
2749 host_to_le16(hostapd_own_capab_info(hapd
));
2750 reply
->u
.assoc_resp
.status_code
= host_to_le16(status_code
);
2752 reply
->u
.assoc_resp
.aid
= host_to_le16((sta
? sta
->aid
: 0) |
2754 /* Supported rates */
2755 p
= hostapd_eid_supp_rates(hapd
, reply
->u
.assoc_resp
.variable
);
2756 /* Extended supported rates */
2757 p
= hostapd_eid_ext_supp_rates(hapd
, p
);
2759 #ifdef CONFIG_IEEE80211R_AP
2760 if (sta
&& status_code
== WLAN_STATUS_SUCCESS
) {
2761 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
2762 * Transition Information, RSN, [RIC Response] */
2763 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, p
,
2765 sta
->auth_alg
, ies
, ies_len
);
2767 #endif /* CONFIG_IEEE80211R_AP */
2770 if (sta
&& (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
))
2771 p
= wpa_auth_write_assoc_resp_owe(sta
->wpa_sm
, p
,
2774 #endif /* CONFIG_OWE */
2776 #ifdef CONFIG_IEEE80211W
2777 if (sta
&& status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
)
2778 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
2779 #endif /* CONFIG_IEEE80211W */
2781 #ifdef CONFIG_IEEE80211N
2782 p
= hostapd_eid_ht_capabilities(hapd
, p
);
2783 p
= hostapd_eid_ht_operation(hapd
, p
);
2784 #endif /* CONFIG_IEEE80211N */
2786 #ifdef CONFIG_IEEE80211AC
2787 if (hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
) {
2788 u32 nsts
= 0, sta_nsts
;
2790 if (sta
&& hapd
->conf
->use_sta_nsts
&& sta
->vht_capabilities
) {
2791 struct ieee80211_vht_capabilities
*capa
;
2793 nsts
= (hapd
->iface
->conf
->vht_capab
>>
2794 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
2795 capa
= sta
->vht_capabilities
;
2796 sta_nsts
= (le_to_host32(capa
->vht_capabilities_info
) >>
2797 VHT_CAP_BEAMFORMEE_STS_OFFSET
) & 7;
2799 if (nsts
< sta_nsts
)
2804 p
= hostapd_eid_vht_capabilities(hapd
, p
, nsts
);
2805 p
= hostapd_eid_vht_operation(hapd
, p
);
2807 #endif /* CONFIG_IEEE80211AC */
2809 p
= hostapd_eid_ext_capab(hapd
, p
);
2810 p
= hostapd_eid_bss_max_idle_period(hapd
, p
);
2811 if (sta
&& sta
->qos_map_enabled
)
2812 p
= hostapd_eid_qos_map_set(hapd
, p
);
2815 if (hapd
->iface
->fst_ies
) {
2816 os_memcpy(p
, wpabuf_head(hapd
->iface
->fst_ies
),
2817 wpabuf_len(hapd
->iface
->fst_ies
));
2818 p
+= wpabuf_len(hapd
->iface
->fst_ies
);
2820 #endif /* CONFIG_FST */
2822 #ifdef CONFIG_IEEE80211AC
2823 if (sta
&& hapd
->conf
->vendor_vht
&& (sta
->flags
& WLAN_STA_VENDOR_VHT
))
2824 p
= hostapd_eid_vendor_vht(hapd
, p
);
2825 #endif /* CONFIG_IEEE80211AC */
2827 if (sta
&& (sta
->flags
& WLAN_STA_WMM
))
2828 p
= hostapd_eid_wmm(hapd
, p
);
2832 ((sta
->flags
& WLAN_STA_WPS
) ||
2833 ((sta
->flags
& WLAN_STA_MAYBE_WPS
) && hapd
->conf
->wpa
))) {
2834 struct wpabuf
*wps
= wps_build_assoc_resp_ie();
2836 os_memcpy(p
, wpabuf_head(wps
), wpabuf_len(wps
));
2837 p
+= wpabuf_len(wps
);
2841 #endif /* CONFIG_WPS */
2844 if (sta
&& sta
->p2p_ie
&& hapd
->p2p_group
) {
2845 struct wpabuf
*p2p_resp_ie
;
2846 enum p2p_status_code status
;
2847 switch (status_code
) {
2848 case WLAN_STATUS_SUCCESS
:
2849 status
= P2P_SC_SUCCESS
;
2851 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
:
2852 status
= P2P_SC_FAIL_LIMIT_REACHED
;
2855 status
= P2P_SC_FAIL_INVALID_PARAMS
;
2858 p2p_resp_ie
= p2p_group_assoc_resp_ie(hapd
->p2p_group
, status
);
2860 os_memcpy(p
, wpabuf_head(p2p_resp_ie
),
2861 wpabuf_len(p2p_resp_ie
));
2862 p
+= wpabuf_len(p2p_resp_ie
);
2863 wpabuf_free(p2p_resp_ie
);
2866 #endif /* CONFIG_P2P */
2868 #ifdef CONFIG_P2P_MANAGER
2869 if (hapd
->conf
->p2p
& P2P_MANAGE
)
2870 p
= hostapd_eid_p2p_manage(hapd
, p
);
2871 #endif /* CONFIG_P2P_MANAGER */
2873 p
= hostapd_eid_mbo(hapd
, p
, buf
+ buflen
- p
);
2875 if (hapd
->conf
->assocresp_elements
&&
2876 (size_t) (buf
+ buflen
- p
) >=
2877 wpabuf_len(hapd
->conf
->assocresp_elements
)) {
2878 os_memcpy(p
, wpabuf_head(hapd
->conf
->assocresp_elements
),
2879 wpabuf_len(hapd
->conf
->assocresp_elements
));
2880 p
+= wpabuf_len(hapd
->conf
->assocresp_elements
);
2883 send_len
+= p
- reply
->u
.assoc_resp
.variable
;
2887 (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
2888 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
2889 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
2890 status_code
== WLAN_STATUS_SUCCESS
) {
2891 struct ieee802_11_elems elems
;
2893 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 0) ==
2894 ParseFailed
|| !elems
.fils_session
) {
2895 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2900 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
2901 *p
++ = 1 + FILS_SESSION_LEN
; /* Length */
2902 *p
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
2903 os_memcpy(p
, elems
.fils_session
, FILS_SESSION_LEN
);
2904 send_len
+= 2 + 1 + FILS_SESSION_LEN
;
2906 send_len
= fils_encrypt_assoc(sta
->wpa_sm
, buf
, send_len
,
2907 buflen
, sta
->fils_hlp_resp
);
2909 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2913 #endif /* CONFIG_FILS */
2916 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
2917 sta
&& sta
->owe_ecdh
&&
2918 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
) {
2921 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2923 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2926 /* OWE Diffie-Hellman Parameter element */
2927 *p
++ = WLAN_EID_EXTENSION
; /* Element ID */
2928 *p
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
2929 *p
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
2930 WPA_PUT_LE16(p
, sta
->owe_group
);
2932 os_memcpy(p
, wpabuf_head(pub
), wpabuf_len(pub
));
2933 p
+= wpabuf_len(pub
);
2934 send_len
+= 3 + 2 + wpabuf_len(pub
);
2937 #endif /* CONFIG_OWE */
2939 if (hostapd_drv_send_mlme(hapd
, reply
, send_len
, 0) < 0) {
2940 wpa_printf(MSG_INFO
, "Failed to send assoc resp: %s",
2942 res
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2952 u8
* owe_auth_req_process(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2953 const u8
*owe_dh
, u8 owe_dh_len
,
2954 u8
*owe_buf
, u16
*reason
)
2958 *reason
= owe_process_assoc_req(hapd
, sta
, owe_dh
, owe_dh_len
);
2959 if (*reason
!= WLAN_STATUS_SUCCESS
)
2961 pub
= crypto_ecdh_get_pubkey(sta
->owe_ecdh
, 0);
2963 *reason
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
2967 /* OWE Diffie-Hellman Parameter element */
2968 *owe_buf
++ = WLAN_EID_EXTENSION
; /* Element ID */
2969 *owe_buf
++ = 1 + 2 + wpabuf_len(pub
); /* Length */
2970 *owe_buf
++ = WLAN_EID_EXT_OWE_DH_PARAM
; /* Element ID Extension */
2971 WPA_PUT_LE16(owe_buf
, OWE_DH_GROUP
);
2973 os_memcpy(owe_buf
, wpabuf_head(pub
), wpabuf_len(pub
));
2974 owe_buf
+= wpabuf_len(pub
);
2976 *reason
= WLAN_STATUS_SUCCESS
;
2979 #endif /* CONFIG_OWE */
2984 void fils_hlp_finish_assoc(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2988 wpa_printf(MSG_DEBUG
, "FILS: Finish association with " MACSTR
,
2989 MAC2STR(sta
->addr
));
2990 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
2991 if (!sta
->fils_pending_assoc_req
)
2993 reply_res
= send_assoc_resp(hapd
, sta
, sta
->addr
, WLAN_STATUS_SUCCESS
,
2994 sta
->fils_pending_assoc_is_reassoc
,
2995 sta
->fils_pending_assoc_req
,
2996 sta
->fils_pending_assoc_req_len
);
2997 os_free(sta
->fils_pending_assoc_req
);
2998 sta
->fils_pending_assoc_req
= NULL
;
2999 sta
->fils_pending_assoc_req_len
= 0;
3000 wpabuf_free(sta
->fils_hlp_resp
);
3001 sta
->fils_hlp_resp
= NULL
;
3002 wpabuf_free(sta
->hlp_dhcp_discover
);
3003 sta
->hlp_dhcp_discover
= NULL
;
3006 * Remove the station in case transmission of a success response fails.
3007 * At this point the station was already added associated to the driver.
3009 if (reply_res
!= WLAN_STATUS_SUCCESS
)
3010 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3014 void fils_hlp_timeout(void *eloop_ctx
, void *eloop_data
)
3016 struct hostapd_data
*hapd
= eloop_ctx
;
3017 struct sta_info
*sta
= eloop_data
;
3019 wpa_printf(MSG_DEBUG
,
3020 "FILS: HLP response timeout - continue with association response for "
3021 MACSTR
, MAC2STR(sta
->addr
));
3022 if (sta
->fils_drv_assoc_finish
)
3023 hostapd_notify_assoc_fils_finish(hapd
, sta
);
3025 fils_hlp_finish_assoc(hapd
, sta
);
3028 #endif /* CONFIG_FILS */
3031 static void handle_assoc(struct hostapd_data
*hapd
,
3032 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3035 u16 capab_info
, listen_interval
, seq_ctrl
, fc
;
3036 u16 resp
= WLAN_STATUS_SUCCESS
, reply_res
;
3039 struct sta_info
*sta
;
3041 struct hostapd_sta_wpa_psk_short
*psk
= NULL
;
3042 char *identity
= NULL
;
3043 char *radius_cui
= NULL
;
3045 int delay_assoc
= 0;
3046 #endif /* CONFIG_FILS */
3048 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_req
) :
3049 sizeof(mgmt
->u
.assoc_req
))) {
3050 wpa_printf(MSG_INFO
, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3051 reassoc
, (unsigned long) len
);
3055 #ifdef CONFIG_TESTING_OPTIONS
3057 if (hapd
->iconf
->ignore_reassoc_probability
> 0.0 &&
3058 drand48() < hapd
->iconf
->ignore_reassoc_probability
) {
3059 wpa_printf(MSG_INFO
,
3060 "TESTING: ignoring reassoc request from "
3061 MACSTR
, MAC2STR(mgmt
->sa
));
3065 if (hapd
->iconf
->ignore_assoc_probability
> 0.0 &&
3066 drand48() < hapd
->iconf
->ignore_assoc_probability
) {
3067 wpa_printf(MSG_INFO
,
3068 "TESTING: ignoring assoc request from "
3069 MACSTR
, MAC2STR(mgmt
->sa
));
3073 #endif /* CONFIG_TESTING_OPTIONS */
3075 fc
= le_to_host16(mgmt
->frame_control
);
3076 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3079 capab_info
= le_to_host16(mgmt
->u
.reassoc_req
.capab_info
);
3080 listen_interval
= le_to_host16(
3081 mgmt
->u
.reassoc_req
.listen_interval
);
3082 wpa_printf(MSG_DEBUG
, "reassociation request: STA=" MACSTR
3083 " capab_info=0x%02x listen_interval=%d current_ap="
3084 MACSTR
" seq_ctrl=0x%x%s",
3085 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3086 MAC2STR(mgmt
->u
.reassoc_req
.current_ap
),
3087 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3088 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.reassoc_req
));
3089 pos
= mgmt
->u
.reassoc_req
.variable
;
3091 capab_info
= le_to_host16(mgmt
->u
.assoc_req
.capab_info
);
3092 listen_interval
= le_to_host16(
3093 mgmt
->u
.assoc_req
.listen_interval
);
3094 wpa_printf(MSG_DEBUG
, "association request: STA=" MACSTR
3095 " capab_info=0x%02x listen_interval=%d "
3097 MAC2STR(mgmt
->sa
), capab_info
, listen_interval
,
3098 seq_ctrl
, (fc
& WLAN_FC_RETRY
) ? " retry" : "");
3099 left
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_req
));
3100 pos
= mgmt
->u
.assoc_req
.variable
;
3103 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3104 #ifdef CONFIG_IEEE80211R_AP
3105 if (sta
&& sta
->auth_alg
== WLAN_AUTH_FT
&&
3106 (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3107 wpa_printf(MSG_DEBUG
, "FT: Allow STA " MACSTR
" to associate "
3108 "prior to authentication since it is using "
3109 "over-the-DS FT", MAC2STR(mgmt
->sa
));
3112 * Mark station as authenticated, to avoid adding station
3113 * entry in the driver as associated and not authenticated
3115 sta
->flags
|= WLAN_STA_AUTH
;
3117 #endif /* CONFIG_IEEE80211R_AP */
3118 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
3119 if (hapd
->iface
->current_mode
&&
3120 hapd
->iface
->current_mode
->mode
==
3121 HOSTAPD_MODE_IEEE80211AD
) {
3123 u32 session_timeout
, acct_interim_interval
;
3124 struct vlan_description vlan_id
;
3126 acl_res
= ieee802_11_allowed_address(
3127 hapd
, mgmt
->sa
, (const u8
*) mgmt
, len
,
3128 &session_timeout
, &acct_interim_interval
,
3129 &vlan_id
, &psk
, &identity
, &radius_cui
);
3130 if (acl_res
== HOSTAPD_ACL_REJECT
) {
3131 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3134 if (acl_res
== HOSTAPD_ACL_PENDING
)
3137 /* DMG/IEEE 802.11ad does not use authentication.
3138 * Allocate sta entry upon association. */
3139 sta
= ap_sta_add(hapd
, mgmt
->sa
);
3141 hostapd_logger(hapd
, mgmt
->sa
,
3142 HOSTAPD_MODULE_IEEE80211
,
3144 "Failed to add STA");
3145 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3149 acl_res
= ieee802_11_set_radius_info(
3150 hapd
, sta
, acl_res
, session_timeout
,
3151 acct_interim_interval
, &vlan_id
, &psk
,
3152 &identity
, &radius_cui
);
3154 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3158 hostapd_logger(hapd
, sta
->addr
,
3159 HOSTAPD_MODULE_IEEE80211
,
3160 HOSTAPD_LEVEL_DEBUG
,
3161 "Skip authentication for DMG/IEEE 802.11ad");
3162 sta
->flags
|= WLAN_STA_AUTH
;
3163 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
3164 sta
->auth_alg
= WLAN_AUTH_OPEN
;
3166 hostapd_logger(hapd
, mgmt
->sa
,
3167 HOSTAPD_MODULE_IEEE80211
,
3169 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3170 sta
? sta
->aid
: -1,
3171 sta
? sta
->flags
: 0);
3172 send_deauth(hapd
, mgmt
->sa
,
3173 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
3178 if ((fc
& WLAN_FC_RETRY
) &&
3179 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3180 sta
->last_seq_ctrl
== seq_ctrl
&&
3181 sta
->last_subtype
== (reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3182 WLAN_FC_STYPE_ASSOC_REQ
)) {
3183 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3184 HOSTAPD_LEVEL_DEBUG
,
3185 "Drop repeated association frame seq_ctrl=0x%x",
3189 sta
->last_seq_ctrl
= seq_ctrl
;
3190 sta
->last_subtype
= reassoc
? WLAN_FC_STYPE_REASSOC_REQ
:
3191 WLAN_FC_STYPE_ASSOC_REQ
;
3193 if (hapd
->tkip_countermeasures
) {
3194 resp
= WLAN_REASON_MICHAEL_MIC_FAILURE
;
3198 if (listen_interval
> hapd
->conf
->max_listen_interval
) {
3199 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3200 HOSTAPD_LEVEL_DEBUG
,
3201 "Too large Listen Interval (%d)",
3203 resp
= WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE
;
3208 if (hapd
->conf
->mbo_enabled
&& hapd
->mbo_assoc_disallow
) {
3209 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3212 #endif /* CONFIG_MBO */
3215 * sta->capability is used in check_assoc_ies() for RRM enabled
3216 * capability element.
3218 sta
->capability
= capab_info
;
3221 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3222 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3223 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3224 /* The end of the payload is encrypted. Need to decrypt it
3225 * before parsing. */
3227 tmp
= os_memdup(pos
, left
);
3229 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3233 left
= fils_decrypt_assoc(sta
->wpa_sm
, sta
->fils_session
, mgmt
,
3236 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
3241 #endif /* CONFIG_FILS */
3243 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3245 resp
= check_assoc_ies(hapd
, sta
, pos
, left
, reassoc
);
3246 if (resp
!= WLAN_STATUS_SUCCESS
)
3249 if (hostapd_get_aid(hapd
, sta
) < 0) {
3250 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3251 HOSTAPD_LEVEL_INFO
, "No room for more AIDs");
3252 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3256 sta
->listen_interval
= listen_interval
;
3258 if (hapd
->iface
->current_mode
&&
3259 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
3260 sta
->flags
|= WLAN_STA_NONERP
;
3261 for (i
= 0; i
< sta
->supported_rates_len
; i
++) {
3262 if ((sta
->supported_rates
[i
] & 0x7f) > 22) {
3263 sta
->flags
&= ~WLAN_STA_NONERP
;
3267 if (sta
->flags
& WLAN_STA_NONERP
&& !sta
->nonerp_set
) {
3268 sta
->nonerp_set
= 1;
3269 hapd
->iface
->num_sta_non_erp
++;
3270 if (hapd
->iface
->num_sta_non_erp
== 1)
3271 ieee802_11_set_beacons(hapd
->iface
);
3274 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
) &&
3275 !sta
->no_short_slot_time_set
) {
3276 sta
->no_short_slot_time_set
= 1;
3277 hapd
->iface
->num_sta_no_short_slot_time
++;
3278 if (hapd
->iface
->current_mode
&&
3279 hapd
->iface
->current_mode
->mode
==
3280 HOSTAPD_MODE_IEEE80211G
&&
3281 hapd
->iface
->num_sta_no_short_slot_time
== 1)
3282 ieee802_11_set_beacons(hapd
->iface
);
3285 if (sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3286 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
3288 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
3290 if (!(sta
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) &&
3291 !sta
->no_short_preamble_set
) {
3292 sta
->no_short_preamble_set
= 1;
3293 hapd
->iface
->num_sta_no_short_preamble
++;
3294 if (hapd
->iface
->current_mode
&&
3295 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
3296 && hapd
->iface
->num_sta_no_short_preamble
== 1)
3297 ieee802_11_set_beacons(hapd
->iface
);
3300 #ifdef CONFIG_IEEE80211N
3301 update_ht_state(hapd
, sta
);
3302 #endif /* CONFIG_IEEE80211N */
3304 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3305 HOSTAPD_LEVEL_DEBUG
,
3306 "association OK (aid %d)", sta
->aid
);
3307 /* Station will be marked associated, after it acknowledges AssocResp
3309 sta
->flags
|= WLAN_STA_ASSOC_REQ_OK
;
3311 #ifdef CONFIG_IEEE80211W
3312 if ((sta
->flags
& WLAN_STA_MFP
) && sta
->sa_query_timed_out
) {
3313 wpa_printf(MSG_DEBUG
, "Allowing %sassociation after timed out "
3314 "SA Query procedure", reassoc
? "re" : "");
3315 /* TODO: Send a protected Disassociate frame to the STA using
3316 * the old key and Reason Code "Previous Authentication no
3317 * longer valid". Make sure this is only sent protected since
3318 * unprotected frame would be received by the STA that is now
3319 * trying to associate.
3322 #endif /* CONFIG_IEEE80211W */
3324 /* Make sure that the previously registered inactivity timer will not
3325 * remove the STA immediately. */
3326 sta
->timeout_next
= STA_NULLFUNC
;
3328 #ifdef CONFIG_TAXONOMY
3329 taxonomy_sta_info_assoc_req(hapd
, sta
, pos
, left
);
3330 #endif /* CONFIG_TAXONOMY */
3332 sta
->pending_wds_enable
= 0;
3335 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3336 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3337 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
3338 if (fils_process_hlp(hapd
, sta
, pos
, left
) > 0)
3341 #endif /* CONFIG_FILS */
3345 os_free(radius_cui
);
3346 hostapd_free_psk_list(psk
);
3349 * In case of a successful response, add the station to the driver.
3350 * Otherwise, the kernel may ignore Data frames before we process the
3351 * ACK frame (TX status). In case of a failure, this station will be
3354 * Note that this is not compliant with the IEEE 802.11 standard that
3355 * states that a non-AP station should transition into the
3356 * authenticated/associated state only after the station acknowledges
3357 * the (Re)Association Response frame. However, still do this as:
3359 * 1. In case the station does not acknowledge the (Re)Association
3360 * Response frame, it will be removed.
3361 * 2. Data frames will be dropped in the kernel until the station is
3362 * set into authorized state, and there are no significant known
3363 * issues with processing other non-Data Class 3 frames during this
3366 if (resp
== WLAN_STATUS_SUCCESS
&& sta
&& add_associated_sta(hapd
, sta
))
3367 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
3371 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3372 os_free(sta
->fils_pending_assoc_req
);
3373 sta
->fils_pending_assoc_req
= NULL
;
3374 sta
->fils_pending_assoc_req_len
= 0;
3375 wpabuf_free(sta
->fils_hlp_resp
);
3376 sta
->fils_hlp_resp
= NULL
;
3378 if (sta
&& delay_assoc
&& resp
== WLAN_STATUS_SUCCESS
) {
3379 sta
->fils_pending_assoc_req
= tmp
;
3380 sta
->fils_pending_assoc_req_len
= left
;
3381 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
3382 sta
->fils_drv_assoc_finish
= 0;
3383 wpa_printf(MSG_DEBUG
,
3384 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
3385 MACSTR
, MAC2STR(sta
->addr
));
3386 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
3387 eloop_register_timeout(0, hapd
->conf
->fils_hlp_wait_time
* 1024,
3388 fils_hlp_timeout
, hapd
, sta
);
3391 #endif /* CONFIG_FILS */
3393 reply_res
= send_assoc_resp(hapd
, sta
, mgmt
->sa
, resp
, reassoc
, pos
,
3398 * Remove the station in case tranmission of a success response fails
3399 * (the STA was added associated to the driver) or if the station was
3400 * previously added unassociated.
3402 if (sta
&& ((reply_res
!= WLAN_STATUS_SUCCESS
&&
3403 resp
== WLAN_STATUS_SUCCESS
) || sta
->added_unassoc
)) {
3404 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3405 sta
->added_unassoc
= 0;
3410 static void handle_disassoc(struct hostapd_data
*hapd
,
3411 const struct ieee80211_mgmt
*mgmt
, size_t len
)
3413 struct sta_info
*sta
;
3415 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.disassoc
)) {
3416 wpa_printf(MSG_INFO
, "handle_disassoc - too short payload (len=%lu)",
3417 (unsigned long) len
);
3421 wpa_printf(MSG_DEBUG
, "disassocation: STA=" MACSTR
" reason_code=%d",
3423 le_to_host16(mgmt
->u
.disassoc
.reason_code
));
3425 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3427 wpa_printf(MSG_INFO
, "Station " MACSTR
" trying to disassociate, but it is not associated",
3432 ap_sta_set_authorized(hapd
, sta
, 0);
3433 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
3434 sta
->flags
&= ~(WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
);
3435 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
3436 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3437 HOSTAPD_LEVEL_INFO
, "disassociated");
3438 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
3439 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
3440 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
3442 accounting_sta_stop(hapd
, sta
);
3443 ieee802_1x_free_station(hapd
, sta
);
3445 hostapd_drv_br_delete_ip_neigh(hapd
, 4, (u8
*) &sta
->ipaddr
);
3446 ap_sta_ip6addr_del(hapd
, sta
);
3447 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3448 sta
->added_unassoc
= 0;
3450 if (sta
->timeout_next
== STA_NULLFUNC
||
3451 sta
->timeout_next
== STA_DISASSOC
) {
3452 sta
->timeout_next
= STA_DEAUTH
;
3453 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
3454 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
3458 mlme_disassociate_indication(
3459 hapd
, sta
, le_to_host16(mgmt
->u
.disassoc
.reason_code
));
3461 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
3462 * disassociation. */
3463 if (hapd
->iface
->current_mode
&&
3464 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211AD
) {
3465 sta
->flags
&= ~WLAN_STA_AUTH
;
3466 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
3467 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3468 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
3469 ap_free_sta(hapd
, sta
);
3474 static void handle_deauth(struct hostapd_data
*hapd
,
3475 const struct ieee80211_mgmt
*mgmt
, size_t len
)
3477 struct sta_info
*sta
;
3479 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.deauth
)) {
3480 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "handle_deauth - too short "
3481 "payload (len=%lu)", (unsigned long) len
);
3485 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "deauthentication: STA=" MACSTR
3487 MAC2STR(mgmt
->sa
), le_to_host16(mgmt
->u
.deauth
.reason_code
));
3489 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3491 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
" trying "
3492 "to deauthenticate, but it is not authenticated",
3497 ap_sta_set_authorized(hapd
, sta
, 0);
3498 sta
->last_seq_ctrl
= WLAN_INVALID_MGMT_SEQ
;
3499 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
3500 WLAN_STA_ASSOC_REQ_OK
);
3501 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
3502 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3503 HOSTAPD_LEVEL_DEBUG
, "deauthenticated");
3504 mlme_deauthenticate_indication(
3505 hapd
, sta
, le_to_host16(mgmt
->u
.deauth
.reason_code
));
3506 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
3507 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
3508 ap_free_sta(hapd
, sta
);
3512 static void handle_beacon(struct hostapd_data
*hapd
,
3513 const struct ieee80211_mgmt
*mgmt
, size_t len
,
3514 struct hostapd_frame_info
*fi
)
3516 struct ieee802_11_elems elems
;
3518 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.beacon
)) {
3519 wpa_printf(MSG_INFO
, "handle_beacon - too short payload (len=%lu)",
3520 (unsigned long) len
);
3524 (void) ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
3525 len
- (IEEE80211_HDRLEN
+
3526 sizeof(mgmt
->u
.beacon
)), &elems
,
3529 ap_list_process_beacon(hapd
->iface
, mgmt
, &elems
, fi
);
3533 #ifdef CONFIG_IEEE80211W
3535 static int hostapd_sa_query_action(struct hostapd_data
*hapd
,
3536 const struct ieee80211_mgmt
*mgmt
,
3541 end
= mgmt
->u
.action
.u
.sa_query_resp
.trans_id
+
3542 WLAN_SA_QUERY_TR_ID_LEN
;
3543 if (((u8
*) mgmt
) + len
< end
) {
3544 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Too short SA Query Action "
3545 "frame (len=%lu)", (unsigned long) len
);
3549 ieee802_11_sa_query_action(hapd
, mgmt
->sa
,
3550 mgmt
->u
.action
.u
.sa_query_resp
.action
,
3551 mgmt
->u
.action
.u
.sa_query_resp
.trans_id
);
3556 static int robust_action_frame(u8 category
)
3558 return category
!= WLAN_ACTION_PUBLIC
&&
3559 category
!= WLAN_ACTION_HT
;
3561 #endif /* CONFIG_IEEE80211W */
3564 static int handle_action(struct hostapd_data
*hapd
,
3565 const struct ieee80211_mgmt
*mgmt
, size_t len
)
3567 struct sta_info
*sta
;
3568 sta
= ap_get_sta(hapd
, mgmt
->sa
);
3570 if (len
< IEEE80211_HDRLEN
+ 1) {
3571 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3572 HOSTAPD_LEVEL_DEBUG
,
3573 "handle_action - too short payload (len=%lu)",
3574 (unsigned long) len
);
3578 if (mgmt
->u
.action
.category
!= WLAN_ACTION_PUBLIC
&&
3579 (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
3580 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignored Action "
3581 "frame (category=%u) from unassociated STA " MACSTR
,
3582 mgmt
->u
.action
.category
, MAC2STR(mgmt
->sa
));
3586 #ifdef CONFIG_IEEE80211W
3587 if (sta
&& (sta
->flags
& WLAN_STA_MFP
) &&
3588 !(mgmt
->frame_control
& host_to_le16(WLAN_FC_ISWEP
)) &&
3589 robust_action_frame(mgmt
->u
.action
.category
)) {
3590 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3591 HOSTAPD_LEVEL_DEBUG
,
3592 "Dropped unprotected Robust Action frame from "
3596 #endif /* CONFIG_IEEE80211W */
3599 u16 fc
= le_to_host16(mgmt
->frame_control
);
3600 u16 seq_ctrl
= le_to_host16(mgmt
->seq_ctrl
);
3602 if ((fc
& WLAN_FC_RETRY
) &&
3603 sta
->last_seq_ctrl
!= WLAN_INVALID_MGMT_SEQ
&&
3604 sta
->last_seq_ctrl
== seq_ctrl
&&
3605 sta
->last_subtype
== WLAN_FC_STYPE_ACTION
) {
3606 hostapd_logger(hapd
, sta
->addr
,
3607 HOSTAPD_MODULE_IEEE80211
,
3608 HOSTAPD_LEVEL_DEBUG
,
3609 "Drop repeated action frame seq_ctrl=0x%x",
3614 sta
->last_seq_ctrl
= seq_ctrl
;
3615 sta
->last_subtype
= WLAN_FC_STYPE_ACTION
;
3618 switch (mgmt
->u
.action
.category
) {
3619 #ifdef CONFIG_IEEE80211R_AP
3620 case WLAN_ACTION_FT
:
3622 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
,
3623 len
- IEEE80211_HDRLEN
))
3626 #endif /* CONFIG_IEEE80211R_AP */
3627 case WLAN_ACTION_WMM
:
3628 hostapd_wmm_action(hapd
, mgmt
, len
);
3630 #ifdef CONFIG_IEEE80211W
3631 case WLAN_ACTION_SA_QUERY
:
3632 return hostapd_sa_query_action(hapd
, mgmt
, len
);
3633 #endif /* CONFIG_IEEE80211W */
3634 #ifdef CONFIG_WNM_AP
3635 case WLAN_ACTION_WNM
:
3636 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, len
);
3638 #endif /* CONFIG_WNM_AP */
3640 case WLAN_ACTION_FST
:
3641 if (hapd
->iface
->fst
)
3642 fst_rx_action(hapd
->iface
->fst
, mgmt
, len
);
3644 wpa_printf(MSG_DEBUG
,
3645 "FST: Ignore FST Action frame - no FST attached");
3647 #endif /* CONFIG_FST */
3648 case WLAN_ACTION_PUBLIC
:
3649 case WLAN_ACTION_PROTECTED_DUAL
:
3650 #ifdef CONFIG_IEEE80211N
3651 if (len
>= IEEE80211_HDRLEN
+ 2 &&
3652 mgmt
->u
.action
.u
.public_action
.action
==
3653 WLAN_PA_20_40_BSS_COEX
) {
3654 wpa_printf(MSG_DEBUG
,
3655 "HT20/40 coex mgmt frame received from STA "
3656 MACSTR
, MAC2STR(mgmt
->sa
));
3657 hostapd_2040_coex_action(hapd
, mgmt
, len
);
3660 #endif /* CONFIG_IEEE80211N */
3662 if (len
>= IEEE80211_HDRLEN
+ 6 &&
3663 mgmt
->u
.action
.u
.vs_public_action
.action
==
3664 WLAN_PA_VENDOR_SPECIFIC
&&
3665 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
3667 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
3669 const u8
*pos
, *end
;
3671 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
3672 end
= ((const u8
*) mgmt
) + len
;
3673 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
3677 if (len
>= IEEE80211_HDRLEN
+ 2 &&
3678 (mgmt
->u
.action
.u
.public_action
.action
==
3679 WLAN_PA_GAS_INITIAL_RESP
||
3680 mgmt
->u
.action
.u
.public_action
.action
==
3681 WLAN_PA_GAS_COMEBACK_RESP
)) {
3682 const u8
*pos
, *end
;
3684 pos
= &mgmt
->u
.action
.u
.public_action
.action
;
3685 end
= ((const u8
*) mgmt
) + len
;
3686 gas_query_ap_rx(hapd
->gas
, mgmt
->sa
,
3687 mgmt
->u
.action
.category
,
3688 pos
, end
- pos
, hapd
->iface
->freq
);
3691 #endif /* CONFIG_DPP */
3692 if (hapd
->public_action_cb
) {
3693 hapd
->public_action_cb(hapd
->public_action_cb_ctx
,
3697 if (hapd
->public_action_cb2
) {
3698 hapd
->public_action_cb2(hapd
->public_action_cb2_ctx
,
3702 if (hapd
->public_action_cb
|| hapd
->public_action_cb2
)
3705 case WLAN_ACTION_VENDOR_SPECIFIC
:
3706 if (hapd
->vendor_action_cb
) {
3707 if (hapd
->vendor_action_cb(hapd
->vendor_action_cb_ctx
,
3709 hapd
->iface
->freq
) == 0)
3713 case WLAN_ACTION_RADIO_MEASUREMENT
:
3714 hostapd_handle_radio_measurement(hapd
, (const u8
*) mgmt
, len
);
3718 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3719 HOSTAPD_LEVEL_DEBUG
,
3720 "handle_action - unknown action category %d or invalid "
3722 mgmt
->u
.action
.category
);
3723 if (!is_multicast_ether_addr(mgmt
->da
) &&
3724 !(mgmt
->u
.action
.category
& 0x80) &&
3725 !is_multicast_ether_addr(mgmt
->sa
)) {
3726 struct ieee80211_mgmt
*resp
;
3729 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
3730 * Return the Action frame to the source without change
3731 * except that MSB of the Category set to 1.
3733 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Return unknown Action "
3734 "frame back to sender");
3735 resp
= os_memdup(mgmt
, len
);
3738 os_memcpy(resp
->da
, resp
->sa
, ETH_ALEN
);
3739 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
3740 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
3741 resp
->u
.action
.category
|= 0x80;
3743 if (hostapd_drv_send_mlme(hapd
, resp
, len
, 0) < 0) {
3744 wpa_printf(MSG_ERROR
, "IEEE 802.11: Failed to send "
3755 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
3756 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
3758 * @buf: management frame data (starting from IEEE 802.11 header)
3759 * @len: length of frame data in octets
3760 * @fi: meta data about received frame (signal level, etc.)
3762 * Process all incoming IEEE 802.11 management frames. This will be called for
3763 * each frame received from the kernel driver through wlan#ap interface. In
3764 * addition, it can be called to re-inserted pending frames (e.g., when using
3765 * external RADIUS server as an MAC ACL).
3767 int ieee802_11_mgmt(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
3768 struct hostapd_frame_info
*fi
)
3770 struct ieee80211_mgmt
*mgmt
;
3777 mgmt
= (struct ieee80211_mgmt
*) buf
;
3778 fc
= le_to_host16(mgmt
->frame_control
);
3779 stype
= WLAN_FC_GET_STYPE(fc
);
3781 if (stype
== WLAN_FC_STYPE_BEACON
) {
3782 handle_beacon(hapd
, mgmt
, len
, fi
);
3786 if (!is_broadcast_ether_addr(mgmt
->bssid
) &&
3788 /* Invitation responses can be sent with the peer MAC as BSSID */
3789 !((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
3790 stype
== WLAN_FC_STYPE_ACTION
) &&
3791 #endif /* CONFIG_P2P */
3793 !(hapd
->conf
->mesh
& MESH_ENABLED
) &&
3794 #endif /* CONFIG_MESH */
3795 os_memcmp(mgmt
->bssid
, hapd
->own_addr
, ETH_ALEN
) != 0) {
3796 wpa_printf(MSG_INFO
, "MGMT: BSSID=" MACSTR
" not our address",
3797 MAC2STR(mgmt
->bssid
));
3802 if (stype
== WLAN_FC_STYPE_PROBE_REQ
) {
3803 handle_probe_req(hapd
, mgmt
, len
, fi
->ssi_signal
);
3807 if ((!is_broadcast_ether_addr(mgmt
->da
) ||
3808 stype
!= WLAN_FC_STYPE_ACTION
) &&
3809 os_memcmp(mgmt
->da
, hapd
->own_addr
, ETH_ALEN
) != 0) {
3810 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3811 HOSTAPD_LEVEL_DEBUG
,
3812 "MGMT: DA=" MACSTR
" not our address",
3817 if (hapd
->iconf
->track_sta_max_num
)
3818 sta_track_add(hapd
->iface
, mgmt
->sa
, fi
->ssi_signal
);
3821 case WLAN_FC_STYPE_AUTH
:
3822 wpa_printf(MSG_DEBUG
, "mgmt::auth");
3823 handle_auth(hapd
, mgmt
, len
);
3826 case WLAN_FC_STYPE_ASSOC_REQ
:
3827 wpa_printf(MSG_DEBUG
, "mgmt::assoc_req");
3828 handle_assoc(hapd
, mgmt
, len
, 0);
3831 case WLAN_FC_STYPE_REASSOC_REQ
:
3832 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_req");
3833 handle_assoc(hapd
, mgmt
, len
, 1);
3836 case WLAN_FC_STYPE_DISASSOC
:
3837 wpa_printf(MSG_DEBUG
, "mgmt::disassoc");
3838 handle_disassoc(hapd
, mgmt
, len
);
3841 case WLAN_FC_STYPE_DEAUTH
:
3842 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "mgmt::deauth");
3843 handle_deauth(hapd
, mgmt
, len
);
3846 case WLAN_FC_STYPE_ACTION
:
3847 wpa_printf(MSG_DEBUG
, "mgmt::action");
3848 ret
= handle_action(hapd
, mgmt
, len
);
3851 hostapd_logger(hapd
, mgmt
->sa
, HOSTAPD_MODULE_IEEE80211
,
3852 HOSTAPD_LEVEL_DEBUG
,
3853 "unknown mgmt frame subtype %d", stype
);
3861 static void handle_auth_cb(struct hostapd_data
*hapd
,
3862 const struct ieee80211_mgmt
*mgmt
,
3865 u16 auth_alg
, auth_transaction
, status_code
;
3866 struct sta_info
*sta
;
3868 sta
= ap_get_sta(hapd
, mgmt
->da
);
3870 wpa_printf(MSG_INFO
, "handle_auth_cb: STA " MACSTR
" not found",
3875 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3876 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3877 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
3880 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
3881 HOSTAPD_LEVEL_NOTICE
,
3882 "did not acknowledge authentication response");
3886 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.auth
)) {
3887 wpa_printf(MSG_INFO
, "handle_auth_cb - too short payload (len=%lu)",
3888 (unsigned long) len
);
3892 if (status_code
== WLAN_STATUS_SUCCESS
&&
3893 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
3894 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
3895 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3896 HOSTAPD_LEVEL_INFO
, "authenticated");
3897 sta
->flags
|= WLAN_STA_AUTH
;
3898 if (sta
->added_unassoc
)
3899 hostapd_set_sta_flags(hapd
, sta
);
3904 if (status_code
!= WLAN_STATUS_SUCCESS
&& sta
->added_unassoc
) {
3905 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3906 sta
->added_unassoc
= 0;
3911 static void hostapd_set_wds_encryption(struct hostapd_data
*hapd
,
3912 struct sta_info
*sta
,
3916 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
3918 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
3921 for (i
= 0; i
< 4; i
++) {
3922 if (ssid
->wep
.key
[i
] &&
3923 hostapd_drv_set_key(ifname_wds
, hapd
, WPA_ALG_WEP
, NULL
, i
,
3924 i
== ssid
->wep
.idx
, NULL
, 0,
3925 ssid
->wep
.key
[i
], ssid
->wep
.len
[i
])) {
3926 wpa_printf(MSG_WARNING
,
3927 "Could not set WEP keys for WDS interface; %s",
3935 static void handle_assoc_cb(struct hostapd_data
*hapd
,
3936 const struct ieee80211_mgmt
*mgmt
,
3937 size_t len
, int reassoc
, int ok
)
3940 struct sta_info
*sta
;
3943 sta
= ap_get_sta(hapd
, mgmt
->da
);
3945 wpa_printf(MSG_INFO
, "handle_assoc_cb: STA " MACSTR
" not found",
3950 if (len
< IEEE80211_HDRLEN
+ (reassoc
? sizeof(mgmt
->u
.reassoc_resp
) :
3951 sizeof(mgmt
->u
.assoc_resp
))) {
3952 wpa_printf(MSG_INFO
,
3953 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
3954 reassoc
, (unsigned long) len
);
3955 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3960 status
= le_to_host16(mgmt
->u
.reassoc_resp
.status_code
);
3962 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
3965 hostapd_logger(hapd
, mgmt
->da
, HOSTAPD_MODULE_IEEE80211
,
3966 HOSTAPD_LEVEL_DEBUG
,
3967 "did not acknowledge association response");
3968 sta
->flags
&= ~WLAN_STA_ASSOC_REQ_OK
;
3969 /* The STA is added only in case of SUCCESS */
3970 if (status
== WLAN_STATUS_SUCCESS
)
3971 hostapd_drv_sta_remove(hapd
, sta
->addr
);
3976 if (status
!= WLAN_STATUS_SUCCESS
)
3979 /* Stop previous accounting session, if one is started, and allocate
3980 * new session id for the new session. */
3981 accounting_sta_stop(hapd
, sta
);
3983 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
3985 "associated (aid %d)",
3988 if (sta
->flags
& WLAN_STA_ASSOC
)
3990 sta
->flags
|= WLAN_STA_ASSOC
;
3991 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
3992 if ((!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
3993 !hapd
->conf
->osen
) ||
3994 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
3995 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
3996 sta
->auth_alg
== WLAN_AUTH_FILS_PK
||
3997 sta
->auth_alg
== WLAN_AUTH_FT
) {
3999 * Open, static WEP, FT protocol, or FILS; no separate
4000 * authorization step.
4002 ap_sta_set_authorized(hapd
, sta
, 1);
4006 mlme_reassociate_indication(hapd
, sta
);
4008 mlme_associate_indication(hapd
, sta
);
4010 #ifdef CONFIG_IEEE80211W
4011 sta
->sa_query_timed_out
= 0;
4012 #endif /* CONFIG_IEEE80211W */
4014 if (sta
->eapol_sm
== NULL
) {
4016 * This STA does not use RADIUS server for EAP authentication,
4017 * so bind it to the selected VLAN interface now, since the
4018 * interface selection is not going to change anymore.
4020 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4022 } else if (sta
->vlan_id
) {
4023 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4024 if (ap_sta_bind_vlan(hapd
, sta
) < 0)
4028 hostapd_set_sta_flags(hapd
, sta
);
4030 if (!(sta
->flags
& WLAN_STA_WDS
) && sta
->pending_wds_enable
) {
4031 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for STA "
4032 MACSTR
" based on pending request",
4033 MAC2STR(sta
->addr
));
4034 sta
->pending_wds_enable
= 0;
4035 sta
->flags
|= WLAN_STA_WDS
;
4038 if (sta
->flags
& WLAN_STA_WDS
) {
4040 char ifname_wds
[IFNAMSIZ
+ 1];
4042 wpa_printf(MSG_DEBUG
, "Reenable 4-address WDS mode for STA "
4044 MAC2STR(sta
->addr
), sta
->aid
);
4045 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
, sta
->addr
,
4048 hostapd_set_wds_encryption(hapd
, sta
, ifname_wds
);
4051 if (sta
->auth_alg
== WLAN_AUTH_FT
)
4052 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
4054 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
4055 hapd
->new_assoc_sta_cb(hapd
, sta
, !new_assoc
);
4056 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
4059 if ((sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
4060 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
4061 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) &&
4062 fils_set_tk(sta
->wpa_sm
) < 0) {
4063 wpa_printf(MSG_DEBUG
, "FILS: TK configuration failed");
4064 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
4065 WLAN_REASON_UNSPECIFIED
);
4068 #endif /* CONFIG_FILS */
4070 if (sta
->pending_eapol_rx
) {
4071 struct os_reltime now
, age
;
4073 os_get_reltime(&now
);
4074 os_reltime_sub(&now
, &sta
->pending_eapol_rx
->rx_time
, &age
);
4075 if (age
.sec
== 0 && age
.usec
< 200000) {
4076 wpa_printf(MSG_DEBUG
,
4077 "Process pending EAPOL frame that was received from " MACSTR
" just before association notification",
4078 MAC2STR(sta
->addr
));
4081 wpabuf_head(sta
->pending_eapol_rx
->buf
),
4082 wpabuf_len(sta
->pending_eapol_rx
->buf
));
4084 wpabuf_free(sta
->pending_eapol_rx
->buf
);
4085 os_free(sta
->pending_eapol_rx
);
4086 sta
->pending_eapol_rx
= NULL
;
4091 static void handle_deauth_cb(struct hostapd_data
*hapd
,
4092 const struct ieee80211_mgmt
*mgmt
,
4095 struct sta_info
*sta
;
4096 if (is_multicast_ether_addr(mgmt
->da
))
4098 sta
= ap_get_sta(hapd
, mgmt
->da
);
4100 wpa_printf(MSG_DEBUG
, "handle_deauth_cb: STA " MACSTR
4101 " not found", MAC2STR(mgmt
->da
));
4105 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged deauth",
4106 MAC2STR(sta
->addr
));
4108 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4109 "deauth", MAC2STR(sta
->addr
));
4111 ap_sta_deauth_cb(hapd
, sta
);
4115 static void handle_disassoc_cb(struct hostapd_data
*hapd
,
4116 const struct ieee80211_mgmt
*mgmt
,
4119 struct sta_info
*sta
;
4120 if (is_multicast_ether_addr(mgmt
->da
))
4122 sta
= ap_get_sta(hapd
, mgmt
->da
);
4124 wpa_printf(MSG_DEBUG
, "handle_disassoc_cb: STA " MACSTR
4125 " not found", MAC2STR(mgmt
->da
));
4129 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" acknowledged disassoc",
4130 MAC2STR(sta
->addr
));
4132 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" did not acknowledge "
4133 "disassoc", MAC2STR(sta
->addr
));
4135 ap_sta_disassoc_cb(hapd
, sta
);
4139 static void handle_action_cb(struct hostapd_data
*hapd
,
4140 const struct ieee80211_mgmt
*mgmt
,
4143 struct sta_info
*sta
;
4144 const struct rrm_measurement_report_element
*report
;
4146 if (is_multicast_ether_addr(mgmt
->da
))
4149 if (len
>= IEEE80211_HDRLEN
+ 6 &&
4150 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4151 mgmt
->u
.action
.u
.vs_public_action
.action
==
4152 WLAN_PA_VENDOR_SPECIFIC
&&
4153 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
4155 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
4157 const u8
*pos
, *end
;
4159 pos
= &mgmt
->u
.action
.u
.vs_public_action
.variable
[1];
4160 end
= ((const u8
*) mgmt
) + len
;
4161 hostapd_dpp_tx_status(hapd
, mgmt
->da
, pos
, end
- pos
, ok
);
4164 if (len
>= IEEE80211_HDRLEN
+ 2 &&
4165 mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
&&
4166 (mgmt
->u
.action
.u
.public_action
.action
==
4167 WLAN_PA_GAS_INITIAL_REQ
||
4168 mgmt
->u
.action
.u
.public_action
.action
==
4169 WLAN_PA_GAS_COMEBACK_REQ
)) {
4170 const u8
*pos
, *end
;
4172 pos
= mgmt
->u
.action
.u
.public_action
.variable
;
4173 end
= ((const u8
*) mgmt
) + len
;
4174 gas_query_ap_tx_status(hapd
->gas
, mgmt
->da
, pos
, end
- pos
, ok
);
4177 #endif /* CONFIG_DPP */
4178 sta
= ap_get_sta(hapd
, mgmt
->da
);
4180 wpa_printf(MSG_DEBUG
, "handle_action_cb: STA " MACSTR
4181 " not found", MAC2STR(mgmt
->da
));
4185 if (len
< 24 + 5 + sizeof(*report
))
4187 report
= (const struct rrm_measurement_report_element
*)
4188 &mgmt
->u
.action
.u
.rrm
.variable
[2];
4189 if (mgmt
->u
.action
.category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4190 mgmt
->u
.action
.u
.rrm
.action
== WLAN_RRM_RADIO_MEASUREMENT_REQUEST
&&
4191 report
->eid
== WLAN_EID_MEASURE_REQUEST
&&
4193 report
->type
== MEASURE_TYPE_BEACON
)
4194 hostapd_rrm_beacon_req_tx_status(hapd
, mgmt
, len
, ok
);
4199 * ieee802_11_mgmt_cb - Process management frame TX status callback
4200 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4202 * @buf: management frame data (starting from IEEE 802.11 header)
4203 * @len: length of frame data in octets
4204 * @stype: management frame subtype from frame control field
4205 * @ok: Whether the frame was ACK'ed
4207 void ieee802_11_mgmt_cb(struct hostapd_data
*hapd
, const u8
*buf
, size_t len
,
4210 const struct ieee80211_mgmt
*mgmt
;
4211 mgmt
= (const struct ieee80211_mgmt
*) buf
;
4213 #ifdef CONFIG_TESTING_OPTIONS
4214 if (hapd
->ext_mgmt_frame_handling
) {
4215 size_t hex_len
= 2 * len
+ 1;
4216 char *hex
= os_malloc(hex_len
);
4219 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
4220 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
4221 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4227 #endif /* CONFIG_TESTING_OPTIONS */
4230 case WLAN_FC_STYPE_AUTH
:
4231 wpa_printf(MSG_DEBUG
, "mgmt::auth cb");
4232 handle_auth_cb(hapd
, mgmt
, len
, ok
);
4234 case WLAN_FC_STYPE_ASSOC_RESP
:
4235 wpa_printf(MSG_DEBUG
, "mgmt::assoc_resp cb");
4236 handle_assoc_cb(hapd
, mgmt
, len
, 0, ok
);
4238 case WLAN_FC_STYPE_REASSOC_RESP
:
4239 wpa_printf(MSG_DEBUG
, "mgmt::reassoc_resp cb");
4240 handle_assoc_cb(hapd
, mgmt
, len
, 1, ok
);
4242 case WLAN_FC_STYPE_PROBE_RESP
:
4243 wpa_printf(MSG_EXCESSIVE
, "mgmt::proberesp cb ok=%d", ok
);
4245 case WLAN_FC_STYPE_DEAUTH
:
4246 wpa_printf(MSG_DEBUG
, "mgmt::deauth cb");
4247 handle_deauth_cb(hapd
, mgmt
, len
, ok
);
4249 case WLAN_FC_STYPE_DISASSOC
:
4250 wpa_printf(MSG_DEBUG
, "mgmt::disassoc cb");
4251 handle_disassoc_cb(hapd
, mgmt
, len
, ok
);
4253 case WLAN_FC_STYPE_ACTION
:
4254 wpa_printf(MSG_DEBUG
, "mgmt::action cb ok=%d", ok
);
4255 handle_action_cb(hapd
, mgmt
, len
, ok
);
4258 wpa_printf(MSG_INFO
, "unknown mgmt cb frame subtype %d", stype
);
4264 int ieee802_11_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
4271 int ieee802_11_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
4272 char *buf
, size_t buflen
)
4279 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
4280 const u8
*buf
, size_t len
, int ack
)
4282 struct sta_info
*sta
;
4283 struct hostapd_iface
*iface
= hapd
->iface
;
4285 sta
= ap_get_sta(hapd
, addr
);
4286 if (sta
== NULL
&& iface
->num_bss
> 1) {
4288 for (j
= 0; j
< iface
->num_bss
; j
++) {
4289 hapd
= iface
->bss
[j
];
4290 sta
= ap_get_sta(hapd
, addr
);
4295 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))
4297 if (sta
->flags
& WLAN_STA_PENDING_POLL
) {
4298 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
4299 "activity poll", MAC2STR(sta
->addr
),
4300 ack
? "ACKed" : "did not ACK");
4302 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4305 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
4309 void hostapd_eapol_tx_status(struct hostapd_data
*hapd
, const u8
*dst
,
4310 const u8
*data
, size_t len
, int ack
)
4312 struct sta_info
*sta
;
4313 struct hostapd_iface
*iface
= hapd
->iface
;
4315 sta
= ap_get_sta(hapd
, dst
);
4316 if (sta
== NULL
&& iface
->num_bss
> 1) {
4318 for (j
= 0; j
< iface
->num_bss
; j
++) {
4319 hapd
= iface
->bss
[j
];
4320 sta
= ap_get_sta(hapd
, dst
);
4325 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
4326 wpa_printf(MSG_DEBUG
, "Ignore TX status for Data frame to STA "
4327 MACSTR
" that is not currently associated",
4332 ieee802_1x_eapol_tx_status(hapd
, sta
, data
, len
, ack
);
4336 void hostapd_client_poll_ok(struct hostapd_data
*hapd
, const u8
*addr
)
4338 struct sta_info
*sta
;
4339 struct hostapd_iface
*iface
= hapd
->iface
;
4341 sta
= ap_get_sta(hapd
, addr
);
4342 if (sta
== NULL
&& iface
->num_bss
> 1) {
4344 for (j
= 0; j
< iface
->num_bss
; j
++) {
4345 hapd
= iface
->bss
[j
];
4346 sta
= ap_get_sta(hapd
, addr
);
4353 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POLL_OK MACSTR
,
4354 MAC2STR(sta
->addr
));
4355 if (!(sta
->flags
& WLAN_STA_PENDING_POLL
))
4358 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" ACKed pending "
4359 "activity poll", MAC2STR(sta
->addr
));
4360 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
4364 void ieee802_11_rx_from_unknown(struct hostapd_data
*hapd
, const u8
*src
,
4367 struct sta_info
*sta
;
4369 sta
= ap_get_sta(hapd
, src
);
4371 ((sta
->flags
& WLAN_STA_ASSOC
) ||
4372 ((sta
->flags
& WLAN_STA_ASSOC_REQ_OK
) && wds
))) {
4373 if (!hapd
->conf
->wds_sta
)
4376 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_ASSOC_REQ_OK
)) ==
4377 WLAN_STA_ASSOC_REQ_OK
) {
4378 wpa_printf(MSG_DEBUG
,
4379 "Postpone 4-address WDS mode enabling for STA "
4380 MACSTR
" since TX status for AssocResp is not yet known",
4381 MAC2STR(sta
->addr
));
4382 sta
->pending_wds_enable
= 1;
4386 if (wds
&& !(sta
->flags
& WLAN_STA_WDS
)) {
4388 char ifname_wds
[IFNAMSIZ
+ 1];
4390 wpa_printf(MSG_DEBUG
, "Enable 4-address WDS mode for "
4391 "STA " MACSTR
" (aid %u)",
4392 MAC2STR(sta
->addr
), sta
->aid
);
4393 sta
->flags
|= WLAN_STA_WDS
;
4394 ret
= hostapd_set_wds_sta(hapd
, ifname_wds
,
4395 sta
->addr
, sta
->aid
, 1);
4397 hostapd_set_wds_encryption(hapd
, sta
,
4403 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated STA "
4404 MACSTR
, MAC2STR(src
));
4405 if (is_multicast_ether_addr(src
)) {
4406 /* Broadcast bit set in SA?! Ignore the frame silently. */
4410 if (sta
&& (sta
->flags
& WLAN_STA_ASSOC_REQ_OK
)) {
4411 wpa_printf(MSG_DEBUG
, "Association Response to the STA has "
4412 "already been sent, but no TX status yet known - "
4413 "ignore Class 3 frame issue with " MACSTR
,
4418 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
4419 hostapd_drv_sta_disassoc(
4421 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
4423 hostapd_drv_sta_deauth(
4425 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
4429 #endif /* CONFIG_NATIVE_WINDOWS */