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"
47 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
52 if (hapd->iface->current_rates == NULL)
55 *pos++ = WLAN_EID_SUPP_RATES;
56 num = hapd->iface->num_rates;
57 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
59 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
62 /* rest of the rates are encoded in Extended supported
68 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
71 *pos = hapd->iface->current_rates[i].rate / 5;
72 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
77 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
79 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
82 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
84 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
91 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
96 if (hapd->iface->current_rates == NULL)
99 num = hapd->iface->num_rates;
100 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
102 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
108 *pos++ = WLAN_EID_EXT_SUPP_RATES;
110 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
114 continue; /* already in SuppRates IE */
115 *pos = hapd->iface->current_rates[i].rate / 5;
116 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
121 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
124 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
127 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
130 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
137 u16 hostapd_own_capab_info(struct hostapd_data *hapd)
139 int capab = WLAN_CAPABILITY_ESS;
143 /* Check if any of configured channels require DFS */
144 dfs = hostapd_is_dfs_required(hapd->iface);
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
151 if (hapd->iface->num_sta_no_short_preamble == 0 &&
152 hapd->iconf->preamble == SHORT_PREAMBLE)
153 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
155 privacy = hapd->conf->ssid.wep.keys_set;
157 if (hapd->conf->ieee802_1x &&
158 (hapd->conf->default_wep_key_len ||
159 hapd->conf->individual_wep_key_len))
166 if (hapd->conf->osen)
168 #endif /* CONFIG_HS20 */
171 capab |= WLAN_CAPABILITY_PRIVACY;
173 if (hapd->iface->current_mode &&
174 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
175 hapd->iface->num_sta_no_short_slot_time == 0)
176 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
179 * Currently, Spectrum Management capability bit is set when directly
180 * requested in configuration by spectrum_mgmt_required or when AP is
181 * running on DFS channel.
182 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
184 if (hapd->iface->current_mode &&
185 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
186 (hapd->iconf->spectrum_mgmt_required || dfs))
187 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
189 if (hapd->conf->radio_measurements)
190 capab |= IEEE80211_CAP_RRM;
196 #ifndef CONFIG_NO_RC4
197 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
198 u16 auth_transaction, const u8 *challenge,
201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
203 "authentication (shared key, transaction %d)",
206 if (auth_transaction == 1) {
207 if (!sta->challenge) {
208 /* Generate a pseudo-random challenge */
211 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
212 if (sta->challenge == NULL)
213 return WLAN_STATUS_UNSPECIFIED_FAILURE;
215 if (os_get_random(key, sizeof(key)) < 0) {
216 os_free(sta->challenge);
217 sta->challenge = NULL;
218 return WLAN_STATUS_UNSPECIFIED_FAILURE;
221 rc4_skip(key, sizeof(key), 0,
222 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
227 if (auth_transaction != 3)
228 return WLAN_STATUS_UNSPECIFIED_FAILURE;
231 if (!iswep || !sta->challenge || !challenge ||
232 os_memcmp_const(sta->challenge, challenge,
233 WLAN_AUTH_CHALLENGE_LEN)) {
234 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
236 "shared key authentication - invalid "
237 "challenge-response");
238 return WLAN_STATUS_CHALLENGE_FAIL;
241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 "authentication OK (shared key)");
244 sta->flags |= WLAN_STA_AUTH;
245 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
246 os_free(sta->challenge);
247 sta->challenge = NULL;
251 #endif /* CONFIG_NO_RC4 */
254 static int send_auth_reply(struct hostapd_data *hapd,
255 const u8 *dst, const u8 *bssid,
256 u16 auth_alg, u16 auth_transaction, u16 resp,
257 const u8 *ies, size_t ies_len)
259 struct ieee80211_mgmt *reply;
262 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
264 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
265 buf = os_zalloc(rlen);
269 reply = (struct ieee80211_mgmt *) buf;
270 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
272 os_memcpy(reply->da, dst, ETH_ALEN);
273 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
274 os_memcpy(reply->bssid, bssid, ETH_ALEN);
276 reply->u.auth.auth_alg = host_to_le16(auth_alg);
277 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
278 reply->u.auth.status_code = host_to_le16(resp);
281 os_memcpy(reply->u.auth.variable, ies, ies_len);
283 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
284 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
285 MAC2STR(dst), auth_alg, auth_transaction,
286 resp, (unsigned long) ies_len);
287 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
288 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
290 reply_res = WLAN_STATUS_SUCCESS;
298 #ifdef CONFIG_IEEE80211R
299 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
300 u16 auth_transaction, u16 status,
301 const u8 *ies, size_t ies_len)
303 struct hostapd_data *hapd = ctx;
304 struct sta_info *sta;
307 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
308 auth_transaction, status, ies, ies_len);
310 sta = ap_get_sta(hapd, dst);
314 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
315 status != WLAN_STATUS_SUCCESS)) {
316 hostapd_drv_sta_remove(hapd, sta->addr);
317 sta->added_unassoc = 0;
321 if (status != WLAN_STATUS_SUCCESS)
324 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
325 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
326 sta->flags |= WLAN_STA_AUTH;
327 mlme_authenticate_indication(hapd, sta);
329 #endif /* CONFIG_IEEE80211R */
334 #define dot11RSNASAESync 5 /* attempts */
337 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
338 struct sta_info *sta, int update)
342 if (hapd->conf->ssid.wpa_passphrase == NULL) {
343 wpa_printf(MSG_DEBUG, "SAE: No password available");
348 sae_prepare_commit(hapd->own_addr, sta->addr,
349 (u8 *) hapd->conf->ssid.wpa_passphrase,
350 os_strlen(hapd->conf->ssid.wpa_passphrase),
352 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
356 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
359 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
360 sta->sae->tmp->anti_clogging_token : NULL);
366 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
367 struct sta_info *sta)
371 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
375 sae_write_confirm(sta->sae, buf);
381 static int auth_sae_send_commit(struct hostapd_data *hapd,
382 struct sta_info *sta,
383 const u8 *bssid, int update)
388 data = auth_build_sae_commit(hapd, sta, update);
390 return WLAN_STATUS_UNSPECIFIED_FAILURE;
392 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
393 WLAN_STATUS_SUCCESS, wpabuf_head(data),
402 static int auth_sae_send_confirm(struct hostapd_data *hapd,
403 struct sta_info *sta,
409 data = auth_build_sae_confirm(hapd, sta);
411 return WLAN_STATUS_UNSPECIFIED_FAILURE;
413 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
414 WLAN_STATUS_SUCCESS, wpabuf_head(data),
423 static int use_sae_anti_clogging(struct hostapd_data *hapd)
425 struct sta_info *sta;
426 unsigned int open = 0;
428 if (hapd->conf->sae_anti_clogging_threshold == 0)
431 for (sta = hapd->sta_list; sta; sta = sta->next) {
434 if (sta->sae->state != SAE_COMMITTED &&
435 sta->sae->state != SAE_CONFIRMED)
438 if (open >= hapd->conf->sae_anti_clogging_threshold)
446 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
447 const u8 *token, size_t token_len)
449 u8 mac[SHA256_MAC_LEN];
451 if (token_len != SHA256_MAC_LEN)
453 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
454 addr, ETH_ALEN, mac) < 0 ||
455 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
462 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
463 int group, const u8 *addr)
467 struct os_reltime now;
469 os_get_reltime(&now);
470 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
471 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
472 if (random_get_bytes(hapd->sae_token_key,
473 sizeof(hapd->sae_token_key)) < 0)
475 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
476 hapd->sae_token_key, sizeof(hapd->sae_token_key));
477 hapd->last_sae_token_key_update = now;
480 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
484 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
486 token = wpabuf_put(buf, SHA256_MAC_LEN);
487 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
488 addr, ETH_ALEN, token);
494 static int sae_check_big_sync(struct sta_info *sta)
496 if (sta->sae->sync > dot11RSNASAESync) {
497 sta->sae->state = SAE_NOTHING;
505 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
507 struct hostapd_data *hapd = eloop_ctx;
508 struct sta_info *sta = eloop_data;
511 if (sae_check_big_sync(sta))
515 switch (sta->sae->state) {
517 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
518 eloop_register_timeout(0,
519 hapd->dot11RSNASAERetransPeriod * 1000,
520 auth_sae_retransmit_timer, hapd, sta);
523 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
524 eloop_register_timeout(0,
525 hapd->dot11RSNASAERetransPeriod * 1000,
526 auth_sae_retransmit_timer, hapd, sta);
533 if (ret != WLAN_STATUS_SUCCESS)
534 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
538 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
540 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
544 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
545 struct sta_info *sta)
547 if (!(hapd->conf->mesh & MESH_ENABLED))
550 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
551 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
552 auth_sae_retransmit_timer, hapd, sta);
556 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
557 const u8 *bssid, u8 auth_transaction)
561 if (auth_transaction != 1 && auth_transaction != 2)
562 return WLAN_STATUS_UNSPECIFIED_FAILURE;
564 switch (sta->sae->state) {
566 if (auth_transaction == 1) {
567 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
570 sta->sae->state = SAE_COMMITTED;
572 if (sae_process_commit(sta->sae) < 0)
573 return WLAN_STATUS_UNSPECIFIED_FAILURE;
576 * In mesh case, both Commit and Confirm can be sent
577 * immediately. In infrastructure BSS, only a single
578 * Authentication frame (Commit) is expected from the AP
579 * here and the second one (Confirm) will be sent once
580 * the STA has sent its second Authentication frame
583 if (hapd->conf->mesh & MESH_ENABLED) {
585 * Send both Commit and Confirm immediately
586 * based on SAE finite state machine
587 * Nothing -> Confirm transition.
589 ret = auth_sae_send_confirm(hapd, sta, bssid);
592 sta->sae->state = SAE_CONFIRMED;
595 * For infrastructure BSS, send only the Commit
596 * message now to get alternating sequence of
597 * Authentication frames between the AP and STA.
598 * Confirm will be sent in
599 * Commited -> Confirmed/Accepted transition
600 * when receiving Confirm from STA.
604 sae_set_retransmit_timer(hapd, sta);
606 hostapd_logger(hapd, sta->addr,
607 HOSTAPD_MODULE_IEEE80211,
609 "SAE confirm before commit");
613 sae_clear_retransmit_timer(hapd, sta);
614 if (auth_transaction == 1) {
615 if (sae_process_commit(sta->sae) < 0)
616 return WLAN_STATUS_UNSPECIFIED_FAILURE;
618 ret = auth_sae_send_confirm(hapd, sta, bssid);
621 sta->sae->state = SAE_CONFIRMED;
623 sae_set_retransmit_timer(hapd, sta);
624 } else if (hapd->conf->mesh & MESH_ENABLED) {
626 * In mesh case, follow SAE finite state machine and
627 * send Commit now, if sync count allows.
629 if (sae_check_big_sync(sta))
630 return WLAN_STATUS_SUCCESS;
633 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
637 sae_set_retransmit_timer(hapd, sta);
640 * For instructure BSS, send the postponed Confirm from
641 * Nothing -> Confirmed transition that was reduced to
642 * Nothing -> Committed above.
644 ret = auth_sae_send_confirm(hapd, sta, bssid);
648 sta->sae->state = SAE_CONFIRMED;
651 * Since this was triggered on Confirm RX, run another
652 * step to get to Accepted without waiting for
655 return sae_sm_step(hapd, sta, bssid, auth_transaction);
659 sae_clear_retransmit_timer(hapd, sta);
660 if (auth_transaction == 1) {
661 if (sae_check_big_sync(sta))
662 return WLAN_STATUS_SUCCESS;
665 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
669 if (sae_process_commit(sta->sae) < 0)
670 return WLAN_STATUS_UNSPECIFIED_FAILURE;
672 ret = auth_sae_send_confirm(hapd, sta, bssid);
676 sae_set_retransmit_timer(hapd, sta);
678 sta->flags |= WLAN_STA_AUTH;
679 sta->auth_alg = WLAN_AUTH_SAE;
680 mlme_authenticate_indication(hapd, sta);
681 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
682 sta->sae->state = SAE_ACCEPTED;
683 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
684 sta->sae->pmk, sta->sae->pmkid);
688 if (auth_transaction == 1) {
689 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
690 ") doing reauthentication",
692 ap_free_sta(hapd, sta);
694 if (sae_check_big_sync(sta))
695 return WLAN_STATUS_SUCCESS;
698 ret = auth_sae_send_confirm(hapd, sta, bssid);
699 sae_clear_temp_data(sta->sae);
705 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
707 return WLAN_STATUS_UNSPECIFIED_FAILURE;
709 return WLAN_STATUS_SUCCESS;
713 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
714 const struct ieee80211_mgmt *mgmt, size_t len,
715 u16 auth_transaction, u16 status_code)
717 int resp = WLAN_STATUS_SUCCESS;
718 struct wpabuf *data = NULL;
721 if (auth_transaction != 1 ||
722 status_code != WLAN_STATUS_SUCCESS) {
726 sta->sae = os_zalloc(sizeof(*sta->sae));
731 sta->sae->state = SAE_NOTHING;
735 if (auth_transaction == 1) {
736 const u8 *token = NULL, *pos, *end;
737 size_t token_len = 0;
738 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
740 "start SAE authentication (RX commit, status=%u)",
743 if ((hapd->conf->mesh & MESH_ENABLED) &&
744 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
746 pos = mgmt->u.auth.variable;
747 end = ((const u8 *) mgmt) + len;
748 if (pos + sizeof(le16) > end) {
749 wpa_printf(MSG_ERROR,
750 "SAE: Too short anti-clogging token request");
751 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
754 resp = sae_group_allowed(sta->sae,
755 hapd->conf->sae_groups,
757 if (resp != WLAN_STATUS_SUCCESS) {
758 wpa_printf(MSG_ERROR,
759 "SAE: Invalid group in anti-clogging token request");
764 wpabuf_free(sta->sae->tmp->anti_clogging_token);
765 sta->sae->tmp->anti_clogging_token =
766 wpabuf_alloc_copy(pos, end - pos);
767 if (sta->sae->tmp->anti_clogging_token == NULL) {
768 wpa_printf(MSG_ERROR,
769 "SAE: Failed to alloc for anti-clogging token");
770 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
775 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
776 * is 76, a new Commit Message shall be constructed
777 * with the Anti-Clogging Token from the received
778 * Authentication frame, and the commit-scalar and
779 * COMMIT-ELEMENT previously sent.
781 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
782 if (resp != WLAN_STATUS_SUCCESS) {
783 wpa_printf(MSG_ERROR,
784 "SAE: Failed to send commit message");
787 sta->sae->state = SAE_COMMITTED;
789 sae_set_retransmit_timer(hapd, sta);
793 if (status_code != WLAN_STATUS_SUCCESS)
796 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
797 ((const u8 *) mgmt) + len -
798 mgmt->u.auth.variable, &token,
799 &token_len, hapd->conf->sae_groups);
800 if (resp == SAE_SILENTLY_DISCARD) {
801 wpa_printf(MSG_DEBUG,
802 "SAE: Drop commit message from " MACSTR " due to reflection attack",
806 if (token && check_sae_token(hapd, sta->addr, token, token_len)
808 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
809 "incorrect token from " MACSTR,
811 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
815 if (resp != WLAN_STATUS_SUCCESS)
818 if (!token && use_sae_anti_clogging(hapd)) {
819 wpa_printf(MSG_DEBUG,
820 "SAE: Request anti-clogging token from "
821 MACSTR, MAC2STR(sta->addr));
822 data = auth_build_token_req(hapd, sta->sae->group,
824 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
825 if (hapd->conf->mesh & MESH_ENABLED)
826 sta->sae->state = SAE_NOTHING;
830 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
831 } else if (auth_transaction == 2) {
832 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
834 "SAE authentication (RX confirm, status=%u)",
836 if (status_code != WLAN_STATUS_SUCCESS)
838 if (sta->sae->state >= SAE_CONFIRMED ||
839 !(hapd->conf->mesh & MESH_ENABLED)) {
840 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
841 ((u8 *) mgmt) + len -
842 mgmt->u.auth.variable) < 0) {
843 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
847 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
849 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
851 "unexpected SAE authentication transaction %u (status=%u)",
852 auth_transaction, status_code);
853 if (status_code != WLAN_STATUS_SUCCESS)
855 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
859 if (resp != WLAN_STATUS_SUCCESS) {
860 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
861 auth_transaction, resp,
862 data ? wpabuf_head(data) : (u8 *) "",
863 data ? wpabuf_len(data) : 0);
867 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
868 status_code != WLAN_STATUS_SUCCESS)) {
869 hostapd_drv_sta_remove(hapd, sta->addr);
870 sta->added_unassoc = 0;
877 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
878 * @hapd: BSS data for the device initiating the authentication
879 * @sta: the peer to which commit authentication frame is sent
881 * This function implements Init event handling (IEEE Std 802.11-2012,
882 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
883 * sta->sae structure should be initialized appropriately via a call to
884 * sae_prepare_commit().
886 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
890 if (!sta->sae || !sta->sae->tmp)
893 if (sta->sae->state != SAE_NOTHING)
896 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
900 sta->sae->state = SAE_COMMITTED;
902 sae_set_retransmit_timer(hapd, sta);
907 #endif /* CONFIG_SAE */
910 static void handle_auth(struct hostapd_data *hapd,
911 const struct ieee80211_mgmt *mgmt, size_t len)
913 u16 auth_alg, auth_transaction, status_code;
914 u16 resp = WLAN_STATUS_SUCCESS;
915 struct sta_info *sta = NULL;
918 const u8 *challenge = NULL;
919 u32 session_timeout, acct_interim_interval;
920 struct vlan_description vlan_id;
921 struct hostapd_sta_wpa_psk_short *psk = NULL;
922 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
923 size_t resp_ies_len = 0;
924 char *identity = NULL;
925 char *radius_cui = NULL;
928 os_memset(&vlan_id, 0, sizeof(vlan_id));
930 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
931 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
932 (unsigned long) len);
936 #ifdef CONFIG_TESTING_OPTIONS
937 if (hapd->iconf->ignore_auth_probability > 0.0 &&
938 drand48() < hapd->iconf->ignore_auth_probability) {
940 "TESTING: ignoring auth frame from " MACSTR,
944 #endif /* CONFIG_TESTING_OPTIONS */
946 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
947 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
948 status_code = le_to_host16(mgmt->u.auth.status_code);
949 fc = le_to_host16(mgmt->frame_control);
950 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
952 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
953 2 + WLAN_AUTH_CHALLENGE_LEN &&
954 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
955 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
956 challenge = &mgmt->u.auth.variable[2];
958 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
959 "auth_transaction=%d status_code=%d wep=%d%s "
961 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
962 status_code, !!(fc & WLAN_FC_ISWEP),
963 challenge ? " challenge" : "",
964 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
967 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
969 "Unsupported authentication algorithm (%d)",
971 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
974 #endif /* CONFIG_NO_RC4 */
976 if (hapd->tkip_countermeasures) {
977 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
981 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
982 auth_alg == WLAN_AUTH_OPEN) ||
983 #ifdef CONFIG_IEEE80211R
984 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
985 auth_alg == WLAN_AUTH_FT) ||
986 #endif /* CONFIG_IEEE80211R */
988 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
989 auth_alg == WLAN_AUTH_SAE) ||
990 #endif /* CONFIG_SAE */
991 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
992 auth_alg == WLAN_AUTH_SHARED_KEY))) {
993 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
995 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
999 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
1000 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
1001 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1003 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1007 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
1008 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1010 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1014 if (hapd->conf->no_auth_if_seen_on) {
1015 struct hostapd_data *other;
1017 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1018 hapd->conf->no_auth_if_seen_on);
1022 u8 op_class, channel, phytype;
1024 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1025 MACSTR " since STA has been seen on %s",
1026 hapd->conf->iface, MAC2STR(mgmt->sa),
1027 hapd->conf->no_auth_if_seen_on);
1029 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1031 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1033 os_memcpy(pos, other->own_addr, ETH_ALEN);
1035 info = 0; /* TODO: BSSID Information */
1036 WPA_PUT_LE32(pos, info);
1038 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1039 phytype = 8; /* dmg */
1040 else if (other->iconf->ieee80211ac)
1041 phytype = 9; /* vht */
1042 else if (other->iconf->ieee80211n)
1043 phytype = 7; /* ht */
1044 else if (other->iconf->hw_mode ==
1045 HOSTAPD_MODE_IEEE80211A)
1046 phytype = 4; /* ofdm */
1047 else if (other->iconf->hw_mode ==
1048 HOSTAPD_MODE_IEEE80211G)
1049 phytype = 6; /* erp */
1051 phytype = 5; /* hrdsss */
1052 if (ieee80211_freq_to_channel_ext(
1053 hostapd_hw_get_freq(other,
1054 other->iconf->channel),
1055 other->iconf->secondary_channel,
1056 other->iconf->ieee80211ac,
1057 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1059 channel = other->iconf->channel;
1064 resp_ies_len = pos - &resp_ies[0];
1069 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1071 &acct_interim_interval, &vlan_id,
1072 &psk, &identity, &radius_cui);
1074 if (res == HOSTAPD_ACL_REJECT) {
1075 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1077 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1080 if (res == HOSTAPD_ACL_PENDING) {
1081 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1082 " waiting for an external authentication",
1084 /* Authentication code will re-send the authentication frame
1085 * after it has received (and cached) information from the
1086 * external source. */
1090 sta = ap_get_sta(hapd, mgmt->sa);
1092 if ((fc & WLAN_FC_RETRY) &&
1093 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1094 sta->last_seq_ctrl == seq_ctrl &&
1095 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1096 hostapd_logger(hapd, sta->addr,
1097 HOSTAPD_MODULE_IEEE80211,
1098 HOSTAPD_LEVEL_DEBUG,
1099 "Drop repeated authentication frame seq_ctrl=0x%x",
1104 if ((hapd->conf->mesh & MESH_ENABLED) &&
1105 sta->plink_state == PLINK_BLOCKED) {
1106 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1107 " is blocked - drop Authentication frame",
1111 #endif /* CONFIG_MESH */
1114 if (hapd->conf->mesh & MESH_ENABLED) {
1115 /* if the mesh peer is not available, we don't do auth.
1117 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1118 " not yet known - drop Authentication frame",
1121 * Save a copy of the frame so that it can be processed
1122 * if a new peer entry is added shortly after this.
1124 wpabuf_free(hapd->mesh_pending_auth);
1125 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1126 os_get_reltime(&hapd->mesh_pending_auth_time);
1129 #endif /* CONFIG_MESH */
1131 sta = ap_sta_add(hapd, mgmt->sa);
1133 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1137 sta->last_seq_ctrl = seq_ctrl;
1138 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1140 if (vlan_id.notempty &&
1141 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1142 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1144 "Invalid VLAN %d%s received from RADIUS server",
1146 vlan_id.tagged[0] ? "+" : "");
1147 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1150 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1151 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1155 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1156 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1158 hostapd_free_psk_list(sta->psk);
1159 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1166 sta->identity = identity;
1168 sta->radius_cui = radius_cui;
1171 sta->flags &= ~WLAN_STA_PREAUTH;
1172 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1174 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1175 sta->acct_interim_interval = acct_interim_interval;
1176 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1177 ap_sta_session_timeout(hapd, sta, session_timeout);
1179 ap_sta_no_session_timeout(hapd, sta);
1182 * If the driver supports full AP client state, add a station to the
1183 * driver before sending authentication reply to make sure the driver
1184 * has resources, and not to go through the entire authentication and
1185 * association handshake, and fail it at the end.
1187 * If this is not the first transaction, in a multi-step authentication
1188 * algorithm, the station already exists in the driver
1189 * (sta->added_unassoc = 1) so skip it.
1191 * In mesh mode, the station was already added to the driver when the
1192 * NEW_PEER_CANDIDATE event is received.
1194 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1195 !(hapd->conf->mesh & MESH_ENABLED) &&
1196 !(sta->added_unassoc)) {
1198 * If a station that is already associated to the AP, is trying
1199 * to authenticate again, remove the STA entry, in order to make
1200 * sure the STA PS state gets cleared and configuration gets
1201 * updated. To handle this, station's added_unassoc flag is
1202 * cleared once the station has completed association.
1204 hostapd_drv_sta_remove(hapd, sta->addr);
1205 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1206 WLAN_STA_AUTHORIZED);
1208 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1209 NULL, NULL, sta->flags, 0, 0, 0)) {
1210 hostapd_logger(hapd, sta->addr,
1211 HOSTAPD_MODULE_IEEE80211,
1212 HOSTAPD_LEVEL_NOTICE,
1213 "Could not add STA to kernel driver");
1214 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1218 sta->added_unassoc = 1;
1222 case WLAN_AUTH_OPEN:
1223 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1224 HOSTAPD_LEVEL_DEBUG,
1225 "authentication OK (open system)");
1226 sta->flags |= WLAN_STA_AUTH;
1227 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1228 sta->auth_alg = WLAN_AUTH_OPEN;
1229 mlme_authenticate_indication(hapd, sta);
1231 #ifndef CONFIG_NO_RC4
1232 case WLAN_AUTH_SHARED_KEY:
1233 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1234 fc & WLAN_FC_ISWEP);
1235 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1236 mlme_authenticate_indication(hapd, sta);
1237 if (sta->challenge && auth_transaction == 1) {
1238 resp_ies[0] = WLAN_EID_CHALLENGE;
1239 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1240 os_memcpy(resp_ies + 2, sta->challenge,
1241 WLAN_AUTH_CHALLENGE_LEN);
1242 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1245 #endif /* CONFIG_NO_RC4 */
1246 #ifdef CONFIG_IEEE80211R
1248 sta->auth_alg = WLAN_AUTH_FT;
1249 if (sta->wpa_sm == NULL)
1250 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1252 if (sta->wpa_sm == NULL) {
1253 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1255 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1258 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1259 auth_transaction, mgmt->u.auth.variable,
1260 len - IEEE80211_HDRLEN -
1261 sizeof(mgmt->u.auth),
1262 handle_auth_ft_finish, hapd);
1263 /* handle_auth_ft_finish() callback will complete auth. */
1265 #endif /* CONFIG_IEEE80211R */
1269 if (status_code == WLAN_STATUS_SUCCESS &&
1270 hapd->conf->mesh & MESH_ENABLED) {
1271 if (sta->wpa_sm == NULL)
1273 wpa_auth_sta_init(hapd->wpa_auth,
1275 if (sta->wpa_sm == NULL) {
1276 wpa_printf(MSG_DEBUG,
1277 "SAE: Failed to initialize WPA state machine");
1278 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1282 #endif /* CONFIG_MESH */
1283 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1286 #endif /* CONFIG_SAE */
1291 os_free(radius_cui);
1292 hostapd_free_psk_list(psk);
1294 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1295 auth_transaction + 1, resp, resp_ies,
1298 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1299 reply_res != WLAN_STATUS_SUCCESS)) {
1300 hostapd_drv_sta_remove(hapd, sta->addr);
1301 sta->added_unassoc = 0;
1306 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1310 /* get a unique AID */
1312 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1316 for (i = 0; i < AID_WORDS; i++) {
1317 if (hapd->sta_aid[i] == (u32) -1)
1319 for (j = 0; j < 32; j++) {
1320 if (!(hapd->sta_aid[i] & BIT(j)))
1328 aid = i * 32 + j + 1;
1333 hapd->sta_aid[i] |= BIT(j);
1334 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1339 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1340 const u8 *ssid_ie, size_t ssid_ie_len)
1342 if (ssid_ie == NULL)
1343 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1345 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1346 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1347 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1349 "Station tried to associate with unknown SSID "
1350 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1351 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1354 return WLAN_STATUS_SUCCESS;
1358 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1359 const u8 *wmm_ie, size_t wmm_ie_len)
1361 sta->flags &= ~WLAN_STA_WMM;
1363 if (wmm_ie && hapd->conf->wmm_enabled) {
1364 struct wmm_information_element *wmm;
1366 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1367 hostapd_logger(hapd, sta->addr,
1369 HOSTAPD_LEVEL_DEBUG,
1370 "invalid WMM element in association "
1372 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1375 sta->flags |= WLAN_STA_WMM;
1376 wmm = (struct wmm_information_element *) wmm_ie;
1377 sta->qosinfo = wmm->qos_info;
1379 return WLAN_STATUS_SUCCESS;
1383 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1384 struct ieee802_11_elems *elems)
1386 if (!elems->supp_rates) {
1387 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1388 HOSTAPD_LEVEL_DEBUG,
1389 "No supported rates element in AssocReq");
1390 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1393 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1394 sizeof(sta->supported_rates)) {
1395 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1396 HOSTAPD_LEVEL_DEBUG,
1397 "Invalid supported rates element length %d+%d",
1398 elems->supp_rates_len,
1399 elems->ext_supp_rates_len);
1400 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1403 sta->supported_rates_len = merge_byte_arrays(
1404 sta->supported_rates, sizeof(sta->supported_rates),
1405 elems->supp_rates, elems->supp_rates_len,
1406 elems->ext_supp_rates, elems->ext_supp_rates_len);
1408 return WLAN_STATUS_SUCCESS;
1412 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1413 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1415 #ifdef CONFIG_INTERWORKING
1416 /* check for QoS Map support */
1417 if (ext_capab_ie_len >= 5) {
1418 if (ext_capab_ie[4] & 0x01)
1419 sta->qos_map_enabled = 1;
1421 #endif /* CONFIG_INTERWORKING */
1423 if (ext_capab_ie_len > 0)
1424 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1426 return WLAN_STATUS_SUCCESS;
1430 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1431 const u8 *ies, size_t ies_len, int reassoc)
1433 struct ieee802_11_elems elems;
1437 const u8 *p2p_dev_addr = NULL;
1439 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1440 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1441 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1442 "association request");
1443 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1446 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1447 if (resp != WLAN_STATUS_SUCCESS)
1449 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1450 if (resp != WLAN_STATUS_SUCCESS)
1452 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1453 if (resp != WLAN_STATUS_SUCCESS)
1455 resp = copy_supp_rates(hapd, sta, &elems);
1456 if (resp != WLAN_STATUS_SUCCESS)
1458 #ifdef CONFIG_IEEE80211N
1459 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1460 if (resp != WLAN_STATUS_SUCCESS)
1462 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1463 !(sta->flags & WLAN_STA_HT)) {
1464 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1465 HOSTAPD_LEVEL_INFO, "Station does not support "
1466 "mandatory HT PHY - reject association");
1467 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1469 #endif /* CONFIG_IEEE80211N */
1471 #ifdef CONFIG_IEEE80211AC
1472 if (hapd->iconf->ieee80211ac) {
1473 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1474 if (resp != WLAN_STATUS_SUCCESS)
1477 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1478 if (resp != WLAN_STATUS_SUCCESS)
1482 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1483 !(sta->flags & WLAN_STA_VHT)) {
1484 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1485 HOSTAPD_LEVEL_INFO, "Station does not support "
1486 "mandatory VHT PHY - reject association");
1487 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1490 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1491 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1492 elems.vendor_vht_len);
1493 if (resp != WLAN_STATUS_SUCCESS)
1496 #endif /* CONFIG_IEEE80211AC */
1500 wpabuf_free(sta->p2p_ie);
1501 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1502 P2P_IE_VENDOR_TYPE);
1504 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1506 wpabuf_free(sta->p2p_ie);
1509 #endif /* CONFIG_P2P */
1511 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1512 wpa_ie = elems.rsn_ie;
1513 wpa_ie_len = elems.rsn_ie_len;
1514 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1516 wpa_ie = elems.wpa_ie;
1517 wpa_ie_len = elems.wpa_ie_len;
1524 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1525 if (hapd->conf->wps_state && elems.wps_ie) {
1526 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1527 "Request - assume WPS is used");
1528 sta->flags |= WLAN_STA_WPS;
1529 wpabuf_free(sta->wps_ie);
1530 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1531 WPS_IE_VENDOR_TYPE);
1532 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1533 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1534 sta->flags |= WLAN_STA_WPS2;
1538 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1539 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1540 "(Re)Association Request - reject");
1541 return WLAN_STATUS_INVALID_IE;
1543 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1544 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1545 "(Re)Association Request - possible WPS use");
1546 sta->flags |= WLAN_STA_MAYBE_WPS;
1548 #endif /* CONFIG_WPS */
1549 if (hapd->conf->wpa && wpa_ie == NULL) {
1550 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1552 "No WPA/RSN IE in association request");
1553 return WLAN_STATUS_INVALID_IE;
1556 if (hapd->conf->wpa && wpa_ie) {
1560 if (sta->wpa_sm == NULL)
1561 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1564 if (sta->wpa_sm == NULL) {
1565 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1567 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1569 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1571 elems.mdie, elems.mdie_len);
1572 if (res == WPA_INVALID_GROUP)
1573 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1574 else if (res == WPA_INVALID_PAIRWISE)
1575 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1576 else if (res == WPA_INVALID_AKMP)
1577 resp = WLAN_STATUS_AKMP_NOT_VALID;
1578 else if (res == WPA_ALLOC_FAIL)
1579 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1580 #ifdef CONFIG_IEEE80211W
1581 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1582 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1583 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1584 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1585 #endif /* CONFIG_IEEE80211W */
1586 else if (res == WPA_INVALID_MDIE)
1587 resp = WLAN_STATUS_INVALID_MDIE;
1588 else if (res != WPA_IE_OK)
1589 resp = WLAN_STATUS_INVALID_IE;
1590 if (resp != WLAN_STATUS_SUCCESS)
1592 #ifdef CONFIG_IEEE80211W
1593 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1594 sta->sa_query_count > 0)
1595 ap_check_sa_query_timeout(hapd, sta);
1596 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1597 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1599 * STA has already been associated with MFP and SA
1600 * Query timeout has not been reached. Reject the
1601 * association attempt temporarily and start SA Query,
1602 * if one is not pending.
1605 if (sta->sa_query_count == 0)
1606 ap_sta_start_sa_query(hapd, sta);
1608 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1611 if (wpa_auth_uses_mfp(sta->wpa_sm))
1612 sta->flags |= WLAN_STA_MFP;
1614 sta->flags &= ~WLAN_STA_MFP;
1615 #endif /* CONFIG_IEEE80211W */
1617 #ifdef CONFIG_IEEE80211R
1618 if (sta->auth_alg == WLAN_AUTH_FT) {
1620 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1621 "to use association (not "
1622 "re-association) with FT auth_alg",
1623 MAC2STR(sta->addr));
1624 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1627 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1629 if (resp != WLAN_STATUS_SUCCESS)
1632 #endif /* CONFIG_IEEE80211R */
1635 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1636 sta->auth_alg == WLAN_AUTH_OPEN) {
1637 struct rsn_pmksa_cache_entry *sa;
1638 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1639 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1640 wpa_printf(MSG_DEBUG,
1641 "SAE: No PMKSA cache entry found for "
1642 MACSTR, MAC2STR(sta->addr));
1643 return WLAN_STATUS_INVALID_PMKID;
1645 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1646 " using PMKSA caching", MAC2STR(sta->addr));
1647 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1648 sta->auth_alg != WLAN_AUTH_SAE &&
1649 !(sta->auth_alg == WLAN_AUTH_FT &&
1650 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1651 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1652 "SAE AKM after non-SAE auth_alg %u",
1653 MAC2STR(sta->addr), sta->auth_alg);
1654 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1656 #endif /* CONFIG_SAE */
1658 #ifdef CONFIG_IEEE80211N
1659 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1660 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1661 hostapd_logger(hapd, sta->addr,
1662 HOSTAPD_MODULE_IEEE80211,
1664 "Station tried to use TKIP with HT "
1666 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1668 #endif /* CONFIG_IEEE80211N */
1670 } else if (hapd->conf->osen) {
1671 if (elems.osen == NULL) {
1673 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1675 "No HS 2.0 OSEN element in association request");
1676 return WLAN_STATUS_INVALID_IE;
1679 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1680 if (sta->wpa_sm == NULL)
1681 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1683 if (sta->wpa_sm == NULL) {
1684 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1686 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1688 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1689 elems.osen - 2, elems.osen_len + 2) < 0)
1690 return WLAN_STATUS_INVALID_IE;
1691 #endif /* CONFIG_HS20 */
1693 wpa_auth_sta_no_wpa(sta->wpa_sm);
1696 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1697 #endif /* CONFIG_P2P */
1700 wpabuf_free(sta->hs20_ie);
1701 if (elems.hs20 && elems.hs20_len > 4) {
1702 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1703 elems.hs20_len - 4);
1705 sta->hs20_ie = NULL;
1706 #endif /* CONFIG_HS20 */
1709 wpabuf_free(sta->mb_ies);
1710 if (hapd->iface->fst)
1711 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1714 #endif /* CONFIG_FST */
1716 return WLAN_STATUS_SUCCESS;
1720 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1724 struct ieee80211_mgmt reply;
1726 os_memset(&reply, 0, sizeof(reply));
1727 reply.frame_control =
1728 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1729 os_memcpy(reply.da, addr, ETH_ALEN);
1730 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1731 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1733 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1734 reply.u.deauth.reason_code = host_to_le16(reason_code);
1736 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1737 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1742 static int add_associated_sta(struct hostapd_data *hapd,
1743 struct sta_info *sta)
1745 struct ieee80211_ht_capabilities ht_cap;
1746 struct ieee80211_vht_capabilities vht_cap;
1749 * Remove the STA entry to ensure the STA PS state gets cleared and
1750 * configuration gets updated. This is relevant for cases, such as
1751 * FT-over-the-DS, where a station re-associates back to the same AP but
1752 * skips the authentication flow, or if working with a driver that
1753 * does not support full AP client state.
1755 if (!sta->added_unassoc)
1756 hostapd_drv_sta_remove(hapd, sta->addr);
1758 #ifdef CONFIG_IEEE80211N
1759 if (sta->flags & WLAN_STA_HT)
1760 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1761 #endif /* CONFIG_IEEE80211N */
1762 #ifdef CONFIG_IEEE80211AC
1763 if (sta->flags & WLAN_STA_VHT)
1764 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1765 #endif /* CONFIG_IEEE80211AC */
1768 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1769 * will be set when the ACK frame for the (Re)Association Response frame
1770 * is processed (TX status driver event).
1772 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1773 sta->supported_rates, sta->supported_rates_len,
1774 sta->listen_interval,
1775 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1776 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1777 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1778 sta->vht_opmode, sta->added_unassoc)) {
1779 hostapd_logger(hapd, sta->addr,
1780 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1781 "Could not %s STA to kernel driver",
1782 sta->added_unassoc ? "set" : "add");
1784 if (sta->added_unassoc) {
1785 hostapd_drv_sta_remove(hapd, sta->addr);
1786 sta->added_unassoc = 0;
1792 sta->added_unassoc = 0;
1798 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1799 u16 status_code, int reassoc, const u8 *ies,
1803 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1804 struct ieee80211_mgmt *reply;
1807 os_memset(buf, 0, sizeof(buf));
1808 reply = (struct ieee80211_mgmt *) buf;
1809 reply->frame_control =
1810 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1811 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1812 WLAN_FC_STYPE_ASSOC_RESP));
1813 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1814 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1815 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1817 send_len = IEEE80211_HDRLEN;
1818 send_len += sizeof(reply->u.assoc_resp);
1819 reply->u.assoc_resp.capab_info =
1820 host_to_le16(hostapd_own_capab_info(hapd));
1821 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1822 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1823 /* Supported rates */
1824 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1825 /* Extended supported rates */
1826 p = hostapd_eid_ext_supp_rates(hapd, p);
1828 #ifdef CONFIG_IEEE80211R
1829 if (status_code == WLAN_STATUS_SUCCESS) {
1830 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1831 * Transition Information, RSN, [RIC Response] */
1832 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1833 buf + sizeof(buf) - p,
1834 sta->auth_alg, ies, ies_len);
1836 #endif /* CONFIG_IEEE80211R */
1838 #ifdef CONFIG_IEEE80211W
1839 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1840 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1841 #endif /* CONFIG_IEEE80211W */
1843 #ifdef CONFIG_IEEE80211N
1844 p = hostapd_eid_ht_capabilities(hapd, p);
1845 p = hostapd_eid_ht_operation(hapd, p);
1846 #endif /* CONFIG_IEEE80211N */
1848 #ifdef CONFIG_IEEE80211AC
1849 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1850 p = hostapd_eid_vht_capabilities(hapd, p);
1851 p = hostapd_eid_vht_operation(hapd, p);
1853 #endif /* CONFIG_IEEE80211AC */
1855 p = hostapd_eid_ext_capab(hapd, p);
1856 p = hostapd_eid_bss_max_idle_period(hapd, p);
1857 if (sta->qos_map_enabled)
1858 p = hostapd_eid_qos_map_set(hapd, p);
1861 if (hapd->iface->fst_ies) {
1862 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1863 wpabuf_len(hapd->iface->fst_ies));
1864 p += wpabuf_len(hapd->iface->fst_ies);
1866 #endif /* CONFIG_FST */
1868 #ifdef CONFIG_IEEE80211AC
1869 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1870 p = hostapd_eid_vendor_vht(hapd, p);
1871 #endif /* CONFIG_IEEE80211AC */
1873 if (sta->flags & WLAN_STA_WMM)
1874 p = hostapd_eid_wmm(hapd, p);
1877 if ((sta->flags & WLAN_STA_WPS) ||
1878 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1879 struct wpabuf *wps = wps_build_assoc_resp_ie();
1881 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1882 p += wpabuf_len(wps);
1886 #endif /* CONFIG_WPS */
1889 if (sta->p2p_ie && hapd->p2p_group) {
1890 struct wpabuf *p2p_resp_ie;
1891 enum p2p_status_code status;
1892 switch (status_code) {
1893 case WLAN_STATUS_SUCCESS:
1894 status = P2P_SC_SUCCESS;
1896 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1897 status = P2P_SC_FAIL_LIMIT_REACHED;
1900 status = P2P_SC_FAIL_INVALID_PARAMS;
1903 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1905 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1906 wpabuf_len(p2p_resp_ie));
1907 p += wpabuf_len(p2p_resp_ie);
1908 wpabuf_free(p2p_resp_ie);
1911 #endif /* CONFIG_P2P */
1913 #ifdef CONFIG_P2P_MANAGER
1914 if (hapd->conf->p2p & P2P_MANAGE)
1915 p = hostapd_eid_p2p_manage(hapd, p);
1916 #endif /* CONFIG_P2P_MANAGER */
1918 send_len += p - reply->u.assoc_resp.variable;
1920 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
1921 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1923 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1926 return WLAN_STATUS_SUCCESS;
1930 static void handle_assoc(struct hostapd_data *hapd,
1931 const struct ieee80211_mgmt *mgmt, size_t len,
1934 u16 capab_info, listen_interval, seq_ctrl, fc;
1935 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
1938 struct sta_info *sta;
1940 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1941 sizeof(mgmt->u.assoc_req))) {
1942 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1943 reassoc, (unsigned long) len);
1947 #ifdef CONFIG_TESTING_OPTIONS
1949 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1950 drand48() < hapd->iconf->ignore_reassoc_probability) {
1951 wpa_printf(MSG_INFO,
1952 "TESTING: ignoring reassoc request from "
1953 MACSTR, MAC2STR(mgmt->sa));
1957 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1958 drand48() < hapd->iconf->ignore_assoc_probability) {
1959 wpa_printf(MSG_INFO,
1960 "TESTING: ignoring assoc request from "
1961 MACSTR, MAC2STR(mgmt->sa));
1965 #endif /* CONFIG_TESTING_OPTIONS */
1967 fc = le_to_host16(mgmt->frame_control);
1968 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1971 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1972 listen_interval = le_to_host16(
1973 mgmt->u.reassoc_req.listen_interval);
1974 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1975 " capab_info=0x%02x listen_interval=%d current_ap="
1976 MACSTR " seq_ctrl=0x%x%s",
1977 MAC2STR(mgmt->sa), capab_info, listen_interval,
1978 MAC2STR(mgmt->u.reassoc_req.current_ap),
1979 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1980 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1981 pos = mgmt->u.reassoc_req.variable;
1983 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1984 listen_interval = le_to_host16(
1985 mgmt->u.assoc_req.listen_interval);
1986 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1987 " capab_info=0x%02x listen_interval=%d "
1989 MAC2STR(mgmt->sa), capab_info, listen_interval,
1990 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1991 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1992 pos = mgmt->u.assoc_req.variable;
1995 sta = ap_get_sta(hapd, mgmt->sa);
1996 #ifdef CONFIG_IEEE80211R
1997 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1998 (sta->flags & WLAN_STA_AUTH) == 0) {
1999 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2000 "prior to authentication since it is using "
2001 "over-the-DS FT", MAC2STR(mgmt->sa));
2004 * Mark station as authenticated, to avoid adding station
2005 * entry in the driver as associated and not authenticated
2007 sta->flags |= WLAN_STA_AUTH;
2009 #endif /* CONFIG_IEEE80211R */
2010 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2011 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2012 HOSTAPD_LEVEL_INFO, "Station tried to "
2013 "associate before authentication "
2014 "(aid=%d flags=0x%x)",
2015 sta ? sta->aid : -1,
2016 sta ? sta->flags : 0);
2017 send_deauth(hapd, mgmt->sa,
2018 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2022 if ((fc & WLAN_FC_RETRY) &&
2023 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2024 sta->last_seq_ctrl == seq_ctrl &&
2025 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2026 WLAN_FC_STYPE_ASSOC_REQ) {
2027 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2028 HOSTAPD_LEVEL_DEBUG,
2029 "Drop repeated association frame seq_ctrl=0x%x",
2033 sta->last_seq_ctrl = seq_ctrl;
2034 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2035 WLAN_FC_STYPE_ASSOC_REQ;
2037 if (hapd->tkip_countermeasures) {
2038 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2042 if (listen_interval > hapd->conf->max_listen_interval) {
2043 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2044 HOSTAPD_LEVEL_DEBUG,
2045 "Too large Listen Interval (%d)",
2047 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2051 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2053 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2054 if (resp != WLAN_STATUS_SUCCESS)
2057 if (hostapd_get_aid(hapd, sta) < 0) {
2058 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2059 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2060 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2064 sta->capability = capab_info;
2065 sta->listen_interval = listen_interval;
2067 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2068 sta->flags |= WLAN_STA_NONERP;
2069 for (i = 0; i < sta->supported_rates_len; i++) {
2070 if ((sta->supported_rates[i] & 0x7f) > 22) {
2071 sta->flags &= ~WLAN_STA_NONERP;
2075 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2076 sta->nonerp_set = 1;
2077 hapd->iface->num_sta_non_erp++;
2078 if (hapd->iface->num_sta_non_erp == 1)
2079 ieee802_11_set_beacons(hapd->iface);
2082 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2083 !sta->no_short_slot_time_set) {
2084 sta->no_short_slot_time_set = 1;
2085 hapd->iface->num_sta_no_short_slot_time++;
2086 if (hapd->iface->current_mode->mode ==
2087 HOSTAPD_MODE_IEEE80211G &&
2088 hapd->iface->num_sta_no_short_slot_time == 1)
2089 ieee802_11_set_beacons(hapd->iface);
2092 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2093 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2095 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2097 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2098 !sta->no_short_preamble_set) {
2099 sta->no_short_preamble_set = 1;
2100 hapd->iface->num_sta_no_short_preamble++;
2101 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2102 && hapd->iface->num_sta_no_short_preamble == 1)
2103 ieee802_11_set_beacons(hapd->iface);
2106 #ifdef CONFIG_IEEE80211N
2107 update_ht_state(hapd, sta);
2108 #endif /* CONFIG_IEEE80211N */
2110 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2111 HOSTAPD_LEVEL_DEBUG,
2112 "association OK (aid %d)", sta->aid);
2113 /* Station will be marked associated, after it acknowledges AssocResp
2115 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2117 #ifdef CONFIG_IEEE80211W
2118 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2119 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2120 "SA Query procedure", reassoc ? "re" : "");
2121 /* TODO: Send a protected Disassociate frame to the STA using
2122 * the old key and Reason Code "Previous Authentication no
2123 * longer valid". Make sure this is only sent protected since
2124 * unprotected frame would be received by the STA that is now
2125 * trying to associate.
2128 #endif /* CONFIG_IEEE80211W */
2130 /* Make sure that the previously registered inactivity timer will not
2131 * remove the STA immediately. */
2132 sta->timeout_next = STA_NULLFUNC;
2136 * In case of a successful response, add the station to the driver.
2137 * Otherwise, the kernel may ignore Data frames before we process the
2138 * ACK frame (TX status). In case of a failure, this station will be
2141 * Note that this is not compliant with the IEEE 802.11 standard that
2142 * states that a non-AP station should transition into the
2143 * authenticated/associated state only after the station acknowledges
2144 * the (Re)Association Response frame. However, still do this as:
2146 * 1. In case the station does not acknowledge the (Re)Association
2147 * Response frame, it will be removed.
2148 * 2. Data frames will be dropped in the kernel until the station is
2149 * set into authorized state, and there are no significant known
2150 * issues with processing other non-Data Class 3 frames during this
2153 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2154 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2156 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2159 * Remove the station in case tranmission of a success response fails
2160 * (the STA was added associated to the driver) or if the station was
2161 * previously added unassociated.
2163 if ((reply_res != WLAN_STATUS_SUCCESS &&
2164 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2165 hostapd_drv_sta_remove(hapd, sta->addr);
2166 sta->added_unassoc = 0;
2171 static void handle_disassoc(struct hostapd_data *hapd,
2172 const struct ieee80211_mgmt *mgmt, size_t len)
2174 struct sta_info *sta;
2176 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2177 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2178 (unsigned long) len);
2182 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2184 le_to_host16(mgmt->u.disassoc.reason_code));
2186 sta = ap_get_sta(hapd, mgmt->sa);
2188 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2193 ap_sta_set_authorized(hapd, sta, 0);
2194 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2195 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2196 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2197 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2198 HOSTAPD_LEVEL_INFO, "disassociated");
2199 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2200 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2201 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2203 accounting_sta_stop(hapd, sta);
2204 ieee802_1x_free_station(hapd, sta);
2206 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2207 ap_sta_ip6addr_del(hapd, sta);
2208 hostapd_drv_sta_remove(hapd, sta->addr);
2209 sta->added_unassoc = 0;
2211 if (sta->timeout_next == STA_NULLFUNC ||
2212 sta->timeout_next == STA_DISASSOC) {
2213 sta->timeout_next = STA_DEAUTH;
2214 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2215 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2219 mlme_disassociate_indication(
2220 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2224 static void handle_deauth(struct hostapd_data *hapd,
2225 const struct ieee80211_mgmt *mgmt, size_t len)
2227 struct sta_info *sta;
2229 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2230 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2231 "payload (len=%lu)", (unsigned long) len);
2235 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2237 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2239 sta = ap_get_sta(hapd, mgmt->sa);
2241 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2242 "to deauthenticate, but it is not authenticated",
2247 ap_sta_set_authorized(hapd, sta, 0);
2248 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2249 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2250 WLAN_STA_ASSOC_REQ_OK);
2251 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2252 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2253 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2254 mlme_deauthenticate_indication(
2255 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2256 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2257 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2258 ap_free_sta(hapd, sta);
2262 static void handle_beacon(struct hostapd_data *hapd,
2263 const struct ieee80211_mgmt *mgmt, size_t len,
2264 struct hostapd_frame_info *fi)
2266 struct ieee802_11_elems elems;
2268 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2269 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2270 (unsigned long) len);
2274 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2275 len - (IEEE80211_HDRLEN +
2276 sizeof(mgmt->u.beacon)), &elems,
2279 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2283 #ifdef CONFIG_IEEE80211W
2285 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2286 const struct ieee80211_mgmt *mgmt,
2291 end = mgmt->u.action.u.sa_query_resp.trans_id +
2292 WLAN_SA_QUERY_TR_ID_LEN;
2293 if (((u8 *) mgmt) + len < end) {
2294 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2295 "frame (len=%lu)", (unsigned long) len);
2299 ieee802_11_sa_query_action(hapd, mgmt->sa,
2300 mgmt->u.action.u.sa_query_resp.action,
2301 mgmt->u.action.u.sa_query_resp.trans_id);
2306 static int robust_action_frame(u8 category)
2308 return category != WLAN_ACTION_PUBLIC &&
2309 category != WLAN_ACTION_HT;
2311 #endif /* CONFIG_IEEE80211W */
2314 static int handle_action(struct hostapd_data *hapd,
2315 const struct ieee80211_mgmt *mgmt, size_t len)
2317 struct sta_info *sta;
2318 sta = ap_get_sta(hapd, mgmt->sa);
2320 if (len < IEEE80211_HDRLEN + 1) {
2321 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2322 HOSTAPD_LEVEL_DEBUG,
2323 "handle_action - too short payload (len=%lu)",
2324 (unsigned long) len);
2328 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2329 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2330 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2331 "frame (category=%u) from unassociated STA " MACSTR,
2332 MAC2STR(mgmt->sa), mgmt->u.action.category);
2336 #ifdef CONFIG_IEEE80211W
2337 if (sta && (sta->flags & WLAN_STA_MFP) &&
2338 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2339 robust_action_frame(mgmt->u.action.category)) {
2340 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2341 HOSTAPD_LEVEL_DEBUG,
2342 "Dropped unprotected Robust Action frame from "
2346 #endif /* CONFIG_IEEE80211W */
2349 u16 fc = le_to_host16(mgmt->frame_control);
2350 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2352 if ((fc & WLAN_FC_RETRY) &&
2353 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2354 sta->last_seq_ctrl == seq_ctrl &&
2355 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2356 hostapd_logger(hapd, sta->addr,
2357 HOSTAPD_MODULE_IEEE80211,
2358 HOSTAPD_LEVEL_DEBUG,
2359 "Drop repeated action frame seq_ctrl=0x%x",
2364 sta->last_seq_ctrl = seq_ctrl;
2365 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2368 switch (mgmt->u.action.category) {
2369 #ifdef CONFIG_IEEE80211R
2370 case WLAN_ACTION_FT:
2372 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2373 len - IEEE80211_HDRLEN))
2376 #endif /* CONFIG_IEEE80211R */
2377 case WLAN_ACTION_WMM:
2378 hostapd_wmm_action(hapd, mgmt, len);
2380 #ifdef CONFIG_IEEE80211W
2381 case WLAN_ACTION_SA_QUERY:
2382 return hostapd_sa_query_action(hapd, mgmt, len);
2383 #endif /* CONFIG_IEEE80211W */
2385 case WLAN_ACTION_WNM:
2386 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2388 #endif /* CONFIG_WNM */
2390 case WLAN_ACTION_FST:
2391 if (hapd->iface->fst)
2392 fst_rx_action(hapd->iface->fst, mgmt, len);
2394 wpa_printf(MSG_DEBUG,
2395 "FST: Ignore FST Action frame - no FST attached");
2397 #endif /* CONFIG_FST */
2398 case WLAN_ACTION_PUBLIC:
2399 case WLAN_ACTION_PROTECTED_DUAL:
2400 #ifdef CONFIG_IEEE80211N
2401 if (len >= IEEE80211_HDRLEN + 2 &&
2402 mgmt->u.action.u.public_action.action ==
2403 WLAN_PA_20_40_BSS_COEX) {
2404 wpa_printf(MSG_DEBUG,
2405 "HT20/40 coex mgmt frame received from STA "
2406 MACSTR, MAC2STR(mgmt->sa));
2407 hostapd_2040_coex_action(hapd, mgmt, len);
2409 #endif /* CONFIG_IEEE80211N */
2410 if (hapd->public_action_cb) {
2411 hapd->public_action_cb(hapd->public_action_cb_ctx,
2415 if (hapd->public_action_cb2) {
2416 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2420 if (hapd->public_action_cb || hapd->public_action_cb2)
2423 case WLAN_ACTION_VENDOR_SPECIFIC:
2424 if (hapd->vendor_action_cb) {
2425 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2427 hapd->iface->freq) == 0)
2433 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2434 HOSTAPD_LEVEL_DEBUG,
2435 "handle_action - unknown action category %d or invalid "
2437 mgmt->u.action.category);
2438 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2439 !(mgmt->sa[0] & 0x01)) {
2440 struct ieee80211_mgmt *resp;
2443 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2444 * Return the Action frame to the source without change
2445 * except that MSB of the Category set to 1.
2447 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2448 "frame back to sender");
2449 resp = os_malloc(len);
2452 os_memcpy(resp, mgmt, len);
2453 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2454 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2455 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2456 resp->u.action.category |= 0x80;
2458 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2459 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2470 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2471 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2473 * @buf: management frame data (starting from IEEE 802.11 header)
2474 * @len: length of frame data in octets
2475 * @fi: meta data about received frame (signal level, etc.)
2477 * Process all incoming IEEE 802.11 management frames. This will be called for
2478 * each frame received from the kernel driver through wlan#ap interface. In
2479 * addition, it can be called to re-inserted pending frames (e.g., when using
2480 * external RADIUS server as an MAC ACL).
2482 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2483 struct hostapd_frame_info *fi)
2485 struct ieee80211_mgmt *mgmt;
2493 mgmt = (struct ieee80211_mgmt *) buf;
2494 fc = le_to_host16(mgmt->frame_control);
2495 stype = WLAN_FC_GET_STYPE(fc);
2497 if (stype == WLAN_FC_STYPE_BEACON) {
2498 handle_beacon(hapd, mgmt, len, fi);
2502 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2503 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2504 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2508 /* Invitation responses can be sent with the peer MAC as BSSID */
2509 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2510 stype == WLAN_FC_STYPE_ACTION) &&
2511 #endif /* CONFIG_P2P */
2513 !(hapd->conf->mesh & MESH_ENABLED) &&
2514 #endif /* CONFIG_MESH */
2515 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2516 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2517 MAC2STR(mgmt->bssid));
2522 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2523 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2527 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2528 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2529 HOSTAPD_LEVEL_DEBUG,
2530 "MGMT: DA=" MACSTR " not our address",
2535 if (hapd->iconf->track_sta_max_num)
2536 sta_track_add(hapd->iface, mgmt->sa);
2539 case WLAN_FC_STYPE_AUTH:
2540 wpa_printf(MSG_DEBUG, "mgmt::auth");
2541 handle_auth(hapd, mgmt, len);
2544 case WLAN_FC_STYPE_ASSOC_REQ:
2545 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2546 handle_assoc(hapd, mgmt, len, 0);
2549 case WLAN_FC_STYPE_REASSOC_REQ:
2550 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2551 handle_assoc(hapd, mgmt, len, 1);
2554 case WLAN_FC_STYPE_DISASSOC:
2555 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2556 handle_disassoc(hapd, mgmt, len);
2559 case WLAN_FC_STYPE_DEAUTH:
2560 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2561 handle_deauth(hapd, mgmt, len);
2564 case WLAN_FC_STYPE_ACTION:
2565 wpa_printf(MSG_DEBUG, "mgmt::action");
2566 ret = handle_action(hapd, mgmt, len);
2569 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2570 HOSTAPD_LEVEL_DEBUG,
2571 "unknown mgmt frame subtype %d", stype);
2579 static void handle_auth_cb(struct hostapd_data *hapd,
2580 const struct ieee80211_mgmt *mgmt,
2583 u16 auth_alg, auth_transaction, status_code;
2584 struct sta_info *sta;
2586 sta = ap_get_sta(hapd, mgmt->da);
2588 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2593 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2594 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2595 status_code = le_to_host16(mgmt->u.auth.status_code);
2598 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2599 HOSTAPD_LEVEL_NOTICE,
2600 "did not acknowledge authentication response");
2604 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2605 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2606 (unsigned long) len);
2610 if (status_code == WLAN_STATUS_SUCCESS &&
2611 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2612 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2613 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2614 HOSTAPD_LEVEL_INFO, "authenticated");
2615 sta->flags |= WLAN_STA_AUTH;
2616 if (sta->added_unassoc)
2617 hostapd_set_sta_flags(hapd, sta);
2622 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2623 hostapd_drv_sta_remove(hapd, sta->addr);
2624 sta->added_unassoc = 0;
2629 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2630 struct sta_info *sta,
2634 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2636 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2639 for (i = 0; i < 4; i++) {
2640 if (ssid->wep.key[i] &&
2641 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2642 i == ssid->wep.idx, NULL, 0,
2643 ssid->wep.key[i], ssid->wep.len[i])) {
2644 wpa_printf(MSG_WARNING,
2645 "Could not set WEP keys for WDS interface; %s",
2653 static void handle_assoc_cb(struct hostapd_data *hapd,
2654 const struct ieee80211_mgmt *mgmt,
2655 size_t len, int reassoc, int ok)
2658 struct sta_info *sta;
2661 sta = ap_get_sta(hapd, mgmt->da);
2663 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2668 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2669 sizeof(mgmt->u.assoc_resp))) {
2670 wpa_printf(MSG_INFO,
2671 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2672 reassoc, (unsigned long) len);
2673 hostapd_drv_sta_remove(hapd, sta->addr);
2678 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2680 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2683 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2684 HOSTAPD_LEVEL_DEBUG,
2685 "did not acknowledge association response");
2686 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2687 /* The STA is added only in case of SUCCESS */
2688 if (status == WLAN_STATUS_SUCCESS)
2689 hostapd_drv_sta_remove(hapd, sta->addr);
2694 if (status != WLAN_STATUS_SUCCESS)
2697 /* Stop previous accounting session, if one is started, and allocate
2698 * new session id for the new session. */
2699 accounting_sta_stop(hapd, sta);
2701 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2703 "associated (aid %d)",
2706 if (sta->flags & WLAN_STA_ASSOC)
2708 sta->flags |= WLAN_STA_ASSOC;
2709 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2710 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2711 sta->auth_alg == WLAN_AUTH_FT) {
2713 * Open, static WEP, or FT protocol; no separate authorization
2716 ap_sta_set_authorized(hapd, sta, 1);
2720 mlme_reassociate_indication(hapd, sta);
2722 mlme_associate_indication(hapd, sta);
2724 #ifdef CONFIG_IEEE80211W
2725 sta->sa_query_timed_out = 0;
2726 #endif /* CONFIG_IEEE80211W */
2728 if (sta->flags & WLAN_STA_WDS) {
2730 char ifname_wds[IFNAMSIZ + 1];
2732 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2735 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2738 if (sta->eapol_sm == NULL) {
2740 * This STA does not use RADIUS server for EAP authentication,
2741 * so bind it to the selected VLAN interface now, since the
2742 * interface selection is not going to change anymore.
2744 if (ap_sta_bind_vlan(hapd, sta) < 0)
2746 } else if (sta->vlan_id) {
2747 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2748 if (ap_sta_bind_vlan(hapd, sta) < 0)
2752 hostapd_set_sta_flags(hapd, sta);
2754 if (sta->auth_alg == WLAN_AUTH_FT)
2755 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2757 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2758 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2759 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2763 static void handle_deauth_cb(struct hostapd_data *hapd,
2764 const struct ieee80211_mgmt *mgmt,
2767 struct sta_info *sta;
2768 if (mgmt->da[0] & 0x01)
2770 sta = ap_get_sta(hapd, mgmt->da);
2772 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2773 " not found", MAC2STR(mgmt->da));
2777 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2778 MAC2STR(sta->addr));
2780 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2781 "deauth", MAC2STR(sta->addr));
2783 ap_sta_deauth_cb(hapd, sta);
2787 static void handle_disassoc_cb(struct hostapd_data *hapd,
2788 const struct ieee80211_mgmt *mgmt,
2791 struct sta_info *sta;
2792 if (mgmt->da[0] & 0x01)
2794 sta = ap_get_sta(hapd, mgmt->da);
2796 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2797 " not found", MAC2STR(mgmt->da));
2801 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2802 MAC2STR(sta->addr));
2804 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2805 "disassoc", MAC2STR(sta->addr));
2807 ap_sta_disassoc_cb(hapd, sta);
2812 * ieee802_11_mgmt_cb - Process management frame TX status callback
2813 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2815 * @buf: management frame data (starting from IEEE 802.11 header)
2816 * @len: length of frame data in octets
2817 * @stype: management frame subtype from frame control field
2818 * @ok: Whether the frame was ACK'ed
2820 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2823 const struct ieee80211_mgmt *mgmt;
2824 mgmt = (const struct ieee80211_mgmt *) buf;
2826 #ifdef CONFIG_TESTING_OPTIONS
2827 if (hapd->ext_mgmt_frame_handling) {
2828 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2832 #endif /* CONFIG_TESTING_OPTIONS */
2835 case WLAN_FC_STYPE_AUTH:
2836 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2837 handle_auth_cb(hapd, mgmt, len, ok);
2839 case WLAN_FC_STYPE_ASSOC_RESP:
2840 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2841 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2843 case WLAN_FC_STYPE_REASSOC_RESP:
2844 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2845 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2847 case WLAN_FC_STYPE_PROBE_RESP:
2848 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2850 case WLAN_FC_STYPE_DEAUTH:
2851 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2852 handle_deauth_cb(hapd, mgmt, len, ok);
2854 case WLAN_FC_STYPE_DISASSOC:
2855 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2856 handle_disassoc_cb(hapd, mgmt, len, ok);
2858 case WLAN_FC_STYPE_ACTION:
2859 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2862 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2868 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2875 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2876 char *buf, size_t buflen)
2883 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2884 const u8 *buf, size_t len, int ack)
2886 struct sta_info *sta;
2887 struct hostapd_iface *iface = hapd->iface;
2889 sta = ap_get_sta(hapd, addr);
2890 if (sta == NULL && iface->num_bss > 1) {
2892 for (j = 0; j < iface->num_bss; j++) {
2893 hapd = iface->bss[j];
2894 sta = ap_get_sta(hapd, addr);
2899 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2901 if (sta->flags & WLAN_STA_PENDING_POLL) {
2902 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2903 "activity poll", MAC2STR(sta->addr),
2904 ack ? "ACKed" : "did not ACK");
2906 sta->flags &= ~WLAN_STA_PENDING_POLL;
2909 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2913 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2914 const u8 *data, size_t len, int ack)
2916 struct sta_info *sta;
2917 struct hostapd_iface *iface = hapd->iface;
2919 sta = ap_get_sta(hapd, dst);
2920 if (sta == NULL && iface->num_bss > 1) {
2922 for (j = 0; j < iface->num_bss; j++) {
2923 hapd = iface->bss[j];
2924 sta = ap_get_sta(hapd, dst);
2929 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2930 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2931 MACSTR " that is not currently associated",
2936 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2940 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2942 struct sta_info *sta;
2943 struct hostapd_iface *iface = hapd->iface;
2945 sta = ap_get_sta(hapd, addr);
2946 if (sta == NULL && iface->num_bss > 1) {
2948 for (j = 0; j < iface->num_bss; j++) {
2949 hapd = iface->bss[j];
2950 sta = ap_get_sta(hapd, addr);
2957 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2960 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2961 "activity poll", MAC2STR(sta->addr));
2962 sta->flags &= ~WLAN_STA_PENDING_POLL;
2966 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2969 struct sta_info *sta;
2971 sta = ap_get_sta(hapd, src);
2972 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2973 if (!hapd->conf->wds_sta)
2976 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2978 char ifname_wds[IFNAMSIZ + 1];
2980 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2981 "STA " MACSTR " (aid %u)",
2982 MAC2STR(sta->addr), sta->aid);
2983 sta->flags |= WLAN_STA_WDS;
2984 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2985 sta->addr, sta->aid, 1);
2987 hostapd_set_wds_encryption(hapd, sta,
2993 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2994 MACSTR, MAC2STR(src));
2995 if (src[0] & 0x01) {
2996 /* Broadcast bit set in SA?! Ignore the frame silently. */
3000 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3001 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3002 "already been sent, but no TX status yet known - "
3003 "ignore Class 3 frame issue with " MACSTR,
3008 if (sta && (sta->flags & WLAN_STA_AUTH))
3009 hostapd_drv_sta_disassoc(
3011 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3013 hostapd_drv_sta_deauth(
3015 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3019 #endif /* CONFIG_NATIVE_WINDOWS */