2 * hostapd / IEEE 802.1X-2004 Authenticator
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "crypto/md5.h"
20 #include "crypto/crypto.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/wpa_ctrl.h"
23 #include "radius/radius.h"
24 #include "radius/radius_client.h"
25 #include "eap_server/eap.h"
26 #include "eap_common/eap_wsc_common.h"
27 #include "eapol_auth/eapol_auth_sm.h"
28 #include "eapol_auth/eapol_auth_sm_i.h"
30 #include "accounting.h"
33 #include "preauth_auth.h"
34 #include "pmksa_cache_auth.h"
35 #include "ap_config.h"
36 #include "ieee802_1x.h"
39 static void ieee802_1x_finished(struct hostapd_data
*hapd
,
40 struct sta_info
*sta
, int success
);
43 static void ieee802_1x_send(struct hostapd_data
*hapd
, struct sta_info
*sta
,
44 u8 type
, const u8
*data
, size_t datalen
)
47 struct ieee802_1x_hdr
*xhdr
;
51 len
= sizeof(*xhdr
) + datalen
;
54 wpa_printf(MSG_ERROR
, "malloc() failed for "
55 "ieee802_1x_send(len=%lu)",
60 xhdr
= (struct ieee802_1x_hdr
*) buf
;
61 xhdr
->version
= hapd
->conf
->eapol_version
;
63 xhdr
->length
= host_to_be16(datalen
);
65 if (datalen
> 0 && data
!= NULL
)
66 os_memcpy(xhdr
+ 1, data
, datalen
);
68 if (wpa_auth_pairwise_set(sta
->wpa_sm
))
70 if (sta
->flags
& WLAN_STA_PREAUTH
) {
71 rsn_preauth_send(hapd
, sta
, buf
, len
);
73 hapd
->drv
.send_eapol(hapd
, sta
->addr
, buf
, len
, encrypt
);
80 void ieee802_1x_set_sta_authorized(struct hostapd_data
*hapd
,
81 struct sta_info
*sta
, int authorized
)
85 if (sta
->flags
& WLAN_STA_PREAUTH
)
89 if (!(sta
->flags
& WLAN_STA_AUTHORIZED
))
90 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
91 AP_STA_CONNECTED MACSTR
, MAC2STR(sta
->addr
));
92 sta
->flags
|= WLAN_STA_AUTHORIZED
;
93 res
= hapd
->drv
.set_authorized(hapd
, sta
, 1);
94 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
95 HOSTAPD_LEVEL_DEBUG
, "authorizing port");
97 if ((sta
->flags
& (WLAN_STA_AUTHORIZED
| WLAN_STA_ASSOC
)) ==
98 (WLAN_STA_AUTHORIZED
| WLAN_STA_ASSOC
))
99 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
100 AP_STA_DISCONNECTED MACSTR
,
102 sta
->flags
&= ~WLAN_STA_AUTHORIZED
;
103 res
= hapd
->drv
.set_authorized(hapd
, sta
, 0);
104 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
105 HOSTAPD_LEVEL_DEBUG
, "unauthorizing port");
108 if (res
&& errno
!= ENOENT
) {
109 printf("Could not set station " MACSTR
" flags for kernel "
110 "driver (errno=%d).\n", MAC2STR(sta
->addr
), errno
);
114 accounting_sta_start(hapd
, sta
);
118 static void ieee802_1x_tx_key_one(struct hostapd_data
*hapd
,
119 struct sta_info
*sta
,
120 int idx
, int broadcast
,
121 u8
*key_data
, size_t key_len
)
124 struct ieee802_1x_hdr
*hdr
;
125 struct ieee802_1x_eapol_key
*key
;
126 size_t len
, ekey_len
;
127 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
132 len
= sizeof(*key
) + key_len
;
133 buf
= os_zalloc(sizeof(*hdr
) + len
);
137 hdr
= (struct ieee802_1x_hdr
*) buf
;
138 key
= (struct ieee802_1x_eapol_key
*) (hdr
+ 1);
139 key
->type
= EAPOL_KEY_TYPE_RC4
;
140 key
->key_length
= htons(key_len
);
141 wpa_get_ntp_timestamp(key
->replay_counter
);
143 if (os_get_random(key
->key_iv
, sizeof(key
->key_iv
))) {
144 wpa_printf(MSG_ERROR
, "Could not get random numbers");
149 key
->key_index
= idx
| (broadcast
? 0 : BIT(7));
150 if (hapd
->conf
->eapol_key_index_workaround
) {
151 /* According to some information, WinXP Supplicant seems to
152 * interpret bit7 as an indication whether the key is to be
153 * activated, so make it possible to enable workaround that
154 * sets this bit for all keys. */
155 key
->key_index
|= BIT(7);
158 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
159 * MSK[32..63] is used to sign the message. */
160 if (sm
->eap_if
->eapKeyData
== NULL
|| sm
->eap_if
->eapKeyDataLen
< 64) {
161 wpa_printf(MSG_ERROR
, "No eapKeyData available for encrypting "
162 "and signing EAPOL-Key");
166 os_memcpy((u8
*) (key
+ 1), key_data
, key_len
);
167 ekey_len
= sizeof(key
->key_iv
) + 32;
168 ekey
= os_malloc(ekey_len
);
170 wpa_printf(MSG_ERROR
, "Could not encrypt key");
174 os_memcpy(ekey
, key
->key_iv
, sizeof(key
->key_iv
));
175 os_memcpy(ekey
+ sizeof(key
->key_iv
), sm
->eap_if
->eapKeyData
, 32);
176 rc4_skip(ekey
, ekey_len
, 0, (u8
*) (key
+ 1), key_len
);
179 /* This header is needed here for HMAC-MD5, but it will be regenerated
180 * in ieee802_1x_send() */
181 hdr
->version
= hapd
->conf
->eapol_version
;
182 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
183 hdr
->length
= host_to_be16(len
);
184 hmac_md5(sm
->eap_if
->eapKeyData
+ 32, 32, buf
, sizeof(*hdr
) + len
,
187 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
188 " (%s index=%d)", MAC2STR(sm
->addr
),
189 broadcast
? "broadcast" : "unicast", idx
);
190 ieee802_1x_send(hapd
, sta
, IEEE802_1X_TYPE_EAPOL_KEY
, (u8
*) key
, len
);
192 sta
->eapol_sm
->dot1xAuthEapolFramesTx
++;
197 #ifndef CONFIG_NO_VLAN
198 static struct hostapd_wep_keys
*
199 ieee802_1x_group_alloc(struct hostapd_data
*hapd
, const char *ifname
)
201 struct hostapd_wep_keys
*key
;
203 key
= os_zalloc(sizeof(*key
));
207 key
->default_len
= hapd
->conf
->default_wep_key_len
;
209 if (key
->idx
>= hapd
->conf
->broadcast_key_idx_max
||
210 key
->idx
< hapd
->conf
->broadcast_key_idx_min
)
211 key
->idx
= hapd
->conf
->broadcast_key_idx_min
;
215 if (!key
->key
[key
->idx
])
216 key
->key
[key
->idx
] = os_malloc(key
->default_len
);
217 if (key
->key
[key
->idx
] == NULL
||
218 os_get_random(key
->key
[key
->idx
], key
->default_len
)) {
219 printf("Could not generate random WEP key (dynamic VLAN).\n");
220 os_free(key
->key
[key
->idx
]);
221 key
->key
[key
->idx
] = NULL
;
225 key
->len
[key
->idx
] = key
->default_len
;
227 wpa_printf(MSG_DEBUG
, "%s: Default WEP idx %d for dynamic VLAN\n",
229 wpa_hexdump_key(MSG_DEBUG
, "Default WEP key (dynamic VLAN)",
230 key
->key
[key
->idx
], key
->len
[key
->idx
]);
232 if (hapd
->drv
.set_key(ifname
, hapd
, WPA_ALG_WEP
, NULL
, key
->idx
, 1,
233 NULL
, 0, key
->key
[key
->idx
], key
->len
[key
->idx
]))
234 printf("Could not set dynamic VLAN WEP encryption key.\n");
236 hapd
->drv
.set_drv_ieee8021x(hapd
, ifname
, 1);
242 static struct hostapd_wep_keys
*
243 ieee802_1x_get_group(struct hostapd_data
*hapd
, struct hostapd_ssid
*ssid
,
251 if (vlan_id
<= ssid
->max_dyn_vlan_keys
&& ssid
->dyn_vlan_keys
&&
252 ssid
->dyn_vlan_keys
[vlan_id
])
253 return ssid
->dyn_vlan_keys
[vlan_id
];
255 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Creating new group "
256 "state machine for VLAN ID %lu",
257 (unsigned long) vlan_id
);
259 ifname
= hostapd_get_vlan_id_ifname(hapd
->conf
->vlan
, vlan_id
);
260 if (ifname
== NULL
) {
261 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Unknown VLAN ID %lu - "
262 "cannot create group key state machine",
263 (unsigned long) vlan_id
);
267 if (ssid
->dyn_vlan_keys
== NULL
) {
268 int size
= (vlan_id
+ 1) * sizeof(ssid
->dyn_vlan_keys
[0]);
269 ssid
->dyn_vlan_keys
= os_zalloc(size
);
270 if (ssid
->dyn_vlan_keys
== NULL
)
272 ssid
->max_dyn_vlan_keys
= vlan_id
;
275 if (ssid
->max_dyn_vlan_keys
< vlan_id
) {
276 struct hostapd_wep_keys
**na
;
277 int size
= (vlan_id
+ 1) * sizeof(ssid
->dyn_vlan_keys
[0]);
278 na
= os_realloc(ssid
->dyn_vlan_keys
, size
);
281 ssid
->dyn_vlan_keys
= na
;
282 os_memset(&ssid
->dyn_vlan_keys
[ssid
->max_dyn_vlan_keys
+ 1], 0,
283 (vlan_id
- ssid
->max_dyn_vlan_keys
) *
284 sizeof(ssid
->dyn_vlan_keys
[0]));
285 ssid
->max_dyn_vlan_keys
= vlan_id
;
288 ssid
->dyn_vlan_keys
[vlan_id
] = ieee802_1x_group_alloc(hapd
, ifname
);
290 return ssid
->dyn_vlan_keys
[vlan_id
];
292 #endif /* CONFIG_NO_VLAN */
295 void ieee802_1x_tx_key(struct hostapd_data
*hapd
, struct sta_info
*sta
)
297 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
298 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
299 #ifndef CONFIG_NO_VLAN
300 struct hostapd_wep_keys
*key
= NULL
;
302 #endif /* CONFIG_NO_VLAN */
304 if (sm
== NULL
|| !sm
->eap_if
->eapKeyData
)
307 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR
,
310 #ifndef CONFIG_NO_VLAN
311 vlan_id
= sta
->vlan_id
;
312 if (vlan_id
< 0 || vlan_id
> MAX_VLAN_ID
)
316 key
= ieee802_1x_get_group(hapd
, sta
->ssid
, vlan_id
);
317 if (key
&& key
->key
[key
->idx
])
318 ieee802_1x_tx_key_one(hapd
, sta
, key
->idx
, 1,
322 #endif /* CONFIG_NO_VLAN */
323 if (eapol
->default_wep_key
) {
324 ieee802_1x_tx_key_one(hapd
, sta
, eapol
->default_wep_key_idx
, 1,
325 eapol
->default_wep_key
,
326 hapd
->conf
->default_wep_key_len
);
329 if (hapd
->conf
->individual_wep_key_len
> 0) {
331 ikey
= os_malloc(hapd
->conf
->individual_wep_key_len
);
333 os_get_random(ikey
, hapd
->conf
->individual_wep_key_len
)) {
334 wpa_printf(MSG_ERROR
, "Could not generate random "
335 "individual WEP key.");
340 wpa_hexdump_key(MSG_DEBUG
, "Individual WEP key",
341 ikey
, hapd
->conf
->individual_wep_key_len
);
343 ieee802_1x_tx_key_one(hapd
, sta
, 0, 0, ikey
,
344 hapd
->conf
->individual_wep_key_len
);
346 /* TODO: set encryption in TX callback, i.e., only after STA
347 * has ACKed EAPOL-Key frame */
348 if (hapd
->drv
.set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_WEP
,
349 sta
->addr
, 0, 1, NULL
, 0, ikey
,
350 hapd
->conf
->individual_wep_key_len
)) {
351 wpa_printf(MSG_ERROR
, "Could not set individual WEP "
360 const char *radius_mode_txt(struct hostapd_data
*hapd
)
362 switch (hapd
->iface
->conf
->hw_mode
) {
363 case HOSTAPD_MODE_IEEE80211A
:
365 case HOSTAPD_MODE_IEEE80211G
:
367 case HOSTAPD_MODE_IEEE80211B
:
374 int radius_sta_rate(struct hostapd_data
*hapd
, struct sta_info
*sta
)
379 for (i
= 0; i
< sta
->supported_rates_len
; i
++)
380 if ((sta
->supported_rates
[i
] & 0x7f) > rate
)
381 rate
= sta
->supported_rates
[i
] & 0x7f;
387 #ifndef CONFIG_NO_RADIUS
388 static void ieee802_1x_learn_identity(struct hostapd_data
*hapd
,
389 struct eapol_state_machine
*sm
,
390 const u8
*eap
, size_t len
)
395 if (len
<= sizeof(struct eap_hdr
) ||
396 eap
[sizeof(struct eap_hdr
)] != EAP_TYPE_IDENTITY
)
399 identity
= eap_get_identity(sm
->eap
, &identity_len
);
400 if (identity
== NULL
)
403 /* Save station identity for future RADIUS packets */
404 os_free(sm
->identity
);
405 sm
->identity
= os_malloc(identity_len
+ 1);
406 if (sm
->identity
== NULL
) {
407 sm
->identity_len
= 0;
411 os_memcpy(sm
->identity
, identity
, identity_len
);
412 sm
->identity_len
= identity_len
;
413 sm
->identity
[identity_len
] = '\0';
414 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
415 HOSTAPD_LEVEL_DEBUG
, "STA identity '%s'", sm
->identity
);
416 sm
->dot1xAuthEapolRespIdFramesRx
++;
420 static void ieee802_1x_encapsulate_radius(struct hostapd_data
*hapd
,
421 struct sta_info
*sta
,
422 const u8
*eap
, size_t len
)
424 struct radius_msg
*msg
;
426 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
431 ieee802_1x_learn_identity(hapd
, sm
, eap
, len
);
433 wpa_printf(MSG_DEBUG
, "Encapsulating EAP message into a RADIUS "
436 sm
->radius_identifier
= radius_client_get_id(hapd
->radius
);
437 msg
= radius_msg_new(RADIUS_CODE_ACCESS_REQUEST
,
438 sm
->radius_identifier
);
440 printf("Could not create net RADIUS packet\n");
444 radius_msg_make_authenticator(msg
, (u8
*) sta
, sizeof(*sta
));
447 !radius_msg_add_attr(msg
, RADIUS_ATTR_USER_NAME
,
448 sm
->identity
, sm
->identity_len
)) {
449 printf("Could not add User-Name\n");
453 if (hapd
->conf
->own_ip_addr
.af
== AF_INET
&&
454 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IP_ADDRESS
,
455 (u8
*) &hapd
->conf
->own_ip_addr
.u
.v4
, 4)) {
456 printf("Could not add NAS-IP-Address\n");
461 if (hapd
->conf
->own_ip_addr
.af
== AF_INET6
&&
462 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IPV6_ADDRESS
,
463 (u8
*) &hapd
->conf
->own_ip_addr
.u
.v6
, 16)) {
464 printf("Could not add NAS-IPv6-Address\n");
467 #endif /* CONFIG_IPV6 */
469 if (hapd
->conf
->nas_identifier
&&
470 !radius_msg_add_attr(msg
, RADIUS_ATTR_NAS_IDENTIFIER
,
471 (u8
*) hapd
->conf
->nas_identifier
,
472 os_strlen(hapd
->conf
->nas_identifier
))) {
473 printf("Could not add NAS-Identifier\n");
477 if (!radius_msg_add_attr_int32(msg
, RADIUS_ATTR_NAS_PORT
, sta
->aid
)) {
478 printf("Could not add NAS-Port\n");
482 os_snprintf(buf
, sizeof(buf
), RADIUS_802_1X_ADDR_FORMAT
":%s",
483 MAC2STR(hapd
->own_addr
), hapd
->conf
->ssid
.ssid
);
484 buf
[sizeof(buf
) - 1] = '\0';
485 if (!radius_msg_add_attr(msg
, RADIUS_ATTR_CALLED_STATION_ID
,
486 (u8
*) buf
, os_strlen(buf
))) {
487 printf("Could not add Called-Station-Id\n");
491 os_snprintf(buf
, sizeof(buf
), RADIUS_802_1X_ADDR_FORMAT
,
493 buf
[sizeof(buf
) - 1] = '\0';
494 if (!radius_msg_add_attr(msg
, RADIUS_ATTR_CALLING_STATION_ID
,
495 (u8
*) buf
, os_strlen(buf
))) {
496 printf("Could not add Calling-Station-Id\n");
500 /* TODO: should probably check MTU from driver config; 2304 is max for
501 * IEEE 802.11, but use 1400 to avoid problems with too large packets
503 if (!radius_msg_add_attr_int32(msg
, RADIUS_ATTR_FRAMED_MTU
, 1400)) {
504 printf("Could not add Framed-MTU\n");
508 if (!radius_msg_add_attr_int32(msg
, RADIUS_ATTR_NAS_PORT_TYPE
,
509 RADIUS_NAS_PORT_TYPE_IEEE_802_11
)) {
510 printf("Could not add NAS-Port-Type\n");
514 if (sta
->flags
& WLAN_STA_PREAUTH
) {
515 os_strlcpy(buf
, "IEEE 802.11i Pre-Authentication",
518 os_snprintf(buf
, sizeof(buf
), "CONNECT %d%sMbps %s",
519 radius_sta_rate(hapd
, sta
) / 2,
520 (radius_sta_rate(hapd
, sta
) & 1) ? ".5" : "",
521 radius_mode_txt(hapd
));
522 buf
[sizeof(buf
) - 1] = '\0';
524 if (!radius_msg_add_attr(msg
, RADIUS_ATTR_CONNECT_INFO
,
525 (u8
*) buf
, os_strlen(buf
))) {
526 printf("Could not add Connect-Info\n");
530 if (eap
&& !radius_msg_add_eap(msg
, eap
, len
)) {
531 printf("Could not add EAP-Message\n");
535 /* State attribute must be copied if and only if this packet is
536 * Access-Request reply to the previous Access-Challenge */
537 if (sm
->last_recv_radius
&&
538 radius_msg_get_hdr(sm
->last_recv_radius
)->code
==
539 RADIUS_CODE_ACCESS_CHALLENGE
) {
540 int res
= radius_msg_copy_attr(msg
, sm
->last_recv_radius
,
543 printf("Could not copy State attribute from previous "
544 "Access-Challenge\n");
548 wpa_printf(MSG_DEBUG
, "Copied RADIUS State Attribute");
552 radius_client_send(hapd
->radius
, msg
, RADIUS_AUTH
, sta
->addr
);
556 radius_msg_free(msg
);
558 #endif /* CONFIG_NO_RADIUS */
561 static void handle_eap_response(struct hostapd_data
*hapd
,
562 struct sta_info
*sta
, struct eap_hdr
*eap
,
566 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
570 data
= (u8
*) (eap
+ 1);
572 if (len
< sizeof(*eap
) + 1) {
573 printf("handle_eap_response: too short response data\n");
577 sm
->eap_type_supp
= type
= data
[0];
579 hostapd_logger(hapd
, sm
->addr
, HOSTAPD_MODULE_IEEE8021X
,
580 HOSTAPD_LEVEL_DEBUG
, "received EAP packet (code=%d "
581 "id=%d len=%d) from STA: EAP Response-%s (%d)",
582 eap
->code
, eap
->identifier
, be_to_host16(eap
->length
),
583 eap_server_get_name(0, type
), type
);
585 sm
->dot1xAuthEapolRespFramesRx
++;
587 wpabuf_free(sm
->eap_if
->eapRespData
);
588 sm
->eap_if
->eapRespData
= wpabuf_alloc_copy(eap
, len
);
593 /* Process incoming EAP packet from Supplicant */
594 static void handle_eap(struct hostapd_data
*hapd
, struct sta_info
*sta
,
600 if (len
< sizeof(*eap
)) {
601 printf(" too short EAP packet\n");
605 eap
= (struct eap_hdr
*) buf
;
607 eap_len
= be_to_host16(eap
->length
);
608 wpa_printf(MSG_DEBUG
, "EAP: code=%d identifier=%d length=%d",
609 eap
->code
, eap
->identifier
, eap_len
);
610 if (eap_len
< sizeof(*eap
)) {
611 wpa_printf(MSG_DEBUG
, " Invalid EAP length");
613 } else if (eap_len
> len
) {
614 wpa_printf(MSG_DEBUG
, " Too short frame to contain this EAP "
617 } else if (eap_len
< len
) {
618 wpa_printf(MSG_DEBUG
, " Ignoring %lu extra bytes after EAP "
619 "packet", (unsigned long) len
- eap_len
);
623 case EAP_CODE_REQUEST
:
624 wpa_printf(MSG_DEBUG
, " (request)");
626 case EAP_CODE_RESPONSE
:
627 wpa_printf(MSG_DEBUG
, " (response)");
628 handle_eap_response(hapd
, sta
, eap
, eap_len
);
630 case EAP_CODE_SUCCESS
:
631 wpa_printf(MSG_DEBUG
, " (success)");
633 case EAP_CODE_FAILURE
:
634 wpa_printf(MSG_DEBUG
, " (failure)");
637 wpa_printf(MSG_DEBUG
, " (unknown code)");
643 static struct eapol_state_machine
*
644 ieee802_1x_alloc_eapol_sm(struct hostapd_data
*hapd
, struct sta_info
*sta
)
647 if (sta
->flags
& WLAN_STA_PREAUTH
)
648 flags
|= EAPOL_SM_PREAUTH
;
650 flags
|= EAPOL_SM_USES_WPA
;
651 if (wpa_auth_sta_get_pmksa(sta
->wpa_sm
))
652 flags
|= EAPOL_SM_FROM_PMKSA_CACHE
;
654 return eapol_auth_alloc(hapd
->eapol_auth
, sta
->addr
, flags
,
660 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
661 * @hapd: hostapd BSS data
662 * @sa: Source address (sender of the EAPOL frame)
664 * @len: Length of buf in octets
666 * This function is called for each incoming EAPOL frame from the interface
668 void ieee802_1x_receive(struct hostapd_data
*hapd
, const u8
*sa
, const u8
*buf
,
671 struct sta_info
*sta
;
672 struct ieee802_1x_hdr
*hdr
;
673 struct ieee802_1x_eapol_key
*key
;
675 struct rsn_pmksa_cache_entry
*pmksa
;
677 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&&
678 !hapd
->conf
->wps_state
)
681 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: %lu bytes from " MACSTR
,
682 (unsigned long) len
, MAC2STR(sa
));
683 sta
= ap_get_sta(hapd
, sa
);
684 if (!sta
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
685 wpa_printf(MSG_DEBUG
, "IEEE 802.1X data frame from not "
690 if (len
< sizeof(*hdr
)) {
691 printf(" too short IEEE 802.1X packet\n");
695 hdr
= (struct ieee802_1x_hdr
*) buf
;
696 datalen
= be_to_host16(hdr
->length
);
697 wpa_printf(MSG_DEBUG
, " IEEE 802.1X: version=%d type=%d length=%d",
698 hdr
->version
, hdr
->type
, datalen
);
700 if (len
- sizeof(*hdr
) < datalen
) {
701 printf(" frame too short for this IEEE 802.1X packet\n");
703 sta
->eapol_sm
->dot1xAuthEapLengthErrorFramesRx
++;
706 if (len
- sizeof(*hdr
) > datalen
) {
707 wpa_printf(MSG_DEBUG
, " ignoring %lu extra octets after "
708 "IEEE 802.1X packet",
709 (unsigned long) len
- sizeof(*hdr
) - datalen
);
713 sta
->eapol_sm
->dot1xAuthLastEapolFrameVersion
= hdr
->version
;
714 sta
->eapol_sm
->dot1xAuthEapolFramesRx
++;
717 key
= (struct ieee802_1x_eapol_key
*) (hdr
+ 1);
718 if (datalen
>= sizeof(struct ieee802_1x_eapol_key
) &&
719 hdr
->type
== IEEE802_1X_TYPE_EAPOL_KEY
&&
720 (key
->type
== EAPOL_KEY_TYPE_WPA
||
721 key
->type
== EAPOL_KEY_TYPE_RSN
)) {
722 wpa_receive(hapd
->wpa_auth
, sta
->wpa_sm
, (u8
*) hdr
,
723 sizeof(*hdr
) + datalen
);
727 if ((!hapd
->conf
->ieee802_1x
&&
728 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
))) ||
729 wpa_key_mgmt_wpa_psk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
)))
732 if (!sta
->eapol_sm
) {
733 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
738 if (!hapd
->conf
->ieee802_1x
&&
739 ((sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) ==
740 WLAN_STA_MAYBE_WPS
)) {
742 * Delay EAPOL frame transmission until a possible WPS
743 * STA initiates the handshake with EAPOL-Start.
745 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
747 #endif /* CONFIG_WPS */
749 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
752 /* since we support version 1, we can ignore version field and proceed
753 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
754 /* TODO: actually, we are not version 1 anymore.. However, Version 2
755 * does not change frame contents, so should be ok to process frames
756 * more or less identically. Some changes might be needed for
757 * verification of fields. */
760 case IEEE802_1X_TYPE_EAP_PACKET
:
761 handle_eap(hapd
, sta
, (u8
*) (hdr
+ 1), datalen
);
764 case IEEE802_1X_TYPE_EAPOL_START
:
765 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
766 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Start "
768 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
769 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
771 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
772 HOSTAPD_LEVEL_DEBUG
, "cached PMKSA "
773 "available - ignore it since "
774 "STA sent EAPOL-Start");
775 wpa_auth_sta_clear_pmksa(sta
->wpa_sm
, pmksa
);
777 sta
->eapol_sm
->eapolStart
= TRUE
;
778 sta
->eapol_sm
->dot1xAuthEapolStartFramesRx
++;
779 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
782 case IEEE802_1X_TYPE_EAPOL_LOGOFF
:
783 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
784 HOSTAPD_LEVEL_DEBUG
, "received EAPOL-Logoff "
786 sta
->acct_terminate_cause
=
787 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
788 accounting_sta_stop(hapd
, sta
);
789 sta
->eapol_sm
->eapolLogoff
= TRUE
;
790 sta
->eapol_sm
->dot1xAuthEapolLogoffFramesRx
++;
793 case IEEE802_1X_TYPE_EAPOL_KEY
:
794 wpa_printf(MSG_DEBUG
, " EAPOL-Key");
795 if (!(sta
->flags
& WLAN_STA_AUTHORIZED
)) {
796 wpa_printf(MSG_DEBUG
, " Dropped key data from "
797 "unauthorized Supplicant");
802 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
:
803 wpa_printf(MSG_DEBUG
, " EAPOL-Encapsulated-ASF-Alert");
804 /* TODO: implement support for this; show data */
808 wpa_printf(MSG_DEBUG
, " unknown IEEE 802.1X packet type");
809 sta
->eapol_sm
->dot1xAuthInvalidEapolFramesRx
++;
813 eapol_auth_step(sta
->eapol_sm
);
818 * ieee802_1x_new_station - Start IEEE 802.1X authentication
819 * @hapd: hostapd BSS data
822 * This function is called to start IEEE 802.1X authentication when a new
823 * station completes IEEE 802.11 association.
825 void ieee802_1x_new_station(struct hostapd_data
*hapd
, struct sta_info
*sta
)
827 struct rsn_pmksa_cache_entry
*pmksa
;
832 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
833 (sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
))) {
835 * Need to enable IEEE 802.1X/EAPOL state machines for possible
836 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
837 * authentication in this BSS.
841 #endif /* CONFIG_WPS */
843 if ((!force_1x
&& !hapd
->conf
->ieee802_1x
) ||
844 wpa_key_mgmt_wpa_psk(wpa_auth_sta_key_mgmt(sta
->wpa_sm
)))
847 if (sta
->eapol_sm
== NULL
) {
848 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
849 HOSTAPD_LEVEL_DEBUG
, "start authentication");
850 sta
->eapol_sm
= ieee802_1x_alloc_eapol_sm(hapd
, sta
);
851 if (sta
->eapol_sm
== NULL
) {
852 hostapd_logger(hapd
, sta
->addr
,
853 HOSTAPD_MODULE_IEEE8021X
,
855 "failed to allocate state machine");
862 sta
->eapol_sm
->flags
&= ~EAPOL_SM_WAIT_START
;
863 if (!hapd
->conf
->ieee802_1x
&& !(sta
->flags
& WLAN_STA_WPS
)) {
865 * Delay EAPOL frame transmission until a possible WPS
866 * initiates the handshake with EAPOL-Start.
868 sta
->eapol_sm
->flags
|= EAPOL_SM_WAIT_START
;
870 #endif /* CONFIG_WPS */
872 sta
->eapol_sm
->eap_if
->portEnabled
= TRUE
;
874 pmksa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
878 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
880 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
881 /* Setup EAPOL state machines to already authenticated state
882 * because of existing PMKSA information in the cache. */
883 sta
->eapol_sm
->keyRun
= TRUE
;
884 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
885 sta
->eapol_sm
->auth_pae_state
= AUTH_PAE_AUTHENTICATING
;
886 sta
->eapol_sm
->be_auth_state
= BE_AUTH_SUCCESS
;
887 sta
->eapol_sm
->authSuccess
= TRUE
;
888 if (sta
->eapol_sm
->eap
)
889 eap_sm_notify_cached(sta
->eapol_sm
->eap
);
890 old_vlanid
= sta
->vlan_id
;
891 pmksa_cache_to_eapol_data(pmksa
, sta
->eapol_sm
);
892 if (sta
->ssid
->dynamic_vlan
== DYNAMIC_VLAN_DISABLED
)
894 ap_sta_bind_vlan(hapd
, sta
, old_vlanid
);
898 * Force EAPOL state machines to start
899 * re-authentication without having to wait for the
900 * Supplicant to send EAPOL-Start.
902 sta
->eapol_sm
->reAuthenticate
= TRUE
;
904 eapol_auth_step(sta
->eapol_sm
);
909 void ieee802_1x_free_station(struct sta_info
*sta
)
911 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
916 sta
->eapol_sm
= NULL
;
918 #ifndef CONFIG_NO_RADIUS
919 radius_msg_free(sm
->last_recv_radius
);
920 radius_free_class(&sm
->radius_class
);
921 #endif /* CONFIG_NO_RADIUS */
923 os_free(sm
->identity
);
928 #ifndef CONFIG_NO_RADIUS
929 static void ieee802_1x_decapsulate_radius(struct hostapd_data
*hapd
,
930 struct sta_info
*sta
)
937 struct radius_msg
*msg
;
938 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
940 if (sm
== NULL
|| sm
->last_recv_radius
== NULL
) {
942 sm
->eap_if
->aaaEapNoReq
= TRUE
;
946 msg
= sm
->last_recv_radius
;
948 eap
= radius_msg_get_eap(msg
, &len
);
950 /* RFC 3579, Chap. 2.6.3:
951 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
953 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
954 HOSTAPD_LEVEL_WARNING
, "could not extract "
955 "EAP-Message from RADIUS message");
956 sm
->eap_if
->aaaEapNoReq
= TRUE
;
960 if (len
< sizeof(*hdr
)) {
961 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
962 HOSTAPD_LEVEL_WARNING
, "too short EAP packet "
963 "received from authentication server");
965 sm
->eap_if
->aaaEapNoReq
= TRUE
;
969 if (len
> sizeof(*hdr
))
970 eap_type
= eap
[sizeof(*hdr
)];
972 hdr
= (struct eap_hdr
*) eap
;
974 case EAP_CODE_REQUEST
:
976 sm
->eap_type_authsrv
= eap_type
;
977 os_snprintf(buf
, sizeof(buf
), "EAP-Request-%s (%d)",
978 eap_type
>= 0 ? eap_server_get_name(0, eap_type
) :
982 case EAP_CODE_RESPONSE
:
983 os_snprintf(buf
, sizeof(buf
), "EAP Response-%s (%d)",
984 eap_type
>= 0 ? eap_server_get_name(0, eap_type
) :
988 case EAP_CODE_SUCCESS
:
989 os_strlcpy(buf
, "EAP Success", sizeof(buf
));
991 case EAP_CODE_FAILURE
:
992 os_strlcpy(buf
, "EAP Failure", sizeof(buf
));
995 os_strlcpy(buf
, "unknown EAP code", sizeof(buf
));
998 buf
[sizeof(buf
) - 1] = '\0';
999 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1000 HOSTAPD_LEVEL_DEBUG
, "decapsulated EAP packet (code=%d "
1001 "id=%d len=%d) from RADIUS server: %s",
1002 hdr
->code
, hdr
->identifier
, be_to_host16(hdr
->length
),
1004 sm
->eap_if
->aaaEapReq
= TRUE
;
1006 wpabuf_free(sm
->eap_if
->aaaEapReqData
);
1007 sm
->eap_if
->aaaEapReqData
= wpabuf_alloc_ext_data(eap
, len
);
1011 static void ieee802_1x_get_keys(struct hostapd_data
*hapd
,
1012 struct sta_info
*sta
, struct radius_msg
*msg
,
1013 struct radius_msg
*req
,
1014 const u8
*shared_secret
,
1015 size_t shared_secret_len
)
1017 struct radius_ms_mppe_keys
*keys
;
1018 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1022 keys
= radius_msg_get_ms_keys(msg
, req
, shared_secret
,
1025 if (keys
&& keys
->send
&& keys
->recv
) {
1026 size_t len
= keys
->send_len
+ keys
->recv_len
;
1027 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Send-Key",
1028 keys
->send
, keys
->send_len
);
1029 wpa_hexdump_key(MSG_DEBUG
, "MS-MPPE-Recv-Key",
1030 keys
->recv
, keys
->recv_len
);
1032 os_free(sm
->eap_if
->aaaEapKeyData
);
1033 sm
->eap_if
->aaaEapKeyData
= os_malloc(len
);
1034 if (sm
->eap_if
->aaaEapKeyData
) {
1035 os_memcpy(sm
->eap_if
->aaaEapKeyData
, keys
->recv
,
1037 os_memcpy(sm
->eap_if
->aaaEapKeyData
+ keys
->recv_len
,
1038 keys
->send
, keys
->send_len
);
1039 sm
->eap_if
->aaaEapKeyDataLen
= len
;
1040 sm
->eap_if
->aaaEapKeyAvailable
= TRUE
;
1045 os_free(keys
->send
);
1046 os_free(keys
->recv
);
1052 static void ieee802_1x_store_radius_class(struct hostapd_data
*hapd
,
1053 struct sta_info
*sta
,
1054 struct radius_msg
*msg
)
1058 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1060 struct radius_attr_data
*nclass
;
1061 size_t nclass_count
;
1063 if (!hapd
->conf
->radius
->acct_server
|| hapd
->radius
== NULL
||
1067 radius_free_class(&sm
->radius_class
);
1068 count
= radius_msg_count_attr(msg
, RADIUS_ATTR_CLASS
, 1);
1072 nclass
= os_zalloc(count
* sizeof(struct radius_attr_data
));
1079 for (i
= 0; i
< count
; i
++) {
1081 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_CLASS
,
1087 } while (class_len
< 1);
1089 nclass
[nclass_count
].data
= os_malloc(class_len
);
1090 if (nclass
[nclass_count
].data
== NULL
)
1093 os_memcpy(nclass
[nclass_count
].data
, class, class_len
);
1094 nclass
[nclass_count
].len
= class_len
;
1098 sm
->radius_class
.attr
= nclass
;
1099 sm
->radius_class
.count
= nclass_count
;
1100 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Stored %lu RADIUS Class "
1101 "attributes for " MACSTR
,
1102 (unsigned long) sm
->radius_class
.count
,
1103 MAC2STR(sta
->addr
));
1107 /* Update sta->identity based on User-Name attribute in Access-Accept */
1108 static void ieee802_1x_update_sta_identity(struct hostapd_data
*hapd
,
1109 struct sta_info
*sta
,
1110 struct radius_msg
*msg
)
1114 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1119 if (radius_msg_get_attr_ptr(msg
, RADIUS_ATTR_USER_NAME
, &buf
, &len
,
1123 identity
= os_malloc(len
+ 1);
1124 if (identity
== NULL
)
1127 os_memcpy(identity
, buf
, len
);
1128 identity
[len
] = '\0';
1130 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1131 HOSTAPD_LEVEL_DEBUG
, "old identity '%s' updated with "
1132 "User-Name from Access-Accept '%s'",
1133 sm
->identity
? (char *) sm
->identity
: "N/A",
1136 os_free(sm
->identity
);
1137 sm
->identity
= identity
;
1138 sm
->identity_len
= len
;
1142 struct sta_id_search
{
1144 struct eapol_state_machine
*sm
;
1148 static int ieee802_1x_select_radius_identifier(struct hostapd_data
*hapd
,
1149 struct sta_info
*sta
,
1152 struct sta_id_search
*id_search
= ctx
;
1153 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1155 if (sm
&& sm
->radius_identifier
>= 0 &&
1156 sm
->radius_identifier
== id_search
->identifier
) {
1164 static struct eapol_state_machine
*
1165 ieee802_1x_search_radius_identifier(struct hostapd_data
*hapd
, u8 identifier
)
1167 struct sta_id_search id_search
;
1168 id_search
.identifier
= identifier
;
1169 id_search
.sm
= NULL
;
1170 ap_for_each_sta(hapd
, ieee802_1x_select_radius_identifier
, &id_search
);
1171 return id_search
.sm
;
1176 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1177 * @msg: RADIUS response message
1178 * @req: RADIUS request message
1179 * @shared_secret: RADIUS shared secret
1180 * @shared_secret_len: Length of shared_secret in octets
1181 * @data: Context data (struct hostapd_data *)
1182 * Returns: Processing status
1184 static RadiusRxResult
1185 ieee802_1x_receive_auth(struct radius_msg
*msg
, struct radius_msg
*req
,
1186 const u8
*shared_secret
, size_t shared_secret_len
,
1189 struct hostapd_data
*hapd
= data
;
1190 struct sta_info
*sta
;
1191 u32 session_timeout
= 0, termination_action
, acct_interim_interval
;
1192 int session_timeout_set
, old_vlanid
= 0;
1193 struct eapol_state_machine
*sm
;
1194 int override_eapReq
= 0;
1195 struct radius_hdr
*hdr
= radius_msg_get_hdr(msg
);
1197 sm
= ieee802_1x_search_radius_identifier(hapd
, hdr
->identifier
);
1199 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: Could not find matching "
1200 "station for this RADIUS message");
1201 return RADIUS_RX_UNKNOWN
;
1205 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1206 * present when packet contains an EAP-Message attribute */
1207 if (hdr
->code
== RADIUS_CODE_ACCESS_REJECT
&&
1208 radius_msg_get_attr(msg
, RADIUS_ATTR_MESSAGE_AUTHENTICATOR
, NULL
,
1210 radius_msg_get_attr(msg
, RADIUS_ATTR_EAP_MESSAGE
, NULL
, 0) < 0) {
1211 wpa_printf(MSG_DEBUG
, "Allowing RADIUS Access-Reject without "
1212 "Message-Authenticator since it does not include "
1214 } else if (radius_msg_verify(msg
, shared_secret
, shared_secret_len
,
1216 printf("Incoming RADIUS packet did not have correct "
1217 "Message-Authenticator - dropped\n");
1218 return RADIUS_RX_INVALID_AUTHENTICATOR
;
1221 if (hdr
->code
!= RADIUS_CODE_ACCESS_ACCEPT
&&
1222 hdr
->code
!= RADIUS_CODE_ACCESS_REJECT
&&
1223 hdr
->code
!= RADIUS_CODE_ACCESS_CHALLENGE
) {
1224 printf("Unknown RADIUS message code\n");
1225 return RADIUS_RX_UNKNOWN
;
1228 sm
->radius_identifier
= -1;
1229 wpa_printf(MSG_DEBUG
, "RADIUS packet matching with station " MACSTR
,
1230 MAC2STR(sta
->addr
));
1232 radius_msg_free(sm
->last_recv_radius
);
1233 sm
->last_recv_radius
= msg
;
1235 session_timeout_set
=
1236 !radius_msg_get_attr_int32(msg
, RADIUS_ATTR_SESSION_TIMEOUT
,
1238 if (radius_msg_get_attr_int32(msg
, RADIUS_ATTR_TERMINATION_ACTION
,
1239 &termination_action
))
1240 termination_action
= RADIUS_TERMINATION_ACTION_DEFAULT
;
1242 if (hapd
->conf
->acct_interim_interval
== 0 &&
1243 hdr
->code
== RADIUS_CODE_ACCESS_ACCEPT
&&
1244 radius_msg_get_attr_int32(msg
, RADIUS_ATTR_ACCT_INTERIM_INTERVAL
,
1245 &acct_interim_interval
) == 0) {
1246 if (acct_interim_interval
< 60) {
1247 hostapd_logger(hapd
, sta
->addr
,
1248 HOSTAPD_MODULE_IEEE8021X
,
1250 "ignored too small "
1251 "Acct-Interim-Interval %d",
1252 acct_interim_interval
);
1254 sta
->acct_interim_interval
= acct_interim_interval
;
1258 switch (hdr
->code
) {
1259 case RADIUS_CODE_ACCESS_ACCEPT
:
1260 if (sta
->ssid
->dynamic_vlan
== DYNAMIC_VLAN_DISABLED
)
1262 #ifndef CONFIG_NO_VLAN
1264 old_vlanid
= sta
->vlan_id
;
1265 sta
->vlan_id
= radius_msg_get_vlanid(msg
);
1267 if (sta
->vlan_id
> 0 &&
1268 hostapd_get_vlan_id_ifname(hapd
->conf
->vlan
,
1270 hostapd_logger(hapd
, sta
->addr
,
1271 HOSTAPD_MODULE_RADIUS
,
1273 "VLAN ID %d", sta
->vlan_id
);
1274 } else if (sta
->ssid
->dynamic_vlan
== DYNAMIC_VLAN_REQUIRED
) {
1275 sta
->eapol_sm
->authFail
= TRUE
;
1276 hostapd_logger(hapd
, sta
->addr
,
1277 HOSTAPD_MODULE_IEEE8021X
,
1278 HOSTAPD_LEVEL_INFO
, "authentication "
1279 "server did not include required VLAN "
1280 "ID in Access-Accept");
1283 #endif /* CONFIG_NO_VLAN */
1285 if (ap_sta_bind_vlan(hapd
, sta
, old_vlanid
) < 0)
1288 /* RFC 3580, Ch. 3.17 */
1289 if (session_timeout_set
&& termination_action
==
1290 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST
) {
1291 sm
->reAuthPeriod
= session_timeout
;
1292 } else if (session_timeout_set
)
1293 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1295 sm
->eap_if
->aaaSuccess
= TRUE
;
1296 override_eapReq
= 1;
1297 ieee802_1x_get_keys(hapd
, sta
, msg
, req
, shared_secret
,
1299 ieee802_1x_store_radius_class(hapd
, sta
, msg
);
1300 ieee802_1x_update_sta_identity(hapd
, sta
, msg
);
1301 if (sm
->eap_if
->eapKeyAvailable
&&
1302 wpa_auth_pmksa_add(sta
->wpa_sm
, sm
->eapol_key_crypt
,
1303 session_timeout_set
?
1304 (int) session_timeout
: -1, sm
) == 0) {
1305 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
1306 HOSTAPD_LEVEL_DEBUG
,
1307 "Added PMKSA cache entry");
1310 case RADIUS_CODE_ACCESS_REJECT
:
1311 sm
->eap_if
->aaaFail
= TRUE
;
1312 override_eapReq
= 1;
1314 case RADIUS_CODE_ACCESS_CHALLENGE
:
1315 sm
->eap_if
->aaaEapReq
= TRUE
;
1316 if (session_timeout_set
) {
1317 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1318 sm
->eap_if
->aaaMethodTimeout
= session_timeout
;
1319 hostapd_logger(hapd
, sm
->addr
,
1320 HOSTAPD_MODULE_IEEE8021X
,
1321 HOSTAPD_LEVEL_DEBUG
,
1322 "using EAP timeout of %d seconds (from "
1324 sm
->eap_if
->aaaMethodTimeout
);
1327 * Use dynamic retransmission behavior per EAP
1330 sm
->eap_if
->aaaMethodTimeout
= 0;
1335 ieee802_1x_decapsulate_radius(hapd
, sta
);
1336 if (override_eapReq
)
1337 sm
->eap_if
->aaaEapReq
= FALSE
;
1339 eapol_auth_step(sm
);
1341 return RADIUS_RX_QUEUED
;
1343 #endif /* CONFIG_NO_RADIUS */
1346 void ieee802_1x_abort_auth(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1348 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1352 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1353 HOSTAPD_LEVEL_DEBUG
, "aborting authentication");
1355 #ifndef CONFIG_NO_RADIUS
1356 radius_msg_free(sm
->last_recv_radius
);
1357 sm
->last_recv_radius
= NULL
;
1358 #endif /* CONFIG_NO_RADIUS */
1360 if (sm
->eap_if
->eapTimeout
) {
1362 * Disconnect the STA since it did not reply to the last EAP
1363 * request and we cannot continue EAP processing (EAP-Failure
1364 * could only be sent if the EAP peer actually replied).
1366 sm
->eap_if
->portEnabled
= FALSE
;
1367 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1368 WLAN_REASON_PREV_AUTH_NOT_VALID
);
1373 static int ieee802_1x_rekey_broadcast(struct hostapd_data
*hapd
)
1375 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
1377 if (hapd
->conf
->default_wep_key_len
< 1)
1380 os_free(eapol
->default_wep_key
);
1381 eapol
->default_wep_key
= os_malloc(hapd
->conf
->default_wep_key_len
);
1382 if (eapol
->default_wep_key
== NULL
||
1383 os_get_random(eapol
->default_wep_key
,
1384 hapd
->conf
->default_wep_key_len
)) {
1385 printf("Could not generate random WEP key.\n");
1386 os_free(eapol
->default_wep_key
);
1387 eapol
->default_wep_key
= NULL
;
1391 wpa_hexdump_key(MSG_DEBUG
, "IEEE 802.1X: New default WEP key",
1392 eapol
->default_wep_key
,
1393 hapd
->conf
->default_wep_key_len
);
1399 static int ieee802_1x_sta_key_available(struct hostapd_data
*hapd
,
1400 struct sta_info
*sta
, void *ctx
)
1402 if (sta
->eapol_sm
) {
1403 sta
->eapol_sm
->eap_if
->eapKeyAvailable
= TRUE
;
1404 eapol_auth_step(sta
->eapol_sm
);
1410 static void ieee802_1x_rekey(void *eloop_ctx
, void *timeout_ctx
)
1412 struct hostapd_data
*hapd
= eloop_ctx
;
1413 struct eapol_authenticator
*eapol
= hapd
->eapol_auth
;
1415 if (eapol
->default_wep_key_idx
>= 3)
1416 eapol
->default_wep_key_idx
=
1417 hapd
->conf
->individual_wep_key_len
> 0 ? 1 : 0;
1419 eapol
->default_wep_key_idx
++;
1421 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: New default WEP key index %d",
1422 eapol
->default_wep_key_idx
);
1424 if (ieee802_1x_rekey_broadcast(hapd
)) {
1425 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
1426 HOSTAPD_LEVEL_WARNING
, "failed to generate a "
1427 "new broadcast key");
1428 os_free(eapol
->default_wep_key
);
1429 eapol
->default_wep_key
= NULL
;
1433 /* TODO: Could setup key for RX here, but change default TX keyid only
1434 * after new broadcast key has been sent to all stations. */
1435 if (hapd
->drv
.set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_WEP
, NULL
,
1436 eapol
->default_wep_key_idx
, 1, NULL
, 0,
1437 eapol
->default_wep_key
,
1438 hapd
->conf
->default_wep_key_len
)) {
1439 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE8021X
,
1440 HOSTAPD_LEVEL_WARNING
, "failed to configure a "
1441 "new broadcast key");
1442 os_free(eapol
->default_wep_key
);
1443 eapol
->default_wep_key
= NULL
;
1447 ap_for_each_sta(hapd
, ieee802_1x_sta_key_available
, NULL
);
1449 if (hapd
->conf
->wep_rekeying_period
> 0) {
1450 eloop_register_timeout(hapd
->conf
->wep_rekeying_period
, 0,
1451 ieee802_1x_rekey
, hapd
, NULL
);
1456 static void ieee802_1x_eapol_send(void *ctx
, void *sta_ctx
, u8 type
,
1457 const u8
*data
, size_t datalen
)
1460 struct sta_info
*sta
= sta_ctx
;
1462 if ((sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)) ==
1463 WLAN_STA_MAYBE_WPS
) {
1465 size_t identity_len
;
1466 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1468 identity
= eap_get_identity(sm
->eap
, &identity_len
);
1470 ((identity_len
== WSC_ID_ENROLLEE_LEN
&&
1471 os_memcmp(identity
, WSC_ID_ENROLLEE
,
1472 WSC_ID_ENROLLEE_LEN
) == 0) ||
1473 (identity_len
== WSC_ID_REGISTRAR_LEN
&&
1474 os_memcmp(identity
, WSC_ID_REGISTRAR
,
1475 WSC_ID_REGISTRAR_LEN
) == 0))) {
1476 wpa_printf(MSG_DEBUG
, "WPS: WLAN_STA_MAYBE_WPS -> "
1478 sta
->flags
|= WLAN_STA_WPS
;
1481 #endif /* CONFIG_WPS */
1483 ieee802_1x_send(ctx
, sta_ctx
, type
, data
, datalen
);
1487 static void ieee802_1x_aaa_send(void *ctx
, void *sta_ctx
,
1488 const u8
*data
, size_t datalen
)
1490 #ifndef CONFIG_NO_RADIUS
1491 struct hostapd_data
*hapd
= ctx
;
1492 struct sta_info
*sta
= sta_ctx
;
1494 ieee802_1x_encapsulate_radius(hapd
, sta
, data
, datalen
);
1495 #endif /* CONFIG_NO_RADIUS */
1499 static void _ieee802_1x_finished(void *ctx
, void *sta_ctx
, int success
,
1502 struct hostapd_data
*hapd
= ctx
;
1503 struct sta_info
*sta
= sta_ctx
;
1505 rsn_preauth_finished(hapd
, sta
, success
);
1507 ieee802_1x_finished(hapd
, sta
, success
);
1511 static int ieee802_1x_get_eap_user(void *ctx
, const u8
*identity
,
1512 size_t identity_len
, int phase2
,
1513 struct eap_user
*user
)
1515 struct hostapd_data
*hapd
= ctx
;
1516 const struct hostapd_eap_user
*eap_user
;
1519 eap_user
= hostapd_get_eap_user(hapd
->conf
, identity
,
1520 identity_len
, phase2
);
1521 if (eap_user
== NULL
)
1524 os_memset(user
, 0, sizeof(*user
));
1525 user
->phase2
= phase2
;
1526 count
= EAP_USER_MAX_METHODS
;
1527 if (count
> EAP_MAX_METHODS
)
1528 count
= EAP_MAX_METHODS
;
1529 for (i
= 0; i
< count
; i
++) {
1530 user
->methods
[i
].vendor
= eap_user
->methods
[i
].vendor
;
1531 user
->methods
[i
].method
= eap_user
->methods
[i
].method
;
1534 if (eap_user
->password
) {
1535 user
->password
= os_malloc(eap_user
->password_len
);
1536 if (user
->password
== NULL
)
1538 os_memcpy(user
->password
, eap_user
->password
,
1539 eap_user
->password_len
);
1540 user
->password_len
= eap_user
->password_len
;
1542 user
->force_version
= eap_user
->force_version
;
1543 user
->ttls_auth
= eap_user
->ttls_auth
;
1549 static int ieee802_1x_sta_entry_alive(void *ctx
, const u8
*addr
)
1551 struct hostapd_data
*hapd
= ctx
;
1552 struct sta_info
*sta
;
1553 sta
= ap_get_sta(hapd
, addr
);
1554 if (sta
== NULL
|| sta
->eapol_sm
== NULL
)
1560 static void ieee802_1x_logger(void *ctx
, const u8
*addr
,
1561 eapol_logger_level level
, const char *txt
)
1563 #ifndef CONFIG_NO_HOSTAPD_LOGGER
1564 struct hostapd_data
*hapd
= ctx
;
1568 case EAPOL_LOGGER_WARNING
:
1569 hlevel
= HOSTAPD_LEVEL_WARNING
;
1571 case EAPOL_LOGGER_INFO
:
1572 hlevel
= HOSTAPD_LEVEL_INFO
;
1574 case EAPOL_LOGGER_DEBUG
:
1576 hlevel
= HOSTAPD_LEVEL_DEBUG
;
1580 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE8021X
, hlevel
, "%s",
1582 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
1586 static void ieee802_1x_set_port_authorized(void *ctx
, void *sta_ctx
,
1589 struct hostapd_data
*hapd
= ctx
;
1590 struct sta_info
*sta
= sta_ctx
;
1591 ieee802_1x_set_sta_authorized(hapd
, sta
, authorized
);
1595 static void _ieee802_1x_abort_auth(void *ctx
, void *sta_ctx
)
1597 struct hostapd_data
*hapd
= ctx
;
1598 struct sta_info
*sta
= sta_ctx
;
1599 ieee802_1x_abort_auth(hapd
, sta
);
1603 static void _ieee802_1x_tx_key(void *ctx
, void *sta_ctx
)
1605 struct hostapd_data
*hapd
= ctx
;
1606 struct sta_info
*sta
= sta_ctx
;
1607 ieee802_1x_tx_key(hapd
, sta
);
1611 static void ieee802_1x_eapol_event(void *ctx
, void *sta_ctx
,
1612 enum eapol_event type
)
1614 /* struct hostapd_data *hapd = ctx; */
1615 struct sta_info
*sta
= sta_ctx
;
1617 case EAPOL_AUTH_SM_CHANGE
:
1618 wpa_auth_sm_notify(sta
->wpa_sm
);
1620 case EAPOL_AUTH_REAUTHENTICATE
:
1621 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH_EAPOL
);
1627 int ieee802_1x_init(struct hostapd_data
*hapd
)
1630 struct eapol_auth_config conf
;
1631 struct eapol_auth_cb cb
;
1633 os_memset(&conf
, 0, sizeof(conf
));
1635 conf
.eap_reauth_period
= hapd
->conf
->eap_reauth_period
;
1636 conf
.wpa
= hapd
->conf
->wpa
;
1637 conf
.individual_wep_key_len
= hapd
->conf
->individual_wep_key_len
;
1638 conf
.eap_server
= hapd
->conf
->eap_server
;
1639 conf
.ssl_ctx
= hapd
->ssl_ctx
;
1640 conf
.msg_ctx
= hapd
->msg_ctx
;
1641 conf
.eap_sim_db_priv
= hapd
->eap_sim_db_priv
;
1642 conf
.eap_req_id_text
= hapd
->conf
->eap_req_id_text
;
1643 conf
.eap_req_id_text_len
= hapd
->conf
->eap_req_id_text_len
;
1644 conf
.pac_opaque_encr_key
= hapd
->conf
->pac_opaque_encr_key
;
1645 conf
.eap_fast_a_id
= hapd
->conf
->eap_fast_a_id
;
1646 conf
.eap_fast_a_id_len
= hapd
->conf
->eap_fast_a_id_len
;
1647 conf
.eap_fast_a_id_info
= hapd
->conf
->eap_fast_a_id_info
;
1648 conf
.eap_fast_prov
= hapd
->conf
->eap_fast_prov
;
1649 conf
.pac_key_lifetime
= hapd
->conf
->pac_key_lifetime
;
1650 conf
.pac_key_refresh_time
= hapd
->conf
->pac_key_refresh_time
;
1651 conf
.eap_sim_aka_result_ind
= hapd
->conf
->eap_sim_aka_result_ind
;
1652 conf
.tnc
= hapd
->conf
->tnc
;
1653 conf
.wps
= hapd
->wps
;
1655 os_memset(&cb
, 0, sizeof(cb
));
1656 cb
.eapol_send
= ieee802_1x_eapol_send
;
1657 cb
.aaa_send
= ieee802_1x_aaa_send
;
1658 cb
.finished
= _ieee802_1x_finished
;
1659 cb
.get_eap_user
= ieee802_1x_get_eap_user
;
1660 cb
.sta_entry_alive
= ieee802_1x_sta_entry_alive
;
1661 cb
.logger
= ieee802_1x_logger
;
1662 cb
.set_port_authorized
= ieee802_1x_set_port_authorized
;
1663 cb
.abort_auth
= _ieee802_1x_abort_auth
;
1664 cb
.tx_key
= _ieee802_1x_tx_key
;
1665 cb
.eapol_event
= ieee802_1x_eapol_event
;
1667 hapd
->eapol_auth
= eapol_auth_init(&conf
, &cb
);
1668 if (hapd
->eapol_auth
== NULL
)
1671 if ((hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
) &&
1672 hapd
->drv
.set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1))
1675 #ifndef CONFIG_NO_RADIUS
1676 if (radius_client_register(hapd
->radius
, RADIUS_AUTH
,
1677 ieee802_1x_receive_auth
, hapd
))
1679 #endif /* CONFIG_NO_RADIUS */
1681 if (hapd
->conf
->default_wep_key_len
) {
1682 for (i
= 0; i
< 4; i
++)
1683 hapd
->drv
.set_key(hapd
->conf
->iface
, hapd
,
1684 WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
1687 ieee802_1x_rekey(hapd
, NULL
);
1689 if (hapd
->eapol_auth
->default_wep_key
== NULL
)
1697 void ieee802_1x_deinit(struct hostapd_data
*hapd
)
1699 eloop_cancel_timeout(ieee802_1x_rekey
, hapd
, NULL
);
1701 if (hapd
->driver
!= NULL
&&
1702 (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
))
1703 hapd
->drv
.set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
1705 eapol_auth_deinit(hapd
->eapol_auth
);
1706 hapd
->eapol_auth
= NULL
;
1710 int ieee802_1x_tx_status(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1711 const u8
*buf
, size_t len
, int ack
)
1713 struct ieee80211_hdr
*hdr
;
1714 struct ieee802_1x_hdr
*xhdr
;
1715 struct ieee802_1x_eapol_key
*key
;
1717 const unsigned char rfc1042_hdr
[ETH_ALEN
] =
1718 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1722 if (len
< sizeof(*hdr
) + sizeof(rfc1042_hdr
) + 2 + sizeof(*xhdr
))
1725 hdr
= (struct ieee80211_hdr
*) buf
;
1726 pos
= (u8
*) (hdr
+ 1);
1727 if (os_memcmp(pos
, rfc1042_hdr
, sizeof(rfc1042_hdr
)) != 0)
1729 pos
+= sizeof(rfc1042_hdr
);
1730 if (WPA_GET_BE16(pos
) != ETH_P_PAE
)
1734 xhdr
= (struct ieee802_1x_hdr
*) pos
;
1735 pos
+= sizeof(*xhdr
);
1737 wpa_printf(MSG_DEBUG
, "IEEE 802.1X: " MACSTR
" TX status - version=%d "
1738 "type=%d length=%d - ack=%d",
1739 MAC2STR(sta
->addr
), xhdr
->version
, xhdr
->type
,
1740 be_to_host16(xhdr
->length
), ack
);
1742 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
1743 * or Authenticator state machines, but EAPOL-Key packets are not
1744 * retransmitted in case of failure. Try to re-sent failed EAPOL-Key
1745 * packets couple of times because otherwise STA keys become
1746 * unsynchronized with AP. */
1747 if (xhdr
->type
== IEEE802_1X_TYPE_EAPOL_KEY
&& !ack
&&
1748 pos
+ sizeof(*key
) <= buf
+ len
) {
1749 key
= (struct ieee802_1x_eapol_key
*) pos
;
1750 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE8021X
,
1751 HOSTAPD_LEVEL_DEBUG
, "did not Ack EAPOL-Key "
1752 "frame (%scast index=%d)",
1753 key
->key_index
& BIT(7) ? "uni" : "broad",
1754 key
->key_index
& ~BIT(7));
1755 /* TODO: re-send EAPOL-Key couple of times (with short delay
1756 * between them?). If all attempt fail, report error and
1757 * deauthenticate STA so that it will get new keys when
1758 * authenticating again (e.g., after returning in range).
1759 * Separate limit/transmit state needed both for unicast and
1760 * broadcast keys(?) */
1762 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
1763 * to here and change the key only if the EAPOL-Key packet was Acked.
1770 u8
* ieee802_1x_get_identity(struct eapol_state_machine
*sm
, size_t *len
)
1772 if (sm
== NULL
|| sm
->identity
== NULL
)
1775 *len
= sm
->identity_len
;
1776 return sm
->identity
;
1780 u8
* ieee802_1x_get_radius_class(struct eapol_state_machine
*sm
, size_t *len
,
1783 if (sm
== NULL
|| sm
->radius_class
.attr
== NULL
||
1784 idx
>= (int) sm
->radius_class
.count
)
1787 *len
= sm
->radius_class
.attr
[idx
].len
;
1788 return sm
->radius_class
.attr
[idx
].data
;
1792 const u8
* ieee802_1x_get_key(struct eapol_state_machine
*sm
, size_t *len
)
1797 *len
= sm
->eap_if
->eapKeyDataLen
;
1798 return sm
->eap_if
->eapKeyData
;
1802 void ieee802_1x_notify_port_enabled(struct eapol_state_machine
*sm
,
1807 sm
->eap_if
->portEnabled
= enabled
? TRUE
: FALSE
;
1808 eapol_auth_step(sm
);
1812 void ieee802_1x_notify_port_valid(struct eapol_state_machine
*sm
,
1817 sm
->portValid
= valid
? TRUE
: FALSE
;
1818 eapol_auth_step(sm
);
1822 void ieee802_1x_notify_pre_auth(struct eapol_state_machine
*sm
, int pre_auth
)
1827 sm
->flags
|= EAPOL_SM_PREAUTH
;
1829 sm
->flags
&= ~EAPOL_SM_PREAUTH
;
1833 static const char * bool_txt(Boolean
bool)
1835 return bool ? "TRUE" : "FALSE";
1839 int ieee802_1x_get_mib(struct hostapd_data
*hapd
, char *buf
, size_t buflen
)
1846 int ieee802_1x_get_mib_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1847 char *buf
, size_t buflen
)
1850 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
1855 ret
= os_snprintf(buf
+ len
, buflen
- len
,
1856 "dot1xPaePortNumber=%d\n"
1857 "dot1xPaePortProtocolVersion=%d\n"
1858 "dot1xPaePortCapabilities=1\n"
1859 "dot1xPaePortInitialize=%d\n"
1860 "dot1xPaePortReauthenticate=FALSE\n",
1864 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
1868 /* dot1xAuthConfigTable */
1869 ret
= os_snprintf(buf
+ len
, buflen
- len
,
1870 "dot1xAuthPaeState=%d\n"
1871 "dot1xAuthBackendAuthState=%d\n"
1872 "dot1xAuthAdminControlledDirections=%d\n"
1873 "dot1xAuthOperControlledDirections=%d\n"
1874 "dot1xAuthAuthControlledPortStatus=%d\n"
1875 "dot1xAuthAuthControlledPortControl=%d\n"
1876 "dot1xAuthQuietPeriod=%u\n"
1877 "dot1xAuthServerTimeout=%u\n"
1878 "dot1xAuthReAuthPeriod=%u\n"
1879 "dot1xAuthReAuthEnabled=%s\n"
1880 "dot1xAuthKeyTxEnabled=%s\n",
1881 sm
->auth_pae_state
+ 1,
1882 sm
->be_auth_state
+ 1,
1883 sm
->adminControlledDirections
,
1884 sm
->operControlledDirections
,
1890 bool_txt(sm
->reAuthEnabled
),
1891 bool_txt(sm
->keyTxEnabled
));
1892 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
1896 /* dot1xAuthStatsTable */
1897 ret
= os_snprintf(buf
+ len
, buflen
- len
,
1898 "dot1xAuthEapolFramesRx=%u\n"
1899 "dot1xAuthEapolFramesTx=%u\n"
1900 "dot1xAuthEapolStartFramesRx=%u\n"
1901 "dot1xAuthEapolLogoffFramesRx=%u\n"
1902 "dot1xAuthEapolRespIdFramesRx=%u\n"
1903 "dot1xAuthEapolRespFramesRx=%u\n"
1904 "dot1xAuthEapolReqIdFramesTx=%u\n"
1905 "dot1xAuthEapolReqFramesTx=%u\n"
1906 "dot1xAuthInvalidEapolFramesRx=%u\n"
1907 "dot1xAuthEapLengthErrorFramesRx=%u\n"
1908 "dot1xAuthLastEapolFrameVersion=%u\n"
1909 "dot1xAuthLastEapolFrameSource=" MACSTR
"\n",
1910 sm
->dot1xAuthEapolFramesRx
,
1911 sm
->dot1xAuthEapolFramesTx
,
1912 sm
->dot1xAuthEapolStartFramesRx
,
1913 sm
->dot1xAuthEapolLogoffFramesRx
,
1914 sm
->dot1xAuthEapolRespIdFramesRx
,
1915 sm
->dot1xAuthEapolRespFramesRx
,
1916 sm
->dot1xAuthEapolReqIdFramesTx
,
1917 sm
->dot1xAuthEapolReqFramesTx
,
1918 sm
->dot1xAuthInvalidEapolFramesRx
,
1919 sm
->dot1xAuthEapLengthErrorFramesRx
,
1920 sm
->dot1xAuthLastEapolFrameVersion
,
1922 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
1926 /* dot1xAuthDiagTable */
1927 ret
= os_snprintf(buf
+ len
, buflen
- len
,
1928 "dot1xAuthEntersConnecting=%u\n"
1929 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
1930 "dot1xAuthEntersAuthenticating=%u\n"
1931 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
1932 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
1933 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
1934 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
1935 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
1936 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
1937 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
1938 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
1939 "dot1xAuthBackendResponses=%u\n"
1940 "dot1xAuthBackendAccessChallenges=%u\n"
1941 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
1942 "dot1xAuthBackendAuthSuccesses=%u\n"
1943 "dot1xAuthBackendAuthFails=%u\n",
1944 sm
->authEntersConnecting
,
1945 sm
->authEapLogoffsWhileConnecting
,
1946 sm
->authEntersAuthenticating
,
1947 sm
->authAuthSuccessesWhileAuthenticating
,
1948 sm
->authAuthTimeoutsWhileAuthenticating
,
1949 sm
->authAuthFailWhileAuthenticating
,
1950 sm
->authAuthEapStartsWhileAuthenticating
,
1951 sm
->authAuthEapLogoffWhileAuthenticating
,
1952 sm
->authAuthReauthsWhileAuthenticated
,
1953 sm
->authAuthEapStartsWhileAuthenticated
,
1954 sm
->authAuthEapLogoffWhileAuthenticated
,
1955 sm
->backendResponses
,
1956 sm
->backendAccessChallenges
,
1957 sm
->backendOtherRequestsToSupplicant
,
1958 sm
->backendAuthSuccesses
,
1959 sm
->backendAuthFails
);
1960 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
1964 /* dot1xAuthSessionStatsTable */
1965 ret
= os_snprintf(buf
+ len
, buflen
- len
,
1966 /* TODO: dot1xAuthSessionOctetsRx */
1967 /* TODO: dot1xAuthSessionOctetsTx */
1968 /* TODO: dot1xAuthSessionFramesRx */
1969 /* TODO: dot1xAuthSessionFramesTx */
1970 "dot1xAuthSessionId=%08X-%08X\n"
1971 "dot1xAuthSessionAuthenticMethod=%d\n"
1972 "dot1xAuthSessionTime=%u\n"
1973 "dot1xAuthSessionTerminateCause=999\n"
1974 "dot1xAuthSessionUserName=%s\n",
1975 sta
->acct_session_id_hi
, sta
->acct_session_id_lo
,
1976 (wpa_key_mgmt_wpa_ieee8021x(
1977 wpa_auth_sta_key_mgmt(sta
->wpa_sm
))) ?
1979 (unsigned int) (time(NULL
) -
1980 sta
->acct_session_start
),
1982 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
1990 static void ieee802_1x_finished(struct hostapd_data
*hapd
,
1991 struct sta_info
*sta
, int success
)
1995 /* TODO: get PMKLifetime from WPA parameters */
1996 static const int dot11RSNAConfigPMKLifetime
= 43200;
1998 key
= ieee802_1x_get_key(sta
->eapol_sm
, &len
);
1999 if (success
&& key
&& len
>= PMK_LEN
&&
2000 wpa_auth_pmksa_add(sta
->wpa_sm
, key
, dot11RSNAConfigPMKLifetime
,
2001 sta
->eapol_sm
) == 0) {
2002 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_WPA
,
2003 HOSTAPD_LEVEL_DEBUG
,
2004 "Added PMKSA cache entry (IEEE 802.1X)");
2008 if (!success
&& (sta
->flags
& WLAN_STA_WPS
)) {
2010 * Many devices require deauthentication after WPS provisioning
2011 * and some may not be be able to do that themselves, so
2012 * disconnect the client here.
2014 wpa_printf(MSG_DEBUG
, "WPS: Force disconnection after "
2016 /* Add a small sleep to increase likelihood of previously
2017 * requested EAP-Failure TX getting out before this should the
2018 * driver reorder operations.
2021 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
2022 WLAN_REASON_PREV_AUTH_NOT_VALID
);
2024 #endif /* CONFIG_WPS */