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"
28 #include "ieee802_11_auth.h"
30 #include "ieee802_1x.h"
32 #include "pmksa_cache_auth.h"
35 #include "accounting.h"
36 #include "ap_config.h"
38 #include "p2p_hostapd.h"
39 #include "ap_drv_ops.h"
41 #include "ieee802_11.h"
45 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
50 if (hapd->iface->current_rates == NULL)
53 *pos++ = WLAN_EID_SUPP_RATES;
54 num = hapd->iface->num_rates;
55 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
57 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
60 /* rest of the rates are encoded in Extended supported
66 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
69 *pos = hapd->iface->current_rates[i].rate / 5;
70 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
75 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
77 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
80 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
82 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
89 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
94 if (hapd->iface->current_rates == NULL)
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
106 *pos++ = WLAN_EID_EXT_SUPP_RATES;
108 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
112 continue; /* already in SuppRates IE */
113 *pos = hapd->iface->current_rates[i].rate / 5;
114 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
119 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
122 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
125 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
128 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
135 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
138 int capab = WLAN_CAPABILITY_ESS;
142 /* Check if any of configured channels require DFS */
143 dfs = hostapd_is_dfs_required(hapd->iface);
145 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
150 if (hapd->iface->num_sta_no_short_preamble == 0 &&
151 hapd->iconf->preamble == SHORT_PREAMBLE)
152 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
154 privacy = hapd->conf->ssid.wep.keys_set;
156 if (hapd->conf->ieee802_1x &&
157 (hapd->conf->default_wep_key_len ||
158 hapd->conf->individual_wep_key_len))
165 if (hapd->conf->osen)
167 #endif /* CONFIG_HS20 */
170 int policy, def_klen;
171 if (probe && sta->ssid_probe) {
172 policy = sta->ssid_probe->security_policy;
173 def_klen = sta->ssid_probe->wep.default_len;
175 policy = sta->ssid->security_policy;
176 def_klen = sta->ssid->wep.default_len;
178 privacy = policy != SECURITY_PLAINTEXT;
179 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
184 capab |= WLAN_CAPABILITY_PRIVACY;
186 if (hapd->iface->current_mode &&
187 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
188 hapd->iface->num_sta_no_short_slot_time == 0)
189 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
192 * Currently, Spectrum Management capability bit is set when directly
193 * requested in configuration by spectrum_mgmt_required or when AP is
194 * running on DFS channel.
195 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
197 if (hapd->iface->current_mode &&
198 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
199 (hapd->iconf->spectrum_mgmt_required || dfs))
200 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
206 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
207 u16 auth_transaction, const u8 *challenge,
210 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
212 "authentication (shared key, transaction %d)",
215 if (auth_transaction == 1) {
216 if (!sta->challenge) {
217 /* Generate a pseudo-random challenge */
221 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
222 if (sta->challenge == NULL)
223 return WLAN_STATUS_UNSPECIFIED_FAILURE;
227 os_memcpy(key, &now.sec, 4);
228 os_memcpy(key + 4, &r, 4);
229 rc4_skip(key, sizeof(key), 0,
230 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
235 if (auth_transaction != 3)
236 return WLAN_STATUS_UNSPECIFIED_FAILURE;
239 if (!iswep || !sta->challenge || !challenge ||
240 os_memcmp_const(sta->challenge, challenge,
241 WLAN_AUTH_CHALLENGE_LEN)) {
242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
244 "shared key authentication - invalid "
245 "challenge-response");
246 return WLAN_STATUS_CHALLENGE_FAIL;
249 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
251 "authentication OK (shared key)");
252 sta->flags |= WLAN_STA_AUTH;
253 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
254 os_free(sta->challenge);
255 sta->challenge = NULL;
261 static void send_auth_reply(struct hostapd_data *hapd,
262 const u8 *dst, const u8 *bssid,
263 u16 auth_alg, u16 auth_transaction, u16 resp,
264 const u8 *ies, size_t ies_len)
266 struct ieee80211_mgmt *reply;
270 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
271 buf = os_zalloc(rlen);
275 reply = (struct ieee80211_mgmt *) buf;
276 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
278 os_memcpy(reply->da, dst, ETH_ALEN);
279 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
280 os_memcpy(reply->bssid, bssid, ETH_ALEN);
282 reply->u.auth.auth_alg = host_to_le16(auth_alg);
283 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
284 reply->u.auth.status_code = host_to_le16(resp);
287 os_memcpy(reply->u.auth.variable, ies, ies_len);
289 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
290 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
291 MAC2STR(dst), auth_alg, auth_transaction,
292 resp, (unsigned long) ies_len);
293 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
294 wpa_printf(MSG_INFO, "send_auth_reply: send");
300 #ifdef CONFIG_IEEE80211R
301 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
302 u16 auth_transaction, u16 status,
303 const u8 *ies, size_t ies_len)
305 struct hostapd_data *hapd = ctx;
306 struct sta_info *sta;
308 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
309 status, ies, ies_len);
311 if (status != WLAN_STATUS_SUCCESS)
314 sta = ap_get_sta(hapd, dst);
318 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
319 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
320 sta->flags |= WLAN_STA_AUTH;
321 mlme_authenticate_indication(hapd, sta);
323 #endif /* CONFIG_IEEE80211R */
328 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
329 struct sta_info *sta)
333 if (hapd->conf->ssid.wpa_passphrase == NULL) {
334 wpa_printf(MSG_DEBUG, "SAE: No password available");
338 if (sae_prepare_commit(hapd->own_addr, sta->addr,
339 (u8 *) hapd->conf->ssid.wpa_passphrase,
340 os_strlen(hapd->conf->ssid.wpa_passphrase),
342 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
346 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
349 sae_write_commit(sta->sae, buf, NULL);
355 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
356 struct sta_info *sta)
360 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
364 sae_write_confirm(sta->sae, buf);
370 static int auth_sae_send_commit(struct hostapd_data *hapd,
371 struct sta_info *sta,
376 data = auth_build_sae_commit(hapd, sta);
378 return WLAN_STATUS_UNSPECIFIED_FAILURE;
380 send_auth_reply(hapd, sta->addr, bssid,
381 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
382 wpabuf_head(data), wpabuf_len(data));
386 return WLAN_STATUS_SUCCESS;
390 static int auth_sae_send_confirm(struct hostapd_data *hapd,
391 struct sta_info *sta,
396 data = auth_build_sae_confirm(hapd, sta);
398 return WLAN_STATUS_UNSPECIFIED_FAILURE;
400 send_auth_reply(hapd, sta->addr, bssid,
401 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
402 wpabuf_head(data), wpabuf_len(data));
406 return WLAN_STATUS_SUCCESS;
410 static int use_sae_anti_clogging(struct hostapd_data *hapd)
412 struct sta_info *sta;
413 unsigned int open = 0;
415 if (hapd->conf->sae_anti_clogging_threshold == 0)
418 for (sta = hapd->sta_list; sta; sta = sta->next) {
421 if (sta->sae->state != SAE_COMMITTED &&
422 sta->sae->state != SAE_CONFIRMED)
425 if (open >= hapd->conf->sae_anti_clogging_threshold)
433 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
434 const u8 *token, size_t token_len)
436 u8 mac[SHA256_MAC_LEN];
438 if (token_len != SHA256_MAC_LEN)
440 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
441 addr, ETH_ALEN, mac) < 0 ||
442 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
449 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
454 struct os_reltime now;
456 os_get_reltime(&now);
457 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
458 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
459 if (random_get_bytes(hapd->sae_token_key,
460 sizeof(hapd->sae_token_key)) < 0)
462 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
463 hapd->sae_token_key, sizeof(hapd->sae_token_key));
464 hapd->last_sae_token_key_update = now;
467 buf = wpabuf_alloc(SHA256_MAC_LEN);
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_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
480 const u8 *bssid, u8 auth_transaction)
484 if (auth_transaction != 1 && auth_transaction != 2)
485 return WLAN_STATUS_UNSPECIFIED_FAILURE;
487 switch (sta->sae->state) {
489 if (auth_transaction == 1) {
490 ret = auth_sae_send_commit(hapd, sta, bssid);
493 sta->sae->state = SAE_COMMITTED;
495 if (sae_process_commit(sta->sae) < 0)
496 return WLAN_STATUS_UNSPECIFIED_FAILURE;
499 * In mesh case, both Commit and Confirm can be sent
500 * immediately. In infrastructure BSS, only a single
501 * Authentication frame (Commit) is expected from the AP
502 * here and the second one (Confirm) will be sent once
503 * the STA has sent its second Authentication frame
506 if (hapd->conf->mesh & MESH_ENABLED) {
508 * Send both Commit and Confirm immediately
509 * based on SAE finite state machine
510 * Nothing -> Confirm transition.
512 ret = auth_sae_send_confirm(hapd, sta, bssid);
515 sta->sae->state = SAE_CONFIRMED;
518 * For infrastructure BSS, send only the Commit
519 * message now to get alternating sequence of
520 * Authentication frames between the AP and STA.
521 * Confirm will be sent in
522 * Commited -> Confirmed/Accepted transition
523 * when receiving Confirm from STA.
527 hostapd_logger(hapd, sta->addr,
528 HOSTAPD_MODULE_IEEE80211,
530 "SAE confirm before commit");
534 if (auth_transaction == 1) {
535 if (sae_process_commit(sta->sae) < 0)
536 return WLAN_STATUS_UNSPECIFIED_FAILURE;
538 ret = auth_sae_send_confirm(hapd, sta, bssid);
541 sta->sae->state = SAE_CONFIRMED;
542 } else if (hapd->conf->mesh & MESH_ENABLED) {
544 * In mesh case, follow SAE finite state machine and
547 ret = auth_sae_send_commit(hapd, sta, bssid);
552 * For instructure BSS, send the postponed Confirm from
553 * Nothing -> Confirmed transition that was reduced to
554 * Nothing -> Committed above.
556 ret = auth_sae_send_confirm(hapd, sta, bssid);
560 sta->sae->state = SAE_CONFIRMED;
563 * Since this was triggered on Confirm RX, run another
564 * step to get to Accepted without waiting for
567 return sae_sm_step(hapd, sta, bssid, auth_transaction);
571 if (auth_transaction == 1) {
572 ret = auth_sae_send_commit(hapd, sta, bssid);
576 if (sae_process_commit(sta->sae) < 0)
577 return WLAN_STATUS_UNSPECIFIED_FAILURE;
579 ret = auth_sae_send_confirm(hapd, sta, bssid);
583 sta->flags |= WLAN_STA_AUTH;
584 sta->auth_alg = WLAN_AUTH_SAE;
585 mlme_authenticate_indication(hapd, sta);
586 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
587 sta->sae->state = SAE_ACCEPTED;
588 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
593 if (auth_transaction == 1) {
594 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
595 ") doing reauthentication",
597 ap_free_sta(hapd, sta);
599 ret = auth_sae_send_confirm(hapd, sta, bssid);
600 sae_clear_temp_data(sta->sae);
606 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
608 return WLAN_STATUS_UNSPECIFIED_FAILURE;
610 return WLAN_STATUS_SUCCESS;
614 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
615 const struct ieee80211_mgmt *mgmt, size_t len,
618 u16 resp = WLAN_STATUS_SUCCESS;
619 struct wpabuf *data = NULL;
622 if (auth_transaction != 1)
624 sta->sae = os_zalloc(sizeof(*sta->sae));
625 if (sta->sae == NULL)
627 sta->sae->state = SAE_NOTHING;
630 if (auth_transaction == 1) {
631 const u8 *token = NULL;
632 size_t token_len = 0;
633 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
635 "start SAE authentication (RX commit)");
636 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
637 ((const u8 *) mgmt) + len -
638 mgmt->u.auth.variable, &token,
639 &token_len, hapd->conf->sae_groups);
640 if (token && check_sae_token(hapd, sta->addr, token, token_len)
642 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
643 "incorrect token from " MACSTR,
648 if (resp != WLAN_STATUS_SUCCESS)
651 if (!token && use_sae_anti_clogging(hapd)) {
652 wpa_printf(MSG_DEBUG,
653 "SAE: Request anti-clogging token from "
654 MACSTR, MAC2STR(sta->addr));
655 data = auth_build_token_req(hapd, sta->addr);
656 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
660 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
661 } else if (auth_transaction == 2) {
662 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
664 "SAE authentication (RX confirm)");
665 if (sta->sae->state >= SAE_CONFIRMED ||
666 !(hapd->conf->mesh & MESH_ENABLED)) {
667 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
668 ((u8 *) mgmt) + len -
669 mgmt->u.auth.variable) < 0) {
670 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
674 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
677 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
679 "unexpected SAE authentication transaction %u",
681 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
685 if (resp != WLAN_STATUS_SUCCESS) {
686 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
687 auth_transaction, resp,
688 data ? wpabuf_head(data) : (u8 *) "",
689 data ? wpabuf_len(data) : 0);
693 #endif /* CONFIG_SAE */
696 static void handle_auth(struct hostapd_data *hapd,
697 const struct ieee80211_mgmt *mgmt, size_t len)
699 u16 auth_alg, auth_transaction, status_code;
700 u16 resp = WLAN_STATUS_SUCCESS;
701 struct sta_info *sta = NULL;
704 const u8 *challenge = NULL;
705 u32 session_timeout, acct_interim_interval;
707 struct hostapd_sta_wpa_psk_short *psk = NULL;
708 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
709 size_t resp_ies_len = 0;
710 char *identity = NULL;
711 char *radius_cui = NULL;
714 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
715 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
716 (unsigned long) len);
720 #ifdef CONFIG_TESTING_OPTIONS
721 if (hapd->iconf->ignore_auth_probability > 0.0 &&
722 drand48() < hapd->iconf->ignore_auth_probability) {
724 "TESTING: ignoring auth frame from " MACSTR,
728 #endif /* CONFIG_TESTING_OPTIONS */
730 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
731 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
732 status_code = le_to_host16(mgmt->u.auth.status_code);
733 fc = le_to_host16(mgmt->frame_control);
734 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
736 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
737 2 + WLAN_AUTH_CHALLENGE_LEN &&
738 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
739 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
740 challenge = &mgmt->u.auth.variable[2];
742 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
743 "auth_transaction=%d status_code=%d wep=%d%s "
745 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
746 status_code, !!(fc & WLAN_FC_ISWEP),
747 challenge ? " challenge" : "",
748 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
750 if (hapd->tkip_countermeasures) {
751 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
755 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
756 auth_alg == WLAN_AUTH_OPEN) ||
757 #ifdef CONFIG_IEEE80211R
758 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
759 auth_alg == WLAN_AUTH_FT) ||
760 #endif /* CONFIG_IEEE80211R */
762 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
763 auth_alg == WLAN_AUTH_SAE) ||
764 #endif /* CONFIG_SAE */
765 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
766 auth_alg == WLAN_AUTH_SHARED_KEY))) {
767 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
769 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
773 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
774 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
775 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
777 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
781 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
782 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
784 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
788 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
790 &acct_interim_interval, &vlan_id,
791 &psk, &identity, &radius_cui);
793 if (res == HOSTAPD_ACL_REJECT) {
794 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
796 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
799 if (res == HOSTAPD_ACL_PENDING) {
800 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
801 " waiting for an external authentication",
803 /* Authentication code will re-send the authentication frame
804 * after it has received (and cached) information from the
805 * external source. */
809 sta = ap_get_sta(hapd, mgmt->sa);
811 if ((fc & WLAN_FC_RETRY) &&
812 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
813 sta->last_seq_ctrl == seq_ctrl &&
814 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
815 hostapd_logger(hapd, sta->addr,
816 HOSTAPD_MODULE_IEEE80211,
818 "Drop repeated authentication frame seq_ctrl=0x%x",
824 if (hapd->conf->mesh & MESH_ENABLED) {
825 /* if the mesh peer is not available, we don't do auth.
829 #endif /* CONFIG_MESH */
831 sta = ap_sta_add(hapd, mgmt->sa);
833 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
837 sta->last_seq_ctrl = seq_ctrl;
838 sta->last_subtype = WLAN_FC_STYPE_AUTH;
841 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
842 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
843 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
844 "%d received from RADIUS server",
846 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
849 sta->vlan_id = vlan_id;
850 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
851 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
854 hostapd_free_psk_list(sta->psk);
855 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
862 sta->identity = identity;
864 sta->radius_cui = radius_cui;
867 sta->flags &= ~WLAN_STA_PREAUTH;
868 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
870 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
871 sta->acct_interim_interval = acct_interim_interval;
872 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
873 ap_sta_session_timeout(hapd, sta, session_timeout);
875 ap_sta_no_session_timeout(hapd, sta);
879 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
881 "authentication OK (open system)");
882 sta->flags |= WLAN_STA_AUTH;
883 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
884 sta->auth_alg = WLAN_AUTH_OPEN;
885 mlme_authenticate_indication(hapd, sta);
887 case WLAN_AUTH_SHARED_KEY:
888 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
890 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
891 mlme_authenticate_indication(hapd, sta);
892 if (sta->challenge && auth_transaction == 1) {
893 resp_ies[0] = WLAN_EID_CHALLENGE;
894 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
895 os_memcpy(resp_ies + 2, sta->challenge,
896 WLAN_AUTH_CHALLENGE_LEN);
897 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
900 #ifdef CONFIG_IEEE80211R
902 sta->auth_alg = WLAN_AUTH_FT;
903 if (sta->wpa_sm == NULL)
904 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
906 if (sta->wpa_sm == NULL) {
907 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
909 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
912 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
913 auth_transaction, mgmt->u.auth.variable,
914 len - IEEE80211_HDRLEN -
915 sizeof(mgmt->u.auth),
916 handle_auth_ft_finish, hapd);
917 /* handle_auth_ft_finish() callback will complete auth. */
919 #endif /* CONFIG_IEEE80211R */
923 if (hapd->conf->mesh & MESH_ENABLED) {
924 if (sta->wpa_sm == NULL)
926 wpa_auth_sta_init(hapd->wpa_auth,
928 if (sta->wpa_sm == NULL) {
929 wpa_printf(MSG_DEBUG,
930 "SAE: Failed to initialize WPA state machine");
931 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
935 #endif /* CONFIG_MESH */
936 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
938 #endif /* CONFIG_SAE */
944 hostapd_free_psk_list(psk);
946 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
947 auth_transaction + 1, resp, resp_ies, resp_ies_len);
951 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
955 /* get a unique AID */
957 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
961 for (i = 0; i < AID_WORDS; i++) {
962 if (hapd->sta_aid[i] == (u32) -1)
964 for (j = 0; j < 32; j++) {
965 if (!(hapd->sta_aid[i] & BIT(j)))
973 aid = i * 32 + j + 1;
978 hapd->sta_aid[i] |= BIT(j);
979 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
984 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
985 const u8 *ssid_ie, size_t ssid_ie_len)
988 return WLAN_STATUS_UNSPECIFIED_FAILURE;
990 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
991 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
992 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
994 "Station tried to associate with unknown SSID "
995 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
996 return WLAN_STATUS_UNSPECIFIED_FAILURE;
999 return WLAN_STATUS_SUCCESS;
1003 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1004 const u8 *wmm_ie, size_t wmm_ie_len)
1006 sta->flags &= ~WLAN_STA_WMM;
1008 if (wmm_ie && hapd->conf->wmm_enabled) {
1009 struct wmm_information_element *wmm;
1011 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
1012 hostapd_logger(hapd, sta->addr,
1014 HOSTAPD_LEVEL_DEBUG,
1015 "invalid WMM element in association "
1017 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1020 sta->flags |= WLAN_STA_WMM;
1021 wmm = (struct wmm_information_element *) wmm_ie;
1022 sta->qosinfo = wmm->qos_info;
1024 return WLAN_STATUS_SUCCESS;
1028 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1029 struct ieee802_11_elems *elems)
1031 if (!elems->supp_rates) {
1032 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1033 HOSTAPD_LEVEL_DEBUG,
1034 "No supported rates element in AssocReq");
1035 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1038 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1039 sizeof(sta->supported_rates)) {
1040 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1041 HOSTAPD_LEVEL_DEBUG,
1042 "Invalid supported rates element length %d+%d",
1043 elems->supp_rates_len,
1044 elems->ext_supp_rates_len);
1045 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1048 sta->supported_rates_len = merge_byte_arrays(
1049 sta->supported_rates, sizeof(sta->supported_rates),
1050 elems->supp_rates, elems->supp_rates_len,
1051 elems->ext_supp_rates, elems->ext_supp_rates_len);
1053 return WLAN_STATUS_SUCCESS;
1057 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1058 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1060 #ifdef CONFIG_INTERWORKING
1061 /* check for QoS Map support */
1062 if (ext_capab_ie_len >= 5) {
1063 if (ext_capab_ie[4] & 0x01)
1064 sta->qos_map_enabled = 1;
1066 #endif /* CONFIG_INTERWORKING */
1068 return WLAN_STATUS_SUCCESS;
1072 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1073 const u8 *ies, size_t ies_len, int reassoc)
1075 struct ieee802_11_elems elems;
1079 const u8 *p2p_dev_addr = NULL;
1081 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1082 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1083 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1084 "association request");
1085 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1088 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1089 if (resp != WLAN_STATUS_SUCCESS)
1091 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1092 if (resp != WLAN_STATUS_SUCCESS)
1094 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1095 if (resp != WLAN_STATUS_SUCCESS)
1097 resp = copy_supp_rates(hapd, sta, &elems);
1098 if (resp != WLAN_STATUS_SUCCESS)
1100 #ifdef CONFIG_IEEE80211N
1101 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
1102 elems.ht_capabilities_len);
1103 if (resp != WLAN_STATUS_SUCCESS)
1105 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1106 !(sta->flags & WLAN_STA_HT)) {
1107 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1108 HOSTAPD_LEVEL_INFO, "Station does not support "
1109 "mandatory HT PHY - reject association");
1110 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1112 #endif /* CONFIG_IEEE80211N */
1114 #ifdef CONFIG_IEEE80211AC
1115 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
1116 elems.vht_capabilities_len);
1117 if (resp != WLAN_STATUS_SUCCESS)
1120 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1121 if (resp != WLAN_STATUS_SUCCESS)
1124 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1125 !(sta->flags & WLAN_STA_VHT)) {
1126 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1127 HOSTAPD_LEVEL_INFO, "Station does not support "
1128 "mandatory VHT PHY - reject association");
1129 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
1131 #endif /* CONFIG_IEEE80211AC */
1135 wpabuf_free(sta->p2p_ie);
1136 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1137 P2P_IE_VENDOR_TYPE);
1139 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1141 wpabuf_free(sta->p2p_ie);
1144 #endif /* CONFIG_P2P */
1146 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1147 wpa_ie = elems.rsn_ie;
1148 wpa_ie_len = elems.rsn_ie_len;
1149 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1151 wpa_ie = elems.wpa_ie;
1152 wpa_ie_len = elems.wpa_ie_len;
1159 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1160 if (hapd->conf->wps_state && elems.wps_ie) {
1161 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1162 "Request - assume WPS is used");
1163 sta->flags |= WLAN_STA_WPS;
1164 wpabuf_free(sta->wps_ie);
1165 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1166 WPS_IE_VENDOR_TYPE);
1167 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1168 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1169 sta->flags |= WLAN_STA_WPS2;
1173 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1174 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1175 "(Re)Association Request - reject");
1176 return WLAN_STATUS_INVALID_IE;
1178 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1179 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1180 "(Re)Association Request - possible WPS use");
1181 sta->flags |= WLAN_STA_MAYBE_WPS;
1183 #endif /* CONFIG_WPS */
1184 if (hapd->conf->wpa && wpa_ie == NULL) {
1185 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1187 "No WPA/RSN IE in association request");
1188 return WLAN_STATUS_INVALID_IE;
1191 if (hapd->conf->wpa && wpa_ie) {
1195 if (sta->wpa_sm == NULL)
1196 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1199 if (sta->wpa_sm == NULL) {
1200 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1202 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1204 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1206 elems.mdie, elems.mdie_len);
1207 if (res == WPA_INVALID_GROUP)
1208 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1209 else if (res == WPA_INVALID_PAIRWISE)
1210 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1211 else if (res == WPA_INVALID_AKMP)
1212 resp = WLAN_STATUS_AKMP_NOT_VALID;
1213 else if (res == WPA_ALLOC_FAIL)
1214 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1215 #ifdef CONFIG_IEEE80211W
1216 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1217 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1218 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1219 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1220 #endif /* CONFIG_IEEE80211W */
1221 else if (res == WPA_INVALID_MDIE)
1222 resp = WLAN_STATUS_INVALID_MDIE;
1223 else if (res != WPA_IE_OK)
1224 resp = WLAN_STATUS_INVALID_IE;
1225 if (resp != WLAN_STATUS_SUCCESS)
1227 #ifdef CONFIG_IEEE80211W
1228 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1229 sta->sa_query_count > 0)
1230 ap_check_sa_query_timeout(hapd, sta);
1231 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1232 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1234 * STA has already been associated with MFP and SA
1235 * Query timeout has not been reached. Reject the
1236 * association attempt temporarily and start SA Query,
1237 * if one is not pending.
1240 if (sta->sa_query_count == 0)
1241 ap_sta_start_sa_query(hapd, sta);
1243 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1246 if (wpa_auth_uses_mfp(sta->wpa_sm))
1247 sta->flags |= WLAN_STA_MFP;
1249 sta->flags &= ~WLAN_STA_MFP;
1250 #endif /* CONFIG_IEEE80211W */
1252 #ifdef CONFIG_IEEE80211R
1253 if (sta->auth_alg == WLAN_AUTH_FT) {
1255 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1256 "to use association (not "
1257 "re-association) with FT auth_alg",
1258 MAC2STR(sta->addr));
1259 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1262 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1264 if (resp != WLAN_STATUS_SUCCESS)
1267 #endif /* CONFIG_IEEE80211R */
1270 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1271 sta->auth_alg == WLAN_AUTH_OPEN) {
1272 struct rsn_pmksa_cache_entry *sa;
1273 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1274 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1275 wpa_printf(MSG_DEBUG,
1276 "SAE: No PMKSA cache entry found for "
1277 MACSTR, MAC2STR(sta->addr));
1278 return WLAN_STATUS_INVALID_PMKID;
1280 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1281 " using PMKSA caching", MAC2STR(sta->addr));
1282 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1283 sta->auth_alg != WLAN_AUTH_SAE &&
1284 !(sta->auth_alg == WLAN_AUTH_FT &&
1285 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1286 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1287 "SAE AKM after non-SAE auth_alg %u",
1288 MAC2STR(sta->addr), sta->auth_alg);
1289 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1291 #endif /* CONFIG_SAE */
1293 #ifdef CONFIG_IEEE80211N
1294 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1295 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1296 hostapd_logger(hapd, sta->addr,
1297 HOSTAPD_MODULE_IEEE80211,
1299 "Station tried to use TKIP with HT "
1301 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1303 #endif /* CONFIG_IEEE80211N */
1305 } else if (hapd->conf->osen) {
1306 if (elems.osen == NULL) {
1308 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1310 "No HS 2.0 OSEN element in association request");
1311 return WLAN_STATUS_INVALID_IE;
1314 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1315 if (sta->wpa_sm == NULL)
1316 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1318 if (sta->wpa_sm == NULL) {
1319 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1321 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1323 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1324 elems.osen - 2, elems.osen_len + 2) < 0)
1325 return WLAN_STATUS_INVALID_IE;
1326 #endif /* CONFIG_HS20 */
1328 wpa_auth_sta_no_wpa(sta->wpa_sm);
1331 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1332 #endif /* CONFIG_P2P */
1335 wpabuf_free(sta->hs20_ie);
1336 if (elems.hs20 && elems.hs20_len > 4) {
1337 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1338 elems.hs20_len - 4);
1340 sta->hs20_ie = NULL;
1341 #endif /* CONFIG_HS20 */
1343 return WLAN_STATUS_SUCCESS;
1347 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1351 struct ieee80211_mgmt reply;
1353 os_memset(&reply, 0, sizeof(reply));
1354 reply.frame_control =
1355 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1356 os_memcpy(reply.da, addr, ETH_ALEN);
1357 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1358 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1360 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1361 reply.u.deauth.reason_code = host_to_le16(reason_code);
1363 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1364 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1369 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1370 u16 status_code, int reassoc, const u8 *ies,
1374 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1375 struct ieee80211_mgmt *reply;
1378 os_memset(buf, 0, sizeof(buf));
1379 reply = (struct ieee80211_mgmt *) buf;
1380 reply->frame_control =
1381 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1382 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1383 WLAN_FC_STYPE_ASSOC_RESP));
1384 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1385 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1386 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1388 send_len = IEEE80211_HDRLEN;
1389 send_len += sizeof(reply->u.assoc_resp);
1390 reply->u.assoc_resp.capab_info =
1391 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1392 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1393 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1394 /* Supported rates */
1395 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1396 /* Extended supported rates */
1397 p = hostapd_eid_ext_supp_rates(hapd, p);
1399 #ifdef CONFIG_IEEE80211R
1400 if (status_code == WLAN_STATUS_SUCCESS) {
1401 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1402 * Transition Information, RSN, [RIC Response] */
1403 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1404 buf + sizeof(buf) - p,
1405 sta->auth_alg, ies, ies_len);
1407 #endif /* CONFIG_IEEE80211R */
1409 #ifdef CONFIG_IEEE80211W
1410 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1411 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1412 #endif /* CONFIG_IEEE80211W */
1414 #ifdef CONFIG_IEEE80211N
1415 p = hostapd_eid_ht_capabilities(hapd, p);
1416 p = hostapd_eid_ht_operation(hapd, p);
1417 #endif /* CONFIG_IEEE80211N */
1419 #ifdef CONFIG_IEEE80211AC
1420 p = hostapd_eid_vht_capabilities(hapd, p);
1421 p = hostapd_eid_vht_operation(hapd, p);
1422 #endif /* CONFIG_IEEE80211AC */
1424 p = hostapd_eid_ext_capab(hapd, p);
1425 p = hostapd_eid_bss_max_idle_period(hapd, p);
1426 if (sta->qos_map_enabled)
1427 p = hostapd_eid_qos_map_set(hapd, p);
1429 if (sta->flags & WLAN_STA_WMM)
1430 p = hostapd_eid_wmm(hapd, p);
1433 if ((sta->flags & WLAN_STA_WPS) ||
1434 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1435 struct wpabuf *wps = wps_build_assoc_resp_ie();
1437 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1438 p += wpabuf_len(wps);
1442 #endif /* CONFIG_WPS */
1446 struct wpabuf *p2p_resp_ie;
1447 enum p2p_status_code status;
1448 switch (status_code) {
1449 case WLAN_STATUS_SUCCESS:
1450 status = P2P_SC_SUCCESS;
1452 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1453 status = P2P_SC_FAIL_LIMIT_REACHED;
1456 status = P2P_SC_FAIL_INVALID_PARAMS;
1459 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1461 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1462 wpabuf_len(p2p_resp_ie));
1463 p += wpabuf_len(p2p_resp_ie);
1464 wpabuf_free(p2p_resp_ie);
1467 #endif /* CONFIG_P2P */
1469 #ifdef CONFIG_P2P_MANAGER
1470 if (hapd->conf->p2p & P2P_MANAGE)
1471 p = hostapd_eid_p2p_manage(hapd, p);
1472 #endif /* CONFIG_P2P_MANAGER */
1474 send_len += p - reply->u.assoc_resp.variable;
1476 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1477 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1482 static void handle_assoc(struct hostapd_data *hapd,
1483 const struct ieee80211_mgmt *mgmt, size_t len,
1486 u16 capab_info, listen_interval, seq_ctrl, fc;
1487 u16 resp = WLAN_STATUS_SUCCESS;
1490 struct sta_info *sta;
1492 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1493 sizeof(mgmt->u.assoc_req))) {
1494 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1495 reassoc, (unsigned long) len);
1499 #ifdef CONFIG_TESTING_OPTIONS
1501 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1502 drand48() < hapd->iconf->ignore_reassoc_probability) {
1503 wpa_printf(MSG_INFO,
1504 "TESTING: ignoring reassoc request from "
1505 MACSTR, MAC2STR(mgmt->sa));
1509 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1510 drand48() < hapd->iconf->ignore_assoc_probability) {
1511 wpa_printf(MSG_INFO,
1512 "TESTING: ignoring assoc request from "
1513 MACSTR, MAC2STR(mgmt->sa));
1517 #endif /* CONFIG_TESTING_OPTIONS */
1519 fc = le_to_host16(mgmt->frame_control);
1520 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1523 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1524 listen_interval = le_to_host16(
1525 mgmt->u.reassoc_req.listen_interval);
1526 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1527 " capab_info=0x%02x listen_interval=%d current_ap="
1528 MACSTR " seq_ctrl=0x%x%s",
1529 MAC2STR(mgmt->sa), capab_info, listen_interval,
1530 MAC2STR(mgmt->u.reassoc_req.current_ap),
1531 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1532 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1533 pos = mgmt->u.reassoc_req.variable;
1535 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1536 listen_interval = le_to_host16(
1537 mgmt->u.assoc_req.listen_interval);
1538 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1539 " capab_info=0x%02x listen_interval=%d "
1541 MAC2STR(mgmt->sa), capab_info, listen_interval,
1542 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
1543 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1544 pos = mgmt->u.assoc_req.variable;
1547 sta = ap_get_sta(hapd, mgmt->sa);
1548 #ifdef CONFIG_IEEE80211R
1549 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1550 (sta->flags & WLAN_STA_AUTH) == 0) {
1551 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1552 "prior to authentication since it is using "
1553 "over-the-DS FT", MAC2STR(mgmt->sa));
1555 #endif /* CONFIG_IEEE80211R */
1556 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1557 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1558 HOSTAPD_LEVEL_INFO, "Station tried to "
1559 "associate before authentication "
1560 "(aid=%d flags=0x%x)",
1561 sta ? sta->aid : -1,
1562 sta ? sta->flags : 0);
1563 send_deauth(hapd, mgmt->sa,
1564 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1568 if ((fc & WLAN_FC_RETRY) &&
1569 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1570 sta->last_seq_ctrl == seq_ctrl &&
1571 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1572 WLAN_FC_STYPE_ASSOC_REQ) {
1573 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1574 HOSTAPD_LEVEL_DEBUG,
1575 "Drop repeated association frame seq_ctrl=0x%x",
1579 sta->last_seq_ctrl = seq_ctrl;
1580 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1581 WLAN_FC_STYPE_ASSOC_REQ;
1583 if (hapd->tkip_countermeasures) {
1584 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1588 if (listen_interval > hapd->conf->max_listen_interval) {
1589 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1590 HOSTAPD_LEVEL_DEBUG,
1591 "Too large Listen Interval (%d)",
1593 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1597 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1599 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1600 if (resp != WLAN_STATUS_SUCCESS)
1603 if (hostapd_get_aid(hapd, sta) < 0) {
1604 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1605 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1606 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1610 sta->capability = capab_info;
1611 sta->listen_interval = listen_interval;
1613 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1614 sta->flags |= WLAN_STA_NONERP;
1615 for (i = 0; i < sta->supported_rates_len; i++) {
1616 if ((sta->supported_rates[i] & 0x7f) > 22) {
1617 sta->flags &= ~WLAN_STA_NONERP;
1621 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1622 sta->nonerp_set = 1;
1623 hapd->iface->num_sta_non_erp++;
1624 if (hapd->iface->num_sta_non_erp == 1)
1625 ieee802_11_set_beacons(hapd->iface);
1628 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1629 !sta->no_short_slot_time_set) {
1630 sta->no_short_slot_time_set = 1;
1631 hapd->iface->num_sta_no_short_slot_time++;
1632 if (hapd->iface->current_mode->mode ==
1633 HOSTAPD_MODE_IEEE80211G &&
1634 hapd->iface->num_sta_no_short_slot_time == 1)
1635 ieee802_11_set_beacons(hapd->iface);
1638 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1639 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1641 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1643 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1644 !sta->no_short_preamble_set) {
1645 sta->no_short_preamble_set = 1;
1646 hapd->iface->num_sta_no_short_preamble++;
1647 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1648 && hapd->iface->num_sta_no_short_preamble == 1)
1649 ieee802_11_set_beacons(hapd->iface);
1652 #ifdef CONFIG_IEEE80211N
1653 update_ht_state(hapd, sta);
1654 #endif /* CONFIG_IEEE80211N */
1656 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1657 HOSTAPD_LEVEL_DEBUG,
1658 "association OK (aid %d)", sta->aid);
1659 /* Station will be marked associated, after it acknowledges AssocResp
1661 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1663 #ifdef CONFIG_IEEE80211W
1664 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1665 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1666 "SA Query procedure", reassoc ? "re" : "");
1667 /* TODO: Send a protected Disassociate frame to the STA using
1668 * the old key and Reason Code "Previous Authentication no
1669 * longer valid". Make sure this is only sent protected since
1670 * unprotected frame would be received by the STA that is now
1671 * trying to associate.
1674 #endif /* CONFIG_IEEE80211W */
1676 /* Make sure that the previously registered inactivity timer will not
1677 * remove the STA immediately. */
1678 sta->timeout_next = STA_NULLFUNC;
1681 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1685 static void handle_disassoc(struct hostapd_data *hapd,
1686 const struct ieee80211_mgmt *mgmt, size_t len)
1688 struct sta_info *sta;
1690 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1691 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1692 (unsigned long) len);
1696 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1698 le_to_host16(mgmt->u.disassoc.reason_code));
1700 sta = ap_get_sta(hapd, mgmt->sa);
1702 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1707 ap_sta_set_authorized(hapd, sta, 0);
1708 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
1709 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1710 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1711 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1712 HOSTAPD_LEVEL_INFO, "disassociated");
1713 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1714 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1715 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1717 accounting_sta_stop(hapd, sta);
1718 ieee802_1x_free_station(sta);
1720 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
1721 hostapd_drv_sta_remove(hapd, sta->addr);
1723 if (sta->timeout_next == STA_NULLFUNC ||
1724 sta->timeout_next == STA_DISASSOC) {
1725 sta->timeout_next = STA_DEAUTH;
1726 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1727 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1731 mlme_disassociate_indication(
1732 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1736 static void handle_deauth(struct hostapd_data *hapd,
1737 const struct ieee80211_mgmt *mgmt, size_t len)
1739 struct sta_info *sta;
1741 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1742 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1743 "payload (len=%lu)", (unsigned long) len);
1747 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1749 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1751 sta = ap_get_sta(hapd, mgmt->sa);
1753 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1754 "to deauthenticate, but it is not authenticated",
1759 ap_sta_set_authorized(hapd, sta, 0);
1760 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
1761 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1762 WLAN_STA_ASSOC_REQ_OK);
1763 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1764 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1765 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1766 mlme_deauthenticate_indication(
1767 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1768 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1769 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1770 ap_free_sta(hapd, sta);
1774 static void handle_beacon(struct hostapd_data *hapd,
1775 const struct ieee80211_mgmt *mgmt, size_t len,
1776 struct hostapd_frame_info *fi)
1778 struct ieee802_11_elems elems;
1780 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1781 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1782 (unsigned long) len);
1786 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1787 len - (IEEE80211_HDRLEN +
1788 sizeof(mgmt->u.beacon)), &elems,
1791 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1795 #ifdef CONFIG_IEEE80211W
1797 static int hostapd_sa_query_action(struct hostapd_data *hapd,
1798 const struct ieee80211_mgmt *mgmt,
1803 end = mgmt->u.action.u.sa_query_resp.trans_id +
1804 WLAN_SA_QUERY_TR_ID_LEN;
1805 if (((u8 *) mgmt) + len < end) {
1806 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1807 "frame (len=%lu)", (unsigned long) len);
1811 ieee802_11_sa_query_action(hapd, mgmt->sa,
1812 mgmt->u.action.u.sa_query_resp.action,
1813 mgmt->u.action.u.sa_query_resp.trans_id);
1818 static int robust_action_frame(u8 category)
1820 return category != WLAN_ACTION_PUBLIC &&
1821 category != WLAN_ACTION_HT;
1823 #endif /* CONFIG_IEEE80211W */
1826 static int handle_action(struct hostapd_data *hapd,
1827 const struct ieee80211_mgmt *mgmt, size_t len)
1829 struct sta_info *sta;
1830 sta = ap_get_sta(hapd, mgmt->sa);
1832 if (len < IEEE80211_HDRLEN + 1) {
1833 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1834 HOSTAPD_LEVEL_DEBUG,
1835 "handle_action - too short payload (len=%lu)",
1836 (unsigned long) len);
1840 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1841 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1842 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1843 "frame (category=%u) from unassociated STA " MACSTR,
1844 MAC2STR(mgmt->sa), mgmt->u.action.category);
1848 #ifdef CONFIG_IEEE80211W
1849 if (sta && (sta->flags & WLAN_STA_MFP) &&
1850 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
1851 robust_action_frame(mgmt->u.action.category)) {
1852 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1853 HOSTAPD_LEVEL_DEBUG,
1854 "Dropped unprotected Robust Action frame from "
1858 #endif /* CONFIG_IEEE80211W */
1861 u16 fc = le_to_host16(mgmt->frame_control);
1862 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1864 if ((fc & WLAN_FC_RETRY) &&
1865 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1866 sta->last_seq_ctrl == seq_ctrl &&
1867 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
1868 hostapd_logger(hapd, sta->addr,
1869 HOSTAPD_MODULE_IEEE80211,
1870 HOSTAPD_LEVEL_DEBUG,
1871 "Drop repeated action frame seq_ctrl=0x%x",
1876 sta->last_seq_ctrl = seq_ctrl;
1877 sta->last_subtype = WLAN_FC_STYPE_ACTION;
1880 switch (mgmt->u.action.category) {
1881 #ifdef CONFIG_IEEE80211R
1882 case WLAN_ACTION_FT:
1884 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1885 len - IEEE80211_HDRLEN))
1888 #endif /* CONFIG_IEEE80211R */
1889 case WLAN_ACTION_WMM:
1890 hostapd_wmm_action(hapd, mgmt, len);
1892 #ifdef CONFIG_IEEE80211W
1893 case WLAN_ACTION_SA_QUERY:
1894 return hostapd_sa_query_action(hapd, mgmt, len);
1895 #endif /* CONFIG_IEEE80211W */
1897 case WLAN_ACTION_WNM:
1898 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
1900 #endif /* CONFIG_WNM */
1901 case WLAN_ACTION_PUBLIC:
1902 case WLAN_ACTION_PROTECTED_DUAL:
1903 #ifdef CONFIG_IEEE80211N
1904 if (mgmt->u.action.u.public_action.action ==
1905 WLAN_PA_20_40_BSS_COEX) {
1906 wpa_printf(MSG_DEBUG,
1907 "HT20/40 coex mgmt frame received from STA "
1908 MACSTR, MAC2STR(mgmt->sa));
1909 hostapd_2040_coex_action(hapd, mgmt, len);
1911 #endif /* CONFIG_IEEE80211N */
1912 if (hapd->public_action_cb) {
1913 hapd->public_action_cb(hapd->public_action_cb_ctx,
1917 if (hapd->public_action_cb2) {
1918 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1922 if (hapd->public_action_cb || hapd->public_action_cb2)
1925 case WLAN_ACTION_VENDOR_SPECIFIC:
1926 if (hapd->vendor_action_cb) {
1927 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1929 hapd->iface->freq) == 0)
1935 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1936 HOSTAPD_LEVEL_DEBUG,
1937 "handle_action - unknown action category %d or invalid "
1939 mgmt->u.action.category);
1940 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1941 !(mgmt->sa[0] & 0x01)) {
1942 struct ieee80211_mgmt *resp;
1945 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1946 * Return the Action frame to the source without change
1947 * except that MSB of the Category set to 1.
1949 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1950 "frame back to sender");
1951 resp = os_malloc(len);
1954 os_memcpy(resp, mgmt, len);
1955 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1956 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1957 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1958 resp->u.action.category |= 0x80;
1960 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1961 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1972 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1973 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1975 * @buf: management frame data (starting from IEEE 802.11 header)
1976 * @len: length of frame data in octets
1977 * @fi: meta data about received frame (signal level, etc.)
1979 * Process all incoming IEEE 802.11 management frames. This will be called for
1980 * each frame received from the kernel driver through wlan#ap interface. In
1981 * addition, it can be called to re-inserted pending frames (e.g., when using
1982 * external RADIUS server as an MAC ACL).
1984 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1985 struct hostapd_frame_info *fi)
1987 struct ieee80211_mgmt *mgmt;
1995 mgmt = (struct ieee80211_mgmt *) buf;
1996 fc = le_to_host16(mgmt->frame_control);
1997 stype = WLAN_FC_GET_STYPE(fc);
1999 if (stype == WLAN_FC_STYPE_BEACON) {
2000 handle_beacon(hapd, mgmt, len, fi);
2004 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2005 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2006 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2010 /* Invitation responses can be sent with the peer MAC as BSSID */
2011 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2012 stype == WLAN_FC_STYPE_ACTION) &&
2013 #endif /* CONFIG_P2P */
2015 !(hapd->conf->mesh & MESH_ENABLED) &&
2016 #endif /* CONFIG_MESH */
2017 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
2018 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2019 MAC2STR(mgmt->bssid));
2024 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
2025 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
2029 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2030 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2031 HOSTAPD_LEVEL_DEBUG,
2032 "MGMT: DA=" MACSTR " not our address",
2038 case WLAN_FC_STYPE_AUTH:
2039 wpa_printf(MSG_DEBUG, "mgmt::auth");
2040 handle_auth(hapd, mgmt, len);
2043 case WLAN_FC_STYPE_ASSOC_REQ:
2044 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2045 handle_assoc(hapd, mgmt, len, 0);
2048 case WLAN_FC_STYPE_REASSOC_REQ:
2049 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2050 handle_assoc(hapd, mgmt, len, 1);
2053 case WLAN_FC_STYPE_DISASSOC:
2054 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2055 handle_disassoc(hapd, mgmt, len);
2058 case WLAN_FC_STYPE_DEAUTH:
2059 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
2060 handle_deauth(hapd, mgmt, len);
2063 case WLAN_FC_STYPE_ACTION:
2064 wpa_printf(MSG_DEBUG, "mgmt::action");
2065 ret = handle_action(hapd, mgmt, len);
2068 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2069 HOSTAPD_LEVEL_DEBUG,
2070 "unknown mgmt frame subtype %d", stype);
2078 static void handle_auth_cb(struct hostapd_data *hapd,
2079 const struct ieee80211_mgmt *mgmt,
2082 u16 auth_alg, auth_transaction, status_code;
2083 struct sta_info *sta;
2086 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2087 HOSTAPD_LEVEL_NOTICE,
2088 "did not acknowledge authentication response");
2092 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2093 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2094 (unsigned long) len);
2098 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2099 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2100 status_code = le_to_host16(mgmt->u.auth.status_code);
2102 sta = ap_get_sta(hapd, mgmt->da);
2104 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2109 if (status_code == WLAN_STATUS_SUCCESS &&
2110 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2111 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2112 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2113 HOSTAPD_LEVEL_INFO, "authenticated");
2114 sta->flags |= WLAN_STA_AUTH;
2119 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2120 struct sta_info *sta,
2124 struct hostapd_ssid *ssid = sta->ssid;
2126 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2129 for (i = 0; i < 4; i++) {
2130 if (ssid->wep.key[i] &&
2131 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2132 i == ssid->wep.idx, NULL, 0,
2133 ssid->wep.key[i], ssid->wep.len[i])) {
2134 wpa_printf(MSG_WARNING,
2135 "Could not set WEP keys for WDS interface; %s",
2143 static void handle_assoc_cb(struct hostapd_data *hapd,
2144 const struct ieee80211_mgmt *mgmt,
2145 size_t len, int reassoc, int ok)
2148 struct sta_info *sta;
2150 struct ieee80211_ht_capabilities ht_cap;
2151 struct ieee80211_vht_capabilities vht_cap;
2153 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2154 sizeof(mgmt->u.assoc_resp))) {
2155 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2156 reassoc, (unsigned long) len);
2160 sta = ap_get_sta(hapd, mgmt->da);
2162 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2168 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2169 HOSTAPD_LEVEL_DEBUG,
2170 "did not acknowledge association response");
2171 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2176 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2178 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2180 if (status != WLAN_STATUS_SUCCESS)
2183 /* Stop previous accounting session, if one is started, and allocate
2184 * new session id for the new session. */
2185 accounting_sta_stop(hapd, sta);
2187 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2189 "associated (aid %d)",
2192 if (sta->flags & WLAN_STA_ASSOC)
2194 sta->flags |= WLAN_STA_ASSOC;
2195 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
2196 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
2197 sta->auth_alg == WLAN_AUTH_FT) {
2199 * Open, static WEP, or FT protocol; no separate authorization
2202 ap_sta_set_authorized(hapd, sta, 1);
2206 mlme_reassociate_indication(hapd, sta);
2208 mlme_associate_indication(hapd, sta);
2210 #ifdef CONFIG_IEEE80211W
2211 sta->sa_query_timed_out = 0;
2212 #endif /* CONFIG_IEEE80211W */
2215 * Remove the STA entry in order to make sure the STA PS state gets
2216 * cleared and configuration gets updated in case of reassociation back
2219 hostapd_drv_sta_remove(hapd, sta->addr);
2221 #ifdef CONFIG_IEEE80211N
2222 if (sta->flags & WLAN_STA_HT)
2223 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2224 #endif /* CONFIG_IEEE80211N */
2225 #ifdef CONFIG_IEEE80211AC
2226 if (sta->flags & WLAN_STA_VHT)
2227 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2228 #endif /* CONFIG_IEEE80211AC */
2230 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2231 sta->supported_rates, sta->supported_rates_len,
2232 sta->listen_interval,
2233 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
2234 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
2235 sta->flags, sta->qosinfo, sta->vht_opmode)) {
2236 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2237 HOSTAPD_LEVEL_NOTICE,
2238 "Could not add STA to kernel driver");
2240 ap_sta_disconnect(hapd, sta, sta->addr,
2241 WLAN_REASON_DISASSOC_AP_BUSY);
2246 if (sta->flags & WLAN_STA_WDS) {
2248 char ifname_wds[IFNAMSIZ + 1];
2250 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2253 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2256 if (sta->eapol_sm == NULL) {
2258 * This STA does not use RADIUS server for EAP authentication,
2259 * so bind it to the selected VLAN interface now, since the
2260 * interface selection is not going to change anymore.
2262 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2264 } else if (sta->vlan_id) {
2265 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2266 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2270 hostapd_set_sta_flags(hapd, sta);
2272 if (sta->auth_alg == WLAN_AUTH_FT)
2273 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2275 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2276 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2278 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2282 static void handle_deauth_cb(struct hostapd_data *hapd,
2283 const struct ieee80211_mgmt *mgmt,
2286 struct sta_info *sta;
2287 if (mgmt->da[0] & 0x01)
2289 sta = ap_get_sta(hapd, mgmt->da);
2291 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2292 " not found", MAC2STR(mgmt->da));
2296 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2297 MAC2STR(sta->addr));
2299 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2300 "deauth", MAC2STR(sta->addr));
2302 ap_sta_deauth_cb(hapd, sta);
2306 static void handle_disassoc_cb(struct hostapd_data *hapd,
2307 const struct ieee80211_mgmt *mgmt,
2310 struct sta_info *sta;
2311 if (mgmt->da[0] & 0x01)
2313 sta = ap_get_sta(hapd, mgmt->da);
2315 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2316 " not found", MAC2STR(mgmt->da));
2320 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2321 MAC2STR(sta->addr));
2323 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2324 "disassoc", MAC2STR(sta->addr));
2326 ap_sta_disassoc_cb(hapd, sta);
2331 * ieee802_11_mgmt_cb - Process management frame TX status callback
2332 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2334 * @buf: management frame data (starting from IEEE 802.11 header)
2335 * @len: length of frame data in octets
2336 * @stype: management frame subtype from frame control field
2337 * @ok: Whether the frame was ACK'ed
2339 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2342 const struct ieee80211_mgmt *mgmt;
2343 mgmt = (const struct ieee80211_mgmt *) buf;
2345 #ifdef CONFIG_TESTING_OPTIONS
2346 if (hapd->ext_mgmt_frame_handling) {
2347 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2351 #endif /* CONFIG_TESTING_OPTIONS */
2354 case WLAN_FC_STYPE_AUTH:
2355 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2356 handle_auth_cb(hapd, mgmt, len, ok);
2358 case WLAN_FC_STYPE_ASSOC_RESP:
2359 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2360 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2362 case WLAN_FC_STYPE_REASSOC_RESP:
2363 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2364 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2366 case WLAN_FC_STYPE_PROBE_RESP:
2367 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2369 case WLAN_FC_STYPE_DEAUTH:
2370 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2371 handle_deauth_cb(hapd, mgmt, len, ok);
2373 case WLAN_FC_STYPE_DISASSOC:
2374 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2375 handle_disassoc_cb(hapd, mgmt, len, ok);
2377 case WLAN_FC_STYPE_ACTION:
2378 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2381 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2387 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2394 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2395 char *buf, size_t buflen)
2402 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2403 const u8 *buf, size_t len, int ack)
2405 struct sta_info *sta;
2406 struct hostapd_iface *iface = hapd->iface;
2408 sta = ap_get_sta(hapd, addr);
2409 if (sta == NULL && iface->num_bss > 1) {
2411 for (j = 0; j < iface->num_bss; j++) {
2412 hapd = iface->bss[j];
2413 sta = ap_get_sta(hapd, addr);
2418 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2420 if (sta->flags & WLAN_STA_PENDING_POLL) {
2421 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2422 "activity poll", MAC2STR(sta->addr),
2423 ack ? "ACKed" : "did not ACK");
2425 sta->flags &= ~WLAN_STA_PENDING_POLL;
2428 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2432 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2433 const u8 *data, size_t len, int ack)
2435 struct sta_info *sta;
2436 struct hostapd_iface *iface = hapd->iface;
2438 sta = ap_get_sta(hapd, dst);
2439 if (sta == NULL && iface->num_bss > 1) {
2441 for (j = 0; j < iface->num_bss; j++) {
2442 hapd = iface->bss[j];
2443 sta = ap_get_sta(hapd, dst);
2448 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2449 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2450 MACSTR " that is not currently associated",
2455 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2459 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2461 struct sta_info *sta;
2462 struct hostapd_iface *iface = hapd->iface;
2464 sta = ap_get_sta(hapd, addr);
2465 if (sta == NULL && iface->num_bss > 1) {
2467 for (j = 0; j < iface->num_bss; j++) {
2468 hapd = iface->bss[j];
2469 sta = ap_get_sta(hapd, addr);
2476 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2479 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2480 "activity poll", MAC2STR(sta->addr));
2481 sta->flags &= ~WLAN_STA_PENDING_POLL;
2485 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2488 struct sta_info *sta;
2490 sta = ap_get_sta(hapd, src);
2491 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2492 if (!hapd->conf->wds_sta)
2495 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2497 char ifname_wds[IFNAMSIZ + 1];
2499 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2500 "STA " MACSTR " (aid %u)",
2501 MAC2STR(sta->addr), sta->aid);
2502 sta->flags |= WLAN_STA_WDS;
2503 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2504 sta->addr, sta->aid, 1);
2506 hostapd_set_wds_encryption(hapd, sta,
2512 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2513 MACSTR, MAC2STR(src));
2514 if (src[0] & 0x01) {
2515 /* Broadcast bit set in SA?! Ignore the frame silently. */
2519 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2520 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2521 "already been sent, but no TX status yet known - "
2522 "ignore Class 3 frame issue with " MACSTR,
2527 if (sta && (sta->flags & WLAN_STA_AUTH))
2528 hostapd_drv_sta_disassoc(
2530 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2532 hostapd_drv_sta_deauth(
2534 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2538 #endif /* CONFIG_NATIVE_WINDOWS */