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;
145 /* Check if any of configured channels require DFS */
146 dfs = hostapd_is_dfs_required(hapd->iface);
148 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
153 if (hapd->iface->num_sta_no_short_preamble == 0 &&
154 hapd->iconf->preamble == SHORT_PREAMBLE)
155 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
157 privacy = hapd->conf->ssid.wep.keys_set;
159 if (hapd->conf->ieee802_1x &&
160 (hapd->conf->default_wep_key_len ||
161 hapd->conf->individual_wep_key_len))
168 if (hapd->conf->osen)
170 #endif /* CONFIG_HS20 */
173 capab |= WLAN_CAPABILITY_PRIVACY;
175 if (hapd->iface->current_mode &&
176 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
177 hapd->iface->num_sta_no_short_slot_time == 0)
178 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
181 * Currently, Spectrum Management capability bit is set when directly
182 * requested in configuration by spectrum_mgmt_required or when AP is
183 * running on DFS channel.
184 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
186 if (hapd->iface->current_mode &&
187 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
188 (hapd->iconf->spectrum_mgmt_required || dfs))
189 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
191 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
192 if (hapd->conf->radio_measurements[i]) {
193 capab |= IEEE80211_CAP_RRM;
202 #ifndef CONFIG_NO_RC4
203 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
204 u16 auth_transaction, const u8 *challenge,
207 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
209 "authentication (shared key, transaction %d)",
212 if (auth_transaction == 1) {
213 if (!sta->challenge) {
214 /* Generate a pseudo-random challenge */
217 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
218 if (sta->challenge == NULL)
219 return WLAN_STATUS_UNSPECIFIED_FAILURE;
221 if (os_get_random(key, sizeof(key)) < 0) {
222 os_free(sta->challenge);
223 sta->challenge = NULL;
224 return WLAN_STATUS_UNSPECIFIED_FAILURE;
227 rc4_skip(key, sizeof(key), 0,
228 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
233 if (auth_transaction != 3)
234 return WLAN_STATUS_UNSPECIFIED_FAILURE;
237 if (!iswep || !sta->challenge || !challenge ||
238 os_memcmp_const(sta->challenge, challenge,
239 WLAN_AUTH_CHALLENGE_LEN)) {
240 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
242 "shared key authentication - invalid "
243 "challenge-response");
244 return WLAN_STATUS_CHALLENGE_FAIL;
247 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
249 "authentication OK (shared key)");
250 sta->flags |= WLAN_STA_AUTH;
251 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
252 os_free(sta->challenge);
253 sta->challenge = NULL;
257 #endif /* CONFIG_NO_RC4 */
260 static int send_auth_reply(struct hostapd_data *hapd,
261 const u8 *dst, const u8 *bssid,
262 u16 auth_alg, u16 auth_transaction, u16 resp,
263 const u8 *ies, size_t ies_len)
265 struct ieee80211_mgmt *reply;
268 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
270 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
271 buf = os_zalloc(rlen);
275 reply = (struct ieee80211_mgmt *) buf;
276 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
278 os_memcpy(reply->da, dst, ETH_ALEN);
279 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
280 os_memcpy(reply->bssid, bssid, ETH_ALEN);
282 reply->u.auth.auth_alg = host_to_le16(auth_alg);
283 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
284 reply->u.auth.status_code = host_to_le16(resp);
287 os_memcpy(reply->u.auth.variable, ies, ies_len);
289 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
290 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
291 MAC2STR(dst), auth_alg, auth_transaction,
292 resp, (unsigned long) ies_len);
293 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
294 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
296 reply_res = WLAN_STATUS_SUCCESS;
304 #ifdef CONFIG_IEEE80211R
305 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
306 u16 auth_transaction, u16 status,
307 const u8 *ies, size_t ies_len)
309 struct hostapd_data *hapd = ctx;
310 struct sta_info *sta;
313 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
314 auth_transaction, status, ies, ies_len);
316 sta = ap_get_sta(hapd, dst);
320 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
321 status != WLAN_STATUS_SUCCESS)) {
322 hostapd_drv_sta_remove(hapd, sta->addr);
323 sta->added_unassoc = 0;
327 if (status != WLAN_STATUS_SUCCESS)
330 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
331 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
332 sta->flags |= WLAN_STA_AUTH;
333 mlme_authenticate_indication(hapd, sta);
335 #endif /* CONFIG_IEEE80211R */
340 #define dot11RSNASAESync 5 /* attempts */
343 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
344 struct sta_info *sta, int update)
348 if (hapd->conf->ssid.wpa_passphrase == NULL) {
349 wpa_printf(MSG_DEBUG, "SAE: No password available");
354 sae_prepare_commit(hapd->own_addr, sta->addr,
355 (u8 *) hapd->conf->ssid.wpa_passphrase,
356 os_strlen(hapd->conf->ssid.wpa_passphrase),
358 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
362 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
365 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
366 sta->sae->tmp->anti_clogging_token : NULL);
372 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
373 struct sta_info *sta)
377 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
381 sae_write_confirm(sta->sae, buf);
387 static int auth_sae_send_commit(struct hostapd_data *hapd,
388 struct sta_info *sta,
389 const u8 *bssid, int update)
394 data = auth_build_sae_commit(hapd, sta, update);
396 return WLAN_STATUS_UNSPECIFIED_FAILURE;
398 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
399 WLAN_STATUS_SUCCESS, wpabuf_head(data),
408 static int auth_sae_send_confirm(struct hostapd_data *hapd,
409 struct sta_info *sta,
415 data = auth_build_sae_confirm(hapd, sta);
417 return WLAN_STATUS_UNSPECIFIED_FAILURE;
419 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
420 WLAN_STATUS_SUCCESS, wpabuf_head(data),
429 static int use_sae_anti_clogging(struct hostapd_data *hapd)
431 struct sta_info *sta;
432 unsigned int open = 0;
434 if (hapd->conf->sae_anti_clogging_threshold == 0)
437 for (sta = hapd->sta_list; sta; sta = sta->next) {
440 if (sta->sae->state != SAE_COMMITTED &&
441 sta->sae->state != SAE_CONFIRMED)
444 if (open >= hapd->conf->sae_anti_clogging_threshold)
452 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
453 const u8 *token, size_t token_len)
455 u8 mac[SHA256_MAC_LEN];
457 if (token_len != SHA256_MAC_LEN)
459 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
460 addr, ETH_ALEN, mac) < 0 ||
461 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
468 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
469 int group, const u8 *addr)
473 struct os_reltime now;
475 os_get_reltime(&now);
476 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
477 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
478 if (random_get_bytes(hapd->sae_token_key,
479 sizeof(hapd->sae_token_key)) < 0)
481 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
482 hapd->sae_token_key, sizeof(hapd->sae_token_key));
483 hapd->last_sae_token_key_update = now;
486 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
490 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
492 token = wpabuf_put(buf, SHA256_MAC_LEN);
493 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
494 addr, ETH_ALEN, token);
500 static int sae_check_big_sync(struct sta_info *sta)
502 if (sta->sae->sync > dot11RSNASAESync) {
503 sta->sae->state = SAE_NOTHING;
511 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
513 struct hostapd_data *hapd = eloop_ctx;
514 struct sta_info *sta = eloop_data;
517 if (sae_check_big_sync(sta))
521 switch (sta->sae->state) {
523 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
524 eloop_register_timeout(0,
525 hapd->dot11RSNASAERetransPeriod * 1000,
526 auth_sae_retransmit_timer, hapd, sta);
529 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
530 eloop_register_timeout(0,
531 hapd->dot11RSNASAERetransPeriod * 1000,
532 auth_sae_retransmit_timer, hapd, sta);
539 if (ret != WLAN_STATUS_SUCCESS)
540 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
544 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
546 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
550 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
551 struct sta_info *sta)
553 if (!(hapd->conf->mesh & MESH_ENABLED))
556 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
557 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
558 auth_sae_retransmit_timer, hapd, sta);
562 void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
564 sta->flags |= WLAN_STA_AUTH;
565 sta->auth_alg = WLAN_AUTH_SAE;
566 mlme_authenticate_indication(hapd, sta);
567 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
568 sta->sae->state = SAE_ACCEPTED;
569 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
570 sta->sae->pmk, sta->sae->pmkid);
574 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
575 const u8 *bssid, u8 auth_transaction)
579 if (auth_transaction != 1 && auth_transaction != 2)
580 return WLAN_STATUS_UNSPECIFIED_FAILURE;
582 switch (sta->sae->state) {
584 if (auth_transaction == 1) {
585 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
588 sta->sae->state = SAE_COMMITTED;
590 if (sae_process_commit(sta->sae) < 0)
591 return WLAN_STATUS_UNSPECIFIED_FAILURE;
594 * In mesh case, both Commit and Confirm can be sent
595 * immediately. In infrastructure BSS, only a single
596 * Authentication frame (Commit) is expected from the AP
597 * here and the second one (Confirm) will be sent once
598 * the STA has sent its second Authentication frame
601 if (hapd->conf->mesh & MESH_ENABLED) {
603 * Send both Commit and Confirm immediately
604 * based on SAE finite state machine
605 * Nothing -> Confirm transition.
607 ret = auth_sae_send_confirm(hapd, sta, bssid);
610 sta->sae->state = SAE_CONFIRMED;
613 * For infrastructure BSS, send only the Commit
614 * message now to get alternating sequence of
615 * Authentication frames between the AP and STA.
616 * Confirm will be sent in
617 * Commited -> Confirmed/Accepted transition
618 * when receiving Confirm from STA.
622 sae_set_retransmit_timer(hapd, sta);
624 hostapd_logger(hapd, sta->addr,
625 HOSTAPD_MODULE_IEEE80211,
627 "SAE confirm before commit");
631 sae_clear_retransmit_timer(hapd, sta);
632 if (auth_transaction == 1) {
633 if (sae_process_commit(sta->sae) < 0)
634 return WLAN_STATUS_UNSPECIFIED_FAILURE;
636 ret = auth_sae_send_confirm(hapd, sta, bssid);
639 sta->sae->state = SAE_CONFIRMED;
641 sae_set_retransmit_timer(hapd, sta);
642 } else if (hapd->conf->mesh & MESH_ENABLED) {
644 * In mesh case, follow SAE finite state machine and
645 * send Commit now, if sync count allows.
647 if (sae_check_big_sync(sta))
648 return WLAN_STATUS_SUCCESS;
651 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
655 sae_set_retransmit_timer(hapd, sta);
658 * For instructure BSS, send the postponed Confirm from
659 * Nothing -> Confirmed transition that was reduced to
660 * Nothing -> Committed above.
662 ret = auth_sae_send_confirm(hapd, sta, bssid);
666 sta->sae->state = SAE_CONFIRMED;
669 * Since this was triggered on Confirm RX, run another
670 * step to get to Accepted without waiting for
673 return sae_sm_step(hapd, sta, bssid, auth_transaction);
677 sae_clear_retransmit_timer(hapd, sta);
678 if (auth_transaction == 1) {
679 if (sae_check_big_sync(sta))
680 return WLAN_STATUS_SUCCESS;
683 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
687 if (sae_process_commit(sta->sae) < 0)
688 return WLAN_STATUS_UNSPECIFIED_FAILURE;
690 ret = auth_sae_send_confirm(hapd, sta, bssid);
694 sae_set_retransmit_timer(hapd, sta);
696 sae_accept_sta(hapd, sta);
700 if (auth_transaction == 1) {
701 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
702 ") doing reauthentication",
704 ap_free_sta(hapd, sta);
705 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
707 if (sae_check_big_sync(sta))
708 return WLAN_STATUS_SUCCESS;
711 ret = auth_sae_send_confirm(hapd, sta, bssid);
712 sae_clear_temp_data(sta->sae);
718 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
720 return WLAN_STATUS_UNSPECIFIED_FAILURE;
722 return WLAN_STATUS_SUCCESS;
726 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
727 const struct ieee80211_mgmt *mgmt, size_t len,
728 u16 auth_transaction, u16 status_code)
730 int resp = WLAN_STATUS_SUCCESS;
731 struct wpabuf *data = NULL;
734 if (auth_transaction != 1 ||
735 status_code != WLAN_STATUS_SUCCESS) {
739 sta->sae = os_zalloc(sizeof(*sta->sae));
744 sta->sae->state = SAE_NOTHING;
748 if (sta->mesh_sae_pmksa_caching) {
749 wpa_printf(MSG_DEBUG,
750 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
751 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
752 sta->mesh_sae_pmksa_caching = 0;
755 if (auth_transaction == 1) {
756 const u8 *token = NULL, *pos, *end;
757 size_t token_len = 0;
758 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
760 "start SAE authentication (RX commit, status=%u)",
763 if ((hapd->conf->mesh & MESH_ENABLED) &&
764 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
766 pos = mgmt->u.auth.variable;
767 end = ((const u8 *) mgmt) + len;
768 if (pos + sizeof(le16) > end) {
769 wpa_printf(MSG_ERROR,
770 "SAE: Too short anti-clogging token request");
771 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
774 resp = sae_group_allowed(sta->sae,
775 hapd->conf->sae_groups,
777 if (resp != WLAN_STATUS_SUCCESS) {
778 wpa_printf(MSG_ERROR,
779 "SAE: Invalid group in anti-clogging token request");
784 wpabuf_free(sta->sae->tmp->anti_clogging_token);
785 sta->sae->tmp->anti_clogging_token =
786 wpabuf_alloc_copy(pos, end - pos);
787 if (sta->sae->tmp->anti_clogging_token == NULL) {
788 wpa_printf(MSG_ERROR,
789 "SAE: Failed to alloc for anti-clogging token");
790 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
795 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
796 * is 76, a new Commit Message shall be constructed
797 * with the Anti-Clogging Token from the received
798 * Authentication frame, and the commit-scalar and
799 * COMMIT-ELEMENT previously sent.
801 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
802 if (resp != WLAN_STATUS_SUCCESS) {
803 wpa_printf(MSG_ERROR,
804 "SAE: Failed to send commit message");
807 sta->sae->state = SAE_COMMITTED;
809 sae_set_retransmit_timer(hapd, sta);
813 if (status_code != WLAN_STATUS_SUCCESS)
816 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
817 ((const u8 *) mgmt) + len -
818 mgmt->u.auth.variable, &token,
819 &token_len, hapd->conf->sae_groups);
820 if (resp == SAE_SILENTLY_DISCARD) {
821 wpa_printf(MSG_DEBUG,
822 "SAE: Drop commit message from " MACSTR " due to reflection attack",
826 if (token && check_sae_token(hapd, sta->addr, token, token_len)
828 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
829 "incorrect token from " MACSTR,
831 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
835 if (resp != WLAN_STATUS_SUCCESS)
838 if (!token && use_sae_anti_clogging(hapd)) {
839 wpa_printf(MSG_DEBUG,
840 "SAE: Request anti-clogging token from "
841 MACSTR, MAC2STR(sta->addr));
842 data = auth_build_token_req(hapd, sta->sae->group,
844 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
845 if (hapd->conf->mesh & MESH_ENABLED)
846 sta->sae->state = SAE_NOTHING;
850 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
851 } else if (auth_transaction == 2) {
852 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
854 "SAE authentication (RX confirm, status=%u)",
856 if (status_code != WLAN_STATUS_SUCCESS)
858 if (sta->sae->state >= SAE_CONFIRMED ||
859 !(hapd->conf->mesh & MESH_ENABLED)) {
860 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
861 ((u8 *) mgmt) + len -
862 mgmt->u.auth.variable) < 0) {
863 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
867 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
869 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
871 "unexpected SAE authentication transaction %u (status=%u)",
872 auth_transaction, status_code);
873 if (status_code != WLAN_STATUS_SUCCESS)
875 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
879 if (resp != WLAN_STATUS_SUCCESS) {
880 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
881 auth_transaction, resp,
882 data ? wpabuf_head(data) : (u8 *) "",
883 data ? wpabuf_len(data) : 0);
887 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
888 status_code != WLAN_STATUS_SUCCESS)) {
889 hostapd_drv_sta_remove(hapd, sta->addr);
890 sta->added_unassoc = 0;
897 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
898 * @hapd: BSS data for the device initiating the authentication
899 * @sta: the peer to which commit authentication frame is sent
901 * This function implements Init event handling (IEEE Std 802.11-2012,
902 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
903 * sta->sae structure should be initialized appropriately via a call to
904 * sae_prepare_commit().
906 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
910 if (!sta->sae || !sta->sae->tmp)
913 if (sta->sae->state != SAE_NOTHING)
916 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
920 sta->sae->state = SAE_COMMITTED;
922 sae_set_retransmit_timer(hapd, sta);
927 #endif /* CONFIG_SAE */
930 static void handle_auth(struct hostapd_data *hapd,
931 const struct ieee80211_mgmt *mgmt, size_t len)
933 u16 auth_alg, auth_transaction, status_code;
934 u16 resp = WLAN_STATUS_SUCCESS;
935 struct sta_info *sta = NULL;
938 const u8 *challenge = NULL;
939 u32 session_timeout, acct_interim_interval;
940 struct vlan_description vlan_id;
941 struct hostapd_sta_wpa_psk_short *psk = NULL;
942 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
943 size_t resp_ies_len = 0;
944 char *identity = NULL;
945 char *radius_cui = NULL;
948 os_memset(&vlan_id, 0, sizeof(vlan_id));
950 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
951 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
952 (unsigned long) len);
956 #ifdef CONFIG_TESTING_OPTIONS
957 if (hapd->iconf->ignore_auth_probability > 0.0 &&
958 drand48() < hapd->iconf->ignore_auth_probability) {
960 "TESTING: ignoring auth frame from " MACSTR,
964 #endif /* CONFIG_TESTING_OPTIONS */
966 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
967 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
968 status_code = le_to_host16(mgmt->u.auth.status_code);
969 fc = le_to_host16(mgmt->frame_control);
970 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
972 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
973 2 + WLAN_AUTH_CHALLENGE_LEN &&
974 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
975 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
976 challenge = &mgmt->u.auth.variable[2];
978 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
979 "auth_transaction=%d status_code=%d wep=%d%s "
981 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
982 status_code, !!(fc & WLAN_FC_ISWEP),
983 challenge ? " challenge" : "",
984 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
987 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
989 "Unsupported authentication algorithm (%d)",
991 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
994 #endif /* CONFIG_NO_RC4 */
996 if (hapd->tkip_countermeasures) {
997 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1001 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
1002 auth_alg == WLAN_AUTH_OPEN) ||
1003 #ifdef CONFIG_IEEE80211R
1004 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
1005 auth_alg == WLAN_AUTH_FT) ||
1006 #endif /* CONFIG_IEEE80211R */
1008 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1009 auth_alg == WLAN_AUTH_SAE) ||
1010 #endif /* CONFIG_SAE */
1011 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1012 auth_alg == WLAN_AUTH_SHARED_KEY))) {
1013 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1015 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1019 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
1020 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
1021 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1023 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1027 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
1028 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1030 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1034 if (hapd->conf->no_auth_if_seen_on) {
1035 struct hostapd_data *other;
1037 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1038 hapd->conf->no_auth_if_seen_on);
1042 u8 op_class, channel, phytype;
1044 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1045 MACSTR " since STA has been seen on %s",
1046 hapd->conf->iface, MAC2STR(mgmt->sa),
1047 hapd->conf->no_auth_if_seen_on);
1049 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1051 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1053 os_memcpy(pos, other->own_addr, ETH_ALEN);
1055 info = 0; /* TODO: BSSID Information */
1056 WPA_PUT_LE32(pos, info);
1058 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1059 phytype = 8; /* dmg */
1060 else if (other->iconf->ieee80211ac)
1061 phytype = 9; /* vht */
1062 else if (other->iconf->ieee80211n)
1063 phytype = 7; /* ht */
1064 else if (other->iconf->hw_mode ==
1065 HOSTAPD_MODE_IEEE80211A)
1066 phytype = 4; /* ofdm */
1067 else if (other->iconf->hw_mode ==
1068 HOSTAPD_MODE_IEEE80211G)
1069 phytype = 6; /* erp */
1071 phytype = 5; /* hrdsss */
1072 if (ieee80211_freq_to_channel_ext(
1073 hostapd_hw_get_freq(other,
1074 other->iconf->channel),
1075 other->iconf->secondary_channel,
1076 other->iconf->ieee80211ac,
1077 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1079 channel = other->iconf->channel;
1084 resp_ies_len = pos - &resp_ies[0];
1089 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1091 &acct_interim_interval, &vlan_id,
1092 &psk, &identity, &radius_cui);
1094 if (res == HOSTAPD_ACL_REJECT) {
1095 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1097 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1100 if (res == HOSTAPD_ACL_PENDING) {
1101 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1102 " waiting for an external authentication",
1104 /* Authentication code will re-send the authentication frame
1105 * after it has received (and cached) information from the
1106 * external source. */
1110 sta = ap_get_sta(hapd, mgmt->sa);
1112 if ((fc & WLAN_FC_RETRY) &&
1113 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1114 sta->last_seq_ctrl == seq_ctrl &&
1115 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1116 hostapd_logger(hapd, sta->addr,
1117 HOSTAPD_MODULE_IEEE80211,
1118 HOSTAPD_LEVEL_DEBUG,
1119 "Drop repeated authentication frame seq_ctrl=0x%x",
1124 if ((hapd->conf->mesh & MESH_ENABLED) &&
1125 sta->plink_state == PLINK_BLOCKED) {
1126 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1127 " is blocked - drop Authentication frame",
1131 #endif /* CONFIG_MESH */
1134 if (hapd->conf->mesh & MESH_ENABLED) {
1135 /* if the mesh peer is not available, we don't do auth.
1137 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1138 " not yet known - drop Authentication frame",
1141 * Save a copy of the frame so that it can be processed
1142 * if a new peer entry is added shortly after this.
1144 wpabuf_free(hapd->mesh_pending_auth);
1145 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1146 os_get_reltime(&hapd->mesh_pending_auth_time);
1149 #endif /* CONFIG_MESH */
1151 sta = ap_sta_add(hapd, mgmt->sa);
1153 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1157 sta->last_seq_ctrl = seq_ctrl;
1158 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1160 if (vlan_id.notempty &&
1161 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1162 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1164 "Invalid VLAN %d%s received from RADIUS server",
1166 vlan_id.tagged[0] ? "+" : "");
1167 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1170 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1171 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1175 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1176 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1178 hostapd_free_psk_list(sta->psk);
1179 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1186 sta->identity = identity;
1188 sta->radius_cui = radius_cui;
1191 sta->flags &= ~WLAN_STA_PREAUTH;
1192 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1194 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1195 sta->acct_interim_interval = acct_interim_interval;
1196 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1197 ap_sta_session_timeout(hapd, sta, session_timeout);
1199 ap_sta_no_session_timeout(hapd, sta);
1202 * If the driver supports full AP client state, add a station to the
1203 * driver before sending authentication reply to make sure the driver
1204 * has resources, and not to go through the entire authentication and
1205 * association handshake, and fail it at the end.
1207 * If this is not the first transaction, in a multi-step authentication
1208 * algorithm, the station already exists in the driver
1209 * (sta->added_unassoc = 1) so skip it.
1211 * In mesh mode, the station was already added to the driver when the
1212 * NEW_PEER_CANDIDATE event is received.
1214 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1215 !(hapd->conf->mesh & MESH_ENABLED) &&
1216 !(sta->added_unassoc)) {
1218 * If a station that is already associated to the AP, is trying
1219 * to authenticate again, remove the STA entry, in order to make
1220 * sure the STA PS state gets cleared and configuration gets
1221 * updated. To handle this, station's added_unassoc flag is
1222 * cleared once the station has completed association.
1224 hostapd_drv_sta_remove(hapd, sta->addr);
1225 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1226 WLAN_STA_AUTHORIZED);
1228 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1229 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
1230 hostapd_logger(hapd, sta->addr,
1231 HOSTAPD_MODULE_IEEE80211,
1232 HOSTAPD_LEVEL_NOTICE,
1233 "Could not add STA to kernel driver");
1234 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1238 sta->added_unassoc = 1;
1242 case WLAN_AUTH_OPEN:
1243 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1244 HOSTAPD_LEVEL_DEBUG,
1245 "authentication OK (open system)");
1246 sta->flags |= WLAN_STA_AUTH;
1247 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1248 sta->auth_alg = WLAN_AUTH_OPEN;
1249 mlme_authenticate_indication(hapd, sta);
1251 #ifndef CONFIG_NO_RC4
1252 case WLAN_AUTH_SHARED_KEY:
1253 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1254 fc & WLAN_FC_ISWEP);
1255 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1256 mlme_authenticate_indication(hapd, sta);
1257 if (sta->challenge && auth_transaction == 1) {
1258 resp_ies[0] = WLAN_EID_CHALLENGE;
1259 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1260 os_memcpy(resp_ies + 2, sta->challenge,
1261 WLAN_AUTH_CHALLENGE_LEN);
1262 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1265 #endif /* CONFIG_NO_RC4 */
1266 #ifdef CONFIG_IEEE80211R
1268 sta->auth_alg = WLAN_AUTH_FT;
1269 if (sta->wpa_sm == NULL)
1270 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1272 if (sta->wpa_sm == NULL) {
1273 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1275 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1278 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1279 auth_transaction, mgmt->u.auth.variable,
1280 len - IEEE80211_HDRLEN -
1281 sizeof(mgmt->u.auth),
1282 handle_auth_ft_finish, hapd);
1283 /* handle_auth_ft_finish() callback will complete auth. */
1285 #endif /* CONFIG_IEEE80211R */
1289 if (status_code == WLAN_STATUS_SUCCESS &&
1290 hapd->conf->mesh & MESH_ENABLED) {
1291 if (sta->wpa_sm == NULL)
1293 wpa_auth_sta_init(hapd->wpa_auth,
1295 if (sta->wpa_sm == NULL) {
1296 wpa_printf(MSG_DEBUG,
1297 "SAE: Failed to initialize WPA state machine");
1298 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1302 #endif /* CONFIG_MESH */
1303 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1306 #endif /* CONFIG_SAE */
1311 os_free(radius_cui);
1312 hostapd_free_psk_list(psk);
1314 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1315 auth_transaction + 1, resp, resp_ies,
1318 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1319 reply_res != WLAN_STATUS_SUCCESS)) {
1320 hostapd_drv_sta_remove(hapd, sta->addr);
1321 sta->added_unassoc = 0;
1326 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1330 /* get a unique AID */
1332 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1336 for (i = 0; i < AID_WORDS; i++) {
1337 if (hapd->sta_aid[i] == (u32) -1)
1339 for (j = 0; j < 32; j++) {
1340 if (!(hapd->sta_aid[i] & BIT(j)))
1348 aid = i * 32 + j + 1;
1353 hapd->sta_aid[i] |= BIT(j);
1354 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1359 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1360 const u8 *ssid_ie, size_t ssid_ie_len)
1362 if (ssid_ie == NULL)
1363 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1365 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1366 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1367 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1369 "Station tried to associate with unknown SSID "
1370 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1371 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1374 return WLAN_STATUS_SUCCESS;
1378 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1379 const u8 *wmm_ie, size_t wmm_ie_len)
1381 sta->flags &= ~WLAN_STA_WMM;
1383 if (wmm_ie && hapd->conf->wmm_enabled) {
1384 struct wmm_information_element *wmm;
1386 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1387 hostapd_logger(hapd, sta->addr,
1389 HOSTAPD_LEVEL_DEBUG,
1390 "invalid WMM element in association "
1392 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1395 sta->flags |= WLAN_STA_WMM;
1396 wmm = (struct wmm_information_element *) wmm_ie;
1397 sta->qosinfo = wmm->qos_info;
1399 return WLAN_STATUS_SUCCESS;
1403 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1404 struct ieee802_11_elems *elems)
1406 if (!elems->supp_rates) {
1407 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1408 HOSTAPD_LEVEL_DEBUG,
1409 "No supported rates element in AssocReq");
1410 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1413 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1414 sizeof(sta->supported_rates)) {
1415 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1416 HOSTAPD_LEVEL_DEBUG,
1417 "Invalid supported rates element length %d+%d",
1418 elems->supp_rates_len,
1419 elems->ext_supp_rates_len);
1420 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1423 sta->supported_rates_len = merge_byte_arrays(
1424 sta->supported_rates, sizeof(sta->supported_rates),
1425 elems->supp_rates, elems->supp_rates_len,
1426 elems->ext_supp_rates, elems->ext_supp_rates_len);
1428 return WLAN_STATUS_SUCCESS;
1432 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1433 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1435 #ifdef CONFIG_INTERWORKING
1436 /* check for QoS Map support */
1437 if (ext_capab_ie_len >= 5) {
1438 if (ext_capab_ie[4] & 0x01)
1439 sta->qos_map_enabled = 1;
1441 #endif /* CONFIG_INTERWORKING */
1443 if (ext_capab_ie_len > 0)
1444 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1446 return WLAN_STATUS_SUCCESS;
1450 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1451 const u8 *ies, size_t ies_len, int reassoc)
1453 struct ieee802_11_elems elems;
1457 const u8 *p2p_dev_addr = NULL;
1459 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1460 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1461 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1462 "association request");
1463 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1466 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1467 if (resp != WLAN_STATUS_SUCCESS)
1469 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1470 if (resp != WLAN_STATUS_SUCCESS)
1472 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1473 if (resp != WLAN_STATUS_SUCCESS)
1475 resp = copy_supp_rates(hapd, sta, &elems);
1476 if (resp != WLAN_STATUS_SUCCESS)
1478 #ifdef CONFIG_IEEE80211N
1479 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1480 if (resp != WLAN_STATUS_SUCCESS)
1482 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1483 !(sta->flags & WLAN_STA_HT)) {
1484 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1485 HOSTAPD_LEVEL_INFO, "Station does not support "
1486 "mandatory HT PHY - reject association");
1487 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1489 #endif /* CONFIG_IEEE80211N */
1491 #ifdef CONFIG_IEEE80211AC
1492 if (hapd->iconf->ieee80211ac) {
1493 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1494 if (resp != WLAN_STATUS_SUCCESS)
1497 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1498 if (resp != WLAN_STATUS_SUCCESS)
1502 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1503 !(sta->flags & WLAN_STA_VHT)) {
1504 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1505 HOSTAPD_LEVEL_INFO, "Station does not support "
1506 "mandatory VHT PHY - reject association");
1507 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1510 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1511 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1512 elems.vendor_vht_len);
1513 if (resp != WLAN_STATUS_SUCCESS)
1516 #endif /* CONFIG_IEEE80211AC */
1520 wpabuf_free(sta->p2p_ie);
1521 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1522 P2P_IE_VENDOR_TYPE);
1524 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1526 wpabuf_free(sta->p2p_ie);
1529 #endif /* CONFIG_P2P */
1531 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1532 wpa_ie = elems.rsn_ie;
1533 wpa_ie_len = elems.rsn_ie_len;
1534 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1536 wpa_ie = elems.wpa_ie;
1537 wpa_ie_len = elems.wpa_ie_len;
1544 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1545 if (hapd->conf->wps_state && elems.wps_ie) {
1546 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1547 "Request - assume WPS is used");
1548 sta->flags |= WLAN_STA_WPS;
1549 wpabuf_free(sta->wps_ie);
1550 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1551 WPS_IE_VENDOR_TYPE);
1552 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1553 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1554 sta->flags |= WLAN_STA_WPS2;
1558 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1559 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1560 "(Re)Association Request - reject");
1561 return WLAN_STATUS_INVALID_IE;
1563 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1564 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1565 "(Re)Association Request - possible WPS use");
1566 sta->flags |= WLAN_STA_MAYBE_WPS;
1568 #endif /* CONFIG_WPS */
1569 if (hapd->conf->wpa && wpa_ie == NULL) {
1570 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1572 "No WPA/RSN IE in association request");
1573 return WLAN_STATUS_INVALID_IE;
1576 if (hapd->conf->wpa && wpa_ie) {
1580 if (sta->wpa_sm == NULL)
1581 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1584 if (sta->wpa_sm == NULL) {
1585 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1587 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1589 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1591 elems.mdie, elems.mdie_len);
1592 if (res == WPA_INVALID_GROUP)
1593 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1594 else if (res == WPA_INVALID_PAIRWISE)
1595 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1596 else if (res == WPA_INVALID_AKMP)
1597 resp = WLAN_STATUS_AKMP_NOT_VALID;
1598 else if (res == WPA_ALLOC_FAIL)
1599 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1600 #ifdef CONFIG_IEEE80211W
1601 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1602 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1603 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1604 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1605 #endif /* CONFIG_IEEE80211W */
1606 else if (res == WPA_INVALID_MDIE)
1607 resp = WLAN_STATUS_INVALID_MDIE;
1608 else if (res != WPA_IE_OK)
1609 resp = WLAN_STATUS_INVALID_IE;
1610 if (resp != WLAN_STATUS_SUCCESS)
1612 #ifdef CONFIG_IEEE80211W
1613 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1614 sta->sa_query_count > 0)
1615 ap_check_sa_query_timeout(hapd, sta);
1616 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1617 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1619 * STA has already been associated with MFP and SA
1620 * Query timeout has not been reached. Reject the
1621 * association attempt temporarily and start SA Query,
1622 * if one is not pending.
1625 if (sta->sa_query_count == 0)
1626 ap_sta_start_sa_query(hapd, sta);
1628 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1631 if (wpa_auth_uses_mfp(sta->wpa_sm))
1632 sta->flags |= WLAN_STA_MFP;
1634 sta->flags &= ~WLAN_STA_MFP;
1635 #endif /* CONFIG_IEEE80211W */
1637 #ifdef CONFIG_IEEE80211R
1638 if (sta->auth_alg == WLAN_AUTH_FT) {
1640 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1641 "to use association (not "
1642 "re-association) with FT auth_alg",
1643 MAC2STR(sta->addr));
1644 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1647 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1649 if (resp != WLAN_STATUS_SUCCESS)
1652 #endif /* CONFIG_IEEE80211R */
1655 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1656 sta->auth_alg == WLAN_AUTH_OPEN) {
1657 struct rsn_pmksa_cache_entry *sa;
1658 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1659 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1660 wpa_printf(MSG_DEBUG,
1661 "SAE: No PMKSA cache entry found for "
1662 MACSTR, MAC2STR(sta->addr));
1663 return WLAN_STATUS_INVALID_PMKID;
1665 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1666 " using PMKSA caching", MAC2STR(sta->addr));
1667 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1668 sta->auth_alg != WLAN_AUTH_SAE &&
1669 !(sta->auth_alg == WLAN_AUTH_FT &&
1670 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1671 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1672 "SAE AKM after non-SAE auth_alg %u",
1673 MAC2STR(sta->addr), sta->auth_alg);
1674 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1676 #endif /* CONFIG_SAE */
1678 #ifdef CONFIG_IEEE80211N
1679 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1680 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1681 hostapd_logger(hapd, sta->addr,
1682 HOSTAPD_MODULE_IEEE80211,
1684 "Station tried to use TKIP with HT "
1686 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1688 #endif /* CONFIG_IEEE80211N */
1690 } else if (hapd->conf->osen) {
1691 if (elems.osen == NULL) {
1693 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1695 "No HS 2.0 OSEN element in association request");
1696 return WLAN_STATUS_INVALID_IE;
1699 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1700 if (sta->wpa_sm == NULL)
1701 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1703 if (sta->wpa_sm == NULL) {
1704 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1706 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1708 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1709 elems.osen - 2, elems.osen_len + 2) < 0)
1710 return WLAN_STATUS_INVALID_IE;
1711 #endif /* CONFIG_HS20 */
1713 wpa_auth_sta_no_wpa(sta->wpa_sm);
1716 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1717 #endif /* CONFIG_P2P */
1720 wpabuf_free(sta->hs20_ie);
1721 if (elems.hs20 && elems.hs20_len > 4) {
1722 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1723 elems.hs20_len - 4);
1725 sta->hs20_ie = NULL;
1726 #endif /* CONFIG_HS20 */
1729 wpabuf_free(sta->mb_ies);
1730 if (hapd->iface->fst)
1731 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1734 #endif /* CONFIG_FST */
1737 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1739 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1740 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1741 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1742 wpa_printf(MSG_INFO,
1743 "MBO: Reject WPA2 association without PMF");
1744 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1746 #endif /* CONFIG_MBO */
1748 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
1749 elems.supp_op_classes_len);
1751 return WLAN_STATUS_SUCCESS;
1755 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1759 struct ieee80211_mgmt reply;
1761 os_memset(&reply, 0, sizeof(reply));
1762 reply.frame_control =
1763 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1764 os_memcpy(reply.da, addr, ETH_ALEN);
1765 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1766 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1768 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1769 reply.u.deauth.reason_code = host_to_le16(reason_code);
1771 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1772 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1777 static int add_associated_sta(struct hostapd_data *hapd,
1778 struct sta_info *sta)
1780 struct ieee80211_ht_capabilities ht_cap;
1781 struct ieee80211_vht_capabilities vht_cap;
1784 * Remove the STA entry to ensure the STA PS state gets cleared and
1785 * configuration gets updated. This is relevant for cases, such as
1786 * FT-over-the-DS, where a station re-associates back to the same AP but
1787 * skips the authentication flow, or if working with a driver that
1788 * does not support full AP client state.
1790 if (!sta->added_unassoc)
1791 hostapd_drv_sta_remove(hapd, sta->addr);
1793 #ifdef CONFIG_IEEE80211N
1794 if (sta->flags & WLAN_STA_HT)
1795 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1796 #endif /* CONFIG_IEEE80211N */
1797 #ifdef CONFIG_IEEE80211AC
1798 if (sta->flags & WLAN_STA_VHT)
1799 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1800 #endif /* CONFIG_IEEE80211AC */
1803 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1804 * will be set when the ACK frame for the (Re)Association Response frame
1805 * is processed (TX status driver event).
1807 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1808 sta->supported_rates, sta->supported_rates_len,
1809 sta->listen_interval,
1810 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1811 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1812 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1813 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
1814 sta->added_unassoc)) {
1815 hostapd_logger(hapd, sta->addr,
1816 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1817 "Could not %s STA to kernel driver",
1818 sta->added_unassoc ? "set" : "add");
1820 if (sta->added_unassoc) {
1821 hostapd_drv_sta_remove(hapd, sta->addr);
1822 sta->added_unassoc = 0;
1828 sta->added_unassoc = 0;
1834 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1835 u16 status_code, int reassoc, const u8 *ies,
1839 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1840 struct ieee80211_mgmt *reply;
1843 os_memset(buf, 0, sizeof(buf));
1844 reply = (struct ieee80211_mgmt *) buf;
1845 reply->frame_control =
1846 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1847 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1848 WLAN_FC_STYPE_ASSOC_RESP));
1849 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1850 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1851 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1853 send_len = IEEE80211_HDRLEN;
1854 send_len += sizeof(reply->u.assoc_resp);
1855 reply->u.assoc_resp.capab_info =
1856 host_to_le16(hostapd_own_capab_info(hapd));
1857 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1858 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1859 /* Supported rates */
1860 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1861 /* Extended supported rates */
1862 p = hostapd_eid_ext_supp_rates(hapd, p);
1864 #ifdef CONFIG_IEEE80211R
1865 if (status_code == WLAN_STATUS_SUCCESS) {
1866 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1867 * Transition Information, RSN, [RIC Response] */
1868 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1869 buf + sizeof(buf) - p,
1870 sta->auth_alg, ies, ies_len);
1872 #endif /* CONFIG_IEEE80211R */
1874 #ifdef CONFIG_IEEE80211W
1875 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1876 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1877 #endif /* CONFIG_IEEE80211W */
1879 #ifdef CONFIG_IEEE80211N
1880 p = hostapd_eid_ht_capabilities(hapd, p);
1881 p = hostapd_eid_ht_operation(hapd, p);
1882 #endif /* CONFIG_IEEE80211N */
1884 #ifdef CONFIG_IEEE80211AC
1885 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1886 p = hostapd_eid_vht_capabilities(hapd, p);
1887 p = hostapd_eid_vht_operation(hapd, p);
1889 #endif /* CONFIG_IEEE80211AC */
1891 p = hostapd_eid_ext_capab(hapd, p);
1892 p = hostapd_eid_bss_max_idle_period(hapd, p);
1893 if (sta->qos_map_enabled)
1894 p = hostapd_eid_qos_map_set(hapd, p);
1897 if (hapd->iface->fst_ies) {
1898 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1899 wpabuf_len(hapd->iface->fst_ies));
1900 p += wpabuf_len(hapd->iface->fst_ies);
1902 #endif /* CONFIG_FST */
1904 #ifdef CONFIG_IEEE80211AC
1905 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1906 p = hostapd_eid_vendor_vht(hapd, p);
1907 #endif /* CONFIG_IEEE80211AC */
1909 if (sta->flags & WLAN_STA_WMM)
1910 p = hostapd_eid_wmm(hapd, p);
1913 if ((sta->flags & WLAN_STA_WPS) ||
1914 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1915 struct wpabuf *wps = wps_build_assoc_resp_ie();
1917 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1918 p += wpabuf_len(wps);
1922 #endif /* CONFIG_WPS */
1925 if (sta->p2p_ie && hapd->p2p_group) {
1926 struct wpabuf *p2p_resp_ie;
1927 enum p2p_status_code status;
1928 switch (status_code) {
1929 case WLAN_STATUS_SUCCESS:
1930 status = P2P_SC_SUCCESS;
1932 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1933 status = P2P_SC_FAIL_LIMIT_REACHED;
1936 status = P2P_SC_FAIL_INVALID_PARAMS;
1939 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1941 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1942 wpabuf_len(p2p_resp_ie));
1943 p += wpabuf_len(p2p_resp_ie);
1944 wpabuf_free(p2p_resp_ie);
1947 #endif /* CONFIG_P2P */
1949 #ifdef CONFIG_P2P_MANAGER
1950 if (hapd->conf->p2p & P2P_MANAGE)
1951 p = hostapd_eid_p2p_manage(hapd, p);
1952 #endif /* CONFIG_P2P_MANAGER */
1954 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1956 send_len += p - reply->u.assoc_resp.variable;
1958 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
1959 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1961 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1964 return WLAN_STATUS_SUCCESS;
1968 static void handle_assoc(struct hostapd_data *hapd,
1969 const struct ieee80211_mgmt *mgmt, size_t len,
1972 u16 capab_info, listen_interval, seq_ctrl, fc;
1973 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
1976 struct sta_info *sta;
1978 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1979 sizeof(mgmt->u.assoc_req))) {
1980 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1981 reassoc, (unsigned long) len);
1985 #ifdef CONFIG_TESTING_OPTIONS
1987 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1988 drand48() < hapd->iconf->ignore_reassoc_probability) {
1989 wpa_printf(MSG_INFO,
1990 "TESTING: ignoring reassoc request from "
1991 MACSTR, MAC2STR(mgmt->sa));
1995 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1996 drand48() < hapd->iconf->ignore_assoc_probability) {
1997 wpa_printf(MSG_INFO,
1998 "TESTING: ignoring assoc request from "
1999 MACSTR, MAC2STR(mgmt->sa));
2003 #endif /* CONFIG_TESTING_OPTIONS */
2005 fc = le_to_host16(mgmt->frame_control);
2006 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2009 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
2010 listen_interval = le_to_host16(
2011 mgmt->u.reassoc_req.listen_interval);
2012 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
2013 " capab_info=0x%02x listen_interval=%d current_ap="
2014 MACSTR " seq_ctrl=0x%x%s",
2015 MAC2STR(mgmt->sa), capab_info, listen_interval,
2016 MAC2STR(mgmt->u.reassoc_req.current_ap),
2017 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2018 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
2019 pos = mgmt->u.reassoc_req.variable;
2021 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2022 listen_interval = le_to_host16(
2023 mgmt->u.assoc_req.listen_interval);
2024 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
2025 " capab_info=0x%02x listen_interval=%d "
2027 MAC2STR(mgmt->sa), capab_info, listen_interval,
2028 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2029 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2030 pos = mgmt->u.assoc_req.variable;
2033 sta = ap_get_sta(hapd, mgmt->sa);
2034 #ifdef CONFIG_IEEE80211R
2035 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2036 (sta->flags & WLAN_STA_AUTH) == 0) {
2037 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2038 "prior to authentication since it is using "
2039 "over-the-DS FT", MAC2STR(mgmt->sa));
2042 * Mark station as authenticated, to avoid adding station
2043 * entry in the driver as associated and not authenticated
2045 sta->flags |= WLAN_STA_AUTH;
2047 #endif /* CONFIG_IEEE80211R */
2048 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2049 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2050 HOSTAPD_LEVEL_INFO, "Station tried to "
2051 "associate before authentication "
2052 "(aid=%d flags=0x%x)",
2053 sta ? sta->aid : -1,
2054 sta ? sta->flags : 0);
2055 send_deauth(hapd, mgmt->sa,
2056 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2060 if ((fc & WLAN_FC_RETRY) &&
2061 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2062 sta->last_seq_ctrl == seq_ctrl &&
2063 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2064 WLAN_FC_STYPE_ASSOC_REQ) {
2065 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2066 HOSTAPD_LEVEL_DEBUG,
2067 "Drop repeated association frame seq_ctrl=0x%x",
2071 sta->last_seq_ctrl = seq_ctrl;
2072 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2073 WLAN_FC_STYPE_ASSOC_REQ;
2075 if (hapd->tkip_countermeasures) {
2076 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2080 if (listen_interval > hapd->conf->max_listen_interval) {
2081 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2082 HOSTAPD_LEVEL_DEBUG,
2083 "Too large Listen Interval (%d)",
2085 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2090 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2091 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2094 #endif /* CONFIG_MBO */
2096 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2098 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2099 if (resp != WLAN_STATUS_SUCCESS)
2102 if (hostapd_get_aid(hapd, sta) < 0) {
2103 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2104 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2105 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2109 sta->capability = capab_info;
2110 sta->listen_interval = listen_interval;
2112 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2113 sta->flags |= WLAN_STA_NONERP;
2114 for (i = 0; i < sta->supported_rates_len; i++) {
2115 if ((sta->supported_rates[i] & 0x7f) > 22) {
2116 sta->flags &= ~WLAN_STA_NONERP;
2120 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2121 sta->nonerp_set = 1;
2122 hapd->iface->num_sta_non_erp++;
2123 if (hapd->iface->num_sta_non_erp == 1)
2124 ieee802_11_set_beacons(hapd->iface);
2127 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2128 !sta->no_short_slot_time_set) {
2129 sta->no_short_slot_time_set = 1;
2130 hapd->iface->num_sta_no_short_slot_time++;
2131 if (hapd->iface->current_mode->mode ==
2132 HOSTAPD_MODE_IEEE80211G &&
2133 hapd->iface->num_sta_no_short_slot_time == 1)
2134 ieee802_11_set_beacons(hapd->iface);
2137 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2138 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2140 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2142 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2143 !sta->no_short_preamble_set) {
2144 sta->no_short_preamble_set = 1;
2145 hapd->iface->num_sta_no_short_preamble++;
2146 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2147 && hapd->iface->num_sta_no_short_preamble == 1)
2148 ieee802_11_set_beacons(hapd->iface);
2151 #ifdef CONFIG_IEEE80211N
2152 update_ht_state(hapd, sta);
2153 #endif /* CONFIG_IEEE80211N */
2155 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2156 HOSTAPD_LEVEL_DEBUG,
2157 "association OK (aid %d)", sta->aid);
2158 /* Station will be marked associated, after it acknowledges AssocResp
2160 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2162 #ifdef CONFIG_IEEE80211W
2163 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2164 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2165 "SA Query procedure", reassoc ? "re" : "");
2166 /* TODO: Send a protected Disassociate frame to the STA using
2167 * the old key and Reason Code "Previous Authentication no
2168 * longer valid". Make sure this is only sent protected since
2169 * unprotected frame would be received by the STA that is now
2170 * trying to associate.
2173 #endif /* CONFIG_IEEE80211W */
2175 /* Make sure that the previously registered inactivity timer will not
2176 * remove the STA immediately. */
2177 sta->timeout_next = STA_NULLFUNC;
2181 * In case of a successful response, add the station to the driver.
2182 * Otherwise, the kernel may ignore Data frames before we process the
2183 * ACK frame (TX status). In case of a failure, this station will be
2186 * Note that this is not compliant with the IEEE 802.11 standard that
2187 * states that a non-AP station should transition into the
2188 * authenticated/associated state only after the station acknowledges
2189 * the (Re)Association Response frame. However, still do this as:
2191 * 1. In case the station does not acknowledge the (Re)Association
2192 * Response frame, it will be removed.
2193 * 2. Data frames will be dropped in the kernel until the station is
2194 * set into authorized state, and there are no significant known
2195 * issues with processing other non-Data Class 3 frames during this
2198 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2199 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2201 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2204 * Remove the station in case tranmission of a success response fails
2205 * (the STA was added associated to the driver) or if the station was
2206 * previously added unassociated.
2208 if ((reply_res != WLAN_STATUS_SUCCESS &&
2209 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2210 hostapd_drv_sta_remove(hapd, sta->addr);
2211 sta->added_unassoc = 0;
2216 static void handle_disassoc(struct hostapd_data *hapd,
2217 const struct ieee80211_mgmt *mgmt, size_t len)
2219 struct sta_info *sta;
2221 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2222 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2223 (unsigned long) len);
2227 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2229 le_to_host16(mgmt->u.disassoc.reason_code));
2231 sta = ap_get_sta(hapd, mgmt->sa);
2233 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2238 ap_sta_set_authorized(hapd, sta, 0);
2239 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2240 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2241 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2243 HOSTAPD_LEVEL_INFO, "disassociated");
2244 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2245 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2246 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2248 accounting_sta_stop(hapd, sta);
2249 ieee802_1x_free_station(hapd, sta);
2251 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2252 ap_sta_ip6addr_del(hapd, sta);
2253 hostapd_drv_sta_remove(hapd, sta->addr);
2254 sta->added_unassoc = 0;
2256 if (sta->timeout_next == STA_NULLFUNC ||
2257 sta->timeout_next == STA_DISASSOC) {
2258 sta->timeout_next = STA_DEAUTH;
2259 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2260 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2264 mlme_disassociate_indication(
2265 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2269 static void handle_deauth(struct hostapd_data *hapd,
2270 const struct ieee80211_mgmt *mgmt, size_t len)
2272 struct sta_info *sta;
2274 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2275 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2276 "payload (len=%lu)", (unsigned long) len);
2280 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2282 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2284 sta = ap_get_sta(hapd, mgmt->sa);
2286 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2287 "to deauthenticate, but it is not authenticated",
2292 ap_sta_set_authorized(hapd, sta, 0);
2293 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2294 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2295 WLAN_STA_ASSOC_REQ_OK);
2296 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2297 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2298 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2299 mlme_deauthenticate_indication(
2300 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2301 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2302 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2303 ap_free_sta(hapd, sta);
2307 static void handle_beacon(struct hostapd_data *hapd,
2308 const struct ieee80211_mgmt *mgmt, size_t len,
2309 struct hostapd_frame_info *fi)
2311 struct ieee802_11_elems elems;
2313 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2314 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2315 (unsigned long) len);
2319 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2320 len - (IEEE80211_HDRLEN +
2321 sizeof(mgmt->u.beacon)), &elems,
2324 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2328 #ifdef CONFIG_IEEE80211W
2330 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2331 const struct ieee80211_mgmt *mgmt,
2336 end = mgmt->u.action.u.sa_query_resp.trans_id +
2337 WLAN_SA_QUERY_TR_ID_LEN;
2338 if (((u8 *) mgmt) + len < end) {
2339 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2340 "frame (len=%lu)", (unsigned long) len);
2344 ieee802_11_sa_query_action(hapd, mgmt->sa,
2345 mgmt->u.action.u.sa_query_resp.action,
2346 mgmt->u.action.u.sa_query_resp.trans_id);
2351 static int robust_action_frame(u8 category)
2353 return category != WLAN_ACTION_PUBLIC &&
2354 category != WLAN_ACTION_HT;
2356 #endif /* CONFIG_IEEE80211W */
2359 static int handle_action(struct hostapd_data *hapd,
2360 const struct ieee80211_mgmt *mgmt, size_t len)
2362 struct sta_info *sta;
2363 sta = ap_get_sta(hapd, mgmt->sa);
2365 if (len < IEEE80211_HDRLEN + 1) {
2366 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2367 HOSTAPD_LEVEL_DEBUG,
2368 "handle_action - too short payload (len=%lu)",
2369 (unsigned long) len);
2373 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2374 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2375 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2376 "frame (category=%u) from unassociated STA " MACSTR,
2377 MAC2STR(mgmt->sa), mgmt->u.action.category);
2381 #ifdef CONFIG_IEEE80211W
2382 if (sta && (sta->flags & WLAN_STA_MFP) &&
2383 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2384 robust_action_frame(mgmt->u.action.category)) {
2385 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2386 HOSTAPD_LEVEL_DEBUG,
2387 "Dropped unprotected Robust Action frame from "
2391 #endif /* CONFIG_IEEE80211W */
2394 u16 fc = le_to_host16(mgmt->frame_control);
2395 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2397 if ((fc & WLAN_FC_RETRY) &&
2398 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2399 sta->last_seq_ctrl == seq_ctrl &&
2400 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2401 hostapd_logger(hapd, sta->addr,
2402 HOSTAPD_MODULE_IEEE80211,
2403 HOSTAPD_LEVEL_DEBUG,
2404 "Drop repeated action frame seq_ctrl=0x%x",
2409 sta->last_seq_ctrl = seq_ctrl;
2410 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2413 switch (mgmt->u.action.category) {
2414 #ifdef CONFIG_IEEE80211R
2415 case WLAN_ACTION_FT:
2417 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2418 len - IEEE80211_HDRLEN))
2421 #endif /* CONFIG_IEEE80211R */
2422 case WLAN_ACTION_WMM:
2423 hostapd_wmm_action(hapd, mgmt, len);
2425 #ifdef CONFIG_IEEE80211W
2426 case WLAN_ACTION_SA_QUERY:
2427 return hostapd_sa_query_action(hapd, mgmt, len);
2428 #endif /* CONFIG_IEEE80211W */
2430 case WLAN_ACTION_WNM:
2431 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2433 #endif /* CONFIG_WNM */
2435 case WLAN_ACTION_FST:
2436 if (hapd->iface->fst)
2437 fst_rx_action(hapd->iface->fst, mgmt, len);
2439 wpa_printf(MSG_DEBUG,
2440 "FST: Ignore FST Action frame - no FST attached");
2442 #endif /* CONFIG_FST */
2443 case WLAN_ACTION_PUBLIC:
2444 case WLAN_ACTION_PROTECTED_DUAL:
2445 #ifdef CONFIG_IEEE80211N
2446 if (len >= IEEE80211_HDRLEN + 2 &&
2447 mgmt->u.action.u.public_action.action ==
2448 WLAN_PA_20_40_BSS_COEX) {
2449 wpa_printf(MSG_DEBUG,
2450 "HT20/40 coex mgmt frame received from STA "
2451 MACSTR, MAC2STR(mgmt->sa));
2452 hostapd_2040_coex_action(hapd, mgmt, len);
2454 #endif /* CONFIG_IEEE80211N */
2455 if (hapd->public_action_cb) {
2456 hapd->public_action_cb(hapd->public_action_cb_ctx,
2460 if (hapd->public_action_cb2) {
2461 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2465 if (hapd->public_action_cb || hapd->public_action_cb2)
2468 case WLAN_ACTION_VENDOR_SPECIFIC:
2469 if (hapd->vendor_action_cb) {
2470 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2472 hapd->iface->freq) == 0)
2478 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2479 HOSTAPD_LEVEL_DEBUG,
2480 "handle_action - unknown action category %d or invalid "
2482 mgmt->u.action.category);
2483 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2484 !(mgmt->sa[0] & 0x01)) {
2485 struct ieee80211_mgmt *resp;
2488 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2489 * Return the Action frame to the source without change
2490 * except that MSB of the Category set to 1.
2492 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2493 "frame back to sender");
2494 resp = os_malloc(len);
2497 os_memcpy(resp, mgmt, len);
2498 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2499 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2500 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2501 resp->u.action.category |= 0x80;
2503 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2504 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2515 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2516 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2518 * @buf: management frame data (starting from IEEE 802.11 header)
2519 * @len: length of frame data in octets
2520 * @fi: meta data about received frame (signal level, etc.)
2522 * Process all incoming IEEE 802.11 management frames. This will be called for
2523 * each frame received from the kernel driver through wlan#ap interface. In
2524 * addition, it can be called to re-inserted pending frames (e.g., when using
2525 * external RADIUS server as an MAC ACL).
2527 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2528 struct hostapd_frame_info *fi)
2530 struct ieee80211_mgmt *mgmt;
2538 mgmt = (struct ieee80211_mgmt *) buf;
2539 fc = le_to_host16(mgmt->frame_control);
2540 stype = WLAN_FC_GET_STYPE(fc);
2542 if (stype == WLAN_FC_STYPE_BEACON) {
2543 handle_beacon(hapd, mgmt, len, fi);
2547 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2548 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2549 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2553 /* Invitation responses can be sent with the peer MAC as BSSID */
2554 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2555 stype == WLAN_FC_STYPE_ACTION) &&
2556 #endif /* CONFIG_P2P */
2558 !(hapd->conf->mesh & MESH_ENABLED) &&
2559 #endif /* CONFIG_MESH */
2560 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2561 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2562 MAC2STR(mgmt->bssid));
2567 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2568 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2572 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2573 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2574 HOSTAPD_LEVEL_DEBUG,
2575 "MGMT: DA=" MACSTR " not our address",
2580 if (hapd->iconf->track_sta_max_num)
2581 sta_track_add(hapd->iface, mgmt->sa);
2584 case WLAN_FC_STYPE_AUTH:
2585 wpa_printf(MSG_DEBUG, "mgmt::auth");
2586 handle_auth(hapd, mgmt, len);
2589 case WLAN_FC_STYPE_ASSOC_REQ:
2590 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2591 handle_assoc(hapd, mgmt, len, 0);
2594 case WLAN_FC_STYPE_REASSOC_REQ:
2595 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2596 handle_assoc(hapd, mgmt, len, 1);
2599 case WLAN_FC_STYPE_DISASSOC:
2600 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2601 handle_disassoc(hapd, mgmt, len);
2604 case WLAN_FC_STYPE_DEAUTH:
2605 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2606 handle_deauth(hapd, mgmt, len);
2609 case WLAN_FC_STYPE_ACTION:
2610 wpa_printf(MSG_DEBUG, "mgmt::action");
2611 ret = handle_action(hapd, mgmt, len);
2614 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2615 HOSTAPD_LEVEL_DEBUG,
2616 "unknown mgmt frame subtype %d", stype);
2624 static void handle_auth_cb(struct hostapd_data *hapd,
2625 const struct ieee80211_mgmt *mgmt,
2628 u16 auth_alg, auth_transaction, status_code;
2629 struct sta_info *sta;
2631 sta = ap_get_sta(hapd, mgmt->da);
2633 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2638 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2639 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2640 status_code = le_to_host16(mgmt->u.auth.status_code);
2643 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2644 HOSTAPD_LEVEL_NOTICE,
2645 "did not acknowledge authentication response");
2649 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2650 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2651 (unsigned long) len);
2655 if (status_code == WLAN_STATUS_SUCCESS &&
2656 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2657 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2658 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2659 HOSTAPD_LEVEL_INFO, "authenticated");
2660 sta->flags |= WLAN_STA_AUTH;
2661 if (sta->added_unassoc)
2662 hostapd_set_sta_flags(hapd, sta);
2667 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2668 hostapd_drv_sta_remove(hapd, sta->addr);
2669 sta->added_unassoc = 0;
2674 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2675 struct sta_info *sta,
2679 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2681 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2684 for (i = 0; i < 4; i++) {
2685 if (ssid->wep.key[i] &&
2686 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2687 i == ssid->wep.idx, NULL, 0,
2688 ssid->wep.key[i], ssid->wep.len[i])) {
2689 wpa_printf(MSG_WARNING,
2690 "Could not set WEP keys for WDS interface; %s",
2698 static void handle_assoc_cb(struct hostapd_data *hapd,
2699 const struct ieee80211_mgmt *mgmt,
2700 size_t len, int reassoc, int ok)
2703 struct sta_info *sta;
2706 sta = ap_get_sta(hapd, mgmt->da);
2708 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2713 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2714 sizeof(mgmt->u.assoc_resp))) {
2715 wpa_printf(MSG_INFO,
2716 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2717 reassoc, (unsigned long) len);
2718 hostapd_drv_sta_remove(hapd, sta->addr);
2723 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2725 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2728 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2729 HOSTAPD_LEVEL_DEBUG,
2730 "did not acknowledge association response");
2731 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2732 /* The STA is added only in case of SUCCESS */
2733 if (status == WLAN_STATUS_SUCCESS)
2734 hostapd_drv_sta_remove(hapd, sta->addr);
2739 if (status != WLAN_STATUS_SUCCESS)
2742 /* Stop previous accounting session, if one is started, and allocate
2743 * new session id for the new session. */
2744 accounting_sta_stop(hapd, sta);
2746 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2748 "associated (aid %d)",
2751 if (sta->flags & WLAN_STA_ASSOC)
2753 sta->flags |= WLAN_STA_ASSOC;
2754 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2755 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2756 sta->auth_alg == WLAN_AUTH_FT) {
2758 * Open, static WEP, or FT protocol; no separate authorization
2761 ap_sta_set_authorized(hapd, sta, 1);
2765 mlme_reassociate_indication(hapd, sta);
2767 mlme_associate_indication(hapd, sta);
2769 #ifdef CONFIG_IEEE80211W
2770 sta->sa_query_timed_out = 0;
2771 #endif /* CONFIG_IEEE80211W */
2773 if (sta->flags & WLAN_STA_WDS) {
2775 char ifname_wds[IFNAMSIZ + 1];
2777 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2780 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2783 if (sta->eapol_sm == NULL) {
2785 * This STA does not use RADIUS server for EAP authentication,
2786 * so bind it to the selected VLAN interface now, since the
2787 * interface selection is not going to change anymore.
2789 if (ap_sta_bind_vlan(hapd, sta) < 0)
2791 } else if (sta->vlan_id) {
2792 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2793 if (ap_sta_bind_vlan(hapd, sta) < 0)
2797 hostapd_set_sta_flags(hapd, sta);
2799 if (sta->auth_alg == WLAN_AUTH_FT)
2800 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2802 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2803 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2804 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2806 if (sta->pending_eapol_rx) {
2807 struct os_reltime now, age;
2809 os_get_reltime(&now);
2810 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
2811 if (age.sec == 0 && age.usec < 200000) {
2812 wpa_printf(MSG_DEBUG,
2813 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
2814 MAC2STR(sta->addr));
2817 wpabuf_head(sta->pending_eapol_rx->buf),
2818 wpabuf_len(sta->pending_eapol_rx->buf));
2820 wpabuf_free(sta->pending_eapol_rx->buf);
2821 os_free(sta->pending_eapol_rx);
2822 sta->pending_eapol_rx = NULL;
2827 static void handle_deauth_cb(struct hostapd_data *hapd,
2828 const struct ieee80211_mgmt *mgmt,
2831 struct sta_info *sta;
2832 if (mgmt->da[0] & 0x01)
2834 sta = ap_get_sta(hapd, mgmt->da);
2836 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2837 " not found", MAC2STR(mgmt->da));
2841 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2842 MAC2STR(sta->addr));
2844 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2845 "deauth", MAC2STR(sta->addr));
2847 ap_sta_deauth_cb(hapd, sta);
2851 static void handle_disassoc_cb(struct hostapd_data *hapd,
2852 const struct ieee80211_mgmt *mgmt,
2855 struct sta_info *sta;
2856 if (mgmt->da[0] & 0x01)
2858 sta = ap_get_sta(hapd, mgmt->da);
2860 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2861 " not found", MAC2STR(mgmt->da));
2865 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2866 MAC2STR(sta->addr));
2868 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2869 "disassoc", MAC2STR(sta->addr));
2871 ap_sta_disassoc_cb(hapd, sta);
2876 * ieee802_11_mgmt_cb - Process management frame TX status callback
2877 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2879 * @buf: management frame data (starting from IEEE 802.11 header)
2880 * @len: length of frame data in octets
2881 * @stype: management frame subtype from frame control field
2882 * @ok: Whether the frame was ACK'ed
2884 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2887 const struct ieee80211_mgmt *mgmt;
2888 mgmt = (const struct ieee80211_mgmt *) buf;
2890 #ifdef CONFIG_TESTING_OPTIONS
2891 if (hapd->ext_mgmt_frame_handling) {
2892 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2896 #endif /* CONFIG_TESTING_OPTIONS */
2899 case WLAN_FC_STYPE_AUTH:
2900 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2901 handle_auth_cb(hapd, mgmt, len, ok);
2903 case WLAN_FC_STYPE_ASSOC_RESP:
2904 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2905 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2907 case WLAN_FC_STYPE_REASSOC_RESP:
2908 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2909 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2911 case WLAN_FC_STYPE_PROBE_RESP:
2912 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
2914 case WLAN_FC_STYPE_DEAUTH:
2915 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2916 handle_deauth_cb(hapd, mgmt, len, ok);
2918 case WLAN_FC_STYPE_DISASSOC:
2919 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2920 handle_disassoc_cb(hapd, mgmt, len, ok);
2922 case WLAN_FC_STYPE_ACTION:
2923 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
2926 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2932 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2939 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2940 char *buf, size_t buflen)
2947 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2948 const u8 *buf, size_t len, int ack)
2950 struct sta_info *sta;
2951 struct hostapd_iface *iface = hapd->iface;
2953 sta = ap_get_sta(hapd, addr);
2954 if (sta == NULL && iface->num_bss > 1) {
2956 for (j = 0; j < iface->num_bss; j++) {
2957 hapd = iface->bss[j];
2958 sta = ap_get_sta(hapd, addr);
2963 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2965 if (sta->flags & WLAN_STA_PENDING_POLL) {
2966 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2967 "activity poll", MAC2STR(sta->addr),
2968 ack ? "ACKed" : "did not ACK");
2970 sta->flags &= ~WLAN_STA_PENDING_POLL;
2973 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2977 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2978 const u8 *data, size_t len, int ack)
2980 struct sta_info *sta;
2981 struct hostapd_iface *iface = hapd->iface;
2983 sta = ap_get_sta(hapd, dst);
2984 if (sta == NULL && iface->num_bss > 1) {
2986 for (j = 0; j < iface->num_bss; j++) {
2987 hapd = iface->bss[j];
2988 sta = ap_get_sta(hapd, dst);
2993 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2994 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2995 MACSTR " that is not currently associated",
3000 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
3004 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
3006 struct sta_info *sta;
3007 struct hostapd_iface *iface = hapd->iface;
3009 sta = ap_get_sta(hapd, addr);
3010 if (sta == NULL && iface->num_bss > 1) {
3012 for (j = 0; j < iface->num_bss; j++) {
3013 hapd = iface->bss[j];
3014 sta = ap_get_sta(hapd, addr);
3021 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
3022 MAC2STR(sta->addr));
3023 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3026 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3027 "activity poll", MAC2STR(sta->addr));
3028 sta->flags &= ~WLAN_STA_PENDING_POLL;
3032 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3035 struct sta_info *sta;
3037 sta = ap_get_sta(hapd, src);
3038 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
3039 if (!hapd->conf->wds_sta)
3042 if (wds && !(sta->flags & WLAN_STA_WDS)) {
3044 char ifname_wds[IFNAMSIZ + 1];
3046 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3047 "STA " MACSTR " (aid %u)",
3048 MAC2STR(sta->addr), sta->aid);
3049 sta->flags |= WLAN_STA_WDS;
3050 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3051 sta->addr, sta->aid, 1);
3053 hostapd_set_wds_encryption(hapd, sta,
3059 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3060 MACSTR, MAC2STR(src));
3061 if (src[0] & 0x01) {
3062 /* Broadcast bit set in SA?! Ignore the frame silently. */
3066 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3067 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3068 "already been sent, but no TX status yet known - "
3069 "ignore Class 3 frame issue with " MACSTR,
3074 if (sta && (sta->flags & WLAN_STA_AUTH))
3075 hostapd_drv_sta_disassoc(
3077 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3079 hostapd_drv_sta_deauth(
3081 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3085 #endif /* CONFIG_NATIVE_WINDOWS */