2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
18 #ifndef CONFIG_NATIVE_WINDOWS
24 #include "ieee802_11.h"
26 #include "hw_features.h"
27 #include "radius/radius.h"
28 #include "radius/radius_client.h"
29 #include "ieee802_11_auth.h"
32 #include "ieee802_1x.h"
36 #include "accounting.h"
41 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
46 if (hapd->iface->current_rates == NULL)
49 *pos++ = WLAN_EID_SUPP_RATES;
50 num = hapd->iface->num_rates;
52 /* rest of the rates are encoded in Extended supported
59 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
62 *pos = hapd->iface->current_rates[i].rate / 5;
63 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
72 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
77 if (hapd->iface->current_rates == NULL)
80 num = hapd->iface->num_rates;
85 *pos++ = WLAN_EID_EXT_SUPP_RATES;
88 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
92 continue; /* already in SuppRates IE */
93 *pos = hapd->iface->current_rates[i].rate / 5;
94 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
103 u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid)
105 #ifdef CONFIG_IEEE80211N
106 struct ieee80211_ht_capability *cap;
109 if (!hapd->iconf->ieee80211n)
112 *pos++ = WLAN_EID_HT_CAP;
113 *pos++ = sizeof(*cap);
115 cap = (struct ieee80211_ht_capability *) pos;
116 os_memset(cap, 0, sizeof(*cap));
117 SET_2BIT_U8(&cap->mac_ht_params_info,
118 MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
119 MAX_RX_AMPDU_FACTOR_64KB);
121 cap->capabilities_info = host_to_le16(hapd->iconf->ht_capab);
123 cap->supported_mcs_set[0] = 0xff;
124 cap->supported_mcs_set[1] = 0xff;
129 #else /* CONFIG_IEEE80211N */
131 #endif /* CONFIG_IEEE80211N */
135 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
137 #ifdef CONFIG_IEEE80211N
138 struct ieee80211_ht_operation *oper;
141 if (!hapd->iconf->ieee80211n)
144 *pos++ = WLAN_EID_HT_OPERATION;
145 *pos++ = sizeof(*oper);
147 oper = (struct ieee80211_ht_operation *) pos;
148 os_memset(oper, 0, sizeof(*oper));
150 oper->control_chan = hapd->iconf->channel;
151 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
152 if (hapd->iconf->secondary_channel == 1)
153 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
154 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
155 if (hapd->iconf->secondary_channel == -1)
156 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
157 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
159 pos += sizeof(*oper);
162 #else /* CONFIG_IEEE80211N */
164 #endif /* CONFIG_IEEE80211N */
168 #ifdef CONFIG_IEEE80211N
172 Set to 0 (HT pure) under the followign conditions
173 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
174 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
175 Set to 1 (HT non-member protection) if there may be non-HT STAs
176 in both the primary and the secondary channel
177 Set to 2 if only HT STAs are associated in BSS,
178 however and at least one 20 MHz HT STA is associated
179 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
180 (currently non-GF HT station is considered as non-HT STA also)
182 int hostapd_ht_operation_update(struct hostapd_iface *iface)
184 u16 cur_op_mode, new_op_mode;
185 int op_mode_changes = 0;
187 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
190 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
191 __func__, iface->ht_op_mode);
193 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
194 && iface->num_sta_ht_no_gf) {
196 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
198 } else if ((iface->ht_op_mode &
199 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
200 iface->num_sta_ht_no_gf == 0) {
202 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
206 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
207 (iface->num_sta_no_ht || iface->olbc_ht)) {
208 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
210 } else if ((iface->ht_op_mode &
211 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
212 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
214 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
218 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
219 * station is associated. Probably it's a theoretical case, since
220 * it looks like all known HT STAs support greenfield.
223 if (iface->num_sta_no_ht ||
224 (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
225 new_op_mode = OP_MODE_MIXED;
226 else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
227 && iface->num_sta_ht_20mhz)
228 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
229 else if (iface->olbc_ht)
230 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
232 new_op_mode = OP_MODE_PURE;
234 cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
235 if (cur_op_mode != new_op_mode) {
236 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
237 iface->ht_op_mode |= new_op_mode;
241 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
242 __func__, iface->ht_op_mode, op_mode_changes);
244 return op_mode_changes;
247 #endif /* CONFIG_IEEE80211N */
250 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
253 int capab = WLAN_CAPABILITY_ESS;
256 if (hapd->iface->num_sta_no_short_preamble == 0 &&
257 hapd->iconf->preamble == SHORT_PREAMBLE)
258 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
260 privacy = hapd->conf->ssid.wep.keys_set;
262 if (hapd->conf->ieee802_1x &&
263 (hapd->conf->default_wep_key_len ||
264 hapd->conf->individual_wep_key_len))
271 int policy, def_klen;
272 if (probe && sta->ssid_probe) {
273 policy = sta->ssid_probe->security_policy;
274 def_klen = sta->ssid_probe->wep.default_len;
276 policy = sta->ssid->security_policy;
277 def_klen = sta->ssid->wep.default_len;
279 privacy = policy != SECURITY_PLAINTEXT;
280 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
285 capab |= WLAN_CAPABILITY_PRIVACY;
287 if (hapd->iface->current_mode &&
288 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
289 hapd->iface->num_sta_no_short_slot_time == 0)
290 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
296 #ifdef CONFIG_IEEE80211W
297 static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
298 struct sta_info *sta, u8 *eid)
302 struct os_time now, passed;
304 *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
307 os_time_sub(&now, &sta->sa_query_start, &passed);
308 tu = (passed.sec * 1000000 + passed.usec) / 1024;
309 if (hapd->conf->assoc_sa_query_max_timeout > tu)
310 timeout = hapd->conf->assoc_sa_query_max_timeout - tu;
313 if (timeout < hapd->conf->assoc_sa_query_max_timeout)
314 timeout++; /* add some extra time for local timers */
315 WPA_PUT_LE32(pos, timeout);
320 #endif /* CONFIG_IEEE80211W */
323 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
326 if (len > HOSTAPD_MAX_SSID_LEN)
327 len = HOSTAPD_MAX_SSID_LEN;
328 for (i = 0; i < len; i++) {
329 if (ssid[i] >= 32 && ssid[i] < 127)
338 void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
340 struct ieee80211_mgmt mgmt;
342 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
344 "deauthenticate - reason %d", reason);
345 os_memset(&mgmt, 0, sizeof(mgmt));
346 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
347 WLAN_FC_STYPE_DEAUTH);
348 os_memcpy(mgmt.da, addr, ETH_ALEN);
349 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
350 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
351 mgmt.u.deauth.reason_code = host_to_le16(reason);
352 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
353 sizeof(mgmt.u.deauth), 0) < 0)
354 perror("ieee802_11_send_deauth: send");
358 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
359 u16 auth_transaction, u8 *challenge, int iswep)
361 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
363 "authentication (shared key, transaction %d)",
366 if (auth_transaction == 1) {
367 if (!sta->challenge) {
368 /* Generate a pseudo-random challenge */
372 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
373 if (sta->challenge == NULL)
374 return WLAN_STATUS_UNSPECIFIED_FAILURE;
378 os_memcpy(key, &now, 4);
379 os_memcpy(key + 4, &r, 4);
380 rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
386 if (auth_transaction != 3)
387 return WLAN_STATUS_UNSPECIFIED_FAILURE;
390 if (!iswep || !sta->challenge || !challenge ||
391 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
392 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
394 "shared key authentication - invalid "
395 "challenge-response");
396 return WLAN_STATUS_CHALLENGE_FAIL;
399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
401 "authentication OK (shared key)");
402 #ifdef IEEE80211_REQUIRE_AUTH_ACK
403 /* Station will be marked authenticated if it ACKs the
404 * authentication reply. */
406 sta->flags |= WLAN_STA_AUTH;
407 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
409 os_free(sta->challenge);
410 sta->challenge = NULL;
416 static void send_auth_reply(struct hostapd_data *hapd,
417 const u8 *dst, const u8 *bssid,
418 u16 auth_alg, u16 auth_transaction, u16 resp,
419 const u8 *ies, size_t ies_len)
421 struct ieee80211_mgmt *reply;
425 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
426 buf = os_zalloc(rlen);
430 reply = (struct ieee80211_mgmt *) buf;
431 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
433 os_memcpy(reply->da, dst, ETH_ALEN);
434 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
435 os_memcpy(reply->bssid, bssid, ETH_ALEN);
437 reply->u.auth.auth_alg = host_to_le16(auth_alg);
438 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
439 reply->u.auth.status_code = host_to_le16(resp);
442 os_memcpy(reply->u.auth.variable, ies, ies_len);
444 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
445 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
446 MAC2STR(dst), auth_alg, auth_transaction,
447 resp, (unsigned long) ies_len);
448 if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
449 perror("send_auth_reply: send");
455 #ifdef CONFIG_IEEE80211R
456 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
457 u16 auth_transaction, u16 status,
458 const u8 *ies, size_t ies_len)
460 struct hostapd_data *hapd = ctx;
461 struct sta_info *sta;
463 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
464 status, ies, ies_len);
466 if (status != WLAN_STATUS_SUCCESS)
469 sta = ap_get_sta(hapd, dst);
473 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
474 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
475 sta->flags |= WLAN_STA_AUTH;
476 mlme_authenticate_indication(hapd, sta);
478 #endif /* CONFIG_IEEE80211R */
481 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
484 u16 auth_alg, auth_transaction, status_code;
485 u16 resp = WLAN_STATUS_SUCCESS;
486 struct sta_info *sta = NULL;
489 u8 *challenge = NULL;
490 u32 session_timeout, acct_interim_interval;
492 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
493 size_t resp_ies_len = 0;
495 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
496 printf("handle_auth - too short payload (len=%lu)\n",
497 (unsigned long) len);
501 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
502 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
503 status_code = le_to_host16(mgmt->u.auth.status_code);
504 fc = le_to_host16(mgmt->frame_control);
506 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
507 2 + WLAN_AUTH_CHALLENGE_LEN &&
508 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
509 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
510 challenge = &mgmt->u.auth.variable[2];
512 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
513 "auth_transaction=%d status_code=%d wep=%d%s",
514 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
515 status_code, !!(fc & WLAN_FC_ISWEP),
516 challenge ? " challenge" : "");
518 if (hapd->tkip_countermeasures) {
519 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
523 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
524 auth_alg == WLAN_AUTH_OPEN) ||
525 #ifdef CONFIG_IEEE80211R
527 (hapd->conf->wpa_key_mgmt &
528 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
529 auth_alg == WLAN_AUTH_FT) ||
530 #endif /* CONFIG_IEEE80211R */
531 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
532 auth_alg == WLAN_AUTH_SHARED_KEY))) {
533 printf("Unsupported authentication algorithm (%d)\n",
535 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
539 if (!(auth_transaction == 1 ||
540 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
541 printf("Unknown authentication transaction number (%d)\n",
543 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
547 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
548 printf("Station " MACSTR " not allowed to authenticate.\n",
550 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
554 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
556 &acct_interim_interval, &vlan_id);
557 if (res == HOSTAPD_ACL_REJECT) {
558 printf("Station " MACSTR " not allowed to authenticate.\n",
560 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
563 if (res == HOSTAPD_ACL_PENDING) {
564 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
565 " waiting for an external authentication",
567 /* Authentication code will re-send the authentication frame
568 * after it has received (and cached) information from the
569 * external source. */
573 sta = ap_sta_add(hapd, mgmt->sa);
575 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
580 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
581 sta->vlan_id) == NULL) {
582 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
583 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
584 "%d received from RADIUS server",
586 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
589 sta->vlan_id = vlan_id;
590 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
591 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
594 sta->flags &= ~WLAN_STA_PREAUTH;
595 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
597 if (hapd->conf->radius->acct_interim_interval == 0 &&
598 acct_interim_interval)
599 sta->acct_interim_interval = acct_interim_interval;
600 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
601 ap_sta_session_timeout(hapd, sta, session_timeout);
603 ap_sta_no_session_timeout(hapd, sta);
607 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
609 "authentication OK (open system)");
610 #ifdef IEEE80211_REQUIRE_AUTH_ACK
611 /* Station will be marked authenticated if it ACKs the
612 * authentication reply. */
614 sta->flags |= WLAN_STA_AUTH;
615 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
616 sta->auth_alg = WLAN_AUTH_OPEN;
617 mlme_authenticate_indication(hapd, sta);
620 case WLAN_AUTH_SHARED_KEY:
621 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
623 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
624 mlme_authenticate_indication(hapd, sta);
625 if (sta->challenge && auth_transaction == 1) {
626 resp_ies[0] = WLAN_EID_CHALLENGE;
627 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
628 os_memcpy(resp_ies + 2, sta->challenge,
629 WLAN_AUTH_CHALLENGE_LEN);
630 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
633 #ifdef CONFIG_IEEE80211R
635 sta->auth_alg = WLAN_AUTH_FT;
636 if (sta->wpa_sm == NULL)
637 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
639 if (sta->wpa_sm == NULL) {
640 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
642 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
645 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
646 auth_transaction, mgmt->u.auth.variable,
647 len - IEEE80211_HDRLEN -
648 sizeof(mgmt->u.auth),
649 handle_auth_ft_finish, hapd);
650 /* handle_auth_ft_finish() callback will complete auth. */
652 #endif /* CONFIG_IEEE80211R */
656 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
657 auth_transaction + 1, resp, resp_ies, resp_ies_len);
661 static void handle_assoc(struct hostapd_data *hapd,
662 struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
664 u16 capab_info, listen_interval;
665 u16 resp = WLAN_STATUS_SUCCESS;
668 int send_deauth = 0, send_len, left, i;
669 struct sta_info *sta;
670 struct ieee802_11_elems elems;
671 u8 buf[sizeof(struct ieee80211_mgmt) + 512];
672 struct ieee80211_mgmt *reply;
674 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
675 sizeof(mgmt->u.assoc_req))) {
676 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
677 "\n", reassoc, (unsigned long) len);
682 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
683 listen_interval = le_to_host16(
684 mgmt->u.reassoc_req.listen_interval);
685 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
686 " capab_info=0x%02x listen_interval=%d current_ap="
688 MAC2STR(mgmt->sa), capab_info, listen_interval,
689 MAC2STR(mgmt->u.reassoc_req.current_ap));
690 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
691 pos = mgmt->u.reassoc_req.variable;
693 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
694 listen_interval = le_to_host16(
695 mgmt->u.assoc_req.listen_interval);
696 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
697 " capab_info=0x%02x listen_interval=%d",
698 MAC2STR(mgmt->sa), capab_info, listen_interval);
699 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
700 pos = mgmt->u.assoc_req.variable;
703 sta = ap_get_sta(hapd, mgmt->sa);
704 #ifdef CONFIG_IEEE80211R
705 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
706 (sta->flags & WLAN_STA_AUTH) == 0) {
707 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
708 "prior to authentication since it is using "
709 "over-the-DS FT", MAC2STR(mgmt->sa));
711 #endif /* CONFIG_IEEE80211R */
712 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
713 printf("STA " MACSTR " trying to associate before "
714 "authentication\n", MAC2STR(mgmt->sa));
716 printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
717 MAC2STR(sta->addr), sta->aid, sta->flags);
720 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
724 if (hapd->tkip_countermeasures) {
725 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
729 if (listen_interval > hapd->conf->max_listen_interval) {
730 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
732 "Too large Listen Interval (%d)",
734 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
738 sta->capability = capab_info;
739 sta->listen_interval = listen_interval;
741 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
743 if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
745 printf("STA " MACSTR " sent invalid association request\n",
747 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
751 if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
752 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
755 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
756 printf("Station " MACSTR " tried to associate with "
757 "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
758 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
762 sta->flags &= ~WLAN_STA_WME;
763 if (elems.wme && hapd->conf->wme_enabled) {
764 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
765 hostapd_logger(hapd, sta->addr,
768 "invalid WME element in association "
771 sta->flags |= WLAN_STA_WME;
774 if (!elems.supp_rates) {
775 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
777 "No supported rates element in AssocReq");
778 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
782 if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
783 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
785 "Invalid supported rates element length %d",
786 elems.supp_rates_len);
787 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
791 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
792 os_memcpy(sta->supported_rates, elems.supp_rates,
793 elems.supp_rates_len);
794 sta->supported_rates_len = elems.supp_rates_len;
796 if (elems.ext_supp_rates) {
797 if (elems.supp_rates_len + elems.ext_supp_rates_len >
798 sizeof(sta->supported_rates)) {
799 hostapd_logger(hapd, mgmt->sa,
800 HOSTAPD_MODULE_IEEE80211,
802 "Invalid supported rates element length"
803 " %d+%d", elems.supp_rates_len,
804 elems.ext_supp_rates_len);
805 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
809 os_memcpy(sta->supported_rates + elems.supp_rates_len,
810 elems.ext_supp_rates, elems.ext_supp_rates_len);
811 sta->supported_rates_len += elems.ext_supp_rates_len;
814 #ifdef CONFIG_IEEE80211N
815 /* save HT capabilities in the sta object */
816 os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
817 if (elems.ht_capabilities &&
818 elems.ht_capabilities_len >=
819 sizeof(struct ieee80211_ht_capability)) {
820 sta->flags |= WLAN_STA_HT;
821 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
822 sta->ht_capabilities.length =
823 sizeof(struct ieee80211_ht_capability);
824 os_memcpy(&sta->ht_capabilities.data,
825 elems.ht_capabilities,
826 sizeof(struct ieee80211_ht_capability));
828 sta->flags &= ~WLAN_STA_HT;
829 #endif /* CONFIG_IEEE80211N */
831 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
832 wpa_ie = elems.rsn_ie;
833 wpa_ie_len = elems.rsn_ie_len;
834 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
836 wpa_ie = elems.wpa_ie;
837 wpa_ie_len = elems.wpa_ie_len;
843 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
844 if (hapd->conf->wps_state && wpa_ie == NULL) {
846 wpa_printf(MSG_DEBUG, "STA included WPS IE in "
847 "(Re)Association Request - assume WPS is "
849 sta->flags |= WLAN_STA_WPS;
850 wpabuf_free(sta->wps_ie);
851 sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4,
852 elems.wps_ie_len - 4);
854 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE "
855 "in (Re)Association Request - possible WPS "
857 sta->flags |= WLAN_STA_MAYBE_WPS;
860 #endif /* CONFIG_WPS */
861 if (hapd->conf->wpa && wpa_ie == NULL) {
862 printf("STA " MACSTR ": No WPA/RSN IE in association "
863 "request\n", MAC2STR(sta->addr));
864 resp = WLAN_STATUS_INVALID_IE;
868 if (hapd->conf->wpa && wpa_ie) {
872 if (sta->wpa_sm == NULL)
873 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
875 if (sta->wpa_sm == NULL) {
876 printf("Failed to initialize WPA state machine\n");
877 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
880 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
882 elems.mdie, elems.mdie_len);
883 if (res == WPA_INVALID_GROUP)
884 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
885 else if (res == WPA_INVALID_PAIRWISE)
886 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
887 else if (res == WPA_INVALID_AKMP)
888 resp = WLAN_STATUS_AKMP_NOT_VALID;
889 else if (res == WPA_ALLOC_FAIL)
890 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
891 #ifdef CONFIG_IEEE80211W
892 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
893 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
894 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
895 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
896 #endif /* CONFIG_IEEE80211W */
897 else if (res == WPA_INVALID_MDIE)
898 resp = WLAN_STATUS_INVALID_MDIE;
899 else if (res != WPA_IE_OK)
900 resp = WLAN_STATUS_INVALID_IE;
901 if (resp != WLAN_STATUS_SUCCESS)
903 #ifdef CONFIG_IEEE80211W
904 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
905 sta->sa_query_count > 0)
906 ap_check_sa_query_timeout(hapd, sta);
907 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out) {
909 * STA has already been associated with MFP and SA
910 * Query timeout has not been reached. Reject the
911 * association attempt temporarily and start SA Query,
912 * if one is not pending.
915 if (sta->sa_query_count == 0)
916 ap_sta_start_sa_query(hapd, sta);
918 resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
922 if (wpa_auth_uses_mfp(sta->wpa_sm))
923 sta->flags |= WLAN_STA_MFP;
925 sta->flags &= ~WLAN_STA_MFP;
926 #endif /* CONFIG_IEEE80211W */
928 #ifdef CONFIG_IEEE80211R
929 if (sta->auth_alg == WLAN_AUTH_FT) {
931 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
932 "to use association (not "
933 "re-association) with FT auth_alg",
935 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
939 resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
940 if (resp != WLAN_STATUS_SUCCESS)
943 #endif /* CONFIG_IEEE80211R */
944 #ifdef CONFIG_IEEE80211N
945 if ((sta->flags & WLAN_STA_HT) &&
946 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
947 wpa_printf(MSG_DEBUG, "HT: " MACSTR " tried to "
948 "use TKIP with HT association",
950 resp = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
953 #endif /* CONFIG_IEEE80211N */
955 wpa_auth_sta_no_wpa(sta->wpa_sm);
957 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
958 sta->flags |= WLAN_STA_NONERP;
959 for (i = 0; i < sta->supported_rates_len; i++) {
960 if ((sta->supported_rates[i] & 0x7f) > 22) {
961 sta->flags &= ~WLAN_STA_NONERP;
965 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
967 hapd->iface->num_sta_non_erp++;
968 if (hapd->iface->num_sta_non_erp == 1)
969 ieee802_11_set_beacons(hapd->iface);
972 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
973 !sta->no_short_slot_time_set) {
974 sta->no_short_slot_time_set = 1;
975 hapd->iface->num_sta_no_short_slot_time++;
976 if (hapd->iface->current_mode->mode ==
977 HOSTAPD_MODE_IEEE80211G &&
978 hapd->iface->num_sta_no_short_slot_time == 1)
979 ieee802_11_set_beacons(hapd->iface);
982 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
983 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
985 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
987 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
988 !sta->no_short_preamble_set) {
989 sta->no_short_preamble_set = 1;
990 hapd->iface->num_sta_no_short_preamble++;
991 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
992 && hapd->iface->num_sta_no_short_preamble == 1)
993 ieee802_11_set_beacons(hapd->iface);
996 #ifdef CONFIG_IEEE80211N
997 if (sta->flags & WLAN_STA_HT) {
998 u16 ht_capab = le_to_host16(
999 sta->ht_capabilities.data.capabilities_info);
1000 wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities "
1001 "Info: 0x%04x", MAC2STR(sta->addr), ht_capab);
1002 if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
1003 if (!sta->no_ht_gf_set) {
1004 sta->no_ht_gf_set = 1;
1005 hapd->iface->num_sta_ht_no_gf++;
1007 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
1008 "greenfield, num of non-gf stations %d",
1009 __func__, MAC2STR(sta->addr),
1010 hapd->iface->num_sta_ht_no_gf);
1012 if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
1013 if (!sta->ht_20mhz_set) {
1014 sta->ht_20mhz_set = 1;
1015 hapd->iface->num_sta_ht_20mhz++;
1017 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
1018 "num of 20MHz HT STAs %d",
1019 __func__, MAC2STR(sta->addr),
1020 hapd->iface->num_sta_ht_20mhz);
1023 if (!sta->no_ht_set) {
1025 hapd->iface->num_sta_no_ht++;
1027 if (hapd->iconf->ieee80211n) {
1028 wpa_printf(MSG_DEBUG, "%s STA " MACSTR
1029 " - no HT, num of non-HT stations %d",
1030 __func__, MAC2STR(sta->addr),
1031 hapd->iface->num_sta_no_ht);
1035 if (hostapd_ht_operation_update(hapd->iface) > 0)
1036 ieee802_11_set_beacons(hapd->iface);
1037 #endif /* CONFIG_IEEE80211N */
1039 /* get a unique AID */
1041 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1043 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1044 if (hapd->sta_aid[sta->aid - 1] == NULL)
1046 if (sta->aid > MAX_AID_TABLE_SIZE) {
1048 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1049 wpa_printf(MSG_ERROR, " no room for more AIDs");
1052 hapd->sta_aid[sta->aid - 1] = sta;
1053 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1057 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1058 HOSTAPD_LEVEL_DEBUG,
1059 "association OK (aid %d)", sta->aid);
1060 /* Station will be marked associated, after it acknowledges AssocResp
1064 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1068 if (sta->last_assoc_req)
1069 os_free(sta->last_assoc_req);
1070 sta->last_assoc_req = os_malloc(len);
1071 if (sta->last_assoc_req)
1072 os_memcpy(sta->last_assoc_req, mgmt, len);
1074 /* Make sure that the previously registered inactivity timer will not
1075 * remove the STA immediately. */
1076 sta->timeout_next = STA_NULLFUNC;
1079 os_memset(buf, 0, sizeof(buf));
1080 reply = (struct ieee80211_mgmt *) buf;
1081 reply->frame_control =
1082 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1083 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1084 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1085 WLAN_FC_STYPE_ASSOC_RESP)));
1086 os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1087 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1088 os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1090 send_len = IEEE80211_HDRLEN;
1092 send_len += sizeof(reply->u.deauth);
1093 reply->u.deauth.reason_code = host_to_le16(resp);
1096 send_len += sizeof(reply->u.assoc_resp);
1097 reply->u.assoc_resp.capab_info =
1098 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1099 reply->u.assoc_resp.status_code = host_to_le16(resp);
1100 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1101 | BIT(14) | BIT(15));
1102 /* Supported rates */
1103 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1104 /* Extended supported rates */
1105 p = hostapd_eid_ext_supp_rates(hapd, p);
1106 if (sta->flags & WLAN_STA_WME)
1107 p = hostapd_eid_wme(hapd, p);
1109 p = hostapd_eid_ht_capabilities_info(hapd, p);
1110 p = hostapd_eid_ht_operation(hapd, p);
1112 #ifdef CONFIG_IEEE80211R
1113 if (resp == WLAN_STATUS_SUCCESS) {
1114 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1115 * Transition Information, RSN */
1116 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1117 buf + sizeof(buf) - p,
1120 #endif /* CONFIG_IEEE80211R */
1122 #ifdef CONFIG_IEEE80211W
1123 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1124 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1125 #endif /* CONFIG_IEEE80211W */
1127 send_len += p - reply->u.assoc_resp.variable;
1130 if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1131 perror("handle_assoc: send");
1135 static void handle_disassoc(struct hostapd_data *hapd,
1136 struct ieee80211_mgmt *mgmt, size_t len)
1138 struct sta_info *sta;
1140 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1141 printf("handle_disassoc - too short payload (len=%lu)\n",
1142 (unsigned long) len);
1146 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1148 le_to_host16(mgmt->u.disassoc.reason_code));
1150 sta = ap_get_sta(hapd, mgmt->sa);
1152 printf("Station " MACSTR " trying to disassociate, but it "
1153 "is not associated.\n", MAC2STR(mgmt->sa));
1157 sta->flags &= ~WLAN_STA_ASSOC;
1158 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1159 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1160 HOSTAPD_LEVEL_INFO, "disassociated");
1161 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1162 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1163 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1165 accounting_sta_stop(hapd, sta);
1166 ieee802_1x_free_station(sta);
1167 hostapd_sta_remove(hapd, sta->addr);
1169 if (sta->timeout_next == STA_NULLFUNC ||
1170 sta->timeout_next == STA_DISASSOC) {
1171 sta->timeout_next = STA_DEAUTH;
1172 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1173 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1177 mlme_disassociate_indication(
1178 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1182 static void handle_deauth(struct hostapd_data *hapd,
1183 struct ieee80211_mgmt *mgmt, size_t len)
1185 struct sta_info *sta;
1187 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1188 printf("handle_deauth - too short payload (len=%lu)\n",
1189 (unsigned long) len);
1193 wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1196 le_to_host16(mgmt->u.deauth.reason_code));
1198 sta = ap_get_sta(hapd, mgmt->sa);
1200 printf("Station " MACSTR " trying to deauthenticate, but it "
1201 "is not authenticated.\n", MAC2STR(mgmt->sa));
1205 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1206 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1207 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1208 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1209 mlme_deauthenticate_indication(
1210 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1211 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1212 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1213 ap_free_sta(hapd, sta);
1217 static void handle_beacon(struct hostapd_data *hapd,
1218 struct ieee80211_mgmt *mgmt, size_t len,
1219 struct hostapd_frame_info *fi)
1221 struct ieee802_11_elems elems;
1223 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1224 printf("handle_beacon - too short payload (len=%lu)\n",
1225 (unsigned long) len);
1229 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1230 len - (IEEE80211_HDRLEN +
1231 sizeof(mgmt->u.beacon)), &elems,
1234 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1238 #ifdef CONFIG_IEEE80211W
1239 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1240 struct ieee80211_mgmt *mgmt, size_t len)
1242 struct sta_info *sta;
1246 end = mgmt->u.action.u.sa_query_resp.trans_id +
1247 WLAN_SA_QUERY_TR_ID_LEN;
1248 if (((u8 *) mgmt) + len < end) {
1249 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1250 "frame (len=%lu)", (unsigned long) len);
1254 if (mgmt->u.action.u.sa_query_resp.action != WLAN_SA_QUERY_RESPONSE) {
1255 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
1256 "Action %d", mgmt->u.action.u.sa_query_resp.action);
1260 /* MLME-SAQuery.confirm */
1262 sta = ap_get_sta(hapd, mgmt->sa);
1263 if (sta == NULL || sta->sa_query_trans_id == NULL) {
1264 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1265 "pending SA Query request found");
1269 for (i = 0; i < sta->sa_query_count; i++) {
1270 if (os_memcmp(sta->sa_query_trans_id +
1271 i * WLAN_SA_QUERY_TR_ID_LEN,
1272 mgmt->u.action.u.sa_query_resp.trans_id,
1273 WLAN_SA_QUERY_TR_ID_LEN) == 0)
1277 if (i >= sta->sa_query_count) {
1278 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching SA Query "
1279 "transaction identifier found");
1283 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1284 HOSTAPD_LEVEL_DEBUG,
1285 "Reply to pending SA Query received");
1286 ap_sta_stop_sa_query(hapd, sta);
1288 #endif /* CONFIG_IEEE80211W */
1291 static void handle_action(struct hostapd_data *hapd,
1292 struct ieee80211_mgmt *mgmt, size_t len)
1294 if (len < IEEE80211_HDRLEN + 1) {
1295 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1296 HOSTAPD_LEVEL_DEBUG,
1297 "handle_action - too short payload (len=%lu)",
1298 (unsigned long) len);
1302 switch (mgmt->u.action.category) {
1303 #ifdef CONFIG_IEEE80211R
1304 case WLAN_ACTION_FT:
1306 struct sta_info *sta;
1308 sta = ap_get_sta(hapd, mgmt->sa);
1309 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1310 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1311 "frame from unassociated STA " MACSTR,
1316 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1317 len - IEEE80211_HDRLEN))
1322 #endif /* CONFIG_IEEE80211R */
1323 case WLAN_ACTION_WMM:
1324 hostapd_wme_action(hapd, mgmt, len);
1326 #ifdef CONFIG_IEEE80211W
1327 case WLAN_ACTION_SA_QUERY:
1328 hostapd_sa_query_action(hapd, mgmt, len);
1330 #endif /* CONFIG_IEEE80211W */
1333 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1334 HOSTAPD_LEVEL_DEBUG,
1335 "handle_action - unknown action category %d or invalid "
1337 mgmt->u.action.category);
1338 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1339 !(mgmt->sa[0] & 0x01)) {
1341 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1342 * Return the Action frame to the source without change
1343 * except that MSB of the Category set to 1.
1345 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1346 "frame back to sender");
1347 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1348 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1349 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1350 mgmt->u.action.category |= 0x80;
1352 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1358 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1359 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1361 * @buf: management frame data (starting from IEEE 802.11 header)
1362 * @len: length of frame data in octets
1363 * @stype: management frame subtype from frame control field
1365 * Process all incoming IEEE 802.11 management frames. This will be called for
1366 * each frame received from the kernel driver through wlan#ap interface. In
1367 * addition, it can be called to re-inserted pending frames (e.g., when using
1368 * external RADIUS server as an MAC ACL).
1370 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1371 struct hostapd_frame_info *fi)
1373 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1376 if (stype == WLAN_FC_STYPE_BEACON) {
1377 handle_beacon(hapd, mgmt, len, fi);
1381 if (fi && fi->passive_scan)
1384 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1385 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1386 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1389 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1390 printf("MGMT: BSSID=" MACSTR " not our address\n",
1391 MAC2STR(mgmt->bssid));
1396 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1397 handle_probe_req(hapd, mgmt, len);
1401 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1402 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1403 HOSTAPD_LEVEL_DEBUG,
1404 "MGMT: DA=" MACSTR " not our address",
1410 case WLAN_FC_STYPE_AUTH:
1411 wpa_printf(MSG_DEBUG, "mgmt::auth");
1412 handle_auth(hapd, mgmt, len);
1414 case WLAN_FC_STYPE_ASSOC_REQ:
1415 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1416 handle_assoc(hapd, mgmt, len, 0);
1418 case WLAN_FC_STYPE_REASSOC_REQ:
1419 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1420 handle_assoc(hapd, mgmt, len, 1);
1422 case WLAN_FC_STYPE_DISASSOC:
1423 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1424 handle_disassoc(hapd, mgmt, len);
1426 case WLAN_FC_STYPE_DEAUTH:
1427 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1428 handle_deauth(hapd, mgmt, len);
1430 case WLAN_FC_STYPE_ACTION:
1431 wpa_printf(MSG_DEBUG, "mgmt::action");
1432 handle_action(hapd, mgmt, len);
1435 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1436 HOSTAPD_LEVEL_DEBUG,
1437 "unknown mgmt frame subtype %d", stype);
1443 static void handle_auth_cb(struct hostapd_data *hapd,
1444 struct ieee80211_mgmt *mgmt,
1447 u16 auth_alg, auth_transaction, status_code;
1448 struct sta_info *sta;
1451 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1452 HOSTAPD_LEVEL_NOTICE,
1453 "did not acknowledge authentication response");
1457 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1458 printf("handle_auth_cb - too short payload (len=%lu)\n",
1459 (unsigned long) len);
1463 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1464 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1465 status_code = le_to_host16(mgmt->u.auth.status_code);
1467 sta = ap_get_sta(hapd, mgmt->da);
1469 printf("handle_auth_cb: STA " MACSTR " not found\n",
1474 if (status_code == WLAN_STATUS_SUCCESS &&
1475 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1476 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1477 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1478 HOSTAPD_LEVEL_INFO, "authenticated");
1479 sta->flags |= WLAN_STA_AUTH;
1484 static void handle_assoc_cb(struct hostapd_data *hapd,
1485 struct ieee80211_mgmt *mgmt,
1486 size_t len, int reassoc, int ok)
1489 struct sta_info *sta;
1491 struct ht_cap_ie *ht_cap = NULL;
1494 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1495 HOSTAPD_LEVEL_DEBUG,
1496 "did not acknowledge association response");
1500 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1501 sizeof(mgmt->u.assoc_resp))) {
1502 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1503 "(len=%lu)\n", reassoc, (unsigned long) len);
1508 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1510 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1512 sta = ap_get_sta(hapd, mgmt->da);
1514 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1519 if (status != WLAN_STATUS_SUCCESS)
1522 /* Stop previous accounting session, if one is started, and allocate
1523 * new session id for the new session. */
1524 accounting_sta_stop(hapd, sta);
1526 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1528 "associated (aid %d)",
1531 if (sta->flags & WLAN_STA_ASSOC)
1533 sta->flags |= WLAN_STA_ASSOC;
1536 mlme_reassociate_indication(hapd, sta);
1538 mlme_associate_indication(hapd, sta);
1540 #ifdef CONFIG_IEEE80211N
1541 if (sta->flags & WLAN_STA_HT)
1542 ht_cap = &sta->ht_capabilities;
1543 #endif /* CONFIG_IEEE80211N */
1545 #ifdef CONFIG_IEEE80211W
1546 sta->sa_query_timed_out = 0;
1547 #endif /* CONFIG_IEEE80211W */
1549 if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1550 sta->capability, sta->supported_rates,
1551 sta->supported_rates_len, 0, sta->listen_interval,
1554 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1555 HOSTAPD_LEVEL_NOTICE,
1556 "Could not add STA to kernel driver");
1559 if (sta->eapol_sm == NULL) {
1561 * This STA does not use RADIUS server for EAP authentication,
1562 * so bind it to the selected VLAN interface now, since the
1563 * interface selection is not going to change anymore.
1565 ap_sta_bind_vlan(hapd, sta, 0);
1566 } else if (sta->vlan_id) {
1567 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1568 ap_sta_bind_vlan(hapd, sta, 0);
1570 if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1571 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1572 WLAN_STA_SHORT_PREAMBLE, ~0);
1574 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1575 0, ~WLAN_STA_SHORT_PREAMBLE);
1578 if (sta->auth_alg == WLAN_AUTH_FT)
1579 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1581 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1582 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1584 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1587 /* Copy of the association request is not needed anymore */
1588 if (sta->last_assoc_req) {
1589 os_free(sta->last_assoc_req);
1590 sta->last_assoc_req = NULL;
1595 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1598 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1601 case WLAN_FC_STYPE_AUTH:
1602 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1603 handle_auth_cb(hapd, mgmt, len, ok);
1605 case WLAN_FC_STYPE_ASSOC_RESP:
1606 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1607 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1609 case WLAN_FC_STYPE_REASSOC_RESP:
1610 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1611 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1613 case WLAN_FC_STYPE_PROBE_RESP:
1614 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1616 case WLAN_FC_STYPE_DEAUTH:
1619 case WLAN_FC_STYPE_ACTION:
1620 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1623 printf("unknown mgmt cb frame subtype %d\n", stype);
1629 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1632 struct hostapd_data *hapd = eloop_ctx;
1633 hapd->tkip_countermeasures = 0;
1634 hostapd_set_countermeasures(hapd, 0);
1635 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1636 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
1640 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
1642 struct sta_info *sta;
1644 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1645 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
1647 wpa_auth_countermeasures_start(hapd->wpa_auth);
1648 hapd->tkip_countermeasures = 1;
1649 hostapd_set_countermeasures(hapd, 1);
1650 wpa_gtk_rekey(hapd->wpa_auth);
1651 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
1652 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
1654 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
1655 hostapd_sta_deauth(hapd, sta->addr,
1656 WLAN_REASON_MICHAEL_MIC_FAILURE);
1657 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1658 WLAN_STA_AUTHORIZED);
1659 hostapd_sta_remove(hapd, sta->addr);
1664 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
1669 if (addr && local) {
1670 struct sta_info *sta = ap_get_sta(hapd, addr);
1672 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
1673 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1675 "Michael MIC failure detected in "
1677 mlme_michaelmicfailure_indication(hapd, addr);
1679 wpa_printf(MSG_DEBUG,
1680 "MLME-MICHAELMICFAILURE.indication "
1681 "for not associated STA (" MACSTR
1682 ") ignored", MAC2STR(addr));
1688 if (now > hapd->michael_mic_failure + 60) {
1689 hapd->michael_mic_failures = 1;
1691 hapd->michael_mic_failures++;
1692 if (hapd->michael_mic_failures > 1)
1693 ieee80211_tkip_countermeasures_start(hapd);
1695 hapd->michael_mic_failure = now;
1699 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1706 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1707 char *buf, size_t buflen)
1713 #endif /* CONFIG_NATIVE_WINDOWS */