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 sta->flags |= WLAN_STA_AUTH;
242 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
243 os_free(sta->challenge);
244 sta->challenge = NULL;
250 static void send_auth_reply(struct hostapd_data *hapd,
251 const u8 *dst, const u8 *bssid,
252 u16 auth_alg, u16 auth_transaction, u16 resp,
253 const u8 *ies, size_t ies_len)
255 struct ieee80211_mgmt *reply;
259 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
260 buf = os_zalloc(rlen);
264 reply = (struct ieee80211_mgmt *) buf;
265 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
267 os_memcpy(reply->da, dst, ETH_ALEN);
268 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
269 os_memcpy(reply->bssid, bssid, ETH_ALEN);
271 reply->u.auth.auth_alg = host_to_le16(auth_alg);
272 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
273 reply->u.auth.status_code = host_to_le16(resp);
276 os_memcpy(reply->u.auth.variable, ies, ies_len);
278 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
279 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
280 MAC2STR(dst), auth_alg, auth_transaction,
281 resp, (unsigned long) ies_len);
282 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
283 wpa_printf(MSG_INFO, "send_auth_reply: send");
289 #ifdef CONFIG_IEEE80211R
290 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
291 u16 auth_transaction, u16 status,
292 const u8 *ies, size_t ies_len)
294 struct hostapd_data *hapd = ctx;
295 struct sta_info *sta;
297 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
298 status, ies, ies_len);
300 if (status != WLAN_STATUS_SUCCESS)
303 sta = ap_get_sta(hapd, dst);
307 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
308 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
309 sta->flags |= WLAN_STA_AUTH;
310 mlme_authenticate_indication(hapd, sta);
312 #endif /* CONFIG_IEEE80211R */
317 static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
318 struct sta_info *sta)
322 if (hapd->conf->ssid.wpa_passphrase == NULL) {
323 wpa_printf(MSG_DEBUG, "SAE: No password available");
327 if (sae_prepare_commit(hapd->own_addr, sta->addr,
328 (u8 *) hapd->conf->ssid.wpa_passphrase,
329 os_strlen(hapd->conf->ssid.wpa_passphrase),
331 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
335 if (sae_process_commit(sta->sae) < 0) {
336 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
340 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
343 sae_write_commit(sta->sae, buf, NULL);
349 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
350 struct sta_info *sta)
354 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
358 sae_write_confirm(sta->sae, buf);
364 static int use_sae_anti_clogging(struct hostapd_data *hapd)
366 struct sta_info *sta;
367 unsigned int open = 0;
369 if (hapd->conf->sae_anti_clogging_threshold == 0)
372 for (sta = hapd->sta_list; sta; sta = sta->next) {
375 if (sta->sae->state != SAE_COMMITTED &&
376 sta->sae->state != SAE_CONFIRMED)
379 if (open >= hapd->conf->sae_anti_clogging_threshold)
387 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
388 const u8 *token, size_t token_len)
390 u8 mac[SHA256_MAC_LEN];
392 if (token_len != SHA256_MAC_LEN)
394 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
395 addr, ETH_ALEN, mac) < 0 ||
396 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
403 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
408 struct os_reltime now;
410 os_get_reltime(&now);
411 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
412 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
413 if (random_get_bytes(hapd->sae_token_key,
414 sizeof(hapd->sae_token_key)) < 0)
416 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
417 hapd->sae_token_key, sizeof(hapd->sae_token_key));
418 hapd->last_sae_token_key_update = now;
421 buf = wpabuf_alloc(SHA256_MAC_LEN);
425 token = wpabuf_put(buf, SHA256_MAC_LEN);
426 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
427 addr, ETH_ALEN, token);
433 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
434 const struct ieee80211_mgmt *mgmt, size_t len,
437 u16 resp = WLAN_STATUS_SUCCESS;
438 struct wpabuf *data = NULL;
441 if (auth_transaction != 1)
443 sta->sae = os_zalloc(sizeof(*sta->sae));
444 if (sta->sae == NULL)
446 sta->sae->state = SAE_NOTHING;
449 if (auth_transaction == 1) {
450 const u8 *token = NULL;
451 size_t token_len = 0;
452 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
454 "start SAE authentication (RX commit)");
455 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
456 ((const u8 *) mgmt) + len -
457 mgmt->u.auth.variable, &token,
458 &token_len, hapd->conf->sae_groups);
459 if (token && check_sae_token(hapd, sta->addr, token, token_len)
461 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
462 "incorrect token from " MACSTR,
467 if (resp == WLAN_STATUS_SUCCESS) {
468 if (!token && use_sae_anti_clogging(hapd)) {
469 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
470 "clogging token from " MACSTR,
472 data = auth_build_token_req(hapd, sta->addr);
473 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
475 data = auth_process_sae_commit(hapd, sta);
477 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
479 sta->sae->state = SAE_COMMITTED;
482 } else if (auth_transaction == 2) {
483 if (sta->sae->state != SAE_COMMITTED) {
484 hostapd_logger(hapd, sta->addr,
485 HOSTAPD_MODULE_IEEE80211,
487 "SAE confirm before commit");
488 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
490 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
492 "SAE authentication (RX confirm)");
493 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
494 ((u8 *) mgmt) + len -
495 mgmt->u.auth.variable) < 0) {
496 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
498 resp = WLAN_STATUS_SUCCESS;
499 sta->flags |= WLAN_STA_AUTH;
500 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
501 sta->auth_alg = WLAN_AUTH_SAE;
502 mlme_authenticate_indication(hapd, sta);
504 data = auth_build_sae_confirm(hapd, sta);
506 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
508 sta->sae->state = SAE_ACCEPTED;
509 sae_clear_temp_data(sta->sae);
513 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
515 "unexpected SAE authentication transaction %u",
517 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
520 sta->auth_alg = WLAN_AUTH_SAE;
522 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
523 auth_transaction, resp,
524 data ? wpabuf_head(data) : (u8 *) "",
525 data ? wpabuf_len(data) : 0);
528 #endif /* CONFIG_SAE */
531 static void handle_auth(struct hostapd_data *hapd,
532 const struct ieee80211_mgmt *mgmt, size_t len)
534 u16 auth_alg, auth_transaction, status_code;
535 u16 resp = WLAN_STATUS_SUCCESS;
536 struct sta_info *sta = NULL;
539 const u8 *challenge = NULL;
540 u32 session_timeout, acct_interim_interval;
542 struct hostapd_sta_wpa_psk_short *psk = NULL;
543 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
544 size_t resp_ies_len = 0;
545 char *identity = NULL;
546 char *radius_cui = NULL;
548 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
549 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
550 (unsigned long) len);
554 #ifdef CONFIG_TESTING_OPTIONS
555 if (hapd->iconf->ignore_auth_probability > 0.0d &&
556 drand48() < hapd->iconf->ignore_auth_probability) {
558 "TESTING: ignoring auth frame from " MACSTR,
562 #endif /* CONFIG_TESTING_OPTIONS */
564 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
565 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
566 status_code = le_to_host16(mgmt->u.auth.status_code);
567 fc = le_to_host16(mgmt->frame_control);
569 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
570 2 + WLAN_AUTH_CHALLENGE_LEN &&
571 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
572 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
573 challenge = &mgmt->u.auth.variable[2];
575 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
576 "auth_transaction=%d status_code=%d wep=%d%s",
577 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
578 status_code, !!(fc & WLAN_FC_ISWEP),
579 challenge ? " challenge" : "");
581 if (hapd->tkip_countermeasures) {
582 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
586 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
587 auth_alg == WLAN_AUTH_OPEN) ||
588 #ifdef CONFIG_IEEE80211R
589 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
590 auth_alg == WLAN_AUTH_FT) ||
591 #endif /* CONFIG_IEEE80211R */
593 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
594 auth_alg == WLAN_AUTH_SAE) ||
595 #endif /* CONFIG_SAE */
596 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
597 auth_alg == WLAN_AUTH_SHARED_KEY))) {
598 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
600 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
604 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
605 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
606 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
608 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
612 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
613 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
615 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
619 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
621 &acct_interim_interval, &vlan_id,
622 &psk, &identity, &radius_cui);
624 if (res == HOSTAPD_ACL_REJECT) {
625 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
627 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
630 if (res == HOSTAPD_ACL_PENDING) {
631 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
632 " waiting for an external authentication",
634 /* Authentication code will re-send the authentication frame
635 * after it has received (and cached) information from the
636 * external source. */
640 sta = ap_sta_add(hapd, mgmt->sa);
642 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
647 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
648 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
649 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
650 "%d received from RADIUS server",
652 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
655 sta->vlan_id = vlan_id;
656 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
657 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
660 hostapd_free_psk_list(sta->psk);
661 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
668 sta->identity = identity;
670 sta->radius_cui = radius_cui;
673 sta->flags &= ~WLAN_STA_PREAUTH;
674 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
676 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
677 sta->acct_interim_interval = acct_interim_interval;
678 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
679 ap_sta_session_timeout(hapd, sta, session_timeout);
681 ap_sta_no_session_timeout(hapd, sta);
685 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
687 "authentication OK (open system)");
688 sta->flags |= WLAN_STA_AUTH;
689 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
690 sta->auth_alg = WLAN_AUTH_OPEN;
691 mlme_authenticate_indication(hapd, sta);
693 case WLAN_AUTH_SHARED_KEY:
694 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
696 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
697 mlme_authenticate_indication(hapd, sta);
698 if (sta->challenge && auth_transaction == 1) {
699 resp_ies[0] = WLAN_EID_CHALLENGE;
700 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
701 os_memcpy(resp_ies + 2, sta->challenge,
702 WLAN_AUTH_CHALLENGE_LEN);
703 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
706 #ifdef CONFIG_IEEE80211R
708 sta->auth_alg = WLAN_AUTH_FT;
709 if (sta->wpa_sm == NULL)
710 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
712 if (sta->wpa_sm == NULL) {
713 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
715 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
718 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
719 auth_transaction, mgmt->u.auth.variable,
720 len - IEEE80211_HDRLEN -
721 sizeof(mgmt->u.auth),
722 handle_auth_ft_finish, hapd);
723 /* handle_auth_ft_finish() callback will complete auth. */
725 #endif /* CONFIG_IEEE80211R */
728 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
730 #endif /* CONFIG_SAE */
736 hostapd_free_psk_list(psk);
738 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
739 auth_transaction + 1, resp, resp_ies, resp_ies_len);
743 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
747 /* get a unique AID */
749 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
753 for (i = 0; i < AID_WORDS; i++) {
754 if (hapd->sta_aid[i] == (u32) -1)
756 for (j = 0; j < 32; j++) {
757 if (!(hapd->sta_aid[i] & BIT(j)))
765 aid = i * 32 + j + 1;
770 hapd->sta_aid[i] |= BIT(j);
771 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
776 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
777 const u8 *ssid_ie, size_t ssid_ie_len)
780 return WLAN_STATUS_UNSPECIFIED_FAILURE;
782 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
783 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
785 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
786 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
788 "Station tried to associate with unknown SSID "
790 return WLAN_STATUS_UNSPECIFIED_FAILURE;
793 return WLAN_STATUS_SUCCESS;
797 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
798 const u8 *wmm_ie, size_t wmm_ie_len)
800 sta->flags &= ~WLAN_STA_WMM;
802 if (wmm_ie && hapd->conf->wmm_enabled) {
803 struct wmm_information_element *wmm;
805 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
806 hostapd_logger(hapd, sta->addr,
809 "invalid WMM element in association "
811 return WLAN_STATUS_UNSPECIFIED_FAILURE;
814 sta->flags |= WLAN_STA_WMM;
815 wmm = (struct wmm_information_element *) wmm_ie;
816 sta->qosinfo = wmm->qos_info;
818 return WLAN_STATUS_SUCCESS;
822 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
823 struct ieee802_11_elems *elems)
825 if (!elems->supp_rates) {
826 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
828 "No supported rates element in AssocReq");
829 return WLAN_STATUS_UNSPECIFIED_FAILURE;
832 if (elems->supp_rates_len + elems->ext_supp_rates_len >
833 sizeof(sta->supported_rates)) {
834 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
836 "Invalid supported rates element length %d+%d",
837 elems->supp_rates_len,
838 elems->ext_supp_rates_len);
839 return WLAN_STATUS_UNSPECIFIED_FAILURE;
842 sta->supported_rates_len = merge_byte_arrays(
843 sta->supported_rates, sizeof(sta->supported_rates),
844 elems->supp_rates, elems->supp_rates_len,
845 elems->ext_supp_rates, elems->ext_supp_rates_len);
847 return WLAN_STATUS_SUCCESS;
851 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
852 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
854 #ifdef CONFIG_INTERWORKING
855 /* check for QoS Map support */
856 if (ext_capab_ie_len >= 5) {
857 if (ext_capab_ie[4] & 0x01)
858 sta->qos_map_enabled = 1;
860 #endif /* CONFIG_INTERWORKING */
862 return WLAN_STATUS_SUCCESS;
866 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
867 const u8 *ies, size_t ies_len, int reassoc)
869 struct ieee802_11_elems elems;
873 const u8 *p2p_dev_addr = NULL;
875 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
876 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
877 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
878 "association request");
879 return WLAN_STATUS_UNSPECIFIED_FAILURE;
882 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
883 if (resp != WLAN_STATUS_SUCCESS)
885 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
886 if (resp != WLAN_STATUS_SUCCESS)
888 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
889 if (resp != WLAN_STATUS_SUCCESS)
891 resp = copy_supp_rates(hapd, sta, &elems);
892 if (resp != WLAN_STATUS_SUCCESS)
894 #ifdef CONFIG_IEEE80211N
895 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
896 elems.ht_capabilities_len);
897 if (resp != WLAN_STATUS_SUCCESS)
899 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
900 !(sta->flags & WLAN_STA_HT)) {
901 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
902 HOSTAPD_LEVEL_INFO, "Station does not support "
903 "mandatory HT PHY - reject association");
904 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
906 #endif /* CONFIG_IEEE80211N */
908 #ifdef CONFIG_IEEE80211AC
909 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
910 elems.vht_capabilities_len);
911 if (resp != WLAN_STATUS_SUCCESS)
913 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
914 !(sta->flags & WLAN_STA_VHT)) {
915 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
916 HOSTAPD_LEVEL_INFO, "Station does not support "
917 "mandatory VHT PHY - reject association");
918 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
920 #endif /* CONFIG_IEEE80211AC */
924 wpabuf_free(sta->p2p_ie);
925 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
928 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
930 wpabuf_free(sta->p2p_ie);
933 #endif /* CONFIG_P2P */
935 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
936 wpa_ie = elems.rsn_ie;
937 wpa_ie_len = elems.rsn_ie_len;
938 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
940 wpa_ie = elems.wpa_ie;
941 wpa_ie_len = elems.wpa_ie_len;
948 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
949 if (hapd->conf->wps_state && elems.wps_ie) {
950 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
951 "Request - assume WPS is used");
952 sta->flags |= WLAN_STA_WPS;
953 wpabuf_free(sta->wps_ie);
954 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
956 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
957 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
958 sta->flags |= WLAN_STA_WPS2;
962 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
963 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
964 "(Re)Association Request - reject");
965 return WLAN_STATUS_INVALID_IE;
967 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
968 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
969 "(Re)Association Request - possible WPS use");
970 sta->flags |= WLAN_STA_MAYBE_WPS;
972 #endif /* CONFIG_WPS */
973 if (hapd->conf->wpa && wpa_ie == NULL) {
974 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
976 "No WPA/RSN IE in association request");
977 return WLAN_STATUS_INVALID_IE;
980 if (hapd->conf->wpa && wpa_ie) {
984 if (sta->wpa_sm == NULL)
985 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
988 if (sta->wpa_sm == NULL) {
989 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
991 return WLAN_STATUS_UNSPECIFIED_FAILURE;
993 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
995 elems.mdie, elems.mdie_len);
996 if (res == WPA_INVALID_GROUP)
997 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
998 else if (res == WPA_INVALID_PAIRWISE)
999 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1000 else if (res == WPA_INVALID_AKMP)
1001 resp = WLAN_STATUS_AKMP_NOT_VALID;
1002 else if (res == WPA_ALLOC_FAIL)
1003 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1004 #ifdef CONFIG_IEEE80211W
1005 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1006 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1007 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1008 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1009 #endif /* CONFIG_IEEE80211W */
1010 else if (res == WPA_INVALID_MDIE)
1011 resp = WLAN_STATUS_INVALID_MDIE;
1012 else if (res != WPA_IE_OK)
1013 resp = WLAN_STATUS_INVALID_IE;
1014 if (resp != WLAN_STATUS_SUCCESS)
1016 #ifdef CONFIG_IEEE80211W
1017 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1018 sta->sa_query_count > 0)
1019 ap_check_sa_query_timeout(hapd, sta);
1020 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1021 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1023 * STA has already been associated with MFP and SA
1024 * Query timeout has not been reached. Reject the
1025 * association attempt temporarily and start SA Query,
1026 * if one is not pending.
1029 if (sta->sa_query_count == 0)
1030 ap_sta_start_sa_query(hapd, sta);
1032 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1035 if (wpa_auth_uses_mfp(sta->wpa_sm))
1036 sta->flags |= WLAN_STA_MFP;
1038 sta->flags &= ~WLAN_STA_MFP;
1039 #endif /* CONFIG_IEEE80211W */
1041 #ifdef CONFIG_IEEE80211R
1042 if (sta->auth_alg == WLAN_AUTH_FT) {
1044 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1045 "to use association (not "
1046 "re-association) with FT auth_alg",
1047 MAC2STR(sta->addr));
1048 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1051 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1053 if (resp != WLAN_STATUS_SUCCESS)
1056 #endif /* CONFIG_IEEE80211R */
1059 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1060 sta->auth_alg != WLAN_AUTH_SAE &&
1061 !(sta->auth_alg == WLAN_AUTH_FT &&
1062 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
1063 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1064 "SAE AKM after non-SAE auth_alg %u",
1065 MAC2STR(sta->addr), sta->auth_alg);
1066 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1068 #endif /* CONFIG_SAE */
1070 #ifdef CONFIG_IEEE80211N
1071 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1072 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1073 hostapd_logger(hapd, sta->addr,
1074 HOSTAPD_MODULE_IEEE80211,
1076 "Station tried to use TKIP with HT "
1078 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1080 #endif /* CONFIG_IEEE80211N */
1082 wpa_auth_sta_no_wpa(sta->wpa_sm);
1085 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1086 #endif /* CONFIG_P2P */
1089 wpabuf_free(sta->hs20_ie);
1090 if (elems.hs20 && elems.hs20_len > 4) {
1091 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1092 elems.hs20_len - 4);
1094 sta->hs20_ie = NULL;
1095 #endif /* CONFIG_HS20 */
1097 return WLAN_STATUS_SUCCESS;
1101 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1105 struct ieee80211_mgmt reply;
1107 os_memset(&reply, 0, sizeof(reply));
1108 reply.frame_control =
1109 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1110 os_memcpy(reply.da, addr, ETH_ALEN);
1111 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1112 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1114 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1115 reply.u.deauth.reason_code = host_to_le16(reason_code);
1117 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1118 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1123 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1124 u16 status_code, int reassoc, const u8 *ies,
1128 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1129 struct ieee80211_mgmt *reply;
1132 os_memset(buf, 0, sizeof(buf));
1133 reply = (struct ieee80211_mgmt *) buf;
1134 reply->frame_control =
1135 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1136 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1137 WLAN_FC_STYPE_ASSOC_RESP));
1138 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1139 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1140 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1142 send_len = IEEE80211_HDRLEN;
1143 send_len += sizeof(reply->u.assoc_resp);
1144 reply->u.assoc_resp.capab_info =
1145 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1146 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1147 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1148 | BIT(14) | BIT(15));
1149 /* Supported rates */
1150 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1151 /* Extended supported rates */
1152 p = hostapd_eid_ext_supp_rates(hapd, p);
1154 #ifdef CONFIG_IEEE80211R
1155 if (status_code == WLAN_STATUS_SUCCESS) {
1156 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1157 * Transition Information, RSN, [RIC Response] */
1158 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1159 buf + sizeof(buf) - p,
1160 sta->auth_alg, ies, ies_len);
1162 #endif /* CONFIG_IEEE80211R */
1164 #ifdef CONFIG_IEEE80211W
1165 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1166 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1167 #endif /* CONFIG_IEEE80211W */
1169 #ifdef CONFIG_IEEE80211N
1170 p = hostapd_eid_ht_capabilities(hapd, p);
1171 p = hostapd_eid_ht_operation(hapd, p);
1172 #endif /* CONFIG_IEEE80211N */
1174 #ifdef CONFIG_IEEE80211AC
1175 p = hostapd_eid_vht_capabilities(hapd, p);
1176 p = hostapd_eid_vht_operation(hapd, p);
1177 #endif /* CONFIG_IEEE80211AC */
1179 p = hostapd_eid_ext_capab(hapd, p);
1180 p = hostapd_eid_bss_max_idle_period(hapd, p);
1181 if (sta->qos_map_enabled)
1182 p = hostapd_eid_qos_map_set(hapd, p);
1184 if (sta->flags & WLAN_STA_WMM)
1185 p = hostapd_eid_wmm(hapd, p);
1188 if ((sta->flags & WLAN_STA_WPS) ||
1189 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1190 struct wpabuf *wps = wps_build_assoc_resp_ie();
1192 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1193 p += wpabuf_len(wps);
1197 #endif /* CONFIG_WPS */
1201 struct wpabuf *p2p_resp_ie;
1202 enum p2p_status_code status;
1203 switch (status_code) {
1204 case WLAN_STATUS_SUCCESS:
1205 status = P2P_SC_SUCCESS;
1207 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1208 status = P2P_SC_FAIL_LIMIT_REACHED;
1211 status = P2P_SC_FAIL_INVALID_PARAMS;
1214 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1216 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1217 wpabuf_len(p2p_resp_ie));
1218 p += wpabuf_len(p2p_resp_ie);
1219 wpabuf_free(p2p_resp_ie);
1222 #endif /* CONFIG_P2P */
1224 #ifdef CONFIG_P2P_MANAGER
1225 if (hapd->conf->p2p & P2P_MANAGE)
1226 p = hostapd_eid_p2p_manage(hapd, p);
1227 #endif /* CONFIG_P2P_MANAGER */
1229 send_len += p - reply->u.assoc_resp.variable;
1231 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1232 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1237 static void handle_assoc(struct hostapd_data *hapd,
1238 const struct ieee80211_mgmt *mgmt, size_t len,
1241 u16 capab_info, listen_interval;
1242 u16 resp = WLAN_STATUS_SUCCESS;
1245 struct sta_info *sta;
1247 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1248 sizeof(mgmt->u.assoc_req))) {
1249 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1250 reassoc, (unsigned long) len);
1254 #ifdef CONFIG_TESTING_OPTIONS
1256 if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
1257 drand48() < hapd->iconf->ignore_reassoc_probability) {
1258 wpa_printf(MSG_INFO,
1259 "TESTING: ignoring reassoc request from "
1260 MACSTR, MAC2STR(mgmt->sa));
1264 if (hapd->iconf->ignore_assoc_probability > 0.0d &&
1265 drand48() < hapd->iconf->ignore_assoc_probability) {
1266 wpa_printf(MSG_INFO,
1267 "TESTING: ignoring assoc request from "
1268 MACSTR, MAC2STR(mgmt->sa));
1272 #endif /* CONFIG_TESTING_OPTIONS */
1275 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1276 listen_interval = le_to_host16(
1277 mgmt->u.reassoc_req.listen_interval);
1278 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1279 " capab_info=0x%02x listen_interval=%d current_ap="
1281 MAC2STR(mgmt->sa), capab_info, listen_interval,
1282 MAC2STR(mgmt->u.reassoc_req.current_ap));
1283 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1284 pos = mgmt->u.reassoc_req.variable;
1286 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1287 listen_interval = le_to_host16(
1288 mgmt->u.assoc_req.listen_interval);
1289 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1290 " capab_info=0x%02x listen_interval=%d",
1291 MAC2STR(mgmt->sa), capab_info, listen_interval);
1292 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1293 pos = mgmt->u.assoc_req.variable;
1296 sta = ap_get_sta(hapd, mgmt->sa);
1297 #ifdef CONFIG_IEEE80211R
1298 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1299 (sta->flags & WLAN_STA_AUTH) == 0) {
1300 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1301 "prior to authentication since it is using "
1302 "over-the-DS FT", MAC2STR(mgmt->sa));
1304 #endif /* CONFIG_IEEE80211R */
1305 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1306 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1307 HOSTAPD_LEVEL_INFO, "Station tried to "
1308 "associate before authentication "
1309 "(aid=%d flags=0x%x)",
1310 sta ? sta->aid : -1,
1311 sta ? sta->flags : 0);
1312 send_deauth(hapd, mgmt->sa,
1313 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1317 if (hapd->tkip_countermeasures) {
1318 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1322 if (listen_interval > hapd->conf->max_listen_interval) {
1323 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1324 HOSTAPD_LEVEL_DEBUG,
1325 "Too large Listen Interval (%d)",
1327 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1331 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1333 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1334 if (resp != WLAN_STATUS_SUCCESS)
1337 if (hostapd_get_aid(hapd, sta) < 0) {
1338 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1339 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1340 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1344 sta->capability = capab_info;
1345 sta->listen_interval = listen_interval;
1347 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1348 sta->flags |= WLAN_STA_NONERP;
1349 for (i = 0; i < sta->supported_rates_len; i++) {
1350 if ((sta->supported_rates[i] & 0x7f) > 22) {
1351 sta->flags &= ~WLAN_STA_NONERP;
1355 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1356 sta->nonerp_set = 1;
1357 hapd->iface->num_sta_non_erp++;
1358 if (hapd->iface->num_sta_non_erp == 1)
1359 ieee802_11_set_beacons(hapd->iface);
1362 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1363 !sta->no_short_slot_time_set) {
1364 sta->no_short_slot_time_set = 1;
1365 hapd->iface->num_sta_no_short_slot_time++;
1366 if (hapd->iface->current_mode->mode ==
1367 HOSTAPD_MODE_IEEE80211G &&
1368 hapd->iface->num_sta_no_short_slot_time == 1)
1369 ieee802_11_set_beacons(hapd->iface);
1372 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1373 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1375 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1377 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1378 !sta->no_short_preamble_set) {
1379 sta->no_short_preamble_set = 1;
1380 hapd->iface->num_sta_no_short_preamble++;
1381 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1382 && hapd->iface->num_sta_no_short_preamble == 1)
1383 ieee802_11_set_beacons(hapd->iface);
1386 #ifdef CONFIG_IEEE80211N
1387 update_ht_state(hapd, sta);
1388 #endif /* CONFIG_IEEE80211N */
1390 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1391 HOSTAPD_LEVEL_DEBUG,
1392 "association OK (aid %d)", sta->aid);
1393 /* Station will be marked associated, after it acknowledges AssocResp
1395 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1397 #ifdef CONFIG_IEEE80211W
1398 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1399 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1400 "SA Query procedure", reassoc ? "re" : "");
1401 /* TODO: Send a protected Disassociate frame to the STA using
1402 * the old key and Reason Code "Previous Authentication no
1403 * longer valid". Make sure this is only sent protected since
1404 * unprotected frame would be received by the STA that is now
1405 * trying to associate.
1408 #endif /* CONFIG_IEEE80211W */
1411 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1415 if (sta->last_assoc_req)
1416 os_free(sta->last_assoc_req);
1417 sta->last_assoc_req = os_malloc(len);
1418 if (sta->last_assoc_req)
1419 os_memcpy(sta->last_assoc_req, mgmt, len);
1421 /* Make sure that the previously registered inactivity timer will not
1422 * remove the STA immediately. */
1423 sta->timeout_next = STA_NULLFUNC;
1426 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1430 static void handle_disassoc(struct hostapd_data *hapd,
1431 const struct ieee80211_mgmt *mgmt, size_t len)
1433 struct sta_info *sta;
1435 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1436 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1437 (unsigned long) len);
1441 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1443 le_to_host16(mgmt->u.disassoc.reason_code));
1445 sta = ap_get_sta(hapd, mgmt->sa);
1447 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1452 ap_sta_set_authorized(hapd, sta, 0);
1453 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1454 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1455 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1456 HOSTAPD_LEVEL_INFO, "disassociated");
1457 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1458 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1459 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1461 accounting_sta_stop(hapd, sta);
1462 ieee802_1x_free_station(sta);
1463 hostapd_drv_sta_remove(hapd, sta->addr);
1465 if (sta->timeout_next == STA_NULLFUNC ||
1466 sta->timeout_next == STA_DISASSOC) {
1467 sta->timeout_next = STA_DEAUTH;
1468 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1469 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1473 mlme_disassociate_indication(
1474 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1478 static void handle_deauth(struct hostapd_data *hapd,
1479 const struct ieee80211_mgmt *mgmt, size_t len)
1481 struct sta_info *sta;
1483 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1484 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1485 "payload (len=%lu)", (unsigned long) len);
1489 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1491 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1493 sta = ap_get_sta(hapd, mgmt->sa);
1495 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1496 "to deauthenticate, but it is not authenticated",
1501 ap_sta_set_authorized(hapd, sta, 0);
1502 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1503 WLAN_STA_ASSOC_REQ_OK);
1504 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1505 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1506 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1507 mlme_deauthenticate_indication(
1508 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1509 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1510 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1511 ap_free_sta(hapd, sta);
1515 static void handle_beacon(struct hostapd_data *hapd,
1516 const struct ieee80211_mgmt *mgmt, size_t len,
1517 struct hostapd_frame_info *fi)
1519 struct ieee802_11_elems elems;
1521 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1522 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1523 (unsigned long) len);
1527 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1528 len - (IEEE80211_HDRLEN +
1529 sizeof(mgmt->u.beacon)), &elems,
1532 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1536 #ifdef CONFIG_IEEE80211W
1538 static int hostapd_sa_query_action(struct hostapd_data *hapd,
1539 const struct ieee80211_mgmt *mgmt,
1544 end = mgmt->u.action.u.sa_query_resp.trans_id +
1545 WLAN_SA_QUERY_TR_ID_LEN;
1546 if (((u8 *) mgmt) + len < end) {
1547 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1548 "frame (len=%lu)", (unsigned long) len);
1552 ieee802_11_sa_query_action(hapd, mgmt->sa,
1553 mgmt->u.action.u.sa_query_resp.action,
1554 mgmt->u.action.u.sa_query_resp.trans_id);
1559 static int robust_action_frame(u8 category)
1561 return category != WLAN_ACTION_PUBLIC &&
1562 category != WLAN_ACTION_HT;
1564 #endif /* CONFIG_IEEE80211W */
1567 static int handle_action(struct hostapd_data *hapd,
1568 const struct ieee80211_mgmt *mgmt, size_t len)
1570 struct sta_info *sta;
1571 sta = ap_get_sta(hapd, mgmt->sa);
1573 if (len < IEEE80211_HDRLEN + 1) {
1574 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1575 HOSTAPD_LEVEL_DEBUG,
1576 "handle_action - too short payload (len=%lu)",
1577 (unsigned long) len);
1581 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1582 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1583 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1584 "frame (category=%u) from unassociated STA " MACSTR,
1585 MAC2STR(mgmt->sa), mgmt->u.action.category);
1589 #ifdef CONFIG_IEEE80211W
1590 if (sta && (sta->flags & WLAN_STA_MFP) &&
1591 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
1592 robust_action_frame(mgmt->u.action.category)) {
1593 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1594 HOSTAPD_LEVEL_DEBUG,
1595 "Dropped unprotected Robust Action frame from "
1599 #endif /* CONFIG_IEEE80211W */
1601 switch (mgmt->u.action.category) {
1602 #ifdef CONFIG_IEEE80211R
1603 case WLAN_ACTION_FT:
1604 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1605 len - IEEE80211_HDRLEN))
1608 #endif /* CONFIG_IEEE80211R */
1609 case WLAN_ACTION_WMM:
1610 hostapd_wmm_action(hapd, mgmt, len);
1612 #ifdef CONFIG_IEEE80211W
1613 case WLAN_ACTION_SA_QUERY:
1614 return hostapd_sa_query_action(hapd, mgmt, len);
1615 #endif /* CONFIG_IEEE80211W */
1617 case WLAN_ACTION_WNM:
1618 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
1620 #endif /* CONFIG_WNM */
1621 case WLAN_ACTION_PUBLIC:
1622 case WLAN_ACTION_PROTECTED_DUAL:
1623 if (hapd->public_action_cb) {
1624 hapd->public_action_cb(hapd->public_action_cb_ctx,
1628 if (hapd->public_action_cb2) {
1629 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1633 if (hapd->public_action_cb || hapd->public_action_cb2)
1636 case WLAN_ACTION_VENDOR_SPECIFIC:
1637 if (hapd->vendor_action_cb) {
1638 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1640 hapd->iface->freq) == 0)
1646 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1647 HOSTAPD_LEVEL_DEBUG,
1648 "handle_action - unknown action category %d or invalid "
1650 mgmt->u.action.category);
1651 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1652 !(mgmt->sa[0] & 0x01)) {
1653 struct ieee80211_mgmt *resp;
1656 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1657 * Return the Action frame to the source without change
1658 * except that MSB of the Category set to 1.
1660 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1661 "frame back to sender");
1662 resp = os_malloc(len);
1665 os_memcpy(resp, mgmt, len);
1666 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1667 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1668 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1669 resp->u.action.category |= 0x80;
1671 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1672 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1683 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1684 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1686 * @buf: management frame data (starting from IEEE 802.11 header)
1687 * @len: length of frame data in octets
1688 * @fi: meta data about received frame (signal level, etc.)
1690 * Process all incoming IEEE 802.11 management frames. This will be called for
1691 * each frame received from the kernel driver through wlan#ap interface. In
1692 * addition, it can be called to re-inserted pending frames (e.g., when using
1693 * external RADIUS server as an MAC ACL).
1695 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1696 struct hostapd_frame_info *fi)
1698 struct ieee80211_mgmt *mgmt;
1703 #ifdef CONFIG_TESTING_OPTIONS
1704 if (hapd->ext_mgmt_frame_handling) {
1705 size_t hex_len = 2 * len + 1;
1706 char *hex = os_malloc(hex_len);
1708 wpa_snprintf_hex(hex, hex_len, buf, len);
1709 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1714 #endif /* CONFIG_TESTING_OPTIONS */
1719 mgmt = (struct ieee80211_mgmt *) buf;
1720 fc = le_to_host16(mgmt->frame_control);
1721 stype = WLAN_FC_GET_STYPE(fc);
1723 if (stype == WLAN_FC_STYPE_BEACON) {
1724 handle_beacon(hapd, mgmt, len, fi);
1728 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1729 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1730 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1734 /* Invitation responses can be sent with the peer MAC as BSSID */
1735 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1736 stype == WLAN_FC_STYPE_ACTION) &&
1737 #endif /* CONFIG_P2P */
1738 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1739 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
1740 MAC2STR(mgmt->bssid));
1745 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1746 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1750 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1751 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1752 HOSTAPD_LEVEL_DEBUG,
1753 "MGMT: DA=" MACSTR " not our address",
1759 case WLAN_FC_STYPE_AUTH:
1760 wpa_printf(MSG_DEBUG, "mgmt::auth");
1761 handle_auth(hapd, mgmt, len);
1764 case WLAN_FC_STYPE_ASSOC_REQ:
1765 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1766 handle_assoc(hapd, mgmt, len, 0);
1769 case WLAN_FC_STYPE_REASSOC_REQ:
1770 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1771 handle_assoc(hapd, mgmt, len, 1);
1774 case WLAN_FC_STYPE_DISASSOC:
1775 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1776 handle_disassoc(hapd, mgmt, len);
1779 case WLAN_FC_STYPE_DEAUTH:
1780 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1781 handle_deauth(hapd, mgmt, len);
1784 case WLAN_FC_STYPE_ACTION:
1785 wpa_printf(MSG_DEBUG, "mgmt::action");
1786 ret = handle_action(hapd, mgmt, len);
1789 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1790 HOSTAPD_LEVEL_DEBUG,
1791 "unknown mgmt frame subtype %d", stype);
1799 static void handle_auth_cb(struct hostapd_data *hapd,
1800 const struct ieee80211_mgmt *mgmt,
1803 u16 auth_alg, auth_transaction, status_code;
1804 struct sta_info *sta;
1807 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1808 HOSTAPD_LEVEL_NOTICE,
1809 "did not acknowledge authentication response");
1813 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1814 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
1815 (unsigned long) len);
1819 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1820 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1821 status_code = le_to_host16(mgmt->u.auth.status_code);
1823 sta = ap_get_sta(hapd, mgmt->da);
1825 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
1830 if (status_code == WLAN_STATUS_SUCCESS &&
1831 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1832 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1833 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1834 HOSTAPD_LEVEL_INFO, "authenticated");
1835 sta->flags |= WLAN_STA_AUTH;
1840 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
1841 struct sta_info *sta,
1845 struct hostapd_ssid *ssid = sta->ssid;
1847 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
1850 for (i = 0; i < 4; i++) {
1851 if (ssid->wep.key[i] &&
1852 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
1853 i == ssid->wep.idx, NULL, 0,
1854 ssid->wep.key[i], ssid->wep.len[i])) {
1855 wpa_printf(MSG_WARNING,
1856 "Could not set WEP keys for WDS interface; %s",
1864 static void handle_assoc_cb(struct hostapd_data *hapd,
1865 const struct ieee80211_mgmt *mgmt,
1866 size_t len, int reassoc, int ok)
1869 struct sta_info *sta;
1871 struct ieee80211_ht_capabilities ht_cap;
1872 struct ieee80211_vht_capabilities vht_cap;
1874 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1875 sizeof(mgmt->u.assoc_resp))) {
1876 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
1877 reassoc, (unsigned long) len);
1881 sta = ap_get_sta(hapd, mgmt->da);
1883 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
1889 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1890 HOSTAPD_LEVEL_DEBUG,
1891 "did not acknowledge association response");
1892 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1897 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1899 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1901 if (status != WLAN_STATUS_SUCCESS)
1904 /* Stop previous accounting session, if one is started, and allocate
1905 * new session id for the new session. */
1906 accounting_sta_stop(hapd, sta);
1908 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1910 "associated (aid %d)",
1913 if (sta->flags & WLAN_STA_ASSOC)
1915 sta->flags |= WLAN_STA_ASSOC;
1916 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
1917 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1918 sta->auth_alg == WLAN_AUTH_FT) {
1920 * Open, static WEP, or FT protocol; no separate authorization
1923 ap_sta_set_authorized(hapd, sta, 1);
1927 mlme_reassociate_indication(hapd, sta);
1929 mlme_associate_indication(hapd, sta);
1931 #ifdef CONFIG_IEEE80211W
1932 sta->sa_query_timed_out = 0;
1933 #endif /* CONFIG_IEEE80211W */
1936 * Remove the STA entry in order to make sure the STA PS state gets
1937 * cleared and configuration gets updated in case of reassociation back
1940 hostapd_drv_sta_remove(hapd, sta->addr);
1942 #ifdef CONFIG_IEEE80211N
1943 if (sta->flags & WLAN_STA_HT)
1944 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1945 #endif /* CONFIG_IEEE80211N */
1946 #ifdef CONFIG_IEEE80211AC
1947 if (sta->flags & WLAN_STA_VHT)
1948 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1949 #endif /* CONFIG_IEEE80211AC */
1951 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1952 sta->supported_rates, sta->supported_rates_len,
1953 sta->listen_interval,
1954 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1955 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1956 sta->flags, sta->qosinfo)) {
1957 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1958 HOSTAPD_LEVEL_NOTICE,
1959 "Could not add STA to kernel driver");
1961 ap_sta_disconnect(hapd, sta, sta->addr,
1962 WLAN_REASON_DISASSOC_AP_BUSY);
1967 if (sta->flags & WLAN_STA_WDS) {
1969 char ifname_wds[IFNAMSIZ + 1];
1971 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
1974 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
1977 if (sta->eapol_sm == NULL) {
1979 * This STA does not use RADIUS server for EAP authentication,
1980 * so bind it to the selected VLAN interface now, since the
1981 * interface selection is not going to change anymore.
1983 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1985 } else if (sta->vlan_id) {
1986 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1987 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1991 hostapd_set_sta_flags(hapd, sta);
1993 if (sta->auth_alg == WLAN_AUTH_FT)
1994 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1996 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1997 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1999 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
2002 /* Copy of the association request is not needed anymore */
2003 if (sta->last_assoc_req) {
2004 os_free(sta->last_assoc_req);
2005 sta->last_assoc_req = NULL;
2010 static void handle_deauth_cb(struct hostapd_data *hapd,
2011 const struct ieee80211_mgmt *mgmt,
2014 struct sta_info *sta;
2015 if (mgmt->da[0] & 0x01)
2017 sta = ap_get_sta(hapd, mgmt->da);
2019 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2020 " not found", MAC2STR(mgmt->da));
2024 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2025 MAC2STR(sta->addr));
2027 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2028 "deauth", MAC2STR(sta->addr));
2030 ap_sta_deauth_cb(hapd, sta);
2034 static void handle_disassoc_cb(struct hostapd_data *hapd,
2035 const struct ieee80211_mgmt *mgmt,
2038 struct sta_info *sta;
2039 if (mgmt->da[0] & 0x01)
2041 sta = ap_get_sta(hapd, mgmt->da);
2043 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2044 " not found", MAC2STR(mgmt->da));
2048 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2049 MAC2STR(sta->addr));
2051 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2052 "disassoc", MAC2STR(sta->addr));
2054 ap_sta_disassoc_cb(hapd, sta);
2059 * ieee802_11_mgmt_cb - Process management frame TX status callback
2060 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2062 * @buf: management frame data (starting from IEEE 802.11 header)
2063 * @len: length of frame data in octets
2064 * @stype: management frame subtype from frame control field
2065 * @ok: Whether the frame was ACK'ed
2067 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2070 const struct ieee80211_mgmt *mgmt;
2071 mgmt = (const struct ieee80211_mgmt *) buf;
2073 #ifdef CONFIG_TESTING_OPTIONS
2074 if (hapd->ext_mgmt_frame_handling) {
2075 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2079 #endif /* CONFIG_TESTING_OPTIONS */
2082 case WLAN_FC_STYPE_AUTH:
2083 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2084 handle_auth_cb(hapd, mgmt, len, ok);
2086 case WLAN_FC_STYPE_ASSOC_RESP:
2087 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2088 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2090 case WLAN_FC_STYPE_REASSOC_RESP:
2091 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2092 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2094 case WLAN_FC_STYPE_PROBE_RESP:
2095 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2097 case WLAN_FC_STYPE_DEAUTH:
2098 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2099 handle_deauth_cb(hapd, mgmt, len, ok);
2101 case WLAN_FC_STYPE_DISASSOC:
2102 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2103 handle_disassoc_cb(hapd, mgmt, len, ok);
2105 case WLAN_FC_STYPE_ACTION:
2106 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2109 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
2115 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2122 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2123 char *buf, size_t buflen)
2130 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2131 const u8 *buf, size_t len, int ack)
2133 struct sta_info *sta;
2134 struct hostapd_iface *iface = hapd->iface;
2136 sta = ap_get_sta(hapd, addr);
2137 if (sta == NULL && iface->num_bss > 1) {
2139 for (j = 0; j < iface->num_bss; j++) {
2140 hapd = iface->bss[j];
2141 sta = ap_get_sta(hapd, addr);
2146 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2148 if (sta->flags & WLAN_STA_PENDING_POLL) {
2149 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2150 "activity poll", MAC2STR(sta->addr),
2151 ack ? "ACKed" : "did not ACK");
2153 sta->flags &= ~WLAN_STA_PENDING_POLL;
2156 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2160 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2161 const u8 *data, size_t len, int ack)
2163 struct sta_info *sta;
2164 struct hostapd_iface *iface = hapd->iface;
2166 sta = ap_get_sta(hapd, dst);
2167 if (sta == NULL && iface->num_bss > 1) {
2169 for (j = 0; j < iface->num_bss; j++) {
2170 hapd = iface->bss[j];
2171 sta = ap_get_sta(hapd, dst);
2176 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2177 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2178 MACSTR " that is not currently associated",
2183 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2187 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2189 struct sta_info *sta;
2190 struct hostapd_iface *iface = hapd->iface;
2192 sta = ap_get_sta(hapd, addr);
2193 if (sta == NULL && iface->num_bss > 1) {
2195 for (j = 0; j < iface->num_bss; j++) {
2196 hapd = iface->bss[j];
2197 sta = ap_get_sta(hapd, addr);
2204 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2207 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2208 "activity poll", MAC2STR(sta->addr));
2209 sta->flags &= ~WLAN_STA_PENDING_POLL;
2213 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2216 struct sta_info *sta;
2218 sta = ap_get_sta(hapd, src);
2219 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2220 if (!hapd->conf->wds_sta)
2223 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2225 char ifname_wds[IFNAMSIZ + 1];
2227 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2228 "STA " MACSTR " (aid %u)",
2229 MAC2STR(sta->addr), sta->aid);
2230 sta->flags |= WLAN_STA_WDS;
2231 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2232 sta->addr, sta->aid, 1);
2234 hostapd_set_wds_encryption(hapd, sta,
2240 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2241 MACSTR, MAC2STR(src));
2242 if (src[0] & 0x01) {
2243 /* Broadcast bit set in SA?! Ignore the frame silently. */
2247 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2248 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2249 "already been sent, but no TX status yet known - "
2250 "ignore Class 3 frame issue with " MACSTR,
2255 if (sta && (sta->flags & WLAN_STA_AUTH))
2256 hostapd_drv_sta_disassoc(
2258 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2260 hostapd_drv_sta_deauth(
2262 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2266 #endif /* CONFIG_NATIVE_WINDOWS */