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->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
152 pos += sizeof(*oper);
155 #else /* CONFIG_IEEE80211N */
157 #endif /* CONFIG_IEEE80211N */
161 #ifdef CONFIG_IEEE80211N
165 Set to 0 (HT pure) under the followign conditions
166 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
167 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
168 Set to 1 (HT non-member protection) if there may be non-HT STAs
169 in both the primary and the secondary channel
170 Set to 2 if only HT STAs are associated in BSS,
171 however and at least one 20 MHz HT STA is associated
172 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
173 (currently non-GF HT station is considered as non-HT STA also)
175 int hostapd_ht_operation_update(struct hostapd_iface *iface)
177 u16 cur_op_mode, new_op_mode;
178 int op_mode_changes = 0;
180 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
183 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
184 __func__, iface->ht_op_mode);
186 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
187 && iface->num_sta_ht_no_gf) {
189 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
191 } else if ((iface->ht_op_mode &
192 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
193 iface->num_sta_ht_no_gf == 0) {
195 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
199 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
200 (iface->num_sta_no_ht || iface->olbc_ht)) {
201 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
203 } else if ((iface->ht_op_mode &
204 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
205 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
207 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
211 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
212 * station is associated. Probably it's a theoretical case, since
213 * it looks like all known HT STAs support greenfield.
216 if (iface->num_sta_no_ht ||
217 (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
218 new_op_mode = OP_MODE_MIXED;
219 else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
220 && iface->num_sta_ht_20mhz)
221 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
222 else if (iface->olbc_ht)
223 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
225 new_op_mode = OP_MODE_PURE;
227 cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
228 if (cur_op_mode != new_op_mode) {
229 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
230 iface->ht_op_mode |= new_op_mode;
234 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
235 __func__, iface->ht_op_mode, op_mode_changes);
237 return op_mode_changes;
240 #endif /* CONFIG_IEEE80211N */
243 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
246 int capab = WLAN_CAPABILITY_ESS;
249 if (hapd->iface->num_sta_no_short_preamble == 0 &&
250 hapd->iconf->preamble == SHORT_PREAMBLE)
251 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
253 privacy = hapd->conf->ssid.wep.keys_set;
255 if (hapd->conf->ieee802_1x &&
256 (hapd->conf->default_wep_key_len ||
257 hapd->conf->individual_wep_key_len))
264 int policy, def_klen;
265 if (probe && sta->ssid_probe) {
266 policy = sta->ssid_probe->security_policy;
267 def_klen = sta->ssid_probe->wep.default_len;
269 policy = sta->ssid->security_policy;
270 def_klen = sta->ssid->wep.default_len;
272 privacy = policy != SECURITY_PLAINTEXT;
273 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
278 capab |= WLAN_CAPABILITY_PRIVACY;
280 if (hapd->iface->current_mode &&
281 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
282 hapd->iface->num_sta_no_short_slot_time == 0)
283 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
289 #ifdef CONFIG_IEEE80211W
290 static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
291 struct sta_info *sta, u8 *eid)
296 *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
298 timeout = (hapd->conf->assoc_ping_attempts - sta->ping_count + 1) *
299 hapd->conf->assoc_ping_timeout;
300 WPA_PUT_LE32(pos, timeout);
305 #endif /* CONFIG_IEEE80211W */
308 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
311 if (len > HOSTAPD_MAX_SSID_LEN)
312 len = HOSTAPD_MAX_SSID_LEN;
313 for (i = 0; i < len; i++) {
314 if (ssid[i] >= 32 && ssid[i] < 127)
323 void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
325 struct ieee80211_mgmt mgmt;
327 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
329 "deauthenticate - reason %d", reason);
330 os_memset(&mgmt, 0, sizeof(mgmt));
331 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
332 WLAN_FC_STYPE_DEAUTH);
333 os_memcpy(mgmt.da, addr, ETH_ALEN);
334 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
335 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
336 mgmt.u.deauth.reason_code = host_to_le16(reason);
337 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
338 sizeof(mgmt.u.deauth), 0) < 0)
339 perror("ieee802_11_send_deauth: send");
343 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
344 u16 auth_transaction, u8 *challenge, int iswep)
346 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
348 "authentication (shared key, transaction %d)",
351 if (auth_transaction == 1) {
352 if (!sta->challenge) {
353 /* Generate a pseudo-random challenge */
357 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
358 if (sta->challenge == NULL)
359 return WLAN_STATUS_UNSPECIFIED_FAILURE;
363 os_memcpy(key, &now, 4);
364 os_memcpy(key + 4, &r, 4);
365 rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
371 if (auth_transaction != 3)
372 return WLAN_STATUS_UNSPECIFIED_FAILURE;
375 if (!iswep || !sta->challenge || !challenge ||
376 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
377 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
379 "shared key authentication - invalid "
380 "challenge-response");
381 return WLAN_STATUS_CHALLENGE_FAIL;
384 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
386 "authentication OK (shared key)");
387 #ifdef IEEE80211_REQUIRE_AUTH_ACK
388 /* Station will be marked authenticated if it ACKs the
389 * authentication reply. */
391 sta->flags |= WLAN_STA_AUTH;
392 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
394 os_free(sta->challenge);
395 sta->challenge = NULL;
401 static void send_auth_reply(struct hostapd_data *hapd,
402 const u8 *dst, const u8 *bssid,
403 u16 auth_alg, u16 auth_transaction, u16 resp,
404 const u8 *ies, size_t ies_len)
406 struct ieee80211_mgmt *reply;
410 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
411 buf = os_zalloc(rlen);
415 reply = (struct ieee80211_mgmt *) buf;
416 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
418 os_memcpy(reply->da, dst, ETH_ALEN);
419 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
420 os_memcpy(reply->bssid, bssid, ETH_ALEN);
422 reply->u.auth.auth_alg = host_to_le16(auth_alg);
423 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
424 reply->u.auth.status_code = host_to_le16(resp);
427 os_memcpy(reply->u.auth.variable, ies, ies_len);
429 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
430 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
431 MAC2STR(dst), auth_alg, auth_transaction,
432 resp, (unsigned long) ies_len);
433 if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
434 perror("send_auth_reply: send");
440 #ifdef CONFIG_IEEE80211R
441 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
442 u16 auth_transaction, u16 status,
443 const u8 *ies, size_t ies_len)
445 struct hostapd_data *hapd = ctx;
446 struct sta_info *sta;
448 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
449 status, ies, ies_len);
451 if (status != WLAN_STATUS_SUCCESS)
454 sta = ap_get_sta(hapd, dst);
458 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
459 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
460 sta->flags |= WLAN_STA_AUTH;
461 mlme_authenticate_indication(hapd, sta);
463 #endif /* CONFIG_IEEE80211R */
466 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
469 u16 auth_alg, auth_transaction, status_code;
470 u16 resp = WLAN_STATUS_SUCCESS;
471 struct sta_info *sta = NULL;
474 u8 *challenge = NULL;
475 u32 session_timeout, acct_interim_interval;
477 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
478 size_t resp_ies_len = 0;
480 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
481 printf("handle_auth - too short payload (len=%lu)\n",
482 (unsigned long) len);
486 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
487 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
488 status_code = le_to_host16(mgmt->u.auth.status_code);
489 fc = le_to_host16(mgmt->frame_control);
491 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
492 2 + WLAN_AUTH_CHALLENGE_LEN &&
493 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
494 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
495 challenge = &mgmt->u.auth.variable[2];
497 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
498 "auth_transaction=%d status_code=%d wep=%d%s",
499 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
500 status_code, !!(fc & WLAN_FC_ISWEP),
501 challenge ? " challenge" : "");
503 if (hapd->tkip_countermeasures) {
504 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
508 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
509 auth_alg == WLAN_AUTH_OPEN) ||
510 #ifdef CONFIG_IEEE80211R
512 (hapd->conf->wpa_key_mgmt &
513 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
514 auth_alg == WLAN_AUTH_FT) ||
515 #endif /* CONFIG_IEEE80211R */
516 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
517 auth_alg == WLAN_AUTH_SHARED_KEY))) {
518 printf("Unsupported authentication algorithm (%d)\n",
520 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
524 if (!(auth_transaction == 1 ||
525 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
526 printf("Unknown authentication transaction number (%d)\n",
528 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
532 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
533 printf("Station " MACSTR " not allowed to authenticate.\n",
535 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
539 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
541 &acct_interim_interval, &vlan_id);
542 if (res == HOSTAPD_ACL_REJECT) {
543 printf("Station " MACSTR " not allowed to authenticate.\n",
545 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
548 if (res == HOSTAPD_ACL_PENDING) {
549 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
550 " waiting for an external authentication",
552 /* Authentication code will re-send the authentication frame
553 * after it has received (and cached) information from the
554 * external source. */
558 sta = ap_sta_add(hapd, mgmt->sa);
560 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
565 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
566 sta->vlan_id) == NULL) {
567 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
568 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
569 "%d received from RADIUS server",
571 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
574 sta->vlan_id = vlan_id;
575 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
576 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
579 sta->flags &= ~WLAN_STA_PREAUTH;
580 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
582 if (hapd->conf->radius->acct_interim_interval == 0 &&
583 acct_interim_interval)
584 sta->acct_interim_interval = acct_interim_interval;
585 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
586 ap_sta_session_timeout(hapd, sta, session_timeout);
588 ap_sta_no_session_timeout(hapd, sta);
592 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
594 "authentication OK (open system)");
595 #ifdef IEEE80211_REQUIRE_AUTH_ACK
596 /* Station will be marked authenticated if it ACKs the
597 * authentication reply. */
599 sta->flags |= WLAN_STA_AUTH;
600 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
601 sta->auth_alg = WLAN_AUTH_OPEN;
602 mlme_authenticate_indication(hapd, sta);
605 case WLAN_AUTH_SHARED_KEY:
606 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
608 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
609 mlme_authenticate_indication(hapd, sta);
610 if (sta->challenge && auth_transaction == 1) {
611 resp_ies[0] = WLAN_EID_CHALLENGE;
612 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
613 os_memcpy(resp_ies + 2, sta->challenge,
614 WLAN_AUTH_CHALLENGE_LEN);
615 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
618 #ifdef CONFIG_IEEE80211R
620 sta->auth_alg = WLAN_AUTH_FT;
621 if (sta->wpa_sm == NULL)
622 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
624 if (sta->wpa_sm == NULL) {
625 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
627 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
630 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
631 auth_transaction, mgmt->u.auth.variable,
632 len - IEEE80211_HDRLEN -
633 sizeof(mgmt->u.auth),
634 handle_auth_ft_finish, hapd);
635 /* handle_auth_ft_finish() callback will complete auth. */
637 #endif /* CONFIG_IEEE80211R */
641 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
642 auth_transaction + 1, resp, resp_ies, resp_ies_len);
646 static void handle_assoc(struct hostapd_data *hapd,
647 struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
649 u16 capab_info, listen_interval;
650 u16 resp = WLAN_STATUS_SUCCESS;
653 int send_deauth = 0, send_len, left, i;
654 struct sta_info *sta;
655 struct ieee802_11_elems elems;
656 u8 buf[sizeof(struct ieee80211_mgmt) + 512];
657 struct ieee80211_mgmt *reply;
659 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
660 sizeof(mgmt->u.assoc_req))) {
661 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
662 "\n", reassoc, (unsigned long) len);
667 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
668 listen_interval = le_to_host16(
669 mgmt->u.reassoc_req.listen_interval);
670 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
671 " capab_info=0x%02x listen_interval=%d current_ap="
673 MAC2STR(mgmt->sa), capab_info, listen_interval,
674 MAC2STR(mgmt->u.reassoc_req.current_ap));
675 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
676 pos = mgmt->u.reassoc_req.variable;
678 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
679 listen_interval = le_to_host16(
680 mgmt->u.assoc_req.listen_interval);
681 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
682 " capab_info=0x%02x listen_interval=%d",
683 MAC2STR(mgmt->sa), capab_info, listen_interval);
684 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
685 pos = mgmt->u.assoc_req.variable;
688 sta = ap_get_sta(hapd, mgmt->sa);
689 #ifdef CONFIG_IEEE80211R
690 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
691 (sta->flags & WLAN_STA_AUTH) == 0) {
692 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
693 "prior to authentication since it is using "
694 "over-the-DS FT", MAC2STR(mgmt->sa));
696 #endif /* CONFIG_IEEE80211R */
697 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
698 printf("STA " MACSTR " trying to associate before "
699 "authentication\n", MAC2STR(mgmt->sa));
701 printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
702 MAC2STR(sta->addr), sta->aid, sta->flags);
705 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
709 if (hapd->tkip_countermeasures) {
710 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
714 if (listen_interval > hapd->conf->max_listen_interval) {
715 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
717 "Too large Listen Interval (%d)",
719 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
723 sta->capability = capab_info;
725 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
727 if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
729 printf("STA " MACSTR " sent invalid association request\n",
731 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
735 if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
736 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
739 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
740 printf("Station " MACSTR " tried to associate with "
741 "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
742 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
746 sta->flags &= ~WLAN_STA_WME;
747 if (elems.wme && hapd->conf->wme_enabled) {
748 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
749 hostapd_logger(hapd, sta->addr,
752 "invalid WME element in association "
755 sta->flags |= WLAN_STA_WME;
758 if (!elems.supp_rates) {
759 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
761 "No supported rates element in AssocReq");
762 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
766 if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
767 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
769 "Invalid supported rates element length %d",
770 elems.supp_rates_len);
771 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
775 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
776 os_memcpy(sta->supported_rates, elems.supp_rates,
777 elems.supp_rates_len);
778 sta->supported_rates_len = elems.supp_rates_len;
780 if (elems.ext_supp_rates) {
781 if (elems.supp_rates_len + elems.ext_supp_rates_len >
782 sizeof(sta->supported_rates)) {
783 hostapd_logger(hapd, mgmt->sa,
784 HOSTAPD_MODULE_IEEE80211,
786 "Invalid supported rates element length"
787 " %d+%d", elems.supp_rates_len,
788 elems.ext_supp_rates_len);
789 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
793 os_memcpy(sta->supported_rates + elems.supp_rates_len,
794 elems.ext_supp_rates, elems.ext_supp_rates_len);
795 sta->supported_rates_len += elems.ext_supp_rates_len;
798 #ifdef CONFIG_IEEE80211N
799 /* save HT capabilities in the sta object */
800 os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
801 if (elems.ht_capabilities &&
802 elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
803 && (sta->flags & WLAN_STA_WME)) {
804 /* note: without WMM capability, treat the sta as non-HT */
805 sta->flags |= WLAN_STA_HT;
806 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
807 sta->ht_capabilities.length =
808 sizeof(struct ieee80211_ht_capability);
809 os_memcpy(&sta->ht_capabilities.data,
810 elems.ht_capabilities,
811 sizeof(struct ieee80211_ht_capability));
813 sta->flags &= ~WLAN_STA_HT;
814 #endif /* CONFIG_IEEE80211N */
816 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
817 wpa_ie = elems.rsn_ie;
818 wpa_ie_len = elems.rsn_ie_len;
819 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
821 wpa_ie = elems.wpa_ie;
822 wpa_ie_len = elems.wpa_ie_len;
827 if (hapd->conf->wpa && wpa_ie == NULL) {
828 printf("STA " MACSTR ": No WPA/RSN IE in association "
829 "request\n", MAC2STR(sta->addr));
830 resp = WLAN_STATUS_INVALID_IE;
834 if (hapd->conf->wpa && wpa_ie) {
838 if (sta->wpa_sm == NULL)
839 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
841 if (sta->wpa_sm == NULL) {
842 printf("Failed to initialize WPA state machine\n");
843 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
846 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
848 elems.mdie, elems.mdie_len);
849 if (res == WPA_INVALID_GROUP)
850 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
851 else if (res == WPA_INVALID_PAIRWISE)
852 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
853 else if (res == WPA_INVALID_AKMP)
854 resp = WLAN_STATUS_AKMP_NOT_VALID;
855 else if (res == WPA_ALLOC_FAIL)
856 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
857 #ifdef CONFIG_IEEE80211W
858 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
859 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
860 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
861 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
862 #endif /* CONFIG_IEEE80211W */
863 else if (res == WPA_INVALID_MDIE)
864 resp = WLAN_STATUS_INVALID_MDIE;
865 else if (res != WPA_IE_OK)
866 resp = WLAN_STATUS_INVALID_IE;
867 if (resp != WLAN_STATUS_SUCCESS)
869 #ifdef CONFIG_IEEE80211W
870 if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
872 * STA has already been associated with MFP and ping
873 * timeout has not been reached. Reject the
874 * association attempt temporarily and start ping, if
875 * one is not pending.
878 if (sta->ping_count == 0)
879 ap_sta_start_ping(hapd, sta);
881 resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
885 if (wpa_auth_uses_mfp(sta->wpa_sm))
886 sta->flags |= WLAN_STA_MFP;
888 sta->flags &= ~WLAN_STA_MFP;
889 #endif /* CONFIG_IEEE80211W */
891 #ifdef CONFIG_IEEE80211R
892 if (sta->auth_alg == WLAN_AUTH_FT) {
894 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
895 "to use association (not "
896 "re-association) with FT auth_alg",
898 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
902 resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
903 if (resp != WLAN_STATUS_SUCCESS)
906 #endif /* CONFIG_IEEE80211R */
909 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
910 sta->flags |= WLAN_STA_NONERP;
911 for (i = 0; i < sta->supported_rates_len; i++) {
912 if ((sta->supported_rates[i] & 0x7f) > 22) {
913 sta->flags &= ~WLAN_STA_NONERP;
917 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
919 hapd->iface->num_sta_non_erp++;
920 if (hapd->iface->num_sta_non_erp == 1)
921 ieee802_11_set_beacons(hapd->iface);
924 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
925 !sta->no_short_slot_time_set) {
926 sta->no_short_slot_time_set = 1;
927 hapd->iface->num_sta_no_short_slot_time++;
928 if (hapd->iface->current_mode->mode ==
929 HOSTAPD_MODE_IEEE80211G &&
930 hapd->iface->num_sta_no_short_slot_time == 1)
931 ieee802_11_set_beacons(hapd->iface);
934 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
935 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
937 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
939 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
940 !sta->no_short_preamble_set) {
941 sta->no_short_preamble_set = 1;
942 hapd->iface->num_sta_no_short_preamble++;
943 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
944 && hapd->iface->num_sta_no_short_preamble == 1)
945 ieee802_11_set_beacons(hapd->iface);
948 #ifdef CONFIG_IEEE80211N
949 if (sta->flags & WLAN_STA_HT) {
950 if ((sta->ht_capabilities.data.capabilities_info &
951 HT_CAP_INFO_GREEN_FIELD) == 0) {
952 hapd->iface->num_sta_ht_no_gf++;
953 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
954 "greenfield, num of non-gf stations %d",
955 __func__, MAC2STR(sta->addr),
956 hapd->iface->num_sta_ht_no_gf);
958 if ((sta->ht_capabilities.data.capabilities_info &
959 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
960 hapd->iface->num_sta_ht_20mhz++;
961 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
962 "num of 20MHz HT STAs %d",
963 __func__, MAC2STR(sta->addr),
964 hapd->iface->num_sta_ht_20mhz);
967 hapd->iface->num_sta_no_ht++;
968 if (hapd->iconf->ieee80211n) {
969 wpa_printf(MSG_DEBUG, "%s STA " MACSTR
970 " - no HT, num of non-HT stations %d",
971 __func__, MAC2STR(sta->addr),
972 hapd->iface->num_sta_no_ht);
976 if (hostapd_ht_operation_update(hapd->iface) > 0)
977 ieee802_11_set_beacons(hapd->iface);
978 #endif /* CONFIG_IEEE80211N */
980 /* get a unique AID */
982 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
984 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
985 if (hapd->sta_aid[sta->aid - 1] == NULL)
987 if (sta->aid > MAX_AID_TABLE_SIZE) {
989 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
990 wpa_printf(MSG_ERROR, " no room for more AIDs");
993 hapd->sta_aid[sta->aid - 1] = sta;
994 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
998 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1000 "association OK (aid %d)", sta->aid);
1001 /* Station will be marked associated, after it acknowledges AssocResp
1005 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1009 if (sta->last_assoc_req)
1010 os_free(sta->last_assoc_req);
1011 sta->last_assoc_req = os_malloc(len);
1012 if (sta->last_assoc_req)
1013 os_memcpy(sta->last_assoc_req, mgmt, len);
1015 /* Make sure that the previously registered inactivity timer will not
1016 * remove the STA immediately. */
1017 sta->timeout_next = STA_NULLFUNC;
1020 os_memset(buf, 0, sizeof(buf));
1021 reply = (struct ieee80211_mgmt *) buf;
1022 reply->frame_control =
1023 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1024 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1025 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1026 WLAN_FC_STYPE_ASSOC_RESP)));
1027 os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1028 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1029 os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1031 send_len = IEEE80211_HDRLEN;
1033 send_len += sizeof(reply->u.deauth);
1034 reply->u.deauth.reason_code = host_to_le16(resp);
1037 send_len += sizeof(reply->u.assoc_resp);
1038 reply->u.assoc_resp.capab_info =
1039 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1040 reply->u.assoc_resp.status_code = host_to_le16(resp);
1041 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1042 | BIT(14) | BIT(15));
1043 /* Supported rates */
1044 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1045 /* Extended supported rates */
1046 p = hostapd_eid_ext_supp_rates(hapd, p);
1047 if (sta->flags & WLAN_STA_WME)
1048 p = hostapd_eid_wme(hapd, p);
1050 p = hostapd_eid_ht_capabilities_info(hapd, p);
1051 p = hostapd_eid_ht_operation(hapd, p);
1053 #ifdef CONFIG_IEEE80211R
1054 if (resp == WLAN_STATUS_SUCCESS) {
1055 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1056 * Transition Information, RSN */
1057 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1058 buf + sizeof(buf) - p,
1061 #endif /* CONFIG_IEEE80211R */
1063 #ifdef CONFIG_IEEE80211W
1064 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1065 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1066 #endif /* CONFIG_IEEE80211W */
1068 send_len += p - reply->u.assoc_resp.variable;
1071 if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1072 perror("handle_assoc: send");
1076 static void handle_disassoc(struct hostapd_data *hapd,
1077 struct ieee80211_mgmt *mgmt, size_t len)
1079 struct sta_info *sta;
1081 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1082 printf("handle_disassoc - too short payload (len=%lu)\n",
1083 (unsigned long) len);
1087 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1089 le_to_host16(mgmt->u.disassoc.reason_code));
1091 sta = ap_get_sta(hapd, mgmt->sa);
1093 printf("Station " MACSTR " trying to disassociate, but it "
1094 "is not associated.\n", MAC2STR(mgmt->sa));
1098 sta->flags &= ~WLAN_STA_ASSOC;
1099 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1100 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1101 HOSTAPD_LEVEL_INFO, "disassociated");
1102 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1103 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1104 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1106 accounting_sta_stop(hapd, sta);
1107 ieee802_1x_free_station(sta);
1108 hostapd_sta_remove(hapd, sta->addr);
1110 if (sta->timeout_next == STA_NULLFUNC ||
1111 sta->timeout_next == STA_DISASSOC) {
1112 sta->timeout_next = STA_DEAUTH;
1113 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1114 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1118 mlme_disassociate_indication(
1119 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1123 static void handle_deauth(struct hostapd_data *hapd,
1124 struct ieee80211_mgmt *mgmt, size_t len)
1126 struct sta_info *sta;
1128 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1129 printf("handle_deauth - too short payload (len=%lu)\n",
1130 (unsigned long) len);
1134 wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1137 le_to_host16(mgmt->u.deauth.reason_code));
1139 sta = ap_get_sta(hapd, mgmt->sa);
1141 printf("Station " MACSTR " trying to deauthenticate, but it "
1142 "is not authenticated.\n", MAC2STR(mgmt->sa));
1146 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1147 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1148 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1149 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1150 mlme_deauthenticate_indication(
1151 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1152 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1153 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1154 ap_free_sta(hapd, sta);
1158 static void handle_beacon(struct hostapd_data *hapd,
1159 struct ieee80211_mgmt *mgmt, size_t len,
1160 struct hostapd_frame_info *fi)
1162 struct ieee802_11_elems elems;
1164 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1165 printf("handle_beacon - too short payload (len=%lu)\n",
1166 (unsigned long) len);
1170 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1171 len - (IEEE80211_HDRLEN +
1172 sizeof(mgmt->u.beacon)), &elems,
1175 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1179 #ifdef CONFIG_IEEE80211W
1180 static void hostapd_ping_action(struct hostapd_data *hapd,
1181 struct ieee80211_mgmt *mgmt, size_t len)
1183 struct sta_info *sta;
1187 end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
1188 if (((u8 *) mgmt) + len < end) {
1189 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
1190 "frame (len=%lu)", (unsigned long) len);
1194 if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
1195 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
1196 mgmt->u.action.u.ping_resp.action);
1200 /* MLME-PING.confirm */
1202 sta = ap_get_sta(hapd, mgmt->sa);
1203 if (sta == NULL || sta->ping_trans_id == NULL) {
1204 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1205 "pending ping request found");
1209 for (i = 0; i < sta->ping_count; i++) {
1210 if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
1211 mgmt->u.action.u.ping_resp.trans_id,
1212 WLAN_PING_TRANS_ID_LEN) == 0)
1216 if (i >= sta->ping_count) {
1217 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
1218 "transaction identifier found");
1222 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1223 HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
1224 ap_sta_stop_ping(hapd, sta);
1226 #endif /* CONFIG_IEEE80211W */
1229 static void handle_action(struct hostapd_data *hapd,
1230 struct ieee80211_mgmt *mgmt, size_t len)
1232 if (len < IEEE80211_HDRLEN + 1) {
1233 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1234 HOSTAPD_LEVEL_DEBUG,
1235 "handle_action - too short payload (len=%lu)",
1236 (unsigned long) len);
1240 switch (mgmt->u.action.category) {
1241 #ifdef CONFIG_IEEE80211R
1242 case WLAN_ACTION_FT:
1244 struct sta_info *sta;
1246 sta = ap_get_sta(hapd, mgmt->sa);
1247 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1248 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1249 "frame from unassociated STA " MACSTR,
1254 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1255 len - IEEE80211_HDRLEN))
1260 #endif /* CONFIG_IEEE80211R */
1261 case WLAN_ACTION_WMM:
1262 hostapd_wme_action(hapd, mgmt, len);
1264 #ifdef CONFIG_IEEE80211W
1265 case WLAN_ACTION_PING:
1266 hostapd_ping_action(hapd, mgmt, len);
1268 #endif /* CONFIG_IEEE80211W */
1271 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1272 HOSTAPD_LEVEL_DEBUG,
1273 "handle_action - unknown action category %d or invalid "
1275 mgmt->u.action.category);
1276 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1277 !(mgmt->sa[0] & 0x01)) {
1279 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1280 * Return the Action frame to the source without change
1281 * except that MSB of the Category set to 1.
1283 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1284 "frame back to sender");
1285 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1286 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1287 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1288 mgmt->u.action.category |= 0x80;
1290 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1296 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1297 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1299 * @buf: management frame data (starting from IEEE 802.11 header)
1300 * @len: length of frame data in octets
1301 * @stype: management frame subtype from frame control field
1303 * Process all incoming IEEE 802.11 management frames. This will be called for
1304 * each frame received from the kernel driver through wlan#ap interface. In
1305 * addition, it can be called to re-inserted pending frames (e.g., when using
1306 * external RADIUS server as an MAC ACL).
1308 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1309 struct hostapd_frame_info *fi)
1311 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1314 if (stype == WLAN_FC_STYPE_BEACON) {
1315 handle_beacon(hapd, mgmt, len, fi);
1319 if (fi && fi->passive_scan)
1322 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1323 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1324 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1327 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1328 printf("MGMT: BSSID=" MACSTR " not our address\n",
1329 MAC2STR(mgmt->bssid));
1334 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1335 handle_probe_req(hapd, mgmt, len);
1339 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1340 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1341 HOSTAPD_LEVEL_DEBUG,
1342 "MGMT: DA=" MACSTR " not our address",
1348 case WLAN_FC_STYPE_AUTH:
1349 wpa_printf(MSG_DEBUG, "mgmt::auth");
1350 handle_auth(hapd, mgmt, len);
1352 case WLAN_FC_STYPE_ASSOC_REQ:
1353 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1354 handle_assoc(hapd, mgmt, len, 0);
1356 case WLAN_FC_STYPE_REASSOC_REQ:
1357 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1358 handle_assoc(hapd, mgmt, len, 1);
1360 case WLAN_FC_STYPE_DISASSOC:
1361 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1362 handle_disassoc(hapd, mgmt, len);
1364 case WLAN_FC_STYPE_DEAUTH:
1365 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1366 handle_deauth(hapd, mgmt, len);
1368 case WLAN_FC_STYPE_ACTION:
1369 wpa_printf(MSG_DEBUG, "mgmt::action");
1370 handle_action(hapd, mgmt, len);
1373 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1374 HOSTAPD_LEVEL_DEBUG,
1375 "unknown mgmt frame subtype %d", stype);
1381 static void handle_auth_cb(struct hostapd_data *hapd,
1382 struct ieee80211_mgmt *mgmt,
1385 u16 auth_alg, auth_transaction, status_code;
1386 struct sta_info *sta;
1389 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1390 HOSTAPD_LEVEL_NOTICE,
1391 "did not acknowledge authentication response");
1395 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1396 printf("handle_auth_cb - too short payload (len=%lu)\n",
1397 (unsigned long) len);
1401 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1402 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1403 status_code = le_to_host16(mgmt->u.auth.status_code);
1405 sta = ap_get_sta(hapd, mgmt->da);
1407 printf("handle_auth_cb: STA " MACSTR " not found\n",
1412 if (status_code == WLAN_STATUS_SUCCESS &&
1413 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1414 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1415 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1416 HOSTAPD_LEVEL_INFO, "authenticated");
1417 sta->flags |= WLAN_STA_AUTH;
1422 static void handle_assoc_cb(struct hostapd_data *hapd,
1423 struct ieee80211_mgmt *mgmt,
1424 size_t len, int reassoc, int ok)
1427 struct sta_info *sta;
1429 struct ht_cap_ie *ht_cap = NULL;
1432 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1433 HOSTAPD_LEVEL_DEBUG,
1434 "did not acknowledge association response");
1438 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1439 sizeof(mgmt->u.assoc_resp))) {
1440 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1441 "(len=%lu)\n", reassoc, (unsigned long) len);
1446 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1448 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1450 sta = ap_get_sta(hapd, mgmt->da);
1452 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1457 if (status != WLAN_STATUS_SUCCESS)
1460 /* Stop previous accounting session, if one is started, and allocate
1461 * new session id for the new session. */
1462 accounting_sta_stop(hapd, sta);
1463 accounting_sta_get_id(hapd, sta);
1465 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1467 "associated (aid %d, accounting session %08X-%08X)",
1468 sta->aid, sta->acct_session_id_hi,
1469 sta->acct_session_id_lo);
1471 if (sta->flags & WLAN_STA_ASSOC)
1473 sta->flags |= WLAN_STA_ASSOC;
1476 mlme_reassociate_indication(hapd, sta);
1478 mlme_associate_indication(hapd, sta);
1480 #ifdef CONFIG_IEEE80211N
1481 if (sta->flags & WLAN_STA_HT)
1482 ht_cap = &sta->ht_capabilities;
1483 #endif /* CONFIG_IEEE80211N */
1485 #ifdef CONFIG_IEEE80211W
1486 sta->ping_timed_out = 0;
1487 #endif /* CONFIG_IEEE80211W */
1489 if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1490 sta->capability, sta->supported_rates,
1491 sta->supported_rates_len, 0, sta->listen_interval,
1494 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1495 HOSTAPD_LEVEL_NOTICE,
1496 "Could not add STA to kernel driver");
1499 if (sta->eapol_sm == NULL) {
1501 * This STA does not use RADIUS server for EAP authentication,
1502 * so bind it to the selected VLAN interface now, since the
1503 * interface selection is not going to change anymore.
1505 ap_sta_bind_vlan(hapd, sta, 0);
1506 } else if (sta->vlan_id) {
1507 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1508 ap_sta_bind_vlan(hapd, sta, 0);
1510 if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1511 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1512 WLAN_STA_SHORT_PREAMBLE, ~0);
1514 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1515 0, ~WLAN_STA_SHORT_PREAMBLE);
1518 if (sta->auth_alg == WLAN_AUTH_FT)
1519 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1521 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1522 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1524 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1527 /* Copy of the association request is not needed anymore */
1528 if (sta->last_assoc_req) {
1529 os_free(sta->last_assoc_req);
1530 sta->last_assoc_req = NULL;
1535 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1538 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1541 case WLAN_FC_STYPE_AUTH:
1542 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1543 handle_auth_cb(hapd, mgmt, len, ok);
1545 case WLAN_FC_STYPE_ASSOC_RESP:
1546 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1547 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1549 case WLAN_FC_STYPE_REASSOC_RESP:
1550 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1551 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1553 case WLAN_FC_STYPE_PROBE_RESP:
1554 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1556 case WLAN_FC_STYPE_DEAUTH:
1559 case WLAN_FC_STYPE_ACTION:
1560 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1563 printf("unknown mgmt cb frame subtype %d\n", stype);
1569 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1572 struct hostapd_data *hapd = eloop_ctx;
1573 hapd->tkip_countermeasures = 0;
1574 hostapd_set_countermeasures(hapd, 0);
1575 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1576 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
1580 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
1582 struct sta_info *sta;
1584 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1585 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
1587 wpa_auth_countermeasures_start(hapd->wpa_auth);
1588 hapd->tkip_countermeasures = 1;
1589 hostapd_set_countermeasures(hapd, 1);
1590 wpa_gtk_rekey(hapd->wpa_auth);
1591 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
1592 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
1594 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
1595 hostapd_sta_deauth(hapd, sta->addr,
1596 WLAN_REASON_MICHAEL_MIC_FAILURE);
1597 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1598 WLAN_STA_AUTHORIZED);
1599 hostapd_sta_remove(hapd, sta->addr);
1604 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
1609 if (addr && local) {
1610 struct sta_info *sta = ap_get_sta(hapd, addr);
1612 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
1613 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1615 "Michael MIC failure detected in "
1617 mlme_michaelmicfailure_indication(hapd, addr);
1619 wpa_printf(MSG_DEBUG,
1620 "MLME-MICHAELMICFAILURE.indication "
1621 "for not associated STA (" MACSTR
1622 ") ignored", MAC2STR(addr));
1628 if (now > hapd->michael_mic_failure + 60) {
1629 hapd->michael_mic_failures = 1;
1631 hapd->michael_mic_failures++;
1632 if (hapd->michael_mic_failures > 1)
1633 ieee80211_tkip_countermeasures_start(hapd);
1635 hapd->michael_mic_failure = now;
1639 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1646 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1647 char *buf, size_t buflen)
1653 #endif /* CONFIG_NATIVE_WINDOWS */