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
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;
109 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
113 continue; /* already in SuppRates IE */
114 *pos = hapd->iface->current_rates[i].rate / 5;
115 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
120 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
123 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
126 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
129 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
136 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
139 int capab = WLAN_CAPABILITY_ESS;
143 /* Check if any of configured channels require DFS */
144 dfs = hostapd_is_dfs_required(hapd->iface);
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
151 if (hapd->iface->num_sta_no_short_preamble == 0 &&
152 hapd->iconf->preamble == SHORT_PREAMBLE)
153 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
155 privacy = hapd->conf->ssid.wep.keys_set;
157 if (hapd->conf->ieee802_1x &&
158 (hapd->conf->default_wep_key_len ||
159 hapd->conf->individual_wep_key_len))
166 if (hapd->conf->osen)
168 #endif /* CONFIG_HS20 */
171 int policy, def_klen;
172 if (probe && sta->ssid_probe) {
173 policy = sta->ssid_probe->security_policy;
174 def_klen = sta->ssid_probe->wep.default_len;
176 policy = sta->ssid->security_policy;
177 def_klen = sta->ssid->wep.default_len;
179 privacy = policy != SECURITY_PLAINTEXT;
180 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
185 capab |= WLAN_CAPABILITY_PRIVACY;
187 if (hapd->iface->current_mode &&
188 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
189 hapd->iface->num_sta_no_short_slot_time == 0)
190 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
193 * Currently, Spectrum Management capability bit is set when directly
194 * requested in configuration by spectrum_mgmt_required or when AP is
195 * running on DFS channel.
196 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
198 if (hapd->iface->current_mode &&
199 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
200 (hapd->iconf->spectrum_mgmt_required || dfs))
201 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
207 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
208 u16 auth_transaction, const u8 *challenge,
211 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
213 "authentication (shared key, transaction %d)",
216 if (auth_transaction == 1) {
217 if (!sta->challenge) {
218 /* Generate a pseudo-random challenge */
222 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
223 if (sta->challenge == NULL)
224 return WLAN_STATUS_UNSPECIFIED_FAILURE;
228 os_memcpy(key, &now.sec, 4);
229 os_memcpy(key + 4, &r, 4);
230 rc4_skip(key, sizeof(key), 0,
231 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
236 if (auth_transaction != 3)
237 return WLAN_STATUS_UNSPECIFIED_FAILURE;
240 if (!iswep || !sta->challenge || !challenge ||
241 os_memcmp(sta->challenge, challenge, 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_process_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 if (sae_process_commit(sta->sae) < 0) {
347 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
351 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
354 sae_write_commit(sta->sae, buf, NULL);
360 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
361 struct sta_info *sta)
365 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
369 sae_write_confirm(sta->sae, buf);
375 static int use_sae_anti_clogging(struct hostapd_data *hapd)
377 struct sta_info *sta;
378 unsigned int open = 0;
380 if (hapd->conf->sae_anti_clogging_threshold == 0)
383 for (sta = hapd->sta_list; sta; sta = sta->next) {
386 if (sta->sae->state != SAE_COMMITTED &&
387 sta->sae->state != SAE_CONFIRMED)
390 if (open >= hapd->conf->sae_anti_clogging_threshold)
398 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
399 const u8 *token, size_t token_len)
401 u8 mac[SHA256_MAC_LEN];
403 if (token_len != SHA256_MAC_LEN)
405 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
406 addr, ETH_ALEN, mac) < 0 ||
407 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
414 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
419 struct os_reltime now;
421 os_get_reltime(&now);
422 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
423 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
424 if (random_get_bytes(hapd->sae_token_key,
425 sizeof(hapd->sae_token_key)) < 0)
427 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
428 hapd->sae_token_key, sizeof(hapd->sae_token_key));
429 hapd->last_sae_token_key_update = now;
432 buf = wpabuf_alloc(SHA256_MAC_LEN);
436 token = wpabuf_put(buf, SHA256_MAC_LEN);
437 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
438 addr, ETH_ALEN, token);
444 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
445 const struct ieee80211_mgmt *mgmt, size_t len,
448 u16 resp = WLAN_STATUS_SUCCESS;
449 struct wpabuf *data = NULL;
452 if (auth_transaction != 1)
454 sta->sae = os_zalloc(sizeof(*sta->sae));
455 if (sta->sae == NULL)
457 sta->sae->state = SAE_NOTHING;
460 if (auth_transaction == 1) {
461 const u8 *token = NULL;
462 size_t token_len = 0;
463 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
465 "start SAE authentication (RX commit)");
466 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
467 ((const u8 *) mgmt) + len -
468 mgmt->u.auth.variable, &token,
469 &token_len, hapd->conf->sae_groups);
470 if (token && check_sae_token(hapd, sta->addr, token, token_len)
472 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
473 "incorrect token from " MACSTR,
478 if (resp == WLAN_STATUS_SUCCESS) {
479 if (!token && use_sae_anti_clogging(hapd)) {
480 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
481 "clogging token from " MACSTR,
483 data = auth_build_token_req(hapd, sta->addr);
484 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
486 data = auth_process_sae_commit(hapd, sta);
488 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
490 sta->sae->state = SAE_COMMITTED;
493 } else if (auth_transaction == 2) {
494 if (sta->sae->state != SAE_COMMITTED) {
495 hostapd_logger(hapd, sta->addr,
496 HOSTAPD_MODULE_IEEE80211,
498 "SAE confirm before commit");
499 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
502 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
504 "SAE authentication (RX confirm)");
505 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
506 ((u8 *) mgmt) + len -
507 mgmt->u.auth.variable) < 0) {
508 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
510 resp = WLAN_STATUS_SUCCESS;
511 sta->flags |= WLAN_STA_AUTH;
512 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
513 sta->auth_alg = WLAN_AUTH_SAE;
514 mlme_authenticate_indication(hapd, sta);
516 data = auth_build_sae_confirm(hapd, sta);
518 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
520 sta->sae->state = SAE_ACCEPTED;
521 sae_clear_temp_data(sta->sae);
525 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
527 "unexpected SAE authentication transaction %u",
529 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
533 sta->auth_alg = WLAN_AUTH_SAE;
535 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
536 auth_transaction, resp,
537 data ? wpabuf_head(data) : (u8 *) "",
538 data ? wpabuf_len(data) : 0);
541 #endif /* CONFIG_SAE */
544 static void handle_auth(struct hostapd_data *hapd,
545 const struct ieee80211_mgmt *mgmt, size_t len)
547 u16 auth_alg, auth_transaction, status_code;
548 u16 resp = WLAN_STATUS_SUCCESS;
549 struct sta_info *sta = NULL;
552 const u8 *challenge = NULL;
553 u32 session_timeout, acct_interim_interval;
555 struct hostapd_sta_wpa_psk_short *psk = NULL;
556 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
557 size_t resp_ies_len = 0;
558 char *identity = NULL;
559 char *radius_cui = NULL;
561 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
562 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
563 (unsigned long) len);
567 #ifdef CONFIG_TESTING_OPTIONS
568 if (hapd->iconf->ignore_auth_probability > 0.0d &&
569 drand48() < hapd->iconf->ignore_auth_probability) {
571 "TESTING: ignoring auth frame from " MACSTR,
575 #endif /* CONFIG_TESTING_OPTIONS */
577 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
578 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
579 status_code = le_to_host16(mgmt->u.auth.status_code);
580 fc = le_to_host16(mgmt->frame_control);
582 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
583 2 + WLAN_AUTH_CHALLENGE_LEN &&
584 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
585 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
586 challenge = &mgmt->u.auth.variable[2];
588 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
589 "auth_transaction=%d status_code=%d wep=%d%s",
590 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
591 status_code, !!(fc & WLAN_FC_ISWEP),
592 challenge ? " challenge" : "");
594 if (hapd->tkip_countermeasures) {
595 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
599 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
600 auth_alg == WLAN_AUTH_OPEN) ||
601 #ifdef CONFIG_IEEE80211R
602 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
603 auth_alg == WLAN_AUTH_FT) ||
604 #endif /* CONFIG_IEEE80211R */
606 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
607 auth_alg == WLAN_AUTH_SAE) ||
608 #endif /* CONFIG_SAE */
609 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
610 auth_alg == WLAN_AUTH_SHARED_KEY))) {
611 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
613 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
617 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
618 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
619 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
621 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
625 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
626 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
628 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
632 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
634 &acct_interim_interval, &vlan_id,
635 &psk, &identity, &radius_cui);
637 if (res == HOSTAPD_ACL_REJECT) {
638 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
640 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
643 if (res == HOSTAPD_ACL_PENDING) {
644 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
645 " waiting for an external authentication",
647 /* Authentication code will re-send the authentication frame
648 * after it has received (and cached) information from the
649 * external source. */
653 sta = ap_sta_add(hapd, mgmt->sa);
655 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
660 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
661 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
662 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
663 "%d received from RADIUS server",
665 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
668 sta->vlan_id = vlan_id;
669 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
670 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
673 hostapd_free_psk_list(sta->psk);
674 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
681 sta->identity = identity;
683 sta->radius_cui = radius_cui;
686 sta->flags &= ~WLAN_STA_PREAUTH;
687 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
689 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
690 sta->acct_interim_interval = acct_interim_interval;
691 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
692 ap_sta_session_timeout(hapd, sta, session_timeout);
694 ap_sta_no_session_timeout(hapd, sta);
698 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
700 "authentication OK (open system)");
701 sta->flags |= WLAN_STA_AUTH;
702 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
703 sta->auth_alg = WLAN_AUTH_OPEN;
704 mlme_authenticate_indication(hapd, sta);
706 case WLAN_AUTH_SHARED_KEY:
707 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
709 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
710 mlme_authenticate_indication(hapd, sta);
711 if (sta->challenge && auth_transaction == 1) {
712 resp_ies[0] = WLAN_EID_CHALLENGE;
713 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
714 os_memcpy(resp_ies + 2, sta->challenge,
715 WLAN_AUTH_CHALLENGE_LEN);
716 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
719 #ifdef CONFIG_IEEE80211R
721 sta->auth_alg = WLAN_AUTH_FT;
722 if (sta->wpa_sm == NULL)
723 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
725 if (sta->wpa_sm == NULL) {
726 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
728 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
731 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
732 auth_transaction, mgmt->u.auth.variable,
733 len - IEEE80211_HDRLEN -
734 sizeof(mgmt->u.auth),
735 handle_auth_ft_finish, hapd);
736 /* handle_auth_ft_finish() callback will complete auth. */
738 #endif /* CONFIG_IEEE80211R */
741 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
743 #endif /* CONFIG_SAE */
749 hostapd_free_psk_list(psk);
751 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
752 auth_transaction + 1, resp, resp_ies, resp_ies_len);
756 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
760 /* get a unique AID */
762 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
766 for (i = 0; i < AID_WORDS; i++) {
767 if (hapd->sta_aid[i] == (u32) -1)
769 for (j = 0; j < 32; j++) {
770 if (!(hapd->sta_aid[i] & BIT(j)))
778 aid = i * 32 + j + 1;
783 hapd->sta_aid[i] |= BIT(j);
784 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
789 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
790 const u8 *ssid_ie, size_t ssid_ie_len)
793 return WLAN_STATUS_UNSPECIFIED_FAILURE;
795 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
796 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
797 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
799 "Station tried to associate with unknown SSID "
800 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
801 return WLAN_STATUS_UNSPECIFIED_FAILURE;
804 return WLAN_STATUS_SUCCESS;
808 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
809 const u8 *wmm_ie, size_t wmm_ie_len)
811 sta->flags &= ~WLAN_STA_WMM;
813 if (wmm_ie && hapd->conf->wmm_enabled) {
814 struct wmm_information_element *wmm;
816 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
817 hostapd_logger(hapd, sta->addr,
820 "invalid WMM element in association "
822 return WLAN_STATUS_UNSPECIFIED_FAILURE;
825 sta->flags |= WLAN_STA_WMM;
826 wmm = (struct wmm_information_element *) wmm_ie;
827 sta->qosinfo = wmm->qos_info;
829 return WLAN_STATUS_SUCCESS;
833 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
834 struct ieee802_11_elems *elems)
836 if (!elems->supp_rates) {
837 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
839 "No supported rates element in AssocReq");
840 return WLAN_STATUS_UNSPECIFIED_FAILURE;
843 if (elems->supp_rates_len + elems->ext_supp_rates_len >
844 sizeof(sta->supported_rates)) {
845 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
847 "Invalid supported rates element length %d+%d",
848 elems->supp_rates_len,
849 elems->ext_supp_rates_len);
850 return WLAN_STATUS_UNSPECIFIED_FAILURE;
853 sta->supported_rates_len = merge_byte_arrays(
854 sta->supported_rates, sizeof(sta->supported_rates),
855 elems->supp_rates, elems->supp_rates_len,
856 elems->ext_supp_rates, elems->ext_supp_rates_len);
858 return WLAN_STATUS_SUCCESS;
862 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
863 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
865 #ifdef CONFIG_INTERWORKING
866 /* check for QoS Map support */
867 if (ext_capab_ie_len >= 5) {
868 if (ext_capab_ie[4] & 0x01)
869 sta->qos_map_enabled = 1;
871 #endif /* CONFIG_INTERWORKING */
873 return WLAN_STATUS_SUCCESS;
877 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
878 const u8 *ies, size_t ies_len, int reassoc)
880 struct ieee802_11_elems elems;
884 const u8 *p2p_dev_addr = NULL;
886 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
887 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
888 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
889 "association request");
890 return WLAN_STATUS_UNSPECIFIED_FAILURE;
893 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
894 if (resp != WLAN_STATUS_SUCCESS)
896 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
897 if (resp != WLAN_STATUS_SUCCESS)
899 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
900 if (resp != WLAN_STATUS_SUCCESS)
902 resp = copy_supp_rates(hapd, sta, &elems);
903 if (resp != WLAN_STATUS_SUCCESS)
905 #ifdef CONFIG_IEEE80211N
906 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
907 elems.ht_capabilities_len);
908 if (resp != WLAN_STATUS_SUCCESS)
910 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
911 !(sta->flags & WLAN_STA_HT)) {
912 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
913 HOSTAPD_LEVEL_INFO, "Station does not support "
914 "mandatory HT PHY - reject association");
915 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
917 #endif /* CONFIG_IEEE80211N */
919 #ifdef CONFIG_IEEE80211AC
920 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
921 elems.vht_capabilities_len);
922 if (resp != WLAN_STATUS_SUCCESS)
925 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
926 if (resp != WLAN_STATUS_SUCCESS)
929 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
930 !(sta->flags & WLAN_STA_VHT)) {
931 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
932 HOSTAPD_LEVEL_INFO, "Station does not support "
933 "mandatory VHT PHY - reject association");
934 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
936 #endif /* CONFIG_IEEE80211AC */
940 wpabuf_free(sta->p2p_ie);
941 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
944 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
946 wpabuf_free(sta->p2p_ie);
949 #endif /* CONFIG_P2P */
951 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
952 wpa_ie = elems.rsn_ie;
953 wpa_ie_len = elems.rsn_ie_len;
954 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
956 wpa_ie = elems.wpa_ie;
957 wpa_ie_len = elems.wpa_ie_len;
964 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
965 if (hapd->conf->wps_state && elems.wps_ie) {
966 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
967 "Request - assume WPS is used");
968 sta->flags |= WLAN_STA_WPS;
969 wpabuf_free(sta->wps_ie);
970 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
972 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
973 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
974 sta->flags |= WLAN_STA_WPS2;
978 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
979 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
980 "(Re)Association Request - reject");
981 return WLAN_STATUS_INVALID_IE;
983 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
984 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
985 "(Re)Association Request - possible WPS use");
986 sta->flags |= WLAN_STA_MAYBE_WPS;
988 #endif /* CONFIG_WPS */
989 if (hapd->conf->wpa && wpa_ie == NULL) {
990 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
992 "No WPA/RSN IE in association request");
993 return WLAN_STATUS_INVALID_IE;
996 if (hapd->conf->wpa && wpa_ie) {
1000 if (sta->wpa_sm == NULL)
1001 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1004 if (sta->wpa_sm == NULL) {
1005 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1007 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1009 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1011 elems.mdie, elems.mdie_len);
1012 if (res == WPA_INVALID_GROUP)
1013 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1014 else if (res == WPA_INVALID_PAIRWISE)
1015 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1016 else if (res == WPA_INVALID_AKMP)
1017 resp = WLAN_STATUS_AKMP_NOT_VALID;
1018 else if (res == WPA_ALLOC_FAIL)
1019 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1020 #ifdef CONFIG_IEEE80211W
1021 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1022 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1023 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1024 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1025 #endif /* CONFIG_IEEE80211W */
1026 else if (res == WPA_INVALID_MDIE)
1027 resp = WLAN_STATUS_INVALID_MDIE;
1028 else if (res != WPA_IE_OK)
1029 resp = WLAN_STATUS_INVALID_IE;
1030 if (resp != WLAN_STATUS_SUCCESS)
1032 #ifdef CONFIG_IEEE80211W
1033 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1034 sta->sa_query_count > 0)
1035 ap_check_sa_query_timeout(hapd, sta);
1036 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1037 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1039 * STA has already been associated with MFP and SA
1040 * Query timeout has not been reached. Reject the
1041 * association attempt temporarily and start SA Query,
1042 * if one is not pending.
1045 if (sta->sa_query_count == 0)
1046 ap_sta_start_sa_query(hapd, sta);
1048 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1051 if (wpa_auth_uses_mfp(sta->wpa_sm))
1052 sta->flags |= WLAN_STA_MFP;
1054 sta->flags &= ~WLAN_STA_MFP;
1055 #endif /* CONFIG_IEEE80211W */
1057 #ifdef CONFIG_IEEE80211R
1058 if (sta->auth_alg == WLAN_AUTH_FT) {
1060 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1061 "to use association (not "
1062 "re-association) with FT auth_alg",
1063 MAC2STR(sta->addr));
1064 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1067 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1069 if (resp != WLAN_STATUS_SUCCESS)
1072 #endif /* CONFIG_IEEE80211R */
1075 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1076 sta->auth_alg != WLAN_AUTH_SAE &&
1077 !(sta->auth_alg == WLAN_AUTH_FT &&
1078 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1079 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1080 "SAE AKM after non-SAE auth_alg %u",
1081 MAC2STR(sta->addr), sta->auth_alg);
1082 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1084 #endif /* CONFIG_SAE */
1086 #ifdef CONFIG_IEEE80211N
1087 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1088 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1089 hostapd_logger(hapd, sta->addr,
1090 HOSTAPD_MODULE_IEEE80211,
1092 "Station tried to use TKIP with HT "
1094 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1096 #endif /* CONFIG_IEEE80211N */
1098 } else if (hapd->conf->osen) {
1099 if (elems.osen == NULL) {
1101 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1103 "No HS 2.0 OSEN element in association request");
1104 return WLAN_STATUS_INVALID_IE;
1107 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1108 if (sta->wpa_sm == NULL)
1109 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1111 if (sta->wpa_sm == NULL) {
1112 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1114 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1116 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1117 elems.osen - 2, elems.osen_len + 2) < 0)
1118 return WLAN_STATUS_INVALID_IE;
1119 #endif /* CONFIG_HS20 */
1121 wpa_auth_sta_no_wpa(sta->wpa_sm);
1124 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1125 #endif /* CONFIG_P2P */
1128 wpabuf_free(sta->hs20_ie);
1129 if (elems.hs20 && elems.hs20_len > 4) {
1130 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1131 elems.hs20_len - 4);
1133 sta->hs20_ie = NULL;
1134 #endif /* CONFIG_HS20 */
1136 return WLAN_STATUS_SUCCESS;
1140 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1144 struct ieee80211_mgmt reply;
1146 os_memset(&reply, 0, sizeof(reply));
1147 reply.frame_control =
1148 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1149 os_memcpy(reply.da, addr, ETH_ALEN);
1150 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1151 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1153 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1154 reply.u.deauth.reason_code = host_to_le16(reason_code);
1156 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1157 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1162 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1163 u16 status_code, int reassoc, const u8 *ies,
1167 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1168 struct ieee80211_mgmt *reply;
1171 os_memset(buf, 0, sizeof(buf));
1172 reply = (struct ieee80211_mgmt *) buf;
1173 reply->frame_control =
1174 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1175 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1176 WLAN_FC_STYPE_ASSOC_RESP));
1177 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1178 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1179 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1181 send_len = IEEE80211_HDRLEN;
1182 send_len += sizeof(reply->u.assoc_resp);
1183 reply->u.assoc_resp.capab_info =
1184 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1185 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1186 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
1187 /* Supported rates */
1188 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1189 /* Extended supported rates */
1190 p = hostapd_eid_ext_supp_rates(hapd, p);
1192 #ifdef CONFIG_IEEE80211R
1193 if (status_code == WLAN_STATUS_SUCCESS) {
1194 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1195 * Transition Information, RSN, [RIC Response] */
1196 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1197 buf + sizeof(buf) - p,
1198 sta->auth_alg, ies, ies_len);
1200 #endif /* CONFIG_IEEE80211R */
1202 #ifdef CONFIG_IEEE80211W
1203 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1204 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1205 #endif /* CONFIG_IEEE80211W */
1207 #ifdef CONFIG_IEEE80211N
1208 p = hostapd_eid_ht_capabilities(hapd, p);
1209 p = hostapd_eid_ht_operation(hapd, p);
1210 #endif /* CONFIG_IEEE80211N */
1212 #ifdef CONFIG_IEEE80211AC
1213 p = hostapd_eid_vht_capabilities(hapd, p);
1214 p = hostapd_eid_vht_operation(hapd, p);
1215 #endif /* CONFIG_IEEE80211AC */
1217 p = hostapd_eid_ext_capab(hapd, p);
1218 p = hostapd_eid_bss_max_idle_period(hapd, p);
1219 if (sta->qos_map_enabled)
1220 p = hostapd_eid_qos_map_set(hapd, p);
1222 if (sta->flags & WLAN_STA_WMM)
1223 p = hostapd_eid_wmm(hapd, p);
1226 if ((sta->flags & WLAN_STA_WPS) ||
1227 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1228 struct wpabuf *wps = wps_build_assoc_resp_ie();
1230 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1231 p += wpabuf_len(wps);
1235 #endif /* CONFIG_WPS */
1239 struct wpabuf *p2p_resp_ie;
1240 enum p2p_status_code status;
1241 switch (status_code) {
1242 case WLAN_STATUS_SUCCESS:
1243 status = P2P_SC_SUCCESS;
1245 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1246 status = P2P_SC_FAIL_LIMIT_REACHED;
1249 status = P2P_SC_FAIL_INVALID_PARAMS;
1252 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1254 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1255 wpabuf_len(p2p_resp_ie));
1256 p += wpabuf_len(p2p_resp_ie);
1257 wpabuf_free(p2p_resp_ie);
1260 #endif /* CONFIG_P2P */
1262 #ifdef CONFIG_P2P_MANAGER
1263 if (hapd->conf->p2p & P2P_MANAGE)
1264 p = hostapd_eid_p2p_manage(hapd, p);
1265 #endif /* CONFIG_P2P_MANAGER */
1267 send_len += p - reply->u.assoc_resp.variable;
1269 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1270 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1275 static void handle_assoc(struct hostapd_data *hapd,
1276 const struct ieee80211_mgmt *mgmt, size_t len,
1279 u16 capab_info, listen_interval;
1280 u16 resp = WLAN_STATUS_SUCCESS;
1283 struct sta_info *sta;
1285 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1286 sizeof(mgmt->u.assoc_req))) {
1287 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1288 reassoc, (unsigned long) len);
1292 #ifdef CONFIG_TESTING_OPTIONS
1294 if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
1295 drand48() < hapd->iconf->ignore_reassoc_probability) {
1296 wpa_printf(MSG_INFO,
1297 "TESTING: ignoring reassoc request from "
1298 MACSTR, MAC2STR(mgmt->sa));
1302 if (hapd->iconf->ignore_assoc_probability > 0.0d &&
1303 drand48() < hapd->iconf->ignore_assoc_probability) {
1304 wpa_printf(MSG_INFO,
1305 "TESTING: ignoring assoc request from "
1306 MACSTR, MAC2STR(mgmt->sa));
1310 #endif /* CONFIG_TESTING_OPTIONS */
1313 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1314 listen_interval = le_to_host16(
1315 mgmt->u.reassoc_req.listen_interval);
1316 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1317 " capab_info=0x%02x listen_interval=%d current_ap="
1319 MAC2STR(mgmt->sa), capab_info, listen_interval,
1320 MAC2STR(mgmt->u.reassoc_req.current_ap));
1321 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1322 pos = mgmt->u.reassoc_req.variable;
1324 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1325 listen_interval = le_to_host16(
1326 mgmt->u.assoc_req.listen_interval);
1327 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1328 " capab_info=0x%02x listen_interval=%d",
1329 MAC2STR(mgmt->sa), capab_info, listen_interval);
1330 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1331 pos = mgmt->u.assoc_req.variable;
1334 sta = ap_get_sta(hapd, mgmt->sa);
1335 #ifdef CONFIG_IEEE80211R
1336 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1337 (sta->flags & WLAN_STA_AUTH) == 0) {
1338 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1339 "prior to authentication since it is using "
1340 "over-the-DS FT", MAC2STR(mgmt->sa));
1342 #endif /* CONFIG_IEEE80211R */
1343 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1344 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1345 HOSTAPD_LEVEL_INFO, "Station tried to "
1346 "associate before authentication "
1347 "(aid=%d flags=0x%x)",
1348 sta ? sta->aid : -1,
1349 sta ? sta->flags : 0);
1350 send_deauth(hapd, mgmt->sa,
1351 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1355 if (hapd->tkip_countermeasures) {
1356 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1360 if (listen_interval > hapd->conf->max_listen_interval) {
1361 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1362 HOSTAPD_LEVEL_DEBUG,
1363 "Too large Listen Interval (%d)",
1365 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1369 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1371 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1372 if (resp != WLAN_STATUS_SUCCESS)
1375 if (hostapd_get_aid(hapd, sta) < 0) {
1376 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1377 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1378 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1382 sta->capability = capab_info;
1383 sta->listen_interval = listen_interval;
1385 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1386 sta->flags |= WLAN_STA_NONERP;
1387 for (i = 0; i < sta->supported_rates_len; i++) {
1388 if ((sta->supported_rates[i] & 0x7f) > 22) {
1389 sta->flags &= ~WLAN_STA_NONERP;
1393 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1394 sta->nonerp_set = 1;
1395 hapd->iface->num_sta_non_erp++;
1396 if (hapd->iface->num_sta_non_erp == 1)
1397 ieee802_11_set_beacons(hapd->iface);
1400 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1401 !sta->no_short_slot_time_set) {
1402 sta->no_short_slot_time_set = 1;
1403 hapd->iface->num_sta_no_short_slot_time++;
1404 if (hapd->iface->current_mode->mode ==
1405 HOSTAPD_MODE_IEEE80211G &&
1406 hapd->iface->num_sta_no_short_slot_time == 1)
1407 ieee802_11_set_beacons(hapd->iface);
1410 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1411 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1413 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1415 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1416 !sta->no_short_preamble_set) {
1417 sta->no_short_preamble_set = 1;
1418 hapd->iface->num_sta_no_short_preamble++;
1419 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1420 && hapd->iface->num_sta_no_short_preamble == 1)
1421 ieee802_11_set_beacons(hapd->iface);
1424 #ifdef CONFIG_IEEE80211N
1425 update_ht_state(hapd, sta);
1426 #endif /* CONFIG_IEEE80211N */
1428 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1429 HOSTAPD_LEVEL_DEBUG,
1430 "association OK (aid %d)", sta->aid);
1431 /* Station will be marked associated, after it acknowledges AssocResp
1433 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1435 #ifdef CONFIG_IEEE80211W
1436 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1437 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1438 "SA Query procedure", reassoc ? "re" : "");
1439 /* TODO: Send a protected Disassociate frame to the STA using
1440 * the old key and Reason Code "Previous Authentication no
1441 * longer valid". Make sure this is only sent protected since
1442 * unprotected frame would be received by the STA that is now
1443 * trying to associate.
1446 #endif /* CONFIG_IEEE80211W */
1448 /* Make sure that the previously registered inactivity timer will not
1449 * remove the STA immediately. */
1450 sta->timeout_next = STA_NULLFUNC;
1453 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1457 static void handle_disassoc(struct hostapd_data *hapd,
1458 const struct ieee80211_mgmt *mgmt, size_t len)
1460 struct sta_info *sta;
1462 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1463 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1464 (unsigned long) len);
1468 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1470 le_to_host16(mgmt->u.disassoc.reason_code));
1472 sta = ap_get_sta(hapd, mgmt->sa);
1474 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1479 ap_sta_set_authorized(hapd, sta, 0);
1480 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1481 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1482 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1483 HOSTAPD_LEVEL_INFO, "disassociated");
1484 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1485 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1486 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1488 accounting_sta_stop(hapd, sta);
1489 ieee802_1x_free_station(sta);
1490 hostapd_drv_sta_remove(hapd, sta->addr);
1492 if (sta->timeout_next == STA_NULLFUNC ||
1493 sta->timeout_next == STA_DISASSOC) {
1494 sta->timeout_next = STA_DEAUTH;
1495 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1496 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1500 mlme_disassociate_indication(
1501 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1505 static void handle_deauth(struct hostapd_data *hapd,
1506 const struct ieee80211_mgmt *mgmt, size_t len)
1508 struct sta_info *sta;
1510 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1511 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1512 "payload (len=%lu)", (unsigned long) len);
1516 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1518 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1520 sta = ap_get_sta(hapd, mgmt->sa);
1522 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1523 "to deauthenticate, but it is not authenticated",
1528 ap_sta_set_authorized(hapd, sta, 0);
1529 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1530 WLAN_STA_ASSOC_REQ_OK);
1531 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1532 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1533 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1534 mlme_deauthenticate_indication(
1535 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1536 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1537 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1538 ap_free_sta(hapd, sta);
1542 static void handle_beacon(struct hostapd_data *hapd,
1543 const struct ieee80211_mgmt *mgmt, size_t len,
1544 struct hostapd_frame_info *fi)
1546 struct ieee802_11_elems elems;
1548 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1549 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1550 (unsigned long) len);
1554 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1555 len - (IEEE80211_HDRLEN +
1556 sizeof(mgmt->u.beacon)), &elems,
1559 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1563 #ifdef CONFIG_IEEE80211W
1565 static int hostapd_sa_query_action(struct hostapd_data *hapd,
1566 const struct ieee80211_mgmt *mgmt,
1571 end = mgmt->u.action.u.sa_query_resp.trans_id +
1572 WLAN_SA_QUERY_TR_ID_LEN;
1573 if (((u8 *) mgmt) + len < end) {
1574 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1575 "frame (len=%lu)", (unsigned long) len);
1579 ieee802_11_sa_query_action(hapd, mgmt->sa,
1580 mgmt->u.action.u.sa_query_resp.action,
1581 mgmt->u.action.u.sa_query_resp.trans_id);
1586 static int robust_action_frame(u8 category)
1588 return category != WLAN_ACTION_PUBLIC &&
1589 category != WLAN_ACTION_HT;
1591 #endif /* CONFIG_IEEE80211W */
1594 static int handle_action(struct hostapd_data *hapd,
1595 const struct ieee80211_mgmt *mgmt, size_t len)
1597 struct sta_info *sta;
1598 sta = ap_get_sta(hapd, mgmt->sa);
1600 if (len < IEEE80211_HDRLEN + 1) {
1601 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1602 HOSTAPD_LEVEL_DEBUG,
1603 "handle_action - too short payload (len=%lu)",
1604 (unsigned long) len);
1608 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1609 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1610 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1611 "frame (category=%u) from unassociated STA " MACSTR,
1612 MAC2STR(mgmt->sa), mgmt->u.action.category);
1616 #ifdef CONFIG_IEEE80211W
1617 if (sta && (sta->flags & WLAN_STA_MFP) &&
1618 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
1619 robust_action_frame(mgmt->u.action.category)) {
1620 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1621 HOSTAPD_LEVEL_DEBUG,
1622 "Dropped unprotected Robust Action frame from "
1626 #endif /* CONFIG_IEEE80211W */
1628 switch (mgmt->u.action.category) {
1629 #ifdef CONFIG_IEEE80211R
1630 case WLAN_ACTION_FT:
1631 if (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 if (hapd->public_action_cb) {
1651 hapd->public_action_cb(hapd->public_action_cb_ctx,
1655 if (hapd->public_action_cb2) {
1656 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1660 if (hapd->public_action_cb || hapd->public_action_cb2)
1663 case WLAN_ACTION_VENDOR_SPECIFIC:
1664 if (hapd->vendor_action_cb) {
1665 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1667 hapd->iface->freq) == 0)
1673 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1674 HOSTAPD_LEVEL_DEBUG,
1675 "handle_action - unknown action category %d or invalid "
1677 mgmt->u.action.category);
1678 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1679 !(mgmt->sa[0] & 0x01)) {
1680 struct ieee80211_mgmt *resp;
1683 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1684 * Return the Action frame to the source without change
1685 * except that MSB of the Category set to 1.
1687 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1688 "frame back to sender");
1689 resp = os_malloc(len);
1692 os_memcpy(resp, mgmt, len);
1693 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1694 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1695 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1696 resp->u.action.category |= 0x80;
1698 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1699 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1710 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1711 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1713 * @buf: management frame data (starting from IEEE 802.11 header)
1714 * @len: length of frame data in octets
1715 * @fi: meta data about received frame (signal level, etc.)
1717 * Process all incoming IEEE 802.11 management frames. This will be called for
1718 * each frame received from the kernel driver through wlan#ap interface. In
1719 * addition, it can be called to re-inserted pending frames (e.g., when using
1720 * external RADIUS server as an MAC ACL).
1722 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1723 struct hostapd_frame_info *fi)
1725 struct ieee80211_mgmt *mgmt;
1733 mgmt = (struct ieee80211_mgmt *) buf;
1734 fc = le_to_host16(mgmt->frame_control);
1735 stype = WLAN_FC_GET_STYPE(fc);
1737 if (stype == WLAN_FC_STYPE_BEACON) {
1738 handle_beacon(hapd, mgmt, len, fi);
1742 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1743 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1744 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1748 /* Invitation responses can be sent with the peer MAC as BSSID */
1749 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1750 stype == WLAN_FC_STYPE_ACTION) &&
1751 #endif /* CONFIG_P2P */
1752 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1753 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
1754 MAC2STR(mgmt->bssid));
1759 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1760 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1764 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1765 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1766 HOSTAPD_LEVEL_DEBUG,
1767 "MGMT: DA=" MACSTR " not our address",
1773 case WLAN_FC_STYPE_AUTH:
1774 wpa_printf(MSG_DEBUG, "mgmt::auth");
1775 handle_auth(hapd, mgmt, len);
1778 case WLAN_FC_STYPE_ASSOC_REQ:
1779 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1780 handle_assoc(hapd, mgmt, len, 0);
1783 case WLAN_FC_STYPE_REASSOC_REQ:
1784 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1785 handle_assoc(hapd, mgmt, len, 1);
1788 case WLAN_FC_STYPE_DISASSOC:
1789 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1790 handle_disassoc(hapd, mgmt, len);
1793 case WLAN_FC_STYPE_DEAUTH:
1794 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1795 handle_deauth(hapd, mgmt, len);
1798 case WLAN_FC_STYPE_ACTION:
1799 wpa_printf(MSG_DEBUG, "mgmt::action");
1800 ret = handle_action(hapd, mgmt, len);
1803 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1804 HOSTAPD_LEVEL_DEBUG,
1805 "unknown mgmt frame subtype %d", stype);
1813 static void handle_auth_cb(struct hostapd_data *hapd,
1814 const struct ieee80211_mgmt *mgmt,
1817 u16 auth_alg, auth_transaction, status_code;
1818 struct sta_info *sta;
1821 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1822 HOSTAPD_LEVEL_NOTICE,
1823 "did not acknowledge authentication response");
1827 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1828 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
1829 (unsigned long) len);
1833 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1834 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1835 status_code = le_to_host16(mgmt->u.auth.status_code);
1837 sta = ap_get_sta(hapd, mgmt->da);
1839 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
1844 if (status_code == WLAN_STATUS_SUCCESS &&
1845 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1846 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1847 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1848 HOSTAPD_LEVEL_INFO, "authenticated");
1849 sta->flags |= WLAN_STA_AUTH;
1854 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
1855 struct sta_info *sta,
1859 struct hostapd_ssid *ssid = sta->ssid;
1861 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
1864 for (i = 0; i < 4; i++) {
1865 if (ssid->wep.key[i] &&
1866 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
1867 i == ssid->wep.idx, NULL, 0,
1868 ssid->wep.key[i], ssid->wep.len[i])) {
1869 wpa_printf(MSG_WARNING,
1870 "Could not set WEP keys for WDS interface; %s",
1878 static void handle_assoc_cb(struct hostapd_data *hapd,
1879 const struct ieee80211_mgmt *mgmt,
1880 size_t len, int reassoc, int ok)
1883 struct sta_info *sta;
1885 struct ieee80211_ht_capabilities ht_cap;
1886 struct ieee80211_vht_capabilities vht_cap;
1888 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1889 sizeof(mgmt->u.assoc_resp))) {
1890 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
1891 reassoc, (unsigned long) len);
1895 sta = ap_get_sta(hapd, mgmt->da);
1897 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
1903 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1904 HOSTAPD_LEVEL_DEBUG,
1905 "did not acknowledge association response");
1906 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1911 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1913 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1915 if (status != WLAN_STATUS_SUCCESS)
1918 /* Stop previous accounting session, if one is started, and allocate
1919 * new session id for the new session. */
1920 accounting_sta_stop(hapd, sta);
1922 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1924 "associated (aid %d)",
1927 if (sta->flags & WLAN_STA_ASSOC)
1929 sta->flags |= WLAN_STA_ASSOC;
1930 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
1931 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
1932 sta->auth_alg == WLAN_AUTH_FT) {
1934 * Open, static WEP, or FT protocol; no separate authorization
1937 ap_sta_set_authorized(hapd, sta, 1);
1941 mlme_reassociate_indication(hapd, sta);
1943 mlme_associate_indication(hapd, sta);
1945 #ifdef CONFIG_IEEE80211W
1946 sta->sa_query_timed_out = 0;
1947 #endif /* CONFIG_IEEE80211W */
1950 * Remove the STA entry in order to make sure the STA PS state gets
1951 * cleared and configuration gets updated in case of reassociation back
1954 hostapd_drv_sta_remove(hapd, sta->addr);
1956 #ifdef CONFIG_IEEE80211N
1957 if (sta->flags & WLAN_STA_HT)
1958 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1959 #endif /* CONFIG_IEEE80211N */
1960 #ifdef CONFIG_IEEE80211AC
1961 if (sta->flags & WLAN_STA_VHT)
1962 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1963 #endif /* CONFIG_IEEE80211AC */
1965 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1966 sta->supported_rates, sta->supported_rates_len,
1967 sta->listen_interval,
1968 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1969 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1970 sta->flags, sta->qosinfo, sta->vht_opmode)) {
1971 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1972 HOSTAPD_LEVEL_NOTICE,
1973 "Could not add STA to kernel driver");
1975 ap_sta_disconnect(hapd, sta, sta->addr,
1976 WLAN_REASON_DISASSOC_AP_BUSY);
1981 if (sta->flags & WLAN_STA_WDS) {
1983 char ifname_wds[IFNAMSIZ + 1];
1985 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
1988 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
1991 if (sta->eapol_sm == NULL) {
1993 * This STA does not use RADIUS server for EAP authentication,
1994 * so bind it to the selected VLAN interface now, since the
1995 * interface selection is not going to change anymore.
1997 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1999 } else if (sta->vlan_id) {
2000 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2001 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2005 hostapd_set_sta_flags(hapd, sta);
2007 if (sta->auth_alg == WLAN_AUTH_FT)
2008 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2010 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2011 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2013 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2017 static void handle_deauth_cb(struct hostapd_data *hapd,
2018 const struct ieee80211_mgmt *mgmt,
2021 struct sta_info *sta;
2022 if (mgmt->da[0] & 0x01)
2024 sta = ap_get_sta(hapd, mgmt->da);
2026 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2027 " not found", MAC2STR(mgmt->da));
2031 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2032 MAC2STR(sta->addr));
2034 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2035 "deauth", MAC2STR(sta->addr));
2037 ap_sta_deauth_cb(hapd, sta);
2041 static void handle_disassoc_cb(struct hostapd_data *hapd,
2042 const struct ieee80211_mgmt *mgmt,
2045 struct sta_info *sta;
2046 if (mgmt->da[0] & 0x01)
2048 sta = ap_get_sta(hapd, mgmt->da);
2050 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2051 " not found", MAC2STR(mgmt->da));
2055 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2056 MAC2STR(sta->addr));
2058 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2059 "disassoc", MAC2STR(sta->addr));
2061 ap_sta_disassoc_cb(hapd, sta);
2066 * ieee802_11_mgmt_cb - Process management frame TX status callback
2067 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2069 * @buf: management frame data (starting from IEEE 802.11 header)
2070 * @len: length of frame data in octets
2071 * @stype: management frame subtype from frame control field
2072 * @ok: Whether the frame was ACK'ed
2074 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2077 const struct ieee80211_mgmt *mgmt;
2078 mgmt = (const struct ieee80211_mgmt *) buf;
2080 #ifdef CONFIG_TESTING_OPTIONS
2081 if (hapd->ext_mgmt_frame_handling) {
2082 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2086 #endif /* CONFIG_TESTING_OPTIONS */
2089 case WLAN_FC_STYPE_AUTH:
2090 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2091 handle_auth_cb(hapd, mgmt, len, ok);
2093 case WLAN_FC_STYPE_ASSOC_RESP:
2094 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2095 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2097 case WLAN_FC_STYPE_REASSOC_RESP:
2098 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2099 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2101 case WLAN_FC_STYPE_PROBE_RESP:
2102 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2104 case WLAN_FC_STYPE_DEAUTH:
2105 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2106 handle_deauth_cb(hapd, mgmt, len, ok);
2108 case WLAN_FC_STYPE_DISASSOC:
2109 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2110 handle_disassoc_cb(hapd, mgmt, len, ok);
2112 case WLAN_FC_STYPE_ACTION:
2113 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2116 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2122 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2129 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2130 char *buf, size_t buflen)
2137 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2138 const u8 *buf, size_t len, int ack)
2140 struct sta_info *sta;
2141 struct hostapd_iface *iface = hapd->iface;
2143 sta = ap_get_sta(hapd, addr);
2144 if (sta == NULL && iface->num_bss > 1) {
2146 for (j = 0; j < iface->num_bss; j++) {
2147 hapd = iface->bss[j];
2148 sta = ap_get_sta(hapd, addr);
2153 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2155 if (sta->flags & WLAN_STA_PENDING_POLL) {
2156 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2157 "activity poll", MAC2STR(sta->addr),
2158 ack ? "ACKed" : "did not ACK");
2160 sta->flags &= ~WLAN_STA_PENDING_POLL;
2163 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2167 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2168 const u8 *data, size_t len, int ack)
2170 struct sta_info *sta;
2171 struct hostapd_iface *iface = hapd->iface;
2173 sta = ap_get_sta(hapd, dst);
2174 if (sta == NULL && iface->num_bss > 1) {
2176 for (j = 0; j < iface->num_bss; j++) {
2177 hapd = iface->bss[j];
2178 sta = ap_get_sta(hapd, dst);
2183 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2184 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2185 MACSTR " that is not currently associated",
2190 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2194 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2196 struct sta_info *sta;
2197 struct hostapd_iface *iface = hapd->iface;
2199 sta = ap_get_sta(hapd, addr);
2200 if (sta == NULL && iface->num_bss > 1) {
2202 for (j = 0; j < iface->num_bss; j++) {
2203 hapd = iface->bss[j];
2204 sta = ap_get_sta(hapd, addr);
2211 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2214 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2215 "activity poll", MAC2STR(sta->addr));
2216 sta->flags &= ~WLAN_STA_PENDING_POLL;
2220 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2223 struct sta_info *sta;
2225 sta = ap_get_sta(hapd, src);
2226 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2227 if (!hapd->conf->wds_sta)
2230 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2232 char ifname_wds[IFNAMSIZ + 1];
2234 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2235 "STA " MACSTR " (aid %u)",
2236 MAC2STR(sta->addr), sta->aid);
2237 sta->flags |= WLAN_STA_WDS;
2238 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2239 sta->addr, sta->aid, 1);
2241 hostapd_set_wds_encryption(hapd, sta,
2247 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2248 MACSTR, MAC2STR(src));
2249 if (src[0] & 0x01) {
2250 /* Broadcast bit set in SA?! Ignore the frame silently. */
2254 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2255 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2256 "already been sent, but no TX status yet known - "
2257 "ignore Class 3 frame issue with " MACSTR,
2262 if (sta && (sta->flags & WLAN_STA_AUTH))
2263 hostapd_drv_sta_disassoc(
2265 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2267 hostapd_drv_sta_deauth(
2269 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2273 #endif /* CONFIG_NATIVE_WINDOWS */