2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, 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 "drivers/driver.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #include "common/sae.h"
23 #include "radius/radius.h"
24 #include "radius/radius_client.h"
29 #include "ieee802_11_auth.h"
31 #include "ieee802_1x.h"
35 #include "accounting.h"
36 #include "ap_config.h"
38 #include "p2p_hostapd.h"
39 #include "ap_drv_ops.h"
41 #include "ieee802_11.h"
44 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
49 if (hapd->iface->current_rates == NULL)
52 *pos++ = WLAN_EID_SUPP_RATES;
53 num = hapd->iface->num_rates;
54 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
56 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
59 /* rest of the rates are encoded in Extended supported
66 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
69 *pos = hapd->iface->current_rates[i].rate / 5;
70 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
75 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
77 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
80 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
82 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
89 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
94 if (hapd->iface->current_rates == NULL)
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
106 *pos++ = WLAN_EID_EXT_SUPP_RATES;
109 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
113 continue; /* already in SuppRates IE */
114 *pos = hapd->iface->current_rates[i].rate / 5;
115 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
120 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
123 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
126 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
129 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
136 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
139 int capab = WLAN_CAPABILITY_ESS;
142 if (hapd->iface->num_sta_no_short_preamble == 0 &&
143 hapd->iconf->preamble == SHORT_PREAMBLE)
144 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
146 privacy = hapd->conf->ssid.wep.keys_set;
148 if (hapd->conf->ieee802_1x &&
149 (hapd->conf->default_wep_key_len ||
150 hapd->conf->individual_wep_key_len))
157 int policy, def_klen;
158 if (probe && sta->ssid_probe) {
159 policy = sta->ssid_probe->security_policy;
160 def_klen = sta->ssid_probe->wep.default_len;
162 policy = sta->ssid->security_policy;
163 def_klen = sta->ssid->wep.default_len;
165 privacy = policy != SECURITY_PLAINTEXT;
166 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
171 capab |= WLAN_CAPABILITY_PRIVACY;
173 if (hapd->iface->current_mode &&
174 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
175 hapd->iface->num_sta_no_short_slot_time == 0)
176 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
182 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
185 if (len > HOSTAPD_MAX_SSID_LEN)
186 len = HOSTAPD_MAX_SSID_LEN;
187 for (i = 0; i < len; i++) {
188 if (ssid[i] >= 32 && ssid[i] < 127)
197 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
198 u16 auth_transaction, const u8 *challenge,
201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
203 "authentication (shared key, transaction %d)",
206 if (auth_transaction == 1) {
207 if (!sta->challenge) {
208 /* Generate a pseudo-random challenge */
212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
218 os_memcpy(key, &now.sec, 4);
219 os_memcpy(key + 4, &r, 4);
220 rc4_skip(key, sizeof(key), 0,
221 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
226 if (auth_transaction != 3)
227 return WLAN_STATUS_UNSPECIFIED_FAILURE;
230 if (!iswep || !sta->challenge || !challenge ||
231 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
232 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
234 "shared key authentication - invalid "
235 "challenge-response");
236 return WLAN_STATUS_CHALLENGE_FAIL;
239 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
241 "authentication OK (shared key)");
242 #ifdef IEEE80211_REQUIRE_AUTH_ACK
243 /* Station will be marked authenticated if it ACKs the
244 * authentication reply. */
246 sta->flags |= WLAN_STA_AUTH;
247 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
249 os_free(sta->challenge);
250 sta->challenge = NULL;
256 static void send_auth_reply(struct hostapd_data *hapd,
257 const u8 *dst, const u8 *bssid,
258 u16 auth_alg, u16 auth_transaction, u16 resp,
259 const u8 *ies, size_t ies_len)
261 struct ieee80211_mgmt *reply;
265 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
266 buf = os_zalloc(rlen);
270 reply = (struct ieee80211_mgmt *) buf;
271 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
273 os_memcpy(reply->da, dst, ETH_ALEN);
274 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
275 os_memcpy(reply->bssid, bssid, ETH_ALEN);
277 reply->u.auth.auth_alg = host_to_le16(auth_alg);
278 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
279 reply->u.auth.status_code = host_to_le16(resp);
282 os_memcpy(reply->u.auth.variable, ies, ies_len);
284 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
285 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
286 MAC2STR(dst), auth_alg, auth_transaction,
287 resp, (unsigned long) ies_len);
288 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
289 perror("send_auth_reply: send");
295 #ifdef CONFIG_IEEE80211R
296 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
297 u16 auth_transaction, u16 status,
298 const u8 *ies, size_t ies_len)
300 struct hostapd_data *hapd = ctx;
301 struct sta_info *sta;
303 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
304 status, ies, ies_len);
306 if (status != WLAN_STATUS_SUCCESS)
309 sta = ap_get_sta(hapd, dst);
313 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
314 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
315 sta->flags |= WLAN_STA_AUTH;
316 mlme_authenticate_indication(hapd, sta);
318 #endif /* CONFIG_IEEE80211R */
323 static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
324 struct sta_info *sta)
328 if (hapd->conf->ssid.wpa_passphrase == NULL) {
329 wpa_printf(MSG_DEBUG, "SAE: No password available");
333 if (sae_prepare_commit(hapd->own_addr, sta->addr,
334 (u8 *) hapd->conf->ssid.wpa_passphrase,
335 os_strlen(hapd->conf->ssid.wpa_passphrase),
337 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
341 if (sae_process_commit(sta->sae) < 0) {
342 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
346 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
349 sae_write_commit(sta->sae, buf, NULL);
355 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
356 struct sta_info *sta)
360 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
364 sae_write_confirm(sta->sae, buf);
370 static int use_sae_anti_clogging(struct hostapd_data *hapd)
372 struct sta_info *sta;
373 unsigned int open = 0;
375 if (hapd->conf->sae_anti_clogging_threshold == 0)
378 for (sta = hapd->sta_list; sta; sta = sta->next) {
381 if (sta->sae->state != SAE_COMMITTED &&
382 sta->sae->state != SAE_CONFIRMED)
385 if (open >= hapd->conf->sae_anti_clogging_threshold)
393 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
394 const u8 *token, size_t token_len)
396 u8 mac[SHA256_MAC_LEN];
398 if (token_len != SHA256_MAC_LEN)
400 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
401 addr, ETH_ALEN, mac) < 0 ||
402 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
409 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
417 if (hapd->last_sae_token_key_update == 0 ||
418 t.sec > hapd->last_sae_token_key_update + 60) {
419 random_get_bytes(hapd->sae_token_key,
420 sizeof(hapd->sae_token_key));
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 = t.sec;
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;
516 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
518 "unexpected SAE authentication transaction %u",
520 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
523 sta->auth_alg = WLAN_AUTH_SAE;
525 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
526 auth_transaction, resp,
527 data ? wpabuf_head(data) : (u8 *) "",
528 data ? wpabuf_len(data) : 0);
531 #endif /* CONFIG_SAE */
534 static void handle_auth(struct hostapd_data *hapd,
535 const struct ieee80211_mgmt *mgmt, size_t len)
537 u16 auth_alg, auth_transaction, status_code;
538 u16 resp = WLAN_STATUS_SUCCESS;
539 struct sta_info *sta = NULL;
542 const u8 *challenge = NULL;
543 u32 session_timeout, acct_interim_interval;
545 struct hostapd_sta_wpa_psk_short *psk = NULL;
546 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
547 size_t resp_ies_len = 0;
548 char *identity = NULL;
549 char *radius_cui = NULL;
551 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
552 printf("handle_auth - too short payload (len=%lu)\n",
553 (unsigned long) len);
557 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
558 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
559 status_code = le_to_host16(mgmt->u.auth.status_code);
560 fc = le_to_host16(mgmt->frame_control);
562 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
563 2 + WLAN_AUTH_CHALLENGE_LEN &&
564 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
565 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
566 challenge = &mgmt->u.auth.variable[2];
568 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
569 "auth_transaction=%d status_code=%d wep=%d%s",
570 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
571 status_code, !!(fc & WLAN_FC_ISWEP),
572 challenge ? " challenge" : "");
574 if (hapd->tkip_countermeasures) {
575 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
579 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
580 auth_alg == WLAN_AUTH_OPEN) ||
581 #ifdef CONFIG_IEEE80211R
582 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
583 auth_alg == WLAN_AUTH_FT) ||
584 #endif /* CONFIG_IEEE80211R */
586 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
587 auth_alg == WLAN_AUTH_SAE) ||
588 #endif /* CONFIG_SAE */
589 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
590 auth_alg == WLAN_AUTH_SHARED_KEY))) {
591 printf("Unsupported authentication algorithm (%d)\n",
593 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
597 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
598 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
599 printf("Unknown authentication transaction number (%d)\n",
601 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
605 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
606 printf("Station " MACSTR " not allowed to authenticate.\n",
608 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
612 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
614 &acct_interim_interval, &vlan_id,
615 &psk, &identity, &radius_cui);
617 if (res == HOSTAPD_ACL_REJECT) {
618 printf("Station " MACSTR " not allowed to authenticate.\n",
620 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
623 if (res == HOSTAPD_ACL_PENDING) {
624 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
625 " waiting for an external authentication",
627 /* Authentication code will re-send the authentication frame
628 * after it has received (and cached) information from the
629 * external source. */
633 sta = ap_sta_add(hapd, mgmt->sa);
635 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
640 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
642 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
643 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
644 "%d received from RADIUS server",
646 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
649 sta->vlan_id = vlan_id;
650 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
651 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
654 hostapd_free_psk_list(sta->psk);
655 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
662 sta->identity = identity;
664 sta->radius_cui = radius_cui;
667 sta->flags &= ~WLAN_STA_PREAUTH;
668 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
670 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
671 sta->acct_interim_interval = acct_interim_interval;
672 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
673 ap_sta_session_timeout(hapd, sta, session_timeout);
675 ap_sta_no_session_timeout(hapd, sta);
679 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
681 "authentication OK (open system)");
682 #ifdef IEEE80211_REQUIRE_AUTH_ACK
683 /* Station will be marked authenticated if it ACKs the
684 * authentication reply. */
686 sta->flags |= WLAN_STA_AUTH;
687 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
688 sta->auth_alg = WLAN_AUTH_OPEN;
689 mlme_authenticate_indication(hapd, sta);
692 case WLAN_AUTH_SHARED_KEY:
693 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
695 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
696 mlme_authenticate_indication(hapd, sta);
697 if (sta->challenge && auth_transaction == 1) {
698 resp_ies[0] = WLAN_EID_CHALLENGE;
699 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
700 os_memcpy(resp_ies + 2, sta->challenge,
701 WLAN_AUTH_CHALLENGE_LEN);
702 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
705 #ifdef CONFIG_IEEE80211R
707 sta->auth_alg = WLAN_AUTH_FT;
708 if (sta->wpa_sm == NULL)
709 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
711 if (sta->wpa_sm == NULL) {
712 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
714 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
717 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
718 auth_transaction, mgmt->u.auth.variable,
719 len - IEEE80211_HDRLEN -
720 sizeof(mgmt->u.auth),
721 handle_auth_ft_finish, hapd);
722 /* handle_auth_ft_finish() callback will complete auth. */
724 #endif /* CONFIG_IEEE80211R */
727 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
729 #endif /* CONFIG_SAE */
735 hostapd_free_psk_list(psk);
737 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
738 auth_transaction + 1, resp, resp_ies, resp_ies_len);
742 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
746 /* get a unique AID */
748 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
752 for (i = 0; i < AID_WORDS; i++) {
753 if (hapd->sta_aid[i] == (u32) -1)
755 for (j = 0; j < 32; j++) {
756 if (!(hapd->sta_aid[i] & BIT(j)))
764 aid = i * 32 + j + 1;
769 hapd->sta_aid[i] |= BIT(j);
770 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
775 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
776 const u8 *ssid_ie, size_t ssid_ie_len)
779 return WLAN_STATUS_UNSPECIFIED_FAILURE;
781 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
782 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
784 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
785 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
787 "Station tried to associate with unknown SSID "
789 return WLAN_STATUS_UNSPECIFIED_FAILURE;
792 return WLAN_STATUS_SUCCESS;
796 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
797 const u8 *wmm_ie, size_t wmm_ie_len)
799 sta->flags &= ~WLAN_STA_WMM;
801 if (wmm_ie && hapd->conf->wmm_enabled) {
802 struct wmm_information_element *wmm;
804 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
805 hostapd_logger(hapd, sta->addr,
808 "invalid WMM element in association "
810 return WLAN_STATUS_UNSPECIFIED_FAILURE;
813 sta->flags |= WLAN_STA_WMM;
814 wmm = (struct wmm_information_element *) wmm_ie;
815 sta->qosinfo = wmm->qos_info;
817 return WLAN_STATUS_SUCCESS;
821 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
822 struct ieee802_11_elems *elems)
824 if (!elems->supp_rates) {
825 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
827 "No supported rates element in AssocReq");
828 return WLAN_STATUS_UNSPECIFIED_FAILURE;
831 if (elems->supp_rates_len + elems->ext_supp_rates_len >
832 sizeof(sta->supported_rates)) {
833 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
835 "Invalid supported rates element length %d+%d",
836 elems->supp_rates_len,
837 elems->ext_supp_rates_len);
838 return WLAN_STATUS_UNSPECIFIED_FAILURE;
841 sta->supported_rates_len = merge_byte_arrays(
842 sta->supported_rates, sizeof(sta->supported_rates),
843 elems->supp_rates, elems->supp_rates_len,
844 elems->ext_supp_rates, elems->ext_supp_rates_len);
846 return WLAN_STATUS_SUCCESS;
850 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
851 const u8 *ies, size_t ies_len, int reassoc)
853 struct ieee802_11_elems elems;
858 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
859 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
860 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
861 "association request");
862 return WLAN_STATUS_UNSPECIFIED_FAILURE;
865 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
866 if (resp != WLAN_STATUS_SUCCESS)
868 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
869 if (resp != WLAN_STATUS_SUCCESS)
871 resp = copy_supp_rates(hapd, sta, &elems);
872 if (resp != WLAN_STATUS_SUCCESS)
874 #ifdef CONFIG_IEEE80211N
875 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
876 elems.ht_capabilities_len);
877 if (resp != WLAN_STATUS_SUCCESS)
879 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
880 !(sta->flags & WLAN_STA_HT)) {
881 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
882 HOSTAPD_LEVEL_INFO, "Station does not support "
883 "mandatory HT PHY - reject association");
884 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
886 #endif /* CONFIG_IEEE80211N */
888 #ifdef CONFIG_IEEE80211AC
889 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
890 elems.vht_capabilities_len);
891 if (resp != WLAN_STATUS_SUCCESS)
893 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
894 !(sta->flags & WLAN_STA_VHT)) {
895 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
896 HOSTAPD_LEVEL_INFO, "Station does not support "
897 "mandatory VHT PHY - reject association");
898 return WLAN_STATUS_UNSPECIFIED_FAILURE;
900 #endif /* CONFIG_IEEE80211AC */
902 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
903 wpa_ie = elems.rsn_ie;
904 wpa_ie_len = elems.rsn_ie_len;
905 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
907 wpa_ie = elems.wpa_ie;
908 wpa_ie_len = elems.wpa_ie_len;
915 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
916 if (hapd->conf->wps_state && elems.wps_ie) {
917 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
918 "Request - assume WPS is used");
919 sta->flags |= WLAN_STA_WPS;
920 wpabuf_free(sta->wps_ie);
921 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
923 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
924 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
925 sta->flags |= WLAN_STA_WPS2;
929 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
930 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
931 "(Re)Association Request - reject");
932 return WLAN_STATUS_INVALID_IE;
934 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
935 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
936 "(Re)Association Request - possible WPS use");
937 sta->flags |= WLAN_STA_MAYBE_WPS;
939 #endif /* CONFIG_WPS */
940 if (hapd->conf->wpa && wpa_ie == NULL) {
941 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
943 "No WPA/RSN IE in association request");
944 return WLAN_STATUS_INVALID_IE;
947 if (hapd->conf->wpa && wpa_ie) {
951 if (sta->wpa_sm == NULL)
952 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
954 if (sta->wpa_sm == NULL) {
955 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
957 return WLAN_STATUS_UNSPECIFIED_FAILURE;
959 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
961 elems.mdie, elems.mdie_len);
962 if (res == WPA_INVALID_GROUP)
963 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
964 else if (res == WPA_INVALID_PAIRWISE)
965 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
966 else if (res == WPA_INVALID_AKMP)
967 resp = WLAN_STATUS_AKMP_NOT_VALID;
968 else if (res == WPA_ALLOC_FAIL)
969 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
970 #ifdef CONFIG_IEEE80211W
971 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
972 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
973 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
974 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
975 #endif /* CONFIG_IEEE80211W */
976 else if (res == WPA_INVALID_MDIE)
977 resp = WLAN_STATUS_INVALID_MDIE;
978 else if (res != WPA_IE_OK)
979 resp = WLAN_STATUS_INVALID_IE;
980 if (resp != WLAN_STATUS_SUCCESS)
982 #ifdef CONFIG_IEEE80211W
983 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
984 sta->sa_query_count > 0)
985 ap_check_sa_query_timeout(hapd, sta);
986 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
987 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
989 * STA has already been associated with MFP and SA
990 * Query timeout has not been reached. Reject the
991 * association attempt temporarily and start SA Query,
992 * if one is not pending.
995 if (sta->sa_query_count == 0)
996 ap_sta_start_sa_query(hapd, sta);
998 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1001 if (wpa_auth_uses_mfp(sta->wpa_sm))
1002 sta->flags |= WLAN_STA_MFP;
1004 sta->flags &= ~WLAN_STA_MFP;
1005 #endif /* CONFIG_IEEE80211W */
1007 #ifdef CONFIG_IEEE80211R
1008 if (sta->auth_alg == WLAN_AUTH_FT) {
1010 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1011 "to use association (not "
1012 "re-association) with FT auth_alg",
1013 MAC2STR(sta->addr));
1014 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1017 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1019 if (resp != WLAN_STATUS_SUCCESS)
1022 #endif /* CONFIG_IEEE80211R */
1025 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1026 sta->auth_alg != WLAN_AUTH_SAE) {
1027 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1028 "SAE AKM after non-SAE auth_alg %u",
1029 MAC2STR(sta->addr), sta->auth_alg);
1030 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1032 #endif /* CONFIG_SAE */
1034 #ifdef CONFIG_IEEE80211N
1035 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1036 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1037 hostapd_logger(hapd, sta->addr,
1038 HOSTAPD_MODULE_IEEE80211,
1040 "Station tried to use TKIP with HT "
1042 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1044 #endif /* CONFIG_IEEE80211N */
1046 wpa_auth_sta_no_wpa(sta->wpa_sm);
1050 wpabuf_free(sta->p2p_ie);
1051 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1052 P2P_IE_VENDOR_TYPE);
1055 wpabuf_free(sta->p2p_ie);
1059 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1060 #endif /* CONFIG_P2P */
1063 wpabuf_free(sta->hs20_ie);
1064 if (elems.hs20 && elems.hs20_len > 4) {
1065 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1066 elems.hs20_len - 4);
1068 sta->hs20_ie = NULL;
1069 #endif /* CONFIG_HS20 */
1071 return WLAN_STATUS_SUCCESS;
1075 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1079 struct ieee80211_mgmt reply;
1081 os_memset(&reply, 0, sizeof(reply));
1082 reply.frame_control =
1083 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1084 os_memcpy(reply.da, addr, ETH_ALEN);
1085 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1086 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1088 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1089 reply.u.deauth.reason_code = host_to_le16(reason_code);
1091 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1092 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1097 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1098 u16 status_code, int reassoc, const u8 *ies,
1102 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1103 struct ieee80211_mgmt *reply;
1106 os_memset(buf, 0, sizeof(buf));
1107 reply = (struct ieee80211_mgmt *) buf;
1108 reply->frame_control =
1109 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1110 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1111 WLAN_FC_STYPE_ASSOC_RESP));
1112 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1113 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1114 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1116 send_len = IEEE80211_HDRLEN;
1117 send_len += sizeof(reply->u.assoc_resp);
1118 reply->u.assoc_resp.capab_info =
1119 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1120 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1121 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1122 | BIT(14) | BIT(15));
1123 /* Supported rates */
1124 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1125 /* Extended supported rates */
1126 p = hostapd_eid_ext_supp_rates(hapd, p);
1128 #ifdef CONFIG_IEEE80211R
1129 if (status_code == WLAN_STATUS_SUCCESS) {
1130 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1131 * Transition Information, RSN, [RIC Response] */
1132 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1133 buf + sizeof(buf) - p,
1134 sta->auth_alg, ies, ies_len);
1136 #endif /* CONFIG_IEEE80211R */
1138 #ifdef CONFIG_IEEE80211W
1139 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1140 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1141 #endif /* CONFIG_IEEE80211W */
1143 #ifdef CONFIG_IEEE80211N
1144 p = hostapd_eid_ht_capabilities(hapd, p);
1145 p = hostapd_eid_ht_operation(hapd, p);
1146 #endif /* CONFIG_IEEE80211N */
1148 #ifdef CONFIG_IEEE80211AC
1149 p = hostapd_eid_vht_capabilities(hapd, p);
1150 p = hostapd_eid_vht_operation(hapd, p);
1151 #endif /* CONFIG_IEEE80211AC */
1153 p = hostapd_eid_ext_capab(hapd, p);
1154 p = hostapd_eid_bss_max_idle_period(hapd, p);
1156 if (sta->flags & WLAN_STA_WMM)
1157 p = hostapd_eid_wmm(hapd, p);
1160 if ((sta->flags & WLAN_STA_WPS) ||
1161 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1162 struct wpabuf *wps = wps_build_assoc_resp_ie();
1164 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1165 p += wpabuf_len(wps);
1169 #endif /* CONFIG_WPS */
1173 struct wpabuf *p2p_resp_ie;
1174 enum p2p_status_code status;
1175 switch (status_code) {
1176 case WLAN_STATUS_SUCCESS:
1177 status = P2P_SC_SUCCESS;
1179 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1180 status = P2P_SC_FAIL_LIMIT_REACHED;
1183 status = P2P_SC_FAIL_INVALID_PARAMS;
1186 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1188 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1189 wpabuf_len(p2p_resp_ie));
1190 p += wpabuf_len(p2p_resp_ie);
1191 wpabuf_free(p2p_resp_ie);
1194 #endif /* CONFIG_P2P */
1196 #ifdef CONFIG_P2P_MANAGER
1197 if (hapd->conf->p2p & P2P_MANAGE)
1198 p = hostapd_eid_p2p_manage(hapd, p);
1199 #endif /* CONFIG_P2P_MANAGER */
1201 send_len += p - reply->u.assoc_resp.variable;
1203 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1204 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1209 static void handle_assoc(struct hostapd_data *hapd,
1210 const struct ieee80211_mgmt *mgmt, size_t len,
1213 u16 capab_info, listen_interval;
1214 u16 resp = WLAN_STATUS_SUCCESS;
1217 struct sta_info *sta;
1219 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1220 sizeof(mgmt->u.assoc_req))) {
1221 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1222 "\n", reassoc, (unsigned long) len);
1227 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1228 listen_interval = le_to_host16(
1229 mgmt->u.reassoc_req.listen_interval);
1230 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1231 " capab_info=0x%02x listen_interval=%d current_ap="
1233 MAC2STR(mgmt->sa), capab_info, listen_interval,
1234 MAC2STR(mgmt->u.reassoc_req.current_ap));
1235 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1236 pos = mgmt->u.reassoc_req.variable;
1238 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1239 listen_interval = le_to_host16(
1240 mgmt->u.assoc_req.listen_interval);
1241 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1242 " capab_info=0x%02x listen_interval=%d",
1243 MAC2STR(mgmt->sa), capab_info, listen_interval);
1244 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1245 pos = mgmt->u.assoc_req.variable;
1248 sta = ap_get_sta(hapd, mgmt->sa);
1249 #ifdef CONFIG_IEEE80211R
1250 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1251 (sta->flags & WLAN_STA_AUTH) == 0) {
1252 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1253 "prior to authentication since it is using "
1254 "over-the-DS FT", MAC2STR(mgmt->sa));
1256 #endif /* CONFIG_IEEE80211R */
1257 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1258 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1259 HOSTAPD_LEVEL_INFO, "Station tried to "
1260 "associate before authentication "
1261 "(aid=%d flags=0x%x)",
1262 sta ? sta->aid : -1,
1263 sta ? sta->flags : 0);
1264 send_deauth(hapd, mgmt->sa,
1265 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1269 if (hapd->tkip_countermeasures) {
1270 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1274 if (listen_interval > hapd->conf->max_listen_interval) {
1275 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1276 HOSTAPD_LEVEL_DEBUG,
1277 "Too large Listen Interval (%d)",
1279 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1283 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1285 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1286 if (resp != WLAN_STATUS_SUCCESS)
1289 if (hostapd_get_aid(hapd, sta) < 0) {
1290 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1291 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1292 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1296 sta->capability = capab_info;
1297 sta->listen_interval = listen_interval;
1299 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1300 sta->flags |= WLAN_STA_NONERP;
1301 for (i = 0; i < sta->supported_rates_len; i++) {
1302 if ((sta->supported_rates[i] & 0x7f) > 22) {
1303 sta->flags &= ~WLAN_STA_NONERP;
1307 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1308 sta->nonerp_set = 1;
1309 hapd->iface->num_sta_non_erp++;
1310 if (hapd->iface->num_sta_non_erp == 1)
1311 ieee802_11_set_beacons(hapd->iface);
1314 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1315 !sta->no_short_slot_time_set) {
1316 sta->no_short_slot_time_set = 1;
1317 hapd->iface->num_sta_no_short_slot_time++;
1318 if (hapd->iface->current_mode->mode ==
1319 HOSTAPD_MODE_IEEE80211G &&
1320 hapd->iface->num_sta_no_short_slot_time == 1)
1321 ieee802_11_set_beacons(hapd->iface);
1324 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1325 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1327 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1329 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1330 !sta->no_short_preamble_set) {
1331 sta->no_short_preamble_set = 1;
1332 hapd->iface->num_sta_no_short_preamble++;
1333 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1334 && hapd->iface->num_sta_no_short_preamble == 1)
1335 ieee802_11_set_beacons(hapd->iface);
1338 #ifdef CONFIG_IEEE80211N
1339 update_ht_state(hapd, sta);
1340 #endif /* CONFIG_IEEE80211N */
1342 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1343 HOSTAPD_LEVEL_DEBUG,
1344 "association OK (aid %d)", sta->aid);
1345 /* Station will be marked associated, after it acknowledges AssocResp
1347 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1349 #ifdef CONFIG_IEEE80211W
1350 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1351 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1352 "SA Query procedure", reassoc ? "re" : "");
1353 /* TODO: Send a protected Disassociate frame to the STA using
1354 * the old key and Reason Code "Previous Authentication no
1355 * longer valid". Make sure this is only sent protected since
1356 * unprotected frame would be received by the STA that is now
1357 * trying to associate.
1360 #endif /* CONFIG_IEEE80211W */
1363 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1367 if (sta->last_assoc_req)
1368 os_free(sta->last_assoc_req);
1369 sta->last_assoc_req = os_malloc(len);
1370 if (sta->last_assoc_req)
1371 os_memcpy(sta->last_assoc_req, mgmt, len);
1373 /* Make sure that the previously registered inactivity timer will not
1374 * remove the STA immediately. */
1375 sta->timeout_next = STA_NULLFUNC;
1378 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1382 static void handle_disassoc(struct hostapd_data *hapd,
1383 const struct ieee80211_mgmt *mgmt, size_t len)
1385 struct sta_info *sta;
1387 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1388 printf("handle_disassoc - too short payload (len=%lu)\n",
1389 (unsigned long) len);
1393 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1395 le_to_host16(mgmt->u.disassoc.reason_code));
1397 sta = ap_get_sta(hapd, mgmt->sa);
1399 printf("Station " MACSTR " trying to disassociate, but it "
1400 "is not associated.\n", MAC2STR(mgmt->sa));
1404 ap_sta_set_authorized(hapd, sta, 0);
1405 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1406 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1407 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1408 HOSTAPD_LEVEL_INFO, "disassociated");
1409 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1410 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1411 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1413 accounting_sta_stop(hapd, sta);
1414 ieee802_1x_free_station(sta);
1415 hostapd_drv_sta_remove(hapd, sta->addr);
1417 if (sta->timeout_next == STA_NULLFUNC ||
1418 sta->timeout_next == STA_DISASSOC) {
1419 sta->timeout_next = STA_DEAUTH;
1420 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1421 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1425 mlme_disassociate_indication(
1426 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1430 static void handle_deauth(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.deauth)) {
1436 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1437 "payload (len=%lu)", (unsigned long) len);
1441 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1443 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1445 sta = ap_get_sta(hapd, mgmt->sa);
1447 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1448 "to deauthenticate, but it is not authenticated",
1453 ap_sta_set_authorized(hapd, sta, 0);
1454 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1455 WLAN_STA_ASSOC_REQ_OK);
1456 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1457 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1458 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1459 mlme_deauthenticate_indication(
1460 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1461 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1462 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1463 ap_free_sta(hapd, sta);
1467 static void handle_beacon(struct hostapd_data *hapd,
1468 const struct ieee80211_mgmt *mgmt, size_t len,
1469 struct hostapd_frame_info *fi)
1471 struct ieee802_11_elems elems;
1473 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1474 printf("handle_beacon - too short payload (len=%lu)\n",
1475 (unsigned long) len);
1479 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1480 len - (IEEE80211_HDRLEN +
1481 sizeof(mgmt->u.beacon)), &elems,
1484 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1488 #ifdef CONFIG_IEEE80211W
1490 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1491 const struct ieee80211_mgmt *mgmt,
1496 end = mgmt->u.action.u.sa_query_resp.trans_id +
1497 WLAN_SA_QUERY_TR_ID_LEN;
1498 if (((u8 *) mgmt) + len < end) {
1499 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1500 "frame (len=%lu)", (unsigned long) len);
1504 ieee802_11_sa_query_action(hapd, mgmt->sa,
1505 mgmt->u.action.u.sa_query_resp.action,
1506 mgmt->u.action.u.sa_query_resp.trans_id);
1510 static int robust_action_frame(u8 category)
1512 return category != WLAN_ACTION_PUBLIC &&
1513 category != WLAN_ACTION_HT;
1515 #endif /* CONFIG_IEEE80211W */
1519 static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
1520 const struct ieee80211_mgmt *mgmt,
1523 struct rx_action action;
1524 if (len < IEEE80211_HDRLEN + 2)
1526 os_memset(&action, 0, sizeof(action));
1527 action.da = mgmt->da;
1528 action.sa = mgmt->sa;
1529 action.bssid = mgmt->bssid;
1530 action.category = mgmt->u.action.category;
1531 action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
1532 action.len = len - IEEE80211_HDRLEN - 1;
1533 action.freq = hapd->iface->freq;
1534 ieee802_11_rx_wnm_action_ap(hapd, &action);
1536 #endif /* CONFIG_WNM */
1539 static void handle_action(struct hostapd_data *hapd,
1540 const struct ieee80211_mgmt *mgmt, size_t len)
1542 struct sta_info *sta;
1543 sta = ap_get_sta(hapd, mgmt->sa);
1545 if (len < IEEE80211_HDRLEN + 1) {
1546 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1547 HOSTAPD_LEVEL_DEBUG,
1548 "handle_action - too short payload (len=%lu)",
1549 (unsigned long) len);
1553 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1554 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1555 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1556 "frame (category=%u) from unassociated STA " MACSTR,
1557 MAC2STR(mgmt->sa), mgmt->u.action.category);
1561 #ifdef CONFIG_IEEE80211W
1562 if (sta && (sta->flags & WLAN_STA_MFP) &&
1563 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1564 robust_action_frame(mgmt->u.action.category))) {
1565 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1566 HOSTAPD_LEVEL_DEBUG,
1567 "Dropped unprotected Robust Action frame from "
1571 #endif /* CONFIG_IEEE80211W */
1573 switch (mgmt->u.action.category) {
1574 #ifdef CONFIG_IEEE80211R
1575 case WLAN_ACTION_FT:
1576 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1577 len - IEEE80211_HDRLEN))
1580 #endif /* CONFIG_IEEE80211R */
1581 case WLAN_ACTION_WMM:
1582 hostapd_wmm_action(hapd, mgmt, len);
1584 #ifdef CONFIG_IEEE80211W
1585 case WLAN_ACTION_SA_QUERY:
1586 hostapd_sa_query_action(hapd, mgmt, len);
1588 #endif /* CONFIG_IEEE80211W */
1590 case WLAN_ACTION_WNM:
1591 hostapd_wnm_action(hapd, sta, mgmt, len);
1593 #endif /* CONFIG_WNM */
1594 case WLAN_ACTION_PUBLIC:
1595 if (hapd->public_action_cb) {
1596 hapd->public_action_cb(hapd->public_action_cb_ctx,
1602 case WLAN_ACTION_VENDOR_SPECIFIC:
1603 if (hapd->vendor_action_cb) {
1604 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1606 hapd->iface->freq) == 0)
1612 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1613 HOSTAPD_LEVEL_DEBUG,
1614 "handle_action - unknown action category %d or invalid "
1616 mgmt->u.action.category);
1617 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1618 !(mgmt->sa[0] & 0x01)) {
1619 struct ieee80211_mgmt *resp;
1622 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1623 * Return the Action frame to the source without change
1624 * except that MSB of the Category set to 1.
1626 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1627 "frame back to sender");
1628 resp = os_malloc(len);
1631 os_memcpy(resp, mgmt, len);
1632 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1633 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1634 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1635 resp->u.action.category |= 0x80;
1637 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1638 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1647 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1648 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1650 * @buf: management frame data (starting from IEEE 802.11 header)
1651 * @len: length of frame data in octets
1652 * @fi: meta data about received frame (signal level, etc.)
1654 * Process all incoming IEEE 802.11 management frames. This will be called for
1655 * each frame received from the kernel driver through wlan#ap interface. In
1656 * addition, it can be called to re-inserted pending frames (e.g., when using
1657 * external RADIUS server as an MAC ACL).
1659 void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1660 struct hostapd_frame_info *fi)
1662 struct ieee80211_mgmt *mgmt;
1669 mgmt = (struct ieee80211_mgmt *) buf;
1670 fc = le_to_host16(mgmt->frame_control);
1671 stype = WLAN_FC_GET_STYPE(fc);
1673 if (stype == WLAN_FC_STYPE_BEACON) {
1674 handle_beacon(hapd, mgmt, len, fi);
1678 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1679 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1680 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1684 /* Invitation responses can be sent with the peer MAC as BSSID */
1685 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1686 stype == WLAN_FC_STYPE_ACTION) &&
1687 #endif /* CONFIG_P2P */
1688 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1689 printf("MGMT: BSSID=" MACSTR " not our address\n",
1690 MAC2STR(mgmt->bssid));
1695 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1696 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1700 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1701 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1702 HOSTAPD_LEVEL_DEBUG,
1703 "MGMT: DA=" MACSTR " not our address",
1709 case WLAN_FC_STYPE_AUTH:
1710 wpa_printf(MSG_DEBUG, "mgmt::auth");
1711 handle_auth(hapd, mgmt, len);
1713 case WLAN_FC_STYPE_ASSOC_REQ:
1714 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1715 handle_assoc(hapd, mgmt, len, 0);
1717 case WLAN_FC_STYPE_REASSOC_REQ:
1718 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1719 handle_assoc(hapd, mgmt, len, 1);
1721 case WLAN_FC_STYPE_DISASSOC:
1722 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1723 handle_disassoc(hapd, mgmt, len);
1725 case WLAN_FC_STYPE_DEAUTH:
1726 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1727 handle_deauth(hapd, mgmt, len);
1729 case WLAN_FC_STYPE_ACTION:
1730 wpa_printf(MSG_DEBUG, "mgmt::action");
1731 handle_action(hapd, mgmt, len);
1734 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1735 HOSTAPD_LEVEL_DEBUG,
1736 "unknown mgmt frame subtype %d", stype);
1742 static void handle_auth_cb(struct hostapd_data *hapd,
1743 const struct ieee80211_mgmt *mgmt,
1746 u16 auth_alg, auth_transaction, status_code;
1747 struct sta_info *sta;
1750 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1751 HOSTAPD_LEVEL_NOTICE,
1752 "did not acknowledge authentication response");
1756 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1757 printf("handle_auth_cb - too short payload (len=%lu)\n",
1758 (unsigned long) len);
1762 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1763 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1764 status_code = le_to_host16(mgmt->u.auth.status_code);
1766 sta = ap_get_sta(hapd, mgmt->da);
1768 printf("handle_auth_cb: STA " MACSTR " not found\n",
1773 if (status_code == WLAN_STATUS_SUCCESS &&
1774 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1775 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1776 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1777 HOSTAPD_LEVEL_INFO, "authenticated");
1778 sta->flags |= WLAN_STA_AUTH;
1783 static void handle_assoc_cb(struct hostapd_data *hapd,
1784 const struct ieee80211_mgmt *mgmt,
1785 size_t len, int reassoc, int ok)
1788 struct sta_info *sta;
1790 struct ieee80211_ht_capabilities ht_cap;
1791 struct ieee80211_vht_capabilities vht_cap;
1793 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1794 sizeof(mgmt->u.assoc_resp))) {
1795 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1796 "(len=%lu)\n", reassoc, (unsigned long) len);
1800 sta = ap_get_sta(hapd, mgmt->da);
1802 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1808 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1809 HOSTAPD_LEVEL_DEBUG,
1810 "did not acknowledge association response");
1811 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1816 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1818 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1820 if (status != WLAN_STATUS_SUCCESS)
1823 /* Stop previous accounting session, if one is started, and allocate
1824 * new session id for the new session. */
1825 accounting_sta_stop(hapd, sta);
1827 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1829 "associated (aid %d)",
1832 if (sta->flags & WLAN_STA_ASSOC)
1834 sta->flags |= WLAN_STA_ASSOC;
1835 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1836 sta->auth_alg == WLAN_AUTH_FT) {
1838 * Open, static WEP, or FT protocol; no separate authorization
1841 ap_sta_set_authorized(hapd, sta, 1);
1845 mlme_reassociate_indication(hapd, sta);
1847 mlme_associate_indication(hapd, sta);
1849 #ifdef CONFIG_IEEE80211W
1850 sta->sa_query_timed_out = 0;
1851 #endif /* CONFIG_IEEE80211W */
1854 * Remove the STA entry in order to make sure the STA PS state gets
1855 * cleared and configuration gets updated in case of reassociation back
1858 hostapd_drv_sta_remove(hapd, sta->addr);
1860 #ifdef CONFIG_IEEE80211N
1861 if (sta->flags & WLAN_STA_HT)
1862 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1863 #endif /* CONFIG_IEEE80211N */
1864 #ifdef CONFIG_IEEE80211AC
1865 if (sta->flags & WLAN_STA_VHT)
1866 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1867 #endif /* CONFIG_IEEE80211AC */
1869 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1870 sta->supported_rates, sta->supported_rates_len,
1871 sta->listen_interval,
1872 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1873 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1874 sta->flags, sta->qosinfo)) {
1875 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1876 HOSTAPD_LEVEL_NOTICE,
1877 "Could not add STA to kernel driver");
1879 ap_sta_disconnect(hapd, sta, sta->addr,
1880 WLAN_REASON_DISASSOC_AP_BUSY);
1885 if (sta->flags & WLAN_STA_WDS)
1886 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1888 if (sta->eapol_sm == NULL) {
1890 * This STA does not use RADIUS server for EAP authentication,
1891 * so bind it to the selected VLAN interface now, since the
1892 * interface selection is not going to change anymore.
1894 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1896 } else if (sta->vlan_id) {
1897 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1898 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1902 hostapd_set_sta_flags(hapd, sta);
1904 if (sta->auth_alg == WLAN_AUTH_FT)
1905 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1907 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1908 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1910 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1913 /* Copy of the association request is not needed anymore */
1914 if (sta->last_assoc_req) {
1915 os_free(sta->last_assoc_req);
1916 sta->last_assoc_req = NULL;
1921 static void handle_deauth_cb(struct hostapd_data *hapd,
1922 const struct ieee80211_mgmt *mgmt,
1925 struct sta_info *sta;
1926 if (mgmt->da[0] & 0x01)
1928 sta = ap_get_sta(hapd, mgmt->da);
1930 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
1931 " not found", MAC2STR(mgmt->da));
1935 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
1936 MAC2STR(sta->addr));
1938 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1939 "deauth", MAC2STR(sta->addr));
1941 ap_sta_deauth_cb(hapd, sta);
1945 static void handle_disassoc_cb(struct hostapd_data *hapd,
1946 const struct ieee80211_mgmt *mgmt,
1949 struct sta_info *sta;
1950 if (mgmt->da[0] & 0x01)
1952 sta = ap_get_sta(hapd, mgmt->da);
1954 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
1955 " not found", MAC2STR(mgmt->da));
1959 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
1960 MAC2STR(sta->addr));
1962 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1963 "disassoc", MAC2STR(sta->addr));
1965 ap_sta_disassoc_cb(hapd, sta);
1970 * ieee802_11_mgmt_cb - Process management frame TX status callback
1971 * @hapd: hostapd BSS data structure (the BSS from which the management frame
1973 * @buf: management frame data (starting from IEEE 802.11 header)
1974 * @len: length of frame data in octets
1975 * @stype: management frame subtype from frame control field
1976 * @ok: Whether the frame was ACK'ed
1978 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
1981 const struct ieee80211_mgmt *mgmt;
1982 mgmt = (const struct ieee80211_mgmt *) buf;
1985 case WLAN_FC_STYPE_AUTH:
1986 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1987 handle_auth_cb(hapd, mgmt, len, ok);
1989 case WLAN_FC_STYPE_ASSOC_RESP:
1990 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1991 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1993 case WLAN_FC_STYPE_REASSOC_RESP:
1994 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1995 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1997 case WLAN_FC_STYPE_PROBE_RESP:
1998 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2000 case WLAN_FC_STYPE_DEAUTH:
2001 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2002 handle_deauth_cb(hapd, mgmt, len, ok);
2004 case WLAN_FC_STYPE_DISASSOC:
2005 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2006 handle_disassoc_cb(hapd, mgmt, len, ok);
2008 case WLAN_FC_STYPE_ACTION:
2009 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2012 printf("unknown mgmt cb frame subtype %d\n", stype);
2018 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2025 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2026 char *buf, size_t buflen)
2033 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2034 const u8 *buf, size_t len, int ack)
2036 struct sta_info *sta;
2037 struct hostapd_iface *iface = hapd->iface;
2039 sta = ap_get_sta(hapd, addr);
2040 if (sta == NULL && iface->num_bss > 1) {
2042 for (j = 0; j < iface->num_bss; j++) {
2043 hapd = iface->bss[j];
2044 sta = ap_get_sta(hapd, addr);
2049 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2051 if (sta->flags & WLAN_STA_PENDING_POLL) {
2052 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2053 "activity poll", MAC2STR(sta->addr),
2054 ack ? "ACKed" : "did not ACK");
2056 sta->flags &= ~WLAN_STA_PENDING_POLL;
2059 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2063 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2064 const u8 *data, size_t len, int ack)
2066 struct sta_info *sta;
2067 struct hostapd_iface *iface = hapd->iface;
2069 sta = ap_get_sta(hapd, dst);
2070 if (sta == NULL && iface->num_bss > 1) {
2072 for (j = 0; j < iface->num_bss; j++) {
2073 hapd = iface->bss[j];
2074 sta = ap_get_sta(hapd, dst);
2079 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2080 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2081 MACSTR " that is not currently associated",
2086 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2090 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2092 struct sta_info *sta;
2093 struct hostapd_iface *iface = hapd->iface;
2095 sta = ap_get_sta(hapd, addr);
2096 if (sta == NULL && iface->num_bss > 1) {
2098 for (j = 0; j < iface->num_bss; j++) {
2099 hapd = iface->bss[j];
2100 sta = ap_get_sta(hapd, addr);
2107 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2110 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2111 "activity poll", MAC2STR(sta->addr));
2112 sta->flags &= ~WLAN_STA_PENDING_POLL;
2116 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2119 struct sta_info *sta;
2121 sta = ap_get_sta(hapd, src);
2122 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2123 if (!hapd->conf->wds_sta)
2126 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2127 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2128 "STA " MACSTR " (aid %u)",
2129 MAC2STR(sta->addr), sta->aid);
2130 sta->flags |= WLAN_STA_WDS;
2131 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
2136 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2137 MACSTR, MAC2STR(src));
2138 if (src[0] & 0x01) {
2139 /* Broadcast bit set in SA?! Ignore the frame silently. */
2143 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2144 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2145 "already been sent, but no TX status yet known - "
2146 "ignore Class 3 frame issue with " MACSTR,
2151 if (sta && (sta->flags & WLAN_STA_AUTH))
2152 hostapd_drv_sta_disassoc(
2154 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2156 hostapd_drv_sta_deauth(
2158 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2162 #endif /* CONFIG_NATIVE_WINDOWS */