2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2014, 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/random.h"
18 #include "common/ieee802_11_defs.h"
19 #include "common/ieee802_11_common.h"
20 #include "common/wpa_ctrl.h"
21 #include "common/sae.h"
22 #include "radius/radius.h"
23 #include "radius/radius_client.h"
29 #include "ieee802_11_auth.h"
31 #include "ieee802_1x.h"
33 #include "pmksa_cache_auth.h"
36 #include "accounting.h"
37 #include "ap_config.h"
39 #include "p2p_hostapd.h"
40 #include "ap_drv_ops.h"
42 #include "hw_features.h"
43 #include "ieee802_11.h"
48 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
53 if (hapd->iface->current_rates == NULL)
56 *pos++ = WLAN_EID_SUPP_RATES;
57 num = hapd->iface->num_rates;
58 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
60 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
63 /* rest of the rates are encoded in Extended supported
69 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
72 *pos = hapd->iface->current_rates[i].rate / 5;
73 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
78 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
80 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
83 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
85 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
92 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
97 if (hapd->iface->current_rates == NULL)
100 num = hapd->iface->num_rates;
101 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
103 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
109 *pos++ = WLAN_EID_EXT_SUPP_RATES;
111 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
115 continue; /* already in SuppRates IE */
116 *pos = hapd->iface->current_rates[i].rate / 5;
117 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
122 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
125 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
128 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
131 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
138 u16 hostapd_own_capab_info(struct hostapd_data *hapd)
140 int capab = WLAN_CAPABILITY_ESS;
144 /* Check if any of configured channels require DFS */
145 dfs = hostapd_is_dfs_required(hapd->iface);
147 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
152 if (hapd->iface->num_sta_no_short_preamble == 0 &&
153 hapd->iconf->preamble == SHORT_PREAMBLE)
154 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
156 privacy = hapd->conf->ssid.wep.keys_set;
158 if (hapd->conf->ieee802_1x &&
159 (hapd->conf->default_wep_key_len ||
160 hapd->conf->individual_wep_key_len))
167 if (hapd->conf->osen)
169 #endif /* CONFIG_HS20 */
172 capab |= WLAN_CAPABILITY_PRIVACY;
174 if (hapd->iface->current_mode &&
175 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
176 hapd->iface->num_sta_no_short_slot_time == 0)
177 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
180 * Currently, Spectrum Management capability bit is set when directly
181 * requested in configuration by spectrum_mgmt_required or when AP is
182 * running on DFS channel.
183 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
185 if (hapd->iface->current_mode &&
186 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
187 (hapd->iconf->spectrum_mgmt_required || dfs))
188 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
190 if (hapd->conf->radio_measurements)
191 capab |= IEEE80211_CAP_RRM;
197 #ifndef CONFIG_NO_RC4
198 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
199 u16 auth_transaction, const u8 *challenge,
202 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
204 "authentication (shared key, transaction %d)",
207 if (auth_transaction == 1) {
208 if (!sta->challenge) {
209 /* Generate a pseudo-random challenge */
212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
216 if (os_get_random(key, sizeof(key)) < 0) {
217 os_free(sta->challenge);
218 sta->challenge = NULL;
219 return WLAN_STATUS_UNSPECIFIED_FAILURE;
222 rc4_skip(key, sizeof(key), 0,
223 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
228 if (auth_transaction != 3)
229 return WLAN_STATUS_UNSPECIFIED_FAILURE;
232 if (!iswep || !sta->challenge || !challenge ||
233 os_memcmp_const(sta->challenge, challenge,
234 WLAN_AUTH_CHALLENGE_LEN)) {
235 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
237 "shared key authentication - invalid "
238 "challenge-response");
239 return WLAN_STATUS_CHALLENGE_FAIL;
242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
244 "authentication OK (shared key)");
245 sta->flags |= WLAN_STA_AUTH;
246 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
247 os_free(sta->challenge);
248 sta->challenge = NULL;
252 #endif /* CONFIG_NO_RC4 */
255 static int send_auth_reply(struct hostapd_data *hapd,
256 const u8 *dst, const u8 *bssid,
257 u16 auth_alg, u16 auth_transaction, u16 resp,
258 const u8 *ies, size_t ies_len)
260 struct ieee80211_mgmt *reply;
263 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
265 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
266 buf = os_zalloc(rlen);
270 reply = (struct ieee80211_mgmt *) buf;
271 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
273 os_memcpy(reply->da, dst, ETH_ALEN);
274 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
275 os_memcpy(reply->bssid, bssid, ETH_ALEN);
277 reply->u.auth.auth_alg = host_to_le16(auth_alg);
278 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
279 reply->u.auth.status_code = host_to_le16(resp);
282 os_memcpy(reply->u.auth.variable, ies, ies_len);
284 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
285 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
286 MAC2STR(dst), auth_alg, auth_transaction,
287 resp, (unsigned long) ies_len);
288 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
289 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
291 reply_res = WLAN_STATUS_SUCCESS;
299 #ifdef CONFIG_IEEE80211R
300 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
301 u16 auth_transaction, u16 status,
302 const u8 *ies, size_t ies_len)
304 struct hostapd_data *hapd = ctx;
305 struct sta_info *sta;
308 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
309 auth_transaction, status, ies, ies_len);
311 sta = ap_get_sta(hapd, dst);
315 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
316 status != WLAN_STATUS_SUCCESS)) {
317 hostapd_drv_sta_remove(hapd, sta->addr);
318 sta->added_unassoc = 0;
322 if (status != WLAN_STATUS_SUCCESS)
325 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
326 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
327 sta->flags |= WLAN_STA_AUTH;
328 mlme_authenticate_indication(hapd, sta);
330 #endif /* CONFIG_IEEE80211R */
335 #define dot11RSNASAESync 5 /* attempts */
338 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
339 struct sta_info *sta, int update)
343 if (hapd->conf->ssid.wpa_passphrase == NULL) {
344 wpa_printf(MSG_DEBUG, "SAE: No password available");
349 sae_prepare_commit(hapd->own_addr, sta->addr,
350 (u8 *) hapd->conf->ssid.wpa_passphrase,
351 os_strlen(hapd->conf->ssid.wpa_passphrase),
353 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
357 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
360 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
361 sta->sae->tmp->anti_clogging_token : NULL);
367 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
368 struct sta_info *sta)
372 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
376 sae_write_confirm(sta->sae, buf);
382 static int auth_sae_send_commit(struct hostapd_data *hapd,
383 struct sta_info *sta,
384 const u8 *bssid, int update)
389 data = auth_build_sae_commit(hapd, sta, update);
391 return WLAN_STATUS_UNSPECIFIED_FAILURE;
393 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
394 WLAN_STATUS_SUCCESS, wpabuf_head(data),
403 static int auth_sae_send_confirm(struct hostapd_data *hapd,
404 struct sta_info *sta,
410 data = auth_build_sae_confirm(hapd, sta);
412 return WLAN_STATUS_UNSPECIFIED_FAILURE;
414 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
415 WLAN_STATUS_SUCCESS, wpabuf_head(data),
424 static int use_sae_anti_clogging(struct hostapd_data *hapd)
426 struct sta_info *sta;
427 unsigned int open = 0;
429 if (hapd->conf->sae_anti_clogging_threshold == 0)
432 for (sta = hapd->sta_list; sta; sta = sta->next) {
435 if (sta->sae->state != SAE_COMMITTED &&
436 sta->sae->state != SAE_CONFIRMED)
439 if (open >= hapd->conf->sae_anti_clogging_threshold)
447 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
448 const u8 *token, size_t token_len)
450 u8 mac[SHA256_MAC_LEN];
452 if (token_len != SHA256_MAC_LEN)
454 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
455 addr, ETH_ALEN, mac) < 0 ||
456 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
463 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
464 int group, const u8 *addr)
468 struct os_reltime now;
470 os_get_reltime(&now);
471 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
472 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
473 if (random_get_bytes(hapd->sae_token_key,
474 sizeof(hapd->sae_token_key)) < 0)
476 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
477 hapd->sae_token_key, sizeof(hapd->sae_token_key));
478 hapd->last_sae_token_key_update = now;
481 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
485 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
487 token = wpabuf_put(buf, SHA256_MAC_LEN);
488 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
489 addr, ETH_ALEN, token);
495 static int sae_check_big_sync(struct sta_info *sta)
497 if (sta->sae->sync > dot11RSNASAESync) {
498 sta->sae->state = SAE_NOTHING;
506 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
508 struct hostapd_data *hapd = eloop_ctx;
509 struct sta_info *sta = eloop_data;
512 if (sae_check_big_sync(sta))
516 switch (sta->sae->state) {
518 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
519 eloop_register_timeout(0,
520 hapd->dot11RSNASAERetransPeriod * 1000,
521 auth_sae_retransmit_timer, hapd, sta);
524 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
525 eloop_register_timeout(0,
526 hapd->dot11RSNASAERetransPeriod * 1000,
527 auth_sae_retransmit_timer, hapd, sta);
534 if (ret != WLAN_STATUS_SUCCESS)
535 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
539 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
541 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
545 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
546 struct sta_info *sta)
548 if (!(hapd->conf->mesh & MESH_ENABLED))
551 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
552 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
553 auth_sae_retransmit_timer, hapd, sta);
557 void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
559 sta->flags |= WLAN_STA_AUTH;
560 sta->auth_alg = WLAN_AUTH_SAE;
561 mlme_authenticate_indication(hapd, sta);
562 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
563 sta->sae->state = SAE_ACCEPTED;
564 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
565 sta->sae->pmk, sta->sae->pmkid);
569 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
570 const u8 *bssid, u8 auth_transaction)
574 if (auth_transaction != 1 && auth_transaction != 2)
575 return WLAN_STATUS_UNSPECIFIED_FAILURE;
577 switch (sta->sae->state) {
579 if (auth_transaction == 1) {
580 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
583 sta->sae->state = SAE_COMMITTED;
585 if (sae_process_commit(sta->sae) < 0)
586 return WLAN_STATUS_UNSPECIFIED_FAILURE;
589 * In mesh case, both Commit and Confirm can be sent
590 * immediately. In infrastructure BSS, only a single
591 * Authentication frame (Commit) is expected from the AP
592 * here and the second one (Confirm) will be sent once
593 * the STA has sent its second Authentication frame
596 if (hapd->conf->mesh & MESH_ENABLED) {
598 * Send both Commit and Confirm immediately
599 * based on SAE finite state machine
600 * Nothing -> Confirm transition.
602 ret = auth_sae_send_confirm(hapd, sta, bssid);
605 sta->sae->state = SAE_CONFIRMED;
608 * For infrastructure BSS, send only the Commit
609 * message now to get alternating sequence of
610 * Authentication frames between the AP and STA.
611 * Confirm will be sent in
612 * Commited -> Confirmed/Accepted transition
613 * when receiving Confirm from STA.
617 sae_set_retransmit_timer(hapd, sta);
619 hostapd_logger(hapd, sta->addr,
620 HOSTAPD_MODULE_IEEE80211,
622 "SAE confirm before commit");
626 sae_clear_retransmit_timer(hapd, sta);
627 if (auth_transaction == 1) {
628 if (sae_process_commit(sta->sae) < 0)
629 return WLAN_STATUS_UNSPECIFIED_FAILURE;
631 ret = auth_sae_send_confirm(hapd, sta, bssid);
634 sta->sae->state = SAE_CONFIRMED;
636 sae_set_retransmit_timer(hapd, sta);
637 } else if (hapd->conf->mesh & MESH_ENABLED) {
639 * In mesh case, follow SAE finite state machine and
640 * send Commit now, if sync count allows.
642 if (sae_check_big_sync(sta))
643 return WLAN_STATUS_SUCCESS;
646 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
650 sae_set_retransmit_timer(hapd, sta);
653 * For instructure BSS, send the postponed Confirm from
654 * Nothing -> Confirmed transition that was reduced to
655 * Nothing -> Committed above.
657 ret = auth_sae_send_confirm(hapd, sta, bssid);
661 sta->sae->state = SAE_CONFIRMED;
664 * Since this was triggered on Confirm RX, run another
665 * step to get to Accepted without waiting for
668 return sae_sm_step(hapd, sta, bssid, auth_transaction);
672 sae_clear_retransmit_timer(hapd, sta);
673 if (auth_transaction == 1) {
674 if (sae_check_big_sync(sta))
675 return WLAN_STATUS_SUCCESS;
678 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
682 if (sae_process_commit(sta->sae) < 0)
683 return WLAN_STATUS_UNSPECIFIED_FAILURE;
685 ret = auth_sae_send_confirm(hapd, sta, bssid);
689 sae_set_retransmit_timer(hapd, sta);
691 sae_accept_sta(hapd, sta);
695 if (auth_transaction == 1) {
696 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
697 ") doing reauthentication",
699 ap_free_sta(hapd, sta);
700 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
702 if (sae_check_big_sync(sta))
703 return WLAN_STATUS_SUCCESS;
706 ret = auth_sae_send_confirm(hapd, sta, bssid);
707 sae_clear_temp_data(sta->sae);
713 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
715 return WLAN_STATUS_UNSPECIFIED_FAILURE;
717 return WLAN_STATUS_SUCCESS;
721 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
722 const struct ieee80211_mgmt *mgmt, size_t len,
723 u16 auth_transaction, u16 status_code)
725 int resp = WLAN_STATUS_SUCCESS;
726 struct wpabuf *data = NULL;
729 if (auth_transaction != 1 ||
730 status_code != WLAN_STATUS_SUCCESS) {
734 sta->sae = os_zalloc(sizeof(*sta->sae));
739 sta->sae->state = SAE_NOTHING;
743 if (sta->mesh_sae_pmksa_caching) {
744 wpa_printf(MSG_DEBUG,
745 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
746 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
747 sta->mesh_sae_pmksa_caching = 0;
750 if (auth_transaction == 1) {
751 const u8 *token = NULL, *pos, *end;
752 size_t token_len = 0;
753 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
755 "start SAE authentication (RX commit, status=%u)",
758 if ((hapd->conf->mesh & MESH_ENABLED) &&
759 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
761 pos = mgmt->u.auth.variable;
762 end = ((const u8 *) mgmt) + len;
763 if (pos + sizeof(le16) > end) {
764 wpa_printf(MSG_ERROR,
765 "SAE: Too short anti-clogging token request");
766 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
769 resp = sae_group_allowed(sta->sae,
770 hapd->conf->sae_groups,
772 if (resp != WLAN_STATUS_SUCCESS) {
773 wpa_printf(MSG_ERROR,
774 "SAE: Invalid group in anti-clogging token request");
779 wpabuf_free(sta->sae->tmp->anti_clogging_token);
780 sta->sae->tmp->anti_clogging_token =
781 wpabuf_alloc_copy(pos, end - pos);
782 if (sta->sae->tmp->anti_clogging_token == NULL) {
783 wpa_printf(MSG_ERROR,
784 "SAE: Failed to alloc for anti-clogging token");
785 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
790 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
791 * is 76, a new Commit Message shall be constructed
792 * with the Anti-Clogging Token from the received
793 * Authentication frame, and the commit-scalar and
794 * COMMIT-ELEMENT previously sent.
796 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
797 if (resp != WLAN_STATUS_SUCCESS) {
798 wpa_printf(MSG_ERROR,
799 "SAE: Failed to send commit message");
802 sta->sae->state = SAE_COMMITTED;
804 sae_set_retransmit_timer(hapd, sta);
808 if (status_code != WLAN_STATUS_SUCCESS)
811 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
812 ((const u8 *) mgmt) + len -
813 mgmt->u.auth.variable, &token,
814 &token_len, hapd->conf->sae_groups);
815 if (resp == SAE_SILENTLY_DISCARD) {
816 wpa_printf(MSG_DEBUG,
817 "SAE: Drop commit message from " MACSTR " due to reflection attack",
821 if (token && check_sae_token(hapd, sta->addr, token, token_len)
823 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
824 "incorrect token from " MACSTR,
826 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
830 if (resp != WLAN_STATUS_SUCCESS)
833 if (!token && use_sae_anti_clogging(hapd)) {
834 wpa_printf(MSG_DEBUG,
835 "SAE: Request anti-clogging token from "
836 MACSTR, MAC2STR(sta->addr));
837 data = auth_build_token_req(hapd, sta->sae->group,
839 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
840 if (hapd->conf->mesh & MESH_ENABLED)
841 sta->sae->state = SAE_NOTHING;
845 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
846 } else if (auth_transaction == 2) {
847 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
849 "SAE authentication (RX confirm, status=%u)",
851 if (status_code != WLAN_STATUS_SUCCESS)
853 if (sta->sae->state >= SAE_CONFIRMED ||
854 !(hapd->conf->mesh & MESH_ENABLED)) {
855 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
856 ((u8 *) mgmt) + len -
857 mgmt->u.auth.variable) < 0) {
858 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
862 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
864 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
866 "unexpected SAE authentication transaction %u (status=%u)",
867 auth_transaction, status_code);
868 if (status_code != WLAN_STATUS_SUCCESS)
870 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
874 if (resp != WLAN_STATUS_SUCCESS) {
875 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
876 auth_transaction, resp,
877 data ? wpabuf_head(data) : (u8 *) "",
878 data ? wpabuf_len(data) : 0);
882 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
883 status_code != WLAN_STATUS_SUCCESS)) {
884 hostapd_drv_sta_remove(hapd, sta->addr);
885 sta->added_unassoc = 0;
892 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
893 * @hapd: BSS data for the device initiating the authentication
894 * @sta: the peer to which commit authentication frame is sent
896 * This function implements Init event handling (IEEE Std 802.11-2012,
897 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
898 * sta->sae structure should be initialized appropriately via a call to
899 * sae_prepare_commit().
901 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
905 if (!sta->sae || !sta->sae->tmp)
908 if (sta->sae->state != SAE_NOTHING)
911 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
915 sta->sae->state = SAE_COMMITTED;
917 sae_set_retransmit_timer(hapd, sta);
922 #endif /* CONFIG_SAE */
925 static void handle_auth(struct hostapd_data *hapd,
926 const struct ieee80211_mgmt *mgmt, size_t len)
928 u16 auth_alg, auth_transaction, status_code;
929 u16 resp = WLAN_STATUS_SUCCESS;
930 struct sta_info *sta = NULL;
933 const u8 *challenge = NULL;
934 u32 session_timeout, acct_interim_interval;
935 struct vlan_description vlan_id;
936 struct hostapd_sta_wpa_psk_short *psk = NULL;
937 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
938 size_t resp_ies_len = 0;
939 char *identity = NULL;
940 char *radius_cui = NULL;
943 os_memset(&vlan_id, 0, sizeof(vlan_id));
945 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
946 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
947 (unsigned long) len);
951 #ifdef CONFIG_TESTING_OPTIONS
952 if (hapd->iconf->ignore_auth_probability > 0.0 &&
953 drand48() < hapd->iconf->ignore_auth_probability) {
955 "TESTING: ignoring auth frame from " MACSTR,
959 #endif /* CONFIG_TESTING_OPTIONS */
961 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
962 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
963 status_code = le_to_host16(mgmt->u.auth.status_code);
964 fc = le_to_host16(mgmt->frame_control);
965 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
967 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
968 2 + WLAN_AUTH_CHALLENGE_LEN &&
969 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
970 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
971 challenge = &mgmt->u.auth.variable[2];
973 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
974 "auth_transaction=%d status_code=%d wep=%d%s "
976 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
977 status_code, !!(fc & WLAN_FC_ISWEP),
978 challenge ? " challenge" : "",
979 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
982 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
984 "Unsupported authentication algorithm (%d)",
986 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
989 #endif /* CONFIG_NO_RC4 */
991 if (hapd->tkip_countermeasures) {
992 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
996 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
997 auth_alg == WLAN_AUTH_OPEN) ||
998 #ifdef CONFIG_IEEE80211R
999 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
1000 auth_alg == WLAN_AUTH_FT) ||
1001 #endif /* CONFIG_IEEE80211R */
1003 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1004 auth_alg == WLAN_AUTH_SAE) ||
1005 #endif /* CONFIG_SAE */
1006 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1007 auth_alg == WLAN_AUTH_SHARED_KEY))) {
1008 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1010 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1014 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
1015 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
1016 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1018 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1022 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
1023 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1025 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1029 if (hapd->conf->no_auth_if_seen_on) {
1030 struct hostapd_data *other;
1032 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1033 hapd->conf->no_auth_if_seen_on);
1037 u8 op_class, channel, phytype;
1039 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1040 MACSTR " since STA has been seen on %s",
1041 hapd->conf->iface, MAC2STR(mgmt->sa),
1042 hapd->conf->no_auth_if_seen_on);
1044 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1046 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1048 os_memcpy(pos, other->own_addr, ETH_ALEN);
1050 info = 0; /* TODO: BSSID Information */
1051 WPA_PUT_LE32(pos, info);
1053 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1054 phytype = 8; /* dmg */
1055 else if (other->iconf->ieee80211ac)
1056 phytype = 9; /* vht */
1057 else if (other->iconf->ieee80211n)
1058 phytype = 7; /* ht */
1059 else if (other->iconf->hw_mode ==
1060 HOSTAPD_MODE_IEEE80211A)
1061 phytype = 4; /* ofdm */
1062 else if (other->iconf->hw_mode ==
1063 HOSTAPD_MODE_IEEE80211G)
1064 phytype = 6; /* erp */
1066 phytype = 5; /* hrdsss */
1067 if (ieee80211_freq_to_channel_ext(
1068 hostapd_hw_get_freq(other,
1069 other->iconf->channel),
1070 other->iconf->secondary_channel,
1071 other->iconf->ieee80211ac,
1072 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1074 channel = other->iconf->channel;
1079 resp_ies_len = pos - &resp_ies[0];
1084 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1086 &acct_interim_interval, &vlan_id,
1087 &psk, &identity, &radius_cui);
1089 if (res == HOSTAPD_ACL_REJECT) {
1090 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1092 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1095 if (res == HOSTAPD_ACL_PENDING) {
1096 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1097 " waiting for an external authentication",
1099 /* Authentication code will re-send the authentication frame
1100 * after it has received (and cached) information from the
1101 * external source. */
1105 sta = ap_get_sta(hapd, mgmt->sa);
1107 if ((fc & WLAN_FC_RETRY) &&
1108 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1109 sta->last_seq_ctrl == seq_ctrl &&
1110 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1111 hostapd_logger(hapd, sta->addr,
1112 HOSTAPD_MODULE_IEEE80211,
1113 HOSTAPD_LEVEL_DEBUG,
1114 "Drop repeated authentication frame seq_ctrl=0x%x",
1119 if ((hapd->conf->mesh & MESH_ENABLED) &&
1120 sta->plink_state == PLINK_BLOCKED) {
1121 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1122 " is blocked - drop Authentication frame",
1126 #endif /* CONFIG_MESH */
1129 if (hapd->conf->mesh & MESH_ENABLED) {
1130 /* if the mesh peer is not available, we don't do auth.
1132 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1133 " not yet known - drop Authentication frame",
1136 * Save a copy of the frame so that it can be processed
1137 * if a new peer entry is added shortly after this.
1139 wpabuf_free(hapd->mesh_pending_auth);
1140 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1141 os_get_reltime(&hapd->mesh_pending_auth_time);
1144 #endif /* CONFIG_MESH */
1146 sta = ap_sta_add(hapd, mgmt->sa);
1148 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1152 sta->last_seq_ctrl = seq_ctrl;
1153 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1155 if (vlan_id.notempty &&
1156 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1157 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1159 "Invalid VLAN %d%s received from RADIUS server",
1161 vlan_id.tagged[0] ? "+" : "");
1162 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1165 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1166 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1170 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1171 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1173 hostapd_free_psk_list(sta->psk);
1174 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1181 sta->identity = identity;
1183 sta->radius_cui = radius_cui;
1186 sta->flags &= ~WLAN_STA_PREAUTH;
1187 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1189 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1190 sta->acct_interim_interval = acct_interim_interval;
1191 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1192 ap_sta_session_timeout(hapd, sta, session_timeout);
1194 ap_sta_no_session_timeout(hapd, sta);
1197 * If the driver supports full AP client state, add a station to the
1198 * driver before sending authentication reply to make sure the driver
1199 * has resources, and not to go through the entire authentication and
1200 * association handshake, and fail it at the end.
1202 * If this is not the first transaction, in a multi-step authentication
1203 * algorithm, the station already exists in the driver
1204 * (sta->added_unassoc = 1) so skip it.
1206 * In mesh mode, the station was already added to the driver when the
1207 * NEW_PEER_CANDIDATE event is received.
1209 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1210 !(hapd->conf->mesh & MESH_ENABLED) &&
1211 !(sta->added_unassoc)) {
1213 * If a station that is already associated to the AP, is trying
1214 * to authenticate again, remove the STA entry, in order to make
1215 * sure the STA PS state gets cleared and configuration gets
1216 * updated. To handle this, station's added_unassoc flag is
1217 * cleared once the station has completed association.
1219 hostapd_drv_sta_remove(hapd, sta->addr);
1220 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1221 WLAN_STA_AUTHORIZED);
1223 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1224 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
1225 hostapd_logger(hapd, sta->addr,
1226 HOSTAPD_MODULE_IEEE80211,
1227 HOSTAPD_LEVEL_NOTICE,
1228 "Could not add STA to kernel driver");
1229 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1233 sta->added_unassoc = 1;
1237 case WLAN_AUTH_OPEN:
1238 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1239 HOSTAPD_LEVEL_DEBUG,
1240 "authentication OK (open system)");
1241 sta->flags |= WLAN_STA_AUTH;
1242 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1243 sta->auth_alg = WLAN_AUTH_OPEN;
1244 mlme_authenticate_indication(hapd, sta);
1246 #ifndef CONFIG_NO_RC4
1247 case WLAN_AUTH_SHARED_KEY:
1248 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1249 fc & WLAN_FC_ISWEP);
1250 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1251 mlme_authenticate_indication(hapd, sta);
1252 if (sta->challenge && auth_transaction == 1) {
1253 resp_ies[0] = WLAN_EID_CHALLENGE;
1254 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1255 os_memcpy(resp_ies + 2, sta->challenge,
1256 WLAN_AUTH_CHALLENGE_LEN);
1257 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1260 #endif /* CONFIG_NO_RC4 */
1261 #ifdef CONFIG_IEEE80211R
1263 sta->auth_alg = WLAN_AUTH_FT;
1264 if (sta->wpa_sm == NULL)
1265 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1267 if (sta->wpa_sm == NULL) {
1268 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1270 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1273 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1274 auth_transaction, mgmt->u.auth.variable,
1275 len - IEEE80211_HDRLEN -
1276 sizeof(mgmt->u.auth),
1277 handle_auth_ft_finish, hapd);
1278 /* handle_auth_ft_finish() callback will complete auth. */
1280 #endif /* CONFIG_IEEE80211R */
1284 if (status_code == WLAN_STATUS_SUCCESS &&
1285 hapd->conf->mesh & MESH_ENABLED) {
1286 if (sta->wpa_sm == NULL)
1288 wpa_auth_sta_init(hapd->wpa_auth,
1290 if (sta->wpa_sm == NULL) {
1291 wpa_printf(MSG_DEBUG,
1292 "SAE: Failed to initialize WPA state machine");
1293 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1297 #endif /* CONFIG_MESH */
1298 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1301 #endif /* CONFIG_SAE */
1306 os_free(radius_cui);
1307 hostapd_free_psk_list(psk);
1309 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1310 auth_transaction + 1, resp, resp_ies,
1313 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1314 reply_res != WLAN_STATUS_SUCCESS)) {
1315 hostapd_drv_sta_remove(hapd, sta->addr);
1316 sta->added_unassoc = 0;
1321 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1325 /* get a unique AID */
1327 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1331 for (i = 0; i < AID_WORDS; i++) {
1332 if (hapd->sta_aid[i] == (u32) -1)
1334 for (j = 0; j < 32; j++) {
1335 if (!(hapd->sta_aid[i] & BIT(j)))
1343 aid = i * 32 + j + 1;
1348 hapd->sta_aid[i] |= BIT(j);
1349 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1354 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1355 const u8 *ssid_ie, size_t ssid_ie_len)
1357 if (ssid_ie == NULL)
1358 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1360 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1361 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1362 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1364 "Station tried to associate with unknown SSID "
1365 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1366 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1369 return WLAN_STATUS_SUCCESS;
1373 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1374 const u8 *wmm_ie, size_t wmm_ie_len)
1376 sta->flags &= ~WLAN_STA_WMM;
1378 if (wmm_ie && hapd->conf->wmm_enabled) {
1379 struct wmm_information_element *wmm;
1381 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1382 hostapd_logger(hapd, sta->addr,
1384 HOSTAPD_LEVEL_DEBUG,
1385 "invalid WMM element in association "
1387 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1390 sta->flags |= WLAN_STA_WMM;
1391 wmm = (struct wmm_information_element *) wmm_ie;
1392 sta->qosinfo = wmm->qos_info;
1394 return WLAN_STATUS_SUCCESS;
1398 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1399 struct ieee802_11_elems *elems)
1401 if (!elems->supp_rates) {
1402 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1403 HOSTAPD_LEVEL_DEBUG,
1404 "No supported rates element in AssocReq");
1405 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1408 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1409 sizeof(sta->supported_rates)) {
1410 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1411 HOSTAPD_LEVEL_DEBUG,
1412 "Invalid supported rates element length %d+%d",
1413 elems->supp_rates_len,
1414 elems->ext_supp_rates_len);
1415 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1418 sta->supported_rates_len = merge_byte_arrays(
1419 sta->supported_rates, sizeof(sta->supported_rates),
1420 elems->supp_rates, elems->supp_rates_len,
1421 elems->ext_supp_rates, elems->ext_supp_rates_len);
1423 return WLAN_STATUS_SUCCESS;
1427 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1428 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1430 #ifdef CONFIG_INTERWORKING
1431 /* check for QoS Map support */
1432 if (ext_capab_ie_len >= 5) {
1433 if (ext_capab_ie[4] & 0x01)
1434 sta->qos_map_enabled = 1;
1436 #endif /* CONFIG_INTERWORKING */
1438 if (ext_capab_ie_len > 0)
1439 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1441 return WLAN_STATUS_SUCCESS;
1445 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1446 const u8 *ies, size_t ies_len, int reassoc)
1448 struct ieee802_11_elems elems;
1452 const u8 *p2p_dev_addr = NULL;
1454 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1455 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1456 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1457 "association request");
1458 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1461 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1462 if (resp != WLAN_STATUS_SUCCESS)
1464 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1465 if (resp != WLAN_STATUS_SUCCESS)
1467 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1468 if (resp != WLAN_STATUS_SUCCESS)
1470 resp = copy_supp_rates(hapd, sta, &elems);
1471 if (resp != WLAN_STATUS_SUCCESS)
1473 #ifdef CONFIG_IEEE80211N
1474 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1475 if (resp != WLAN_STATUS_SUCCESS)
1477 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1478 !(sta->flags & WLAN_STA_HT)) {
1479 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1480 HOSTAPD_LEVEL_INFO, "Station does not support "
1481 "mandatory HT PHY - reject association");
1482 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1484 #endif /* CONFIG_IEEE80211N */
1486 #ifdef CONFIG_IEEE80211AC
1487 if (hapd->iconf->ieee80211ac) {
1488 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1489 if (resp != WLAN_STATUS_SUCCESS)
1492 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1493 if (resp != WLAN_STATUS_SUCCESS)
1497 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1498 !(sta->flags & WLAN_STA_VHT)) {
1499 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1500 HOSTAPD_LEVEL_INFO, "Station does not support "
1501 "mandatory VHT PHY - reject association");
1502 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1505 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1506 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1507 elems.vendor_vht_len);
1508 if (resp != WLAN_STATUS_SUCCESS)
1511 #endif /* CONFIG_IEEE80211AC */
1515 wpabuf_free(sta->p2p_ie);
1516 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1517 P2P_IE_VENDOR_TYPE);
1519 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1521 wpabuf_free(sta->p2p_ie);
1524 #endif /* CONFIG_P2P */
1526 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1527 wpa_ie = elems.rsn_ie;
1528 wpa_ie_len = elems.rsn_ie_len;
1529 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1531 wpa_ie = elems.wpa_ie;
1532 wpa_ie_len = elems.wpa_ie_len;
1539 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1540 if (hapd->conf->wps_state && elems.wps_ie) {
1541 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1542 "Request - assume WPS is used");
1543 sta->flags |= WLAN_STA_WPS;
1544 wpabuf_free(sta->wps_ie);
1545 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1546 WPS_IE_VENDOR_TYPE);
1547 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1548 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1549 sta->flags |= WLAN_STA_WPS2;
1553 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1554 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1555 "(Re)Association Request - reject");
1556 return WLAN_STATUS_INVALID_IE;
1558 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1559 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1560 "(Re)Association Request - possible WPS use");
1561 sta->flags |= WLAN_STA_MAYBE_WPS;
1563 #endif /* CONFIG_WPS */
1564 if (hapd->conf->wpa && wpa_ie == NULL) {
1565 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1567 "No WPA/RSN IE in association request");
1568 return WLAN_STATUS_INVALID_IE;
1571 if (hapd->conf->wpa && wpa_ie) {
1575 if (sta->wpa_sm == NULL)
1576 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1579 if (sta->wpa_sm == NULL) {
1580 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1582 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1584 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1586 elems.mdie, elems.mdie_len);
1587 if (res == WPA_INVALID_GROUP)
1588 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1589 else if (res == WPA_INVALID_PAIRWISE)
1590 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1591 else if (res == WPA_INVALID_AKMP)
1592 resp = WLAN_STATUS_AKMP_NOT_VALID;
1593 else if (res == WPA_ALLOC_FAIL)
1594 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1595 #ifdef CONFIG_IEEE80211W
1596 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1597 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1598 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1599 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1600 #endif /* CONFIG_IEEE80211W */
1601 else if (res == WPA_INVALID_MDIE)
1602 resp = WLAN_STATUS_INVALID_MDIE;
1603 else if (res != WPA_IE_OK)
1604 resp = WLAN_STATUS_INVALID_IE;
1605 if (resp != WLAN_STATUS_SUCCESS)
1607 #ifdef CONFIG_IEEE80211W
1608 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1609 sta->sa_query_count > 0)
1610 ap_check_sa_query_timeout(hapd, sta);
1611 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1612 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1614 * STA has already been associated with MFP and SA
1615 * Query timeout has not been reached. Reject the
1616 * association attempt temporarily and start SA Query,
1617 * if one is not pending.
1620 if (sta->sa_query_count == 0)
1621 ap_sta_start_sa_query(hapd, sta);
1623 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1626 if (wpa_auth_uses_mfp(sta->wpa_sm))
1627 sta->flags |= WLAN_STA_MFP;
1629 sta->flags &= ~WLAN_STA_MFP;
1630 #endif /* CONFIG_IEEE80211W */
1632 #ifdef CONFIG_IEEE80211R
1633 if (sta->auth_alg == WLAN_AUTH_FT) {
1635 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1636 "to use association (not "
1637 "re-association) with FT auth_alg",
1638 MAC2STR(sta->addr));
1639 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1642 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1644 if (resp != WLAN_STATUS_SUCCESS)
1647 #endif /* CONFIG_IEEE80211R */
1650 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1651 sta->auth_alg == WLAN_AUTH_OPEN) {
1652 struct rsn_pmksa_cache_entry *sa;
1653 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1654 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1655 wpa_printf(MSG_DEBUG,
1656 "SAE: No PMKSA cache entry found for "
1657 MACSTR, MAC2STR(sta->addr));
1658 return WLAN_STATUS_INVALID_PMKID;
1660 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1661 " using PMKSA caching", MAC2STR(sta->addr));
1662 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1663 sta->auth_alg != WLAN_AUTH_SAE &&
1664 !(sta->auth_alg == WLAN_AUTH_FT &&
1665 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1666 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1667 "SAE AKM after non-SAE auth_alg %u",
1668 MAC2STR(sta->addr), sta->auth_alg);
1669 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1671 #endif /* CONFIG_SAE */
1673 #ifdef CONFIG_IEEE80211N
1674 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1675 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1676 hostapd_logger(hapd, sta->addr,
1677 HOSTAPD_MODULE_IEEE80211,
1679 "Station tried to use TKIP with HT "
1681 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1683 #endif /* CONFIG_IEEE80211N */
1685 } else if (hapd->conf->osen) {
1686 if (elems.osen == NULL) {
1688 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1690 "No HS 2.0 OSEN element in association request");
1691 return WLAN_STATUS_INVALID_IE;
1694 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1695 if (sta->wpa_sm == NULL)
1696 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1698 if (sta->wpa_sm == NULL) {
1699 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1701 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1703 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1704 elems.osen - 2, elems.osen_len + 2) < 0)
1705 return WLAN_STATUS_INVALID_IE;
1706 #endif /* CONFIG_HS20 */
1708 wpa_auth_sta_no_wpa(sta->wpa_sm);
1711 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1712 #endif /* CONFIG_P2P */
1715 wpabuf_free(sta->hs20_ie);
1716 if (elems.hs20 && elems.hs20_len > 4) {
1717 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1718 elems.hs20_len - 4);
1720 sta->hs20_ie = NULL;
1721 #endif /* CONFIG_HS20 */
1724 wpabuf_free(sta->mb_ies);
1725 if (hapd->iface->fst)
1726 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1729 #endif /* CONFIG_FST */
1732 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1734 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1735 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1736 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1737 wpa_printf(MSG_INFO,
1738 "MBO: Reject WPA2 association without PMF");
1739 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1741 #endif /* CONFIG_MBO */
1743 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
1744 elems.supp_op_classes_len);
1746 return WLAN_STATUS_SUCCESS;
1750 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1754 struct ieee80211_mgmt reply;
1756 os_memset(&reply, 0, sizeof(reply));
1757 reply.frame_control =
1758 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1759 os_memcpy(reply.da, addr, ETH_ALEN);
1760 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1761 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1763 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1764 reply.u.deauth.reason_code = host_to_le16(reason_code);
1766 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1767 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1772 static int add_associated_sta(struct hostapd_data *hapd,
1773 struct sta_info *sta)
1775 struct ieee80211_ht_capabilities ht_cap;
1776 struct ieee80211_vht_capabilities vht_cap;
1779 * Remove the STA entry to ensure the STA PS state gets cleared and
1780 * configuration gets updated. This is relevant for cases, such as
1781 * FT-over-the-DS, where a station re-associates back to the same AP but
1782 * skips the authentication flow, or if working with a driver that
1783 * does not support full AP client state.
1785 if (!sta->added_unassoc)
1786 hostapd_drv_sta_remove(hapd, sta->addr);
1788 #ifdef CONFIG_IEEE80211N
1789 if (sta->flags & WLAN_STA_HT)
1790 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1791 #endif /* CONFIG_IEEE80211N */
1792 #ifdef CONFIG_IEEE80211AC
1793 if (sta->flags & WLAN_STA_VHT)
1794 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1795 #endif /* CONFIG_IEEE80211AC */
1798 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1799 * will be set when the ACK frame for the (Re)Association Response frame
1800 * is processed (TX status driver event).
1802 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1803 sta->supported_rates, sta->supported_rates_len,
1804 sta->listen_interval,
1805 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1806 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1807 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1808 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
1809 sta->added_unassoc)) {
1810 hostapd_logger(hapd, sta->addr,
1811 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1812 "Could not %s STA to kernel driver",
1813 sta->added_unassoc ? "set" : "add");
1815 if (sta->added_unassoc) {
1816 hostapd_drv_sta_remove(hapd, sta->addr);
1817 sta->added_unassoc = 0;
1823 sta->added_unassoc = 0;
1829 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1830 u16 status_code, int reassoc, const u8 *ies,
1834 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1835 struct ieee80211_mgmt *reply;
1838 os_memset(buf, 0, sizeof(buf));
1839 reply = (struct ieee80211_mgmt *) buf;
1840 reply->frame_control =
1841 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1842 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1843 WLAN_FC_STYPE_ASSOC_RESP));
1844 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1845 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1846 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1848 send_len = IEEE80211_HDRLEN;
1849 send_len += sizeof(reply->u.assoc_resp);
1850 reply->u.assoc_resp.capab_info =
1851 host_to_le16(hostapd_own_capab_info(hapd));
1852 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1853 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1854 /* Supported rates */
1855 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1856 /* Extended supported rates */
1857 p = hostapd_eid_ext_supp_rates(hapd, p);
1859 #ifdef CONFIG_IEEE80211R
1860 if (status_code == WLAN_STATUS_SUCCESS) {
1861 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1862 * Transition Information, RSN, [RIC Response] */
1863 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1864 buf + sizeof(buf) - p,
1865 sta->auth_alg, ies, ies_len);
1867 #endif /* CONFIG_IEEE80211R */
1869 #ifdef CONFIG_IEEE80211W
1870 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1871 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1872 #endif /* CONFIG_IEEE80211W */
1874 #ifdef CONFIG_IEEE80211N
1875 p = hostapd_eid_ht_capabilities(hapd, p);
1876 p = hostapd_eid_ht_operation(hapd, p);
1877 #endif /* CONFIG_IEEE80211N */
1879 #ifdef CONFIG_IEEE80211AC
1880 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1881 p = hostapd_eid_vht_capabilities(hapd, p);
1882 p = hostapd_eid_vht_operation(hapd, p);
1884 #endif /* CONFIG_IEEE80211AC */
1886 p = hostapd_eid_ext_capab(hapd, p);
1887 p = hostapd_eid_bss_max_idle_period(hapd, p);
1888 if (sta->qos_map_enabled)
1889 p = hostapd_eid_qos_map_set(hapd, p);
1892 if (hapd->iface->fst_ies) {
1893 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1894 wpabuf_len(hapd->iface->fst_ies));
1895 p += wpabuf_len(hapd->iface->fst_ies);
1897 #endif /* CONFIG_FST */
1899 #ifdef CONFIG_IEEE80211AC
1900 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1901 p = hostapd_eid_vendor_vht(hapd, p);
1902 #endif /* CONFIG_IEEE80211AC */
1904 if (sta->flags & WLAN_STA_WMM)
1905 p = hostapd_eid_wmm(hapd, p);
1908 if ((sta->flags & WLAN_STA_WPS) ||
1909 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1910 struct wpabuf *wps = wps_build_assoc_resp_ie();
1912 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1913 p += wpabuf_len(wps);
1917 #endif /* CONFIG_WPS */
1920 if (sta->p2p_ie && hapd->p2p_group) {
1921 struct wpabuf *p2p_resp_ie;
1922 enum p2p_status_code status;
1923 switch (status_code) {
1924 case WLAN_STATUS_SUCCESS:
1925 status = P2P_SC_SUCCESS;
1927 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1928 status = P2P_SC_FAIL_LIMIT_REACHED;
1931 status = P2P_SC_FAIL_INVALID_PARAMS;
1934 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1936 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1937 wpabuf_len(p2p_resp_ie));
1938 p += wpabuf_len(p2p_resp_ie);
1939 wpabuf_free(p2p_resp_ie);
1942 #endif /* CONFIG_P2P */
1944 #ifdef CONFIG_P2P_MANAGER
1945 if (hapd->conf->p2p & P2P_MANAGE)
1946 p = hostapd_eid_p2p_manage(hapd, p);
1947 #endif /* CONFIG_P2P_MANAGER */
1949 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1951 send_len += p - reply->u.assoc_resp.variable;
1953 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
1954 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1956 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1959 return WLAN_STATUS_SUCCESS;
1963 static void handle_assoc(struct hostapd_data *hapd,
1964 const struct ieee80211_mgmt *mgmt, size_t len,
1967 u16 capab_info, listen_interval, seq_ctrl, fc;
1968 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
1971 struct sta_info *sta;
1973 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1974 sizeof(mgmt->u.assoc_req))) {
1975 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1976 reassoc, (unsigned long) len);
1980 #ifdef CONFIG_TESTING_OPTIONS
1982 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1983 drand48() < hapd->iconf->ignore_reassoc_probability) {
1984 wpa_printf(MSG_INFO,
1985 "TESTING: ignoring reassoc request from "
1986 MACSTR, MAC2STR(mgmt->sa));
1990 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1991 drand48() < hapd->iconf->ignore_assoc_probability) {
1992 wpa_printf(MSG_INFO,
1993 "TESTING: ignoring assoc request from "
1994 MACSTR, MAC2STR(mgmt->sa));
1998 #endif /* CONFIG_TESTING_OPTIONS */
2000 fc = le_to_host16(mgmt->frame_control);
2001 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2004 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
2005 listen_interval = le_to_host16(
2006 mgmt->u.reassoc_req.listen_interval);
2007 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
2008 " capab_info=0x%02x listen_interval=%d current_ap="
2009 MACSTR " seq_ctrl=0x%x%s",
2010 MAC2STR(mgmt->sa), capab_info, listen_interval,
2011 MAC2STR(mgmt->u.reassoc_req.current_ap),
2012 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2013 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
2014 pos = mgmt->u.reassoc_req.variable;
2016 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2017 listen_interval = le_to_host16(
2018 mgmt->u.assoc_req.listen_interval);
2019 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
2020 " capab_info=0x%02x listen_interval=%d "
2022 MAC2STR(mgmt->sa), capab_info, listen_interval,
2023 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2024 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2025 pos = mgmt->u.assoc_req.variable;
2028 sta = ap_get_sta(hapd, mgmt->sa);
2029 #ifdef CONFIG_IEEE80211R
2030 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2031 (sta->flags & WLAN_STA_AUTH) == 0) {
2032 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2033 "prior to authentication since it is using "
2034 "over-the-DS FT", MAC2STR(mgmt->sa));
2037 * Mark station as authenticated, to avoid adding station
2038 * entry in the driver as associated and not authenticated
2040 sta->flags |= WLAN_STA_AUTH;
2042 #endif /* CONFIG_IEEE80211R */
2043 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2044 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2045 HOSTAPD_LEVEL_INFO, "Station tried to "
2046 "associate before authentication "
2047 "(aid=%d flags=0x%x)",
2048 sta ? sta->aid : -1,
2049 sta ? sta->flags : 0);
2050 send_deauth(hapd, mgmt->sa,
2051 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2055 if ((fc & WLAN_FC_RETRY) &&
2056 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2057 sta->last_seq_ctrl == seq_ctrl &&
2058 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2059 WLAN_FC_STYPE_ASSOC_REQ) {
2060 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2061 HOSTAPD_LEVEL_DEBUG,
2062 "Drop repeated association frame seq_ctrl=0x%x",
2066 sta->last_seq_ctrl = seq_ctrl;
2067 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2068 WLAN_FC_STYPE_ASSOC_REQ;
2070 if (hapd->tkip_countermeasures) {
2071 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2075 if (listen_interval > hapd->conf->max_listen_interval) {
2076 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2077 HOSTAPD_LEVEL_DEBUG,
2078 "Too large Listen Interval (%d)",
2080 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2085 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2086 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2089 #endif /* CONFIG_MBO */
2091 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2093 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2094 if (resp != WLAN_STATUS_SUCCESS)
2097 if (hostapd_get_aid(hapd, sta) < 0) {
2098 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2099 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2100 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2104 sta->capability = capab_info;
2105 sta->listen_interval = listen_interval;
2107 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2108 sta->flags |= WLAN_STA_NONERP;
2109 for (i = 0; i < sta->supported_rates_len; i++) {
2110 if ((sta->supported_rates[i] & 0x7f) > 22) {
2111 sta->flags &= ~WLAN_STA_NONERP;
2115 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2116 sta->nonerp_set = 1;
2117 hapd->iface->num_sta_non_erp++;
2118 if (hapd->iface->num_sta_non_erp == 1)
2119 ieee802_11_set_beacons(hapd->iface);
2122 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2123 !sta->no_short_slot_time_set) {
2124 sta->no_short_slot_time_set = 1;
2125 hapd->iface->num_sta_no_short_slot_time++;
2126 if (hapd->iface->current_mode->mode ==
2127 HOSTAPD_MODE_IEEE80211G &&
2128 hapd->iface->num_sta_no_short_slot_time == 1)
2129 ieee802_11_set_beacons(hapd->iface);
2132 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2133 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2135 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2137 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2138 !sta->no_short_preamble_set) {
2139 sta->no_short_preamble_set = 1;
2140 hapd->iface->num_sta_no_short_preamble++;
2141 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2142 && hapd->iface->num_sta_no_short_preamble == 1)
2143 ieee802_11_set_beacons(hapd->iface);
2146 #ifdef CONFIG_IEEE80211N
2147 update_ht_state(hapd, sta);
2148 #endif /* CONFIG_IEEE80211N */
2150 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2151 HOSTAPD_LEVEL_DEBUG,
2152 "association OK (aid %d)", sta->aid);
2153 /* Station will be marked associated, after it acknowledges AssocResp
2155 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2157 #ifdef CONFIG_IEEE80211W
2158 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2159 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2160 "SA Query procedure", reassoc ? "re" : "");
2161 /* TODO: Send a protected Disassociate frame to the STA using
2162 * the old key and Reason Code "Previous Authentication no
2163 * longer valid". Make sure this is only sent protected since
2164 * unprotected frame would be received by the STA that is now
2165 * trying to associate.
2168 #endif /* CONFIG_IEEE80211W */
2170 /* Make sure that the previously registered inactivity timer will not
2171 * remove the STA immediately. */
2172 sta->timeout_next = STA_NULLFUNC;
2176 * In case of a successful response, add the station to the driver.
2177 * Otherwise, the kernel may ignore Data frames before we process the
2178 * ACK frame (TX status). In case of a failure, this station will be
2181 * Note that this is not compliant with the IEEE 802.11 standard that
2182 * states that a non-AP station should transition into the
2183 * authenticated/associated state only after the station acknowledges
2184 * the (Re)Association Response frame. However, still do this as:
2186 * 1. In case the station does not acknowledge the (Re)Association
2187 * Response frame, it will be removed.
2188 * 2. Data frames will be dropped in the kernel until the station is
2189 * set into authorized state, and there are no significant known
2190 * issues with processing other non-Data Class 3 frames during this
2193 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2194 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2196 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2199 * Remove the station in case tranmission of a success response fails
2200 * (the STA was added associated to the driver) or if the station was
2201 * previously added unassociated.
2203 if ((reply_res != WLAN_STATUS_SUCCESS &&
2204 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2205 hostapd_drv_sta_remove(hapd, sta->addr);
2206 sta->added_unassoc = 0;
2211 static void handle_disassoc(struct hostapd_data *hapd,
2212 const struct ieee80211_mgmt *mgmt, size_t len)
2214 struct sta_info *sta;
2216 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2217 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2218 (unsigned long) len);
2222 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2224 le_to_host16(mgmt->u.disassoc.reason_code));
2226 sta = ap_get_sta(hapd, mgmt->sa);
2228 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2233 ap_sta_set_authorized(hapd, sta, 0);
2234 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2235 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2236 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2237 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2238 HOSTAPD_LEVEL_INFO, "disassociated");
2239 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2240 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2241 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2243 accounting_sta_stop(hapd, sta);
2244 ieee802_1x_free_station(hapd, sta);
2246 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2247 ap_sta_ip6addr_del(hapd, sta);
2248 hostapd_drv_sta_remove(hapd, sta->addr);
2249 sta->added_unassoc = 0;
2251 if (sta->timeout_next == STA_NULLFUNC ||
2252 sta->timeout_next == STA_DISASSOC) {
2253 sta->timeout_next = STA_DEAUTH;
2254 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2255 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2259 mlme_disassociate_indication(
2260 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2264 static void handle_deauth(struct hostapd_data *hapd,
2265 const struct ieee80211_mgmt *mgmt, size_t len)
2267 struct sta_info *sta;
2269 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2270 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2271 "payload (len=%lu)", (unsigned long) len);
2275 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2277 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2279 sta = ap_get_sta(hapd, mgmt->sa);
2281 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2282 "to deauthenticate, but it is not authenticated",
2287 ap_sta_set_authorized(hapd, sta, 0);
2288 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2289 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2290 WLAN_STA_ASSOC_REQ_OK);
2291 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2292 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2293 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2294 mlme_deauthenticate_indication(
2295 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2296 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2297 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2298 ap_free_sta(hapd, sta);
2302 static void handle_beacon(struct hostapd_data *hapd,
2303 const struct ieee80211_mgmt *mgmt, size_t len,
2304 struct hostapd_frame_info *fi)
2306 struct ieee802_11_elems elems;
2308 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2309 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2310 (unsigned long) len);
2314 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2315 len - (IEEE80211_HDRLEN +
2316 sizeof(mgmt->u.beacon)), &elems,
2319 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2323 #ifdef CONFIG_IEEE80211W
2325 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2326 const struct ieee80211_mgmt *mgmt,
2331 end = mgmt->u.action.u.sa_query_resp.trans_id +
2332 WLAN_SA_QUERY_TR_ID_LEN;
2333 if (((u8 *) mgmt) + len < end) {
2334 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2335 "frame (len=%lu)", (unsigned long) len);
2339 ieee802_11_sa_query_action(hapd, mgmt->sa,
2340 mgmt->u.action.u.sa_query_resp.action,
2341 mgmt->u.action.u.sa_query_resp.trans_id);
2346 static int robust_action_frame(u8 category)
2348 return category != WLAN_ACTION_PUBLIC &&
2349 category != WLAN_ACTION_HT;
2351 #endif /* CONFIG_IEEE80211W */
2354 static int handle_action(struct hostapd_data *hapd,
2355 const struct ieee80211_mgmt *mgmt, size_t len)
2357 struct sta_info *sta;
2358 sta = ap_get_sta(hapd, mgmt->sa);
2360 if (len < IEEE80211_HDRLEN + 1) {
2361 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2362 HOSTAPD_LEVEL_DEBUG,
2363 "handle_action - too short payload (len=%lu)",
2364 (unsigned long) len);
2368 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2369 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2370 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2371 "frame (category=%u) from unassociated STA " MACSTR,
2372 MAC2STR(mgmt->sa), mgmt->u.action.category);
2376 #ifdef CONFIG_IEEE80211W
2377 if (sta && (sta->flags & WLAN_STA_MFP) &&
2378 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2379 robust_action_frame(mgmt->u.action.category)) {
2380 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2381 HOSTAPD_LEVEL_DEBUG,
2382 "Dropped unprotected Robust Action frame from "
2386 #endif /* CONFIG_IEEE80211W */
2389 u16 fc = le_to_host16(mgmt->frame_control);
2390 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2392 if ((fc & WLAN_FC_RETRY) &&
2393 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2394 sta->last_seq_ctrl == seq_ctrl &&
2395 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2396 hostapd_logger(hapd, sta->addr,
2397 HOSTAPD_MODULE_IEEE80211,
2398 HOSTAPD_LEVEL_DEBUG,
2399 "Drop repeated action frame seq_ctrl=0x%x",
2404 sta->last_seq_ctrl = seq_ctrl;
2405 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2408 switch (mgmt->u.action.category) {
2409 #ifdef CONFIG_IEEE80211R
2410 case WLAN_ACTION_FT:
2412 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2413 len - IEEE80211_HDRLEN))
2416 #endif /* CONFIG_IEEE80211R */
2417 case WLAN_ACTION_WMM:
2418 hostapd_wmm_action(hapd, mgmt, len);
2420 #ifdef CONFIG_IEEE80211W
2421 case WLAN_ACTION_SA_QUERY:
2422 return hostapd_sa_query_action(hapd, mgmt, len);
2423 #endif /* CONFIG_IEEE80211W */
2425 case WLAN_ACTION_WNM:
2426 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2428 #endif /* CONFIG_WNM */
2430 case WLAN_ACTION_FST:
2431 if (hapd->iface->fst)
2432 fst_rx_action(hapd->iface->fst, mgmt, len);
2434 wpa_printf(MSG_DEBUG,
2435 "FST: Ignore FST Action frame - no FST attached");
2437 #endif /* CONFIG_FST */
2438 case WLAN_ACTION_PUBLIC:
2439 case WLAN_ACTION_PROTECTED_DUAL:
2440 #ifdef CONFIG_IEEE80211N
2441 if (len >= IEEE80211_HDRLEN + 2 &&
2442 mgmt->u.action.u.public_action.action ==
2443 WLAN_PA_20_40_BSS_COEX) {
2444 wpa_printf(MSG_DEBUG,
2445 "HT20/40 coex mgmt frame received from STA "
2446 MACSTR, MAC2STR(mgmt->sa));
2447 hostapd_2040_coex_action(hapd, mgmt, len);
2449 #endif /* CONFIG_IEEE80211N */
2450 if (hapd->public_action_cb) {
2451 hapd->public_action_cb(hapd->public_action_cb_ctx,
2455 if (hapd->public_action_cb2) {
2456 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2460 if (hapd->public_action_cb || hapd->public_action_cb2)
2463 case WLAN_ACTION_VENDOR_SPECIFIC:
2464 if (hapd->vendor_action_cb) {
2465 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2467 hapd->iface->freq) == 0)
2473 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2474 HOSTAPD_LEVEL_DEBUG,
2475 "handle_action - unknown action category %d or invalid "
2477 mgmt->u.action.category);
2478 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2479 !(mgmt->sa[0] & 0x01)) {
2480 struct ieee80211_mgmt *resp;
2483 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2484 * Return the Action frame to the source without change
2485 * except that MSB of the Category set to 1.
2487 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2488 "frame back to sender");
2489 resp = os_malloc(len);
2492 os_memcpy(resp, mgmt, len);
2493 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2494 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2495 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2496 resp->u.action.category |= 0x80;
2498 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2499 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2510 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2511 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2513 * @buf: management frame data (starting from IEEE 802.11 header)
2514 * @len: length of frame data in octets
2515 * @fi: meta data about received frame (signal level, etc.)
2517 * Process all incoming IEEE 802.11 management frames. This will be called for
2518 * each frame received from the kernel driver through wlan#ap interface. In
2519 * addition, it can be called to re-inserted pending frames (e.g., when using
2520 * external RADIUS server as an MAC ACL).
2522 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2523 struct hostapd_frame_info *fi)
2525 struct ieee80211_mgmt *mgmt;
2533 mgmt = (struct ieee80211_mgmt *) buf;
2534 fc = le_to_host16(mgmt->frame_control);
2535 stype = WLAN_FC_GET_STYPE(fc);
2537 if (stype == WLAN_FC_STYPE_BEACON) {
2538 handle_beacon(hapd, mgmt, len, fi);
2542 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2543 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2544 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2548 /* Invitation responses can be sent with the peer MAC as BSSID */
2549 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2550 stype == WLAN_FC_STYPE_ACTION) &&
2551 #endif /* CONFIG_P2P */
2553 !(hapd->conf->mesh & MESH_ENABLED) &&
2554 #endif /* CONFIG_MESH */
2555 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2556 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2557 MAC2STR(mgmt->bssid));
2562 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2563 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2567 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2568 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2569 HOSTAPD_LEVEL_DEBUG,
2570 "MGMT: DA=" MACSTR " not our address",
2575 if (hapd->iconf->track_sta_max_num)
2576 sta_track_add(hapd->iface, mgmt->sa);
2579 case WLAN_FC_STYPE_AUTH:
2580 wpa_printf(MSG_DEBUG, "mgmt::auth");
2581 handle_auth(hapd, mgmt, len);
2584 case WLAN_FC_STYPE_ASSOC_REQ:
2585 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2586 handle_assoc(hapd, mgmt, len, 0);
2589 case WLAN_FC_STYPE_REASSOC_REQ:
2590 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2591 handle_assoc(hapd, mgmt, len, 1);
2594 case WLAN_FC_STYPE_DISASSOC:
2595 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2596 handle_disassoc(hapd, mgmt, len);
2599 case WLAN_FC_STYPE_DEAUTH:
2600 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2601 handle_deauth(hapd, mgmt, len);
2604 case WLAN_FC_STYPE_ACTION:
2605 wpa_printf(MSG_DEBUG, "mgmt::action");
2606 ret = handle_action(hapd, mgmt, len);
2609 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2610 HOSTAPD_LEVEL_DEBUG,
2611 "unknown mgmt frame subtype %d", stype);
2619 static void handle_auth_cb(struct hostapd_data *hapd,
2620 const struct ieee80211_mgmt *mgmt,
2623 u16 auth_alg, auth_transaction, status_code;
2624 struct sta_info *sta;
2626 sta = ap_get_sta(hapd, mgmt->da);
2628 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2633 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2634 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2635 status_code = le_to_host16(mgmt->u.auth.status_code);
2638 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2639 HOSTAPD_LEVEL_NOTICE,
2640 "did not acknowledge authentication response");
2644 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2645 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2646 (unsigned long) len);
2650 if (status_code == WLAN_STATUS_SUCCESS &&
2651 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2652 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2653 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2654 HOSTAPD_LEVEL_INFO, "authenticated");
2655 sta->flags |= WLAN_STA_AUTH;
2656 if (sta->added_unassoc)
2657 hostapd_set_sta_flags(hapd, sta);
2662 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2663 hostapd_drv_sta_remove(hapd, sta->addr);
2664 sta->added_unassoc = 0;
2669 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2670 struct sta_info *sta,
2674 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2676 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2679 for (i = 0; i < 4; i++) {
2680 if (ssid->wep.key[i] &&
2681 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2682 i == ssid->wep.idx, NULL, 0,
2683 ssid->wep.key[i], ssid->wep.len[i])) {
2684 wpa_printf(MSG_WARNING,
2685 "Could not set WEP keys for WDS interface; %s",
2693 static void handle_assoc_cb(struct hostapd_data *hapd,
2694 const struct ieee80211_mgmt *mgmt,
2695 size_t len, int reassoc, int ok)
2698 struct sta_info *sta;
2701 sta = ap_get_sta(hapd, mgmt->da);
2703 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2708 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2709 sizeof(mgmt->u.assoc_resp))) {
2710 wpa_printf(MSG_INFO,
2711 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2712 reassoc, (unsigned long) len);
2713 hostapd_drv_sta_remove(hapd, sta->addr);
2718 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2720 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2723 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2724 HOSTAPD_LEVEL_DEBUG,
2725 "did not acknowledge association response");
2726 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2727 /* The STA is added only in case of SUCCESS */
2728 if (status == WLAN_STATUS_SUCCESS)
2729 hostapd_drv_sta_remove(hapd, sta->addr);
2734 if (status != WLAN_STATUS_SUCCESS)
2737 /* Stop previous accounting session, if one is started, and allocate
2738 * new session id for the new session. */
2739 accounting_sta_stop(hapd, sta);
2741 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2743 "associated (aid %d)",
2746 if (sta->flags & WLAN_STA_ASSOC)
2748 sta->flags |= WLAN_STA_ASSOC;
2749 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2750 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2751 sta->auth_alg == WLAN_AUTH_FT) {
2753 * Open, static WEP, or FT protocol; no separate authorization
2756 ap_sta_set_authorized(hapd, sta, 1);
2760 mlme_reassociate_indication(hapd, sta);
2762 mlme_associate_indication(hapd, sta);
2764 #ifdef CONFIG_IEEE80211W
2765 sta->sa_query_timed_out = 0;
2766 #endif /* CONFIG_IEEE80211W */
2768 if (sta->flags & WLAN_STA_WDS) {
2770 char ifname_wds[IFNAMSIZ + 1];
2772 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2775 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2778 if (sta->eapol_sm == NULL) {
2780 * This STA does not use RADIUS server for EAP authentication,
2781 * so bind it to the selected VLAN interface now, since the
2782 * interface selection is not going to change anymore.
2784 if (ap_sta_bind_vlan(hapd, sta) < 0)
2786 } else if (sta->vlan_id) {
2787 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2788 if (ap_sta_bind_vlan(hapd, sta) < 0)
2792 hostapd_set_sta_flags(hapd, sta);
2794 if (sta->auth_alg == WLAN_AUTH_FT)
2795 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2797 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2798 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2799 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2801 if (sta->pending_eapol_rx) {
2802 struct os_reltime now, age;
2804 os_get_reltime(&now);
2805 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
2806 if (age.sec == 0 && age.usec < 200000) {
2807 wpa_printf(MSG_DEBUG,
2808 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
2809 MAC2STR(sta->addr));
2812 wpabuf_head(sta->pending_eapol_rx->buf),
2813 wpabuf_len(sta->pending_eapol_rx->buf));
2815 wpabuf_free(sta->pending_eapol_rx->buf);
2816 os_free(sta->pending_eapol_rx);
2817 sta->pending_eapol_rx = NULL;
2822 static void handle_deauth_cb(struct hostapd_data *hapd,
2823 const struct ieee80211_mgmt *mgmt,
2826 struct sta_info *sta;
2827 if (mgmt->da[0] & 0x01)
2829 sta = ap_get_sta(hapd, mgmt->da);
2831 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2832 " not found", MAC2STR(mgmt->da));
2836 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2837 MAC2STR(sta->addr));
2839 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2840 "deauth", MAC2STR(sta->addr));
2842 ap_sta_deauth_cb(hapd, sta);
2846 static void handle_disassoc_cb(struct hostapd_data *hapd,
2847 const struct ieee80211_mgmt *mgmt,
2850 struct sta_info *sta;
2851 if (mgmt->da[0] & 0x01)
2853 sta = ap_get_sta(hapd, mgmt->da);
2855 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2856 " not found", MAC2STR(mgmt->da));
2860 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2861 MAC2STR(sta->addr));
2863 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2864 "disassoc", MAC2STR(sta->addr));
2866 ap_sta_disassoc_cb(hapd, sta);
2871 * ieee802_11_mgmt_cb - Process management frame TX status callback
2872 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2874 * @buf: management frame data (starting from IEEE 802.11 header)
2875 * @len: length of frame data in octets
2876 * @stype: management frame subtype from frame control field
2877 * @ok: Whether the frame was ACK'ed
2879 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2882 const struct ieee80211_mgmt *mgmt;
2883 mgmt = (const struct ieee80211_mgmt *) buf;
2885 #ifdef CONFIG_TESTING_OPTIONS
2886 if (hapd->ext_mgmt_frame_handling) {
2887 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2891 #endif /* CONFIG_TESTING_OPTIONS */
2894 case WLAN_FC_STYPE_AUTH:
2895 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2896 handle_auth_cb(hapd, mgmt, len, ok);
2898 case WLAN_FC_STYPE_ASSOC_RESP:
2899 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2900 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2902 case WLAN_FC_STYPE_REASSOC_RESP:
2903 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2904 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2906 case WLAN_FC_STYPE_PROBE_RESP:
2907 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
2909 case WLAN_FC_STYPE_DEAUTH:
2910 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2911 handle_deauth_cb(hapd, mgmt, len, ok);
2913 case WLAN_FC_STYPE_DISASSOC:
2914 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2915 handle_disassoc_cb(hapd, mgmt, len, ok);
2917 case WLAN_FC_STYPE_ACTION:
2918 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
2921 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2927 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2934 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2935 char *buf, size_t buflen)
2942 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2943 const u8 *buf, size_t len, int ack)
2945 struct sta_info *sta;
2946 struct hostapd_iface *iface = hapd->iface;
2948 sta = ap_get_sta(hapd, addr);
2949 if (sta == NULL && iface->num_bss > 1) {
2951 for (j = 0; j < iface->num_bss; j++) {
2952 hapd = iface->bss[j];
2953 sta = ap_get_sta(hapd, addr);
2958 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2960 if (sta->flags & WLAN_STA_PENDING_POLL) {
2961 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2962 "activity poll", MAC2STR(sta->addr),
2963 ack ? "ACKed" : "did not ACK");
2965 sta->flags &= ~WLAN_STA_PENDING_POLL;
2968 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2972 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2973 const u8 *data, size_t len, int ack)
2975 struct sta_info *sta;
2976 struct hostapd_iface *iface = hapd->iface;
2978 sta = ap_get_sta(hapd, dst);
2979 if (sta == NULL && iface->num_bss > 1) {
2981 for (j = 0; j < iface->num_bss; j++) {
2982 hapd = iface->bss[j];
2983 sta = ap_get_sta(hapd, dst);
2988 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2989 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2990 MACSTR " that is not currently associated",
2995 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2999 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
3001 struct sta_info *sta;
3002 struct hostapd_iface *iface = hapd->iface;
3004 sta = ap_get_sta(hapd, addr);
3005 if (sta == NULL && iface->num_bss > 1) {
3007 for (j = 0; j < iface->num_bss; j++) {
3008 hapd = iface->bss[j];
3009 sta = ap_get_sta(hapd, addr);
3016 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3019 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3020 "activity poll", MAC2STR(sta->addr));
3021 sta->flags &= ~WLAN_STA_PENDING_POLL;
3025 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3028 struct sta_info *sta;
3030 sta = ap_get_sta(hapd, src);
3031 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
3032 if (!hapd->conf->wds_sta)
3035 if (wds && !(sta->flags & WLAN_STA_WDS)) {
3037 char ifname_wds[IFNAMSIZ + 1];
3039 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3040 "STA " MACSTR " (aid %u)",
3041 MAC2STR(sta->addr), sta->aid);
3042 sta->flags |= WLAN_STA_WDS;
3043 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3044 sta->addr, sta->aid, 1);
3046 hostapd_set_wds_encryption(hapd, sta,
3052 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3053 MACSTR, MAC2STR(src));
3054 if (src[0] & 0x01) {
3055 /* Broadcast bit set in SA?! Ignore the frame silently. */
3059 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3060 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3061 "already been sent, but no TX status yet known - "
3062 "ignore Class 3 frame issue with " MACSTR,
3067 if (sta && (sta->flags & WLAN_STA_AUTH))
3068 hostapd_drv_sta_disassoc(
3070 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3072 hostapd_drv_sta_deauth(
3074 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3078 #endif /* CONFIG_NATIVE_WINDOWS */