2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2013, 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"
34 #include "accounting.h"
35 #include "ap_config.h"
37 #include "p2p_hostapd.h"
38 #include "ap_drv_ops.h"
40 #include "ieee802_11.h"
44 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
49 if (hapd->iface->current_rates == NULL)
52 *pos++ = WLAN_EID_SUPP_RATES;
53 num = hapd->iface->num_rates;
54 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
56 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
59 /* rest of the rates are encoded in Extended supported
65 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
68 *pos = hapd->iface->current_rates[i].rate / 5;
69 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
74 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
76 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
79 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
81 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
88 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
93 if (hapd->iface->current_rates == NULL)
96 num = hapd->iface->num_rates;
97 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
99 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
105 *pos++ = WLAN_EID_EXT_SUPP_RATES;
107 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
111 continue; /* already in SuppRates IE */
112 *pos = hapd->iface->current_rates[i].rate / 5;
113 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
118 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
121 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
124 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
127 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
134 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
137 int capab = WLAN_CAPABILITY_ESS;
141 /* Check if any of configured channels require DFS */
142 dfs = hostapd_is_dfs_required(hapd->iface);
144 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
149 if (hapd->iface->num_sta_no_short_preamble == 0 &&
150 hapd->iconf->preamble == SHORT_PREAMBLE)
151 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
153 privacy = hapd->conf->ssid.wep.keys_set;
155 if (hapd->conf->ieee802_1x &&
156 (hapd->conf->default_wep_key_len ||
157 hapd->conf->individual_wep_key_len))
164 if (hapd->conf->osen)
166 #endif /* CONFIG_HS20 */
169 int policy, def_klen;
170 if (probe && sta->ssid_probe) {
171 policy = sta->ssid_probe->security_policy;
172 def_klen = sta->ssid_probe->wep.default_len;
174 policy = sta->ssid->security_policy;
175 def_klen = sta->ssid->wep.default_len;
177 privacy = policy != SECURITY_PLAINTEXT;
178 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
183 capab |= WLAN_CAPABILITY_PRIVACY;
185 if (hapd->iface->current_mode &&
186 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
187 hapd->iface->num_sta_no_short_slot_time == 0)
188 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
191 * Currently, Spectrum Management capability bit is set when directly
192 * requested in configuration by spectrum_mgmt_required or when AP is
193 * running on DFS channel.
194 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
196 if (hapd->iface->current_mode &&
197 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
198 (hapd->iconf->spectrum_mgmt_required || dfs))
199 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
205 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
206 u16 auth_transaction, const u8 *challenge,
209 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
211 "authentication (shared key, transaction %d)",
214 if (auth_transaction == 1) {
215 if (!sta->challenge) {
216 /* Generate a pseudo-random challenge */
220 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
221 if (sta->challenge == NULL)
222 return WLAN_STATUS_UNSPECIFIED_FAILURE;
226 os_memcpy(key, &now.sec, 4);
227 os_memcpy(key + 4, &r, 4);
228 rc4_skip(key, sizeof(key), 0,
229 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
234 if (auth_transaction != 3)
235 return WLAN_STATUS_UNSPECIFIED_FAILURE;
238 if (!iswep || !sta->challenge || !challenge ||
239 os_memcmp_const(sta->challenge, challenge,
240 WLAN_AUTH_CHALLENGE_LEN)) {
241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 "shared key authentication - invalid "
244 "challenge-response");
245 return WLAN_STATUS_CHALLENGE_FAIL;
248 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
250 "authentication OK (shared key)");
251 sta->flags |= WLAN_STA_AUTH;
252 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
253 os_free(sta->challenge);
254 sta->challenge = NULL;
260 static void send_auth_reply(struct hostapd_data *hapd,
261 const u8 *dst, const u8 *bssid,
262 u16 auth_alg, u16 auth_transaction, u16 resp,
263 const u8 *ies, size_t ies_len)
265 struct ieee80211_mgmt *reply;
269 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
270 buf = os_zalloc(rlen);
274 reply = (struct ieee80211_mgmt *) buf;
275 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
277 os_memcpy(reply->da, dst, ETH_ALEN);
278 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
279 os_memcpy(reply->bssid, bssid, ETH_ALEN);
281 reply->u.auth.auth_alg = host_to_le16(auth_alg);
282 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
283 reply->u.auth.status_code = host_to_le16(resp);
286 os_memcpy(reply->u.auth.variable, ies, ies_len);
288 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
289 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
290 MAC2STR(dst), auth_alg, auth_transaction,
291 resp, (unsigned long) ies_len);
292 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
293 wpa_printf(MSG_INFO, "send_auth_reply: send");
299 #ifdef CONFIG_IEEE80211R
300 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
301 u16 auth_transaction, u16 status,
302 const u8 *ies, size_t ies_len)
304 struct hostapd_data *hapd = ctx;
305 struct sta_info *sta;
307 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
308 status, ies, ies_len);
310 if (status != WLAN_STATUS_SUCCESS)
313 sta = ap_get_sta(hapd, dst);
317 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
318 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
319 sta->flags |= WLAN_STA_AUTH;
320 mlme_authenticate_indication(hapd, sta);
322 #endif /* CONFIG_IEEE80211R */
327 static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
328 struct sta_info *sta)
332 if (hapd->conf->ssid.wpa_passphrase == NULL) {
333 wpa_printf(MSG_DEBUG, "SAE: No password available");
337 if (sae_prepare_commit(hapd->own_addr, sta->addr,
338 (u8 *) hapd->conf->ssid.wpa_passphrase,
339 os_strlen(hapd->conf->ssid.wpa_passphrase),
341 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
345 if (sae_process_commit(sta->sae) < 0) {
346 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
350 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
353 sae_write_commit(sta->sae, buf, NULL);
359 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
360 struct sta_info *sta)
364 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
368 sae_write_confirm(sta->sae, buf);
374 static int use_sae_anti_clogging(struct hostapd_data *hapd)
376 struct sta_info *sta;
377 unsigned int open = 0;
379 if (hapd->conf->sae_anti_clogging_threshold == 0)
382 for (sta = hapd->sta_list; sta; sta = sta->next) {
385 if (sta->sae->state != SAE_COMMITTED &&
386 sta->sae->state != SAE_CONFIRMED)
389 if (open >= hapd->conf->sae_anti_clogging_threshold)
397 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
398 const u8 *token, size_t token_len)
400 u8 mac[SHA256_MAC_LEN];
402 if (token_len != SHA256_MAC_LEN)
404 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
405 addr, ETH_ALEN, mac) < 0 ||
406 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
413 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
418 struct os_reltime now;
420 os_get_reltime(&now);
421 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
422 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
423 if (random_get_bytes(hapd->sae_token_key,
424 sizeof(hapd->sae_token_key)) < 0)
426 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
427 hapd->sae_token_key, sizeof(hapd->sae_token_key));
428 hapd->last_sae_token_key_update = now;
431 buf = wpabuf_alloc(SHA256_MAC_LEN);
435 token = wpabuf_put(buf, SHA256_MAC_LEN);
436 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
437 addr, ETH_ALEN, token);
443 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
444 const struct ieee80211_mgmt *mgmt, size_t len,
447 u16 resp = WLAN_STATUS_SUCCESS;
448 struct wpabuf *data = NULL;
451 if (auth_transaction != 1)
453 sta->sae = os_zalloc(sizeof(*sta->sae));
454 if (sta->sae == NULL)
456 sta->sae->state = SAE_NOTHING;
459 if (auth_transaction == 1) {
460 const u8 *token = NULL;
461 size_t token_len = 0;
462 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
464 "start SAE authentication (RX commit)");
465 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
466 ((const u8 *) mgmt) + len -
467 mgmt->u.auth.variable, &token,
468 &token_len, hapd->conf->sae_groups);
469 if (token && check_sae_token(hapd, sta->addr, token, token_len)
471 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
472 "incorrect token from " MACSTR,
477 if (resp == WLAN_STATUS_SUCCESS) {
478 if (!token && use_sae_anti_clogging(hapd)) {
479 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
480 "clogging token from " MACSTR,
482 data = auth_build_token_req(hapd, sta->addr);
483 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
485 data = auth_process_sae_commit(hapd, sta);
487 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
489 sta->sae->state = SAE_COMMITTED;
492 } else if (auth_transaction == 2) {
493 if (sta->sae->state != SAE_COMMITTED) {
494 hostapd_logger(hapd, sta->addr,
495 HOSTAPD_MODULE_IEEE80211,
497 "SAE confirm before commit");
498 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
501 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
503 "SAE authentication (RX confirm)");
504 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
505 ((u8 *) mgmt) + len -
506 mgmt->u.auth.variable) < 0) {
507 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
509 resp = WLAN_STATUS_SUCCESS;
510 sta->flags |= WLAN_STA_AUTH;
511 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
512 sta->auth_alg = WLAN_AUTH_SAE;
513 mlme_authenticate_indication(hapd, sta);
515 data = auth_build_sae_confirm(hapd, sta);
517 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
519 sta->sae->state = SAE_ACCEPTED;
520 sae_clear_temp_data(sta->sae);
524 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
526 "unexpected SAE authentication transaction %u",
528 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
532 sta->auth_alg = WLAN_AUTH_SAE;
534 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
535 auth_transaction, resp,
536 data ? wpabuf_head(data) : (u8 *) "",
537 data ? wpabuf_len(data) : 0);
540 #endif /* CONFIG_SAE */
543 static void handle_auth(struct hostapd_data *hapd,
544 const struct ieee80211_mgmt *mgmt, size_t len)
546 u16 auth_alg, auth_transaction, status_code;
547 u16 resp = WLAN_STATUS_SUCCESS;
548 struct sta_info *sta = NULL;
551 const u8 *challenge = NULL;
552 u32 session_timeout, acct_interim_interval;
554 struct hostapd_sta_wpa_psk_short *psk = NULL;
555 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
556 size_t resp_ies_len = 0;
557 char *identity = NULL;
558 char *radius_cui = NULL;
560 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
561 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
562 (unsigned long) len);
566 #ifdef CONFIG_TESTING_OPTIONS
567 if (hapd->iconf->ignore_auth_probability > 0.0 &&
568 drand48() < hapd->iconf->ignore_auth_probability) {
570 "TESTING: ignoring auth frame from " MACSTR,
574 #endif /* CONFIG_TESTING_OPTIONS */
576 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
577 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
578 status_code = le_to_host16(mgmt->u.auth.status_code);
579 fc = le_to_host16(mgmt->frame_control);
581 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
582 2 + WLAN_AUTH_CHALLENGE_LEN &&
583 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
584 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
585 challenge = &mgmt->u.auth.variable[2];
587 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
588 "auth_transaction=%d status_code=%d wep=%d%s",
589 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
590 status_code, !!(fc & WLAN_FC_ISWEP),
591 challenge ? " challenge" : "");
593 if (hapd->tkip_countermeasures) {
594 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
598 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
599 auth_alg == WLAN_AUTH_OPEN) ||
600 #ifdef CONFIG_IEEE80211R
601 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
602 auth_alg == WLAN_AUTH_FT) ||
603 #endif /* CONFIG_IEEE80211R */
605 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
606 auth_alg == WLAN_AUTH_SAE) ||
607 #endif /* CONFIG_SAE */
608 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
609 auth_alg == WLAN_AUTH_SHARED_KEY))) {
610 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
612 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
616 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
617 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
618 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
620 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
624 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
625 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
627 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
631 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
633 &acct_interim_interval, &vlan_id,
634 &psk, &identity, &radius_cui);
636 if (res == HOSTAPD_ACL_REJECT) {
637 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
639 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
642 if (res == HOSTAPD_ACL_PENDING) {
643 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
644 " waiting for an external authentication",
646 /* Authentication code will re-send the authentication frame
647 * after it has received (and cached) information from the
648 * external source. */
652 sta = ap_sta_add(hapd, mgmt->sa);
654 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
659 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
660 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
661 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
662 "%d received from RADIUS server",
664 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
667 sta->vlan_id = vlan_id;
668 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
669 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
672 hostapd_free_psk_list(sta->psk);
673 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
680 sta->identity = identity;
682 sta->radius_cui = radius_cui;
685 sta->flags &= ~WLAN_STA_PREAUTH;
686 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
688 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
689 sta->acct_interim_interval = acct_interim_interval;
690 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
691 ap_sta_session_timeout(hapd, sta, session_timeout);
693 ap_sta_no_session_timeout(hapd, sta);
697 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
699 "authentication OK (open system)");
700 sta->flags |= WLAN_STA_AUTH;
701 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
702 sta->auth_alg = WLAN_AUTH_OPEN;
703 mlme_authenticate_indication(hapd, sta);
705 case WLAN_AUTH_SHARED_KEY:
706 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
708 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
709 mlme_authenticate_indication(hapd, sta);
710 if (sta->challenge && auth_transaction == 1) {
711 resp_ies[0] = WLAN_EID_CHALLENGE;
712 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
713 os_memcpy(resp_ies + 2, sta->challenge,
714 WLAN_AUTH_CHALLENGE_LEN);
715 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
718 #ifdef CONFIG_IEEE80211R
720 sta->auth_alg = WLAN_AUTH_FT;
721 if (sta->wpa_sm == NULL)
722 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
724 if (sta->wpa_sm == NULL) {
725 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
727 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
730 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
731 auth_transaction, mgmt->u.auth.variable,
732 len - IEEE80211_HDRLEN -
733 sizeof(mgmt->u.auth),
734 handle_auth_ft_finish, hapd);
735 /* handle_auth_ft_finish() callback will complete auth. */
737 #endif /* CONFIG_IEEE80211R */
740 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
742 #endif /* CONFIG_SAE */
748 hostapd_free_psk_list(psk);
750 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
751 auth_transaction + 1, resp, resp_ies, resp_ies_len);
755 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
759 /* get a unique AID */
761 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
765 for (i = 0; i < AID_WORDS; i++) {
766 if (hapd->sta_aid[i] == (u32) -1)
768 for (j = 0; j < 32; j++) {
769 if (!(hapd->sta_aid[i] & BIT(j)))
777 aid = i * 32 + j + 1;
782 hapd->sta_aid[i] |= BIT(j);
783 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
788 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
789 const u8 *ssid_ie, size_t ssid_ie_len)
792 return WLAN_STATUS_UNSPECIFIED_FAILURE;
794 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
795 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
796 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
798 "Station tried to associate with unknown SSID "
799 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
800 return WLAN_STATUS_UNSPECIFIED_FAILURE;
803 return WLAN_STATUS_SUCCESS;
807 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
808 const u8 *wmm_ie, size_t wmm_ie_len)
810 sta->flags &= ~WLAN_STA_WMM;
812 if (wmm_ie && hapd->conf->wmm_enabled) {
813 struct wmm_information_element *wmm;
815 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
816 hostapd_logger(hapd, sta->addr,
819 "invalid WMM element in association "
821 return WLAN_STATUS_UNSPECIFIED_FAILURE;
824 sta->flags |= WLAN_STA_WMM;
825 wmm = (struct wmm_information_element *) wmm_ie;
826 sta->qosinfo = wmm->qos_info;
828 return WLAN_STATUS_SUCCESS;
832 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
833 struct ieee802_11_elems *elems)
835 if (!elems->supp_rates) {
836 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
838 "No supported rates element in AssocReq");
839 return WLAN_STATUS_UNSPECIFIED_FAILURE;
842 if (elems->supp_rates_len + elems->ext_supp_rates_len >
843 sizeof(sta->supported_rates)) {
844 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
846 "Invalid supported rates element length %d+%d",
847 elems->supp_rates_len,
848 elems->ext_supp_rates_len);
849 return WLAN_STATUS_UNSPECIFIED_FAILURE;
852 sta->supported_rates_len = merge_byte_arrays(
853 sta->supported_rates, sizeof(sta->supported_rates),
854 elems->supp_rates, elems->supp_rates_len,
855 elems->ext_supp_rates, elems->ext_supp_rates_len);
857 return WLAN_STATUS_SUCCESS;
861 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
862 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
864 #ifdef CONFIG_INTERWORKING
865 /* check for QoS Map support */
866 if (ext_capab_ie_len >= 5) {
867 if (ext_capab_ie[4] & 0x01)
868 sta->qos_map_enabled = 1;
870 #endif /* CONFIG_INTERWORKING */
872 return WLAN_STATUS_SUCCESS;
876 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
877 const u8 *ies, size_t ies_len, int reassoc)
879 struct ieee802_11_elems elems;
883 const u8 *p2p_dev_addr = NULL;
885 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
886 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
887 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
888 "association request");
889 return WLAN_STATUS_UNSPECIFIED_FAILURE;
892 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
893 if (resp != WLAN_STATUS_SUCCESS)
895 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
896 if (resp != WLAN_STATUS_SUCCESS)
898 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
899 if (resp != WLAN_STATUS_SUCCESS)
901 resp = copy_supp_rates(hapd, sta, &elems);
902 if (resp != WLAN_STATUS_SUCCESS)
904 #ifdef CONFIG_IEEE80211N
905 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
906 elems.ht_capabilities_len);
907 if (resp != WLAN_STATUS_SUCCESS)
909 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
910 !(sta->flags & WLAN_STA_HT)) {
911 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
912 HOSTAPD_LEVEL_INFO, "Station does not support "
913 "mandatory HT PHY - reject association");
914 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
916 #endif /* CONFIG_IEEE80211N */
918 #ifdef CONFIG_IEEE80211AC
919 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
920 elems.vht_capabilities_len);
921 if (resp != WLAN_STATUS_SUCCESS)
924 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
925 if (resp != WLAN_STATUS_SUCCESS)
928 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
929 !(sta->flags & WLAN_STA_VHT)) {
930 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
931 HOSTAPD_LEVEL_INFO, "Station does not support "
932 "mandatory VHT PHY - reject association");
933 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
935 #endif /* CONFIG_IEEE80211AC */
939 wpabuf_free(sta->p2p_ie);
940 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
943 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
945 wpabuf_free(sta->p2p_ie);
948 #endif /* CONFIG_P2P */
950 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
951 wpa_ie = elems.rsn_ie;
952 wpa_ie_len = elems.rsn_ie_len;
953 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
955 wpa_ie = elems.wpa_ie;
956 wpa_ie_len = elems.wpa_ie_len;
963 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
964 if (hapd->conf->wps_state && elems.wps_ie) {
965 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
966 "Request - assume WPS is used");
967 sta->flags |= WLAN_STA_WPS;
968 wpabuf_free(sta->wps_ie);
969 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
971 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
972 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
973 sta->flags |= WLAN_STA_WPS2;
977 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
978 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
979 "(Re)Association Request - reject");
980 return WLAN_STATUS_INVALID_IE;
982 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
983 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
984 "(Re)Association Request - possible WPS use");
985 sta->flags |= WLAN_STA_MAYBE_WPS;
987 #endif /* CONFIG_WPS */
988 if (hapd->conf->wpa && wpa_ie == NULL) {
989 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
991 "No WPA/RSN IE in association request");
992 return WLAN_STATUS_INVALID_IE;
995 if (hapd->conf->wpa && wpa_ie) {
999 if (sta->wpa_sm == NULL)
1000 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1003 if (sta->wpa_sm == NULL) {
1004 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1006 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1008 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1010 elems.mdie, elems.mdie_len);
1011 if (res == WPA_INVALID_GROUP)
1012 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1013 else if (res == WPA_INVALID_PAIRWISE)
1014 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1015 else if (res == WPA_INVALID_AKMP)
1016 resp = WLAN_STATUS_AKMP_NOT_VALID;
1017 else if (res == WPA_ALLOC_FAIL)
1018 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1019 #ifdef CONFIG_IEEE80211W
1020 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1021 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1022 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1023 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1024 #endif /* CONFIG_IEEE80211W */
1025 else if (res == WPA_INVALID_MDIE)
1026 resp = WLAN_STATUS_INVALID_MDIE;
1027 else if (res != WPA_IE_OK)
1028 resp = WLAN_STATUS_INVALID_IE;
1029 if (resp != WLAN_STATUS_SUCCESS)
1031 #ifdef CONFIG_IEEE80211W
1032 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1033 sta->sa_query_count > 0)
1034 ap_check_sa_query_timeout(hapd, sta);
1035 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1036 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1038 * STA has already been associated with MFP and SA
1039 * Query timeout has not been reached. Reject the
1040 * association attempt temporarily and start SA Query,
1041 * if one is not pending.
1044 if (sta->sa_query_count == 0)
1045 ap_sta_start_sa_query(hapd, sta);
1047 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1050 if (wpa_auth_uses_mfp(sta->wpa_sm))
1051 sta->flags |= WLAN_STA_MFP;
1053 sta->flags &= ~WLAN_STA_MFP;
1054 #endif /* CONFIG_IEEE80211W */
1056 #ifdef CONFIG_IEEE80211R
1057 if (sta->auth_alg == WLAN_AUTH_FT) {
1059 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1060 "to use association (not "
1061 "re-association) with FT auth_alg",
1062 MAC2STR(sta->addr));
1063 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1066 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1068 if (resp != WLAN_STATUS_SUCCESS)
1071 #endif /* CONFIG_IEEE80211R */
1074 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1075 sta->auth_alg != WLAN_AUTH_SAE &&
1076 !(sta->auth_alg == WLAN_AUTH_FT &&
1077 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1078 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1079 "SAE AKM after non-SAE auth_alg %u",
1080 MAC2STR(sta->addr), sta->auth_alg);
1081 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1083 #endif /* CONFIG_SAE */
1085 #ifdef CONFIG_IEEE80211N
1086 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1087 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1088 hostapd_logger(hapd, sta->addr,
1089 HOSTAPD_MODULE_IEEE80211,
1091 "Station tried to use TKIP with HT "
1093 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1095 #endif /* CONFIG_IEEE80211N */
1097 } else if (hapd->conf->osen) {
1098 if (elems.osen == NULL) {
1100 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1102 "No HS 2.0 OSEN element in association request");
1103 return WLAN_STATUS_INVALID_IE;
1106 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1107 if (sta->wpa_sm == NULL)
1108 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1110 if (sta->wpa_sm == NULL) {
1111 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1113 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1115 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1116 elems.osen - 2, elems.osen_len + 2) < 0)
1117 return WLAN_STATUS_INVALID_IE;
1118 #endif /* CONFIG_HS20 */
1120 wpa_auth_sta_no_wpa(sta->wpa_sm);
1123 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1124 #endif /* CONFIG_P2P */
1127 wpabuf_free(sta->hs20_ie);
1128 if (elems.hs20 && elems.hs20_len > 4) {
1129 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1130 elems.hs20_len - 4);
1132 sta->hs20_ie = NULL;
1133 #endif /* CONFIG_HS20 */
1135 return WLAN_STATUS_SUCCESS;
1139 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1143 struct ieee80211_mgmt reply;
1145 os_memset(&reply, 0, sizeof(reply));
1146 reply.frame_control =
1147 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1148 os_memcpy(reply.da, addr, ETH_ALEN);
1149 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1150 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1152 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1153 reply.u.deauth.reason_code = host_to_le16(reason_code);
1155 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1156 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1161 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1162 u16 status_code, int reassoc, const u8 *ies,
1166 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1167 struct ieee80211_mgmt *reply;
1170 os_memset(buf, 0, sizeof(buf));
1171 reply = (struct ieee80211_mgmt *) buf;
1172 reply->frame_control =
1173 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1174 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1175 WLAN_FC_STYPE_ASSOC_RESP));
1176 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1177 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1178 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1180 send_len = IEEE80211_HDRLEN;
1181 send_len += sizeof(reply->u.assoc_resp);
1182 reply->u.assoc_resp.capab_info =
1183 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1184 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1185 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1186 /* Supported rates */
1187 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1188 /* Extended supported rates */
1189 p = hostapd_eid_ext_supp_rates(hapd, p);
1191 #ifdef CONFIG_IEEE80211R
1192 if (status_code == WLAN_STATUS_SUCCESS) {
1193 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1194 * Transition Information, RSN, [RIC Response] */
1195 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1196 buf + sizeof(buf) - p,
1197 sta->auth_alg, ies, ies_len);
1199 #endif /* CONFIG_IEEE80211R */
1201 #ifdef CONFIG_IEEE80211W
1202 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1203 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1204 #endif /* CONFIG_IEEE80211W */
1206 #ifdef CONFIG_IEEE80211N
1207 p = hostapd_eid_ht_capabilities(hapd, p);
1208 p = hostapd_eid_ht_operation(hapd, p);
1209 #endif /* CONFIG_IEEE80211N */
1211 #ifdef CONFIG_IEEE80211AC
1212 p = hostapd_eid_vht_capabilities(hapd, p);
1213 p = hostapd_eid_vht_operation(hapd, p);
1214 #endif /* CONFIG_IEEE80211AC */
1216 p = hostapd_eid_ext_capab(hapd, p);
1217 p = hostapd_eid_bss_max_idle_period(hapd, p);
1218 if (sta->qos_map_enabled)
1219 p = hostapd_eid_qos_map_set(hapd, p);
1221 if (sta->flags & WLAN_STA_WMM)
1222 p = hostapd_eid_wmm(hapd, p);
1225 if ((sta->flags & WLAN_STA_WPS) ||
1226 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1227 struct wpabuf *wps = wps_build_assoc_resp_ie();
1229 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1230 p += wpabuf_len(wps);
1234 #endif /* CONFIG_WPS */
1238 struct wpabuf *p2p_resp_ie;
1239 enum p2p_status_code status;
1240 switch (status_code) {
1241 case WLAN_STATUS_SUCCESS:
1242 status = P2P_SC_SUCCESS;
1244 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1245 status = P2P_SC_FAIL_LIMIT_REACHED;
1248 status = P2P_SC_FAIL_INVALID_PARAMS;
1251 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1253 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1254 wpabuf_len(p2p_resp_ie));
1255 p += wpabuf_len(p2p_resp_ie);
1256 wpabuf_free(p2p_resp_ie);
1259 #endif /* CONFIG_P2P */
1261 #ifdef CONFIG_P2P_MANAGER
1262 if (hapd->conf->p2p & P2P_MANAGE)
1263 p = hostapd_eid_p2p_manage(hapd, p);
1264 #endif /* CONFIG_P2P_MANAGER */
1266 send_len += p - reply->u.assoc_resp.variable;
1268 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1269 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1274 static void handle_assoc(struct hostapd_data *hapd,
1275 const struct ieee80211_mgmt *mgmt, size_t len,
1278 u16 capab_info, listen_interval;
1279 u16 resp = WLAN_STATUS_SUCCESS;
1282 struct sta_info *sta;
1284 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1285 sizeof(mgmt->u.assoc_req))) {
1286 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1287 reassoc, (unsigned long) len);
1291 #ifdef CONFIG_TESTING_OPTIONS
1293 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
1294 drand48() < hapd->iconf->ignore_reassoc_probability) {
1295 wpa_printf(MSG_INFO,
1296 "TESTING: ignoring reassoc request from "
1297 MACSTR, MAC2STR(mgmt->sa));
1301 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
1302 drand48() < hapd->iconf->ignore_assoc_probability) {
1303 wpa_printf(MSG_INFO,
1304 "TESTING: ignoring assoc request from "
1305 MACSTR, MAC2STR(mgmt->sa));
1309 #endif /* CONFIG_TESTING_OPTIONS */
1312 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1313 listen_interval = le_to_host16(
1314 mgmt->u.reassoc_req.listen_interval);
1315 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1316 " capab_info=0x%02x listen_interval=%d current_ap="
1318 MAC2STR(mgmt->sa), capab_info, listen_interval,
1319 MAC2STR(mgmt->u.reassoc_req.current_ap));
1320 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1321 pos = mgmt->u.reassoc_req.variable;
1323 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1324 listen_interval = le_to_host16(
1325 mgmt->u.assoc_req.listen_interval);
1326 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1327 " capab_info=0x%02x listen_interval=%d",
1328 MAC2STR(mgmt->sa), capab_info, listen_interval);
1329 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1330 pos = mgmt->u.assoc_req.variable;
1333 sta = ap_get_sta(hapd, mgmt->sa);
1334 #ifdef CONFIG_IEEE80211R
1335 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1336 (sta->flags & WLAN_STA_AUTH) == 0) {
1337 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1338 "prior to authentication since it is using "
1339 "over-the-DS FT", MAC2STR(mgmt->sa));
1341 #endif /* CONFIG_IEEE80211R */
1342 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1343 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1344 HOSTAPD_LEVEL_INFO, "Station tried to "
1345 "associate before authentication "
1346 "(aid=%d flags=0x%x)",
1347 sta ? sta->aid : -1,
1348 sta ? sta->flags : 0);
1349 send_deauth(hapd, mgmt->sa,
1350 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1354 if (hapd->tkip_countermeasures) {
1355 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1359 if (listen_interval > hapd->conf->max_listen_interval) {
1360 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1361 HOSTAPD_LEVEL_DEBUG,
1362 "Too large Listen Interval (%d)",
1364 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1368 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1370 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1371 if (resp != WLAN_STATUS_SUCCESS)
1374 if (hostapd_get_aid(hapd, sta) < 0) {
1375 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1376 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1377 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1381 sta->capability = capab_info;
1382 sta->listen_interval = listen_interval;
1384 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1385 sta->flags |= WLAN_STA_NONERP;
1386 for (i = 0; i < sta->supported_rates_len; i++) {
1387 if ((sta->supported_rates[i] & 0x7f) > 22) {
1388 sta->flags &= ~WLAN_STA_NONERP;
1392 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1393 sta->nonerp_set = 1;
1394 hapd->iface->num_sta_non_erp++;
1395 if (hapd->iface->num_sta_non_erp == 1)
1396 ieee802_11_set_beacons(hapd->iface);
1399 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1400 !sta->no_short_slot_time_set) {
1401 sta->no_short_slot_time_set = 1;
1402 hapd->iface->num_sta_no_short_slot_time++;
1403 if (hapd->iface->current_mode->mode ==
1404 HOSTAPD_MODE_IEEE80211G &&
1405 hapd->iface->num_sta_no_short_slot_time == 1)
1406 ieee802_11_set_beacons(hapd->iface);
1409 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1410 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1412 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1414 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1415 !sta->no_short_preamble_set) {
1416 sta->no_short_preamble_set = 1;
1417 hapd->iface->num_sta_no_short_preamble++;
1418 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1419 && hapd->iface->num_sta_no_short_preamble == 1)
1420 ieee802_11_set_beacons(hapd->iface);
1423 #ifdef CONFIG_IEEE80211N
1424 update_ht_state(hapd, sta);
1425 #endif /* CONFIG_IEEE80211N */
1427 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1428 HOSTAPD_LEVEL_DEBUG,
1429 "association OK (aid %d)", sta->aid);
1430 /* Station will be marked associated, after it acknowledges AssocResp
1432 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1434 #ifdef CONFIG_IEEE80211W
1435 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1436 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1437 "SA Query procedure", reassoc ? "re" : "");
1438 /* TODO: Send a protected Disassociate frame to the STA using
1439 * the old key and Reason Code "Previous Authentication no
1440 * longer valid". Make sure this is only sent protected since
1441 * unprotected frame would be received by the STA that is now
1442 * trying to associate.
1445 #endif /* CONFIG_IEEE80211W */
1447 /* Make sure that the previously registered inactivity timer will not
1448 * remove the STA immediately. */
1449 sta->timeout_next = STA_NULLFUNC;
1452 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1456 static void handle_disassoc(struct hostapd_data *hapd,
1457 const struct ieee80211_mgmt *mgmt, size_t len)
1459 struct sta_info *sta;
1461 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1462 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1463 (unsigned long) len);
1467 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1469 le_to_host16(mgmt->u.disassoc.reason_code));
1471 sta = ap_get_sta(hapd, mgmt->sa);
1473 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1478 ap_sta_set_authorized(hapd, sta, 0);
1479 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1480 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1482 HOSTAPD_LEVEL_INFO, "disassociated");
1483 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1484 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1485 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1487 accounting_sta_stop(hapd, sta);
1488 ieee802_1x_free_station(sta);
1489 hostapd_drv_sta_remove(hapd, sta->addr);
1491 if (sta->timeout_next == STA_NULLFUNC ||
1492 sta->timeout_next == STA_DISASSOC) {
1493 sta->timeout_next = STA_DEAUTH;
1494 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1495 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1499 mlme_disassociate_indication(
1500 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1504 static void handle_deauth(struct hostapd_data *hapd,
1505 const struct ieee80211_mgmt *mgmt, size_t len)
1507 struct sta_info *sta;
1509 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1510 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1511 "payload (len=%lu)", (unsigned long) len);
1515 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1517 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1519 sta = ap_get_sta(hapd, mgmt->sa);
1521 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1522 "to deauthenticate, but it is not authenticated",
1527 ap_sta_set_authorized(hapd, sta, 0);
1528 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1529 WLAN_STA_ASSOC_REQ_OK);
1530 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1531 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1532 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1533 mlme_deauthenticate_indication(
1534 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1535 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1536 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1537 ap_free_sta(hapd, sta);
1541 static void handle_beacon(struct hostapd_data *hapd,
1542 const struct ieee80211_mgmt *mgmt, size_t len,
1543 struct hostapd_frame_info *fi)
1545 struct ieee802_11_elems elems;
1547 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1548 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1549 (unsigned long) len);
1553 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1554 len - (IEEE80211_HDRLEN +
1555 sizeof(mgmt->u.beacon)), &elems,
1558 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1562 #ifdef CONFIG_IEEE80211W
1564 static int hostapd_sa_query_action(struct hostapd_data *hapd,
1565 const struct ieee80211_mgmt *mgmt,
1570 end = mgmt->u.action.u.sa_query_resp.trans_id +
1571 WLAN_SA_QUERY_TR_ID_LEN;
1572 if (((u8 *) mgmt) + len < end) {
1573 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1574 "frame (len=%lu)", (unsigned long) len);
1578 ieee802_11_sa_query_action(hapd, mgmt->sa,
1579 mgmt->u.action.u.sa_query_resp.action,
1580 mgmt->u.action.u.sa_query_resp.trans_id);
1585 static int robust_action_frame(u8 category)
1587 return category != WLAN_ACTION_PUBLIC &&
1588 category != WLAN_ACTION_HT;
1590 #endif /* CONFIG_IEEE80211W */
1593 static int handle_action(struct hostapd_data *hapd,
1594 const struct ieee80211_mgmt *mgmt, size_t len)
1596 struct sta_info *sta;
1597 sta = ap_get_sta(hapd, mgmt->sa);
1599 if (len < IEEE80211_HDRLEN + 1) {
1600 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1601 HOSTAPD_LEVEL_DEBUG,
1602 "handle_action - too short payload (len=%lu)",
1603 (unsigned long) len);
1607 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1608 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1609 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1610 "frame (category=%u) from unassociated STA " MACSTR,
1611 MAC2STR(mgmt->sa), mgmt->u.action.category);
1615 #ifdef CONFIG_IEEE80211W
1616 if (sta && (sta->flags & WLAN_STA_MFP) &&
1617 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
1618 robust_action_frame(mgmt->u.action.category)) {
1619 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1620 HOSTAPD_LEVEL_DEBUG,
1621 "Dropped unprotected Robust Action frame from "
1625 #endif /* CONFIG_IEEE80211W */
1627 switch (mgmt->u.action.category) {
1628 #ifdef CONFIG_IEEE80211R
1629 case WLAN_ACTION_FT:
1631 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1632 len - IEEE80211_HDRLEN))
1635 #endif /* CONFIG_IEEE80211R */
1636 case WLAN_ACTION_WMM:
1637 hostapd_wmm_action(hapd, mgmt, len);
1639 #ifdef CONFIG_IEEE80211W
1640 case WLAN_ACTION_SA_QUERY:
1641 return hostapd_sa_query_action(hapd, mgmt, len);
1642 #endif /* CONFIG_IEEE80211W */
1644 case WLAN_ACTION_WNM:
1645 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
1647 #endif /* CONFIG_WNM */
1648 case WLAN_ACTION_PUBLIC:
1649 case WLAN_ACTION_PROTECTED_DUAL:
1650 #ifdef CONFIG_IEEE80211N
1651 if (mgmt->u.action.u.public_action.action ==
1652 WLAN_PA_20_40_BSS_COEX) {
1653 wpa_printf(MSG_DEBUG,
1654 "HT20/40 coex mgmt frame received from STA "
1655 MACSTR, MAC2STR(mgmt->sa));
1656 hostapd_2040_coex_action(hapd, mgmt, len);
1658 #endif /* CONFIG_IEEE80211N */
1659 if (hapd->public_action_cb) {
1660 hapd->public_action_cb(hapd->public_action_cb_ctx,
1664 if (hapd->public_action_cb2) {
1665 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1669 if (hapd->public_action_cb || hapd->public_action_cb2)
1672 case WLAN_ACTION_VENDOR_SPECIFIC:
1673 if (hapd->vendor_action_cb) {
1674 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1676 hapd->iface->freq) == 0)
1682 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1683 HOSTAPD_LEVEL_DEBUG,
1684 "handle_action - unknown action category %d or invalid "
1686 mgmt->u.action.category);
1687 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1688 !(mgmt->sa[0] & 0x01)) {
1689 struct ieee80211_mgmt *resp;
1692 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1693 * Return the Action frame to the source without change
1694 * except that MSB of the Category set to 1.
1696 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1697 "frame back to sender");
1698 resp = os_malloc(len);
1701 os_memcpy(resp, mgmt, len);
1702 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1703 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1704 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1705 resp->u.action.category |= 0x80;
1707 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1708 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1719 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1720 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1722 * @buf: management frame data (starting from IEEE 802.11 header)
1723 * @len: length of frame data in octets
1724 * @fi: meta data about received frame (signal level, etc.)
1726 * Process all incoming IEEE 802.11 management frames. This will be called for
1727 * each frame received from the kernel driver through wlan#ap interface. In
1728 * addition, it can be called to re-inserted pending frames (e.g., when using
1729 * external RADIUS server as an MAC ACL).
1731 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1732 struct hostapd_frame_info *fi)
1734 struct ieee80211_mgmt *mgmt;
1742 mgmt = (struct ieee80211_mgmt *) buf;
1743 fc = le_to_host16(mgmt->frame_control);
1744 stype = WLAN_FC_GET_STYPE(fc);
1746 if (stype == WLAN_FC_STYPE_BEACON) {
1747 handle_beacon(hapd, mgmt, len, fi);
1751 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1752 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1753 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1757 /* Invitation responses can be sent with the peer MAC as BSSID */
1758 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1759 stype == WLAN_FC_STYPE_ACTION) &&
1760 #endif /* CONFIG_P2P */
1761 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1762 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
1763 MAC2STR(mgmt->bssid));
1768 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1769 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1773 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1774 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1775 HOSTAPD_LEVEL_DEBUG,
1776 "MGMT: DA=" MACSTR " not our address",
1782 case WLAN_FC_STYPE_AUTH:
1783 wpa_printf(MSG_DEBUG, "mgmt::auth");
1784 handle_auth(hapd, mgmt, len);
1787 case WLAN_FC_STYPE_ASSOC_REQ:
1788 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1789 handle_assoc(hapd, mgmt, len, 0);
1792 case WLAN_FC_STYPE_REASSOC_REQ:
1793 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1794 handle_assoc(hapd, mgmt, len, 1);
1797 case WLAN_FC_STYPE_DISASSOC:
1798 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1799 handle_disassoc(hapd, mgmt, len);
1802 case WLAN_FC_STYPE_DEAUTH:
1803 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1804 handle_deauth(hapd, mgmt, len);
1807 case WLAN_FC_STYPE_ACTION:
1808 wpa_printf(MSG_DEBUG, "mgmt::action");
1809 ret = handle_action(hapd, mgmt, len);
1812 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1813 HOSTAPD_LEVEL_DEBUG,
1814 "unknown mgmt frame subtype %d", stype);
1822 static void handle_auth_cb(struct hostapd_data *hapd,
1823 const struct ieee80211_mgmt *mgmt,
1826 u16 auth_alg, auth_transaction, status_code;
1827 struct sta_info *sta;
1830 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1831 HOSTAPD_LEVEL_NOTICE,
1832 "did not acknowledge authentication response");
1836 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1837 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
1838 (unsigned long) len);
1842 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1843 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1844 status_code = le_to_host16(mgmt->u.auth.status_code);
1846 sta = ap_get_sta(hapd, mgmt->da);
1848 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
1853 if (status_code == WLAN_STATUS_SUCCESS &&
1854 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1855 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1856 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1857 HOSTAPD_LEVEL_INFO, "authenticated");
1858 sta->flags |= WLAN_STA_AUTH;
1863 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
1864 struct sta_info *sta,
1868 struct hostapd_ssid *ssid = sta->ssid;
1870 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
1873 for (i = 0; i < 4; i++) {
1874 if (ssid->wep.key[i] &&
1875 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
1876 i == ssid->wep.idx, NULL, 0,
1877 ssid->wep.key[i], ssid->wep.len[i])) {
1878 wpa_printf(MSG_WARNING,
1879 "Could not set WEP keys for WDS interface; %s",
1887 static void handle_assoc_cb(struct hostapd_data *hapd,
1888 const struct ieee80211_mgmt *mgmt,
1889 size_t len, int reassoc, int ok)
1892 struct sta_info *sta;
1894 struct ieee80211_ht_capabilities ht_cap;
1895 struct ieee80211_vht_capabilities vht_cap;
1897 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1898 sizeof(mgmt->u.assoc_resp))) {
1899 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
1900 reassoc, (unsigned long) len);
1904 sta = ap_get_sta(hapd, mgmt->da);
1906 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
1912 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1913 HOSTAPD_LEVEL_DEBUG,
1914 "did not acknowledge association response");
1915 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1920 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1922 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1924 if (status != WLAN_STATUS_SUCCESS)
1927 /* Stop previous accounting session, if one is started, and allocate
1928 * new session id for the new session. */
1929 accounting_sta_stop(hapd, sta);
1931 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1933 "associated (aid %d)",
1936 if (sta->flags & WLAN_STA_ASSOC)
1938 sta->flags |= WLAN_STA_ASSOC;
1939 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
1940 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
1941 sta->auth_alg == WLAN_AUTH_FT) {
1943 * Open, static WEP, or FT protocol; no separate authorization
1946 ap_sta_set_authorized(hapd, sta, 1);
1950 mlme_reassociate_indication(hapd, sta);
1952 mlme_associate_indication(hapd, sta);
1954 #ifdef CONFIG_IEEE80211W
1955 sta->sa_query_timed_out = 0;
1956 #endif /* CONFIG_IEEE80211W */
1959 * Remove the STA entry in order to make sure the STA PS state gets
1960 * cleared and configuration gets updated in case of reassociation back
1963 hostapd_drv_sta_remove(hapd, sta->addr);
1965 #ifdef CONFIG_IEEE80211N
1966 if (sta->flags & WLAN_STA_HT)
1967 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1968 #endif /* CONFIG_IEEE80211N */
1969 #ifdef CONFIG_IEEE80211AC
1970 if (sta->flags & WLAN_STA_VHT)
1971 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1972 #endif /* CONFIG_IEEE80211AC */
1974 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1975 sta->supported_rates, sta->supported_rates_len,
1976 sta->listen_interval,
1977 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1978 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1979 sta->flags, sta->qosinfo, sta->vht_opmode)) {
1980 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1981 HOSTAPD_LEVEL_NOTICE,
1982 "Could not add STA to kernel driver");
1984 ap_sta_disconnect(hapd, sta, sta->addr,
1985 WLAN_REASON_DISASSOC_AP_BUSY);
1990 if (sta->flags & WLAN_STA_WDS) {
1992 char ifname_wds[IFNAMSIZ + 1];
1994 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
1997 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2000 if (sta->eapol_sm == NULL) {
2002 * This STA does not use RADIUS server for EAP authentication,
2003 * so bind it to the selected VLAN interface now, since the
2004 * interface selection is not going to change anymore.
2006 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2008 } else if (sta->vlan_id) {
2009 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2010 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2014 hostapd_set_sta_flags(hapd, sta);
2016 if (sta->auth_alg == WLAN_AUTH_FT)
2017 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2019 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2020 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2022 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2026 static void handle_deauth_cb(struct hostapd_data *hapd,
2027 const struct ieee80211_mgmt *mgmt,
2030 struct sta_info *sta;
2031 if (mgmt->da[0] & 0x01)
2033 sta = ap_get_sta(hapd, mgmt->da);
2035 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2036 " not found", MAC2STR(mgmt->da));
2040 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2041 MAC2STR(sta->addr));
2043 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2044 "deauth", MAC2STR(sta->addr));
2046 ap_sta_deauth_cb(hapd, sta);
2050 static void handle_disassoc_cb(struct hostapd_data *hapd,
2051 const struct ieee80211_mgmt *mgmt,
2054 struct sta_info *sta;
2055 if (mgmt->da[0] & 0x01)
2057 sta = ap_get_sta(hapd, mgmt->da);
2059 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2060 " not found", MAC2STR(mgmt->da));
2064 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2065 MAC2STR(sta->addr));
2067 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2068 "disassoc", MAC2STR(sta->addr));
2070 ap_sta_disassoc_cb(hapd, sta);
2075 * ieee802_11_mgmt_cb - Process management frame TX status callback
2076 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2078 * @buf: management frame data (starting from IEEE 802.11 header)
2079 * @len: length of frame data in octets
2080 * @stype: management frame subtype from frame control field
2081 * @ok: Whether the frame was ACK'ed
2083 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2086 const struct ieee80211_mgmt *mgmt;
2087 mgmt = (const struct ieee80211_mgmt *) buf;
2089 #ifdef CONFIG_TESTING_OPTIONS
2090 if (hapd->ext_mgmt_frame_handling) {
2091 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2095 #endif /* CONFIG_TESTING_OPTIONS */
2098 case WLAN_FC_STYPE_AUTH:
2099 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2100 handle_auth_cb(hapd, mgmt, len, ok);
2102 case WLAN_FC_STYPE_ASSOC_RESP:
2103 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2104 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2106 case WLAN_FC_STYPE_REASSOC_RESP:
2107 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2108 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2110 case WLAN_FC_STYPE_PROBE_RESP:
2111 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2113 case WLAN_FC_STYPE_DEAUTH:
2114 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2115 handle_deauth_cb(hapd, mgmt, len, ok);
2117 case WLAN_FC_STYPE_DISASSOC:
2118 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2119 handle_disassoc_cb(hapd, mgmt, len, ok);
2121 case WLAN_FC_STYPE_ACTION:
2122 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2125 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2131 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2138 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2139 char *buf, size_t buflen)
2146 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2147 const u8 *buf, size_t len, int ack)
2149 struct sta_info *sta;
2150 struct hostapd_iface *iface = hapd->iface;
2152 sta = ap_get_sta(hapd, addr);
2153 if (sta == NULL && iface->num_bss > 1) {
2155 for (j = 0; j < iface->num_bss; j++) {
2156 hapd = iface->bss[j];
2157 sta = ap_get_sta(hapd, addr);
2162 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2164 if (sta->flags & WLAN_STA_PENDING_POLL) {
2165 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2166 "activity poll", MAC2STR(sta->addr),
2167 ack ? "ACKed" : "did not ACK");
2169 sta->flags &= ~WLAN_STA_PENDING_POLL;
2172 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2176 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2177 const u8 *data, size_t len, int ack)
2179 struct sta_info *sta;
2180 struct hostapd_iface *iface = hapd->iface;
2182 sta = ap_get_sta(hapd, dst);
2183 if (sta == NULL && iface->num_bss > 1) {
2185 for (j = 0; j < iface->num_bss; j++) {
2186 hapd = iface->bss[j];
2187 sta = ap_get_sta(hapd, dst);
2192 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2193 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2194 MACSTR " that is not currently associated",
2199 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2203 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2205 struct sta_info *sta;
2206 struct hostapd_iface *iface = hapd->iface;
2208 sta = ap_get_sta(hapd, addr);
2209 if (sta == NULL && iface->num_bss > 1) {
2211 for (j = 0; j < iface->num_bss; j++) {
2212 hapd = iface->bss[j];
2213 sta = ap_get_sta(hapd, addr);
2220 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2223 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2224 "activity poll", MAC2STR(sta->addr));
2225 sta->flags &= ~WLAN_STA_PENDING_POLL;
2229 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2232 struct sta_info *sta;
2234 sta = ap_get_sta(hapd, src);
2235 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2236 if (!hapd->conf->wds_sta)
2239 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2241 char ifname_wds[IFNAMSIZ + 1];
2243 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2244 "STA " MACSTR " (aid %u)",
2245 MAC2STR(sta->addr), sta->aid);
2246 sta->flags |= WLAN_STA_WDS;
2247 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2248 sta->addr, sta->aid, 1);
2250 hostapd_set_wds_encryption(hapd, sta,
2256 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2257 MACSTR, MAC2STR(src));
2258 if (src[0] & 0x01) {
2259 /* Broadcast bit set in SA?! Ignore the frame silently. */
2263 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2264 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2265 "already been sent, but no TX status yet known - "
2266 "ignore Class 3 frame issue with " MACSTR,
2271 if (sta && (sta->flags & WLAN_STA_AUTH))
2272 hostapd_drv_sta_disassoc(
2274 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2276 hostapd_drv_sta_deauth(
2278 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2282 #endif /* CONFIG_NATIVE_WINDOWS */