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"
49 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
54 if (hapd->iface->current_rates == NULL)
57 *pos++ = WLAN_EID_SUPP_RATES;
58 num = hapd->iface->num_rates;
59 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
61 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
64 /* rest of the rates are encoded in Extended supported
70 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
73 *pos = hapd->iface->current_rates[i].rate / 5;
74 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
79 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
81 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
84 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
86 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
93 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
98 if (hapd->iface->current_rates == NULL)
101 num = hapd->iface->num_rates;
102 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
104 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
110 *pos++ = WLAN_EID_EXT_SUPP_RATES;
112 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
116 continue; /* already in SuppRates IE */
117 *pos = hapd->iface->current_rates[i].rate / 5;
118 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
123 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
126 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
129 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
132 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
139 u16 hostapd_own_capab_info(struct hostapd_data *hapd)
141 int capab = WLAN_CAPABILITY_ESS;
146 /* Check if any of configured channels require DFS */
147 dfs = hostapd_is_dfs_required(hapd->iface);
149 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
154 if (hapd->iface->num_sta_no_short_preamble == 0 &&
155 hapd->iconf->preamble == SHORT_PREAMBLE)
156 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
158 privacy = hapd->conf->ssid.wep.keys_set;
160 if (hapd->conf->ieee802_1x &&
161 (hapd->conf->default_wep_key_len ||
162 hapd->conf->individual_wep_key_len))
169 if (hapd->conf->osen)
171 #endif /* CONFIG_HS20 */
174 capab |= WLAN_CAPABILITY_PRIVACY;
176 if (hapd->iface->current_mode &&
177 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
178 hapd->iface->num_sta_no_short_slot_time == 0)
179 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
182 * Currently, Spectrum Management capability bit is set when directly
183 * requested in configuration by spectrum_mgmt_required or when AP is
184 * running on DFS channel.
185 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
187 if (hapd->iface->current_mode &&
188 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
189 (hapd->iconf->spectrum_mgmt_required || dfs))
190 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
192 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
193 if (hapd->conf->radio_measurements[i]) {
194 capab |= IEEE80211_CAP_RRM;
203 #ifndef CONFIG_NO_RC4
204 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
205 u16 auth_transaction, const u8 *challenge,
208 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
210 "authentication (shared key, transaction %d)",
213 if (auth_transaction == 1) {
214 if (!sta->challenge) {
215 /* Generate a pseudo-random challenge */
218 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
219 if (sta->challenge == NULL)
220 return WLAN_STATUS_UNSPECIFIED_FAILURE;
222 if (os_get_random(key, sizeof(key)) < 0) {
223 os_free(sta->challenge);
224 sta->challenge = NULL;
225 return WLAN_STATUS_UNSPECIFIED_FAILURE;
228 rc4_skip(key, sizeof(key), 0,
229 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
234 if (auth_transaction != 3)
235 return WLAN_STATUS_UNSPECIFIED_FAILURE;
238 if (!iswep || !sta->challenge || !challenge ||
239 os_memcmp_const(sta->challenge, challenge,
240 WLAN_AUTH_CHALLENGE_LEN)) {
241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 "shared key authentication - invalid "
244 "challenge-response");
245 return WLAN_STATUS_CHALLENGE_FAIL;
248 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
250 "authentication OK (shared key)");
251 sta->flags |= WLAN_STA_AUTH;
252 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
253 os_free(sta->challenge);
254 sta->challenge = NULL;
258 #endif /* CONFIG_NO_RC4 */
261 static int send_auth_reply(struct hostapd_data *hapd,
262 const u8 *dst, const u8 *bssid,
263 u16 auth_alg, u16 auth_transaction, u16 resp,
264 const u8 *ies, size_t ies_len)
266 struct ieee80211_mgmt *reply;
269 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
271 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
272 buf = os_zalloc(rlen);
276 reply = (struct ieee80211_mgmt *) buf;
277 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
279 os_memcpy(reply->da, dst, ETH_ALEN);
280 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
281 os_memcpy(reply->bssid, bssid, ETH_ALEN);
283 reply->u.auth.auth_alg = host_to_le16(auth_alg);
284 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
285 reply->u.auth.status_code = host_to_le16(resp);
288 os_memcpy(reply->u.auth.variable, ies, ies_len);
290 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
291 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
292 MAC2STR(dst), auth_alg, auth_transaction,
293 resp, (unsigned long) ies_len);
294 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
295 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
297 reply_res = WLAN_STATUS_SUCCESS;
305 #ifdef CONFIG_IEEE80211R
306 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
307 u16 auth_transaction, u16 status,
308 const u8 *ies, size_t ies_len)
310 struct hostapd_data *hapd = ctx;
311 struct sta_info *sta;
314 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
315 auth_transaction, status, ies, ies_len);
317 sta = ap_get_sta(hapd, dst);
321 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
322 status != WLAN_STATUS_SUCCESS)) {
323 hostapd_drv_sta_remove(hapd, sta->addr);
324 sta->added_unassoc = 0;
328 if (status != WLAN_STATUS_SUCCESS)
331 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
332 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
333 sta->flags |= WLAN_STA_AUTH;
334 mlme_authenticate_indication(hapd, sta);
336 #endif /* CONFIG_IEEE80211R */
341 #define dot11RSNASAESync 5 /* attempts */
344 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
345 struct sta_info *sta, int update)
349 if (hapd->conf->ssid.wpa_passphrase == NULL) {
350 wpa_printf(MSG_DEBUG, "SAE: No password available");
355 sae_prepare_commit(hapd->own_addr, sta->addr,
356 (u8 *) hapd->conf->ssid.wpa_passphrase,
357 os_strlen(hapd->conf->ssid.wpa_passphrase),
359 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
363 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
366 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
367 sta->sae->tmp->anti_clogging_token : NULL);
373 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
374 struct sta_info *sta)
378 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
382 sae_write_confirm(sta->sae, buf);
388 static int auth_sae_send_commit(struct hostapd_data *hapd,
389 struct sta_info *sta,
390 const u8 *bssid, int update)
395 data = auth_build_sae_commit(hapd, sta, update);
397 return WLAN_STATUS_UNSPECIFIED_FAILURE;
399 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
400 WLAN_STATUS_SUCCESS, wpabuf_head(data),
409 static int auth_sae_send_confirm(struct hostapd_data *hapd,
410 struct sta_info *sta,
416 data = auth_build_sae_confirm(hapd, sta);
418 return WLAN_STATUS_UNSPECIFIED_FAILURE;
420 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
421 WLAN_STATUS_SUCCESS, wpabuf_head(data),
430 static int use_sae_anti_clogging(struct hostapd_data *hapd)
432 struct sta_info *sta;
433 unsigned int open = 0;
435 if (hapd->conf->sae_anti_clogging_threshold == 0)
438 for (sta = hapd->sta_list; sta; sta = sta->next) {
441 if (sta->sae->state != SAE_COMMITTED &&
442 sta->sae->state != SAE_CONFIRMED)
445 if (open >= hapd->conf->sae_anti_clogging_threshold)
453 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
454 const u8 *token, size_t token_len)
456 u8 mac[SHA256_MAC_LEN];
458 if (token_len != SHA256_MAC_LEN)
460 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
461 addr, ETH_ALEN, mac) < 0 ||
462 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
469 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
470 int group, const u8 *addr)
474 struct os_reltime now;
476 os_get_reltime(&now);
477 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
478 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
479 if (random_get_bytes(hapd->sae_token_key,
480 sizeof(hapd->sae_token_key)) < 0)
482 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
483 hapd->sae_token_key, sizeof(hapd->sae_token_key));
484 hapd->last_sae_token_key_update = now;
487 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
491 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
493 token = wpabuf_put(buf, SHA256_MAC_LEN);
494 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
495 addr, ETH_ALEN, token);
501 static int sae_check_big_sync(struct sta_info *sta)
503 if (sta->sae->sync > dot11RSNASAESync) {
504 sta->sae->state = SAE_NOTHING;
512 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
514 struct hostapd_data *hapd = eloop_ctx;
515 struct sta_info *sta = eloop_data;
518 if (sae_check_big_sync(sta))
522 switch (sta->sae->state) {
524 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
525 eloop_register_timeout(0,
526 hapd->dot11RSNASAERetransPeriod * 1000,
527 auth_sae_retransmit_timer, hapd, sta);
530 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
531 eloop_register_timeout(0,
532 hapd->dot11RSNASAERetransPeriod * 1000,
533 auth_sae_retransmit_timer, hapd, sta);
540 if (ret != WLAN_STATUS_SUCCESS)
541 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
545 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
547 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
551 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
552 struct sta_info *sta)
554 if (!(hapd->conf->mesh & MESH_ENABLED))
557 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
558 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
559 auth_sae_retransmit_timer, hapd, sta);
563 void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
565 sta->flags |= WLAN_STA_AUTH;
566 sta->auth_alg = WLAN_AUTH_SAE;
567 mlme_authenticate_indication(hapd, sta);
568 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
569 sta->sae->state = SAE_ACCEPTED;
570 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
571 sta->sae->pmk, sta->sae->pmkid);
575 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
576 const u8 *bssid, u8 auth_transaction)
580 if (auth_transaction != 1 && auth_transaction != 2)
581 return WLAN_STATUS_UNSPECIFIED_FAILURE;
583 switch (sta->sae->state) {
585 if (auth_transaction == 1) {
586 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
589 sta->sae->state = SAE_COMMITTED;
591 if (sae_process_commit(sta->sae) < 0)
592 return WLAN_STATUS_UNSPECIFIED_FAILURE;
595 * In mesh case, both Commit and Confirm can be sent
596 * immediately. In infrastructure BSS, only a single
597 * Authentication frame (Commit) is expected from the AP
598 * here and the second one (Confirm) will be sent once
599 * the STA has sent its second Authentication frame
602 if (hapd->conf->mesh & MESH_ENABLED) {
604 * Send both Commit and Confirm immediately
605 * based on SAE finite state machine
606 * Nothing -> Confirm transition.
608 ret = auth_sae_send_confirm(hapd, sta, bssid);
611 sta->sae->state = SAE_CONFIRMED;
614 * For infrastructure BSS, send only the Commit
615 * message now to get alternating sequence of
616 * Authentication frames between the AP and STA.
617 * Confirm will be sent in
618 * Commited -> Confirmed/Accepted transition
619 * when receiving Confirm from STA.
623 sae_set_retransmit_timer(hapd, sta);
625 hostapd_logger(hapd, sta->addr,
626 HOSTAPD_MODULE_IEEE80211,
628 "SAE confirm before commit");
632 sae_clear_retransmit_timer(hapd, sta);
633 if (auth_transaction == 1) {
634 if (sae_process_commit(sta->sae) < 0)
635 return WLAN_STATUS_UNSPECIFIED_FAILURE;
637 ret = auth_sae_send_confirm(hapd, sta, bssid);
640 sta->sae->state = SAE_CONFIRMED;
642 sae_set_retransmit_timer(hapd, sta);
643 } else if (hapd->conf->mesh & MESH_ENABLED) {
645 * In mesh case, follow SAE finite state machine and
646 * send Commit now, if sync count allows.
648 if (sae_check_big_sync(sta))
649 return WLAN_STATUS_SUCCESS;
652 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
656 sae_set_retransmit_timer(hapd, sta);
659 * For instructure BSS, send the postponed Confirm from
660 * Nothing -> Confirmed transition that was reduced to
661 * Nothing -> Committed above.
663 ret = auth_sae_send_confirm(hapd, sta, bssid);
667 sta->sae->state = SAE_CONFIRMED;
670 * Since this was triggered on Confirm RX, run another
671 * step to get to Accepted without waiting for
674 return sae_sm_step(hapd, sta, bssid, auth_transaction);
678 sae_clear_retransmit_timer(hapd, sta);
679 if (auth_transaction == 1) {
680 if (sae_check_big_sync(sta))
681 return WLAN_STATUS_SUCCESS;
684 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
688 if (sae_process_commit(sta->sae) < 0)
689 return WLAN_STATUS_UNSPECIFIED_FAILURE;
691 ret = auth_sae_send_confirm(hapd, sta, bssid);
695 sae_set_retransmit_timer(hapd, sta);
697 sae_accept_sta(hapd, sta);
701 if (auth_transaction == 1) {
702 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
703 ") doing reauthentication",
705 ap_free_sta(hapd, sta);
706 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
708 if (sae_check_big_sync(sta))
709 return WLAN_STATUS_SUCCESS;
712 ret = auth_sae_send_confirm(hapd, sta, bssid);
713 sae_clear_temp_data(sta->sae);
719 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
721 return WLAN_STATUS_UNSPECIFIED_FAILURE;
723 return WLAN_STATUS_SUCCESS;
727 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
728 const struct ieee80211_mgmt *mgmt, size_t len,
729 u16 auth_transaction, u16 status_code)
731 int resp = WLAN_STATUS_SUCCESS;
732 struct wpabuf *data = NULL;
735 if (auth_transaction != 1 ||
736 status_code != WLAN_STATUS_SUCCESS) {
740 sta->sae = os_zalloc(sizeof(*sta->sae));
745 sta->sae->state = SAE_NOTHING;
749 if (sta->mesh_sae_pmksa_caching) {
750 wpa_printf(MSG_DEBUG,
751 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
752 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
753 sta->mesh_sae_pmksa_caching = 0;
756 if (auth_transaction == 1) {
757 const u8 *token = NULL, *pos, *end;
758 size_t token_len = 0;
759 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
761 "start SAE authentication (RX commit, status=%u)",
764 if ((hapd->conf->mesh & MESH_ENABLED) &&
765 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
767 pos = mgmt->u.auth.variable;
768 end = ((const u8 *) mgmt) + len;
769 if (pos + sizeof(le16) > end) {
770 wpa_printf(MSG_ERROR,
771 "SAE: Too short anti-clogging token request");
772 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
775 resp = sae_group_allowed(sta->sae,
776 hapd->conf->sae_groups,
778 if (resp != WLAN_STATUS_SUCCESS) {
779 wpa_printf(MSG_ERROR,
780 "SAE: Invalid group in anti-clogging token request");
785 wpabuf_free(sta->sae->tmp->anti_clogging_token);
786 sta->sae->tmp->anti_clogging_token =
787 wpabuf_alloc_copy(pos, end - pos);
788 if (sta->sae->tmp->anti_clogging_token == NULL) {
789 wpa_printf(MSG_ERROR,
790 "SAE: Failed to alloc for anti-clogging token");
791 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
796 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
797 * is 76, a new Commit Message shall be constructed
798 * with the Anti-Clogging Token from the received
799 * Authentication frame, and the commit-scalar and
800 * COMMIT-ELEMENT previously sent.
802 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
803 if (resp != WLAN_STATUS_SUCCESS) {
804 wpa_printf(MSG_ERROR,
805 "SAE: Failed to send commit message");
808 sta->sae->state = SAE_COMMITTED;
810 sae_set_retransmit_timer(hapd, sta);
814 if (status_code != WLAN_STATUS_SUCCESS)
817 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
818 ((const u8 *) mgmt) + len -
819 mgmt->u.auth.variable, &token,
820 &token_len, hapd->conf->sae_groups);
821 if (resp == SAE_SILENTLY_DISCARD) {
822 wpa_printf(MSG_DEBUG,
823 "SAE: Drop commit message from " MACSTR " due to reflection attack",
827 if (token && check_sae_token(hapd, sta->addr, token, token_len)
829 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
830 "incorrect token from " MACSTR,
832 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
836 if (resp != WLAN_STATUS_SUCCESS)
839 if (!token && use_sae_anti_clogging(hapd)) {
840 wpa_printf(MSG_DEBUG,
841 "SAE: Request anti-clogging token from "
842 MACSTR, MAC2STR(sta->addr));
843 data = auth_build_token_req(hapd, sta->sae->group,
845 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
846 if (hapd->conf->mesh & MESH_ENABLED)
847 sta->sae->state = SAE_NOTHING;
851 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
852 } else if (auth_transaction == 2) {
853 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
855 "SAE authentication (RX confirm, status=%u)",
857 if (status_code != WLAN_STATUS_SUCCESS)
859 if (sta->sae->state >= SAE_CONFIRMED ||
860 !(hapd->conf->mesh & MESH_ENABLED)) {
861 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
862 ((u8 *) mgmt) + len -
863 mgmt->u.auth.variable) < 0) {
864 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
868 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
870 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
872 "unexpected SAE authentication transaction %u (status=%u)",
873 auth_transaction, status_code);
874 if (status_code != WLAN_STATUS_SUCCESS)
876 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
880 if (resp != WLAN_STATUS_SUCCESS) {
881 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
882 auth_transaction, resp,
883 data ? wpabuf_head(data) : (u8 *) "",
884 data ? wpabuf_len(data) : 0);
888 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
889 status_code != WLAN_STATUS_SUCCESS)) {
890 hostapd_drv_sta_remove(hapd, sta->addr);
891 sta->added_unassoc = 0;
898 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
899 * @hapd: BSS data for the device initiating the authentication
900 * @sta: the peer to which commit authentication frame is sent
902 * This function implements Init event handling (IEEE Std 802.11-2012,
903 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
904 * sta->sae structure should be initialized appropriately via a call to
905 * sae_prepare_commit().
907 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
911 if (!sta->sae || !sta->sae->tmp)
914 if (sta->sae->state != SAE_NOTHING)
917 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
921 sta->sae->state = SAE_COMMITTED;
923 sae_set_retransmit_timer(hapd, sta);
928 #endif /* CONFIG_SAE */
931 static void handle_auth(struct hostapd_data *hapd,
932 const struct ieee80211_mgmt *mgmt, size_t len)
934 u16 auth_alg, auth_transaction, status_code;
935 u16 resp = WLAN_STATUS_SUCCESS;
936 struct sta_info *sta = NULL;
939 const u8 *challenge = NULL;
940 u32 session_timeout, acct_interim_interval;
941 struct vlan_description vlan_id;
942 struct hostapd_sta_wpa_psk_short *psk = NULL;
943 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
944 size_t resp_ies_len = 0;
945 char *identity = NULL;
946 char *radius_cui = NULL;
949 os_memset(&vlan_id, 0, sizeof(vlan_id));
951 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
952 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
953 (unsigned long) len);
957 #ifdef CONFIG_TESTING_OPTIONS
958 if (hapd->iconf->ignore_auth_probability > 0.0 &&
959 drand48() < hapd->iconf->ignore_auth_probability) {
961 "TESTING: ignoring auth frame from " MACSTR,
965 #endif /* CONFIG_TESTING_OPTIONS */
967 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
968 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
969 status_code = le_to_host16(mgmt->u.auth.status_code);
970 fc = le_to_host16(mgmt->frame_control);
971 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
973 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
974 2 + WLAN_AUTH_CHALLENGE_LEN &&
975 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
976 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
977 challenge = &mgmt->u.auth.variable[2];
979 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
980 "auth_transaction=%d status_code=%d wep=%d%s "
982 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
983 status_code, !!(fc & WLAN_FC_ISWEP),
984 challenge ? " challenge" : "",
985 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
988 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
990 "Unsupported authentication algorithm (%d)",
992 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
995 #endif /* CONFIG_NO_RC4 */
997 if (hapd->tkip_countermeasures) {
998 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1002 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
1003 auth_alg == WLAN_AUTH_OPEN) ||
1004 #ifdef CONFIG_IEEE80211R
1005 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
1006 auth_alg == WLAN_AUTH_FT) ||
1007 #endif /* CONFIG_IEEE80211R */
1009 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1010 auth_alg == WLAN_AUTH_SAE) ||
1011 #endif /* CONFIG_SAE */
1012 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1013 auth_alg == WLAN_AUTH_SHARED_KEY))) {
1014 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1016 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1020 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
1021 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
1022 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1024 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1028 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
1029 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1031 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1035 if (hapd->conf->no_auth_if_seen_on) {
1036 struct hostapd_data *other;
1038 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1039 hapd->conf->no_auth_if_seen_on);
1043 u8 op_class, channel, phytype;
1045 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1046 MACSTR " since STA has been seen on %s",
1047 hapd->conf->iface, MAC2STR(mgmt->sa),
1048 hapd->conf->no_auth_if_seen_on);
1050 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1052 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1054 os_memcpy(pos, other->own_addr, ETH_ALEN);
1056 info = 0; /* TODO: BSSID Information */
1057 WPA_PUT_LE32(pos, info);
1059 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1060 phytype = 8; /* dmg */
1061 else if (other->iconf->ieee80211ac)
1062 phytype = 9; /* vht */
1063 else if (other->iconf->ieee80211n)
1064 phytype = 7; /* ht */
1065 else if (other->iconf->hw_mode ==
1066 HOSTAPD_MODE_IEEE80211A)
1067 phytype = 4; /* ofdm */
1068 else if (other->iconf->hw_mode ==
1069 HOSTAPD_MODE_IEEE80211G)
1070 phytype = 6; /* erp */
1072 phytype = 5; /* hrdsss */
1073 if (ieee80211_freq_to_channel_ext(
1074 hostapd_hw_get_freq(other,
1075 other->iconf->channel),
1076 other->iconf->secondary_channel,
1077 other->iconf->ieee80211ac,
1078 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1080 channel = other->iconf->channel;
1085 resp_ies_len = pos - &resp_ies[0];
1090 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1092 &acct_interim_interval, &vlan_id,
1093 &psk, &identity, &radius_cui);
1095 if (res == HOSTAPD_ACL_REJECT) {
1096 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1098 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1101 if (res == HOSTAPD_ACL_PENDING) {
1102 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1103 " waiting for an external authentication",
1105 /* Authentication code will re-send the authentication frame
1106 * after it has received (and cached) information from the
1107 * external source. */
1111 sta = ap_get_sta(hapd, mgmt->sa);
1113 if ((fc & WLAN_FC_RETRY) &&
1114 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1115 sta->last_seq_ctrl == seq_ctrl &&
1116 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1117 hostapd_logger(hapd, sta->addr,
1118 HOSTAPD_MODULE_IEEE80211,
1119 HOSTAPD_LEVEL_DEBUG,
1120 "Drop repeated authentication frame seq_ctrl=0x%x",
1125 if ((hapd->conf->mesh & MESH_ENABLED) &&
1126 sta->plink_state == PLINK_BLOCKED) {
1127 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1128 " is blocked - drop Authentication frame",
1132 #endif /* CONFIG_MESH */
1135 if (hapd->conf->mesh & MESH_ENABLED) {
1136 /* if the mesh peer is not available, we don't do auth.
1138 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1139 " not yet known - drop Authentication frame",
1142 * Save a copy of the frame so that it can be processed
1143 * if a new peer entry is added shortly after this.
1145 wpabuf_free(hapd->mesh_pending_auth);
1146 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1147 os_get_reltime(&hapd->mesh_pending_auth_time);
1150 #endif /* CONFIG_MESH */
1152 sta = ap_sta_add(hapd, mgmt->sa);
1154 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1158 sta->last_seq_ctrl = seq_ctrl;
1159 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1161 if (vlan_id.notempty &&
1162 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1163 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1165 "Invalid VLAN %d%s received from RADIUS server",
1167 vlan_id.tagged[0] ? "+" : "");
1168 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1171 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1172 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1176 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1177 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1179 hostapd_free_psk_list(sta->psk);
1180 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1187 sta->identity = identity;
1189 sta->radius_cui = radius_cui;
1192 sta->flags &= ~WLAN_STA_PREAUTH;
1193 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1195 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1196 sta->acct_interim_interval = acct_interim_interval;
1197 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1198 ap_sta_session_timeout(hapd, sta, session_timeout);
1200 ap_sta_no_session_timeout(hapd, sta);
1203 * If the driver supports full AP client state, add a station to the
1204 * driver before sending authentication reply to make sure the driver
1205 * has resources, and not to go through the entire authentication and
1206 * association handshake, and fail it at the end.
1208 * If this is not the first transaction, in a multi-step authentication
1209 * algorithm, the station already exists in the driver
1210 * (sta->added_unassoc = 1) so skip it.
1212 * In mesh mode, the station was already added to the driver when the
1213 * NEW_PEER_CANDIDATE event is received.
1215 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1216 !(hapd->conf->mesh & MESH_ENABLED) &&
1217 !(sta->added_unassoc)) {
1219 * If a station that is already associated to the AP, is trying
1220 * to authenticate again, remove the STA entry, in order to make
1221 * sure the STA PS state gets cleared and configuration gets
1222 * updated. To handle this, station's added_unassoc flag is
1223 * cleared once the station has completed association.
1225 hostapd_drv_sta_remove(hapd, sta->addr);
1226 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1227 WLAN_STA_AUTHORIZED);
1229 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1230 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
1231 hostapd_logger(hapd, sta->addr,
1232 HOSTAPD_MODULE_IEEE80211,
1233 HOSTAPD_LEVEL_NOTICE,
1234 "Could not add STA to kernel driver");
1235 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1239 sta->added_unassoc = 1;
1243 case WLAN_AUTH_OPEN:
1244 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1245 HOSTAPD_LEVEL_DEBUG,
1246 "authentication OK (open system)");
1247 sta->flags |= WLAN_STA_AUTH;
1248 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1249 sta->auth_alg = WLAN_AUTH_OPEN;
1250 mlme_authenticate_indication(hapd, sta);
1252 #ifndef CONFIG_NO_RC4
1253 case WLAN_AUTH_SHARED_KEY:
1254 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1255 fc & WLAN_FC_ISWEP);
1256 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1257 mlme_authenticate_indication(hapd, sta);
1258 if (sta->challenge && auth_transaction == 1) {
1259 resp_ies[0] = WLAN_EID_CHALLENGE;
1260 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1261 os_memcpy(resp_ies + 2, sta->challenge,
1262 WLAN_AUTH_CHALLENGE_LEN);
1263 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1266 #endif /* CONFIG_NO_RC4 */
1267 #ifdef CONFIG_IEEE80211R
1269 sta->auth_alg = WLAN_AUTH_FT;
1270 if (sta->wpa_sm == NULL)
1271 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1273 if (sta->wpa_sm == NULL) {
1274 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1276 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1279 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1280 auth_transaction, mgmt->u.auth.variable,
1281 len - IEEE80211_HDRLEN -
1282 sizeof(mgmt->u.auth),
1283 handle_auth_ft_finish, hapd);
1284 /* handle_auth_ft_finish() callback will complete auth. */
1286 #endif /* CONFIG_IEEE80211R */
1290 if (status_code == WLAN_STATUS_SUCCESS &&
1291 hapd->conf->mesh & MESH_ENABLED) {
1292 if (sta->wpa_sm == NULL)
1294 wpa_auth_sta_init(hapd->wpa_auth,
1296 if (sta->wpa_sm == NULL) {
1297 wpa_printf(MSG_DEBUG,
1298 "SAE: Failed to initialize WPA state machine");
1299 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1303 #endif /* CONFIG_MESH */
1304 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1307 #endif /* CONFIG_SAE */
1312 os_free(radius_cui);
1313 hostapd_free_psk_list(psk);
1315 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1316 auth_transaction + 1, resp, resp_ies,
1319 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1320 reply_res != WLAN_STATUS_SUCCESS)) {
1321 hostapd_drv_sta_remove(hapd, sta->addr);
1322 sta->added_unassoc = 0;
1327 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1331 /* get a unique AID */
1333 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1337 for (i = 0; i < AID_WORDS; i++) {
1338 if (hapd->sta_aid[i] == (u32) -1)
1340 for (j = 0; j < 32; j++) {
1341 if (!(hapd->sta_aid[i] & BIT(j)))
1349 aid = i * 32 + j + 1;
1354 hapd->sta_aid[i] |= BIT(j);
1355 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1360 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1361 const u8 *ssid_ie, size_t ssid_ie_len)
1363 if (ssid_ie == NULL)
1364 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1366 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1367 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1368 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1370 "Station tried to associate with unknown SSID "
1371 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1372 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1375 return WLAN_STATUS_SUCCESS;
1379 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1380 const u8 *wmm_ie, size_t wmm_ie_len)
1382 sta->flags &= ~WLAN_STA_WMM;
1384 if (wmm_ie && hapd->conf->wmm_enabled) {
1385 struct wmm_information_element *wmm;
1387 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1388 hostapd_logger(hapd, sta->addr,
1390 HOSTAPD_LEVEL_DEBUG,
1391 "invalid WMM element in association "
1393 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1396 sta->flags |= WLAN_STA_WMM;
1397 wmm = (struct wmm_information_element *) wmm_ie;
1398 sta->qosinfo = wmm->qos_info;
1400 return WLAN_STATUS_SUCCESS;
1404 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1405 struct ieee802_11_elems *elems)
1407 if (!elems->supp_rates) {
1408 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1409 HOSTAPD_LEVEL_DEBUG,
1410 "No supported rates element in AssocReq");
1411 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1414 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1415 sizeof(sta->supported_rates)) {
1416 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1417 HOSTAPD_LEVEL_DEBUG,
1418 "Invalid supported rates element length %d+%d",
1419 elems->supp_rates_len,
1420 elems->ext_supp_rates_len);
1421 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1424 sta->supported_rates_len = merge_byte_arrays(
1425 sta->supported_rates, sizeof(sta->supported_rates),
1426 elems->supp_rates, elems->supp_rates_len,
1427 elems->ext_supp_rates, elems->ext_supp_rates_len);
1429 return WLAN_STATUS_SUCCESS;
1433 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1434 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1436 #ifdef CONFIG_INTERWORKING
1437 /* check for QoS Map support */
1438 if (ext_capab_ie_len >= 5) {
1439 if (ext_capab_ie[4] & 0x01)
1440 sta->qos_map_enabled = 1;
1442 #endif /* CONFIG_INTERWORKING */
1444 if (ext_capab_ie_len > 0)
1445 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1447 return WLAN_STATUS_SUCCESS;
1451 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1452 const u8 *ies, size_t ies_len, int reassoc)
1454 struct ieee802_11_elems elems;
1458 const u8 *p2p_dev_addr = NULL;
1460 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1461 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1462 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1463 "association request");
1464 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1467 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1468 if (resp != WLAN_STATUS_SUCCESS)
1470 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1471 if (resp != WLAN_STATUS_SUCCESS)
1473 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1474 if (resp != WLAN_STATUS_SUCCESS)
1476 resp = copy_supp_rates(hapd, sta, &elems);
1477 if (resp != WLAN_STATUS_SUCCESS)
1479 #ifdef CONFIG_IEEE80211N
1480 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1481 if (resp != WLAN_STATUS_SUCCESS)
1483 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1484 !(sta->flags & WLAN_STA_HT)) {
1485 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1486 HOSTAPD_LEVEL_INFO, "Station does not support "
1487 "mandatory HT PHY - reject association");
1488 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1490 #endif /* CONFIG_IEEE80211N */
1492 #ifdef CONFIG_IEEE80211AC
1493 if (hapd->iconf->ieee80211ac) {
1494 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1495 if (resp != WLAN_STATUS_SUCCESS)
1498 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1499 if (resp != WLAN_STATUS_SUCCESS)
1503 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1504 !(sta->flags & WLAN_STA_VHT)) {
1505 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1506 HOSTAPD_LEVEL_INFO, "Station does not support "
1507 "mandatory VHT PHY - reject association");
1508 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1511 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1512 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1513 elems.vendor_vht_len);
1514 if (resp != WLAN_STATUS_SUCCESS)
1517 #endif /* CONFIG_IEEE80211AC */
1521 wpabuf_free(sta->p2p_ie);
1522 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1523 P2P_IE_VENDOR_TYPE);
1525 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1527 wpabuf_free(sta->p2p_ie);
1530 #endif /* CONFIG_P2P */
1532 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1533 wpa_ie = elems.rsn_ie;
1534 wpa_ie_len = elems.rsn_ie_len;
1535 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1537 wpa_ie = elems.wpa_ie;
1538 wpa_ie_len = elems.wpa_ie_len;
1545 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1546 if (hapd->conf->wps_state && elems.wps_ie) {
1547 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1548 "Request - assume WPS is used");
1549 sta->flags |= WLAN_STA_WPS;
1550 wpabuf_free(sta->wps_ie);
1551 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1552 WPS_IE_VENDOR_TYPE);
1553 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1554 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1555 sta->flags |= WLAN_STA_WPS2;
1559 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1560 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1561 "(Re)Association Request - reject");
1562 return WLAN_STATUS_INVALID_IE;
1564 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1565 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1566 "(Re)Association Request - possible WPS use");
1567 sta->flags |= WLAN_STA_MAYBE_WPS;
1569 #endif /* CONFIG_WPS */
1570 if (hapd->conf->wpa && wpa_ie == NULL) {
1571 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1573 "No WPA/RSN IE in association request");
1574 return WLAN_STATUS_INVALID_IE;
1577 if (hapd->conf->wpa && wpa_ie) {
1581 if (sta->wpa_sm == NULL)
1582 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1585 if (sta->wpa_sm == NULL) {
1586 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1588 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1590 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1592 elems.mdie, elems.mdie_len);
1593 if (res == WPA_INVALID_GROUP)
1594 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1595 else if (res == WPA_INVALID_PAIRWISE)
1596 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1597 else if (res == WPA_INVALID_AKMP)
1598 resp = WLAN_STATUS_AKMP_NOT_VALID;
1599 else if (res == WPA_ALLOC_FAIL)
1600 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1601 #ifdef CONFIG_IEEE80211W
1602 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1603 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1604 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1605 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1606 #endif /* CONFIG_IEEE80211W */
1607 else if (res == WPA_INVALID_MDIE)
1608 resp = WLAN_STATUS_INVALID_MDIE;
1609 else if (res != WPA_IE_OK)
1610 resp = WLAN_STATUS_INVALID_IE;
1611 if (resp != WLAN_STATUS_SUCCESS)
1613 #ifdef CONFIG_IEEE80211W
1614 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1615 sta->sa_query_count > 0)
1616 ap_check_sa_query_timeout(hapd, sta);
1617 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1618 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1620 * STA has already been associated with MFP and SA
1621 * Query timeout has not been reached. Reject the
1622 * association attempt temporarily and start SA Query,
1623 * if one is not pending.
1626 if (sta->sa_query_count == 0)
1627 ap_sta_start_sa_query(hapd, sta);
1629 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1632 if (wpa_auth_uses_mfp(sta->wpa_sm))
1633 sta->flags |= WLAN_STA_MFP;
1635 sta->flags &= ~WLAN_STA_MFP;
1636 #endif /* CONFIG_IEEE80211W */
1638 #ifdef CONFIG_IEEE80211R
1639 if (sta->auth_alg == WLAN_AUTH_FT) {
1641 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1642 "to use association (not "
1643 "re-association) with FT auth_alg",
1644 MAC2STR(sta->addr));
1645 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1648 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1650 if (resp != WLAN_STATUS_SUCCESS)
1653 #endif /* CONFIG_IEEE80211R */
1656 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1657 sta->auth_alg == WLAN_AUTH_OPEN) {
1658 struct rsn_pmksa_cache_entry *sa;
1659 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1660 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1661 wpa_printf(MSG_DEBUG,
1662 "SAE: No PMKSA cache entry found for "
1663 MACSTR, MAC2STR(sta->addr));
1664 return WLAN_STATUS_INVALID_PMKID;
1666 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1667 " using PMKSA caching", MAC2STR(sta->addr));
1668 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1669 sta->auth_alg != WLAN_AUTH_SAE &&
1670 !(sta->auth_alg == WLAN_AUTH_FT &&
1671 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1672 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1673 "SAE AKM after non-SAE auth_alg %u",
1674 MAC2STR(sta->addr), sta->auth_alg);
1675 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1677 #endif /* CONFIG_SAE */
1679 #ifdef CONFIG_IEEE80211N
1680 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1681 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1682 hostapd_logger(hapd, sta->addr,
1683 HOSTAPD_MODULE_IEEE80211,
1685 "Station tried to use TKIP with HT "
1687 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1689 #endif /* CONFIG_IEEE80211N */
1691 } else if (hapd->conf->osen) {
1692 if (elems.osen == NULL) {
1694 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1696 "No HS 2.0 OSEN element in association request");
1697 return WLAN_STATUS_INVALID_IE;
1700 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1701 if (sta->wpa_sm == NULL)
1702 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1704 if (sta->wpa_sm == NULL) {
1705 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1707 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1709 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1710 elems.osen - 2, elems.osen_len + 2) < 0)
1711 return WLAN_STATUS_INVALID_IE;
1712 #endif /* CONFIG_HS20 */
1714 wpa_auth_sta_no_wpa(sta->wpa_sm);
1717 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1718 #endif /* CONFIG_P2P */
1721 wpabuf_free(sta->hs20_ie);
1722 if (elems.hs20 && elems.hs20_len > 4) {
1723 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1724 elems.hs20_len - 4);
1726 sta->hs20_ie = NULL;
1727 #endif /* CONFIG_HS20 */
1730 wpabuf_free(sta->mb_ies);
1731 if (hapd->iface->fst)
1732 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1735 #endif /* CONFIG_FST */
1738 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1740 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1741 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1742 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1743 wpa_printf(MSG_INFO,
1744 "MBO: Reject WPA2 association without PMF");
1745 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1747 #endif /* CONFIG_MBO */
1749 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
1750 elems.supp_op_classes_len);
1752 return WLAN_STATUS_SUCCESS;
1756 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1760 struct ieee80211_mgmt reply;
1762 os_memset(&reply, 0, sizeof(reply));
1763 reply.frame_control =
1764 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1765 os_memcpy(reply.da, addr, ETH_ALEN);
1766 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1767 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1769 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1770 reply.u.deauth.reason_code = host_to_le16(reason_code);
1772 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1773 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1778 static int add_associated_sta(struct hostapd_data *hapd,
1779 struct sta_info *sta)
1781 struct ieee80211_ht_capabilities ht_cap;
1782 struct ieee80211_vht_capabilities vht_cap;
1785 * Remove the STA entry to ensure the STA PS state gets cleared and
1786 * configuration gets updated. This is relevant for cases, such as
1787 * FT-over-the-DS, where a station re-associates back to the same AP but
1788 * skips the authentication flow, or if working with a driver that
1789 * does not support full AP client state.
1791 if (!sta->added_unassoc)
1792 hostapd_drv_sta_remove(hapd, sta->addr);
1794 #ifdef CONFIG_IEEE80211N
1795 if (sta->flags & WLAN_STA_HT)
1796 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1797 #endif /* CONFIG_IEEE80211N */
1798 #ifdef CONFIG_IEEE80211AC
1799 if (sta->flags & WLAN_STA_VHT)
1800 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1801 #endif /* CONFIG_IEEE80211AC */
1804 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1805 * will be set when the ACK frame for the (Re)Association Response frame
1806 * is processed (TX status driver event).
1808 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1809 sta->supported_rates, sta->supported_rates_len,
1810 sta->listen_interval,
1811 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1812 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1813 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1814 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
1815 sta->added_unassoc)) {
1816 hostapd_logger(hapd, sta->addr,
1817 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1818 "Could not %s STA to kernel driver",
1819 sta->added_unassoc ? "set" : "add");
1821 if (sta->added_unassoc) {
1822 hostapd_drv_sta_remove(hapd, sta->addr);
1823 sta->added_unassoc = 0;
1829 sta->added_unassoc = 0;
1835 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1836 u16 status_code, int reassoc, const u8 *ies,
1840 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1841 struct ieee80211_mgmt *reply;
1844 os_memset(buf, 0, sizeof(buf));
1845 reply = (struct ieee80211_mgmt *) buf;
1846 reply->frame_control =
1847 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1848 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1849 WLAN_FC_STYPE_ASSOC_RESP));
1850 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1851 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1852 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1854 send_len = IEEE80211_HDRLEN;
1855 send_len += sizeof(reply->u.assoc_resp);
1856 reply->u.assoc_resp.capab_info =
1857 host_to_le16(hostapd_own_capab_info(hapd));
1858 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1859 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1860 /* Supported rates */
1861 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1862 /* Extended supported rates */
1863 p = hostapd_eid_ext_supp_rates(hapd, p);
1865 #ifdef CONFIG_IEEE80211R
1866 if (status_code == WLAN_STATUS_SUCCESS) {
1867 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1868 * Transition Information, RSN, [RIC Response] */
1869 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1870 buf + sizeof(buf) - p,
1871 sta->auth_alg, ies, ies_len);
1873 #endif /* CONFIG_IEEE80211R */
1875 #ifdef CONFIG_IEEE80211W
1876 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1877 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1878 #endif /* CONFIG_IEEE80211W */
1880 #ifdef CONFIG_IEEE80211N
1881 p = hostapd_eid_ht_capabilities(hapd, p);
1882 p = hostapd_eid_ht_operation(hapd, p);
1883 #endif /* CONFIG_IEEE80211N */
1885 #ifdef CONFIG_IEEE80211AC
1886 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1887 p = hostapd_eid_vht_capabilities(hapd, p);
1888 p = hostapd_eid_vht_operation(hapd, p);
1890 #endif /* CONFIG_IEEE80211AC */
1892 p = hostapd_eid_ext_capab(hapd, p);
1893 p = hostapd_eid_bss_max_idle_period(hapd, p);
1894 if (sta->qos_map_enabled)
1895 p = hostapd_eid_qos_map_set(hapd, p);
1898 if (hapd->iface->fst_ies) {
1899 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1900 wpabuf_len(hapd->iface->fst_ies));
1901 p += wpabuf_len(hapd->iface->fst_ies);
1903 #endif /* CONFIG_FST */
1905 #ifdef CONFIG_IEEE80211AC
1906 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1907 p = hostapd_eid_vendor_vht(hapd, p);
1908 #endif /* CONFIG_IEEE80211AC */
1910 if (sta->flags & WLAN_STA_WMM)
1911 p = hostapd_eid_wmm(hapd, p);
1914 if ((sta->flags & WLAN_STA_WPS) ||
1915 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1916 struct wpabuf *wps = wps_build_assoc_resp_ie();
1918 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1919 p += wpabuf_len(wps);
1923 #endif /* CONFIG_WPS */
1926 if (sta->p2p_ie && hapd->p2p_group) {
1927 struct wpabuf *p2p_resp_ie;
1928 enum p2p_status_code status;
1929 switch (status_code) {
1930 case WLAN_STATUS_SUCCESS:
1931 status = P2P_SC_SUCCESS;
1933 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1934 status = P2P_SC_FAIL_LIMIT_REACHED;
1937 status = P2P_SC_FAIL_INVALID_PARAMS;
1940 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1942 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1943 wpabuf_len(p2p_resp_ie));
1944 p += wpabuf_len(p2p_resp_ie);
1945 wpabuf_free(p2p_resp_ie);
1948 #endif /* CONFIG_P2P */
1950 #ifdef CONFIG_P2P_MANAGER
1951 if (hapd->conf->p2p & P2P_MANAGE)
1952 p = hostapd_eid_p2p_manage(hapd, p);
1953 #endif /* CONFIG_P2P_MANAGER */
1955 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1957 send_len += p - reply->u.assoc_resp.variable;
1959 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
1960 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1962 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1965 return WLAN_STATUS_SUCCESS;
1969 static void handle_assoc(struct hostapd_data *hapd,
1970 const struct ieee80211_mgmt *mgmt, size_t len,
1973 u16 capab_info, listen_interval, seq_ctrl, fc;
1974 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
1977 struct sta_info *sta;
1979 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1980 sizeof(mgmt->u.assoc_req))) {
1981 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1982 reassoc, (unsigned long) len);
1986 #ifdef CONFIG_TESTING_OPTIONS
1988 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1989 drand48() < hapd->iconf->ignore_reassoc_probability) {
1990 wpa_printf(MSG_INFO,
1991 "TESTING: ignoring reassoc request from "
1992 MACSTR, MAC2STR(mgmt->sa));
1996 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1997 drand48() < hapd->iconf->ignore_assoc_probability) {
1998 wpa_printf(MSG_INFO,
1999 "TESTING: ignoring assoc request from "
2000 MACSTR, MAC2STR(mgmt->sa));
2004 #endif /* CONFIG_TESTING_OPTIONS */
2006 fc = le_to_host16(mgmt->frame_control);
2007 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2010 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
2011 listen_interval = le_to_host16(
2012 mgmt->u.reassoc_req.listen_interval);
2013 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
2014 " capab_info=0x%02x listen_interval=%d current_ap="
2015 MACSTR " seq_ctrl=0x%x%s",
2016 MAC2STR(mgmt->sa), capab_info, listen_interval,
2017 MAC2STR(mgmt->u.reassoc_req.current_ap),
2018 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2019 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
2020 pos = mgmt->u.reassoc_req.variable;
2022 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2023 listen_interval = le_to_host16(
2024 mgmt->u.assoc_req.listen_interval);
2025 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
2026 " capab_info=0x%02x listen_interval=%d "
2028 MAC2STR(mgmt->sa), capab_info, listen_interval,
2029 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
2030 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2031 pos = mgmt->u.assoc_req.variable;
2034 sta = ap_get_sta(hapd, mgmt->sa);
2035 #ifdef CONFIG_IEEE80211R
2036 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2037 (sta->flags & WLAN_STA_AUTH) == 0) {
2038 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2039 "prior to authentication since it is using "
2040 "over-the-DS FT", MAC2STR(mgmt->sa));
2043 * Mark station as authenticated, to avoid adding station
2044 * entry in the driver as associated and not authenticated
2046 sta->flags |= WLAN_STA_AUTH;
2048 #endif /* CONFIG_IEEE80211R */
2049 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2050 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2051 HOSTAPD_LEVEL_INFO, "Station tried to "
2052 "associate before authentication "
2053 "(aid=%d flags=0x%x)",
2054 sta ? sta->aid : -1,
2055 sta ? sta->flags : 0);
2056 send_deauth(hapd, mgmt->sa,
2057 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2061 if ((fc & WLAN_FC_RETRY) &&
2062 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2063 sta->last_seq_ctrl == seq_ctrl &&
2064 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2065 WLAN_FC_STYPE_ASSOC_REQ) {
2066 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2067 HOSTAPD_LEVEL_DEBUG,
2068 "Drop repeated association frame seq_ctrl=0x%x",
2072 sta->last_seq_ctrl = seq_ctrl;
2073 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2074 WLAN_FC_STYPE_ASSOC_REQ;
2076 if (hapd->tkip_countermeasures) {
2077 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2081 if (listen_interval > hapd->conf->max_listen_interval) {
2082 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2083 HOSTAPD_LEVEL_DEBUG,
2084 "Too large Listen Interval (%d)",
2086 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2091 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2092 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2095 #endif /* CONFIG_MBO */
2097 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2099 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2100 if (resp != WLAN_STATUS_SUCCESS)
2103 if (hostapd_get_aid(hapd, sta) < 0) {
2104 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2105 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2106 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2110 sta->capability = capab_info;
2111 sta->listen_interval = listen_interval;
2113 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2114 sta->flags |= WLAN_STA_NONERP;
2115 for (i = 0; i < sta->supported_rates_len; i++) {
2116 if ((sta->supported_rates[i] & 0x7f) > 22) {
2117 sta->flags &= ~WLAN_STA_NONERP;
2121 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2122 sta->nonerp_set = 1;
2123 hapd->iface->num_sta_non_erp++;
2124 if (hapd->iface->num_sta_non_erp == 1)
2125 ieee802_11_set_beacons(hapd->iface);
2128 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2129 !sta->no_short_slot_time_set) {
2130 sta->no_short_slot_time_set = 1;
2131 hapd->iface->num_sta_no_short_slot_time++;
2132 if (hapd->iface->current_mode->mode ==
2133 HOSTAPD_MODE_IEEE80211G &&
2134 hapd->iface->num_sta_no_short_slot_time == 1)
2135 ieee802_11_set_beacons(hapd->iface);
2138 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2139 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2141 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2143 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2144 !sta->no_short_preamble_set) {
2145 sta->no_short_preamble_set = 1;
2146 hapd->iface->num_sta_no_short_preamble++;
2147 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2148 && hapd->iface->num_sta_no_short_preamble == 1)
2149 ieee802_11_set_beacons(hapd->iface);
2152 #ifdef CONFIG_IEEE80211N
2153 update_ht_state(hapd, sta);
2154 #endif /* CONFIG_IEEE80211N */
2156 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2157 HOSTAPD_LEVEL_DEBUG,
2158 "association OK (aid %d)", sta->aid);
2159 /* Station will be marked associated, after it acknowledges AssocResp
2161 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2163 #ifdef CONFIG_IEEE80211W
2164 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2165 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2166 "SA Query procedure", reassoc ? "re" : "");
2167 /* TODO: Send a protected Disassociate frame to the STA using
2168 * the old key and Reason Code "Previous Authentication no
2169 * longer valid". Make sure this is only sent protected since
2170 * unprotected frame would be received by the STA that is now
2171 * trying to associate.
2174 #endif /* CONFIG_IEEE80211W */
2176 /* Make sure that the previously registered inactivity timer will not
2177 * remove the STA immediately. */
2178 sta->timeout_next = STA_NULLFUNC;
2182 * In case of a successful response, add the station to the driver.
2183 * Otherwise, the kernel may ignore Data frames before we process the
2184 * ACK frame (TX status). In case of a failure, this station will be
2187 * Note that this is not compliant with the IEEE 802.11 standard that
2188 * states that a non-AP station should transition into the
2189 * authenticated/associated state only after the station acknowledges
2190 * the (Re)Association Response frame. However, still do this as:
2192 * 1. In case the station does not acknowledge the (Re)Association
2193 * Response frame, it will be removed.
2194 * 2. Data frames will be dropped in the kernel until the station is
2195 * set into authorized state, and there are no significant known
2196 * issues with processing other non-Data Class 3 frames during this
2199 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2200 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2202 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2205 * Remove the station in case tranmission of a success response fails
2206 * (the STA was added associated to the driver) or if the station was
2207 * previously added unassociated.
2209 if ((reply_res != WLAN_STATUS_SUCCESS &&
2210 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2211 hostapd_drv_sta_remove(hapd, sta->addr);
2212 sta->added_unassoc = 0;
2217 static void handle_disassoc(struct hostapd_data *hapd,
2218 const struct ieee80211_mgmt *mgmt, size_t len)
2220 struct sta_info *sta;
2222 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2223 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2224 (unsigned long) len);
2228 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2230 le_to_host16(mgmt->u.disassoc.reason_code));
2232 sta = ap_get_sta(hapd, mgmt->sa);
2234 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2239 ap_sta_set_authorized(hapd, sta, 0);
2240 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2241 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2242 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2243 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2244 HOSTAPD_LEVEL_INFO, "disassociated");
2245 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2246 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2247 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2249 accounting_sta_stop(hapd, sta);
2250 ieee802_1x_free_station(hapd, sta);
2252 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2253 ap_sta_ip6addr_del(hapd, sta);
2254 hostapd_drv_sta_remove(hapd, sta->addr);
2255 sta->added_unassoc = 0;
2257 if (sta->timeout_next == STA_NULLFUNC ||
2258 sta->timeout_next == STA_DISASSOC) {
2259 sta->timeout_next = STA_DEAUTH;
2260 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2261 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2265 mlme_disassociate_indication(
2266 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2270 static void handle_deauth(struct hostapd_data *hapd,
2271 const struct ieee80211_mgmt *mgmt, size_t len)
2273 struct sta_info *sta;
2275 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2276 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2277 "payload (len=%lu)", (unsigned long) len);
2281 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2283 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2285 sta = ap_get_sta(hapd, mgmt->sa);
2287 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2288 "to deauthenticate, but it is not authenticated",
2293 ap_sta_set_authorized(hapd, sta, 0);
2294 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2295 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2296 WLAN_STA_ASSOC_REQ_OK);
2297 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2298 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2299 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2300 mlme_deauthenticate_indication(
2301 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2302 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2303 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2304 ap_free_sta(hapd, sta);
2308 static void handle_beacon(struct hostapd_data *hapd,
2309 const struct ieee80211_mgmt *mgmt, size_t len,
2310 struct hostapd_frame_info *fi)
2312 struct ieee802_11_elems elems;
2314 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2315 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2316 (unsigned long) len);
2320 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2321 len - (IEEE80211_HDRLEN +
2322 sizeof(mgmt->u.beacon)), &elems,
2325 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2329 #ifdef CONFIG_IEEE80211W
2331 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2332 const struct ieee80211_mgmt *mgmt,
2337 end = mgmt->u.action.u.sa_query_resp.trans_id +
2338 WLAN_SA_QUERY_TR_ID_LEN;
2339 if (((u8 *) mgmt) + len < end) {
2340 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2341 "frame (len=%lu)", (unsigned long) len);
2345 ieee802_11_sa_query_action(hapd, mgmt->sa,
2346 mgmt->u.action.u.sa_query_resp.action,
2347 mgmt->u.action.u.sa_query_resp.trans_id);
2352 static int robust_action_frame(u8 category)
2354 return category != WLAN_ACTION_PUBLIC &&
2355 category != WLAN_ACTION_HT;
2357 #endif /* CONFIG_IEEE80211W */
2360 static int handle_action(struct hostapd_data *hapd,
2361 const struct ieee80211_mgmt *mgmt, size_t len)
2363 struct sta_info *sta;
2364 sta = ap_get_sta(hapd, mgmt->sa);
2366 if (len < IEEE80211_HDRLEN + 1) {
2367 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2368 HOSTAPD_LEVEL_DEBUG,
2369 "handle_action - too short payload (len=%lu)",
2370 (unsigned long) len);
2374 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2375 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2376 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2377 "frame (category=%u) from unassociated STA " MACSTR,
2378 MAC2STR(mgmt->sa), mgmt->u.action.category);
2382 #ifdef CONFIG_IEEE80211W
2383 if (sta && (sta->flags & WLAN_STA_MFP) &&
2384 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2385 robust_action_frame(mgmt->u.action.category)) {
2386 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2387 HOSTAPD_LEVEL_DEBUG,
2388 "Dropped unprotected Robust Action frame from "
2392 #endif /* CONFIG_IEEE80211W */
2395 u16 fc = le_to_host16(mgmt->frame_control);
2396 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2398 if ((fc & WLAN_FC_RETRY) &&
2399 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2400 sta->last_seq_ctrl == seq_ctrl &&
2401 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2402 hostapd_logger(hapd, sta->addr,
2403 HOSTAPD_MODULE_IEEE80211,
2404 HOSTAPD_LEVEL_DEBUG,
2405 "Drop repeated action frame seq_ctrl=0x%x",
2410 sta->last_seq_ctrl = seq_ctrl;
2411 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2414 switch (mgmt->u.action.category) {
2415 #ifdef CONFIG_IEEE80211R
2416 case WLAN_ACTION_FT:
2418 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2419 len - IEEE80211_HDRLEN))
2422 #endif /* CONFIG_IEEE80211R */
2423 case WLAN_ACTION_WMM:
2424 hostapd_wmm_action(hapd, mgmt, len);
2426 #ifdef CONFIG_IEEE80211W
2427 case WLAN_ACTION_SA_QUERY:
2428 return hostapd_sa_query_action(hapd, mgmt, len);
2429 #endif /* CONFIG_IEEE80211W */
2431 case WLAN_ACTION_WNM:
2432 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2434 #endif /* CONFIG_WNM */
2436 case WLAN_ACTION_FST:
2437 if (hapd->iface->fst)
2438 fst_rx_action(hapd->iface->fst, mgmt, len);
2440 wpa_printf(MSG_DEBUG,
2441 "FST: Ignore FST Action frame - no FST attached");
2443 #endif /* CONFIG_FST */
2444 case WLAN_ACTION_PUBLIC:
2445 case WLAN_ACTION_PROTECTED_DUAL:
2446 #ifdef CONFIG_IEEE80211N
2447 if (len >= IEEE80211_HDRLEN + 2 &&
2448 mgmt->u.action.u.public_action.action ==
2449 WLAN_PA_20_40_BSS_COEX) {
2450 wpa_printf(MSG_DEBUG,
2451 "HT20/40 coex mgmt frame received from STA "
2452 MACSTR, MAC2STR(mgmt->sa));
2453 hostapd_2040_coex_action(hapd, mgmt, len);
2455 #endif /* CONFIG_IEEE80211N */
2456 if (hapd->public_action_cb) {
2457 hapd->public_action_cb(hapd->public_action_cb_ctx,
2461 if (hapd->public_action_cb2) {
2462 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2466 if (hapd->public_action_cb || hapd->public_action_cb2)
2469 case WLAN_ACTION_VENDOR_SPECIFIC:
2470 if (hapd->vendor_action_cb) {
2471 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2473 hapd->iface->freq) == 0)
2477 case WLAN_ACTION_RADIO_MEASUREMENT:
2478 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
2482 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2483 HOSTAPD_LEVEL_DEBUG,
2484 "handle_action - unknown action category %d or invalid "
2486 mgmt->u.action.category);
2487 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2488 !(mgmt->sa[0] & 0x01)) {
2489 struct ieee80211_mgmt *resp;
2492 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2493 * Return the Action frame to the source without change
2494 * except that MSB of the Category set to 1.
2496 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2497 "frame back to sender");
2498 resp = os_malloc(len);
2501 os_memcpy(resp, mgmt, len);
2502 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2503 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2504 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2505 resp->u.action.category |= 0x80;
2507 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2508 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2519 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2520 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2522 * @buf: management frame data (starting from IEEE 802.11 header)
2523 * @len: length of frame data in octets
2524 * @fi: meta data about received frame (signal level, etc.)
2526 * Process all incoming IEEE 802.11 management frames. This will be called for
2527 * each frame received from the kernel driver through wlan#ap interface. In
2528 * addition, it can be called to re-inserted pending frames (e.g., when using
2529 * external RADIUS server as an MAC ACL).
2531 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2532 struct hostapd_frame_info *fi)
2534 struct ieee80211_mgmt *mgmt;
2542 mgmt = (struct ieee80211_mgmt *) buf;
2543 fc = le_to_host16(mgmt->frame_control);
2544 stype = WLAN_FC_GET_STYPE(fc);
2546 if (stype == WLAN_FC_STYPE_BEACON) {
2547 handle_beacon(hapd, mgmt, len, fi);
2551 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2552 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2553 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2557 /* Invitation responses can be sent with the peer MAC as BSSID */
2558 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2559 stype == WLAN_FC_STYPE_ACTION) &&
2560 #endif /* CONFIG_P2P */
2562 !(hapd->conf->mesh & MESH_ENABLED) &&
2563 #endif /* CONFIG_MESH */
2564 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2565 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2566 MAC2STR(mgmt->bssid));
2571 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2572 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2576 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2577 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2578 HOSTAPD_LEVEL_DEBUG,
2579 "MGMT: DA=" MACSTR " not our address",
2584 if (hapd->iconf->track_sta_max_num)
2585 sta_track_add(hapd->iface, mgmt->sa);
2588 case WLAN_FC_STYPE_AUTH:
2589 wpa_printf(MSG_DEBUG, "mgmt::auth");
2590 handle_auth(hapd, mgmt, len);
2593 case WLAN_FC_STYPE_ASSOC_REQ:
2594 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2595 handle_assoc(hapd, mgmt, len, 0);
2598 case WLAN_FC_STYPE_REASSOC_REQ:
2599 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2600 handle_assoc(hapd, mgmt, len, 1);
2603 case WLAN_FC_STYPE_DISASSOC:
2604 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2605 handle_disassoc(hapd, mgmt, len);
2608 case WLAN_FC_STYPE_DEAUTH:
2609 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2610 handle_deauth(hapd, mgmt, len);
2613 case WLAN_FC_STYPE_ACTION:
2614 wpa_printf(MSG_DEBUG, "mgmt::action");
2615 ret = handle_action(hapd, mgmt, len);
2618 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2619 HOSTAPD_LEVEL_DEBUG,
2620 "unknown mgmt frame subtype %d", stype);
2628 static void handle_auth_cb(struct hostapd_data *hapd,
2629 const struct ieee80211_mgmt *mgmt,
2632 u16 auth_alg, auth_transaction, status_code;
2633 struct sta_info *sta;
2635 sta = ap_get_sta(hapd, mgmt->da);
2637 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2642 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2643 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2644 status_code = le_to_host16(mgmt->u.auth.status_code);
2647 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2648 HOSTAPD_LEVEL_NOTICE,
2649 "did not acknowledge authentication response");
2653 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2654 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2655 (unsigned long) len);
2659 if (status_code == WLAN_STATUS_SUCCESS &&
2660 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2661 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2662 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2663 HOSTAPD_LEVEL_INFO, "authenticated");
2664 sta->flags |= WLAN_STA_AUTH;
2665 if (sta->added_unassoc)
2666 hostapd_set_sta_flags(hapd, sta);
2671 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2672 hostapd_drv_sta_remove(hapd, sta->addr);
2673 sta->added_unassoc = 0;
2678 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2679 struct sta_info *sta,
2683 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2685 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2688 for (i = 0; i < 4; i++) {
2689 if (ssid->wep.key[i] &&
2690 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2691 i == ssid->wep.idx, NULL, 0,
2692 ssid->wep.key[i], ssid->wep.len[i])) {
2693 wpa_printf(MSG_WARNING,
2694 "Could not set WEP keys for WDS interface; %s",
2702 static void handle_assoc_cb(struct hostapd_data *hapd,
2703 const struct ieee80211_mgmt *mgmt,
2704 size_t len, int reassoc, int ok)
2707 struct sta_info *sta;
2710 sta = ap_get_sta(hapd, mgmt->da);
2712 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2717 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2718 sizeof(mgmt->u.assoc_resp))) {
2719 wpa_printf(MSG_INFO,
2720 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2721 reassoc, (unsigned long) len);
2722 hostapd_drv_sta_remove(hapd, sta->addr);
2727 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2729 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2732 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2733 HOSTAPD_LEVEL_DEBUG,
2734 "did not acknowledge association response");
2735 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2736 /* The STA is added only in case of SUCCESS */
2737 if (status == WLAN_STATUS_SUCCESS)
2738 hostapd_drv_sta_remove(hapd, sta->addr);
2743 if (status != WLAN_STATUS_SUCCESS)
2746 /* Stop previous accounting session, if one is started, and allocate
2747 * new session id for the new session. */
2748 accounting_sta_stop(hapd, sta);
2750 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2752 "associated (aid %d)",
2755 if (sta->flags & WLAN_STA_ASSOC)
2757 sta->flags |= WLAN_STA_ASSOC;
2758 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2759 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2760 sta->auth_alg == WLAN_AUTH_FT) {
2762 * Open, static WEP, or FT protocol; no separate authorization
2765 ap_sta_set_authorized(hapd, sta, 1);
2769 mlme_reassociate_indication(hapd, sta);
2771 mlme_associate_indication(hapd, sta);
2773 #ifdef CONFIG_IEEE80211W
2774 sta->sa_query_timed_out = 0;
2775 #endif /* CONFIG_IEEE80211W */
2777 if (sta->flags & WLAN_STA_WDS) {
2779 char ifname_wds[IFNAMSIZ + 1];
2781 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2784 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2787 if (sta->eapol_sm == NULL) {
2789 * This STA does not use RADIUS server for EAP authentication,
2790 * so bind it to the selected VLAN interface now, since the
2791 * interface selection is not going to change anymore.
2793 if (ap_sta_bind_vlan(hapd, sta) < 0)
2795 } else if (sta->vlan_id) {
2796 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2797 if (ap_sta_bind_vlan(hapd, sta) < 0)
2801 hostapd_set_sta_flags(hapd, sta);
2803 if (sta->auth_alg == WLAN_AUTH_FT)
2804 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2806 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2807 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2808 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2810 if (sta->pending_eapol_rx) {
2811 struct os_reltime now, age;
2813 os_get_reltime(&now);
2814 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
2815 if (age.sec == 0 && age.usec < 200000) {
2816 wpa_printf(MSG_DEBUG,
2817 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
2818 MAC2STR(sta->addr));
2821 wpabuf_head(sta->pending_eapol_rx->buf),
2822 wpabuf_len(sta->pending_eapol_rx->buf));
2824 wpabuf_free(sta->pending_eapol_rx->buf);
2825 os_free(sta->pending_eapol_rx);
2826 sta->pending_eapol_rx = NULL;
2831 static void handle_deauth_cb(struct hostapd_data *hapd,
2832 const struct ieee80211_mgmt *mgmt,
2835 struct sta_info *sta;
2836 if (mgmt->da[0] & 0x01)
2838 sta = ap_get_sta(hapd, mgmt->da);
2840 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2841 " not found", MAC2STR(mgmt->da));
2845 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2846 MAC2STR(sta->addr));
2848 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2849 "deauth", MAC2STR(sta->addr));
2851 ap_sta_deauth_cb(hapd, sta);
2855 static void handle_disassoc_cb(struct hostapd_data *hapd,
2856 const struct ieee80211_mgmt *mgmt,
2859 struct sta_info *sta;
2860 if (mgmt->da[0] & 0x01)
2862 sta = ap_get_sta(hapd, mgmt->da);
2864 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2865 " not found", MAC2STR(mgmt->da));
2869 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2870 MAC2STR(sta->addr));
2872 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2873 "disassoc", MAC2STR(sta->addr));
2875 ap_sta_disassoc_cb(hapd, sta);
2880 * ieee802_11_mgmt_cb - Process management frame TX status callback
2881 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2883 * @buf: management frame data (starting from IEEE 802.11 header)
2884 * @len: length of frame data in octets
2885 * @stype: management frame subtype from frame control field
2886 * @ok: Whether the frame was ACK'ed
2888 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2891 const struct ieee80211_mgmt *mgmt;
2892 mgmt = (const struct ieee80211_mgmt *) buf;
2894 #ifdef CONFIG_TESTING_OPTIONS
2895 if (hapd->ext_mgmt_frame_handling) {
2896 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2900 #endif /* CONFIG_TESTING_OPTIONS */
2903 case WLAN_FC_STYPE_AUTH:
2904 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2905 handle_auth_cb(hapd, mgmt, len, ok);
2907 case WLAN_FC_STYPE_ASSOC_RESP:
2908 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2909 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2911 case WLAN_FC_STYPE_REASSOC_RESP:
2912 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2913 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2915 case WLAN_FC_STYPE_PROBE_RESP:
2916 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
2918 case WLAN_FC_STYPE_DEAUTH:
2919 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2920 handle_deauth_cb(hapd, mgmt, len, ok);
2922 case WLAN_FC_STYPE_DISASSOC:
2923 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2924 handle_disassoc_cb(hapd, mgmt, len, ok);
2926 case WLAN_FC_STYPE_ACTION:
2927 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
2930 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2936 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2943 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2944 char *buf, size_t buflen)
2951 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2952 const u8 *buf, size_t len, int ack)
2954 struct sta_info *sta;
2955 struct hostapd_iface *iface = hapd->iface;
2957 sta = ap_get_sta(hapd, addr);
2958 if (sta == NULL && iface->num_bss > 1) {
2960 for (j = 0; j < iface->num_bss; j++) {
2961 hapd = iface->bss[j];
2962 sta = ap_get_sta(hapd, addr);
2967 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2969 if (sta->flags & WLAN_STA_PENDING_POLL) {
2970 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2971 "activity poll", MAC2STR(sta->addr),
2972 ack ? "ACKed" : "did not ACK");
2974 sta->flags &= ~WLAN_STA_PENDING_POLL;
2977 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2981 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2982 const u8 *data, size_t len, int ack)
2984 struct sta_info *sta;
2985 struct hostapd_iface *iface = hapd->iface;
2987 sta = ap_get_sta(hapd, dst);
2988 if (sta == NULL && iface->num_bss > 1) {
2990 for (j = 0; j < iface->num_bss; j++) {
2991 hapd = iface->bss[j];
2992 sta = ap_get_sta(hapd, dst);
2997 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2998 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2999 MACSTR " that is not currently associated",
3004 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
3008 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
3010 struct sta_info *sta;
3011 struct hostapd_iface *iface = hapd->iface;
3013 sta = ap_get_sta(hapd, addr);
3014 if (sta == NULL && iface->num_bss > 1) {
3016 for (j = 0; j < iface->num_bss; j++) {
3017 hapd = iface->bss[j];
3018 sta = ap_get_sta(hapd, addr);
3025 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
3026 MAC2STR(sta->addr));
3027 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3030 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3031 "activity poll", MAC2STR(sta->addr));
3032 sta->flags &= ~WLAN_STA_PENDING_POLL;
3036 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3039 struct sta_info *sta;
3041 sta = ap_get_sta(hapd, src);
3042 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
3043 if (!hapd->conf->wds_sta)
3046 if (wds && !(sta->flags & WLAN_STA_WDS)) {
3048 char ifname_wds[IFNAMSIZ + 1];
3050 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3051 "STA " MACSTR " (aid %u)",
3052 MAC2STR(sta->addr), sta->aid);
3053 sta->flags |= WLAN_STA_WDS;
3054 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3055 sta->addr, sta->aid, 1);
3057 hostapd_set_wds_encryption(hapd, sta,
3063 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3064 MACSTR, MAC2STR(src));
3065 if (src[0] & 0x01) {
3066 /* Broadcast bit set in SA?! Ignore the frame silently. */
3070 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3071 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3072 "already been sent, but no TX status yet known - "
3073 "ignore Class 3 frame issue with " MACSTR,
3078 if (sta && (sta->flags & WLAN_STA_AUTH))
3079 hostapd_drv_sta_disassoc(
3081 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3083 hostapd_drv_sta_deauth(
3085 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3089 #endif /* CONFIG_NATIVE_WINDOWS */