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 if (random_get_bytes(hapd->sae_token_key,
420 sizeof(hapd->sae_token_key)) < 0)
422 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
423 hapd->sae_token_key, sizeof(hapd->sae_token_key));
424 hapd->last_sae_token_key_update = t.sec;
427 buf = wpabuf_alloc(SHA256_MAC_LEN);
431 token = wpabuf_put(buf, SHA256_MAC_LEN);
432 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
433 addr, ETH_ALEN, token);
439 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
440 const struct ieee80211_mgmt *mgmt, size_t len,
443 u16 resp = WLAN_STATUS_SUCCESS;
444 struct wpabuf *data = NULL;
447 if (auth_transaction != 1)
449 sta->sae = os_zalloc(sizeof(*sta->sae));
450 if (sta->sae == NULL)
452 sta->sae->state = SAE_NOTHING;
455 if (auth_transaction == 1) {
456 const u8 *token = NULL;
457 size_t token_len = 0;
458 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
460 "start SAE authentication (RX commit)");
461 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
462 ((const u8 *) mgmt) + len -
463 mgmt->u.auth.variable, &token,
464 &token_len, hapd->conf->sae_groups);
465 if (token && check_sae_token(hapd, sta->addr, token, token_len)
467 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
468 "incorrect token from " MACSTR,
473 if (resp == WLAN_STATUS_SUCCESS) {
474 if (!token && use_sae_anti_clogging(hapd)) {
475 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
476 "clogging token from " MACSTR,
478 data = auth_build_token_req(hapd, sta->addr);
479 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
481 data = auth_process_sae_commit(hapd, sta);
483 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
485 sta->sae->state = SAE_COMMITTED;
488 } else if (auth_transaction == 2) {
489 if (sta->sae->state != SAE_COMMITTED) {
490 hostapd_logger(hapd, sta->addr,
491 HOSTAPD_MODULE_IEEE80211,
493 "SAE confirm before commit");
494 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
496 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
498 "SAE authentication (RX confirm)");
499 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
500 ((u8 *) mgmt) + len -
501 mgmt->u.auth.variable) < 0) {
502 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
504 resp = WLAN_STATUS_SUCCESS;
505 sta->flags |= WLAN_STA_AUTH;
506 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
507 sta->auth_alg = WLAN_AUTH_SAE;
508 mlme_authenticate_indication(hapd, sta);
510 data = auth_build_sae_confirm(hapd, sta);
512 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
514 sta->sae->state = SAE_ACCEPTED;
515 sae_clear_temp_data(sta->sae);
519 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
521 "unexpected SAE authentication transaction %u",
523 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
526 sta->auth_alg = WLAN_AUTH_SAE;
528 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
529 auth_transaction, resp,
530 data ? wpabuf_head(data) : (u8 *) "",
531 data ? wpabuf_len(data) : 0);
534 #endif /* CONFIG_SAE */
537 static void handle_auth(struct hostapd_data *hapd,
538 const struct ieee80211_mgmt *mgmt, size_t len)
540 u16 auth_alg, auth_transaction, status_code;
541 u16 resp = WLAN_STATUS_SUCCESS;
542 struct sta_info *sta = NULL;
545 const u8 *challenge = NULL;
546 u32 session_timeout, acct_interim_interval;
548 struct hostapd_sta_wpa_psk_short *psk = NULL;
549 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
550 size_t resp_ies_len = 0;
551 char *identity = NULL;
552 char *radius_cui = NULL;
554 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
555 printf("handle_auth - too short payload (len=%lu)\n",
556 (unsigned long) len);
560 #ifdef CONFIG_TESTING_OPTIONS
561 if (hapd->iconf->ignore_auth_probability > 0.0d &&
562 drand48() < hapd->iconf->ignore_auth_probability) {
564 "TESTING: ignoring auth frame from " MACSTR,
568 #endif /* CONFIG_TESTING_OPTIONS */
570 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
571 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
572 status_code = le_to_host16(mgmt->u.auth.status_code);
573 fc = le_to_host16(mgmt->frame_control);
575 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
576 2 + WLAN_AUTH_CHALLENGE_LEN &&
577 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
578 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
579 challenge = &mgmt->u.auth.variable[2];
581 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
582 "auth_transaction=%d status_code=%d wep=%d%s",
583 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
584 status_code, !!(fc & WLAN_FC_ISWEP),
585 challenge ? " challenge" : "");
587 if (hapd->tkip_countermeasures) {
588 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
592 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
593 auth_alg == WLAN_AUTH_OPEN) ||
594 #ifdef CONFIG_IEEE80211R
595 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
596 auth_alg == WLAN_AUTH_FT) ||
597 #endif /* CONFIG_IEEE80211R */
599 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
600 auth_alg == WLAN_AUTH_SAE) ||
601 #endif /* CONFIG_SAE */
602 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
603 auth_alg == WLAN_AUTH_SHARED_KEY))) {
604 printf("Unsupported authentication algorithm (%d)\n",
606 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
610 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
611 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
612 printf("Unknown authentication transaction number (%d)\n",
614 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
618 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
619 printf("Station " MACSTR " not allowed to authenticate.\n",
621 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
625 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
627 &acct_interim_interval, &vlan_id,
628 &psk, &identity, &radius_cui);
630 if (res == HOSTAPD_ACL_REJECT) {
631 printf("Station " MACSTR " not allowed to authenticate.\n",
633 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
636 if (res == HOSTAPD_ACL_PENDING) {
637 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
638 " waiting for an external authentication",
640 /* Authentication code will re-send the authentication frame
641 * after it has received (and cached) information from the
642 * external source. */
646 sta = ap_sta_add(hapd, mgmt->sa);
648 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
653 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
655 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
656 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
657 "%d received from RADIUS server",
659 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
662 sta->vlan_id = vlan_id;
663 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
664 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
667 hostapd_free_psk_list(sta->psk);
668 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
675 sta->identity = identity;
677 sta->radius_cui = radius_cui;
680 sta->flags &= ~WLAN_STA_PREAUTH;
681 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
683 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
684 sta->acct_interim_interval = acct_interim_interval;
685 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
686 ap_sta_session_timeout(hapd, sta, session_timeout);
688 ap_sta_no_session_timeout(hapd, sta);
692 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
694 "authentication OK (open system)");
695 #ifdef IEEE80211_REQUIRE_AUTH_ACK
696 /* Station will be marked authenticated if it ACKs the
697 * authentication reply. */
699 sta->flags |= WLAN_STA_AUTH;
700 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
701 sta->auth_alg = WLAN_AUTH_OPEN;
702 mlme_authenticate_indication(hapd, sta);
705 case WLAN_AUTH_SHARED_KEY:
706 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
708 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
709 mlme_authenticate_indication(hapd, sta);
710 if (sta->challenge && auth_transaction == 1) {
711 resp_ies[0] = WLAN_EID_CHALLENGE;
712 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
713 os_memcpy(resp_ies + 2, sta->challenge,
714 WLAN_AUTH_CHALLENGE_LEN);
715 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
718 #ifdef CONFIG_IEEE80211R
720 sta->auth_alg = WLAN_AUTH_FT;
721 if (sta->wpa_sm == NULL)
722 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
724 if (sta->wpa_sm == NULL) {
725 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
727 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
730 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
731 auth_transaction, mgmt->u.auth.variable,
732 len - IEEE80211_HDRLEN -
733 sizeof(mgmt->u.auth),
734 handle_auth_ft_finish, hapd);
735 /* handle_auth_ft_finish() callback will complete auth. */
737 #endif /* CONFIG_IEEE80211R */
740 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
742 #endif /* CONFIG_SAE */
748 hostapd_free_psk_list(psk);
750 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
751 auth_transaction + 1, resp, resp_ies, resp_ies_len);
755 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
759 /* get a unique AID */
761 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
765 for (i = 0; i < AID_WORDS; i++) {
766 if (hapd->sta_aid[i] == (u32) -1)
768 for (j = 0; j < 32; j++) {
769 if (!(hapd->sta_aid[i] & BIT(j)))
777 aid = i * 32 + j + 1;
782 hapd->sta_aid[i] |= BIT(j);
783 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
788 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
789 const u8 *ssid_ie, size_t ssid_ie_len)
792 return WLAN_STATUS_UNSPECIFIED_FAILURE;
794 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
795 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
797 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
798 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
800 "Station tried to associate with unknown SSID "
802 return WLAN_STATUS_UNSPECIFIED_FAILURE;
805 return WLAN_STATUS_SUCCESS;
809 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
810 const u8 *wmm_ie, size_t wmm_ie_len)
812 sta->flags &= ~WLAN_STA_WMM;
814 if (wmm_ie && hapd->conf->wmm_enabled) {
815 struct wmm_information_element *wmm;
817 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
818 hostapd_logger(hapd, sta->addr,
821 "invalid WMM element in association "
823 return WLAN_STATUS_UNSPECIFIED_FAILURE;
826 sta->flags |= WLAN_STA_WMM;
827 wmm = (struct wmm_information_element *) wmm_ie;
828 sta->qosinfo = wmm->qos_info;
830 return WLAN_STATUS_SUCCESS;
834 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
835 struct ieee802_11_elems *elems)
837 if (!elems->supp_rates) {
838 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
840 "No supported rates element in AssocReq");
841 return WLAN_STATUS_UNSPECIFIED_FAILURE;
844 if (elems->supp_rates_len + elems->ext_supp_rates_len >
845 sizeof(sta->supported_rates)) {
846 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
848 "Invalid supported rates element length %d+%d",
849 elems->supp_rates_len,
850 elems->ext_supp_rates_len);
851 return WLAN_STATUS_UNSPECIFIED_FAILURE;
854 sta->supported_rates_len = merge_byte_arrays(
855 sta->supported_rates, sizeof(sta->supported_rates),
856 elems->supp_rates, elems->supp_rates_len,
857 elems->ext_supp_rates, elems->ext_supp_rates_len);
859 return WLAN_STATUS_SUCCESS;
863 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
864 const u8 *ies, size_t ies_len, int reassoc)
866 struct ieee802_11_elems elems;
871 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
872 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
873 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
874 "association request");
875 return WLAN_STATUS_UNSPECIFIED_FAILURE;
878 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
879 if (resp != WLAN_STATUS_SUCCESS)
881 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
882 if (resp != WLAN_STATUS_SUCCESS)
884 resp = copy_supp_rates(hapd, sta, &elems);
885 if (resp != WLAN_STATUS_SUCCESS)
887 #ifdef CONFIG_IEEE80211N
888 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
889 elems.ht_capabilities_len);
890 if (resp != WLAN_STATUS_SUCCESS)
892 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
893 !(sta->flags & WLAN_STA_HT)) {
894 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
895 HOSTAPD_LEVEL_INFO, "Station does not support "
896 "mandatory HT PHY - reject association");
897 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
899 #endif /* CONFIG_IEEE80211N */
901 #ifdef CONFIG_IEEE80211AC
902 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
903 elems.vht_capabilities_len);
904 if (resp != WLAN_STATUS_SUCCESS)
906 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
907 !(sta->flags & WLAN_STA_VHT)) {
908 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
909 HOSTAPD_LEVEL_INFO, "Station does not support "
910 "mandatory VHT PHY - reject association");
911 return WLAN_STATUS_UNSPECIFIED_FAILURE;
913 #endif /* CONFIG_IEEE80211AC */
915 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
916 wpa_ie = elems.rsn_ie;
917 wpa_ie_len = elems.rsn_ie_len;
918 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
920 wpa_ie = elems.wpa_ie;
921 wpa_ie_len = elems.wpa_ie_len;
928 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
929 if (hapd->conf->wps_state && elems.wps_ie) {
930 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
931 "Request - assume WPS is used");
932 sta->flags |= WLAN_STA_WPS;
933 wpabuf_free(sta->wps_ie);
934 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
936 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
937 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
938 sta->flags |= WLAN_STA_WPS2;
942 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
943 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
944 "(Re)Association Request - reject");
945 return WLAN_STATUS_INVALID_IE;
947 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
948 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
949 "(Re)Association Request - possible WPS use");
950 sta->flags |= WLAN_STA_MAYBE_WPS;
952 #endif /* CONFIG_WPS */
953 if (hapd->conf->wpa && wpa_ie == NULL) {
954 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
956 "No WPA/RSN IE in association request");
957 return WLAN_STATUS_INVALID_IE;
960 if (hapd->conf->wpa && wpa_ie) {
964 if (sta->wpa_sm == NULL)
965 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
967 if (sta->wpa_sm == NULL) {
968 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
970 return WLAN_STATUS_UNSPECIFIED_FAILURE;
972 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
974 elems.mdie, elems.mdie_len);
975 if (res == WPA_INVALID_GROUP)
976 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
977 else if (res == WPA_INVALID_PAIRWISE)
978 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
979 else if (res == WPA_INVALID_AKMP)
980 resp = WLAN_STATUS_AKMP_NOT_VALID;
981 else if (res == WPA_ALLOC_FAIL)
982 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
983 #ifdef CONFIG_IEEE80211W
984 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
985 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
986 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
987 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
988 #endif /* CONFIG_IEEE80211W */
989 else if (res == WPA_INVALID_MDIE)
990 resp = WLAN_STATUS_INVALID_MDIE;
991 else if (res != WPA_IE_OK)
992 resp = WLAN_STATUS_INVALID_IE;
993 if (resp != WLAN_STATUS_SUCCESS)
995 #ifdef CONFIG_IEEE80211W
996 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
997 sta->sa_query_count > 0)
998 ap_check_sa_query_timeout(hapd, sta);
999 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1000 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1002 * STA has already been associated with MFP and SA
1003 * Query timeout has not been reached. Reject the
1004 * association attempt temporarily and start SA Query,
1005 * if one is not pending.
1008 if (sta->sa_query_count == 0)
1009 ap_sta_start_sa_query(hapd, sta);
1011 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1014 if (wpa_auth_uses_mfp(sta->wpa_sm))
1015 sta->flags |= WLAN_STA_MFP;
1017 sta->flags &= ~WLAN_STA_MFP;
1018 #endif /* CONFIG_IEEE80211W */
1020 #ifdef CONFIG_IEEE80211R
1021 if (sta->auth_alg == WLAN_AUTH_FT) {
1023 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1024 "to use association (not "
1025 "re-association) with FT auth_alg",
1026 MAC2STR(sta->addr));
1027 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1030 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1032 if (resp != WLAN_STATUS_SUCCESS)
1035 #endif /* CONFIG_IEEE80211R */
1038 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1039 sta->auth_alg != WLAN_AUTH_SAE) {
1040 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1041 "SAE AKM after non-SAE auth_alg %u",
1042 MAC2STR(sta->addr), sta->auth_alg);
1043 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1045 #endif /* CONFIG_SAE */
1047 #ifdef CONFIG_IEEE80211N
1048 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
1049 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1050 hostapd_logger(hapd, sta->addr,
1051 HOSTAPD_MODULE_IEEE80211,
1053 "Station tried to use TKIP with HT "
1055 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1057 #endif /* CONFIG_IEEE80211N */
1059 wpa_auth_sta_no_wpa(sta->wpa_sm);
1063 wpabuf_free(sta->p2p_ie);
1064 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1065 P2P_IE_VENDOR_TYPE);
1068 wpabuf_free(sta->p2p_ie);
1072 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1073 #endif /* CONFIG_P2P */
1076 wpabuf_free(sta->hs20_ie);
1077 if (elems.hs20 && elems.hs20_len > 4) {
1078 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1079 elems.hs20_len - 4);
1081 sta->hs20_ie = NULL;
1082 #endif /* CONFIG_HS20 */
1084 return WLAN_STATUS_SUCCESS;
1088 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1092 struct ieee80211_mgmt reply;
1094 os_memset(&reply, 0, sizeof(reply));
1095 reply.frame_control =
1096 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1097 os_memcpy(reply.da, addr, ETH_ALEN);
1098 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1099 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1101 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1102 reply.u.deauth.reason_code = host_to_le16(reason_code);
1104 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
1105 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1110 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1111 u16 status_code, int reassoc, const u8 *ies,
1115 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1116 struct ieee80211_mgmt *reply;
1119 os_memset(buf, 0, sizeof(buf));
1120 reply = (struct ieee80211_mgmt *) buf;
1121 reply->frame_control =
1122 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1123 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1124 WLAN_FC_STYPE_ASSOC_RESP));
1125 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1126 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1127 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1129 send_len = IEEE80211_HDRLEN;
1130 send_len += sizeof(reply->u.assoc_resp);
1131 reply->u.assoc_resp.capab_info =
1132 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1133 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1134 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1135 | BIT(14) | BIT(15));
1136 /* Supported rates */
1137 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1138 /* Extended supported rates */
1139 p = hostapd_eid_ext_supp_rates(hapd, p);
1141 #ifdef CONFIG_IEEE80211R
1142 if (status_code == WLAN_STATUS_SUCCESS) {
1143 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1144 * Transition Information, RSN, [RIC Response] */
1145 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1146 buf + sizeof(buf) - p,
1147 sta->auth_alg, ies, ies_len);
1149 #endif /* CONFIG_IEEE80211R */
1151 #ifdef CONFIG_IEEE80211W
1152 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1153 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1154 #endif /* CONFIG_IEEE80211W */
1156 #ifdef CONFIG_IEEE80211N
1157 p = hostapd_eid_ht_capabilities(hapd, p);
1158 p = hostapd_eid_ht_operation(hapd, p);
1159 #endif /* CONFIG_IEEE80211N */
1161 #ifdef CONFIG_IEEE80211AC
1162 p = hostapd_eid_vht_capabilities(hapd, p);
1163 p = hostapd_eid_vht_operation(hapd, p);
1164 #endif /* CONFIG_IEEE80211AC */
1166 p = hostapd_eid_ext_capab(hapd, p);
1167 p = hostapd_eid_bss_max_idle_period(hapd, p);
1169 if (sta->flags & WLAN_STA_WMM)
1170 p = hostapd_eid_wmm(hapd, p);
1173 if ((sta->flags & WLAN_STA_WPS) ||
1174 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
1175 struct wpabuf *wps = wps_build_assoc_resp_ie();
1177 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1178 p += wpabuf_len(wps);
1182 #endif /* CONFIG_WPS */
1186 struct wpabuf *p2p_resp_ie;
1187 enum p2p_status_code status;
1188 switch (status_code) {
1189 case WLAN_STATUS_SUCCESS:
1190 status = P2P_SC_SUCCESS;
1192 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1193 status = P2P_SC_FAIL_LIMIT_REACHED;
1196 status = P2P_SC_FAIL_INVALID_PARAMS;
1199 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1201 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1202 wpabuf_len(p2p_resp_ie));
1203 p += wpabuf_len(p2p_resp_ie);
1204 wpabuf_free(p2p_resp_ie);
1207 #endif /* CONFIG_P2P */
1209 #ifdef CONFIG_P2P_MANAGER
1210 if (hapd->conf->p2p & P2P_MANAGE)
1211 p = hostapd_eid_p2p_manage(hapd, p);
1212 #endif /* CONFIG_P2P_MANAGER */
1214 send_len += p - reply->u.assoc_resp.variable;
1216 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1217 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1222 static void handle_assoc(struct hostapd_data *hapd,
1223 const struct ieee80211_mgmt *mgmt, size_t len,
1226 u16 capab_info, listen_interval;
1227 u16 resp = WLAN_STATUS_SUCCESS;
1230 struct sta_info *sta;
1232 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1233 sizeof(mgmt->u.assoc_req))) {
1234 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1235 "\n", reassoc, (unsigned long) len);
1239 #ifdef CONFIG_TESTING_OPTIONS
1241 if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
1242 drand48() < hapd->iconf->ignore_reassoc_probability) {
1243 wpa_printf(MSG_INFO,
1244 "TESTING: ignoring reassoc request from "
1245 MACSTR, MAC2STR(mgmt->sa));
1249 if (hapd->iconf->ignore_assoc_probability > 0.0d &&
1250 drand48() < hapd->iconf->ignore_assoc_probability) {
1251 wpa_printf(MSG_INFO,
1252 "TESTING: ignoring assoc request from "
1253 MACSTR, MAC2STR(mgmt->sa));
1257 #endif /* CONFIG_TESTING_OPTIONS */
1260 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1261 listen_interval = le_to_host16(
1262 mgmt->u.reassoc_req.listen_interval);
1263 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1264 " capab_info=0x%02x listen_interval=%d current_ap="
1266 MAC2STR(mgmt->sa), capab_info, listen_interval,
1267 MAC2STR(mgmt->u.reassoc_req.current_ap));
1268 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1269 pos = mgmt->u.reassoc_req.variable;
1271 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1272 listen_interval = le_to_host16(
1273 mgmt->u.assoc_req.listen_interval);
1274 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1275 " capab_info=0x%02x listen_interval=%d",
1276 MAC2STR(mgmt->sa), capab_info, listen_interval);
1277 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1278 pos = mgmt->u.assoc_req.variable;
1281 sta = ap_get_sta(hapd, mgmt->sa);
1282 #ifdef CONFIG_IEEE80211R
1283 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1284 (sta->flags & WLAN_STA_AUTH) == 0) {
1285 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1286 "prior to authentication since it is using "
1287 "over-the-DS FT", MAC2STR(mgmt->sa));
1289 #endif /* CONFIG_IEEE80211R */
1290 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1291 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1292 HOSTAPD_LEVEL_INFO, "Station tried to "
1293 "associate before authentication "
1294 "(aid=%d flags=0x%x)",
1295 sta ? sta->aid : -1,
1296 sta ? sta->flags : 0);
1297 send_deauth(hapd, mgmt->sa,
1298 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1302 if (hapd->tkip_countermeasures) {
1303 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1307 if (listen_interval > hapd->conf->max_listen_interval) {
1308 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1309 HOSTAPD_LEVEL_DEBUG,
1310 "Too large Listen Interval (%d)",
1312 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1316 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1318 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1319 if (resp != WLAN_STATUS_SUCCESS)
1322 if (hostapd_get_aid(hapd, sta) < 0) {
1323 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1324 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1325 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1329 sta->capability = capab_info;
1330 sta->listen_interval = listen_interval;
1332 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1333 sta->flags |= WLAN_STA_NONERP;
1334 for (i = 0; i < sta->supported_rates_len; i++) {
1335 if ((sta->supported_rates[i] & 0x7f) > 22) {
1336 sta->flags &= ~WLAN_STA_NONERP;
1340 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1341 sta->nonerp_set = 1;
1342 hapd->iface->num_sta_non_erp++;
1343 if (hapd->iface->num_sta_non_erp == 1)
1344 ieee802_11_set_beacons(hapd->iface);
1347 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1348 !sta->no_short_slot_time_set) {
1349 sta->no_short_slot_time_set = 1;
1350 hapd->iface->num_sta_no_short_slot_time++;
1351 if (hapd->iface->current_mode->mode ==
1352 HOSTAPD_MODE_IEEE80211G &&
1353 hapd->iface->num_sta_no_short_slot_time == 1)
1354 ieee802_11_set_beacons(hapd->iface);
1357 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1358 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1360 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1362 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1363 !sta->no_short_preamble_set) {
1364 sta->no_short_preamble_set = 1;
1365 hapd->iface->num_sta_no_short_preamble++;
1366 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1367 && hapd->iface->num_sta_no_short_preamble == 1)
1368 ieee802_11_set_beacons(hapd->iface);
1371 #ifdef CONFIG_IEEE80211N
1372 update_ht_state(hapd, sta);
1373 #endif /* CONFIG_IEEE80211N */
1375 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1376 HOSTAPD_LEVEL_DEBUG,
1377 "association OK (aid %d)", sta->aid);
1378 /* Station will be marked associated, after it acknowledges AssocResp
1380 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1382 #ifdef CONFIG_IEEE80211W
1383 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1384 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1385 "SA Query procedure", reassoc ? "re" : "");
1386 /* TODO: Send a protected Disassociate frame to the STA using
1387 * the old key and Reason Code "Previous Authentication no
1388 * longer valid". Make sure this is only sent protected since
1389 * unprotected frame would be received by the STA that is now
1390 * trying to associate.
1393 #endif /* CONFIG_IEEE80211W */
1396 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1400 if (sta->last_assoc_req)
1401 os_free(sta->last_assoc_req);
1402 sta->last_assoc_req = os_malloc(len);
1403 if (sta->last_assoc_req)
1404 os_memcpy(sta->last_assoc_req, mgmt, len);
1406 /* Make sure that the previously registered inactivity timer will not
1407 * remove the STA immediately. */
1408 sta->timeout_next = STA_NULLFUNC;
1411 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1415 static void handle_disassoc(struct hostapd_data *hapd,
1416 const struct ieee80211_mgmt *mgmt, size_t len)
1418 struct sta_info *sta;
1420 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1421 printf("handle_disassoc - too short payload (len=%lu)\n",
1422 (unsigned long) len);
1426 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1428 le_to_host16(mgmt->u.disassoc.reason_code));
1430 sta = ap_get_sta(hapd, mgmt->sa);
1432 printf("Station " MACSTR " trying to disassociate, but it "
1433 "is not associated.\n", MAC2STR(mgmt->sa));
1437 ap_sta_set_authorized(hapd, sta, 0);
1438 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1439 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1440 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1441 HOSTAPD_LEVEL_INFO, "disassociated");
1442 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1443 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1444 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1446 accounting_sta_stop(hapd, sta);
1447 ieee802_1x_free_station(sta);
1448 hostapd_drv_sta_remove(hapd, sta->addr);
1450 if (sta->timeout_next == STA_NULLFUNC ||
1451 sta->timeout_next == STA_DISASSOC) {
1452 sta->timeout_next = STA_DEAUTH;
1453 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1454 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1458 mlme_disassociate_indication(
1459 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1463 static void handle_deauth(struct hostapd_data *hapd,
1464 const struct ieee80211_mgmt *mgmt, size_t len)
1466 struct sta_info *sta;
1468 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1469 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1470 "payload (len=%lu)", (unsigned long) len);
1474 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1476 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1478 sta = ap_get_sta(hapd, mgmt->sa);
1480 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1481 "to deauthenticate, but it is not authenticated",
1486 ap_sta_set_authorized(hapd, sta, 0);
1487 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1488 WLAN_STA_ASSOC_REQ_OK);
1489 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1490 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1491 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1492 mlme_deauthenticate_indication(
1493 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1494 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1495 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1496 ap_free_sta(hapd, sta);
1500 static void handle_beacon(struct hostapd_data *hapd,
1501 const struct ieee80211_mgmt *mgmt, size_t len,
1502 struct hostapd_frame_info *fi)
1504 struct ieee802_11_elems elems;
1506 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1507 printf("handle_beacon - too short payload (len=%lu)\n",
1508 (unsigned long) len);
1512 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1513 len - (IEEE80211_HDRLEN +
1514 sizeof(mgmt->u.beacon)), &elems,
1517 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1521 #ifdef CONFIG_IEEE80211W
1523 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1524 const struct ieee80211_mgmt *mgmt,
1529 end = mgmt->u.action.u.sa_query_resp.trans_id +
1530 WLAN_SA_QUERY_TR_ID_LEN;
1531 if (((u8 *) mgmt) + len < end) {
1532 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1533 "frame (len=%lu)", (unsigned long) len);
1537 ieee802_11_sa_query_action(hapd, mgmt->sa,
1538 mgmt->u.action.u.sa_query_resp.action,
1539 mgmt->u.action.u.sa_query_resp.trans_id);
1543 static int robust_action_frame(u8 category)
1545 return category != WLAN_ACTION_PUBLIC &&
1546 category != WLAN_ACTION_HT;
1548 #endif /* CONFIG_IEEE80211W */
1552 static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
1553 const struct ieee80211_mgmt *mgmt,
1556 struct rx_action action;
1557 if (len < IEEE80211_HDRLEN + 2)
1559 os_memset(&action, 0, sizeof(action));
1560 action.da = mgmt->da;
1561 action.sa = mgmt->sa;
1562 action.bssid = mgmt->bssid;
1563 action.category = mgmt->u.action.category;
1564 action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
1565 action.len = len - IEEE80211_HDRLEN - 1;
1566 action.freq = hapd->iface->freq;
1567 ieee802_11_rx_wnm_action_ap(hapd, &action);
1569 #endif /* CONFIG_WNM */
1572 static void handle_action(struct hostapd_data *hapd,
1573 const struct ieee80211_mgmt *mgmt, size_t len)
1575 struct sta_info *sta;
1576 sta = ap_get_sta(hapd, mgmt->sa);
1578 if (len < IEEE80211_HDRLEN + 1) {
1579 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1580 HOSTAPD_LEVEL_DEBUG,
1581 "handle_action - too short payload (len=%lu)",
1582 (unsigned long) len);
1586 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1587 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1588 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1589 "frame (category=%u) from unassociated STA " MACSTR,
1590 MAC2STR(mgmt->sa), mgmt->u.action.category);
1594 #ifdef CONFIG_IEEE80211W
1595 if (sta && (sta->flags & WLAN_STA_MFP) &&
1596 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1597 robust_action_frame(mgmt->u.action.category))) {
1598 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1599 HOSTAPD_LEVEL_DEBUG,
1600 "Dropped unprotected Robust Action frame from "
1604 #endif /* CONFIG_IEEE80211W */
1606 switch (mgmt->u.action.category) {
1607 #ifdef CONFIG_IEEE80211R
1608 case WLAN_ACTION_FT:
1609 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1610 len - IEEE80211_HDRLEN))
1613 #endif /* CONFIG_IEEE80211R */
1614 case WLAN_ACTION_WMM:
1615 hostapd_wmm_action(hapd, mgmt, len);
1617 #ifdef CONFIG_IEEE80211W
1618 case WLAN_ACTION_SA_QUERY:
1619 hostapd_sa_query_action(hapd, mgmt, len);
1621 #endif /* CONFIG_IEEE80211W */
1623 case WLAN_ACTION_WNM:
1624 hostapd_wnm_action(hapd, sta, mgmt, len);
1626 #endif /* CONFIG_WNM */
1627 case WLAN_ACTION_PUBLIC:
1628 if (hapd->public_action_cb) {
1629 hapd->public_action_cb(hapd->public_action_cb_ctx,
1633 if (hapd->public_action_cb2) {
1634 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
1638 if (hapd->public_action_cb || hapd->public_action_cb2)
1641 case WLAN_ACTION_VENDOR_SPECIFIC:
1642 if (hapd->vendor_action_cb) {
1643 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1645 hapd->iface->freq) == 0)
1651 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1652 HOSTAPD_LEVEL_DEBUG,
1653 "handle_action - unknown action category %d or invalid "
1655 mgmt->u.action.category);
1656 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1657 !(mgmt->sa[0] & 0x01)) {
1658 struct ieee80211_mgmt *resp;
1661 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1662 * Return the Action frame to the source without change
1663 * except that MSB of the Category set to 1.
1665 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1666 "frame back to sender");
1667 resp = os_malloc(len);
1670 os_memcpy(resp, mgmt, len);
1671 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1672 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1673 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1674 resp->u.action.category |= 0x80;
1676 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1677 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1686 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1687 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1689 * @buf: management frame data (starting from IEEE 802.11 header)
1690 * @len: length of frame data in octets
1691 * @fi: meta data about received frame (signal level, etc.)
1693 * Process all incoming IEEE 802.11 management frames. This will be called for
1694 * each frame received from the kernel driver through wlan#ap interface. In
1695 * addition, it can be called to re-inserted pending frames (e.g., when using
1696 * external RADIUS server as an MAC ACL).
1698 void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1699 struct hostapd_frame_info *fi)
1701 struct ieee80211_mgmt *mgmt;
1708 mgmt = (struct ieee80211_mgmt *) buf;
1709 fc = le_to_host16(mgmt->frame_control);
1710 stype = WLAN_FC_GET_STYPE(fc);
1712 if (stype == WLAN_FC_STYPE_BEACON) {
1713 handle_beacon(hapd, mgmt, len, fi);
1717 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1718 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1719 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1723 /* Invitation responses can be sent with the peer MAC as BSSID */
1724 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1725 stype == WLAN_FC_STYPE_ACTION) &&
1726 #endif /* CONFIG_P2P */
1727 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1728 printf("MGMT: BSSID=" MACSTR " not our address\n",
1729 MAC2STR(mgmt->bssid));
1734 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1735 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1739 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1740 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1741 HOSTAPD_LEVEL_DEBUG,
1742 "MGMT: DA=" MACSTR " not our address",
1748 case WLAN_FC_STYPE_AUTH:
1749 wpa_printf(MSG_DEBUG, "mgmt::auth");
1750 handle_auth(hapd, mgmt, len);
1752 case WLAN_FC_STYPE_ASSOC_REQ:
1753 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1754 handle_assoc(hapd, mgmt, len, 0);
1756 case WLAN_FC_STYPE_REASSOC_REQ:
1757 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1758 handle_assoc(hapd, mgmt, len, 1);
1760 case WLAN_FC_STYPE_DISASSOC:
1761 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1762 handle_disassoc(hapd, mgmt, len);
1764 case WLAN_FC_STYPE_DEAUTH:
1765 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1766 handle_deauth(hapd, mgmt, len);
1768 case WLAN_FC_STYPE_ACTION:
1769 wpa_printf(MSG_DEBUG, "mgmt::action");
1770 handle_action(hapd, mgmt, len);
1773 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1774 HOSTAPD_LEVEL_DEBUG,
1775 "unknown mgmt frame subtype %d", stype);
1781 static void handle_auth_cb(struct hostapd_data *hapd,
1782 const struct ieee80211_mgmt *mgmt,
1785 u16 auth_alg, auth_transaction, status_code;
1786 struct sta_info *sta;
1789 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1790 HOSTAPD_LEVEL_NOTICE,
1791 "did not acknowledge authentication response");
1795 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1796 printf("handle_auth_cb - too short payload (len=%lu)\n",
1797 (unsigned long) len);
1801 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1802 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1803 status_code = le_to_host16(mgmt->u.auth.status_code);
1805 sta = ap_get_sta(hapd, mgmt->da);
1807 printf("handle_auth_cb: STA " MACSTR " not found\n",
1812 if (status_code == WLAN_STATUS_SUCCESS &&
1813 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1814 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1815 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1816 HOSTAPD_LEVEL_INFO, "authenticated");
1817 sta->flags |= WLAN_STA_AUTH;
1822 static void handle_assoc_cb(struct hostapd_data *hapd,
1823 const struct ieee80211_mgmt *mgmt,
1824 size_t len, int reassoc, int ok)
1827 struct sta_info *sta;
1829 struct ieee80211_ht_capabilities ht_cap;
1830 struct ieee80211_vht_capabilities vht_cap;
1832 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1833 sizeof(mgmt->u.assoc_resp))) {
1834 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1835 "(len=%lu)\n", reassoc, (unsigned long) len);
1839 sta = ap_get_sta(hapd, mgmt->da);
1841 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1847 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1848 HOSTAPD_LEVEL_DEBUG,
1849 "did not acknowledge association response");
1850 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1855 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1857 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1859 if (status != WLAN_STATUS_SUCCESS)
1862 /* Stop previous accounting session, if one is started, and allocate
1863 * new session id for the new session. */
1864 accounting_sta_stop(hapd, sta);
1866 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1868 "associated (aid %d)",
1871 if (sta->flags & WLAN_STA_ASSOC)
1873 sta->flags |= WLAN_STA_ASSOC;
1874 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1875 sta->auth_alg == WLAN_AUTH_FT) {
1877 * Open, static WEP, or FT protocol; no separate authorization
1880 ap_sta_set_authorized(hapd, sta, 1);
1884 mlme_reassociate_indication(hapd, sta);
1886 mlme_associate_indication(hapd, sta);
1888 #ifdef CONFIG_IEEE80211W
1889 sta->sa_query_timed_out = 0;
1890 #endif /* CONFIG_IEEE80211W */
1893 * Remove the STA entry in order to make sure the STA PS state gets
1894 * cleared and configuration gets updated in case of reassociation back
1897 hostapd_drv_sta_remove(hapd, sta->addr);
1899 #ifdef CONFIG_IEEE80211N
1900 if (sta->flags & WLAN_STA_HT)
1901 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1902 #endif /* CONFIG_IEEE80211N */
1903 #ifdef CONFIG_IEEE80211AC
1904 if (sta->flags & WLAN_STA_VHT)
1905 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1906 #endif /* CONFIG_IEEE80211AC */
1908 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1909 sta->supported_rates, sta->supported_rates_len,
1910 sta->listen_interval,
1911 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1912 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1913 sta->flags, sta->qosinfo)) {
1914 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1915 HOSTAPD_LEVEL_NOTICE,
1916 "Could not add STA to kernel driver");
1918 ap_sta_disconnect(hapd, sta, sta->addr,
1919 WLAN_REASON_DISASSOC_AP_BUSY);
1924 if (sta->flags & WLAN_STA_WDS)
1925 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1927 if (sta->eapol_sm == NULL) {
1929 * This STA does not use RADIUS server for EAP authentication,
1930 * so bind it to the selected VLAN interface now, since the
1931 * interface selection is not going to change anymore.
1933 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1935 } else if (sta->vlan_id) {
1936 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1937 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1941 hostapd_set_sta_flags(hapd, sta);
1943 if (sta->auth_alg == WLAN_AUTH_FT)
1944 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1946 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1947 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1949 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1952 /* Copy of the association request is not needed anymore */
1953 if (sta->last_assoc_req) {
1954 os_free(sta->last_assoc_req);
1955 sta->last_assoc_req = NULL;
1960 static void handle_deauth_cb(struct hostapd_data *hapd,
1961 const struct ieee80211_mgmt *mgmt,
1964 struct sta_info *sta;
1965 if (mgmt->da[0] & 0x01)
1967 sta = ap_get_sta(hapd, mgmt->da);
1969 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
1970 " not found", MAC2STR(mgmt->da));
1974 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
1975 MAC2STR(sta->addr));
1977 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1978 "deauth", MAC2STR(sta->addr));
1980 ap_sta_deauth_cb(hapd, sta);
1984 static void handle_disassoc_cb(struct hostapd_data *hapd,
1985 const struct ieee80211_mgmt *mgmt,
1988 struct sta_info *sta;
1989 if (mgmt->da[0] & 0x01)
1991 sta = ap_get_sta(hapd, mgmt->da);
1993 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
1994 " not found", MAC2STR(mgmt->da));
1998 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
1999 MAC2STR(sta->addr));
2001 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2002 "disassoc", MAC2STR(sta->addr));
2004 ap_sta_disassoc_cb(hapd, sta);
2009 * ieee802_11_mgmt_cb - Process management frame TX status callback
2010 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2012 * @buf: management frame data (starting from IEEE 802.11 header)
2013 * @len: length of frame data in octets
2014 * @stype: management frame subtype from frame control field
2015 * @ok: Whether the frame was ACK'ed
2017 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2020 const struct ieee80211_mgmt *mgmt;
2021 mgmt = (const struct ieee80211_mgmt *) buf;
2024 case WLAN_FC_STYPE_AUTH:
2025 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2026 handle_auth_cb(hapd, mgmt, len, ok);
2028 case WLAN_FC_STYPE_ASSOC_RESP:
2029 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2030 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2032 case WLAN_FC_STYPE_REASSOC_RESP:
2033 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2034 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2036 case WLAN_FC_STYPE_PROBE_RESP:
2037 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2039 case WLAN_FC_STYPE_DEAUTH:
2040 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2041 handle_deauth_cb(hapd, mgmt, len, ok);
2043 case WLAN_FC_STYPE_DISASSOC:
2044 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2045 handle_disassoc_cb(hapd, mgmt, len, ok);
2047 case WLAN_FC_STYPE_ACTION:
2048 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2051 printf("unknown mgmt cb frame subtype %d\n", stype);
2057 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2064 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2065 char *buf, size_t buflen)
2072 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2073 const u8 *buf, size_t len, int ack)
2075 struct sta_info *sta;
2076 struct hostapd_iface *iface = hapd->iface;
2078 sta = ap_get_sta(hapd, addr);
2079 if (sta == NULL && iface->num_bss > 1) {
2081 for (j = 0; j < iface->num_bss; j++) {
2082 hapd = iface->bss[j];
2083 sta = ap_get_sta(hapd, addr);
2088 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
2090 if (sta->flags & WLAN_STA_PENDING_POLL) {
2091 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2092 "activity poll", MAC2STR(sta->addr),
2093 ack ? "ACKed" : "did not ACK");
2095 sta->flags &= ~WLAN_STA_PENDING_POLL;
2098 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2102 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2103 const u8 *data, size_t len, int ack)
2105 struct sta_info *sta;
2106 struct hostapd_iface *iface = hapd->iface;
2108 sta = ap_get_sta(hapd, dst);
2109 if (sta == NULL && iface->num_bss > 1) {
2111 for (j = 0; j < iface->num_bss; j++) {
2112 hapd = iface->bss[j];
2113 sta = ap_get_sta(hapd, dst);
2118 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2119 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2120 MACSTR " that is not currently associated",
2125 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2129 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2131 struct sta_info *sta;
2132 struct hostapd_iface *iface = hapd->iface;
2134 sta = ap_get_sta(hapd, addr);
2135 if (sta == NULL && iface->num_bss > 1) {
2137 for (j = 0; j < iface->num_bss; j++) {
2138 hapd = iface->bss[j];
2139 sta = ap_get_sta(hapd, addr);
2146 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2149 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2150 "activity poll", MAC2STR(sta->addr));
2151 sta->flags &= ~WLAN_STA_PENDING_POLL;
2155 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2158 struct sta_info *sta;
2160 sta = ap_get_sta(hapd, src);
2161 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
2162 if (!hapd->conf->wds_sta)
2165 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2166 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2167 "STA " MACSTR " (aid %u)",
2168 MAC2STR(sta->addr), sta->aid);
2169 sta->flags |= WLAN_STA_WDS;
2170 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
2175 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2176 MACSTR, MAC2STR(src));
2177 if (src[0] & 0x01) {
2178 /* Broadcast bit set in SA?! Ignore the frame silently. */
2182 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2183 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2184 "already been sent, but no TX status yet known - "
2185 "ignore Class 3 frame issue with " MACSTR,
2190 if (sta && (sta->flags & WLAN_STA_AUTH))
2191 hostapd_drv_sta_disassoc(
2193 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2195 hostapd_drv_sta_deauth(
2197 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2201 #endif /* CONFIG_NATIVE_WINDOWS */