2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #ifndef CONFIG_NATIVE_WINDOWS
19 #include "utils/common.h"
20 #include "utils/eloop.h"
21 #include "crypto/crypto.h"
22 #include "drivers/driver.h"
23 #include "common/ieee802_11_defs.h"
24 #include "common/ieee802_11_common.h"
25 #include "common/wpa_ctrl.h"
26 #include "radius/radius.h"
27 #include "radius/radius_client.h"
32 #include "ieee802_11_auth.h"
34 #include "ieee802_1x.h"
38 #include "accounting.h"
39 #include "ap_config.h"
41 #include "p2p_hostapd.h"
42 #include "ap_drv_ops.h"
43 #include "ieee802_11.h"
46 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
51 if (hapd->iface->current_rates == NULL)
54 *pos++ = WLAN_EID_SUPP_RATES;
55 num = hapd->iface->num_rates;
56 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
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 &&
76 hapd->iface->num_rates < 8)
77 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
83 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
88 if (hapd->iface->current_rates == NULL)
91 num = hapd->iface->num_rates;
92 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
98 *pos++ = WLAN_EID_EXT_SUPP_RATES;
101 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
105 continue; /* already in SuppRates IE */
106 *pos = hapd->iface->current_rates[i].rate / 5;
107 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
112 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
113 hapd->iface->num_rates >= 8)
114 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
120 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
123 int capab = WLAN_CAPABILITY_ESS;
126 if (hapd->iface->num_sta_no_short_preamble == 0 &&
127 hapd->iconf->preamble == SHORT_PREAMBLE)
128 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
130 privacy = hapd->conf->ssid.wep.keys_set;
132 if (hapd->conf->ieee802_1x &&
133 (hapd->conf->default_wep_key_len ||
134 hapd->conf->individual_wep_key_len))
141 int policy, def_klen;
142 if (probe && sta->ssid_probe) {
143 policy = sta->ssid_probe->security_policy;
144 def_klen = sta->ssid_probe->wep.default_len;
146 policy = sta->ssid->security_policy;
147 def_klen = sta->ssid->wep.default_len;
149 privacy = policy != SECURITY_PLAINTEXT;
150 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
155 capab |= WLAN_CAPABILITY_PRIVACY;
157 if (hapd->iface->current_mode &&
158 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
159 hapd->iface->num_sta_no_short_slot_time == 0)
160 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
166 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
169 if (len > HOSTAPD_MAX_SSID_LEN)
170 len = HOSTAPD_MAX_SSID_LEN;
171 for (i = 0; i < len; i++) {
172 if (ssid[i] >= 32 && ssid[i] < 127)
181 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
182 u16 auth_transaction, const u8 *challenge,
185 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
187 "authentication (shared key, transaction %d)",
190 if (auth_transaction == 1) {
191 if (!sta->challenge) {
192 /* Generate a pseudo-random challenge */
196 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
197 if (sta->challenge == NULL)
198 return WLAN_STATUS_UNSPECIFIED_FAILURE;
202 os_memcpy(key, &now.sec, 4);
203 os_memcpy(key + 4, &r, 4);
204 rc4_skip(key, sizeof(key), 0,
205 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
210 if (auth_transaction != 3)
211 return WLAN_STATUS_UNSPECIFIED_FAILURE;
214 if (!iswep || !sta->challenge || !challenge ||
215 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
216 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
218 "shared key authentication - invalid "
219 "challenge-response");
220 return WLAN_STATUS_CHALLENGE_FAIL;
223 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
225 "authentication OK (shared key)");
226 #ifdef IEEE80211_REQUIRE_AUTH_ACK
227 /* Station will be marked authenticated if it ACKs the
228 * authentication reply. */
230 sta->flags |= WLAN_STA_AUTH;
231 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
233 os_free(sta->challenge);
234 sta->challenge = NULL;
240 static void send_auth_reply(struct hostapd_data *hapd,
241 const u8 *dst, const u8 *bssid,
242 u16 auth_alg, u16 auth_transaction, u16 resp,
243 const u8 *ies, size_t ies_len)
245 struct ieee80211_mgmt *reply;
249 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
250 buf = os_zalloc(rlen);
254 reply = (struct ieee80211_mgmt *) buf;
255 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
257 os_memcpy(reply->da, dst, ETH_ALEN);
258 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
259 os_memcpy(reply->bssid, bssid, ETH_ALEN);
261 reply->u.auth.auth_alg = host_to_le16(auth_alg);
262 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
263 reply->u.auth.status_code = host_to_le16(resp);
266 os_memcpy(reply->u.auth.variable, ies, ies_len);
268 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
269 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
270 MAC2STR(dst), auth_alg, auth_transaction,
271 resp, (unsigned long) ies_len);
272 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
273 perror("send_auth_reply: send");
279 #ifdef CONFIG_IEEE80211R
280 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
281 u16 auth_transaction, u16 status,
282 const u8 *ies, size_t ies_len)
284 struct hostapd_data *hapd = ctx;
285 struct sta_info *sta;
287 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
288 status, ies, ies_len);
290 if (status != WLAN_STATUS_SUCCESS)
293 sta = ap_get_sta(hapd, dst);
297 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
298 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
299 sta->flags |= WLAN_STA_AUTH;
300 mlme_authenticate_indication(hapd, sta);
302 #endif /* CONFIG_IEEE80211R */
305 static void handle_auth(struct hostapd_data *hapd,
306 const struct ieee80211_mgmt *mgmt, size_t len)
308 u16 auth_alg, auth_transaction, status_code;
309 u16 resp = WLAN_STATUS_SUCCESS;
310 struct sta_info *sta = NULL;
313 const u8 *challenge = NULL;
314 u32 session_timeout, acct_interim_interval;
318 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
319 size_t resp_ies_len = 0;
321 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
322 printf("handle_auth - too short payload (len=%lu)\n",
323 (unsigned long) len);
327 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
328 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
329 status_code = le_to_host16(mgmt->u.auth.status_code);
330 fc = le_to_host16(mgmt->frame_control);
332 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
333 2 + WLAN_AUTH_CHALLENGE_LEN &&
334 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
335 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
336 challenge = &mgmt->u.auth.variable[2];
338 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
339 "auth_transaction=%d status_code=%d wep=%d%s",
340 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
341 status_code, !!(fc & WLAN_FC_ISWEP),
342 challenge ? " challenge" : "");
344 if (hapd->tkip_countermeasures) {
345 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
349 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
350 auth_alg == WLAN_AUTH_OPEN) ||
351 #ifdef CONFIG_IEEE80211R
352 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
353 auth_alg == WLAN_AUTH_FT) ||
354 #endif /* CONFIG_IEEE80211R */
355 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
356 auth_alg == WLAN_AUTH_SHARED_KEY))) {
357 printf("Unsupported authentication algorithm (%d)\n",
359 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
363 if (!(auth_transaction == 1 ||
364 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
365 printf("Unknown authentication transaction number (%d)\n",
367 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
371 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
372 printf("Station " MACSTR " not allowed to authenticate.\n",
374 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
378 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
380 &acct_interim_interval, &vlan_id,
383 if (res == HOSTAPD_ACL_REJECT) {
384 printf("Station " MACSTR " not allowed to authenticate.\n",
386 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
389 if (res == HOSTAPD_ACL_PENDING) {
390 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
391 " waiting for an external authentication",
393 /* Authentication code will re-send the authentication frame
394 * after it has received (and cached) information from the
395 * external source. */
399 sta = ap_sta_add(hapd, mgmt->sa);
401 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
406 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
408 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
409 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
410 "%d received from RADIUS server",
412 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
415 sta->vlan_id = vlan_id;
416 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
417 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
420 if (has_psk && hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
422 sta->psk = os_malloc(PMK_LEN);
424 os_memcpy(sta->psk, psk, PMK_LEN);
430 sta->flags &= ~WLAN_STA_PREAUTH;
431 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
433 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
434 sta->acct_interim_interval = acct_interim_interval;
435 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
436 ap_sta_session_timeout(hapd, sta, session_timeout);
438 ap_sta_no_session_timeout(hapd, sta);
442 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
444 "authentication OK (open system)");
445 #ifdef IEEE80211_REQUIRE_AUTH_ACK
446 /* Station will be marked authenticated if it ACKs the
447 * authentication reply. */
449 sta->flags |= WLAN_STA_AUTH;
450 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
451 sta->auth_alg = WLAN_AUTH_OPEN;
452 mlme_authenticate_indication(hapd, sta);
455 case WLAN_AUTH_SHARED_KEY:
456 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
458 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
459 mlme_authenticate_indication(hapd, sta);
460 if (sta->challenge && auth_transaction == 1) {
461 resp_ies[0] = WLAN_EID_CHALLENGE;
462 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
463 os_memcpy(resp_ies + 2, sta->challenge,
464 WLAN_AUTH_CHALLENGE_LEN);
465 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
468 #ifdef CONFIG_IEEE80211R
470 sta->auth_alg = WLAN_AUTH_FT;
471 if (sta->wpa_sm == NULL)
472 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
474 if (sta->wpa_sm == NULL) {
475 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
477 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
480 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
481 auth_transaction, mgmt->u.auth.variable,
482 len - IEEE80211_HDRLEN -
483 sizeof(mgmt->u.auth),
484 handle_auth_ft_finish, hapd);
485 /* handle_auth_ft_finish() callback will complete auth. */
487 #endif /* CONFIG_IEEE80211R */
491 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
492 auth_transaction + 1, resp, resp_ies, resp_ies_len);
496 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
500 /* get a unique AID */
502 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
506 for (i = 0; i < AID_WORDS; i++) {
507 if (hapd->sta_aid[i] == (u32) -1)
509 for (j = 0; j < 32; j++) {
510 if (!(hapd->sta_aid[i] & BIT(j)))
518 aid = i * 32 + j + 1;
523 hapd->sta_aid[i] |= BIT(j);
524 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
529 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
530 const u8 *ssid_ie, size_t ssid_ie_len)
533 return WLAN_STATUS_UNSPECIFIED_FAILURE;
535 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
536 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
538 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
539 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
541 "Station tried to associate with unknown SSID "
543 return WLAN_STATUS_UNSPECIFIED_FAILURE;
546 return WLAN_STATUS_SUCCESS;
550 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
551 const u8 *wmm_ie, size_t wmm_ie_len)
553 sta->flags &= ~WLAN_STA_WMM;
555 if (wmm_ie && hapd->conf->wmm_enabled) {
556 struct wmm_information_element *wmm;
558 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
559 hostapd_logger(hapd, sta->addr,
562 "invalid WMM element in association "
564 return WLAN_STATUS_UNSPECIFIED_FAILURE;
567 sta->flags |= WLAN_STA_WMM;
568 wmm = (struct wmm_information_element *) wmm_ie;
569 sta->qosinfo = wmm->qos_info;
571 return WLAN_STATUS_SUCCESS;
575 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
576 struct ieee802_11_elems *elems)
578 if (!elems->supp_rates) {
579 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
581 "No supported rates element in AssocReq");
582 return WLAN_STATUS_UNSPECIFIED_FAILURE;
585 if (elems->supp_rates_len > sizeof(sta->supported_rates)) {
586 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
588 "Invalid supported rates element length %d",
589 elems->supp_rates_len);
590 return WLAN_STATUS_UNSPECIFIED_FAILURE;
593 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
594 os_memcpy(sta->supported_rates, elems->supp_rates,
595 elems->supp_rates_len);
596 sta->supported_rates_len = elems->supp_rates_len;
598 if (elems->ext_supp_rates) {
599 if (elems->supp_rates_len + elems->ext_supp_rates_len >
600 sizeof(sta->supported_rates)) {
601 hostapd_logger(hapd, sta->addr,
602 HOSTAPD_MODULE_IEEE80211,
604 "Invalid supported rates element length"
605 " %d+%d", elems->supp_rates_len,
606 elems->ext_supp_rates_len);
607 return WLAN_STATUS_UNSPECIFIED_FAILURE;
610 os_memcpy(sta->supported_rates + elems->supp_rates_len,
611 elems->ext_supp_rates, elems->ext_supp_rates_len);
612 sta->supported_rates_len += elems->ext_supp_rates_len;
615 return WLAN_STATUS_SUCCESS;
619 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
620 const u8 *ies, size_t ies_len, int reassoc)
622 struct ieee802_11_elems elems;
627 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
628 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
629 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
630 "association request");
631 return WLAN_STATUS_UNSPECIFIED_FAILURE;
634 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
635 if (resp != WLAN_STATUS_SUCCESS)
637 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
638 if (resp != WLAN_STATUS_SUCCESS)
640 resp = copy_supp_rates(hapd, sta, &elems);
641 if (resp != WLAN_STATUS_SUCCESS)
643 #ifdef CONFIG_IEEE80211N
644 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
645 elems.ht_capabilities_len);
646 if (resp != WLAN_STATUS_SUCCESS)
648 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
649 !(sta->flags & WLAN_STA_HT)) {
650 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
651 HOSTAPD_LEVEL_INFO, "Station does not support "
652 "mandatory HT PHY - reject association");
653 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
655 #endif /* CONFIG_IEEE80211N */
657 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
658 wpa_ie = elems.rsn_ie;
659 wpa_ie_len = elems.rsn_ie_len;
660 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
662 wpa_ie = elems.wpa_ie;
663 wpa_ie_len = elems.wpa_ie_len;
670 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
671 if (hapd->conf->wps_state && elems.wps_ie) {
672 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
673 "Request - assume WPS is used");
674 sta->flags |= WLAN_STA_WPS;
675 wpabuf_free(sta->wps_ie);
676 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
678 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
679 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
680 sta->flags |= WLAN_STA_WPS2;
684 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
685 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
686 "(Re)Association Request - reject");
687 return WLAN_STATUS_INVALID_IE;
689 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
690 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
691 "(Re)Association Request - possible WPS use");
692 sta->flags |= WLAN_STA_MAYBE_WPS;
694 #endif /* CONFIG_WPS */
695 if (hapd->conf->wpa && wpa_ie == NULL) {
696 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
698 "No WPA/RSN IE in association request");
699 return WLAN_STATUS_INVALID_IE;
702 if (hapd->conf->wpa && wpa_ie) {
706 if (sta->wpa_sm == NULL)
707 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
709 if (sta->wpa_sm == NULL) {
710 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
712 return WLAN_STATUS_UNSPECIFIED_FAILURE;
714 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
716 elems.mdie, elems.mdie_len);
717 if (res == WPA_INVALID_GROUP)
718 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
719 else if (res == WPA_INVALID_PAIRWISE)
720 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
721 else if (res == WPA_INVALID_AKMP)
722 resp = WLAN_STATUS_AKMP_NOT_VALID;
723 else if (res == WPA_ALLOC_FAIL)
724 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
725 #ifdef CONFIG_IEEE80211W
726 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
727 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
728 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
729 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
730 #endif /* CONFIG_IEEE80211W */
731 else if (res == WPA_INVALID_MDIE)
732 resp = WLAN_STATUS_INVALID_MDIE;
733 else if (res != WPA_IE_OK)
734 resp = WLAN_STATUS_INVALID_IE;
735 if (resp != WLAN_STATUS_SUCCESS)
737 #ifdef CONFIG_IEEE80211W
738 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
739 sta->sa_query_count > 0)
740 ap_check_sa_query_timeout(hapd, sta);
741 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
742 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
744 * STA has already been associated with MFP and SA
745 * Query timeout has not been reached. Reject the
746 * association attempt temporarily and start SA Query,
747 * if one is not pending.
750 if (sta->sa_query_count == 0)
751 ap_sta_start_sa_query(hapd, sta);
753 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
756 if (wpa_auth_uses_mfp(sta->wpa_sm))
757 sta->flags |= WLAN_STA_MFP;
759 sta->flags &= ~WLAN_STA_MFP;
760 #endif /* CONFIG_IEEE80211W */
762 #ifdef CONFIG_IEEE80211R
763 if (sta->auth_alg == WLAN_AUTH_FT) {
765 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
766 "to use association (not "
767 "re-association) with FT auth_alg",
769 return WLAN_STATUS_UNSPECIFIED_FAILURE;
772 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
774 if (resp != WLAN_STATUS_SUCCESS)
777 #endif /* CONFIG_IEEE80211R */
779 #ifdef CONFIG_IEEE80211N
780 if ((sta->flags & WLAN_STA_HT) &&
781 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
782 hostapd_logger(hapd, sta->addr,
783 HOSTAPD_MODULE_IEEE80211,
785 "Station tried to use TKIP with HT "
787 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
789 #endif /* CONFIG_IEEE80211N */
791 wpa_auth_sta_no_wpa(sta->wpa_sm);
795 wpabuf_free(sta->p2p_ie);
796 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
800 wpabuf_free(sta->p2p_ie);
804 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
805 #endif /* CONFIG_P2P */
807 return WLAN_STATUS_SUCCESS;
811 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
815 struct ieee80211_mgmt reply;
817 os_memset(&reply, 0, sizeof(reply));
818 reply.frame_control =
819 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
820 os_memcpy(reply.da, addr, ETH_ALEN);
821 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
822 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
824 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
825 reply.u.deauth.reason_code = host_to_le16(reason_code);
827 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
828 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
833 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
834 u16 status_code, int reassoc, const u8 *ies,
838 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
839 struct ieee80211_mgmt *reply;
842 os_memset(buf, 0, sizeof(buf));
843 reply = (struct ieee80211_mgmt *) buf;
844 reply->frame_control =
845 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
846 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
847 WLAN_FC_STYPE_ASSOC_RESP));
848 os_memcpy(reply->da, sta->addr, ETH_ALEN);
849 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
850 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
852 send_len = IEEE80211_HDRLEN;
853 send_len += sizeof(reply->u.assoc_resp);
854 reply->u.assoc_resp.capab_info =
855 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
856 reply->u.assoc_resp.status_code = host_to_le16(status_code);
857 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
858 | BIT(14) | BIT(15));
859 /* Supported rates */
860 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
861 /* Extended supported rates */
862 p = hostapd_eid_ext_supp_rates(hapd, p);
864 #ifdef CONFIG_IEEE80211R
865 if (status_code == WLAN_STATUS_SUCCESS) {
866 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
867 * Transition Information, RSN, [RIC Response] */
868 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
869 buf + sizeof(buf) - p,
870 sta->auth_alg, ies, ies_len);
872 #endif /* CONFIG_IEEE80211R */
874 #ifdef CONFIG_IEEE80211W
875 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
876 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
877 #endif /* CONFIG_IEEE80211W */
879 #ifdef CONFIG_IEEE80211N
880 p = hostapd_eid_ht_capabilities(hapd, p);
881 p = hostapd_eid_ht_operation(hapd, p);
882 #endif /* CONFIG_IEEE80211N */
884 p = hostapd_eid_ext_capab(hapd, p);
886 if (sta->flags & WLAN_STA_WMM)
887 p = hostapd_eid_wmm(hapd, p);
890 if ((sta->flags & WLAN_STA_WPS) ||
891 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
892 struct wpabuf *wps = wps_build_assoc_resp_ie();
894 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
895 p += wpabuf_len(wps);
899 #endif /* CONFIG_WPS */
903 struct wpabuf *p2p_resp_ie;
904 enum p2p_status_code status;
905 switch (status_code) {
906 case WLAN_STATUS_SUCCESS:
907 status = P2P_SC_SUCCESS;
909 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
910 status = P2P_SC_FAIL_LIMIT_REACHED;
913 status = P2P_SC_FAIL_INVALID_PARAMS;
916 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
918 os_memcpy(p, wpabuf_head(p2p_resp_ie),
919 wpabuf_len(p2p_resp_ie));
920 p += wpabuf_len(p2p_resp_ie);
921 wpabuf_free(p2p_resp_ie);
924 #endif /* CONFIG_P2P */
926 #ifdef CONFIG_P2P_MANAGER
927 if (hapd->conf->p2p & P2P_MANAGE)
928 p = hostapd_eid_p2p_manage(hapd, p);
929 #endif /* CONFIG_P2P_MANAGER */
931 send_len += p - reply->u.assoc_resp.variable;
933 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
934 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
939 static void handle_assoc(struct hostapd_data *hapd,
940 const struct ieee80211_mgmt *mgmt, size_t len,
943 u16 capab_info, listen_interval;
944 u16 resp = WLAN_STATUS_SUCCESS;
947 struct sta_info *sta;
949 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
950 sizeof(mgmt->u.assoc_req))) {
951 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
952 "\n", reassoc, (unsigned long) len);
957 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
958 listen_interval = le_to_host16(
959 mgmt->u.reassoc_req.listen_interval);
960 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
961 " capab_info=0x%02x listen_interval=%d current_ap="
963 MAC2STR(mgmt->sa), capab_info, listen_interval,
964 MAC2STR(mgmt->u.reassoc_req.current_ap));
965 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
966 pos = mgmt->u.reassoc_req.variable;
968 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
969 listen_interval = le_to_host16(
970 mgmt->u.assoc_req.listen_interval);
971 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
972 " capab_info=0x%02x listen_interval=%d",
973 MAC2STR(mgmt->sa), capab_info, listen_interval);
974 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
975 pos = mgmt->u.assoc_req.variable;
978 sta = ap_get_sta(hapd, mgmt->sa);
979 #ifdef CONFIG_IEEE80211R
980 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
981 (sta->flags & WLAN_STA_AUTH) == 0) {
982 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
983 "prior to authentication since it is using "
984 "over-the-DS FT", MAC2STR(mgmt->sa));
986 #endif /* CONFIG_IEEE80211R */
987 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
988 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
989 HOSTAPD_LEVEL_INFO, "Station tried to "
990 "associate before authentication "
991 "(aid=%d flags=0x%x)",
993 sta ? sta->flags : 0);
994 send_deauth(hapd, mgmt->sa,
995 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
999 if (hapd->tkip_countermeasures) {
1000 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1004 if (listen_interval > hapd->conf->max_listen_interval) {
1005 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1006 HOSTAPD_LEVEL_DEBUG,
1007 "Too large Listen Interval (%d)",
1009 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1013 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1015 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1016 if (resp != WLAN_STATUS_SUCCESS)
1019 if (hostapd_get_aid(hapd, sta) < 0) {
1020 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1021 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1022 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1026 sta->capability = capab_info;
1027 sta->listen_interval = listen_interval;
1029 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1030 sta->flags |= WLAN_STA_NONERP;
1031 for (i = 0; i < sta->supported_rates_len; i++) {
1032 if ((sta->supported_rates[i] & 0x7f) > 22) {
1033 sta->flags &= ~WLAN_STA_NONERP;
1037 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1038 sta->nonerp_set = 1;
1039 hapd->iface->num_sta_non_erp++;
1040 if (hapd->iface->num_sta_non_erp == 1)
1041 ieee802_11_set_beacons(hapd->iface);
1044 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1045 !sta->no_short_slot_time_set) {
1046 sta->no_short_slot_time_set = 1;
1047 hapd->iface->num_sta_no_short_slot_time++;
1048 if (hapd->iface->current_mode->mode ==
1049 HOSTAPD_MODE_IEEE80211G &&
1050 hapd->iface->num_sta_no_short_slot_time == 1)
1051 ieee802_11_set_beacons(hapd->iface);
1054 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1055 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1057 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1059 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1060 !sta->no_short_preamble_set) {
1061 sta->no_short_preamble_set = 1;
1062 hapd->iface->num_sta_no_short_preamble++;
1063 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1064 && hapd->iface->num_sta_no_short_preamble == 1)
1065 ieee802_11_set_beacons(hapd->iface);
1068 #ifdef CONFIG_IEEE80211N
1069 update_ht_state(hapd, sta);
1070 #endif /* CONFIG_IEEE80211N */
1072 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1073 HOSTAPD_LEVEL_DEBUG,
1074 "association OK (aid %d)", sta->aid);
1075 /* Station will be marked associated, after it acknowledges AssocResp
1077 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1079 #ifdef CONFIG_IEEE80211W
1080 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1081 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1082 "SA Query procedure", reassoc ? "re" : "");
1083 /* TODO: Send a protected Disassociate frame to the STA using
1084 * the old key and Reason Code "Previous Authentication no
1085 * longer valid". Make sure this is only sent protected since
1086 * unprotected frame would be received by the STA that is now
1087 * trying to associate.
1090 #endif /* CONFIG_IEEE80211W */
1093 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1097 if (sta->last_assoc_req)
1098 os_free(sta->last_assoc_req);
1099 sta->last_assoc_req = os_malloc(len);
1100 if (sta->last_assoc_req)
1101 os_memcpy(sta->last_assoc_req, mgmt, len);
1103 /* Make sure that the previously registered inactivity timer will not
1104 * remove the STA immediately. */
1105 sta->timeout_next = STA_NULLFUNC;
1108 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1112 static void handle_disassoc(struct hostapd_data *hapd,
1113 const struct ieee80211_mgmt *mgmt, size_t len)
1115 struct sta_info *sta;
1117 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1118 printf("handle_disassoc - too short payload (len=%lu)\n",
1119 (unsigned long) len);
1123 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1125 le_to_host16(mgmt->u.disassoc.reason_code));
1127 sta = ap_get_sta(hapd, mgmt->sa);
1129 printf("Station " MACSTR " trying to disassociate, but it "
1130 "is not associated.\n", MAC2STR(mgmt->sa));
1134 ap_sta_set_authorized(hapd, sta, 0);
1135 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1136 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1137 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1138 HOSTAPD_LEVEL_INFO, "disassociated");
1139 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1140 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1141 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1143 accounting_sta_stop(hapd, sta);
1144 ieee802_1x_free_station(sta);
1145 hostapd_drv_sta_remove(hapd, sta->addr);
1147 if (sta->timeout_next == STA_NULLFUNC ||
1148 sta->timeout_next == STA_DISASSOC) {
1149 sta->timeout_next = STA_DEAUTH;
1150 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1151 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1155 mlme_disassociate_indication(
1156 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1160 static void handle_deauth(struct hostapd_data *hapd,
1161 const struct ieee80211_mgmt *mgmt, size_t len)
1163 struct sta_info *sta;
1165 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1166 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1167 "payload (len=%lu)", (unsigned long) len);
1171 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1173 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1175 sta = ap_get_sta(hapd, mgmt->sa);
1177 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1178 "to deauthenticate, but it is not authenticated",
1183 ap_sta_set_authorized(hapd, sta, 0);
1184 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1185 WLAN_STA_ASSOC_REQ_OK);
1186 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1187 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1188 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1189 mlme_deauthenticate_indication(
1190 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1191 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1192 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1193 ap_free_sta(hapd, sta);
1197 static void handle_beacon(struct hostapd_data *hapd,
1198 const struct ieee80211_mgmt *mgmt, size_t len,
1199 struct hostapd_frame_info *fi)
1201 struct ieee802_11_elems elems;
1203 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1204 printf("handle_beacon - too short payload (len=%lu)\n",
1205 (unsigned long) len);
1209 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1210 len - (IEEE80211_HDRLEN +
1211 sizeof(mgmt->u.beacon)), &elems,
1214 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1218 #ifdef CONFIG_IEEE80211W
1220 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1221 const struct ieee80211_mgmt *mgmt,
1226 end = mgmt->u.action.u.sa_query_resp.trans_id +
1227 WLAN_SA_QUERY_TR_ID_LEN;
1228 if (((u8 *) mgmt) + len < end) {
1229 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1230 "frame (len=%lu)", (unsigned long) len);
1234 ieee802_11_sa_query_action(hapd, mgmt->sa,
1235 mgmt->u.action.u.sa_query_resp.action,
1236 mgmt->u.action.u.sa_query_resp.trans_id);
1240 static int robust_action_frame(u8 category)
1242 return category != WLAN_ACTION_PUBLIC &&
1243 category != WLAN_ACTION_HT;
1245 #endif /* CONFIG_IEEE80211W */
1248 static void handle_action(struct hostapd_data *hapd,
1249 const struct ieee80211_mgmt *mgmt, size_t len)
1251 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_IEEE80211R)
1252 struct sta_info *sta;
1253 sta = ap_get_sta(hapd, mgmt->sa);
1254 #endif /* CONFIG_IEEE80211W || CONFIG_IEEE80211R */
1256 if (len < IEEE80211_HDRLEN + 1) {
1257 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1258 HOSTAPD_LEVEL_DEBUG,
1259 "handle_action - too short payload (len=%lu)",
1260 (unsigned long) len);
1264 #ifdef CONFIG_IEEE80211W
1265 if (sta && (sta->flags & WLAN_STA_MFP) &&
1266 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1267 robust_action_frame(mgmt->u.action.category))) {
1268 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1269 HOSTAPD_LEVEL_DEBUG,
1270 "Dropped unprotected Robust Action frame from "
1274 #endif /* CONFIG_IEEE80211W */
1276 switch (mgmt->u.action.category) {
1277 #ifdef CONFIG_IEEE80211R
1278 case WLAN_ACTION_FT:
1280 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1281 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1282 "frame from unassociated STA " MACSTR,
1287 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1288 len - IEEE80211_HDRLEN))
1293 #endif /* CONFIG_IEEE80211R */
1294 case WLAN_ACTION_WMM:
1295 hostapd_wmm_action(hapd, mgmt, len);
1297 #ifdef CONFIG_IEEE80211W
1298 case WLAN_ACTION_SA_QUERY:
1299 hostapd_sa_query_action(hapd, mgmt, len);
1301 #endif /* CONFIG_IEEE80211W */
1302 case WLAN_ACTION_PUBLIC:
1303 if (hapd->public_action_cb) {
1304 hapd->public_action_cb(hapd->public_action_cb_ctx,
1310 case WLAN_ACTION_VENDOR_SPECIFIC:
1311 if (hapd->vendor_action_cb) {
1312 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1314 hapd->iface->freq) == 0)
1320 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1321 HOSTAPD_LEVEL_DEBUG,
1322 "handle_action - unknown action category %d or invalid "
1324 mgmt->u.action.category);
1325 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1326 !(mgmt->sa[0] & 0x01)) {
1327 struct ieee80211_mgmt *resp;
1330 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1331 * Return the Action frame to the source without change
1332 * except that MSB of the Category set to 1.
1334 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1335 "frame back to sender");
1336 resp = os_malloc(len);
1339 os_memcpy(resp, mgmt, len);
1340 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1341 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1342 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1343 resp->u.action.category |= 0x80;
1345 hostapd_drv_send_mlme(hapd, resp, len, 0);
1352 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1353 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1355 * @buf: management frame data (starting from IEEE 802.11 header)
1356 * @len: length of frame data in octets
1357 * @fi: meta data about received frame (signal level, etc.)
1359 * Process all incoming IEEE 802.11 management frames. This will be called for
1360 * each frame received from the kernel driver through wlan#ap interface. In
1361 * addition, it can be called to re-inserted pending frames (e.g., when using
1362 * external RADIUS server as an MAC ACL).
1364 void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1365 struct hostapd_frame_info *fi)
1367 struct ieee80211_mgmt *mgmt;
1374 mgmt = (struct ieee80211_mgmt *) buf;
1375 fc = le_to_host16(mgmt->frame_control);
1376 stype = WLAN_FC_GET_STYPE(fc);
1378 if (stype == WLAN_FC_STYPE_BEACON) {
1379 handle_beacon(hapd, mgmt, len, fi);
1383 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1384 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1385 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1389 /* Invitation responses can be sent with the peer MAC as BSSID */
1390 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1391 stype == WLAN_FC_STYPE_ACTION) &&
1392 #endif /* CONFIG_P2P */
1393 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1394 printf("MGMT: BSSID=" MACSTR " not our address\n",
1395 MAC2STR(mgmt->bssid));
1400 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1401 handle_probe_req(hapd, mgmt, len);
1405 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1406 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1407 HOSTAPD_LEVEL_DEBUG,
1408 "MGMT: DA=" MACSTR " not our address",
1414 case WLAN_FC_STYPE_AUTH:
1415 wpa_printf(MSG_DEBUG, "mgmt::auth");
1416 handle_auth(hapd, mgmt, len);
1418 case WLAN_FC_STYPE_ASSOC_REQ:
1419 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1420 handle_assoc(hapd, mgmt, len, 0);
1422 case WLAN_FC_STYPE_REASSOC_REQ:
1423 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1424 handle_assoc(hapd, mgmt, len, 1);
1426 case WLAN_FC_STYPE_DISASSOC:
1427 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1428 handle_disassoc(hapd, mgmt, len);
1430 case WLAN_FC_STYPE_DEAUTH:
1431 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1432 handle_deauth(hapd, mgmt, len);
1434 case WLAN_FC_STYPE_ACTION:
1435 wpa_printf(MSG_DEBUG, "mgmt::action");
1436 handle_action(hapd, mgmt, len);
1439 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1440 HOSTAPD_LEVEL_DEBUG,
1441 "unknown mgmt frame subtype %d", stype);
1447 static void handle_auth_cb(struct hostapd_data *hapd,
1448 const struct ieee80211_mgmt *mgmt,
1451 u16 auth_alg, auth_transaction, status_code;
1452 struct sta_info *sta;
1455 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1456 HOSTAPD_LEVEL_NOTICE,
1457 "did not acknowledge authentication response");
1461 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1462 printf("handle_auth_cb - too short payload (len=%lu)\n",
1463 (unsigned long) len);
1467 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1468 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1469 status_code = le_to_host16(mgmt->u.auth.status_code);
1471 sta = ap_get_sta(hapd, mgmt->da);
1473 printf("handle_auth_cb: STA " MACSTR " not found\n",
1478 if (status_code == WLAN_STATUS_SUCCESS &&
1479 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1480 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1482 HOSTAPD_LEVEL_INFO, "authenticated");
1483 sta->flags |= WLAN_STA_AUTH;
1488 static void handle_assoc_cb(struct hostapd_data *hapd,
1489 const struct ieee80211_mgmt *mgmt,
1490 size_t len, int reassoc, int ok)
1493 struct sta_info *sta;
1495 struct ieee80211_ht_capabilities ht_cap;
1498 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1499 HOSTAPD_LEVEL_DEBUG,
1500 "did not acknowledge association response");
1504 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1505 sizeof(mgmt->u.assoc_resp))) {
1506 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1507 "(len=%lu)\n", reassoc, (unsigned long) len);
1512 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1514 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1516 sta = ap_get_sta(hapd, mgmt->da);
1518 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1523 if (status != WLAN_STATUS_SUCCESS)
1526 /* Stop previous accounting session, if one is started, and allocate
1527 * new session id for the new session. */
1528 accounting_sta_stop(hapd, sta);
1530 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1532 "associated (aid %d)",
1535 if (sta->flags & WLAN_STA_ASSOC)
1537 sta->flags |= WLAN_STA_ASSOC;
1538 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1539 sta->auth_alg == WLAN_AUTH_FT) {
1541 * Open, static WEP, or FT protocol; no separate authorization
1544 ap_sta_set_authorized(hapd, sta, 1);
1548 mlme_reassociate_indication(hapd, sta);
1550 mlme_associate_indication(hapd, sta);
1552 #ifdef CONFIG_IEEE80211W
1553 sta->sa_query_timed_out = 0;
1554 #endif /* CONFIG_IEEE80211W */
1557 * Remove the STA entry in order to make sure the STA PS state gets
1558 * cleared and configuration gets updated in case of reassociation back
1561 hostapd_drv_sta_remove(hapd, sta->addr);
1563 #ifdef CONFIG_IEEE80211N
1564 if (sta->flags & WLAN_STA_HT)
1565 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1566 #endif /* CONFIG_IEEE80211N */
1568 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1569 sta->supported_rates, sta->supported_rates_len,
1570 sta->listen_interval,
1571 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1572 sta->flags, sta->qosinfo)) {
1573 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1574 HOSTAPD_LEVEL_NOTICE,
1575 "Could not add STA to kernel driver");
1577 ap_sta_disconnect(hapd, sta, sta->addr,
1578 WLAN_REASON_DISASSOC_AP_BUSY);
1583 if (sta->flags & WLAN_STA_WDS)
1584 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1586 if (sta->eapol_sm == NULL) {
1588 * This STA does not use RADIUS server for EAP authentication,
1589 * so bind it to the selected VLAN interface now, since the
1590 * interface selection is not going to change anymore.
1592 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1594 } else if (sta->vlan_id) {
1595 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1596 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1600 hostapd_set_sta_flags(hapd, sta);
1602 if (sta->auth_alg == WLAN_AUTH_FT)
1603 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1605 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1606 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1608 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1611 /* Copy of the association request is not needed anymore */
1612 if (sta->last_assoc_req) {
1613 os_free(sta->last_assoc_req);
1614 sta->last_assoc_req = NULL;
1619 static void handle_deauth_cb(struct hostapd_data *hapd,
1620 const struct ieee80211_mgmt *mgmt,
1623 struct sta_info *sta;
1624 if (mgmt->da[0] & 0x01)
1626 sta = ap_get_sta(hapd, mgmt->da);
1628 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
1629 " not found", MAC2STR(mgmt->da));
1633 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
1634 MAC2STR(sta->addr));
1636 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1637 "deauth", MAC2STR(sta->addr));
1639 ap_sta_deauth_cb(hapd, sta);
1643 static void handle_disassoc_cb(struct hostapd_data *hapd,
1644 const struct ieee80211_mgmt *mgmt,
1647 struct sta_info *sta;
1648 if (mgmt->da[0] & 0x01)
1650 sta = ap_get_sta(hapd, mgmt->da);
1652 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
1653 " not found", MAC2STR(mgmt->da));
1657 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
1658 MAC2STR(sta->addr));
1660 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1661 "disassoc", MAC2STR(sta->addr));
1663 ap_sta_disassoc_cb(hapd, sta);
1668 * ieee802_11_mgmt_cb - Process management frame TX status callback
1669 * @hapd: hostapd BSS data structure (the BSS from which the management frame
1671 * @buf: management frame data (starting from IEEE 802.11 header)
1672 * @len: length of frame data in octets
1673 * @stype: management frame subtype from frame control field
1674 * @ok: Whether the frame was ACK'ed
1676 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
1679 const struct ieee80211_mgmt *mgmt;
1680 mgmt = (const struct ieee80211_mgmt *) buf;
1683 case WLAN_FC_STYPE_AUTH:
1684 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1685 handle_auth_cb(hapd, mgmt, len, ok);
1687 case WLAN_FC_STYPE_ASSOC_RESP:
1688 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1689 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1691 case WLAN_FC_STYPE_REASSOC_RESP:
1692 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1693 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1695 case WLAN_FC_STYPE_PROBE_RESP:
1696 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
1698 case WLAN_FC_STYPE_DEAUTH:
1699 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
1700 handle_deauth_cb(hapd, mgmt, len, ok);
1702 case WLAN_FC_STYPE_DISASSOC:
1703 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
1704 handle_disassoc_cb(hapd, mgmt, len, ok);
1706 case WLAN_FC_STYPE_ACTION:
1707 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1710 printf("unknown mgmt cb frame subtype %d\n", stype);
1716 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1723 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1724 char *buf, size_t buflen)
1731 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
1732 const u8 *buf, size_t len, int ack)
1734 struct sta_info *sta;
1735 struct hostapd_iface *iface = hapd->iface;
1737 sta = ap_get_sta(hapd, addr);
1738 if (sta == NULL && iface->num_bss > 1) {
1740 for (j = 0; j < iface->num_bss; j++) {
1741 hapd = iface->bss[j];
1742 sta = ap_get_sta(hapd, addr);
1749 if (sta->flags & WLAN_STA_PENDING_POLL) {
1750 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
1751 "activity poll", MAC2STR(sta->addr),
1752 ack ? "ACKed" : "did not ACK");
1754 sta->flags &= ~WLAN_STA_PENDING_POLL;
1757 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
1761 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
1762 const u8 *data, size_t len, int ack)
1764 struct sta_info *sta;
1765 struct hostapd_iface *iface = hapd->iface;
1767 sta = ap_get_sta(hapd, dst);
1768 if (sta == NULL && iface->num_bss > 1) {
1770 for (j = 0; j < iface->num_bss; j++) {
1771 hapd = iface->bss[j];
1772 sta = ap_get_sta(hapd, dst);
1777 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1778 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
1779 MACSTR " that is not currently associated",
1784 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
1788 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
1790 struct sta_info *sta;
1791 struct hostapd_iface *iface = hapd->iface;
1793 sta = ap_get_sta(hapd, addr);
1794 if (sta == NULL && iface->num_bss > 1) {
1796 for (j = 0; j < iface->num_bss; j++) {
1797 hapd = iface->bss[j];
1798 sta = ap_get_sta(hapd, addr);
1805 if (!(sta->flags & WLAN_STA_PENDING_POLL))
1808 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
1809 "activity poll", MAC2STR(sta->addr));
1810 sta->flags &= ~WLAN_STA_PENDING_POLL;
1814 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
1817 struct sta_info *sta;
1819 sta = ap_get_sta(hapd, src);
1820 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
1821 if (wds && !(sta->flags & WLAN_STA_WDS)) {
1822 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
1823 "STA " MACSTR " (aid %u)",
1824 MAC2STR(sta->addr), sta->aid);
1825 sta->flags |= WLAN_STA_WDS;
1826 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1831 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
1832 MACSTR, MAC2STR(src));
1833 if (src[0] & 0x01) {
1834 /* Broadcast bit set in SA?! Ignore the frame silently. */
1838 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
1839 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
1840 "already been sent, but no TX status yet known - "
1841 "ignore Class 3 frame issue with " MACSTR,
1846 if (sta && (sta->flags & WLAN_STA_AUTH))
1847 hostapd_drv_sta_disassoc(
1849 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1851 hostapd_drv_sta_deauth(
1853 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1857 #endif /* CONFIG_NATIVE_WINDOWS */