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 */
212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
218 os_memcpy(key, &now.sec, 4);
219 os_memcpy(key + 4, &r, 4);
220 rc4_skip(key, sizeof(key), 0,
221 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
226 if (auth_transaction != 3)
227 return WLAN_STATUS_UNSPECIFIED_FAILURE;
230 if (!iswep || !sta->challenge || !challenge ||
231 os_memcmp_const(sta->challenge, challenge,
232 WLAN_AUTH_CHALLENGE_LEN)) {
233 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
235 "shared key authentication - invalid "
236 "challenge-response");
237 return WLAN_STATUS_CHALLENGE_FAIL;
240 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
242 "authentication OK (shared key)");
243 sta->flags |= WLAN_STA_AUTH;
244 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
245 os_free(sta->challenge);
246 sta->challenge = NULL;
250 #endif /* CONFIG_NO_RC4 */
253 static void send_auth_reply(struct hostapd_data *hapd,
254 const u8 *dst, const u8 *bssid,
255 u16 auth_alg, u16 auth_transaction, u16 resp,
256 const u8 *ies, size_t ies_len)
258 struct ieee80211_mgmt *reply;
262 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
263 buf = os_zalloc(rlen);
267 reply = (struct ieee80211_mgmt *) buf;
268 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
270 os_memcpy(reply->da, dst, ETH_ALEN);
271 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
272 os_memcpy(reply->bssid, bssid, ETH_ALEN);
274 reply->u.auth.auth_alg = host_to_le16(auth_alg);
275 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
276 reply->u.auth.status_code = host_to_le16(resp);
279 os_memcpy(reply->u.auth.variable, ies, ies_len);
281 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
282 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
283 MAC2STR(dst), auth_alg, auth_transaction,
284 resp, (unsigned long) ies_len);
285 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
286 wpa_printf(MSG_INFO, "send_auth_reply: send");
292 #ifdef CONFIG_IEEE80211R
293 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
294 u16 auth_transaction, u16 status,
295 const u8 *ies, size_t ies_len)
297 struct hostapd_data *hapd = ctx;
298 struct sta_info *sta;
300 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
301 status, ies, ies_len);
303 if (status != WLAN_STATUS_SUCCESS)
306 sta = ap_get_sta(hapd, dst);
310 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
311 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
312 sta->flags |= WLAN_STA_AUTH;
313 mlme_authenticate_indication(hapd, sta);
315 #endif /* CONFIG_IEEE80211R */
320 #define dot11RSNASAESync 5 /* attempts */
323 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
324 struct sta_info *sta, int update)
328 if (hapd->conf->ssid.wpa_passphrase == NULL) {
329 wpa_printf(MSG_DEBUG, "SAE: No password available");
334 sae_prepare_commit(hapd->own_addr, sta->addr,
335 (u8 *) hapd->conf->ssid.wpa_passphrase,
336 os_strlen(hapd->conf->ssid.wpa_passphrase),
338 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
342 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
345 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
346 sta->sae->tmp->anti_clogging_token : NULL);
352 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
353 struct sta_info *sta)
357 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
361 sae_write_confirm(sta->sae, buf);
367 static int auth_sae_send_commit(struct hostapd_data *hapd,
368 struct sta_info *sta,
369 const u8 *bssid, int update)
373 data = auth_build_sae_commit(hapd, sta, update);
375 return WLAN_STATUS_UNSPECIFIED_FAILURE;
377 send_auth_reply(hapd, sta->addr, bssid,
378 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
379 wpabuf_head(data), wpabuf_len(data));
383 return WLAN_STATUS_SUCCESS;
387 static int auth_sae_send_confirm(struct hostapd_data *hapd,
388 struct sta_info *sta,
393 data = auth_build_sae_confirm(hapd, sta);
395 return WLAN_STATUS_UNSPECIFIED_FAILURE;
397 send_auth_reply(hapd, sta->addr, bssid,
398 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
399 wpabuf_head(data), wpabuf_len(data));
403 return WLAN_STATUS_SUCCESS;
407 static int use_sae_anti_clogging(struct hostapd_data *hapd)
409 struct sta_info *sta;
410 unsigned int open = 0;
412 if (hapd->conf->sae_anti_clogging_threshold == 0)
415 for (sta = hapd->sta_list; sta; sta = sta->next) {
418 if (sta->sae->state != SAE_COMMITTED &&
419 sta->sae->state != SAE_CONFIRMED)
422 if (open >= hapd->conf->sae_anti_clogging_threshold)
430 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
431 const u8 *token, size_t token_len)
433 u8 mac[SHA256_MAC_LEN];
435 if (token_len != SHA256_MAC_LEN)
437 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
438 addr, ETH_ALEN, mac) < 0 ||
439 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
446 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
447 int group, const u8 *addr)
451 struct os_reltime now;
453 os_get_reltime(&now);
454 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
455 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
456 if (random_get_bytes(hapd->sae_token_key,
457 sizeof(hapd->sae_token_key)) < 0)
459 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
460 hapd->sae_token_key, sizeof(hapd->sae_token_key));
461 hapd->last_sae_token_key_update = now;
464 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
468 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
470 token = wpabuf_put(buf, SHA256_MAC_LEN);
471 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
472 addr, ETH_ALEN, token);
478 static int sae_check_big_sync(struct sta_info *sta)
480 if (sta->sae->sync > dot11RSNASAESync) {
481 sta->sae->state = SAE_NOTHING;
489 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
491 struct hostapd_data *hapd = eloop_ctx;
492 struct sta_info *sta = eloop_data;
495 if (sae_check_big_sync(sta))
499 switch (sta->sae->state) {
501 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
502 eloop_register_timeout(0,
503 hapd->dot11RSNASAERetransPeriod * 1000,
504 auth_sae_retransmit_timer, hapd, sta);
507 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
508 eloop_register_timeout(0,
509 hapd->dot11RSNASAERetransPeriod * 1000,
510 auth_sae_retransmit_timer, hapd, sta);
517 if (ret != WLAN_STATUS_SUCCESS)
518 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
522 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
524 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
528 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
529 struct sta_info *sta)
531 if (!(hapd->conf->mesh & MESH_ENABLED))
534 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
535 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
536 auth_sae_retransmit_timer, hapd, sta);
540 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
541 const u8 *bssid, u8 auth_transaction)
545 if (auth_transaction != 1 && auth_transaction != 2)
546 return WLAN_STATUS_UNSPECIFIED_FAILURE;
548 switch (sta->sae->state) {
550 if (auth_transaction == 1) {
551 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
554 sta->sae->state = SAE_COMMITTED;
556 if (sae_process_commit(sta->sae) < 0)
557 return WLAN_STATUS_UNSPECIFIED_FAILURE;
560 * In mesh case, both Commit and Confirm can be sent
561 * immediately. In infrastructure BSS, only a single
562 * Authentication frame (Commit) is expected from the AP
563 * here and the second one (Confirm) will be sent once
564 * the STA has sent its second Authentication frame
567 if (hapd->conf->mesh & MESH_ENABLED) {
569 * Send both Commit and Confirm immediately
570 * based on SAE finite state machine
571 * Nothing -> Confirm transition.
573 ret = auth_sae_send_confirm(hapd, sta, bssid);
576 sta->sae->state = SAE_CONFIRMED;
579 * For infrastructure BSS, send only the Commit
580 * message now to get alternating sequence of
581 * Authentication frames between the AP and STA.
582 * Confirm will be sent in
583 * Commited -> Confirmed/Accepted transition
584 * when receiving Confirm from STA.
588 sae_set_retransmit_timer(hapd, sta);
590 hostapd_logger(hapd, sta->addr,
591 HOSTAPD_MODULE_IEEE80211,
593 "SAE confirm before commit");
597 sae_clear_retransmit_timer(hapd, sta);
598 if (auth_transaction == 1) {
599 if (sae_process_commit(sta->sae) < 0)
600 return WLAN_STATUS_UNSPECIFIED_FAILURE;
602 ret = auth_sae_send_confirm(hapd, sta, bssid);
605 sta->sae->state = SAE_CONFIRMED;
607 sae_set_retransmit_timer(hapd, sta);
608 } else if (hapd->conf->mesh & MESH_ENABLED) {
610 * In mesh case, follow SAE finite state machine and
611 * send Commit now, if sync count allows.
613 if (sae_check_big_sync(sta))
614 return WLAN_STATUS_SUCCESS;
617 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
621 sae_set_retransmit_timer(hapd, sta);
624 * For instructure BSS, send the postponed Confirm from
625 * Nothing -> Confirmed transition that was reduced to
626 * Nothing -> Committed above.
628 ret = auth_sae_send_confirm(hapd, sta, bssid);
632 sta->sae->state = SAE_CONFIRMED;
635 * Since this was triggered on Confirm RX, run another
636 * step to get to Accepted without waiting for
639 return sae_sm_step(hapd, sta, bssid, auth_transaction);
643 sae_clear_retransmit_timer(hapd, sta);
644 if (auth_transaction == 1) {
645 if (sae_check_big_sync(sta))
646 return WLAN_STATUS_SUCCESS;
649 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
653 if (sae_process_commit(sta->sae) < 0)
654 return WLAN_STATUS_UNSPECIFIED_FAILURE;
656 ret = auth_sae_send_confirm(hapd, sta, bssid);
660 sae_set_retransmit_timer(hapd, sta);
662 sta->flags |= WLAN_STA_AUTH;
663 sta->auth_alg = WLAN_AUTH_SAE;
664 mlme_authenticate_indication(hapd, sta);
665 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
666 sta->sae->state = SAE_ACCEPTED;
667 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
672 if (auth_transaction == 1) {
673 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
674 ") doing reauthentication",
676 ap_free_sta(hapd, sta);
678 if (sae_check_big_sync(sta))
679 return WLAN_STATUS_SUCCESS;
682 ret = auth_sae_send_confirm(hapd, sta, bssid);
683 sae_clear_temp_data(sta->sae);
689 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
691 return WLAN_STATUS_UNSPECIFIED_FAILURE;
693 return WLAN_STATUS_SUCCESS;
697 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
698 const struct ieee80211_mgmt *mgmt, size_t len,
699 u16 auth_transaction, u16 status_code)
701 u16 resp = WLAN_STATUS_SUCCESS;
702 struct wpabuf *data = NULL;
705 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
707 sta->sae = os_zalloc(sizeof(*sta->sae));
708 if (sta->sae == NULL)
710 sta->sae->state = SAE_NOTHING;
714 if (auth_transaction == 1) {
715 const u8 *token = NULL, *pos, *end;
716 size_t token_len = 0;
717 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
719 "start SAE authentication (RX commit, status=%u)",
722 if ((hapd->conf->mesh & MESH_ENABLED) &&
723 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
725 pos = mgmt->u.auth.variable;
726 end = ((const u8 *) mgmt) + len;
727 if (pos + sizeof(le16) > end) {
728 wpa_printf(MSG_ERROR,
729 "SAE: Too short anti-clogging token request");
730 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
733 resp = sae_group_allowed(sta->sae,
734 hapd->conf->sae_groups,
736 if (resp != WLAN_STATUS_SUCCESS) {
737 wpa_printf(MSG_ERROR,
738 "SAE: Invalid group in anti-clogging token request");
743 wpabuf_free(sta->sae->tmp->anti_clogging_token);
744 sta->sae->tmp->anti_clogging_token =
745 wpabuf_alloc_copy(pos, end - pos);
746 if (sta->sae->tmp->anti_clogging_token == NULL) {
747 wpa_printf(MSG_ERROR,
748 "SAE: Failed to alloc for anti-clogging token");
753 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
754 * is 76, a new Commit Message shall be constructed
755 * with the Anti-Clogging Token from the received
756 * Authentication frame, and the commit-scalar and
757 * COMMIT-ELEMENT previously sent.
759 if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) {
760 wpa_printf(MSG_ERROR,
761 "SAE: Failed to send commit message");
764 sta->sae->state = SAE_COMMITTED;
766 sae_set_retransmit_timer(hapd, sta);
770 if (status_code != WLAN_STATUS_SUCCESS)
773 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
774 ((const u8 *) mgmt) + len -
775 mgmt->u.auth.variable, &token,
776 &token_len, hapd->conf->sae_groups);
777 if (resp == SAE_SILENTLY_DISCARD) {
778 wpa_printf(MSG_DEBUG,
779 "SAE: Drop commit message from " MACSTR " due to reflection attack",
783 if (token && check_sae_token(hapd, sta->addr, token, token_len)
785 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
786 "incorrect token from " MACSTR,
791 if (resp != WLAN_STATUS_SUCCESS)
794 if (!token && use_sae_anti_clogging(hapd)) {
795 wpa_printf(MSG_DEBUG,
796 "SAE: Request anti-clogging token from "
797 MACSTR, MAC2STR(sta->addr));
798 data = auth_build_token_req(hapd, sta->sae->group,
800 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
801 if (hapd->conf->mesh & MESH_ENABLED)
802 sta->sae->state = SAE_NOTHING;
806 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
807 } else if (auth_transaction == 2) {
808 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
810 "SAE authentication (RX confirm, status=%u)",
812 if (status_code != WLAN_STATUS_SUCCESS)
814 if (sta->sae->state >= SAE_CONFIRMED ||
815 !(hapd->conf->mesh & MESH_ENABLED)) {
816 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
817 ((u8 *) mgmt) + len -
818 mgmt->u.auth.variable) < 0) {
819 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
823 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
825 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
827 "unexpected SAE authentication transaction %u (status=%u)",
828 auth_transaction, status_code);
829 if (status_code != WLAN_STATUS_SUCCESS)
831 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
835 if (resp != WLAN_STATUS_SUCCESS) {
836 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
837 auth_transaction, resp,
838 data ? wpabuf_head(data) : (u8 *) "",
839 data ? wpabuf_len(data) : 0);
846 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
847 * @hapd: BSS data for the device initiating the authentication
848 * @sta: the peer to which commit authentication frame is sent
850 * This function implements Init event handling (IEEE Std 802.11-2012,
851 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
852 * sta->sae structure should be initialized appropriately via a call to
853 * sae_prepare_commit().
855 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
859 if (!sta->sae || !sta->sae->tmp)
862 if (sta->sae->state != SAE_NOTHING)
865 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
869 sta->sae->state = SAE_COMMITTED;
871 sae_set_retransmit_timer(hapd, sta);
876 #endif /* CONFIG_SAE */
879 static void handle_auth(struct hostapd_data *hapd,
880 const struct ieee80211_mgmt *mgmt, size_t len)
882 u16 auth_alg, auth_transaction, status_code;
883 u16 resp = WLAN_STATUS_SUCCESS;
884 struct sta_info *sta = NULL;
887 const u8 *challenge = NULL;
888 u32 session_timeout, acct_interim_interval;
889 struct vlan_description vlan_id;
890 struct hostapd_sta_wpa_psk_short *psk = NULL;
891 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
892 size_t resp_ies_len = 0;
893 char *identity = NULL;
894 char *radius_cui = NULL;
897 os_memset(&vlan_id, 0, sizeof(vlan_id));
899 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
900 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
901 (unsigned long) len);
905 #ifdef CONFIG_TESTING_OPTIONS
906 if (hapd->iconf->ignore_auth_probability > 0.0 &&
907 drand48() < hapd->iconf->ignore_auth_probability) {
909 "TESTING: ignoring auth frame from " MACSTR,
913 #endif /* CONFIG_TESTING_OPTIONS */
915 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
916 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
917 status_code = le_to_host16(mgmt->u.auth.status_code);
918 fc = le_to_host16(mgmt->frame_control);
919 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
921 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
922 2 + WLAN_AUTH_CHALLENGE_LEN &&
923 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
924 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
925 challenge = &mgmt->u.auth.variable[2];
927 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
928 "auth_transaction=%d status_code=%d wep=%d%s "
930 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
931 status_code, !!(fc & WLAN_FC_ISWEP),
932 challenge ? " challenge" : "",
933 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
936 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
938 "Unsupported authentication algorithm (%d)",
940 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
943 #endif /* CONFIG_NO_RC4 */
945 if (hapd->tkip_countermeasures) {
946 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
950 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
951 auth_alg == WLAN_AUTH_OPEN) ||
952 #ifdef CONFIG_IEEE80211R
953 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
954 auth_alg == WLAN_AUTH_FT) ||
955 #endif /* CONFIG_IEEE80211R */
957 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
958 auth_alg == WLAN_AUTH_SAE) ||
959 #endif /* CONFIG_SAE */
960 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
961 auth_alg == WLAN_AUTH_SHARED_KEY))) {
962 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
964 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
968 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
969 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
970 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
972 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
976 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
977 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
979 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
983 if (hapd->conf->no_auth_if_seen_on) {
984 struct hostapd_data *other;
986 other = sta_track_seen_on(hapd->iface, mgmt->sa,
987 hapd->conf->no_auth_if_seen_on);
991 u8 op_class, channel, phytype;
993 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
994 MACSTR " since STA has been seen on %s",
995 hapd->conf->iface, MAC2STR(mgmt->sa),
996 hapd->conf->no_auth_if_seen_on);
998 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1000 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1002 os_memcpy(pos, other->own_addr, ETH_ALEN);
1004 info = 0; /* TODO: BSSID Information */
1005 WPA_PUT_LE32(pos, info);
1007 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1008 phytype = 8; /* dmg */
1009 else if (other->iconf->ieee80211ac)
1010 phytype = 9; /* vht */
1011 else if (other->iconf->ieee80211n)
1012 phytype = 7; /* ht */
1013 else if (other->iconf->hw_mode ==
1014 HOSTAPD_MODE_IEEE80211A)
1015 phytype = 4; /* ofdm */
1016 else if (other->iconf->hw_mode ==
1017 HOSTAPD_MODE_IEEE80211G)
1018 phytype = 6; /* erp */
1020 phytype = 5; /* hrdsss */
1021 if (ieee80211_freq_to_channel_ext(
1022 hostapd_hw_get_freq(other,
1023 other->iconf->channel),
1024 other->iconf->secondary_channel,
1025 other->iconf->ieee80211ac,
1026 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1028 channel = other->iconf->channel;
1033 resp_ies_len = pos - &resp_ies[0];
1038 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1040 &acct_interim_interval, &vlan_id,
1041 &psk, &identity, &radius_cui);
1043 if (res == HOSTAPD_ACL_REJECT) {
1044 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1046 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1049 if (res == HOSTAPD_ACL_PENDING) {
1050 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1051 " waiting for an external authentication",
1053 /* Authentication code will re-send the authentication frame
1054 * after it has received (and cached) information from the
1055 * external source. */
1059 sta = ap_get_sta(hapd, mgmt->sa);
1061 if ((fc & WLAN_FC_RETRY) &&
1062 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1063 sta->last_seq_ctrl == seq_ctrl &&
1064 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1065 hostapd_logger(hapd, sta->addr,
1066 HOSTAPD_MODULE_IEEE80211,
1067 HOSTAPD_LEVEL_DEBUG,
1068 "Drop repeated authentication frame seq_ctrl=0x%x",
1074 if (hapd->conf->mesh & MESH_ENABLED) {
1075 /* if the mesh peer is not available, we don't do auth.
1077 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1078 " not yet known - drop Authentiation frame",
1081 * Save a copy of the frame so that it can be processed
1082 * if a new peer entry is added shortly after this.
1084 wpabuf_free(hapd->mesh_pending_auth);
1085 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1086 os_get_reltime(&hapd->mesh_pending_auth_time);
1089 #endif /* CONFIG_MESH */
1091 sta = ap_sta_add(hapd, mgmt->sa);
1093 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1097 sta->last_seq_ctrl = seq_ctrl;
1098 sta->last_subtype = WLAN_FC_STYPE_AUTH;
1100 if (vlan_id.notempty) {
1101 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1102 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1104 "Invalid VLAN %d received from RADIUS server",
1106 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1109 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1110 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1113 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1114 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1117 hostapd_free_psk_list(sta->psk);
1118 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1125 sta->identity = identity;
1127 sta->radius_cui = radius_cui;
1130 sta->flags &= ~WLAN_STA_PREAUTH;
1131 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1133 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1134 sta->acct_interim_interval = acct_interim_interval;
1135 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1136 ap_sta_session_timeout(hapd, sta, session_timeout);
1138 ap_sta_no_session_timeout(hapd, sta);
1141 case WLAN_AUTH_OPEN:
1142 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1143 HOSTAPD_LEVEL_DEBUG,
1144 "authentication OK (open system)");
1145 sta->flags |= WLAN_STA_AUTH;
1146 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1147 sta->auth_alg = WLAN_AUTH_OPEN;
1148 mlme_authenticate_indication(hapd, sta);
1150 #ifndef CONFIG_NO_RC4
1151 case WLAN_AUTH_SHARED_KEY:
1152 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1153 fc & WLAN_FC_ISWEP);
1154 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1155 mlme_authenticate_indication(hapd, sta);
1156 if (sta->challenge && auth_transaction == 1) {
1157 resp_ies[0] = WLAN_EID_CHALLENGE;
1158 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1159 os_memcpy(resp_ies + 2, sta->challenge,
1160 WLAN_AUTH_CHALLENGE_LEN);
1161 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1164 #endif /* CONFIG_NO_RC4 */
1165 #ifdef CONFIG_IEEE80211R
1167 sta->auth_alg = WLAN_AUTH_FT;
1168 if (sta->wpa_sm == NULL)
1169 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1171 if (sta->wpa_sm == NULL) {
1172 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1174 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1177 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1178 auth_transaction, mgmt->u.auth.variable,
1179 len - IEEE80211_HDRLEN -
1180 sizeof(mgmt->u.auth),
1181 handle_auth_ft_finish, hapd);
1182 /* handle_auth_ft_finish() callback will complete auth. */
1184 #endif /* CONFIG_IEEE80211R */
1188 if (status_code == WLAN_STATUS_SUCCESS &&
1189 hapd->conf->mesh & MESH_ENABLED) {
1190 if (sta->wpa_sm == NULL)
1192 wpa_auth_sta_init(hapd->wpa_auth,
1194 if (sta->wpa_sm == NULL) {
1195 wpa_printf(MSG_DEBUG,
1196 "SAE: Failed to initialize WPA state machine");
1197 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1201 #endif /* CONFIG_MESH */
1202 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1205 #endif /* CONFIG_SAE */
1210 os_free(radius_cui);
1211 hostapd_free_psk_list(psk);
1213 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1214 auth_transaction + 1, resp, resp_ies, resp_ies_len);
1218 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1222 /* get a unique AID */
1224 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1228 for (i = 0; i < AID_WORDS; i++) {
1229 if (hapd->sta_aid[i] == (u32) -1)
1231 for (j = 0; j < 32; j++) {
1232 if (!(hapd->sta_aid[i] & BIT(j)))
1240 aid = i * 32 + j + 1;
1245 hapd->sta_aid[i] |= BIT(j);
1246 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1251 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1252 const u8 *ssid_ie, size_t ssid_ie_len)
1254 if (ssid_ie == NULL)
1255 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1257 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1258 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
1259 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1261 "Station tried to associate with unknown SSID "
1262 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
1263 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1266 return WLAN_STATUS_SUCCESS;
1270 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1271 const u8 *wmm_ie, size_t wmm_ie_len)
1273 sta->flags &= ~WLAN_STA_WMM;
1275 if (wmm_ie && hapd->conf->wmm_enabled) {
1276 struct wmm_information_element *wmm;
1278 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1279 hostapd_logger(hapd, sta->addr,
1281 HOSTAPD_LEVEL_DEBUG,
1282 "invalid WMM element in association "
1284 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1287 sta->flags |= WLAN_STA_WMM;
1288 wmm = (struct wmm_information_element *) wmm_ie;
1289 sta->qosinfo = wmm->qos_info;
1291 return WLAN_STATUS_SUCCESS;
1295 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1296 struct ieee802_11_elems *elems)
1298 if (!elems->supp_rates) {
1299 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1300 HOSTAPD_LEVEL_DEBUG,
1301 "No supported rates element in AssocReq");
1302 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1305 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1306 sizeof(sta->supported_rates)) {
1307 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1308 HOSTAPD_LEVEL_DEBUG,
1309 "Invalid supported rates element length %d+%d",
1310 elems->supp_rates_len,
1311 elems->ext_supp_rates_len);
1312 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1315 sta->supported_rates_len = merge_byte_arrays(
1316 sta->supported_rates, sizeof(sta->supported_rates),
1317 elems->supp_rates, elems->supp_rates_len,
1318 elems->ext_supp_rates, elems->ext_supp_rates_len);
1320 return WLAN_STATUS_SUCCESS;
1324 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1325 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1327 #ifdef CONFIG_INTERWORKING
1328 /* check for QoS Map support */
1329 if (ext_capab_ie_len >= 5) {
1330 if (ext_capab_ie[4] & 0x01)
1331 sta->qos_map_enabled = 1;
1333 #endif /* CONFIG_INTERWORKING */
1335 if (ext_capab_ie_len > 0)
1336 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1338 return WLAN_STATUS_SUCCESS;
1342 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1343 const u8 *ies, size_t ies_len, int reassoc)
1345 struct ieee802_11_elems elems;
1349 const u8 *p2p_dev_addr = NULL;
1351 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1352 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1353 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1354 "association request");
1355 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1358 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1359 if (resp != WLAN_STATUS_SUCCESS)
1361 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1362 if (resp != WLAN_STATUS_SUCCESS)
1364 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1365 if (resp != WLAN_STATUS_SUCCESS)
1367 resp = copy_supp_rates(hapd, sta, &elems);
1368 if (resp != WLAN_STATUS_SUCCESS)
1370 #ifdef CONFIG_IEEE80211N
1371 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
1372 if (resp != WLAN_STATUS_SUCCESS)
1374 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1375 !(sta->flags & WLAN_STA_HT)) {
1376 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1377 HOSTAPD_LEVEL_INFO, "Station does not support "
1378 "mandatory HT PHY - reject association");
1379 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1381 #endif /* CONFIG_IEEE80211N */
1383 #ifdef CONFIG_IEEE80211AC
1384 if (hapd->iconf->ieee80211ac) {
1385 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1386 if (resp != WLAN_STATUS_SUCCESS)
1389 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1390 if (resp != WLAN_STATUS_SUCCESS)
1394 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1395 !(sta->flags & WLAN_STA_VHT)) {
1396 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1397 HOSTAPD_LEVEL_INFO, "Station does not support "
1398 "mandatory VHT PHY - reject association");
1399 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1402 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1403 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1404 elems.vendor_vht_len);
1405 if (resp != WLAN_STATUS_SUCCESS)
1408 #endif /* CONFIG_IEEE80211AC */
1412 wpabuf_free(sta->p2p_ie);
1413 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1414 P2P_IE_VENDOR_TYPE);
1416 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1418 wpabuf_free(sta->p2p_ie);
1421 #endif /* CONFIG_P2P */
1423 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1424 wpa_ie = elems.rsn_ie;
1425 wpa_ie_len = elems.rsn_ie_len;
1426 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1428 wpa_ie = elems.wpa_ie;
1429 wpa_ie_len = elems.wpa_ie_len;
1436 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1437 if (hapd->conf->wps_state && elems.wps_ie) {
1438 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1439 "Request - assume WPS is used");
1440 sta->flags |= WLAN_STA_WPS;
1441 wpabuf_free(sta->wps_ie);
1442 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1443 WPS_IE_VENDOR_TYPE);
1444 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1445 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1446 sta->flags |= WLAN_STA_WPS2;
1450 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1451 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1452 "(Re)Association Request - reject");
1453 return WLAN_STATUS_INVALID_IE;
1455 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1456 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1457 "(Re)Association Request - possible WPS use");
1458 sta->flags |= WLAN_STA_MAYBE_WPS;
1460 #endif /* CONFIG_WPS */
1461 if (hapd->conf->wpa && wpa_ie == NULL) {
1462 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1464 "No WPA/RSN IE in association request");
1465 return WLAN_STATUS_INVALID_IE;
1468 if (hapd->conf->wpa && wpa_ie) {
1472 if (sta->wpa_sm == NULL)
1473 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1476 if (sta->wpa_sm == NULL) {
1477 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1479 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1481 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1483 elems.mdie, elems.mdie_len);
1484 if (res == WPA_INVALID_GROUP)
1485 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1486 else if (res == WPA_INVALID_PAIRWISE)
1487 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1488 else if (res == WPA_INVALID_AKMP)
1489 resp = WLAN_STATUS_AKMP_NOT_VALID;
1490 else if (res == WPA_ALLOC_FAIL)
1491 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1492 #ifdef CONFIG_IEEE80211W
1493 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1494 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1495 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1496 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1497 #endif /* CONFIG_IEEE80211W */
1498 else if (res == WPA_INVALID_MDIE)
1499 resp = WLAN_STATUS_INVALID_MDIE;
1500 else if (res != WPA_IE_OK)
1501 resp = WLAN_STATUS_INVALID_IE;
1502 if (resp != WLAN_STATUS_SUCCESS)
1504 #ifdef CONFIG_IEEE80211W
1505 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1506 sta->sa_query_count > 0)
1507 ap_check_sa_query_timeout(hapd, sta);
1508 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1509 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1511 * STA has already been associated with MFP and SA
1512 * Query timeout has not been reached. Reject the
1513 * association attempt temporarily and start SA Query,
1514 * if one is not pending.
1517 if (sta->sa_query_count == 0)
1518 ap_sta_start_sa_query(hapd, sta);
1520 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1523 if (wpa_auth_uses_mfp(sta->wpa_sm))
1524 sta->flags |= WLAN_STA_MFP;
1526 sta->flags &= ~WLAN_STA_MFP;
1527 #endif /* CONFIG_IEEE80211W */
1529 #ifdef CONFIG_IEEE80211R
1530 if (sta->auth_alg == WLAN_AUTH_FT) {
1532 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1533 "to use association (not "
1534 "re-association) with FT auth_alg",
1535 MAC2STR(sta->addr));
1536 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1539 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1541 if (resp != WLAN_STATUS_SUCCESS)
1544 #endif /* CONFIG_IEEE80211R */
1547 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1548 sta->auth_alg == WLAN_AUTH_OPEN) {
1549 struct rsn_pmksa_cache_entry *sa;
1550 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1551 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1552 wpa_printf(MSG_DEBUG,
1553 "SAE: No PMKSA cache entry found for "
1554 MACSTR, MAC2STR(sta->addr));
1555 return WLAN_STATUS_INVALID_PMKID;
1557 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1558 " using PMKSA caching", MAC2STR(sta->addr));
1559 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1560 sta->auth_alg != WLAN_AUTH_SAE &&
1561 !(sta->auth_alg == WLAN_AUTH_FT &&
1562 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1563 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1564 "SAE AKM after non-SAE auth_alg %u",
1565 MAC2STR(sta->addr), sta->auth_alg);
1566 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1568 #endif /* CONFIG_SAE */
1570 #ifdef CONFIG_IEEE80211N
1571 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1572 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1573 hostapd_logger(hapd, sta->addr,
1574 HOSTAPD_MODULE_IEEE80211,
1576 "Station tried to use TKIP with HT "
1578 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1580 #endif /* CONFIG_IEEE80211N */
1582 } else if (hapd->conf->osen) {
1583 if (elems.osen == NULL) {
1585 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1587 "No HS 2.0 OSEN element in association request");
1588 return WLAN_STATUS_INVALID_IE;
1591 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1592 if (sta->wpa_sm == NULL)
1593 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1595 if (sta->wpa_sm == NULL) {
1596 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1598 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1600 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1601 elems.osen - 2, elems.osen_len + 2) < 0)
1602 return WLAN_STATUS_INVALID_IE;
1603 #endif /* CONFIG_HS20 */
1605 wpa_auth_sta_no_wpa(sta->wpa_sm);
1608 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1609 #endif /* CONFIG_P2P */
1612 wpabuf_free(sta->hs20_ie);
1613 if (elems.hs20 && elems.hs20_len > 4) {
1614 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1615 elems.hs20_len - 4);
1617 sta->hs20_ie = NULL;
1618 #endif /* CONFIG_HS20 */
1621 wpabuf_free(sta->mb_ies);
1622 if (hapd->iface->fst)
1623 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1626 #endif /* CONFIG_FST */
1628 return WLAN_STATUS_SUCCESS;
1632 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1636 struct ieee80211_mgmt reply;
1638 os_memset(&reply, 0, sizeof(reply));
1639 reply.frame_control =
1640 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1641 os_memcpy(reply.da, addr, ETH_ALEN);
1642 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1643 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1645 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1646 reply.u.deauth.reason_code = host_to_le16(reason_code);
1648 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1649 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1654 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1655 u16 status_code, int reassoc, const u8 *ies,
1659 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1660 struct ieee80211_mgmt *reply;
1663 os_memset(buf, 0, sizeof(buf));
1664 reply = (struct ieee80211_mgmt *) buf;
1665 reply->frame_control =
1666 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1667 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1668 WLAN_FC_STYPE_ASSOC_RESP));
1669 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1670 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1671 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1673 send_len = IEEE80211_HDRLEN;
1674 send_len += sizeof(reply->u.assoc_resp);
1675 reply->u.assoc_resp.capab_info =
1676 host_to_le16(hostapd_own_capab_info(hapd));
1677 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1678 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1679 /* Supported rates */
1680 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1681 /* Extended supported rates */
1682 p = hostapd_eid_ext_supp_rates(hapd, p);
1684 #ifdef CONFIG_IEEE80211R
1685 if (status_code == WLAN_STATUS_SUCCESS) {
1686 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1687 * Transition Information, RSN, [RIC Response] */
1688 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1689 buf + sizeof(buf) - p,
1690 sta->auth_alg, ies, ies_len);
1692 #endif /* CONFIG_IEEE80211R */
1694 #ifdef CONFIG_IEEE80211W
1695 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1696 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1697 #endif /* CONFIG_IEEE80211W */
1699 #ifdef CONFIG_IEEE80211N
1700 p = hostapd_eid_ht_capabilities(hapd, p);
1701 p = hostapd_eid_ht_operation(hapd, p);
1702 #endif /* CONFIG_IEEE80211N */
1704 #ifdef CONFIG_IEEE80211AC
1705 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1706 p = hostapd_eid_vht_capabilities(hapd, p);
1707 p = hostapd_eid_vht_operation(hapd, p);
1709 #endif /* CONFIG_IEEE80211AC */
1711 p = hostapd_eid_ext_capab(hapd, p);
1712 p = hostapd_eid_bss_max_idle_period(hapd, p);
1713 if (sta->qos_map_enabled)
1714 p = hostapd_eid_qos_map_set(hapd, p);
1717 if (hapd->iface->fst_ies) {
1718 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1719 wpabuf_len(hapd->iface->fst_ies));
1720 p += wpabuf_len(hapd->iface->fst_ies);
1722 #endif /* CONFIG_FST */
1724 #ifdef CONFIG_IEEE80211AC
1725 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1726 p = hostapd_eid_vendor_vht(hapd, p);
1727 #endif /* CONFIG_IEEE80211AC */
1729 if (sta->flags & WLAN_STA_WMM)
1730 p = hostapd_eid_wmm(hapd, p);
1733 if ((sta->flags & WLAN_STA_WPS) ||
1734 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1735 struct wpabuf *wps = wps_build_assoc_resp_ie();
1737 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1738 p += wpabuf_len(wps);
1742 #endif /* CONFIG_WPS */
1745 if (sta->p2p_ie && hapd->p2p_group) {
1746 struct wpabuf *p2p_resp_ie;
1747 enum p2p_status_code status;
1748 switch (status_code) {
1749 case WLAN_STATUS_SUCCESS:
1750 status = P2P_SC_SUCCESS;
1752 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1753 status = P2P_SC_FAIL_LIMIT_REACHED;
1756 status = P2P_SC_FAIL_INVALID_PARAMS;
1759 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1761 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1762 wpabuf_len(p2p_resp_ie));
1763 p += wpabuf_len(p2p_resp_ie);
1764 wpabuf_free(p2p_resp_ie);
1767 #endif /* CONFIG_P2P */
1769 #ifdef CONFIG_P2P_MANAGER
1770 if (hapd->conf->p2p & P2P_MANAGE)
1771 p = hostapd_eid_p2p_manage(hapd, p);
1772 #endif /* CONFIG_P2P_MANAGER */
1774 send_len += p - reply->u.assoc_resp.variable;
1776 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1777 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1782 static void handle_assoc(struct hostapd_data *hapd,
1783 const struct ieee80211_mgmt *mgmt, size_t len,
1786 u16 capab_info, listen_interval, seq_ctrl, fc;
1787 u16 resp = WLAN_STATUS_SUCCESS;
1790 struct sta_info *sta;
1792 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1793 sizeof(mgmt->u.assoc_req))) {
1794 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1795 reassoc, (unsigned long) len);
1799 #ifdef CONFIG_TESTING_OPTIONS
1801 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1802 drand48() < hapd->iconf->ignore_reassoc_probability) {
1803 wpa_printf(MSG_INFO,
1804 "TESTING: ignoring reassoc request from "
1805 MACSTR, MAC2STR(mgmt->sa));
1809 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1810 drand48() < hapd->iconf->ignore_assoc_probability) {
1811 wpa_printf(MSG_INFO,
1812 "TESTING: ignoring assoc request from "
1813 MACSTR, MAC2STR(mgmt->sa));
1817 #endif /* CONFIG_TESTING_OPTIONS */
1819 fc = le_to_host16(mgmt->frame_control);
1820 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1823 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1824 listen_interval = le_to_host16(
1825 mgmt->u.reassoc_req.listen_interval);
1826 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1827 " capab_info=0x%02x listen_interval=%d current_ap="
1828 MACSTR " seq_ctrl=0x%x%s",
1829 MAC2STR(mgmt->sa), capab_info, listen_interval,
1830 MAC2STR(mgmt->u.reassoc_req.current_ap),
1831 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1832 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1833 pos = mgmt->u.reassoc_req.variable;
1835 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1836 listen_interval = le_to_host16(
1837 mgmt->u.assoc_req.listen_interval);
1838 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1839 " capab_info=0x%02x listen_interval=%d "
1841 MAC2STR(mgmt->sa), capab_info, listen_interval,
1842 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1843 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1844 pos = mgmt->u.assoc_req.variable;
1847 sta = ap_get_sta(hapd, mgmt->sa);
1848 #ifdef CONFIG_IEEE80211R
1849 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1850 (sta->flags & WLAN_STA_AUTH) == 0) {
1851 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1852 "prior to authentication since it is using "
1853 "over-the-DS FT", MAC2STR(mgmt->sa));
1855 #endif /* CONFIG_IEEE80211R */
1856 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1857 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1858 HOSTAPD_LEVEL_INFO, "Station tried to "
1859 "associate before authentication "
1860 "(aid=%d flags=0x%x)",
1861 sta ? sta->aid : -1,
1862 sta ? sta->flags : 0);
1863 send_deauth(hapd, mgmt->sa,
1864 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1868 if ((fc & WLAN_FC_RETRY) &&
1869 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1870 sta->last_seq_ctrl == seq_ctrl &&
1871 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1872 WLAN_FC_STYPE_ASSOC_REQ) {
1873 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1874 HOSTAPD_LEVEL_DEBUG,
1875 "Drop repeated association frame seq_ctrl=0x%x",
1879 sta->last_seq_ctrl = seq_ctrl;
1880 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1881 WLAN_FC_STYPE_ASSOC_REQ;
1883 if (hapd->tkip_countermeasures) {
1884 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1888 if (listen_interval > hapd->conf->max_listen_interval) {
1889 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1890 HOSTAPD_LEVEL_DEBUG,
1891 "Too large Listen Interval (%d)",
1893 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1897 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1899 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1900 if (resp != WLAN_STATUS_SUCCESS)
1903 if (hostapd_get_aid(hapd, sta) < 0) {
1904 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1905 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1906 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1910 sta->capability = capab_info;
1911 sta->listen_interval = listen_interval;
1913 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1914 sta->flags |= WLAN_STA_NONERP;
1915 for (i = 0; i < sta->supported_rates_len; i++) {
1916 if ((sta->supported_rates[i] & 0x7f) > 22) {
1917 sta->flags &= ~WLAN_STA_NONERP;
1921 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1922 sta->nonerp_set = 1;
1923 hapd->iface->num_sta_non_erp++;
1924 if (hapd->iface->num_sta_non_erp == 1)
1925 ieee802_11_set_beacons(hapd->iface);
1928 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1929 !sta->no_short_slot_time_set) {
1930 sta->no_short_slot_time_set = 1;
1931 hapd->iface->num_sta_no_short_slot_time++;
1932 if (hapd->iface->current_mode->mode ==
1933 HOSTAPD_MODE_IEEE80211G &&
1934 hapd->iface->num_sta_no_short_slot_time == 1)
1935 ieee802_11_set_beacons(hapd->iface);
1938 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1939 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1941 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1943 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1944 !sta->no_short_preamble_set) {
1945 sta->no_short_preamble_set = 1;
1946 hapd->iface->num_sta_no_short_preamble++;
1947 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1948 && hapd->iface->num_sta_no_short_preamble == 1)
1949 ieee802_11_set_beacons(hapd->iface);
1952 #ifdef CONFIG_IEEE80211N
1953 update_ht_state(hapd, sta);
1954 #endif /* CONFIG_IEEE80211N */
1956 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1957 HOSTAPD_LEVEL_DEBUG,
1958 "association OK (aid %d)", sta->aid);
1959 /* Station will be marked associated, after it acknowledges AssocResp
1961 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1963 #ifdef CONFIG_IEEE80211W
1964 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1965 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1966 "SA Query procedure", reassoc ? "re" : "");
1967 /* TODO: Send a protected Disassociate frame to the STA using
1968 * the old key and Reason Code "Previous Authentication no
1969 * longer valid". Make sure this is only sent protected since
1970 * unprotected frame would be received by the STA that is now
1971 * trying to associate.
1974 #endif /* CONFIG_IEEE80211W */
1976 /* Make sure that the previously registered inactivity timer will not
1977 * remove the STA immediately. */
1978 sta->timeout_next = STA_NULLFUNC;
1981 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1985 static void handle_disassoc(struct hostapd_data *hapd,
1986 const struct ieee80211_mgmt *mgmt, size_t len)
1988 struct sta_info *sta;
1990 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1991 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1992 (unsigned long) len);
1996 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1998 le_to_host16(mgmt->u.disassoc.reason_code));
2000 sta = ap_get_sta(hapd, mgmt->sa);
2002 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2007 ap_sta_set_authorized(hapd, sta, 0);
2008 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2009 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
2010 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2011 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2012 HOSTAPD_LEVEL_INFO, "disassociated");
2013 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2014 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2015 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2017 accounting_sta_stop(hapd, sta);
2018 ieee802_1x_free_station(hapd, sta);
2020 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2021 ap_sta_ip6addr_del(hapd, sta);
2022 hostapd_drv_sta_remove(hapd, sta->addr);
2024 if (sta->timeout_next == STA_NULLFUNC ||
2025 sta->timeout_next == STA_DISASSOC) {
2026 sta->timeout_next = STA_DEAUTH;
2027 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2028 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2032 mlme_disassociate_indication(
2033 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2037 static void handle_deauth(struct hostapd_data *hapd,
2038 const struct ieee80211_mgmt *mgmt, size_t len)
2040 struct sta_info *sta;
2042 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
2043 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2044 "payload (len=%lu)", (unsigned long) len);
2048 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
2050 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2052 sta = ap_get_sta(hapd, mgmt->sa);
2054 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2055 "to deauthenticate, but it is not authenticated",
2060 ap_sta_set_authorized(hapd, sta, 0);
2061 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
2062 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2063 WLAN_STA_ASSOC_REQ_OK);
2064 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2065 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2066 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2067 mlme_deauthenticate_indication(
2068 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2069 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2070 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2071 ap_free_sta(hapd, sta);
2075 static void handle_beacon(struct hostapd_data *hapd,
2076 const struct ieee80211_mgmt *mgmt, size_t len,
2077 struct hostapd_frame_info *fi)
2079 struct ieee802_11_elems elems;
2081 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
2082 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2083 (unsigned long) len);
2087 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2088 len - (IEEE80211_HDRLEN +
2089 sizeof(mgmt->u.beacon)), &elems,
2092 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2096 #ifdef CONFIG_IEEE80211W
2098 static int hostapd_sa_query_action(struct hostapd_data *hapd,
2099 const struct ieee80211_mgmt *mgmt,
2104 end = mgmt->u.action.u.sa_query_resp.trans_id +
2105 WLAN_SA_QUERY_TR_ID_LEN;
2106 if (((u8 *) mgmt) + len < end) {
2107 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2108 "frame (len=%lu)", (unsigned long) len);
2112 ieee802_11_sa_query_action(hapd, mgmt->sa,
2113 mgmt->u.action.u.sa_query_resp.action,
2114 mgmt->u.action.u.sa_query_resp.trans_id);
2119 static int robust_action_frame(u8 category)
2121 return category != WLAN_ACTION_PUBLIC &&
2122 category != WLAN_ACTION_HT;
2124 #endif /* CONFIG_IEEE80211W */
2127 static int handle_action(struct hostapd_data *hapd,
2128 const struct ieee80211_mgmt *mgmt, size_t len)
2130 struct sta_info *sta;
2131 sta = ap_get_sta(hapd, mgmt->sa);
2133 if (len < IEEE80211_HDRLEN + 1) {
2134 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2135 HOSTAPD_LEVEL_DEBUG,
2136 "handle_action - too short payload (len=%lu)",
2137 (unsigned long) len);
2141 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2142 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2143 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2144 "frame (category=%u) from unassociated STA " MACSTR,
2145 MAC2STR(mgmt->sa), mgmt->u.action.category);
2149 #ifdef CONFIG_IEEE80211W
2150 if (sta && (sta->flags & WLAN_STA_MFP) &&
2151 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2152 robust_action_frame(mgmt->u.action.category)) {
2153 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2154 HOSTAPD_LEVEL_DEBUG,
2155 "Dropped unprotected Robust Action frame from "
2159 #endif /* CONFIG_IEEE80211W */
2162 u16 fc = le_to_host16(mgmt->frame_control);
2163 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2165 if ((fc & WLAN_FC_RETRY) &&
2166 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2167 sta->last_seq_ctrl == seq_ctrl &&
2168 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2169 hostapd_logger(hapd, sta->addr,
2170 HOSTAPD_MODULE_IEEE80211,
2171 HOSTAPD_LEVEL_DEBUG,
2172 "Drop repeated action frame seq_ctrl=0x%x",
2177 sta->last_seq_ctrl = seq_ctrl;
2178 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2181 switch (mgmt->u.action.category) {
2182 #ifdef CONFIG_IEEE80211R
2183 case WLAN_ACTION_FT:
2185 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
2186 len - IEEE80211_HDRLEN))
2189 #endif /* CONFIG_IEEE80211R */
2190 case WLAN_ACTION_WMM:
2191 hostapd_wmm_action(hapd, mgmt, len);
2193 #ifdef CONFIG_IEEE80211W
2194 case WLAN_ACTION_SA_QUERY:
2195 return hostapd_sa_query_action(hapd, mgmt, len);
2196 #endif /* CONFIG_IEEE80211W */
2198 case WLAN_ACTION_WNM:
2199 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2201 #endif /* CONFIG_WNM */
2203 case WLAN_ACTION_FST:
2204 if (hapd->iface->fst)
2205 fst_rx_action(hapd->iface->fst, mgmt, len);
2207 wpa_printf(MSG_DEBUG,
2208 "FST: Ignore FST Action frame - no FST attached");
2210 #endif /* CONFIG_FST */
2211 case WLAN_ACTION_PUBLIC:
2212 case WLAN_ACTION_PROTECTED_DUAL:
2213 #ifdef CONFIG_IEEE80211N
2214 if (len >= IEEE80211_HDRLEN + 2 &&
2215 mgmt->u.action.u.public_action.action ==
2216 WLAN_PA_20_40_BSS_COEX) {
2217 wpa_printf(MSG_DEBUG,
2218 "HT20/40 coex mgmt frame received from STA "
2219 MACSTR, MAC2STR(mgmt->sa));
2220 hostapd_2040_coex_action(hapd, mgmt, len);
2222 #endif /* CONFIG_IEEE80211N */
2223 if (hapd->public_action_cb) {
2224 hapd->public_action_cb(hapd->public_action_cb_ctx,
2228 if (hapd->public_action_cb2) {
2229 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2233 if (hapd->public_action_cb || hapd->public_action_cb2)
2236 case WLAN_ACTION_VENDOR_SPECIFIC:
2237 if (hapd->vendor_action_cb) {
2238 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2240 hapd->iface->freq) == 0)
2246 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2247 HOSTAPD_LEVEL_DEBUG,
2248 "handle_action - unknown action category %d or invalid "
2250 mgmt->u.action.category);
2251 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2252 !(mgmt->sa[0] & 0x01)) {
2253 struct ieee80211_mgmt *resp;
2256 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2257 * Return the Action frame to the source without change
2258 * except that MSB of the Category set to 1.
2260 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2261 "frame back to sender");
2262 resp = os_malloc(len);
2265 os_memcpy(resp, mgmt, len);
2266 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2267 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2268 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2269 resp->u.action.category |= 0x80;
2271 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2272 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2283 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2284 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2286 * @buf: management frame data (starting from IEEE 802.11 header)
2287 * @len: length of frame data in octets
2288 * @fi: meta data about received frame (signal level, etc.)
2290 * Process all incoming IEEE 802.11 management frames. This will be called for
2291 * each frame received from the kernel driver through wlan#ap interface. In
2292 * addition, it can be called to re-inserted pending frames (e.g., when using
2293 * external RADIUS server as an MAC ACL).
2295 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2296 struct hostapd_frame_info *fi)
2298 struct ieee80211_mgmt *mgmt;
2306 mgmt = (struct ieee80211_mgmt *) buf;
2307 fc = le_to_host16(mgmt->frame_control);
2308 stype = WLAN_FC_GET_STYPE(fc);
2310 if (stype == WLAN_FC_STYPE_BEACON) {
2311 handle_beacon(hapd, mgmt, len, fi);
2315 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2316 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2317 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2321 /* Invitation responses can be sent with the peer MAC as BSSID */
2322 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2323 stype == WLAN_FC_STYPE_ACTION) &&
2324 #endif /* CONFIG_P2P */
2326 !(hapd->conf->mesh & MESH_ENABLED) &&
2327 #endif /* CONFIG_MESH */
2328 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2329 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2330 MAC2STR(mgmt->bssid));
2335 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2336 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2340 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2341 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2342 HOSTAPD_LEVEL_DEBUG,
2343 "MGMT: DA=" MACSTR " not our address",
2348 if (hapd->iconf->track_sta_max_num)
2349 sta_track_add(hapd->iface, mgmt->sa);
2352 case WLAN_FC_STYPE_AUTH:
2353 wpa_printf(MSG_DEBUG, "mgmt::auth");
2354 handle_auth(hapd, mgmt, len);
2357 case WLAN_FC_STYPE_ASSOC_REQ:
2358 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2359 handle_assoc(hapd, mgmt, len, 0);
2362 case WLAN_FC_STYPE_REASSOC_REQ:
2363 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2364 handle_assoc(hapd, mgmt, len, 1);
2367 case WLAN_FC_STYPE_DISASSOC:
2368 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2369 handle_disassoc(hapd, mgmt, len);
2372 case WLAN_FC_STYPE_DEAUTH:
2373 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2374 handle_deauth(hapd, mgmt, len);
2377 case WLAN_FC_STYPE_ACTION:
2378 wpa_printf(MSG_DEBUG, "mgmt::action");
2379 ret = handle_action(hapd, mgmt, len);
2382 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2383 HOSTAPD_LEVEL_DEBUG,
2384 "unknown mgmt frame subtype %d", stype);
2392 static void handle_auth_cb(struct hostapd_data *hapd,
2393 const struct ieee80211_mgmt *mgmt,
2396 u16 auth_alg, auth_transaction, status_code;
2397 struct sta_info *sta;
2400 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2401 HOSTAPD_LEVEL_NOTICE,
2402 "did not acknowledge authentication response");
2406 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2407 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2408 (unsigned long) len);
2412 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2413 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2414 status_code = le_to_host16(mgmt->u.auth.status_code);
2416 sta = ap_get_sta(hapd, mgmt->da);
2418 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2423 if (status_code == WLAN_STATUS_SUCCESS &&
2424 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2425 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2426 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2427 HOSTAPD_LEVEL_INFO, "authenticated");
2428 sta->flags |= WLAN_STA_AUTH;
2433 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2434 struct sta_info *sta,
2438 struct hostapd_ssid *ssid = &hapd->conf->ssid;
2440 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2443 for (i = 0; i < 4; i++) {
2444 if (ssid->wep.key[i] &&
2445 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2446 i == ssid->wep.idx, NULL, 0,
2447 ssid->wep.key[i], ssid->wep.len[i])) {
2448 wpa_printf(MSG_WARNING,
2449 "Could not set WEP keys for WDS interface; %s",
2457 static void handle_assoc_cb(struct hostapd_data *hapd,
2458 const struct ieee80211_mgmt *mgmt,
2459 size_t len, int reassoc, int ok)
2462 struct sta_info *sta;
2464 struct ieee80211_ht_capabilities ht_cap;
2465 struct ieee80211_vht_capabilities vht_cap;
2467 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2468 sizeof(mgmt->u.assoc_resp))) {
2469 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2470 reassoc, (unsigned long) len);
2474 sta = ap_get_sta(hapd, mgmt->da);
2476 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2482 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2483 HOSTAPD_LEVEL_DEBUG,
2484 "did not acknowledge association response");
2485 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2490 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2492 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2494 if (status != WLAN_STATUS_SUCCESS)
2497 /* Stop previous accounting session, if one is started, and allocate
2498 * new session id for the new session. */
2499 accounting_sta_stop(hapd, sta);
2501 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2503 "associated (aid %d)",
2506 if (sta->flags & WLAN_STA_ASSOC)
2508 sta->flags |= WLAN_STA_ASSOC;
2509 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2510 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2511 sta->auth_alg == WLAN_AUTH_FT) {
2513 * Open, static WEP, or FT protocol; no separate authorization
2516 ap_sta_set_authorized(hapd, sta, 1);
2520 mlme_reassociate_indication(hapd, sta);
2522 mlme_associate_indication(hapd, sta);
2524 #ifdef CONFIG_IEEE80211W
2525 sta->sa_query_timed_out = 0;
2526 #endif /* CONFIG_IEEE80211W */
2529 * Remove the STA entry in order to make sure the STA PS state gets
2530 * cleared and configuration gets updated in case of reassociation back
2533 hostapd_drv_sta_remove(hapd, sta->addr);
2535 #ifdef CONFIG_IEEE80211N
2536 if (sta->flags & WLAN_STA_HT)
2537 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2538 #endif /* CONFIG_IEEE80211N */
2539 #ifdef CONFIG_IEEE80211AC
2540 if (sta->flags & WLAN_STA_VHT)
2541 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2542 #endif /* CONFIG_IEEE80211AC */
2544 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2545 sta->supported_rates, sta->supported_rates_len,
2546 sta->listen_interval,
2547 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
2548 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
2549 sta->flags, sta->qosinfo, sta->vht_opmode)) {
2550 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2551 HOSTAPD_LEVEL_NOTICE,
2552 "Could not add STA to kernel driver");
2554 ap_sta_disconnect(hapd, sta, sta->addr,
2555 WLAN_REASON_DISASSOC_AP_BUSY);
2560 if (sta->flags & WLAN_STA_WDS) {
2562 char ifname_wds[IFNAMSIZ + 1];
2564 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2567 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2570 if (sta->eapol_sm == NULL) {
2572 * This STA does not use RADIUS server for EAP authentication,
2573 * so bind it to the selected VLAN interface now, since the
2574 * interface selection is not going to change anymore.
2576 if (ap_sta_bind_vlan(hapd, sta) < 0)
2578 } else if (sta->vlan_id) {
2579 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2580 if (ap_sta_bind_vlan(hapd, sta) < 0)
2584 hostapd_set_sta_flags(hapd, sta);
2586 if (sta->auth_alg == WLAN_AUTH_FT)
2587 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2589 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2590 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2592 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2596 static void handle_deauth_cb(struct hostapd_data *hapd,
2597 const struct ieee80211_mgmt *mgmt,
2600 struct sta_info *sta;
2601 if (mgmt->da[0] & 0x01)
2603 sta = ap_get_sta(hapd, mgmt->da);
2605 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2606 " not found", MAC2STR(mgmt->da));
2610 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2611 MAC2STR(sta->addr));
2613 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2614 "deauth", MAC2STR(sta->addr));
2616 ap_sta_deauth_cb(hapd, sta);
2620 static void handle_disassoc_cb(struct hostapd_data *hapd,
2621 const struct ieee80211_mgmt *mgmt,
2624 struct sta_info *sta;
2625 if (mgmt->da[0] & 0x01)
2627 sta = ap_get_sta(hapd, mgmt->da);
2629 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2630 " not found", MAC2STR(mgmt->da));
2634 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2635 MAC2STR(sta->addr));
2637 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2638 "disassoc", MAC2STR(sta->addr));
2640 ap_sta_disassoc_cb(hapd, sta);
2645 * ieee802_11_mgmt_cb - Process management frame TX status callback
2646 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2648 * @buf: management frame data (starting from IEEE 802.11 header)
2649 * @len: length of frame data in octets
2650 * @stype: management frame subtype from frame control field
2651 * @ok: Whether the frame was ACK'ed
2653 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2656 const struct ieee80211_mgmt *mgmt;
2657 mgmt = (const struct ieee80211_mgmt *) buf;
2659 #ifdef CONFIG_TESTING_OPTIONS
2660 if (hapd->ext_mgmt_frame_handling) {
2661 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2665 #endif /* CONFIG_TESTING_OPTIONS */
2668 case WLAN_FC_STYPE_AUTH:
2669 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2670 handle_auth_cb(hapd, mgmt, len, ok);
2672 case WLAN_FC_STYPE_ASSOC_RESP:
2673 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2674 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2676 case WLAN_FC_STYPE_REASSOC_RESP:
2677 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2678 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2680 case WLAN_FC_STYPE_PROBE_RESP:
2681 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2683 case WLAN_FC_STYPE_DEAUTH:
2684 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2685 handle_deauth_cb(hapd, mgmt, len, ok);
2687 case WLAN_FC_STYPE_DISASSOC:
2688 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2689 handle_disassoc_cb(hapd, mgmt, len, ok);
2691 case WLAN_FC_STYPE_ACTION:
2692 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2695 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2701 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2708 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2709 char *buf, size_t buflen)
2716 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2717 const u8 *buf, size_t len, int ack)
2719 struct sta_info *sta;
2720 struct hostapd_iface *iface = hapd->iface;
2722 sta = ap_get_sta(hapd, addr);
2723 if (sta == NULL && iface->num_bss > 1) {
2725 for (j = 0; j < iface->num_bss; j++) {
2726 hapd = iface->bss[j];
2727 sta = ap_get_sta(hapd, addr);
2732 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2734 if (sta->flags & WLAN_STA_PENDING_POLL) {
2735 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2736 "activity poll", MAC2STR(sta->addr),
2737 ack ? "ACKed" : "did not ACK");
2739 sta->flags &= ~WLAN_STA_PENDING_POLL;
2742 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2746 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2747 const u8 *data, size_t len, int ack)
2749 struct sta_info *sta;
2750 struct hostapd_iface *iface = hapd->iface;
2752 sta = ap_get_sta(hapd, dst);
2753 if (sta == NULL && iface->num_bss > 1) {
2755 for (j = 0; j < iface->num_bss; j++) {
2756 hapd = iface->bss[j];
2757 sta = ap_get_sta(hapd, dst);
2762 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2763 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2764 MACSTR " that is not currently associated",
2769 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2773 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2775 struct sta_info *sta;
2776 struct hostapd_iface *iface = hapd->iface;
2778 sta = ap_get_sta(hapd, addr);
2779 if (sta == NULL && iface->num_bss > 1) {
2781 for (j = 0; j < iface->num_bss; j++) {
2782 hapd = iface->bss[j];
2783 sta = ap_get_sta(hapd, addr);
2790 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2793 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2794 "activity poll", MAC2STR(sta->addr));
2795 sta->flags &= ~WLAN_STA_PENDING_POLL;
2799 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2802 struct sta_info *sta;
2804 sta = ap_get_sta(hapd, src);
2805 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2806 if (!hapd->conf->wds_sta)
2809 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2811 char ifname_wds[IFNAMSIZ + 1];
2813 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2814 "STA " MACSTR " (aid %u)",
2815 MAC2STR(sta->addr), sta->aid);
2816 sta->flags |= WLAN_STA_WDS;
2817 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2818 sta->addr, sta->aid, 1);
2820 hostapd_set_wds_encryption(hapd, sta,
2826 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2827 MACSTR, MAC2STR(src));
2828 if (src[0] & 0x01) {
2829 /* Broadcast bit set in SA?! Ignore the frame silently. */
2833 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2834 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2835 "already been sent, but no TX status yet known - "
2836 "ignore Class 3 frame issue with " MACSTR,
2841 if (sta && (sta->flags & WLAN_STA_AUTH))
2842 hostapd_drv_sta_disassoc(
2844 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2846 hostapd_drv_sta_deauth(
2848 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2852 #endif /* CONFIG_NATIVE_WINDOWS */