2 * hostapd / IEEE 802.1X-2004 Authenticator
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "crypto/md5.h"
14 #include "crypto/crypto.h"
15 #include "crypto/random.h"
16 #include "common/ieee802_11_defs.h"
17 #include "radius/radius.h"
18 #include "radius/radius_client.h"
19 #include "eap_server/eap.h"
20 #include "eap_common/eap_wsc_common.h"
21 #include "eapol_auth/eapol_auth_sm.h"
22 #include "eapol_auth/eapol_auth_sm_i.h"
25 #include "accounting.h"
28 #include "preauth_auth.h"
29 #include "pmksa_cache_auth.h"
30 #include "ap_config.h"
31 #include "ap_drv_ops.h"
32 #include "ieee802_1x.h"
35 static void ieee802_1x_finished(struct hostapd_data *hapd,
36 struct sta_info *sta, int success);
39 static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
40 u8 type, const u8 *data, size_t datalen)
43 struct ieee802_1x_hdr *xhdr;
47 len = sizeof(*xhdr) + datalen;
50 wpa_printf(MSG_ERROR, "malloc() failed for "
51 "ieee802_1x_send(len=%lu)",
56 xhdr = (struct ieee802_1x_hdr *) buf;
57 xhdr->version = hapd->conf->eapol_version;
59 xhdr->length = host_to_be16(datalen);
61 if (datalen > 0 && data != NULL)
62 os_memcpy(xhdr + 1, data, datalen);
64 if (wpa_auth_pairwise_set(sta->wpa_sm))
66 if (sta->flags & WLAN_STA_PREAUTH) {
67 rsn_preauth_send(hapd, sta, buf, len);
69 hostapd_drv_hapd_send_eapol(hapd, sta->addr, buf, len,
77 void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
78 struct sta_info *sta, int authorized)
82 if (sta->flags & WLAN_STA_PREAUTH)
86 ap_sta_set_authorized(hapd, sta, 1);
87 res = hostapd_set_authorized(hapd, sta, 1);
88 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
89 HOSTAPD_LEVEL_DEBUG, "authorizing port");
91 ap_sta_set_authorized(hapd, sta, 0);
92 res = hostapd_set_authorized(hapd, sta, 0);
93 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
94 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
97 if (res && errno != ENOENT) {
98 printf("Could not set station " MACSTR " flags for kernel "
99 "driver (errno=%d).\n", MAC2STR(sta->addr), errno);
103 accounting_sta_start(hapd, sta);
107 static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
108 struct sta_info *sta,
109 int idx, int broadcast,
110 u8 *key_data, size_t key_len)
113 struct ieee802_1x_hdr *hdr;
114 struct ieee802_1x_eapol_key *key;
115 size_t len, ekey_len;
116 struct eapol_state_machine *sm = sta->eapol_sm;
121 len = sizeof(*key) + key_len;
122 buf = os_zalloc(sizeof(*hdr) + len);
126 hdr = (struct ieee802_1x_hdr *) buf;
127 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
128 key->type = EAPOL_KEY_TYPE_RC4;
129 key->key_length = htons(key_len);
130 wpa_get_ntp_timestamp(key->replay_counter);
132 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
133 wpa_printf(MSG_ERROR, "Could not get random numbers");
138 key->key_index = idx | (broadcast ? 0 : BIT(7));
139 if (hapd->conf->eapol_key_index_workaround) {
140 /* According to some information, WinXP Supplicant seems to
141 * interpret bit7 as an indication whether the key is to be
142 * activated, so make it possible to enable workaround that
143 * sets this bit for all keys. */
144 key->key_index |= BIT(7);
147 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
148 * MSK[32..63] is used to sign the message. */
149 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
150 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
151 "and signing EAPOL-Key");
155 os_memcpy((u8 *) (key + 1), key_data, key_len);
156 ekey_len = sizeof(key->key_iv) + 32;
157 ekey = os_malloc(ekey_len);
159 wpa_printf(MSG_ERROR, "Could not encrypt key");
163 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
164 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
165 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
168 /* This header is needed here for HMAC-MD5, but it will be regenerated
169 * in ieee802_1x_send() */
170 hdr->version = hapd->conf->eapol_version;
171 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
172 hdr->length = host_to_be16(len);
173 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
176 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
177 " (%s index=%d)", MAC2STR(sm->addr),
178 broadcast ? "broadcast" : "unicast", idx);
179 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
181 sta->eapol_sm->dot1xAuthEapolFramesTx++;
186 #ifndef CONFIG_NO_VLAN
187 static struct hostapd_wep_keys *
188 ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
190 struct hostapd_wep_keys *key;
192 key = os_zalloc(sizeof(*key));
196 key->default_len = hapd->conf->default_wep_key_len;
198 if (key->idx >= hapd->conf->broadcast_key_idx_max ||
199 key->idx < hapd->conf->broadcast_key_idx_min)
200 key->idx = hapd->conf->broadcast_key_idx_min;
204 if (!key->key[key->idx])
205 key->key[key->idx] = os_malloc(key->default_len);
206 if (key->key[key->idx] == NULL ||
207 random_get_bytes(key->key[key->idx], key->default_len)) {
208 printf("Could not generate random WEP key (dynamic VLAN).\n");
209 os_free(key->key[key->idx]);
210 key->key[key->idx] = NULL;
214 key->len[key->idx] = key->default_len;
216 wpa_printf(MSG_DEBUG, "%s: Default WEP idx %d for dynamic VLAN\n",
218 wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
219 key->key[key->idx], key->len[key->idx]);
221 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
222 broadcast_ether_addr, key->idx, 1,
223 NULL, 0, key->key[key->idx],
225 printf("Could not set dynamic VLAN WEP encryption key.\n");
227 hostapd_set_drv_ieee8021x(hapd, ifname, 1);
233 static struct hostapd_wep_keys *
234 ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
242 if (vlan_id <= ssid->max_dyn_vlan_keys && ssid->dyn_vlan_keys &&
243 ssid->dyn_vlan_keys[vlan_id])
244 return ssid->dyn_vlan_keys[vlan_id];
246 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Creating new group "
247 "state machine for VLAN ID %lu",
248 (unsigned long) vlan_id);
250 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
251 if (ifname == NULL) {
252 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Unknown VLAN ID %lu - "
253 "cannot create group key state machine",
254 (unsigned long) vlan_id);
258 if (ssid->dyn_vlan_keys == NULL) {
259 int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
260 ssid->dyn_vlan_keys = os_zalloc(size);
261 if (ssid->dyn_vlan_keys == NULL)
263 ssid->max_dyn_vlan_keys = vlan_id;
266 if (ssid->max_dyn_vlan_keys < vlan_id) {
267 struct hostapd_wep_keys **na;
268 int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
269 na = os_realloc(ssid->dyn_vlan_keys, size);
272 ssid->dyn_vlan_keys = na;
273 os_memset(&ssid->dyn_vlan_keys[ssid->max_dyn_vlan_keys + 1], 0,
274 (vlan_id - ssid->max_dyn_vlan_keys) *
275 sizeof(ssid->dyn_vlan_keys[0]));
276 ssid->max_dyn_vlan_keys = vlan_id;
279 ssid->dyn_vlan_keys[vlan_id] = ieee802_1x_group_alloc(hapd, ifname);
281 return ssid->dyn_vlan_keys[vlan_id];
283 #endif /* CONFIG_NO_VLAN */
286 void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
288 struct eapol_authenticator *eapol = hapd->eapol_auth;
289 struct eapol_state_machine *sm = sta->eapol_sm;
290 #ifndef CONFIG_NO_VLAN
291 struct hostapd_wep_keys *key = NULL;
293 #endif /* CONFIG_NO_VLAN */
295 if (sm == NULL || !sm->eap_if->eapKeyData)
298 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
301 #ifndef CONFIG_NO_VLAN
302 vlan_id = sta->vlan_id;
303 if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
307 key = ieee802_1x_get_group(hapd, sta->ssid, vlan_id);
308 if (key && key->key[key->idx])
309 ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
313 #endif /* CONFIG_NO_VLAN */
314 if (eapol->default_wep_key) {
315 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
316 eapol->default_wep_key,
317 hapd->conf->default_wep_key_len);
320 if (hapd->conf->individual_wep_key_len > 0) {
322 ikey = os_malloc(hapd->conf->individual_wep_key_len);
324 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
326 wpa_printf(MSG_ERROR, "Could not generate random "
327 "individual WEP key.");
332 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
333 ikey, hapd->conf->individual_wep_key_len);
335 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
336 hapd->conf->individual_wep_key_len);
338 /* TODO: set encryption in TX callback, i.e., only after STA
339 * has ACKed EAPOL-Key frame */
340 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
341 sta->addr, 0, 1, NULL, 0, ikey,
342 hapd->conf->individual_wep_key_len)) {
343 wpa_printf(MSG_ERROR, "Could not set individual WEP "
352 const char *radius_mode_txt(struct hostapd_data *hapd)
354 switch (hapd->iface->conf->hw_mode) {
355 case HOSTAPD_MODE_IEEE80211A:
357 case HOSTAPD_MODE_IEEE80211G:
359 case HOSTAPD_MODE_IEEE80211B:
366 int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
371 for (i = 0; i < sta->supported_rates_len; i++)
372 if ((sta->supported_rates[i] & 0x7f) > rate)
373 rate = sta->supported_rates[i] & 0x7f;
379 #ifndef CONFIG_NO_RADIUS
380 static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
381 struct eapol_state_machine *sm,
382 const u8 *eap, size_t len)
387 if (len <= sizeof(struct eap_hdr) ||
388 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY)
391 identity = eap_get_identity(sm->eap, &identity_len);
392 if (identity == NULL)
395 /* Save station identity for future RADIUS packets */
396 os_free(sm->identity);
397 sm->identity = os_malloc(identity_len + 1);
398 if (sm->identity == NULL) {
399 sm->identity_len = 0;
403 os_memcpy(sm->identity, identity, identity_len);
404 sm->identity_len = identity_len;
405 sm->identity[identity_len] = '\0';
406 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
407 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
408 sm->dot1xAuthEapolRespIdFramesRx++;
412 static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
413 struct sta_info *sta,
414 const u8 *eap, size_t len)
416 struct radius_msg *msg;
418 struct eapol_state_machine *sm = sta->eapol_sm;
423 ieee802_1x_learn_identity(hapd, sm, eap, len);
425 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
428 sm->radius_identifier = radius_client_get_id(hapd->radius);
429 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
430 sm->radius_identifier);
432 printf("Could not create net RADIUS packet\n");
436 radius_msg_make_authenticator(msg, (u8 *) sta, sizeof(*sta));
439 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
440 sm->identity, sm->identity_len)) {
441 printf("Could not add User-Name\n");
445 if (hapd->conf->own_ip_addr.af == AF_INET &&
446 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
447 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
448 printf("Could not add NAS-IP-Address\n");
453 if (hapd->conf->own_ip_addr.af == AF_INET6 &&
454 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
455 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
456 printf("Could not add NAS-IPv6-Address\n");
459 #endif /* CONFIG_IPV6 */
461 if (hapd->conf->nas_identifier &&
462 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
463 (u8 *) hapd->conf->nas_identifier,
464 os_strlen(hapd->conf->nas_identifier))) {
465 printf("Could not add NAS-Identifier\n");
469 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
470 printf("Could not add NAS-Port\n");
474 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
475 MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
476 buf[sizeof(buf) - 1] = '\0';
477 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
478 (u8 *) buf, os_strlen(buf))) {
479 printf("Could not add Called-Station-Id\n");
483 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
485 buf[sizeof(buf) - 1] = '\0';
486 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
487 (u8 *) buf, os_strlen(buf))) {
488 printf("Could not add Calling-Station-Id\n");
492 /* TODO: should probably check MTU from driver config; 2304 is max for
493 * IEEE 802.11, but use 1400 to avoid problems with too large packets
495 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
496 printf("Could not add Framed-MTU\n");
500 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
501 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
502 printf("Could not add NAS-Port-Type\n");
506 if (sta->flags & WLAN_STA_PREAUTH) {
507 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
510 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
511 radius_sta_rate(hapd, sta) / 2,
512 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
513 radius_mode_txt(hapd));
514 buf[sizeof(buf) - 1] = '\0';
516 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
517 (u8 *) buf, os_strlen(buf))) {
518 printf("Could not add Connect-Info\n");
522 if (eap && !radius_msg_add_eap(msg, eap, len)) {
523 printf("Could not add EAP-Message\n");
527 /* State attribute must be copied if and only if this packet is
528 * Access-Request reply to the previous Access-Challenge */
529 if (sm->last_recv_radius &&
530 radius_msg_get_hdr(sm->last_recv_radius)->code ==
531 RADIUS_CODE_ACCESS_CHALLENGE) {
532 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
535 printf("Could not copy State attribute from previous "
536 "Access-Challenge\n");
540 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
544 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
550 radius_msg_free(msg);
552 #endif /* CONFIG_NO_RADIUS */
555 static void handle_eap_response(struct hostapd_data *hapd,
556 struct sta_info *sta, struct eap_hdr *eap,
560 struct eapol_state_machine *sm = sta->eapol_sm;
564 data = (u8 *) (eap + 1);
566 if (len < sizeof(*eap) + 1) {
567 printf("handle_eap_response: too short response data\n");
571 sm->eap_type_supp = type = data[0];
573 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
574 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
575 "id=%d len=%d) from STA: EAP Response-%s (%d)",
576 eap->code, eap->identifier, be_to_host16(eap->length),
577 eap_server_get_name(0, type), type);
579 sm->dot1xAuthEapolRespFramesRx++;
581 wpabuf_free(sm->eap_if->eapRespData);
582 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
587 /* Process incoming EAP packet from Supplicant */
588 static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
594 if (len < sizeof(*eap)) {
595 printf(" too short EAP packet\n");
599 eap = (struct eap_hdr *) buf;
601 eap_len = be_to_host16(eap->length);
602 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
603 eap->code, eap->identifier, eap_len);
604 if (eap_len < sizeof(*eap)) {
605 wpa_printf(MSG_DEBUG, " Invalid EAP length");
607 } else if (eap_len > len) {
608 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
611 } else if (eap_len < len) {
612 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
613 "packet", (unsigned long) len - eap_len);
617 case EAP_CODE_REQUEST:
618 wpa_printf(MSG_DEBUG, " (request)");
620 case EAP_CODE_RESPONSE:
621 wpa_printf(MSG_DEBUG, " (response)");
622 handle_eap_response(hapd, sta, eap, eap_len);
624 case EAP_CODE_SUCCESS:
625 wpa_printf(MSG_DEBUG, " (success)");
627 case EAP_CODE_FAILURE:
628 wpa_printf(MSG_DEBUG, " (failure)");
631 wpa_printf(MSG_DEBUG, " (unknown code)");
637 static struct eapol_state_machine *
638 ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
641 if (sta->flags & WLAN_STA_PREAUTH)
642 flags |= EAPOL_SM_PREAUTH;
644 flags |= EAPOL_SM_USES_WPA;
645 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
646 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
648 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
649 sta->wps_ie, sta->p2p_ie, sta);
654 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
655 * @hapd: hostapd BSS data
656 * @sa: Source address (sender of the EAPOL frame)
658 * @len: Length of buf in octets
660 * This function is called for each incoming EAPOL frame from the interface
662 void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
665 struct sta_info *sta;
666 struct ieee802_1x_hdr *hdr;
667 struct ieee802_1x_eapol_key *key;
669 struct rsn_pmksa_cache_entry *pmksa;
672 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
673 !hapd->conf->wps_state)
676 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
677 (unsigned long) len, MAC2STR(sa));
678 sta = ap_get_sta(hapd, sa);
679 if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
680 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
681 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
682 "associated/Pre-authenticating STA");
686 if (len < sizeof(*hdr)) {
687 printf(" too short IEEE 802.1X packet\n");
691 hdr = (struct ieee802_1x_hdr *) buf;
692 datalen = be_to_host16(hdr->length);
693 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
694 hdr->version, hdr->type, datalen);
696 if (len - sizeof(*hdr) < datalen) {
697 printf(" frame too short for this IEEE 802.1X packet\n");
699 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
702 if (len - sizeof(*hdr) > datalen) {
703 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
704 "IEEE 802.1X packet",
705 (unsigned long) len - sizeof(*hdr) - datalen);
709 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
710 sta->eapol_sm->dot1xAuthEapolFramesRx++;
713 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
714 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
715 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
716 (key->type == EAPOL_KEY_TYPE_WPA ||
717 key->type == EAPOL_KEY_TYPE_RSN)) {
718 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
719 sizeof(*hdr) + datalen);
723 if (!hapd->conf->ieee802_1x &&
724 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
725 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
726 "802.1X not enabled and WPS not used");
730 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
731 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
732 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
737 if (!sta->eapol_sm) {
738 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
743 if (!hapd->conf->ieee802_1x) {
744 u32 wflags = sta->flags & (WLAN_STA_WPS |
747 if (wflags == WLAN_STA_MAYBE_WPS ||
748 wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
750 * Delay EAPOL frame transmission until a
751 * possible WPS STA initiates the handshake
752 * with EAPOL-Start. Only allow the wait to be
753 * skipped if the STA is known to support WPS
756 wpa_printf(MSG_DEBUG, "WPS: Do not start "
757 "EAPOL until EAPOL-Start is "
759 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
762 #endif /* CONFIG_WPS */
764 sta->eapol_sm->eap_if->portEnabled = TRUE;
767 /* since we support version 1, we can ignore version field and proceed
768 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
769 /* TODO: actually, we are not version 1 anymore.. However, Version 2
770 * does not change frame contents, so should be ok to process frames
771 * more or less identically. Some changes might be needed for
772 * verification of fields. */
775 case IEEE802_1X_TYPE_EAP_PACKET:
776 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
779 case IEEE802_1X_TYPE_EAPOL_START:
780 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
781 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
783 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
784 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
786 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
787 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
788 "available - ignore it since "
789 "STA sent EAPOL-Start");
790 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
792 sta->eapol_sm->eapolStart = TRUE;
793 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
794 eap_server_clear_identity(sta->eapol_sm->eap);
795 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
798 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
799 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
800 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
802 sta->acct_terminate_cause =
803 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
804 accounting_sta_stop(hapd, sta);
805 sta->eapol_sm->eapolLogoff = TRUE;
806 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
807 eap_server_clear_identity(sta->eapol_sm->eap);
810 case IEEE802_1X_TYPE_EAPOL_KEY:
811 wpa_printf(MSG_DEBUG, " EAPOL-Key");
812 if (!ap_sta_is_authorized(sta)) {
813 wpa_printf(MSG_DEBUG, " Dropped key data from "
814 "unauthorized Supplicant");
819 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
820 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
821 /* TODO: implement support for this; show data */
825 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
826 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
830 eapol_auth_step(sta->eapol_sm);
835 * ieee802_1x_new_station - Start IEEE 802.1X authentication
836 * @hapd: hostapd BSS data
839 * This function is called to start IEEE 802.1X authentication when a new
840 * station completes IEEE 802.11 association.
842 void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
844 struct rsn_pmksa_cache_entry *pmksa;
850 if (hapd->conf->wps_state && hapd->conf->wpa &&
851 (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
853 * Need to enable IEEE 802.1X/EAPOL state machines for possible
854 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
855 * authentication in this BSS.
859 #endif /* CONFIG_WPS */
861 if (!force_1x && !hapd->conf->ieee802_1x) {
862 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
863 "802.1X not enabled or forced for WPS");
867 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
868 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
869 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
873 if (sta->eapol_sm == NULL) {
874 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
875 HOSTAPD_LEVEL_DEBUG, "start authentication");
876 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
877 if (sta->eapol_sm == NULL) {
878 hostapd_logger(hapd, sta->addr,
879 HOSTAPD_MODULE_IEEE8021X,
881 "failed to allocate state machine");
888 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
889 if (!hapd->conf->ieee802_1x && !(sta->flags & WLAN_STA_WPS2)) {
891 * Delay EAPOL frame transmission until a possible WPS STA
892 * initiates the handshake with EAPOL-Start. Only allow the
893 * wait to be skipped if the STA is known to support WPS 2.0.
895 wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
896 "EAPOL-Start is received");
897 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
899 #endif /* CONFIG_WPS */
901 sta->eapol_sm->eap_if->portEnabled = TRUE;
903 #ifdef CONFIG_IEEE80211R
904 if (sta->auth_alg == WLAN_AUTH_FT) {
905 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
907 "PMK from FT - skip IEEE 802.1X/EAP");
908 /* Setup EAPOL state machines to already authenticated state
909 * because of existing FT information from R0KH. */
910 sta->eapol_sm->keyRun = TRUE;
911 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
912 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
913 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
914 sta->eapol_sm->authSuccess = TRUE;
915 sta->eapol_sm->authFail = FALSE;
916 if (sta->eapol_sm->eap)
917 eap_sm_notify_cached(sta->eapol_sm->eap);
918 /* TODO: get vlan_id from R0KH using RRB message */
921 #endif /* CONFIG_IEEE80211R */
923 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
927 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
929 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
930 /* Setup EAPOL state machines to already authenticated state
931 * because of existing PMKSA information in the cache. */
932 sta->eapol_sm->keyRun = TRUE;
933 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
934 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
935 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
936 sta->eapol_sm->authSuccess = TRUE;
937 sta->eapol_sm->authFail = FALSE;
938 if (sta->eapol_sm->eap)
939 eap_sm_notify_cached(sta->eapol_sm->eap);
940 old_vlanid = sta->vlan_id;
941 pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
942 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
944 ap_sta_bind_vlan(hapd, sta, old_vlanid);
948 * Force EAPOL state machines to start
949 * re-authentication without having to wait for the
950 * Supplicant to send EAPOL-Start.
952 sta->eapol_sm->reAuthenticate = TRUE;
954 eapol_auth_step(sta->eapol_sm);
959 void ieee802_1x_free_station(struct sta_info *sta)
961 struct eapol_state_machine *sm = sta->eapol_sm;
966 sta->eapol_sm = NULL;
968 #ifndef CONFIG_NO_RADIUS
969 radius_msg_free(sm->last_recv_radius);
970 radius_free_class(&sm->radius_class);
971 #endif /* CONFIG_NO_RADIUS */
973 os_free(sm->identity);
978 #ifndef CONFIG_NO_RADIUS
979 static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
980 struct sta_info *sta)
987 struct radius_msg *msg;
988 struct eapol_state_machine *sm = sta->eapol_sm;
990 if (sm == NULL || sm->last_recv_radius == NULL) {
992 sm->eap_if->aaaEapNoReq = TRUE;
996 msg = sm->last_recv_radius;
998 eap = radius_msg_get_eap(msg, &len);
1000 /* RFC 3579, Chap. 2.6.3:
1001 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1003 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1004 HOSTAPD_LEVEL_WARNING, "could not extract "
1005 "EAP-Message from RADIUS message");
1006 sm->eap_if->aaaEapNoReq = TRUE;
1010 if (len < sizeof(*hdr)) {
1011 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1012 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1013 "received from authentication server");
1015 sm->eap_if->aaaEapNoReq = TRUE;
1019 if (len > sizeof(*hdr))
1020 eap_type = eap[sizeof(*hdr)];
1022 hdr = (struct eap_hdr *) eap;
1023 switch (hdr->code) {
1024 case EAP_CODE_REQUEST:
1026 sm->eap_type_authsrv = eap_type;
1027 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
1028 eap_type >= 0 ? eap_server_get_name(0, eap_type) :
1032 case EAP_CODE_RESPONSE:
1033 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
1034 eap_type >= 0 ? eap_server_get_name(0, eap_type) :
1038 case EAP_CODE_SUCCESS:
1039 os_strlcpy(buf, "EAP Success", sizeof(buf));
1041 case EAP_CODE_FAILURE:
1042 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1045 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1048 buf[sizeof(buf) - 1] = '\0';
1049 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1050 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1051 "id=%d len=%d) from RADIUS server: %s",
1052 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1054 sm->eap_if->aaaEapReq = TRUE;
1056 wpabuf_free(sm->eap_if->aaaEapReqData);
1057 sm->eap_if->aaaEapReqData = wpabuf_alloc_ext_data(eap, len);
1061 static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1062 struct sta_info *sta, struct radius_msg *msg,
1063 struct radius_msg *req,
1064 const u8 *shared_secret,
1065 size_t shared_secret_len)
1067 struct radius_ms_mppe_keys *keys;
1068 struct eapol_state_machine *sm = sta->eapol_sm;
1072 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1075 if (keys && keys->send && keys->recv) {
1076 size_t len = keys->send_len + keys->recv_len;
1077 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1078 keys->send, keys->send_len);
1079 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1080 keys->recv, keys->recv_len);
1082 os_free(sm->eap_if->aaaEapKeyData);
1083 sm->eap_if->aaaEapKeyData = os_malloc(len);
1084 if (sm->eap_if->aaaEapKeyData) {
1085 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1087 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1088 keys->send, keys->send_len);
1089 sm->eap_if->aaaEapKeyDataLen = len;
1090 sm->eap_if->aaaEapKeyAvailable = TRUE;
1095 os_free(keys->send);
1096 os_free(keys->recv);
1102 static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1103 struct sta_info *sta,
1104 struct radius_msg *msg)
1108 struct eapol_state_machine *sm = sta->eapol_sm;
1110 struct radius_attr_data *nclass;
1111 size_t nclass_count;
1113 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1117 radius_free_class(&sm->radius_class);
1118 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1122 nclass = os_zalloc(count * sizeof(struct radius_attr_data));
1129 for (i = 0; i < count; i++) {
1131 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
1137 } while (class_len < 1);
1139 nclass[nclass_count].data = os_malloc(class_len);
1140 if (nclass[nclass_count].data == NULL)
1143 os_memcpy(nclass[nclass_count].data, class, class_len);
1144 nclass[nclass_count].len = class_len;
1148 sm->radius_class.attr = nclass;
1149 sm->radius_class.count = nclass_count;
1150 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1151 "attributes for " MACSTR,
1152 (unsigned long) sm->radius_class.count,
1153 MAC2STR(sta->addr));
1157 /* Update sta->identity based on User-Name attribute in Access-Accept */
1158 static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1159 struct sta_info *sta,
1160 struct radius_msg *msg)
1164 struct eapol_state_machine *sm = sta->eapol_sm;
1169 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1173 identity = os_malloc(len + 1);
1174 if (identity == NULL)
1177 os_memcpy(identity, buf, len);
1178 identity[len] = '\0';
1180 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1181 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1182 "User-Name from Access-Accept '%s'",
1183 sm->identity ? (char *) sm->identity : "N/A",
1186 os_free(sm->identity);
1187 sm->identity = identity;
1188 sm->identity_len = len;
1192 struct sta_id_search {
1194 struct eapol_state_machine *sm;
1198 static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1199 struct sta_info *sta,
1202 struct sta_id_search *id_search = ctx;
1203 struct eapol_state_machine *sm = sta->eapol_sm;
1205 if (sm && sm->radius_identifier >= 0 &&
1206 sm->radius_identifier == id_search->identifier) {
1214 static struct eapol_state_machine *
1215 ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1217 struct sta_id_search id_search;
1218 id_search.identifier = identifier;
1219 id_search.sm = NULL;
1220 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1221 return id_search.sm;
1226 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1227 * @msg: RADIUS response message
1228 * @req: RADIUS request message
1229 * @shared_secret: RADIUS shared secret
1230 * @shared_secret_len: Length of shared_secret in octets
1231 * @data: Context data (struct hostapd_data *)
1232 * Returns: Processing status
1234 static RadiusRxResult
1235 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1236 const u8 *shared_secret, size_t shared_secret_len,
1239 struct hostapd_data *hapd = data;
1240 struct sta_info *sta;
1241 u32 session_timeout = 0, termination_action, acct_interim_interval;
1242 int session_timeout_set, old_vlanid = 0;
1243 struct eapol_state_machine *sm;
1244 int override_eapReq = 0;
1245 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
1247 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1249 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1250 "station for this RADIUS message");
1251 return RADIUS_RX_UNKNOWN;
1255 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1256 * present when packet contains an EAP-Message attribute */
1257 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1258 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1260 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1261 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1262 "Message-Authenticator since it does not include "
1264 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1266 printf("Incoming RADIUS packet did not have correct "
1267 "Message-Authenticator - dropped\n");
1268 return RADIUS_RX_INVALID_AUTHENTICATOR;
1271 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1272 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1273 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
1274 printf("Unknown RADIUS message code\n");
1275 return RADIUS_RX_UNKNOWN;
1278 sm->radius_identifier = -1;
1279 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1280 MAC2STR(sta->addr));
1282 radius_msg_free(sm->last_recv_radius);
1283 sm->last_recv_radius = msg;
1285 session_timeout_set =
1286 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1288 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1289 &termination_action))
1290 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1292 if (hapd->conf->acct_interim_interval == 0 &&
1293 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1294 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1295 &acct_interim_interval) == 0) {
1296 if (acct_interim_interval < 60) {
1297 hostapd_logger(hapd, sta->addr,
1298 HOSTAPD_MODULE_IEEE8021X,
1300 "ignored too small "
1301 "Acct-Interim-Interval %d",
1302 acct_interim_interval);
1304 sta->acct_interim_interval = acct_interim_interval;
1308 switch (hdr->code) {
1309 case RADIUS_CODE_ACCESS_ACCEPT:
1310 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
1312 #ifndef CONFIG_NO_VLAN
1314 old_vlanid = sta->vlan_id;
1315 sta->vlan_id = radius_msg_get_vlanid(msg);
1317 if (sta->vlan_id > 0 &&
1318 hostapd_get_vlan_id_ifname(hapd->conf->vlan,
1320 hostapd_logger(hapd, sta->addr,
1321 HOSTAPD_MODULE_RADIUS,
1323 "VLAN ID %d", sta->vlan_id);
1324 } else if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_REQUIRED) {
1325 sta->eapol_sm->authFail = TRUE;
1326 hostapd_logger(hapd, sta->addr,
1327 HOSTAPD_MODULE_IEEE8021X,
1328 HOSTAPD_LEVEL_INFO, "authentication "
1329 "server did not include required VLAN "
1330 "ID in Access-Accept");
1333 #endif /* CONFIG_NO_VLAN */
1335 if (ap_sta_bind_vlan(hapd, sta, old_vlanid) < 0)
1338 /* RFC 3580, Ch. 3.17 */
1339 if (session_timeout_set && termination_action ==
1340 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
1341 sm->reAuthPeriod = session_timeout;
1342 } else if (session_timeout_set)
1343 ap_sta_session_timeout(hapd, sta, session_timeout);
1345 sm->eap_if->aaaSuccess = TRUE;
1346 override_eapReq = 1;
1347 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1349 ieee802_1x_store_radius_class(hapd, sta, msg);
1350 ieee802_1x_update_sta_identity(hapd, sta, msg);
1351 if (sm->eap_if->eapKeyAvailable &&
1352 wpa_auth_pmksa_add(sta->wpa_sm, sm->eapol_key_crypt,
1353 session_timeout_set ?
1354 (int) session_timeout : -1, sm) == 0) {
1355 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
1356 HOSTAPD_LEVEL_DEBUG,
1357 "Added PMKSA cache entry");
1360 case RADIUS_CODE_ACCESS_REJECT:
1361 sm->eap_if->aaaFail = TRUE;
1362 override_eapReq = 1;
1364 case RADIUS_CODE_ACCESS_CHALLENGE:
1365 sm->eap_if->aaaEapReq = TRUE;
1366 if (session_timeout_set) {
1367 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1368 sm->eap_if->aaaMethodTimeout = session_timeout;
1369 hostapd_logger(hapd, sm->addr,
1370 HOSTAPD_MODULE_IEEE8021X,
1371 HOSTAPD_LEVEL_DEBUG,
1372 "using EAP timeout of %d seconds (from "
1374 sm->eap_if->aaaMethodTimeout);
1377 * Use dynamic retransmission behavior per EAP
1380 sm->eap_if->aaaMethodTimeout = 0;
1385 ieee802_1x_decapsulate_radius(hapd, sta);
1386 if (override_eapReq)
1387 sm->eap_if->aaaEapReq = FALSE;
1389 eapol_auth_step(sm);
1391 return RADIUS_RX_QUEUED;
1393 #endif /* CONFIG_NO_RADIUS */
1396 void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
1398 struct eapol_state_machine *sm = sta->eapol_sm;
1402 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1403 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
1405 #ifndef CONFIG_NO_RADIUS
1406 radius_msg_free(sm->last_recv_radius);
1407 sm->last_recv_radius = NULL;
1408 #endif /* CONFIG_NO_RADIUS */
1410 if (sm->eap_if->eapTimeout) {
1412 * Disconnect the STA since it did not reply to the last EAP
1413 * request and we cannot continue EAP processing (EAP-Failure
1414 * could only be sent if the EAP peer actually replied).
1416 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
1417 MAC2STR(sta->addr));
1419 sm->eap_if->portEnabled = FALSE;
1420 ap_sta_disconnect(hapd, sta, sta->addr,
1421 WLAN_REASON_PREV_AUTH_NOT_VALID);
1426 static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
1428 struct eapol_authenticator *eapol = hapd->eapol_auth;
1430 if (hapd->conf->default_wep_key_len < 1)
1433 os_free(eapol->default_wep_key);
1434 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
1435 if (eapol->default_wep_key == NULL ||
1436 random_get_bytes(eapol->default_wep_key,
1437 hapd->conf->default_wep_key_len)) {
1438 printf("Could not generate random WEP key.\n");
1439 os_free(eapol->default_wep_key);
1440 eapol->default_wep_key = NULL;
1444 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
1445 eapol->default_wep_key,
1446 hapd->conf->default_wep_key_len);
1452 static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
1453 struct sta_info *sta, void *ctx)
1455 if (sta->eapol_sm) {
1456 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1457 eapol_auth_step(sta->eapol_sm);
1463 static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
1465 struct hostapd_data *hapd = eloop_ctx;
1466 struct eapol_authenticator *eapol = hapd->eapol_auth;
1468 if (eapol->default_wep_key_idx >= 3)
1469 eapol->default_wep_key_idx =
1470 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
1472 eapol->default_wep_key_idx++;
1474 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
1475 eapol->default_wep_key_idx);
1477 if (ieee802_1x_rekey_broadcast(hapd)) {
1478 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1479 HOSTAPD_LEVEL_WARNING, "failed to generate a "
1480 "new broadcast key");
1481 os_free(eapol->default_wep_key);
1482 eapol->default_wep_key = NULL;
1486 /* TODO: Could setup key for RX here, but change default TX keyid only
1487 * after new broadcast key has been sent to all stations. */
1488 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
1489 broadcast_ether_addr,
1490 eapol->default_wep_key_idx, 1, NULL, 0,
1491 eapol->default_wep_key,
1492 hapd->conf->default_wep_key_len)) {
1493 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1494 HOSTAPD_LEVEL_WARNING, "failed to configure a "
1495 "new broadcast key");
1496 os_free(eapol->default_wep_key);
1497 eapol->default_wep_key = NULL;
1501 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
1503 if (hapd->conf->wep_rekeying_period > 0) {
1504 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
1505 ieee802_1x_rekey, hapd, NULL);
1510 static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
1511 const u8 *data, size_t datalen)
1514 struct sta_info *sta = sta_ctx;
1516 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
1517 WLAN_STA_MAYBE_WPS) {
1519 size_t identity_len;
1520 struct eapol_state_machine *sm = sta->eapol_sm;
1522 identity = eap_get_identity(sm->eap, &identity_len);
1524 ((identity_len == WSC_ID_ENROLLEE_LEN &&
1525 os_memcmp(identity, WSC_ID_ENROLLEE,
1526 WSC_ID_ENROLLEE_LEN) == 0) ||
1527 (identity_len == WSC_ID_REGISTRAR_LEN &&
1528 os_memcmp(identity, WSC_ID_REGISTRAR,
1529 WSC_ID_REGISTRAR_LEN) == 0))) {
1530 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
1532 sta->flags |= WLAN_STA_WPS;
1535 #endif /* CONFIG_WPS */
1537 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
1541 static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
1542 const u8 *data, size_t datalen)
1544 #ifndef CONFIG_NO_RADIUS
1545 struct hostapd_data *hapd = ctx;
1546 struct sta_info *sta = sta_ctx;
1548 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
1549 #endif /* CONFIG_NO_RADIUS */
1553 static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
1556 struct hostapd_data *hapd = ctx;
1557 struct sta_info *sta = sta_ctx;
1559 rsn_preauth_finished(hapd, sta, success);
1561 ieee802_1x_finished(hapd, sta, success);
1565 static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
1566 size_t identity_len, int phase2,
1567 struct eap_user *user)
1569 struct hostapd_data *hapd = ctx;
1570 const struct hostapd_eap_user *eap_user;
1573 eap_user = hostapd_get_eap_user(hapd->conf, identity,
1574 identity_len, phase2);
1575 if (eap_user == NULL)
1578 os_memset(user, 0, sizeof(*user));
1579 user->phase2 = phase2;
1580 for (i = 0; i < EAP_MAX_METHODS; i++) {
1581 user->methods[i].vendor = eap_user->methods[i].vendor;
1582 user->methods[i].method = eap_user->methods[i].method;
1585 if (eap_user->password) {
1586 user->password = os_malloc(eap_user->password_len);
1587 if (user->password == NULL)
1589 os_memcpy(user->password, eap_user->password,
1590 eap_user->password_len);
1591 user->password_len = eap_user->password_len;
1592 user->password_hash = eap_user->password_hash;
1594 user->force_version = eap_user->force_version;
1595 user->ttls_auth = eap_user->ttls_auth;
1601 static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
1603 struct hostapd_data *hapd = ctx;
1604 struct sta_info *sta;
1605 sta = ap_get_sta(hapd, addr);
1606 if (sta == NULL || sta->eapol_sm == NULL)
1612 static void ieee802_1x_logger(void *ctx, const u8 *addr,
1613 eapol_logger_level level, const char *txt)
1615 #ifndef CONFIG_NO_HOSTAPD_LOGGER
1616 struct hostapd_data *hapd = ctx;
1620 case EAPOL_LOGGER_WARNING:
1621 hlevel = HOSTAPD_LEVEL_WARNING;
1623 case EAPOL_LOGGER_INFO:
1624 hlevel = HOSTAPD_LEVEL_INFO;
1626 case EAPOL_LOGGER_DEBUG:
1628 hlevel = HOSTAPD_LEVEL_DEBUG;
1632 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
1634 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
1638 static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
1641 struct hostapd_data *hapd = ctx;
1642 struct sta_info *sta = sta_ctx;
1643 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
1647 static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
1649 struct hostapd_data *hapd = ctx;
1650 struct sta_info *sta = sta_ctx;
1651 ieee802_1x_abort_auth(hapd, sta);
1655 static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
1657 struct hostapd_data *hapd = ctx;
1658 struct sta_info *sta = sta_ctx;
1659 ieee802_1x_tx_key(hapd, sta);
1663 static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
1664 enum eapol_event type)
1666 /* struct hostapd_data *hapd = ctx; */
1667 struct sta_info *sta = sta_ctx;
1669 case EAPOL_AUTH_SM_CHANGE:
1670 wpa_auth_sm_notify(sta->wpa_sm);
1672 case EAPOL_AUTH_REAUTHENTICATE:
1673 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
1679 int ieee802_1x_init(struct hostapd_data *hapd)
1682 struct eapol_auth_config conf;
1683 struct eapol_auth_cb cb;
1685 os_memset(&conf, 0, sizeof(conf));
1687 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
1688 conf.wpa = hapd->conf->wpa;
1689 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
1690 conf.eap_server = hapd->conf->eap_server;
1691 conf.ssl_ctx = hapd->ssl_ctx;
1692 conf.msg_ctx = hapd->msg_ctx;
1693 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
1694 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
1695 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
1696 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
1697 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
1698 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
1699 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
1700 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
1701 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
1702 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
1703 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
1704 conf.tnc = hapd->conf->tnc;
1705 conf.wps = hapd->wps;
1706 conf.fragment_size = hapd->conf->fragment_size;
1707 conf.pwd_group = hapd->conf->pwd_group;
1708 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
1710 os_memset(&cb, 0, sizeof(cb));
1711 cb.eapol_send = ieee802_1x_eapol_send;
1712 cb.aaa_send = ieee802_1x_aaa_send;
1713 cb.finished = _ieee802_1x_finished;
1714 cb.get_eap_user = ieee802_1x_get_eap_user;
1715 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
1716 cb.logger = ieee802_1x_logger;
1717 cb.set_port_authorized = ieee802_1x_set_port_authorized;
1718 cb.abort_auth = _ieee802_1x_abort_auth;
1719 cb.tx_key = _ieee802_1x_tx_key;
1720 cb.eapol_event = ieee802_1x_eapol_event;
1722 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
1723 if (hapd->eapol_auth == NULL)
1726 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
1727 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
1730 #ifndef CONFIG_NO_RADIUS
1731 if (radius_client_register(hapd->radius, RADIUS_AUTH,
1732 ieee802_1x_receive_auth, hapd))
1734 #endif /* CONFIG_NO_RADIUS */
1736 if (hapd->conf->default_wep_key_len) {
1737 for (i = 0; i < 4; i++)
1738 hostapd_drv_set_key(hapd->conf->iface, hapd,
1739 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
1742 ieee802_1x_rekey(hapd, NULL);
1744 if (hapd->eapol_auth->default_wep_key == NULL)
1752 void ieee802_1x_deinit(struct hostapd_data *hapd)
1754 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
1756 if (hapd->driver != NULL &&
1757 (hapd->conf->ieee802_1x || hapd->conf->wpa))
1758 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
1760 eapol_auth_deinit(hapd->eapol_auth);
1761 hapd->eapol_auth = NULL;
1765 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
1766 const u8 *buf, size_t len, int ack)
1768 struct ieee80211_hdr *hdr;
1770 const unsigned char rfc1042_hdr[ETH_ALEN] =
1771 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1775 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
1778 hdr = (struct ieee80211_hdr *) buf;
1779 pos = (u8 *) (hdr + 1);
1780 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
1782 pos += sizeof(rfc1042_hdr);
1783 if (WPA_GET_BE16(pos) != ETH_P_PAE)
1787 return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
1792 int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
1793 const u8 *buf, int len, int ack)
1795 const struct ieee802_1x_hdr *xhdr =
1796 (const struct ieee802_1x_hdr *) buf;
1797 const u8 *pos = buf + sizeof(*xhdr);
1798 struct ieee802_1x_eapol_key *key;
1800 if (len < (int) sizeof(*xhdr))
1802 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
1803 "type=%d length=%d - ack=%d",
1804 MAC2STR(sta->addr), xhdr->version, xhdr->type,
1805 be_to_host16(xhdr->length), ack);
1807 if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
1810 if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
1811 const struct wpa_eapol_key *wpa;
1812 wpa = (const struct wpa_eapol_key *) pos;
1813 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
1814 wpa->type == EAPOL_KEY_TYPE_WPA)
1815 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
1819 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
1820 * or Authenticator state machines, but EAPOL-Key packets are not
1821 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
1822 * packets couple of times because otherwise STA keys become
1823 * unsynchronized with AP. */
1824 if (!ack && pos + sizeof(*key) <= buf + len) {
1825 key = (struct ieee802_1x_eapol_key *) pos;
1826 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1827 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
1828 "frame (%scast index=%d)",
1829 key->key_index & BIT(7) ? "uni" : "broad",
1830 key->key_index & ~BIT(7));
1831 /* TODO: re-send EAPOL-Key couple of times (with short delay
1832 * between them?). If all attempt fail, report error and
1833 * deauthenticate STA so that it will get new keys when
1834 * authenticating again (e.g., after returning in range).
1835 * Separate limit/transmit state needed both for unicast and
1836 * broadcast keys(?) */
1838 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
1839 * to here and change the key only if the EAPOL-Key packet was Acked.
1846 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
1848 if (sm == NULL || sm->identity == NULL)
1851 *len = sm->identity_len;
1852 return sm->identity;
1856 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
1859 if (sm == NULL || sm->radius_class.attr == NULL ||
1860 idx >= (int) sm->radius_class.count)
1863 *len = sm->radius_class.attr[idx].len;
1864 return sm->radius_class.attr[idx].data;
1868 const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
1874 *len = sm->eap_if->eapKeyDataLen;
1875 return sm->eap_if->eapKeyData;
1879 void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
1884 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
1885 eapol_auth_step(sm);
1889 void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
1894 sm->portValid = valid ? TRUE : FALSE;
1895 eapol_auth_step(sm);
1899 void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
1904 sm->flags |= EAPOL_SM_PREAUTH;
1906 sm->flags &= ~EAPOL_SM_PREAUTH;
1910 static const char * bool_txt(Boolean bool)
1912 return bool ? "TRUE" : "FALSE";
1916 int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1923 int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1924 char *buf, size_t buflen)
1927 struct eapol_state_machine *sm = sta->eapol_sm;
1933 ret = os_snprintf(buf + len, buflen - len,
1934 "dot1xPaePortNumber=%d\n"
1935 "dot1xPaePortProtocolVersion=%d\n"
1936 "dot1xPaePortCapabilities=1\n"
1937 "dot1xPaePortInitialize=%d\n"
1938 "dot1xPaePortReauthenticate=FALSE\n",
1942 if (ret < 0 || (size_t) ret >= buflen - len)
1946 /* dot1xAuthConfigTable */
1947 ret = os_snprintf(buf + len, buflen - len,
1948 "dot1xAuthPaeState=%d\n"
1949 "dot1xAuthBackendAuthState=%d\n"
1950 "dot1xAuthAdminControlledDirections=%d\n"
1951 "dot1xAuthOperControlledDirections=%d\n"
1952 "dot1xAuthAuthControlledPortStatus=%d\n"
1953 "dot1xAuthAuthControlledPortControl=%d\n"
1954 "dot1xAuthQuietPeriod=%u\n"
1955 "dot1xAuthServerTimeout=%u\n"
1956 "dot1xAuthReAuthPeriod=%u\n"
1957 "dot1xAuthReAuthEnabled=%s\n"
1958 "dot1xAuthKeyTxEnabled=%s\n",
1959 sm->auth_pae_state + 1,
1960 sm->be_auth_state + 1,
1961 sm->adminControlledDirections,
1962 sm->operControlledDirections,
1968 bool_txt(sm->reAuthEnabled),
1969 bool_txt(sm->keyTxEnabled));
1970 if (ret < 0 || (size_t) ret >= buflen - len)
1974 /* dot1xAuthStatsTable */
1975 ret = os_snprintf(buf + len, buflen - len,
1976 "dot1xAuthEapolFramesRx=%u\n"
1977 "dot1xAuthEapolFramesTx=%u\n"
1978 "dot1xAuthEapolStartFramesRx=%u\n"
1979 "dot1xAuthEapolLogoffFramesRx=%u\n"
1980 "dot1xAuthEapolRespIdFramesRx=%u\n"
1981 "dot1xAuthEapolRespFramesRx=%u\n"
1982 "dot1xAuthEapolReqIdFramesTx=%u\n"
1983 "dot1xAuthEapolReqFramesTx=%u\n"
1984 "dot1xAuthInvalidEapolFramesRx=%u\n"
1985 "dot1xAuthEapLengthErrorFramesRx=%u\n"
1986 "dot1xAuthLastEapolFrameVersion=%u\n"
1987 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
1988 sm->dot1xAuthEapolFramesRx,
1989 sm->dot1xAuthEapolFramesTx,
1990 sm->dot1xAuthEapolStartFramesRx,
1991 sm->dot1xAuthEapolLogoffFramesRx,
1992 sm->dot1xAuthEapolRespIdFramesRx,
1993 sm->dot1xAuthEapolRespFramesRx,
1994 sm->dot1xAuthEapolReqIdFramesTx,
1995 sm->dot1xAuthEapolReqFramesTx,
1996 sm->dot1xAuthInvalidEapolFramesRx,
1997 sm->dot1xAuthEapLengthErrorFramesRx,
1998 sm->dot1xAuthLastEapolFrameVersion,
2000 if (ret < 0 || (size_t) ret >= buflen - len)
2004 /* dot1xAuthDiagTable */
2005 ret = os_snprintf(buf + len, buflen - len,
2006 "dot1xAuthEntersConnecting=%u\n"
2007 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2008 "dot1xAuthEntersAuthenticating=%u\n"
2009 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2010 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2011 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2012 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2013 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2014 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2015 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2016 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2017 "dot1xAuthBackendResponses=%u\n"
2018 "dot1xAuthBackendAccessChallenges=%u\n"
2019 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2020 "dot1xAuthBackendAuthSuccesses=%u\n"
2021 "dot1xAuthBackendAuthFails=%u\n",
2022 sm->authEntersConnecting,
2023 sm->authEapLogoffsWhileConnecting,
2024 sm->authEntersAuthenticating,
2025 sm->authAuthSuccessesWhileAuthenticating,
2026 sm->authAuthTimeoutsWhileAuthenticating,
2027 sm->authAuthFailWhileAuthenticating,
2028 sm->authAuthEapStartsWhileAuthenticating,
2029 sm->authAuthEapLogoffWhileAuthenticating,
2030 sm->authAuthReauthsWhileAuthenticated,
2031 sm->authAuthEapStartsWhileAuthenticated,
2032 sm->authAuthEapLogoffWhileAuthenticated,
2033 sm->backendResponses,
2034 sm->backendAccessChallenges,
2035 sm->backendOtherRequestsToSupplicant,
2036 sm->backendAuthSuccesses,
2037 sm->backendAuthFails);
2038 if (ret < 0 || (size_t) ret >= buflen - len)
2042 /* dot1xAuthSessionStatsTable */
2044 ret = os_snprintf(buf + len, buflen - len,
2045 /* TODO: dot1xAuthSessionOctetsRx */
2046 /* TODO: dot1xAuthSessionOctetsTx */
2047 /* TODO: dot1xAuthSessionFramesRx */
2048 /* TODO: dot1xAuthSessionFramesTx */
2049 "dot1xAuthSessionId=%08X-%08X\n"
2050 "dot1xAuthSessionAuthenticMethod=%d\n"
2051 "dot1xAuthSessionTime=%u\n"
2052 "dot1xAuthSessionTerminateCause=999\n"
2053 "dot1xAuthSessionUserName=%s\n",
2054 sta->acct_session_id_hi, sta->acct_session_id_lo,
2055 (wpa_key_mgmt_wpa_ieee8021x(
2056 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2058 (unsigned int) (t.sec - sta->acct_session_start),
2060 if (ret < 0 || (size_t) ret >= buflen - len)
2068 static void ieee802_1x_finished(struct hostapd_data *hapd,
2069 struct sta_info *sta, int success)
2073 /* TODO: get PMKLifetime from WPA parameters */
2074 static const int dot11RSNAConfigPMKLifetime = 43200;
2076 key = ieee802_1x_get_key(sta->eapol_sm, &len);
2077 if (success && key && len >= PMK_LEN &&
2078 wpa_auth_pmksa_add(sta->wpa_sm, key, dot11RSNAConfigPMKLifetime,
2079 sta->eapol_sm) == 0) {
2080 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2081 HOSTAPD_LEVEL_DEBUG,
2082 "Added PMKSA cache entry (IEEE 802.1X)");
2087 * Many devices require deauthentication after WPS provisioning
2088 * and some may not be be able to do that themselves, so
2089 * disconnect the client here. In addition, this may also
2090 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2091 * the EAPOL PAE state machine would remain in HELD state for
2092 * considerable amount of time and some EAP methods, like
2093 * EAP-FAST with anonymous provisioning, may require another
2094 * EAPOL authentication to be started to complete connection.
2096 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "IEEE 802.1X: Force "
2097 "disconnection after EAP-Failure");
2098 /* Add a small sleep to increase likelihood of previously
2099 * requested EAP-Failure TX getting out before this should the
2100 * driver reorder operations.
2103 ap_sta_disconnect(hapd, sta, sta->addr,
2104 WLAN_REASON_IEEE_802_1X_AUTH_FAILED);