2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #ifndef CONFIG_NATIVE_WINDOWS
13 #include "utils/common.h"
14 #include "utils/eloop.h"
15 #include "crypto/crypto.h"
16 #include "crypto/sha256.h"
17 #include "crypto/random.h"
18 #include "common/ieee802_11_defs.h"
19 #include "common/ieee802_11_common.h"
20 #include "common/wpa_ctrl.h"
21 #include "common/sae.h"
22 #include "radius/radius.h"
23 #include "radius/radius_client.h"
29 #include "ieee802_11_auth.h"
31 #include "ieee802_1x.h"
33 #include "pmksa_cache_auth.h"
36 #include "accounting.h"
37 #include "ap_config.h"
39 #include "p2p_hostapd.h"
40 #include "ap_drv_ops.h"
42 #include "hw_features.h"
43 #include "ieee802_11.h"
47 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
52 if (hapd->iface->current_rates == NULL)
55 *pos++ = WLAN_EID_SUPP_RATES;
56 num = hapd->iface->num_rates;
57 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
59 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
62 /* rest of the rates are encoded in Extended supported
68 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
71 *pos = hapd->iface->current_rates[i].rate / 5;
72 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
77 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
79 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
82 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
84 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
91 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
96 if (hapd->iface->current_rates == NULL)
99 num = hapd->iface->num_rates;
100 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
102 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
108 *pos++ = WLAN_EID_EXT_SUPP_RATES;
110 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
114 continue; /* already in SuppRates IE */
115 *pos = hapd->iface->current_rates[i].rate / 5;
116 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
121 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
124 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
127 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
130 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
137 u16 hostapd_own_capab_info(struct hostapd_data *hapd)
139 int capab = WLAN_CAPABILITY_ESS;
143 /* Check if any of configured channels require DFS */
144 dfs = hostapd_is_dfs_required(hapd->iface);
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
151 if (hapd->iface->num_sta_no_short_preamble == 0 &&
152 hapd->iconf->preamble == SHORT_PREAMBLE)
153 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
155 privacy = hapd->conf->ssid.wep.keys_set;
157 if (hapd->conf->ieee802_1x &&
158 (hapd->conf->default_wep_key_len ||
159 hapd->conf->individual_wep_key_len))
166 if (hapd->conf->osen)
168 #endif /* CONFIG_HS20 */
171 capab |= WLAN_CAPABILITY_PRIVACY;
173 if (hapd->iface->current_mode &&
174 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
175 hapd->iface->num_sta_no_short_slot_time == 0)
176 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
179 * Currently, Spectrum Management capability bit is set when directly
180 * requested in configuration by spectrum_mgmt_required or when AP is
181 * running on DFS channel.
182 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
184 if (hapd->iface->current_mode &&
185 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
186 (hapd->iconf->spectrum_mgmt_required || dfs))
187 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
189 if (hapd->conf->radio_measurements)
190 capab |= IEEE80211_CAP_RRM;
196 #ifndef CONFIG_NO_RC4
197 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
198 u16 auth_transaction, const u8 *challenge,
201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
203 "authentication (shared key, transaction %d)",
206 if (auth_transaction == 1) {
207 if (!sta->challenge) {
208 /* Generate a pseudo-random challenge */
211 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
212 if (sta->challenge == NULL)
213 return WLAN_STATUS_UNSPECIFIED_FAILURE;
215 if (os_get_random(key, sizeof(key)) < 0) {
216 os_free(sta->challenge);
217 sta->challenge = NULL;
218 return WLAN_STATUS_UNSPECIFIED_FAILURE;
221 rc4_skip(key, sizeof(key), 0,
222 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
227 if (auth_transaction != 3)
228 return WLAN_STATUS_UNSPECIFIED_FAILURE;
231 if (!iswep || !sta->challenge || !challenge ||
232 os_memcmp_const(sta->challenge, challenge,
233 WLAN_AUTH_CHALLENGE_LEN)) {
234 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
236 "shared key authentication - invalid "
237 "challenge-response");
238 return WLAN_STATUS_CHALLENGE_FAIL;
241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 "authentication OK (shared key)");
244 sta->flags |= WLAN_STA_AUTH;
245 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
246 os_free(sta->challenge);
247 sta->challenge = NULL;
251 #endif /* CONFIG_NO_RC4 */
254 static void send_auth_reply(struct hostapd_data *hapd,
255 const u8 *dst, const u8 *bssid,
256 u16 auth_alg, u16 auth_transaction, u16 resp,
257 const u8 *ies, size_t ies_len)
259 struct ieee80211_mgmt *reply;
263 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
264 buf = os_zalloc(rlen);
268 reply = (struct ieee80211_mgmt *) buf;
269 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
271 os_memcpy(reply->da, dst, ETH_ALEN);
272 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
273 os_memcpy(reply->bssid, bssid, ETH_ALEN);
275 reply->u.auth.auth_alg = host_to_le16(auth_alg);
276 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
277 reply->u.auth.status_code = host_to_le16(resp);
280 os_memcpy(reply->u.auth.variable, ies, ies_len);
282 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
283 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
284 MAC2STR(dst), auth_alg, auth_transaction,
285 resp, (unsigned long) ies_len);
286 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
287 wpa_printf(MSG_INFO, "send_auth_reply: send");
293 #ifdef CONFIG_IEEE80211R
294 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
295 u16 auth_transaction, u16 status,
296 const u8 *ies, size_t ies_len)
298 struct hostapd_data *hapd = ctx;
299 struct sta_info *sta;
301 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
302 status, ies, ies_len);
304 if (status != WLAN_STATUS_SUCCESS)
307 sta = ap_get_sta(hapd, dst);
311 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
312 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
313 sta->flags |= WLAN_STA_AUTH;
314 mlme_authenticate_indication(hapd, sta);
316 #endif /* CONFIG_IEEE80211R */
321 #define dot11RSNASAESync 5 /* attempts */
324 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
325 struct sta_info *sta, int update)
329 if (hapd->conf->ssid.wpa_passphrase == NULL) {
330 wpa_printf(MSG_DEBUG, "SAE: No password available");
335 sae_prepare_commit(hapd->own_addr, sta->addr,
336 (u8 *) hapd->conf->ssid.wpa_passphrase,
337 os_strlen(hapd->conf->ssid.wpa_passphrase),
339 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
343 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
346 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
347 sta->sae->tmp->anti_clogging_token : NULL);
353 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
354 struct sta_info *sta)
358 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
362 sae_write_confirm(sta->sae, buf);
368 static int auth_sae_send_commit(struct hostapd_data *hapd,
369 struct sta_info *sta,
370 const u8 *bssid, int update)
374 data = auth_build_sae_commit(hapd, sta, update);
376 return WLAN_STATUS_UNSPECIFIED_FAILURE;
378 send_auth_reply(hapd, sta->addr, bssid,
379 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
380 wpabuf_head(data), wpabuf_len(data));
384 return WLAN_STATUS_SUCCESS;
388 static int auth_sae_send_confirm(struct hostapd_data *hapd,
389 struct sta_info *sta,
394 data = auth_build_sae_confirm(hapd, sta);
396 return WLAN_STATUS_UNSPECIFIED_FAILURE;
398 send_auth_reply(hapd, sta->addr, bssid,
399 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
400 wpabuf_head(data), wpabuf_len(data));
404 return WLAN_STATUS_SUCCESS;
408 static int use_sae_anti_clogging(struct hostapd_data *hapd)
410 struct sta_info *sta;
411 unsigned int open = 0;
413 if (hapd->conf->sae_anti_clogging_threshold == 0)
416 for (sta = hapd->sta_list; sta; sta = sta->next) {
419 if (sta->sae->state != SAE_COMMITTED &&
420 sta->sae->state != SAE_CONFIRMED)
423 if (open >= hapd->conf->sae_anti_clogging_threshold)
431 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
432 const u8 *token, size_t token_len)
434 u8 mac[SHA256_MAC_LEN];
436 if (token_len != SHA256_MAC_LEN)
438 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
439 addr, ETH_ALEN, mac) < 0 ||
440 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
447 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
448 int group, const u8 *addr)
452 struct os_reltime now;
454 os_get_reltime(&now);
455 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
456 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
457 if (random_get_bytes(hapd->sae_token_key,
458 sizeof(hapd->sae_token_key)) < 0)
460 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
461 hapd->sae_token_key, sizeof(hapd->sae_token_key));
462 hapd->last_sae_token_key_update = now;
465 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
469 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
471 token = wpabuf_put(buf, SHA256_MAC_LEN);
472 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
473 addr, ETH_ALEN, token);
479 static int sae_check_big_sync(struct sta_info *sta)
481 if (sta->sae->sync > dot11RSNASAESync) {
482 sta->sae->state = SAE_NOTHING;
490 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
492 struct hostapd_data *hapd = eloop_ctx;
493 struct sta_info *sta = eloop_data;
496 if (sae_check_big_sync(sta))
500 switch (sta->sae->state) {
502 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
503 eloop_register_timeout(0,
504 hapd->dot11RSNASAERetransPeriod * 1000,
505 auth_sae_retransmit_timer, hapd, sta);
508 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
509 eloop_register_timeout(0,
510 hapd->dot11RSNASAERetransPeriod * 1000,
511 auth_sae_retransmit_timer, hapd, sta);
518 if (ret != WLAN_STATUS_SUCCESS)
519 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
523 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
525 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
529 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
530 struct sta_info *sta)
532 if (!(hapd->conf->mesh & MESH_ENABLED))
535 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
536 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
537 auth_sae_retransmit_timer, hapd, sta);
541 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
542 const u8 *bssid, u8 auth_transaction)
546 if (auth_transaction != 1 && auth_transaction != 2)
547 return WLAN_STATUS_UNSPECIFIED_FAILURE;
549 switch (sta->sae->state) {
551 if (auth_transaction == 1) {
552 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
555 sta->sae->state = SAE_COMMITTED;
557 if (sae_process_commit(sta->sae) < 0)
558 return WLAN_STATUS_UNSPECIFIED_FAILURE;
561 * In mesh case, both Commit and Confirm can be sent
562 * immediately. In infrastructure BSS, only a single
563 * Authentication frame (Commit) is expected from the AP
564 * here and the second one (Confirm) will be sent once
565 * the STA has sent its second Authentication frame
568 if (hapd->conf->mesh & MESH_ENABLED) {
570 * Send both Commit and Confirm immediately
571 * based on SAE finite state machine
572 * Nothing -> Confirm transition.
574 ret = auth_sae_send_confirm(hapd, sta, bssid);
577 sta->sae->state = SAE_CONFIRMED;
580 * For infrastructure BSS, send only the Commit
581 * message now to get alternating sequence of
582 * Authentication frames between the AP and STA.
583 * Confirm will be sent in
584 * Commited -> Confirmed/Accepted transition
585 * when receiving Confirm from STA.
589 sae_set_retransmit_timer(hapd, sta);
591 hostapd_logger(hapd, sta->addr,
592 HOSTAPD_MODULE_IEEE80211,
594 "SAE confirm before commit");
598 sae_clear_retransmit_timer(hapd, sta);
599 if (auth_transaction == 1) {
600 if (sae_process_commit(sta->sae) < 0)
601 return WLAN_STATUS_UNSPECIFIED_FAILURE;
603 ret = auth_sae_send_confirm(hapd, sta, bssid);
606 sta->sae->state = SAE_CONFIRMED;
608 sae_set_retransmit_timer(hapd, sta);
609 } else if (hapd->conf->mesh & MESH_ENABLED) {
611 * In mesh case, follow SAE finite state machine and
612 * send Commit now, if sync count allows.
614 if (sae_check_big_sync(sta))
615 return WLAN_STATUS_SUCCESS;
618 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
622 sae_set_retransmit_timer(hapd, sta);
625 * For instructure BSS, send the postponed Confirm from
626 * Nothing -> Confirmed transition that was reduced to
627 * Nothing -> Committed above.
629 ret = auth_sae_send_confirm(hapd, sta, bssid);
633 sta->sae->state = SAE_CONFIRMED;
636 * Since this was triggered on Confirm RX, run another
637 * step to get to Accepted without waiting for
640 return sae_sm_step(hapd, sta, bssid, auth_transaction);
644 sae_clear_retransmit_timer(hapd, sta);
645 if (auth_transaction == 1) {
646 if (sae_check_big_sync(sta))
647 return WLAN_STATUS_SUCCESS;
650 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
654 if (sae_process_commit(sta->sae) < 0)
655 return WLAN_STATUS_UNSPECIFIED_FAILURE;
657 ret = auth_sae_send_confirm(hapd, sta, bssid);
661 sae_set_retransmit_timer(hapd, sta);
663 sta->flags |= WLAN_STA_AUTH;
664 sta->auth_alg = WLAN_AUTH_SAE;
665 mlme_authenticate_indication(hapd, sta);
666 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
667 sta->sae->state = SAE_ACCEPTED;
668 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
669 sta->sae->pmk, sta->sae->pmkid);
673 if (auth_transaction == 1) {
674 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
675 ") doing reauthentication",
677 ap_free_sta(hapd, sta);
679 if (sae_check_big_sync(sta))
680 return WLAN_STATUS_SUCCESS;
683 ret = auth_sae_send_confirm(hapd, sta, bssid);
684 sae_clear_temp_data(sta->sae);
690 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
692 return WLAN_STATUS_UNSPECIFIED_FAILURE;
694 return WLAN_STATUS_SUCCESS;
698 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
699 const struct ieee80211_mgmt *mgmt, size_t len,
700 u16 auth_transaction, u16 status_code)
702 u16 resp = WLAN_STATUS_SUCCESS;
703 struct wpabuf *data = NULL;
706 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
708 sta->sae = os_zalloc(sizeof(*sta->sae));
709 if (sta->sae == NULL)
711 sta->sae->state = SAE_NOTHING;
715 if (auth_transaction == 1) {
716 const u8 *token = NULL, *pos, *end;
717 size_t token_len = 0;
718 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
720 "start SAE authentication (RX commit, status=%u)",
723 if ((hapd->conf->mesh & MESH_ENABLED) &&
724 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
726 pos = mgmt->u.auth.variable;
727 end = ((const u8 *) mgmt) + len;
728 if (pos + sizeof(le16) > end) {
729 wpa_printf(MSG_ERROR,
730 "SAE: Too short anti-clogging token request");
731 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
734 resp = sae_group_allowed(sta->sae,
735 hapd->conf->sae_groups,
737 if (resp != WLAN_STATUS_SUCCESS) {
738 wpa_printf(MSG_ERROR,
739 "SAE: Invalid group in anti-clogging token request");
744 wpabuf_free(sta->sae->tmp->anti_clogging_token);
745 sta->sae->tmp->anti_clogging_token =
746 wpabuf_alloc_copy(pos, end - pos);
747 if (sta->sae->tmp->anti_clogging_token == NULL) {
748 wpa_printf(MSG_ERROR,
749 "SAE: Failed to alloc for anti-clogging token");
754 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
755 * is 76, a new Commit Message shall be constructed
756 * with the Anti-Clogging Token from the received
757 * Authentication frame, and the commit-scalar and
758 * COMMIT-ELEMENT previously sent.
760 if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) {
761 wpa_printf(MSG_ERROR,
762 "SAE: Failed to send commit message");
765 sta->sae->state = SAE_COMMITTED;
767 sae_set_retransmit_timer(hapd, sta);
771 if (status_code != WLAN_STATUS_SUCCESS)
774 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
775 ((const u8 *) mgmt) + len -
776 mgmt->u.auth.variable, &token,
777 &token_len, hapd->conf->sae_groups);
778 if (resp == SAE_SILENTLY_DISCARD) {
779 wpa_printf(MSG_DEBUG,
780 "SAE: Drop commit message from " MACSTR " due to reflection attack",
784 if (token && check_sae_token(hapd, sta->addr, token, token_len)
786 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
787 "incorrect token from " MACSTR,
792 if (resp != WLAN_STATUS_SUCCESS)
795 if (!token && use_sae_anti_clogging(hapd)) {
796 wpa_printf(MSG_DEBUG,
797 "SAE: Request anti-clogging token from "
798 MACSTR, MAC2STR(sta->addr));
799 data = auth_build_token_req(hapd, sta->sae->group,
801 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
802 if (hapd->conf->mesh & MESH_ENABLED)
803 sta->sae->state = SAE_NOTHING;
807 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
808 } else if (auth_transaction == 2) {
809 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
811 "SAE authentication (RX confirm, status=%u)",
813 if (status_code != WLAN_STATUS_SUCCESS)
815 if (sta->sae->state >= SAE_CONFIRMED ||
816 !(hapd->conf->mesh & MESH_ENABLED)) {
817 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
818 ((u8 *) mgmt) + len -
819 mgmt->u.auth.variable) < 0) {
820 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
824 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
826 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
828 "unexpected SAE authentication transaction %u (status=%u)",
829 auth_transaction, status_code);
830 if (status_code != WLAN_STATUS_SUCCESS)
832 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
836 if (resp != WLAN_STATUS_SUCCESS) {
837 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
838 auth_transaction, resp,
839 data ? wpabuf_head(data) : (u8 *) "",
840 data ? wpabuf_len(data) : 0);
847 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
848 * @hapd: BSS data for the device initiating the authentication
849 * @sta: the peer to which commit authentication frame is sent
851 * This function implements Init event handling (IEEE Std 802.11-2012,
852 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
853 * sta->sae structure should be initialized appropriately via a call to
854 * sae_prepare_commit().
856 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
860 if (!sta->sae || !sta->sae->tmp)
863 if (sta->sae->state != SAE_NOTHING)
866 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
870 sta->sae->state = SAE_COMMITTED;
872 sae_set_retransmit_timer(hapd, sta);
877 #endif /* CONFIG_SAE */
880 static void handle_auth(struct hostapd_data *hapd,
881 const struct ieee80211_mgmt *mgmt, size_t len)
883 u16 auth_alg, auth_transaction, status_code;
884 u16 resp = WLAN_STATUS_SUCCESS;
885 struct sta_info *sta = NULL;
888 const u8 *challenge = NULL;
889 u32 session_timeout, acct_interim_interval;
890 struct vlan_description vlan_id;
891 struct hostapd_sta_wpa_psk_short *psk = NULL;
892 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
893 size_t resp_ies_len = 0;
894 char *identity = NULL;
895 char *radius_cui = NULL;
898 os_memset(&vlan_id, 0, sizeof(vlan_id));
900 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
901 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
902 (unsigned long) len);
906 #ifdef CONFIG_TESTING_OPTIONS
907 if (hapd->iconf->ignore_auth_probability > 0.0 &&
908 drand48() < hapd->iconf->ignore_auth_probability) {
910 "TESTING: ignoring auth frame from " MACSTR,
914 #endif /* CONFIG_TESTING_OPTIONS */
916 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
917 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
918 status_code = le_to_host16(mgmt->u.auth.status_code);
919 fc = le_to_host16(mgmt->frame_control);
920 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
922 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
923 2 + WLAN_AUTH_CHALLENGE_LEN &&
924 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
925 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
926 challenge = &mgmt->u.auth.variable[2];
928 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
929 "auth_transaction=%d status_code=%d wep=%d%s "
931 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
932 status_code, !!(fc & WLAN_FC_ISWEP),
933 challenge ? " challenge" : "",
934 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
937 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
939 "Unsupported authentication algorithm (%d)",
941 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
944 #endif /* CONFIG_NO_RC4 */
946 if (hapd->tkip_countermeasures) {
947 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
951 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
952 auth_alg == WLAN_AUTH_OPEN) ||
953 #ifdef CONFIG_IEEE80211R
954 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
955 auth_alg == WLAN_AUTH_FT) ||
956 #endif /* CONFIG_IEEE80211R */
958 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
959 auth_alg == WLAN_AUTH_SAE) ||
960 #endif /* CONFIG_SAE */
961 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
962 auth_alg == WLAN_AUTH_SHARED_KEY))) {
963 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
965 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
969 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
970 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
971 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
973 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
977 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
978 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
980 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
984 if (hapd->conf->no_auth_if_seen_on) {
985 struct hostapd_data *other;
987 other = sta_track_seen_on(hapd->iface, mgmt->sa,
988 hapd->conf->no_auth_if_seen_on);
992 u8 op_class, channel, phytype;
994 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
995 MACSTR " since STA has been seen on %s",
996 hapd->conf->iface, MAC2STR(mgmt->sa),
997 hapd->conf->no_auth_if_seen_on);
999 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1001 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1003 os_memcpy(pos, other->own_addr, ETH_ALEN);
1005 info = 0; /* TODO: BSSID Information */
1006 WPA_PUT_LE32(pos, info);
1008 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1009 phytype = 8; /* dmg */
1010 else if (other->iconf->ieee80211ac)
1011 phytype = 9; /* vht */
1012 else if (other->iconf->ieee80211n)
1013 phytype = 7; /* ht */
1014 else if (other->iconf->hw_mode ==
1015 HOSTAPD_MODE_IEEE80211A)
1016 phytype = 4; /* ofdm */
1017 else if (other->iconf->hw_mode ==
1018 HOSTAPD_MODE_IEEE80211G)
1019 phytype = 6; /* erp */
1021 phytype = 5; /* hrdsss */
1022 if (ieee80211_freq_to_channel_ext(
1023 hostapd_hw_get_freq(other,
1024 other->iconf->channel),
1025 other->iconf->secondary_channel,
1026 other->iconf->ieee80211ac,
1027 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1029 channel = other->iconf->channel;
1034 resp_ies_len = pos - &resp_ies[0];
1039 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1041 &acct_interim_interval, &vlan_id,
1042 &psk, &identity, &radius_cui);
1044 if (res == HOSTAPD_ACL_REJECT) {
1045 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1047 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1050 if (res == HOSTAPD_ACL_PENDING) {
1051 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1052 " waiting for an external authentication",
1054 /* Authentication code will re-send the authentication frame
1055 * after it has received (and cached) information from the
1056 * external source. */
1060 sta = ap_get_sta(hapd, mgmt->sa);
1062 if ((fc & WLAN_FC_RETRY) &&
1063 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1064 sta->last_seq_ctrl == seq_ctrl &&
1065 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1066 hostapd_logger(hapd, sta->addr,
1067 HOSTAPD_MODULE_IEEE80211,
1068 HOSTAPD_LEVEL_DEBUG,
1069 "Drop repeated authentication frame seq_ctrl=0x%x",
1074 if ((hapd->conf->mesh & MESH_ENABLED) &&
1075 sta->plink_state == PLINK_BLOCKED) {
1076 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1077 " is blocked - drop Authentication frame",
1081 #endif /* CONFIG_MESH */
1084 if (hapd->conf->mesh & MESH_ENABLED) {
1085 /* if the mesh peer is not available, we don't do auth.
1087 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1088 " not yet known - drop Authentication frame",
1091 * Save a copy of the frame so that it can be processed
1092 * if a new peer entry is added shortly after this.
1094 wpabuf_free(hapd->mesh_pending_auth);
1095 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1096 os_get_reltime(&hapd->mesh_pending_auth_time);
1099 #endif /* CONFIG_MESH */
1101 sta = ap_sta_add(hapd, mgmt->sa);
1103 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1107 sta->last_seq_ctrl = seq_ctrl;
1108 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1110 if (vlan_id.notempty &&
1111 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1112 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1114 "Invalid VLAN %d%s received from RADIUS server",
1116 vlan_id.tagged[0] ? "+" : "");
1117 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1120 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1121 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1125 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1126 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1128 hostapd_free_psk_list(sta->psk);
1129 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1136 sta->identity = identity;
1138 sta->radius_cui = radius_cui;
1141 sta->flags &= ~WLAN_STA_PREAUTH;
1142 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1144 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1145 sta->acct_interim_interval = acct_interim_interval;
1146 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1147 ap_sta_session_timeout(hapd, sta, session_timeout);
1149 ap_sta_no_session_timeout(hapd, sta);
1152 case WLAN_AUTH_OPEN:
1153 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1154 HOSTAPD_LEVEL_DEBUG,
1155 "authentication OK (open system)");
1156 sta->flags |= WLAN_STA_AUTH;
1157 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1158 sta->auth_alg = WLAN_AUTH_OPEN;
1159 mlme_authenticate_indication(hapd, sta);
1161 #ifndef CONFIG_NO_RC4
1162 case WLAN_AUTH_SHARED_KEY:
1163 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1164 fc & WLAN_FC_ISWEP);
1165 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1166 mlme_authenticate_indication(hapd, sta);
1167 if (sta->challenge && auth_transaction == 1) {
1168 resp_ies[0] = WLAN_EID_CHALLENGE;
1169 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1170 os_memcpy(resp_ies + 2, sta->challenge,
1171 WLAN_AUTH_CHALLENGE_LEN);
1172 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1175 #endif /* CONFIG_NO_RC4 */
1176 #ifdef CONFIG_IEEE80211R
1178 sta->auth_alg = WLAN_AUTH_FT;
1179 if (sta->wpa_sm == NULL)
1180 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1182 if (sta->wpa_sm == NULL) {
1183 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1185 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1188 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1189 auth_transaction, mgmt->u.auth.variable,
1190 len - IEEE80211_HDRLEN -
1191 sizeof(mgmt->u.auth),
1192 handle_auth_ft_finish, hapd);
1193 /* handle_auth_ft_finish() callback will complete auth. */
1195 #endif /* CONFIG_IEEE80211R */
1199 if (status_code == WLAN_STATUS_SUCCESS &&
1200 hapd->conf->mesh & MESH_ENABLED) {
1201 if (sta->wpa_sm == NULL)
1203 wpa_auth_sta_init(hapd->wpa_auth,
1205 if (sta->wpa_sm == NULL) {
1206 wpa_printf(MSG_DEBUG,
1207 "SAE: Failed to initialize WPA state machine");
1208 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1212 #endif /* CONFIG_MESH */
1213 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1216 #endif /* CONFIG_SAE */
1221 os_free(radius_cui);
1222 hostapd_free_psk_list(psk);
1224 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1225 auth_transaction + 1, resp, resp_ies, resp_ies_len);
1229 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1233 /* get a unique AID */
1235 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1239 for (i = 0; i < AID_WORDS; i++) {
1240 if (hapd->sta_aid[i] == (u32) -1)
1242 for (j = 0; j < 32; j++) {
1243 if (!(hapd->sta_aid[i] & BIT(j)))
1251 aid = i * 32 + j + 1;
1256 hapd->sta_aid[i] |= BIT(j);
1257 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1262 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1263 const u8 *ssid_ie, size_t ssid_ie_len)
1265 if (ssid_ie == NULL)
1266 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1268 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1269 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1270 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1272 "Station tried to associate with unknown SSID "
1273 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1274 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1277 return WLAN_STATUS_SUCCESS;
1281 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1282 const u8 *wmm_ie, size_t wmm_ie_len)
1284 sta->flags &= ~WLAN_STA_WMM;
1286 if (wmm_ie && hapd->conf->wmm_enabled) {
1287 struct wmm_information_element *wmm;
1289 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1290 hostapd_logger(hapd, sta->addr,
1292 HOSTAPD_LEVEL_DEBUG,
1293 "invalid WMM element in association "
1295 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1298 sta->flags |= WLAN_STA_WMM;
1299 wmm = (struct wmm_information_element *) wmm_ie;
1300 sta->qosinfo = wmm->qos_info;
1302 return WLAN_STATUS_SUCCESS;
1306 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1307 struct ieee802_11_elems *elems)
1309 if (!elems->supp_rates) {
1310 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1311 HOSTAPD_LEVEL_DEBUG,
1312 "No supported rates element in AssocReq");
1313 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1316 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1317 sizeof(sta->supported_rates)) {
1318 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1319 HOSTAPD_LEVEL_DEBUG,
1320 "Invalid supported rates element length %d+%d",
1321 elems->supp_rates_len,
1322 elems->ext_supp_rates_len);
1323 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1326 sta->supported_rates_len = merge_byte_arrays(
1327 sta->supported_rates, sizeof(sta->supported_rates),
1328 elems->supp_rates, elems->supp_rates_len,
1329 elems->ext_supp_rates, elems->ext_supp_rates_len);
1331 return WLAN_STATUS_SUCCESS;
1335 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1336 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1338 #ifdef CONFIG_INTERWORKING
1339 /* check for QoS Map support */
1340 if (ext_capab_ie_len >= 5) {
1341 if (ext_capab_ie[4] & 0x01)
1342 sta->qos_map_enabled = 1;
1344 #endif /* CONFIG_INTERWORKING */
1346 if (ext_capab_ie_len > 0)
1347 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1349 return WLAN_STATUS_SUCCESS;
1353 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1354 const u8 *ies, size_t ies_len, int reassoc)
1356 struct ieee802_11_elems elems;
1360 const u8 *p2p_dev_addr = NULL;
1362 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1363 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1364 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1365 "association request");
1366 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1369 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1370 if (resp != WLAN_STATUS_SUCCESS)
1372 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1373 if (resp != WLAN_STATUS_SUCCESS)
1375 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1376 if (resp != WLAN_STATUS_SUCCESS)
1378 resp = copy_supp_rates(hapd, sta, &elems);
1379 if (resp != WLAN_STATUS_SUCCESS)
1381 #ifdef CONFIG_IEEE80211N
1382 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1383 if (resp != WLAN_STATUS_SUCCESS)
1385 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1386 !(sta->flags & WLAN_STA_HT)) {
1387 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1388 HOSTAPD_LEVEL_INFO, "Station does not support "
1389 "mandatory HT PHY - reject association");
1390 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1392 #endif /* CONFIG_IEEE80211N */
1394 #ifdef CONFIG_IEEE80211AC
1395 if (hapd->iconf->ieee80211ac) {
1396 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1397 if (resp != WLAN_STATUS_SUCCESS)
1400 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1401 if (resp != WLAN_STATUS_SUCCESS)
1405 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1406 !(sta->flags & WLAN_STA_VHT)) {
1407 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1408 HOSTAPD_LEVEL_INFO, "Station does not support "
1409 "mandatory VHT PHY - reject association");
1410 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1413 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1414 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1415 elems.vendor_vht_len);
1416 if (resp != WLAN_STATUS_SUCCESS)
1419 #endif /* CONFIG_IEEE80211AC */
1423 wpabuf_free(sta->p2p_ie);
1424 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1425 P2P_IE_VENDOR_TYPE);
1427 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1429 wpabuf_free(sta->p2p_ie);
1432 #endif /* CONFIG_P2P */
1434 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1435 wpa_ie = elems.rsn_ie;
1436 wpa_ie_len = elems.rsn_ie_len;
1437 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1439 wpa_ie = elems.wpa_ie;
1440 wpa_ie_len = elems.wpa_ie_len;
1447 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1448 if (hapd->conf->wps_state && elems.wps_ie) {
1449 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1450 "Request - assume WPS is used");
1451 sta->flags |= WLAN_STA_WPS;
1452 wpabuf_free(sta->wps_ie);
1453 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1454 WPS_IE_VENDOR_TYPE);
1455 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1456 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1457 sta->flags |= WLAN_STA_WPS2;
1461 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1462 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1463 "(Re)Association Request - reject");
1464 return WLAN_STATUS_INVALID_IE;
1466 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1467 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1468 "(Re)Association Request - possible WPS use");
1469 sta->flags |= WLAN_STA_MAYBE_WPS;
1471 #endif /* CONFIG_WPS */
1472 if (hapd->conf->wpa && wpa_ie == NULL) {
1473 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1475 "No WPA/RSN IE in association request");
1476 return WLAN_STATUS_INVALID_IE;
1479 if (hapd->conf->wpa && wpa_ie) {
1483 if (sta->wpa_sm == NULL)
1484 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1487 if (sta->wpa_sm == NULL) {
1488 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1490 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1492 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1494 elems.mdie, elems.mdie_len);
1495 if (res == WPA_INVALID_GROUP)
1496 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1497 else if (res == WPA_INVALID_PAIRWISE)
1498 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1499 else if (res == WPA_INVALID_AKMP)
1500 resp = WLAN_STATUS_AKMP_NOT_VALID;
1501 else if (res == WPA_ALLOC_FAIL)
1502 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1503 #ifdef CONFIG_IEEE80211W
1504 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1505 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1506 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1507 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1508 #endif /* CONFIG_IEEE80211W */
1509 else if (res == WPA_INVALID_MDIE)
1510 resp = WLAN_STATUS_INVALID_MDIE;
1511 else if (res != WPA_IE_OK)
1512 resp = WLAN_STATUS_INVALID_IE;
1513 if (resp != WLAN_STATUS_SUCCESS)
1515 #ifdef CONFIG_IEEE80211W
1516 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1517 sta->sa_query_count > 0)
1518 ap_check_sa_query_timeout(hapd, sta);
1519 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1520 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1522 * STA has already been associated with MFP and SA
1523 * Query timeout has not been reached. Reject the
1524 * association attempt temporarily and start SA Query,
1525 * if one is not pending.
1528 if (sta->sa_query_count == 0)
1529 ap_sta_start_sa_query(hapd, sta);
1531 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1534 if (wpa_auth_uses_mfp(sta->wpa_sm))
1535 sta->flags |= WLAN_STA_MFP;
1537 sta->flags &= ~WLAN_STA_MFP;
1538 #endif /* CONFIG_IEEE80211W */
1540 #ifdef CONFIG_IEEE80211R
1541 if (sta->auth_alg == WLAN_AUTH_FT) {
1543 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1544 "to use association (not "
1545 "re-association) with FT auth_alg",
1546 MAC2STR(sta->addr));
1547 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1550 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1552 if (resp != WLAN_STATUS_SUCCESS)
1555 #endif /* CONFIG_IEEE80211R */
1558 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1559 sta->auth_alg == WLAN_AUTH_OPEN) {
1560 struct rsn_pmksa_cache_entry *sa;
1561 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1562 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1563 wpa_printf(MSG_DEBUG,
1564 "SAE: No PMKSA cache entry found for "
1565 MACSTR, MAC2STR(sta->addr));
1566 return WLAN_STATUS_INVALID_PMKID;
1568 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1569 " using PMKSA caching", MAC2STR(sta->addr));
1570 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1571 sta->auth_alg != WLAN_AUTH_SAE &&
1572 !(sta->auth_alg == WLAN_AUTH_FT &&
1573 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1574 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1575 "SAE AKM after non-SAE auth_alg %u",
1576 MAC2STR(sta->addr), sta->auth_alg);
1577 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1579 #endif /* CONFIG_SAE */
1581 #ifdef CONFIG_IEEE80211N
1582 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1583 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1584 hostapd_logger(hapd, sta->addr,
1585 HOSTAPD_MODULE_IEEE80211,
1587 "Station tried to use TKIP with HT "
1589 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1591 #endif /* CONFIG_IEEE80211N */
1593 } else if (hapd->conf->osen) {
1594 if (elems.osen == NULL) {
1596 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1598 "No HS 2.0 OSEN element in association request");
1599 return WLAN_STATUS_INVALID_IE;
1602 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1603 if (sta->wpa_sm == NULL)
1604 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1606 if (sta->wpa_sm == NULL) {
1607 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1609 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1611 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1612 elems.osen - 2, elems.osen_len + 2) < 0)
1613 return WLAN_STATUS_INVALID_IE;
1614 #endif /* CONFIG_HS20 */
1616 wpa_auth_sta_no_wpa(sta->wpa_sm);
1619 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1620 #endif /* CONFIG_P2P */
1623 wpabuf_free(sta->hs20_ie);
1624 if (elems.hs20 && elems.hs20_len > 4) {
1625 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1626 elems.hs20_len - 4);
1628 sta->hs20_ie = NULL;
1629 #endif /* CONFIG_HS20 */
1632 wpabuf_free(sta->mb_ies);
1633 if (hapd->iface->fst)
1634 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1637 #endif /* CONFIG_FST */
1639 return WLAN_STATUS_SUCCESS;
1643 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1647 struct ieee80211_mgmt reply;
1649 os_memset(&reply, 0, sizeof(reply));
1650 reply.frame_control =
1651 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1652 os_memcpy(reply.da, addr, ETH_ALEN);
1653 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1654 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1656 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1657 reply.u.deauth.reason_code = host_to_le16(reason_code);
1659 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1660 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1665 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1666 u16 status_code, int reassoc, const u8 *ies,
1670 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1671 struct ieee80211_mgmt *reply;
1674 os_memset(buf, 0, sizeof(buf));
1675 reply = (struct ieee80211_mgmt *) buf;
1676 reply->frame_control =
1677 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1678 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1679 WLAN_FC_STYPE_ASSOC_RESP));
1680 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1681 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1682 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1684 send_len = IEEE80211_HDRLEN;
1685 send_len += sizeof(reply->u.assoc_resp);
1686 reply->u.assoc_resp.capab_info =
1687 host_to_le16(hostapd_own_capab_info(hapd));
1688 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1689 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1690 /* Supported rates */
1691 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1692 /* Extended supported rates */
1693 p = hostapd_eid_ext_supp_rates(hapd, p);
1695 #ifdef CONFIG_IEEE80211R
1696 if (status_code == WLAN_STATUS_SUCCESS) {
1697 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1698 * Transition Information, RSN, [RIC Response] */
1699 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1700 buf + sizeof(buf) - p,
1701 sta->auth_alg, ies, ies_len);
1703 #endif /* CONFIG_IEEE80211R */
1705 #ifdef CONFIG_IEEE80211W
1706 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1707 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1708 #endif /* CONFIG_IEEE80211W */
1710 #ifdef CONFIG_IEEE80211N
1711 p = hostapd_eid_ht_capabilities(hapd, p);
1712 p = hostapd_eid_ht_operation(hapd, p);
1713 #endif /* CONFIG_IEEE80211N */
1715 #ifdef CONFIG_IEEE80211AC
1716 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1717 p = hostapd_eid_vht_capabilities(hapd, p);
1718 p = hostapd_eid_vht_operation(hapd, p);
1720 #endif /* CONFIG_IEEE80211AC */
1722 p = hostapd_eid_ext_capab(hapd, p);
1723 p = hostapd_eid_bss_max_idle_period(hapd, p);
1724 if (sta->qos_map_enabled)
1725 p = hostapd_eid_qos_map_set(hapd, p);
1728 if (hapd->iface->fst_ies) {
1729 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1730 wpabuf_len(hapd->iface->fst_ies));
1731 p += wpabuf_len(hapd->iface->fst_ies);
1733 #endif /* CONFIG_FST */
1735 #ifdef CONFIG_IEEE80211AC
1736 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1737 p = hostapd_eid_vendor_vht(hapd, p);
1738 #endif /* CONFIG_IEEE80211AC */
1740 if (sta->flags & WLAN_STA_WMM)
1741 p = hostapd_eid_wmm(hapd, p);
1744 if ((sta->flags & WLAN_STA_WPS) ||
1745 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1746 struct wpabuf *wps = wps_build_assoc_resp_ie();
1748 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1749 p += wpabuf_len(wps);
1753 #endif /* CONFIG_WPS */
1756 if (sta->p2p_ie && hapd->p2p_group) {
1757 struct wpabuf *p2p_resp_ie;
1758 enum p2p_status_code status;
1759 switch (status_code) {
1760 case WLAN_STATUS_SUCCESS:
1761 status = P2P_SC_SUCCESS;
1763 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1764 status = P2P_SC_FAIL_LIMIT_REACHED;
1767 status = P2P_SC_FAIL_INVALID_PARAMS;
1770 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1772 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1773 wpabuf_len(p2p_resp_ie));
1774 p += wpabuf_len(p2p_resp_ie);
1775 wpabuf_free(p2p_resp_ie);
1778 #endif /* CONFIG_P2P */
1780 #ifdef CONFIG_P2P_MANAGER
1781 if (hapd->conf->p2p & P2P_MANAGE)
1782 p = hostapd_eid_p2p_manage(hapd, p);
1783 #endif /* CONFIG_P2P_MANAGER */
1785 send_len += p - reply->u.assoc_resp.variable;
1787 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1788 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1793 static void handle_assoc(struct hostapd_data *hapd,
1794 const struct ieee80211_mgmt *mgmt, size_t len,
1797 u16 capab_info, listen_interval, seq_ctrl, fc;
1798 u16 resp = WLAN_STATUS_SUCCESS;
1801 struct sta_info *sta;
1803 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1804 sizeof(mgmt->u.assoc_req))) {
1805 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1806 reassoc, (unsigned long) len);
1810 #ifdef CONFIG_TESTING_OPTIONS
1812 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1813 drand48() < hapd->iconf->ignore_reassoc_probability) {
1814 wpa_printf(MSG_INFO,
1815 "TESTING: ignoring reassoc request from "
1816 MACSTR, MAC2STR(mgmt->sa));
1820 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1821 drand48() < hapd->iconf->ignore_assoc_probability) {
1822 wpa_printf(MSG_INFO,
1823 "TESTING: ignoring assoc request from "
1824 MACSTR, MAC2STR(mgmt->sa));
1828 #endif /* CONFIG_TESTING_OPTIONS */
1830 fc = le_to_host16(mgmt->frame_control);
1831 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1834 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1835 listen_interval = le_to_host16(
1836 mgmt->u.reassoc_req.listen_interval);
1837 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1838 " capab_info=0x%02x listen_interval=%d current_ap="
1839 MACSTR " seq_ctrl=0x%x%s",
1840 MAC2STR(mgmt->sa), capab_info, listen_interval,
1841 MAC2STR(mgmt->u.reassoc_req.current_ap),
1842 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1843 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1844 pos = mgmt->u.reassoc_req.variable;
1846 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1847 listen_interval = le_to_host16(
1848 mgmt->u.assoc_req.listen_interval);
1849 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1850 " capab_info=0x%02x listen_interval=%d "
1852 MAC2STR(mgmt->sa), capab_info, listen_interval,
1853 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1854 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1855 pos = mgmt->u.assoc_req.variable;
1858 sta = ap_get_sta(hapd, mgmt->sa);
1859 #ifdef CONFIG_IEEE80211R
1860 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1861 (sta->flags & WLAN_STA_AUTH) == 0) {
1862 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1863 "prior to authentication since it is using "
1864 "over-the-DS FT", MAC2STR(mgmt->sa));
1866 #endif /* CONFIG_IEEE80211R */
1867 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1868 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1869 HOSTAPD_LEVEL_INFO, "Station tried to "
1870 "associate before authentication "
1871 "(aid=%d flags=0x%x)",
1872 sta ? sta->aid : -1,
1873 sta ? sta->flags : 0);
1874 send_deauth(hapd, mgmt->sa,
1875 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1879 if ((fc & WLAN_FC_RETRY) &&
1880 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1881 sta->last_seq_ctrl == seq_ctrl &&
1882 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1883 WLAN_FC_STYPE_ASSOC_REQ) {
1884 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1885 HOSTAPD_LEVEL_DEBUG,
1886 "Drop repeated association frame seq_ctrl=0x%x",
1890 sta->last_seq_ctrl = seq_ctrl;
1891 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1892 WLAN_FC_STYPE_ASSOC_REQ;
1894 if (hapd->tkip_countermeasures) {
1895 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1899 if (listen_interval > hapd->conf->max_listen_interval) {
1900 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1901 HOSTAPD_LEVEL_DEBUG,
1902 "Too large Listen Interval (%d)",
1904 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1908 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1910 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1911 if (resp != WLAN_STATUS_SUCCESS)
1914 if (hostapd_get_aid(hapd, sta) < 0) {
1915 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1916 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1917 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1921 sta->capability = capab_info;
1922 sta->listen_interval = listen_interval;
1924 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1925 sta->flags |= WLAN_STA_NONERP;
1926 for (i = 0; i < sta->supported_rates_len; i++) {
1927 if ((sta->supported_rates[i] & 0x7f) > 22) {
1928 sta->flags &= ~WLAN_STA_NONERP;
1932 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1933 sta->nonerp_set = 1;
1934 hapd->iface->num_sta_non_erp++;
1935 if (hapd->iface->num_sta_non_erp == 1)
1936 ieee802_11_set_beacons(hapd->iface);
1939 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1940 !sta->no_short_slot_time_set) {
1941 sta->no_short_slot_time_set = 1;
1942 hapd->iface->num_sta_no_short_slot_time++;
1943 if (hapd->iface->current_mode->mode ==
1944 HOSTAPD_MODE_IEEE80211G &&
1945 hapd->iface->num_sta_no_short_slot_time == 1)
1946 ieee802_11_set_beacons(hapd->iface);
1949 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1950 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1952 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1954 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1955 !sta->no_short_preamble_set) {
1956 sta->no_short_preamble_set = 1;
1957 hapd->iface->num_sta_no_short_preamble++;
1958 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1959 && hapd->iface->num_sta_no_short_preamble == 1)
1960 ieee802_11_set_beacons(hapd->iface);
1963 #ifdef CONFIG_IEEE80211N
1964 update_ht_state(hapd, sta);
1965 #endif /* CONFIG_IEEE80211N */
1967 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1968 HOSTAPD_LEVEL_DEBUG,
1969 "association OK (aid %d)", sta->aid);
1970 /* Station will be marked associated, after it acknowledges AssocResp
1972 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1974 #ifdef CONFIG_IEEE80211W
1975 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1976 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1977 "SA Query procedure", reassoc ? "re" : "");
1978 /* TODO: Send a protected Disassociate frame to the STA using
1979 * the old key and Reason Code "Previous Authentication no
1980 * longer valid". Make sure this is only sent protected since
1981 * unprotected frame would be received by the STA that is now
1982 * trying to associate.
1985 #endif /* CONFIG_IEEE80211W */
1987 /* Make sure that the previously registered inactivity timer will not
1988 * remove the STA immediately. */
1989 sta->timeout_next = STA_NULLFUNC;
1992 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1996 static void handle_disassoc(struct hostapd_data *hapd,
1997 const struct ieee80211_mgmt *mgmt, size_t len)
1999 struct sta_info *sta;
2001 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
2002 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2003 (unsigned long) len);
2007 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2009 le_to_host16(mgmt->u.disassoc.reason_code));
2011 sta = ap_get_sta(hapd, mgmt->sa);
2013 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2018 ap_sta_set_authorized(hapd, sta, 0);
2019 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2020 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2021 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2022 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2023 HOSTAPD_LEVEL_INFO, "disassociated");
2024 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2025 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2026 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2028 accounting_sta_stop(hapd, sta);
2029 ieee802_1x_free_station(hapd, sta);
2031 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2032 ap_sta_ip6addr_del(hapd, sta);
2033 hostapd_drv_sta_remove(hapd, sta->addr);
2035 if (sta->timeout_next == STA_NULLFUNC ||
2036 sta->timeout_next == STA_DISASSOC) {
2037 sta->timeout_next = STA_DEAUTH;
2038 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2039 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2043 mlme_disassociate_indication(
2044 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2048 static void handle_deauth(struct hostapd_data *hapd,
2049 const struct ieee80211_mgmt *mgmt, size_t len)
2051 struct sta_info *sta;
2053 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2054 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2055 "payload (len=%lu)", (unsigned long) len);
2059 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2061 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2063 sta = ap_get_sta(hapd, mgmt->sa);
2065 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2066 "to deauthenticate, but it is not authenticated",
2071 ap_sta_set_authorized(hapd, sta, 0);
2072 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2073 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2074 WLAN_STA_ASSOC_REQ_OK);
2075 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2076 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2077 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2078 mlme_deauthenticate_indication(
2079 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2080 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2081 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2082 ap_free_sta(hapd, sta);
2086 static void handle_beacon(struct hostapd_data *hapd,
2087 const struct ieee80211_mgmt *mgmt, size_t len,
2088 struct hostapd_frame_info *fi)
2090 struct ieee802_11_elems elems;
2092 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2093 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2094 (unsigned long) len);
2098 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2099 len - (IEEE80211_HDRLEN +
2100 sizeof(mgmt->u.beacon)), &elems,
2103 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2107 #ifdef CONFIG_IEEE80211W
2109 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2110 const struct ieee80211_mgmt *mgmt,
2115 end = mgmt->u.action.u.sa_query_resp.trans_id +
2116 WLAN_SA_QUERY_TR_ID_LEN;
2117 if (((u8 *) mgmt) + len < end) {
2118 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2119 "frame (len=%lu)", (unsigned long) len);
2123 ieee802_11_sa_query_action(hapd, mgmt->sa,
2124 mgmt->u.action.u.sa_query_resp.action,
2125 mgmt->u.action.u.sa_query_resp.trans_id);
2130 static int robust_action_frame(u8 category)
2132 return category != WLAN_ACTION_PUBLIC &&
2133 category != WLAN_ACTION_HT;
2135 #endif /* CONFIG_IEEE80211W */
2138 static int handle_action(struct hostapd_data *hapd,
2139 const struct ieee80211_mgmt *mgmt, size_t len)
2141 struct sta_info *sta;
2142 sta = ap_get_sta(hapd, mgmt->sa);
2144 if (len < IEEE80211_HDRLEN + 1) {
2145 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2146 HOSTAPD_LEVEL_DEBUG,
2147 "handle_action - too short payload (len=%lu)",
2148 (unsigned long) len);
2152 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2153 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2154 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2155 "frame (category=%u) from unassociated STA " MACSTR,
2156 MAC2STR(mgmt->sa), mgmt->u.action.category);
2160 #ifdef CONFIG_IEEE80211W
2161 if (sta && (sta->flags & WLAN_STA_MFP) &&
2162 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2163 robust_action_frame(mgmt->u.action.category)) {
2164 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2165 HOSTAPD_LEVEL_DEBUG,
2166 "Dropped unprotected Robust Action frame from "
2170 #endif /* CONFIG_IEEE80211W */
2173 u16 fc = le_to_host16(mgmt->frame_control);
2174 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2176 if ((fc & WLAN_FC_RETRY) &&
2177 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2178 sta->last_seq_ctrl == seq_ctrl &&
2179 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2180 hostapd_logger(hapd, sta->addr,
2181 HOSTAPD_MODULE_IEEE80211,
2182 HOSTAPD_LEVEL_DEBUG,
2183 "Drop repeated action frame seq_ctrl=0x%x",
2188 sta->last_seq_ctrl = seq_ctrl;
2189 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2192 switch (mgmt->u.action.category) {
2193 #ifdef CONFIG_IEEE80211R
2194 case WLAN_ACTION_FT:
2196 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2197 len - IEEE80211_HDRLEN))
2200 #endif /* CONFIG_IEEE80211R */
2201 case WLAN_ACTION_WMM:
2202 hostapd_wmm_action(hapd, mgmt, len);
2204 #ifdef CONFIG_IEEE80211W
2205 case WLAN_ACTION_SA_QUERY:
2206 return hostapd_sa_query_action(hapd, mgmt, len);
2207 #endif /* CONFIG_IEEE80211W */
2209 case WLAN_ACTION_WNM:
2210 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2212 #endif /* CONFIG_WNM */
2214 case WLAN_ACTION_FST:
2215 if (hapd->iface->fst)
2216 fst_rx_action(hapd->iface->fst, mgmt, len);
2218 wpa_printf(MSG_DEBUG,
2219 "FST: Ignore FST Action frame - no FST attached");
2221 #endif /* CONFIG_FST */
2222 case WLAN_ACTION_PUBLIC:
2223 case WLAN_ACTION_PROTECTED_DUAL:
2224 #ifdef CONFIG_IEEE80211N
2225 if (len >= IEEE80211_HDRLEN + 2 &&
2226 mgmt->u.action.u.public_action.action ==
2227 WLAN_PA_20_40_BSS_COEX) {
2228 wpa_printf(MSG_DEBUG,
2229 "HT20/40 coex mgmt frame received from STA "
2230 MACSTR, MAC2STR(mgmt->sa));
2231 hostapd_2040_coex_action(hapd, mgmt, len);
2233 #endif /* CONFIG_IEEE80211N */
2234 if (hapd->public_action_cb) {
2235 hapd->public_action_cb(hapd->public_action_cb_ctx,
2239 if (hapd->public_action_cb2) {
2240 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2244 if (hapd->public_action_cb || hapd->public_action_cb2)
2247 case WLAN_ACTION_VENDOR_SPECIFIC:
2248 if (hapd->vendor_action_cb) {
2249 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2251 hapd->iface->freq) == 0)
2257 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2258 HOSTAPD_LEVEL_DEBUG,
2259 "handle_action - unknown action category %d or invalid "
2261 mgmt->u.action.category);
2262 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2263 !(mgmt->sa[0] & 0x01)) {
2264 struct ieee80211_mgmt *resp;
2267 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2268 * Return the Action frame to the source without change
2269 * except that MSB of the Category set to 1.
2271 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2272 "frame back to sender");
2273 resp = os_malloc(len);
2276 os_memcpy(resp, mgmt, len);
2277 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2278 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2279 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2280 resp->u.action.category |= 0x80;
2282 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2283 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2294 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2295 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2297 * @buf: management frame data (starting from IEEE 802.11 header)
2298 * @len: length of frame data in octets
2299 * @fi: meta data about received frame (signal level, etc.)
2301 * Process all incoming IEEE 802.11 management frames. This will be called for
2302 * each frame received from the kernel driver through wlan#ap interface. In
2303 * addition, it can be called to re-inserted pending frames (e.g., when using
2304 * external RADIUS server as an MAC ACL).
2306 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2307 struct hostapd_frame_info *fi)
2309 struct ieee80211_mgmt *mgmt;
2317 mgmt = (struct ieee80211_mgmt *) buf;
2318 fc = le_to_host16(mgmt->frame_control);
2319 stype = WLAN_FC_GET_STYPE(fc);
2321 if (stype == WLAN_FC_STYPE_BEACON) {
2322 handle_beacon(hapd, mgmt, len, fi);
2326 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2327 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2328 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2332 /* Invitation responses can be sent with the peer MAC as BSSID */
2333 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2334 stype == WLAN_FC_STYPE_ACTION) &&
2335 #endif /* CONFIG_P2P */
2337 !(hapd->conf->mesh & MESH_ENABLED) &&
2338 #endif /* CONFIG_MESH */
2339 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2340 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2341 MAC2STR(mgmt->bssid));
2346 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2347 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2351 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2352 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2353 HOSTAPD_LEVEL_DEBUG,
2354 "MGMT: DA=" MACSTR " not our address",
2359 if (hapd->iconf->track_sta_max_num)
2360 sta_track_add(hapd->iface, mgmt->sa);
2363 case WLAN_FC_STYPE_AUTH:
2364 wpa_printf(MSG_DEBUG, "mgmt::auth");
2365 handle_auth(hapd, mgmt, len);
2368 case WLAN_FC_STYPE_ASSOC_REQ:
2369 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2370 handle_assoc(hapd, mgmt, len, 0);
2373 case WLAN_FC_STYPE_REASSOC_REQ:
2374 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2375 handle_assoc(hapd, mgmt, len, 1);
2378 case WLAN_FC_STYPE_DISASSOC:
2379 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2380 handle_disassoc(hapd, mgmt, len);
2383 case WLAN_FC_STYPE_DEAUTH:
2384 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2385 handle_deauth(hapd, mgmt, len);
2388 case WLAN_FC_STYPE_ACTION:
2389 wpa_printf(MSG_DEBUG, "mgmt::action");
2390 ret = handle_action(hapd, mgmt, len);
2393 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2394 HOSTAPD_LEVEL_DEBUG,
2395 "unknown mgmt frame subtype %d", stype);
2403 static void handle_auth_cb(struct hostapd_data *hapd,
2404 const struct ieee80211_mgmt *mgmt,
2407 u16 auth_alg, auth_transaction, status_code;
2408 struct sta_info *sta;
2411 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2412 HOSTAPD_LEVEL_NOTICE,
2413 "did not acknowledge authentication response");
2417 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2418 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2419 (unsigned long) len);
2423 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2424 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2425 status_code = le_to_host16(mgmt->u.auth.status_code);
2427 sta = ap_get_sta(hapd, mgmt->da);
2429 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2434 if (status_code == WLAN_STATUS_SUCCESS &&
2435 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2436 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2437 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2438 HOSTAPD_LEVEL_INFO, "authenticated");
2439 sta->flags |= WLAN_STA_AUTH;
2444 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2445 struct sta_info *sta,
2449 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2451 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2454 for (i = 0; i < 4; i++) {
2455 if (ssid->wep.key[i] &&
2456 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2457 i == ssid->wep.idx, NULL, 0,
2458 ssid->wep.key[i], ssid->wep.len[i])) {
2459 wpa_printf(MSG_WARNING,
2460 "Could not set WEP keys for WDS interface; %s",
2468 static void handle_assoc_cb(struct hostapd_data *hapd,
2469 const struct ieee80211_mgmt *mgmt,
2470 size_t len, int reassoc, int ok)
2473 struct sta_info *sta;
2475 struct ieee80211_ht_capabilities ht_cap;
2476 struct ieee80211_vht_capabilities vht_cap;
2478 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2479 sizeof(mgmt->u.assoc_resp))) {
2480 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2481 reassoc, (unsigned long) len);
2485 sta = ap_get_sta(hapd, mgmt->da);
2487 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2493 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2494 HOSTAPD_LEVEL_DEBUG,
2495 "did not acknowledge association response");
2496 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2501 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2503 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2505 if (status != WLAN_STATUS_SUCCESS)
2508 /* Stop previous accounting session, if one is started, and allocate
2509 * new session id for the new session. */
2510 accounting_sta_stop(hapd, sta);
2512 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2514 "associated (aid %d)",
2517 if (sta->flags & WLAN_STA_ASSOC)
2519 sta->flags |= WLAN_STA_ASSOC;
2520 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2521 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2522 sta->auth_alg == WLAN_AUTH_FT) {
2524 * Open, static WEP, or FT protocol; no separate authorization
2527 ap_sta_set_authorized(hapd, sta, 1);
2531 mlme_reassociate_indication(hapd, sta);
2533 mlme_associate_indication(hapd, sta);
2535 #ifdef CONFIG_IEEE80211W
2536 sta->sa_query_timed_out = 0;
2537 #endif /* CONFIG_IEEE80211W */
2540 * Remove the STA entry in order to make sure the STA PS state gets
2541 * cleared and configuration gets updated in case of reassociation back
2544 hostapd_drv_sta_remove(hapd, sta->addr);
2546 #ifdef CONFIG_IEEE80211N
2547 if (sta->flags & WLAN_STA_HT)
2548 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2549 #endif /* CONFIG_IEEE80211N */
2550 #ifdef CONFIG_IEEE80211AC
2551 if (sta->flags & WLAN_STA_VHT)
2552 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2553 #endif /* CONFIG_IEEE80211AC */
2555 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2556 sta->supported_rates, sta->supported_rates_len,
2557 sta->listen_interval,
2558 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
2559 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
2560 sta->flags, sta->qosinfo, sta->vht_opmode)) {
2561 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2562 HOSTAPD_LEVEL_NOTICE,
2563 "Could not add STA to kernel driver");
2565 ap_sta_disconnect(hapd, sta, sta->addr,
2566 WLAN_REASON_DISASSOC_AP_BUSY);
2571 if (sta->flags & WLAN_STA_WDS) {
2573 char ifname_wds[IFNAMSIZ + 1];
2575 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2578 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2581 if (sta->eapol_sm == NULL) {
2583 * This STA does not use RADIUS server for EAP authentication,
2584 * so bind it to the selected VLAN interface now, since the
2585 * interface selection is not going to change anymore.
2587 if (ap_sta_bind_vlan(hapd, sta) < 0)
2589 } else if (sta->vlan_id) {
2590 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2591 if (ap_sta_bind_vlan(hapd, sta) < 0)
2595 hostapd_set_sta_flags(hapd, sta);
2597 if (sta->auth_alg == WLAN_AUTH_FT)
2598 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2600 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2601 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2603 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2607 static void handle_deauth_cb(struct hostapd_data *hapd,
2608 const struct ieee80211_mgmt *mgmt,
2611 struct sta_info *sta;
2612 if (mgmt->da[0] & 0x01)
2614 sta = ap_get_sta(hapd, mgmt->da);
2616 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2617 " not found", MAC2STR(mgmt->da));
2621 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2622 MAC2STR(sta->addr));
2624 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2625 "deauth", MAC2STR(sta->addr));
2627 ap_sta_deauth_cb(hapd, sta);
2631 static void handle_disassoc_cb(struct hostapd_data *hapd,
2632 const struct ieee80211_mgmt *mgmt,
2635 struct sta_info *sta;
2636 if (mgmt->da[0] & 0x01)
2638 sta = ap_get_sta(hapd, mgmt->da);
2640 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2641 " not found", MAC2STR(mgmt->da));
2645 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2646 MAC2STR(sta->addr));
2648 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2649 "disassoc", MAC2STR(sta->addr));
2651 ap_sta_disassoc_cb(hapd, sta);
2656 * ieee802_11_mgmt_cb - Process management frame TX status callback
2657 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2659 * @buf: management frame data (starting from IEEE 802.11 header)
2660 * @len: length of frame data in octets
2661 * @stype: management frame subtype from frame control field
2662 * @ok: Whether the frame was ACK'ed
2664 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2667 const struct ieee80211_mgmt *mgmt;
2668 mgmt = (const struct ieee80211_mgmt *) buf;
2670 #ifdef CONFIG_TESTING_OPTIONS
2671 if (hapd->ext_mgmt_frame_handling) {
2672 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2676 #endif /* CONFIG_TESTING_OPTIONS */
2679 case WLAN_FC_STYPE_AUTH:
2680 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2681 handle_auth_cb(hapd, mgmt, len, ok);
2683 case WLAN_FC_STYPE_ASSOC_RESP:
2684 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2685 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2687 case WLAN_FC_STYPE_REASSOC_RESP:
2688 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2689 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2691 case WLAN_FC_STYPE_PROBE_RESP:
2692 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2694 case WLAN_FC_STYPE_DEAUTH:
2695 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2696 handle_deauth_cb(hapd, mgmt, len, ok);
2698 case WLAN_FC_STYPE_DISASSOC:
2699 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2700 handle_disassoc_cb(hapd, mgmt, len, ok);
2702 case WLAN_FC_STYPE_ACTION:
2703 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2706 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2712 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2719 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2720 char *buf, size_t buflen)
2727 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2728 const u8 *buf, size_t len, int ack)
2730 struct sta_info *sta;
2731 struct hostapd_iface *iface = hapd->iface;
2733 sta = ap_get_sta(hapd, addr);
2734 if (sta == NULL && iface->num_bss > 1) {
2736 for (j = 0; j < iface->num_bss; j++) {
2737 hapd = iface->bss[j];
2738 sta = ap_get_sta(hapd, addr);
2743 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2745 if (sta->flags & WLAN_STA_PENDING_POLL) {
2746 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2747 "activity poll", MAC2STR(sta->addr),
2748 ack ? "ACKed" : "did not ACK");
2750 sta->flags &= ~WLAN_STA_PENDING_POLL;
2753 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2757 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2758 const u8 *data, size_t len, int ack)
2760 struct sta_info *sta;
2761 struct hostapd_iface *iface = hapd->iface;
2763 sta = ap_get_sta(hapd, dst);
2764 if (sta == NULL && iface->num_bss > 1) {
2766 for (j = 0; j < iface->num_bss; j++) {
2767 hapd = iface->bss[j];
2768 sta = ap_get_sta(hapd, dst);
2773 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2774 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2775 MACSTR " that is not currently associated",
2780 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2784 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2786 struct sta_info *sta;
2787 struct hostapd_iface *iface = hapd->iface;
2789 sta = ap_get_sta(hapd, addr);
2790 if (sta == NULL && iface->num_bss > 1) {
2792 for (j = 0; j < iface->num_bss; j++) {
2793 hapd = iface->bss[j];
2794 sta = ap_get_sta(hapd, addr);
2801 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2804 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2805 "activity poll", MAC2STR(sta->addr));
2806 sta->flags &= ~WLAN_STA_PENDING_POLL;
2810 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2813 struct sta_info *sta;
2815 sta = ap_get_sta(hapd, src);
2816 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2817 if (!hapd->conf->wds_sta)
2820 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2822 char ifname_wds[IFNAMSIZ + 1];
2824 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2825 "STA " MACSTR " (aid %u)",
2826 MAC2STR(sta->addr), sta->aid);
2827 sta->flags |= WLAN_STA_WDS;
2828 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2829 sta->addr, sta->aid, 1);
2831 hostapd_set_wds_encryption(hapd, sta,
2837 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2838 MACSTR, MAC2STR(src));
2839 if (src[0] & 0x01) {
2840 /* Broadcast bit set in SA?! Ignore the frame silently. */
2844 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2845 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2846 "already been sent, but no TX status yet known - "
2847 "ignore Class 3 frame issue with " MACSTR,
2852 if (sta && (sta->flags & WLAN_STA_AUTH))
2853 hostapd_drv_sta_disassoc(
2855 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2857 hostapd_drv_sta_deauth(
2859 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2863 #endif /* CONFIG_NATIVE_WINDOWS */