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(struct hostapd_data *hapd,
297 u8 *pos, size_t elen,
298 struct ieee802_11_elems *elems,
303 /* first 3 bytes in vendor specific information element are the IEEE
304 * OUI of the vendor. The following byte is used a vendor specific
308 wpa_printf(MSG_MSGDUMP, "short vendor specific "
309 "information element ignored (len=%lu)",
310 (unsigned long) elen);
315 oui = WPA_GET_BE24(pos);
318 /* Microsoft/Wi-Fi information elements are further typed and
322 /* Microsoft OUI (00:50:F2) with OUI Type 1:
323 * real WPA information element */
325 elems->wpa_ie_len = elen;
327 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
329 wpa_printf(MSG_MSGDUMP, "short WME "
330 "information element ignored "
332 (unsigned long) elen);
336 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
337 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
339 elems->wme_len = elen;
341 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
342 elems->wme_tspec = pos;
343 elems->wme_tspec_len = elen;
346 wpa_printf(MSG_MSGDUMP, "unknown WME "
347 "information element ignored "
348 "(subtype=%d len=%lu)",
349 pos[4], (unsigned long) elen);
354 wpa_printf(MSG_MSGDUMP, "Unknown Microsoft "
355 "information element ignored "
356 "(type=%d len=%lu)\n",
357 pos[3], (unsigned long) elen);
363 wpa_printf(MSG_MSGDUMP, "unknown vendor specific information "
364 "element ignored (vendor OUI %02x:%02x:%02x "
366 pos[0], pos[1], pos[2], (unsigned long) elen);
374 #ifdef CONFIG_IEEE80211W
375 static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
376 struct sta_info *sta, u8 *eid)
381 *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
383 timeout = (hapd->conf->assoc_ping_attempts - sta->ping_count + 1) *
384 hapd->conf->assoc_ping_timeout;
385 WPA_PUT_LE32(pos, timeout);
390 #endif /* CONFIG_IEEE80211W */
393 ParseRes ieee802_11_parse_elems(struct hostapd_data *hapd, u8 *start,
395 struct ieee802_11_elems *elems,
402 os_memset(elems, 0, sizeof(*elems));
413 wpa_printf(MSG_DEBUG, "IEEE 802.11 element "
414 "parse failed (id=%d elen=%d "
416 id, elen, (unsigned long) left);
417 wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
425 elems->ssid_len = elen;
427 case WLAN_EID_SUPP_RATES:
428 elems->supp_rates = pos;
429 elems->supp_rates_len = elen;
431 case WLAN_EID_FH_PARAMS:
432 elems->fh_params = pos;
433 elems->fh_params_len = elen;
435 case WLAN_EID_DS_PARAMS:
436 elems->ds_params = pos;
437 elems->ds_params_len = elen;
439 case WLAN_EID_CF_PARAMS:
440 elems->cf_params = pos;
441 elems->cf_params_len = elen;
445 elems->tim_len = elen;
447 case WLAN_EID_IBSS_PARAMS:
448 elems->ibss_params = pos;
449 elems->ibss_params_len = elen;
451 case WLAN_EID_CHALLENGE:
452 elems->challenge = pos;
453 elems->challenge_len = elen;
455 case WLAN_EID_ERP_INFO:
456 elems->erp_info = pos;
457 elems->erp_info_len = elen;
459 case WLAN_EID_EXT_SUPP_RATES:
460 elems->ext_supp_rates = pos;
461 elems->ext_supp_rates_len = elen;
463 case WLAN_EID_VENDOR_SPECIFIC:
464 if (ieee802_11_parse_vendor_specific(hapd, pos, elen,
471 elems->rsn_ie_len = elen;
473 case WLAN_EID_PWR_CAPABILITY:
474 elems->power_cap = pos;
475 elems->power_cap_len = elen;
477 case WLAN_EID_SUPPORTED_CHANNELS:
478 elems->supp_channels = pos;
479 elems->supp_channels_len = elen;
481 case WLAN_EID_MOBILITY_DOMAIN:
483 elems->mdie_len = elen;
485 case WLAN_EID_FAST_BSS_TRANSITION:
487 elems->ftie_len = elen;
489 case WLAN_EID_HT_CAP:
490 elems->ht_capabilities = pos;
491 elems->ht_capabilities_len = elen;
493 case WLAN_EID_HT_OPERATION:
494 elems->ht_operation = pos;
495 elems->ht_operation_len = elen;
501 wpa_printf(MSG_MSGDUMP, "IEEE 802.11 element parse "
502 "ignored unknown element (id=%d elen=%d)",
514 return unknown ? ParseUnknown : ParseOK;
518 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
521 if (len > HOSTAPD_MAX_SSID_LEN)
522 len = HOSTAPD_MAX_SSID_LEN;
523 for (i = 0; i < len; i++) {
524 if (ssid[i] >= 32 && ssid[i] < 127)
533 void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
535 struct ieee80211_mgmt mgmt;
537 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
539 "deauthenticate - reason %d", reason);
540 os_memset(&mgmt, 0, sizeof(mgmt));
541 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
542 WLAN_FC_STYPE_DEAUTH);
543 os_memcpy(mgmt.da, addr, ETH_ALEN);
544 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
545 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
546 mgmt.u.deauth.reason_code = host_to_le16(reason);
547 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
548 sizeof(mgmt.u.deauth), 0) < 0)
549 perror("ieee802_11_send_deauth: send");
553 static void ieee802_11_sta_authenticate(void *eloop_ctx, void *timeout_ctx)
555 struct hostapd_data *hapd = eloop_ctx;
556 struct ieee80211_mgmt mgmt;
559 if (hapd->assoc_ap_state == WAIT_BEACON)
560 hapd->assoc_ap_state = AUTHENTICATE;
561 if (hapd->assoc_ap_state != AUTHENTICATE)
564 ieee802_11_print_ssid(ssid_txt, (u8 *) hapd->assoc_ap_ssid,
565 hapd->assoc_ap_ssid_len);
566 printf("Authenticate with AP " MACSTR " SSID=%s (as station)\n",
567 MAC2STR(hapd->conf->assoc_ap_addr), ssid_txt);
569 os_memset(&mgmt, 0, sizeof(mgmt));
570 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
572 os_memcpy(mgmt.da, hapd->conf->assoc_ap_addr, ETH_ALEN);
573 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
574 os_memcpy(mgmt.bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
575 mgmt.u.auth.auth_alg = host_to_le16(WLAN_AUTH_OPEN);
576 mgmt.u.auth.auth_transaction = host_to_le16(1);
577 mgmt.u.auth.status_code = host_to_le16(0);
578 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
579 sizeof(mgmt.u.auth), 0) < 0)
580 perror("ieee802_11_sta_authenticate: send");
582 /* Try to authenticate again, if this attempt fails or times out. */
583 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate, hapd, NULL);
587 static void ieee802_11_sta_associate(void *eloop_ctx, void *timeout_ctx)
589 struct hostapd_data *hapd = eloop_ctx;
591 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
595 if (hapd->assoc_ap_state == AUTHENTICATE)
596 hapd->assoc_ap_state = ASSOCIATE;
597 if (hapd->assoc_ap_state != ASSOCIATE)
600 ieee802_11_print_ssid(ssid_txt, (u8 *) hapd->assoc_ap_ssid,
601 hapd->assoc_ap_ssid_len);
602 printf("Associate with AP " MACSTR " SSID=%s (as station)\n",
603 MAC2STR(hapd->conf->assoc_ap_addr), ssid_txt);
605 os_memset(mgmt, 0, sizeof(*mgmt));
606 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
607 WLAN_FC_STYPE_ASSOC_REQ);
608 os_memcpy(mgmt->da, hapd->conf->assoc_ap_addr, ETH_ALEN);
609 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
610 os_memcpy(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
611 mgmt->u.assoc_req.capab_info = host_to_le16(0);
612 mgmt->u.assoc_req.listen_interval = host_to_le16(1);
613 p = &mgmt->u.assoc_req.variable[0];
615 *p++ = WLAN_EID_SSID;
616 *p++ = hapd->assoc_ap_ssid_len;
617 os_memcpy(p, hapd->assoc_ap_ssid, hapd->assoc_ap_ssid_len);
618 p += hapd->assoc_ap_ssid_len;
620 p = hostapd_eid_supp_rates(hapd, p);
621 p = hostapd_eid_ext_supp_rates(hapd, p);
623 if (hostapd_send_mgmt_frame(hapd, mgmt, p - (u8 *) mgmt, 0) < 0)
624 perror("ieee802_11_sta_associate: send");
626 /* Try to authenticate again, if this attempt fails or times out. */
627 eloop_register_timeout(5, 0, ieee802_11_sta_associate, hapd, NULL);
631 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
632 u16 auth_transaction, u8 *challenge, int iswep)
634 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
636 "authentication (shared key, transaction %d)",
639 if (auth_transaction == 1) {
640 if (!sta->challenge) {
641 /* Generate a pseudo-random challenge */
645 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
646 if (sta->challenge == NULL)
647 return WLAN_STATUS_UNSPECIFIED_FAILURE;
651 os_memcpy(key, &now, 4);
652 os_memcpy(key + 4, &r, 4);
653 rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
659 if (auth_transaction != 3)
660 return WLAN_STATUS_UNSPECIFIED_FAILURE;
663 if (!iswep || !sta->challenge || !challenge ||
664 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
665 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
667 "shared key authentication - invalid "
668 "challenge-response");
669 return WLAN_STATUS_CHALLENGE_FAIL;
672 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
674 "authentication OK (shared key)");
675 #ifdef IEEE80211_REQUIRE_AUTH_ACK
676 /* Station will be marked authenticated if it ACKs the
677 * authentication reply. */
679 sta->flags |= WLAN_STA_AUTH;
680 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
682 os_free(sta->challenge);
683 sta->challenge = NULL;
689 static void send_auth_reply(struct hostapd_data *hapd,
690 const u8 *dst, const u8 *bssid,
691 u16 auth_alg, u16 auth_transaction, u16 resp,
692 const u8 *ies, size_t ies_len)
694 struct ieee80211_mgmt *reply;
698 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
699 buf = os_zalloc(rlen);
703 reply = (struct ieee80211_mgmt *) buf;
704 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
706 os_memcpy(reply->da, dst, ETH_ALEN);
707 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
708 os_memcpy(reply->bssid, bssid, ETH_ALEN);
710 reply->u.auth.auth_alg = host_to_le16(auth_alg);
711 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
712 reply->u.auth.status_code = host_to_le16(resp);
715 os_memcpy(reply->u.auth.variable, ies, ies_len);
717 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
718 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
719 MAC2STR(dst), auth_alg, auth_transaction,
720 resp, (unsigned long) ies_len);
721 if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
722 perror("send_auth_reply: send");
728 #ifdef CONFIG_IEEE80211R
729 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
730 u16 auth_transaction, u16 status,
731 const u8 *ies, size_t ies_len)
733 struct hostapd_data *hapd = ctx;
734 struct sta_info *sta;
736 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
737 status, ies, ies_len);
739 if (status != WLAN_STATUS_SUCCESS)
742 sta = ap_get_sta(hapd, dst);
746 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
747 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
748 sta->flags |= WLAN_STA_AUTH;
749 mlme_authenticate_indication(hapd, sta);
751 #endif /* CONFIG_IEEE80211R */
754 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
757 u16 auth_alg, auth_transaction, status_code;
758 u16 resp = WLAN_STATUS_SUCCESS;
759 struct sta_info *sta = NULL;
762 u8 *challenge = NULL;
763 u32 session_timeout, acct_interim_interval;
765 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
766 size_t resp_ies_len = 0;
768 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
769 printf("handle_auth - too short payload (len=%lu)\n",
770 (unsigned long) len);
774 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
775 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
776 status_code = le_to_host16(mgmt->u.auth.status_code);
777 fc = le_to_host16(mgmt->frame_control);
779 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
780 2 + WLAN_AUTH_CHALLENGE_LEN &&
781 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
782 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
783 challenge = &mgmt->u.auth.variable[2];
785 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
786 "auth_transaction=%d status_code=%d wep=%d%s",
787 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
788 status_code, !!(fc & WLAN_FC_ISWEP),
789 challenge ? " challenge" : "");
791 if (hapd->assoc_ap_state == AUTHENTICATE && auth_transaction == 2 &&
792 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0 &&
793 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
794 if (status_code != 0) {
795 printf("Authentication (as station) with AP "
796 MACSTR " failed (status_code=%d)\n",
797 MAC2STR(hapd->conf->assoc_ap_addr),
801 printf("Authenticated (as station) with AP " MACSTR "\n",
802 MAC2STR(hapd->conf->assoc_ap_addr));
803 ieee802_11_sta_associate(hapd, NULL);
807 if (hapd->tkip_countermeasures) {
808 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
812 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
813 auth_alg == WLAN_AUTH_OPEN) ||
814 #ifdef CONFIG_IEEE80211R
816 (hapd->conf->wpa_key_mgmt &
817 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
818 auth_alg == WLAN_AUTH_FT) ||
819 #endif /* CONFIG_IEEE80211R */
820 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
821 auth_alg == WLAN_AUTH_SHARED_KEY))) {
822 printf("Unsupported authentication algorithm (%d)\n",
824 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
828 if (!(auth_transaction == 1 ||
829 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
830 printf("Unknown authentication transaction number (%d)\n",
832 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
836 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
837 printf("Station " MACSTR " not allowed to authenticate.\n",
839 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
843 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
845 &acct_interim_interval, &vlan_id);
846 if (res == HOSTAPD_ACL_REJECT) {
847 printf("Station " MACSTR " not allowed to authenticate.\n",
849 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
852 if (res == HOSTAPD_ACL_PENDING) {
853 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
854 " waiting for an external authentication",
856 /* Authentication code will re-send the authentication frame
857 * after it has received (and cached) information from the
858 * external source. */
862 sta = ap_sta_add(hapd, mgmt->sa);
864 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
869 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
870 sta->vlan_id) == NULL) {
871 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
872 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
873 "%d received from RADIUS server",
875 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
878 sta->vlan_id = vlan_id;
879 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
880 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
883 sta->flags &= ~WLAN_STA_PREAUTH;
884 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
886 if (hapd->conf->radius->acct_interim_interval == 0 &&
887 acct_interim_interval)
888 sta->acct_interim_interval = acct_interim_interval;
889 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
890 ap_sta_session_timeout(hapd, sta, session_timeout);
892 ap_sta_no_session_timeout(hapd, sta);
896 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
898 "authentication OK (open system)");
899 #ifdef IEEE80211_REQUIRE_AUTH_ACK
900 /* Station will be marked authenticated if it ACKs the
901 * authentication reply. */
903 sta->flags |= WLAN_STA_AUTH;
904 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
905 sta->auth_alg = WLAN_AUTH_OPEN;
906 mlme_authenticate_indication(hapd, sta);
909 case WLAN_AUTH_SHARED_KEY:
910 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
912 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
913 mlme_authenticate_indication(hapd, sta);
914 if (sta->challenge && auth_transaction == 1) {
915 resp_ies[0] = WLAN_EID_CHALLENGE;
916 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
917 os_memcpy(resp_ies + 2, sta->challenge,
918 WLAN_AUTH_CHALLENGE_LEN);
919 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
922 #ifdef CONFIG_IEEE80211R
924 sta->auth_alg = WLAN_AUTH_FT;
925 if (sta->wpa_sm == NULL)
926 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
928 if (sta->wpa_sm == NULL) {
929 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
931 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
934 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
935 auth_transaction, mgmt->u.auth.variable,
936 len - IEEE80211_HDRLEN -
937 sizeof(mgmt->u.auth),
938 handle_auth_ft_finish, hapd);
939 /* handle_auth_ft_finish() callback will complete auth. */
941 #endif /* CONFIG_IEEE80211R */
945 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
946 auth_transaction + 1, resp, resp_ies, resp_ies_len);
950 static void handle_assoc(struct hostapd_data *hapd,
951 struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
953 u16 capab_info, listen_interval;
954 u16 resp = WLAN_STATUS_SUCCESS;
957 int send_deauth = 0, send_len, left, i;
958 struct sta_info *sta;
959 struct ieee802_11_elems elems;
960 u8 buf[sizeof(struct ieee80211_mgmt) + 512];
961 struct ieee80211_mgmt *reply;
963 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
964 sizeof(mgmt->u.assoc_req))) {
965 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
966 "\n", reassoc, (unsigned long) len);
971 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
972 listen_interval = le_to_host16(
973 mgmt->u.reassoc_req.listen_interval);
974 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
975 " capab_info=0x%02x listen_interval=%d current_ap="
977 MAC2STR(mgmt->sa), capab_info, listen_interval,
978 MAC2STR(mgmt->u.reassoc_req.current_ap));
979 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
980 pos = mgmt->u.reassoc_req.variable;
982 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
983 listen_interval = le_to_host16(
984 mgmt->u.assoc_req.listen_interval);
985 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
986 " capab_info=0x%02x listen_interval=%d",
987 MAC2STR(mgmt->sa), capab_info, listen_interval);
988 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
989 pos = mgmt->u.assoc_req.variable;
992 sta = ap_get_sta(hapd, mgmt->sa);
993 #ifdef CONFIG_IEEE80211R
994 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
995 (sta->flags & WLAN_STA_AUTH) == 0) {
996 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
997 "prior to authentication since it is using "
998 "over-the-DS FT", MAC2STR(mgmt->sa));
1000 #endif /* CONFIG_IEEE80211R */
1001 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1002 printf("STA " MACSTR " trying to associate before "
1003 "authentication\n", MAC2STR(mgmt->sa));
1005 printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
1006 MAC2STR(sta->addr), sta->aid, sta->flags);
1009 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1013 if (hapd->tkip_countermeasures) {
1014 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1018 if (listen_interval > hapd->conf->max_listen_interval) {
1019 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1020 HOSTAPD_LEVEL_DEBUG,
1021 "Too large Listen Interval (%d)",
1023 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1027 sta->capability = capab_info;
1029 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1031 if (ieee802_11_parse_elems(hapd, pos, left, &elems, 1) == ParseFailed
1033 printf("STA " MACSTR " sent invalid association request\n",
1034 MAC2STR(sta->addr));
1035 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1039 if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
1040 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
1043 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
1044 printf("Station " MACSTR " tried to associate with "
1045 "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
1046 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1050 sta->flags &= ~WLAN_STA_WME;
1051 if (elems.wme && hapd->conf->wme_enabled) {
1052 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
1053 hostapd_logger(hapd, sta->addr,
1055 HOSTAPD_LEVEL_DEBUG,
1056 "invalid WME element in association "
1059 sta->flags |= WLAN_STA_WME;
1062 if (!elems.supp_rates) {
1063 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1064 HOSTAPD_LEVEL_DEBUG,
1065 "No supported rates element in AssocReq");
1066 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1070 if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
1071 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1072 HOSTAPD_LEVEL_DEBUG,
1073 "Invalid supported rates element length %d",
1074 elems.supp_rates_len);
1075 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1079 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
1080 os_memcpy(sta->supported_rates, elems.supp_rates,
1081 elems.supp_rates_len);
1082 sta->supported_rates_len = elems.supp_rates_len;
1084 if (elems.ext_supp_rates) {
1085 if (elems.supp_rates_len + elems.ext_supp_rates_len >
1086 sizeof(sta->supported_rates)) {
1087 hostapd_logger(hapd, mgmt->sa,
1088 HOSTAPD_MODULE_IEEE80211,
1089 HOSTAPD_LEVEL_DEBUG,
1090 "Invalid supported rates element length"
1091 " %d+%d", elems.supp_rates_len,
1092 elems.ext_supp_rates_len);
1093 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1097 os_memcpy(sta->supported_rates + elems.supp_rates_len,
1098 elems.ext_supp_rates, elems.ext_supp_rates_len);
1099 sta->supported_rates_len += elems.ext_supp_rates_len;
1102 #ifdef CONFIG_IEEE80211N
1103 /* save HT capabilities in the sta object */
1104 os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
1105 if (elems.ht_capabilities &&
1106 elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
1107 && (sta->flags & WLAN_STA_WME)) {
1108 /* note: without WMM capability, treat the sta as non-HT */
1109 sta->flags |= WLAN_STA_HT;
1110 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
1111 sta->ht_capabilities.length =
1112 sizeof(struct ieee80211_ht_capability);
1113 os_memcpy(&sta->ht_capabilities.data,
1114 elems.ht_capabilities,
1115 sizeof(struct ieee80211_ht_capability));
1117 sta->flags &= ~WLAN_STA_HT;
1118 #endif /* CONFIG_IEEE80211N */
1120 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1121 wpa_ie = elems.rsn_ie;
1122 wpa_ie_len = elems.rsn_ie_len;
1123 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1125 wpa_ie = elems.wpa_ie;
1126 wpa_ie_len = elems.wpa_ie_len;
1131 if (hapd->conf->wpa && wpa_ie == NULL) {
1132 printf("STA " MACSTR ": No WPA/RSN IE in association "
1133 "request\n", MAC2STR(sta->addr));
1134 resp = WLAN_STATUS_INVALID_IE;
1138 if (hapd->conf->wpa && wpa_ie) {
1142 if (sta->wpa_sm == NULL)
1143 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1145 if (sta->wpa_sm == NULL) {
1146 printf("Failed to initialize WPA state machine\n");
1147 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1150 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1152 elems.mdie, elems.mdie_len);
1153 if (res == WPA_INVALID_GROUP)
1154 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1155 else if (res == WPA_INVALID_PAIRWISE)
1156 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1157 else if (res == WPA_INVALID_AKMP)
1158 resp = WLAN_STATUS_AKMP_NOT_VALID;
1159 else if (res == WPA_ALLOC_FAIL)
1160 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1161 #ifdef CONFIG_IEEE80211W
1162 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1163 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1164 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1165 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1166 #endif /* CONFIG_IEEE80211W */
1167 else if (res == WPA_INVALID_MDIE)
1168 resp = WLAN_STATUS_INVALID_MDIE;
1169 else if (res != WPA_IE_OK)
1170 resp = WLAN_STATUS_INVALID_IE;
1171 if (resp != WLAN_STATUS_SUCCESS)
1173 #ifdef CONFIG_IEEE80211W
1174 if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
1176 * STA has already been associated with MFP and ping
1177 * timeout has not been reached. Reject the
1178 * association attempt temporarily and start ping, if
1179 * one is not pending.
1182 if (sta->ping_count == 0)
1183 ap_sta_start_ping(hapd, sta);
1185 resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1189 if (wpa_auth_uses_mfp(sta->wpa_sm))
1190 sta->flags |= WLAN_STA_MFP;
1192 sta->flags &= ~WLAN_STA_MFP;
1193 #endif /* CONFIG_IEEE80211W */
1195 #ifdef CONFIG_IEEE80211R
1196 if (sta->auth_alg == WLAN_AUTH_FT) {
1198 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1199 "to use association (not "
1200 "re-association) with FT auth_alg",
1201 MAC2STR(sta->addr));
1202 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1206 resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
1207 if (resp != WLAN_STATUS_SUCCESS)
1210 #endif /* CONFIG_IEEE80211R */
1213 if (hapd->iface->dfs_enable &&
1214 hapd->iconf->ieee80211h == SPECT_STRICT_BINDING) {
1215 if (hostapd_check_power_cap(hapd, elems.power_cap,
1216 elems.power_cap_len)) {
1217 resp = WLAN_STATUS_PWR_CAPABILITY_NOT_VALID;
1218 hostapd_logger(hapd, sta->addr,
1219 HOSTAPD_MODULE_IEEE80211,
1220 HOSTAPD_LEVEL_DEBUG,
1221 "Power capabilities of the station not "
1227 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1228 sta->flags |= WLAN_STA_NONERP;
1229 for (i = 0; i < sta->supported_rates_len; i++) {
1230 if ((sta->supported_rates[i] & 0x7f) > 22) {
1231 sta->flags &= ~WLAN_STA_NONERP;
1235 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1236 sta->nonerp_set = 1;
1237 hapd->iface->num_sta_non_erp++;
1238 if (hapd->iface->num_sta_non_erp == 1)
1239 ieee802_11_set_beacons(hapd->iface);
1242 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1243 !sta->no_short_slot_time_set) {
1244 sta->no_short_slot_time_set = 1;
1245 hapd->iface->num_sta_no_short_slot_time++;
1246 if (hapd->iface->current_mode->mode ==
1247 HOSTAPD_MODE_IEEE80211G &&
1248 hapd->iface->num_sta_no_short_slot_time == 1)
1249 ieee802_11_set_beacons(hapd->iface);
1252 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1253 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1255 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1257 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1258 !sta->no_short_preamble_set) {
1259 sta->no_short_preamble_set = 1;
1260 hapd->iface->num_sta_no_short_preamble++;
1261 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1262 && hapd->iface->num_sta_no_short_preamble == 1)
1263 ieee802_11_set_beacons(hapd->iface);
1266 #ifdef CONFIG_IEEE80211N
1267 if (sta->flags & WLAN_STA_HT) {
1268 if ((sta->ht_capabilities.data.capabilities_info &
1269 HT_CAP_INFO_GREEN_FIELD) == 0) {
1270 hapd->iface->num_sta_ht_no_gf++;
1271 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
1272 "greenfield, num of non-gf stations %d",
1273 __func__, MAC2STR(sta->addr),
1274 hapd->iface->num_sta_ht_no_gf);
1276 if ((sta->ht_capabilities.data.capabilities_info &
1277 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
1278 hapd->iface->num_sta_ht_20mhz++;
1279 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
1280 "num of 20MHz HT STAs %d",
1281 __func__, MAC2STR(sta->addr),
1282 hapd->iface->num_sta_ht_20mhz);
1285 hapd->iface->num_sta_no_ht++;
1286 if (hapd->iconf->ieee80211n) {
1287 wpa_printf(MSG_DEBUG, "%s STA " MACSTR
1288 " - no HT, num of non-HT stations %d",
1289 __func__, MAC2STR(sta->addr),
1290 hapd->iface->num_sta_no_ht);
1294 if (hostapd_ht_operation_update(hapd->iface) > 0)
1295 ieee802_11_set_beacons(hapd->iface);
1296 #endif /* CONFIG_IEEE80211N */
1298 /* get a unique AID */
1300 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1302 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1303 if (hapd->sta_aid[sta->aid - 1] == NULL)
1305 if (sta->aid > MAX_AID_TABLE_SIZE) {
1307 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1308 wpa_printf(MSG_ERROR, " no room for more AIDs");
1311 hapd->sta_aid[sta->aid - 1] = sta;
1312 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1316 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1317 HOSTAPD_LEVEL_DEBUG,
1318 "association OK (aid %d)", sta->aid);
1319 /* Station will be marked associated, after it acknowledges AssocResp
1323 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1327 if (sta->last_assoc_req)
1328 os_free(sta->last_assoc_req);
1329 sta->last_assoc_req = os_malloc(len);
1330 if (sta->last_assoc_req)
1331 os_memcpy(sta->last_assoc_req, mgmt, len);
1333 /* Make sure that the previously registered inactivity timer will not
1334 * remove the STA immediately. */
1335 sta->timeout_next = STA_NULLFUNC;
1338 os_memset(buf, 0, sizeof(buf));
1339 reply = (struct ieee80211_mgmt *) buf;
1340 reply->frame_control =
1341 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1342 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1343 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1344 WLAN_FC_STYPE_ASSOC_RESP)));
1345 os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1346 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1347 os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1349 send_len = IEEE80211_HDRLEN;
1351 send_len += sizeof(reply->u.deauth);
1352 reply->u.deauth.reason_code = host_to_le16(resp);
1355 send_len += sizeof(reply->u.assoc_resp);
1356 reply->u.assoc_resp.capab_info =
1357 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1358 reply->u.assoc_resp.status_code = host_to_le16(resp);
1359 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1360 | BIT(14) | BIT(15));
1361 /* Supported rates */
1362 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1363 /* Extended supported rates */
1364 p = hostapd_eid_ext_supp_rates(hapd, p);
1365 if (sta->flags & WLAN_STA_WME)
1366 p = hostapd_eid_wme(hapd, p);
1368 p = hostapd_eid_ht_capabilities_info(hapd, p);
1369 p = hostapd_eid_ht_operation(hapd, p);
1371 #ifdef CONFIG_IEEE80211R
1372 if (resp == WLAN_STATUS_SUCCESS) {
1373 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1374 * Transition Information, RSN */
1375 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1376 buf + sizeof(buf) - p,
1379 #endif /* CONFIG_IEEE80211R */
1381 #ifdef CONFIG_IEEE80211W
1382 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1383 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1384 #endif /* CONFIG_IEEE80211W */
1386 send_len += p - reply->u.assoc_resp.variable;
1389 if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1390 perror("handle_assoc: send");
1394 static void handle_assoc_resp(struct hostapd_data *hapd,
1395 struct ieee80211_mgmt *mgmt, size_t len)
1397 u16 status_code, aid;
1399 if (hapd->assoc_ap_state != ASSOCIATE) {
1400 printf("Unexpected association response received from " MACSTR
1401 "\n", MAC2STR(mgmt->sa));
1405 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_resp)) {
1406 printf("handle_assoc_resp - too short payload (len=%lu)\n",
1407 (unsigned long) len);
1411 if (os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0 ||
1412 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0) {
1413 printf("Received association response from unexpected address "
1414 "(SA=" MACSTR " BSSID=" MACSTR "\n",
1415 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
1419 status_code = le_to_host16(mgmt->u.assoc_resp.status_code);
1420 aid = le_to_host16(mgmt->u.assoc_resp.aid);
1421 aid &= ~(BIT(14) | BIT(15));
1423 if (status_code != 0) {
1424 printf("Association (as station) with AP " MACSTR " failed "
1425 "(status_code=%d)\n",
1426 MAC2STR(hapd->conf->assoc_ap_addr), status_code);
1427 /* Try to authenticate again */
1428 hapd->assoc_ap_state = AUTHENTICATE;
1429 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate,
1433 printf("Associated (as station) with AP " MACSTR " (aid=%d)\n",
1434 MAC2STR(hapd->conf->assoc_ap_addr), aid);
1435 hapd->assoc_ap_aid = aid;
1436 hapd->assoc_ap_state = ASSOCIATED;
1438 if (hostapd_set_assoc_ap(hapd, hapd->conf->assoc_ap_addr)) {
1439 printf("Could not set associated AP address to kernel "
1445 static void handle_disassoc(struct hostapd_data *hapd,
1446 struct ieee80211_mgmt *mgmt, size_t len)
1448 struct sta_info *sta;
1450 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1451 printf("handle_disassoc - too short payload (len=%lu)\n",
1452 (unsigned long) len);
1456 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1458 le_to_host16(mgmt->u.disassoc.reason_code));
1460 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1461 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1462 printf("Assoc AP " MACSTR " sent disassociation "
1463 "(reason_code=%d) - try to authenticate\n",
1464 MAC2STR(hapd->conf->assoc_ap_addr),
1465 le_to_host16(mgmt->u.disassoc.reason_code));
1466 hapd->assoc_ap_state = AUTHENTICATE;
1467 ieee802_11_sta_authenticate(hapd, NULL);
1468 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1473 sta = ap_get_sta(hapd, mgmt->sa);
1475 printf("Station " MACSTR " trying to disassociate, but it "
1476 "is not associated.\n", MAC2STR(mgmt->sa));
1480 sta->flags &= ~WLAN_STA_ASSOC;
1481 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1482 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1483 HOSTAPD_LEVEL_INFO, "disassociated");
1484 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1485 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1486 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1488 accounting_sta_stop(hapd, sta);
1489 ieee802_1x_free_station(sta);
1490 hostapd_sta_remove(hapd, sta->addr);
1492 if (sta->timeout_next == STA_NULLFUNC ||
1493 sta->timeout_next == STA_DISASSOC) {
1494 sta->timeout_next = STA_DEAUTH;
1495 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1496 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1500 mlme_disassociate_indication(
1501 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1505 static void handle_deauth(struct hostapd_data *hapd,
1506 struct ieee80211_mgmt *mgmt, size_t len)
1508 struct sta_info *sta;
1510 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1511 printf("handle_deauth - too short payload (len=%lu)\n",
1512 (unsigned long) len);
1516 wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1519 le_to_host16(mgmt->u.deauth.reason_code));
1521 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1522 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1523 printf("Assoc AP " MACSTR " sent deauthentication "
1524 "(reason_code=%d) - try to authenticate\n",
1525 MAC2STR(hapd->conf->assoc_ap_addr),
1526 le_to_host16(mgmt->u.deauth.reason_code));
1527 hapd->assoc_ap_state = AUTHENTICATE;
1528 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1533 sta = ap_get_sta(hapd, mgmt->sa);
1535 printf("Station " MACSTR " trying to deauthenticate, but it "
1536 "is not authenticated.\n", MAC2STR(mgmt->sa));
1540 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1541 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1542 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1543 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1544 mlme_deauthenticate_indication(
1545 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1546 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1547 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1548 ap_free_sta(hapd, sta);
1552 static void handle_beacon(struct hostapd_data *hapd,
1553 struct ieee80211_mgmt *mgmt, size_t len,
1554 struct hostapd_frame_info *fi)
1556 struct ieee802_11_elems elems;
1558 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1559 printf("handle_beacon - too short payload (len=%lu)\n",
1560 (unsigned long) len);
1564 (void) ieee802_11_parse_elems(hapd, mgmt->u.beacon.variable,
1565 len - (IEEE80211_HDRLEN +
1566 sizeof(mgmt->u.beacon)), &elems,
1569 if (hapd->assoc_ap_state == WAIT_BEACON &&
1570 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1571 if (elems.ssid && elems.ssid_len <= 32) {
1572 os_memcpy(hapd->assoc_ap_ssid, elems.ssid,
1574 hapd->assoc_ap_ssid[elems.ssid_len] = '\0';
1575 hapd->assoc_ap_ssid_len = elems.ssid_len;
1577 ieee802_11_sta_authenticate(hapd, NULL);
1580 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1584 #ifdef CONFIG_IEEE80211W
1585 static void hostapd_ping_action(struct hostapd_data *hapd,
1586 struct ieee80211_mgmt *mgmt, size_t len)
1588 struct sta_info *sta;
1592 end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
1593 if (((u8 *) mgmt) + len < end) {
1594 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
1595 "frame (len=%lu)", (unsigned long) len);
1599 if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
1600 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
1601 mgmt->u.action.u.ping_resp.action);
1605 /* MLME-PING.confirm */
1607 sta = ap_get_sta(hapd, mgmt->sa);
1608 if (sta == NULL || sta->ping_trans_id == NULL) {
1609 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1610 "pending ping request found");
1614 for (i = 0; i < sta->ping_count; i++) {
1615 if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
1616 mgmt->u.action.u.ping_resp.trans_id,
1617 WLAN_PING_TRANS_ID_LEN) == 0)
1621 if (i >= sta->ping_count) {
1622 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
1623 "transaction identifier found");
1627 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1628 HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
1629 ap_sta_stop_ping(hapd, sta);
1631 #endif /* CONFIG_IEEE80211W */
1634 static void handle_action(struct hostapd_data *hapd,
1635 struct ieee80211_mgmt *mgmt, size_t len)
1637 if (len < IEEE80211_HDRLEN + 1) {
1638 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1639 HOSTAPD_LEVEL_DEBUG,
1640 "handle_action - too short payload (len=%lu)",
1641 (unsigned long) len);
1645 switch (mgmt->u.action.category) {
1646 #ifdef CONFIG_IEEE80211R
1647 case WLAN_ACTION_FT:
1649 struct sta_info *sta;
1651 sta = ap_get_sta(hapd, mgmt->sa);
1652 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1653 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1654 "frame from unassociated STA " MACSTR,
1659 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1660 len - IEEE80211_HDRLEN))
1665 #endif /* CONFIG_IEEE80211R */
1666 case WLAN_ACTION_WMM:
1667 hostapd_wme_action(hapd, mgmt, len);
1669 #ifdef CONFIG_IEEE80211W
1670 case WLAN_ACTION_PING:
1671 hostapd_ping_action(hapd, mgmt, len);
1673 #endif /* CONFIG_IEEE80211W */
1676 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1677 HOSTAPD_LEVEL_DEBUG,
1678 "handle_action - unknown action category %d or invalid "
1680 mgmt->u.action.category);
1681 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1682 !(mgmt->sa[0] & 0x01)) {
1684 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1685 * Return the Action frame to the source without change
1686 * except that MSB of the Category set to 1.
1688 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1689 "frame back to sender");
1690 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1691 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1692 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1693 mgmt->u.action.category |= 0x80;
1695 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1701 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1702 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1704 * @buf: management frame data (starting from IEEE 802.11 header)
1705 * @len: length of frame data in octets
1706 * @stype: management frame subtype from frame control field
1708 * Process all incoming IEEE 802.11 management frames. This will be called for
1709 * each frame received from the kernel driver through wlan#ap interface. In
1710 * addition, it can be called to re-inserted pending frames (e.g., when using
1711 * external RADIUS server as an MAC ACL).
1713 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1714 struct hostapd_frame_info *fi)
1716 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1719 if (stype == WLAN_FC_STYPE_BEACON) {
1720 handle_beacon(hapd, mgmt, len, fi);
1724 if (fi && fi->passive_scan)
1727 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1728 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1729 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1732 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0 &&
1733 (hapd->assoc_ap_state == DO_NOT_ASSOC ||
1734 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0))
1736 printf("MGMT: BSSID=" MACSTR " not our address\n",
1737 MAC2STR(mgmt->bssid));
1742 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1743 handle_probe_req(hapd, mgmt, len);
1747 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1748 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1749 HOSTAPD_LEVEL_DEBUG,
1750 "MGMT: DA=" MACSTR " not our address",
1756 case WLAN_FC_STYPE_AUTH:
1757 wpa_printf(MSG_DEBUG, "mgmt::auth");
1758 handle_auth(hapd, mgmt, len);
1760 case WLAN_FC_STYPE_ASSOC_REQ:
1761 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1762 handle_assoc(hapd, mgmt, len, 0);
1764 case WLAN_FC_STYPE_ASSOC_RESP:
1765 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp");
1766 handle_assoc_resp(hapd, mgmt, len);
1768 case WLAN_FC_STYPE_REASSOC_REQ:
1769 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1770 handle_assoc(hapd, mgmt, len, 1);
1772 case WLAN_FC_STYPE_DISASSOC:
1773 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1774 handle_disassoc(hapd, mgmt, len);
1776 case WLAN_FC_STYPE_DEAUTH:
1777 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1778 handle_deauth(hapd, mgmt, len);
1780 case WLAN_FC_STYPE_ACTION:
1781 wpa_printf(MSG_DEBUG, "mgmt::action");
1782 handle_action(hapd, mgmt, len);
1785 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1786 HOSTAPD_LEVEL_DEBUG,
1787 "unknown mgmt frame subtype %d", stype);
1793 static void handle_auth_cb(struct hostapd_data *hapd,
1794 struct ieee80211_mgmt *mgmt,
1797 u16 auth_alg, auth_transaction, status_code;
1798 struct sta_info *sta;
1801 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1802 HOSTAPD_LEVEL_NOTICE,
1803 "did not acknowledge authentication response");
1807 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1808 printf("handle_auth_cb - too short payload (len=%lu)\n",
1809 (unsigned long) len);
1813 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1814 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1815 status_code = le_to_host16(mgmt->u.auth.status_code);
1817 sta = ap_get_sta(hapd, mgmt->da);
1819 printf("handle_auth_cb: STA " MACSTR " not found\n",
1824 if (status_code == WLAN_STATUS_SUCCESS &&
1825 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1826 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1827 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1828 HOSTAPD_LEVEL_INFO, "authenticated");
1829 sta->flags |= WLAN_STA_AUTH;
1834 static void handle_assoc_cb(struct hostapd_data *hapd,
1835 struct ieee80211_mgmt *mgmt,
1836 size_t len, int reassoc, int ok)
1839 struct sta_info *sta;
1841 struct ht_cap_ie *ht_cap = NULL;
1844 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1845 HOSTAPD_LEVEL_DEBUG,
1846 "did not acknowledge association response");
1850 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1851 sizeof(mgmt->u.assoc_resp))) {
1852 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1853 "(len=%lu)\n", reassoc, (unsigned long) len);
1858 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1860 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1862 sta = ap_get_sta(hapd, mgmt->da);
1864 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1869 if (status != WLAN_STATUS_SUCCESS)
1872 /* Stop previous accounting session, if one is started, and allocate
1873 * new session id for the new session. */
1874 accounting_sta_stop(hapd, sta);
1875 accounting_sta_get_id(hapd, sta);
1877 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1879 "associated (aid %d, accounting session %08X-%08X)",
1880 sta->aid, sta->acct_session_id_hi,
1881 sta->acct_session_id_lo);
1883 if (sta->flags & WLAN_STA_ASSOC)
1885 sta->flags |= WLAN_STA_ASSOC;
1888 mlme_reassociate_indication(hapd, sta);
1890 mlme_associate_indication(hapd, sta);
1892 #ifdef CONFIG_IEEE80211N
1893 if (sta->flags & WLAN_STA_HT)
1894 ht_cap = &sta->ht_capabilities;
1895 #endif /* CONFIG_IEEE80211N */
1897 #ifdef CONFIG_IEEE80211W
1898 sta->ping_timed_out = 0;
1899 #endif /* CONFIG_IEEE80211W */
1901 if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1902 sta->capability, sta->supported_rates,
1903 sta->supported_rates_len, 0, sta->listen_interval,
1906 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1907 HOSTAPD_LEVEL_NOTICE,
1908 "Could not add STA to kernel driver");
1911 if (sta->eapol_sm == NULL) {
1913 * This STA does not use RADIUS server for EAP authentication,
1914 * so bind it to the selected VLAN interface now, since the
1915 * interface selection is not going to change anymore.
1917 ap_sta_bind_vlan(hapd, sta, 0);
1918 } else if (sta->vlan_id) {
1919 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1920 ap_sta_bind_vlan(hapd, sta, 0);
1922 if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1923 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1924 WLAN_STA_SHORT_PREAMBLE, ~0);
1926 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1927 0, ~WLAN_STA_SHORT_PREAMBLE);
1930 if (sta->auth_alg == WLAN_AUTH_FT)
1931 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1933 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1934 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1936 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1939 /* Copy of the association request is not needed anymore */
1940 if (sta->last_assoc_req) {
1941 os_free(sta->last_assoc_req);
1942 sta->last_assoc_req = NULL;
1947 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1950 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1953 case WLAN_FC_STYPE_AUTH:
1954 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1955 handle_auth_cb(hapd, mgmt, len, ok);
1957 case WLAN_FC_STYPE_ASSOC_RESP:
1958 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1959 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1961 case WLAN_FC_STYPE_REASSOC_RESP:
1962 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1963 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1965 case WLAN_FC_STYPE_PROBE_RESP:
1966 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1968 case WLAN_FC_STYPE_DEAUTH:
1971 case WLAN_FC_STYPE_ACTION:
1972 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1975 printf("unknown mgmt cb frame subtype %d\n", stype);
1981 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1984 struct hostapd_data *hapd = eloop_ctx;
1985 hapd->tkip_countermeasures = 0;
1986 hostapd_set_countermeasures(hapd, 0);
1987 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1988 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
1992 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
1994 struct sta_info *sta;
1996 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1997 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
1999 wpa_auth_countermeasures_start(hapd->wpa_auth);
2000 hapd->tkip_countermeasures = 1;
2001 hostapd_set_countermeasures(hapd, 1);
2002 wpa_gtk_rekey(hapd->wpa_auth);
2003 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
2004 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
2006 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
2007 hostapd_sta_deauth(hapd, sta->addr,
2008 WLAN_REASON_MICHAEL_MIC_FAILURE);
2009 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2010 WLAN_STA_AUTHORIZED);
2011 hostapd_sta_remove(hapd, sta->addr);
2016 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
2021 if (addr && local) {
2022 struct sta_info *sta = ap_get_sta(hapd, addr);
2024 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
2025 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
2027 "Michael MIC failure detected in "
2029 mlme_michaelmicfailure_indication(hapd, addr);
2031 wpa_printf(MSG_DEBUG,
2032 "MLME-MICHAELMICFAILURE.indication "
2033 "for not associated STA (" MACSTR
2034 ") ignored", MAC2STR(addr));
2040 if (now > hapd->michael_mic_failure + 60) {
2041 hapd->michael_mic_failures = 1;
2043 hapd->michael_mic_failures++;
2044 if (hapd->michael_mic_failures > 1)
2045 ieee80211_tkip_countermeasures_start(hapd);
2047 hapd->michael_mic_failure = now;
2051 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2058 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2059 char *buf, size_t buflen)
2065 #endif /* CONFIG_NATIVE_WINDOWS */