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"
43 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
48 if (hapd->iface->current_rates == NULL)
51 *pos++ = WLAN_EID_SUPP_RATES;
52 num = hapd->iface->num_rates;
53 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
55 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
58 /* 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;
108 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
112 continue; /* already in SuppRates IE */
113 *pos = hapd->iface->current_rates[i].rate / 5;
114 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
119 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
122 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
125 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
128 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
135 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
138 int capab = WLAN_CAPABILITY_ESS;
141 if (hapd->iface->num_sta_no_short_preamble == 0 &&
142 hapd->iconf->preamble == SHORT_PREAMBLE)
143 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
145 privacy = hapd->conf->ssid.wep.keys_set;
147 if (hapd->conf->ieee802_1x &&
148 (hapd->conf->default_wep_key_len ||
149 hapd->conf->individual_wep_key_len))
156 int policy, def_klen;
157 if (probe && sta->ssid_probe) {
158 policy = sta->ssid_probe->security_policy;
159 def_klen = sta->ssid_probe->wep.default_len;
161 policy = sta->ssid->security_policy;
162 def_klen = sta->ssid->wep.default_len;
164 privacy = policy != SECURITY_PLAINTEXT;
165 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
170 capab |= WLAN_CAPABILITY_PRIVACY;
172 if (hapd->iface->current_mode &&
173 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
174 hapd->iface->num_sta_no_short_slot_time == 0)
175 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
181 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
184 if (len > HOSTAPD_MAX_SSID_LEN)
185 len = HOSTAPD_MAX_SSID_LEN;
186 for (i = 0; i < len; i++) {
187 if (ssid[i] >= 32 && ssid[i] < 127)
196 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
197 u16 auth_transaction, const u8 *challenge,
200 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
202 "authentication (shared key, transaction %d)",
205 if (auth_transaction == 1) {
206 if (!sta->challenge) {
207 /* Generate a pseudo-random challenge */
211 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
212 if (sta->challenge == NULL)
213 return WLAN_STATUS_UNSPECIFIED_FAILURE;
217 os_memcpy(key, &now.sec, 4);
218 os_memcpy(key + 4, &r, 4);
219 rc4_skip(key, sizeof(key), 0,
220 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
225 if (auth_transaction != 3)
226 return WLAN_STATUS_UNSPECIFIED_FAILURE;
229 if (!iswep || !sta->challenge || !challenge ||
230 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
231 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
233 "shared key authentication - invalid "
234 "challenge-response");
235 return WLAN_STATUS_CHALLENGE_FAIL;
238 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
240 "authentication OK (shared key)");
241 #ifdef IEEE80211_REQUIRE_AUTH_ACK
242 /* Station will be marked authenticated if it ACKs the
243 * authentication reply. */
245 sta->flags |= WLAN_STA_AUTH;
246 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
248 os_free(sta->challenge);
249 sta->challenge = NULL;
255 static void send_auth_reply(struct hostapd_data *hapd,
256 const u8 *dst, const u8 *bssid,
257 u16 auth_alg, u16 auth_transaction, u16 resp,
258 const u8 *ies, size_t ies_len)
260 struct ieee80211_mgmt *reply;
264 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
265 buf = os_zalloc(rlen);
269 reply = (struct ieee80211_mgmt *) buf;
270 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
272 os_memcpy(reply->da, dst, ETH_ALEN);
273 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
274 os_memcpy(reply->bssid, bssid, ETH_ALEN);
276 reply->u.auth.auth_alg = host_to_le16(auth_alg);
277 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
278 reply->u.auth.status_code = host_to_le16(resp);
281 os_memcpy(reply->u.auth.variable, ies, ies_len);
283 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
284 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
285 MAC2STR(dst), auth_alg, auth_transaction,
286 resp, (unsigned long) ies_len);
287 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
288 wpa_printf(MSG_INFO, "send_auth_reply: send");
294 #ifdef CONFIG_IEEE80211R
295 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
296 u16 auth_transaction, u16 status,
297 const u8 *ies, size_t ies_len)
299 struct hostapd_data *hapd = ctx;
300 struct sta_info *sta;
302 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
303 status, ies, ies_len);
305 if (status != WLAN_STATUS_SUCCESS)
308 sta = ap_get_sta(hapd, dst);
312 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
313 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
314 sta->flags |= WLAN_STA_AUTH;
315 mlme_authenticate_indication(hapd, sta);
317 #endif /* CONFIG_IEEE80211R */
322 static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
323 struct sta_info *sta)
327 if (hapd->conf->ssid.wpa_passphrase == NULL) {
328 wpa_printf(MSG_DEBUG, "SAE: No password available");
332 if (sae_prepare_commit(hapd->own_addr, sta->addr,
333 (u8 *) hapd->conf->ssid.wpa_passphrase,
334 os_strlen(hapd->conf->ssid.wpa_passphrase),
336 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
340 if (sae_process_commit(sta->sae) < 0) {
341 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
345 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
348 sae_write_commit(sta->sae, buf, NULL);
354 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
355 struct sta_info *sta)
359 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
363 sae_write_confirm(sta->sae, buf);
369 static int use_sae_anti_clogging(struct hostapd_data *hapd)
371 struct sta_info *sta;
372 unsigned int open = 0;
374 if (hapd->conf->sae_anti_clogging_threshold == 0)
377 for (sta = hapd->sta_list; sta; sta = sta->next) {
380 if (sta->sae->state != SAE_COMMITTED &&
381 sta->sae->state != SAE_CONFIRMED)
384 if (open >= hapd->conf->sae_anti_clogging_threshold)
392 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
393 const u8 *token, size_t token_len)
395 u8 mac[SHA256_MAC_LEN];
397 if (token_len != SHA256_MAC_LEN)
399 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
400 addr, ETH_ALEN, mac) < 0 ||
401 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
408 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
413 struct os_reltime now;
415 os_get_reltime(&now);
416 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
417 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
418 if (random_get_bytes(hapd->sae_token_key,
419 sizeof(hapd->sae_token_key)) < 0)
421 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
422 hapd->sae_token_key, sizeof(hapd->sae_token_key));
423 hapd->last_sae_token_key_update = now;
426 buf = wpabuf_alloc(SHA256_MAC_LEN);
430 token = wpabuf_put(buf, SHA256_MAC_LEN);
431 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
432 addr, ETH_ALEN, token);
438 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
439 const struct ieee80211_mgmt *mgmt, size_t len,
442 u16 resp = WLAN_STATUS_SUCCESS;
443 struct wpabuf *data = NULL;
446 if (auth_transaction != 1)
448 sta->sae = os_zalloc(sizeof(*sta->sae));
449 if (sta->sae == NULL)
451 sta->sae->state = SAE_NOTHING;
454 if (auth_transaction == 1) {
455 const u8 *token = NULL;
456 size_t token_len = 0;
457 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
459 "start SAE authentication (RX commit)");
460 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
461 ((const u8 *) mgmt) + len -
462 mgmt->u.auth.variable, &token,
463 &token_len, hapd->conf->sae_groups);
464 if (token && check_sae_token(hapd, sta->addr, token, token_len)
466 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
467 "incorrect token from " MACSTR,
472 if (resp == WLAN_STATUS_SUCCESS) {
473 if (!token && use_sae_anti_clogging(hapd)) {
474 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
475 "clogging token from " MACSTR,
477 data = auth_build_token_req(hapd, sta->addr);
478 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
480 data = auth_process_sae_commit(hapd, sta);
482 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
484 sta->sae->state = SAE_COMMITTED;
487 } else if (auth_transaction == 2) {
488 if (sta->sae->state != SAE_COMMITTED) {
489 hostapd_logger(hapd, sta->addr,
490 HOSTAPD_MODULE_IEEE80211,
492 "SAE confirm before commit");
493 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
495 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
497 "SAE authentication (RX confirm)");
498 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
499 ((u8 *) mgmt) + len -
500 mgmt->u.auth.variable) < 0) {
501 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
503 resp = WLAN_STATUS_SUCCESS;
504 sta->flags |= WLAN_STA_AUTH;
505 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
506 sta->auth_alg = WLAN_AUTH_SAE;
507 mlme_authenticate_indication(hapd, sta);
509 data = auth_build_sae_confirm(hapd, sta);
511 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
513 sta->sae->state = SAE_ACCEPTED;
514 sae_clear_temp_data(sta->sae);
518 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
520 "unexpected SAE authentication transaction %u",
522 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
525 sta->auth_alg = WLAN_AUTH_SAE;
527 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
528 auth_transaction, resp,
529 data ? wpabuf_head(data) : (u8 *) "",
530 data ? wpabuf_len(data) : 0);
533 #endif /* CONFIG_SAE */
536 static void handle_auth(struct hostapd_data *hapd,
537 const struct ieee80211_mgmt *mgmt, size_t len)
539 u16 auth_alg, auth_transaction, status_code;
540 u16 resp = WLAN_STATUS_SUCCESS;
541 struct sta_info *sta = NULL;
544 const u8 *challenge = NULL;
545 u32 session_timeout, acct_interim_interval;
547 struct hostapd_sta_wpa_psk_short *psk = NULL;
548 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
549 size_t resp_ies_len = 0;
550 char *identity = NULL;
551 char *radius_cui = NULL;
553 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
554 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
555 (unsigned long) len);
559 #ifdef CONFIG_TESTING_OPTIONS
560 if (hapd->iconf->ignore_auth_probability > 0.0d &&
561 drand48() < hapd->iconf->ignore_auth_probability) {
563 "TESTING: ignoring auth frame from " MACSTR,
567 #endif /* CONFIG_TESTING_OPTIONS */
569 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
570 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
571 status_code = le_to_host16(mgmt->u.auth.status_code);
572 fc = le_to_host16(mgmt->frame_control);
574 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
575 2 + WLAN_AUTH_CHALLENGE_LEN &&
576 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
577 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
578 challenge = &mgmt->u.auth.variable[2];
580 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
581 "auth_transaction=%d status_code=%d wep=%d%s",
582 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
583 status_code, !!(fc & WLAN_FC_ISWEP),
584 challenge ? " challenge" : "");
586 if (hapd->tkip_countermeasures) {
587 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
591 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
592 auth_alg == WLAN_AUTH_OPEN) ||
593 #ifdef CONFIG_IEEE80211R
594 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
595 auth_alg == WLAN_AUTH_FT) ||
596 #endif /* CONFIG_IEEE80211R */
598 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
599 auth_alg == WLAN_AUTH_SAE) ||
600 #endif /* CONFIG_SAE */
601 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
602 auth_alg == WLAN_AUTH_SHARED_KEY))) {
603 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
605 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
609 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
610 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
611 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
613 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
617 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
618 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
620 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
624 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
626 &acct_interim_interval, &vlan_id,
627 &psk, &identity, &radius_cui);
629 if (res == HOSTAPD_ACL_REJECT) {
630 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
632 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
635 if (res == HOSTAPD_ACL_PENDING) {
636 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
637 " waiting for an external authentication",
639 /* Authentication code will re-send the authentication frame
640 * after it has received (and cached) information from the
641 * external source. */
645 sta = ap_sta_add(hapd, mgmt->sa);
647 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
652 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
653 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
654 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
655 "%d received from RADIUS server",
657 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
660 sta->vlan_id = vlan_id;
661 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
662 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
665 hostapd_free_psk_list(sta->psk);
666 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
673 sta->identity = identity;
675 sta->radius_cui = radius_cui;
678 sta->flags &= ~WLAN_STA_PREAUTH;
679 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
681 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
682 sta->acct_interim_interval = acct_interim_interval;
683 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
684 ap_sta_session_timeout(hapd, sta, session_timeout);
686 ap_sta_no_session_timeout(hapd, sta);
690 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
692 "authentication OK (open system)");
693 #ifdef IEEE80211_REQUIRE_AUTH_ACK
694 /* Station will be marked authenticated if it ACKs the
695 * authentication reply. */
697 sta->flags |= WLAN_STA_AUTH;
698 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
699 sta->auth_alg = WLAN_AUTH_OPEN;
700 mlme_authenticate_indication(hapd, sta);
703 case WLAN_AUTH_SHARED_KEY:
704 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
706 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
707 mlme_authenticate_indication(hapd, sta);
708 if (sta->challenge && auth_transaction == 1) {
709 resp_ies[0] = WLAN_EID_CHALLENGE;
710 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
711 os_memcpy(resp_ies + 2, sta->challenge,
712 WLAN_AUTH_CHALLENGE_LEN);
713 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
716 #ifdef CONFIG_IEEE80211R
718 sta->auth_alg = WLAN_AUTH_FT;
719 if (sta->wpa_sm == NULL)
720 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
722 if (sta->wpa_sm == NULL) {
723 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
725 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
728 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
729 auth_transaction, mgmt->u.auth.variable,
730 len - IEEE80211_HDRLEN -
731 sizeof(mgmt->u.auth),
732 handle_auth_ft_finish, hapd);
733 /* handle_auth_ft_finish() callback will complete auth. */
735 #endif /* CONFIG_IEEE80211R */
738 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
740 #endif /* CONFIG_SAE */
746 hostapd_free_psk_list(psk);
748 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
749 auth_transaction + 1, resp, resp_ies, resp_ies_len);
753 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
757 /* get a unique AID */
759 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
763 for (i = 0; i < AID_WORDS; i++) {
764 if (hapd->sta_aid[i] == (u32) -1)
766 for (j = 0; j < 32; j++) {
767 if (!(hapd->sta_aid[i] & BIT(j)))
775 aid = i * 32 + j + 1;
780 hapd->sta_aid[i] |= BIT(j);
781 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
786 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
787 const u8 *ssid_ie, size_t ssid_ie_len)
790 return WLAN_STATUS_UNSPECIFIED_FAILURE;
792 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
793 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
795 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
796 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
798 "Station tried to associate with unknown SSID "
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)
923 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
924 !(sta->flags & WLAN_STA_VHT)) {
925 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
926 HOSTAPD_LEVEL_INFO, "Station does not support "
927 "mandatory VHT PHY - reject association");
928 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
930 #endif /* CONFIG_IEEE80211AC */
934 wpabuf_free(sta->p2p_ie);
935 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
938 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
940 wpabuf_free(sta->p2p_ie);
943 #endif /* CONFIG_P2P */
945 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
946 wpa_ie = elems.rsn_ie;
947 wpa_ie_len = elems.rsn_ie_len;
948 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
950 wpa_ie = elems.wpa_ie;
951 wpa_ie_len = elems.wpa_ie_len;
958 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
959 if (hapd->conf->wps_state && elems.wps_ie) {
960 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
961 "Request - assume WPS is used");
962 sta->flags |= WLAN_STA_WPS;
963 wpabuf_free(sta->wps_ie);
964 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
966 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
967 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
968 sta->flags |= WLAN_STA_WPS2;
972 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
973 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
974 "(Re)Association Request - reject");
975 return WLAN_STATUS_INVALID_IE;
977 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
978 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
979 "(Re)Association Request - possible WPS use");
980 sta->flags |= WLAN_STA_MAYBE_WPS;
982 #endif /* CONFIG_WPS */
983 if (hapd->conf->wpa && wpa_ie == NULL) {
984 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
986 "No WPA/RSN IE in association request");
987 return WLAN_STATUS_INVALID_IE;
990 if (hapd->conf->wpa && wpa_ie) {
994 if (sta->wpa_sm == NULL)
995 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
998 if (sta->wpa_sm == NULL) {
999 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1001 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1003 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1005 elems.mdie, elems.mdie_len);
1006 if (res == WPA_INVALID_GROUP)
1007 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1008 else if (res == WPA_INVALID_PAIRWISE)
1009 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1010 else if (res == WPA_INVALID_AKMP)
1011 resp = WLAN_STATUS_AKMP_NOT_VALID;
1012 else if (res == WPA_ALLOC_FAIL)
1013 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1014 #ifdef CONFIG_IEEE80211W
1015 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1016 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1017 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1018 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1019 #endif /* CONFIG_IEEE80211W */
1020 else if (res == WPA_INVALID_MDIE)
1021 resp = WLAN_STATUS_INVALID_MDIE;
1022 else if (res != WPA_IE_OK)
1023 resp = WLAN_STATUS_INVALID_IE;
1024 if (resp != WLAN_STATUS_SUCCESS)
1026 #ifdef CONFIG_IEEE80211W
1027 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1028 sta->sa_query_count > 0)
1029 ap_check_sa_query_timeout(hapd, sta);
1030 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1031 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1033 * STA has already been associated with MFP and SA
1034 * Query timeout has not been reached. Reject the
1035 * association attempt temporarily and start SA Query,
1036 * if one is not pending.
1039 if (sta->sa_query_count == 0)
1040 ap_sta_start_sa_query(hapd, sta);
1042 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1045 if (wpa_auth_uses_mfp(sta->wpa_sm))
1046 sta->flags |= WLAN_STA_MFP;
1048 sta->flags &= ~WLAN_STA_MFP;
1049 #endif /* CONFIG_IEEE80211W */
1051 #ifdef CONFIG_IEEE80211R
1052 if (sta->auth_alg == WLAN_AUTH_FT) {
1054 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1055 "to use association (not "
1056 "re-association) with FT auth_alg",
1057 MAC2STR(sta->addr));
1058 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1061 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1063 if (resp != WLAN_STATUS_SUCCESS)
1066 #endif /* CONFIG_IEEE80211R */
1069 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1070 sta->auth_alg != WLAN_AUTH_SAE) {
1071 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1072 "SAE AKM after non-SAE auth_alg %u",
1073 MAC2STR(sta->addr), sta->auth_alg);
1074 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1076 #endif /* CONFIG_SAE */
1078 #ifdef CONFIG_IEEE80211N
1079 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1080 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1081 hostapd_logger(hapd, sta->addr,
1082 HOSTAPD_MODULE_IEEE80211,
1084 "Station tried to use TKIP with HT "
1086 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1088 #endif /* CONFIG_IEEE80211N */
1090 wpa_auth_sta_no_wpa(sta->wpa_sm);
1093 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1094 #endif /* CONFIG_P2P */
1097 wpabuf_free(sta->hs20_ie);
1098 if (elems.hs20 && elems.hs20_len > 4) {
1099 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1100 elems.hs20_len - 4);
1102 sta->hs20_ie = NULL;
1103 #endif /* CONFIG_HS20 */
1105 return WLAN_STATUS_SUCCESS;
1109 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1113 struct ieee80211_mgmt reply;
1115 os_memset(&reply, 0, sizeof(reply));
1116 reply.frame_control =
1117 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1118 os_memcpy(reply.da, addr, ETH_ALEN);
1119 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1120 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1122 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1123 reply.u.deauth.reason_code = host_to_le16(reason_code);
1125 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1126 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1131 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1132 u16 status_code, int reassoc, const u8 *ies,
1136 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1137 struct ieee80211_mgmt *reply;
1140 os_memset(buf, 0, sizeof(buf));
1141 reply = (struct ieee80211_mgmt *) buf;
1142 reply->frame_control =
1143 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1144 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1145 WLAN_FC_STYPE_ASSOC_RESP));
1146 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1147 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1148 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1150 send_len = IEEE80211_HDRLEN;
1151 send_len += sizeof(reply->u.assoc_resp);
1152 reply->u.assoc_resp.capab_info =
1153 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1154 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1155 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1156 | BIT(14) | BIT(15));
1157 /* Supported rates */
1158 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1159 /* Extended supported rates */
1160 p = hostapd_eid_ext_supp_rates(hapd, p);
1162 #ifdef CONFIG_IEEE80211R
1163 if (status_code == WLAN_STATUS_SUCCESS) {
1164 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1165 * Transition Information, RSN, [RIC Response] */
1166 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1167 buf + sizeof(buf) - p,
1168 sta->auth_alg, ies, ies_len);
1170 #endif /* CONFIG_IEEE80211R */
1172 #ifdef CONFIG_IEEE80211W
1173 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1174 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1175 #endif /* CONFIG_IEEE80211W */
1177 #ifdef CONFIG_IEEE80211N
1178 p = hostapd_eid_ht_capabilities(hapd, p);
1179 p = hostapd_eid_ht_operation(hapd, p);
1180 #endif /* CONFIG_IEEE80211N */
1182 #ifdef CONFIG_IEEE80211AC
1183 p = hostapd_eid_vht_capabilities(hapd, p);
1184 p = hostapd_eid_vht_operation(hapd, p);
1185 #endif /* CONFIG_IEEE80211AC */
1187 p = hostapd_eid_ext_capab(hapd, p);
1188 p = hostapd_eid_bss_max_idle_period(hapd, p);
1189 if (sta->qos_map_enabled)
1190 p = hostapd_eid_qos_map_set(hapd, p);
1192 if (sta->flags & WLAN_STA_WMM)
1193 p = hostapd_eid_wmm(hapd, p);
1196 if ((sta->flags & WLAN_STA_WPS) ||
1197 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1198 struct wpabuf *wps = wps_build_assoc_resp_ie();
1200 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1201 p += wpabuf_len(wps);
1205 #endif /* CONFIG_WPS */
1209 struct wpabuf *p2p_resp_ie;
1210 enum p2p_status_code status;
1211 switch (status_code) {
1212 case WLAN_STATUS_SUCCESS:
1213 status = P2P_SC_SUCCESS;
1215 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1216 status = P2P_SC_FAIL_LIMIT_REACHED;
1219 status = P2P_SC_FAIL_INVALID_PARAMS;
1222 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1224 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1225 wpabuf_len(p2p_resp_ie));
1226 p += wpabuf_len(p2p_resp_ie);
1227 wpabuf_free(p2p_resp_ie);
1230 #endif /* CONFIG_P2P */
1232 #ifdef CONFIG_P2P_MANAGER
1233 if (hapd->conf->p2p & P2P_MANAGE)
1234 p = hostapd_eid_p2p_manage(hapd, p);
1235 #endif /* CONFIG_P2P_MANAGER */
1237 send_len += p - reply->u.assoc_resp.variable;
1239 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1240 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1245 static void handle_assoc(struct hostapd_data *hapd,
1246 const struct ieee80211_mgmt *mgmt, size_t len,
1249 u16 capab_info, listen_interval;
1250 u16 resp = WLAN_STATUS_SUCCESS;
1253 struct sta_info *sta;
1255 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1256 sizeof(mgmt->u.assoc_req))) {
1257 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1258 reassoc, (unsigned long) len);
1262 #ifdef CONFIG_TESTING_OPTIONS
1264 if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
1265 drand48() < hapd->iconf->ignore_reassoc_probability) {
1266 wpa_printf(MSG_INFO,
1267 "TESTING: ignoring reassoc request from "
1268 MACSTR, MAC2STR(mgmt->sa));
1272 if (hapd->iconf->ignore_assoc_probability > 0.0d &&
1273 drand48() < hapd->iconf->ignore_assoc_probability) {
1274 wpa_printf(MSG_INFO,
1275 "TESTING: ignoring assoc request from "
1276 MACSTR, MAC2STR(mgmt->sa));
1280 #endif /* CONFIG_TESTING_OPTIONS */
1283 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1284 listen_interval = le_to_host16(
1285 mgmt->u.reassoc_req.listen_interval);
1286 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1287 " capab_info=0x%02x listen_interval=%d current_ap="
1289 MAC2STR(mgmt->sa), capab_info, listen_interval,
1290 MAC2STR(mgmt->u.reassoc_req.current_ap));
1291 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1292 pos = mgmt->u.reassoc_req.variable;
1294 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1295 listen_interval = le_to_host16(
1296 mgmt->u.assoc_req.listen_interval);
1297 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1298 " capab_info=0x%02x listen_interval=%d",
1299 MAC2STR(mgmt->sa), capab_info, listen_interval);
1300 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1301 pos = mgmt->u.assoc_req.variable;
1304 sta = ap_get_sta(hapd, mgmt->sa);
1305 #ifdef CONFIG_IEEE80211R
1306 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1307 (sta->flags & WLAN_STA_AUTH) == 0) {
1308 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1309 "prior to authentication since it is using "
1310 "over-the-DS FT", MAC2STR(mgmt->sa));
1312 #endif /* CONFIG_IEEE80211R */
1313 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1314 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1315 HOSTAPD_LEVEL_INFO, "Station tried to "
1316 "associate before authentication "
1317 "(aid=%d flags=0x%x)",
1318 sta ? sta->aid : -1,
1319 sta ? sta->flags : 0);
1320 send_deauth(hapd, mgmt->sa,
1321 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1325 if (hapd->tkip_countermeasures) {
1326 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1330 if (listen_interval > hapd->conf->max_listen_interval) {
1331 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1332 HOSTAPD_LEVEL_DEBUG,
1333 "Too large Listen Interval (%d)",
1335 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1339 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1341 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1342 if (resp != WLAN_STATUS_SUCCESS)
1345 if (hostapd_get_aid(hapd, sta) < 0) {
1346 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1347 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1348 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1352 sta->capability = capab_info;
1353 sta->listen_interval = listen_interval;
1355 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1356 sta->flags |= WLAN_STA_NONERP;
1357 for (i = 0; i < sta->supported_rates_len; i++) {
1358 if ((sta->supported_rates[i] & 0x7f) > 22) {
1359 sta->flags &= ~WLAN_STA_NONERP;
1363 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1364 sta->nonerp_set = 1;
1365 hapd->iface->num_sta_non_erp++;
1366 if (hapd->iface->num_sta_non_erp == 1)
1367 ieee802_11_set_beacons(hapd->iface);
1370 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1371 !sta->no_short_slot_time_set) {
1372 sta->no_short_slot_time_set = 1;
1373 hapd->iface->num_sta_no_short_slot_time++;
1374 if (hapd->iface->current_mode->mode ==
1375 HOSTAPD_MODE_IEEE80211G &&
1376 hapd->iface->num_sta_no_short_slot_time == 1)
1377 ieee802_11_set_beacons(hapd->iface);
1380 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1381 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1383 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1385 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1386 !sta->no_short_preamble_set) {
1387 sta->no_short_preamble_set = 1;
1388 hapd->iface->num_sta_no_short_preamble++;
1389 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1390 && hapd->iface->num_sta_no_short_preamble == 1)
1391 ieee802_11_set_beacons(hapd->iface);
1394 #ifdef CONFIG_IEEE80211N
1395 update_ht_state(hapd, sta);
1396 #endif /* CONFIG_IEEE80211N */
1398 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1399 HOSTAPD_LEVEL_DEBUG,
1400 "association OK (aid %d)", sta->aid);
1401 /* Station will be marked associated, after it acknowledges AssocResp
1403 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1405 #ifdef CONFIG_IEEE80211W
1406 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1407 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1408 "SA Query procedure", reassoc ? "re" : "");
1409 /* TODO: Send a protected Disassociate frame to the STA using
1410 * the old key and Reason Code "Previous Authentication no
1411 * longer valid". Make sure this is only sent protected since
1412 * unprotected frame would be received by the STA that is now
1413 * trying to associate.
1416 #endif /* CONFIG_IEEE80211W */
1419 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1423 if (sta->last_assoc_req)
1424 os_free(sta->last_assoc_req);
1425 sta->last_assoc_req = os_malloc(len);
1426 if (sta->last_assoc_req)
1427 os_memcpy(sta->last_assoc_req, mgmt, len);
1429 /* Make sure that the previously registered inactivity timer will not
1430 * remove the STA immediately. */
1431 sta->timeout_next = STA_NULLFUNC;
1434 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1438 static void handle_disassoc(struct hostapd_data *hapd,
1439 const struct ieee80211_mgmt *mgmt, size_t len)
1441 struct sta_info *sta;
1443 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1444 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1445 (unsigned long) len);
1449 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1451 le_to_host16(mgmt->u.disassoc.reason_code));
1453 sta = ap_get_sta(hapd, mgmt->sa);
1455 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1460 ap_sta_set_authorized(hapd, sta, 0);
1461 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1462 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1463 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1464 HOSTAPD_LEVEL_INFO, "disassociated");
1465 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1466 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1467 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1469 accounting_sta_stop(hapd, sta);
1470 ieee802_1x_free_station(sta);
1471 hostapd_drv_sta_remove(hapd, sta->addr);
1473 if (sta->timeout_next == STA_NULLFUNC ||
1474 sta->timeout_next == STA_DISASSOC) {
1475 sta->timeout_next = STA_DEAUTH;
1476 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1477 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1481 mlme_disassociate_indication(
1482 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1486 static void handle_deauth(struct hostapd_data *hapd,
1487 const struct ieee80211_mgmt *mgmt, size_t len)
1489 struct sta_info *sta;
1491 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1492 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1493 "payload (len=%lu)", (unsigned long) len);
1497 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1499 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1501 sta = ap_get_sta(hapd, mgmt->sa);
1503 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1504 "to deauthenticate, but it is not authenticated",
1509 ap_sta_set_authorized(hapd, sta, 0);
1510 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1511 WLAN_STA_ASSOC_REQ_OK);
1512 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1513 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1514 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1515 mlme_deauthenticate_indication(
1516 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1517 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1518 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1519 ap_free_sta(hapd, sta);
1523 static void handle_beacon(struct hostapd_data *hapd,
1524 const struct ieee80211_mgmt *mgmt, size_t len,
1525 struct hostapd_frame_info *fi)
1527 struct ieee802_11_elems elems;
1529 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1530 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1531 (unsigned long) len);
1535 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1536 len - (IEEE80211_HDRLEN +
1537 sizeof(mgmt->u.beacon)), &elems,
1540 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1544 #ifdef CONFIG_IEEE80211W
1546 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1547 const struct ieee80211_mgmt *mgmt,
1552 end = mgmt->u.action.u.sa_query_resp.trans_id +
1553 WLAN_SA_QUERY_TR_ID_LEN;
1554 if (((u8 *) mgmt) + len < end) {
1555 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1556 "frame (len=%lu)", (unsigned long) len);
1560 ieee802_11_sa_query_action(hapd, mgmt->sa,
1561 mgmt->u.action.u.sa_query_resp.action,
1562 mgmt->u.action.u.sa_query_resp.trans_id);
1566 static int robust_action_frame(u8 category)
1568 return category != WLAN_ACTION_PUBLIC &&
1569 category != WLAN_ACTION_HT;
1571 #endif /* CONFIG_IEEE80211W */
1575 static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
1576 const struct ieee80211_mgmt *mgmt,
1579 struct rx_action action;
1580 if (len < IEEE80211_HDRLEN + 2)
1582 os_memset(&action, 0, sizeof(action));
1583 action.da = mgmt->da;
1584 action.sa = mgmt->sa;
1585 action.bssid = mgmt->bssid;
1586 action.category = mgmt->u.action.category;
1587 action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
1588 action.len = len - IEEE80211_HDRLEN - 1;
1589 action.freq = hapd->iface->freq;
1590 ieee802_11_rx_wnm_action_ap(hapd, &action);
1592 #endif /* CONFIG_WNM */
1595 static void handle_action(struct hostapd_data *hapd,
1596 const struct ieee80211_mgmt *mgmt, size_t len)
1598 struct sta_info *sta;
1599 sta = ap_get_sta(hapd, mgmt->sa);
1601 if (len < IEEE80211_HDRLEN + 1) {
1602 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1603 HOSTAPD_LEVEL_DEBUG,
1604 "handle_action - too short payload (len=%lu)",
1605 (unsigned long) len);
1609 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1610 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1611 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1612 "frame (category=%u) from unassociated STA " MACSTR,
1613 MAC2STR(mgmt->sa), mgmt->u.action.category);
1617 #ifdef CONFIG_IEEE80211W
1618 if (sta && (sta->flags & WLAN_STA_MFP) &&
1619 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1620 robust_action_frame(mgmt->u.action.category))) {
1621 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1622 HOSTAPD_LEVEL_DEBUG,
1623 "Dropped unprotected Robust Action frame from "
1627 #endif /* CONFIG_IEEE80211W */
1629 switch (mgmt->u.action.category) {
1630 #ifdef CONFIG_IEEE80211R
1631 case WLAN_ACTION_FT:
1632 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1633 len - IEEE80211_HDRLEN))
1636 #endif /* CONFIG_IEEE80211R */
1637 case WLAN_ACTION_WMM:
1638 hostapd_wmm_action(hapd, mgmt, len);
1640 #ifdef CONFIG_IEEE80211W
1641 case WLAN_ACTION_SA_QUERY:
1642 hostapd_sa_query_action(hapd, mgmt, len);
1644 #endif /* CONFIG_IEEE80211W */
1646 case WLAN_ACTION_WNM:
1647 hostapd_wnm_action(hapd, sta, mgmt, len);
1649 #endif /* CONFIG_WNM */
1650 case WLAN_ACTION_PUBLIC:
1651 if (hapd->public_action_cb) {
1652 hapd->public_action_cb(hapd->public_action_cb_ctx,
1656 if (hapd->public_action_cb2) {
1657 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1661 if (hapd->public_action_cb || hapd->public_action_cb2)
1664 case WLAN_ACTION_VENDOR_SPECIFIC:
1665 if (hapd->vendor_action_cb) {
1666 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1668 hapd->iface->freq) == 0)
1674 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1675 HOSTAPD_LEVEL_DEBUG,
1676 "handle_action - unknown action category %d or invalid "
1678 mgmt->u.action.category);
1679 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1680 !(mgmt->sa[0] & 0x01)) {
1681 struct ieee80211_mgmt *resp;
1684 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1685 * Return the Action frame to the source without change
1686 * except that MSB of the Category set to 1.
1688 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1689 "frame back to sender");
1690 resp = os_malloc(len);
1693 os_memcpy(resp, mgmt, len);
1694 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1695 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1696 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1697 resp->u.action.category |= 0x80;
1699 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1700 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1709 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1710 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1712 * @buf: management frame data (starting from IEEE 802.11 header)
1713 * @len: length of frame data in octets
1714 * @fi: meta data about received frame (signal level, etc.)
1716 * Process all incoming IEEE 802.11 management frames. This will be called for
1717 * each frame received from the kernel driver through wlan#ap interface. In
1718 * addition, it can be called to re-inserted pending frames (e.g., when using
1719 * external RADIUS server as an MAC ACL).
1721 void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1722 struct hostapd_frame_info *fi)
1724 struct ieee80211_mgmt *mgmt;
1728 #ifdef CONFIG_TESTING_OPTIONS
1729 if (hapd->ext_mgmt_frame_handling) {
1730 size_t hex_len = 2 * len + 1;
1731 char *hex = os_malloc(hex_len);
1733 wpa_snprintf_hex(hex, hex_len, buf, len);
1734 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1739 #endif /* CONFIG_TESTING_OPTIONS */
1744 mgmt = (struct ieee80211_mgmt *) buf;
1745 fc = le_to_host16(mgmt->frame_control);
1746 stype = WLAN_FC_GET_STYPE(fc);
1748 if (stype == WLAN_FC_STYPE_BEACON) {
1749 handle_beacon(hapd, mgmt, len, fi);
1753 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1754 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1755 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1759 /* Invitation responses can be sent with the peer MAC as BSSID */
1760 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1761 stype == WLAN_FC_STYPE_ACTION) &&
1762 #endif /* CONFIG_P2P */
1763 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1764 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
1765 MAC2STR(mgmt->bssid));
1770 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1771 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1775 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1776 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1777 HOSTAPD_LEVEL_DEBUG,
1778 "MGMT: DA=" MACSTR " not our address",
1784 case WLAN_FC_STYPE_AUTH:
1785 wpa_printf(MSG_DEBUG, "mgmt::auth");
1786 handle_auth(hapd, mgmt, len);
1788 case WLAN_FC_STYPE_ASSOC_REQ:
1789 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1790 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);
1796 case WLAN_FC_STYPE_DISASSOC:
1797 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1798 handle_disassoc(hapd, mgmt, len);
1800 case WLAN_FC_STYPE_DEAUTH:
1801 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1802 handle_deauth(hapd, mgmt, len);
1804 case WLAN_FC_STYPE_ACTION:
1805 wpa_printf(MSG_DEBUG, "mgmt::action");
1806 handle_action(hapd, mgmt, len);
1809 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1810 HOSTAPD_LEVEL_DEBUG,
1811 "unknown mgmt frame subtype %d", stype);
1817 static void handle_auth_cb(struct hostapd_data *hapd,
1818 const struct ieee80211_mgmt *mgmt,
1821 u16 auth_alg, auth_transaction, status_code;
1822 struct sta_info *sta;
1825 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1826 HOSTAPD_LEVEL_NOTICE,
1827 "did not acknowledge authentication response");
1831 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1832 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
1833 (unsigned long) len);
1837 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1838 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1839 status_code = le_to_host16(mgmt->u.auth.status_code);
1841 sta = ap_get_sta(hapd, mgmt->da);
1843 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
1848 if (status_code == WLAN_STATUS_SUCCESS &&
1849 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1850 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1851 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1852 HOSTAPD_LEVEL_INFO, "authenticated");
1853 sta->flags |= WLAN_STA_AUTH;
1858 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
1859 struct sta_info *sta,
1863 struct hostapd_ssid *ssid = sta->ssid;
1865 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
1868 for (i = 0; i < 4; i++) {
1869 if (ssid->wep.key[i] &&
1870 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
1871 i == ssid->wep.idx, NULL, 0,
1872 ssid->wep.key[i], ssid->wep.len[i])) {
1873 wpa_printf(MSG_WARNING,
1874 "Could not set WEP keys for WDS interface; %s",
1882 static void handle_assoc_cb(struct hostapd_data *hapd,
1883 const struct ieee80211_mgmt *mgmt,
1884 size_t len, int reassoc, int ok)
1887 struct sta_info *sta;
1889 struct ieee80211_ht_capabilities ht_cap;
1890 struct ieee80211_vht_capabilities vht_cap;
1892 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1893 sizeof(mgmt->u.assoc_resp))) {
1894 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
1895 reassoc, (unsigned long) len);
1899 sta = ap_get_sta(hapd, mgmt->da);
1901 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
1907 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1908 HOSTAPD_LEVEL_DEBUG,
1909 "did not acknowledge association response");
1910 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1915 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1917 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1919 if (status != WLAN_STATUS_SUCCESS)
1922 /* Stop previous accounting session, if one is started, and allocate
1923 * new session id for the new session. */
1924 accounting_sta_stop(hapd, sta);
1926 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1928 "associated (aid %d)",
1931 if (sta->flags & WLAN_STA_ASSOC)
1933 sta->flags |= WLAN_STA_ASSOC;
1934 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
1935 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1936 sta->auth_alg == WLAN_AUTH_FT) {
1938 * Open, static WEP, or FT protocol; no separate authorization
1941 ap_sta_set_authorized(hapd, sta, 1);
1945 mlme_reassociate_indication(hapd, sta);
1947 mlme_associate_indication(hapd, sta);
1949 #ifdef CONFIG_IEEE80211W
1950 sta->sa_query_timed_out = 0;
1951 #endif /* CONFIG_IEEE80211W */
1954 * Remove the STA entry in order to make sure the STA PS state gets
1955 * cleared and configuration gets updated in case of reassociation back
1958 hostapd_drv_sta_remove(hapd, sta->addr);
1960 #ifdef CONFIG_IEEE80211N
1961 if (sta->flags & WLAN_STA_HT)
1962 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1963 #endif /* CONFIG_IEEE80211N */
1964 #ifdef CONFIG_IEEE80211AC
1965 if (sta->flags & WLAN_STA_VHT)
1966 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1967 #endif /* CONFIG_IEEE80211AC */
1969 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1970 sta->supported_rates, sta->supported_rates_len,
1971 sta->listen_interval,
1972 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1973 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1974 sta->flags, sta->qosinfo)) {
1975 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1976 HOSTAPD_LEVEL_NOTICE,
1977 "Could not add STA to kernel driver");
1979 ap_sta_disconnect(hapd, sta, sta->addr,
1980 WLAN_REASON_DISASSOC_AP_BUSY);
1985 if (sta->flags & WLAN_STA_WDS) {
1987 char ifname_wds[IFNAMSIZ + 1];
1989 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
1992 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
1995 if (sta->eapol_sm == NULL) {
1997 * This STA does not use RADIUS server for EAP authentication,
1998 * so bind it to the selected VLAN interface now, since the
1999 * interface selection is not going to change anymore.
2001 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2003 } else if (sta->vlan_id) {
2004 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2005 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
2009 hostapd_set_sta_flags(hapd, sta);
2011 if (sta->auth_alg == WLAN_AUTH_FT)
2012 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2014 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2015 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2017 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2020 /* Copy of the association request is not needed anymore */
2021 if (sta->last_assoc_req) {
2022 os_free(sta->last_assoc_req);
2023 sta->last_assoc_req = NULL;
2028 static void handle_deauth_cb(struct hostapd_data *hapd,
2029 const struct ieee80211_mgmt *mgmt,
2032 struct sta_info *sta;
2033 if (mgmt->da[0] & 0x01)
2035 sta = ap_get_sta(hapd, mgmt->da);
2037 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2038 " not found", MAC2STR(mgmt->da));
2042 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2043 MAC2STR(sta->addr));
2045 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2046 "deauth", MAC2STR(sta->addr));
2048 ap_sta_deauth_cb(hapd, sta);
2052 static void handle_disassoc_cb(struct hostapd_data *hapd,
2053 const struct ieee80211_mgmt *mgmt,
2056 struct sta_info *sta;
2057 if (mgmt->da[0] & 0x01)
2059 sta = ap_get_sta(hapd, mgmt->da);
2061 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2062 " not found", MAC2STR(mgmt->da));
2066 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2067 MAC2STR(sta->addr));
2069 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2070 "disassoc", MAC2STR(sta->addr));
2072 ap_sta_disassoc_cb(hapd, sta);
2077 * ieee802_11_mgmt_cb - Process management frame TX status callback
2078 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2080 * @buf: management frame data (starting from IEEE 802.11 header)
2081 * @len: length of frame data in octets
2082 * @stype: management frame subtype from frame control field
2083 * @ok: Whether the frame was ACK'ed
2085 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2088 const struct ieee80211_mgmt *mgmt;
2089 mgmt = (const struct ieee80211_mgmt *) buf;
2091 #ifdef CONFIG_TESTING_OPTIONS
2092 if (hapd->ext_mgmt_frame_handling) {
2093 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2097 #endif /* CONFIG_TESTING_OPTIONS */
2100 case WLAN_FC_STYPE_AUTH:
2101 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2102 handle_auth_cb(hapd, mgmt, len, ok);
2104 case WLAN_FC_STYPE_ASSOC_RESP:
2105 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2106 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2108 case WLAN_FC_STYPE_REASSOC_RESP:
2109 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2110 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2112 case WLAN_FC_STYPE_PROBE_RESP:
2113 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2115 case WLAN_FC_STYPE_DEAUTH:
2116 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2117 handle_deauth_cb(hapd, mgmt, len, ok);
2119 case WLAN_FC_STYPE_DISASSOC:
2120 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2121 handle_disassoc_cb(hapd, mgmt, len, ok);
2123 case WLAN_FC_STYPE_ACTION:
2124 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2127 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2133 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2140 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2141 char *buf, size_t buflen)
2148 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2149 const u8 *buf, size_t len, int ack)
2151 struct sta_info *sta;
2152 struct hostapd_iface *iface = hapd->iface;
2154 sta = ap_get_sta(hapd, addr);
2155 if (sta == NULL && iface->num_bss > 1) {
2157 for (j = 0; j < iface->num_bss; j++) {
2158 hapd = iface->bss[j];
2159 sta = ap_get_sta(hapd, addr);
2164 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2166 if (sta->flags & WLAN_STA_PENDING_POLL) {
2167 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2168 "activity poll", MAC2STR(sta->addr),
2169 ack ? "ACKed" : "did not ACK");
2171 sta->flags &= ~WLAN_STA_PENDING_POLL;
2174 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2178 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2179 const u8 *data, size_t len, int ack)
2181 struct sta_info *sta;
2182 struct hostapd_iface *iface = hapd->iface;
2184 sta = ap_get_sta(hapd, dst);
2185 if (sta == NULL && iface->num_bss > 1) {
2187 for (j = 0; j < iface->num_bss; j++) {
2188 hapd = iface->bss[j];
2189 sta = ap_get_sta(hapd, dst);
2194 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2195 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2196 MACSTR " that is not currently associated",
2201 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2205 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2207 struct sta_info *sta;
2208 struct hostapd_iface *iface = hapd->iface;
2210 sta = ap_get_sta(hapd, addr);
2211 if (sta == NULL && iface->num_bss > 1) {
2213 for (j = 0; j < iface->num_bss; j++) {
2214 hapd = iface->bss[j];
2215 sta = ap_get_sta(hapd, addr);
2222 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2225 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2226 "activity poll", MAC2STR(sta->addr));
2227 sta->flags &= ~WLAN_STA_PENDING_POLL;
2231 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2234 struct sta_info *sta;
2236 sta = ap_get_sta(hapd, src);
2237 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2238 if (!hapd->conf->wds_sta)
2241 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2243 char ifname_wds[IFNAMSIZ + 1];
2245 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2246 "STA " MACSTR " (aid %u)",
2247 MAC2STR(sta->addr), sta->aid);
2248 sta->flags |= WLAN_STA_WDS;
2249 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2250 sta->addr, sta->aid, 1);
2252 hostapd_set_wds_encryption(hapd, sta,
2258 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2259 MACSTR, MAC2STR(src));
2260 if (src[0] & 0x01) {
2261 /* Broadcast bit set in SA?! Ignore the frame silently. */
2265 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2266 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2267 "already been sent, but no TX status yet known - "
2268 "ignore Class 3 frame issue with " MACSTR,
2273 if (sta && (sta->flags & WLAN_STA_AUTH))
2274 hostapd_drv_sta_disassoc(
2276 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2278 hostapd_drv_sta_deauth(
2280 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2284 #endif /* CONFIG_NATIVE_WINDOWS */