2 * hostapd / IEEE 802.1X-2004 Authenticator
3 * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "crypto/md5.h"
20 #include "crypto/crypto.h"
21 #include "crypto/random.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/wpa_ctrl.h"
24 #include "radius/radius.h"
25 #include "radius/radius_client.h"
26 #include "eap_server/eap.h"
27 #include "eap_common/eap_wsc_common.h"
28 #include "eapol_auth/eapol_auth_sm.h"
29 #include "eapol_auth/eapol_auth_sm_i.h"
31 #include "accounting.h"
34 #include "preauth_auth.h"
35 #include "pmksa_cache_auth.h"
36 #include "ap_config.h"
37 #include "ap_drv_ops.h"
38 #include "ieee802_1x.h"
41 static void ieee802_1x_finished(struct hostapd_data *hapd,
42 struct sta_info *sta, int success);
45 static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
46 u8 type, const u8 *data, size_t datalen)
49 struct ieee802_1x_hdr *xhdr;
53 len = sizeof(*xhdr) + datalen;
56 wpa_printf(MSG_ERROR, "malloc() failed for "
57 "ieee802_1x_send(len=%lu)",
62 xhdr = (struct ieee802_1x_hdr *) buf;
63 xhdr->version = hapd->conf->eapol_version;
65 xhdr->length = host_to_be16(datalen);
67 if (datalen > 0 && data != NULL)
68 os_memcpy(xhdr + 1, data, datalen);
70 if (wpa_auth_pairwise_set(sta->wpa_sm))
72 if (sta->flags & WLAN_STA_PREAUTH) {
73 rsn_preauth_send(hapd, sta, buf, len);
75 hostapd_drv_hapd_send_eapol(hapd, sta->addr, buf, len,
83 void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
84 struct sta_info *sta, int authorized)
88 if (sta->flags & WLAN_STA_PREAUTH)
92 if (!ap_sta_is_authorized(sta))
93 wpa_msg(hapd->msg_ctx, MSG_INFO,
94 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
95 ap_sta_set_authorized(hapd, sta, 1);
96 res = hostapd_set_authorized(hapd, sta, 1);
97 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
98 HOSTAPD_LEVEL_DEBUG, "authorizing port");
100 if (ap_sta_is_authorized(sta) && (sta->flags & WLAN_STA_ASSOC))
101 wpa_msg(hapd->msg_ctx, MSG_INFO,
102 AP_STA_DISCONNECTED MACSTR,
104 ap_sta_set_authorized(hapd, sta, 0);
105 res = hostapd_set_authorized(hapd, sta, 0);
106 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
107 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
110 if (res && errno != ENOENT) {
111 printf("Could not set station " MACSTR " flags for kernel "
112 "driver (errno=%d).\n", MAC2STR(sta->addr), errno);
116 accounting_sta_start(hapd, sta);
120 static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
121 struct sta_info *sta,
122 int idx, int broadcast,
123 u8 *key_data, size_t key_len)
126 struct ieee802_1x_hdr *hdr;
127 struct ieee802_1x_eapol_key *key;
128 size_t len, ekey_len;
129 struct eapol_state_machine *sm = sta->eapol_sm;
134 len = sizeof(*key) + key_len;
135 buf = os_zalloc(sizeof(*hdr) + len);
139 hdr = (struct ieee802_1x_hdr *) buf;
140 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
141 key->type = EAPOL_KEY_TYPE_RC4;
142 key->key_length = htons(key_len);
143 wpa_get_ntp_timestamp(key->replay_counter);
145 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
146 wpa_printf(MSG_ERROR, "Could not get random numbers");
151 key->key_index = idx | (broadcast ? 0 : BIT(7));
152 if (hapd->conf->eapol_key_index_workaround) {
153 /* According to some information, WinXP Supplicant seems to
154 * interpret bit7 as an indication whether the key is to be
155 * activated, so make it possible to enable workaround that
156 * sets this bit for all keys. */
157 key->key_index |= BIT(7);
160 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
161 * MSK[32..63] is used to sign the message. */
162 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
163 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
164 "and signing EAPOL-Key");
168 os_memcpy((u8 *) (key + 1), key_data, key_len);
169 ekey_len = sizeof(key->key_iv) + 32;
170 ekey = os_malloc(ekey_len);
172 wpa_printf(MSG_ERROR, "Could not encrypt key");
176 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
177 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
178 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
181 /* This header is needed here for HMAC-MD5, but it will be regenerated
182 * in ieee802_1x_send() */
183 hdr->version = hapd->conf->eapol_version;
184 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
185 hdr->length = host_to_be16(len);
186 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
189 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
190 " (%s index=%d)", MAC2STR(sm->addr),
191 broadcast ? "broadcast" : "unicast", idx);
192 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
194 sta->eapol_sm->dot1xAuthEapolFramesTx++;
199 #ifndef CONFIG_NO_VLAN
200 static struct hostapd_wep_keys *
201 ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
203 struct hostapd_wep_keys *key;
205 key = os_zalloc(sizeof(*key));
209 key->default_len = hapd->conf->default_wep_key_len;
211 if (key->idx >= hapd->conf->broadcast_key_idx_max ||
212 key->idx < hapd->conf->broadcast_key_idx_min)
213 key->idx = hapd->conf->broadcast_key_idx_min;
217 if (!key->key[key->idx])
218 key->key[key->idx] = os_malloc(key->default_len);
219 if (key->key[key->idx] == NULL ||
220 random_get_bytes(key->key[key->idx], key->default_len)) {
221 printf("Could not generate random WEP key (dynamic VLAN).\n");
222 os_free(key->key[key->idx]);
223 key->key[key->idx] = NULL;
227 key->len[key->idx] = key->default_len;
229 wpa_printf(MSG_DEBUG, "%s: Default WEP idx %d for dynamic VLAN\n",
231 wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
232 key->key[key->idx], key->len[key->idx]);
234 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
235 broadcast_ether_addr, key->idx, 1,
236 NULL, 0, key->key[key->idx],
238 printf("Could not set dynamic VLAN WEP encryption key.\n");
240 hostapd_set_drv_ieee8021x(hapd, ifname, 1);
246 static struct hostapd_wep_keys *
247 ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
255 if (vlan_id <= ssid->max_dyn_vlan_keys && ssid->dyn_vlan_keys &&
256 ssid->dyn_vlan_keys[vlan_id])
257 return ssid->dyn_vlan_keys[vlan_id];
259 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Creating new group "
260 "state machine for VLAN ID %lu",
261 (unsigned long) vlan_id);
263 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
264 if (ifname == NULL) {
265 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Unknown VLAN ID %lu - "
266 "cannot create group key state machine",
267 (unsigned long) vlan_id);
271 if (ssid->dyn_vlan_keys == NULL) {
272 int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
273 ssid->dyn_vlan_keys = os_zalloc(size);
274 if (ssid->dyn_vlan_keys == NULL)
276 ssid->max_dyn_vlan_keys = vlan_id;
279 if (ssid->max_dyn_vlan_keys < vlan_id) {
280 struct hostapd_wep_keys **na;
281 int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
282 na = os_realloc(ssid->dyn_vlan_keys, size);
285 ssid->dyn_vlan_keys = na;
286 os_memset(&ssid->dyn_vlan_keys[ssid->max_dyn_vlan_keys + 1], 0,
287 (vlan_id - ssid->max_dyn_vlan_keys) *
288 sizeof(ssid->dyn_vlan_keys[0]));
289 ssid->max_dyn_vlan_keys = vlan_id;
292 ssid->dyn_vlan_keys[vlan_id] = ieee802_1x_group_alloc(hapd, ifname);
294 return ssid->dyn_vlan_keys[vlan_id];
296 #endif /* CONFIG_NO_VLAN */
299 void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
301 struct eapol_authenticator *eapol = hapd->eapol_auth;
302 struct eapol_state_machine *sm = sta->eapol_sm;
303 #ifndef CONFIG_NO_VLAN
304 struct hostapd_wep_keys *key = NULL;
306 #endif /* CONFIG_NO_VLAN */
308 if (sm == NULL || !sm->eap_if->eapKeyData)
311 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
314 #ifndef CONFIG_NO_VLAN
315 vlan_id = sta->vlan_id;
316 if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
320 key = ieee802_1x_get_group(hapd, sta->ssid, vlan_id);
321 if (key && key->key[key->idx])
322 ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
326 #endif /* CONFIG_NO_VLAN */
327 if (eapol->default_wep_key) {
328 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
329 eapol->default_wep_key,
330 hapd->conf->default_wep_key_len);
333 if (hapd->conf->individual_wep_key_len > 0) {
335 ikey = os_malloc(hapd->conf->individual_wep_key_len);
337 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
339 wpa_printf(MSG_ERROR, "Could not generate random "
340 "individual WEP key.");
345 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
346 ikey, hapd->conf->individual_wep_key_len);
348 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
349 hapd->conf->individual_wep_key_len);
351 /* TODO: set encryption in TX callback, i.e., only after STA
352 * has ACKed EAPOL-Key frame */
353 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
354 sta->addr, 0, 1, NULL, 0, ikey,
355 hapd->conf->individual_wep_key_len)) {
356 wpa_printf(MSG_ERROR, "Could not set individual WEP "
365 const char *radius_mode_txt(struct hostapd_data *hapd)
367 switch (hapd->iface->conf->hw_mode) {
368 case HOSTAPD_MODE_IEEE80211A:
370 case HOSTAPD_MODE_IEEE80211G:
372 case HOSTAPD_MODE_IEEE80211B:
379 int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
384 for (i = 0; i < sta->supported_rates_len; i++)
385 if ((sta->supported_rates[i] & 0x7f) > rate)
386 rate = sta->supported_rates[i] & 0x7f;
392 #ifndef CONFIG_NO_RADIUS
393 static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
394 struct eapol_state_machine *sm,
395 const u8 *eap, size_t len)
400 if (len <= sizeof(struct eap_hdr) ||
401 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY)
404 identity = eap_get_identity(sm->eap, &identity_len);
405 if (identity == NULL)
408 /* Save station identity for future RADIUS packets */
409 os_free(sm->identity);
410 sm->identity = os_malloc(identity_len + 1);
411 if (sm->identity == NULL) {
412 sm->identity_len = 0;
416 os_memcpy(sm->identity, identity, identity_len);
417 sm->identity_len = identity_len;
418 sm->identity[identity_len] = '\0';
419 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
420 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
421 sm->dot1xAuthEapolRespIdFramesRx++;
425 static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
426 struct sta_info *sta,
427 const u8 *eap, size_t len)
429 struct radius_msg *msg;
431 struct eapol_state_machine *sm = sta->eapol_sm;
436 ieee802_1x_learn_identity(hapd, sm, eap, len);
438 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
441 sm->radius_identifier = radius_client_get_id(hapd->radius);
442 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
443 sm->radius_identifier);
445 printf("Could not create net RADIUS packet\n");
449 radius_msg_make_authenticator(msg, (u8 *) sta, sizeof(*sta));
452 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
453 sm->identity, sm->identity_len)) {
454 printf("Could not add User-Name\n");
458 if (hapd->conf->own_ip_addr.af == AF_INET &&
459 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
460 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
461 printf("Could not add NAS-IP-Address\n");
466 if (hapd->conf->own_ip_addr.af == AF_INET6 &&
467 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
468 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
469 printf("Could not add NAS-IPv6-Address\n");
472 #endif /* CONFIG_IPV6 */
474 if (hapd->conf->nas_identifier &&
475 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
476 (u8 *) hapd->conf->nas_identifier,
477 os_strlen(hapd->conf->nas_identifier))) {
478 printf("Could not add NAS-Identifier\n");
482 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
483 printf("Could not add NAS-Port\n");
487 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
488 MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
489 buf[sizeof(buf) - 1] = '\0';
490 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
491 (u8 *) buf, os_strlen(buf))) {
492 printf("Could not add Called-Station-Id\n");
496 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
498 buf[sizeof(buf) - 1] = '\0';
499 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
500 (u8 *) buf, os_strlen(buf))) {
501 printf("Could not add Calling-Station-Id\n");
505 /* TODO: should probably check MTU from driver config; 2304 is max for
506 * IEEE 802.11, but use 1400 to avoid problems with too large packets
508 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
509 printf("Could not add Framed-MTU\n");
513 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
514 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
515 printf("Could not add NAS-Port-Type\n");
519 if (sta->flags & WLAN_STA_PREAUTH) {
520 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
523 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
524 radius_sta_rate(hapd, sta) / 2,
525 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
526 radius_mode_txt(hapd));
527 buf[sizeof(buf) - 1] = '\0';
529 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
530 (u8 *) buf, os_strlen(buf))) {
531 printf("Could not add Connect-Info\n");
535 if (eap && !radius_msg_add_eap(msg, eap, len)) {
536 printf("Could not add EAP-Message\n");
540 /* State attribute must be copied if and only if this packet is
541 * Access-Request reply to the previous Access-Challenge */
542 if (sm->last_recv_radius &&
543 radius_msg_get_hdr(sm->last_recv_radius)->code ==
544 RADIUS_CODE_ACCESS_CHALLENGE) {
545 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
548 printf("Could not copy State attribute from previous "
549 "Access-Challenge\n");
553 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
557 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
563 radius_msg_free(msg);
565 #endif /* CONFIG_NO_RADIUS */
568 static void handle_eap_response(struct hostapd_data *hapd,
569 struct sta_info *sta, struct eap_hdr *eap,
573 struct eapol_state_machine *sm = sta->eapol_sm;
577 data = (u8 *) (eap + 1);
579 if (len < sizeof(*eap) + 1) {
580 printf("handle_eap_response: too short response data\n");
584 sm->eap_type_supp = type = data[0];
586 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
587 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
588 "id=%d len=%d) from STA: EAP Response-%s (%d)",
589 eap->code, eap->identifier, be_to_host16(eap->length),
590 eap_server_get_name(0, type), type);
592 sm->dot1xAuthEapolRespFramesRx++;
594 wpabuf_free(sm->eap_if->eapRespData);
595 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
600 /* Process incoming EAP packet from Supplicant */
601 static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
607 if (len < sizeof(*eap)) {
608 printf(" too short EAP packet\n");
612 eap = (struct eap_hdr *) buf;
614 eap_len = be_to_host16(eap->length);
615 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
616 eap->code, eap->identifier, eap_len);
617 if (eap_len < sizeof(*eap)) {
618 wpa_printf(MSG_DEBUG, " Invalid EAP length");
620 } else if (eap_len > len) {
621 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
624 } else if (eap_len < len) {
625 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
626 "packet", (unsigned long) len - eap_len);
630 case EAP_CODE_REQUEST:
631 wpa_printf(MSG_DEBUG, " (request)");
633 case EAP_CODE_RESPONSE:
634 wpa_printf(MSG_DEBUG, " (response)");
635 handle_eap_response(hapd, sta, eap, eap_len);
637 case EAP_CODE_SUCCESS:
638 wpa_printf(MSG_DEBUG, " (success)");
640 case EAP_CODE_FAILURE:
641 wpa_printf(MSG_DEBUG, " (failure)");
644 wpa_printf(MSG_DEBUG, " (unknown code)");
650 static struct eapol_state_machine *
651 ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
654 if (sta->flags & WLAN_STA_PREAUTH)
655 flags |= EAPOL_SM_PREAUTH;
657 flags |= EAPOL_SM_USES_WPA;
658 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
659 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
661 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
662 sta->wps_ie, sta->p2p_ie, sta);
667 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
668 * @hapd: hostapd BSS data
669 * @sa: Source address (sender of the EAPOL frame)
671 * @len: Length of buf in octets
673 * This function is called for each incoming EAPOL frame from the interface
675 void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
678 struct sta_info *sta;
679 struct ieee802_1x_hdr *hdr;
680 struct ieee802_1x_eapol_key *key;
682 struct rsn_pmksa_cache_entry *pmksa;
685 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
686 !hapd->conf->wps_state)
689 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
690 (unsigned long) len, MAC2STR(sa));
691 sta = ap_get_sta(hapd, sa);
692 if (!sta || !(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH))) {
693 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
694 "associated/Pre-authenticating STA");
698 if (len < sizeof(*hdr)) {
699 printf(" too short IEEE 802.1X packet\n");
703 hdr = (struct ieee802_1x_hdr *) buf;
704 datalen = be_to_host16(hdr->length);
705 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
706 hdr->version, hdr->type, datalen);
708 if (len - sizeof(*hdr) < datalen) {
709 printf(" frame too short for this IEEE 802.1X packet\n");
711 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
714 if (len - sizeof(*hdr) > datalen) {
715 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
716 "IEEE 802.1X packet",
717 (unsigned long) len - sizeof(*hdr) - datalen);
721 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
722 sta->eapol_sm->dot1xAuthEapolFramesRx++;
725 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
726 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
727 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
728 (key->type == EAPOL_KEY_TYPE_WPA ||
729 key->type == EAPOL_KEY_TYPE_RSN)) {
730 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
731 sizeof(*hdr) + datalen);
735 if (!hapd->conf->ieee802_1x &&
736 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
737 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
738 "802.1X not enabled and WPS not used");
742 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
743 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
744 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
749 if (!sta->eapol_sm) {
750 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
755 if (!hapd->conf->ieee802_1x &&
756 ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
757 WLAN_STA_MAYBE_WPS)) {
759 * Delay EAPOL frame transmission until a possible WPS
760 * STA initiates the handshake with EAPOL-Start.
762 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
764 #endif /* CONFIG_WPS */
766 sta->eapol_sm->eap_if->portEnabled = TRUE;
769 /* since we support version 1, we can ignore version field and proceed
770 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
771 /* TODO: actually, we are not version 1 anymore.. However, Version 2
772 * does not change frame contents, so should be ok to process frames
773 * more or less identically. Some changes might be needed for
774 * verification of fields. */
777 case IEEE802_1X_TYPE_EAP_PACKET:
778 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
781 case IEEE802_1X_TYPE_EAPOL_START:
782 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
783 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
785 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
786 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
788 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
789 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
790 "available - ignore it since "
791 "STA sent EAPOL-Start");
792 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
794 sta->eapol_sm->eapolStart = TRUE;
795 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
796 eap_server_clear_identity(sta->eapol_sm->eap);
797 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
800 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
801 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
802 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
804 sta->acct_terminate_cause =
805 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
806 accounting_sta_stop(hapd, sta);
807 sta->eapol_sm->eapolLogoff = TRUE;
808 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
809 eap_server_clear_identity(sta->eapol_sm->eap);
812 case IEEE802_1X_TYPE_EAPOL_KEY:
813 wpa_printf(MSG_DEBUG, " EAPOL-Key");
814 if (!ap_sta_is_authorized(sta)) {
815 wpa_printf(MSG_DEBUG, " Dropped key data from "
816 "unauthorized Supplicant");
821 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
822 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
823 /* TODO: implement support for this; show data */
827 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
828 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
832 eapol_auth_step(sta->eapol_sm);
837 * ieee802_1x_new_station - Start IEEE 802.1X authentication
838 * @hapd: hostapd BSS data
841 * This function is called to start IEEE 802.1X authentication when a new
842 * station completes IEEE 802.11 association.
844 void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
846 struct rsn_pmksa_cache_entry *pmksa;
852 if (hapd->conf->wps_state && hapd->conf->wpa &&
853 (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
855 * Need to enable IEEE 802.1X/EAPOL state machines for possible
856 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
857 * authentication in this BSS.
861 #endif /* CONFIG_WPS */
863 if (!force_1x && !hapd->conf->ieee802_1x) {
864 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
865 "802.1X not enabled or forced for WPS");
869 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
870 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
871 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
875 if (sta->eapol_sm == NULL) {
876 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
877 HOSTAPD_LEVEL_DEBUG, "start authentication");
878 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
879 if (sta->eapol_sm == NULL) {
880 hostapd_logger(hapd, sta->addr,
881 HOSTAPD_MODULE_IEEE8021X,
883 "failed to allocate state machine");
890 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
891 if (!hapd->conf->ieee802_1x && !(sta->flags & WLAN_STA_WPS)) {
893 * Delay EAPOL frame transmission until a possible WPS
894 * initiates the handshake with EAPOL-Start.
896 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
898 #endif /* CONFIG_WPS */
900 sta->eapol_sm->eap_if->portEnabled = TRUE;
902 #ifdef CONFIG_IEEE80211R
903 if (sta->auth_alg == WLAN_AUTH_FT) {
904 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
906 "PMK from FT - skip IEEE 802.1X/EAP");
907 /* Setup EAPOL state machines to already authenticated state
908 * because of existing FT information from R0KH. */
909 sta->eapol_sm->keyRun = TRUE;
910 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
911 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
912 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
913 sta->eapol_sm->authSuccess = TRUE;
914 if (sta->eapol_sm->eap)
915 eap_sm_notify_cached(sta->eapol_sm->eap);
916 /* TODO: get vlan_id from R0KH using RRB message */
919 #endif /* CONFIG_IEEE80211R */
921 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
925 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
927 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
928 /* Setup EAPOL state machines to already authenticated state
929 * because of existing PMKSA information in the cache. */
930 sta->eapol_sm->keyRun = TRUE;
931 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
932 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
933 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
934 sta->eapol_sm->authSuccess = TRUE;
935 if (sta->eapol_sm->eap)
936 eap_sm_notify_cached(sta->eapol_sm->eap);
937 old_vlanid = sta->vlan_id;
938 pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
939 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
941 ap_sta_bind_vlan(hapd, sta, old_vlanid);
945 * Force EAPOL state machines to start
946 * re-authentication without having to wait for the
947 * Supplicant to send EAPOL-Start.
949 sta->eapol_sm->reAuthenticate = TRUE;
951 eapol_auth_step(sta->eapol_sm);
956 void ieee802_1x_free_station(struct sta_info *sta)
958 struct eapol_state_machine *sm = sta->eapol_sm;
963 sta->eapol_sm = NULL;
965 #ifndef CONFIG_NO_RADIUS
966 radius_msg_free(sm->last_recv_radius);
967 radius_free_class(&sm->radius_class);
968 #endif /* CONFIG_NO_RADIUS */
970 os_free(sm->identity);
975 #ifndef CONFIG_NO_RADIUS
976 static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
977 struct sta_info *sta)
984 struct radius_msg *msg;
985 struct eapol_state_machine *sm = sta->eapol_sm;
987 if (sm == NULL || sm->last_recv_radius == NULL) {
989 sm->eap_if->aaaEapNoReq = TRUE;
993 msg = sm->last_recv_radius;
995 eap = radius_msg_get_eap(msg, &len);
997 /* RFC 3579, Chap. 2.6.3:
998 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1000 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1001 HOSTAPD_LEVEL_WARNING, "could not extract "
1002 "EAP-Message from RADIUS message");
1003 sm->eap_if->aaaEapNoReq = TRUE;
1007 if (len < sizeof(*hdr)) {
1008 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1009 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1010 "received from authentication server");
1012 sm->eap_if->aaaEapNoReq = TRUE;
1016 if (len > sizeof(*hdr))
1017 eap_type = eap[sizeof(*hdr)];
1019 hdr = (struct eap_hdr *) eap;
1020 switch (hdr->code) {
1021 case EAP_CODE_REQUEST:
1023 sm->eap_type_authsrv = eap_type;
1024 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
1025 eap_type >= 0 ? eap_server_get_name(0, eap_type) :
1029 case EAP_CODE_RESPONSE:
1030 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
1031 eap_type >= 0 ? eap_server_get_name(0, eap_type) :
1035 case EAP_CODE_SUCCESS:
1036 os_strlcpy(buf, "EAP Success", sizeof(buf));
1038 case EAP_CODE_FAILURE:
1039 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1042 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1045 buf[sizeof(buf) - 1] = '\0';
1046 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1047 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1048 "id=%d len=%d) from RADIUS server: %s",
1049 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1051 sm->eap_if->aaaEapReq = TRUE;
1053 wpabuf_free(sm->eap_if->aaaEapReqData);
1054 sm->eap_if->aaaEapReqData = wpabuf_alloc_ext_data(eap, len);
1058 static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1059 struct sta_info *sta, struct radius_msg *msg,
1060 struct radius_msg *req,
1061 const u8 *shared_secret,
1062 size_t shared_secret_len)
1064 struct radius_ms_mppe_keys *keys;
1065 struct eapol_state_machine *sm = sta->eapol_sm;
1069 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1072 if (keys && keys->send && keys->recv) {
1073 size_t len = keys->send_len + keys->recv_len;
1074 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1075 keys->send, keys->send_len);
1076 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1077 keys->recv, keys->recv_len);
1079 os_free(sm->eap_if->aaaEapKeyData);
1080 sm->eap_if->aaaEapKeyData = os_malloc(len);
1081 if (sm->eap_if->aaaEapKeyData) {
1082 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1084 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1085 keys->send, keys->send_len);
1086 sm->eap_if->aaaEapKeyDataLen = len;
1087 sm->eap_if->aaaEapKeyAvailable = TRUE;
1092 os_free(keys->send);
1093 os_free(keys->recv);
1099 static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1100 struct sta_info *sta,
1101 struct radius_msg *msg)
1105 struct eapol_state_machine *sm = sta->eapol_sm;
1107 struct radius_attr_data *nclass;
1108 size_t nclass_count;
1110 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1114 radius_free_class(&sm->radius_class);
1115 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1119 nclass = os_zalloc(count * sizeof(struct radius_attr_data));
1126 for (i = 0; i < count; i++) {
1128 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
1134 } while (class_len < 1);
1136 nclass[nclass_count].data = os_malloc(class_len);
1137 if (nclass[nclass_count].data == NULL)
1140 os_memcpy(nclass[nclass_count].data, class, class_len);
1141 nclass[nclass_count].len = class_len;
1145 sm->radius_class.attr = nclass;
1146 sm->radius_class.count = nclass_count;
1147 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1148 "attributes for " MACSTR,
1149 (unsigned long) sm->radius_class.count,
1150 MAC2STR(sta->addr));
1154 /* Update sta->identity based on User-Name attribute in Access-Accept */
1155 static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1156 struct sta_info *sta,
1157 struct radius_msg *msg)
1161 struct eapol_state_machine *sm = sta->eapol_sm;
1166 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1170 identity = os_malloc(len + 1);
1171 if (identity == NULL)
1174 os_memcpy(identity, buf, len);
1175 identity[len] = '\0';
1177 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1178 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1179 "User-Name from Access-Accept '%s'",
1180 sm->identity ? (char *) sm->identity : "N/A",
1183 os_free(sm->identity);
1184 sm->identity = identity;
1185 sm->identity_len = len;
1189 struct sta_id_search {
1191 struct eapol_state_machine *sm;
1195 static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1196 struct sta_info *sta,
1199 struct sta_id_search *id_search = ctx;
1200 struct eapol_state_machine *sm = sta->eapol_sm;
1202 if (sm && sm->radius_identifier >= 0 &&
1203 sm->radius_identifier == id_search->identifier) {
1211 static struct eapol_state_machine *
1212 ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1214 struct sta_id_search id_search;
1215 id_search.identifier = identifier;
1216 id_search.sm = NULL;
1217 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1218 return id_search.sm;
1223 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1224 * @msg: RADIUS response message
1225 * @req: RADIUS request message
1226 * @shared_secret: RADIUS shared secret
1227 * @shared_secret_len: Length of shared_secret in octets
1228 * @data: Context data (struct hostapd_data *)
1229 * Returns: Processing status
1231 static RadiusRxResult
1232 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1233 const u8 *shared_secret, size_t shared_secret_len,
1236 struct hostapd_data *hapd = data;
1237 struct sta_info *sta;
1238 u32 session_timeout = 0, termination_action, acct_interim_interval;
1239 int session_timeout_set, old_vlanid = 0;
1240 struct eapol_state_machine *sm;
1241 int override_eapReq = 0;
1242 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
1244 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1246 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1247 "station for this RADIUS message");
1248 return RADIUS_RX_UNKNOWN;
1252 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1253 * present when packet contains an EAP-Message attribute */
1254 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1255 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1257 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1258 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1259 "Message-Authenticator since it does not include "
1261 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1263 printf("Incoming RADIUS packet did not have correct "
1264 "Message-Authenticator - dropped\n");
1265 return RADIUS_RX_INVALID_AUTHENTICATOR;
1268 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1269 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1270 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
1271 printf("Unknown RADIUS message code\n");
1272 return RADIUS_RX_UNKNOWN;
1275 sm->radius_identifier = -1;
1276 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1277 MAC2STR(sta->addr));
1279 radius_msg_free(sm->last_recv_radius);
1280 sm->last_recv_radius = msg;
1282 session_timeout_set =
1283 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1285 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1286 &termination_action))
1287 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1289 if (hapd->conf->acct_interim_interval == 0 &&
1290 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1291 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1292 &acct_interim_interval) == 0) {
1293 if (acct_interim_interval < 60) {
1294 hostapd_logger(hapd, sta->addr,
1295 HOSTAPD_MODULE_IEEE8021X,
1297 "ignored too small "
1298 "Acct-Interim-Interval %d",
1299 acct_interim_interval);
1301 sta->acct_interim_interval = acct_interim_interval;
1305 switch (hdr->code) {
1306 case RADIUS_CODE_ACCESS_ACCEPT:
1307 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
1309 #ifndef CONFIG_NO_VLAN
1311 old_vlanid = sta->vlan_id;
1312 sta->vlan_id = radius_msg_get_vlanid(msg);
1314 if (sta->vlan_id > 0 &&
1315 hostapd_get_vlan_id_ifname(hapd->conf->vlan,
1317 hostapd_logger(hapd, sta->addr,
1318 HOSTAPD_MODULE_RADIUS,
1320 "VLAN ID %d", sta->vlan_id);
1321 } else if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_REQUIRED) {
1322 sta->eapol_sm->authFail = TRUE;
1323 hostapd_logger(hapd, sta->addr,
1324 HOSTAPD_MODULE_IEEE8021X,
1325 HOSTAPD_LEVEL_INFO, "authentication "
1326 "server did not include required VLAN "
1327 "ID in Access-Accept");
1330 #endif /* CONFIG_NO_VLAN */
1332 if (ap_sta_bind_vlan(hapd, sta, old_vlanid) < 0)
1335 /* RFC 3580, Ch. 3.17 */
1336 if (session_timeout_set && termination_action ==
1337 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
1338 sm->reAuthPeriod = session_timeout;
1339 } else if (session_timeout_set)
1340 ap_sta_session_timeout(hapd, sta, session_timeout);
1342 sm->eap_if->aaaSuccess = TRUE;
1343 override_eapReq = 1;
1344 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1346 ieee802_1x_store_radius_class(hapd, sta, msg);
1347 ieee802_1x_update_sta_identity(hapd, sta, msg);
1348 if (sm->eap_if->eapKeyAvailable &&
1349 wpa_auth_pmksa_add(sta->wpa_sm, sm->eapol_key_crypt,
1350 session_timeout_set ?
1351 (int) session_timeout : -1, sm) == 0) {
1352 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
1353 HOSTAPD_LEVEL_DEBUG,
1354 "Added PMKSA cache entry");
1357 case RADIUS_CODE_ACCESS_REJECT:
1358 sm->eap_if->aaaFail = TRUE;
1359 override_eapReq = 1;
1361 case RADIUS_CODE_ACCESS_CHALLENGE:
1362 sm->eap_if->aaaEapReq = TRUE;
1363 if (session_timeout_set) {
1364 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1365 sm->eap_if->aaaMethodTimeout = session_timeout;
1366 hostapd_logger(hapd, sm->addr,
1367 HOSTAPD_MODULE_IEEE8021X,
1368 HOSTAPD_LEVEL_DEBUG,
1369 "using EAP timeout of %d seconds (from "
1371 sm->eap_if->aaaMethodTimeout);
1374 * Use dynamic retransmission behavior per EAP
1377 sm->eap_if->aaaMethodTimeout = 0;
1382 ieee802_1x_decapsulate_radius(hapd, sta);
1383 if (override_eapReq)
1384 sm->eap_if->aaaEapReq = FALSE;
1386 eapol_auth_step(sm);
1388 return RADIUS_RX_QUEUED;
1390 #endif /* CONFIG_NO_RADIUS */
1393 void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
1395 struct eapol_state_machine *sm = sta->eapol_sm;
1399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1400 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
1402 #ifndef CONFIG_NO_RADIUS
1403 radius_msg_free(sm->last_recv_radius);
1404 sm->last_recv_radius = NULL;
1405 #endif /* CONFIG_NO_RADIUS */
1407 if (sm->eap_if->eapTimeout) {
1409 * Disconnect the STA since it did not reply to the last EAP
1410 * request and we cannot continue EAP processing (EAP-Failure
1411 * could only be sent if the EAP peer actually replied).
1413 sm->eap_if->portEnabled = FALSE;
1414 ap_sta_disconnect(hapd, sta, sta->addr,
1415 WLAN_REASON_PREV_AUTH_NOT_VALID);
1420 static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
1422 struct eapol_authenticator *eapol = hapd->eapol_auth;
1424 if (hapd->conf->default_wep_key_len < 1)
1427 os_free(eapol->default_wep_key);
1428 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
1429 if (eapol->default_wep_key == NULL ||
1430 random_get_bytes(eapol->default_wep_key,
1431 hapd->conf->default_wep_key_len)) {
1432 printf("Could not generate random WEP key.\n");
1433 os_free(eapol->default_wep_key);
1434 eapol->default_wep_key = NULL;
1438 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
1439 eapol->default_wep_key,
1440 hapd->conf->default_wep_key_len);
1446 static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
1447 struct sta_info *sta, void *ctx)
1449 if (sta->eapol_sm) {
1450 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1451 eapol_auth_step(sta->eapol_sm);
1457 static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
1459 struct hostapd_data *hapd = eloop_ctx;
1460 struct eapol_authenticator *eapol = hapd->eapol_auth;
1462 if (eapol->default_wep_key_idx >= 3)
1463 eapol->default_wep_key_idx =
1464 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
1466 eapol->default_wep_key_idx++;
1468 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
1469 eapol->default_wep_key_idx);
1471 if (ieee802_1x_rekey_broadcast(hapd)) {
1472 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1473 HOSTAPD_LEVEL_WARNING, "failed to generate a "
1474 "new broadcast key");
1475 os_free(eapol->default_wep_key);
1476 eapol->default_wep_key = NULL;
1480 /* TODO: Could setup key for RX here, but change default TX keyid only
1481 * after new broadcast key has been sent to all stations. */
1482 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
1483 broadcast_ether_addr,
1484 eapol->default_wep_key_idx, 1, NULL, 0,
1485 eapol->default_wep_key,
1486 hapd->conf->default_wep_key_len)) {
1487 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1488 HOSTAPD_LEVEL_WARNING, "failed to configure a "
1489 "new broadcast key");
1490 os_free(eapol->default_wep_key);
1491 eapol->default_wep_key = NULL;
1495 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
1497 if (hapd->conf->wep_rekeying_period > 0) {
1498 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
1499 ieee802_1x_rekey, hapd, NULL);
1504 static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
1505 const u8 *data, size_t datalen)
1508 struct sta_info *sta = sta_ctx;
1510 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
1511 WLAN_STA_MAYBE_WPS) {
1513 size_t identity_len;
1514 struct eapol_state_machine *sm = sta->eapol_sm;
1516 identity = eap_get_identity(sm->eap, &identity_len);
1518 ((identity_len == WSC_ID_ENROLLEE_LEN &&
1519 os_memcmp(identity, WSC_ID_ENROLLEE,
1520 WSC_ID_ENROLLEE_LEN) == 0) ||
1521 (identity_len == WSC_ID_REGISTRAR_LEN &&
1522 os_memcmp(identity, WSC_ID_REGISTRAR,
1523 WSC_ID_REGISTRAR_LEN) == 0))) {
1524 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
1526 sta->flags |= WLAN_STA_WPS;
1529 #endif /* CONFIG_WPS */
1531 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
1535 static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
1536 const u8 *data, size_t datalen)
1538 #ifndef CONFIG_NO_RADIUS
1539 struct hostapd_data *hapd = ctx;
1540 struct sta_info *sta = sta_ctx;
1542 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
1543 #endif /* CONFIG_NO_RADIUS */
1547 static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
1550 struct hostapd_data *hapd = ctx;
1551 struct sta_info *sta = sta_ctx;
1553 rsn_preauth_finished(hapd, sta, success);
1555 ieee802_1x_finished(hapd, sta, success);
1559 static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
1560 size_t identity_len, int phase2,
1561 struct eap_user *user)
1563 struct hostapd_data *hapd = ctx;
1564 const struct hostapd_eap_user *eap_user;
1567 eap_user = hostapd_get_eap_user(hapd->conf, identity,
1568 identity_len, phase2);
1569 if (eap_user == NULL)
1572 os_memset(user, 0, sizeof(*user));
1573 user->phase2 = phase2;
1574 count = EAP_USER_MAX_METHODS;
1575 if (count > EAP_MAX_METHODS)
1576 count = EAP_MAX_METHODS;
1577 for (i = 0; i < count; i++) {
1578 user->methods[i].vendor = eap_user->methods[i].vendor;
1579 user->methods[i].method = eap_user->methods[i].method;
1582 if (eap_user->password) {
1583 user->password = os_malloc(eap_user->password_len);
1584 if (user->password == NULL)
1586 os_memcpy(user->password, eap_user->password,
1587 eap_user->password_len);
1588 user->password_len = eap_user->password_len;
1590 user->force_version = eap_user->force_version;
1591 user->ttls_auth = eap_user->ttls_auth;
1597 static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
1599 struct hostapd_data *hapd = ctx;
1600 struct sta_info *sta;
1601 sta = ap_get_sta(hapd, addr);
1602 if (sta == NULL || sta->eapol_sm == NULL)
1608 static void ieee802_1x_logger(void *ctx, const u8 *addr,
1609 eapol_logger_level level, const char *txt)
1611 #ifndef CONFIG_NO_HOSTAPD_LOGGER
1612 struct hostapd_data *hapd = ctx;
1616 case EAPOL_LOGGER_WARNING:
1617 hlevel = HOSTAPD_LEVEL_WARNING;
1619 case EAPOL_LOGGER_INFO:
1620 hlevel = HOSTAPD_LEVEL_INFO;
1622 case EAPOL_LOGGER_DEBUG:
1624 hlevel = HOSTAPD_LEVEL_DEBUG;
1628 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
1630 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
1634 static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
1637 struct hostapd_data *hapd = ctx;
1638 struct sta_info *sta = sta_ctx;
1639 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
1643 static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
1645 struct hostapd_data *hapd = ctx;
1646 struct sta_info *sta = sta_ctx;
1647 ieee802_1x_abort_auth(hapd, sta);
1651 static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
1653 struct hostapd_data *hapd = ctx;
1654 struct sta_info *sta = sta_ctx;
1655 ieee802_1x_tx_key(hapd, sta);
1659 static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
1660 enum eapol_event type)
1662 /* struct hostapd_data *hapd = ctx; */
1663 struct sta_info *sta = sta_ctx;
1665 case EAPOL_AUTH_SM_CHANGE:
1666 wpa_auth_sm_notify(sta->wpa_sm);
1668 case EAPOL_AUTH_REAUTHENTICATE:
1669 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
1675 int ieee802_1x_init(struct hostapd_data *hapd)
1678 struct eapol_auth_config conf;
1679 struct eapol_auth_cb cb;
1681 os_memset(&conf, 0, sizeof(conf));
1683 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
1684 conf.wpa = hapd->conf->wpa;
1685 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
1686 conf.eap_server = hapd->conf->eap_server;
1687 conf.ssl_ctx = hapd->ssl_ctx;
1688 conf.msg_ctx = hapd->msg_ctx;
1689 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
1690 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
1691 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
1692 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
1693 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
1694 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
1695 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
1696 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
1697 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
1698 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
1699 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
1700 conf.tnc = hapd->conf->tnc;
1701 conf.wps = hapd->wps;
1702 conf.fragment_size = hapd->conf->fragment_size;
1703 conf.pwd_group = hapd->conf->pwd_group;
1704 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
1706 os_memset(&cb, 0, sizeof(cb));
1707 cb.eapol_send = ieee802_1x_eapol_send;
1708 cb.aaa_send = ieee802_1x_aaa_send;
1709 cb.finished = _ieee802_1x_finished;
1710 cb.get_eap_user = ieee802_1x_get_eap_user;
1711 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
1712 cb.logger = ieee802_1x_logger;
1713 cb.set_port_authorized = ieee802_1x_set_port_authorized;
1714 cb.abort_auth = _ieee802_1x_abort_auth;
1715 cb.tx_key = _ieee802_1x_tx_key;
1716 cb.eapol_event = ieee802_1x_eapol_event;
1718 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
1719 if (hapd->eapol_auth == NULL)
1722 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
1723 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
1726 #ifndef CONFIG_NO_RADIUS
1727 if (radius_client_register(hapd->radius, RADIUS_AUTH,
1728 ieee802_1x_receive_auth, hapd))
1730 #endif /* CONFIG_NO_RADIUS */
1732 if (hapd->conf->default_wep_key_len) {
1733 for (i = 0; i < 4; i++)
1734 hostapd_drv_set_key(hapd->conf->iface, hapd,
1735 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
1738 ieee802_1x_rekey(hapd, NULL);
1740 if (hapd->eapol_auth->default_wep_key == NULL)
1748 void ieee802_1x_deinit(struct hostapd_data *hapd)
1750 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
1752 if (hapd->driver != NULL &&
1753 (hapd->conf->ieee802_1x || hapd->conf->wpa))
1754 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
1756 eapol_auth_deinit(hapd->eapol_auth);
1757 hapd->eapol_auth = NULL;
1761 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
1762 const u8 *buf, size_t len, int ack)
1764 struct ieee80211_hdr *hdr;
1765 struct ieee802_1x_hdr *xhdr;
1766 struct ieee802_1x_eapol_key *key;
1768 const unsigned char rfc1042_hdr[ETH_ALEN] =
1769 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1773 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2 + sizeof(*xhdr))
1776 hdr = (struct ieee80211_hdr *) buf;
1777 pos = (u8 *) (hdr + 1);
1778 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
1780 pos += sizeof(rfc1042_hdr);
1781 if (WPA_GET_BE16(pos) != ETH_P_PAE)
1785 xhdr = (struct ieee802_1x_hdr *) pos;
1786 pos += sizeof(*xhdr);
1788 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
1789 "type=%d length=%d - ack=%d",
1790 MAC2STR(sta->addr), xhdr->version, xhdr->type,
1791 be_to_host16(xhdr->length), ack);
1793 if (xhdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
1794 pos + sizeof(struct wpa_eapol_key) <= buf + len) {
1795 const struct wpa_eapol_key *wpa;
1796 wpa = (const struct wpa_eapol_key *) pos;
1797 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
1798 wpa->type == EAPOL_KEY_TYPE_WPA)
1799 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
1803 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
1804 * or Authenticator state machines, but EAPOL-Key packets are not
1805 * retransmitted in case of failure. Try to re-sent failed EAPOL-Key
1806 * packets couple of times because otherwise STA keys become
1807 * unsynchronized with AP. */
1808 if (xhdr->type == IEEE802_1X_TYPE_EAPOL_KEY && !ack &&
1809 pos + sizeof(*key) <= buf + len) {
1810 key = (struct ieee802_1x_eapol_key *) pos;
1811 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1812 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
1813 "frame (%scast index=%d)",
1814 key->key_index & BIT(7) ? "uni" : "broad",
1815 key->key_index & ~BIT(7));
1816 /* TODO: re-send EAPOL-Key couple of times (with short delay
1817 * between them?). If all attempt fail, report error and
1818 * deauthenticate STA so that it will get new keys when
1819 * authenticating again (e.g., after returning in range).
1820 * Separate limit/transmit state needed both for unicast and
1821 * broadcast keys(?) */
1823 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
1824 * to here and change the key only if the EAPOL-Key packet was Acked.
1831 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
1833 if (sm == NULL || sm->identity == NULL)
1836 *len = sm->identity_len;
1837 return sm->identity;
1841 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
1844 if (sm == NULL || sm->radius_class.attr == NULL ||
1845 idx >= (int) sm->radius_class.count)
1848 *len = sm->radius_class.attr[idx].len;
1849 return sm->radius_class.attr[idx].data;
1853 const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
1859 *len = sm->eap_if->eapKeyDataLen;
1860 return sm->eap_if->eapKeyData;
1864 void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
1869 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
1870 eapol_auth_step(sm);
1874 void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
1879 sm->portValid = valid ? TRUE : FALSE;
1880 eapol_auth_step(sm);
1884 void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
1889 sm->flags |= EAPOL_SM_PREAUTH;
1891 sm->flags &= ~EAPOL_SM_PREAUTH;
1895 static const char * bool_txt(Boolean bool)
1897 return bool ? "TRUE" : "FALSE";
1901 int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1908 int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1909 char *buf, size_t buflen)
1912 struct eapol_state_machine *sm = sta->eapol_sm;
1917 ret = os_snprintf(buf + len, buflen - len,
1918 "dot1xPaePortNumber=%d\n"
1919 "dot1xPaePortProtocolVersion=%d\n"
1920 "dot1xPaePortCapabilities=1\n"
1921 "dot1xPaePortInitialize=%d\n"
1922 "dot1xPaePortReauthenticate=FALSE\n",
1926 if (ret < 0 || (size_t) ret >= buflen - len)
1930 /* dot1xAuthConfigTable */
1931 ret = os_snprintf(buf + len, buflen - len,
1932 "dot1xAuthPaeState=%d\n"
1933 "dot1xAuthBackendAuthState=%d\n"
1934 "dot1xAuthAdminControlledDirections=%d\n"
1935 "dot1xAuthOperControlledDirections=%d\n"
1936 "dot1xAuthAuthControlledPortStatus=%d\n"
1937 "dot1xAuthAuthControlledPortControl=%d\n"
1938 "dot1xAuthQuietPeriod=%u\n"
1939 "dot1xAuthServerTimeout=%u\n"
1940 "dot1xAuthReAuthPeriod=%u\n"
1941 "dot1xAuthReAuthEnabled=%s\n"
1942 "dot1xAuthKeyTxEnabled=%s\n",
1943 sm->auth_pae_state + 1,
1944 sm->be_auth_state + 1,
1945 sm->adminControlledDirections,
1946 sm->operControlledDirections,
1952 bool_txt(sm->reAuthEnabled),
1953 bool_txt(sm->keyTxEnabled));
1954 if (ret < 0 || (size_t) ret >= buflen - len)
1958 /* dot1xAuthStatsTable */
1959 ret = os_snprintf(buf + len, buflen - len,
1960 "dot1xAuthEapolFramesRx=%u\n"
1961 "dot1xAuthEapolFramesTx=%u\n"
1962 "dot1xAuthEapolStartFramesRx=%u\n"
1963 "dot1xAuthEapolLogoffFramesRx=%u\n"
1964 "dot1xAuthEapolRespIdFramesRx=%u\n"
1965 "dot1xAuthEapolRespFramesRx=%u\n"
1966 "dot1xAuthEapolReqIdFramesTx=%u\n"
1967 "dot1xAuthEapolReqFramesTx=%u\n"
1968 "dot1xAuthInvalidEapolFramesRx=%u\n"
1969 "dot1xAuthEapLengthErrorFramesRx=%u\n"
1970 "dot1xAuthLastEapolFrameVersion=%u\n"
1971 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
1972 sm->dot1xAuthEapolFramesRx,
1973 sm->dot1xAuthEapolFramesTx,
1974 sm->dot1xAuthEapolStartFramesRx,
1975 sm->dot1xAuthEapolLogoffFramesRx,
1976 sm->dot1xAuthEapolRespIdFramesRx,
1977 sm->dot1xAuthEapolRespFramesRx,
1978 sm->dot1xAuthEapolReqIdFramesTx,
1979 sm->dot1xAuthEapolReqFramesTx,
1980 sm->dot1xAuthInvalidEapolFramesRx,
1981 sm->dot1xAuthEapLengthErrorFramesRx,
1982 sm->dot1xAuthLastEapolFrameVersion,
1984 if (ret < 0 || (size_t) ret >= buflen - len)
1988 /* dot1xAuthDiagTable */
1989 ret = os_snprintf(buf + len, buflen - len,
1990 "dot1xAuthEntersConnecting=%u\n"
1991 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
1992 "dot1xAuthEntersAuthenticating=%u\n"
1993 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
1994 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
1995 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
1996 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
1997 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
1998 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
1999 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2000 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2001 "dot1xAuthBackendResponses=%u\n"
2002 "dot1xAuthBackendAccessChallenges=%u\n"
2003 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2004 "dot1xAuthBackendAuthSuccesses=%u\n"
2005 "dot1xAuthBackendAuthFails=%u\n",
2006 sm->authEntersConnecting,
2007 sm->authEapLogoffsWhileConnecting,
2008 sm->authEntersAuthenticating,
2009 sm->authAuthSuccessesWhileAuthenticating,
2010 sm->authAuthTimeoutsWhileAuthenticating,
2011 sm->authAuthFailWhileAuthenticating,
2012 sm->authAuthEapStartsWhileAuthenticating,
2013 sm->authAuthEapLogoffWhileAuthenticating,
2014 sm->authAuthReauthsWhileAuthenticated,
2015 sm->authAuthEapStartsWhileAuthenticated,
2016 sm->authAuthEapLogoffWhileAuthenticated,
2017 sm->backendResponses,
2018 sm->backendAccessChallenges,
2019 sm->backendOtherRequestsToSupplicant,
2020 sm->backendAuthSuccesses,
2021 sm->backendAuthFails);
2022 if (ret < 0 || (size_t) ret >= buflen - len)
2026 /* dot1xAuthSessionStatsTable */
2027 ret = os_snprintf(buf + len, buflen - len,
2028 /* TODO: dot1xAuthSessionOctetsRx */
2029 /* TODO: dot1xAuthSessionOctetsTx */
2030 /* TODO: dot1xAuthSessionFramesRx */
2031 /* TODO: dot1xAuthSessionFramesTx */
2032 "dot1xAuthSessionId=%08X-%08X\n"
2033 "dot1xAuthSessionAuthenticMethod=%d\n"
2034 "dot1xAuthSessionTime=%u\n"
2035 "dot1xAuthSessionTerminateCause=999\n"
2036 "dot1xAuthSessionUserName=%s\n",
2037 sta->acct_session_id_hi, sta->acct_session_id_lo,
2038 (wpa_key_mgmt_wpa_ieee8021x(
2039 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2041 (unsigned int) (time(NULL) -
2042 sta->acct_session_start),
2044 if (ret < 0 || (size_t) ret >= buflen - len)
2052 static void ieee802_1x_finished(struct hostapd_data *hapd,
2053 struct sta_info *sta, int success)
2057 /* TODO: get PMKLifetime from WPA parameters */
2058 static const int dot11RSNAConfigPMKLifetime = 43200;
2060 key = ieee802_1x_get_key(sta->eapol_sm, &len);
2061 if (success && key && len >= PMK_LEN &&
2062 wpa_auth_pmksa_add(sta->wpa_sm, key, dot11RSNAConfigPMKLifetime,
2063 sta->eapol_sm) == 0) {
2064 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2065 HOSTAPD_LEVEL_DEBUG,
2066 "Added PMKSA cache entry (IEEE 802.1X)");
2070 if (!success && (sta->flags & WLAN_STA_WPS)) {
2072 * Many devices require deauthentication after WPS provisioning
2073 * and some may not be be able to do that themselves, so
2074 * disconnect the client here.
2076 wpa_printf(MSG_DEBUG, "WPS: Force disconnection after "
2078 /* Add a small sleep to increase likelihood of previously
2079 * requested EAP-Failure TX getting out before this should the
2080 * driver reorder operations.
2083 ap_sta_disconnect(hapd, sta, sta->addr,
2084 WLAN_REASON_PREV_AUTH_NOT_VALID);
2086 #endif /* CONFIG_WPS */