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 "wps_hostapd.h"
34 /* FIX: Not really a good thing to require ieee802_11.h here.. (FILS) */
35 #include "ieee802_11.h"
36 #include "ieee802_1x.h"
40 static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx);
41 #endif /* CONFIG_HS20 */
42 static void ieee802_1x_finished(struct hostapd_data *hapd,
43 struct sta_info *sta, int success,
47 static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
48 u8 type, const u8 *data, size_t datalen)
51 struct ieee802_1x_hdr *xhdr;
55 len = sizeof(*xhdr) + datalen;
58 wpa_printf(MSG_ERROR, "malloc() failed for "
59 "ieee802_1x_send(len=%lu)",
64 xhdr = (struct ieee802_1x_hdr *) buf;
65 xhdr->version = hapd->conf->eapol_version;
67 xhdr->length = host_to_be16(datalen);
69 if (datalen > 0 && data != NULL)
70 os_memcpy(xhdr + 1, data, datalen);
72 if (wpa_auth_pairwise_set(sta->wpa_sm))
74 #ifdef CONFIG_TESTING_OPTIONS
75 if (hapd->ext_eapol_frame_io) {
76 size_t hex_len = 2 * len + 1;
77 char *hex = os_malloc(hex_len);
80 wpa_snprintf_hex(hex, hex_len, buf, len);
81 wpa_msg(hapd->msg_ctx, MSG_INFO,
82 "EAPOL-TX " MACSTR " %s",
83 MAC2STR(sta->addr), hex);
87 #endif /* CONFIG_TESTING_OPTIONS */
88 if (sta->flags & WLAN_STA_PREAUTH) {
89 rsn_preauth_send(hapd, sta, buf, len);
91 hostapd_drv_hapd_send_eapol(
92 hapd, sta->addr, buf, len,
93 encrypt, hostapd_sta_flags_to_drv(sta->flags));
100 void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
101 struct sta_info *sta, int authorized)
105 if (sta->flags & WLAN_STA_PREAUTH)
109 ap_sta_set_authorized(hapd, sta, 1);
110 res = hostapd_set_authorized(hapd, sta, 1);
111 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
112 HOSTAPD_LEVEL_DEBUG, "authorizing port");
114 ap_sta_set_authorized(hapd, sta, 0);
115 res = hostapd_set_authorized(hapd, sta, 0);
116 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
117 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
120 if (res && errno != ENOENT) {
121 wpa_printf(MSG_DEBUG, "Could not set station " MACSTR
122 " flags for kernel driver (errno=%d).",
123 MAC2STR(sta->addr), errno);
127 os_get_reltime(&sta->connected_time);
128 accounting_sta_start(hapd, sta);
134 #ifndef CONFIG_NO_RC4
136 static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
137 struct sta_info *sta,
138 int idx, int broadcast,
139 u8 *key_data, size_t key_len)
142 struct ieee802_1x_hdr *hdr;
143 struct ieee802_1x_eapol_key *key;
144 size_t len, ekey_len;
145 struct eapol_state_machine *sm = sta->eapol_sm;
150 len = sizeof(*key) + key_len;
151 buf = os_zalloc(sizeof(*hdr) + len);
155 hdr = (struct ieee802_1x_hdr *) buf;
156 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
157 key->type = EAPOL_KEY_TYPE_RC4;
158 WPA_PUT_BE16(key->key_length, key_len);
159 wpa_get_ntp_timestamp(key->replay_counter);
161 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
162 wpa_printf(MSG_ERROR, "Could not get random numbers");
167 key->key_index = idx | (broadcast ? 0 : BIT(7));
168 if (hapd->conf->eapol_key_index_workaround) {
169 /* According to some information, WinXP Supplicant seems to
170 * interpret bit7 as an indication whether the key is to be
171 * activated, so make it possible to enable workaround that
172 * sets this bit for all keys. */
173 key->key_index |= BIT(7);
176 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
177 * MSK[32..63] is used to sign the message. */
178 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
179 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
180 "and signing EAPOL-Key");
184 os_memcpy((u8 *) (key + 1), key_data, key_len);
185 ekey_len = sizeof(key->key_iv) + 32;
186 ekey = os_malloc(ekey_len);
188 wpa_printf(MSG_ERROR, "Could not encrypt key");
192 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
193 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
194 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
197 /* This header is needed here for HMAC-MD5, but it will be regenerated
198 * in ieee802_1x_send() */
199 hdr->version = hapd->conf->eapol_version;
200 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
201 hdr->length = host_to_be16(len);
202 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
205 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
206 " (%s index=%d)", MAC2STR(sm->addr),
207 broadcast ? "broadcast" : "unicast", idx);
208 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
210 sta->eapol_sm->dot1xAuthEapolFramesTx++;
215 static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
217 struct eapol_authenticator *eapol = hapd->eapol_auth;
218 struct eapol_state_machine *sm = sta->eapol_sm;
220 if (sm == NULL || !sm->eap_if->eapKeyData)
223 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
226 #ifndef CONFIG_NO_VLAN
227 if (sta->vlan_id > 0) {
228 wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
231 #endif /* CONFIG_NO_VLAN */
233 if (eapol->default_wep_key) {
234 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
235 eapol->default_wep_key,
236 hapd->conf->default_wep_key_len);
239 if (hapd->conf->individual_wep_key_len > 0) {
241 ikey = os_malloc(hapd->conf->individual_wep_key_len);
243 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
245 wpa_printf(MSG_ERROR, "Could not generate random "
246 "individual WEP key.");
251 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
252 ikey, hapd->conf->individual_wep_key_len);
254 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
255 hapd->conf->individual_wep_key_len);
257 /* TODO: set encryption in TX callback, i.e., only after STA
258 * has ACKed EAPOL-Key frame */
259 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
260 sta->addr, 0, 1, NULL, 0, ikey,
261 hapd->conf->individual_wep_key_len)) {
262 wpa_printf(MSG_ERROR, "Could not set individual WEP "
270 #endif /* CONFIG_NO_RC4 */
271 #endif /* CONFIG_FIPS */
274 const char *radius_mode_txt(struct hostapd_data *hapd)
276 switch (hapd->iface->conf->hw_mode) {
277 case HOSTAPD_MODE_IEEE80211AD:
279 case HOSTAPD_MODE_IEEE80211A:
281 case HOSTAPD_MODE_IEEE80211G:
283 case HOSTAPD_MODE_IEEE80211B:
290 int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
295 for (i = 0; i < sta->supported_rates_len; i++)
296 if ((sta->supported_rates[i] & 0x7f) > rate)
297 rate = sta->supported_rates[i] & 0x7f;
303 #ifndef CONFIG_NO_RADIUS
304 static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
305 struct eapol_state_machine *sm,
306 const u8 *eap, size_t len)
310 const struct eap_hdr *hdr = (const struct eap_hdr *) eap;
312 if (len <= sizeof(struct eap_hdr) ||
313 (hdr->code == EAP_CODE_RESPONSE &&
314 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) ||
315 (hdr->code == EAP_CODE_INITIATE &&
316 eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) ||
317 (hdr->code != EAP_CODE_RESPONSE &&
318 hdr->code != EAP_CODE_INITIATE))
321 eap_erp_update_identity(sm->eap, eap, len);
322 identity = eap_get_identity(sm->eap, &identity_len);
323 if (identity == NULL)
326 /* Save station identity for future RADIUS packets */
327 os_free(sm->identity);
328 sm->identity = (u8 *) dup_binstr(identity, identity_len);
329 if (sm->identity == NULL) {
330 sm->identity_len = 0;
334 sm->identity_len = identity_len;
335 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
336 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
337 sm->dot1xAuthEapolRespIdFramesRx++;
341 static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd,
342 struct hostapd_radius_attr *req_attr,
343 struct sta_info *sta,
344 struct radius_msg *msg)
349 ver = wpa_auth_sta_wpa_version(sta->wpa_sm);
350 val = wpa_auth_get_pairwise(sta->wpa_sm);
351 suite = wpa_cipher_to_suite(ver, val);
353 !hostapd_config_get_radius_attr(req_attr,
354 RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) &&
355 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER,
357 wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher");
361 suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) ||
363 WPA_PROTO_RSN : WPA_PROTO_WPA,
364 hapd->conf->wpa_group);
365 if (!hostapd_config_get_radius_attr(req_attr,
366 RADIUS_ATTR_WLAN_GROUP_CIPHER) &&
367 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER,
369 wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher");
373 val = wpa_auth_sta_key_mgmt(sta->wpa_sm);
374 suite = wpa_akm_to_suite(val);
376 !hostapd_config_get_radius_attr(req_attr,
377 RADIUS_ATTR_WLAN_AKM_SUITE) &&
378 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE,
380 wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite");
384 #ifdef CONFIG_IEEE80211W
385 if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
386 suite = wpa_cipher_to_suite(WPA_PROTO_RSN,
387 hapd->conf->group_mgmt_cipher);
388 if (!hostapd_config_get_radius_attr(
389 req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) &&
390 !radius_msg_add_attr_int32(
391 msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) {
392 wpa_printf(MSG_ERROR,
393 "Could not add WLAN-Group-Mgmt-Cipher");
397 #endif /* CONFIG_IEEE80211W */
403 static int add_common_radius_sta_attr(struct hostapd_data *hapd,
404 struct hostapd_radius_attr *req_attr,
405 struct sta_info *sta,
406 struct radius_msg *msg)
410 if (!hostapd_config_get_radius_attr(req_attr,
411 RADIUS_ATTR_SERVICE_TYPE) &&
412 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_SERVICE_TYPE,
413 RADIUS_SERVICE_TYPE_FRAMED)) {
414 wpa_printf(MSG_ERROR, "Could not add Service-Type");
418 if (!hostapd_config_get_radius_attr(req_attr,
419 RADIUS_ATTR_NAS_PORT) &&
421 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
422 wpa_printf(MSG_ERROR, "Could not add NAS-Port");
426 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
428 buf[sizeof(buf) - 1] = '\0';
429 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
430 (u8 *) buf, os_strlen(buf))) {
431 wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id");
435 if (sta->flags & WLAN_STA_PREAUTH) {
436 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
439 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
440 radius_sta_rate(hapd, sta) / 2,
441 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
442 radius_mode_txt(hapd));
443 buf[sizeof(buf) - 1] = '\0';
445 if (!hostapd_config_get_radius_attr(req_attr,
446 RADIUS_ATTR_CONNECT_INFO) &&
447 !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
448 (u8 *) buf, os_strlen(buf))) {
449 wpa_printf(MSG_ERROR, "Could not add Connect-Info");
453 if (sta->acct_session_id) {
454 os_snprintf(buf, sizeof(buf), "%016llX",
455 (unsigned long long) sta->acct_session_id);
456 if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
457 (u8 *) buf, os_strlen(buf))) {
458 wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
463 if ((hapd->conf->wpa & 2) &&
464 !hapd->conf->disable_pmksa_caching &&
465 sta->eapol_sm && sta->eapol_sm->acct_multi_session_id) {
466 os_snprintf(buf, sizeof(buf), "%016llX",
468 sta->eapol_sm->acct_multi_session_id);
469 if (!radius_msg_add_attr(
470 msg, RADIUS_ATTR_ACCT_MULTI_SESSION_ID,
471 (u8 *) buf, os_strlen(buf))) {
473 "Could not add Acct-Multi-Session-Id");
478 #ifdef CONFIG_IEEE80211R_AP
479 if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
481 (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) ||
482 sta->auth_alg == WLAN_AUTH_FT) &&
483 !hostapd_config_get_radius_attr(req_attr,
484 RADIUS_ATTR_MOBILITY_DOMAIN_ID) &&
485 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID,
487 hapd->conf->mobility_domain))) {
488 wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id");
491 #endif /* CONFIG_IEEE80211R_AP */
493 if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm &&
494 add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0)
501 int add_common_radius_attr(struct hostapd_data *hapd,
502 struct hostapd_radius_attr *req_attr,
503 struct sta_info *sta,
504 struct radius_msg *msg)
507 struct hostapd_radius_attr *attr;
510 if (!hostapd_config_get_radius_attr(req_attr,
511 RADIUS_ATTR_NAS_IP_ADDRESS) &&
512 hapd->conf->own_ip_addr.af == AF_INET &&
513 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
514 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
515 wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address");
520 if (!hostapd_config_get_radius_attr(req_attr,
521 RADIUS_ATTR_NAS_IPV6_ADDRESS) &&
522 hapd->conf->own_ip_addr.af == AF_INET6 &&
523 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
524 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
525 wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address");
528 #endif /* CONFIG_IPV6 */
530 if (!hostapd_config_get_radius_attr(req_attr,
531 RADIUS_ATTR_NAS_IDENTIFIER) &&
532 hapd->conf->nas_identifier &&
533 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
534 (u8 *) hapd->conf->nas_identifier,
535 os_strlen(hapd->conf->nas_identifier))) {
536 wpa_printf(MSG_ERROR, "Could not add NAS-Identifier");
540 len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
541 MAC2STR(hapd->own_addr));
542 os_memcpy(&buf[len], hapd->conf->ssid.ssid,
543 hapd->conf->ssid.ssid_len);
544 len += hapd->conf->ssid.ssid_len;
545 if (!hostapd_config_get_radius_attr(req_attr,
546 RADIUS_ATTR_CALLED_STATION_ID) &&
547 !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
549 wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
553 if (!hostapd_config_get_radius_attr(req_attr,
554 RADIUS_ATTR_NAS_PORT_TYPE) &&
555 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
556 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
557 wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type");
561 #ifdef CONFIG_INTERWORKING
562 if (hapd->conf->interworking &&
563 !is_zero_ether_addr(hapd->conf->hessid)) {
564 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
565 MAC2STR(hapd->conf->hessid));
566 buf[sizeof(buf) - 1] = '\0';
567 if (!hostapd_config_get_radius_attr(req_attr,
568 RADIUS_ATTR_WLAN_HESSID) &&
569 !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID,
570 (u8 *) buf, os_strlen(buf))) {
571 wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID");
575 #endif /* CONFIG_INTERWORKING */
577 if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0)
580 for (attr = req_attr; attr; attr = attr->next) {
581 if (!radius_msg_add_attr(msg, attr->type,
582 wpabuf_head(attr->val),
583 wpabuf_len(attr->val))) {
584 wpa_printf(MSG_ERROR, "Could not add RADIUS "
594 void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
595 struct sta_info *sta,
596 const u8 *eap, size_t len)
598 struct radius_msg *msg;
599 struct eapol_state_machine *sm = sta->eapol_sm;
604 ieee802_1x_learn_identity(hapd, sm, eap, len);
606 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
609 sm->radius_identifier = radius_client_get_id(hapd->radius);
610 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
611 sm->radius_identifier);
613 wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
617 if (radius_msg_make_authenticator(msg) < 0) {
618 wpa_printf(MSG_INFO, "Could not make Request Authenticator");
623 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
624 sm->identity, sm->identity_len)) {
625 wpa_printf(MSG_INFO, "Could not add User-Name");
629 if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
633 /* TODO: should probably check MTU from driver config; 2304 is max for
634 * IEEE 802.11, but use 1400 to avoid problems with too large packets
636 if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
637 RADIUS_ATTR_FRAMED_MTU) &&
638 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
639 wpa_printf(MSG_INFO, "Could not add Framed-MTU");
643 if (!radius_msg_add_eap(msg, eap, len)) {
644 wpa_printf(MSG_INFO, "Could not add EAP-Message");
648 /* State attribute must be copied if and only if this packet is
649 * Access-Request reply to the previous Access-Challenge */
650 if (sm->last_recv_radius &&
651 radius_msg_get_hdr(sm->last_recv_radius)->code ==
652 RADIUS_CODE_ACCESS_CHALLENGE) {
653 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
656 wpa_printf(MSG_INFO, "Could not copy State attribute from previous Access-Challenge");
660 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
664 if (hapd->conf->radius_request_cui) {
667 /* Add previously learned CUI or nul CUI to request CUI */
668 if (sm->radius_cui) {
669 cui = wpabuf_head(sm->radius_cui);
670 cui_len = wpabuf_len(sm->radius_cui);
672 cui = (const u8 *) "\0";
675 if (!radius_msg_add_attr(msg,
676 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
678 wpa_printf(MSG_ERROR, "Could not add CUI");
684 if (hapd->conf->hs20) {
685 u8 ver = 1; /* Release 2 */
686 if (HS20_VERSION > 0x10)
687 ver = 2; /* Release 3 */
688 if (!radius_msg_add_wfa(
689 msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION,
691 wpa_printf(MSG_ERROR, "Could not add HS 2.0 AP "
696 if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) {
700 pos = wpabuf_head_u8(sta->hs20_ie);
701 buf[0] = (*pos) >> 4;
702 if (((*pos) & HS20_PPS_MO_ID_PRESENT) &&
703 wpabuf_len(sta->hs20_ie) >= 3)
704 id = WPA_GET_LE16(pos + 1);
707 WPA_PUT_BE16(buf + 1, id);
708 if (!radius_msg_add_wfa(
710 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION,
712 wpa_printf(MSG_ERROR, "Could not add HS 2.0 "
718 if (sta->roaming_consortium &&
720 msg, RADIUS_VENDOR_ATTR_WFA_HS20_ROAMING_CONSORTIUM,
721 wpabuf_head(sta->roaming_consortium),
722 wpabuf_len(sta->roaming_consortium))) {
723 wpa_printf(MSG_ERROR,
724 "Could not add HS 2.0 Roaming Consortium");
728 if (hapd->conf->t_c_filename) {
731 if (!radius_msg_add_wfa(
733 RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILENAME,
734 (const u8 *) hapd->conf->t_c_filename,
735 os_strlen(hapd->conf->t_c_filename))) {
736 wpa_printf(MSG_ERROR,
737 "Could not add HS 2.0 T&C Filename");
741 timestamp = host_to_be32(hapd->conf->t_c_timestamp);
742 if (!radius_msg_add_wfa(
744 RADIUS_VENDOR_ATTR_WFA_HS20_TIMESTAMP,
745 (const u8 *) ×tamp,
746 sizeof(timestamp))) {
747 wpa_printf(MSG_ERROR,
748 "Could not add HS 2.0 Timestamp");
753 #endif /* CONFIG_HS20 */
755 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
761 radius_msg_free(msg);
763 #endif /* CONFIG_NO_RADIUS */
766 static void handle_eap_response(struct hostapd_data *hapd,
767 struct sta_info *sta, struct eap_hdr *eap,
771 struct eapol_state_machine *sm = sta->eapol_sm;
775 data = (u8 *) (eap + 1);
777 if (len < sizeof(*eap) + 1) {
778 wpa_printf(MSG_INFO, "handle_eap_response: too short response data");
782 sm->eap_type_supp = type = data[0];
784 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
785 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
786 "id=%d len=%d) from STA: EAP Response-%s (%d)",
787 eap->code, eap->identifier, be_to_host16(eap->length),
788 eap_server_get_name(0, type), type);
790 sm->dot1xAuthEapolRespFramesRx++;
792 wpabuf_free(sm->eap_if->eapRespData);
793 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
798 static void handle_eap_initiate(struct hostapd_data *hapd,
799 struct sta_info *sta, struct eap_hdr *eap,
804 struct eapol_state_machine *sm = sta->eapol_sm;
809 if (len < sizeof(*eap) + 1) {
811 "handle_eap_initiate: too short response data");
815 data = (u8 *) (eap + 1);
818 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
819 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
820 "id=%d len=%d) from STA: EAP Initiate type %u",
821 eap->code, eap->identifier, be_to_host16(eap->length),
824 wpabuf_free(sm->eap_if->eapRespData);
825 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
827 #endif /* CONFIG_ERP */
831 /* Process incoming EAP packet from Supplicant */
832 static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
838 if (len < sizeof(*eap)) {
839 wpa_printf(MSG_INFO, " too short EAP packet");
843 eap = (struct eap_hdr *) buf;
845 eap_len = be_to_host16(eap->length);
846 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
847 eap->code, eap->identifier, eap_len);
848 if (eap_len < sizeof(*eap)) {
849 wpa_printf(MSG_DEBUG, " Invalid EAP length");
851 } else if (eap_len > len) {
852 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
855 } else if (eap_len < len) {
856 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
857 "packet", (unsigned long) len - eap_len);
861 case EAP_CODE_REQUEST:
862 wpa_printf(MSG_DEBUG, " (request)");
864 case EAP_CODE_RESPONSE:
865 wpa_printf(MSG_DEBUG, " (response)");
866 handle_eap_response(hapd, sta, eap, eap_len);
868 case EAP_CODE_SUCCESS:
869 wpa_printf(MSG_DEBUG, " (success)");
871 case EAP_CODE_FAILURE:
872 wpa_printf(MSG_DEBUG, " (failure)");
874 case EAP_CODE_INITIATE:
875 wpa_printf(MSG_DEBUG, " (initiate)");
876 handle_eap_initiate(hapd, sta, eap, eap_len);
878 case EAP_CODE_FINISH:
879 wpa_printf(MSG_DEBUG, " (finish)");
882 wpa_printf(MSG_DEBUG, " (unknown code)");
888 struct eapol_state_machine *
889 ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
892 if (sta->flags & WLAN_STA_PREAUTH)
893 flags |= EAPOL_SM_PREAUTH;
895 flags |= EAPOL_SM_USES_WPA;
896 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
897 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
899 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
900 sta->wps_ie, sta->p2p_ie, sta,
901 sta->identity, sta->radius_cui);
905 static void ieee802_1x_save_eapol(struct sta_info *sta, const u8 *buf,
908 if (sta->pending_eapol_rx) {
909 wpabuf_free(sta->pending_eapol_rx->buf);
911 sta->pending_eapol_rx =
912 os_malloc(sizeof(*sta->pending_eapol_rx));
913 if (!sta->pending_eapol_rx)
917 sta->pending_eapol_rx->buf = wpabuf_alloc_copy(buf, len);
918 if (!sta->pending_eapol_rx->buf) {
919 os_free(sta->pending_eapol_rx);
920 sta->pending_eapol_rx = NULL;
924 os_get_reltime(&sta->pending_eapol_rx->rx_time);
929 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
930 * @hapd: hostapd BSS data
931 * @sa: Source address (sender of the EAPOL frame)
933 * @len: Length of buf in octets
935 * This function is called for each incoming EAPOL frame from the interface
937 void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
940 struct sta_info *sta;
941 struct ieee802_1x_hdr *hdr;
942 struct ieee802_1x_eapol_key *key;
944 struct rsn_pmksa_cache_entry *pmksa;
947 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen &&
948 !hapd->conf->wps_state)
951 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
952 (unsigned long) len, MAC2STR(sa));
953 sta = ap_get_sta(hapd, sa);
954 if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
955 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
956 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
957 "associated/Pre-authenticating STA");
959 if (sta && (sta->flags & WLAN_STA_AUTH)) {
960 wpa_printf(MSG_DEBUG, "Saving EAPOL frame from " MACSTR
961 " for later use", MAC2STR(sta->addr));
962 ieee802_1x_save_eapol(sta, buf, len);
968 if (len < sizeof(*hdr)) {
969 wpa_printf(MSG_INFO, " too short IEEE 802.1X packet");
973 hdr = (struct ieee802_1x_hdr *) buf;
974 datalen = be_to_host16(hdr->length);
975 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
976 hdr->version, hdr->type, datalen);
978 if (len - sizeof(*hdr) < datalen) {
979 wpa_printf(MSG_INFO, " frame too short for this IEEE 802.1X packet");
981 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
984 if (len - sizeof(*hdr) > datalen) {
985 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
986 "IEEE 802.1X packet",
987 (unsigned long) len - sizeof(*hdr) - datalen);
991 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
992 sta->eapol_sm->dot1xAuthEapolFramesRx++;
995 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
996 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
997 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
998 (key->type == EAPOL_KEY_TYPE_WPA ||
999 key->type == EAPOL_KEY_TYPE_RSN)) {
1000 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
1001 sizeof(*hdr) + datalen);
1005 if (!hapd->conf->ieee802_1x && !hapd->conf->osen &&
1006 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
1007 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1008 "802.1X not enabled and WPS not used");
1012 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
1013 if (key_mgmt != -1 &&
1014 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1015 key_mgmt == WPA_KEY_MGMT_DPP)) {
1016 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1017 "STA is using PSK");
1021 if (!sta->eapol_sm) {
1022 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1027 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) {
1028 u32 wflags = sta->flags & (WLAN_STA_WPS |
1030 WLAN_STA_MAYBE_WPS);
1031 if (wflags == WLAN_STA_MAYBE_WPS ||
1032 wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
1034 * Delay EAPOL frame transmission until a
1035 * possible WPS STA initiates the handshake
1036 * with EAPOL-Start. Only allow the wait to be
1037 * skipped if the STA is known to support WPS
1040 wpa_printf(MSG_DEBUG, "WPS: Do not start "
1041 "EAPOL until EAPOL-Start is "
1043 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1046 #endif /* CONFIG_WPS */
1048 sta->eapol_sm->eap_if->portEnabled = TRUE;
1051 /* since we support version 1, we can ignore version field and proceed
1052 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
1053 /* TODO: actually, we are not version 1 anymore.. However, Version 2
1054 * does not change frame contents, so should be ok to process frames
1055 * more or less identically. Some changes might be needed for
1056 * verification of fields. */
1058 switch (hdr->type) {
1059 case IEEE802_1X_TYPE_EAP_PACKET:
1060 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
1063 case IEEE802_1X_TYPE_EAPOL_START:
1064 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1065 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
1067 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
1068 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1070 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
1071 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
1072 "available - ignore it since "
1073 "STA sent EAPOL-Start");
1074 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
1076 sta->eapol_sm->eapolStart = TRUE;
1077 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
1078 eap_server_clear_identity(sta->eapol_sm->eap);
1079 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
1082 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
1083 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1084 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
1086 sta->acct_terminate_cause =
1087 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1088 accounting_sta_stop(hapd, sta);
1089 sta->eapol_sm->eapolLogoff = TRUE;
1090 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
1091 eap_server_clear_identity(sta->eapol_sm->eap);
1094 case IEEE802_1X_TYPE_EAPOL_KEY:
1095 wpa_printf(MSG_DEBUG, " EAPOL-Key");
1096 if (!ap_sta_is_authorized(sta)) {
1097 wpa_printf(MSG_DEBUG, " Dropped key data from "
1098 "unauthorized Supplicant");
1103 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
1104 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
1105 /* TODO: implement support for this; show data */
1109 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
1110 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
1114 eapol_auth_step(sta->eapol_sm);
1119 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1120 * @hapd: hostapd BSS data
1123 * This function is called to start IEEE 802.1X authentication when a new
1124 * station completes IEEE 802.11 association.
1126 void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
1128 struct rsn_pmksa_cache_entry *pmksa;
1134 if (hapd->conf->wps_state &&
1135 ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) ||
1136 (sta->flags & WLAN_STA_WPS))) {
1138 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1139 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1140 * authentication in this BSS.
1144 #endif /* CONFIG_WPS */
1146 if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) {
1147 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
1148 "802.1X not enabled or forced for WPS");
1150 * Clear any possible EAPOL authenticator state to support
1151 * reassociation change from WPS to PSK.
1153 ieee802_1x_free_station(hapd, sta);
1157 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
1158 if (key_mgmt != -1 &&
1159 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1160 key_mgmt == WPA_KEY_MGMT_DPP)) {
1161 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
1163 * Clear any possible EAPOL authenticator state to support
1164 * reassociation change from WPA-EAP to PSK.
1166 ieee802_1x_free_station(hapd, sta);
1170 if (sta->eapol_sm == NULL) {
1171 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1172 HOSTAPD_LEVEL_DEBUG, "start authentication");
1173 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1174 if (sta->eapol_sm == NULL) {
1175 hostapd_logger(hapd, sta->addr,
1176 HOSTAPD_MODULE_IEEE8021X,
1178 "failed to allocate state machine");
1185 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
1186 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state &&
1187 !(sta->flags & WLAN_STA_WPS2)) {
1189 * Delay EAPOL frame transmission until a possible WPS STA
1190 * initiates the handshake with EAPOL-Start. Only allow the
1191 * wait to be skipped if the STA is known to support WPS 2.0.
1193 wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
1194 "EAPOL-Start is received");
1195 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1197 #endif /* CONFIG_WPS */
1199 sta->eapol_sm->eap_if->portEnabled = TRUE;
1201 #ifdef CONFIG_IEEE80211R_AP
1202 if (sta->auth_alg == WLAN_AUTH_FT) {
1203 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1204 HOSTAPD_LEVEL_DEBUG,
1205 "PMK from FT - skip IEEE 802.1X/EAP");
1206 /* Setup EAPOL state machines to already authenticated state
1207 * because of existing FT information from R0KH. */
1208 sta->eapol_sm->keyRun = TRUE;
1209 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1210 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1211 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1212 sta->eapol_sm->authSuccess = TRUE;
1213 sta->eapol_sm->authFail = FALSE;
1214 sta->eapol_sm->portValid = TRUE;
1215 if (sta->eapol_sm->eap)
1216 eap_sm_notify_cached(sta->eapol_sm->eap);
1217 ap_sta_bind_vlan(hapd, sta);
1220 #endif /* CONFIG_IEEE80211R_AP */
1223 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
1224 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
1225 sta->auth_alg == WLAN_AUTH_FILS_PK) {
1226 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1227 HOSTAPD_LEVEL_DEBUG,
1228 "PMK from FILS - skip IEEE 802.1X/EAP");
1229 /* Setup EAPOL state machines to already authenticated state
1230 * because of existing FILS information. */
1231 sta->eapol_sm->keyRun = TRUE;
1232 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1233 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1234 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1235 sta->eapol_sm->authSuccess = TRUE;
1236 sta->eapol_sm->authFail = FALSE;
1237 sta->eapol_sm->portValid = TRUE;
1238 if (sta->eapol_sm->eap)
1239 eap_sm_notify_cached(sta->eapol_sm->eap);
1242 #endif /* CONFIG_FILS */
1244 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1246 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1247 HOSTAPD_LEVEL_DEBUG,
1248 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1249 /* Setup EAPOL state machines to already authenticated state
1250 * because of existing PMKSA information in the cache. */
1251 sta->eapol_sm->keyRun = TRUE;
1252 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1253 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1254 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1255 sta->eapol_sm->authSuccess = TRUE;
1256 sta->eapol_sm->authFail = FALSE;
1257 if (sta->eapol_sm->eap)
1258 eap_sm_notify_cached(sta->eapol_sm->eap);
1259 pmksa_cache_to_eapol_data(hapd, pmksa, sta->eapol_sm);
1260 ap_sta_bind_vlan(hapd, sta);
1264 * Force EAPOL state machines to start
1265 * re-authentication without having to wait for the
1266 * Supplicant to send EAPOL-Start.
1268 sta->eapol_sm->reAuthenticate = TRUE;
1270 eapol_auth_step(sta->eapol_sm);
1275 void ieee802_1x_free_station(struct hostapd_data *hapd, struct sta_info *sta)
1277 struct eapol_state_machine *sm = sta->eapol_sm;
1280 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
1281 #endif /* CONFIG_HS20 */
1283 if (sta->pending_eapol_rx) {
1284 wpabuf_free(sta->pending_eapol_rx->buf);
1285 os_free(sta->pending_eapol_rx);
1286 sta->pending_eapol_rx = NULL;
1292 sta->eapol_sm = NULL;
1294 #ifndef CONFIG_NO_RADIUS
1295 radius_msg_free(sm->last_recv_radius);
1296 radius_free_class(&sm->radius_class);
1297 #endif /* CONFIG_NO_RADIUS */
1299 eapol_auth_free(sm);
1303 #ifndef CONFIG_NO_RADIUS
1304 static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
1305 struct sta_info *sta)
1308 const struct eap_hdr *hdr;
1311 struct radius_msg *msg;
1312 struct eapol_state_machine *sm = sta->eapol_sm;
1314 if (sm == NULL || sm->last_recv_radius == NULL) {
1316 sm->eap_if->aaaEapNoReq = TRUE;
1320 msg = sm->last_recv_radius;
1322 eap = radius_msg_get_eap(msg);
1324 /* RFC 3579, Chap. 2.6.3:
1325 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1327 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1328 HOSTAPD_LEVEL_WARNING, "could not extract "
1329 "EAP-Message from RADIUS message");
1330 sm->eap_if->aaaEapNoReq = TRUE;
1334 if (wpabuf_len(eap) < sizeof(*hdr)) {
1335 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1336 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1337 "received from authentication server");
1339 sm->eap_if->aaaEapNoReq = TRUE;
1343 if (wpabuf_len(eap) > sizeof(*hdr))
1344 eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)];
1346 hdr = wpabuf_head(eap);
1347 switch (hdr->code) {
1348 case EAP_CODE_REQUEST:
1350 sm->eap_type_authsrv = eap_type;
1351 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
1352 eap_server_get_name(0, eap_type), eap_type);
1354 case EAP_CODE_RESPONSE:
1355 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
1356 eap_server_get_name(0, eap_type), eap_type);
1358 case EAP_CODE_SUCCESS:
1359 os_strlcpy(buf, "EAP Success", sizeof(buf));
1361 case EAP_CODE_FAILURE:
1362 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1365 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1368 buf[sizeof(buf) - 1] = '\0';
1369 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1370 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1371 "id=%d len=%d) from RADIUS server: %s",
1372 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1374 sm->eap_if->aaaEapReq = TRUE;
1376 wpabuf_free(sm->eap_if->aaaEapReqData);
1377 sm->eap_if->aaaEapReqData = eap;
1381 static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1382 struct sta_info *sta, struct radius_msg *msg,
1383 struct radius_msg *req,
1384 const u8 *shared_secret,
1385 size_t shared_secret_len)
1387 struct radius_ms_mppe_keys *keys;
1388 struct eapol_state_machine *sm = sta->eapol_sm;
1392 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1395 if (keys && keys->send && keys->recv) {
1396 size_t len = keys->send_len + keys->recv_len;
1397 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1398 keys->send, keys->send_len);
1399 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1400 keys->recv, keys->recv_len);
1402 os_free(sm->eap_if->aaaEapKeyData);
1403 sm->eap_if->aaaEapKeyData = os_malloc(len);
1404 if (sm->eap_if->aaaEapKeyData) {
1405 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1407 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1408 keys->send, keys->send_len);
1409 sm->eap_if->aaaEapKeyDataLen = len;
1410 sm->eap_if->aaaEapKeyAvailable = TRUE;
1413 wpa_printf(MSG_DEBUG,
1414 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1415 keys, keys ? keys->send : NULL,
1416 keys ? keys->recv : NULL);
1420 os_free(keys->send);
1421 os_free(keys->recv);
1427 static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1428 struct sta_info *sta,
1429 struct radius_msg *msg)
1433 struct eapol_state_machine *sm = sta->eapol_sm;
1435 struct radius_attr_data *nclass;
1436 size_t nclass_count;
1438 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1442 radius_free_class(&sm->radius_class);
1443 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1447 nclass = os_calloc(count, sizeof(struct radius_attr_data));
1454 for (i = 0; i < count; i++) {
1456 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
1457 &attr_class, &class_len,
1462 } while (class_len < 1);
1464 nclass[nclass_count].data = os_memdup(attr_class, class_len);
1465 if (nclass[nclass_count].data == NULL)
1468 nclass[nclass_count].len = class_len;
1472 sm->radius_class.attr = nclass;
1473 sm->radius_class.count = nclass_count;
1474 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1475 "attributes for " MACSTR,
1476 (unsigned long) sm->radius_class.count,
1477 MAC2STR(sta->addr));
1481 /* Update sta->identity based on User-Name attribute in Access-Accept */
1482 static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1483 struct sta_info *sta,
1484 struct radius_msg *msg)
1488 struct eapol_state_machine *sm = sta->eapol_sm;
1493 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1497 identity = (u8 *) dup_binstr(buf, len);
1498 if (identity == NULL)
1501 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1502 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1503 "User-Name from Access-Accept '%s'",
1504 sm->identity ? (char *) sm->identity : "N/A",
1507 os_free(sm->identity);
1508 sm->identity = identity;
1509 sm->identity_len = len;
1513 /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1514 static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
1515 struct sta_info *sta,
1516 struct radius_msg *msg)
1518 struct eapol_state_machine *sm = sta->eapol_sm;
1526 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
1527 &buf, &len, NULL) < 0)
1530 cui = wpabuf_alloc_copy(buf, len);
1534 wpabuf_free(sm->radius_cui);
1535 sm->radius_cui = cui;
1541 static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len)
1543 sta->remediation = 1;
1544 os_free(sta->remediation_url);
1546 sta->remediation_url = os_malloc(len);
1547 if (!sta->remediation_url)
1549 sta->remediation_method = pos[0];
1550 os_memcpy(sta->remediation_url, pos + 1, len - 1);
1551 sta->remediation_url[len - 1] = '\0';
1552 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1553 "for " MACSTR " - server method %u URL %s",
1554 MAC2STR(sta->addr), sta->remediation_method,
1555 sta->remediation_url);
1557 sta->remediation_url = NULL;
1558 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1559 "for " MACSTR, MAC2STR(sta->addr));
1561 /* TODO: assign the STA into remediation VLAN or add filtering */
1565 static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd,
1566 struct sta_info *sta, u8 *pos,
1570 return; /* Malformed information */
1571 sta->hs20_deauth_requested = 1;
1572 wpa_printf(MSG_DEBUG, "HS 2.0: Deauthentication request - Code %u "
1574 *pos, WPA_GET_LE16(pos + 1));
1575 wpabuf_free(sta->hs20_deauth_req);
1576 sta->hs20_deauth_req = wpabuf_alloc(len + 1);
1577 if (sta->hs20_deauth_req) {
1578 wpabuf_put_data(sta->hs20_deauth_req, pos, 3);
1579 wpabuf_put_u8(sta->hs20_deauth_req, len - 3);
1580 wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3);
1582 ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout);
1586 static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd,
1587 struct sta_info *sta, u8 *pos,
1588 size_t len, int session_timeout)
1591 int warning_time, beacon_int;
1594 return; /* Malformed information */
1595 os_free(sta->hs20_session_info_url);
1596 sta->hs20_session_info_url = os_malloc(len);
1597 if (sta->hs20_session_info_url == NULL)
1600 os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1);
1601 sta->hs20_session_info_url[len - 1] = '\0';
1602 wpa_printf(MSG_DEBUG, "HS 2.0: Session Information URL='%s' SWT=%u "
1603 "(session_timeout=%d)",
1604 sta->hs20_session_info_url, swt, session_timeout);
1605 if (session_timeout < 0) {
1606 wpa_printf(MSG_DEBUG, "HS 2.0: No Session-Timeout set - ignore session info URL");
1610 swt = 1; /* Use one minute as the AP selected value */
1612 if ((unsigned int) session_timeout < swt * 60)
1615 warning_time = session_timeout - swt * 60;
1617 beacon_int = hapd->iconf->beacon_int;
1619 beacon_int = 100; /* best guess */
1620 sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128;
1621 if (sta->hs20_disassoc_timer > 65535)
1622 sta->hs20_disassoc_timer = 65535;
1624 ap_sta_session_warning_timeout(hapd, sta, warning_time);
1628 static void ieee802_1x_hs20_t_c_filtering(struct hostapd_data *hapd,
1629 struct sta_info *sta, u8 *pos,
1633 return; /* Malformed information */
1634 wpa_printf(MSG_DEBUG,
1635 "HS 2.0: Terms and Conditions filtering %02x %02x %02x %02x",
1636 pos[0], pos[1], pos[2], pos[3]);
1637 hs20_t_c_filtering(hapd, sta, pos[0] & BIT(0));
1641 static void ieee802_1x_hs20_t_c_url(struct hostapd_data *hapd,
1642 struct sta_info *sta, u8 *pos, size_t len)
1644 os_free(sta->t_c_url);
1645 sta->t_c_url = os_malloc(len + 1);
1648 os_memcpy(sta->t_c_url, pos, len);
1649 sta->t_c_url[len] = '\0';
1650 wpa_printf(MSG_DEBUG,
1651 "HS 2.0: Terms and Conditions URL %s", sta->t_c_url);
1654 #endif /* CONFIG_HS20 */
1657 static void ieee802_1x_check_hs20(struct hostapd_data *hapd,
1658 struct sta_info *sta,
1659 struct radius_msg *msg,
1660 int session_timeout)
1663 u8 *buf, *pos, *end, type, sublen;
1667 sta->remediation = 0;
1668 sta->hs20_deauth_requested = 0;
1671 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC,
1672 &buf, &len, buf) < 0)
1678 if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA)
1685 continue; /* invalid length */
1686 sublen -= 2; /* skip header */
1687 if (pos + sublen > end)
1688 continue; /* invalid WFA VSA */
1691 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION:
1692 ieee802_1x_hs20_sub_rem(sta, pos, sublen);
1694 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ:
1695 ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen);
1697 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL:
1698 ieee802_1x_hs20_session_info(hapd, sta, pos, sublen,
1701 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILTERING:
1702 ieee802_1x_hs20_t_c_filtering(hapd, sta, pos, sublen);
1704 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_URL:
1705 ieee802_1x_hs20_t_c_url(hapd, sta, pos, sublen);
1709 #endif /* CONFIG_HS20 */
1713 struct sta_id_search {
1715 struct eapol_state_machine *sm;
1719 static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1720 struct sta_info *sta,
1723 struct sta_id_search *id_search = ctx;
1724 struct eapol_state_machine *sm = sta->eapol_sm;
1726 if (sm && sm->radius_identifier >= 0 &&
1727 sm->radius_identifier == id_search->identifier) {
1735 static struct eapol_state_machine *
1736 ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1738 struct sta_id_search id_search;
1739 id_search.identifier = identifier;
1740 id_search.sm = NULL;
1741 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1742 return id_search.sm;
1747 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1748 * @msg: RADIUS response message
1749 * @req: RADIUS request message
1750 * @shared_secret: RADIUS shared secret
1751 * @shared_secret_len: Length of shared_secret in octets
1752 * @data: Context data (struct hostapd_data *)
1753 * Returns: Processing status
1755 static RadiusRxResult
1756 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1757 const u8 *shared_secret, size_t shared_secret_len,
1760 struct hostapd_data *hapd = data;
1761 struct sta_info *sta;
1762 u32 session_timeout = 0, termination_action, acct_interim_interval;
1763 int session_timeout_set;
1765 struct eapol_state_machine *sm;
1766 int override_eapReq = 0;
1767 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
1768 struct vlan_description vlan_desc;
1769 #ifndef CONFIG_NO_VLAN
1770 int *untagged, *tagged, *notempty;
1771 #endif /* CONFIG_NO_VLAN */
1773 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
1775 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1777 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1778 "station for this RADIUS message");
1779 return RADIUS_RX_UNKNOWN;
1783 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1784 * present when packet contains an EAP-Message attribute */
1785 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1786 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1788 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1789 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1790 "Message-Authenticator since it does not include "
1792 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1794 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
1795 return RADIUS_RX_INVALID_AUTHENTICATOR;
1798 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1799 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1800 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
1801 wpa_printf(MSG_INFO, "Unknown RADIUS message code");
1802 return RADIUS_RX_UNKNOWN;
1805 sm->radius_identifier = -1;
1806 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1807 MAC2STR(sta->addr));
1809 radius_msg_free(sm->last_recv_radius);
1810 sm->last_recv_radius = msg;
1812 session_timeout_set =
1813 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1815 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1816 &termination_action))
1817 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1819 if (hapd->conf->acct_interim_interval == 0 &&
1820 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1821 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1822 &acct_interim_interval) == 0) {
1823 if (acct_interim_interval < 60) {
1824 hostapd_logger(hapd, sta->addr,
1825 HOSTAPD_MODULE_IEEE8021X,
1827 "ignored too small "
1828 "Acct-Interim-Interval %d",
1829 acct_interim_interval);
1831 sta->acct_interim_interval = acct_interim_interval;
1835 switch (hdr->code) {
1836 case RADIUS_CODE_ACCESS_ACCEPT:
1837 #ifndef CONFIG_NO_VLAN
1838 if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED) {
1839 notempty = &vlan_desc.notempty;
1840 untagged = &vlan_desc.untagged;
1841 tagged = vlan_desc.tagged;
1842 *notempty = !!radius_msg_get_vlanid(msg, untagged,
1843 MAX_NUM_TAGGED_VLAN,
1847 if (vlan_desc.notempty &&
1848 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
1849 sta->eapol_sm->authFail = TRUE;
1850 hostapd_logger(hapd, sta->addr,
1851 HOSTAPD_MODULE_RADIUS,
1853 "Invalid VLAN %d%s received from RADIUS server",
1855 vlan_desc.tagged[0] ? "+" : "");
1856 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
1857 ap_sta_set_vlan(hapd, sta, &vlan_desc);
1861 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
1862 !vlan_desc.notempty) {
1863 sta->eapol_sm->authFail = TRUE;
1864 hostapd_logger(hapd, sta->addr,
1865 HOSTAPD_MODULE_IEEE8021X,
1866 HOSTAPD_LEVEL_INFO, "authentication "
1867 "server did not include required VLAN "
1868 "ID in Access-Accept");
1871 #endif /* CONFIG_NO_VLAN */
1873 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0)
1876 #ifndef CONFIG_NO_VLAN
1877 if (sta->vlan_id > 0) {
1878 hostapd_logger(hapd, sta->addr,
1879 HOSTAPD_MODULE_RADIUS,
1881 "VLAN ID %d", sta->vlan_id);
1883 #endif /* CONFIG_NO_VLAN */
1885 if ((sta->flags & WLAN_STA_ASSOC) &&
1886 ap_sta_bind_vlan(hapd, sta) < 0)
1889 sta->session_timeout_set = !!session_timeout_set;
1890 os_get_reltime(&sta->session_timeout);
1891 sta->session_timeout.sec += session_timeout;
1893 /* RFC 3580, Ch. 3.17 */
1894 if (session_timeout_set && termination_action ==
1895 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST)
1896 sm->reAuthPeriod = session_timeout;
1897 else if (session_timeout_set)
1898 ap_sta_session_timeout(hapd, sta, session_timeout);
1900 ap_sta_no_session_timeout(hapd, sta);
1902 sm->eap_if->aaaSuccess = TRUE;
1903 override_eapReq = 1;
1904 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1906 ieee802_1x_store_radius_class(hapd, sta, msg);
1907 ieee802_1x_update_sta_identity(hapd, sta, msg);
1908 ieee802_1x_update_sta_cui(hapd, sta, msg);
1909 ieee802_1x_check_hs20(hapd, sta, msg,
1910 session_timeout_set ?
1911 (int) session_timeout : -1);
1913 case RADIUS_CODE_ACCESS_REJECT:
1914 sm->eap_if->aaaFail = TRUE;
1915 override_eapReq = 1;
1916 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_WLAN_REASON_CODE,
1917 &reason_code) == 0) {
1918 wpa_printf(MSG_DEBUG,
1919 "RADIUS server indicated WLAN-Reason-Code %u in Access-Reject for "
1920 MACSTR, reason_code, MAC2STR(sta->addr));
1921 sta->disconnect_reason_code = reason_code;
1924 case RADIUS_CODE_ACCESS_CHALLENGE:
1925 sm->eap_if->aaaEapReq = TRUE;
1926 if (session_timeout_set) {
1927 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1928 sm->eap_if->aaaMethodTimeout = session_timeout;
1929 hostapd_logger(hapd, sm->addr,
1930 HOSTAPD_MODULE_IEEE8021X,
1931 HOSTAPD_LEVEL_DEBUG,
1932 "using EAP timeout of %d seconds (from "
1934 sm->eap_if->aaaMethodTimeout);
1937 * Use dynamic retransmission behavior per EAP
1940 sm->eap_if->aaaMethodTimeout = 0;
1945 ieee802_1x_decapsulate_radius(hapd, sta);
1946 if (override_eapReq)
1947 sm->eap_if->aaaEapReq = FALSE;
1951 if (sta->flags & WLAN_STA_PENDING_FILS_ERP) {
1952 /* TODO: Add a PMKSA entry on success? */
1953 ieee802_11_finish_fils_auth(
1954 hapd, sta, hdr->code == RADIUS_CODE_ACCESS_ACCEPT,
1955 sm->eap_if->aaaEapReqData,
1956 sm->eap_if->aaaEapKeyData,
1957 sm->eap_if->aaaEapKeyDataLen);
1959 #endif /* NEED_AP_MLME */
1960 #endif /* CONFIG_FILS */
1962 eapol_auth_step(sm);
1964 return RADIUS_RX_QUEUED;
1966 #endif /* CONFIG_NO_RADIUS */
1969 void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
1971 struct eapol_state_machine *sm = sta->eapol_sm;
1975 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1976 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
1978 #ifndef CONFIG_NO_RADIUS
1979 radius_msg_free(sm->last_recv_radius);
1980 sm->last_recv_radius = NULL;
1981 #endif /* CONFIG_NO_RADIUS */
1983 if (sm->eap_if->eapTimeout) {
1985 * Disconnect the STA since it did not reply to the last EAP
1986 * request and we cannot continue EAP processing (EAP-Failure
1987 * could only be sent if the EAP peer actually replied).
1989 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
1990 MAC2STR(sta->addr));
1992 sm->eap_if->portEnabled = FALSE;
1993 ap_sta_disconnect(hapd, sta, sta->addr,
1994 WLAN_REASON_PREV_AUTH_NOT_VALID);
1999 static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
2001 struct eapol_authenticator *eapol = hapd->eapol_auth;
2003 if (hapd->conf->default_wep_key_len < 1)
2006 os_free(eapol->default_wep_key);
2007 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
2008 if (eapol->default_wep_key == NULL ||
2009 random_get_bytes(eapol->default_wep_key,
2010 hapd->conf->default_wep_key_len)) {
2011 wpa_printf(MSG_INFO, "Could not generate random WEP key");
2012 os_free(eapol->default_wep_key);
2013 eapol->default_wep_key = NULL;
2017 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
2018 eapol->default_wep_key,
2019 hapd->conf->default_wep_key_len);
2025 static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
2026 struct sta_info *sta, void *ctx)
2028 if (sta->eapol_sm) {
2029 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
2030 eapol_auth_step(sta->eapol_sm);
2036 static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
2038 struct hostapd_data *hapd = eloop_ctx;
2039 struct eapol_authenticator *eapol = hapd->eapol_auth;
2041 if (eapol->default_wep_key_idx >= 3)
2042 eapol->default_wep_key_idx =
2043 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
2045 eapol->default_wep_key_idx++;
2047 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
2048 eapol->default_wep_key_idx);
2050 if (ieee802_1x_rekey_broadcast(hapd)) {
2051 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2052 HOSTAPD_LEVEL_WARNING, "failed to generate a "
2053 "new broadcast key");
2054 os_free(eapol->default_wep_key);
2055 eapol->default_wep_key = NULL;
2059 /* TODO: Could setup key for RX here, but change default TX keyid only
2060 * after new broadcast key has been sent to all stations. */
2061 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
2062 broadcast_ether_addr,
2063 eapol->default_wep_key_idx, 1, NULL, 0,
2064 eapol->default_wep_key,
2065 hapd->conf->default_wep_key_len)) {
2066 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2067 HOSTAPD_LEVEL_WARNING, "failed to configure a "
2068 "new broadcast key");
2069 os_free(eapol->default_wep_key);
2070 eapol->default_wep_key = NULL;
2074 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
2076 if (hapd->conf->wep_rekeying_period > 0) {
2077 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
2078 ieee802_1x_rekey, hapd, NULL);
2083 static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
2084 const u8 *data, size_t datalen)
2087 struct sta_info *sta = sta_ctx;
2089 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
2090 WLAN_STA_MAYBE_WPS) {
2092 size_t identity_len;
2093 struct eapol_state_machine *sm = sta->eapol_sm;
2095 identity = eap_get_identity(sm->eap, &identity_len);
2097 ((identity_len == WSC_ID_ENROLLEE_LEN &&
2098 os_memcmp(identity, WSC_ID_ENROLLEE,
2099 WSC_ID_ENROLLEE_LEN) == 0) ||
2100 (identity_len == WSC_ID_REGISTRAR_LEN &&
2101 os_memcmp(identity, WSC_ID_REGISTRAR,
2102 WSC_ID_REGISTRAR_LEN) == 0))) {
2103 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
2105 sta->flags |= WLAN_STA_WPS;
2108 #endif /* CONFIG_WPS */
2110 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
2114 static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
2115 const u8 *data, size_t datalen)
2117 #ifndef CONFIG_NO_RADIUS
2118 struct hostapd_data *hapd = ctx;
2119 struct sta_info *sta = sta_ctx;
2121 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
2122 #endif /* CONFIG_NO_RADIUS */
2126 static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
2127 int preauth, int remediation)
2129 struct hostapd_data *hapd = ctx;
2130 struct sta_info *sta = sta_ctx;
2132 rsn_preauth_finished(hapd, sta, success);
2134 ieee802_1x_finished(hapd, sta, success, remediation);
2138 static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
2139 size_t identity_len, int phase2,
2140 struct eap_user *user)
2142 struct hostapd_data *hapd = ctx;
2143 const struct hostapd_eap_user *eap_user;
2147 eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2);
2148 if (eap_user == NULL)
2151 os_memset(user, 0, sizeof(*user));
2152 user->phase2 = phase2;
2153 for (i = 0; i < EAP_MAX_METHODS; i++) {
2154 user->methods[i].vendor = eap_user->methods[i].vendor;
2155 user->methods[i].method = eap_user->methods[i].method;
2158 if (eap_user->password) {
2159 user->password = os_memdup(eap_user->password,
2160 eap_user->password_len);
2161 if (user->password == NULL)
2163 user->password_len = eap_user->password_len;
2164 user->password_hash = eap_user->password_hash;
2165 if (eap_user->salt && eap_user->salt_len) {
2166 user->salt = os_memdup(eap_user->salt,
2167 eap_user->salt_len);
2170 user->salt_len = eap_user->salt_len;
2173 user->force_version = eap_user->force_version;
2174 user->macacl = eap_user->macacl;
2175 user->ttls_auth = eap_user->ttls_auth;
2176 user->remediation = eap_user->remediation;
2181 wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
2187 static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
2189 struct hostapd_data *hapd = ctx;
2190 struct sta_info *sta;
2191 sta = ap_get_sta(hapd, addr);
2192 if (sta == NULL || sta->eapol_sm == NULL)
2198 static void ieee802_1x_logger(void *ctx, const u8 *addr,
2199 eapol_logger_level level, const char *txt)
2201 #ifndef CONFIG_NO_HOSTAPD_LOGGER
2202 struct hostapd_data *hapd = ctx;
2206 case EAPOL_LOGGER_WARNING:
2207 hlevel = HOSTAPD_LEVEL_WARNING;
2209 case EAPOL_LOGGER_INFO:
2210 hlevel = HOSTAPD_LEVEL_INFO;
2212 case EAPOL_LOGGER_DEBUG:
2214 hlevel = HOSTAPD_LEVEL_DEBUG;
2218 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
2220 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
2224 static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
2227 struct hostapd_data *hapd = ctx;
2228 struct sta_info *sta = sta_ctx;
2229 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
2233 static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
2235 struct hostapd_data *hapd = ctx;
2236 struct sta_info *sta = sta_ctx;
2237 ieee802_1x_abort_auth(hapd, sta);
2241 static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
2244 #ifndef CONFIG_NO_RC4
2245 struct hostapd_data *hapd = ctx;
2246 struct sta_info *sta = sta_ctx;
2247 ieee802_1x_tx_key(hapd, sta);
2248 #endif /* CONFIG_NO_RC4 */
2249 #endif /* CONFIG_FIPS */
2253 static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
2254 enum eapol_event type)
2256 /* struct hostapd_data *hapd = ctx; */
2257 struct sta_info *sta = sta_ctx;
2259 case EAPOL_AUTH_SM_CHANGE:
2260 wpa_auth_sm_notify(sta->wpa_sm);
2262 case EAPOL_AUTH_REAUTHENTICATE:
2263 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
2271 static struct eap_server_erp_key *
2272 ieee802_1x_erp_get_key(void *ctx, const char *keyname)
2274 struct hostapd_data *hapd = ctx;
2275 struct eap_server_erp_key *erp;
2277 dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key,
2279 if (os_strcmp(erp->keyname_nai, keyname) == 0)
2287 static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp)
2289 struct hostapd_data *hapd = ctx;
2291 dl_list_add(&hapd->erp_keys, &erp->list);
2295 #endif /* CONFIG_ERP */
2298 int ieee802_1x_init(struct hostapd_data *hapd)
2301 struct eapol_auth_config conf;
2302 struct eapol_auth_cb cb;
2304 dl_list_init(&hapd->erp_keys);
2306 os_memset(&conf, 0, sizeof(conf));
2308 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
2309 conf.wpa = hapd->conf->wpa;
2310 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
2311 conf.eap_server = hapd->conf->eap_server;
2312 conf.ssl_ctx = hapd->ssl_ctx;
2313 conf.msg_ctx = hapd->msg_ctx;
2314 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
2315 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
2316 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
2317 conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start;
2318 conf.erp_domain = hapd->conf->erp_domain;
2319 conf.erp = hapd->conf->eap_server_erp;
2320 conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
2321 conf.tls_flags = hapd->conf->tls_flags;
2322 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
2323 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
2324 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
2325 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
2326 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
2327 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
2328 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
2329 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
2330 conf.tnc = hapd->conf->tnc;
2331 conf.wps = hapd->wps;
2332 conf.fragment_size = hapd->conf->fragment_size;
2333 conf.pwd_group = hapd->conf->pwd_group;
2334 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
2335 if (hapd->conf->server_id) {
2336 conf.server_id = (const u8 *) hapd->conf->server_id;
2337 conf.server_id_len = os_strlen(hapd->conf->server_id);
2339 conf.server_id = (const u8 *) "hostapd";
2340 conf.server_id_len = 7;
2343 os_memset(&cb, 0, sizeof(cb));
2344 cb.eapol_send = ieee802_1x_eapol_send;
2345 cb.aaa_send = ieee802_1x_aaa_send;
2346 cb.finished = _ieee802_1x_finished;
2347 cb.get_eap_user = ieee802_1x_get_eap_user;
2348 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
2349 cb.logger = ieee802_1x_logger;
2350 cb.set_port_authorized = ieee802_1x_set_port_authorized;
2351 cb.abort_auth = _ieee802_1x_abort_auth;
2352 cb.tx_key = _ieee802_1x_tx_key;
2353 cb.eapol_event = ieee802_1x_eapol_event;
2355 cb.erp_get_key = ieee802_1x_erp_get_key;
2356 cb.erp_add_key = ieee802_1x_erp_add_key;
2357 #endif /* CONFIG_ERP */
2359 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
2360 if (hapd->eapol_auth == NULL)
2363 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
2364 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
2367 #ifndef CONFIG_NO_RADIUS
2368 if (radius_client_register(hapd->radius, RADIUS_AUTH,
2369 ieee802_1x_receive_auth, hapd))
2371 #endif /* CONFIG_NO_RADIUS */
2373 if (hapd->conf->default_wep_key_len) {
2374 for (i = 0; i < 4; i++)
2375 hostapd_drv_set_key(hapd->conf->iface, hapd,
2376 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
2379 ieee802_1x_rekey(hapd, NULL);
2381 if (hapd->eapol_auth->default_wep_key == NULL)
2389 void ieee802_1x_erp_flush(struct hostapd_data *hapd)
2391 struct eap_server_erp_key *erp;
2393 while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key,
2395 dl_list_del(&erp->list);
2396 bin_clear_free(erp, sizeof(*erp));
2401 void ieee802_1x_deinit(struct hostapd_data *hapd)
2403 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
2405 if (hapd->driver && hapd->drv_priv &&
2406 (hapd->conf->ieee802_1x || hapd->conf->wpa))
2407 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
2409 eapol_auth_deinit(hapd->eapol_auth);
2410 hapd->eapol_auth = NULL;
2412 ieee802_1x_erp_flush(hapd);
2416 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2417 const u8 *buf, size_t len, int ack)
2419 struct ieee80211_hdr *hdr;
2421 const unsigned char rfc1042_hdr[ETH_ALEN] =
2422 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2426 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
2429 hdr = (struct ieee80211_hdr *) buf;
2430 pos = (u8 *) (hdr + 1);
2431 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
2433 pos += sizeof(rfc1042_hdr);
2434 if (WPA_GET_BE16(pos) != ETH_P_PAE)
2438 return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
2443 int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2444 const u8 *buf, int len, int ack)
2446 const struct ieee802_1x_hdr *xhdr =
2447 (const struct ieee802_1x_hdr *) buf;
2448 const u8 *pos = buf + sizeof(*xhdr);
2449 struct ieee802_1x_eapol_key *key;
2451 if (len < (int) sizeof(*xhdr))
2453 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
2454 "type=%d length=%d - ack=%d",
2455 MAC2STR(sta->addr), xhdr->version, xhdr->type,
2456 be_to_host16(xhdr->length), ack);
2459 if (xhdr->type == IEEE802_1X_TYPE_EAP_PACKET && ack &&
2460 (sta->flags & WLAN_STA_WPS) &&
2461 ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd, sta)) {
2462 wpa_printf(MSG_DEBUG,
2463 "WPS: Indicate EAP completion on ACK for EAP-Failure");
2464 hostapd_wps_eap_completed(hapd);
2466 #endif /* CONFIG_WPS */
2468 if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
2471 if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
2472 const struct wpa_eapol_key *wpa;
2473 wpa = (const struct wpa_eapol_key *) pos;
2474 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
2475 wpa->type == EAPOL_KEY_TYPE_WPA)
2476 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
2480 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2481 * or Authenticator state machines, but EAPOL-Key packets are not
2482 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
2483 * packets couple of times because otherwise STA keys become
2484 * unsynchronized with AP. */
2485 if (!ack && pos + sizeof(*key) <= buf + len) {
2486 key = (struct ieee802_1x_eapol_key *) pos;
2487 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
2488 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
2489 "frame (%scast index=%d)",
2490 key->key_index & BIT(7) ? "uni" : "broad",
2491 key->key_index & ~BIT(7));
2492 /* TODO: re-send EAPOL-Key couple of times (with short delay
2493 * between them?). If all attempt fail, report error and
2494 * deauthenticate STA so that it will get new keys when
2495 * authenticating again (e.g., after returning in range).
2496 * Separate limit/transmit state needed both for unicast and
2497 * broadcast keys(?) */
2499 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2500 * to here and change the key only if the EAPOL-Key packet was Acked.
2507 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
2509 if (sm == NULL || sm->identity == NULL)
2512 *len = sm->identity_len;
2513 return sm->identity;
2517 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
2520 if (sm == NULL || sm->radius_class.attr == NULL ||
2521 idx >= (int) sm->radius_class.count)
2524 *len = sm->radius_class.attr[idx].len;
2525 return sm->radius_class.attr[idx].data;
2529 struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
2533 return sm->radius_cui;
2537 const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
2543 *len = sm->eap_if->eapKeyDataLen;
2544 return sm->eap_if->eapKeyData;
2548 void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
2553 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
2554 eapol_auth_step(sm);
2558 void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
2563 sm->portValid = valid ? TRUE : FALSE;
2564 eapol_auth_step(sm);
2568 void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
2573 sm->flags |= EAPOL_SM_PREAUTH;
2575 sm->flags &= ~EAPOL_SM_PREAUTH;
2579 static const char * bool_txt(Boolean val)
2581 return val ? "TRUE" : "FALSE";
2585 int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2592 int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2593 char *buf, size_t buflen)
2596 struct eapol_state_machine *sm = sta->eapol_sm;
2597 struct os_reltime diff;
2604 ret = os_snprintf(buf + len, buflen - len,
2605 "dot1xPaePortNumber=%d\n"
2606 "dot1xPaePortProtocolVersion=%d\n"
2607 "dot1xPaePortCapabilities=1\n"
2608 "dot1xPaePortInitialize=%d\n"
2609 "dot1xPaePortReauthenticate=FALSE\n",
2613 if (os_snprintf_error(buflen - len, ret))
2617 /* dot1xAuthConfigTable */
2618 ret = os_snprintf(buf + len, buflen - len,
2619 "dot1xAuthPaeState=%d\n"
2620 "dot1xAuthBackendAuthState=%d\n"
2621 "dot1xAuthAdminControlledDirections=%d\n"
2622 "dot1xAuthOperControlledDirections=%d\n"
2623 "dot1xAuthAuthControlledPortStatus=%d\n"
2624 "dot1xAuthAuthControlledPortControl=%d\n"
2625 "dot1xAuthQuietPeriod=%u\n"
2626 "dot1xAuthServerTimeout=%u\n"
2627 "dot1xAuthReAuthPeriod=%u\n"
2628 "dot1xAuthReAuthEnabled=%s\n"
2629 "dot1xAuthKeyTxEnabled=%s\n",
2630 sm->auth_pae_state + 1,
2631 sm->be_auth_state + 1,
2632 sm->adminControlledDirections,
2633 sm->operControlledDirections,
2639 bool_txt(sm->reAuthEnabled),
2640 bool_txt(sm->keyTxEnabled));
2641 if (os_snprintf_error(buflen - len, ret))
2645 /* dot1xAuthStatsTable */
2646 ret = os_snprintf(buf + len, buflen - len,
2647 "dot1xAuthEapolFramesRx=%u\n"
2648 "dot1xAuthEapolFramesTx=%u\n"
2649 "dot1xAuthEapolStartFramesRx=%u\n"
2650 "dot1xAuthEapolLogoffFramesRx=%u\n"
2651 "dot1xAuthEapolRespIdFramesRx=%u\n"
2652 "dot1xAuthEapolRespFramesRx=%u\n"
2653 "dot1xAuthEapolReqIdFramesTx=%u\n"
2654 "dot1xAuthEapolReqFramesTx=%u\n"
2655 "dot1xAuthInvalidEapolFramesRx=%u\n"
2656 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2657 "dot1xAuthLastEapolFrameVersion=%u\n"
2658 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
2659 sm->dot1xAuthEapolFramesRx,
2660 sm->dot1xAuthEapolFramesTx,
2661 sm->dot1xAuthEapolStartFramesRx,
2662 sm->dot1xAuthEapolLogoffFramesRx,
2663 sm->dot1xAuthEapolRespIdFramesRx,
2664 sm->dot1xAuthEapolRespFramesRx,
2665 sm->dot1xAuthEapolReqIdFramesTx,
2666 sm->dot1xAuthEapolReqFramesTx,
2667 sm->dot1xAuthInvalidEapolFramesRx,
2668 sm->dot1xAuthEapLengthErrorFramesRx,
2669 sm->dot1xAuthLastEapolFrameVersion,
2671 if (os_snprintf_error(buflen - len, ret))
2675 /* dot1xAuthDiagTable */
2676 ret = os_snprintf(buf + len, buflen - len,
2677 "dot1xAuthEntersConnecting=%u\n"
2678 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2679 "dot1xAuthEntersAuthenticating=%u\n"
2680 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2681 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2682 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2683 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2684 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2685 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2686 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2687 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2688 "dot1xAuthBackendResponses=%u\n"
2689 "dot1xAuthBackendAccessChallenges=%u\n"
2690 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2691 "dot1xAuthBackendAuthSuccesses=%u\n"
2692 "dot1xAuthBackendAuthFails=%u\n",
2693 sm->authEntersConnecting,
2694 sm->authEapLogoffsWhileConnecting,
2695 sm->authEntersAuthenticating,
2696 sm->authAuthSuccessesWhileAuthenticating,
2697 sm->authAuthTimeoutsWhileAuthenticating,
2698 sm->authAuthFailWhileAuthenticating,
2699 sm->authAuthEapStartsWhileAuthenticating,
2700 sm->authAuthEapLogoffWhileAuthenticating,
2701 sm->authAuthReauthsWhileAuthenticated,
2702 sm->authAuthEapStartsWhileAuthenticated,
2703 sm->authAuthEapLogoffWhileAuthenticated,
2704 sm->backendResponses,
2705 sm->backendAccessChallenges,
2706 sm->backendOtherRequestsToSupplicant,
2707 sm->backendAuthSuccesses,
2708 sm->backendAuthFails);
2709 if (os_snprintf_error(buflen - len, ret))
2713 /* dot1xAuthSessionStatsTable */
2714 os_reltime_age(&sta->acct_session_start, &diff);
2715 ret = os_snprintf(buf + len, buflen - len,
2716 /* TODO: dot1xAuthSessionOctetsRx */
2717 /* TODO: dot1xAuthSessionOctetsTx */
2718 /* TODO: dot1xAuthSessionFramesRx */
2719 /* TODO: dot1xAuthSessionFramesTx */
2720 "dot1xAuthSessionId=%016llX\n"
2721 "dot1xAuthSessionAuthenticMethod=%d\n"
2722 "dot1xAuthSessionTime=%u\n"
2723 "dot1xAuthSessionTerminateCause=999\n"
2724 "dot1xAuthSessionUserName=%s\n",
2725 (unsigned long long) sta->acct_session_id,
2726 (wpa_key_mgmt_wpa_ieee8021x(
2727 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2729 (unsigned int) diff.sec,
2731 if (os_snprintf_error(buflen - len, ret))
2735 if (sm->acct_multi_session_id) {
2736 ret = os_snprintf(buf + len, buflen - len,
2737 "authMultiSessionId=%016llX\n",
2738 (unsigned long long)
2739 sm->acct_multi_session_id);
2740 if (os_snprintf_error(buflen - len, ret))
2745 name1 = eap_server_get_name(0, sm->eap_type_authsrv);
2746 name2 = eap_server_get_name(0, sm->eap_type_supp);
2747 ret = os_snprintf(buf + len, buflen - len,
2748 "last_eap_type_as=%d (%s)\n"
2749 "last_eap_type_sta=%d (%s)\n",
2750 sm->eap_type_authsrv, name1,
2751 sm->eap_type_supp, name2);
2752 if (os_snprintf_error(buflen - len, ret))
2761 static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx)
2763 struct hostapd_data *hapd = eloop_ctx;
2764 struct sta_info *sta = timeout_ctx;
2766 if (sta->remediation) {
2767 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2768 MACSTR " to indicate Subscription Remediation",
2769 MAC2STR(sta->addr));
2770 hs20_send_wnm_notification(hapd, sta->addr,
2771 sta->remediation_method,
2772 sta->remediation_url);
2773 os_free(sta->remediation_url);
2774 sta->remediation_url = NULL;
2777 if (sta->hs20_deauth_req) {
2778 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2779 MACSTR " to indicate imminent deauthentication",
2780 MAC2STR(sta->addr));
2781 hs20_send_wnm_notification_deauth_req(hapd, sta->addr,
2782 sta->hs20_deauth_req);
2785 if (sta->hs20_t_c_filtering) {
2786 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2787 MACSTR " to indicate Terms and Conditions filtering",
2788 MAC2STR(sta->addr));
2789 hs20_send_wnm_notification_t_c(hapd, sta->addr, sta->t_c_url);
2790 os_free(sta->t_c_url);
2791 sta->t_c_url = NULL;
2794 #endif /* CONFIG_HS20 */
2797 static void ieee802_1x_finished(struct hostapd_data *hapd,
2798 struct sta_info *sta, int success,
2803 /* TODO: get PMKLifetime from WPA parameters */
2804 static const int dot11RSNAConfigPMKLifetime = 43200;
2805 unsigned int session_timeout;
2806 struct os_reltime now, remaining;
2809 if (remediation && !sta->remediation) {
2810 sta->remediation = 1;
2811 os_free(sta->remediation_url);
2812 sta->remediation_url =
2813 os_strdup(hapd->conf->subscr_remediation_url);
2814 sta->remediation_method = 1; /* SOAP-XML SPP */
2817 if (success && (sta->remediation || sta->hs20_deauth_req ||
2818 sta->hs20_t_c_filtering)) {
2819 wpa_printf(MSG_DEBUG, "HS 2.0: Schedule WNM-Notification to "
2820 MACSTR " in 100 ms", MAC2STR(sta->addr));
2821 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
2822 eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send,
2825 #endif /* CONFIG_HS20 */
2827 key = ieee802_1x_get_key(sta->eapol_sm, &len);
2828 if (sta->session_timeout_set) {
2829 os_get_reltime(&now);
2830 os_reltime_sub(&sta->session_timeout, &now, &remaining);
2831 session_timeout = (remaining.sec > 0) ? remaining.sec : 1;
2833 session_timeout = dot11RSNAConfigPMKLifetime;
2835 if (success && key && len >= PMK_LEN && !sta->remediation &&
2836 !sta->hs20_deauth_requested &&
2837 wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout,
2838 sta->eapol_sm) == 0) {
2839 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2840 HOSTAPD_LEVEL_DEBUG,
2841 "Added PMKSA cache entry (IEEE 802.1X)");
2846 * Many devices require deauthentication after WPS provisioning
2847 * and some may not be be able to do that themselves, so
2848 * disconnect the client here. In addition, this may also
2849 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2850 * the EAPOL PAE state machine would remain in HELD state for
2851 * considerable amount of time and some EAP methods, like
2852 * EAP-FAST with anonymous provisioning, may require another
2853 * EAPOL authentication to be started to complete connection.
2855 ap_sta_delayed_1x_auth_fail_disconnect(hapd, sta);