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"
38 #include "ieee802_11h.h"
42 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
47 if (hapd->iface->current_rates == NULL)
50 *pos++ = WLAN_EID_SUPP_RATES;
51 num = hapd->iface->num_rates;
53 /* rest of the rates are encoded in Extended supported
60 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
63 *pos = hapd->iface->current_rates[i].rate / 5;
64 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
73 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
78 if (hapd->iface->current_rates == NULL)
81 num = hapd->iface->num_rates;
86 *pos++ = WLAN_EID_EXT_SUPP_RATES;
89 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
93 continue; /* already in SuppRates IE */
94 *pos = hapd->iface->current_rates[i].rate / 5;
95 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
104 u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid)
106 #ifdef CONFIG_IEEE80211N
107 struct ieee80211_ht_capability *cap;
110 if (!hapd->iconf->ieee80211n)
113 *pos++ = WLAN_EID_HT_CAP;
114 *pos++ = sizeof(*cap);
116 cap = (struct ieee80211_ht_capability *) pos;
117 os_memset(cap, 0, sizeof(*cap));
118 SET_2BIT_U8(&cap->mac_ht_params_info,
119 MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
120 MAX_RX_AMPDU_FACTOR_64KB);
122 cap->capabilities_info = host_to_le16(hapd->iconf->ht_capab);
124 cap->supported_mcs_set[0] = 0xff;
125 cap->supported_mcs_set[1] = 0xff;
130 #else /* CONFIG_IEEE80211N */
132 #endif /* CONFIG_IEEE80211N */
136 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
138 #ifdef CONFIG_IEEE80211N
139 struct ieee80211_ht_operation *oper;
142 if (!hapd->iconf->ieee80211n)
145 *pos++ = WLAN_EID_HT_OPERATION;
146 *pos++ = sizeof(*oper);
148 oper = (struct ieee80211_ht_operation *) pos;
149 os_memset(oper, 0, sizeof(*oper));
151 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
153 pos += sizeof(*oper);
156 #else /* CONFIG_IEEE80211N */
158 #endif /* CONFIG_IEEE80211N */
162 #ifdef CONFIG_IEEE80211N
166 Set to 0 (HT pure) under the followign conditions
167 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
168 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
169 Set to 1 (HT non-member protection) if there may be non-HT STAs
170 in both the primary and the secondary channel
171 Set to 2 if only HT STAs are associated in BSS,
172 however and at least one 20 MHz HT STA is associated
173 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
174 (currently non-GF HT station is considered as non-HT STA also)
176 int hostapd_ht_operation_update(struct hostapd_iface *iface)
178 u16 cur_op_mode, new_op_mode;
179 int op_mode_changes = 0;
181 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
184 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
185 __func__, iface->ht_op_mode);
187 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
188 && iface->num_sta_ht_no_gf) {
190 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
192 } else if ((iface->ht_op_mode &
193 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
194 iface->num_sta_ht_no_gf == 0) {
196 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
200 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
201 (iface->num_sta_no_ht || iface->olbc_ht)) {
202 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
204 } else if ((iface->ht_op_mode &
205 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
206 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
208 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
212 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
213 * station is associated. Probably it's a theoretical case, since
214 * it looks like all known HT STAs support greenfield.
217 if (iface->num_sta_no_ht ||
218 (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
219 new_op_mode = OP_MODE_MIXED;
220 else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
221 && iface->num_sta_ht_20mhz)
222 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
223 else if (iface->olbc_ht)
224 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
226 new_op_mode = OP_MODE_PURE;
228 cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
229 if (cur_op_mode != new_op_mode) {
230 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
231 iface->ht_op_mode |= new_op_mode;
235 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
236 __func__, iface->ht_op_mode, op_mode_changes);
238 return op_mode_changes;
241 #endif /* CONFIG_IEEE80211N */
244 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
247 int capab = WLAN_CAPABILITY_ESS;
250 if (hapd->iface->num_sta_no_short_preamble == 0 &&
251 hapd->iconf->preamble == SHORT_PREAMBLE)
252 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
254 privacy = hapd->conf->ssid.wep.keys_set;
256 if (hapd->conf->ieee802_1x &&
257 (hapd->conf->default_wep_key_len ||
258 hapd->conf->individual_wep_key_len))
265 int policy, def_klen;
266 if (probe && sta->ssid_probe) {
267 policy = sta->ssid_probe->security_policy;
268 def_klen = sta->ssid_probe->wep.default_len;
270 policy = sta->ssid->security_policy;
271 def_klen = sta->ssid->wep.default_len;
273 privacy = policy != SECURITY_PLAINTEXT;
274 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
279 capab |= WLAN_CAPABILITY_PRIVACY;
281 if (hapd->iface->current_mode &&
282 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
283 hapd->iface->num_sta_no_short_slot_time == 0)
284 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
286 if (hapd->iface->dfs_enable)
287 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
293 #define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
296 static int ieee802_11_parse_vendor_specific(u8 *pos, size_t elen,
297 struct ieee802_11_elems *elems,
302 /* first 3 bytes in vendor specific information element are the IEEE
303 * OUI of the vendor. The following byte is used a vendor specific
307 wpa_printf(MSG_MSGDUMP, "short vendor specific "
308 "information element ignored (len=%lu)",
309 (unsigned long) elen);
314 oui = WPA_GET_BE24(pos);
317 /* Microsoft/Wi-Fi information elements are further typed and
321 /* Microsoft OUI (00:50:F2) with OUI Type 1:
322 * real WPA information element */
324 elems->wpa_ie_len = elen;
326 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
328 wpa_printf(MSG_MSGDUMP, "short WME "
329 "information element ignored "
331 (unsigned long) elen);
335 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
336 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
338 elems->wme_len = elen;
340 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
341 elems->wme_tspec = pos;
342 elems->wme_tspec_len = elen;
345 wpa_printf(MSG_MSGDUMP, "unknown WME "
346 "information element ignored "
347 "(subtype=%d len=%lu)",
348 pos[4], (unsigned long) elen);
353 wpa_printf(MSG_MSGDUMP, "Unknown Microsoft "
354 "information element ignored "
355 "(type=%d len=%lu)\n",
356 pos[3], (unsigned long) elen);
362 wpa_printf(MSG_MSGDUMP, "unknown vendor specific information "
363 "element ignored (vendor OUI %02x:%02x:%02x "
365 pos[0], pos[1], pos[2], (unsigned long) elen);
373 #ifdef CONFIG_IEEE80211W
374 static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
375 struct sta_info *sta, u8 *eid)
380 *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
382 timeout = (hapd->conf->assoc_ping_attempts - sta->ping_count + 1) *
383 hapd->conf->assoc_ping_timeout;
384 WPA_PUT_LE32(pos, timeout);
389 #endif /* CONFIG_IEEE80211W */
392 ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
393 struct ieee802_11_elems *elems,
400 os_memset(elems, 0, sizeof(*elems));
411 wpa_printf(MSG_DEBUG, "IEEE 802.11 element "
412 "parse failed (id=%d elen=%d "
414 id, elen, (unsigned long) left);
415 wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
423 elems->ssid_len = elen;
425 case WLAN_EID_SUPP_RATES:
426 elems->supp_rates = pos;
427 elems->supp_rates_len = elen;
429 case WLAN_EID_FH_PARAMS:
430 elems->fh_params = pos;
431 elems->fh_params_len = elen;
433 case WLAN_EID_DS_PARAMS:
434 elems->ds_params = pos;
435 elems->ds_params_len = elen;
437 case WLAN_EID_CF_PARAMS:
438 elems->cf_params = pos;
439 elems->cf_params_len = elen;
443 elems->tim_len = elen;
445 case WLAN_EID_IBSS_PARAMS:
446 elems->ibss_params = pos;
447 elems->ibss_params_len = elen;
449 case WLAN_EID_CHALLENGE:
450 elems->challenge = pos;
451 elems->challenge_len = elen;
453 case WLAN_EID_ERP_INFO:
454 elems->erp_info = pos;
455 elems->erp_info_len = elen;
457 case WLAN_EID_EXT_SUPP_RATES:
458 elems->ext_supp_rates = pos;
459 elems->ext_supp_rates_len = elen;
461 case WLAN_EID_VENDOR_SPECIFIC:
462 if (ieee802_11_parse_vendor_specific(pos, elen,
469 elems->rsn_ie_len = elen;
471 case WLAN_EID_PWR_CAPABILITY:
472 elems->power_cap = pos;
473 elems->power_cap_len = elen;
475 case WLAN_EID_SUPPORTED_CHANNELS:
476 elems->supp_channels = pos;
477 elems->supp_channels_len = elen;
479 case WLAN_EID_MOBILITY_DOMAIN:
481 elems->mdie_len = elen;
483 case WLAN_EID_FAST_BSS_TRANSITION:
485 elems->ftie_len = elen;
487 case WLAN_EID_HT_CAP:
488 elems->ht_capabilities = pos;
489 elems->ht_capabilities_len = elen;
491 case WLAN_EID_HT_OPERATION:
492 elems->ht_operation = pos;
493 elems->ht_operation_len = elen;
499 wpa_printf(MSG_MSGDUMP, "IEEE 802.11 element parse "
500 "ignored unknown element (id=%d elen=%d)",
512 return unknown ? ParseUnknown : ParseOK;
516 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
519 if (len > HOSTAPD_MAX_SSID_LEN)
520 len = HOSTAPD_MAX_SSID_LEN;
521 for (i = 0; i < len; i++) {
522 if (ssid[i] >= 32 && ssid[i] < 127)
531 void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
533 struct ieee80211_mgmt mgmt;
535 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
537 "deauthenticate - reason %d", reason);
538 os_memset(&mgmt, 0, sizeof(mgmt));
539 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
540 WLAN_FC_STYPE_DEAUTH);
541 os_memcpy(mgmt.da, addr, ETH_ALEN);
542 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
543 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
544 mgmt.u.deauth.reason_code = host_to_le16(reason);
545 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
546 sizeof(mgmt.u.deauth), 0) < 0)
547 perror("ieee802_11_send_deauth: send");
551 static void ieee802_11_sta_authenticate(void *eloop_ctx, void *timeout_ctx)
553 struct hostapd_data *hapd = eloop_ctx;
554 struct ieee80211_mgmt mgmt;
557 if (hapd->assoc_ap_state == WAIT_BEACON)
558 hapd->assoc_ap_state = AUTHENTICATE;
559 if (hapd->assoc_ap_state != AUTHENTICATE)
562 ieee802_11_print_ssid(ssid_txt, (u8 *) hapd->assoc_ap_ssid,
563 hapd->assoc_ap_ssid_len);
564 printf("Authenticate with AP " MACSTR " SSID=%s (as station)\n",
565 MAC2STR(hapd->conf->assoc_ap_addr), ssid_txt);
567 os_memset(&mgmt, 0, sizeof(mgmt));
568 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
570 os_memcpy(mgmt.da, hapd->conf->assoc_ap_addr, ETH_ALEN);
571 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
572 os_memcpy(mgmt.bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
573 mgmt.u.auth.auth_alg = host_to_le16(WLAN_AUTH_OPEN);
574 mgmt.u.auth.auth_transaction = host_to_le16(1);
575 mgmt.u.auth.status_code = host_to_le16(0);
576 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
577 sizeof(mgmt.u.auth), 0) < 0)
578 perror("ieee802_11_sta_authenticate: send");
580 /* Try to authenticate again, if this attempt fails or times out. */
581 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate, hapd, NULL);
585 static void ieee802_11_sta_associate(void *eloop_ctx, void *timeout_ctx)
587 struct hostapd_data *hapd = eloop_ctx;
589 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
593 if (hapd->assoc_ap_state == AUTHENTICATE)
594 hapd->assoc_ap_state = ASSOCIATE;
595 if (hapd->assoc_ap_state != ASSOCIATE)
598 ieee802_11_print_ssid(ssid_txt, (u8 *) hapd->assoc_ap_ssid,
599 hapd->assoc_ap_ssid_len);
600 printf("Associate with AP " MACSTR " SSID=%s (as station)\n",
601 MAC2STR(hapd->conf->assoc_ap_addr), ssid_txt);
603 os_memset(mgmt, 0, sizeof(*mgmt));
604 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
605 WLAN_FC_STYPE_ASSOC_REQ);
606 os_memcpy(mgmt->da, hapd->conf->assoc_ap_addr, ETH_ALEN);
607 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
608 os_memcpy(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
609 mgmt->u.assoc_req.capab_info = host_to_le16(0);
610 mgmt->u.assoc_req.listen_interval = host_to_le16(1);
611 p = &mgmt->u.assoc_req.variable[0];
613 *p++ = WLAN_EID_SSID;
614 *p++ = hapd->assoc_ap_ssid_len;
615 os_memcpy(p, hapd->assoc_ap_ssid, hapd->assoc_ap_ssid_len);
616 p += hapd->assoc_ap_ssid_len;
618 p = hostapd_eid_supp_rates(hapd, p);
619 p = hostapd_eid_ext_supp_rates(hapd, p);
621 if (hostapd_send_mgmt_frame(hapd, mgmt, p - (u8 *) mgmt, 0) < 0)
622 perror("ieee802_11_sta_associate: send");
624 /* Try to authenticate again, if this attempt fails or times out. */
625 eloop_register_timeout(5, 0, ieee802_11_sta_associate, hapd, NULL);
629 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
630 u16 auth_transaction, u8 *challenge, int iswep)
632 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
634 "authentication (shared key, transaction %d)",
637 if (auth_transaction == 1) {
638 if (!sta->challenge) {
639 /* Generate a pseudo-random challenge */
643 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
644 if (sta->challenge == NULL)
645 return WLAN_STATUS_UNSPECIFIED_FAILURE;
649 os_memcpy(key, &now, 4);
650 os_memcpy(key + 4, &r, 4);
651 rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
657 if (auth_transaction != 3)
658 return WLAN_STATUS_UNSPECIFIED_FAILURE;
661 if (!iswep || !sta->challenge || !challenge ||
662 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
663 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
665 "shared key authentication - invalid "
666 "challenge-response");
667 return WLAN_STATUS_CHALLENGE_FAIL;
670 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
672 "authentication OK (shared key)");
673 #ifdef IEEE80211_REQUIRE_AUTH_ACK
674 /* Station will be marked authenticated if it ACKs the
675 * authentication reply. */
677 sta->flags |= WLAN_STA_AUTH;
678 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
680 os_free(sta->challenge);
681 sta->challenge = NULL;
687 static void send_auth_reply(struct hostapd_data *hapd,
688 const u8 *dst, const u8 *bssid,
689 u16 auth_alg, u16 auth_transaction, u16 resp,
690 const u8 *ies, size_t ies_len)
692 struct ieee80211_mgmt *reply;
696 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
697 buf = os_zalloc(rlen);
701 reply = (struct ieee80211_mgmt *) buf;
702 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
704 os_memcpy(reply->da, dst, ETH_ALEN);
705 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
706 os_memcpy(reply->bssid, bssid, ETH_ALEN);
708 reply->u.auth.auth_alg = host_to_le16(auth_alg);
709 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
710 reply->u.auth.status_code = host_to_le16(resp);
713 os_memcpy(reply->u.auth.variable, ies, ies_len);
715 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
716 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
717 MAC2STR(dst), auth_alg, auth_transaction,
718 resp, (unsigned long) ies_len);
719 if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
720 perror("send_auth_reply: send");
726 #ifdef CONFIG_IEEE80211R
727 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
728 u16 auth_transaction, u16 status,
729 const u8 *ies, size_t ies_len)
731 struct hostapd_data *hapd = ctx;
732 struct sta_info *sta;
734 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
735 status, ies, ies_len);
737 if (status != WLAN_STATUS_SUCCESS)
740 sta = ap_get_sta(hapd, dst);
744 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
745 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
746 sta->flags |= WLAN_STA_AUTH;
747 mlme_authenticate_indication(hapd, sta);
749 #endif /* CONFIG_IEEE80211R */
752 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
755 u16 auth_alg, auth_transaction, status_code;
756 u16 resp = WLAN_STATUS_SUCCESS;
757 struct sta_info *sta = NULL;
760 u8 *challenge = NULL;
761 u32 session_timeout, acct_interim_interval;
763 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
764 size_t resp_ies_len = 0;
766 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
767 printf("handle_auth - too short payload (len=%lu)\n",
768 (unsigned long) len);
772 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
773 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
774 status_code = le_to_host16(mgmt->u.auth.status_code);
775 fc = le_to_host16(mgmt->frame_control);
777 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
778 2 + WLAN_AUTH_CHALLENGE_LEN &&
779 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
780 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
781 challenge = &mgmt->u.auth.variable[2];
783 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
784 "auth_transaction=%d status_code=%d wep=%d%s",
785 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
786 status_code, !!(fc & WLAN_FC_ISWEP),
787 challenge ? " challenge" : "");
789 if (hapd->assoc_ap_state == AUTHENTICATE && auth_transaction == 2 &&
790 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0 &&
791 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
792 if (status_code != 0) {
793 printf("Authentication (as station) with AP "
794 MACSTR " failed (status_code=%d)\n",
795 MAC2STR(hapd->conf->assoc_ap_addr),
799 printf("Authenticated (as station) with AP " MACSTR "\n",
800 MAC2STR(hapd->conf->assoc_ap_addr));
801 ieee802_11_sta_associate(hapd, NULL);
805 if (hapd->tkip_countermeasures) {
806 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
810 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
811 auth_alg == WLAN_AUTH_OPEN) ||
812 #ifdef CONFIG_IEEE80211R
814 (hapd->conf->wpa_key_mgmt &
815 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
816 auth_alg == WLAN_AUTH_FT) ||
817 #endif /* CONFIG_IEEE80211R */
818 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
819 auth_alg == WLAN_AUTH_SHARED_KEY))) {
820 printf("Unsupported authentication algorithm (%d)\n",
822 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
826 if (!(auth_transaction == 1 ||
827 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
828 printf("Unknown authentication transaction number (%d)\n",
830 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
834 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
835 printf("Station " MACSTR " not allowed to authenticate.\n",
837 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
841 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
843 &acct_interim_interval, &vlan_id);
844 if (res == HOSTAPD_ACL_REJECT) {
845 printf("Station " MACSTR " not allowed to authenticate.\n",
847 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
850 if (res == HOSTAPD_ACL_PENDING) {
851 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
852 " waiting for an external authentication",
854 /* Authentication code will re-send the authentication frame
855 * after it has received (and cached) information from the
856 * external source. */
860 sta = ap_sta_add(hapd, mgmt->sa);
862 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
867 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
868 sta->vlan_id) == NULL) {
869 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
870 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
871 "%d received from RADIUS server",
873 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
876 sta->vlan_id = vlan_id;
877 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
878 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
881 sta->flags &= ~WLAN_STA_PREAUTH;
882 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
884 if (hapd->conf->radius->acct_interim_interval == 0 &&
885 acct_interim_interval)
886 sta->acct_interim_interval = acct_interim_interval;
887 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
888 ap_sta_session_timeout(hapd, sta, session_timeout);
890 ap_sta_no_session_timeout(hapd, sta);
894 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
896 "authentication OK (open system)");
897 #ifdef IEEE80211_REQUIRE_AUTH_ACK
898 /* Station will be marked authenticated if it ACKs the
899 * authentication reply. */
901 sta->flags |= WLAN_STA_AUTH;
902 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
903 sta->auth_alg = WLAN_AUTH_OPEN;
904 mlme_authenticate_indication(hapd, sta);
907 case WLAN_AUTH_SHARED_KEY:
908 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
910 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
911 mlme_authenticate_indication(hapd, sta);
912 if (sta->challenge && auth_transaction == 1) {
913 resp_ies[0] = WLAN_EID_CHALLENGE;
914 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
915 os_memcpy(resp_ies + 2, sta->challenge,
916 WLAN_AUTH_CHALLENGE_LEN);
917 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
920 #ifdef CONFIG_IEEE80211R
922 sta->auth_alg = WLAN_AUTH_FT;
923 if (sta->wpa_sm == NULL)
924 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
926 if (sta->wpa_sm == NULL) {
927 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
929 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
932 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
933 auth_transaction, mgmt->u.auth.variable,
934 len - IEEE80211_HDRLEN -
935 sizeof(mgmt->u.auth),
936 handle_auth_ft_finish, hapd);
937 /* handle_auth_ft_finish() callback will complete auth. */
939 #endif /* CONFIG_IEEE80211R */
943 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
944 auth_transaction + 1, resp, resp_ies, resp_ies_len);
948 static void handle_assoc(struct hostapd_data *hapd,
949 struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
951 u16 capab_info, listen_interval;
952 u16 resp = WLAN_STATUS_SUCCESS;
955 int send_deauth = 0, send_len, left, i;
956 struct sta_info *sta;
957 struct ieee802_11_elems elems;
958 u8 buf[sizeof(struct ieee80211_mgmt) + 512];
959 struct ieee80211_mgmt *reply;
961 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
962 sizeof(mgmt->u.assoc_req))) {
963 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
964 "\n", reassoc, (unsigned long) len);
969 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
970 listen_interval = le_to_host16(
971 mgmt->u.reassoc_req.listen_interval);
972 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
973 " capab_info=0x%02x listen_interval=%d current_ap="
975 MAC2STR(mgmt->sa), capab_info, listen_interval,
976 MAC2STR(mgmt->u.reassoc_req.current_ap));
977 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
978 pos = mgmt->u.reassoc_req.variable;
980 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
981 listen_interval = le_to_host16(
982 mgmt->u.assoc_req.listen_interval);
983 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
984 " capab_info=0x%02x listen_interval=%d",
985 MAC2STR(mgmt->sa), capab_info, listen_interval);
986 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
987 pos = mgmt->u.assoc_req.variable;
990 sta = ap_get_sta(hapd, mgmt->sa);
991 #ifdef CONFIG_IEEE80211R
992 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
993 (sta->flags & WLAN_STA_AUTH) == 0) {
994 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
995 "prior to authentication since it is using "
996 "over-the-DS FT", MAC2STR(mgmt->sa));
998 #endif /* CONFIG_IEEE80211R */
999 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1000 printf("STA " MACSTR " trying to associate before "
1001 "authentication\n", MAC2STR(mgmt->sa));
1003 printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
1004 MAC2STR(sta->addr), sta->aid, sta->flags);
1007 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1011 if (hapd->tkip_countermeasures) {
1012 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1016 if (listen_interval > hapd->conf->max_listen_interval) {
1017 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1018 HOSTAPD_LEVEL_DEBUG,
1019 "Too large Listen Interval (%d)",
1021 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1025 sta->capability = capab_info;
1027 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1029 if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
1031 printf("STA " MACSTR " sent invalid association request\n",
1032 MAC2STR(sta->addr));
1033 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1037 if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
1038 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
1041 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
1042 printf("Station " MACSTR " tried to associate with "
1043 "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
1044 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1048 sta->flags &= ~WLAN_STA_WME;
1049 if (elems.wme && hapd->conf->wme_enabled) {
1050 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
1051 hostapd_logger(hapd, sta->addr,
1053 HOSTAPD_LEVEL_DEBUG,
1054 "invalid WME element in association "
1057 sta->flags |= WLAN_STA_WME;
1060 if (!elems.supp_rates) {
1061 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1062 HOSTAPD_LEVEL_DEBUG,
1063 "No supported rates element in AssocReq");
1064 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1068 if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
1069 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1070 HOSTAPD_LEVEL_DEBUG,
1071 "Invalid supported rates element length %d",
1072 elems.supp_rates_len);
1073 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1077 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
1078 os_memcpy(sta->supported_rates, elems.supp_rates,
1079 elems.supp_rates_len);
1080 sta->supported_rates_len = elems.supp_rates_len;
1082 if (elems.ext_supp_rates) {
1083 if (elems.supp_rates_len + elems.ext_supp_rates_len >
1084 sizeof(sta->supported_rates)) {
1085 hostapd_logger(hapd, mgmt->sa,
1086 HOSTAPD_MODULE_IEEE80211,
1087 HOSTAPD_LEVEL_DEBUG,
1088 "Invalid supported rates element length"
1089 " %d+%d", elems.supp_rates_len,
1090 elems.ext_supp_rates_len);
1091 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1095 os_memcpy(sta->supported_rates + elems.supp_rates_len,
1096 elems.ext_supp_rates, elems.ext_supp_rates_len);
1097 sta->supported_rates_len += elems.ext_supp_rates_len;
1100 #ifdef CONFIG_IEEE80211N
1101 /* save HT capabilities in the sta object */
1102 os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
1103 if (elems.ht_capabilities &&
1104 elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
1105 && (sta->flags & WLAN_STA_WME)) {
1106 /* note: without WMM capability, treat the sta as non-HT */
1107 sta->flags |= WLAN_STA_HT;
1108 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
1109 sta->ht_capabilities.length =
1110 sizeof(struct ieee80211_ht_capability);
1111 os_memcpy(&sta->ht_capabilities.data,
1112 elems.ht_capabilities,
1113 sizeof(struct ieee80211_ht_capability));
1115 sta->flags &= ~WLAN_STA_HT;
1116 #endif /* CONFIG_IEEE80211N */
1118 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1119 wpa_ie = elems.rsn_ie;
1120 wpa_ie_len = elems.rsn_ie_len;
1121 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1123 wpa_ie = elems.wpa_ie;
1124 wpa_ie_len = elems.wpa_ie_len;
1129 if (hapd->conf->wpa && wpa_ie == NULL) {
1130 printf("STA " MACSTR ": No WPA/RSN IE in association "
1131 "request\n", MAC2STR(sta->addr));
1132 resp = WLAN_STATUS_INVALID_IE;
1136 if (hapd->conf->wpa && wpa_ie) {
1140 if (sta->wpa_sm == NULL)
1141 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1143 if (sta->wpa_sm == NULL) {
1144 printf("Failed to initialize WPA state machine\n");
1145 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1148 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1150 elems.mdie, elems.mdie_len);
1151 if (res == WPA_INVALID_GROUP)
1152 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1153 else if (res == WPA_INVALID_PAIRWISE)
1154 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1155 else if (res == WPA_INVALID_AKMP)
1156 resp = WLAN_STATUS_AKMP_NOT_VALID;
1157 else if (res == WPA_ALLOC_FAIL)
1158 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1159 #ifdef CONFIG_IEEE80211W
1160 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1161 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1162 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1163 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1164 #endif /* CONFIG_IEEE80211W */
1165 else if (res == WPA_INVALID_MDIE)
1166 resp = WLAN_STATUS_INVALID_MDIE;
1167 else if (res != WPA_IE_OK)
1168 resp = WLAN_STATUS_INVALID_IE;
1169 if (resp != WLAN_STATUS_SUCCESS)
1171 #ifdef CONFIG_IEEE80211W
1172 if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
1174 * STA has already been associated with MFP and ping
1175 * timeout has not been reached. Reject the
1176 * association attempt temporarily and start ping, if
1177 * one is not pending.
1180 if (sta->ping_count == 0)
1181 ap_sta_start_ping(hapd, sta);
1183 resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1187 if (wpa_auth_uses_mfp(sta->wpa_sm))
1188 sta->flags |= WLAN_STA_MFP;
1190 sta->flags &= ~WLAN_STA_MFP;
1191 #endif /* CONFIG_IEEE80211W */
1193 #ifdef CONFIG_IEEE80211R
1194 if (sta->auth_alg == WLAN_AUTH_FT) {
1196 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1197 "to use association (not "
1198 "re-association) with FT auth_alg",
1199 MAC2STR(sta->addr));
1200 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1204 resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
1205 if (resp != WLAN_STATUS_SUCCESS)
1208 #endif /* CONFIG_IEEE80211R */
1211 if (hapd->iface->dfs_enable &&
1212 hapd->iconf->ieee80211h == SPECT_STRICT_BINDING) {
1213 if (hostapd_check_power_cap(hapd, elems.power_cap,
1214 elems.power_cap_len)) {
1215 resp = WLAN_STATUS_PWR_CAPABILITY_NOT_VALID;
1216 hostapd_logger(hapd, sta->addr,
1217 HOSTAPD_MODULE_IEEE80211,
1218 HOSTAPD_LEVEL_DEBUG,
1219 "Power capabilities of the station not "
1225 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1226 sta->flags |= WLAN_STA_NONERP;
1227 for (i = 0; i < sta->supported_rates_len; i++) {
1228 if ((sta->supported_rates[i] & 0x7f) > 22) {
1229 sta->flags &= ~WLAN_STA_NONERP;
1233 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1234 sta->nonerp_set = 1;
1235 hapd->iface->num_sta_non_erp++;
1236 if (hapd->iface->num_sta_non_erp == 1)
1237 ieee802_11_set_beacons(hapd->iface);
1240 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1241 !sta->no_short_slot_time_set) {
1242 sta->no_short_slot_time_set = 1;
1243 hapd->iface->num_sta_no_short_slot_time++;
1244 if (hapd->iface->current_mode->mode ==
1245 HOSTAPD_MODE_IEEE80211G &&
1246 hapd->iface->num_sta_no_short_slot_time == 1)
1247 ieee802_11_set_beacons(hapd->iface);
1250 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1251 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1253 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1255 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1256 !sta->no_short_preamble_set) {
1257 sta->no_short_preamble_set = 1;
1258 hapd->iface->num_sta_no_short_preamble++;
1259 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1260 && hapd->iface->num_sta_no_short_preamble == 1)
1261 ieee802_11_set_beacons(hapd->iface);
1264 #ifdef CONFIG_IEEE80211N
1265 if (sta->flags & WLAN_STA_HT) {
1266 if ((sta->ht_capabilities.data.capabilities_info &
1267 HT_CAP_INFO_GREEN_FIELD) == 0) {
1268 hapd->iface->num_sta_ht_no_gf++;
1269 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
1270 "greenfield, num of non-gf stations %d",
1271 __func__, MAC2STR(sta->addr),
1272 hapd->iface->num_sta_ht_no_gf);
1274 if ((sta->ht_capabilities.data.capabilities_info &
1275 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
1276 hapd->iface->num_sta_ht_20mhz++;
1277 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
1278 "num of 20MHz HT STAs %d",
1279 __func__, MAC2STR(sta->addr),
1280 hapd->iface->num_sta_ht_20mhz);
1283 hapd->iface->num_sta_no_ht++;
1284 if (hapd->iconf->ieee80211n) {
1285 wpa_printf(MSG_DEBUG, "%s STA " MACSTR
1286 " - no HT, num of non-HT stations %d",
1287 __func__, MAC2STR(sta->addr),
1288 hapd->iface->num_sta_no_ht);
1292 if (hostapd_ht_operation_update(hapd->iface) > 0)
1293 ieee802_11_set_beacons(hapd->iface);
1294 #endif /* CONFIG_IEEE80211N */
1296 /* get a unique AID */
1298 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1300 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1301 if (hapd->sta_aid[sta->aid - 1] == NULL)
1303 if (sta->aid > MAX_AID_TABLE_SIZE) {
1305 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1306 wpa_printf(MSG_ERROR, " no room for more AIDs");
1309 hapd->sta_aid[sta->aid - 1] = sta;
1310 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1314 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1315 HOSTAPD_LEVEL_DEBUG,
1316 "association OK (aid %d)", sta->aid);
1317 /* Station will be marked associated, after it acknowledges AssocResp
1321 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1325 if (sta->last_assoc_req)
1326 os_free(sta->last_assoc_req);
1327 sta->last_assoc_req = os_malloc(len);
1328 if (sta->last_assoc_req)
1329 os_memcpy(sta->last_assoc_req, mgmt, len);
1331 /* Make sure that the previously registered inactivity timer will not
1332 * remove the STA immediately. */
1333 sta->timeout_next = STA_NULLFUNC;
1336 os_memset(buf, 0, sizeof(buf));
1337 reply = (struct ieee80211_mgmt *) buf;
1338 reply->frame_control =
1339 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1340 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1341 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1342 WLAN_FC_STYPE_ASSOC_RESP)));
1343 os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1344 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1345 os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1347 send_len = IEEE80211_HDRLEN;
1349 send_len += sizeof(reply->u.deauth);
1350 reply->u.deauth.reason_code = host_to_le16(resp);
1353 send_len += sizeof(reply->u.assoc_resp);
1354 reply->u.assoc_resp.capab_info =
1355 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1356 reply->u.assoc_resp.status_code = host_to_le16(resp);
1357 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1358 | BIT(14) | BIT(15));
1359 /* Supported rates */
1360 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1361 /* Extended supported rates */
1362 p = hostapd_eid_ext_supp_rates(hapd, p);
1363 if (sta->flags & WLAN_STA_WME)
1364 p = hostapd_eid_wme(hapd, p);
1366 p = hostapd_eid_ht_capabilities_info(hapd, p);
1367 p = hostapd_eid_ht_operation(hapd, p);
1369 #ifdef CONFIG_IEEE80211R
1370 if (resp == WLAN_STATUS_SUCCESS) {
1371 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1372 * Transition Information, RSN */
1373 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1374 buf + sizeof(buf) - p,
1377 #endif /* CONFIG_IEEE80211R */
1379 #ifdef CONFIG_IEEE80211W
1380 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1381 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1382 #endif /* CONFIG_IEEE80211W */
1384 send_len += p - reply->u.assoc_resp.variable;
1387 if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1388 perror("handle_assoc: send");
1392 static void handle_assoc_resp(struct hostapd_data *hapd,
1393 struct ieee80211_mgmt *mgmt, size_t len)
1395 u16 status_code, aid;
1397 if (hapd->assoc_ap_state != ASSOCIATE) {
1398 printf("Unexpected association response received from " MACSTR
1399 "\n", MAC2STR(mgmt->sa));
1403 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_resp)) {
1404 printf("handle_assoc_resp - too short payload (len=%lu)\n",
1405 (unsigned long) len);
1409 if (os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0 ||
1410 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0) {
1411 printf("Received association response from unexpected address "
1412 "(SA=" MACSTR " BSSID=" MACSTR "\n",
1413 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
1417 status_code = le_to_host16(mgmt->u.assoc_resp.status_code);
1418 aid = le_to_host16(mgmt->u.assoc_resp.aid);
1419 aid &= ~(BIT(14) | BIT(15));
1421 if (status_code != 0) {
1422 printf("Association (as station) with AP " MACSTR " failed "
1423 "(status_code=%d)\n",
1424 MAC2STR(hapd->conf->assoc_ap_addr), status_code);
1425 /* Try to authenticate again */
1426 hapd->assoc_ap_state = AUTHENTICATE;
1427 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate,
1431 printf("Associated (as station) with AP " MACSTR " (aid=%d)\n",
1432 MAC2STR(hapd->conf->assoc_ap_addr), aid);
1433 hapd->assoc_ap_aid = aid;
1434 hapd->assoc_ap_state = ASSOCIATED;
1436 if (hostapd_set_assoc_ap(hapd, hapd->conf->assoc_ap_addr)) {
1437 printf("Could not set associated AP address to kernel "
1443 static void handle_disassoc(struct hostapd_data *hapd,
1444 struct ieee80211_mgmt *mgmt, size_t len)
1446 struct sta_info *sta;
1448 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1449 printf("handle_disassoc - too short payload (len=%lu)\n",
1450 (unsigned long) len);
1454 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1456 le_to_host16(mgmt->u.disassoc.reason_code));
1458 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1459 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1460 printf("Assoc AP " MACSTR " sent disassociation "
1461 "(reason_code=%d) - try to authenticate\n",
1462 MAC2STR(hapd->conf->assoc_ap_addr),
1463 le_to_host16(mgmt->u.disassoc.reason_code));
1464 hapd->assoc_ap_state = AUTHENTICATE;
1465 ieee802_11_sta_authenticate(hapd, NULL);
1466 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1471 sta = ap_get_sta(hapd, mgmt->sa);
1473 printf("Station " MACSTR " trying to disassociate, but it "
1474 "is not associated.\n", MAC2STR(mgmt->sa));
1478 sta->flags &= ~WLAN_STA_ASSOC;
1479 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1480 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1481 HOSTAPD_LEVEL_INFO, "disassociated");
1482 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1483 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1484 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1486 accounting_sta_stop(hapd, sta);
1487 ieee802_1x_free_station(sta);
1488 hostapd_sta_remove(hapd, sta->addr);
1490 if (sta->timeout_next == STA_NULLFUNC ||
1491 sta->timeout_next == STA_DISASSOC) {
1492 sta->timeout_next = STA_DEAUTH;
1493 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1494 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1498 mlme_disassociate_indication(
1499 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1503 static void handle_deauth(struct hostapd_data *hapd,
1504 struct ieee80211_mgmt *mgmt, size_t len)
1506 struct sta_info *sta;
1508 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1509 printf("handle_deauth - too short payload (len=%lu)\n",
1510 (unsigned long) len);
1514 wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1517 le_to_host16(mgmt->u.deauth.reason_code));
1519 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1520 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1521 printf("Assoc AP " MACSTR " sent deauthentication "
1522 "(reason_code=%d) - try to authenticate\n",
1523 MAC2STR(hapd->conf->assoc_ap_addr),
1524 le_to_host16(mgmt->u.deauth.reason_code));
1525 hapd->assoc_ap_state = AUTHENTICATE;
1526 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1531 sta = ap_get_sta(hapd, mgmt->sa);
1533 printf("Station " MACSTR " trying to deauthenticate, but it "
1534 "is not authenticated.\n", MAC2STR(mgmt->sa));
1538 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1539 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1540 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1541 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1542 mlme_deauthenticate_indication(
1543 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1544 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1545 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1546 ap_free_sta(hapd, sta);
1550 static void handle_beacon(struct hostapd_data *hapd,
1551 struct ieee80211_mgmt *mgmt, size_t len,
1552 struct hostapd_frame_info *fi)
1554 struct ieee802_11_elems elems;
1556 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1557 printf("handle_beacon - too short payload (len=%lu)\n",
1558 (unsigned long) len);
1562 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1563 len - (IEEE80211_HDRLEN +
1564 sizeof(mgmt->u.beacon)), &elems,
1567 if (hapd->assoc_ap_state == WAIT_BEACON &&
1568 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1569 if (elems.ssid && elems.ssid_len <= 32) {
1570 os_memcpy(hapd->assoc_ap_ssid, elems.ssid,
1572 hapd->assoc_ap_ssid[elems.ssid_len] = '\0';
1573 hapd->assoc_ap_ssid_len = elems.ssid_len;
1575 ieee802_11_sta_authenticate(hapd, NULL);
1578 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1582 #ifdef CONFIG_IEEE80211W
1583 static void hostapd_ping_action(struct hostapd_data *hapd,
1584 struct ieee80211_mgmt *mgmt, size_t len)
1586 struct sta_info *sta;
1590 end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
1591 if (((u8 *) mgmt) + len < end) {
1592 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
1593 "frame (len=%lu)", (unsigned long) len);
1597 if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
1598 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
1599 mgmt->u.action.u.ping_resp.action);
1603 /* MLME-PING.confirm */
1605 sta = ap_get_sta(hapd, mgmt->sa);
1606 if (sta == NULL || sta->ping_trans_id == NULL) {
1607 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1608 "pending ping request found");
1612 for (i = 0; i < sta->ping_count; i++) {
1613 if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
1614 mgmt->u.action.u.ping_resp.trans_id,
1615 WLAN_PING_TRANS_ID_LEN) == 0)
1619 if (i >= sta->ping_count) {
1620 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
1621 "transaction identifier found");
1625 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1626 HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
1627 ap_sta_stop_ping(hapd, sta);
1629 #endif /* CONFIG_IEEE80211W */
1632 static void handle_action(struct hostapd_data *hapd,
1633 struct ieee80211_mgmt *mgmt, size_t len)
1635 if (len < IEEE80211_HDRLEN + 1) {
1636 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1637 HOSTAPD_LEVEL_DEBUG,
1638 "handle_action - too short payload (len=%lu)",
1639 (unsigned long) len);
1643 switch (mgmt->u.action.category) {
1644 #ifdef CONFIG_IEEE80211R
1645 case WLAN_ACTION_FT:
1647 struct sta_info *sta;
1649 sta = ap_get_sta(hapd, mgmt->sa);
1650 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1651 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1652 "frame from unassociated STA " MACSTR,
1657 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1658 len - IEEE80211_HDRLEN))
1663 #endif /* CONFIG_IEEE80211R */
1664 case WLAN_ACTION_WMM:
1665 hostapd_wme_action(hapd, mgmt, len);
1667 #ifdef CONFIG_IEEE80211W
1668 case WLAN_ACTION_PING:
1669 hostapd_ping_action(hapd, mgmt, len);
1671 #endif /* CONFIG_IEEE80211W */
1674 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1675 HOSTAPD_LEVEL_DEBUG,
1676 "handle_action - unknown action category %d or invalid "
1678 mgmt->u.action.category);
1679 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1680 !(mgmt->sa[0] & 0x01)) {
1682 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1683 * Return the Action frame to the source without change
1684 * except that MSB of the Category set to 1.
1686 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1687 "frame back to sender");
1688 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1689 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1690 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1691 mgmt->u.action.category |= 0x80;
1693 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1699 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1700 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1702 * @buf: management frame data (starting from IEEE 802.11 header)
1703 * @len: length of frame data in octets
1704 * @stype: management frame subtype from frame control field
1706 * Process all incoming IEEE 802.11 management frames. This will be called for
1707 * each frame received from the kernel driver through wlan#ap interface. In
1708 * addition, it can be called to re-inserted pending frames (e.g., when using
1709 * external RADIUS server as an MAC ACL).
1711 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1712 struct hostapd_frame_info *fi)
1714 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1717 if (stype == WLAN_FC_STYPE_BEACON) {
1718 handle_beacon(hapd, mgmt, len, fi);
1722 if (fi && fi->passive_scan)
1725 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1726 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1727 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1730 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0 &&
1731 (hapd->assoc_ap_state == DO_NOT_ASSOC ||
1732 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0))
1734 printf("MGMT: BSSID=" MACSTR " not our address\n",
1735 MAC2STR(mgmt->bssid));
1740 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1741 handle_probe_req(hapd, mgmt, len);
1745 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1746 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1747 HOSTAPD_LEVEL_DEBUG,
1748 "MGMT: DA=" MACSTR " not our address",
1754 case WLAN_FC_STYPE_AUTH:
1755 wpa_printf(MSG_DEBUG, "mgmt::auth");
1756 handle_auth(hapd, mgmt, len);
1758 case WLAN_FC_STYPE_ASSOC_REQ:
1759 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1760 handle_assoc(hapd, mgmt, len, 0);
1762 case WLAN_FC_STYPE_ASSOC_RESP:
1763 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp");
1764 handle_assoc_resp(hapd, mgmt, len);
1766 case WLAN_FC_STYPE_REASSOC_REQ:
1767 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1768 handle_assoc(hapd, mgmt, len, 1);
1770 case WLAN_FC_STYPE_DISASSOC:
1771 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1772 handle_disassoc(hapd, mgmt, len);
1774 case WLAN_FC_STYPE_DEAUTH:
1775 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1776 handle_deauth(hapd, mgmt, len);
1778 case WLAN_FC_STYPE_ACTION:
1779 wpa_printf(MSG_DEBUG, "mgmt::action");
1780 handle_action(hapd, mgmt, len);
1783 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1784 HOSTAPD_LEVEL_DEBUG,
1785 "unknown mgmt frame subtype %d", stype);
1791 static void handle_auth_cb(struct hostapd_data *hapd,
1792 struct ieee80211_mgmt *mgmt,
1795 u16 auth_alg, auth_transaction, status_code;
1796 struct sta_info *sta;
1799 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1800 HOSTAPD_LEVEL_NOTICE,
1801 "did not acknowledge authentication response");
1805 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1806 printf("handle_auth_cb - too short payload (len=%lu)\n",
1807 (unsigned long) len);
1811 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1812 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1813 status_code = le_to_host16(mgmt->u.auth.status_code);
1815 sta = ap_get_sta(hapd, mgmt->da);
1817 printf("handle_auth_cb: STA " MACSTR " not found\n",
1822 if (status_code == WLAN_STATUS_SUCCESS &&
1823 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1824 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1825 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1826 HOSTAPD_LEVEL_INFO, "authenticated");
1827 sta->flags |= WLAN_STA_AUTH;
1832 static void handle_assoc_cb(struct hostapd_data *hapd,
1833 struct ieee80211_mgmt *mgmt,
1834 size_t len, int reassoc, int ok)
1837 struct sta_info *sta;
1839 struct ht_cap_ie *ht_cap = NULL;
1842 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1843 HOSTAPD_LEVEL_DEBUG,
1844 "did not acknowledge association response");
1848 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1849 sizeof(mgmt->u.assoc_resp))) {
1850 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1851 "(len=%lu)\n", reassoc, (unsigned long) len);
1856 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1858 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1860 sta = ap_get_sta(hapd, mgmt->da);
1862 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1867 if (status != WLAN_STATUS_SUCCESS)
1870 /* Stop previous accounting session, if one is started, and allocate
1871 * new session id for the new session. */
1872 accounting_sta_stop(hapd, sta);
1873 accounting_sta_get_id(hapd, sta);
1875 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1877 "associated (aid %d, accounting session %08X-%08X)",
1878 sta->aid, sta->acct_session_id_hi,
1879 sta->acct_session_id_lo);
1881 if (sta->flags & WLAN_STA_ASSOC)
1883 sta->flags |= WLAN_STA_ASSOC;
1886 mlme_reassociate_indication(hapd, sta);
1888 mlme_associate_indication(hapd, sta);
1890 #ifdef CONFIG_IEEE80211N
1891 if (sta->flags & WLAN_STA_HT)
1892 ht_cap = &sta->ht_capabilities;
1893 #endif /* CONFIG_IEEE80211N */
1895 #ifdef CONFIG_IEEE80211W
1896 sta->ping_timed_out = 0;
1897 #endif /* CONFIG_IEEE80211W */
1899 if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1900 sta->capability, sta->supported_rates,
1901 sta->supported_rates_len, 0, sta->listen_interval,
1904 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1905 HOSTAPD_LEVEL_NOTICE,
1906 "Could not add STA to kernel driver");
1909 if (sta->eapol_sm == NULL) {
1911 * This STA does not use RADIUS server for EAP authentication,
1912 * so bind it to the selected VLAN interface now, since the
1913 * interface selection is not going to change anymore.
1915 ap_sta_bind_vlan(hapd, sta, 0);
1916 } else if (sta->vlan_id) {
1917 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1918 ap_sta_bind_vlan(hapd, sta, 0);
1920 if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1921 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1922 WLAN_STA_SHORT_PREAMBLE, ~0);
1924 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1925 0, ~WLAN_STA_SHORT_PREAMBLE);
1928 if (sta->auth_alg == WLAN_AUTH_FT)
1929 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1931 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1932 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1934 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1937 /* Copy of the association request is not needed anymore */
1938 if (sta->last_assoc_req) {
1939 os_free(sta->last_assoc_req);
1940 sta->last_assoc_req = NULL;
1945 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1948 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1951 case WLAN_FC_STYPE_AUTH:
1952 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1953 handle_auth_cb(hapd, mgmt, len, ok);
1955 case WLAN_FC_STYPE_ASSOC_RESP:
1956 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1957 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1959 case WLAN_FC_STYPE_REASSOC_RESP:
1960 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1961 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1963 case WLAN_FC_STYPE_PROBE_RESP:
1964 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1966 case WLAN_FC_STYPE_DEAUTH:
1969 case WLAN_FC_STYPE_ACTION:
1970 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1973 printf("unknown mgmt cb frame subtype %d\n", stype);
1979 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1982 struct hostapd_data *hapd = eloop_ctx;
1983 hapd->tkip_countermeasures = 0;
1984 hostapd_set_countermeasures(hapd, 0);
1985 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1986 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
1990 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
1992 struct sta_info *sta;
1994 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1995 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
1997 wpa_auth_countermeasures_start(hapd->wpa_auth);
1998 hapd->tkip_countermeasures = 1;
1999 hostapd_set_countermeasures(hapd, 1);
2000 wpa_gtk_rekey(hapd->wpa_auth);
2001 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
2002 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
2004 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
2005 hostapd_sta_deauth(hapd, sta->addr,
2006 WLAN_REASON_MICHAEL_MIC_FAILURE);
2007 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2008 WLAN_STA_AUTHORIZED);
2009 hostapd_sta_remove(hapd, sta->addr);
2014 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
2019 if (addr && local) {
2020 struct sta_info *sta = ap_get_sta(hapd, addr);
2022 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
2023 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
2025 "Michael MIC failure detected in "
2027 mlme_michaelmicfailure_indication(hapd, addr);
2029 wpa_printf(MSG_DEBUG,
2030 "MLME-MICHAELMICFAILURE.indication "
2031 "for not associated STA (" MACSTR
2032 ") ignored", MAC2STR(addr));
2038 if (now > hapd->michael_mic_failure + 60) {
2039 hapd->michael_mic_failures = 1;
2041 hapd->michael_mic_failures++;
2042 if (hapd->michael_mic_failures > 1)
2043 ieee80211_tkip_countermeasures_start(hapd);
2045 hapd->michael_mic_failure = now;
2049 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2056 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2057 char *buf, size_t buflen)
2063 #endif /* CONFIG_NATIVE_WINDOWS */