2 * hostapd / IEEE 802.1X-2004 Authenticator
3 * Copyright (c) 2002-2019, 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"
37 #include "wpa_auth_kay.h"
41 static void ieee802_1x_wnm_notif_send(void *eloop_ctx
, void *timeout_ctx
);
42 #endif /* CONFIG_HS20 */
43 static void ieee802_1x_finished(struct hostapd_data
*hapd
,
44 struct sta_info
*sta
, int success
,
48 static void ieee802_1x_send(struct hostapd_data
*hapd
, struct sta_info
*sta
,
49 u8 type
, const u8
*data
, size_t datalen
)
52 struct ieee802_1x_hdr
*xhdr
;
56 len
= sizeof(*xhdr
) + datalen
;
59 wpa_printf(MSG_ERROR
, "malloc() failed for "
60 "ieee802_1x_send(len=%lu)",
65 xhdr
= (struct ieee802_1x_hdr
*) buf
;
66 xhdr
->version
= hapd
->conf
->eapol_version
;
68 if (xhdr
->version
> 2 && hapd
->conf
->macsec_policy
== 0)
70 #endif /* CONFIG_MACSEC */
72 xhdr
->length
= host_to_be16(datalen
);
74 if (datalen
> 0 && data
!= NULL
)
75 os_memcpy(xhdr
+ 1, data
, datalen
);
77 if (wpa_auth_pairwise_set(sta
->wpa_sm
))
79 #ifdef CONFIG_TESTING_OPTIONS
80 if (hapd
->ext_eapol_frame_io
) {
81 size_t hex_len
= 2 * len
+ 1;
82 char *hex
= os_malloc(hex_len
);
85 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
86 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
87 "EAPOL-TX " MACSTR
" %s",
88 MAC2STR(sta
->addr
), hex
);
92 #endif /* CONFIG_TESTING_OPTIONS */
93 if (sta
->flags
& WLAN_STA_PREAUTH
) {
94 rsn_preauth_send(hapd
, sta
, buf
, len
);
96 hostapd_drv_hapd_send_eapol(
97 hapd
, sta
->addr
, buf
, len
,
98 encrypt
, hostapd_sta_flags_to_drv(sta
->flags
));
105 void ieee802_1x_set_sta_authorized(struct hostapd_data
*hapd
,
106 struct sta_info
*sta
, int authorized
)
110 if (sta
->flags
& WLAN_STA_PREAUTH
)
114 ap_sta_set_authorized(hapd
, sta
, 1);
115 res
= hostapd_set_authorized(hapd
, sta
, 1);
116 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
117 HOSTAPD_LEVEL_DEBUG
, "authorizing port");
119 ap_sta_set_authorized(hapd
, sta
, 0);
120 res
= hostapd_set_authorized(hapd
, sta
, 0);
121 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
122 HOSTAPD_LEVEL_DEBUG
, "unauthorizing port");
125 if (res
&& errno
!= ENOENT
) {
126 wpa_printf(MSG_DEBUG
, "Could not set station " MACSTR
127 " flags for kernel driver (errno=%d).",
128 MAC2STR(sta
->addr
), errno
);
132 os_get_reltime(&sta
->connected_time
);
133 accounting_sta_start(hapd
, sta
);
139 #ifndef CONFIG_NO_RC4
141 static void ieee802_1x_tx_key_one(struct hostapd_data
*hapd
,
142 struct sta_info
*sta
,
143 int idx
, int broadcast
,
144 u8
*key_data
, size_t key_len
)
147 struct ieee802_1x_hdr
*hdr
;
148 struct ieee802_1x_eapol_key
*key
;
149 size_t len
, ekey_len
;
150 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
155 len
= sizeof(*key
) + key_len
;
156 buf
= os_zalloc(sizeof(*hdr
) + len
);
160 hdr
= (struct ieee802_1x_hdr
*) buf
;
161 key
= (struct ieee802_1x_eapol_key
*) (hdr
+ 1);
162 key
->type
= EAPOL_KEY_TYPE_RC4
;
163 WPA_PUT_BE16(key
->key_length
, key_len
);
164 wpa_get_ntp_timestamp(key
->replay_counter
);
165 if (os_memcmp(key
->replay_counter
,
166 hapd
->last_1x_eapol_key_replay_counter
,
167 IEEE8021X_REPLAY_COUNTER_LEN
) <= 0) {
168 /* NTP timestamp did not increment from last EAPOL-Key frame;
169 * use previously used value + 1 instead. */
170 inc_byte_array(hapd
->last_1x_eapol_key_replay_counter
,
171 IEEE8021X_REPLAY_COUNTER_LEN
);
172 os_memcpy(key
->replay_counter
,
173 hapd
->last_1x_eapol_key_replay_counter
,
174 IEEE8021X_REPLAY_COUNTER_LEN
);
176 os_memcpy(hapd
->last_1x_eapol_key_replay_counter
,
178 IEEE8021X_REPLAY_COUNTER_LEN
);
181 if (random_get_bytes(key
->key_iv
, sizeof(key
->key_iv
))) {
182 wpa_printf(MSG_ERROR
, "Could not get random numbers");
187 key
->key_index
= idx
| (broadcast
? 0 : BIT(7));
188 if (hapd
->conf
->eapol_key_index_workaround
) {
189 /* According to some information, WinXP Supplicant seems to
190 * interpret bit7 as an indication whether the key is to be
191 * activated, so make it possible to enable workaround that
192 * sets this bit for all keys. */
193 key
->key_index
|= BIT(7);
196 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
197 * MSK[32..63] is used to sign the message. */
198 if (sm
->eap_if
->eapKeyData
== NULL
|| sm
->eap_if
->eapKeyDataLen
< 64) {
199 wpa_printf(MSG_ERROR
, "No eapKeyData available for encrypting "
200 "and signing EAPOL-Key");
204 os_memcpy((u8
*) (key
+ 1), key_data
, key_len
);
205 ekey_len
= sizeof(key
->key_iv
) + 32;
206 ekey
= os_malloc(ekey_len
);
208 wpa_printf(MSG_ERROR
, "Could not encrypt key");
212 os_memcpy(ekey
, key
->key_iv
, sizeof(key
->key_iv
));
213 os_memcpy(ekey
+ sizeof(key
->key_iv
), sm
->eap_if
->eapKeyData
, 32);
214 rc4_skip(ekey
, ekey_len
, 0, (u8
*) (key
+ 1), key_len
);
217 /* This header is needed here for HMAC-MD5, but it will be regenerated
218 * in ieee802_1x_send() */
219 hdr
->version
= hapd
->conf
->eapol_version
;
221 if (hdr
->version
> 2)
223 #endif /* CONFIG_MACSEC */
224 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
225 hdr
->length
= host_to_be16(len
);
226 hmac_md5(sm
->eap_if
->eapKeyData
+ 32, 32, buf
, sizeof(*hdr
) + len
,
229 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
230 " (%s index=%d)", MAC2STR(sm
->addr
),
231 broadcast
? "broadcast" : "unicast", idx
);
232 ieee802_1x_send(hapd
, sta
, IEEE802_1X_TYPE_EAPOL_KEY
, (u8
*) key
, len
);
234 sta
->eapol_sm
->dot1xAuthEapolFramesTx
++;
239 static void ieee802_1x_tx_key(struct hostapd_data
*hapd
, struct sta_info
*sta
)
241 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
242 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
244 if (sm
== NULL
|| !sm
->eap_if
->eapKeyData
)
247 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR
,
250 #ifndef CONFIG_NO_VLAN
251 if (sta
->vlan_id
> 0) {
252 wpa_printf(MSG_ERROR
, "Using WEP with vlans is not supported.");
255 #endif /* CONFIG_NO_VLAN */
257 if (eapol
->default_wep_key
) {
258 ieee802_1x_tx_key_one(hapd
, sta
, eapol
->default_wep_key_idx
, 1,
259 eapol
->default_wep_key
,
260 hapd
->conf
->default_wep_key_len
);
263 if (hapd
->conf
->individual_wep_key_len
> 0) {
265 ikey
= os_malloc(hapd
->conf
->individual_wep_key_len
);
267 random_get_bytes(ikey
, hapd
->conf
->individual_wep_key_len
))
269 wpa_printf(MSG_ERROR
, "Could not generate random "
270 "individual WEP key.");
275 wpa_hexdump_key(MSG_DEBUG
, "Individual WEP key",
276 ikey
, hapd
->conf
->individual_wep_key_len
);
278 ieee802_1x_tx_key_one(hapd
, sta
, 0, 0, ikey
,
279 hapd
->conf
->individual_wep_key_len
);
281 /* TODO: set encryption in TX callback, i.e., only after STA
282 * has ACKed EAPOL-Key frame */
283 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_WEP
,
284 sta
->addr
, 0, 1, NULL
, 0, ikey
,
285 hapd
->conf
->individual_wep_key_len
)) {
286 wpa_printf(MSG_ERROR
, "Could not set individual WEP "
294 #endif /* CONFIG_NO_RC4 */
295 #endif /* CONFIG_FIPS */
298 const char *radius_mode_txt(struct hostapd_data
*hapd
)
300 switch (hapd
->iface
->conf
->hw_mode
) {
301 case HOSTAPD_MODE_IEEE80211AD
:
303 case HOSTAPD_MODE_IEEE80211A
:
305 case HOSTAPD_MODE_IEEE80211G
:
307 case HOSTAPD_MODE_IEEE80211B
:
314 int radius_sta_rate(struct hostapd_data
*hapd
, struct sta_info
*sta
)
319 for (i
= 0; i
< sta
->supported_rates_len
; i
++)
320 if ((sta
->supported_rates
[i
] & 0x7f) > rate
)
321 rate
= sta
->supported_rates
[i
] & 0x7f;
327 #ifndef CONFIG_NO_RADIUS
328 static void ieee802_1x_learn_identity(struct hostapd_data
*hapd
,
329 struct eapol_state_machine
*sm
,
330 const u8
*eap
, size_t len
)
334 const struct eap_hdr
*hdr
= (const struct eap_hdr
*) eap
;
336 if (len
<= sizeof(struct eap_hdr
) ||
337 (hdr
->code
== EAP_CODE_RESPONSE
&&
338 eap
[sizeof(struct eap_hdr
)] != EAP_TYPE_IDENTITY
) ||
339 (hdr
->code
== EAP_CODE_INITIATE
&&
340 eap
[sizeof(struct eap_hdr
)] != EAP_ERP_TYPE_REAUTH
) ||
341 (hdr
->code
!= EAP_CODE_RESPONSE
&&
342 hdr
->code
!= EAP_CODE_INITIATE
))
345 eap_erp_update_identity(sm
->eap
, eap
, len
);
346 identity
= eap_get_identity(sm
->eap
, &identity_len
);
347 if (identity
== NULL
)
350 /* Save station identity for future RADIUS packets */
351 os_free(sm
->identity
);
352 sm
->identity
= (u8
*) dup_binstr(identity
, identity_len
);
353 if (sm
->identity
== NULL
) {
354 sm
->identity_len
= 0;
358 sm
->identity_len
= identity_len
;
359 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
360 HOSTAPD_LEVEL_DEBUG
, "STA identity '%s'", sm
->identity
);
361 sm
->dot1xAuthEapolRespIdFramesRx
++;
365 static int add_common_radius_sta_attr_rsn(struct hostapd_data
*hapd
,
366 struct hostapd_radius_attr
*req_attr
,
367 struct sta_info
*sta
,
368 struct radius_msg
*msg
)
373 ver
= wpa_auth_sta_wpa_version(sta
->wpa_sm
);
374 val
= wpa_auth_get_pairwise(sta
->wpa_sm
);
375 suite
= wpa_cipher_to_suite(ver
, val
);
377 !hostapd_config_get_radius_attr(req_attr
,
378 RADIUS_ATTR_WLAN_PAIRWISE_CIPHER
) &&
379 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER
,
381 wpa_printf(MSG_ERROR
, "Could not add WLAN-Pairwise-Cipher");
385 suite
= wpa_cipher_to_suite(((hapd
->conf
->wpa
& 0x2) ||
387 WPA_PROTO_RSN
: WPA_PROTO_WPA
,
388 hapd
->conf
->wpa_group
);
389 if (!hostapd_config_get_radius_attr(req_attr
,
390 RADIUS_ATTR_WLAN_GROUP_CIPHER
) &&
391 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_WLAN_GROUP_CIPHER
,
393 wpa_printf(MSG_ERROR
, "Could not add WLAN-Group-Cipher");
397 val
= wpa_auth_sta_key_mgmt(sta
->wpa_sm
);
398 suite
= wpa_akm_to_suite(val
);
400 !hostapd_config_get_radius_attr(req_attr
,
401 RADIUS_ATTR_WLAN_AKM_SUITE
) &&
402 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_WLAN_AKM_SUITE
,
404 wpa_printf(MSG_ERROR
, "Could not add WLAN-AKM-Suite");
408 #ifdef CONFIG_IEEE80211W
409 if (hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
410 suite
= wpa_cipher_to_suite(WPA_PROTO_RSN
,
411 hapd
->conf
->group_mgmt_cipher
);
412 if (!hostapd_config_get_radius_attr(
413 req_attr
, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER
) &&
414 !radius_msg_add_attr_int32(
415 msg
, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER
, suite
)) {
416 wpa_printf(MSG_ERROR
,
417 "Could not add WLAN-Group-Mgmt-Cipher");
421 #endif /* CONFIG_IEEE80211W */
427 static int add_common_radius_sta_attr(struct hostapd_data
*hapd
,
428 struct hostapd_radius_attr
*req_attr
,
429 struct sta_info
*sta
,
430 struct radius_msg
*msg
)
434 if (!hostapd_config_get_radius_attr(req_attr
,
435 RADIUS_ATTR_SERVICE_TYPE
) &&
436 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_SERVICE_TYPE
,
437 RADIUS_SERVICE_TYPE_FRAMED
)) {
438 wpa_printf(MSG_ERROR
, "Could not add Service-Type");
442 if (!hostapd_config_get_radius_attr(req_attr
,
443 RADIUS_ATTR_NAS_PORT
) &&
445 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_NAS_PORT
, sta
->aid
)) {
446 wpa_printf(MSG_ERROR
, "Could not add NAS-Port");
450 os_snprintf(buf
, sizeof(buf
), RADIUS_802_1X_ADDR_FORMAT
,
452 buf
[sizeof(buf
) - 1] = '\0';
453 if (!radius_msg_add_attr(msg
, RADIUS_ATTR_CALLING_STATION_ID
,
454 (u8
*) buf
, os_strlen(buf
))) {
455 wpa_printf(MSG_ERROR
, "Could not add Calling-Station-Id");
459 if (sta
->flags
& WLAN_STA_PREAUTH
) {
460 os_strlcpy(buf
, "IEEE 802.11i Pre-Authentication",
463 os_snprintf(buf
, sizeof(buf
), "CONNECT %d%sMbps %s",
464 radius_sta_rate(hapd
, sta
) / 2,
465 (radius_sta_rate(hapd
, sta
) & 1) ? ".5" : "",
466 radius_mode_txt(hapd
));
467 buf
[sizeof(buf
) - 1] = '\0';
469 if (!hostapd_config_get_radius_attr(req_attr
,
470 RADIUS_ATTR_CONNECT_INFO
) &&
471 !radius_msg_add_attr(msg
, RADIUS_ATTR_CONNECT_INFO
,
472 (u8
*) buf
, os_strlen(buf
))) {
473 wpa_printf(MSG_ERROR
, "Could not add Connect-Info");
477 if (sta
->acct_session_id
) {
478 os_snprintf(buf
, sizeof(buf
), "%016llX",
479 (unsigned long long) sta
->acct_session_id
);
480 if (!radius_msg_add_attr(msg
, RADIUS_ATTR_ACCT_SESSION_ID
,
481 (u8
*) buf
, os_strlen(buf
))) {
482 wpa_printf(MSG_ERROR
, "Could not add Acct-Session-Id");
487 if ((hapd
->conf
->wpa
& 2) &&
488 !hapd
->conf
->disable_pmksa_caching
&&
489 sta
->eapol_sm
&& sta
->eapol_sm
->acct_multi_session_id
) {
490 os_snprintf(buf
, sizeof(buf
), "%016llX",
492 sta
->eapol_sm
->acct_multi_session_id
);
493 if (!radius_msg_add_attr(
494 msg
, RADIUS_ATTR_ACCT_MULTI_SESSION_ID
,
495 (u8
*) buf
, os_strlen(buf
))) {
497 "Could not add Acct-Multi-Session-Id");
502 #ifdef CONFIG_IEEE80211R_AP
503 if (hapd
->conf
->wpa
&& wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) &&
505 (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta
->wpa_sm
)) ||
506 sta
->auth_alg
== WLAN_AUTH_FT
) &&
507 !hostapd_config_get_radius_attr(req_attr
,
508 RADIUS_ATTR_MOBILITY_DOMAIN_ID
) &&
509 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_MOBILITY_DOMAIN_ID
,
511 hapd
->conf
->mobility_domain
))) {
512 wpa_printf(MSG_ERROR
, "Could not add Mobility-Domain-Id");
515 #endif /* CONFIG_IEEE80211R_AP */
517 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && sta
->wpa_sm
&&
518 add_common_radius_sta_attr_rsn(hapd
, req_attr
, sta
, msg
) < 0)
525 int add_common_radius_attr(struct hostapd_data
*hapd
,
526 struct hostapd_radius_attr
*req_attr
,
527 struct sta_info
*sta
,
528 struct radius_msg
*msg
)
531 struct hostapd_radius_attr
*attr
;
534 if (!hostapd_config_get_radius_attr(req_attr
,
535 RADIUS_ATTR_NAS_IP_ADDRESS
) &&
536 hapd
->conf
->own_ip_addr
.af
== AF_INET
&&
537 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IP_ADDRESS
,
538 (u8
*) &hapd
->conf
->own_ip_addr
.u
.v4
, 4)) {
539 wpa_printf(MSG_ERROR
, "Could not add NAS-IP-Address");
544 if (!hostapd_config_get_radius_attr(req_attr
,
545 RADIUS_ATTR_NAS_IPV6_ADDRESS
) &&
546 hapd
->conf
->own_ip_addr
.af
== AF_INET6
&&
547 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IPV6_ADDRESS
,
548 (u8
*) &hapd
->conf
->own_ip_addr
.u
.v6
, 16)) {
549 wpa_printf(MSG_ERROR
, "Could not add NAS-IPv6-Address");
552 #endif /* CONFIG_IPV6 */
554 if (!hostapd_config_get_radius_attr(req_attr
,
555 RADIUS_ATTR_NAS_IDENTIFIER
) &&
556 hapd
->conf
->nas_identifier
&&
557 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IDENTIFIER
,
558 (u8
*) hapd
->conf
->nas_identifier
,
559 os_strlen(hapd
->conf
->nas_identifier
))) {
560 wpa_printf(MSG_ERROR
, "Could not add NAS-Identifier");
564 len
= os_snprintf(buf
, sizeof(buf
), RADIUS_802_1X_ADDR_FORMAT
":",
565 MAC2STR(hapd
->own_addr
));
566 os_memcpy(&buf
[len
], hapd
->conf
->ssid
.ssid
,
567 hapd
->conf
->ssid
.ssid_len
);
568 len
+= hapd
->conf
->ssid
.ssid_len
;
569 if (!hostapd_config_get_radius_attr(req_attr
,
570 RADIUS_ATTR_CALLED_STATION_ID
) &&
571 !radius_msg_add_attr(msg
, RADIUS_ATTR_CALLED_STATION_ID
,
573 wpa_printf(MSG_ERROR
, "Could not add Called-Station-Id");
577 if (!hostapd_config_get_radius_attr(req_attr
,
578 RADIUS_ATTR_NAS_PORT_TYPE
) &&
579 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_NAS_PORT_TYPE
,
580 RADIUS_NAS_PORT_TYPE_IEEE_802_11
)) {
581 wpa_printf(MSG_ERROR
, "Could not add NAS-Port-Type");
585 #ifdef CONFIG_INTERWORKING
586 if (hapd
->conf
->interworking
&&
587 !is_zero_ether_addr(hapd
->conf
->hessid
)) {
588 os_snprintf(buf
, sizeof(buf
), RADIUS_802_1X_ADDR_FORMAT
,
589 MAC2STR(hapd
->conf
->hessid
));
590 buf
[sizeof(buf
) - 1] = '\0';
591 if (!hostapd_config_get_radius_attr(req_attr
,
592 RADIUS_ATTR_WLAN_HESSID
) &&
593 !radius_msg_add_attr(msg
, RADIUS_ATTR_WLAN_HESSID
,
594 (u8
*) buf
, os_strlen(buf
))) {
595 wpa_printf(MSG_ERROR
, "Could not add WLAN-HESSID");
599 #endif /* CONFIG_INTERWORKING */
601 if (sta
&& add_common_radius_sta_attr(hapd
, req_attr
, sta
, msg
) < 0)
604 for (attr
= req_attr
; attr
; attr
= attr
->next
) {
605 if (!radius_msg_add_attr(msg
, attr
->type
,
606 wpabuf_head(attr
->val
),
607 wpabuf_len(attr
->val
))) {
608 wpa_printf(MSG_ERROR
, "Could not add RADIUS "
618 void ieee802_1x_encapsulate_radius(struct hostapd_data
*hapd
,
619 struct sta_info
*sta
,
620 const u8
*eap
, size_t len
)
622 struct radius_msg
*msg
;
623 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
628 ieee802_1x_learn_identity(hapd
, sm
, eap
, len
);
630 wpa_printf(MSG_DEBUG
, "Encapsulating EAP message into a RADIUS "
633 sm
->radius_identifier
= radius_client_get_id(hapd
->radius
);
634 msg
= radius_msg_new(RADIUS_CODE_ACCESS_REQUEST
,
635 sm
->radius_identifier
);
637 wpa_printf(MSG_INFO
, "Could not create new RADIUS packet");
641 if (radius_msg_make_authenticator(msg
) < 0) {
642 wpa_printf(MSG_INFO
, "Could not make Request Authenticator");
647 !radius_msg_add_attr(msg
, RADIUS_ATTR_USER_NAME
,
648 sm
->identity
, sm
->identity_len
)) {
649 wpa_printf(MSG_INFO
, "Could not add User-Name");
653 if (add_common_radius_attr(hapd
, hapd
->conf
->radius_auth_req_attr
, sta
,
657 /* TODO: should probably check MTU from driver config; 2304 is max for
658 * IEEE 802.11, but use 1400 to avoid problems with too large packets
660 if (!hostapd_config_get_radius_attr(hapd
->conf
->radius_auth_req_attr
,
661 RADIUS_ATTR_FRAMED_MTU
) &&
662 !radius_msg_add_attr_int32(msg
, RADIUS_ATTR_FRAMED_MTU
, 1400)) {
663 wpa_printf(MSG_INFO
, "Could not add Framed-MTU");
667 if (!radius_msg_add_eap(msg
, eap
, len
)) {
668 wpa_printf(MSG_INFO
, "Could not add EAP-Message");
672 /* State attribute must be copied if and only if this packet is
673 * Access-Request reply to the previous Access-Challenge */
674 if (sm
->last_recv_radius
&&
675 radius_msg_get_hdr(sm
->last_recv_radius
)->code
==
676 RADIUS_CODE_ACCESS_CHALLENGE
) {
677 int res
= radius_msg_copy_attr(msg
, sm
->last_recv_radius
,
680 wpa_printf(MSG_INFO
, "Could not copy State attribute from previous Access-Challenge");
684 wpa_printf(MSG_DEBUG
, "Copied RADIUS State Attribute");
688 if (hapd
->conf
->radius_request_cui
) {
691 /* Add previously learned CUI or nul CUI to request CUI */
692 if (sm
->radius_cui
) {
693 cui
= wpabuf_head(sm
->radius_cui
);
694 cui_len
= wpabuf_len(sm
->radius_cui
);
696 cui
= (const u8
*) "\0";
699 if (!radius_msg_add_attr(msg
,
700 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY
,
702 wpa_printf(MSG_ERROR
, "Could not add CUI");
708 if (hapd
->conf
->hs20
) {
709 u8 ver
= hapd
->conf
->hs20_release
- 1;
711 if (!radius_msg_add_wfa(
712 msg
, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION
,
714 wpa_printf(MSG_ERROR
, "Could not add HS 2.0 AP "
719 if (sta
->hs20_ie
&& wpabuf_len(sta
->hs20_ie
) > 0) {
723 pos
= wpabuf_head_u8(sta
->hs20_ie
);
724 buf
[0] = (*pos
) >> 4;
725 if (((*pos
) & HS20_PPS_MO_ID_PRESENT
) &&
726 wpabuf_len(sta
->hs20_ie
) >= 3)
727 id
= WPA_GET_LE16(pos
+ 1);
730 WPA_PUT_BE16(buf
+ 1, id
);
731 if (!radius_msg_add_wfa(
733 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION
,
735 wpa_printf(MSG_ERROR
, "Could not add HS 2.0 "
741 if (sta
->roaming_consortium
&&
743 msg
, RADIUS_VENDOR_ATTR_WFA_HS20_ROAMING_CONSORTIUM
,
744 wpabuf_head(sta
->roaming_consortium
),
745 wpabuf_len(sta
->roaming_consortium
))) {
746 wpa_printf(MSG_ERROR
,
747 "Could not add HS 2.0 Roaming Consortium");
751 if (hapd
->conf
->t_c_filename
) {
754 if (!radius_msg_add_wfa(
756 RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILENAME
,
757 (const u8
*) hapd
->conf
->t_c_filename
,
758 os_strlen(hapd
->conf
->t_c_filename
))) {
759 wpa_printf(MSG_ERROR
,
760 "Could not add HS 2.0 T&C Filename");
764 timestamp
= host_to_be32(hapd
->conf
->t_c_timestamp
);
765 if (!radius_msg_add_wfa(
767 RADIUS_VENDOR_ATTR_WFA_HS20_TIMESTAMP
,
768 (const u8
*) ×tamp
,
769 sizeof(timestamp
))) {
770 wpa_printf(MSG_ERROR
,
771 "Could not add HS 2.0 Timestamp");
776 #endif /* CONFIG_HS20 */
778 if (radius_client_send(hapd
->radius
, msg
, RADIUS_AUTH
, sta
->addr
) < 0)
784 radius_msg_free(msg
);
786 #endif /* CONFIG_NO_RADIUS */
789 static void handle_eap_response(struct hostapd_data
*hapd
,
790 struct sta_info
*sta
, struct eap_hdr
*eap
,
794 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
798 data
= (u8
*) (eap
+ 1);
800 if (len
< sizeof(*eap
) + 1) {
801 wpa_printf(MSG_INFO
, "handle_eap_response: too short response data");
805 sm
->eap_type_supp
= type
= data
[0];
807 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
808 HOSTAPD_LEVEL_DEBUG
, "received EAP packet (code=%d "
809 "id=%d len=%d) from STA: EAP Response-%s (%d)",
810 eap
->code
, eap
->identifier
, be_to_host16(eap
->length
),
811 eap_server_get_name(0, type
), type
);
813 sm
->dot1xAuthEapolRespFramesRx
++;
815 wpabuf_free(sm
->eap_if
->eapRespData
);
816 sm
->eap_if
->eapRespData
= wpabuf_alloc_copy(eap
, len
);
821 static void handle_eap_initiate(struct hostapd_data
*hapd
,
822 struct sta_info
*sta
, struct eap_hdr
*eap
,
827 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
832 if (len
< sizeof(*eap
) + 1) {
834 "handle_eap_initiate: too short response data");
838 data
= (u8
*) (eap
+ 1);
841 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
842 HOSTAPD_LEVEL_DEBUG
, "received EAP packet (code=%d "
843 "id=%d len=%d) from STA: EAP Initiate type %u",
844 eap
->code
, eap
->identifier
, be_to_host16(eap
->length
),
847 wpabuf_free(sm
->eap_if
->eapRespData
);
848 sm
->eap_if
->eapRespData
= wpabuf_alloc_copy(eap
, len
);
850 #endif /* CONFIG_ERP */
854 /* Process incoming EAP packet from Supplicant */
855 static void handle_eap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
861 if (len
< sizeof(*eap
)) {
862 wpa_printf(MSG_INFO
, " too short EAP packet");
866 eap
= (struct eap_hdr
*) buf
;
868 eap_len
= be_to_host16(eap
->length
);
869 wpa_printf(MSG_DEBUG
, "EAP: code=%d identifier=%d length=%d",
870 eap
->code
, eap
->identifier
, eap_len
);
871 if (eap_len
< sizeof(*eap
)) {
872 wpa_printf(MSG_DEBUG
, " Invalid EAP length");
874 } else if (eap_len
> len
) {
875 wpa_printf(MSG_DEBUG
, " Too short frame to contain this EAP "
878 } else if (eap_len
< len
) {
879 wpa_printf(MSG_DEBUG
, " Ignoring %lu extra bytes after EAP "
880 "packet", (unsigned long) len
- eap_len
);
884 case EAP_CODE_REQUEST
:
885 wpa_printf(MSG_DEBUG
, " (request)");
887 case EAP_CODE_RESPONSE
:
888 wpa_printf(MSG_DEBUG
, " (response)");
889 handle_eap_response(hapd
, sta
, eap
, eap_len
);
891 case EAP_CODE_SUCCESS
:
892 wpa_printf(MSG_DEBUG
, " (success)");
894 case EAP_CODE_FAILURE
:
895 wpa_printf(MSG_DEBUG
, " (failure)");
897 case EAP_CODE_INITIATE
:
898 wpa_printf(MSG_DEBUG
, " (initiate)");
899 handle_eap_initiate(hapd
, sta
, eap
, eap_len
);
901 case EAP_CODE_FINISH
:
902 wpa_printf(MSG_DEBUG
, " (finish)");
905 wpa_printf(MSG_DEBUG
, " (unknown code)");
911 struct eapol_state_machine
*
912 ieee802_1x_alloc_eapol_sm(struct hostapd_data
*hapd
, struct sta_info
*sta
)
915 if (sta
->flags
& WLAN_STA_PREAUTH
)
916 flags
|= EAPOL_SM_PREAUTH
;
918 flags
|= EAPOL_SM_USES_WPA
;
919 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
))
920 flags
|= EAPOL_SM_FROM_PMKSA_CACHE
;
922 return eapol_auth_alloc(hapd
->eapol_auth
, sta
->addr
, flags
,
923 sta
->wps_ie
, sta
->p2p_ie
, sta
,
924 sta
->identity
, sta
->radius_cui
);
928 static void ieee802_1x_save_eapol(struct sta_info
*sta
, const u8
*buf
,
931 if (sta
->pending_eapol_rx
) {
932 wpabuf_free(sta
->pending_eapol_rx
->buf
);
934 sta
->pending_eapol_rx
=
935 os_malloc(sizeof(*sta
->pending_eapol_rx
));
936 if (!sta
->pending_eapol_rx
)
940 sta
->pending_eapol_rx
->buf
= wpabuf_alloc_copy(buf
, len
);
941 if (!sta
->pending_eapol_rx
->buf
) {
942 os_free(sta
->pending_eapol_rx
);
943 sta
->pending_eapol_rx
= NULL
;
947 os_get_reltime(&sta
->pending_eapol_rx
->rx_time
);
952 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
953 * @hapd: hostapd BSS data
954 * @sa: Source address (sender of the EAPOL frame)
956 * @len: Length of buf in octets
958 * This function is called for each incoming EAPOL frame from the interface
960 void ieee802_1x_receive(struct hostapd_data
*hapd
, const u8
*sa
, const u8
*buf
,
963 struct sta_info
*sta
;
964 struct ieee802_1x_hdr
*hdr
;
965 struct ieee802_1x_eapol_key
*key
;
967 struct rsn_pmksa_cache_entry
*pmksa
;
970 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
&&
971 !hapd
->conf
->wps_state
)
974 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: %lu bytes from " MACSTR
,
975 (unsigned long) len
, MAC2STR(sa
));
976 sta
= ap_get_sta(hapd
, sa
);
977 if (!sta
|| (!(sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_PREAUTH
)) &&
978 !(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))) {
979 wpa_printf(MSG_DEBUG
, "IEEE 802.1X data frame from not "
980 "associated/Pre-authenticating STA");
982 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
)) {
983 wpa_printf(MSG_DEBUG
, "Saving EAPOL frame from " MACSTR
984 " for later use", MAC2STR(sta
->addr
));
985 ieee802_1x_save_eapol(sta
, buf
, len
);
991 if (len
< sizeof(*hdr
)) {
992 wpa_printf(MSG_INFO
, " too short IEEE 802.1X packet");
996 hdr
= (struct ieee802_1x_hdr
*) buf
;
997 datalen
= be_to_host16(hdr
->length
);
998 wpa_printf(MSG_DEBUG
, " IEEE 802.1X: version=%d type=%d length=%d",
999 hdr
->version
, hdr
->type
, datalen
);
1001 if (len
- sizeof(*hdr
) < datalen
) {
1002 wpa_printf(MSG_INFO
, " frame too short for this IEEE 802.1X packet");
1004 sta
->eapol_sm
->dot1xAuthEapLengthErrorFramesRx
++;
1007 if (len
- sizeof(*hdr
) > datalen
) {
1008 wpa_printf(MSG_DEBUG
, " ignoring %lu extra octets after "
1009 "IEEE 802.1X packet",
1010 (unsigned long) len
- sizeof(*hdr
) - datalen
);
1013 if (sta
->eapol_sm
) {
1014 sta
->eapol_sm
->dot1xAuthLastEapolFrameVersion
= hdr
->version
;
1015 sta
->eapol_sm
->dot1xAuthEapolFramesRx
++;
1018 key
= (struct ieee802_1x_eapol_key
*) (hdr
+ 1);
1019 if (datalen
>= sizeof(struct ieee802_1x_eapol_key
) &&
1020 hdr
->type
== IEEE802_1X_TYPE_EAPOL_KEY
&&
1021 (key
->type
== EAPOL_KEY_TYPE_WPA
||
1022 key
->type
== EAPOL_KEY_TYPE_RSN
)) {
1023 wpa_receive(hapd
->wpa_auth
, sta
->wpa_sm
, (u8
*) hdr
,
1024 sizeof(*hdr
) + datalen
);
1028 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->osen
&&
1029 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
))) {
1030 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore EAPOL message - "
1031 "802.1X not enabled and WPS not used");
1035 key_mgmt
= wpa_auth_sta_key_mgmt(sta
->wpa_sm
);
1036 if (key_mgmt
!= -1 &&
1037 (wpa_key_mgmt_wpa_psk(key_mgmt
) || key_mgmt
== WPA_KEY_MGMT_OWE
||
1038 key_mgmt
== WPA_KEY_MGMT_DPP
)) {
1039 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore EAPOL message - "
1040 "STA is using PSK");
1044 if (!sta
->eapol_sm
) {
1045 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1050 if (!hapd
->conf
->ieee802_1x
&& hapd
->conf
->wps_state
) {
1051 u32 wflags
= sta
->flags
& (WLAN_STA_WPS
|
1053 WLAN_STA_MAYBE_WPS
);
1054 if (wflags
== WLAN_STA_MAYBE_WPS
||
1055 wflags
== (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) {
1057 * Delay EAPOL frame transmission until a
1058 * possible WPS STA initiates the handshake
1059 * with EAPOL-Start. Only allow the wait to be
1060 * skipped if the STA is known to support WPS
1063 wpa_printf(MSG_DEBUG
, "WPS: Do not start "
1064 "EAPOL until EAPOL-Start is "
1066 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
1069 #endif /* CONFIG_WPS */
1071 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
1074 /* since we support version 1, we can ignore version field and proceed
1075 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
1076 /* TODO: actually, we are not version 1 anymore.. However, Version 2
1077 * does not change frame contents, so should be ok to process frames
1078 * more or less identically. Some changes might be needed for
1079 * verification of fields. */
1081 switch (hdr
->type
) {
1082 case IEEE802_1X_TYPE_EAP_PACKET
:
1083 handle_eap(hapd
, sta
, (u8
*) (hdr
+ 1), datalen
);
1086 case IEEE802_1X_TYPE_EAPOL_START
:
1087 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1088 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Start "
1090 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
1091 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
1093 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
1094 HOSTAPD_LEVEL_DEBUG
, "cached PMKSA "
1095 "available - ignore it since "
1096 "STA sent EAPOL-Start");
1097 wpa_auth_sta_clear_pmksa(sta
->wpa_sm
, pmksa
);
1099 sta
->eapol_sm
->eapolStart
= TRUE
;
1100 sta
->eapol_sm
->dot1xAuthEapolStartFramesRx
++;
1101 eap_server_clear_identity(sta
->eapol_sm
->eap
);
1102 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
1105 case IEEE802_1X_TYPE_EAPOL_LOGOFF
:
1106 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1107 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Logoff "
1109 sta
->acct_terminate_cause
=
1110 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
1111 accounting_sta_stop(hapd
, sta
);
1112 sta
->eapol_sm
->eapolLogoff
= TRUE
;
1113 sta
->eapol_sm
->dot1xAuthEapolLogoffFramesRx
++;
1114 eap_server_clear_identity(sta
->eapol_sm
->eap
);
1117 case IEEE802_1X_TYPE_EAPOL_KEY
:
1118 wpa_printf(MSG_DEBUG
, " EAPOL-Key");
1119 if (!ap_sta_is_authorized(sta
)) {
1120 wpa_printf(MSG_DEBUG
, " Dropped key data from "
1121 "unauthorized Supplicant");
1126 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
:
1127 wpa_printf(MSG_DEBUG
, " EAPOL-Encapsulated-ASF-Alert");
1128 /* TODO: implement support for this; show data */
1131 #ifdef CONFIG_MACSEC
1132 case IEEE802_1X_TYPE_EAPOL_MKA
:
1133 wpa_printf(MSG_EXCESSIVE
,
1134 "EAPOL type %d will be handled by MKA", hdr
->type
);
1136 #endif /* CONFIG_MACSEC */
1139 wpa_printf(MSG_DEBUG
, " unknown IEEE 802.1X packet type");
1140 sta
->eapol_sm
->dot1xAuthInvalidEapolFramesRx
++;
1144 eapol_auth_step(sta
->eapol_sm
);
1149 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1150 * @hapd: hostapd BSS data
1153 * This function is called to start IEEE 802.1X authentication when a new
1154 * station completes IEEE 802.11 association.
1156 void ieee802_1x_new_station(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1158 struct rsn_pmksa_cache_entry
*pmksa
;
1164 if (hapd
->conf
->wps_state
&&
1165 ((hapd
->conf
->wpa
&& (sta
->flags
& WLAN_STA_MAYBE_WPS
)) ||
1166 (sta
->flags
& WLAN_STA_WPS
))) {
1168 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1169 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1170 * authentication in this BSS.
1174 #endif /* CONFIG_WPS */
1176 if (!force_1x
&& !hapd
->conf
->ieee802_1x
&& !hapd
->conf
->osen
) {
1177 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore STA - "
1178 "802.1X not enabled or forced for WPS");
1180 * Clear any possible EAPOL authenticator state to support
1181 * reassociation change from WPS to PSK.
1183 ieee802_1x_free_station(hapd
, sta
);
1187 key_mgmt
= wpa_auth_sta_key_mgmt(sta
->wpa_sm
);
1188 if (key_mgmt
!= -1 &&
1189 (wpa_key_mgmt_wpa_psk(key_mgmt
) || key_mgmt
== WPA_KEY_MGMT_OWE
||
1190 key_mgmt
== WPA_KEY_MGMT_DPP
)) {
1191 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Ignore STA - using PSK");
1193 * Clear any possible EAPOL authenticator state to support
1194 * reassociation change from WPA-EAP to PSK.
1196 ieee802_1x_free_station(hapd
, sta
);
1200 if (sta
->eapol_sm
== NULL
) {
1201 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1202 HOSTAPD_LEVEL_DEBUG
, "start authentication");
1203 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
1204 if (sta
->eapol_sm
== NULL
) {
1205 hostapd_logger(hapd
, sta
->addr
,
1206 HOSTAPD_MODULE_IEEE8021X
,
1208 "failed to allocate state machine");
1215 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
1216 if (!hapd
->conf
->ieee802_1x
&& hapd
->conf
->wps_state
&&
1217 !(sta
->flags
& WLAN_STA_WPS2
)) {
1219 * Delay EAPOL frame transmission until a possible WPS STA
1220 * initiates the handshake with EAPOL-Start. Only allow the
1221 * wait to be skipped if the STA is known to support WPS 2.0.
1223 wpa_printf(MSG_DEBUG
, "WPS: Do not start EAPOL until "
1224 "EAPOL-Start is received");
1225 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
1227 #endif /* CONFIG_WPS */
1229 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
1231 #ifdef CONFIG_IEEE80211R_AP
1232 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
1233 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1234 HOSTAPD_LEVEL_DEBUG
,
1235 "PMK from FT - skip IEEE 802.1X/EAP");
1236 /* Setup EAPOL state machines to already authenticated state
1237 * because of existing FT information from R0KH. */
1238 sta
->eapol_sm
->keyRun
= TRUE
;
1239 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1240 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1241 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1242 sta
->eapol_sm
->authSuccess
= TRUE
;
1243 sta
->eapol_sm
->authFail
= FALSE
;
1244 sta
->eapol_sm
->portValid
= TRUE
;
1245 if (sta
->eapol_sm
->eap
)
1246 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1247 ap_sta_bind_vlan(hapd
, sta
);
1250 #endif /* CONFIG_IEEE80211R_AP */
1253 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
1254 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
1255 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
1256 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1257 HOSTAPD_LEVEL_DEBUG
,
1258 "PMK from FILS - skip IEEE 802.1X/EAP");
1259 /* Setup EAPOL state machines to already authenticated state
1260 * because of existing FILS information. */
1261 sta
->eapol_sm
->keyRun
= TRUE
;
1262 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1263 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1264 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1265 sta
->eapol_sm
->authSuccess
= TRUE
;
1266 sta
->eapol_sm
->authFail
= FALSE
;
1267 sta
->eapol_sm
->portValid
= TRUE
;
1268 if (sta
->eapol_sm
->eap
)
1269 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1270 wpa_auth_set_ptk_rekey_timer(sta
->wpa_sm
);
1273 #endif /* CONFIG_FILS */
1275 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
1277 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1278 HOSTAPD_LEVEL_DEBUG
,
1279 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1280 /* Setup EAPOL state machines to already authenticated state
1281 * because of existing PMKSA information in the cache. */
1282 sta
->eapol_sm
->keyRun
= TRUE
;
1283 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1284 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
1285 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
1286 sta
->eapol_sm
->authSuccess
= TRUE
;
1287 sta
->eapol_sm
->authFail
= FALSE
;
1288 if (sta
->eapol_sm
->eap
)
1289 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
1290 pmksa_cache_to_eapol_data(hapd
, pmksa
, sta
->eapol_sm
);
1291 ap_sta_bind_vlan(hapd
, sta
);
1295 * Force EAPOL state machines to start
1296 * re-authentication without having to wait for the
1297 * Supplicant to send EAPOL-Start.
1299 sta
->eapol_sm
->reAuthenticate
= TRUE
;
1301 eapol_auth_step(sta
->eapol_sm
);
1306 void ieee802_1x_free_station(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1308 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1311 eloop_cancel_timeout(ieee802_1x_wnm_notif_send
, hapd
, sta
);
1312 #endif /* CONFIG_HS20 */
1314 if (sta
->pending_eapol_rx
) {
1315 wpabuf_free(sta
->pending_eapol_rx
->buf
);
1316 os_free(sta
->pending_eapol_rx
);
1317 sta
->pending_eapol_rx
= NULL
;
1323 sta
->eapol_sm
= NULL
;
1325 #ifndef CONFIG_NO_RADIUS
1326 radius_msg_free(sm
->last_recv_radius
);
1327 radius_free_class(&sm
->radius_class
);
1328 #endif /* CONFIG_NO_RADIUS */
1330 eapol_auth_free(sm
);
1334 #ifndef CONFIG_NO_RADIUS
1335 static void ieee802_1x_decapsulate_radius(struct hostapd_data
*hapd
,
1336 struct sta_info
*sta
)
1339 const struct eap_hdr
*hdr
;
1342 struct radius_msg
*msg
;
1343 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1345 if (sm
== NULL
|| sm
->last_recv_radius
== NULL
) {
1347 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1351 msg
= sm
->last_recv_radius
;
1353 eap
= radius_msg_get_eap(msg
);
1355 /* RFC 3579, Chap. 2.6.3:
1356 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1358 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1359 HOSTAPD_LEVEL_WARNING
, "could not extract "
1360 "EAP-Message from RADIUS message");
1361 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1365 if (wpabuf_len(eap
) < sizeof(*hdr
)) {
1366 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1367 HOSTAPD_LEVEL_WARNING
, "too short EAP packet "
1368 "received from authentication server");
1370 sm
->eap_if
->aaaEapNoReq
= TRUE
;
1374 if (wpabuf_len(eap
) > sizeof(*hdr
))
1375 eap_type
= (wpabuf_head_u8(eap
))[sizeof(*hdr
)];
1377 hdr
= wpabuf_head(eap
);
1378 switch (hdr
->code
) {
1379 case EAP_CODE_REQUEST
:
1381 sm
->eap_type_authsrv
= eap_type
;
1382 os_snprintf(buf
, sizeof(buf
), "EAP-Request-%s (%d)",
1383 eap_server_get_name(0, eap_type
), eap_type
);
1385 case EAP_CODE_RESPONSE
:
1386 os_snprintf(buf
, sizeof(buf
), "EAP Response-%s (%d)",
1387 eap_server_get_name(0, eap_type
), eap_type
);
1389 case EAP_CODE_SUCCESS
:
1390 os_strlcpy(buf
, "EAP Success", sizeof(buf
));
1392 case EAP_CODE_FAILURE
:
1393 os_strlcpy(buf
, "EAP Failure", sizeof(buf
));
1396 os_strlcpy(buf
, "unknown EAP code", sizeof(buf
));
1399 buf
[sizeof(buf
) - 1] = '\0';
1400 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1401 HOSTAPD_LEVEL_DEBUG
, "decapsulated EAP packet (code=%d "
1402 "id=%d len=%d) from RADIUS server: %s",
1403 hdr
->code
, hdr
->identifier
, be_to_host16(hdr
->length
),
1405 sm
->eap_if
->aaaEapReq
= TRUE
;
1407 wpabuf_free(sm
->eap_if
->aaaEapReqData
);
1408 sm
->eap_if
->aaaEapReqData
= eap
;
1412 static void ieee802_1x_get_keys(struct hostapd_data
*hapd
,
1413 struct sta_info
*sta
, struct radius_msg
*msg
,
1414 struct radius_msg
*req
,
1415 const u8
*shared_secret
,
1416 size_t shared_secret_len
)
1418 struct radius_ms_mppe_keys
*keys
;
1421 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1425 keys
= radius_msg_get_ms_keys(msg
, req
, shared_secret
,
1428 if (keys
&& keys
->send
&& keys
->recv
) {
1429 size_t len
= keys
->send_len
+ keys
->recv_len
;
1430 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Send-Key",
1431 keys
->send
, keys
->send_len
);
1432 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Recv-Key",
1433 keys
->recv
, keys
->recv_len
);
1435 os_free(sm
->eap_if
->aaaEapKeyData
);
1436 sm
->eap_if
->aaaEapKeyData
= os_malloc(len
);
1437 if (sm
->eap_if
->aaaEapKeyData
) {
1438 os_memcpy(sm
->eap_if
->aaaEapKeyData
, keys
->recv
,
1440 os_memcpy(sm
->eap_if
->aaaEapKeyData
+ keys
->recv_len
,
1441 keys
->send
, keys
->send_len
);
1442 sm
->eap_if
->aaaEapKeyDataLen
= len
;
1443 sm
->eap_if
->aaaEapKeyAvailable
= TRUE
;
1446 wpa_printf(MSG_DEBUG
,
1447 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1448 keys
, keys
? keys
->send
: NULL
,
1449 keys
? keys
->recv
: NULL
);
1453 os_free(keys
->send
);
1454 os_free(keys
->recv
);
1458 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_EAP_KEY_NAME
, &buf
, &len
,
1460 os_free(sm
->eap_if
->eapSessionId
);
1461 sm
->eap_if
->eapSessionId
= os_memdup(buf
, len
);
1462 if (sm
->eap_if
->eapSessionId
) {
1463 sm
->eap_if
->eapSessionIdLen
= len
;
1464 wpa_hexdump(MSG_DEBUG
, "EAP-Key Name",
1465 sm
->eap_if
->eapSessionId
,
1466 sm
->eap_if
->eapSessionIdLen
);
1469 sm
->eap_if
->eapSessionIdLen
= 0;
1474 static void ieee802_1x_store_radius_class(struct hostapd_data
*hapd
,
1475 struct sta_info
*sta
,
1476 struct radius_msg
*msg
)
1480 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1482 struct radius_attr_data
*nclass
;
1483 size_t nclass_count
;
1485 if (!hapd
->conf
->radius
->acct_server
|| hapd
->radius
== NULL
||
1489 radius_free_class(&sm
->radius_class
);
1490 count
= radius_msg_count_attr(msg
, RADIUS_ATTR_CLASS
, 1);
1494 nclass
= os_calloc(count
, sizeof(struct radius_attr_data
));
1501 for (i
= 0; i
< count
; i
++) {
1503 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_CLASS
,
1504 &attr_class
, &class_len
,
1509 } while (class_len
< 1);
1511 nclass
[nclass_count
].data
= os_memdup(attr_class
, class_len
);
1512 if (nclass
[nclass_count
].data
== NULL
)
1515 nclass
[nclass_count
].len
= class_len
;
1519 sm
->radius_class
.attr
= nclass
;
1520 sm
->radius_class
.count
= nclass_count
;
1521 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Stored %lu RADIUS Class "
1522 "attributes for " MACSTR
,
1523 (unsigned long) sm
->radius_class
.count
,
1524 MAC2STR(sta
->addr
));
1528 /* Update sta->identity based on User-Name attribute in Access-Accept */
1529 static void ieee802_1x_update_sta_identity(struct hostapd_data
*hapd
,
1530 struct sta_info
*sta
,
1531 struct radius_msg
*msg
)
1535 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1540 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_USER_NAME
, &buf
, &len
,
1544 identity
= (u8
*) dup_binstr(buf
, len
);
1545 if (identity
== NULL
)
1548 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1549 HOSTAPD_LEVEL_DEBUG
, "old identity '%s' updated with "
1550 "User-Name from Access-Accept '%s'",
1551 sm
->identity
? (char *) sm
->identity
: "N/A",
1554 os_free(sm
->identity
);
1555 sm
->identity
= identity
;
1556 sm
->identity_len
= len
;
1560 /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1561 static void ieee802_1x_update_sta_cui(struct hostapd_data
*hapd
,
1562 struct sta_info
*sta
,
1563 struct radius_msg
*msg
)
1565 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1573 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY
,
1574 &buf
, &len
, NULL
) < 0)
1577 cui
= wpabuf_alloc_copy(buf
, len
);
1581 wpabuf_free(sm
->radius_cui
);
1582 sm
->radius_cui
= cui
;
1588 static void ieee802_1x_hs20_sub_rem(struct sta_info
*sta
, u8
*pos
, size_t len
)
1590 sta
->remediation
= 1;
1591 os_free(sta
->remediation_url
);
1593 sta
->remediation_url
= os_malloc(len
);
1594 if (!sta
->remediation_url
)
1596 sta
->remediation_method
= pos
[0];
1597 os_memcpy(sta
->remediation_url
, pos
+ 1, len
- 1);
1598 sta
->remediation_url
[len
- 1] = '\0';
1599 wpa_printf(MSG_DEBUG
, "HS 2.0: Subscription remediation needed "
1600 "for " MACSTR
" - server method %u URL %s",
1601 MAC2STR(sta
->addr
), sta
->remediation_method
,
1602 sta
->remediation_url
);
1604 sta
->remediation_url
= NULL
;
1605 wpa_printf(MSG_DEBUG
, "HS 2.0: Subscription remediation needed "
1606 "for " MACSTR
, MAC2STR(sta
->addr
));
1608 /* TODO: assign the STA into remediation VLAN or add filtering */
1612 static void ieee802_1x_hs20_deauth_req(struct hostapd_data
*hapd
,
1613 struct sta_info
*sta
, u8
*pos
,
1617 return; /* Malformed information */
1618 sta
->hs20_deauth_requested
= 1;
1619 wpa_printf(MSG_DEBUG
, "HS 2.0: Deauthentication request - Code %u "
1621 *pos
, WPA_GET_LE16(pos
+ 1));
1622 wpabuf_free(sta
->hs20_deauth_req
);
1623 sta
->hs20_deauth_req
= wpabuf_alloc(len
+ 1);
1624 if (sta
->hs20_deauth_req
) {
1625 wpabuf_put_data(sta
->hs20_deauth_req
, pos
, 3);
1626 wpabuf_put_u8(sta
->hs20_deauth_req
, len
- 3);
1627 wpabuf_put_data(sta
->hs20_deauth_req
, pos
+ 3, len
- 3);
1629 ap_sta_session_timeout(hapd
, sta
, hapd
->conf
->hs20_deauth_req_timeout
);
1633 static void ieee802_1x_hs20_session_info(struct hostapd_data
*hapd
,
1634 struct sta_info
*sta
, u8
*pos
,
1635 size_t len
, int session_timeout
)
1638 int warning_time
, beacon_int
;
1641 return; /* Malformed information */
1642 os_free(sta
->hs20_session_info_url
);
1643 sta
->hs20_session_info_url
= os_malloc(len
);
1644 if (sta
->hs20_session_info_url
== NULL
)
1647 os_memcpy(sta
->hs20_session_info_url
, pos
+ 1, len
- 1);
1648 sta
->hs20_session_info_url
[len
- 1] = '\0';
1649 wpa_printf(MSG_DEBUG
, "HS 2.0: Session Information URL='%s' SWT=%u "
1650 "(session_timeout=%d)",
1651 sta
->hs20_session_info_url
, swt
, session_timeout
);
1652 if (session_timeout
< 0) {
1653 wpa_printf(MSG_DEBUG
, "HS 2.0: No Session-Timeout set - ignore session info URL");
1657 swt
= 1; /* Use one minute as the AP selected value */
1659 if ((unsigned int) session_timeout
< swt
* 60)
1662 warning_time
= session_timeout
- swt
* 60;
1664 beacon_int
= hapd
->iconf
->beacon_int
;
1666 beacon_int
= 100; /* best guess */
1667 sta
->hs20_disassoc_timer
= swt
* 60 * 1000 / beacon_int
* 125 / 128;
1668 if (sta
->hs20_disassoc_timer
> 65535)
1669 sta
->hs20_disassoc_timer
= 65535;
1671 ap_sta_session_warning_timeout(hapd
, sta
, warning_time
);
1675 static void ieee802_1x_hs20_t_c_filtering(struct hostapd_data
*hapd
,
1676 struct sta_info
*sta
, u8
*pos
,
1680 return; /* Malformed information */
1681 wpa_printf(MSG_DEBUG
,
1682 "HS 2.0: Terms and Conditions filtering %02x %02x %02x %02x",
1683 pos
[0], pos
[1], pos
[2], pos
[3]);
1684 hs20_t_c_filtering(hapd
, sta
, pos
[0] & BIT(0));
1688 static void ieee802_1x_hs20_t_c_url(struct hostapd_data
*hapd
,
1689 struct sta_info
*sta
, u8
*pos
, size_t len
)
1691 os_free(sta
->t_c_url
);
1692 sta
->t_c_url
= os_malloc(len
+ 1);
1695 os_memcpy(sta
->t_c_url
, pos
, len
);
1696 sta
->t_c_url
[len
] = '\0';
1697 wpa_printf(MSG_DEBUG
,
1698 "HS 2.0: Terms and Conditions URL %s", sta
->t_c_url
);
1701 #endif /* CONFIG_HS20 */
1704 static void ieee802_1x_check_hs20(struct hostapd_data
*hapd
,
1705 struct sta_info
*sta
,
1706 struct radius_msg
*msg
,
1707 int session_timeout
)
1710 u8
*buf
, *pos
, *end
, type
, sublen
;
1714 sta
->remediation
= 0;
1715 sta
->hs20_deauth_requested
= 0;
1718 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_VENDOR_SPECIFIC
,
1719 &buf
, &len
, buf
) < 0)
1725 if (WPA_GET_BE32(pos
) != RADIUS_VENDOR_ID_WFA
)
1732 continue; /* invalid length */
1733 sublen
-= 2; /* skip header */
1734 if (pos
+ sublen
> end
)
1735 continue; /* invalid WFA VSA */
1738 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION
:
1739 ieee802_1x_hs20_sub_rem(sta
, pos
, sublen
);
1741 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ
:
1742 ieee802_1x_hs20_deauth_req(hapd
, sta
, pos
, sublen
);
1744 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL
:
1745 ieee802_1x_hs20_session_info(hapd
, sta
, pos
, sublen
,
1748 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILTERING
:
1749 ieee802_1x_hs20_t_c_filtering(hapd
, sta
, pos
, sublen
);
1751 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_URL
:
1752 ieee802_1x_hs20_t_c_url(hapd
, sta
, pos
, sublen
);
1756 #endif /* CONFIG_HS20 */
1760 struct sta_id_search
{
1762 struct eapol_state_machine
*sm
;
1766 static int ieee802_1x_select_radius_identifier(struct hostapd_data
*hapd
,
1767 struct sta_info
*sta
,
1770 struct sta_id_search
*id_search
= ctx
;
1771 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1773 if (sm
&& sm
->radius_identifier
>= 0 &&
1774 sm
->radius_identifier
== id_search
->identifier
) {
1782 static struct eapol_state_machine
*
1783 ieee802_1x_search_radius_identifier(struct hostapd_data
*hapd
, u8 identifier
)
1785 struct sta_id_search id_search
;
1786 id_search
.identifier
= identifier
;
1787 id_search
.sm
= NULL
;
1788 ap_for_each_sta(hapd
, ieee802_1x_select_radius_identifier
, &id_search
);
1789 return id_search
.sm
;
1793 #ifndef CONFIG_NO_VLAN
1794 static int ieee802_1x_update_vlan(struct radius_msg
*msg
,
1795 struct hostapd_data
*hapd
,
1796 struct sta_info
*sta
)
1798 struct vlan_description vlan_desc
;
1800 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
1801 vlan_desc
.notempty
= !!radius_msg_get_vlanid(msg
, &vlan_desc
.untagged
,
1802 MAX_NUM_TAGGED_VLAN
,
1805 if (vlan_desc
.notempty
&&
1806 !hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
1807 sta
->eapol_sm
->authFail
= TRUE
;
1808 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_RADIUS
,
1810 "Invalid VLAN %d%s received from RADIUS server",
1812 vlan_desc
.tagged
[0] ? "+" : "");
1813 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
1814 ap_sta_set_vlan(hapd
, sta
, &vlan_desc
);
1818 if (hapd
->conf
->ssid
.dynamic_vlan
== DYNAMIC_VLAN_REQUIRED
&&
1819 !vlan_desc
.notempty
) {
1820 sta
->eapol_sm
->authFail
= TRUE
;
1821 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1823 "authentication server did not include required VLAN ID in Access-Accept");
1827 return ap_sta_set_vlan(hapd
, sta
, &vlan_desc
);
1829 #endif /* CONFIG_NO_VLAN */
1833 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1834 * @msg: RADIUS response message
1835 * @req: RADIUS request message
1836 * @shared_secret: RADIUS shared secret
1837 * @shared_secret_len: Length of shared_secret in octets
1838 * @data: Context data (struct hostapd_data *)
1839 * Returns: Processing status
1841 static RadiusRxResult
1842 ieee802_1x_receive_auth(struct radius_msg
*msg
, struct radius_msg
*req
,
1843 const u8
*shared_secret
, size_t shared_secret_len
,
1846 struct hostapd_data
*hapd
= data
;
1847 struct sta_info
*sta
;
1848 u32 session_timeout
= 0, termination_action
, acct_interim_interval
;
1849 int session_timeout_set
;
1851 struct eapol_state_machine
*sm
;
1852 int override_eapReq
= 0;
1853 struct radius_hdr
*hdr
= radius_msg_get_hdr(msg
);
1855 sm
= ieee802_1x_search_radius_identifier(hapd
, hdr
->identifier
);
1857 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Could not find matching "
1858 "station for this RADIUS message");
1859 return RADIUS_RX_UNKNOWN
;
1863 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1864 * present when packet contains an EAP-Message attribute */
1865 if (hdr
->code
== RADIUS_CODE_ACCESS_REJECT
&&
1866 radius_msg_get_attr(msg
, RADIUS_ATTR_MESSAGE_AUTHENTICATOR
, NULL
,
1868 radius_msg_get_attr(msg
, RADIUS_ATTR_EAP_MESSAGE
, NULL
, 0) < 0) {
1869 wpa_printf(MSG_DEBUG
, "Allowing RADIUS Access-Reject without "
1870 "Message-Authenticator since it does not include "
1872 } else if (radius_msg_verify(msg
, shared_secret
, shared_secret_len
,
1874 wpa_printf(MSG_INFO
, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
1875 return RADIUS_RX_INVALID_AUTHENTICATOR
;
1878 if (hdr
->code
!= RADIUS_CODE_ACCESS_ACCEPT
&&
1879 hdr
->code
!= RADIUS_CODE_ACCESS_REJECT
&&
1880 hdr
->code
!= RADIUS_CODE_ACCESS_CHALLENGE
) {
1881 wpa_printf(MSG_INFO
, "Unknown RADIUS message code");
1882 return RADIUS_RX_UNKNOWN
;
1885 sm
->radius_identifier
= -1;
1886 wpa_printf(MSG_DEBUG
, "RADIUS packet matching with station " MACSTR
,
1887 MAC2STR(sta
->addr
));
1889 radius_msg_free(sm
->last_recv_radius
);
1890 sm
->last_recv_radius
= msg
;
1892 session_timeout_set
=
1893 !radius_msg_get_attr_int32(msg
, RADIUS_ATTR_SESSION_TIMEOUT
,
1895 if (radius_msg_get_attr_int32(msg
, RADIUS_ATTR_TERMINATION_ACTION
,
1896 &termination_action
))
1897 termination_action
= RADIUS_TERMINATION_ACTION_DEFAULT
;
1899 if (hapd
->conf
->acct_interim_interval
== 0 &&
1900 hdr
->code
== RADIUS_CODE_ACCESS_ACCEPT
&&
1901 radius_msg_get_attr_int32(msg
, RADIUS_ATTR_ACCT_INTERIM_INTERVAL
,
1902 &acct_interim_interval
) == 0) {
1903 if (acct_interim_interval
< 60) {
1904 hostapd_logger(hapd
, sta
->addr
,
1905 HOSTAPD_MODULE_IEEE8021X
,
1907 "ignored too small "
1908 "Acct-Interim-Interval %d",
1909 acct_interim_interval
);
1911 sta
->acct_interim_interval
= acct_interim_interval
;
1915 switch (hdr
->code
) {
1916 case RADIUS_CODE_ACCESS_ACCEPT
:
1917 #ifndef CONFIG_NO_VLAN
1918 if (hapd
->conf
->ssid
.dynamic_vlan
!= DYNAMIC_VLAN_DISABLED
&&
1919 ieee802_1x_update_vlan(msg
, hapd
, sta
) < 0)
1922 if (sta
->vlan_id
> 0) {
1923 hostapd_logger(hapd
, sta
->addr
,
1924 HOSTAPD_MODULE_RADIUS
,
1926 "VLAN ID %d", sta
->vlan_id
);
1929 if ((sta
->flags
& WLAN_STA_ASSOC
) &&
1930 ap_sta_bind_vlan(hapd
, sta
) < 0)
1932 #endif /* CONFIG_NO_VLAN */
1934 sta
->session_timeout_set
= !!session_timeout_set
;
1935 os_get_reltime(&sta
->session_timeout
);
1936 sta
->session_timeout
.sec
+= session_timeout
;
1938 /* RFC 3580, Ch. 3.17 */
1939 if (session_timeout_set
&& termination_action
==
1940 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST
)
1941 sm
->reAuthPeriod
= session_timeout
;
1942 else if (session_timeout_set
)
1943 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1945 ap_sta_no_session_timeout(hapd
, sta
);
1947 sm
->eap_if
->aaaSuccess
= TRUE
;
1948 override_eapReq
= 1;
1949 ieee802_1x_get_keys(hapd
, sta
, msg
, req
, shared_secret
,
1951 ieee802_1x_store_radius_class(hapd
, sta
, msg
);
1952 ieee802_1x_update_sta_identity(hapd
, sta
, msg
);
1953 ieee802_1x_update_sta_cui(hapd
, sta
, msg
);
1954 ieee802_1x_check_hs20(hapd
, sta
, msg
,
1955 session_timeout_set
?
1956 (int) session_timeout
: -1);
1958 case RADIUS_CODE_ACCESS_REJECT
:
1959 sm
->eap_if
->aaaFail
= TRUE
;
1960 override_eapReq
= 1;
1961 if (radius_msg_get_attr_int32(msg
, RADIUS_ATTR_WLAN_REASON_CODE
,
1962 &reason_code
) == 0) {
1963 wpa_printf(MSG_DEBUG
,
1964 "RADIUS server indicated WLAN-Reason-Code %u in Access-Reject for "
1965 MACSTR
, reason_code
, MAC2STR(sta
->addr
));
1966 sta
->disconnect_reason_code
= reason_code
;
1969 case RADIUS_CODE_ACCESS_CHALLENGE
:
1970 sm
->eap_if
->aaaEapReq
= TRUE
;
1971 if (session_timeout_set
) {
1972 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1973 sm
->eap_if
->aaaMethodTimeout
= session_timeout
;
1974 hostapd_logger(hapd
, sm
->addr
,
1975 HOSTAPD_MODULE_IEEE8021X
,
1976 HOSTAPD_LEVEL_DEBUG
,
1977 "using EAP timeout of %d seconds (from "
1979 sm
->eap_if
->aaaMethodTimeout
);
1982 * Use dynamic retransmission behavior per EAP
1985 sm
->eap_if
->aaaMethodTimeout
= 0;
1990 ieee802_1x_decapsulate_radius(hapd
, sta
);
1991 if (override_eapReq
)
1992 sm
->eap_if
->aaaEapReq
= FALSE
;
1996 if (sta
->flags
& WLAN_STA_PENDING_FILS_ERP
) {
1997 /* TODO: Add a PMKSA entry on success? */
1998 ieee802_11_finish_fils_auth(
1999 hapd
, sta
, hdr
->code
== RADIUS_CODE_ACCESS_ACCEPT
,
2000 sm
->eap_if
->aaaEapReqData
,
2001 sm
->eap_if
->aaaEapKeyData
,
2002 sm
->eap_if
->aaaEapKeyDataLen
);
2004 #endif /* NEED_AP_MLME */
2005 #endif /* CONFIG_FILS */
2007 eapol_auth_step(sm
);
2009 return RADIUS_RX_QUEUED
;
2011 #endif /* CONFIG_NO_RADIUS */
2014 void ieee802_1x_abort_auth(struct hostapd_data
*hapd
, struct sta_info
*sta
)
2016 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
2020 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
2021 HOSTAPD_LEVEL_DEBUG
, "aborting authentication");
2023 #ifndef CONFIG_NO_RADIUS
2024 radius_msg_free(sm
->last_recv_radius
);
2025 sm
->last_recv_radius
= NULL
;
2026 #endif /* CONFIG_NO_RADIUS */
2028 if (sm
->eap_if
->eapTimeout
) {
2030 * Disconnect the STA since it did not reply to the last EAP
2031 * request and we cannot continue EAP processing (EAP-Failure
2032 * could only be sent if the EAP peer actually replied).
2034 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "EAP Timeout, STA " MACSTR
,
2035 MAC2STR(sta
->addr
));
2037 sm
->eap_if
->portEnabled
= FALSE
;
2038 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
2039 WLAN_REASON_PREV_AUTH_NOT_VALID
);
2044 static int ieee802_1x_rekey_broadcast(struct hostapd_data
*hapd
)
2046 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
2048 if (hapd
->conf
->default_wep_key_len
< 1)
2051 os_free(eapol
->default_wep_key
);
2052 eapol
->default_wep_key
= os_malloc(hapd
->conf
->default_wep_key_len
);
2053 if (eapol
->default_wep_key
== NULL
||
2054 random_get_bytes(eapol
->default_wep_key
,
2055 hapd
->conf
->default_wep_key_len
)) {
2056 wpa_printf(MSG_INFO
, "Could not generate random WEP key");
2057 os_free(eapol
->default_wep_key
);
2058 eapol
->default_wep_key
= NULL
;
2062 wpa_hexdump_key(MSG_DEBUG
, "IEEE 802.1X: New default WEP key",
2063 eapol
->default_wep_key
,
2064 hapd
->conf
->default_wep_key_len
);
2070 static int ieee802_1x_sta_key_available(struct hostapd_data
*hapd
,
2071 struct sta_info
*sta
, void *ctx
)
2073 if (sta
->eapol_sm
) {
2074 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
2075 eapol_auth_step(sta
->eapol_sm
);
2081 static void ieee802_1x_rekey(void *eloop_ctx
, void *timeout_ctx
)
2083 struct hostapd_data
*hapd
= eloop_ctx
;
2084 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
2086 if (eapol
->default_wep_key_idx
>= 3)
2087 eapol
->default_wep_key_idx
=
2088 hapd
->conf
->individual_wep_key_len
> 0 ? 1 : 0;
2090 eapol
->default_wep_key_idx
++;
2092 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: New default WEP key index %d",
2093 eapol
->default_wep_key_idx
);
2095 if (ieee802_1x_rekey_broadcast(hapd
)) {
2096 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
2097 HOSTAPD_LEVEL_WARNING
, "failed to generate a "
2098 "new broadcast key");
2099 os_free(eapol
->default_wep_key
);
2100 eapol
->default_wep_key
= NULL
;
2104 /* TODO: Could setup key for RX here, but change default TX keyid only
2105 * after new broadcast key has been sent to all stations. */
2106 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_WEP
,
2107 broadcast_ether_addr
,
2108 eapol
->default_wep_key_idx
, 1, NULL
, 0,
2109 eapol
->default_wep_key
,
2110 hapd
->conf
->default_wep_key_len
)) {
2111 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
2112 HOSTAPD_LEVEL_WARNING
, "failed to configure a "
2113 "new broadcast key");
2114 os_free(eapol
->default_wep_key
);
2115 eapol
->default_wep_key
= NULL
;
2119 ap_for_each_sta(hapd
, ieee802_1x_sta_key_available
, NULL
);
2121 if (hapd
->conf
->wep_rekeying_period
> 0) {
2122 eloop_register_timeout(hapd
->conf
->wep_rekeying_period
, 0,
2123 ieee802_1x_rekey
, hapd
, NULL
);
2128 static void ieee802_1x_eapol_send(void *ctx
, void *sta_ctx
, u8 type
,
2129 const u8
*data
, size_t datalen
)
2132 struct sta_info
*sta
= sta_ctx
;
2134 if ((sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) ==
2135 WLAN_STA_MAYBE_WPS
) {
2137 size_t identity_len
;
2138 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
2140 identity
= eap_get_identity(sm
->eap
, &identity_len
);
2142 ((identity_len
== WSC_ID_ENROLLEE_LEN
&&
2143 os_memcmp(identity
, WSC_ID_ENROLLEE
,
2144 WSC_ID_ENROLLEE_LEN
) == 0) ||
2145 (identity_len
== WSC_ID_REGISTRAR_LEN
&&
2146 os_memcmp(identity
, WSC_ID_REGISTRAR
,
2147 WSC_ID_REGISTRAR_LEN
) == 0))) {
2148 wpa_printf(MSG_DEBUG
, "WPS: WLAN_STA_MAYBE_WPS -> "
2150 sta
->flags
|= WLAN_STA_WPS
;
2153 #endif /* CONFIG_WPS */
2155 ieee802_1x_send(ctx
, sta_ctx
, type
, data
, datalen
);
2159 static void ieee802_1x_aaa_send(void *ctx
, void *sta_ctx
,
2160 const u8
*data
, size_t datalen
)
2162 #ifndef CONFIG_NO_RADIUS
2163 struct hostapd_data
*hapd
= ctx
;
2164 struct sta_info
*sta
= sta_ctx
;
2166 ieee802_1x_encapsulate_radius(hapd
, sta
, data
, datalen
);
2167 #endif /* CONFIG_NO_RADIUS */
2171 static void _ieee802_1x_finished(void *ctx
, void *sta_ctx
, int success
,
2172 int preauth
, int remediation
)
2174 struct hostapd_data
*hapd
= ctx
;
2175 struct sta_info
*sta
= sta_ctx
;
2177 rsn_preauth_finished(hapd
, sta
, success
);
2179 ieee802_1x_finished(hapd
, sta
, success
, remediation
);
2183 static int ieee802_1x_get_eap_user(void *ctx
, const u8
*identity
,
2184 size_t identity_len
, int phase2
,
2185 struct eap_user
*user
)
2187 struct hostapd_data
*hapd
= ctx
;
2188 const struct hostapd_eap_user
*eap_user
;
2192 eap_user
= hostapd_get_eap_user(hapd
, identity
, identity_len
, phase2
);
2193 if (eap_user
== NULL
)
2196 os_memset(user
, 0, sizeof(*user
));
2197 user
->phase2
= phase2
;
2198 for (i
= 0; i
< EAP_MAX_METHODS
; i
++) {
2199 user
->methods
[i
].vendor
= eap_user
->methods
[i
].vendor
;
2200 user
->methods
[i
].method
= eap_user
->methods
[i
].method
;
2203 if (eap_user
->password
) {
2204 user
->password
= os_memdup(eap_user
->password
,
2205 eap_user
->password_len
);
2206 if (user
->password
== NULL
)
2208 user
->password_len
= eap_user
->password_len
;
2209 user
->password_hash
= eap_user
->password_hash
;
2210 if (eap_user
->salt
&& eap_user
->salt_len
) {
2211 user
->salt
= os_memdup(eap_user
->salt
,
2212 eap_user
->salt_len
);
2215 user
->salt_len
= eap_user
->salt_len
;
2218 user
->force_version
= eap_user
->force_version
;
2219 user
->macacl
= eap_user
->macacl
;
2220 user
->ttls_auth
= eap_user
->ttls_auth
;
2221 user
->remediation
= eap_user
->remediation
;
2226 wpa_printf(MSG_DEBUG
, "%s: Failed to find user", __func__
);
2232 static int ieee802_1x_sta_entry_alive(void *ctx
, const u8
*addr
)
2234 struct hostapd_data
*hapd
= ctx
;
2235 struct sta_info
*sta
;
2236 sta
= ap_get_sta(hapd
, addr
);
2237 if (sta
== NULL
|| sta
->eapol_sm
== NULL
)
2243 static void ieee802_1x_logger(void *ctx
, const u8
*addr
,
2244 eapol_logger_level level
, const char *txt
)
2246 #ifndef CONFIG_NO_HOSTAPD_LOGGER
2247 struct hostapd_data
*hapd
= ctx
;
2251 case EAPOL_LOGGER_WARNING
:
2252 hlevel
= HOSTAPD_LEVEL_WARNING
;
2254 case EAPOL_LOGGER_INFO
:
2255 hlevel
= HOSTAPD_LEVEL_INFO
;
2257 case EAPOL_LOGGER_DEBUG
:
2259 hlevel
= HOSTAPD_LEVEL_DEBUG
;
2263 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE8021X
, hlevel
, "%s",
2265 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
2269 static void ieee802_1x_set_port_authorized(void *ctx
, void *sta_ctx
,
2272 struct hostapd_data
*hapd
= ctx
;
2273 struct sta_info
*sta
= sta_ctx
;
2274 ieee802_1x_set_sta_authorized(hapd
, sta
, authorized
);
2278 static void _ieee802_1x_abort_auth(void *ctx
, void *sta_ctx
)
2280 struct hostapd_data
*hapd
= ctx
;
2281 struct sta_info
*sta
= sta_ctx
;
2282 ieee802_1x_abort_auth(hapd
, sta
);
2286 static void _ieee802_1x_tx_key(void *ctx
, void *sta_ctx
)
2289 #ifndef CONFIG_NO_RC4
2290 struct hostapd_data
*hapd
= ctx
;
2291 struct sta_info
*sta
= sta_ctx
;
2292 ieee802_1x_tx_key(hapd
, sta
);
2293 #endif /* CONFIG_NO_RC4 */
2294 #endif /* CONFIG_FIPS */
2298 static void ieee802_1x_eapol_event(void *ctx
, void *sta_ctx
,
2299 enum eapol_event type
)
2301 /* struct hostapd_data *hapd = ctx; */
2302 struct sta_info
*sta
= sta_ctx
;
2304 case EAPOL_AUTH_SM_CHANGE
:
2305 wpa_auth_sm_notify(sta
->wpa_sm
);
2307 case EAPOL_AUTH_REAUTHENTICATE
:
2308 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
2316 static struct eap_server_erp_key
*
2317 ieee802_1x_erp_get_key(void *ctx
, const char *keyname
)
2319 struct hostapd_data
*hapd
= ctx
;
2320 struct eap_server_erp_key
*erp
;
2322 dl_list_for_each(erp
, &hapd
->erp_keys
, struct eap_server_erp_key
,
2324 if (os_strcmp(erp
->keyname_nai
, keyname
) == 0)
2332 static int ieee802_1x_erp_add_key(void *ctx
, struct eap_server_erp_key
*erp
)
2334 struct hostapd_data
*hapd
= ctx
;
2336 dl_list_add(&hapd
->erp_keys
, &erp
->list
);
2340 #endif /* CONFIG_ERP */
2343 int ieee802_1x_init(struct hostapd_data
*hapd
)
2346 struct eapol_auth_config conf
;
2347 struct eapol_auth_cb cb
;
2349 dl_list_init(&hapd
->erp_keys
);
2351 os_memset(&conf
, 0, sizeof(conf
));
2353 conf
.eap_reauth_period
= hapd
->conf
->eap_reauth_period
;
2354 conf
.wpa
= hapd
->conf
->wpa
;
2355 conf
.individual_wep_key_len
= hapd
->conf
->individual_wep_key_len
;
2356 conf
.eap_server
= hapd
->conf
->eap_server
;
2357 conf
.ssl_ctx
= hapd
->ssl_ctx
;
2358 conf
.msg_ctx
= hapd
->msg_ctx
;
2359 conf
.eap_sim_db_priv
= hapd
->eap_sim_db_priv
;
2360 conf
.eap_req_id_text
= hapd
->conf
->eap_req_id_text
;
2361 conf
.eap_req_id_text_len
= hapd
->conf
->eap_req_id_text_len
;
2362 conf
.erp_send_reauth_start
= hapd
->conf
->erp_send_reauth_start
;
2363 conf
.erp_domain
= hapd
->conf
->erp_domain
;
2364 conf
.erp
= hapd
->conf
->eap_server_erp
;
2365 conf
.tls_session_lifetime
= hapd
->conf
->tls_session_lifetime
;
2366 conf
.tls_flags
= hapd
->conf
->tls_flags
;
2367 conf
.pac_opaque_encr_key
= hapd
->conf
->pac_opaque_encr_key
;
2368 conf
.eap_fast_a_id
= hapd
->conf
->eap_fast_a_id
;
2369 conf
.eap_fast_a_id_len
= hapd
->conf
->eap_fast_a_id_len
;
2370 conf
.eap_fast_a_id_info
= hapd
->conf
->eap_fast_a_id_info
;
2371 conf
.eap_fast_prov
= hapd
->conf
->eap_fast_prov
;
2372 conf
.pac_key_lifetime
= hapd
->conf
->pac_key_lifetime
;
2373 conf
.pac_key_refresh_time
= hapd
->conf
->pac_key_refresh_time
;
2374 conf
.eap_sim_aka_result_ind
= hapd
->conf
->eap_sim_aka_result_ind
;
2375 conf
.tnc
= hapd
->conf
->tnc
;
2376 conf
.wps
= hapd
->wps
;
2377 conf
.fragment_size
= hapd
->conf
->fragment_size
;
2378 conf
.pwd_group
= hapd
->conf
->pwd_group
;
2379 conf
.pbc_in_m1
= hapd
->conf
->pbc_in_m1
;
2380 if (hapd
->conf
->server_id
) {
2381 conf
.server_id
= (const u8
*) hapd
->conf
->server_id
;
2382 conf
.server_id_len
= os_strlen(hapd
->conf
->server_id
);
2384 conf
.server_id
= (const u8
*) "hostapd";
2385 conf
.server_id_len
= 7;
2388 os_memset(&cb
, 0, sizeof(cb
));
2389 cb
.eapol_send
= ieee802_1x_eapol_send
;
2390 cb
.aaa_send
= ieee802_1x_aaa_send
;
2391 cb
.finished
= _ieee802_1x_finished
;
2392 cb
.get_eap_user
= ieee802_1x_get_eap_user
;
2393 cb
.sta_entry_alive
= ieee802_1x_sta_entry_alive
;
2394 cb
.logger
= ieee802_1x_logger
;
2395 cb
.set_port_authorized
= ieee802_1x_set_port_authorized
;
2396 cb
.abort_auth
= _ieee802_1x_abort_auth
;
2397 cb
.tx_key
= _ieee802_1x_tx_key
;
2398 cb
.eapol_event
= ieee802_1x_eapol_event
;
2400 cb
.erp_get_key
= ieee802_1x_erp_get_key
;
2401 cb
.erp_add_key
= ieee802_1x_erp_add_key
;
2402 #endif /* CONFIG_ERP */
2404 hapd
->eapol_auth
= eapol_auth_init(&conf
, &cb
);
2405 if (hapd
->eapol_auth
== NULL
)
2408 if ((hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
) &&
2409 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1))
2412 #ifndef CONFIG_NO_RADIUS
2413 if (radius_client_register(hapd
->radius
, RADIUS_AUTH
,
2414 ieee802_1x_receive_auth
, hapd
))
2416 #endif /* CONFIG_NO_RADIUS */
2418 if (hapd
->conf
->default_wep_key_len
) {
2419 for (i
= 0; i
< 4; i
++)
2420 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2421 WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
2424 ieee802_1x_rekey(hapd
, NULL
);
2426 if (hapd
->eapol_auth
->default_wep_key
== NULL
)
2434 void ieee802_1x_erp_flush(struct hostapd_data
*hapd
)
2436 struct eap_server_erp_key
*erp
;
2438 while ((erp
= dl_list_first(&hapd
->erp_keys
, struct eap_server_erp_key
,
2440 dl_list_del(&erp
->list
);
2441 bin_clear_free(erp
, sizeof(*erp
));
2446 void ieee802_1x_deinit(struct hostapd_data
*hapd
)
2448 eloop_cancel_timeout(ieee802_1x_rekey
, hapd
, NULL
);
2450 if (hapd
->driver
&& hapd
->drv_priv
&&
2451 (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
))
2452 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
2454 eapol_auth_deinit(hapd
->eapol_auth
);
2455 hapd
->eapol_auth
= NULL
;
2457 ieee802_1x_erp_flush(hapd
);
2461 int ieee802_1x_tx_status(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2462 const u8
*buf
, size_t len
, int ack
)
2464 struct ieee80211_hdr
*hdr
;
2466 const unsigned char rfc1042_hdr
[ETH_ALEN
] =
2467 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2471 if (len
< sizeof(*hdr
) + sizeof(rfc1042_hdr
) + 2)
2474 hdr
= (struct ieee80211_hdr
*) buf
;
2475 pos
= (u8
*) (hdr
+ 1);
2476 if (os_memcmp(pos
, rfc1042_hdr
, sizeof(rfc1042_hdr
)) != 0)
2478 pos
+= sizeof(rfc1042_hdr
);
2479 if (WPA_GET_BE16(pos
) != ETH_P_PAE
)
2483 return ieee802_1x_eapol_tx_status(hapd
, sta
, pos
, buf
+ len
- pos
,
2488 int ieee802_1x_eapol_tx_status(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2489 const u8
*buf
, int len
, int ack
)
2491 const struct ieee802_1x_hdr
*xhdr
=
2492 (const struct ieee802_1x_hdr
*) buf
;
2493 const u8
*pos
= buf
+ sizeof(*xhdr
);
2494 struct ieee802_1x_eapol_key
*key
;
2496 if (len
< (int) sizeof(*xhdr
))
2498 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: " MACSTR
" TX status - version=%d "
2499 "type=%d length=%d - ack=%d",
2500 MAC2STR(sta
->addr
), xhdr
->version
, xhdr
->type
,
2501 be_to_host16(xhdr
->length
), ack
);
2504 if (xhdr
->type
== IEEE802_1X_TYPE_EAP_PACKET
&& ack
&&
2505 (sta
->flags
& WLAN_STA_WPS
) &&
2506 ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd
, sta
)) {
2507 wpa_printf(MSG_DEBUG
,
2508 "WPS: Indicate EAP completion on ACK for EAP-Failure");
2509 hostapd_wps_eap_completed(hapd
);
2511 #endif /* CONFIG_WPS */
2513 if (xhdr
->type
!= IEEE802_1X_TYPE_EAPOL_KEY
)
2516 if (pos
+ sizeof(struct wpa_eapol_key
) <= buf
+ len
) {
2517 const struct wpa_eapol_key
*wpa
;
2518 wpa
= (const struct wpa_eapol_key
*) pos
;
2519 if (wpa
->type
== EAPOL_KEY_TYPE_RSN
||
2520 wpa
->type
== EAPOL_KEY_TYPE_WPA
)
2521 wpa_auth_eapol_key_tx_status(hapd
->wpa_auth
,
2525 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2526 * or Authenticator state machines, but EAPOL-Key packets are not
2527 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
2528 * packets couple of times because otherwise STA keys become
2529 * unsynchronized with AP. */
2530 if (!ack
&& pos
+ sizeof(*key
) <= buf
+ len
) {
2531 key
= (struct ieee802_1x_eapol_key
*) pos
;
2532 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
2533 HOSTAPD_LEVEL_DEBUG
, "did not Ack EAPOL-Key "
2534 "frame (%scast index=%d)",
2535 key
->key_index
& BIT(7) ? "uni" : "broad",
2536 key
->key_index
& ~BIT(7));
2537 /* TODO: re-send EAPOL-Key couple of times (with short delay
2538 * between them?). If all attempt fail, report error and
2539 * deauthenticate STA so that it will get new keys when
2540 * authenticating again (e.g., after returning in range).
2541 * Separate limit/transmit state needed both for unicast and
2542 * broadcast keys(?) */
2544 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2545 * to here and change the key only if the EAPOL-Key packet was Acked.
2552 u8
* ieee802_1x_get_identity(struct eapol_state_machine
*sm
, size_t *len
)
2554 if (sm
== NULL
|| sm
->identity
== NULL
)
2557 *len
= sm
->identity_len
;
2558 return sm
->identity
;
2562 u8
* ieee802_1x_get_radius_class(struct eapol_state_machine
*sm
, size_t *len
,
2565 if (sm
== NULL
|| sm
->radius_class
.attr
== NULL
||
2566 idx
>= (int) sm
->radius_class
.count
)
2569 *len
= sm
->radius_class
.attr
[idx
].len
;
2570 return sm
->radius_class
.attr
[idx
].data
;
2574 struct wpabuf
* ieee802_1x_get_radius_cui(struct eapol_state_machine
*sm
)
2578 return sm
->radius_cui
;
2582 const u8
* ieee802_1x_get_key(struct eapol_state_machine
*sm
, size_t *len
)
2588 *len
= sm
->eap_if
->eapKeyDataLen
;
2589 return sm
->eap_if
->eapKeyData
;
2593 #ifdef CONFIG_MACSEC
2594 const u8
* ieee802_1x_get_session_id(struct eapol_state_machine
*sm
,
2598 if (!sm
|| !sm
->eap_if
)
2601 *len
= sm
->eap_if
->eapSessionIdLen
;
2602 return sm
->eap_if
->eapSessionId
;
2604 #endif /* CONFIG_MACSEC */
2607 void ieee802_1x_notify_port_enabled(struct eapol_state_machine
*sm
,
2612 sm
->eap_if
->portEnabled
= enabled
? TRUE
: FALSE
;
2613 eapol_auth_step(sm
);
2617 void ieee802_1x_notify_port_valid(struct eapol_state_machine
*sm
,
2622 sm
->portValid
= valid
? TRUE
: FALSE
;
2623 eapol_auth_step(sm
);
2627 void ieee802_1x_notify_pre_auth(struct eapol_state_machine
*sm
, int pre_auth
)
2632 sm
->flags
|= EAPOL_SM_PREAUTH
;
2634 sm
->flags
&= ~EAPOL_SM_PREAUTH
;
2638 static const char * bool_txt(Boolean val
)
2640 return val
? "TRUE" : "FALSE";
2644 int ieee802_1x_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
2651 int ieee802_1x_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2652 char *buf
, size_t buflen
)
2655 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
2656 struct os_reltime diff
;
2659 char *identity_buf
= NULL
;
2664 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2665 "dot1xPaePortNumber=%d\n"
2666 "dot1xPaePortProtocolVersion=%d\n"
2667 "dot1xPaePortCapabilities=1\n"
2668 "dot1xPaePortInitialize=%d\n"
2669 "dot1xPaePortReauthenticate=FALSE\n",
2673 if (os_snprintf_error(buflen
- len
, ret
))
2677 /* dot1xAuthConfigTable */
2678 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2679 "dot1xAuthPaeState=%d\n"
2680 "dot1xAuthBackendAuthState=%d\n"
2681 "dot1xAuthAdminControlledDirections=%d\n"
2682 "dot1xAuthOperControlledDirections=%d\n"
2683 "dot1xAuthAuthControlledPortStatus=%d\n"
2684 "dot1xAuthAuthControlledPortControl=%d\n"
2685 "dot1xAuthQuietPeriod=%u\n"
2686 "dot1xAuthServerTimeout=%u\n"
2687 "dot1xAuthReAuthPeriod=%u\n"
2688 "dot1xAuthReAuthEnabled=%s\n"
2689 "dot1xAuthKeyTxEnabled=%s\n",
2690 sm
->auth_pae_state
+ 1,
2691 sm
->be_auth_state
+ 1,
2692 sm
->adminControlledDirections
,
2693 sm
->operControlledDirections
,
2699 bool_txt(sm
->reAuthEnabled
),
2700 bool_txt(sm
->keyTxEnabled
));
2701 if (os_snprintf_error(buflen
- len
, ret
))
2705 /* dot1xAuthStatsTable */
2706 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2707 "dot1xAuthEapolFramesRx=%u\n"
2708 "dot1xAuthEapolFramesTx=%u\n"
2709 "dot1xAuthEapolStartFramesRx=%u\n"
2710 "dot1xAuthEapolLogoffFramesRx=%u\n"
2711 "dot1xAuthEapolRespIdFramesRx=%u\n"
2712 "dot1xAuthEapolRespFramesRx=%u\n"
2713 "dot1xAuthEapolReqIdFramesTx=%u\n"
2714 "dot1xAuthEapolReqFramesTx=%u\n"
2715 "dot1xAuthInvalidEapolFramesRx=%u\n"
2716 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2717 "dot1xAuthLastEapolFrameVersion=%u\n"
2718 "dot1xAuthLastEapolFrameSource=" MACSTR
"\n",
2719 sm
->dot1xAuthEapolFramesRx
,
2720 sm
->dot1xAuthEapolFramesTx
,
2721 sm
->dot1xAuthEapolStartFramesRx
,
2722 sm
->dot1xAuthEapolLogoffFramesRx
,
2723 sm
->dot1xAuthEapolRespIdFramesRx
,
2724 sm
->dot1xAuthEapolRespFramesRx
,
2725 sm
->dot1xAuthEapolReqIdFramesTx
,
2726 sm
->dot1xAuthEapolReqFramesTx
,
2727 sm
->dot1xAuthInvalidEapolFramesRx
,
2728 sm
->dot1xAuthEapLengthErrorFramesRx
,
2729 sm
->dot1xAuthLastEapolFrameVersion
,
2731 if (os_snprintf_error(buflen
- len
, ret
))
2735 /* dot1xAuthDiagTable */
2736 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2737 "dot1xAuthEntersConnecting=%u\n"
2738 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2739 "dot1xAuthEntersAuthenticating=%u\n"
2740 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2741 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2742 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2743 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2744 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2745 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2746 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2747 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2748 "dot1xAuthBackendResponses=%u\n"
2749 "dot1xAuthBackendAccessChallenges=%u\n"
2750 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2751 "dot1xAuthBackendAuthSuccesses=%u\n"
2752 "dot1xAuthBackendAuthFails=%u\n",
2753 sm
->authEntersConnecting
,
2754 sm
->authEapLogoffsWhileConnecting
,
2755 sm
->authEntersAuthenticating
,
2756 sm
->authAuthSuccessesWhileAuthenticating
,
2757 sm
->authAuthTimeoutsWhileAuthenticating
,
2758 sm
->authAuthFailWhileAuthenticating
,
2759 sm
->authAuthEapStartsWhileAuthenticating
,
2760 sm
->authAuthEapLogoffWhileAuthenticating
,
2761 sm
->authAuthReauthsWhileAuthenticated
,
2762 sm
->authAuthEapStartsWhileAuthenticated
,
2763 sm
->authAuthEapLogoffWhileAuthenticated
,
2764 sm
->backendResponses
,
2765 sm
->backendAccessChallenges
,
2766 sm
->backendOtherRequestsToSupplicant
,
2767 sm
->backendAuthSuccesses
,
2768 sm
->backendAuthFails
);
2769 if (os_snprintf_error(buflen
- len
, ret
))
2773 /* dot1xAuthSessionStatsTable */
2774 os_reltime_age(&sta
->acct_session_start
, &diff
);
2775 if (sm
->eap
&& !sm
->identity
) {
2779 id
= eap_get_identity(sm
->eap
, &id_len
);
2781 identity_buf
= dup_binstr(id
, id_len
);
2783 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2784 /* TODO: dot1xAuthSessionOctetsRx */
2785 /* TODO: dot1xAuthSessionOctetsTx */
2786 /* TODO: dot1xAuthSessionFramesRx */
2787 /* TODO: dot1xAuthSessionFramesTx */
2788 "dot1xAuthSessionId=%016llX\n"
2789 "dot1xAuthSessionAuthenticMethod=%d\n"
2790 "dot1xAuthSessionTime=%u\n"
2791 "dot1xAuthSessionTerminateCause=999\n"
2792 "dot1xAuthSessionUserName=%s\n",
2793 (unsigned long long) sta
->acct_session_id
,
2794 (wpa_key_mgmt_wpa_ieee8021x(
2795 wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) ?
2797 (unsigned int) diff
.sec
,
2798 sm
->identity
? (char *) sm
->identity
:
2799 (identity_buf
? identity_buf
: "N/A"));
2800 os_free(identity_buf
);
2801 if (os_snprintf_error(buflen
- len
, ret
))
2805 if (sm
->acct_multi_session_id
) {
2806 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2807 "authMultiSessionId=%016llX\n",
2808 (unsigned long long)
2809 sm
->acct_multi_session_id
);
2810 if (os_snprintf_error(buflen
- len
, ret
))
2815 name1
= eap_server_get_name(0, sm
->eap_type_authsrv
);
2816 name2
= eap_server_get_name(0, sm
->eap_type_supp
);
2817 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2818 "last_eap_type_as=%d (%s)\n"
2819 "last_eap_type_sta=%d (%s)\n",
2820 sm
->eap_type_authsrv
, name1
,
2821 sm
->eap_type_supp
, name2
);
2822 if (os_snprintf_error(buflen
- len
, ret
))
2831 static void ieee802_1x_wnm_notif_send(void *eloop_ctx
, void *timeout_ctx
)
2833 struct hostapd_data
*hapd
= eloop_ctx
;
2834 struct sta_info
*sta
= timeout_ctx
;
2836 if (sta
->remediation
) {
2837 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to "
2838 MACSTR
" to indicate Subscription Remediation",
2839 MAC2STR(sta
->addr
));
2840 hs20_send_wnm_notification(hapd
, sta
->addr
,
2841 sta
->remediation_method
,
2842 sta
->remediation_url
);
2843 os_free(sta
->remediation_url
);
2844 sta
->remediation_url
= NULL
;
2847 if (sta
->hs20_deauth_req
) {
2848 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to "
2849 MACSTR
" to indicate imminent deauthentication",
2850 MAC2STR(sta
->addr
));
2851 hs20_send_wnm_notification_deauth_req(hapd
, sta
->addr
,
2852 sta
->hs20_deauth_req
);
2855 if (sta
->hs20_t_c_filtering
) {
2856 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to "
2857 MACSTR
" to indicate Terms and Conditions filtering",
2858 MAC2STR(sta
->addr
));
2859 hs20_send_wnm_notification_t_c(hapd
, sta
->addr
, sta
->t_c_url
);
2860 os_free(sta
->t_c_url
);
2861 sta
->t_c_url
= NULL
;
2864 #endif /* CONFIG_HS20 */
2867 static void ieee802_1x_finished(struct hostapd_data
*hapd
,
2868 struct sta_info
*sta
, int success
,
2873 /* TODO: get PMKLifetime from WPA parameters */
2874 static const int dot11RSNAConfigPMKLifetime
= 43200;
2875 unsigned int session_timeout
;
2876 struct os_reltime now
, remaining
;
2879 if (remediation
&& !sta
->remediation
) {
2880 sta
->remediation
= 1;
2881 os_free(sta
->remediation_url
);
2882 sta
->remediation_url
=
2883 os_strdup(hapd
->conf
->subscr_remediation_url
);
2884 sta
->remediation_method
= 1; /* SOAP-XML SPP */
2887 if (success
&& (sta
->remediation
|| sta
->hs20_deauth_req
||
2888 sta
->hs20_t_c_filtering
)) {
2889 wpa_printf(MSG_DEBUG
, "HS 2.0: Schedule WNM-Notification to "
2890 MACSTR
" in 100 ms", MAC2STR(sta
->addr
));
2891 eloop_cancel_timeout(ieee802_1x_wnm_notif_send
, hapd
, sta
);
2892 eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send
,
2895 #endif /* CONFIG_HS20 */
2897 #ifdef CONFIG_MACSEC
2898 ieee802_1x_notify_create_actor_hapd(hapd
, sta
);
2899 #endif /* CONFIG_MACSEC */
2901 key
= ieee802_1x_get_key(sta
->eapol_sm
, &len
);
2902 if (sta
->session_timeout_set
) {
2903 os_get_reltime(&now
);
2904 os_reltime_sub(&sta
->session_timeout
, &now
, &remaining
);
2905 session_timeout
= (remaining
.sec
> 0) ? remaining
.sec
: 1;
2907 session_timeout
= dot11RSNAConfigPMKLifetime
;
2909 if (success
&& key
&& len
>= PMK_LEN
&& !sta
->remediation
&&
2910 !sta
->hs20_deauth_requested
&&
2911 wpa_auth_pmksa_add(sta
->wpa_sm
, key
, len
, session_timeout
,
2912 sta
->eapol_sm
) == 0) {
2913 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
2914 HOSTAPD_LEVEL_DEBUG
,
2915 "Added PMKSA cache entry (IEEE 802.1X)");
2920 * Many devices require deauthentication after WPS provisioning
2921 * and some may not be be able to do that themselves, so
2922 * disconnect the client here. In addition, this may also
2923 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2924 * the EAPOL PAE state machine would remain in HELD state for
2925 * considerable amount of time and some EAP methods, like
2926 * EAP-FAST with anonymous provisioning, may require another
2927 * EAPOL authentication to be started to complete connection.
2929 ap_sta_delayed_1x_auth_fail_disconnect(hapd
, sta
);