2 * EAP peer state machines (RFC 4137)
3 * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This file implements the Peer State Machine as defined in RFC 4137. The used
9 * states and state transitions match mostly with the RFC. However, there are
10 * couple of additional transitions for working around small issues noticed
11 * during testing. These exceptions are explained in comments within the
12 * functions in this file. The method functions, m.func(), are similar to the
13 * ones used in RFC 4137, but some small changes have used here to optimize
14 * operations and to add functionality needed for fast re-authentication
15 * (session resumption).
21 #include "pcsc_funcs.h"
22 #include "state_machine.h"
23 #include "ext_password.h"
24 #include "crypto/crypto.h"
25 #include "crypto/tls.h"
26 #include "crypto/sha256.h"
27 #include "common/wpa_ctrl.h"
28 #include "eap_common/eap_wsc_common.h"
30 #include "eap_config.h"
32 #define STATE_MACHINE_DATA struct eap_sm
33 #define STATE_MACHINE_DEBUG_PREFIX "EAP"
35 #define EAP_MAX_AUTH_ROUNDS 50
36 #define EAP_CLIENT_TIMEOUT_DEFAULT 60
39 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
41 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id);
42 static void eap_sm_processIdentity(struct eap_sm *sm,
43 const struct wpabuf *req);
44 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req);
45 static struct wpabuf * eap_sm_buildNotify(int id);
46 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req);
47 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
48 static const char * eap_sm_method_state_txt(EapMethodState state);
49 static const char * eap_sm_decision_txt(EapDecision decision);
50 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
51 static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
52 const char *msg, size_t msglen);
56 static Boolean eapol_get_bool(struct eap_sm *sm, enum eapol_bool_var var)
58 return sm->eapol_cb->get_bool(sm->eapol_ctx, var);
62 static void eapol_set_bool(struct eap_sm *sm, enum eapol_bool_var var,
65 sm->eapol_cb->set_bool(sm->eapol_ctx, var, value);
69 static unsigned int eapol_get_int(struct eap_sm *sm, enum eapol_int_var var)
71 return sm->eapol_cb->get_int(sm->eapol_ctx, var);
75 static void eapol_set_int(struct eap_sm *sm, enum eapol_int_var var,
78 sm->eapol_cb->set_int(sm->eapol_ctx, var, value);
82 static struct wpabuf * eapol_get_eapReqData(struct eap_sm *sm)
84 return sm->eapol_cb->get_eapReqData(sm->eapol_ctx);
88 static void eap_notify_status(struct eap_sm *sm, const char *status,
89 const char *parameter)
91 wpa_printf(MSG_DEBUG, "EAP: Status notification: %s (param=%s)",
93 if (sm->eapol_cb->notify_status)
94 sm->eapol_cb->notify_status(sm->eapol_ctx, status, parameter);
98 static void eap_report_error(struct eap_sm *sm, int error_code)
100 wpa_printf(MSG_DEBUG, "EAP: Error notification: %d", error_code);
101 if (sm->eapol_cb->notify_eap_error)
102 sm->eapol_cb->notify_eap_error(sm->eapol_ctx, error_code);
106 static void eap_sm_free_key(struct eap_sm *sm)
108 if (sm->eapKeyData) {
109 bin_clear_free(sm->eapKeyData, sm->eapKeyDataLen);
110 sm->eapKeyData = NULL;
115 static void eap_deinit_prev_method(struct eap_sm *sm, const char *txt)
117 ext_password_free(sm->ext_pw_buf);
118 sm->ext_pw_buf = NULL;
120 if (sm->m == NULL || sm->eap_method_priv == NULL)
123 wpa_printf(MSG_DEBUG, "EAP: deinitialize previously used EAP method "
124 "(%d, %s) at %s", sm->selectedMethod, sm->m->name, txt);
125 sm->m->deinit(sm, sm->eap_method_priv);
126 sm->eap_method_priv = NULL;
132 * eap_config_allowed_method - Check whether EAP method is allowed
133 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
134 * @config: EAP configuration
135 * @vendor: Vendor-Id for expanded types or 0 = IETF for legacy types
137 * Returns: 1 = allowed EAP method, 0 = not allowed
139 static int eap_config_allowed_method(struct eap_sm *sm,
140 struct eap_peer_config *config,
141 int vendor, u32 method)
144 struct eap_method_type *m;
146 if (config == NULL || config->eap_methods == NULL)
149 m = config->eap_methods;
150 for (i = 0; m[i].vendor != EAP_VENDOR_IETF ||
151 m[i].method != EAP_TYPE_NONE; i++) {
152 if (m[i].vendor == vendor && m[i].method == method)
160 * eap_allowed_method - Check whether EAP method is allowed
161 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
162 * @vendor: Vendor-Id for expanded types or 0 = IETF for legacy types
164 * Returns: 1 = allowed EAP method, 0 = not allowed
166 int eap_allowed_method(struct eap_sm *sm, int vendor, u32 method)
168 return eap_config_allowed_method(sm, eap_get_config(sm), vendor,
173 #if defined(PCSC_FUNCS) || defined(CONFIG_EAP_PROXY)
174 static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
175 size_t max_len, size_t *imsi_len,
180 if (*imsi_len + 36 > max_len) {
181 wpa_printf(MSG_WARNING, "No room for realm in IMSI buffer");
185 if (mnc_len != 2 && mnc_len != 3)
192 } else if (mnc_len == 3) {
199 pos = imsi + *imsi_len;
200 pos += os_snprintf(pos, imsi + max_len - pos,
201 "@wlan.mnc%s.mcc%c%c%c.3gppnetwork.org",
202 mnc, imsi[0], imsi[1], imsi[2]);
203 *imsi_len = pos - imsi;
207 #endif /* PCSC_FUNCS || CONFIG_EAP_PROXY */
211 * This state initializes state machine variables when the machine is
212 * activated (portEnabled = TRUE). This is also used when re-starting
213 * authentication (eapRestart == TRUE).
215 SM_STATE(EAP, INITIALIZE)
217 SM_ENTRY(EAP, INITIALIZE);
218 if (sm->fast_reauth && sm->m && sm->m->has_reauth_data &&
219 sm->m->has_reauth_data(sm, sm->eap_method_priv) &&
221 sm->last_config == eap_get_config(sm)) {
222 wpa_printf(MSG_DEBUG, "EAP: maintaining EAP method data for "
223 "fast reauthentication");
224 sm->m->deinit_for_reauth(sm, sm->eap_method_priv);
226 sm->last_config = eap_get_config(sm);
227 eap_deinit_prev_method(sm, "INITIALIZE");
229 sm->selectedMethod = EAP_TYPE_NONE;
230 sm->methodState = METHOD_NONE;
231 sm->allowNotifications = TRUE;
232 sm->decision = DECISION_FAIL;
233 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
234 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
235 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
236 eapol_set_bool(sm, EAPOL_eapFail, FALSE);
238 os_free(sm->eapSessionId);
239 sm->eapSessionId = NULL;
240 sm->eapKeyAvailable = FALSE;
241 eapol_set_bool(sm, EAPOL_eapRestart, FALSE);
242 sm->lastId = -1; /* new session - make sure this does not match with
243 * the first EAP-Packet */
245 * RFC 4137 does not reset eapResp and eapNoResp here. However, this
246 * seemed to be able to trigger cases where both were set and if EAPOL
247 * state machine uses eapNoResp first, it may end up not sending a real
248 * reply correctly. This occurred when the workaround in FAIL state set
249 * eapNoResp = TRUE.. Maybe that workaround needs to be fixed to do
252 eapol_set_bool(sm, EAPOL_eapResp, FALSE);
253 eapol_set_bool(sm, EAPOL_eapNoResp, FALSE);
255 * RFC 4137 does not reset ignore here, but since it is possible for
256 * some method code paths to end up not setting ignore=FALSE, clear the
257 * value here to avoid issues if a previous authentication attempt
258 * failed with ignore=TRUE being left behind in the last
259 * m.check(eapReqData) operation.
263 sm->prev_failure = 0;
264 sm->expected_failure = 0;
265 sm->reauthInit = FALSE;
266 sm->erp_seq = (u32) -1;
271 * This state is reached whenever service from the lower layer is interrupted
272 * or unavailable (portEnabled == FALSE). Immediate transition to INITIALIZE
273 * occurs when the port becomes enabled.
275 SM_STATE(EAP, DISABLED)
277 SM_ENTRY(EAP, DISABLED);
280 * RFC 4137 does not describe clearing of idleWhile here, but doing so
281 * allows the timer tick to be stopped more quickly when EAP is not in
284 eapol_set_int(sm, EAPOL_idleWhile, 0);
289 * The state machine spends most of its time here, waiting for something to
290 * happen. This state is entered unconditionally from INITIALIZE, DISCARD, and
291 * SEND_RESPONSE states.
300 * This state is entered when an EAP packet is received (eapReq == TRUE) to
301 * parse the packet header.
303 SM_STATE(EAP, RECEIVED)
305 const struct wpabuf *eapReqData;
307 SM_ENTRY(EAP, RECEIVED);
308 eapReqData = eapol_get_eapReqData(sm);
309 /* parse rxReq, rxSuccess, rxFailure, reqId, reqMethod */
310 eap_sm_parseEapReq(sm, eapReqData);
316 * This state is entered when a request for a new type comes in. Either the
317 * correct method is started, or a Nak response is built.
319 SM_STATE(EAP, GET_METHOD)
323 const struct eap_method *eap_method;
325 SM_ENTRY(EAP, GET_METHOD);
327 if (sm->reqMethod == EAP_TYPE_EXPANDED)
328 method = sm->reqVendorMethod;
330 method = sm->reqMethod;
332 eap_method = eap_peer_get_eap_method(sm->reqVendor, method);
334 if (!eap_sm_allowMethod(sm, sm->reqVendor, method)) {
335 wpa_printf(MSG_DEBUG, "EAP: vendor %u method %u not allowed",
336 sm->reqVendor, method);
337 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
338 "vendor=%u method=%u -> NAK",
339 sm->reqVendor, method);
340 eap_notify_status(sm, "refuse proposed method",
341 eap_method ? eap_method->name : "unknown");
345 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
346 "vendor=%u method=%u", sm->reqVendor, method);
348 eap_notify_status(sm, "accept proposed method",
349 eap_method ? eap_method->name : "unknown");
351 * RFC 4137 does not define specific operation for fast
352 * re-authentication (session resumption). The design here is to allow
353 * the previously used method data to be maintained for
354 * re-authentication if the method support session resumption.
355 * Otherwise, the previously used method data is freed and a new method
358 if (sm->fast_reauth &&
359 sm->m && sm->m->vendor == sm->reqVendor &&
360 sm->m->method == method &&
361 sm->m->has_reauth_data &&
362 sm->m->has_reauth_data(sm, sm->eap_method_priv)) {
363 wpa_printf(MSG_DEBUG, "EAP: Using previous method data"
364 " for fast re-authentication");
367 eap_deinit_prev_method(sm, "GET_METHOD");
371 sm->selectedMethod = sm->reqMethod;
375 wpa_printf(MSG_DEBUG, "EAP: Could not find selected method: "
376 "vendor %d method %d",
377 sm->reqVendor, method);
381 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
383 wpa_printf(MSG_DEBUG, "EAP: Initialize selected EAP method: "
384 "vendor %u method %u (%s)",
385 sm->reqVendor, method, sm->m->name);
387 sm->eap_method_priv = sm->m->init_for_reauth(
388 sm, sm->eap_method_priv);
390 sm->waiting_ext_cert_check = 0;
391 sm->ext_cert_check = 0;
392 sm->eap_method_priv = sm->m->init(sm);
395 if (sm->eap_method_priv == NULL) {
396 struct eap_peer_config *config = eap_get_config(sm);
397 wpa_msg(sm->msg_ctx, MSG_INFO,
398 "EAP: Failed to initialize EAP method: vendor %u "
400 sm->reqVendor, method, sm->m->name);
402 sm->methodState = METHOD_NONE;
403 sm->selectedMethod = EAP_TYPE_NONE;
404 if (sm->reqMethod == EAP_TYPE_TLS && config &&
405 (config->pending_req_pin ||
406 config->pending_req_passphrase)) {
408 * Return without generating Nak in order to allow
409 * entering of PIN code or passphrase to retry the
410 * current EAP packet.
412 wpa_printf(MSG_DEBUG, "EAP: Pending PIN/passphrase "
413 "request - skip Nak");
420 sm->methodState = METHOD_INIT;
421 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_METHOD
422 "EAP vendor %u method %u (%s) selected",
423 sm->reqVendor, method, sm->m->name);
427 wpabuf_free(sm->eapRespData);
428 sm->eapRespData = NULL;
429 sm->eapRespData = eap_sm_buildNak(sm, sm->reqId);
435 static char * eap_get_realm(struct eap_sm *sm, struct eap_peer_config *config)
443 if (config->identity) {
444 for (i = 0; i < config->identity_len; i++) {
445 if (config->identity[i] == '@')
448 if (i < config->identity_len) {
449 realm_len = config->identity_len - i - 1;
450 realm = os_malloc(realm_len + 1);
453 os_memcpy(realm, &config->identity[i + 1], realm_len);
454 realm[realm_len] = '\0';
459 if (config->anonymous_identity) {
460 for (i = 0; i < config->anonymous_identity_len; i++) {
461 if (config->anonymous_identity[i] == '@')
464 if (i < config->anonymous_identity_len) {
465 realm_len = config->anonymous_identity_len - i - 1;
466 realm = os_malloc(realm_len + 1);
469 os_memcpy(realm, &config->anonymous_identity[i + 1],
471 realm[realm_len] = '\0';
476 #ifdef CONFIG_EAP_PROXY
477 /* When identity is not provided in the config, build the realm from
478 * IMSI for eap_proxy based methods.
480 if (!config->identity && !config->anonymous_identity &&
481 sm->eapol_cb->get_imsi &&
482 (eap_config_allowed_method(sm, config, EAP_VENDOR_IETF,
484 eap_config_allowed_method(sm, config, EAP_VENDOR_IETF,
486 eap_config_allowed_method(sm, config, EAP_VENDOR_IETF,
487 EAP_TYPE_AKA_PRIME))) {
492 wpa_printf(MSG_DEBUG, "EAP: Build realm from IMSI (eap_proxy)");
493 mnc_len = sm->eapol_cb->get_imsi(sm->eapol_ctx, config->sim_num,
498 pos = imsi_len + 1; /* points to the beginning of the realm */
499 if (eap_sm_append_3gpp_realm(sm, imsi, sizeof(imsi), &imsi_len,
501 wpa_printf(MSG_WARNING, "Could not append realm");
505 realm = os_strdup(&imsi[pos]);
509 wpa_printf(MSG_DEBUG, "EAP: Generated realm '%s'", realm);
512 #endif /* CONFIG_EAP_PROXY */
518 static char * eap_home_realm(struct eap_sm *sm)
520 return eap_get_realm(sm, eap_get_config(sm));
524 static struct eap_erp_key *
525 eap_erp_get_key(struct eap_sm *sm, const char *realm)
527 struct eap_erp_key *erp;
529 dl_list_for_each(erp, &sm->erp_keys, struct eap_erp_key, list) {
532 pos = os_strchr(erp->keyname_nai, '@');
536 if (os_strcmp(pos, realm) == 0)
544 static struct eap_erp_key *
545 eap_erp_get_key_nai(struct eap_sm *sm, const char *nai)
547 struct eap_erp_key *erp;
549 dl_list_for_each(erp, &sm->erp_keys, struct eap_erp_key, list) {
550 if (os_strcmp(erp->keyname_nai, nai) == 0)
558 static void eap_peer_erp_free_key(struct eap_erp_key *erp)
560 dl_list_del(&erp->list);
561 bin_clear_free(erp, sizeof(*erp));
565 static void eap_erp_remove_keys_realm(struct eap_sm *sm, const char *realm)
567 struct eap_erp_key *erp;
569 while ((erp = eap_erp_get_key(sm, realm)) != NULL) {
570 wpa_printf(MSG_DEBUG, "EAP: Delete old ERP key %s",
572 eap_peer_erp_free_key(erp);
577 int eap_peer_update_erp_next_seq_num(struct eap_sm *sm, u16 next_seq_num)
579 struct eap_erp_key *erp;
582 home_realm = eap_home_realm(sm);
583 if (!home_realm || os_strlen(home_realm) == 0) {
588 erp = eap_erp_get_key(sm, home_realm);
590 wpa_printf(MSG_DEBUG,
591 "EAP: Failed to find ERP key for realm: %s",
597 if ((u32) next_seq_num < erp->next_seq) {
598 /* Sequence number has wrapped around, clear this ERP
599 * info and do a full auth next time.
601 eap_peer_erp_free_key(erp);
603 erp->next_seq = (u32) next_seq_num;
611 int eap_peer_get_erp_info(struct eap_sm *sm, struct eap_peer_config *config,
612 const u8 **username, size_t *username_len,
613 const u8 **realm, size_t *realm_len,
614 u16 *erp_next_seq_num, const u8 **rrk,
617 struct eap_erp_key *erp;
622 home_realm = eap_get_realm(sm, config);
624 home_realm = eap_home_realm(sm);
625 if (!home_realm || os_strlen(home_realm) == 0) {
630 erp = eap_erp_get_key(sm, home_realm);
635 if (erp->next_seq >= 65536)
636 return -1; /* SEQ has range of 0..65535 */
638 pos = os_strchr(erp->keyname_nai, '@');
640 return -1; /* this cannot really happen */
641 *username_len = pos - erp->keyname_nai;
642 *username = (u8 *) erp->keyname_nai;
645 *realm_len = os_strlen(pos);
648 *erp_next_seq_num = (u16) erp->next_seq;
650 *rrk_len = erp->rRK_len;
653 if (*username_len == 0 || *realm_len == 0 || *rrk_len == 0)
659 #endif /* CONFIG_ERP */
662 void eap_peer_erp_free_keys(struct eap_sm *sm)
665 struct eap_erp_key *erp, *tmp;
667 dl_list_for_each_safe(erp, tmp, &sm->erp_keys, struct eap_erp_key, list)
668 eap_peer_erp_free_key(erp);
669 #endif /* CONFIG_ERP */
673 /* Note: If ext_session and/or ext_emsk are passed to this function, they are
674 * expected to point to allocated memory and those allocations will be freed
675 * unconditionally. */
676 void eap_peer_erp_init(struct eap_sm *sm, u8 *ext_session_id,
677 size_t ext_session_id_len, u8 *ext_emsk,
683 u8 *session_id = NULL;
684 size_t session_id_len = 0;
685 u8 EMSKname[EAP_EMSK_NAME_LEN];
688 size_t realm_len, nai_buf_len;
689 struct eap_erp_key *erp = NULL;
692 realm = eap_home_realm(sm);
695 realm_len = os_strlen(realm);
696 wpa_printf(MSG_DEBUG, "EAP: Realm for ERP keyName-NAI: %s", realm);
697 eap_erp_remove_keys_realm(sm, realm);
699 nai_buf_len = 2 * EAP_EMSK_NAME_LEN + 1 + realm_len;
700 if (nai_buf_len > 253) {
702 * keyName-NAI has a maximum length of 253 octet to fit in
705 wpa_printf(MSG_DEBUG,
706 "EAP: Too long realm for ERP keyName-NAI maximum length");
709 nai_buf_len++; /* null termination */
710 erp = os_zalloc(sizeof(*erp) + nai_buf_len);
716 emsk_len = ext_emsk_len;
718 emsk = sm->m->get_emsk(sm, sm->eap_method_priv, &emsk_len);
721 if (!emsk || emsk_len == 0 || emsk_len > ERP_MAX_KEY_LEN) {
722 wpa_printf(MSG_DEBUG,
723 "EAP: No suitable EMSK available for ERP");
727 wpa_hexdump_key(MSG_DEBUG, "EAP: EMSK", emsk, emsk_len);
729 if (ext_session_id) {
730 session_id = ext_session_id;
731 session_id_len = ext_session_id_len;
733 session_id = sm->eapSessionId;
734 session_id_len = sm->eapSessionIdLen;
737 if (!session_id || session_id_len == 0) {
738 wpa_printf(MSG_DEBUG,
739 "EAP: No suitable session id available for ERP");
743 WPA_PUT_BE16(len, EAP_EMSK_NAME_LEN);
744 if (hmac_sha256_kdf(session_id, session_id_len, "EMSK", len,
745 sizeof(len), EMSKname, EAP_EMSK_NAME_LEN) < 0) {
746 wpa_printf(MSG_DEBUG, "EAP: Could not derive EMSKname");
749 wpa_hexdump(MSG_DEBUG, "EAP: EMSKname", EMSKname, EAP_EMSK_NAME_LEN);
751 pos = wpa_snprintf_hex(erp->keyname_nai, nai_buf_len,
752 EMSKname, EAP_EMSK_NAME_LEN);
753 erp->keyname_nai[pos] = '@';
754 os_memcpy(&erp->keyname_nai[pos + 1], realm, realm_len);
756 WPA_PUT_BE16(len, emsk_len);
757 if (hmac_sha256_kdf(emsk, emsk_len,
758 "EAP Re-authentication Root Key@ietf.org",
759 len, sizeof(len), erp->rRK, emsk_len) < 0) {
760 wpa_printf(MSG_DEBUG, "EAP: Could not derive rRK for ERP");
763 erp->rRK_len = emsk_len;
764 wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rRK", erp->rRK, erp->rRK_len);
766 ctx[0] = EAP_ERP_CS_HMAC_SHA256_128;
767 WPA_PUT_BE16(&ctx[1], erp->rRK_len);
768 if (hmac_sha256_kdf(erp->rRK, erp->rRK_len,
769 "Re-authentication Integrity Key@ietf.org",
770 ctx, sizeof(ctx), erp->rIK, erp->rRK_len) < 0) {
771 wpa_printf(MSG_DEBUG, "EAP: Could not derive rIK for ERP");
774 erp->rIK_len = erp->rRK_len;
775 wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rIK", erp->rIK, erp->rIK_len);
777 wpa_printf(MSG_DEBUG, "EAP: Stored ERP keys %s", erp->keyname_nai);
778 dl_list_add(&sm->erp_keys, &erp->list);
782 bin_clear_free(ext_emsk, ext_emsk_len);
784 bin_clear_free(emsk, emsk_len);
785 bin_clear_free(ext_session_id, ext_session_id_len);
786 bin_clear_free(erp, sizeof(*erp));
788 #endif /* CONFIG_ERP */
793 struct wpabuf * eap_peer_build_erp_reauth_start(struct eap_sm *sm, u8 eap_id)
796 struct eap_erp_key *erp;
798 u8 hash[SHA256_MAC_LEN];
800 realm = eap_home_realm(sm);
804 erp = eap_erp_get_key(sm, realm);
810 if (erp->next_seq >= 65536)
811 return NULL; /* SEQ has range of 0..65535 */
813 /* TODO: check rRK lifetime expiration */
815 wpa_printf(MSG_DEBUG, "EAP: Valid ERP key found %s (SEQ=%u)",
816 erp->keyname_nai, erp->next_seq);
818 msg = eap_msg_alloc(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
819 1 + 2 + 2 + os_strlen(erp->keyname_nai) + 1 + 16,
820 EAP_CODE_INITIATE, eap_id);
824 wpabuf_put_u8(msg, 0x20); /* Flags: R=0 B=0 L=1 */
825 wpabuf_put_be16(msg, erp->next_seq);
827 wpabuf_put_u8(msg, EAP_ERP_TLV_KEYNAME_NAI);
828 wpabuf_put_u8(msg, os_strlen(erp->keyname_nai));
829 wpabuf_put_str(msg, erp->keyname_nai);
831 wpabuf_put_u8(msg, EAP_ERP_CS_HMAC_SHA256_128); /* Cryptosuite */
833 if (hmac_sha256(erp->rIK, erp->rIK_len,
834 wpabuf_head(msg), wpabuf_len(msg), hash) < 0) {
838 wpabuf_put_data(msg, hash, 16);
840 sm->erp_seq = erp->next_seq;
843 wpa_hexdump_buf(MSG_DEBUG, "ERP: EAP-Initiate/Re-auth", msg);
849 static int eap_peer_erp_reauth_start(struct eap_sm *sm, u8 eap_id)
853 msg = eap_peer_build_erp_reauth_start(sm, eap_id);
857 wpa_printf(MSG_DEBUG, "EAP: Sending EAP-Initiate/Re-auth");
858 wpabuf_free(sm->eapRespData);
859 sm->eapRespData = msg;
860 sm->reauthInit = TRUE;
863 #endif /* CONFIG_ERP */
867 * The method processing happens here. The request from the authenticator is
868 * processed, and an appropriate response packet is built.
870 SM_STATE(EAP, METHOD)
872 struct wpabuf *eapReqData;
873 struct eap_method_ret ret;
876 SM_ENTRY(EAP, METHOD);
878 wpa_printf(MSG_WARNING, "EAP::METHOD - method not selected");
882 eapReqData = eapol_get_eapReqData(sm);
883 if (sm->m->vendor == EAP_VENDOR_IETF && sm->m->method == EAP_TYPE_LEAP)
884 min_len = 0; /* LEAP uses EAP-Success without payload */
885 if (!eap_hdr_len_valid(eapReqData, min_len))
889 * Get ignore, methodState, decision, allowNotifications, and
890 * eapRespData. RFC 4137 uses three separate method procedure (check,
891 * process, and buildResp) in this state. These have been combined into
892 * a single function call to m->process() in order to optimize EAP
893 * method implementation interface a bit. These procedures are only
894 * used from within this METHOD state, so there is no need to keep
895 * these as separate C functions.
897 * The RFC 4137 procedures return values as follows:
898 * ignore = m.check(eapReqData)
899 * (methodState, decision, allowNotifications) = m.process(eapReqData)
900 * eapRespData = m.buildResp(reqId)
902 os_memset(&ret, 0, sizeof(ret));
903 ret.ignore = sm->ignore;
904 ret.methodState = sm->methodState;
905 ret.decision = sm->decision;
906 ret.allowNotifications = sm->allowNotifications;
907 wpabuf_free(sm->eapRespData);
908 sm->eapRespData = NULL;
909 sm->eapRespData = sm->m->process(sm, sm->eap_method_priv, &ret,
911 wpa_printf(MSG_DEBUG, "EAP: method process -> ignore=%s "
912 "methodState=%s decision=%s eapRespData=%p",
913 ret.ignore ? "TRUE" : "FALSE",
914 eap_sm_method_state_txt(ret.methodState),
915 eap_sm_decision_txt(ret.decision),
918 sm->ignore = ret.ignore;
921 sm->methodState = ret.methodState;
922 sm->decision = ret.decision;
923 sm->allowNotifications = ret.allowNotifications;
925 if (sm->m->isKeyAvailable && sm->m->getKey &&
926 sm->m->isKeyAvailable(sm, sm->eap_method_priv)) {
928 sm->eapKeyData = sm->m->getKey(sm, sm->eap_method_priv,
930 os_free(sm->eapSessionId);
931 sm->eapSessionId = NULL;
932 if (sm->m->getSessionId) {
933 sm->eapSessionId = sm->m->getSessionId(
934 sm, sm->eap_method_priv,
935 &sm->eapSessionIdLen);
936 wpa_hexdump(MSG_DEBUG, "EAP: Session-Id",
937 sm->eapSessionId, sm->eapSessionIdLen);
944 * This state signals the lower layer that a response packet is ready to be
947 SM_STATE(EAP, SEND_RESPONSE)
949 SM_ENTRY(EAP, SEND_RESPONSE);
950 wpabuf_free(sm->lastRespData);
951 if (sm->eapRespData) {
953 os_memcpy(sm->last_sha1, sm->req_sha1, 20);
954 sm->lastId = sm->reqId;
955 sm->lastRespData = wpabuf_dup(sm->eapRespData);
956 eapol_set_bool(sm, EAPOL_eapResp, TRUE);
958 wpa_printf(MSG_DEBUG, "EAP: No eapRespData available");
959 sm->lastRespData = NULL;
961 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
962 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
963 sm->reauthInit = FALSE;
968 * This state signals the lower layer that the request was discarded, and no
969 * response packet will be sent at this time.
971 SM_STATE(EAP, DISCARD)
973 SM_ENTRY(EAP, DISCARD);
974 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
975 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
980 * Handles requests for Identity method and builds a response.
982 SM_STATE(EAP, IDENTITY)
984 const struct wpabuf *eapReqData;
986 SM_ENTRY(EAP, IDENTITY);
987 eapReqData = eapol_get_eapReqData(sm);
988 if (!eap_hdr_len_valid(eapReqData, 1))
990 eap_sm_processIdentity(sm, eapReqData);
991 wpabuf_free(sm->eapRespData);
992 sm->eapRespData = NULL;
993 sm->eapRespData = eap_sm_buildIdentity(sm, sm->reqId, 0);
998 * Handles requests for Notification method and builds a response.
1000 SM_STATE(EAP, NOTIFICATION)
1002 const struct wpabuf *eapReqData;
1004 SM_ENTRY(EAP, NOTIFICATION);
1005 eapReqData = eapol_get_eapReqData(sm);
1006 if (!eap_hdr_len_valid(eapReqData, 1))
1008 eap_sm_processNotify(sm, eapReqData);
1009 wpabuf_free(sm->eapRespData);
1010 sm->eapRespData = NULL;
1011 sm->eapRespData = eap_sm_buildNotify(sm->reqId);
1016 * This state retransmits the previous response packet.
1018 SM_STATE(EAP, RETRANSMIT)
1020 SM_ENTRY(EAP, RETRANSMIT);
1021 wpabuf_free(sm->eapRespData);
1022 if (sm->lastRespData)
1023 sm->eapRespData = wpabuf_dup(sm->lastRespData);
1025 sm->eapRespData = NULL;
1030 * This state is entered in case of a successful completion of authentication
1031 * and state machine waits here until port is disabled or EAP authentication is
1034 SM_STATE(EAP, SUCCESS)
1036 struct eap_peer_config *config = eap_get_config(sm);
1038 SM_ENTRY(EAP, SUCCESS);
1039 if (sm->eapKeyData != NULL)
1040 sm->eapKeyAvailable = TRUE;
1041 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
1044 * RFC 4137 does not clear eapReq here, but this seems to be required
1045 * to avoid processing the same request twice when state machine is
1048 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
1051 * RFC 4137 does not set eapNoResp here, but this seems to be required
1052 * to get EAPOL Supplicant backend state machine into SUCCESS state. In
1053 * addition, either eapResp or eapNoResp is required to be set after
1054 * processing the received EAP frame.
1056 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
1058 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
1059 "EAP authentication completed successfully");
1061 if (config->erp && sm->m->get_emsk && sm->eapSessionId &&
1062 sm->m->isKeyAvailable &&
1063 sm->m->isKeyAvailable(sm, sm->eap_method_priv))
1064 eap_peer_erp_init(sm, NULL, 0, NULL, 0);
1069 * This state is entered in case of a failure and state machine waits here
1070 * until port is disabled or EAP authentication is restarted.
1072 SM_STATE(EAP, FAILURE)
1074 SM_ENTRY(EAP, FAILURE);
1075 eapol_set_bool(sm, EAPOL_eapFail, TRUE);
1078 * RFC 4137 does not clear eapReq here, but this seems to be required
1079 * to avoid processing the same request twice when state machine is
1082 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
1085 * RFC 4137 does not set eapNoResp here. However, either eapResp or
1086 * eapNoResp is required to be set after processing the received EAP
1089 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
1091 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
1092 "EAP authentication failed");
1094 sm->prev_failure = 1;
1098 static int eap_success_workaround(struct eap_sm *sm, int reqId, int lastId)
1101 * At least Microsoft IAS and Meetinghouse Aegis seem to be sending
1102 * EAP-Success/Failure with lastId + 1 even though RFC 3748 and
1103 * RFC 4137 require that reqId == lastId. In addition, it looks like
1104 * Ringmaster v2.1.2.0 would be using lastId + 2 in EAP-Success.
1106 * Accept this kind of Id if EAP workarounds are enabled. These are
1107 * unauthenticated plaintext messages, so this should have minimal
1108 * security implications (bit easier to fake EAP-Success/Failure).
1110 if (sm->workaround && (reqId == ((lastId + 1) & 0xff) ||
1111 reqId == ((lastId + 2) & 0xff))) {
1112 wpa_printf(MSG_DEBUG, "EAP: Workaround for unexpected "
1113 "identifier field in EAP Success: "
1114 "reqId=%d lastId=%d (these are supposed to be "
1115 "same)", reqId, lastId);
1118 wpa_printf(MSG_DEBUG, "EAP: EAP-Success Id mismatch - reqId=%d "
1119 "lastId=%d", reqId, lastId);
1125 * RFC 4137 - Appendix A.1: EAP Peer State Machine - State transitions
1128 static void eap_peer_sm_step_idle(struct eap_sm *sm)
1131 * The first three transitions are from RFC 4137. The last two are
1132 * local additions to handle special cases with LEAP and PEAP server
1133 * not sending EAP-Success in some cases.
1135 if (eapol_get_bool(sm, EAPOL_eapReq))
1136 SM_ENTER(EAP, RECEIVED);
1137 else if ((eapol_get_bool(sm, EAPOL_altAccept) &&
1138 sm->decision != DECISION_FAIL) ||
1139 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
1140 sm->decision == DECISION_UNCOND_SUCC))
1141 SM_ENTER(EAP, SUCCESS);
1142 else if (eapol_get_bool(sm, EAPOL_altReject) ||
1143 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
1144 sm->decision != DECISION_UNCOND_SUCC) ||
1145 (eapol_get_bool(sm, EAPOL_altAccept) &&
1146 sm->methodState != METHOD_CONT &&
1147 sm->decision == DECISION_FAIL))
1148 SM_ENTER(EAP, FAILURE);
1149 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
1150 sm->leap_done && sm->decision != DECISION_FAIL &&
1151 sm->methodState == METHOD_DONE)
1152 SM_ENTER(EAP, SUCCESS);
1153 else if (sm->selectedMethod == EAP_TYPE_PEAP &&
1154 sm->peap_done && sm->decision != DECISION_FAIL &&
1155 sm->methodState == METHOD_DONE)
1156 SM_ENTER(EAP, SUCCESS);
1160 static int eap_peer_req_is_duplicate(struct eap_sm *sm)
1164 duplicate = (sm->reqId == sm->lastId) && sm->rxReq;
1165 if (sm->workaround && duplicate &&
1166 os_memcmp(sm->req_sha1, sm->last_sha1, 20) != 0) {
1168 * RFC 4137 uses (reqId == lastId) as the only verification for
1169 * duplicate EAP requests. However, this misses cases where the
1170 * AS is incorrectly using the same id again; and
1171 * unfortunately, such implementations exist. Use SHA1 hash as
1172 * an extra verification for the packets being duplicate to
1173 * workaround these issues.
1175 wpa_printf(MSG_DEBUG, "EAP: AS used the same Id again, but "
1176 "EAP packets were not identical");
1177 wpa_printf(MSG_DEBUG, "EAP: workaround - assume this is not a "
1178 "duplicate packet");
1186 static int eap_peer_sm_allow_canned(struct eap_sm *sm)
1188 struct eap_peer_config *config = eap_get_config(sm);
1190 return config && config->phase1 &&
1191 os_strstr(config->phase1, "allow_canned_success=1");
1195 static void eap_peer_sm_step_received(struct eap_sm *sm)
1197 int duplicate = eap_peer_req_is_duplicate(sm);
1200 * Two special cases below for LEAP are local additions to work around
1201 * odd LEAP behavior (EAP-Success in the middle of authentication and
1202 * then swapped roles). Other transitions are based on RFC 4137.
1204 if (sm->rxSuccess && sm->decision != DECISION_FAIL &&
1205 (sm->reqId == sm->lastId ||
1206 eap_success_workaround(sm, sm->reqId, sm->lastId)))
1207 SM_ENTER(EAP, SUCCESS);
1208 else if (sm->workaround && sm->lastId == -1 && sm->rxSuccess &&
1209 !sm->rxFailure && !sm->rxReq && eap_peer_sm_allow_canned(sm))
1210 SM_ENTER(EAP, SUCCESS); /* EAP-Success prior any EAP method */
1211 else if (sm->workaround && sm->lastId == -1 && sm->rxFailure &&
1212 !sm->rxReq && sm->methodState != METHOD_CONT &&
1213 eap_peer_sm_allow_canned(sm))
1214 SM_ENTER(EAP, FAILURE); /* EAP-Failure prior any EAP method */
1215 else if (sm->workaround && sm->rxSuccess && !sm->rxFailure &&
1216 !sm->rxReq && sm->methodState != METHOD_CONT &&
1217 eap_peer_sm_allow_canned(sm))
1218 SM_ENTER(EAP, SUCCESS); /* EAP-Success after Identity */
1219 else if (sm->methodState != METHOD_CONT &&
1221 sm->decision != DECISION_UNCOND_SUCC) ||
1222 (sm->rxSuccess && sm->decision == DECISION_FAIL &&
1223 (sm->selectedMethod != EAP_TYPE_LEAP ||
1224 sm->methodState != METHOD_MAY_CONT))) &&
1225 (sm->reqId == sm->lastId ||
1226 eap_success_workaround(sm, sm->reqId, sm->lastId)))
1227 SM_ENTER(EAP, FAILURE);
1228 else if (sm->rxReq && duplicate)
1229 SM_ENTER(EAP, RETRANSMIT);
1230 else if (sm->rxReq && !duplicate &&
1231 sm->reqMethod == EAP_TYPE_NOTIFICATION &&
1232 sm->allowNotifications)
1233 SM_ENTER(EAP, NOTIFICATION);
1234 else if (sm->rxReq && !duplicate &&
1235 sm->selectedMethod == EAP_TYPE_NONE &&
1236 sm->reqMethod == EAP_TYPE_IDENTITY)
1237 SM_ENTER(EAP, IDENTITY);
1238 else if (sm->rxReq && !duplicate &&
1239 sm->selectedMethod == EAP_TYPE_NONE &&
1240 sm->reqMethod != EAP_TYPE_IDENTITY &&
1241 sm->reqMethod != EAP_TYPE_NOTIFICATION)
1242 SM_ENTER(EAP, GET_METHOD);
1243 else if (sm->rxReq && !duplicate &&
1244 sm->reqMethod == sm->selectedMethod &&
1245 sm->methodState != METHOD_DONE)
1246 SM_ENTER(EAP, METHOD);
1247 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
1248 (sm->rxSuccess || sm->rxResp))
1249 SM_ENTER(EAP, METHOD);
1250 else if (sm->reauthInit)
1251 SM_ENTER(EAP, SEND_RESPONSE);
1253 SM_ENTER(EAP, DISCARD);
1257 static void eap_peer_sm_step_local(struct eap_sm *sm)
1259 switch (sm->EAP_state) {
1260 case EAP_INITIALIZE:
1261 SM_ENTER(EAP, IDLE);
1264 if (eapol_get_bool(sm, EAPOL_portEnabled) &&
1265 !sm->force_disabled)
1266 SM_ENTER(EAP, INITIALIZE);
1269 eap_peer_sm_step_idle(sm);
1272 eap_peer_sm_step_received(sm);
1274 case EAP_GET_METHOD:
1275 if (sm->selectedMethod == sm->reqMethod)
1276 SM_ENTER(EAP, METHOD);
1278 SM_ENTER(EAP, SEND_RESPONSE);
1282 * Note: RFC 4137 uses methodState == DONE && decision == FAIL
1283 * as the condition. eapRespData == NULL here is used to allow
1284 * final EAP method response to be sent without having to change
1285 * all methods to either use methodState MAY_CONT or leaving
1286 * decision to something else than FAIL in cases where the only
1287 * expected response is EAP-Failure.
1290 SM_ENTER(EAP, DISCARD);
1291 else if (sm->methodState == METHOD_DONE &&
1292 sm->decision == DECISION_FAIL && !sm->eapRespData)
1293 SM_ENTER(EAP, FAILURE);
1295 SM_ENTER(EAP, SEND_RESPONSE);
1297 case EAP_SEND_RESPONSE:
1298 SM_ENTER(EAP, IDLE);
1301 SM_ENTER(EAP, IDLE);
1304 SM_ENTER(EAP, SEND_RESPONSE);
1306 case EAP_NOTIFICATION:
1307 SM_ENTER(EAP, SEND_RESPONSE);
1309 case EAP_RETRANSMIT:
1310 SM_ENTER(EAP, SEND_RESPONSE);
1322 /* Global transitions */
1323 if (eapol_get_bool(sm, EAPOL_eapRestart) &&
1324 eapol_get_bool(sm, EAPOL_portEnabled))
1325 SM_ENTER_GLOBAL(EAP, INITIALIZE);
1326 else if (!eapol_get_bool(sm, EAPOL_portEnabled) || sm->force_disabled)
1327 SM_ENTER_GLOBAL(EAP, DISABLED);
1328 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
1329 /* RFC 4137 does not place any limit on number of EAP messages
1330 * in an authentication session. However, some error cases have
1331 * ended up in a state were EAP messages were sent between the
1332 * peer and server in a loop (e.g., TLS ACK frame in both
1333 * direction). Since this is quite undesired outcome, limit the
1334 * total number of EAP round-trips and abort authentication if
1335 * this limit is exceeded.
1337 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
1338 wpa_msg(sm->msg_ctx, MSG_INFO, "EAP: more than %d "
1339 "authentication rounds - abort",
1340 EAP_MAX_AUTH_ROUNDS);
1342 SM_ENTER_GLOBAL(EAP, FAILURE);
1345 /* Local transitions */
1346 eap_peer_sm_step_local(sm);
1351 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
1354 if (!eap_allowed_method(sm, vendor, method)) {
1355 wpa_printf(MSG_DEBUG, "EAP: configuration does not allow: "
1356 "vendor %u method %u", vendor, method);
1359 if (eap_peer_get_eap_method(vendor, method))
1361 wpa_printf(MSG_DEBUG, "EAP: not included in build: "
1362 "vendor %u method %u", vendor, method);
1367 static struct wpabuf * eap_sm_build_expanded_nak(
1368 struct eap_sm *sm, int id, const struct eap_method *methods,
1371 struct wpabuf *resp;
1373 const struct eap_method *m;
1375 wpa_printf(MSG_DEBUG, "EAP: Building expanded EAP-Nak");
1377 /* RFC 3748 - 5.3.2: Expanded Nak */
1378 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_EXPANDED,
1379 8 + 8 * (count + 1), EAP_CODE_RESPONSE, id);
1383 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
1384 wpabuf_put_be32(resp, EAP_TYPE_NAK);
1386 for (m = methods; m; m = m->next) {
1387 if (sm->reqVendor == m->vendor &&
1388 sm->reqVendorMethod == m->method)
1389 continue; /* do not allow the current method again */
1390 if (eap_allowed_method(sm, m->vendor, m->method)) {
1391 wpa_printf(MSG_DEBUG, "EAP: allowed type: "
1392 "vendor=%u method=%u",
1393 m->vendor, m->method);
1394 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
1395 wpabuf_put_be24(resp, m->vendor);
1396 wpabuf_put_be32(resp, m->method);
1402 wpa_printf(MSG_DEBUG, "EAP: no more allowed methods");
1403 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
1404 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
1405 wpabuf_put_be32(resp, EAP_TYPE_NONE);
1408 eap_update_len(resp);
1414 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id)
1416 struct wpabuf *resp;
1418 int found = 0, expanded_found = 0;
1420 const struct eap_method *methods, *m;
1422 wpa_printf(MSG_DEBUG, "EAP: Building EAP-Nak (requested type %u "
1423 "vendor=%u method=%u not allowed)", sm->reqMethod,
1424 sm->reqVendor, sm->reqVendorMethod);
1425 methods = eap_peer_get_methods(&count);
1426 if (methods == NULL)
1428 if (sm->reqMethod == EAP_TYPE_EXPANDED)
1429 return eap_sm_build_expanded_nak(sm, id, methods, count);
1431 /* RFC 3748 - 5.3.1: Legacy Nak */
1432 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NAK,
1433 sizeof(struct eap_hdr) + 1 + count + 1,
1434 EAP_CODE_RESPONSE, id);
1438 start = wpabuf_put(resp, 0);
1439 for (m = methods; m; m = m->next) {
1440 if (m->vendor == EAP_VENDOR_IETF && m->method == sm->reqMethod)
1441 continue; /* do not allow the current method again */
1442 if (eap_allowed_method(sm, m->vendor, m->method)) {
1443 if (m->vendor != EAP_VENDOR_IETF) {
1447 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
1449 wpabuf_put_u8(resp, m->method);
1454 wpabuf_put_u8(resp, EAP_TYPE_NONE);
1455 wpa_hexdump(MSG_DEBUG, "EAP: allowed methods", start, found);
1457 eap_update_len(resp);
1463 static void eap_sm_processIdentity(struct eap_sm *sm, const struct wpabuf *req)
1468 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
1469 "EAP authentication started");
1470 eap_notify_status(sm, "started", "");
1472 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req,
1478 * RFC 3748 - 5.1: Identity
1479 * Data field may contain a displayable message in UTF-8. If this
1480 * includes NUL-character, only the data before that should be
1481 * displayed. Some EAP implementasitons may piggy-back additional
1482 * options after the NUL.
1484 /* TODO: could save displayable message so that it can be shown to the
1485 * user in case of interaction is required */
1486 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Identity data",
1494 * Rules for figuring out MNC length based on IMSI for SIM cards that do not
1495 * include MNC length field.
1497 static int mnc_len_from_imsi(const char *imsi)
1502 os_memcpy(mcc_str, imsi, 3);
1504 mcc = atoi(mcc_str);
1507 return 2; /* Networks in Switzerland use 2-digit MNC */
1509 return 2; /* Networks in Finland use 2-digit MNC */
1515 static int eap_sm_imsi_identity(struct eap_sm *sm,
1516 struct eap_peer_config *conf)
1518 enum { EAP_SM_SIM, EAP_SM_AKA, EAP_SM_AKA_PRIME } method = EAP_SM_SIM;
1521 struct eap_method_type *m = conf->eap_methods;
1524 imsi_len = sizeof(imsi);
1525 if (scard_get_imsi(sm->scard_ctx, imsi, &imsi_len)) {
1526 wpa_printf(MSG_WARNING, "Failed to get IMSI from SIM");
1530 wpa_hexdump_ascii(MSG_DEBUG, "IMSI", (u8 *) imsi, imsi_len);
1533 wpa_printf(MSG_WARNING, "Too short IMSI for SIM identity");
1537 /* MNC (2 or 3 digits) */
1538 mnc_len = scard_get_mnc_len(sm->scard_ctx);
1540 mnc_len = mnc_len_from_imsi(imsi);
1542 wpa_printf(MSG_INFO, "Failed to get MNC length from (U)SIM "
1547 if (eap_sm_append_3gpp_realm(sm, imsi, sizeof(imsi), &imsi_len,
1549 wpa_printf(MSG_WARNING, "Could not add realm to SIM identity");
1552 wpa_hexdump_ascii(MSG_DEBUG, "IMSI + realm", (u8 *) imsi, imsi_len);
1554 for (i = 0; m && (m[i].vendor != EAP_VENDOR_IETF ||
1555 m[i].method != EAP_TYPE_NONE); i++) {
1556 if (m[i].vendor == EAP_VENDOR_IETF &&
1557 m[i].method == EAP_TYPE_AKA_PRIME) {
1558 method = EAP_SM_AKA_PRIME;
1562 if (m[i].vendor == EAP_VENDOR_IETF &&
1563 m[i].method == EAP_TYPE_AKA) {
1564 method = EAP_SM_AKA;
1569 os_free(conf->identity);
1570 conf->identity = os_malloc(1 + imsi_len);
1571 if (conf->identity == NULL) {
1572 wpa_printf(MSG_WARNING, "Failed to allocate buffer for "
1573 "IMSI-based identity");
1579 conf->identity[0] = '1';
1582 conf->identity[0] = '0';
1584 case EAP_SM_AKA_PRIME:
1585 conf->identity[0] = '6';
1588 os_memcpy(conf->identity + 1, imsi, imsi_len);
1589 conf->identity_len = 1 + imsi_len;
1595 static int eap_sm_set_scard_pin(struct eap_sm *sm,
1596 struct eap_peer_config *conf)
1598 if (scard_set_pin(sm->scard_ctx, conf->pin)) {
1600 * Make sure the same PIN is not tried again in order to avoid
1606 wpa_printf(MSG_WARNING, "PIN validation failed");
1607 eap_sm_request_pin(sm);
1614 static int eap_sm_get_scard_identity(struct eap_sm *sm,
1615 struct eap_peer_config *conf)
1617 if (eap_sm_set_scard_pin(sm, conf))
1620 return eap_sm_imsi_identity(sm, conf);
1623 #endif /* PCSC_FUNCS */
1627 * eap_sm_buildIdentity - Build EAP-Identity/Response for the current network
1628 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1629 * @id: EAP identifier for the packet
1630 * @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
1631 * Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
1634 * This function allocates and builds an EAP-Identity/Response packet for the
1635 * current network. The caller is responsible for freeing the returned data.
1637 struct wpabuf * eap_sm_buildIdentity(struct eap_sm *sm, int id, int encrypted)
1639 struct eap_peer_config *config = eap_get_config(sm);
1640 struct wpabuf *resp;
1642 size_t identity_len;
1644 if (config == NULL) {
1645 wpa_printf(MSG_WARNING, "EAP: buildIdentity: configuration "
1646 "was not available");
1650 if (sm->m && sm->m->get_identity &&
1651 (identity = sm->m->get_identity(sm, sm->eap_method_priv,
1652 &identity_len)) != NULL) {
1653 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using method re-auth "
1654 "identity", identity, identity_len);
1655 } else if (!encrypted && config->anonymous_identity) {
1656 identity = config->anonymous_identity;
1657 identity_len = config->anonymous_identity_len;
1658 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using anonymous identity",
1659 identity, identity_len);
1661 identity = config->identity;
1662 identity_len = config->identity_len;
1663 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using real identity",
1664 identity, identity_len);
1670 if (eap_sm_get_scard_identity(sm, config) < 0)
1672 identity = config->identity;
1673 identity_len = config->identity_len;
1674 wpa_hexdump_ascii(MSG_DEBUG,
1675 "permanent identity from IMSI",
1676 identity, identity_len);
1677 } else if (eap_sm_set_scard_pin(sm, config) < 0) {
1680 #else /* PCSC_FUNCS */
1682 #endif /* PCSC_FUNCS */
1683 } else if (!identity) {
1684 wpa_printf(MSG_WARNING,
1685 "EAP: buildIdentity: identity configuration was not available");
1686 eap_sm_request_identity(sm);
1690 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, identity_len,
1691 EAP_CODE_RESPONSE, id);
1695 wpabuf_put_data(resp, identity, identity_len);
1701 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req)
1707 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, req,
1711 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Notification data",
1714 msg = os_malloc(msg_len + 1);
1717 for (i = 0; i < msg_len; i++)
1718 msg[i] = isprint(pos[i]) ? (char) pos[i] : '_';
1719 msg[msg_len] = '\0';
1720 wpa_msg(sm->msg_ctx, MSG_INFO, "%s%s",
1721 WPA_EVENT_EAP_NOTIFICATION, msg);
1726 static struct wpabuf * eap_sm_buildNotify(int id)
1728 wpa_printf(MSG_DEBUG, "EAP: Generating EAP-Response Notification");
1729 return eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, 0,
1730 EAP_CODE_RESPONSE, id);
1734 static void eap_peer_initiate(struct eap_sm *sm, const struct eap_hdr *hdr,
1738 const u8 *pos = (const u8 *) (hdr + 1);
1739 const u8 *end = ((const u8 *) hdr) + len;
1740 struct erp_tlvs parse;
1742 if (len < sizeof(*hdr) + 1) {
1743 wpa_printf(MSG_DEBUG, "EAP: Ignored too short EAP-Initiate");
1747 if (*pos != EAP_ERP_TYPE_REAUTH_START) {
1748 wpa_printf(MSG_DEBUG,
1749 "EAP: Ignored unexpected EAP-Initiate Type=%u",
1756 wpa_printf(MSG_DEBUG,
1757 "EAP: Too short EAP-Initiate/Re-auth-Start");
1760 pos++; /* Reserved */
1761 wpa_hexdump(MSG_DEBUG, "EAP: EAP-Initiate/Re-auth-Start TVs/TLVs",
1764 if (erp_parse_tlvs(pos, end, &parse, 0) < 0)
1768 wpa_hexdump_ascii(MSG_DEBUG,
1769 "EAP: EAP-Initiate/Re-auth-Start - Domain name",
1770 parse.domain, parse.domain_len);
1771 /* TODO: Derivation of domain specific keys for local ER */
1774 if (eap_peer_erp_reauth_start(sm, hdr->identifier) == 0)
1778 #endif /* CONFIG_ERP */
1779 wpa_printf(MSG_DEBUG,
1780 "EAP: EAP-Initiate/Re-auth-Start - No suitable ERP keys available - try to start full EAP authentication");
1781 eapol_set_bool(sm, EAPOL_eapTriggerStart, TRUE);
1785 void eap_peer_finish(struct eap_sm *sm, const struct eap_hdr *hdr, size_t len)
1788 const u8 *pos = (const u8 *) (hdr + 1);
1789 const u8 *end = ((const u8 *) hdr) + len;
1791 struct erp_tlvs parse;
1794 u8 hash[SHA256_MAC_LEN];
1796 struct eap_erp_key *erp;
1800 int auth_tag_ok = 0;
1802 if (len < sizeof(*hdr) + 1) {
1803 wpa_printf(MSG_DEBUG, "EAP: Ignored too short EAP-Finish");
1807 if (*pos != EAP_ERP_TYPE_REAUTH) {
1808 wpa_printf(MSG_DEBUG,
1809 "EAP: Ignored unexpected EAP-Finish Type=%u", *pos);
1813 if (len < sizeof(*hdr) + 4) {
1814 wpa_printf(MSG_DEBUG,
1815 "EAP: Ignored too short EAP-Finish/Re-auth");
1821 seq = WPA_GET_BE16(pos);
1823 wpa_printf(MSG_DEBUG, "EAP: Flags=0x%x SEQ=%u", flags, seq);
1825 if (seq != sm->erp_seq) {
1826 wpa_printf(MSG_DEBUG,
1827 "EAP: Unexpected EAP-Finish/Re-auth SEQ=%u", seq);
1832 * Parse TVs/TLVs. Since we do not yet know the length of the
1833 * Authentication Tag, stop parsing if an unknown TV/TLV is seen and
1834 * just try to find the keyName-NAI first so that we can check the
1835 * Authentication Tag.
1837 if (erp_parse_tlvs(pos, end, &parse, 1) < 0)
1840 if (!parse.keyname) {
1841 wpa_printf(MSG_DEBUG,
1842 "EAP: No keyName-NAI in EAP-Finish/Re-auth Packet");
1846 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Finish/Re-auth - keyName-NAI",
1847 parse.keyname, parse.keyname_len);
1848 if (parse.keyname_len > 253) {
1849 wpa_printf(MSG_DEBUG,
1850 "EAP: Too long keyName-NAI in EAP-Finish/Re-auth");
1853 os_memcpy(nai, parse.keyname, parse.keyname_len);
1854 nai[parse.keyname_len] = '\0';
1856 erp = eap_erp_get_key_nai(sm, nai);
1858 wpa_printf(MSG_DEBUG, "EAP: No matching ERP key found for %s",
1863 /* Is there enough room for Cryptosuite and Authentication Tag? */
1864 start = parse.keyname + parse.keyname_len;
1865 max_len = end - start;
1867 if (max_len < 1 + (int) hash_len) {
1868 wpa_printf(MSG_DEBUG,
1869 "EAP: Not enough room for Authentication Tag");
1874 if (end[-17] != EAP_ERP_CS_HMAC_SHA256_128) {
1875 wpa_printf(MSG_DEBUG, "EAP: Different Cryptosuite used");
1881 if (hmac_sha256(erp->rIK, erp->rIK_len, (const u8 *) hdr,
1882 end - ((const u8 *) hdr) - hash_len, hash) < 0)
1884 if (os_memcmp(end - hash_len, hash, hash_len) != 0) {
1885 wpa_printf(MSG_DEBUG,
1886 "EAP: Authentication Tag mismatch");
1890 end -= 1 + hash_len;
1894 * Parse TVs/TLVs again now that we know the exact part of the buffer
1895 * that contains them.
1897 wpa_hexdump(MSG_DEBUG, "EAP: EAP-Finish/Re-Auth TVs/TLVs",
1899 if (erp_parse_tlvs(pos, end, &parse, 0) < 0)
1902 if (flags & 0x80 || !auth_tag_ok) {
1903 wpa_printf(MSG_DEBUG,
1904 "EAP: EAP-Finish/Re-auth indicated failure");
1905 eapol_set_bool(sm, EAPOL_eapFail, TRUE);
1906 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
1907 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
1908 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
1909 "EAP authentication failed");
1910 sm->prev_failure = 1;
1911 wpa_printf(MSG_DEBUG,
1912 "EAP: Drop ERP key to try full authentication on next attempt");
1913 eap_peer_erp_free_key(erp);
1917 eap_sm_free_key(sm);
1918 sm->eapKeyDataLen = 0;
1919 sm->eapKeyData = os_malloc(erp->rRK_len);
1920 if (!sm->eapKeyData)
1922 sm->eapKeyDataLen = erp->rRK_len;
1924 WPA_PUT_BE16(seed, seq);
1925 WPA_PUT_BE16(&seed[2], erp->rRK_len);
1926 if (hmac_sha256_kdf(erp->rRK, erp->rRK_len,
1927 "Re-authentication Master Session Key@ietf.org",
1929 sm->eapKeyData, erp->rRK_len) < 0) {
1930 wpa_printf(MSG_DEBUG, "EAP: Could not derive rMSK for ERP");
1931 eap_sm_free_key(sm);
1934 wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rMSK",
1935 sm->eapKeyData, sm->eapKeyDataLen);
1936 sm->eapKeyAvailable = TRUE;
1937 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
1938 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
1939 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
1940 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
1941 "EAP re-authentication completed successfully");
1942 #endif /* CONFIG_ERP */
1946 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req)
1948 const struct eap_hdr *hdr;
1952 sm->rxReq = sm->rxResp = sm->rxSuccess = sm->rxFailure = FALSE;
1954 sm->reqMethod = EAP_TYPE_NONE;
1955 sm->reqVendor = EAP_VENDOR_IETF;
1956 sm->reqVendorMethod = EAP_TYPE_NONE;
1958 if (req == NULL || wpabuf_len(req) < sizeof(*hdr))
1961 hdr = wpabuf_head(req);
1962 plen = be_to_host16(hdr->length);
1963 if (plen > wpabuf_len(req)) {
1964 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
1965 "(len=%lu plen=%lu)",
1966 (unsigned long) wpabuf_len(req),
1967 (unsigned long) plen);
1971 sm->reqId = hdr->identifier;
1973 if (sm->workaround) {
1975 addr[0] = wpabuf_head(req);
1976 sha1_vector(1, addr, &plen, sm->req_sha1);
1979 switch (hdr->code) {
1980 case EAP_CODE_REQUEST:
1981 if (plen < sizeof(*hdr) + 1) {
1982 wpa_printf(MSG_DEBUG, "EAP: Too short EAP-Request - "
1987 pos = (const u8 *) (hdr + 1);
1988 sm->reqMethod = *pos++;
1989 if (sm->reqMethod == EAP_TYPE_EXPANDED) {
1990 if (plen < sizeof(*hdr) + 8) {
1991 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
1992 "expanded EAP-Packet (plen=%lu)",
1993 (unsigned long) plen);
1996 sm->reqVendor = WPA_GET_BE24(pos);
1998 sm->reqVendorMethod = WPA_GET_BE32(pos);
2000 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Request id=%d "
2001 "method=%u vendor=%u vendorMethod=%u",
2002 sm->reqId, sm->reqMethod, sm->reqVendor,
2003 sm->reqVendorMethod);
2005 case EAP_CODE_RESPONSE:
2006 if (sm->selectedMethod == EAP_TYPE_LEAP) {
2008 * LEAP differs from RFC 4137 by using reversed roles
2009 * for mutual authentication and because of this, we
2010 * need to accept EAP-Response frames if LEAP is used.
2012 if (plen < sizeof(*hdr) + 1) {
2013 wpa_printf(MSG_DEBUG, "EAP: Too short "
2014 "EAP-Response - no Type field");
2018 pos = (const u8 *) (hdr + 1);
2019 sm->reqMethod = *pos;
2020 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Response for "
2021 "LEAP method=%d id=%d",
2022 sm->reqMethod, sm->reqId);
2025 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Response");
2027 case EAP_CODE_SUCCESS:
2028 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Success");
2029 eap_notify_status(sm, "completion", "success");
2030 sm->rxSuccess = TRUE;
2032 case EAP_CODE_FAILURE:
2033 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Failure");
2034 eap_notify_status(sm, "completion", "failure");
2036 /* Get the error code from method */
2037 if (sm->m && sm->m->get_error_code) {
2040 error_code = sm->m->get_error_code(sm->eap_method_priv);
2041 if (error_code != NO_EAP_METHOD_ERROR)
2042 eap_report_error(sm, error_code);
2044 sm->rxFailure = TRUE;
2046 case EAP_CODE_INITIATE:
2047 eap_peer_initiate(sm, hdr, plen);
2049 case EAP_CODE_FINISH:
2050 eap_peer_finish(sm, hdr, plen);
2053 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Packet with unknown "
2054 "code %d", hdr->code);
2060 static void eap_peer_sm_tls_event(void *ctx, enum tls_event ev,
2061 union tls_event_data *data)
2063 struct eap_sm *sm = ctx;
2064 char *hash_hex = NULL;
2067 case TLS_CERT_CHAIN_SUCCESS:
2068 eap_notify_status(sm, "remote certificate verification",
2070 if (sm->ext_cert_check) {
2071 sm->waiting_ext_cert_check = 1;
2072 eap_sm_request(sm, WPA_CTRL_REQ_EXT_CERT_CHECK,
2076 case TLS_CERT_CHAIN_FAILURE:
2077 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TLS_CERT_ERROR
2078 "reason=%d depth=%d subject='%s' err='%s'",
2079 data->cert_fail.reason,
2080 data->cert_fail.depth,
2081 data->cert_fail.subject,
2082 data->cert_fail.reason_txt);
2083 eap_notify_status(sm, "remote certificate verification",
2084 data->cert_fail.reason_txt);
2086 case TLS_PEER_CERTIFICATE:
2087 if (!sm->eapol_cb->notify_cert)
2090 if (data->peer_cert.hash) {
2091 size_t len = data->peer_cert.hash_len * 2 + 1;
2092 hash_hex = os_malloc(len);
2094 wpa_snprintf_hex(hash_hex, len,
2095 data->peer_cert.hash,
2096 data->peer_cert.hash_len);
2100 sm->eapol_cb->notify_cert(sm->eapol_ctx,
2101 data->peer_cert.depth,
2102 data->peer_cert.subject,
2103 data->peer_cert.altsubject,
2104 data->peer_cert.num_altsubject,
2105 hash_hex, data->peer_cert.cert);
2108 if (data->alert.is_local)
2109 eap_notify_status(sm, "local TLS alert",
2110 data->alert.description);
2112 eap_notify_status(sm, "remote TLS alert",
2113 data->alert.description);
2122 * eap_peer_sm_init - Allocate and initialize EAP peer state machine
2123 * @eapol_ctx: Context data to be used with eapol_cb calls
2124 * @eapol_cb: Pointer to EAPOL callback functions
2125 * @msg_ctx: Context data for wpa_msg() calls
2126 * @conf: EAP configuration
2127 * Returns: Pointer to the allocated EAP state machine or %NULL on failure
2129 * This function allocates and initializes an EAP state machine. In addition,
2130 * this initializes TLS library for the new EAP state machine. eapol_cb pointer
2131 * will be in use until eap_peer_sm_deinit() is used to deinitialize this EAP
2132 * state machine. Consequently, the caller must make sure that this data
2133 * structure remains alive while the EAP state machine is active.
2135 struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
2136 const struct eapol_callbacks *eapol_cb,
2137 void *msg_ctx, struct eap_config *conf)
2140 struct tls_config tlsconf;
2142 sm = os_zalloc(sizeof(*sm));
2145 sm->eapol_ctx = eapol_ctx;
2146 sm->eapol_cb = eapol_cb;
2147 sm->msg_ctx = msg_ctx;
2148 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
2149 sm->wps = conf->wps;
2150 dl_list_init(&sm->erp_keys);
2152 os_memset(&tlsconf, 0, sizeof(tlsconf));
2153 tlsconf.opensc_engine_path = conf->opensc_engine_path;
2154 tlsconf.pkcs11_engine_path = conf->pkcs11_engine_path;
2155 tlsconf.pkcs11_module_path = conf->pkcs11_module_path;
2156 tlsconf.openssl_ciphers = conf->openssl_ciphers;
2158 tlsconf.fips_mode = 1;
2159 #endif /* CONFIG_FIPS */
2160 tlsconf.event_cb = eap_peer_sm_tls_event;
2161 tlsconf.cb_ctx = sm;
2162 tlsconf.cert_in_cb = conf->cert_in_cb;
2163 sm->ssl_ctx = tls_init(&tlsconf);
2164 if (sm->ssl_ctx == NULL) {
2165 wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS "
2171 sm->ssl_ctx2 = tls_init(&tlsconf);
2172 if (sm->ssl_ctx2 == NULL) {
2173 wpa_printf(MSG_INFO, "SSL: Failed to initialize TLS "
2175 /* Run without separate TLS context within TLS tunnel */
2183 * eap_peer_sm_deinit - Deinitialize and free an EAP peer state machine
2184 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2186 * This function deinitializes EAP state machine and frees all allocated
2189 void eap_peer_sm_deinit(struct eap_sm *sm)
2193 eap_deinit_prev_method(sm, "EAP deinit");
2196 tls_deinit(sm->ssl_ctx2);
2197 tls_deinit(sm->ssl_ctx);
2198 eap_peer_erp_free_keys(sm);
2204 * eap_peer_sm_step - Step EAP peer state machine
2205 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2206 * Returns: 1 if EAP state was changed or 0 if not
2208 * This function advances EAP state machine to a new state to match with the
2209 * current variables. This should be called whenever variables used by the EAP
2210 * state machine have changed.
2212 int eap_peer_sm_step(struct eap_sm *sm)
2216 sm->changed = FALSE;
2220 } while (sm->changed);
2226 * eap_sm_abort - Abort EAP authentication
2227 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2229 * Release system resources that have been allocated for the authentication
2230 * session without fully deinitializing the EAP state machine.
2232 void eap_sm_abort(struct eap_sm *sm)
2234 wpabuf_free(sm->lastRespData);
2235 sm->lastRespData = NULL;
2236 wpabuf_free(sm->eapRespData);
2237 sm->eapRespData = NULL;
2238 eap_sm_free_key(sm);
2239 os_free(sm->eapSessionId);
2240 sm->eapSessionId = NULL;
2242 /* This is not clearly specified in the EAP statemachines draft, but
2243 * it seems necessary to make sure that some of the EAPOL variables get
2244 * cleared for the next authentication. */
2245 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
2249 #ifdef CONFIG_CTRL_IFACE
2250 static const char * eap_sm_state_txt(int state)
2253 case EAP_INITIALIZE:
2254 return "INITIALIZE";
2261 case EAP_GET_METHOD:
2262 return "GET_METHOD";
2265 case EAP_SEND_RESPONSE:
2266 return "SEND_RESPONSE";
2271 case EAP_NOTIFICATION:
2272 return "NOTIFICATION";
2273 case EAP_RETRANSMIT:
2274 return "RETRANSMIT";
2283 #endif /* CONFIG_CTRL_IFACE */
2286 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
2287 static const char * eap_sm_method_state_txt(EapMethodState state)
2296 case METHOD_MAY_CONT:
2306 static const char * eap_sm_decision_txt(EapDecision decision)
2311 case DECISION_COND_SUCC:
2313 case DECISION_UNCOND_SUCC:
2314 return "UNCOND_SUCC";
2319 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
2322 #ifdef CONFIG_CTRL_IFACE
2325 * eap_sm_get_status - Get EAP state machine status
2326 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2327 * @buf: Buffer for status information
2328 * @buflen: Maximum buffer length
2329 * @verbose: Whether to include verbose status information
2330 * Returns: Number of bytes written to buf.
2332 * Query EAP state machine for status information. This function fills in a
2333 * text area with current status information from the EAPOL state machine. If
2334 * the buffer (buf) is not large enough, status information will be truncated
2335 * to fit the buffer.
2337 int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
2344 len = os_snprintf(buf, buflen,
2346 eap_sm_state_txt(sm->EAP_state));
2347 if (os_snprintf_error(buflen, len))
2350 if (sm->selectedMethod != EAP_TYPE_NONE) {
2355 const struct eap_method *m =
2356 eap_peer_get_eap_method(EAP_VENDOR_IETF,
2357 sm->selectedMethod);
2363 ret = os_snprintf(buf + len, buflen - len,
2364 "selectedMethod=%d (EAP-%s)\n",
2365 sm->selectedMethod, name);
2366 if (os_snprintf_error(buflen - len, ret))
2370 if (sm->m && sm->m->get_status) {
2371 len += sm->m->get_status(sm, sm->eap_method_priv,
2372 buf + len, buflen - len,
2378 ret = os_snprintf(buf + len, buflen - len,
2382 "ClientTimeout=%d\n",
2384 eap_sm_method_state_txt(sm->methodState),
2385 eap_sm_decision_txt(sm->decision),
2387 if (os_snprintf_error(buflen - len, ret))
2394 #endif /* CONFIG_CTRL_IFACE */
2397 static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
2398 const char *msg, size_t msglen)
2400 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
2401 struct eap_peer_config *config;
2402 const char *txt = NULL;
2407 config = eap_get_config(sm);
2412 case WPA_CTRL_REQ_EAP_IDENTITY:
2413 config->pending_req_identity++;
2415 case WPA_CTRL_REQ_EAP_PASSWORD:
2416 config->pending_req_password++;
2418 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
2419 config->pending_req_new_password++;
2421 case WPA_CTRL_REQ_EAP_PIN:
2422 config->pending_req_pin++;
2424 case WPA_CTRL_REQ_EAP_OTP:
2426 tmp = os_malloc(msglen + 3);
2430 os_memcpy(tmp + 1, msg, msglen);
2431 tmp[msglen + 1] = ']';
2432 tmp[msglen + 2] = '\0';
2434 os_free(config->pending_req_otp);
2435 config->pending_req_otp = tmp;
2436 config->pending_req_otp_len = msglen + 3;
2438 if (config->pending_req_otp == NULL)
2440 txt = config->pending_req_otp;
2443 case WPA_CTRL_REQ_EAP_PASSPHRASE:
2444 config->pending_req_passphrase++;
2446 case WPA_CTRL_REQ_SIM:
2447 config->pending_req_sim++;
2450 case WPA_CTRL_REQ_EXT_CERT_CHECK:
2456 if (sm->eapol_cb->eap_param_needed)
2457 sm->eapol_cb->eap_param_needed(sm->eapol_ctx, field, txt);
2458 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
2462 const char * eap_sm_get_method_name(struct eap_sm *sm)
2471 * eap_sm_request_identity - Request identity from user (ctrl_iface)
2472 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2474 * EAP methods can call this function to request identity information for the
2475 * current network. This is normally called when the identity is not included
2476 * in the network configuration. The request will be sent to monitor programs
2477 * through the control interface.
2479 void eap_sm_request_identity(struct eap_sm *sm)
2481 eap_sm_request(sm, WPA_CTRL_REQ_EAP_IDENTITY, NULL, 0);
2486 * eap_sm_request_password - Request password from user (ctrl_iface)
2487 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2489 * EAP methods can call this function to request password information for the
2490 * current network. This is normally called when the password is not included
2491 * in the network configuration. The request will be sent to monitor programs
2492 * through the control interface.
2494 void eap_sm_request_password(struct eap_sm *sm)
2496 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSWORD, NULL, 0);
2501 * eap_sm_request_new_password - Request new password from user (ctrl_iface)
2502 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2504 * EAP methods can call this function to request new password information for
2505 * the current network. This is normally called when the EAP method indicates
2506 * that the current password has expired and password change is required. The
2507 * request will be sent to monitor programs through the control interface.
2509 void eap_sm_request_new_password(struct eap_sm *sm)
2511 eap_sm_request(sm, WPA_CTRL_REQ_EAP_NEW_PASSWORD, NULL, 0);
2516 * eap_sm_request_pin - Request SIM or smart card PIN from user (ctrl_iface)
2517 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2519 * EAP methods can call this function to request SIM or smart card PIN
2520 * information for the current network. This is normally called when the PIN is
2521 * not included in the network configuration. The request will be sent to
2522 * monitor programs through the control interface.
2524 void eap_sm_request_pin(struct eap_sm *sm)
2526 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PIN, NULL, 0);
2531 * eap_sm_request_otp - Request one time password from user (ctrl_iface)
2532 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2533 * @msg: Message to be displayed to the user when asking for OTP
2534 * @msg_len: Length of the user displayable message
2536 * EAP methods can call this function to request open time password (OTP) for
2537 * the current network. The request will be sent to monitor programs through
2538 * the control interface.
2540 void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
2542 eap_sm_request(sm, WPA_CTRL_REQ_EAP_OTP, msg, msg_len);
2547 * eap_sm_request_passphrase - Request passphrase from user (ctrl_iface)
2548 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2550 * EAP methods can call this function to request passphrase for a private key
2551 * for the current network. This is normally called when the passphrase is not
2552 * included in the network configuration. The request will be sent to monitor
2553 * programs through the control interface.
2555 void eap_sm_request_passphrase(struct eap_sm *sm)
2557 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSPHRASE, NULL, 0);
2562 * eap_sm_request_sim - Request external SIM processing
2563 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2564 * @req: EAP method specific request
2566 void eap_sm_request_sim(struct eap_sm *sm, const char *req)
2568 eap_sm_request(sm, WPA_CTRL_REQ_SIM, req, os_strlen(req));
2573 * eap_sm_notify_ctrl_attached - Notification of attached monitor
2574 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2576 * Notify EAP state machines that a monitor was attached to the control
2577 * interface to trigger re-sending of pending requests for user input.
2579 void eap_sm_notify_ctrl_attached(struct eap_sm *sm)
2581 struct eap_peer_config *config = eap_get_config(sm);
2586 /* Re-send any pending requests for user data since a new control
2587 * interface was added. This handles cases where the EAP authentication
2588 * starts immediately after system startup when the user interface is
2589 * not yet running. */
2590 if (config->pending_req_identity)
2591 eap_sm_request_identity(sm);
2592 if (config->pending_req_password)
2593 eap_sm_request_password(sm);
2594 if (config->pending_req_new_password)
2595 eap_sm_request_new_password(sm);
2596 if (config->pending_req_otp)
2597 eap_sm_request_otp(sm, NULL, 0);
2598 if (config->pending_req_pin)
2599 eap_sm_request_pin(sm);
2600 if (config->pending_req_passphrase)
2601 eap_sm_request_passphrase(sm);
2605 static int eap_allowed_phase2_type(int vendor, int type)
2607 if (vendor != EAP_VENDOR_IETF)
2609 return type != EAP_TYPE_PEAP && type != EAP_TYPE_TTLS &&
2610 type != EAP_TYPE_FAST;
2615 * eap_get_phase2_type - Get EAP type for the given EAP phase 2 method name
2616 * @name: EAP method name, e.g., MD5
2617 * @vendor: Buffer for returning EAP Vendor-Id
2618 * Returns: EAP method type or %EAP_TYPE_NONE if not found
2620 * This function maps EAP type names into EAP type numbers that are allowed for
2621 * Phase 2, i.e., for tunneled authentication. Phase 2 is used, e.g., with
2622 * EAP-PEAP, EAP-TTLS, and EAP-FAST.
2624 u32 eap_get_phase2_type(const char *name, int *vendor)
2627 u32 type = eap_peer_get_type(name, &v);
2628 if (eap_allowed_phase2_type(v, type)) {
2632 *vendor = EAP_VENDOR_IETF;
2633 return EAP_TYPE_NONE;
2638 * eap_get_phase2_types - Get list of allowed EAP phase 2 types
2639 * @config: Pointer to a network configuration
2640 * @count: Pointer to a variable to be filled with number of returned EAP types
2641 * Returns: Pointer to allocated type list or %NULL on failure
2643 * This function generates an array of allowed EAP phase 2 (tunneled) types for
2644 * the given network configuration.
2646 struct eap_method_type * eap_get_phase2_types(struct eap_peer_config *config,
2649 struct eap_method_type *buf;
2653 const struct eap_method *methods, *m;
2655 methods = eap_peer_get_methods(&mcount);
2656 if (methods == NULL)
2659 buf = os_malloc(mcount * sizeof(struct eap_method_type));
2663 for (m = methods; m; m = m->next) {
2666 if (eap_allowed_phase2_type(vendor, method)) {
2667 if (vendor == EAP_VENDOR_IETF &&
2668 method == EAP_TYPE_TLS && config &&
2669 config->private_key2 == NULL)
2671 buf[*count].vendor = vendor;
2672 buf[*count].method = method;
2682 * eap_set_fast_reauth - Update fast_reauth setting
2683 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2684 * @enabled: 1 = Fast reauthentication is enabled, 0 = Disabled
2686 void eap_set_fast_reauth(struct eap_sm *sm, int enabled)
2688 sm->fast_reauth = enabled;
2693 * eap_set_workaround - Update EAP workarounds setting
2694 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2695 * @workaround: 1 = Enable EAP workarounds, 0 = Disable EAP workarounds
2697 void eap_set_workaround(struct eap_sm *sm, unsigned int workaround)
2699 sm->workaround = workaround;
2704 * eap_get_config - Get current network configuration
2705 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2706 * Returns: Pointer to the current network configuration or %NULL if not found
2708 * EAP peer methods should avoid using this function if they can use other
2709 * access functions, like eap_get_config_identity() and
2710 * eap_get_config_password(), that do not require direct access to
2711 * struct eap_peer_config.
2713 struct eap_peer_config * eap_get_config(struct eap_sm *sm)
2715 return sm->eapol_cb->get_config(sm->eapol_ctx);
2720 * eap_get_config_identity - Get identity from the network configuration
2721 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2722 * @len: Buffer for the length of the identity
2723 * Returns: Pointer to the identity or %NULL if not found
2725 const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len)
2727 struct eap_peer_config *config = eap_get_config(sm);
2730 *len = config->identity_len;
2731 return config->identity;
2735 static int eap_get_ext_password(struct eap_sm *sm,
2736 struct eap_peer_config *config)
2740 if (config->password == NULL)
2743 name = os_zalloc(config->password_len + 1);
2746 os_memcpy(name, config->password, config->password_len);
2748 ext_password_free(sm->ext_pw_buf);
2749 sm->ext_pw_buf = ext_password_get(sm->ext_pw, name);
2752 return sm->ext_pw_buf == NULL ? -1 : 0;
2757 * eap_get_config_password - Get password from the network configuration
2758 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2759 * @len: Buffer for the length of the password
2760 * Returns: Pointer to the password or %NULL if not found
2762 const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len)
2764 struct eap_peer_config *config = eap_get_config(sm);
2768 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2769 if (eap_get_ext_password(sm, config) < 0)
2771 *len = wpabuf_len(sm->ext_pw_buf);
2772 return wpabuf_head(sm->ext_pw_buf);
2775 *len = config->password_len;
2776 return config->password;
2781 * eap_get_config_password2 - Get password from the network configuration
2782 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2783 * @len: Buffer for the length of the password
2784 * @hash: Buffer for returning whether the password is stored as a
2785 * NtPasswordHash instead of plaintext password; can be %NULL if this
2786 * information is not needed
2787 * Returns: Pointer to the password or %NULL if not found
2789 const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash)
2791 struct eap_peer_config *config = eap_get_config(sm);
2795 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2796 if (eap_get_ext_password(sm, config) < 0)
2800 *len = wpabuf_len(sm->ext_pw_buf);
2801 return wpabuf_head(sm->ext_pw_buf);
2804 *len = config->password_len;
2806 *hash = !!(config->flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH);
2807 return config->password;
2812 * eap_get_config_new_password - Get new password from network configuration
2813 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2814 * @len: Buffer for the length of the new password
2815 * Returns: Pointer to the new password or %NULL if not found
2817 const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len)
2819 struct eap_peer_config *config = eap_get_config(sm);
2822 *len = config->new_password_len;
2823 return config->new_password;
2828 * eap_get_config_otp - Get one-time password from the network configuration
2829 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2830 * @len: Buffer for the length of the one-time password
2831 * Returns: Pointer to the one-time password or %NULL if not found
2833 const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len)
2835 struct eap_peer_config *config = eap_get_config(sm);
2838 *len = config->otp_len;
2844 * eap_clear_config_otp - Clear used one-time password
2845 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2847 * This function clears a used one-time password (OTP) from the current network
2848 * configuration. This should be called when the OTP has been used and is not
2851 void eap_clear_config_otp(struct eap_sm *sm)
2853 struct eap_peer_config *config = eap_get_config(sm);
2856 os_memset(config->otp, 0, config->otp_len);
2857 os_free(config->otp);
2859 config->otp_len = 0;
2864 * eap_get_config_phase1 - Get phase1 data from the network configuration
2865 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2866 * Returns: Pointer to the phase1 data or %NULL if not found
2868 const char * eap_get_config_phase1(struct eap_sm *sm)
2870 struct eap_peer_config *config = eap_get_config(sm);
2873 return config->phase1;
2878 * eap_get_config_phase2 - Get phase2 data from the network configuration
2879 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2880 * Returns: Pointer to the phase1 data or %NULL if not found
2882 const char * eap_get_config_phase2(struct eap_sm *sm)
2884 struct eap_peer_config *config = eap_get_config(sm);
2887 return config->phase2;
2891 int eap_get_config_fragment_size(struct eap_sm *sm)
2893 struct eap_peer_config *config = eap_get_config(sm);
2896 return config->fragment_size;
2901 * eap_key_available - Get key availability (eapKeyAvailable variable)
2902 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2903 * Returns: 1 if EAP keying material is available, 0 if not
2905 int eap_key_available(struct eap_sm *sm)
2907 return sm ? sm->eapKeyAvailable : 0;
2912 * eap_notify_success - Notify EAP state machine about external success trigger
2913 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2915 * This function is called when external event, e.g., successful completion of
2916 * WPA-PSK key handshake, is indicating that EAP state machine should move to
2917 * success state. This is mainly used with security modes that do not use EAP
2918 * state machine (e.g., WPA-PSK).
2920 void eap_notify_success(struct eap_sm *sm)
2923 sm->decision = DECISION_COND_SUCC;
2924 sm->EAP_state = EAP_SUCCESS;
2930 * eap_notify_lower_layer_success - Notification of lower layer success
2931 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2933 * Notify EAP state machines that a lower layer has detected a successful
2934 * authentication. This is used to recover from dropped EAP-Success messages.
2936 void eap_notify_lower_layer_success(struct eap_sm *sm)
2941 if (eapol_get_bool(sm, EAPOL_eapSuccess) ||
2942 sm->decision == DECISION_FAIL ||
2943 (sm->methodState != METHOD_MAY_CONT &&
2944 sm->methodState != METHOD_DONE))
2947 if (sm->eapKeyData != NULL)
2948 sm->eapKeyAvailable = TRUE;
2949 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
2950 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
2951 "EAP authentication completed successfully (based on lower "
2957 * eap_get_eapSessionId - Get Session-Id from EAP state machine
2958 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2959 * @len: Pointer to variable that will be set to number of bytes in the session
2960 * Returns: Pointer to the EAP Session-Id or %NULL on failure
2962 * Fetch EAP Session-Id from the EAP state machine. The Session-Id is available
2963 * only after a successful authentication. EAP state machine continues to manage
2964 * the Session-Id and the caller must not change or free the returned data.
2966 const u8 * eap_get_eapSessionId(struct eap_sm *sm, size_t *len)
2968 if (sm == NULL || sm->eapSessionId == NULL) {
2973 *len = sm->eapSessionIdLen;
2974 return sm->eapSessionId;
2979 * eap_get_eapKeyData - Get master session key (MSK) from EAP state machine
2980 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2981 * @len: Pointer to variable that will be set to number of bytes in the key
2982 * Returns: Pointer to the EAP keying data or %NULL on failure
2984 * Fetch EAP keying material (MSK, eapKeyData) from the EAP state machine. The
2985 * key is available only after a successful authentication. EAP state machine
2986 * continues to manage the key data and the caller must not change or free the
2989 const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len)
2991 if (sm == NULL || sm->eapKeyData == NULL) {
2996 *len = sm->eapKeyDataLen;
2997 return sm->eapKeyData;
3002 * eap_get_eapKeyData - Get EAP response data
3003 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3004 * Returns: Pointer to the EAP response (eapRespData) or %NULL on failure
3006 * Fetch EAP response (eapRespData) from the EAP state machine. This data is
3007 * available when EAP state machine has processed an incoming EAP request. The
3008 * EAP state machine does not maintain a reference to the response after this
3009 * function is called and the caller is responsible for freeing the data.
3011 struct wpabuf * eap_get_eapRespData(struct eap_sm *sm)
3013 struct wpabuf *resp;
3015 if (sm == NULL || sm->eapRespData == NULL)
3018 resp = sm->eapRespData;
3019 sm->eapRespData = NULL;
3026 * eap_sm_register_scard_ctx - Notification of smart card context
3027 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3028 * @ctx: Context data for smart card operations
3030 * Notify EAP state machines of context data for smart card operations. This
3031 * context data will be used as a parameter for scard_*() functions.
3033 void eap_register_scard_ctx(struct eap_sm *sm, void *ctx)
3036 sm->scard_ctx = ctx;
3041 * eap_set_config_blob - Set or add a named configuration blob
3042 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3043 * @blob: New value for the blob
3045 * Adds a new configuration blob or replaces the current value of an existing
3048 void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob)
3050 #ifndef CONFIG_NO_CONFIG_BLOBS
3051 sm->eapol_cb->set_config_blob(sm->eapol_ctx, blob);
3052 #endif /* CONFIG_NO_CONFIG_BLOBS */
3057 * eap_get_config_blob - Get a named configuration blob
3058 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3059 * @name: Name of the blob
3060 * Returns: Pointer to blob data or %NULL if not found
3062 const struct wpa_config_blob * eap_get_config_blob(struct eap_sm *sm,
3065 #ifndef CONFIG_NO_CONFIG_BLOBS
3066 return sm->eapol_cb->get_config_blob(sm->eapol_ctx, name);
3067 #else /* CONFIG_NO_CONFIG_BLOBS */
3069 #endif /* CONFIG_NO_CONFIG_BLOBS */
3074 * eap_set_force_disabled - Set force_disabled flag
3075 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3076 * @disabled: 1 = EAP disabled, 0 = EAP enabled
3078 * This function is used to force EAP state machine to be disabled when it is
3079 * not in use (e.g., with WPA-PSK or plaintext connections).
3081 void eap_set_force_disabled(struct eap_sm *sm, int disabled)
3083 sm->force_disabled = disabled;
3088 * eap_set_external_sim - Set external_sim flag
3089 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3090 * @external_sim: Whether external SIM/USIM processing is used
3092 void eap_set_external_sim(struct eap_sm *sm, int external_sim)
3094 sm->external_sim = external_sim;
3099 * eap_notify_pending - Notify that EAP method is ready to re-process a request
3100 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3102 * An EAP method can perform a pending operation (e.g., to get a response from
3103 * an external process). Once the response is available, this function can be
3104 * used to request EAPOL state machine to retry delivering the previously
3105 * received (and still unanswered) EAP request to EAP state machine.
3107 void eap_notify_pending(struct eap_sm *sm)
3109 sm->eapol_cb->notify_pending(sm->eapol_ctx);
3114 * eap_invalidate_cached_session - Mark cached session data invalid
3115 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3117 void eap_invalidate_cached_session(struct eap_sm *sm)
3120 eap_deinit_prev_method(sm, "invalidate");
3124 int eap_is_wps_pbc_enrollee(struct eap_peer_config *conf)
3126 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
3127 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
3128 return 0; /* Not a WPS Enrollee */
3130 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pbc=1") == NULL)
3131 return 0; /* Not using PBC */
3137 int eap_is_wps_pin_enrollee(struct eap_peer_config *conf)
3139 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
3140 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
3141 return 0; /* Not a WPS Enrollee */
3143 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pin=") == NULL)
3144 return 0; /* Not using PIN */
3150 void eap_sm_set_ext_pw_ctx(struct eap_sm *sm, struct ext_password_data *ext)
3152 ext_password_free(sm->ext_pw_buf);
3153 sm->ext_pw_buf = NULL;
3159 * eap_set_anon_id - Set or add anonymous identity
3160 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
3161 * @id: Anonymous identity (e.g., EAP-SIM pseudonym) or %NULL to clear
3162 * @len: Length of anonymous identity in octets
3164 void eap_set_anon_id(struct eap_sm *sm, const u8 *id, size_t len)
3166 if (sm->eapol_cb->set_anon_id)
3167 sm->eapol_cb->set_anon_id(sm->eapol_ctx, id, len);
3171 int eap_peer_was_failure_expected(struct eap_sm *sm)
3173 return sm->expected_failure;