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 (!radius_msg_add_wfa(
687 msg
, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION
,
689 wpa_printf(MSG_ERROR
, "Could not add HS 2.0 AP "
694 if (sta
->hs20_ie
&& wpabuf_len(sta
->hs20_ie
) > 0) {
698 pos
= wpabuf_head_u8(sta
->hs20_ie
);
699 buf
[0] = (*pos
) >> 4;
700 if (((*pos
) & HS20_PPS_MO_ID_PRESENT
) &&
701 wpabuf_len(sta
->hs20_ie
) >= 3)
702 id
= WPA_GET_LE16(pos
+ 1);
705 WPA_PUT_BE16(buf
+ 1, id
);
706 if (!radius_msg_add_wfa(
708 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION
,
710 wpa_printf(MSG_ERROR
, "Could not add HS 2.0 "
716 #endif /* CONFIG_HS20 */
718 if (radius_client_send(hapd
->radius
, msg
, RADIUS_AUTH
, sta
->addr
) < 0)
724 radius_msg_free(msg
);
726 #endif /* CONFIG_NO_RADIUS */
729 static void handle_eap_response(struct hostapd_data
*hapd
,
730 struct sta_info
*sta
, struct eap_hdr
*eap
,
734 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
738 data
= (u8
*) (eap
+ 1);
740 if (len
< sizeof(*eap
) + 1) {
741 wpa_printf(MSG_INFO
, "handle_eap_response: too short response data");
745 sm
->eap_type_supp
= type
= data
[0];
747 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
748 HOSTAPD_LEVEL_DEBUG
, "received EAP packet (code=%d "
749 "id=%d len=%d) from STA: EAP Response-%s (%d)",
750 eap
->code
, eap
->identifier
, be_to_host16(eap
->length
),
751 eap_server_get_name(0, type
), type
);
753 sm
->dot1xAuthEapolRespFramesRx
++;
755 wpabuf_free(sm
->eap_if
->eapRespData
);
756 sm
->eap_if
->eapRespData
= wpabuf_alloc_copy(eap
, len
);
761 static void handle_eap_initiate(struct hostapd_data
*hapd
,
762 struct sta_info
*sta
, struct eap_hdr
*eap
,
767 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
772 if (len
< sizeof(*eap
) + 1) {
774 "handle_eap_initiate: too short response data");
778 data
= (u8
*) (eap
+ 1);
781 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
782 HOSTAPD_LEVEL_DEBUG
, "received EAP packet (code=%d "
783 "id=%d len=%d) from STA: EAP Initiate type %u",
784 eap
->code
, eap
->identifier
, be_to_host16(eap
->length
),
787 wpabuf_free(sm
->eap_if
->eapRespData
);
788 sm
->eap_if
->eapRespData
= wpabuf_alloc_copy(eap
, len
);
790 #endif /* CONFIG_ERP */
794 /* Process incoming EAP packet from Supplicant */
795 static void handle_eap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
801 if (len
< sizeof(*eap
)) {
802 wpa_printf(MSG_INFO
, " too short EAP packet");
806 eap
= (struct eap_hdr
*) buf
;
808 eap_len
= be_to_host16(eap
->length
);
809 wpa_printf(MSG_DEBUG
, "EAP: code=%d identifier=%d length=%d",
810 eap
->code
, eap
->identifier
, eap_len
);
811 if (eap_len
< sizeof(*eap
)) {
812 wpa_printf(MSG_DEBUG
, " Invalid EAP length");
814 } else if (eap_len
> len
) {
815 wpa_printf(MSG_DEBUG
, " Too short frame to contain this EAP "
818 } else if (eap_len
< len
) {
819 wpa_printf(MSG_DEBUG
, " Ignoring %lu extra bytes after EAP "
820 "packet", (unsigned long) len
- eap_len
);
824 case EAP_CODE_REQUEST
:
825 wpa_printf(MSG_DEBUG
, " (request)");
827 case EAP_CODE_RESPONSE
:
828 wpa_printf(MSG_DEBUG
, " (response)");
829 handle_eap_response(hapd
, sta
, eap
, eap_len
);
831 case EAP_CODE_SUCCESS
:
832 wpa_printf(MSG_DEBUG
, " (success)");
834 case EAP_CODE_FAILURE
:
835 wpa_printf(MSG_DEBUG
, " (failure)");
837 case EAP_CODE_INITIATE
:
838 wpa_printf(MSG_DEBUG
, " (initiate)");
839 handle_eap_initiate(hapd
, sta
, eap
, eap_len
);
841 case EAP_CODE_FINISH
:
842 wpa_printf(MSG_DEBUG
, " (finish)");
845 wpa_printf(MSG_DEBUG
, " (unknown code)");
851 struct eapol_state_machine
*
852 ieee802_1x_alloc_eapol_sm(struct hostapd_data
*hapd
, struct sta_info
*sta
)
855 if (sta
->flags
& WLAN_STA_PREAUTH
)
856 flags
|= EAPOL_SM_PREAUTH
;
858 flags
|= EAPOL_SM_USES_WPA
;
859 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
))
860 flags
|= EAPOL_SM_FROM_PMKSA_CACHE
;
862 return eapol_auth_alloc(hapd
->eapol_auth
, sta
->addr
, flags
,
863 sta
->wps_ie
, sta
->p2p_ie
, sta
,
864 sta
->identity
, sta
->radius_cui
);
868 static void ieee802_1x_save_eapol(struct sta_info
*sta
, const u8
*buf
,
871 if (sta
->pending_eapol_rx
) {
872 wpabuf_free(sta
->pending_eapol_rx
->buf
);
874 sta
->pending_eapol_rx
=
875 os_malloc(sizeof(*sta
->pending_eapol_rx
));
876 if (!sta
->pending_eapol_rx
)
880 sta
->pending_eapol_rx
->buf
= wpabuf_alloc_copy(buf
, len
);
881 if (!sta
->pending_eapol_rx
->buf
) {
882 os_free(sta
->pending_eapol_rx
);
883 sta
->pending_eapol_rx
= NULL
;
887 os_get_reltime(&sta
->pending_eapol_rx
->rx_time
);
892 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
893 * @hapd: hostapd BSS data
894 * @sa: Source address (sender of the EAPOL frame)
896 * @len: Length of buf in octets
898 * This function is called for each incoming EAPOL frame from the interface
900 void ieee802_1x_receive(struct hostapd_data
*hapd
, const u8
*sa
, const u8
*buf
,
903 struct sta_info
*sta
;
904 struct ieee802_1x_hdr
*hdr
;
905 struct ieee802_1x_eapol_key
*key
;
907 struct rsn_pmksa_cache_entry
*pmksa
;
910 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
&&
911 !hapd
->conf
->wps_state
)
914 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: %lu bytes from " MACSTR
,
915 (unsigned long) len
, MAC2STR(sa
));
916 sta
= ap_get_sta(hapd
, sa
);
917 if (!sta
|| (!(sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_PREAUTH
)) &&
918 !(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))) {
919 wpa_printf(MSG_DEBUG
, "IEEE 802.1X data frame from not "
920 "associated/Pre-authenticating STA");
922 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
)) {
923 wpa_printf(MSG_DEBUG
, "Saving EAPOL frame from " MACSTR
924 " for later use", MAC2STR(sta
->addr
));
925 ieee802_1x_save_eapol(sta
, buf
, len
);
931 if (len
< sizeof(*hdr
)) {
932 wpa_printf(MSG_INFO
, " too short IEEE 802.1X packet");
936 hdr
= (struct ieee802_1x_hdr
*) buf
;
937 datalen
= be_to_host16(hdr
->length
);
938 wpa_printf(MSG_DEBUG
, " IEEE 802.1X: version=%d type=%d length=%d",
939 hdr
->version
, hdr
->type
, datalen
);
941 if (len
- sizeof(*hdr
) < datalen
) {
942 wpa_printf(MSG_INFO
, " frame too short for this IEEE 802.1X packet");
944 sta
->eapol_sm
->dot1xAuthEapLengthErrorFramesRx
++;
947 if (len
- sizeof(*hdr
) > datalen
) {
948 wpa_printf(MSG_DEBUG
, " ignoring %lu extra octets after "
949 "IEEE 802.1X packet",
950 (unsigned long) len
- sizeof(*hdr
) - datalen
);
954 sta
->eapol_sm
->dot1xAuthLastEapolFrameVersion
= hdr
->version
;
955 sta
->eapol_sm
->dot1xAuthEapolFramesRx
++;
958 key
= (struct ieee802_1x_eapol_key
*) (hdr
+ 1);
959 if (datalen
>= sizeof(struct ieee802_1x_eapol_key
) &&
960 hdr
->type
== IEEE802_1X_TYPE_EAPOL_KEY
&&
961 (key
->type
== EAPOL_KEY_TYPE_WPA
||
962 key
->type
== EAPOL_KEY_TYPE_RSN
)) {
963 wpa_receive(hapd
->wpa_auth
, sta
->wpa_sm
, (u8
*) hdr
,
964 sizeof(*hdr
) + datalen
);
968 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->osen
&&
969 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
))) {
970 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore EAPOL message - "
971 "802.1X not enabled and WPS not used");
975 key_mgmt
= wpa_auth_sta_key_mgmt(sta
->wpa_sm
);
976 if (key_mgmt
!= -1 && wpa_key_mgmt_wpa_psk(key_mgmt
)) {
977 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore EAPOL message - "
982 if (!sta
->eapol_sm
) {
983 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
988 if (!hapd
->conf
->ieee802_1x
&& hapd
->conf
->wps_state
) {
989 u32 wflags
= sta
->flags
& (WLAN_STA_WPS
|
992 if (wflags
== WLAN_STA_MAYBE_WPS
||
993 wflags
== (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) {
995 * Delay EAPOL frame transmission until a
996 * possible WPS STA initiates the handshake
997 * with EAPOL-Start. Only allow the wait to be
998 * skipped if the STA is known to support WPS
1001 wpa_printf(MSG_DEBUG
, "WPS: Do not start "
1002 "EAPOL until EAPOL-Start is "
1004 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
1007 #endif /* CONFIG_WPS */
1009 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
1012 /* since we support version 1, we can ignore version field and proceed
1013 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
1014 /* TODO: actually, we are not version 1 anymore.. However, Version 2
1015 * does not change frame contents, so should be ok to process frames
1016 * more or less identically. Some changes might be needed for
1017 * verification of fields. */
1019 switch (hdr
->type
) {
1020 case IEEE802_1X_TYPE_EAP_PACKET
:
1021 handle_eap(hapd
, sta
, (u8
*) (hdr
+ 1), datalen
);
1024 case IEEE802_1X_TYPE_EAPOL_START
:
1025 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1026 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Start "
1028 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
1029 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
1031 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
1032 HOSTAPD_LEVEL_DEBUG
, "cached PMKSA "
1033 "available - ignore it since "
1034 "STA sent EAPOL-Start");
1035 wpa_auth_sta_clear_pmksa(sta
->wpa_sm
, pmksa
);
1037 sta
->eapol_sm
->eapolStart
= TRUE
;
1038 sta
->eapol_sm
->dot1xAuthEapolStartFramesRx
++;
1039 eap_server_clear_identity(sta
->eapol_sm
->eap
);
1040 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
1043 case IEEE802_1X_TYPE_EAPOL_LOGOFF
:
1044 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1045 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Logoff "
1047 sta
->acct_terminate_cause
=
1048 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
1049 accounting_sta_stop(hapd
, sta
);
1050 sta
->eapol_sm
->eapolLogoff
= TRUE
;
1051 sta
->eapol_sm
->dot1xAuthEapolLogoffFramesRx
++;
1052 eap_server_clear_identity(sta
->eapol_sm
->eap
);
1055 case IEEE802_1X_TYPE_EAPOL_KEY
:
1056 wpa_printf(MSG_DEBUG
, " EAPOL-Key");
1057 if (!ap_sta_is_authorized(sta
)) {
1058 wpa_printf(MSG_DEBUG
, " Dropped key data from "
1059 "unauthorized Supplicant");
1064 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
:
1065 wpa_printf(MSG_DEBUG
, " EAPOL-Encapsulated-ASF-Alert");
1066 /* TODO: implement support for this; show data */
1070 wpa_printf(MSG_DEBUG
, " unknown IEEE 802.1X packet type");
1071 sta
->eapol_sm
->dot1xAuthInvalidEapolFramesRx
++;
1075 eapol_auth_step(sta
->eapol_sm
);
1080 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1081 * @hapd: hostapd BSS data
1084 * This function is called to start IEEE 802.1X authentication when a new
1085 * station completes IEEE 802.11 association.
1087 void ieee802_1x_new_station(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1089 struct rsn_pmksa_cache_entry
*pmksa
;
1095 if (hapd
->conf
->wps_state
&&
1096 ((hapd
->conf
->wpa
&& (sta
->flags
& WLAN_STA_MAYBE_WPS
)) ||
1097 (sta
->flags
& WLAN_STA_WPS
))) {
1099 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1100 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1101 * authentication in this BSS.
1105 #endif /* CONFIG_WPS */
1107 if (!force_1x
&& !hapd
->conf
->ieee802_1x
&& !hapd
->conf
->osen
) {
1108 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore STA - "
1109 "802.1X not enabled or forced for WPS");
1111 * Clear any possible EAPOL authenticator state to support
1112 * reassociation change from WPS to PSK.
1114 ieee802_1x_free_station(hapd
, sta
);
1118 key_mgmt
= wpa_auth_sta_key_mgmt(sta
->wpa_sm
);
1119 if (key_mgmt
!= -1 && wpa_key_mgmt_wpa_psk(key_mgmt
)) {
1120 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore STA - using PSK");
1122 * Clear any possible EAPOL authenticator state to support
1123 * reassociation change from WPA-EAP to PSK.
1125 ieee802_1x_free_station(hapd
, sta
);
1129 if (sta
->eapol_sm
== NULL
) {
1130 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1131 HOSTAPD_LEVEL_DEBUG
, "start authentication");
1132 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1133 if (sta
->eapol_sm
== NULL
) {
1134 hostapd_logger(hapd
, sta
->addr
,
1135 HOSTAPD_MODULE_IEEE8021X
,
1137 "failed to allocate state machine");
1144 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
1145 if (!hapd
->conf
->ieee802_1x
&& hapd
->conf
->wps_state
&&
1146 !(sta
->flags
& WLAN_STA_WPS2
)) {
1148 * Delay EAPOL frame transmission until a possible WPS STA
1149 * initiates the handshake with EAPOL-Start. Only allow the
1150 * wait to be skipped if the STA is known to support WPS 2.0.
1152 wpa_printf(MSG_DEBUG
, "WPS: Do not start EAPOL until "
1153 "EAPOL-Start is received");
1154 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
1156 #endif /* CONFIG_WPS */
1158 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
1160 #ifdef CONFIG_IEEE80211R_AP
1161 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
1162 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1163 HOSTAPD_LEVEL_DEBUG
,
1164 "PMK from FT - skip IEEE 802.1X/EAP");
1165 /* Setup EAPOL state machines to already authenticated state
1166 * because of existing FT information from R0KH. */
1167 sta
->eapol_sm
->keyRun
= TRUE
;
1168 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1169 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1170 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1171 sta
->eapol_sm
->authSuccess
= TRUE
;
1172 sta
->eapol_sm
->authFail
= FALSE
;
1173 sta
->eapol_sm
->portValid
= TRUE
;
1174 if (sta
->eapol_sm
->eap
)
1175 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1176 /* TODO: get vlan_id from R0KH using RRB message */
1179 #endif /* CONFIG_IEEE80211R_AP */
1182 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
1183 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
1184 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
1185 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1186 HOSTAPD_LEVEL_DEBUG
,
1187 "PMK from FILS - skip IEEE 802.1X/EAP");
1188 /* Setup EAPOL state machines to already authenticated state
1189 * because of existing FILS information. */
1190 sta
->eapol_sm
->keyRun
= TRUE
;
1191 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1192 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1193 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1194 sta
->eapol_sm
->authSuccess
= TRUE
;
1195 sta
->eapol_sm
->authFail
= FALSE
;
1196 sta
->eapol_sm
->portValid
= TRUE
;
1197 if (sta
->eapol_sm
->eap
)
1198 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1201 #endif /* CONFIG_FILS */
1203 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
1205 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1206 HOSTAPD_LEVEL_DEBUG
,
1207 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1208 /* Setup EAPOL state machines to already authenticated state
1209 * because of existing PMKSA information in the cache. */
1210 sta
->eapol_sm
->keyRun
= TRUE
;
1211 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1212 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1213 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1214 sta
->eapol_sm
->authSuccess
= TRUE
;
1215 sta
->eapol_sm
->authFail
= FALSE
;
1216 if (sta
->eapol_sm
->eap
)
1217 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1218 pmksa_cache_to_eapol_data(hapd
, pmksa
, sta
->eapol_sm
);
1219 ap_sta_bind_vlan(hapd
, sta
);
1223 * Force EAPOL state machines to start
1224 * re-authentication without having to wait for the
1225 * Supplicant to send EAPOL-Start.
1227 sta
->eapol_sm
->reAuthenticate
= TRUE
;
1229 eapol_auth_step(sta
->eapol_sm
);
1234 void ieee802_1x_free_station(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1236 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1239 eloop_cancel_timeout(ieee802_1x_wnm_notif_send
, hapd
, sta
);
1240 #endif /* CONFIG_HS20 */
1242 if (sta
->pending_eapol_rx
) {
1243 wpabuf_free(sta
->pending_eapol_rx
->buf
);
1244 os_free(sta
->pending_eapol_rx
);
1245 sta
->pending_eapol_rx
= NULL
;
1251 sta
->eapol_sm
= NULL
;
1253 #ifndef CONFIG_NO_RADIUS
1254 radius_msg_free(sm
->last_recv_radius
);
1255 radius_free_class(&sm
->radius_class
);
1256 #endif /* CONFIG_NO_RADIUS */
1258 eapol_auth_free(sm
);
1262 #ifndef CONFIG_NO_RADIUS
1263 static void ieee802_1x_decapsulate_radius(struct hostapd_data
*hapd
,
1264 struct sta_info
*sta
)
1267 const struct eap_hdr
*hdr
;
1270 struct radius_msg
*msg
;
1271 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1273 if (sm
== NULL
|| sm
->last_recv_radius
== NULL
) {
1275 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1279 msg
= sm
->last_recv_radius
;
1281 eap
= radius_msg_get_eap(msg
);
1283 /* RFC 3579, Chap. 2.6.3:
1284 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1286 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1287 HOSTAPD_LEVEL_WARNING
, "could not extract "
1288 "EAP-Message from RADIUS message");
1289 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1293 if (wpabuf_len(eap
) < sizeof(*hdr
)) {
1294 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1295 HOSTAPD_LEVEL_WARNING
, "too short EAP packet "
1296 "received from authentication server");
1298 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1302 if (wpabuf_len(eap
) > sizeof(*hdr
))
1303 eap_type
= (wpabuf_head_u8(eap
))[sizeof(*hdr
)];
1305 hdr
= wpabuf_head(eap
);
1306 switch (hdr
->code
) {
1307 case EAP_CODE_REQUEST
:
1309 sm
->eap_type_authsrv
= eap_type
;
1310 os_snprintf(buf
, sizeof(buf
), "EAP-Request-%s (%d)",
1311 eap_server_get_name(0, eap_type
), eap_type
);
1313 case EAP_CODE_RESPONSE
:
1314 os_snprintf(buf
, sizeof(buf
), "EAP Response-%s (%d)",
1315 eap_server_get_name(0, eap_type
), eap_type
);
1317 case EAP_CODE_SUCCESS
:
1318 os_strlcpy(buf
, "EAP Success", sizeof(buf
));
1320 case EAP_CODE_FAILURE
:
1321 os_strlcpy(buf
, "EAP Failure", sizeof(buf
));
1324 os_strlcpy(buf
, "unknown EAP code", sizeof(buf
));
1327 buf
[sizeof(buf
) - 1] = '\0';
1328 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1329 HOSTAPD_LEVEL_DEBUG
, "decapsulated EAP packet (code=%d "
1330 "id=%d len=%d) from RADIUS server: %s",
1331 hdr
->code
, hdr
->identifier
, be_to_host16(hdr
->length
),
1333 sm
->eap_if
->aaaEapReq
= TRUE
;
1335 wpabuf_free(sm
->eap_if
->aaaEapReqData
);
1336 sm
->eap_if
->aaaEapReqData
= eap
;
1340 static void ieee802_1x_get_keys(struct hostapd_data
*hapd
,
1341 struct sta_info
*sta
, struct radius_msg
*msg
,
1342 struct radius_msg
*req
,
1343 const u8
*shared_secret
,
1344 size_t shared_secret_len
)
1346 struct radius_ms_mppe_keys
*keys
;
1347 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1351 keys
= radius_msg_get_ms_keys(msg
, req
, shared_secret
,
1354 if (keys
&& keys
->send
&& keys
->recv
) {
1355 size_t len
= keys
->send_len
+ keys
->recv_len
;
1356 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Send-Key",
1357 keys
->send
, keys
->send_len
);
1358 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Recv-Key",
1359 keys
->recv
, keys
->recv_len
);
1361 os_free(sm
->eap_if
->aaaEapKeyData
);
1362 sm
->eap_if
->aaaEapKeyData
= os_malloc(len
);
1363 if (sm
->eap_if
->aaaEapKeyData
) {
1364 os_memcpy(sm
->eap_if
->aaaEapKeyData
, keys
->recv
,
1366 os_memcpy(sm
->eap_if
->aaaEapKeyData
+ keys
->recv_len
,
1367 keys
->send
, keys
->send_len
);
1368 sm
->eap_if
->aaaEapKeyDataLen
= len
;
1369 sm
->eap_if
->aaaEapKeyAvailable
= TRUE
;
1372 wpa_printf(MSG_DEBUG
,
1373 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1374 keys
, keys
? keys
->send
: NULL
,
1375 keys
? keys
->recv
: NULL
);
1379 os_free(keys
->send
);
1380 os_free(keys
->recv
);
1386 static void ieee802_1x_store_radius_class(struct hostapd_data
*hapd
,
1387 struct sta_info
*sta
,
1388 struct radius_msg
*msg
)
1392 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1394 struct radius_attr_data
*nclass
;
1395 size_t nclass_count
;
1397 if (!hapd
->conf
->radius
->acct_server
|| hapd
->radius
== NULL
||
1401 radius_free_class(&sm
->radius_class
);
1402 count
= radius_msg_count_attr(msg
, RADIUS_ATTR_CLASS
, 1);
1406 nclass
= os_calloc(count
, sizeof(struct radius_attr_data
));
1413 for (i
= 0; i
< count
; i
++) {
1415 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_CLASS
,
1416 &attr_class
, &class_len
,
1421 } while (class_len
< 1);
1423 nclass
[nclass_count
].data
= os_malloc(class_len
);
1424 if (nclass
[nclass_count
].data
== NULL
)
1427 os_memcpy(nclass
[nclass_count
].data
, attr_class
, class_len
);
1428 nclass
[nclass_count
].len
= class_len
;
1432 sm
->radius_class
.attr
= nclass
;
1433 sm
->radius_class
.count
= nclass_count
;
1434 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Stored %lu RADIUS Class "
1435 "attributes for " MACSTR
,
1436 (unsigned long) sm
->radius_class
.count
,
1437 MAC2STR(sta
->addr
));
1441 /* Update sta->identity based on User-Name attribute in Access-Accept */
1442 static void ieee802_1x_update_sta_identity(struct hostapd_data
*hapd
,
1443 struct sta_info
*sta
,
1444 struct radius_msg
*msg
)
1448 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1453 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_USER_NAME
, &buf
, &len
,
1457 identity
= (u8
*) dup_binstr(buf
, len
);
1458 if (identity
== NULL
)
1461 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1462 HOSTAPD_LEVEL_DEBUG
, "old identity '%s' updated with "
1463 "User-Name from Access-Accept '%s'",
1464 sm
->identity
? (char *) sm
->identity
: "N/A",
1467 os_free(sm
->identity
);
1468 sm
->identity
= identity
;
1469 sm
->identity_len
= len
;
1473 /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1474 static void ieee802_1x_update_sta_cui(struct hostapd_data
*hapd
,
1475 struct sta_info
*sta
,
1476 struct radius_msg
*msg
)
1478 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1486 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY
,
1487 &buf
, &len
, NULL
) < 0)
1490 cui
= wpabuf_alloc_copy(buf
, len
);
1494 wpabuf_free(sm
->radius_cui
);
1495 sm
->radius_cui
= cui
;
1501 static void ieee802_1x_hs20_sub_rem(struct sta_info
*sta
, u8
*pos
, size_t len
)
1503 sta
->remediation
= 1;
1504 os_free(sta
->remediation_url
);
1506 sta
->remediation_url
= os_malloc(len
);
1507 if (!sta
->remediation_url
)
1509 sta
->remediation_method
= pos
[0];
1510 os_memcpy(sta
->remediation_url
, pos
+ 1, len
- 1);
1511 sta
->remediation_url
[len
- 1] = '\0';
1512 wpa_printf(MSG_DEBUG
, "HS 2.0: Subscription remediation needed "
1513 "for " MACSTR
" - server method %u URL %s",
1514 MAC2STR(sta
->addr
), sta
->remediation_method
,
1515 sta
->remediation_url
);
1517 sta
->remediation_url
= NULL
;
1518 wpa_printf(MSG_DEBUG
, "HS 2.0: Subscription remediation needed "
1519 "for " MACSTR
, MAC2STR(sta
->addr
));
1521 /* TODO: assign the STA into remediation VLAN or add filtering */
1525 static void ieee802_1x_hs20_deauth_req(struct hostapd_data
*hapd
,
1526 struct sta_info
*sta
, u8
*pos
,
1530 return; /* Malformed information */
1531 sta
->hs20_deauth_requested
= 1;
1532 wpa_printf(MSG_DEBUG
, "HS 2.0: Deauthentication request - Code %u "
1534 *pos
, WPA_GET_LE16(pos
+ 1));
1535 wpabuf_free(sta
->hs20_deauth_req
);
1536 sta
->hs20_deauth_req
= wpabuf_alloc(len
+ 1);
1537 if (sta
->hs20_deauth_req
) {
1538 wpabuf_put_data(sta
->hs20_deauth_req
, pos
, 3);
1539 wpabuf_put_u8(sta
->hs20_deauth_req
, len
- 3);
1540 wpabuf_put_data(sta
->hs20_deauth_req
, pos
+ 3, len
- 3);
1542 ap_sta_session_timeout(hapd
, sta
, hapd
->conf
->hs20_deauth_req_timeout
);
1546 static void ieee802_1x_hs20_session_info(struct hostapd_data
*hapd
,
1547 struct sta_info
*sta
, u8
*pos
,
1548 size_t len
, int session_timeout
)
1551 int warning_time
, beacon_int
;
1554 return; /* Malformed information */
1555 os_free(sta
->hs20_session_info_url
);
1556 sta
->hs20_session_info_url
= os_malloc(len
);
1557 if (sta
->hs20_session_info_url
== NULL
)
1560 os_memcpy(sta
->hs20_session_info_url
, pos
+ 1, len
- 1);
1561 sta
->hs20_session_info_url
[len
- 1] = '\0';
1562 wpa_printf(MSG_DEBUG
, "HS 2.0: Session Information URL='%s' SWT=%u "
1563 "(session_timeout=%d)",
1564 sta
->hs20_session_info_url
, swt
, session_timeout
);
1565 if (session_timeout
< 0) {
1566 wpa_printf(MSG_DEBUG
, "HS 2.0: No Session-Timeout set - ignore session info URL");
1570 swt
= 1; /* Use one minute as the AP selected value */
1572 if ((unsigned int) session_timeout
< swt
* 60)
1575 warning_time
= session_timeout
- swt
* 60;
1577 beacon_int
= hapd
->iconf
->beacon_int
;
1579 beacon_int
= 100; /* best guess */
1580 sta
->hs20_disassoc_timer
= swt
* 60 * 1000 / beacon_int
* 125 / 128;
1581 if (sta
->hs20_disassoc_timer
> 65535)
1582 sta
->hs20_disassoc_timer
= 65535;
1584 ap_sta_session_warning_timeout(hapd
, sta
, warning_time
);
1587 #endif /* CONFIG_HS20 */
1590 static void ieee802_1x_check_hs20(struct hostapd_data
*hapd
,
1591 struct sta_info
*sta
,
1592 struct radius_msg
*msg
,
1593 int session_timeout
)
1596 u8
*buf
, *pos
, *end
, type
, sublen
;
1600 sta
->remediation
= 0;
1601 sta
->hs20_deauth_requested
= 0;
1604 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_VENDOR_SPECIFIC
,
1605 &buf
, &len
, buf
) < 0)
1611 if (WPA_GET_BE32(pos
) != RADIUS_VENDOR_ID_WFA
)
1618 continue; /* invalid length */
1619 sublen
-= 2; /* skip header */
1620 if (pos
+ sublen
> end
)
1621 continue; /* invalid WFA VSA */
1624 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION
:
1625 ieee802_1x_hs20_sub_rem(sta
, pos
, sublen
);
1627 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ
:
1628 ieee802_1x_hs20_deauth_req(hapd
, sta
, pos
, sublen
);
1630 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL
:
1631 ieee802_1x_hs20_session_info(hapd
, sta
, pos
, sublen
,
1636 #endif /* CONFIG_HS20 */
1640 struct sta_id_search
{
1642 struct eapol_state_machine
*sm
;
1646 static int ieee802_1x_select_radius_identifier(struct hostapd_data
*hapd
,
1647 struct sta_info
*sta
,
1650 struct sta_id_search
*id_search
= ctx
;
1651 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1653 if (sm
&& sm
->radius_identifier
>= 0 &&
1654 sm
->radius_identifier
== id_search
->identifier
) {
1662 static struct eapol_state_machine
*
1663 ieee802_1x_search_radius_identifier(struct hostapd_data
*hapd
, u8 identifier
)
1665 struct sta_id_search id_search
;
1666 id_search
.identifier
= identifier
;
1667 id_search
.sm
= NULL
;
1668 ap_for_each_sta(hapd
, ieee802_1x_select_radius_identifier
, &id_search
);
1669 return id_search
.sm
;
1674 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1675 * @msg: RADIUS response message
1676 * @req: RADIUS request message
1677 * @shared_secret: RADIUS shared secret
1678 * @shared_secret_len: Length of shared_secret in octets
1679 * @data: Context data (struct hostapd_data *)
1680 * Returns: Processing status
1682 static RadiusRxResult
1683 ieee802_1x_receive_auth(struct radius_msg
*msg
, struct radius_msg
*req
,
1684 const u8
*shared_secret
, size_t shared_secret_len
,
1687 struct hostapd_data
*hapd
= data
;
1688 struct sta_info
*sta
;
1689 u32 session_timeout
= 0, termination_action
, acct_interim_interval
;
1690 int session_timeout_set
;
1691 struct eapol_state_machine
*sm
;
1692 int override_eapReq
= 0;
1693 struct radius_hdr
*hdr
= radius_msg_get_hdr(msg
);
1694 struct vlan_description vlan_desc
;
1695 #ifndef CONFIG_NO_VLAN
1696 int *untagged
, *tagged
, *notempty
;
1697 #endif /* CONFIG_NO_VLAN */
1699 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
1701 sm
= ieee802_1x_search_radius_identifier(hapd
, hdr
->identifier
);
1703 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Could not find matching "
1704 "station for this RADIUS message");
1705 return RADIUS_RX_UNKNOWN
;
1709 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1710 * present when packet contains an EAP-Message attribute */
1711 if (hdr
->code
== RADIUS_CODE_ACCESS_REJECT
&&
1712 radius_msg_get_attr(msg
, RADIUS_ATTR_MESSAGE_AUTHENTICATOR
, NULL
,
1714 radius_msg_get_attr(msg
, RADIUS_ATTR_EAP_MESSAGE
, NULL
, 0) < 0) {
1715 wpa_printf(MSG_DEBUG
, "Allowing RADIUS Access-Reject without "
1716 "Message-Authenticator since it does not include "
1718 } else if (radius_msg_verify(msg
, shared_secret
, shared_secret_len
,
1720 wpa_printf(MSG_INFO
, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
1721 return RADIUS_RX_INVALID_AUTHENTICATOR
;
1724 if (hdr
->code
!= RADIUS_CODE_ACCESS_ACCEPT
&&
1725 hdr
->code
!= RADIUS_CODE_ACCESS_REJECT
&&
1726 hdr
->code
!= RADIUS_CODE_ACCESS_CHALLENGE
) {
1727 wpa_printf(MSG_INFO
, "Unknown RADIUS message code");
1728 return RADIUS_RX_UNKNOWN
;
1731 sm
->radius_identifier
= -1;
1732 wpa_printf(MSG_DEBUG
, "RADIUS packet matching with station " MACSTR
,
1733 MAC2STR(sta
->addr
));
1735 radius_msg_free(sm
->last_recv_radius
);
1736 sm
->last_recv_radius
= msg
;
1738 session_timeout_set
=
1739 !radius_msg_get_attr_int32(msg
, RADIUS_ATTR_SESSION_TIMEOUT
,
1741 if (radius_msg_get_attr_int32(msg
, RADIUS_ATTR_TERMINATION_ACTION
,
1742 &termination_action
))
1743 termination_action
= RADIUS_TERMINATION_ACTION_DEFAULT
;
1745 if (hapd
->conf
->acct_interim_interval
== 0 &&
1746 hdr
->code
== RADIUS_CODE_ACCESS_ACCEPT
&&
1747 radius_msg_get_attr_int32(msg
, RADIUS_ATTR_ACCT_INTERIM_INTERVAL
,
1748 &acct_interim_interval
) == 0) {
1749 if (acct_interim_interval
< 60) {
1750 hostapd_logger(hapd
, sta
->addr
,
1751 HOSTAPD_MODULE_IEEE8021X
,
1753 "ignored too small "
1754 "Acct-Interim-Interval %d",
1755 acct_interim_interval
);
1757 sta
->acct_interim_interval
= acct_interim_interval
;
1761 switch (hdr
->code
) {
1762 case RADIUS_CODE_ACCESS_ACCEPT
:
1763 #ifndef CONFIG_NO_VLAN
1764 if (hapd
->conf
->ssid
.dynamic_vlan
!= DYNAMIC_VLAN_DISABLED
) {
1765 notempty
= &vlan_desc
.notempty
;
1766 untagged
= &vlan_desc
.untagged
;
1767 tagged
= vlan_desc
.tagged
;
1768 *notempty
= !!radius_msg_get_vlanid(msg
, untagged
,
1769 MAX_NUM_TAGGED_VLAN
,
1773 if (vlan_desc
.notempty
&&
1774 !hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
1775 sta
->eapol_sm
->authFail
= TRUE
;
1776 hostapd_logger(hapd
, sta
->addr
,
1777 HOSTAPD_MODULE_RADIUS
,
1779 "Invalid VLAN %d%s received from RADIUS server",
1781 vlan_desc
.tagged
[0] ? "+" : "");
1782 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
1783 ap_sta_set_vlan(hapd
, sta
, &vlan_desc
);
1787 if (hapd
->conf
->ssid
.dynamic_vlan
== DYNAMIC_VLAN_REQUIRED
&&
1788 !vlan_desc
.notempty
) {
1789 sta
->eapol_sm
->authFail
= TRUE
;
1790 hostapd_logger(hapd
, sta
->addr
,
1791 HOSTAPD_MODULE_IEEE8021X
,
1792 HOSTAPD_LEVEL_INFO
, "authentication "
1793 "server did not include required VLAN "
1794 "ID in Access-Accept");
1797 #endif /* CONFIG_NO_VLAN */
1799 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0)
1802 #ifndef CONFIG_NO_VLAN
1803 if (sta
->vlan_id
> 0) {
1804 hostapd_logger(hapd
, sta
->addr
,
1805 HOSTAPD_MODULE_RADIUS
,
1807 "VLAN ID %d", sta
->vlan_id
);
1809 #endif /* CONFIG_NO_VLAN */
1811 if ((sta
->flags
& WLAN_STA_ASSOC
) &&
1812 ap_sta_bind_vlan(hapd
, sta
) < 0)
1815 sta
->session_timeout_set
= !!session_timeout_set
;
1816 sta
->session_timeout
= session_timeout
;
1818 /* RFC 3580, Ch. 3.17 */
1819 if (session_timeout_set
&& termination_action
==
1820 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST
) {
1821 sm
->reAuthPeriod
= session_timeout
;
1822 } else if (session_timeout_set
)
1823 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1825 sm
->eap_if
->aaaSuccess
= TRUE
;
1826 override_eapReq
= 1;
1827 ieee802_1x_get_keys(hapd
, sta
, msg
, req
, shared_secret
,
1829 ieee802_1x_store_radius_class(hapd
, sta
, msg
);
1830 ieee802_1x_update_sta_identity(hapd
, sta
, msg
);
1831 ieee802_1x_update_sta_cui(hapd
, sta
, msg
);
1832 ieee802_1x_check_hs20(hapd
, sta
, msg
,
1833 session_timeout_set
?
1834 (int) session_timeout
: -1);
1836 case RADIUS_CODE_ACCESS_REJECT
:
1837 sm
->eap_if
->aaaFail
= TRUE
;
1838 override_eapReq
= 1;
1840 case RADIUS_CODE_ACCESS_CHALLENGE
:
1841 sm
->eap_if
->aaaEapReq
= TRUE
;
1842 if (session_timeout_set
) {
1843 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1844 sm
->eap_if
->aaaMethodTimeout
= session_timeout
;
1845 hostapd_logger(hapd
, sm
->addr
,
1846 HOSTAPD_MODULE_IEEE8021X
,
1847 HOSTAPD_LEVEL_DEBUG
,
1848 "using EAP timeout of %d seconds (from "
1850 sm
->eap_if
->aaaMethodTimeout
);
1853 * Use dynamic retransmission behavior per EAP
1856 sm
->eap_if
->aaaMethodTimeout
= 0;
1861 ieee802_1x_decapsulate_radius(hapd
, sta
);
1862 if (override_eapReq
)
1863 sm
->eap_if
->aaaEapReq
= FALSE
;
1867 if (sta
->flags
& WLAN_STA_PENDING_FILS_ERP
) {
1868 /* TODO: Add a PMKSA entry on success? */
1869 ieee802_11_finish_fils_auth(
1870 hapd
, sta
, hdr
->code
== RADIUS_CODE_ACCESS_ACCEPT
,
1871 sm
->eap_if
->aaaEapReqData
,
1872 sm
->eap_if
->aaaEapKeyData
,
1873 sm
->eap_if
->aaaEapKeyDataLen
);
1875 #endif /* NEED_AP_MLME */
1876 #endif /* CONFIG_FILS */
1878 eapol_auth_step(sm
);
1880 return RADIUS_RX_QUEUED
;
1882 #endif /* CONFIG_NO_RADIUS */
1885 void ieee802_1x_abort_auth(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1887 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1891 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1892 HOSTAPD_LEVEL_DEBUG
, "aborting authentication");
1894 #ifndef CONFIG_NO_RADIUS
1895 radius_msg_free(sm
->last_recv_radius
);
1896 sm
->last_recv_radius
= NULL
;
1897 #endif /* CONFIG_NO_RADIUS */
1899 if (sm
->eap_if
->eapTimeout
) {
1901 * Disconnect the STA since it did not reply to the last EAP
1902 * request and we cannot continue EAP processing (EAP-Failure
1903 * could only be sent if the EAP peer actually replied).
1905 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "EAP Timeout, STA " MACSTR
,
1906 MAC2STR(sta
->addr
));
1908 sm
->eap_if
->portEnabled
= FALSE
;
1909 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1910 WLAN_REASON_PREV_AUTH_NOT_VALID
);
1915 static int ieee802_1x_rekey_broadcast(struct hostapd_data
*hapd
)
1917 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
1919 if (hapd
->conf
->default_wep_key_len
< 1)
1922 os_free(eapol
->default_wep_key
);
1923 eapol
->default_wep_key
= os_malloc(hapd
->conf
->default_wep_key_len
);
1924 if (eapol
->default_wep_key
== NULL
||
1925 random_get_bytes(eapol
->default_wep_key
,
1926 hapd
->conf
->default_wep_key_len
)) {
1927 wpa_printf(MSG_INFO
, "Could not generate random WEP key");
1928 os_free(eapol
->default_wep_key
);
1929 eapol
->default_wep_key
= NULL
;
1933 wpa_hexdump_key(MSG_DEBUG
, "IEEE 802.1X: New default WEP key",
1934 eapol
->default_wep_key
,
1935 hapd
->conf
->default_wep_key_len
);
1941 static int ieee802_1x_sta_key_available(struct hostapd_data
*hapd
,
1942 struct sta_info
*sta
, void *ctx
)
1944 if (sta
->eapol_sm
) {
1945 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1946 eapol_auth_step(sta
->eapol_sm
);
1952 static void ieee802_1x_rekey(void *eloop_ctx
, void *timeout_ctx
)
1954 struct hostapd_data
*hapd
= eloop_ctx
;
1955 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
1957 if (eapol
->default_wep_key_idx
>= 3)
1958 eapol
->default_wep_key_idx
=
1959 hapd
->conf
->individual_wep_key_len
> 0 ? 1 : 0;
1961 eapol
->default_wep_key_idx
++;
1963 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: New default WEP key index %d",
1964 eapol
->default_wep_key_idx
);
1966 if (ieee802_1x_rekey_broadcast(hapd
)) {
1967 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
1968 HOSTAPD_LEVEL_WARNING
, "failed to generate a "
1969 "new broadcast key");
1970 os_free(eapol
->default_wep_key
);
1971 eapol
->default_wep_key
= NULL
;
1975 /* TODO: Could setup key for RX here, but change default TX keyid only
1976 * after new broadcast key has been sent to all stations. */
1977 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_WEP
,
1978 broadcast_ether_addr
,
1979 eapol
->default_wep_key_idx
, 1, NULL
, 0,
1980 eapol
->default_wep_key
,
1981 hapd
->conf
->default_wep_key_len
)) {
1982 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
1983 HOSTAPD_LEVEL_WARNING
, "failed to configure a "
1984 "new broadcast key");
1985 os_free(eapol
->default_wep_key
);
1986 eapol
->default_wep_key
= NULL
;
1990 ap_for_each_sta(hapd
, ieee802_1x_sta_key_available
, NULL
);
1992 if (hapd
->conf
->wep_rekeying_period
> 0) {
1993 eloop_register_timeout(hapd
->conf
->wep_rekeying_period
, 0,
1994 ieee802_1x_rekey
, hapd
, NULL
);
1999 static void ieee802_1x_eapol_send(void *ctx
, void *sta_ctx
, u8 type
,
2000 const u8
*data
, size_t datalen
)
2003 struct sta_info
*sta
= sta_ctx
;
2005 if ((sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) ==
2006 WLAN_STA_MAYBE_WPS
) {
2008 size_t identity_len
;
2009 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
2011 identity
= eap_get_identity(sm
->eap
, &identity_len
);
2013 ((identity_len
== WSC_ID_ENROLLEE_LEN
&&
2014 os_memcmp(identity
, WSC_ID_ENROLLEE
,
2015 WSC_ID_ENROLLEE_LEN
) == 0) ||
2016 (identity_len
== WSC_ID_REGISTRAR_LEN
&&
2017 os_memcmp(identity
, WSC_ID_REGISTRAR
,
2018 WSC_ID_REGISTRAR_LEN
) == 0))) {
2019 wpa_printf(MSG_DEBUG
, "WPS: WLAN_STA_MAYBE_WPS -> "
2021 sta
->flags
|= WLAN_STA_WPS
;
2024 #endif /* CONFIG_WPS */
2026 ieee802_1x_send(ctx
, sta_ctx
, type
, data
, datalen
);
2030 static void ieee802_1x_aaa_send(void *ctx
, void *sta_ctx
,
2031 const u8
*data
, size_t datalen
)
2033 #ifndef CONFIG_NO_RADIUS
2034 struct hostapd_data
*hapd
= ctx
;
2035 struct sta_info
*sta
= sta_ctx
;
2037 ieee802_1x_encapsulate_radius(hapd
, sta
, data
, datalen
);
2038 #endif /* CONFIG_NO_RADIUS */
2042 static void _ieee802_1x_finished(void *ctx
, void *sta_ctx
, int success
,
2043 int preauth
, int remediation
)
2045 struct hostapd_data
*hapd
= ctx
;
2046 struct sta_info
*sta
= sta_ctx
;
2048 rsn_preauth_finished(hapd
, sta
, success
);
2050 ieee802_1x_finished(hapd
, sta
, success
, remediation
);
2054 static int ieee802_1x_get_eap_user(void *ctx
, const u8
*identity
,
2055 size_t identity_len
, int phase2
,
2056 struct eap_user
*user
)
2058 struct hostapd_data
*hapd
= ctx
;
2059 const struct hostapd_eap_user
*eap_user
;
2063 eap_user
= hostapd_get_eap_user(hapd
, identity
, identity_len
, phase2
);
2064 if (eap_user
== NULL
)
2067 os_memset(user
, 0, sizeof(*user
));
2068 user
->phase2
= phase2
;
2069 for (i
= 0; i
< EAP_MAX_METHODS
; i
++) {
2070 user
->methods
[i
].vendor
= eap_user
->methods
[i
].vendor
;
2071 user
->methods
[i
].method
= eap_user
->methods
[i
].method
;
2074 if (eap_user
->password
) {
2075 user
->password
= os_malloc(eap_user
->password_len
);
2076 if (user
->password
== NULL
)
2078 os_memcpy(user
->password
, eap_user
->password
,
2079 eap_user
->password_len
);
2080 user
->password_len
= eap_user
->password_len
;
2081 user
->password_hash
= eap_user
->password_hash
;
2083 user
->force_version
= eap_user
->force_version
;
2084 user
->macacl
= eap_user
->macacl
;
2085 user
->ttls_auth
= eap_user
->ttls_auth
;
2086 user
->remediation
= eap_user
->remediation
;
2091 wpa_printf(MSG_DEBUG
, "%s: Failed to find user", __func__
);
2097 static int ieee802_1x_sta_entry_alive(void *ctx
, const u8
*addr
)
2099 struct hostapd_data
*hapd
= ctx
;
2100 struct sta_info
*sta
;
2101 sta
= ap_get_sta(hapd
, addr
);
2102 if (sta
== NULL
|| sta
->eapol_sm
== NULL
)
2108 static void ieee802_1x_logger(void *ctx
, const u8
*addr
,
2109 eapol_logger_level level
, const char *txt
)
2111 #ifndef CONFIG_NO_HOSTAPD_LOGGER
2112 struct hostapd_data
*hapd
= ctx
;
2116 case EAPOL_LOGGER_WARNING
:
2117 hlevel
= HOSTAPD_LEVEL_WARNING
;
2119 case EAPOL_LOGGER_INFO
:
2120 hlevel
= HOSTAPD_LEVEL_INFO
;
2122 case EAPOL_LOGGER_DEBUG
:
2124 hlevel
= HOSTAPD_LEVEL_DEBUG
;
2128 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE8021X
, hlevel
, "%s",
2130 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
2134 static void ieee802_1x_set_port_authorized(void *ctx
, void *sta_ctx
,
2137 struct hostapd_data
*hapd
= ctx
;
2138 struct sta_info
*sta
= sta_ctx
;
2139 ieee802_1x_set_sta_authorized(hapd
, sta
, authorized
);
2143 static void _ieee802_1x_abort_auth(void *ctx
, void *sta_ctx
)
2145 struct hostapd_data
*hapd
= ctx
;
2146 struct sta_info
*sta
= sta_ctx
;
2147 ieee802_1x_abort_auth(hapd
, sta
);
2151 static void _ieee802_1x_tx_key(void *ctx
, void *sta_ctx
)
2154 #ifndef CONFIG_NO_RC4
2155 struct hostapd_data
*hapd
= ctx
;
2156 struct sta_info
*sta
= sta_ctx
;
2157 ieee802_1x_tx_key(hapd
, sta
);
2158 #endif /* CONFIG_NO_RC4 */
2159 #endif /* CONFIG_FIPS */
2163 static void ieee802_1x_eapol_event(void *ctx
, void *sta_ctx
,
2164 enum eapol_event type
)
2166 /* struct hostapd_data *hapd = ctx; */
2167 struct sta_info
*sta
= sta_ctx
;
2169 case EAPOL_AUTH_SM_CHANGE
:
2170 wpa_auth_sm_notify(sta
->wpa_sm
);
2172 case EAPOL_AUTH_REAUTHENTICATE
:
2173 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
2181 static struct eap_server_erp_key
*
2182 ieee802_1x_erp_get_key(void *ctx
, const char *keyname
)
2184 struct hostapd_data
*hapd
= ctx
;
2185 struct eap_server_erp_key
*erp
;
2187 dl_list_for_each(erp
, &hapd
->erp_keys
, struct eap_server_erp_key
,
2189 if (os_strcmp(erp
->keyname_nai
, keyname
) == 0)
2197 static int ieee802_1x_erp_add_key(void *ctx
, struct eap_server_erp_key
*erp
)
2199 struct hostapd_data
*hapd
= ctx
;
2201 dl_list_add(&hapd
->erp_keys
, &erp
->list
);
2205 #endif /* CONFIG_ERP */
2208 int ieee802_1x_init(struct hostapd_data
*hapd
)
2211 struct eapol_auth_config conf
;
2212 struct eapol_auth_cb cb
;
2214 dl_list_init(&hapd
->erp_keys
);
2216 os_memset(&conf
, 0, sizeof(conf
));
2218 conf
.eap_reauth_period
= hapd
->conf
->eap_reauth_period
;
2219 conf
.wpa
= hapd
->conf
->wpa
;
2220 conf
.individual_wep_key_len
= hapd
->conf
->individual_wep_key_len
;
2221 conf
.eap_server
= hapd
->conf
->eap_server
;
2222 conf
.ssl_ctx
= hapd
->ssl_ctx
;
2223 conf
.msg_ctx
= hapd
->msg_ctx
;
2224 conf
.eap_sim_db_priv
= hapd
->eap_sim_db_priv
;
2225 conf
.eap_req_id_text
= hapd
->conf
->eap_req_id_text
;
2226 conf
.eap_req_id_text_len
= hapd
->conf
->eap_req_id_text_len
;
2227 conf
.erp_send_reauth_start
= hapd
->conf
->erp_send_reauth_start
;
2228 conf
.erp_domain
= hapd
->conf
->erp_domain
;
2229 conf
.erp
= hapd
->conf
->eap_server_erp
;
2230 conf
.tls_session_lifetime
= hapd
->conf
->tls_session_lifetime
;
2231 conf
.pac_opaque_encr_key
= hapd
->conf
->pac_opaque_encr_key
;
2232 conf
.eap_fast_a_id
= hapd
->conf
->eap_fast_a_id
;
2233 conf
.eap_fast_a_id_len
= hapd
->conf
->eap_fast_a_id_len
;
2234 conf
.eap_fast_a_id_info
= hapd
->conf
->eap_fast_a_id_info
;
2235 conf
.eap_fast_prov
= hapd
->conf
->eap_fast_prov
;
2236 conf
.pac_key_lifetime
= hapd
->conf
->pac_key_lifetime
;
2237 conf
.pac_key_refresh_time
= hapd
->conf
->pac_key_refresh_time
;
2238 conf
.eap_sim_aka_result_ind
= hapd
->conf
->eap_sim_aka_result_ind
;
2239 conf
.tnc
= hapd
->conf
->tnc
;
2240 conf
.wps
= hapd
->wps
;
2241 conf
.fragment_size
= hapd
->conf
->fragment_size
;
2242 conf
.pwd_group
= hapd
->conf
->pwd_group
;
2243 conf
.pbc_in_m1
= hapd
->conf
->pbc_in_m1
;
2244 if (hapd
->conf
->server_id
) {
2245 conf
.server_id
= (const u8
*) hapd
->conf
->server_id
;
2246 conf
.server_id_len
= os_strlen(hapd
->conf
->server_id
);
2248 conf
.server_id
= (const u8
*) "hostapd";
2249 conf
.server_id_len
= 7;
2252 os_memset(&cb
, 0, sizeof(cb
));
2253 cb
.eapol_send
= ieee802_1x_eapol_send
;
2254 cb
.aaa_send
= ieee802_1x_aaa_send
;
2255 cb
.finished
= _ieee802_1x_finished
;
2256 cb
.get_eap_user
= ieee802_1x_get_eap_user
;
2257 cb
.sta_entry_alive
= ieee802_1x_sta_entry_alive
;
2258 cb
.logger
= ieee802_1x_logger
;
2259 cb
.set_port_authorized
= ieee802_1x_set_port_authorized
;
2260 cb
.abort_auth
= _ieee802_1x_abort_auth
;
2261 cb
.tx_key
= _ieee802_1x_tx_key
;
2262 cb
.eapol_event
= ieee802_1x_eapol_event
;
2264 cb
.erp_get_key
= ieee802_1x_erp_get_key
;
2265 cb
.erp_add_key
= ieee802_1x_erp_add_key
;
2266 #endif /* CONFIG_ERP */
2268 hapd
->eapol_auth
= eapol_auth_init(&conf
, &cb
);
2269 if (hapd
->eapol_auth
== NULL
)
2272 if ((hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
) &&
2273 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1))
2276 #ifndef CONFIG_NO_RADIUS
2277 if (radius_client_register(hapd
->radius
, RADIUS_AUTH
,
2278 ieee802_1x_receive_auth
, hapd
))
2280 #endif /* CONFIG_NO_RADIUS */
2282 if (hapd
->conf
->default_wep_key_len
) {
2283 for (i
= 0; i
< 4; i
++)
2284 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2285 WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
2288 ieee802_1x_rekey(hapd
, NULL
);
2290 if (hapd
->eapol_auth
->default_wep_key
== NULL
)
2298 void ieee802_1x_erp_flush(struct hostapd_data
*hapd
)
2300 struct eap_server_erp_key
*erp
;
2302 while ((erp
= dl_list_first(&hapd
->erp_keys
, struct eap_server_erp_key
,
2304 dl_list_del(&erp
->list
);
2305 bin_clear_free(erp
, sizeof(*erp
));
2310 void ieee802_1x_deinit(struct hostapd_data
*hapd
)
2312 eloop_cancel_timeout(ieee802_1x_rekey
, hapd
, NULL
);
2314 if (hapd
->driver
&& hapd
->drv_priv
&&
2315 (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
))
2316 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
2318 eapol_auth_deinit(hapd
->eapol_auth
);
2319 hapd
->eapol_auth
= NULL
;
2321 ieee802_1x_erp_flush(hapd
);
2325 int ieee802_1x_tx_status(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2326 const u8
*buf
, size_t len
, int ack
)
2328 struct ieee80211_hdr
*hdr
;
2330 const unsigned char rfc1042_hdr
[ETH_ALEN
] =
2331 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2335 if (len
< sizeof(*hdr
) + sizeof(rfc1042_hdr
) + 2)
2338 hdr
= (struct ieee80211_hdr
*) buf
;
2339 pos
= (u8
*) (hdr
+ 1);
2340 if (os_memcmp(pos
, rfc1042_hdr
, sizeof(rfc1042_hdr
)) != 0)
2342 pos
+= sizeof(rfc1042_hdr
);
2343 if (WPA_GET_BE16(pos
) != ETH_P_PAE
)
2347 return ieee802_1x_eapol_tx_status(hapd
, sta
, pos
, buf
+ len
- pos
,
2352 int ieee802_1x_eapol_tx_status(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2353 const u8
*buf
, int len
, int ack
)
2355 const struct ieee802_1x_hdr
*xhdr
=
2356 (const struct ieee802_1x_hdr
*) buf
;
2357 const u8
*pos
= buf
+ sizeof(*xhdr
);
2358 struct ieee802_1x_eapol_key
*key
;
2360 if (len
< (int) sizeof(*xhdr
))
2362 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: " MACSTR
" TX status - version=%d "
2363 "type=%d length=%d - ack=%d",
2364 MAC2STR(sta
->addr
), xhdr
->version
, xhdr
->type
,
2365 be_to_host16(xhdr
->length
), ack
);
2368 if (xhdr
->type
== IEEE802_1X_TYPE_EAP_PACKET
&& ack
&&
2369 (sta
->flags
& WLAN_STA_WPS
) &&
2370 ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd
, sta
)) {
2371 wpa_printf(MSG_DEBUG
,
2372 "WPS: Indicate EAP completion on ACK for EAP-Failure");
2373 hostapd_wps_eap_completed(hapd
);
2375 #endif /* CONFIG_WPS */
2377 if (xhdr
->type
!= IEEE802_1X_TYPE_EAPOL_KEY
)
2380 if (pos
+ sizeof(struct wpa_eapol_key
) <= buf
+ len
) {
2381 const struct wpa_eapol_key
*wpa
;
2382 wpa
= (const struct wpa_eapol_key
*) pos
;
2383 if (wpa
->type
== EAPOL_KEY_TYPE_RSN
||
2384 wpa
->type
== EAPOL_KEY_TYPE_WPA
)
2385 wpa_auth_eapol_key_tx_status(hapd
->wpa_auth
,
2389 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2390 * or Authenticator state machines, but EAPOL-Key packets are not
2391 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
2392 * packets couple of times because otherwise STA keys become
2393 * unsynchronized with AP. */
2394 if (!ack
&& pos
+ sizeof(*key
) <= buf
+ len
) {
2395 key
= (struct ieee802_1x_eapol_key
*) pos
;
2396 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
2397 HOSTAPD_LEVEL_DEBUG
, "did not Ack EAPOL-Key "
2398 "frame (%scast index=%d)",
2399 key
->key_index
& BIT(7) ? "uni" : "broad",
2400 key
->key_index
& ~BIT(7));
2401 /* TODO: re-send EAPOL-Key couple of times (with short delay
2402 * between them?). If all attempt fail, report error and
2403 * deauthenticate STA so that it will get new keys when
2404 * authenticating again (e.g., after returning in range).
2405 * Separate limit/transmit state needed both for unicast and
2406 * broadcast keys(?) */
2408 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2409 * to here and change the key only if the EAPOL-Key packet was Acked.
2416 u8
* ieee802_1x_get_identity(struct eapol_state_machine
*sm
, size_t *len
)
2418 if (sm
== NULL
|| sm
->identity
== NULL
)
2421 *len
= sm
->identity_len
;
2422 return sm
->identity
;
2426 u8
* ieee802_1x_get_radius_class(struct eapol_state_machine
*sm
, size_t *len
,
2429 if (sm
== NULL
|| sm
->radius_class
.attr
== NULL
||
2430 idx
>= (int) sm
->radius_class
.count
)
2433 *len
= sm
->radius_class
.attr
[idx
].len
;
2434 return sm
->radius_class
.attr
[idx
].data
;
2438 struct wpabuf
* ieee802_1x_get_radius_cui(struct eapol_state_machine
*sm
)
2442 return sm
->radius_cui
;
2446 const u8
* ieee802_1x_get_key(struct eapol_state_machine
*sm
, size_t *len
)
2452 *len
= sm
->eap_if
->eapKeyDataLen
;
2453 return sm
->eap_if
->eapKeyData
;
2457 void ieee802_1x_notify_port_enabled(struct eapol_state_machine
*sm
,
2462 sm
->eap_if
->portEnabled
= enabled
? TRUE
: FALSE
;
2463 eapol_auth_step(sm
);
2467 void ieee802_1x_notify_port_valid(struct eapol_state_machine
*sm
,
2472 sm
->portValid
= valid
? TRUE
: FALSE
;
2473 eapol_auth_step(sm
);
2477 void ieee802_1x_notify_pre_auth(struct eapol_state_machine
*sm
, int pre_auth
)
2482 sm
->flags
|= EAPOL_SM_PREAUTH
;
2484 sm
->flags
&= ~EAPOL_SM_PREAUTH
;
2488 static const char * bool_txt(Boolean val
)
2490 return val
? "TRUE" : "FALSE";
2494 int ieee802_1x_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
2501 int ieee802_1x_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2502 char *buf
, size_t buflen
)
2505 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
2506 struct os_reltime diff
;
2513 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2514 "dot1xPaePortNumber=%d\n"
2515 "dot1xPaePortProtocolVersion=%d\n"
2516 "dot1xPaePortCapabilities=1\n"
2517 "dot1xPaePortInitialize=%d\n"
2518 "dot1xPaePortReauthenticate=FALSE\n",
2522 if (os_snprintf_error(buflen
- len
, ret
))
2526 /* dot1xAuthConfigTable */
2527 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2528 "dot1xAuthPaeState=%d\n"
2529 "dot1xAuthBackendAuthState=%d\n"
2530 "dot1xAuthAdminControlledDirections=%d\n"
2531 "dot1xAuthOperControlledDirections=%d\n"
2532 "dot1xAuthAuthControlledPortStatus=%d\n"
2533 "dot1xAuthAuthControlledPortControl=%d\n"
2534 "dot1xAuthQuietPeriod=%u\n"
2535 "dot1xAuthServerTimeout=%u\n"
2536 "dot1xAuthReAuthPeriod=%u\n"
2537 "dot1xAuthReAuthEnabled=%s\n"
2538 "dot1xAuthKeyTxEnabled=%s\n",
2539 sm
->auth_pae_state
+ 1,
2540 sm
->be_auth_state
+ 1,
2541 sm
->adminControlledDirections
,
2542 sm
->operControlledDirections
,
2548 bool_txt(sm
->reAuthEnabled
),
2549 bool_txt(sm
->keyTxEnabled
));
2550 if (os_snprintf_error(buflen
- len
, ret
))
2554 /* dot1xAuthStatsTable */
2555 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2556 "dot1xAuthEapolFramesRx=%u\n"
2557 "dot1xAuthEapolFramesTx=%u\n"
2558 "dot1xAuthEapolStartFramesRx=%u\n"
2559 "dot1xAuthEapolLogoffFramesRx=%u\n"
2560 "dot1xAuthEapolRespIdFramesRx=%u\n"
2561 "dot1xAuthEapolRespFramesRx=%u\n"
2562 "dot1xAuthEapolReqIdFramesTx=%u\n"
2563 "dot1xAuthEapolReqFramesTx=%u\n"
2564 "dot1xAuthInvalidEapolFramesRx=%u\n"
2565 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2566 "dot1xAuthLastEapolFrameVersion=%u\n"
2567 "dot1xAuthLastEapolFrameSource=" MACSTR
"\n",
2568 sm
->dot1xAuthEapolFramesRx
,
2569 sm
->dot1xAuthEapolFramesTx
,
2570 sm
->dot1xAuthEapolStartFramesRx
,
2571 sm
->dot1xAuthEapolLogoffFramesRx
,
2572 sm
->dot1xAuthEapolRespIdFramesRx
,
2573 sm
->dot1xAuthEapolRespFramesRx
,
2574 sm
->dot1xAuthEapolReqIdFramesTx
,
2575 sm
->dot1xAuthEapolReqFramesTx
,
2576 sm
->dot1xAuthInvalidEapolFramesRx
,
2577 sm
->dot1xAuthEapLengthErrorFramesRx
,
2578 sm
->dot1xAuthLastEapolFrameVersion
,
2580 if (os_snprintf_error(buflen
- len
, ret
))
2584 /* dot1xAuthDiagTable */
2585 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2586 "dot1xAuthEntersConnecting=%u\n"
2587 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2588 "dot1xAuthEntersAuthenticating=%u\n"
2589 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2590 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2591 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2592 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2593 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2594 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2595 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2596 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2597 "dot1xAuthBackendResponses=%u\n"
2598 "dot1xAuthBackendAccessChallenges=%u\n"
2599 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2600 "dot1xAuthBackendAuthSuccesses=%u\n"
2601 "dot1xAuthBackendAuthFails=%u\n",
2602 sm
->authEntersConnecting
,
2603 sm
->authEapLogoffsWhileConnecting
,
2604 sm
->authEntersAuthenticating
,
2605 sm
->authAuthSuccessesWhileAuthenticating
,
2606 sm
->authAuthTimeoutsWhileAuthenticating
,
2607 sm
->authAuthFailWhileAuthenticating
,
2608 sm
->authAuthEapStartsWhileAuthenticating
,
2609 sm
->authAuthEapLogoffWhileAuthenticating
,
2610 sm
->authAuthReauthsWhileAuthenticated
,
2611 sm
->authAuthEapStartsWhileAuthenticated
,
2612 sm
->authAuthEapLogoffWhileAuthenticated
,
2613 sm
->backendResponses
,
2614 sm
->backendAccessChallenges
,
2615 sm
->backendOtherRequestsToSupplicant
,
2616 sm
->backendAuthSuccesses
,
2617 sm
->backendAuthFails
);
2618 if (os_snprintf_error(buflen
- len
, ret
))
2622 /* dot1xAuthSessionStatsTable */
2623 os_reltime_age(&sta
->acct_session_start
, &diff
);
2624 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2625 /* TODO: dot1xAuthSessionOctetsRx */
2626 /* TODO: dot1xAuthSessionOctetsTx */
2627 /* TODO: dot1xAuthSessionFramesRx */
2628 /* TODO: dot1xAuthSessionFramesTx */
2629 "dot1xAuthSessionId=%016llX\n"
2630 "dot1xAuthSessionAuthenticMethod=%d\n"
2631 "dot1xAuthSessionTime=%u\n"
2632 "dot1xAuthSessionTerminateCause=999\n"
2633 "dot1xAuthSessionUserName=%s\n",
2634 (unsigned long long) sta
->acct_session_id
,
2635 (wpa_key_mgmt_wpa_ieee8021x(
2636 wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) ?
2638 (unsigned int) diff
.sec
,
2640 if (os_snprintf_error(buflen
- len
, ret
))
2644 if (sm
->acct_multi_session_id
) {
2645 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2646 "authMultiSessionId=%016llX\n",
2647 (unsigned long long)
2648 sm
->acct_multi_session_id
);
2649 if (os_snprintf_error(buflen
- len
, ret
))
2654 name1
= eap_server_get_name(0, sm
->eap_type_authsrv
);
2655 name2
= eap_server_get_name(0, sm
->eap_type_supp
);
2656 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2657 "last_eap_type_as=%d (%s)\n"
2658 "last_eap_type_sta=%d (%s)\n",
2659 sm
->eap_type_authsrv
, name1
,
2660 sm
->eap_type_supp
, name2
);
2661 if (os_snprintf_error(buflen
- len
, ret
))
2670 static void ieee802_1x_wnm_notif_send(void *eloop_ctx
, void *timeout_ctx
)
2672 struct hostapd_data
*hapd
= eloop_ctx
;
2673 struct sta_info
*sta
= timeout_ctx
;
2675 if (sta
->remediation
) {
2676 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to "
2677 MACSTR
" to indicate Subscription Remediation",
2678 MAC2STR(sta
->addr
));
2679 hs20_send_wnm_notification(hapd
, sta
->addr
,
2680 sta
->remediation_method
,
2681 sta
->remediation_url
);
2682 os_free(sta
->remediation_url
);
2683 sta
->remediation_url
= NULL
;
2686 if (sta
->hs20_deauth_req
) {
2687 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to "
2688 MACSTR
" to indicate imminent deauthentication",
2689 MAC2STR(sta
->addr
));
2690 hs20_send_wnm_notification_deauth_req(hapd
, sta
->addr
,
2691 sta
->hs20_deauth_req
);
2694 #endif /* CONFIG_HS20 */
2697 static void ieee802_1x_finished(struct hostapd_data
*hapd
,
2698 struct sta_info
*sta
, int success
,
2703 /* TODO: get PMKLifetime from WPA parameters */
2704 static const int dot11RSNAConfigPMKLifetime
= 43200;
2705 unsigned int session_timeout
;
2708 if (remediation
&& !sta
->remediation
) {
2709 sta
->remediation
= 1;
2710 os_free(sta
->remediation_url
);
2711 sta
->remediation_url
=
2712 os_strdup(hapd
->conf
->subscr_remediation_url
);
2713 sta
->remediation_method
= 1; /* SOAP-XML SPP */
2716 if (success
&& (sta
->remediation
|| sta
->hs20_deauth_req
)) {
2717 wpa_printf(MSG_DEBUG
, "HS 2.0: Schedule WNM-Notification to "
2718 MACSTR
" in 100 ms", MAC2STR(sta
->addr
));
2719 eloop_cancel_timeout(ieee802_1x_wnm_notif_send
, hapd
, sta
);
2720 eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send
,
2723 #endif /* CONFIG_HS20 */
2725 key
= ieee802_1x_get_key(sta
->eapol_sm
, &len
);
2726 if (sta
->session_timeout_set
)
2727 session_timeout
= sta
->session_timeout
;
2729 session_timeout
= dot11RSNAConfigPMKLifetime
;
2730 if (success
&& key
&& len
>= PMK_LEN
&& !sta
->remediation
&&
2731 !sta
->hs20_deauth_requested
&&
2732 wpa_auth_pmksa_add(sta
->wpa_sm
, key
, len
, session_timeout
,
2733 sta
->eapol_sm
) == 0) {
2734 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
2735 HOSTAPD_LEVEL_DEBUG
,
2736 "Added PMKSA cache entry (IEEE 802.1X)");
2741 * Many devices require deauthentication after WPS provisioning
2742 * and some may not be be able to do that themselves, so
2743 * disconnect the client here. In addition, this may also
2744 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2745 * the EAPOL PAE state machine would remain in HELD state for
2746 * considerable amount of time and some EAP methods, like
2747 * EAP-FAST with anonymous provisioning, may require another
2748 * EAPOL authentication to be started to complete connection.
2750 ap_sta_delayed_1x_auth_fail_disconnect(hapd
, sta
);