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 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
558 const u8 *bssid, u8 auth_transaction)
562 if (auth_transaction != 1 && auth_transaction != 2)
563 return WLAN_STATUS_UNSPECIFIED_FAILURE;
565 switch (sta->sae->state) {
567 if (auth_transaction == 1) {
568 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
571 sta->sae->state = SAE_COMMITTED;
573 if (sae_process_commit(sta->sae) < 0)
574 return WLAN_STATUS_UNSPECIFIED_FAILURE;
577 * In mesh case, both Commit and Confirm can be sent
578 * immediately. In infrastructure BSS, only a single
579 * Authentication frame (Commit) is expected from the AP
580 * here and the second one (Confirm) will be sent once
581 * the STA has sent its second Authentication frame
584 if (hapd->conf->mesh & MESH_ENABLED) {
586 * Send both Commit and Confirm immediately
587 * based on SAE finite state machine
588 * Nothing -> Confirm transition.
590 ret = auth_sae_send_confirm(hapd, sta, bssid);
593 sta->sae->state = SAE_CONFIRMED;
596 * For infrastructure BSS, send only the Commit
597 * message now to get alternating sequence of
598 * Authentication frames between the AP and STA.
599 * Confirm will be sent in
600 * Commited -> Confirmed/Accepted transition
601 * when receiving Confirm from STA.
605 sae_set_retransmit_timer(hapd, sta);
607 hostapd_logger(hapd, sta->addr,
608 HOSTAPD_MODULE_IEEE80211,
610 "SAE confirm before commit");
614 sae_clear_retransmit_timer(hapd, sta);
615 if (auth_transaction == 1) {
616 if (sae_process_commit(sta->sae) < 0)
617 return WLAN_STATUS_UNSPECIFIED_FAILURE;
619 ret = auth_sae_send_confirm(hapd, sta, bssid);
622 sta->sae->state = SAE_CONFIRMED;
624 sae_set_retransmit_timer(hapd, sta);
625 } else if (hapd->conf->mesh & MESH_ENABLED) {
627 * In mesh case, follow SAE finite state machine and
628 * send Commit now, if sync count allows.
630 if (sae_check_big_sync(sta))
631 return WLAN_STATUS_SUCCESS;
634 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
638 sae_set_retransmit_timer(hapd, sta);
641 * For instructure BSS, send the postponed Confirm from
642 * Nothing -> Confirmed transition that was reduced to
643 * Nothing -> Committed above.
645 ret = auth_sae_send_confirm(hapd, sta, bssid);
649 sta->sae->state = SAE_CONFIRMED;
652 * Since this was triggered on Confirm RX, run another
653 * step to get to Accepted without waiting for
656 return sae_sm_step(hapd, sta, bssid, auth_transaction);
660 sae_clear_retransmit_timer(hapd, sta);
661 if (auth_transaction == 1) {
662 if (sae_check_big_sync(sta))
663 return WLAN_STATUS_SUCCESS;
666 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
670 if (sae_process_commit(sta->sae) < 0)
671 return WLAN_STATUS_UNSPECIFIED_FAILURE;
673 ret = auth_sae_send_confirm(hapd, sta, bssid);
677 sae_set_retransmit_timer(hapd, sta);
679 sta->flags |= WLAN_STA_AUTH;
680 sta->auth_alg = WLAN_AUTH_SAE;
681 mlme_authenticate_indication(hapd, sta);
682 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
683 sta->sae->state = SAE_ACCEPTED;
684 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
685 sta->sae->pmk, sta->sae->pmkid);
689 if (auth_transaction == 1) {
690 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
691 ") doing reauthentication",
693 ap_free_sta(hapd, sta);
695 if (sae_check_big_sync(sta))
696 return WLAN_STATUS_SUCCESS;
699 ret = auth_sae_send_confirm(hapd, sta, bssid);
700 sae_clear_temp_data(sta->sae);
706 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
708 return WLAN_STATUS_UNSPECIFIED_FAILURE;
710 return WLAN_STATUS_SUCCESS;
714 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
715 const struct ieee80211_mgmt *mgmt, size_t len,
716 u16 auth_transaction, u16 status_code)
718 int resp = WLAN_STATUS_SUCCESS;
719 struct wpabuf *data = NULL;
722 if (auth_transaction != 1 ||
723 status_code != WLAN_STATUS_SUCCESS) {
727 sta->sae = os_zalloc(sizeof(*sta->sae));
732 sta->sae->state = SAE_NOTHING;
736 if (auth_transaction == 1) {
737 const u8 *token = NULL, *pos, *end;
738 size_t token_len = 0;
739 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
741 "start SAE authentication (RX commit, status=%u)",
744 if ((hapd->conf->mesh & MESH_ENABLED) &&
745 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
747 pos = mgmt->u.auth.variable;
748 end = ((const u8 *) mgmt) + len;
749 if (pos + sizeof(le16) > end) {
750 wpa_printf(MSG_ERROR,
751 "SAE: Too short anti-clogging token request");
752 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
755 resp = sae_group_allowed(sta->sae,
756 hapd->conf->sae_groups,
758 if (resp != WLAN_STATUS_SUCCESS) {
759 wpa_printf(MSG_ERROR,
760 "SAE: Invalid group in anti-clogging token request");
765 wpabuf_free(sta->sae->tmp->anti_clogging_token);
766 sta->sae->tmp->anti_clogging_token =
767 wpabuf_alloc_copy(pos, end - pos);
768 if (sta->sae->tmp->anti_clogging_token == NULL) {
769 wpa_printf(MSG_ERROR,
770 "SAE: Failed to alloc for anti-clogging token");
771 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
776 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
777 * is 76, a new Commit Message shall be constructed
778 * with the Anti-Clogging Token from the received
779 * Authentication frame, and the commit-scalar and
780 * COMMIT-ELEMENT previously sent.
782 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
783 if (resp != WLAN_STATUS_SUCCESS) {
784 wpa_printf(MSG_ERROR,
785 "SAE: Failed to send commit message");
788 sta->sae->state = SAE_COMMITTED;
790 sae_set_retransmit_timer(hapd, sta);
794 if (status_code != WLAN_STATUS_SUCCESS)
797 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
798 ((const u8 *) mgmt) + len -
799 mgmt->u.auth.variable, &token,
800 &token_len, hapd->conf->sae_groups);
801 if (resp == SAE_SILENTLY_DISCARD) {
802 wpa_printf(MSG_DEBUG,
803 "SAE: Drop commit message from " MACSTR " due to reflection attack",
807 if (token && check_sae_token(hapd, sta->addr, token, token_len)
809 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
810 "incorrect token from " MACSTR,
812 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
816 if (resp != WLAN_STATUS_SUCCESS)
819 if (!token && use_sae_anti_clogging(hapd)) {
820 wpa_printf(MSG_DEBUG,
821 "SAE: Request anti-clogging token from "
822 MACSTR, MAC2STR(sta->addr));
823 data = auth_build_token_req(hapd, sta->sae->group,
825 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
826 if (hapd->conf->mesh & MESH_ENABLED)
827 sta->sae->state = SAE_NOTHING;
831 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
832 } else if (auth_transaction == 2) {
833 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
835 "SAE authentication (RX confirm, status=%u)",
837 if (status_code != WLAN_STATUS_SUCCESS)
839 if (sta->sae->state >= SAE_CONFIRMED ||
840 !(hapd->conf->mesh & MESH_ENABLED)) {
841 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
842 ((u8 *) mgmt) + len -
843 mgmt->u.auth.variable) < 0) {
844 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
848 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
850 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
852 "unexpected SAE authentication transaction %u (status=%u)",
853 auth_transaction, status_code);
854 if (status_code != WLAN_STATUS_SUCCESS)
856 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
860 if (resp != WLAN_STATUS_SUCCESS) {
861 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
862 auth_transaction, resp,
863 data ? wpabuf_head(data) : (u8 *) "",
864 data ? wpabuf_len(data) : 0);
868 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
869 status_code != WLAN_STATUS_SUCCESS)) {
870 hostapd_drv_sta_remove(hapd, sta->addr);
871 sta->added_unassoc = 0;
878 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
879 * @hapd: BSS data for the device initiating the authentication
880 * @sta: the peer to which commit authentication frame is sent
882 * This function implements Init event handling (IEEE Std 802.11-2012,
883 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
884 * sta->sae structure should be initialized appropriately via a call to
885 * sae_prepare_commit().
887 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
891 if (!sta->sae || !sta->sae->tmp)
894 if (sta->sae->state != SAE_NOTHING)
897 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
901 sta->sae->state = SAE_COMMITTED;
903 sae_set_retransmit_timer(hapd, sta);
908 #endif /* CONFIG_SAE */
911 static void handle_auth(struct hostapd_data *hapd,
912 const struct ieee80211_mgmt *mgmt, size_t len)
914 u16 auth_alg, auth_transaction, status_code;
915 u16 resp = WLAN_STATUS_SUCCESS;
916 struct sta_info *sta = NULL;
919 const u8 *challenge = NULL;
920 u32 session_timeout, acct_interim_interval;
921 struct vlan_description vlan_id;
922 struct hostapd_sta_wpa_psk_short *psk = NULL;
923 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
924 size_t resp_ies_len = 0;
925 char *identity = NULL;
926 char *radius_cui = NULL;
929 os_memset(&vlan_id, 0, sizeof(vlan_id));
931 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
932 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
933 (unsigned long) len);
937 #ifdef CONFIG_TESTING_OPTIONS
938 if (hapd->iconf->ignore_auth_probability > 0.0 &&
939 drand48() < hapd->iconf->ignore_auth_probability) {
941 "TESTING: ignoring auth frame from " MACSTR,
945 #endif /* CONFIG_TESTING_OPTIONS */
947 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
948 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
949 status_code = le_to_host16(mgmt->u.auth.status_code);
950 fc = le_to_host16(mgmt->frame_control);
951 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
953 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
954 2 + WLAN_AUTH_CHALLENGE_LEN &&
955 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
956 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
957 challenge = &mgmt->u.auth.variable[2];
959 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
960 "auth_transaction=%d status_code=%d wep=%d%s "
962 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
963 status_code, !!(fc & WLAN_FC_ISWEP),
964 challenge ? " challenge" : "",
965 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
968 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
970 "Unsupported authentication algorithm (%d)",
972 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
975 #endif /* CONFIG_NO_RC4 */
977 if (hapd->tkip_countermeasures) {
978 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
982 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
983 auth_alg == WLAN_AUTH_OPEN) ||
984 #ifdef CONFIG_IEEE80211R
985 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
986 auth_alg == WLAN_AUTH_FT) ||
987 #endif /* CONFIG_IEEE80211R */
989 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
990 auth_alg == WLAN_AUTH_SAE) ||
991 #endif /* CONFIG_SAE */
992 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
993 auth_alg == WLAN_AUTH_SHARED_KEY))) {
994 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
996 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1000 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
1001 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
1002 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1004 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1008 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
1009 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1011 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1015 if (hapd->conf->no_auth_if_seen_on) {
1016 struct hostapd_data *other;
1018 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1019 hapd->conf->no_auth_if_seen_on);
1023 u8 op_class, channel, phytype;
1025 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1026 MACSTR " since STA has been seen on %s",
1027 hapd->conf->iface, MAC2STR(mgmt->sa),
1028 hapd->conf->no_auth_if_seen_on);
1030 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1032 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1034 os_memcpy(pos, other->own_addr, ETH_ALEN);
1036 info = 0; /* TODO: BSSID Information */
1037 WPA_PUT_LE32(pos, info);
1039 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1040 phytype = 8; /* dmg */
1041 else if (other->iconf->ieee80211ac)
1042 phytype = 9; /* vht */
1043 else if (other->iconf->ieee80211n)
1044 phytype = 7; /* ht */
1045 else if (other->iconf->hw_mode ==
1046 HOSTAPD_MODE_IEEE80211A)
1047 phytype = 4; /* ofdm */
1048 else if (other->iconf->hw_mode ==
1049 HOSTAPD_MODE_IEEE80211G)
1050 phytype = 6; /* erp */
1052 phytype = 5; /* hrdsss */
1053 if (ieee80211_freq_to_channel_ext(
1054 hostapd_hw_get_freq(other,
1055 other->iconf->channel),
1056 other->iconf->secondary_channel,
1057 other->iconf->ieee80211ac,
1058 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1060 channel = other->iconf->channel;
1065 resp_ies_len = pos - &resp_ies[0];
1070 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1072 &acct_interim_interval, &vlan_id,
1073 &psk, &identity, &radius_cui);
1075 if (res == HOSTAPD_ACL_REJECT) {
1076 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1078 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1081 if (res == HOSTAPD_ACL_PENDING) {
1082 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1083 " waiting for an external authentication",
1085 /* Authentication code will re-send the authentication frame
1086 * after it has received (and cached) information from the
1087 * external source. */
1091 sta = ap_get_sta(hapd, mgmt->sa);
1093 if ((fc & WLAN_FC_RETRY) &&
1094 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1095 sta->last_seq_ctrl == seq_ctrl &&
1096 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1097 hostapd_logger(hapd, sta->addr,
1098 HOSTAPD_MODULE_IEEE80211,
1099 HOSTAPD_LEVEL_DEBUG,
1100 "Drop repeated authentication frame seq_ctrl=0x%x",
1105 if ((hapd->conf->mesh & MESH_ENABLED) &&
1106 sta->plink_state == PLINK_BLOCKED) {
1107 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1108 " is blocked - drop Authentication frame",
1112 #endif /* CONFIG_MESH */
1115 if (hapd->conf->mesh & MESH_ENABLED) {
1116 /* if the mesh peer is not available, we don't do auth.
1118 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1119 " not yet known - drop Authentication frame",
1122 * Save a copy of the frame so that it can be processed
1123 * if a new peer entry is added shortly after this.
1125 wpabuf_free(hapd->mesh_pending_auth);
1126 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1127 os_get_reltime(&hapd->mesh_pending_auth_time);
1130 #endif /* CONFIG_MESH */
1132 sta = ap_sta_add(hapd, mgmt->sa);
1134 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1138 sta->last_seq_ctrl = seq_ctrl;
1139 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1141 if (vlan_id.notempty &&
1142 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1143 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1145 "Invalid VLAN %d%s received from RADIUS server",
1147 vlan_id.tagged[0] ? "+" : "");
1148 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1151 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1152 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1156 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1157 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1159 hostapd_free_psk_list(sta->psk);
1160 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1167 sta->identity = identity;
1169 sta->radius_cui = radius_cui;
1172 sta->flags &= ~WLAN_STA_PREAUTH;
1173 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1175 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1176 sta->acct_interim_interval = acct_interim_interval;
1177 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1178 ap_sta_session_timeout(hapd, sta, session_timeout);
1180 ap_sta_no_session_timeout(hapd, sta);
1183 * If the driver supports full AP client state, add a station to the
1184 * driver before sending authentication reply to make sure the driver
1185 * has resources, and not to go through the entire authentication and
1186 * association handshake, and fail it at the end.
1188 * If this is not the first transaction, in a multi-step authentication
1189 * algorithm, the station already exists in the driver
1190 * (sta->added_unassoc = 1) so skip it.
1192 * In mesh mode, the station was already added to the driver when the
1193 * NEW_PEER_CANDIDATE event is received.
1195 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1196 !(hapd->conf->mesh & MESH_ENABLED) &&
1197 !(sta->added_unassoc)) {
1199 * If a station that is already associated to the AP, is trying
1200 * to authenticate again, remove the STA entry, in order to make
1201 * sure the STA PS state gets cleared and configuration gets
1202 * updated. To handle this, station's added_unassoc flag is
1203 * cleared once the station has completed association.
1205 hostapd_drv_sta_remove(hapd, sta->addr);
1206 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1207 WLAN_STA_AUTHORIZED);
1209 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1210 NULL, NULL, sta->flags, 0, 0, 0)) {
1211 hostapd_logger(hapd, sta->addr,
1212 HOSTAPD_MODULE_IEEE80211,
1213 HOSTAPD_LEVEL_NOTICE,
1214 "Could not add STA to kernel driver");
1215 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1219 sta->added_unassoc = 1;
1223 case WLAN_AUTH_OPEN:
1224 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1225 HOSTAPD_LEVEL_DEBUG,
1226 "authentication OK (open system)");
1227 sta->flags |= WLAN_STA_AUTH;
1228 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1229 sta->auth_alg = WLAN_AUTH_OPEN;
1230 mlme_authenticate_indication(hapd, sta);
1232 #ifndef CONFIG_NO_RC4
1233 case WLAN_AUTH_SHARED_KEY:
1234 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1235 fc & WLAN_FC_ISWEP);
1236 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1237 mlme_authenticate_indication(hapd, sta);
1238 if (sta->challenge && auth_transaction == 1) {
1239 resp_ies[0] = WLAN_EID_CHALLENGE;
1240 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1241 os_memcpy(resp_ies + 2, sta->challenge,
1242 WLAN_AUTH_CHALLENGE_LEN);
1243 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1246 #endif /* CONFIG_NO_RC4 */
1247 #ifdef CONFIG_IEEE80211R
1249 sta->auth_alg = WLAN_AUTH_FT;
1250 if (sta->wpa_sm == NULL)
1251 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1253 if (sta->wpa_sm == NULL) {
1254 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1256 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1259 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1260 auth_transaction, mgmt->u.auth.variable,
1261 len - IEEE80211_HDRLEN -
1262 sizeof(mgmt->u.auth),
1263 handle_auth_ft_finish, hapd);
1264 /* handle_auth_ft_finish() callback will complete auth. */
1266 #endif /* CONFIG_IEEE80211R */
1270 if (status_code == WLAN_STATUS_SUCCESS &&
1271 hapd->conf->mesh & MESH_ENABLED) {
1272 if (sta->wpa_sm == NULL)
1274 wpa_auth_sta_init(hapd->wpa_auth,
1276 if (sta->wpa_sm == NULL) {
1277 wpa_printf(MSG_DEBUG,
1278 "SAE: Failed to initialize WPA state machine");
1279 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1283 #endif /* CONFIG_MESH */
1284 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1287 #endif /* CONFIG_SAE */
1292 os_free(radius_cui);
1293 hostapd_free_psk_list(psk);
1295 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1296 auth_transaction + 1, resp, resp_ies,
1299 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1300 reply_res != WLAN_STATUS_SUCCESS)) {
1301 hostapd_drv_sta_remove(hapd, sta->addr);
1302 sta->added_unassoc = 0;
1307 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1311 /* get a unique AID */
1313 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1317 for (i = 0; i < AID_WORDS; i++) {
1318 if (hapd->sta_aid[i] == (u32) -1)
1320 for (j = 0; j < 32; j++) {
1321 if (!(hapd->sta_aid[i] & BIT(j)))
1329 aid = i * 32 + j + 1;
1334 hapd->sta_aid[i] |= BIT(j);
1335 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1340 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1341 const u8 *ssid_ie, size_t ssid_ie_len)
1343 if (ssid_ie == NULL)
1344 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1346 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1347 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1348 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1350 "Station tried to associate with unknown SSID "
1351 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1352 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1355 return WLAN_STATUS_SUCCESS;
1359 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1360 const u8 *wmm_ie, size_t wmm_ie_len)
1362 sta->flags &= ~WLAN_STA_WMM;
1364 if (wmm_ie && hapd->conf->wmm_enabled) {
1365 struct wmm_information_element *wmm;
1367 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1368 hostapd_logger(hapd, sta->addr,
1370 HOSTAPD_LEVEL_DEBUG,
1371 "invalid WMM element in association "
1373 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1376 sta->flags |= WLAN_STA_WMM;
1377 wmm = (struct wmm_information_element *) wmm_ie;
1378 sta->qosinfo = wmm->qos_info;
1380 return WLAN_STATUS_SUCCESS;
1384 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1385 struct ieee802_11_elems *elems)
1387 if (!elems->supp_rates) {
1388 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1389 HOSTAPD_LEVEL_DEBUG,
1390 "No supported rates element in AssocReq");
1391 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1394 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1395 sizeof(sta->supported_rates)) {
1396 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1397 HOSTAPD_LEVEL_DEBUG,
1398 "Invalid supported rates element length %d+%d",
1399 elems->supp_rates_len,
1400 elems->ext_supp_rates_len);
1401 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1404 sta->supported_rates_len = merge_byte_arrays(
1405 sta->supported_rates, sizeof(sta->supported_rates),
1406 elems->supp_rates, elems->supp_rates_len,
1407 elems->ext_supp_rates, elems->ext_supp_rates_len);
1409 return WLAN_STATUS_SUCCESS;
1413 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1414 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1416 #ifdef CONFIG_INTERWORKING
1417 /* check for QoS Map support */
1418 if (ext_capab_ie_len >= 5) {
1419 if (ext_capab_ie[4] & 0x01)
1420 sta->qos_map_enabled = 1;
1422 #endif /* CONFIG_INTERWORKING */
1424 if (ext_capab_ie_len > 0)
1425 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1427 return WLAN_STATUS_SUCCESS;
1431 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1432 const u8 *ies, size_t ies_len, int reassoc)
1434 struct ieee802_11_elems elems;
1438 const u8 *p2p_dev_addr = NULL;
1440 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1441 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1442 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1443 "association request");
1444 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1447 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1448 if (resp != WLAN_STATUS_SUCCESS)
1450 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1451 if (resp != WLAN_STATUS_SUCCESS)
1453 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1454 if (resp != WLAN_STATUS_SUCCESS)
1456 resp = copy_supp_rates(hapd, sta, &elems);
1457 if (resp != WLAN_STATUS_SUCCESS)
1459 #ifdef CONFIG_IEEE80211N
1460 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1461 if (resp != WLAN_STATUS_SUCCESS)
1463 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1464 !(sta->flags & WLAN_STA_HT)) {
1465 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1466 HOSTAPD_LEVEL_INFO, "Station does not support "
1467 "mandatory HT PHY - reject association");
1468 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1470 #endif /* CONFIG_IEEE80211N */
1472 #ifdef CONFIG_IEEE80211AC
1473 if (hapd->iconf->ieee80211ac) {
1474 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1475 if (resp != WLAN_STATUS_SUCCESS)
1478 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1479 if (resp != WLAN_STATUS_SUCCESS)
1483 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1484 !(sta->flags & WLAN_STA_VHT)) {
1485 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1486 HOSTAPD_LEVEL_INFO, "Station does not support "
1487 "mandatory VHT PHY - reject association");
1488 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1491 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1492 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1493 elems.vendor_vht_len);
1494 if (resp != WLAN_STATUS_SUCCESS)
1497 #endif /* CONFIG_IEEE80211AC */
1501 wpabuf_free(sta->p2p_ie);
1502 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1503 P2P_IE_VENDOR_TYPE);
1505 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1507 wpabuf_free(sta->p2p_ie);
1510 #endif /* CONFIG_P2P */
1512 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1513 wpa_ie = elems.rsn_ie;
1514 wpa_ie_len = elems.rsn_ie_len;
1515 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1517 wpa_ie = elems.wpa_ie;
1518 wpa_ie_len = elems.wpa_ie_len;
1525 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1526 if (hapd->conf->wps_state && elems.wps_ie) {
1527 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1528 "Request - assume WPS is used");
1529 sta->flags |= WLAN_STA_WPS;
1530 wpabuf_free(sta->wps_ie);
1531 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1532 WPS_IE_VENDOR_TYPE);
1533 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1534 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1535 sta->flags |= WLAN_STA_WPS2;
1539 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1540 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1541 "(Re)Association Request - reject");
1542 return WLAN_STATUS_INVALID_IE;
1544 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1545 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1546 "(Re)Association Request - possible WPS use");
1547 sta->flags |= WLAN_STA_MAYBE_WPS;
1549 #endif /* CONFIG_WPS */
1550 if (hapd->conf->wpa && wpa_ie == NULL) {
1551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1553 "No WPA/RSN IE in association request");
1554 return WLAN_STATUS_INVALID_IE;
1557 if (hapd->conf->wpa && wpa_ie) {
1561 if (sta->wpa_sm == NULL)
1562 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1565 if (sta->wpa_sm == NULL) {
1566 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1568 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1570 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1572 elems.mdie, elems.mdie_len);
1573 if (res == WPA_INVALID_GROUP)
1574 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1575 else if (res == WPA_INVALID_PAIRWISE)
1576 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1577 else if (res == WPA_INVALID_AKMP)
1578 resp = WLAN_STATUS_AKMP_NOT_VALID;
1579 else if (res == WPA_ALLOC_FAIL)
1580 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1581 #ifdef CONFIG_IEEE80211W
1582 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1583 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1584 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1585 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1586 #endif /* CONFIG_IEEE80211W */
1587 else if (res == WPA_INVALID_MDIE)
1588 resp = WLAN_STATUS_INVALID_MDIE;
1589 else if (res != WPA_IE_OK)
1590 resp = WLAN_STATUS_INVALID_IE;
1591 if (resp != WLAN_STATUS_SUCCESS)
1593 #ifdef CONFIG_IEEE80211W
1594 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1595 sta->sa_query_count > 0)
1596 ap_check_sa_query_timeout(hapd, sta);
1597 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1598 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1600 * STA has already been associated with MFP and SA
1601 * Query timeout has not been reached. Reject the
1602 * association attempt temporarily and start SA Query,
1603 * if one is not pending.
1606 if (sta->sa_query_count == 0)
1607 ap_sta_start_sa_query(hapd, sta);
1609 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1612 if (wpa_auth_uses_mfp(sta->wpa_sm))
1613 sta->flags |= WLAN_STA_MFP;
1615 sta->flags &= ~WLAN_STA_MFP;
1616 #endif /* CONFIG_IEEE80211W */
1618 #ifdef CONFIG_IEEE80211R
1619 if (sta->auth_alg == WLAN_AUTH_FT) {
1621 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1622 "to use association (not "
1623 "re-association) with FT auth_alg",
1624 MAC2STR(sta->addr));
1625 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1628 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1630 if (resp != WLAN_STATUS_SUCCESS)
1633 #endif /* CONFIG_IEEE80211R */
1636 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1637 sta->auth_alg == WLAN_AUTH_OPEN) {
1638 struct rsn_pmksa_cache_entry *sa;
1639 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1640 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1641 wpa_printf(MSG_DEBUG,
1642 "SAE: No PMKSA cache entry found for "
1643 MACSTR, MAC2STR(sta->addr));
1644 return WLAN_STATUS_INVALID_PMKID;
1646 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1647 " using PMKSA caching", MAC2STR(sta->addr));
1648 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1649 sta->auth_alg != WLAN_AUTH_SAE &&
1650 !(sta->auth_alg == WLAN_AUTH_FT &&
1651 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1652 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1653 "SAE AKM after non-SAE auth_alg %u",
1654 MAC2STR(sta->addr), sta->auth_alg);
1655 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1657 #endif /* CONFIG_SAE */
1659 #ifdef CONFIG_IEEE80211N
1660 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1661 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1662 hostapd_logger(hapd, sta->addr,
1663 HOSTAPD_MODULE_IEEE80211,
1665 "Station tried to use TKIP with HT "
1667 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1669 #endif /* CONFIG_IEEE80211N */
1671 } else if (hapd->conf->osen) {
1672 if (elems.osen == NULL) {
1674 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1676 "No HS 2.0 OSEN element in association request");
1677 return WLAN_STATUS_INVALID_IE;
1680 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1681 if (sta->wpa_sm == NULL)
1682 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1684 if (sta->wpa_sm == NULL) {
1685 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1687 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1689 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1690 elems.osen - 2, elems.osen_len + 2) < 0)
1691 return WLAN_STATUS_INVALID_IE;
1692 #endif /* CONFIG_HS20 */
1694 wpa_auth_sta_no_wpa(sta->wpa_sm);
1697 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1698 #endif /* CONFIG_P2P */
1701 wpabuf_free(sta->hs20_ie);
1702 if (elems.hs20 && elems.hs20_len > 4) {
1703 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1704 elems.hs20_len - 4);
1706 sta->hs20_ie = NULL;
1707 #endif /* CONFIG_HS20 */
1710 wpabuf_free(sta->mb_ies);
1711 if (hapd->iface->fst)
1712 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1715 #endif /* CONFIG_FST */
1718 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1720 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1721 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1722 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1723 wpa_printf(MSG_INFO,
1724 "MBO: Reject WPA2 association without PMF");
1725 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1727 #endif /* CONFIG_MBO */
1729 return WLAN_STATUS_SUCCESS;
1733 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1737 struct ieee80211_mgmt reply;
1739 os_memset(&reply, 0, sizeof(reply));
1740 reply.frame_control =
1741 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1742 os_memcpy(reply.da, addr, ETH_ALEN);
1743 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1744 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1746 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1747 reply.u.deauth.reason_code = host_to_le16(reason_code);
1749 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1750 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1755 static int add_associated_sta(struct hostapd_data *hapd,
1756 struct sta_info *sta)
1758 struct ieee80211_ht_capabilities ht_cap;
1759 struct ieee80211_vht_capabilities vht_cap;
1762 * Remove the STA entry to ensure the STA PS state gets cleared and
1763 * configuration gets updated. This is relevant for cases, such as
1764 * FT-over-the-DS, where a station re-associates back to the same AP but
1765 * skips the authentication flow, or if working with a driver that
1766 * does not support full AP client state.
1768 if (!sta->added_unassoc)
1769 hostapd_drv_sta_remove(hapd, sta->addr);
1771 #ifdef CONFIG_IEEE80211N
1772 if (sta->flags & WLAN_STA_HT)
1773 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1774 #endif /* CONFIG_IEEE80211N */
1775 #ifdef CONFIG_IEEE80211AC
1776 if (sta->flags & WLAN_STA_VHT)
1777 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1778 #endif /* CONFIG_IEEE80211AC */
1781 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1782 * will be set when the ACK frame for the (Re)Association Response frame
1783 * is processed (TX status driver event).
1785 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1786 sta->supported_rates, sta->supported_rates_len,
1787 sta->listen_interval,
1788 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1789 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1790 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1791 sta->vht_opmode, sta->added_unassoc)) {
1792 hostapd_logger(hapd, sta->addr,
1793 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1794 "Could not %s STA to kernel driver",
1795 sta->added_unassoc ? "set" : "add");
1797 if (sta->added_unassoc) {
1798 hostapd_drv_sta_remove(hapd, sta->addr);
1799 sta->added_unassoc = 0;
1805 sta->added_unassoc = 0;
1811 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1812 u16 status_code, int reassoc, const u8 *ies,
1816 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1817 struct ieee80211_mgmt *reply;
1820 os_memset(buf, 0, sizeof(buf));
1821 reply = (struct ieee80211_mgmt *) buf;
1822 reply->frame_control =
1823 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1824 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1825 WLAN_FC_STYPE_ASSOC_RESP));
1826 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1827 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1828 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1830 send_len = IEEE80211_HDRLEN;
1831 send_len += sizeof(reply->u.assoc_resp);
1832 reply->u.assoc_resp.capab_info =
1833 host_to_le16(hostapd_own_capab_info(hapd));
1834 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1835 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1836 /* Supported rates */
1837 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1838 /* Extended supported rates */
1839 p = hostapd_eid_ext_supp_rates(hapd, p);
1841 #ifdef CONFIG_IEEE80211R
1842 if (status_code == WLAN_STATUS_SUCCESS) {
1843 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1844 * Transition Information, RSN, [RIC Response] */
1845 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1846 buf + sizeof(buf) - p,
1847 sta->auth_alg, ies, ies_len);
1849 #endif /* CONFIG_IEEE80211R */
1851 #ifdef CONFIG_IEEE80211W
1852 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1853 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1854 #endif /* CONFIG_IEEE80211W */
1856 #ifdef CONFIG_IEEE80211N
1857 p = hostapd_eid_ht_capabilities(hapd, p);
1858 p = hostapd_eid_ht_operation(hapd, p);
1859 #endif /* CONFIG_IEEE80211N */
1861 #ifdef CONFIG_IEEE80211AC
1862 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1863 p = hostapd_eid_vht_capabilities(hapd, p);
1864 p = hostapd_eid_vht_operation(hapd, p);
1866 #endif /* CONFIG_IEEE80211AC */
1868 p = hostapd_eid_ext_capab(hapd, p);
1869 p = hostapd_eid_bss_max_idle_period(hapd, p);
1870 if (sta->qos_map_enabled)
1871 p = hostapd_eid_qos_map_set(hapd, p);
1874 if (hapd->iface->fst_ies) {
1875 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1876 wpabuf_len(hapd->iface->fst_ies));
1877 p += wpabuf_len(hapd->iface->fst_ies);
1879 #endif /* CONFIG_FST */
1881 #ifdef CONFIG_IEEE80211AC
1882 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1883 p = hostapd_eid_vendor_vht(hapd, p);
1884 #endif /* CONFIG_IEEE80211AC */
1886 if (sta->flags & WLAN_STA_WMM)
1887 p = hostapd_eid_wmm(hapd, p);
1890 if ((sta->flags & WLAN_STA_WPS) ||
1891 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1892 struct wpabuf *wps = wps_build_assoc_resp_ie();
1894 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1895 p += wpabuf_len(wps);
1899 #endif /* CONFIG_WPS */
1902 if (sta->p2p_ie && hapd->p2p_group) {
1903 struct wpabuf *p2p_resp_ie;
1904 enum p2p_status_code status;
1905 switch (status_code) {
1906 case WLAN_STATUS_SUCCESS:
1907 status = P2P_SC_SUCCESS;
1909 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1910 status = P2P_SC_FAIL_LIMIT_REACHED;
1913 status = P2P_SC_FAIL_INVALID_PARAMS;
1916 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1918 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1919 wpabuf_len(p2p_resp_ie));
1920 p += wpabuf_len(p2p_resp_ie);
1921 wpabuf_free(p2p_resp_ie);
1924 #endif /* CONFIG_P2P */
1926 #ifdef CONFIG_P2P_MANAGER
1927 if (hapd->conf->p2p & P2P_MANAGE)
1928 p = hostapd_eid_p2p_manage(hapd, p);
1929 #endif /* CONFIG_P2P_MANAGER */
1931 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1933 send_len += p - reply->u.assoc_resp.variable;
1935 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
1936 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1938 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1941 return WLAN_STATUS_SUCCESS;
1945 static void handle_assoc(struct hostapd_data *hapd,
1946 const struct ieee80211_mgmt *mgmt, size_t len,
1949 u16 capab_info, listen_interval, seq_ctrl, fc;
1950 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
1953 struct sta_info *sta;
1955 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1956 sizeof(mgmt->u.assoc_req))) {
1957 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1958 reassoc, (unsigned long) len);
1962 #ifdef CONFIG_TESTING_OPTIONS
1964 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1965 drand48() < hapd->iconf->ignore_reassoc_probability) {
1966 wpa_printf(MSG_INFO,
1967 "TESTING: ignoring reassoc request from "
1968 MACSTR, MAC2STR(mgmt->sa));
1972 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1973 drand48() < hapd->iconf->ignore_assoc_probability) {
1974 wpa_printf(MSG_INFO,
1975 "TESTING: ignoring assoc request from "
1976 MACSTR, MAC2STR(mgmt->sa));
1980 #endif /* CONFIG_TESTING_OPTIONS */
1982 fc = le_to_host16(mgmt->frame_control);
1983 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1986 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1987 listen_interval = le_to_host16(
1988 mgmt->u.reassoc_req.listen_interval);
1989 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1990 " capab_info=0x%02x listen_interval=%d current_ap="
1991 MACSTR " seq_ctrl=0x%x%s",
1992 MAC2STR(mgmt->sa), capab_info, listen_interval,
1993 MAC2STR(mgmt->u.reassoc_req.current_ap),
1994 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1995 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1996 pos = mgmt->u.reassoc_req.variable;
1998 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1999 listen_interval = le_to_host16(
2000 mgmt->u.assoc_req.listen_interval);
2001 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
2002 " capab_info=0x%02x listen_interval=%d "
2004 MAC2STR(mgmt->sa), capab_info, listen_interval,
2005 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2006 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2007 pos = mgmt->u.assoc_req.variable;
2010 sta = ap_get_sta(hapd, mgmt->sa);
2011 #ifdef CONFIG_IEEE80211R
2012 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2013 (sta->flags & WLAN_STA_AUTH) == 0) {
2014 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2015 "prior to authentication since it is using "
2016 "over-the-DS FT", MAC2STR(mgmt->sa));
2019 * Mark station as authenticated, to avoid adding station
2020 * entry in the driver as associated and not authenticated
2022 sta->flags |= WLAN_STA_AUTH;
2024 #endif /* CONFIG_IEEE80211R */
2025 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2026 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2027 HOSTAPD_LEVEL_INFO, "Station tried to "
2028 "associate before authentication "
2029 "(aid=%d flags=0x%x)",
2030 sta ? sta->aid : -1,
2031 sta ? sta->flags : 0);
2032 send_deauth(hapd, mgmt->sa,
2033 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2037 if ((fc & WLAN_FC_RETRY) &&
2038 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2039 sta->last_seq_ctrl == seq_ctrl &&
2040 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2041 WLAN_FC_STYPE_ASSOC_REQ) {
2042 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2043 HOSTAPD_LEVEL_DEBUG,
2044 "Drop repeated association frame seq_ctrl=0x%x",
2048 sta->last_seq_ctrl = seq_ctrl;
2049 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2050 WLAN_FC_STYPE_ASSOC_REQ;
2052 if (hapd->tkip_countermeasures) {
2053 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2057 if (listen_interval > hapd->conf->max_listen_interval) {
2058 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2059 HOSTAPD_LEVEL_DEBUG,
2060 "Too large Listen Interval (%d)",
2062 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2067 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2068 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2071 #endif /* CONFIG_MBO */
2073 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2075 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2076 if (resp != WLAN_STATUS_SUCCESS)
2079 if (hostapd_get_aid(hapd, sta) < 0) {
2080 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2081 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2082 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2086 sta->capability = capab_info;
2087 sta->listen_interval = listen_interval;
2089 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2090 sta->flags |= WLAN_STA_NONERP;
2091 for (i = 0; i < sta->supported_rates_len; i++) {
2092 if ((sta->supported_rates[i] & 0x7f) > 22) {
2093 sta->flags &= ~WLAN_STA_NONERP;
2097 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2098 sta->nonerp_set = 1;
2099 hapd->iface->num_sta_non_erp++;
2100 if (hapd->iface->num_sta_non_erp == 1)
2101 ieee802_11_set_beacons(hapd->iface);
2104 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2105 !sta->no_short_slot_time_set) {
2106 sta->no_short_slot_time_set = 1;
2107 hapd->iface->num_sta_no_short_slot_time++;
2108 if (hapd->iface->current_mode->mode ==
2109 HOSTAPD_MODE_IEEE80211G &&
2110 hapd->iface->num_sta_no_short_slot_time == 1)
2111 ieee802_11_set_beacons(hapd->iface);
2114 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2115 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2117 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2119 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2120 !sta->no_short_preamble_set) {
2121 sta->no_short_preamble_set = 1;
2122 hapd->iface->num_sta_no_short_preamble++;
2123 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2124 && hapd->iface->num_sta_no_short_preamble == 1)
2125 ieee802_11_set_beacons(hapd->iface);
2128 #ifdef CONFIG_IEEE80211N
2129 update_ht_state(hapd, sta);
2130 #endif /* CONFIG_IEEE80211N */
2132 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2133 HOSTAPD_LEVEL_DEBUG,
2134 "association OK (aid %d)", sta->aid);
2135 /* Station will be marked associated, after it acknowledges AssocResp
2137 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2139 #ifdef CONFIG_IEEE80211W
2140 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2141 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2142 "SA Query procedure", reassoc ? "re" : "");
2143 /* TODO: Send a protected Disassociate frame to the STA using
2144 * the old key and Reason Code "Previous Authentication no
2145 * longer valid". Make sure this is only sent protected since
2146 * unprotected frame would be received by the STA that is now
2147 * trying to associate.
2150 #endif /* CONFIG_IEEE80211W */
2152 /* Make sure that the previously registered inactivity timer will not
2153 * remove the STA immediately. */
2154 sta->timeout_next = STA_NULLFUNC;
2158 * In case of a successful response, add the station to the driver.
2159 * Otherwise, the kernel may ignore Data frames before we process the
2160 * ACK frame (TX status). In case of a failure, this station will be
2163 * Note that this is not compliant with the IEEE 802.11 standard that
2164 * states that a non-AP station should transition into the
2165 * authenticated/associated state only after the station acknowledges
2166 * the (Re)Association Response frame. However, still do this as:
2168 * 1. In case the station does not acknowledge the (Re)Association
2169 * Response frame, it will be removed.
2170 * 2. Data frames will be dropped in the kernel until the station is
2171 * set into authorized state, and there are no significant known
2172 * issues with processing other non-Data Class 3 frames during this
2175 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2176 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2178 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2181 * Remove the station in case tranmission of a success response fails
2182 * (the STA was added associated to the driver) or if the station was
2183 * previously added unassociated.
2185 if ((reply_res != WLAN_STATUS_SUCCESS &&
2186 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2187 hostapd_drv_sta_remove(hapd, sta->addr);
2188 sta->added_unassoc = 0;
2193 static void handle_disassoc(struct hostapd_data *hapd,
2194 const struct ieee80211_mgmt *mgmt, size_t len)
2196 struct sta_info *sta;
2198 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2199 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2200 (unsigned long) len);
2204 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2206 le_to_host16(mgmt->u.disassoc.reason_code));
2208 sta = ap_get_sta(hapd, mgmt->sa);
2210 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2215 ap_sta_set_authorized(hapd, sta, 0);
2216 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2217 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2218 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2219 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2220 HOSTAPD_LEVEL_INFO, "disassociated");
2221 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2222 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2223 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2225 accounting_sta_stop(hapd, sta);
2226 ieee802_1x_free_station(hapd, sta);
2228 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2229 ap_sta_ip6addr_del(hapd, sta);
2230 hostapd_drv_sta_remove(hapd, sta->addr);
2231 sta->added_unassoc = 0;
2233 if (sta->timeout_next == STA_NULLFUNC ||
2234 sta->timeout_next == STA_DISASSOC) {
2235 sta->timeout_next = STA_DEAUTH;
2236 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2237 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2241 mlme_disassociate_indication(
2242 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2246 static void handle_deauth(struct hostapd_data *hapd,
2247 const struct ieee80211_mgmt *mgmt, size_t len)
2249 struct sta_info *sta;
2251 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2252 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2253 "payload (len=%lu)", (unsigned long) len);
2257 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2259 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2261 sta = ap_get_sta(hapd, mgmt->sa);
2263 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2264 "to deauthenticate, but it is not authenticated",
2269 ap_sta_set_authorized(hapd, sta, 0);
2270 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2271 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2272 WLAN_STA_ASSOC_REQ_OK);
2273 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2274 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2275 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2276 mlme_deauthenticate_indication(
2277 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2278 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2279 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2280 ap_free_sta(hapd, sta);
2284 static void handle_beacon(struct hostapd_data *hapd,
2285 const struct ieee80211_mgmt *mgmt, size_t len,
2286 struct hostapd_frame_info *fi)
2288 struct ieee802_11_elems elems;
2290 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2291 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2292 (unsigned long) len);
2296 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2297 len - (IEEE80211_HDRLEN +
2298 sizeof(mgmt->u.beacon)), &elems,
2301 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2305 #ifdef CONFIG_IEEE80211W
2307 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2308 const struct ieee80211_mgmt *mgmt,
2313 end = mgmt->u.action.u.sa_query_resp.trans_id +
2314 WLAN_SA_QUERY_TR_ID_LEN;
2315 if (((u8 *) mgmt) + len < end) {
2316 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2317 "frame (len=%lu)", (unsigned long) len);
2321 ieee802_11_sa_query_action(hapd, mgmt->sa,
2322 mgmt->u.action.u.sa_query_resp.action,
2323 mgmt->u.action.u.sa_query_resp.trans_id);
2328 static int robust_action_frame(u8 category)
2330 return category != WLAN_ACTION_PUBLIC &&
2331 category != WLAN_ACTION_HT;
2333 #endif /* CONFIG_IEEE80211W */
2336 static int handle_action(struct hostapd_data *hapd,
2337 const struct ieee80211_mgmt *mgmt, size_t len)
2339 struct sta_info *sta;
2340 sta = ap_get_sta(hapd, mgmt->sa);
2342 if (len < IEEE80211_HDRLEN + 1) {
2343 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2344 HOSTAPD_LEVEL_DEBUG,
2345 "handle_action - too short payload (len=%lu)",
2346 (unsigned long) len);
2350 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2351 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2352 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2353 "frame (category=%u) from unassociated STA " MACSTR,
2354 MAC2STR(mgmt->sa), mgmt->u.action.category);
2358 #ifdef CONFIG_IEEE80211W
2359 if (sta && (sta->flags & WLAN_STA_MFP) &&
2360 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2361 robust_action_frame(mgmt->u.action.category)) {
2362 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2363 HOSTAPD_LEVEL_DEBUG,
2364 "Dropped unprotected Robust Action frame from "
2368 #endif /* CONFIG_IEEE80211W */
2371 u16 fc = le_to_host16(mgmt->frame_control);
2372 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2374 if ((fc & WLAN_FC_RETRY) &&
2375 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2376 sta->last_seq_ctrl == seq_ctrl &&
2377 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2378 hostapd_logger(hapd, sta->addr,
2379 HOSTAPD_MODULE_IEEE80211,
2380 HOSTAPD_LEVEL_DEBUG,
2381 "Drop repeated action frame seq_ctrl=0x%x",
2386 sta->last_seq_ctrl = seq_ctrl;
2387 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2390 switch (mgmt->u.action.category) {
2391 #ifdef CONFIG_IEEE80211R
2392 case WLAN_ACTION_FT:
2394 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2395 len - IEEE80211_HDRLEN))
2398 #endif /* CONFIG_IEEE80211R */
2399 case WLAN_ACTION_WMM:
2400 hostapd_wmm_action(hapd, mgmt, len);
2402 #ifdef CONFIG_IEEE80211W
2403 case WLAN_ACTION_SA_QUERY:
2404 return hostapd_sa_query_action(hapd, mgmt, len);
2405 #endif /* CONFIG_IEEE80211W */
2407 case WLAN_ACTION_WNM:
2408 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2410 #endif /* CONFIG_WNM */
2412 case WLAN_ACTION_FST:
2413 if (hapd->iface->fst)
2414 fst_rx_action(hapd->iface->fst, mgmt, len);
2416 wpa_printf(MSG_DEBUG,
2417 "FST: Ignore FST Action frame - no FST attached");
2419 #endif /* CONFIG_FST */
2420 case WLAN_ACTION_PUBLIC:
2421 case WLAN_ACTION_PROTECTED_DUAL:
2422 #ifdef CONFIG_IEEE80211N
2423 if (len >= IEEE80211_HDRLEN + 2 &&
2424 mgmt->u.action.u.public_action.action ==
2425 WLAN_PA_20_40_BSS_COEX) {
2426 wpa_printf(MSG_DEBUG,
2427 "HT20/40 coex mgmt frame received from STA "
2428 MACSTR, MAC2STR(mgmt->sa));
2429 hostapd_2040_coex_action(hapd, mgmt, len);
2431 #endif /* CONFIG_IEEE80211N */
2432 if (hapd->public_action_cb) {
2433 hapd->public_action_cb(hapd->public_action_cb_ctx,
2437 if (hapd->public_action_cb2) {
2438 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2442 if (hapd->public_action_cb || hapd->public_action_cb2)
2445 case WLAN_ACTION_VENDOR_SPECIFIC:
2446 if (hapd->vendor_action_cb) {
2447 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2449 hapd->iface->freq) == 0)
2455 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2456 HOSTAPD_LEVEL_DEBUG,
2457 "handle_action - unknown action category %d or invalid "
2459 mgmt->u.action.category);
2460 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2461 !(mgmt->sa[0] & 0x01)) {
2462 struct ieee80211_mgmt *resp;
2465 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2466 * Return the Action frame to the source without change
2467 * except that MSB of the Category set to 1.
2469 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2470 "frame back to sender");
2471 resp = os_malloc(len);
2474 os_memcpy(resp, mgmt, len);
2475 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2476 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2477 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2478 resp->u.action.category |= 0x80;
2480 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2481 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2492 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2493 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2495 * @buf: management frame data (starting from IEEE 802.11 header)
2496 * @len: length of frame data in octets
2497 * @fi: meta data about received frame (signal level, etc.)
2499 * Process all incoming IEEE 802.11 management frames. This will be called for
2500 * each frame received from the kernel driver through wlan#ap interface. In
2501 * addition, it can be called to re-inserted pending frames (e.g., when using
2502 * external RADIUS server as an MAC ACL).
2504 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2505 struct hostapd_frame_info *fi)
2507 struct ieee80211_mgmt *mgmt;
2515 mgmt = (struct ieee80211_mgmt *) buf;
2516 fc = le_to_host16(mgmt->frame_control);
2517 stype = WLAN_FC_GET_STYPE(fc);
2519 if (stype == WLAN_FC_STYPE_BEACON) {
2520 handle_beacon(hapd, mgmt, len, fi);
2524 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2525 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2526 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2530 /* Invitation responses can be sent with the peer MAC as BSSID */
2531 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2532 stype == WLAN_FC_STYPE_ACTION) &&
2533 #endif /* CONFIG_P2P */
2535 !(hapd->conf->mesh & MESH_ENABLED) &&
2536 #endif /* CONFIG_MESH */
2537 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2538 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2539 MAC2STR(mgmt->bssid));
2544 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2545 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2549 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2550 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2551 HOSTAPD_LEVEL_DEBUG,
2552 "MGMT: DA=" MACSTR " not our address",
2557 if (hapd->iconf->track_sta_max_num)
2558 sta_track_add(hapd->iface, mgmt->sa);
2561 case WLAN_FC_STYPE_AUTH:
2562 wpa_printf(MSG_DEBUG, "mgmt::auth");
2563 handle_auth(hapd, mgmt, len);
2566 case WLAN_FC_STYPE_ASSOC_REQ:
2567 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2568 handle_assoc(hapd, mgmt, len, 0);
2571 case WLAN_FC_STYPE_REASSOC_REQ:
2572 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2573 handle_assoc(hapd, mgmt, len, 1);
2576 case WLAN_FC_STYPE_DISASSOC:
2577 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2578 handle_disassoc(hapd, mgmt, len);
2581 case WLAN_FC_STYPE_DEAUTH:
2582 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2583 handle_deauth(hapd, mgmt, len);
2586 case WLAN_FC_STYPE_ACTION:
2587 wpa_printf(MSG_DEBUG, "mgmt::action");
2588 ret = handle_action(hapd, mgmt, len);
2591 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2592 HOSTAPD_LEVEL_DEBUG,
2593 "unknown mgmt frame subtype %d", stype);
2601 static void handle_auth_cb(struct hostapd_data *hapd,
2602 const struct ieee80211_mgmt *mgmt,
2605 u16 auth_alg, auth_transaction, status_code;
2606 struct sta_info *sta;
2608 sta = ap_get_sta(hapd, mgmt->da);
2610 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2615 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2616 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2617 status_code = le_to_host16(mgmt->u.auth.status_code);
2620 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2621 HOSTAPD_LEVEL_NOTICE,
2622 "did not acknowledge authentication response");
2626 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2627 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2628 (unsigned long) len);
2632 if (status_code == WLAN_STATUS_SUCCESS &&
2633 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2634 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2635 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2636 HOSTAPD_LEVEL_INFO, "authenticated");
2637 sta->flags |= WLAN_STA_AUTH;
2638 if (sta->added_unassoc)
2639 hostapd_set_sta_flags(hapd, sta);
2644 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2645 hostapd_drv_sta_remove(hapd, sta->addr);
2646 sta->added_unassoc = 0;
2651 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2652 struct sta_info *sta,
2656 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2658 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2661 for (i = 0; i < 4; i++) {
2662 if (ssid->wep.key[i] &&
2663 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2664 i == ssid->wep.idx, NULL, 0,
2665 ssid->wep.key[i], ssid->wep.len[i])) {
2666 wpa_printf(MSG_WARNING,
2667 "Could not set WEP keys for WDS interface; %s",
2675 static void handle_assoc_cb(struct hostapd_data *hapd,
2676 const struct ieee80211_mgmt *mgmt,
2677 size_t len, int reassoc, int ok)
2680 struct sta_info *sta;
2683 sta = ap_get_sta(hapd, mgmt->da);
2685 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2690 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2691 sizeof(mgmt->u.assoc_resp))) {
2692 wpa_printf(MSG_INFO,
2693 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2694 reassoc, (unsigned long) len);
2695 hostapd_drv_sta_remove(hapd, sta->addr);
2700 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2702 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2705 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2706 HOSTAPD_LEVEL_DEBUG,
2707 "did not acknowledge association response");
2708 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2709 /* The STA is added only in case of SUCCESS */
2710 if (status == WLAN_STATUS_SUCCESS)
2711 hostapd_drv_sta_remove(hapd, sta->addr);
2716 if (status != WLAN_STATUS_SUCCESS)
2719 /* Stop previous accounting session, if one is started, and allocate
2720 * new session id for the new session. */
2721 accounting_sta_stop(hapd, sta);
2723 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2725 "associated (aid %d)",
2728 if (sta->flags & WLAN_STA_ASSOC)
2730 sta->flags |= WLAN_STA_ASSOC;
2731 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2732 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2733 sta->auth_alg == WLAN_AUTH_FT) {
2735 * Open, static WEP, or FT protocol; no separate authorization
2738 ap_sta_set_authorized(hapd, sta, 1);
2742 mlme_reassociate_indication(hapd, sta);
2744 mlme_associate_indication(hapd, sta);
2746 #ifdef CONFIG_IEEE80211W
2747 sta->sa_query_timed_out = 0;
2748 #endif /* CONFIG_IEEE80211W */
2750 if (sta->flags & WLAN_STA_WDS) {
2752 char ifname_wds[IFNAMSIZ + 1];
2754 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2757 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2760 if (sta->eapol_sm == NULL) {
2762 * This STA does not use RADIUS server for EAP authentication,
2763 * so bind it to the selected VLAN interface now, since the
2764 * interface selection is not going to change anymore.
2766 if (ap_sta_bind_vlan(hapd, sta) < 0)
2768 } else if (sta->vlan_id) {
2769 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2770 if (ap_sta_bind_vlan(hapd, sta) < 0)
2774 hostapd_set_sta_flags(hapd, sta);
2776 if (sta->auth_alg == WLAN_AUTH_FT)
2777 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2779 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2780 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2781 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2785 static void handle_deauth_cb(struct hostapd_data *hapd,
2786 const struct ieee80211_mgmt *mgmt,
2789 struct sta_info *sta;
2790 if (mgmt->da[0] & 0x01)
2792 sta = ap_get_sta(hapd, mgmt->da);
2794 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2795 " not found", MAC2STR(mgmt->da));
2799 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2800 MAC2STR(sta->addr));
2802 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2803 "deauth", MAC2STR(sta->addr));
2805 ap_sta_deauth_cb(hapd, sta);
2809 static void handle_disassoc_cb(struct hostapd_data *hapd,
2810 const struct ieee80211_mgmt *mgmt,
2813 struct sta_info *sta;
2814 if (mgmt->da[0] & 0x01)
2816 sta = ap_get_sta(hapd, mgmt->da);
2818 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2819 " not found", MAC2STR(mgmt->da));
2823 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2824 MAC2STR(sta->addr));
2826 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2827 "disassoc", MAC2STR(sta->addr));
2829 ap_sta_disassoc_cb(hapd, sta);
2834 * ieee802_11_mgmt_cb - Process management frame TX status callback
2835 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2837 * @buf: management frame data (starting from IEEE 802.11 header)
2838 * @len: length of frame data in octets
2839 * @stype: management frame subtype from frame control field
2840 * @ok: Whether the frame was ACK'ed
2842 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2845 const struct ieee80211_mgmt *mgmt;
2846 mgmt = (const struct ieee80211_mgmt *) buf;
2848 #ifdef CONFIG_TESTING_OPTIONS
2849 if (hapd->ext_mgmt_frame_handling) {
2850 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2854 #endif /* CONFIG_TESTING_OPTIONS */
2857 case WLAN_FC_STYPE_AUTH:
2858 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2859 handle_auth_cb(hapd, mgmt, len, ok);
2861 case WLAN_FC_STYPE_ASSOC_RESP:
2862 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2863 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2865 case WLAN_FC_STYPE_REASSOC_RESP:
2866 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2867 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2869 case WLAN_FC_STYPE_PROBE_RESP:
2870 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2872 case WLAN_FC_STYPE_DEAUTH:
2873 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2874 handle_deauth_cb(hapd, mgmt, len, ok);
2876 case WLAN_FC_STYPE_DISASSOC:
2877 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2878 handle_disassoc_cb(hapd, mgmt, len, ok);
2880 case WLAN_FC_STYPE_ACTION:
2881 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2884 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2890 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2897 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2898 char *buf, size_t buflen)
2905 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2906 const u8 *buf, size_t len, int ack)
2908 struct sta_info *sta;
2909 struct hostapd_iface *iface = hapd->iface;
2911 sta = ap_get_sta(hapd, addr);
2912 if (sta == NULL && iface->num_bss > 1) {
2914 for (j = 0; j < iface->num_bss; j++) {
2915 hapd = iface->bss[j];
2916 sta = ap_get_sta(hapd, addr);
2921 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2923 if (sta->flags & WLAN_STA_PENDING_POLL) {
2924 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2925 "activity poll", MAC2STR(sta->addr),
2926 ack ? "ACKed" : "did not ACK");
2928 sta->flags &= ~WLAN_STA_PENDING_POLL;
2931 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2935 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2936 const u8 *data, size_t len, int ack)
2938 struct sta_info *sta;
2939 struct hostapd_iface *iface = hapd->iface;
2941 sta = ap_get_sta(hapd, dst);
2942 if (sta == NULL && iface->num_bss > 1) {
2944 for (j = 0; j < iface->num_bss; j++) {
2945 hapd = iface->bss[j];
2946 sta = ap_get_sta(hapd, dst);
2951 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2952 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2953 MACSTR " that is not currently associated",
2958 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2962 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2964 struct sta_info *sta;
2965 struct hostapd_iface *iface = hapd->iface;
2967 sta = ap_get_sta(hapd, addr);
2968 if (sta == NULL && iface->num_bss > 1) {
2970 for (j = 0; j < iface->num_bss; j++) {
2971 hapd = iface->bss[j];
2972 sta = ap_get_sta(hapd, addr);
2979 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2982 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2983 "activity poll", MAC2STR(sta->addr));
2984 sta->flags &= ~WLAN_STA_PENDING_POLL;
2988 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2991 struct sta_info *sta;
2993 sta = ap_get_sta(hapd, src);
2994 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2995 if (!hapd->conf->wds_sta)
2998 if (wds && !(sta->flags & WLAN_STA_WDS)) {
3000 char ifname_wds[IFNAMSIZ + 1];
3002 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3003 "STA " MACSTR " (aid %u)",
3004 MAC2STR(sta->addr), sta->aid);
3005 sta->flags |= WLAN_STA_WDS;
3006 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3007 sta->addr, sta->aid, 1);
3009 hostapd_set_wds_encryption(hapd, sta,
3015 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3016 MACSTR, MAC2STR(src));
3017 if (src[0] & 0x01) {
3018 /* Broadcast bit set in SA?! Ignore the frame silently. */
3022 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3023 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3024 "already been sent, but no TX status yet known - "
3025 "ignore Class 3 frame issue with " MACSTR,
3030 if (sta && (sta->flags & WLAN_STA_AUTH))
3031 hostapd_drv_sta_disassoc(
3033 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3035 hostapd_drv_sta_deauth(
3037 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3041 #endif /* CONFIG_NATIVE_WINDOWS */