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 /* Request TX callback */
573 mgmt.frame_control |= host_to_le16(BIT(1));
574 os_memcpy(mgmt.da, hapd->conf->assoc_ap_addr, ETH_ALEN);
575 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
576 os_memcpy(mgmt.bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
577 mgmt.u.auth.auth_alg = host_to_le16(WLAN_AUTH_OPEN);
578 mgmt.u.auth.auth_transaction = host_to_le16(1);
579 mgmt.u.auth.status_code = host_to_le16(0);
580 if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
581 sizeof(mgmt.u.auth), 0) < 0)
582 perror("ieee802_11_sta_authenticate: send");
584 /* Try to authenticate again, if this attempt fails or times out. */
585 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate, hapd, NULL);
589 static void ieee802_11_sta_associate(void *eloop_ctx, void *timeout_ctx)
591 struct hostapd_data *hapd = eloop_ctx;
593 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
597 if (hapd->assoc_ap_state == AUTHENTICATE)
598 hapd->assoc_ap_state = ASSOCIATE;
599 if (hapd->assoc_ap_state != ASSOCIATE)
602 ieee802_11_print_ssid(ssid_txt, (u8 *) hapd->assoc_ap_ssid,
603 hapd->assoc_ap_ssid_len);
604 printf("Associate with AP " MACSTR " SSID=%s (as station)\n",
605 MAC2STR(hapd->conf->assoc_ap_addr), ssid_txt);
607 os_memset(mgmt, 0, sizeof(*mgmt));
608 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
609 WLAN_FC_STYPE_ASSOC_REQ);
610 /* Request TX callback */
611 mgmt->frame_control |= host_to_le16(BIT(1));
612 os_memcpy(mgmt->da, hapd->conf->assoc_ap_addr, ETH_ALEN);
613 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
614 os_memcpy(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN);
615 mgmt->u.assoc_req.capab_info = host_to_le16(0);
616 mgmt->u.assoc_req.listen_interval = host_to_le16(1);
617 p = &mgmt->u.assoc_req.variable[0];
619 *p++ = WLAN_EID_SSID;
620 *p++ = hapd->assoc_ap_ssid_len;
621 os_memcpy(p, hapd->assoc_ap_ssid, hapd->assoc_ap_ssid_len);
622 p += hapd->assoc_ap_ssid_len;
624 p = hostapd_eid_supp_rates(hapd, p);
625 p = hostapd_eid_ext_supp_rates(hapd, p);
627 if (hostapd_send_mgmt_frame(hapd, mgmt, p - (u8 *) mgmt, 0) < 0)
628 perror("ieee802_11_sta_associate: send");
630 /* Try to authenticate again, if this attempt fails or times out. */
631 eloop_register_timeout(5, 0, ieee802_11_sta_associate, hapd, NULL);
635 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
636 u16 auth_transaction, u8 *challenge, int iswep)
638 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
640 "authentication (shared key, transaction %d)",
643 if (auth_transaction == 1) {
644 if (!sta->challenge) {
645 /* Generate a pseudo-random challenge */
649 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
650 if (sta->challenge == NULL)
651 return WLAN_STATUS_UNSPECIFIED_FAILURE;
655 os_memcpy(key, &now, 4);
656 os_memcpy(key + 4, &r, 4);
657 rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
663 if (auth_transaction != 3)
664 return WLAN_STATUS_UNSPECIFIED_FAILURE;
667 if (!iswep || !sta->challenge || !challenge ||
668 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
669 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
671 "shared key authentication - invalid "
672 "challenge-response");
673 return WLAN_STATUS_CHALLENGE_FAIL;
676 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
678 "authentication OK (shared key)");
679 #ifdef IEEE80211_REQUIRE_AUTH_ACK
680 /* Station will be marked authenticated if it ACKs the
681 * authentication reply. */
683 sta->flags |= WLAN_STA_AUTH;
684 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
686 os_free(sta->challenge);
687 sta->challenge = NULL;
693 static void send_auth_reply(struct hostapd_data *hapd,
694 const u8 *dst, const u8 *bssid,
695 u16 auth_alg, u16 auth_transaction, u16 resp,
696 const u8 *ies, size_t ies_len)
698 struct ieee80211_mgmt *reply;
702 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
703 buf = os_zalloc(rlen);
707 reply = (struct ieee80211_mgmt *) buf;
708 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
710 /* Request TX callback */
711 reply->frame_control |= host_to_le16(BIT(1));
712 os_memcpy(reply->da, dst, ETH_ALEN);
713 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
714 os_memcpy(reply->bssid, bssid, ETH_ALEN);
716 reply->u.auth.auth_alg = host_to_le16(auth_alg);
717 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
718 reply->u.auth.status_code = host_to_le16(resp);
721 os_memcpy(reply->u.auth.variable, ies, ies_len);
723 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
724 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
725 MAC2STR(dst), auth_alg, auth_transaction,
726 resp, (unsigned long) ies_len);
727 if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
728 perror("send_auth_reply: send");
734 #ifdef CONFIG_IEEE80211R
735 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
736 u16 auth_transaction, u16 status,
737 const u8 *ies, size_t ies_len)
739 struct hostapd_data *hapd = ctx;
740 struct sta_info *sta;
742 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
743 status, ies, ies_len);
745 if (status != WLAN_STATUS_SUCCESS)
748 sta = ap_get_sta(hapd, dst);
752 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
753 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
754 sta->flags |= WLAN_STA_AUTH;
755 mlme_authenticate_indication(hapd, sta);
757 #endif /* CONFIG_IEEE80211R */
760 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
763 u16 auth_alg, auth_transaction, status_code;
764 u16 resp = WLAN_STATUS_SUCCESS;
765 struct sta_info *sta = NULL;
768 u8 *challenge = NULL;
769 u32 session_timeout, acct_interim_interval;
771 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
772 size_t resp_ies_len = 0;
774 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
775 printf("handle_auth - too short payload (len=%lu)\n",
776 (unsigned long) len);
780 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
781 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
782 status_code = le_to_host16(mgmt->u.auth.status_code);
783 fc = le_to_host16(mgmt->frame_control);
785 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
786 2 + WLAN_AUTH_CHALLENGE_LEN &&
787 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
788 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
789 challenge = &mgmt->u.auth.variable[2];
791 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
792 "auth_transaction=%d status_code=%d wep=%d%s",
793 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
794 status_code, !!(fc & WLAN_FC_ISWEP),
795 challenge ? " challenge" : "");
797 if (hapd->assoc_ap_state == AUTHENTICATE && auth_transaction == 2 &&
798 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0 &&
799 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
800 if (status_code != 0) {
801 printf("Authentication (as station) with AP "
802 MACSTR " failed (status_code=%d)\n",
803 MAC2STR(hapd->conf->assoc_ap_addr),
807 printf("Authenticated (as station) with AP " MACSTR "\n",
808 MAC2STR(hapd->conf->assoc_ap_addr));
809 ieee802_11_sta_associate(hapd, NULL);
813 if (hapd->tkip_countermeasures) {
814 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
818 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
819 auth_alg == WLAN_AUTH_OPEN) ||
820 #ifdef CONFIG_IEEE80211R
822 (hapd->conf->wpa_key_mgmt &
823 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
824 auth_alg == WLAN_AUTH_FT) ||
825 #endif /* CONFIG_IEEE80211R */
826 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
827 auth_alg == WLAN_AUTH_SHARED_KEY))) {
828 printf("Unsupported authentication algorithm (%d)\n",
830 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
834 if (!(auth_transaction == 1 ||
835 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
836 printf("Unknown authentication transaction number (%d)\n",
838 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
842 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
843 printf("Station " MACSTR " not allowed to authenticate.\n",
845 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
849 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
851 &acct_interim_interval, &vlan_id);
852 if (res == HOSTAPD_ACL_REJECT) {
853 printf("Station " MACSTR " not allowed to authenticate.\n",
855 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
858 if (res == HOSTAPD_ACL_PENDING) {
859 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
860 " waiting for an external authentication",
862 /* Authentication code will re-send the authentication frame
863 * after it has received (and cached) information from the
864 * external source. */
868 sta = ap_sta_add(hapd, mgmt->sa);
870 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
875 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
876 sta->vlan_id) == NULL) {
877 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
878 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
879 "%d received from RADIUS server",
881 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
884 sta->vlan_id = vlan_id;
885 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
886 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
889 sta->flags &= ~WLAN_STA_PREAUTH;
890 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
892 if (hapd->conf->radius->acct_interim_interval == 0 &&
893 acct_interim_interval)
894 sta->acct_interim_interval = acct_interim_interval;
895 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
896 ap_sta_session_timeout(hapd, sta, session_timeout);
898 ap_sta_no_session_timeout(hapd, sta);
902 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
904 "authentication OK (open system)");
905 #ifdef IEEE80211_REQUIRE_AUTH_ACK
906 /* Station will be marked authenticated if it ACKs the
907 * authentication reply. */
909 sta->flags |= WLAN_STA_AUTH;
910 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
911 sta->auth_alg = WLAN_AUTH_OPEN;
912 mlme_authenticate_indication(hapd, sta);
915 case WLAN_AUTH_SHARED_KEY:
916 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
918 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
919 mlme_authenticate_indication(hapd, sta);
920 if (sta->challenge && auth_transaction == 1) {
921 resp_ies[0] = WLAN_EID_CHALLENGE;
922 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
923 os_memcpy(resp_ies + 2, sta->challenge,
924 WLAN_AUTH_CHALLENGE_LEN);
925 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
928 #ifdef CONFIG_IEEE80211R
930 sta->auth_alg = WLAN_AUTH_FT;
931 if (sta->wpa_sm == NULL)
932 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
934 if (sta->wpa_sm == NULL) {
935 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
937 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
940 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
941 auth_transaction, mgmt->u.auth.variable,
942 len - IEEE80211_HDRLEN -
943 sizeof(mgmt->u.auth),
944 handle_auth_ft_finish, hapd);
945 /* handle_auth_ft_finish() callback will complete auth. */
947 #endif /* CONFIG_IEEE80211R */
951 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
952 auth_transaction + 1, resp, resp_ies, resp_ies_len);
956 static void handle_assoc(struct hostapd_data *hapd,
957 struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
959 u16 capab_info, listen_interval;
960 u16 resp = WLAN_STATUS_SUCCESS;
963 int send_deauth = 0, send_len, left, i;
964 struct sta_info *sta;
965 struct ieee802_11_elems elems;
966 u8 buf[sizeof(struct ieee80211_mgmt) + 512];
967 struct ieee80211_mgmt *reply;
969 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
970 sizeof(mgmt->u.assoc_req))) {
971 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
972 "\n", reassoc, (unsigned long) len);
977 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
978 listen_interval = le_to_host16(
979 mgmt->u.reassoc_req.listen_interval);
980 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
981 " capab_info=0x%02x listen_interval=%d current_ap="
983 MAC2STR(mgmt->sa), capab_info, listen_interval,
984 MAC2STR(mgmt->u.reassoc_req.current_ap));
985 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
986 pos = mgmt->u.reassoc_req.variable;
988 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
989 listen_interval = le_to_host16(
990 mgmt->u.assoc_req.listen_interval);
991 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
992 " capab_info=0x%02x listen_interval=%d",
993 MAC2STR(mgmt->sa), capab_info, listen_interval);
994 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
995 pos = mgmt->u.assoc_req.variable;
998 sta = ap_get_sta(hapd, mgmt->sa);
999 #ifdef CONFIG_IEEE80211R
1000 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1001 (sta->flags & WLAN_STA_AUTH) == 0) {
1002 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1003 "prior to authentication since it is using "
1004 "over-the-DS FT", MAC2STR(mgmt->sa));
1006 #endif /* CONFIG_IEEE80211R */
1007 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1008 printf("STA " MACSTR " trying to associate before "
1009 "authentication\n", MAC2STR(mgmt->sa));
1011 printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
1012 MAC2STR(sta->addr), sta->aid, sta->flags);
1015 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1019 if (hapd->tkip_countermeasures) {
1020 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1024 if (listen_interval > hapd->conf->max_listen_interval) {
1025 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1026 HOSTAPD_LEVEL_DEBUG,
1027 "Too large Listen Interval (%d)",
1029 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1033 sta->capability = capab_info;
1035 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1037 if (ieee802_11_parse_elems(hapd, pos, left, &elems, 1) == ParseFailed
1039 printf("STA " MACSTR " sent invalid association request\n",
1040 MAC2STR(sta->addr));
1041 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1045 if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
1046 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
1049 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
1050 printf("Station " MACSTR " tried to associate with "
1051 "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
1052 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1056 sta->flags &= ~WLAN_STA_WME;
1057 if (elems.wme && hapd->conf->wme_enabled) {
1058 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
1059 hostapd_logger(hapd, sta->addr,
1061 HOSTAPD_LEVEL_DEBUG,
1062 "invalid WME element in association "
1065 sta->flags |= WLAN_STA_WME;
1068 if (!elems.supp_rates) {
1069 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1070 HOSTAPD_LEVEL_DEBUG,
1071 "No supported rates element in AssocReq");
1072 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1076 if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
1077 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1078 HOSTAPD_LEVEL_DEBUG,
1079 "Invalid supported rates element length %d",
1080 elems.supp_rates_len);
1081 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1085 os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
1086 os_memcpy(sta->supported_rates, elems.supp_rates,
1087 elems.supp_rates_len);
1088 sta->supported_rates_len = elems.supp_rates_len;
1090 if (elems.ext_supp_rates) {
1091 if (elems.supp_rates_len + elems.ext_supp_rates_len >
1092 sizeof(sta->supported_rates)) {
1093 hostapd_logger(hapd, mgmt->sa,
1094 HOSTAPD_MODULE_IEEE80211,
1095 HOSTAPD_LEVEL_DEBUG,
1096 "Invalid supported rates element length"
1097 " %d+%d", elems.supp_rates_len,
1098 elems.ext_supp_rates_len);
1099 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1103 os_memcpy(sta->supported_rates + elems.supp_rates_len,
1104 elems.ext_supp_rates, elems.ext_supp_rates_len);
1105 sta->supported_rates_len += elems.ext_supp_rates_len;
1108 #ifdef CONFIG_IEEE80211N
1109 /* save HT capabilities in the sta object */
1110 os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
1111 if (elems.ht_capabilities &&
1112 elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
1113 && (sta->flags & WLAN_STA_WME)) {
1114 /* note: without WMM capability, treat the sta as non-HT */
1115 sta->flags |= WLAN_STA_HT;
1116 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
1117 sta->ht_capabilities.length =
1118 sizeof(struct ieee80211_ht_capability);
1119 os_memcpy(&sta->ht_capabilities.data,
1120 elems.ht_capabilities,
1121 sizeof(struct ieee80211_ht_capability));
1123 sta->flags &= ~WLAN_STA_HT;
1124 #endif /* CONFIG_IEEE80211N */
1126 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1127 wpa_ie = elems.rsn_ie;
1128 wpa_ie_len = elems.rsn_ie_len;
1129 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1131 wpa_ie = elems.wpa_ie;
1132 wpa_ie_len = elems.wpa_ie_len;
1137 if (hapd->conf->wpa && wpa_ie == NULL) {
1138 printf("STA " MACSTR ": No WPA/RSN IE in association "
1139 "request\n", MAC2STR(sta->addr));
1140 resp = WLAN_STATUS_INVALID_IE;
1144 if (hapd->conf->wpa && wpa_ie) {
1148 if (sta->wpa_sm == NULL)
1149 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1151 if (sta->wpa_sm == NULL) {
1152 printf("Failed to initialize WPA state machine\n");
1153 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1156 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1158 elems.mdie, elems.mdie_len);
1159 if (res == WPA_INVALID_GROUP)
1160 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1161 else if (res == WPA_INVALID_PAIRWISE)
1162 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1163 else if (res == WPA_INVALID_AKMP)
1164 resp = WLAN_STATUS_AKMP_NOT_VALID;
1165 else if (res == WPA_ALLOC_FAIL)
1166 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1167 #ifdef CONFIG_IEEE80211W
1168 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1169 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1170 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1171 resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
1172 #endif /* CONFIG_IEEE80211W */
1173 else if (res == WPA_INVALID_MDIE)
1174 resp = WLAN_STATUS_INVALID_MDIE;
1175 else if (res != WPA_IE_OK)
1176 resp = WLAN_STATUS_INVALID_IE;
1177 if (resp != WLAN_STATUS_SUCCESS)
1179 #ifdef CONFIG_IEEE80211W
1180 if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
1182 * STA has already been associated with MFP and ping
1183 * timeout has not been reached. Reject the
1184 * association attempt temporarily and start ping, if
1185 * one is not pending.
1188 if (sta->ping_count == 0)
1189 ap_sta_start_ping(hapd, sta);
1191 resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1195 if (wpa_auth_uses_mfp(sta->wpa_sm))
1196 sta->flags |= WLAN_STA_MFP;
1198 sta->flags &= ~WLAN_STA_MFP;
1199 #endif /* CONFIG_IEEE80211W */
1201 #ifdef CONFIG_IEEE80211R
1202 if (sta->auth_alg == WLAN_AUTH_FT) {
1204 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1205 "to use association (not "
1206 "re-association) with FT auth_alg",
1207 MAC2STR(sta->addr));
1208 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1212 resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
1213 if (resp != WLAN_STATUS_SUCCESS)
1216 #endif /* CONFIG_IEEE80211R */
1219 if (hapd->iface->dfs_enable &&
1220 hapd->iconf->ieee80211h == SPECT_STRICT_BINDING) {
1221 if (hostapd_check_power_cap(hapd, elems.power_cap,
1222 elems.power_cap_len)) {
1223 resp = WLAN_STATUS_PWR_CAPABILITY_NOT_VALID;
1224 hostapd_logger(hapd, sta->addr,
1225 HOSTAPD_MODULE_IEEE80211,
1226 HOSTAPD_LEVEL_DEBUG,
1227 "Power capabilities of the station not "
1233 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1234 sta->flags |= WLAN_STA_NONERP;
1235 for (i = 0; i < sta->supported_rates_len; i++) {
1236 if ((sta->supported_rates[i] & 0x7f) > 22) {
1237 sta->flags &= ~WLAN_STA_NONERP;
1241 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1242 sta->nonerp_set = 1;
1243 hapd->iface->num_sta_non_erp++;
1244 if (hapd->iface->num_sta_non_erp == 1)
1245 ieee802_11_set_beacons(hapd->iface);
1248 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1249 !sta->no_short_slot_time_set) {
1250 sta->no_short_slot_time_set = 1;
1251 hapd->iface->num_sta_no_short_slot_time++;
1252 if (hapd->iface->current_mode->mode ==
1253 HOSTAPD_MODE_IEEE80211G &&
1254 hapd->iface->num_sta_no_short_slot_time == 1)
1255 ieee802_11_set_beacons(hapd->iface);
1258 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1259 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1261 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1263 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1264 !sta->no_short_preamble_set) {
1265 sta->no_short_preamble_set = 1;
1266 hapd->iface->num_sta_no_short_preamble++;
1267 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1268 && hapd->iface->num_sta_no_short_preamble == 1)
1269 ieee802_11_set_beacons(hapd->iface);
1272 #ifdef CONFIG_IEEE80211N
1273 if (sta->flags & WLAN_STA_HT) {
1274 if ((sta->ht_capabilities.data.capabilities_info &
1275 HT_CAP_INFO_GREEN_FIELD) == 0) {
1276 hapd->iface->num_sta_ht_no_gf++;
1277 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
1278 "greenfield, num of non-gf stations %d",
1279 __func__, MAC2STR(sta->addr),
1280 hapd->iface->num_sta_ht_no_gf);
1282 if ((sta->ht_capabilities.data.capabilities_info &
1283 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
1284 hapd->iface->num_sta_ht_20mhz++;
1285 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
1286 "num of 20MHz HT STAs %d",
1287 __func__, MAC2STR(sta->addr),
1288 hapd->iface->num_sta_ht_20mhz);
1291 hapd->iface->num_sta_no_ht++;
1292 if (hapd->iconf->ieee80211n) {
1293 wpa_printf(MSG_DEBUG, "%s STA " MACSTR
1294 " - no HT, num of non-HT stations %d",
1295 __func__, MAC2STR(sta->addr),
1296 hapd->iface->num_sta_no_ht);
1300 if (hostapd_ht_operation_update(hapd->iface) > 0)
1301 ieee802_11_set_beacons(hapd->iface);
1302 #endif /* CONFIG_IEEE80211N */
1304 /* get a unique AID */
1306 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1308 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1309 if (hapd->sta_aid[sta->aid - 1] == NULL)
1311 if (sta->aid > MAX_AID_TABLE_SIZE) {
1313 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1314 wpa_printf(MSG_ERROR, " no room for more AIDs");
1317 hapd->sta_aid[sta->aid - 1] = sta;
1318 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1322 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1323 HOSTAPD_LEVEL_DEBUG,
1324 "association OK (aid %d)", sta->aid);
1325 /* Station will be marked associated, after it acknowledges AssocResp
1329 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1333 if (sta->last_assoc_req)
1334 os_free(sta->last_assoc_req);
1335 sta->last_assoc_req = os_malloc(len);
1336 if (sta->last_assoc_req)
1337 os_memcpy(sta->last_assoc_req, mgmt, len);
1339 /* Make sure that the previously registered inactivity timer will not
1340 * remove the STA immediately. */
1341 sta->timeout_next = STA_NULLFUNC;
1344 os_memset(buf, 0, sizeof(buf));
1345 reply = (struct ieee80211_mgmt *) buf;
1346 reply->frame_control =
1347 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1348 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1349 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1350 WLAN_FC_STYPE_ASSOC_RESP)));
1351 os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1352 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1353 os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1355 send_len = IEEE80211_HDRLEN;
1357 send_len += sizeof(reply->u.deauth);
1358 reply->u.deauth.reason_code = host_to_le16(resp);
1361 send_len += sizeof(reply->u.assoc_resp);
1362 reply->u.assoc_resp.capab_info =
1363 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1364 reply->u.assoc_resp.status_code = host_to_le16(resp);
1365 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1366 | BIT(14) | BIT(15));
1367 /* Supported rates */
1368 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1369 /* Extended supported rates */
1370 p = hostapd_eid_ext_supp_rates(hapd, p);
1371 if (sta->flags & WLAN_STA_WME)
1372 p = hostapd_eid_wme(hapd, p);
1374 p = hostapd_eid_ht_capabilities_info(hapd, p);
1375 p = hostapd_eid_ht_operation(hapd, p);
1377 #ifdef CONFIG_IEEE80211R
1378 if (resp == WLAN_STATUS_SUCCESS) {
1379 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1380 * Transition Information, RSN */
1381 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1382 buf + sizeof(buf) - p,
1385 #endif /* CONFIG_IEEE80211R */
1387 #ifdef CONFIG_IEEE80211W
1388 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1389 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1390 #endif /* CONFIG_IEEE80211W */
1392 send_len += p - reply->u.assoc_resp.variable;
1394 /* Request TX callback */
1395 reply->frame_control |= host_to_le16(BIT(1));
1398 if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1399 perror("handle_assoc: send");
1403 static void handle_assoc_resp(struct hostapd_data *hapd,
1404 struct ieee80211_mgmt *mgmt, size_t len)
1406 u16 status_code, aid;
1408 if (hapd->assoc_ap_state != ASSOCIATE) {
1409 printf("Unexpected association response received from " MACSTR
1410 "\n", MAC2STR(mgmt->sa));
1414 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_resp)) {
1415 printf("handle_assoc_resp - too short payload (len=%lu)\n",
1416 (unsigned long) len);
1420 if (os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0 ||
1421 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0) {
1422 printf("Received association response from unexpected address "
1423 "(SA=" MACSTR " BSSID=" MACSTR "\n",
1424 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
1428 status_code = le_to_host16(mgmt->u.assoc_resp.status_code);
1429 aid = le_to_host16(mgmt->u.assoc_resp.aid);
1430 aid &= ~(BIT(14) | BIT(15));
1432 if (status_code != 0) {
1433 printf("Association (as station) with AP " MACSTR " failed "
1434 "(status_code=%d)\n",
1435 MAC2STR(hapd->conf->assoc_ap_addr), status_code);
1436 /* Try to authenticate again */
1437 hapd->assoc_ap_state = AUTHENTICATE;
1438 eloop_register_timeout(5, 0, ieee802_11_sta_authenticate,
1442 printf("Associated (as station) with AP " MACSTR " (aid=%d)\n",
1443 MAC2STR(hapd->conf->assoc_ap_addr), aid);
1444 hapd->assoc_ap_aid = aid;
1445 hapd->assoc_ap_state = ASSOCIATED;
1447 if (hostapd_set_assoc_ap(hapd, hapd->conf->assoc_ap_addr)) {
1448 printf("Could not set associated AP address to kernel "
1454 static void handle_disassoc(struct hostapd_data *hapd,
1455 struct ieee80211_mgmt *mgmt, size_t len)
1457 struct sta_info *sta;
1459 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1460 printf("handle_disassoc - too short payload (len=%lu)\n",
1461 (unsigned long) len);
1465 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1467 le_to_host16(mgmt->u.disassoc.reason_code));
1469 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1470 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1471 printf("Assoc AP " MACSTR " sent disassociation "
1472 "(reason_code=%d) - try to authenticate\n",
1473 MAC2STR(hapd->conf->assoc_ap_addr),
1474 le_to_host16(mgmt->u.disassoc.reason_code));
1475 hapd->assoc_ap_state = AUTHENTICATE;
1476 ieee802_11_sta_authenticate(hapd, NULL);
1477 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1482 sta = ap_get_sta(hapd, mgmt->sa);
1484 printf("Station " MACSTR " trying to disassociate, but it "
1485 "is not associated.\n", MAC2STR(mgmt->sa));
1489 sta->flags &= ~WLAN_STA_ASSOC;
1490 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1491 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1492 HOSTAPD_LEVEL_INFO, "disassociated");
1493 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1494 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1495 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1497 accounting_sta_stop(hapd, sta);
1498 ieee802_1x_free_station(sta);
1499 hostapd_sta_remove(hapd, sta->addr);
1501 if (sta->timeout_next == STA_NULLFUNC ||
1502 sta->timeout_next == STA_DISASSOC) {
1503 sta->timeout_next = STA_DEAUTH;
1504 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1505 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1509 mlme_disassociate_indication(
1510 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1514 static void handle_deauth(struct hostapd_data *hapd,
1515 struct ieee80211_mgmt *mgmt, size_t len)
1517 struct sta_info *sta;
1519 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1520 printf("handle_deauth - too short payload (len=%lu)\n",
1521 (unsigned long) len);
1525 wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1528 le_to_host16(mgmt->u.deauth.reason_code));
1530 if (hapd->assoc_ap_state != DO_NOT_ASSOC &&
1531 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1532 printf("Assoc AP " MACSTR " sent deauthentication "
1533 "(reason_code=%d) - try to authenticate\n",
1534 MAC2STR(hapd->conf->assoc_ap_addr),
1535 le_to_host16(mgmt->u.deauth.reason_code));
1536 hapd->assoc_ap_state = AUTHENTICATE;
1537 eloop_register_timeout(0, 500000, ieee802_11_sta_authenticate,
1542 sta = ap_get_sta(hapd, mgmt->sa);
1544 printf("Station " MACSTR " trying to deauthenticate, but it "
1545 "is not authenticated.\n", MAC2STR(mgmt->sa));
1549 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1550 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1552 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1553 mlme_deauthenticate_indication(
1554 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1555 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1556 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1557 ap_free_sta(hapd, sta);
1561 static void handle_beacon(struct hostapd_data *hapd,
1562 struct ieee80211_mgmt *mgmt, size_t len,
1563 struct hostapd_frame_info *fi)
1565 struct ieee802_11_elems elems;
1567 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1568 printf("handle_beacon - too short payload (len=%lu)\n",
1569 (unsigned long) len);
1573 (void) ieee802_11_parse_elems(hapd, mgmt->u.beacon.variable,
1574 len - (IEEE80211_HDRLEN +
1575 sizeof(mgmt->u.beacon)), &elems,
1578 if (hapd->assoc_ap_state == WAIT_BEACON &&
1579 os_memcmp(mgmt->sa, hapd->conf->assoc_ap_addr, ETH_ALEN) == 0) {
1580 if (elems.ssid && elems.ssid_len <= 32) {
1581 os_memcpy(hapd->assoc_ap_ssid, elems.ssid,
1583 hapd->assoc_ap_ssid[elems.ssid_len] = '\0';
1584 hapd->assoc_ap_ssid_len = elems.ssid_len;
1586 ieee802_11_sta_authenticate(hapd, NULL);
1589 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1593 #ifdef CONFIG_IEEE80211W
1594 static void hostapd_ping_action(struct hostapd_data *hapd,
1595 struct ieee80211_mgmt *mgmt, size_t len)
1597 struct sta_info *sta;
1601 end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
1602 if (((u8 *) mgmt) + len < end) {
1603 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
1604 "frame (len=%lu)", (unsigned long) len);
1608 if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
1609 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
1610 mgmt->u.action.u.ping_resp.action);
1614 /* MLME-PING.confirm */
1616 sta = ap_get_sta(hapd, mgmt->sa);
1617 if (sta == NULL || sta->ping_trans_id == NULL) {
1618 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1619 "pending ping request found");
1623 for (i = 0; i < sta->ping_count; i++) {
1624 if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
1625 mgmt->u.action.u.ping_resp.trans_id,
1626 WLAN_PING_TRANS_ID_LEN) == 0)
1630 if (i >= sta->ping_count) {
1631 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
1632 "transaction identifier found");
1636 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1637 HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
1638 ap_sta_stop_ping(hapd, sta);
1640 #endif /* CONFIG_IEEE80211W */
1643 static void handle_action(struct hostapd_data *hapd,
1644 struct ieee80211_mgmt *mgmt, size_t len)
1646 if (len < IEEE80211_HDRLEN + 1) {
1647 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1648 HOSTAPD_LEVEL_DEBUG,
1649 "handle_action - too short payload (len=%lu)",
1650 (unsigned long) len);
1654 switch (mgmt->u.action.category) {
1655 #ifdef CONFIG_IEEE80211R
1656 case WLAN_ACTION_FT:
1658 struct sta_info *sta;
1660 sta = ap_get_sta(hapd, mgmt->sa);
1661 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1662 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1663 "frame from unassociated STA " MACSTR,
1668 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1669 len - IEEE80211_HDRLEN))
1674 #endif /* CONFIG_IEEE80211R */
1675 case WME_ACTION_CATEGORY:
1676 hostapd_wme_action(hapd, mgmt, len);
1678 #ifdef CONFIG_IEEE80211W
1679 case WLAN_ACTION_PING:
1680 hostapd_ping_action(hapd, mgmt, len);
1682 #endif /* CONFIG_IEEE80211W */
1685 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1686 HOSTAPD_LEVEL_DEBUG,
1687 "handle_action - unknown action category %d or invalid "
1689 mgmt->u.action.category);
1690 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1691 !(mgmt->sa[0] & 0x01)) {
1693 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1694 * Return the Action frame to the source without change
1695 * except that MSB of the Category set to 1.
1697 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1698 "frame back to sender");
1699 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1700 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1701 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1702 mgmt->u.action.category |= 0x80;
1704 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1710 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1711 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1713 * @buf: management frame data (starting from IEEE 802.11 header)
1714 * @len: length of frame data in octets
1715 * @stype: management frame subtype from frame control field
1717 * Process all incoming IEEE 802.11 management frames. This will be called for
1718 * each frame received from the kernel driver through wlan#ap interface. In
1719 * addition, it can be called to re-inserted pending frames (e.g., when using
1720 * external RADIUS server as an MAC ACL).
1722 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1723 struct hostapd_frame_info *fi)
1725 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1728 if (stype == WLAN_FC_STYPE_BEACON) {
1729 handle_beacon(hapd, mgmt, len, fi);
1733 if (fi && fi->passive_scan)
1736 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1737 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1738 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1741 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0 &&
1742 (hapd->assoc_ap_state == DO_NOT_ASSOC ||
1743 os_memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0))
1745 printf("MGMT: BSSID=" MACSTR " not our address\n",
1746 MAC2STR(mgmt->bssid));
1751 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1752 handle_probe_req(hapd, mgmt, len);
1756 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1757 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1758 HOSTAPD_LEVEL_DEBUG,
1759 "MGMT: DA=" MACSTR " not our address",
1765 case WLAN_FC_STYPE_AUTH:
1766 wpa_printf(MSG_DEBUG, "mgmt::auth");
1767 handle_auth(hapd, mgmt, len);
1769 case WLAN_FC_STYPE_ASSOC_REQ:
1770 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1771 handle_assoc(hapd, mgmt, len, 0);
1773 case WLAN_FC_STYPE_ASSOC_RESP:
1774 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp");
1775 handle_assoc_resp(hapd, mgmt, len);
1777 case WLAN_FC_STYPE_REASSOC_REQ:
1778 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1779 handle_assoc(hapd, mgmt, len, 1);
1781 case WLAN_FC_STYPE_DISASSOC:
1782 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1783 handle_disassoc(hapd, mgmt, len);
1785 case WLAN_FC_STYPE_DEAUTH:
1786 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1787 handle_deauth(hapd, mgmt, len);
1789 case WLAN_FC_STYPE_ACTION:
1790 wpa_printf(MSG_DEBUG, "mgmt::action");
1791 handle_action(hapd, mgmt, len);
1794 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1795 HOSTAPD_LEVEL_DEBUG,
1796 "unknown mgmt frame subtype %d", stype);
1802 static void handle_auth_cb(struct hostapd_data *hapd,
1803 struct ieee80211_mgmt *mgmt,
1806 u16 auth_alg, auth_transaction, status_code;
1807 struct sta_info *sta;
1810 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1811 HOSTAPD_LEVEL_NOTICE,
1812 "did not acknowledge authentication response");
1816 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1817 printf("handle_auth_cb - too short payload (len=%lu)\n",
1818 (unsigned long) len);
1822 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1823 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1824 status_code = le_to_host16(mgmt->u.auth.status_code);
1826 sta = ap_get_sta(hapd, mgmt->da);
1828 printf("handle_auth_cb: STA " MACSTR " not found\n",
1833 if (status_code == WLAN_STATUS_SUCCESS &&
1834 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1835 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1836 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1837 HOSTAPD_LEVEL_INFO, "authenticated");
1838 sta->flags |= WLAN_STA_AUTH;
1843 static void handle_assoc_cb(struct hostapd_data *hapd,
1844 struct ieee80211_mgmt *mgmt,
1845 size_t len, int reassoc, int ok)
1848 struct sta_info *sta;
1850 struct ht_cap_ie *ht_cap = NULL;
1853 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1854 HOSTAPD_LEVEL_DEBUG,
1855 "did not acknowledge association response");
1859 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1860 sizeof(mgmt->u.assoc_resp))) {
1861 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1862 "(len=%lu)\n", reassoc, (unsigned long) len);
1867 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1869 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1871 sta = ap_get_sta(hapd, mgmt->da);
1873 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1878 if (status != WLAN_STATUS_SUCCESS)
1881 /* Stop previous accounting session, if one is started, and allocate
1882 * new session id for the new session. */
1883 accounting_sta_stop(hapd, sta);
1884 accounting_sta_get_id(hapd, sta);
1886 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1888 "associated (aid %d, accounting session %08X-%08X)",
1889 sta->aid, sta->acct_session_id_hi,
1890 sta->acct_session_id_lo);
1892 if (sta->flags & WLAN_STA_ASSOC)
1894 sta->flags |= WLAN_STA_ASSOC;
1897 mlme_reassociate_indication(hapd, sta);
1899 mlme_associate_indication(hapd, sta);
1901 #ifdef CONFIG_IEEE80211N
1902 if (sta->flags & WLAN_STA_HT)
1903 ht_cap = &sta->ht_capabilities;
1904 #endif /* CONFIG_IEEE80211N */
1906 #ifdef CONFIG_IEEE80211W
1907 sta->ping_timed_out = 0;
1908 #endif /* CONFIG_IEEE80211W */
1910 if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1911 sta->capability, sta->supported_rates,
1912 sta->supported_rates_len, 0, sta->listen_interval,
1915 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1916 HOSTAPD_LEVEL_NOTICE,
1917 "Could not add STA to kernel driver");
1920 if (sta->eapol_sm == NULL) {
1922 * This STA does not use RADIUS server for EAP authentication,
1923 * so bind it to the selected VLAN interface now, since the
1924 * interface selection is not going to change anymore.
1926 ap_sta_bind_vlan(hapd, sta, 0);
1927 } else if (sta->vlan_id) {
1928 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1929 ap_sta_bind_vlan(hapd, sta, 0);
1931 if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1932 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1933 WLAN_STA_SHORT_PREAMBLE, ~0);
1935 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1936 0, ~WLAN_STA_SHORT_PREAMBLE);
1939 if (sta->auth_alg == WLAN_AUTH_FT)
1940 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1942 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1943 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1945 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1948 /* Copy of the association request is not needed anymore */
1949 if (sta->last_assoc_req) {
1950 os_free(sta->last_assoc_req);
1951 sta->last_assoc_req = NULL;
1956 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1959 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1962 case WLAN_FC_STYPE_AUTH:
1963 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1964 handle_auth_cb(hapd, mgmt, len, ok);
1966 case WLAN_FC_STYPE_ASSOC_RESP:
1967 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1968 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1970 case WLAN_FC_STYPE_REASSOC_RESP:
1971 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1972 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1974 case WLAN_FC_STYPE_PROBE_RESP:
1975 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1977 case WLAN_FC_STYPE_DEAUTH:
1980 case WLAN_FC_STYPE_ACTION:
1981 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1984 printf("unknown mgmt cb frame subtype %d\n", stype);
1990 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1993 struct hostapd_data *hapd = eloop_ctx;
1994 hapd->tkip_countermeasures = 0;
1995 hostapd_set_countermeasures(hapd, 0);
1996 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1997 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
2001 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
2003 struct sta_info *sta;
2005 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
2006 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
2008 wpa_auth_countermeasures_start(hapd->wpa_auth);
2009 hapd->tkip_countermeasures = 1;
2010 hostapd_set_countermeasures(hapd, 1);
2011 wpa_gtk_rekey(hapd->wpa_auth);
2012 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
2013 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
2015 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
2016 hostapd_sta_deauth(hapd, sta->addr,
2017 WLAN_REASON_MICHAEL_MIC_FAILURE);
2018 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2019 WLAN_STA_AUTHORIZED);
2020 hostapd_sta_remove(hapd, sta->addr);
2025 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
2030 if (addr && local) {
2031 struct sta_info *sta = ap_get_sta(hapd, addr);
2033 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
2034 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
2036 "Michael MIC failure detected in "
2038 mlme_michaelmicfailure_indication(hapd, addr);
2040 wpa_printf(MSG_DEBUG,
2041 "MLME-MICHAELMICFAILURE.indication "
2042 "for not associated STA (" MACSTR
2043 ") ignored", MAC2STR(addr));
2049 if (now > hapd->michael_mic_failure + 60) {
2050 hapd->michael_mic_failures = 1;
2052 hapd->michael_mic_failures++;
2053 if (hapd->michael_mic_failures > 1)
2054 ieee80211_tkip_countermeasures_start(hapd);
2056 hapd->michael_mic_failure = now;
2060 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2067 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2068 char *buf, size_t buflen)
2074 #endif /* CONFIG_NATIVE_WINDOWS */