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 "common/wpa_ctrl.h"
27 #include "eap_common/eap_wsc_common.h"
29 #include "eap_config.h"
31 #define STATE_MACHINE_DATA struct eap_sm
32 #define STATE_MACHINE_DEBUG_PREFIX "EAP"
34 #define EAP_MAX_AUTH_ROUNDS 50
35 #define EAP_CLIENT_TIMEOUT_DEFAULT 60
38 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
40 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id);
41 static void eap_sm_processIdentity(struct eap_sm *sm,
42 const struct wpabuf *req);
43 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req);
44 static struct wpabuf * eap_sm_buildNotify(int id);
45 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req);
46 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
47 static const char * eap_sm_method_state_txt(EapMethodState state);
48 static const char * eap_sm_decision_txt(EapDecision decision);
49 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
53 static Boolean eapol_get_bool(struct eap_sm *sm, enum eapol_bool_var var)
55 return sm->eapol_cb->get_bool(sm->eapol_ctx, var);
59 static void eapol_set_bool(struct eap_sm *sm, enum eapol_bool_var var,
62 sm->eapol_cb->set_bool(sm->eapol_ctx, var, value);
66 static unsigned int eapol_get_int(struct eap_sm *sm, enum eapol_int_var var)
68 return sm->eapol_cb->get_int(sm->eapol_ctx, var);
72 static void eapol_set_int(struct eap_sm *sm, enum eapol_int_var var,
75 sm->eapol_cb->set_int(sm->eapol_ctx, var, value);
79 static struct wpabuf * eapol_get_eapReqData(struct eap_sm *sm)
81 return sm->eapol_cb->get_eapReqData(sm->eapol_ctx);
85 static void eap_notify_status(struct eap_sm *sm, const char *status,
86 const char *parameter)
88 wpa_printf(MSG_DEBUG, "EAP: Status notification: %s (param=%s)",
90 if (sm->eapol_cb->notify_status)
91 sm->eapol_cb->notify_status(sm->eapol_ctx, status, parameter);
95 static void eap_deinit_prev_method(struct eap_sm *sm, const char *txt)
97 ext_password_free(sm->ext_pw_buf);
98 sm->ext_pw_buf = NULL;
100 if (sm->m == NULL || sm->eap_method_priv == NULL)
103 wpa_printf(MSG_DEBUG, "EAP: deinitialize previously used EAP method "
104 "(%d, %s) at %s", sm->selectedMethod, sm->m->name, txt);
105 sm->m->deinit(sm, sm->eap_method_priv);
106 sm->eap_method_priv = NULL;
112 * eap_allowed_method - Check whether EAP method is allowed
113 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
114 * @vendor: Vendor-Id for expanded types or 0 = IETF for legacy types
116 * Returns: 1 = allowed EAP method, 0 = not allowed
118 int eap_allowed_method(struct eap_sm *sm, int vendor, u32 method)
120 struct eap_peer_config *config = eap_get_config(sm);
122 struct eap_method_type *m;
124 if (config == NULL || config->eap_methods == NULL)
127 m = config->eap_methods;
128 for (i = 0; m[i].vendor != EAP_VENDOR_IETF ||
129 m[i].method != EAP_TYPE_NONE; i++) {
130 if (m[i].vendor == vendor && m[i].method == method)
138 * This state initializes state machine variables when the machine is
139 * activated (portEnabled = TRUE). This is also used when re-starting
140 * authentication (eapRestart == TRUE).
142 SM_STATE(EAP, INITIALIZE)
144 SM_ENTRY(EAP, INITIALIZE);
145 if (sm->fast_reauth && sm->m && sm->m->has_reauth_data &&
146 sm->m->has_reauth_data(sm, sm->eap_method_priv) &&
148 wpa_printf(MSG_DEBUG, "EAP: maintaining EAP method data for "
149 "fast reauthentication");
150 sm->m->deinit_for_reauth(sm, sm->eap_method_priv);
152 eap_deinit_prev_method(sm, "INITIALIZE");
154 sm->selectedMethod = EAP_TYPE_NONE;
155 sm->methodState = METHOD_NONE;
156 sm->allowNotifications = TRUE;
157 sm->decision = DECISION_FAIL;
158 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
159 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
160 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
161 eapol_set_bool(sm, EAPOL_eapFail, FALSE);
162 os_free(sm->eapKeyData);
163 sm->eapKeyData = NULL;
164 os_free(sm->eapSessionId);
165 sm->eapSessionId = NULL;
166 sm->eapKeyAvailable = FALSE;
167 eapol_set_bool(sm, EAPOL_eapRestart, FALSE);
168 sm->lastId = -1; /* new session - make sure this does not match with
169 * the first EAP-Packet */
171 * RFC 4137 does not reset eapResp and eapNoResp here. However, this
172 * seemed to be able to trigger cases where both were set and if EAPOL
173 * state machine uses eapNoResp first, it may end up not sending a real
174 * reply correctly. This occurred when the workaround in FAIL state set
175 * eapNoResp = TRUE.. Maybe that workaround needs to be fixed to do
178 eapol_set_bool(sm, EAPOL_eapResp, FALSE);
179 eapol_set_bool(sm, EAPOL_eapNoResp, FALSE);
181 sm->prev_failure = 0;
182 sm->expected_failure = 0;
187 * This state is reached whenever service from the lower layer is interrupted
188 * or unavailable (portEnabled == FALSE). Immediate transition to INITIALIZE
189 * occurs when the port becomes enabled.
191 SM_STATE(EAP, DISABLED)
193 SM_ENTRY(EAP, DISABLED);
196 * RFC 4137 does not describe clearing of idleWhile here, but doing so
197 * allows the timer tick to be stopped more quickly when EAP is not in
200 eapol_set_int(sm, EAPOL_idleWhile, 0);
205 * The state machine spends most of its time here, waiting for something to
206 * happen. This state is entered unconditionally from INITIALIZE, DISCARD, and
207 * SEND_RESPONSE states.
216 * This state is entered when an EAP packet is received (eapReq == TRUE) to
217 * parse the packet header.
219 SM_STATE(EAP, RECEIVED)
221 const struct wpabuf *eapReqData;
223 SM_ENTRY(EAP, RECEIVED);
224 eapReqData = eapol_get_eapReqData(sm);
225 /* parse rxReq, rxSuccess, rxFailure, reqId, reqMethod */
226 eap_sm_parseEapReq(sm, eapReqData);
232 * This state is entered when a request for a new type comes in. Either the
233 * correct method is started, or a Nak response is built.
235 SM_STATE(EAP, GET_METHOD)
239 const struct eap_method *eap_method;
241 SM_ENTRY(EAP, GET_METHOD);
243 if (sm->reqMethod == EAP_TYPE_EXPANDED)
244 method = sm->reqVendorMethod;
246 method = sm->reqMethod;
248 eap_method = eap_peer_get_eap_method(sm->reqVendor, method);
250 if (!eap_sm_allowMethod(sm, sm->reqVendor, method)) {
251 wpa_printf(MSG_DEBUG, "EAP: vendor %u method %u not allowed",
252 sm->reqVendor, method);
253 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
254 "vendor=%u method=%u -> NAK",
255 sm->reqVendor, method);
256 eap_notify_status(sm, "refuse proposed method",
257 eap_method ? eap_method->name : "unknown");
261 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
262 "vendor=%u method=%u", sm->reqVendor, method);
264 eap_notify_status(sm, "accept proposed method",
265 eap_method ? eap_method->name : "unknown");
267 * RFC 4137 does not define specific operation for fast
268 * re-authentication (session resumption). The design here is to allow
269 * the previously used method data to be maintained for
270 * re-authentication if the method support session resumption.
271 * Otherwise, the previously used method data is freed and a new method
274 if (sm->fast_reauth &&
275 sm->m && sm->m->vendor == sm->reqVendor &&
276 sm->m->method == method &&
277 sm->m->has_reauth_data &&
278 sm->m->has_reauth_data(sm, sm->eap_method_priv)) {
279 wpa_printf(MSG_DEBUG, "EAP: Using previous method data"
280 " for fast re-authentication");
283 eap_deinit_prev_method(sm, "GET_METHOD");
287 sm->selectedMethod = sm->reqMethod;
291 wpa_printf(MSG_DEBUG, "EAP: Could not find selected method: "
292 "vendor %d method %d",
293 sm->reqVendor, method);
297 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
299 wpa_printf(MSG_DEBUG, "EAP: Initialize selected EAP method: "
300 "vendor %u method %u (%s)",
301 sm->reqVendor, method, sm->m->name);
303 sm->eap_method_priv = sm->m->init_for_reauth(
304 sm, sm->eap_method_priv);
306 sm->eap_method_priv = sm->m->init(sm);
308 if (sm->eap_method_priv == NULL) {
309 struct eap_peer_config *config = eap_get_config(sm);
310 wpa_msg(sm->msg_ctx, MSG_INFO,
311 "EAP: Failed to initialize EAP method: vendor %u "
313 sm->reqVendor, method, sm->m->name);
315 sm->methodState = METHOD_NONE;
316 sm->selectedMethod = EAP_TYPE_NONE;
317 if (sm->reqMethod == EAP_TYPE_TLS && config &&
318 (config->pending_req_pin ||
319 config->pending_req_passphrase)) {
321 * Return without generating Nak in order to allow
322 * entering of PIN code or passphrase to retry the
323 * current EAP packet.
325 wpa_printf(MSG_DEBUG, "EAP: Pending PIN/passphrase "
326 "request - skip Nak");
333 sm->methodState = METHOD_INIT;
334 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_METHOD
335 "EAP vendor %u method %u (%s) selected",
336 sm->reqVendor, method, sm->m->name);
340 wpabuf_free(sm->eapRespData);
341 sm->eapRespData = NULL;
342 sm->eapRespData = eap_sm_buildNak(sm, sm->reqId);
347 * The method processing happens here. The request from the authenticator is
348 * processed, and an appropriate response packet is built.
350 SM_STATE(EAP, METHOD)
352 struct wpabuf *eapReqData;
353 struct eap_method_ret ret;
356 SM_ENTRY(EAP, METHOD);
358 wpa_printf(MSG_WARNING, "EAP::METHOD - method not selected");
362 eapReqData = eapol_get_eapReqData(sm);
363 if (sm->m->vendor == EAP_VENDOR_IETF && sm->m->method == EAP_TYPE_LEAP)
364 min_len = 0; /* LEAP uses EAP-Success without payload */
365 if (!eap_hdr_len_valid(eapReqData, min_len))
369 * Get ignore, methodState, decision, allowNotifications, and
370 * eapRespData. RFC 4137 uses three separate method procedure (check,
371 * process, and buildResp) in this state. These have been combined into
372 * a single function call to m->process() in order to optimize EAP
373 * method implementation interface a bit. These procedures are only
374 * used from within this METHOD state, so there is no need to keep
375 * these as separate C functions.
377 * The RFC 4137 procedures return values as follows:
378 * ignore = m.check(eapReqData)
379 * (methodState, decision, allowNotifications) = m.process(eapReqData)
380 * eapRespData = m.buildResp(reqId)
382 os_memset(&ret, 0, sizeof(ret));
383 ret.ignore = sm->ignore;
384 ret.methodState = sm->methodState;
385 ret.decision = sm->decision;
386 ret.allowNotifications = sm->allowNotifications;
387 wpabuf_free(sm->eapRespData);
388 sm->eapRespData = NULL;
389 sm->eapRespData = sm->m->process(sm, sm->eap_method_priv, &ret,
391 wpa_printf(MSG_DEBUG, "EAP: method process -> ignore=%s "
392 "methodState=%s decision=%s eapRespData=%p",
393 ret.ignore ? "TRUE" : "FALSE",
394 eap_sm_method_state_txt(ret.methodState),
395 eap_sm_decision_txt(ret.decision),
398 sm->ignore = ret.ignore;
401 sm->methodState = ret.methodState;
402 sm->decision = ret.decision;
403 sm->allowNotifications = ret.allowNotifications;
405 if (sm->m->isKeyAvailable && sm->m->getKey &&
406 sm->m->isKeyAvailable(sm, sm->eap_method_priv)) {
407 os_free(sm->eapKeyData);
408 sm->eapKeyData = sm->m->getKey(sm, sm->eap_method_priv,
410 os_free(sm->eapSessionId);
411 sm->eapSessionId = NULL;
412 if (sm->m->getSessionId) {
413 sm->eapSessionId = sm->m->getSessionId(
414 sm, sm->eap_method_priv,
415 &sm->eapSessionIdLen);
416 wpa_hexdump(MSG_DEBUG, "EAP: Session-Id",
417 sm->eapSessionId, sm->eapSessionIdLen);
424 * This state signals the lower layer that a response packet is ready to be
427 SM_STATE(EAP, SEND_RESPONSE)
429 SM_ENTRY(EAP, SEND_RESPONSE);
430 wpabuf_free(sm->lastRespData);
431 if (sm->eapRespData) {
433 os_memcpy(sm->last_md5, sm->req_md5, 16);
434 sm->lastId = sm->reqId;
435 sm->lastRespData = wpabuf_dup(sm->eapRespData);
436 eapol_set_bool(sm, EAPOL_eapResp, TRUE);
438 wpa_printf(MSG_DEBUG, "EAP: No eapRespData available");
439 sm->lastRespData = NULL;
441 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
442 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
447 * This state signals the lower layer that the request was discarded, and no
448 * response packet will be sent at this time.
450 SM_STATE(EAP, DISCARD)
452 SM_ENTRY(EAP, DISCARD);
453 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
454 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
459 * Handles requests for Identity method and builds a response.
461 SM_STATE(EAP, IDENTITY)
463 const struct wpabuf *eapReqData;
465 SM_ENTRY(EAP, IDENTITY);
466 eapReqData = eapol_get_eapReqData(sm);
467 if (!eap_hdr_len_valid(eapReqData, 1))
469 eap_sm_processIdentity(sm, eapReqData);
470 wpabuf_free(sm->eapRespData);
471 sm->eapRespData = NULL;
472 sm->eapRespData = eap_sm_buildIdentity(sm, sm->reqId, 0);
477 * Handles requests for Notification method and builds a response.
479 SM_STATE(EAP, NOTIFICATION)
481 const struct wpabuf *eapReqData;
483 SM_ENTRY(EAP, NOTIFICATION);
484 eapReqData = eapol_get_eapReqData(sm);
485 if (!eap_hdr_len_valid(eapReqData, 1))
487 eap_sm_processNotify(sm, eapReqData);
488 wpabuf_free(sm->eapRespData);
489 sm->eapRespData = NULL;
490 sm->eapRespData = eap_sm_buildNotify(sm->reqId);
495 * This state retransmits the previous response packet.
497 SM_STATE(EAP, RETRANSMIT)
499 SM_ENTRY(EAP, RETRANSMIT);
500 wpabuf_free(sm->eapRespData);
501 if (sm->lastRespData)
502 sm->eapRespData = wpabuf_dup(sm->lastRespData);
504 sm->eapRespData = NULL;
509 * This state is entered in case of a successful completion of authentication
510 * and state machine waits here until port is disabled or EAP authentication is
513 SM_STATE(EAP, SUCCESS)
515 SM_ENTRY(EAP, SUCCESS);
516 if (sm->eapKeyData != NULL)
517 sm->eapKeyAvailable = TRUE;
518 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
521 * RFC 4137 does not clear eapReq here, but this seems to be required
522 * to avoid processing the same request twice when state machine is
525 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
528 * RFC 4137 does not set eapNoResp here, but this seems to be required
529 * to get EAPOL Supplicant backend state machine into SUCCESS state. In
530 * addition, either eapResp or eapNoResp is required to be set after
531 * processing the received EAP frame.
533 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
535 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
536 "EAP authentication completed successfully");
541 * This state is entered in case of a failure and state machine waits here
542 * until port is disabled or EAP authentication is restarted.
544 SM_STATE(EAP, FAILURE)
546 SM_ENTRY(EAP, FAILURE);
547 eapol_set_bool(sm, EAPOL_eapFail, TRUE);
550 * RFC 4137 does not clear eapReq here, but this seems to be required
551 * to avoid processing the same request twice when state machine is
554 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
557 * RFC 4137 does not set eapNoResp here. However, either eapResp or
558 * eapNoResp is required to be set after processing the received EAP
561 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
563 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
564 "EAP authentication failed");
566 sm->prev_failure = 1;
570 static int eap_success_workaround(struct eap_sm *sm, int reqId, int lastId)
573 * At least Microsoft IAS and Meetinghouse Aegis seem to be sending
574 * EAP-Success/Failure with lastId + 1 even though RFC 3748 and
575 * RFC 4137 require that reqId == lastId. In addition, it looks like
576 * Ringmaster v2.1.2.0 would be using lastId + 2 in EAP-Success.
578 * Accept this kind of Id if EAP workarounds are enabled. These are
579 * unauthenticated plaintext messages, so this should have minimal
580 * security implications (bit easier to fake EAP-Success/Failure).
582 if (sm->workaround && (reqId == ((lastId + 1) & 0xff) ||
583 reqId == ((lastId + 2) & 0xff))) {
584 wpa_printf(MSG_DEBUG, "EAP: Workaround for unexpected "
585 "identifier field in EAP Success: "
586 "reqId=%d lastId=%d (these are supposed to be "
587 "same)", reqId, lastId);
590 wpa_printf(MSG_DEBUG, "EAP: EAP-Success Id mismatch - reqId=%d "
591 "lastId=%d", reqId, lastId);
597 * RFC 4137 - Appendix A.1: EAP Peer State Machine - State transitions
600 static void eap_peer_sm_step_idle(struct eap_sm *sm)
603 * The first three transitions are from RFC 4137. The last two are
604 * local additions to handle special cases with LEAP and PEAP server
605 * not sending EAP-Success in some cases.
607 if (eapol_get_bool(sm, EAPOL_eapReq))
608 SM_ENTER(EAP, RECEIVED);
609 else if ((eapol_get_bool(sm, EAPOL_altAccept) &&
610 sm->decision != DECISION_FAIL) ||
611 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
612 sm->decision == DECISION_UNCOND_SUCC))
613 SM_ENTER(EAP, SUCCESS);
614 else if (eapol_get_bool(sm, EAPOL_altReject) ||
615 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
616 sm->decision != DECISION_UNCOND_SUCC) ||
617 (eapol_get_bool(sm, EAPOL_altAccept) &&
618 sm->methodState != METHOD_CONT &&
619 sm->decision == DECISION_FAIL))
620 SM_ENTER(EAP, FAILURE);
621 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
622 sm->leap_done && sm->decision != DECISION_FAIL &&
623 sm->methodState == METHOD_DONE)
624 SM_ENTER(EAP, SUCCESS);
625 else if (sm->selectedMethod == EAP_TYPE_PEAP &&
626 sm->peap_done && sm->decision != DECISION_FAIL &&
627 sm->methodState == METHOD_DONE)
628 SM_ENTER(EAP, SUCCESS);
632 static int eap_peer_req_is_duplicate(struct eap_sm *sm)
636 duplicate = (sm->reqId == sm->lastId) && sm->rxReq;
637 if (sm->workaround && duplicate &&
638 os_memcmp(sm->req_md5, sm->last_md5, 16) != 0) {
640 * RFC 4137 uses (reqId == lastId) as the only verification for
641 * duplicate EAP requests. However, this misses cases where the
642 * AS is incorrectly using the same id again; and
643 * unfortunately, such implementations exist. Use MD5 hash as
644 * an extra verification for the packets being duplicate to
645 * workaround these issues.
647 wpa_printf(MSG_DEBUG, "EAP: AS used the same Id again, but "
648 "EAP packets were not identical");
649 wpa_printf(MSG_DEBUG, "EAP: workaround - assume this is not a "
658 static void eap_peer_sm_step_received(struct eap_sm *sm)
660 int duplicate = eap_peer_req_is_duplicate(sm);
663 * Two special cases below for LEAP are local additions to work around
664 * odd LEAP behavior (EAP-Success in the middle of authentication and
665 * then swapped roles). Other transitions are based on RFC 4137.
667 if (sm->rxSuccess && sm->decision != DECISION_FAIL &&
668 (sm->reqId == sm->lastId ||
669 eap_success_workaround(sm, sm->reqId, sm->lastId)))
670 SM_ENTER(EAP, SUCCESS);
671 else if (sm->methodState != METHOD_CONT &&
673 sm->decision != DECISION_UNCOND_SUCC) ||
674 (sm->rxSuccess && sm->decision == DECISION_FAIL &&
675 (sm->selectedMethod != EAP_TYPE_LEAP ||
676 sm->methodState != METHOD_MAY_CONT))) &&
677 (sm->reqId == sm->lastId ||
678 eap_success_workaround(sm, sm->reqId, sm->lastId)))
679 SM_ENTER(EAP, FAILURE);
680 else if (sm->rxReq && duplicate)
681 SM_ENTER(EAP, RETRANSMIT);
682 else if (sm->rxReq && !duplicate &&
683 sm->reqMethod == EAP_TYPE_NOTIFICATION &&
684 sm->allowNotifications)
685 SM_ENTER(EAP, NOTIFICATION);
686 else if (sm->rxReq && !duplicate &&
687 sm->selectedMethod == EAP_TYPE_NONE &&
688 sm->reqMethod == EAP_TYPE_IDENTITY)
689 SM_ENTER(EAP, IDENTITY);
690 else if (sm->rxReq && !duplicate &&
691 sm->selectedMethod == EAP_TYPE_NONE &&
692 sm->reqMethod != EAP_TYPE_IDENTITY &&
693 sm->reqMethod != EAP_TYPE_NOTIFICATION)
694 SM_ENTER(EAP, GET_METHOD);
695 else if (sm->rxReq && !duplicate &&
696 sm->reqMethod == sm->selectedMethod &&
697 sm->methodState != METHOD_DONE)
698 SM_ENTER(EAP, METHOD);
699 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
700 (sm->rxSuccess || sm->rxResp))
701 SM_ENTER(EAP, METHOD);
703 SM_ENTER(EAP, DISCARD);
707 static void eap_peer_sm_step_local(struct eap_sm *sm)
709 switch (sm->EAP_state) {
714 if (eapol_get_bool(sm, EAPOL_portEnabled) &&
716 SM_ENTER(EAP, INITIALIZE);
719 eap_peer_sm_step_idle(sm);
722 eap_peer_sm_step_received(sm);
725 if (sm->selectedMethod == sm->reqMethod)
726 SM_ENTER(EAP, METHOD);
728 SM_ENTER(EAP, SEND_RESPONSE);
732 * Note: RFC 4137 uses methodState == DONE && decision == FAIL
733 * as the condition. eapRespData == NULL here is used to allow
734 * final EAP method response to be sent without having to change
735 * all methods to either use methodState MAY_CONT or leaving
736 * decision to something else than FAIL in cases where the only
737 * expected response is EAP-Failure.
740 SM_ENTER(EAP, DISCARD);
741 else if (sm->methodState == METHOD_DONE &&
742 sm->decision == DECISION_FAIL && !sm->eapRespData)
743 SM_ENTER(EAP, FAILURE);
745 SM_ENTER(EAP, SEND_RESPONSE);
747 case EAP_SEND_RESPONSE:
754 SM_ENTER(EAP, SEND_RESPONSE);
756 case EAP_NOTIFICATION:
757 SM_ENTER(EAP, SEND_RESPONSE);
760 SM_ENTER(EAP, SEND_RESPONSE);
772 /* Global transitions */
773 if (eapol_get_bool(sm, EAPOL_eapRestart) &&
774 eapol_get_bool(sm, EAPOL_portEnabled))
775 SM_ENTER_GLOBAL(EAP, INITIALIZE);
776 else if (!eapol_get_bool(sm, EAPOL_portEnabled) || sm->force_disabled)
777 SM_ENTER_GLOBAL(EAP, DISABLED);
778 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
779 /* RFC 4137 does not place any limit on number of EAP messages
780 * in an authentication session. However, some error cases have
781 * ended up in a state were EAP messages were sent between the
782 * peer and server in a loop (e.g., TLS ACK frame in both
783 * direction). Since this is quite undesired outcome, limit the
784 * total number of EAP round-trips and abort authentication if
785 * this limit is exceeded.
787 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
788 wpa_msg(sm->msg_ctx, MSG_INFO, "EAP: more than %d "
789 "authentication rounds - abort",
790 EAP_MAX_AUTH_ROUNDS);
792 SM_ENTER_GLOBAL(EAP, FAILURE);
795 /* Local transitions */
796 eap_peer_sm_step_local(sm);
801 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
804 if (!eap_allowed_method(sm, vendor, method)) {
805 wpa_printf(MSG_DEBUG, "EAP: configuration does not allow: "
806 "vendor %u method %u", vendor, method);
809 if (eap_peer_get_eap_method(vendor, method))
811 wpa_printf(MSG_DEBUG, "EAP: not included in build: "
812 "vendor %u method %u", vendor, method);
817 static struct wpabuf * eap_sm_build_expanded_nak(
818 struct eap_sm *sm, int id, const struct eap_method *methods,
823 const struct eap_method *m;
825 wpa_printf(MSG_DEBUG, "EAP: Building expanded EAP-Nak");
827 /* RFC 3748 - 5.3.2: Expanded Nak */
828 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_EXPANDED,
829 8 + 8 * (count + 1), EAP_CODE_RESPONSE, id);
833 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
834 wpabuf_put_be32(resp, EAP_TYPE_NAK);
836 for (m = methods; m; m = m->next) {
837 if (sm->reqVendor == m->vendor &&
838 sm->reqVendorMethod == m->method)
839 continue; /* do not allow the current method again */
840 if (eap_allowed_method(sm, m->vendor, m->method)) {
841 wpa_printf(MSG_DEBUG, "EAP: allowed type: "
842 "vendor=%u method=%u",
843 m->vendor, m->method);
844 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
845 wpabuf_put_be24(resp, m->vendor);
846 wpabuf_put_be32(resp, m->method);
852 wpa_printf(MSG_DEBUG, "EAP: no more allowed methods");
853 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
854 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
855 wpabuf_put_be32(resp, EAP_TYPE_NONE);
858 eap_update_len(resp);
864 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id)
868 int found = 0, expanded_found = 0;
870 const struct eap_method *methods, *m;
872 wpa_printf(MSG_DEBUG, "EAP: Building EAP-Nak (requested type %u "
873 "vendor=%u method=%u not allowed)", sm->reqMethod,
874 sm->reqVendor, sm->reqVendorMethod);
875 methods = eap_peer_get_methods(&count);
878 if (sm->reqMethod == EAP_TYPE_EXPANDED)
879 return eap_sm_build_expanded_nak(sm, id, methods, count);
881 /* RFC 3748 - 5.3.1: Legacy Nak */
882 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NAK,
883 sizeof(struct eap_hdr) + 1 + count + 1,
884 EAP_CODE_RESPONSE, id);
888 start = wpabuf_put(resp, 0);
889 for (m = methods; m; m = m->next) {
890 if (m->vendor == EAP_VENDOR_IETF && m->method == sm->reqMethod)
891 continue; /* do not allow the current method again */
892 if (eap_allowed_method(sm, m->vendor, m->method)) {
893 if (m->vendor != EAP_VENDOR_IETF) {
897 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
899 wpabuf_put_u8(resp, m->method);
904 wpabuf_put_u8(resp, EAP_TYPE_NONE);
905 wpa_hexdump(MSG_DEBUG, "EAP: allowed methods", start, found);
907 eap_update_len(resp);
913 static void eap_sm_processIdentity(struct eap_sm *sm, const struct wpabuf *req)
918 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
919 "EAP authentication started");
920 eap_notify_status(sm, "started", "");
922 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req,
928 * RFC 3748 - 5.1: Identity
929 * Data field may contain a displayable message in UTF-8. If this
930 * includes NUL-character, only the data before that should be
931 * displayed. Some EAP implementasitons may piggy-back additional
932 * options after the NUL.
934 /* TODO: could save displayable message so that it can be shown to the
935 * user in case of interaction is required */
936 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Identity data",
944 * Rules for figuring out MNC length based on IMSI for SIM cards that do not
945 * include MNC length field.
947 static int mnc_len_from_imsi(const char *imsi)
952 os_memcpy(mcc_str, imsi, 3);
957 return 2; /* Networks in Switzerland use 2-digit MNC */
959 return 2; /* Networks in Finland use 2-digit MNC */
965 static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
966 size_t max_len, size_t *imsi_len)
971 if (*imsi_len + 36 > max_len) {
972 wpa_printf(MSG_WARNING, "No room for realm in IMSI buffer");
976 /* MNC (2 or 3 digits) */
977 mnc_len = scard_get_mnc_len(sm->scard_ctx);
979 mnc_len = mnc_len_from_imsi(imsi);
981 wpa_printf(MSG_INFO, "Failed to get MNC length from (U)SIM "
990 } else if (mnc_len == 3) {
997 pos = imsi + *imsi_len;
998 pos += os_snprintf(pos, imsi + max_len - pos,
999 "@wlan.mnc%s.mcc%c%c%c.3gppnetwork.org",
1000 mnc, imsi[0], imsi[1], imsi[2]);
1001 *imsi_len = pos - imsi;
1007 static int eap_sm_imsi_identity(struct eap_sm *sm,
1008 struct eap_peer_config *conf)
1010 enum { EAP_SM_SIM, EAP_SM_AKA, EAP_SM_AKA_PRIME } method = EAP_SM_SIM;
1013 struct eap_method_type *m = conf->eap_methods;
1016 imsi_len = sizeof(imsi);
1017 if (scard_get_imsi(sm->scard_ctx, imsi, &imsi_len)) {
1018 wpa_printf(MSG_WARNING, "Failed to get IMSI from SIM");
1022 wpa_hexdump_ascii(MSG_DEBUG, "IMSI", (u8 *) imsi, imsi_len);
1025 wpa_printf(MSG_WARNING, "Too short IMSI for SIM identity");
1029 if (eap_sm_append_3gpp_realm(sm, imsi, sizeof(imsi), &imsi_len) < 0) {
1030 wpa_printf(MSG_WARNING, "Could not add realm to SIM identity");
1033 wpa_hexdump_ascii(MSG_DEBUG, "IMSI + realm", (u8 *) imsi, imsi_len);
1035 for (i = 0; m && (m[i].vendor != EAP_VENDOR_IETF ||
1036 m[i].method != EAP_TYPE_NONE); i++) {
1037 if (m[i].vendor == EAP_VENDOR_IETF &&
1038 m[i].method == EAP_TYPE_AKA_PRIME) {
1039 method = EAP_SM_AKA_PRIME;
1043 if (m[i].vendor == EAP_VENDOR_IETF &&
1044 m[i].method == EAP_TYPE_AKA) {
1045 method = EAP_SM_AKA;
1050 os_free(conf->identity);
1051 conf->identity = os_malloc(1 + imsi_len);
1052 if (conf->identity == NULL) {
1053 wpa_printf(MSG_WARNING, "Failed to allocate buffer for "
1054 "IMSI-based identity");
1060 conf->identity[0] = '1';
1063 conf->identity[0] = '0';
1065 case EAP_SM_AKA_PRIME:
1066 conf->identity[0] = '6';
1069 os_memcpy(conf->identity + 1, imsi, imsi_len);
1070 conf->identity_len = 1 + imsi_len;
1075 #endif /* PCSC_FUNCS */
1078 static int eap_sm_set_scard_pin(struct eap_sm *sm,
1079 struct eap_peer_config *conf)
1082 if (scard_set_pin(sm->scard_ctx, conf->pin)) {
1084 * Make sure the same PIN is not tried again in order to avoid
1090 wpa_printf(MSG_WARNING, "PIN validation failed");
1091 eap_sm_request_pin(sm);
1095 #else /* PCSC_FUNCS */
1097 #endif /* PCSC_FUNCS */
1100 static int eap_sm_get_scard_identity(struct eap_sm *sm,
1101 struct eap_peer_config *conf)
1104 if (eap_sm_set_scard_pin(sm, conf))
1107 return eap_sm_imsi_identity(sm, conf);
1108 #else /* PCSC_FUNCS */
1110 #endif /* PCSC_FUNCS */
1115 * eap_sm_buildIdentity - Build EAP-Identity/Response for the current network
1116 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1117 * @id: EAP identifier for the packet
1118 * @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
1119 * Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
1122 * This function allocates and builds an EAP-Identity/Response packet for the
1123 * current network. The caller is responsible for freeing the returned data.
1125 struct wpabuf * eap_sm_buildIdentity(struct eap_sm *sm, int id, int encrypted)
1127 struct eap_peer_config *config = eap_get_config(sm);
1128 struct wpabuf *resp;
1130 size_t identity_len;
1132 if (config == NULL) {
1133 wpa_printf(MSG_WARNING, "EAP: buildIdentity: configuration "
1134 "was not available");
1138 if (sm->m && sm->m->get_identity &&
1139 (identity = sm->m->get_identity(sm, sm->eap_method_priv,
1140 &identity_len)) != NULL) {
1141 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using method re-auth "
1142 "identity", identity, identity_len);
1143 } else if (!encrypted && config->anonymous_identity) {
1144 identity = config->anonymous_identity;
1145 identity_len = config->anonymous_identity_len;
1146 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using anonymous identity",
1147 identity, identity_len);
1149 identity = config->identity;
1150 identity_len = config->identity_len;
1151 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using real identity",
1152 identity, identity_len);
1155 if (identity == NULL) {
1156 wpa_printf(MSG_WARNING, "EAP: buildIdentity: identity "
1157 "configuration was not available");
1159 if (eap_sm_get_scard_identity(sm, config) < 0)
1161 identity = config->identity;
1162 identity_len = config->identity_len;
1163 wpa_hexdump_ascii(MSG_DEBUG, "permanent identity from "
1164 "IMSI", identity, identity_len);
1166 eap_sm_request_identity(sm);
1169 } else if (config->pcsc) {
1170 if (eap_sm_set_scard_pin(sm, config) < 0)
1174 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, identity_len,
1175 EAP_CODE_RESPONSE, id);
1179 wpabuf_put_data(resp, identity, identity_len);
1185 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req)
1191 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, req,
1195 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Notification data",
1198 msg = os_malloc(msg_len + 1);
1201 for (i = 0; i < msg_len; i++)
1202 msg[i] = isprint(pos[i]) ? (char) pos[i] : '_';
1203 msg[msg_len] = '\0';
1204 wpa_msg(sm->msg_ctx, MSG_INFO, "%s%s",
1205 WPA_EVENT_EAP_NOTIFICATION, msg);
1210 static struct wpabuf * eap_sm_buildNotify(int id)
1212 struct wpabuf *resp;
1214 wpa_printf(MSG_DEBUG, "EAP: Generating EAP-Response Notification");
1215 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, 0,
1216 EAP_CODE_RESPONSE, id);
1224 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req)
1226 const struct eap_hdr *hdr;
1230 sm->rxReq = sm->rxResp = sm->rxSuccess = sm->rxFailure = FALSE;
1232 sm->reqMethod = EAP_TYPE_NONE;
1233 sm->reqVendor = EAP_VENDOR_IETF;
1234 sm->reqVendorMethod = EAP_TYPE_NONE;
1236 if (req == NULL || wpabuf_len(req) < sizeof(*hdr))
1239 hdr = wpabuf_head(req);
1240 plen = be_to_host16(hdr->length);
1241 if (plen > wpabuf_len(req)) {
1242 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
1243 "(len=%lu plen=%lu)",
1244 (unsigned long) wpabuf_len(req),
1245 (unsigned long) plen);
1249 sm->reqId = hdr->identifier;
1251 if (sm->workaround) {
1253 addr[0] = wpabuf_head(req);
1254 md5_vector(1, addr, &plen, sm->req_md5);
1257 switch (hdr->code) {
1258 case EAP_CODE_REQUEST:
1259 if (plen < sizeof(*hdr) + 1) {
1260 wpa_printf(MSG_DEBUG, "EAP: Too short EAP-Request - "
1265 pos = (const u8 *) (hdr + 1);
1266 sm->reqMethod = *pos++;
1267 if (sm->reqMethod == EAP_TYPE_EXPANDED) {
1268 if (plen < sizeof(*hdr) + 8) {
1269 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
1270 "expanded EAP-Packet (plen=%lu)",
1271 (unsigned long) plen);
1274 sm->reqVendor = WPA_GET_BE24(pos);
1276 sm->reqVendorMethod = WPA_GET_BE32(pos);
1278 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Request id=%d "
1279 "method=%u vendor=%u vendorMethod=%u",
1280 sm->reqId, sm->reqMethod, sm->reqVendor,
1281 sm->reqVendorMethod);
1283 case EAP_CODE_RESPONSE:
1284 if (sm->selectedMethod == EAP_TYPE_LEAP) {
1286 * LEAP differs from RFC 4137 by using reversed roles
1287 * for mutual authentication and because of this, we
1288 * need to accept EAP-Response frames if LEAP is used.
1290 if (plen < sizeof(*hdr) + 1) {
1291 wpa_printf(MSG_DEBUG, "EAP: Too short "
1292 "EAP-Response - no Type field");
1296 pos = (const u8 *) (hdr + 1);
1297 sm->reqMethod = *pos;
1298 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Response for "
1299 "LEAP method=%d id=%d",
1300 sm->reqMethod, sm->reqId);
1303 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Response");
1305 case EAP_CODE_SUCCESS:
1306 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Success");
1307 eap_notify_status(sm, "completion", "success");
1308 sm->rxSuccess = TRUE;
1310 case EAP_CODE_FAILURE:
1311 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Failure");
1312 eap_notify_status(sm, "completion", "failure");
1313 sm->rxFailure = TRUE;
1316 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Packet with unknown "
1317 "code %d", hdr->code);
1323 static void eap_peer_sm_tls_event(void *ctx, enum tls_event ev,
1324 union tls_event_data *data)
1326 struct eap_sm *sm = ctx;
1327 char *hash_hex = NULL;
1330 case TLS_CERT_CHAIN_SUCCESS:
1331 eap_notify_status(sm, "remote certificate verification",
1334 case TLS_CERT_CHAIN_FAILURE:
1335 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TLS_CERT_ERROR
1336 "reason=%d depth=%d subject='%s' err='%s'",
1337 data->cert_fail.reason,
1338 data->cert_fail.depth,
1339 data->cert_fail.subject,
1340 data->cert_fail.reason_txt);
1341 eap_notify_status(sm, "remote certificate verification",
1342 data->cert_fail.reason_txt);
1344 case TLS_PEER_CERTIFICATE:
1345 if (!sm->eapol_cb->notify_cert)
1348 if (data->peer_cert.hash) {
1349 size_t len = data->peer_cert.hash_len * 2 + 1;
1350 hash_hex = os_malloc(len);
1352 wpa_snprintf_hex(hash_hex, len,
1353 data->peer_cert.hash,
1354 data->peer_cert.hash_len);
1358 sm->eapol_cb->notify_cert(sm->eapol_ctx,
1359 data->peer_cert.depth,
1360 data->peer_cert.subject,
1361 hash_hex, data->peer_cert.cert);
1364 if (data->alert.is_local)
1365 eap_notify_status(sm, "local TLS alert",
1366 data->alert.description);
1368 eap_notify_status(sm, "remote TLS alert",
1369 data->alert.description);
1378 * eap_peer_sm_init - Allocate and initialize EAP peer state machine
1379 * @eapol_ctx: Context data to be used with eapol_cb calls
1380 * @eapol_cb: Pointer to EAPOL callback functions
1381 * @msg_ctx: Context data for wpa_msg() calls
1382 * @conf: EAP configuration
1383 * Returns: Pointer to the allocated EAP state machine or %NULL on failure
1385 * This function allocates and initializes an EAP state machine. In addition,
1386 * this initializes TLS library for the new EAP state machine. eapol_cb pointer
1387 * will be in use until eap_peer_sm_deinit() is used to deinitialize this EAP
1388 * state machine. Consequently, the caller must make sure that this data
1389 * structure remains alive while the EAP state machine is active.
1391 struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
1392 struct eapol_callbacks *eapol_cb,
1393 void *msg_ctx, struct eap_config *conf)
1396 struct tls_config tlsconf;
1398 sm = os_zalloc(sizeof(*sm));
1401 sm->eapol_ctx = eapol_ctx;
1402 sm->eapol_cb = eapol_cb;
1403 sm->msg_ctx = msg_ctx;
1404 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
1405 sm->wps = conf->wps;
1407 os_memset(&tlsconf, 0, sizeof(tlsconf));
1408 tlsconf.opensc_engine_path = conf->opensc_engine_path;
1409 tlsconf.pkcs11_engine_path = conf->pkcs11_engine_path;
1410 tlsconf.pkcs11_module_path = conf->pkcs11_module_path;
1412 tlsconf.fips_mode = 1;
1413 #endif /* CONFIG_FIPS */
1414 tlsconf.event_cb = eap_peer_sm_tls_event;
1415 tlsconf.cb_ctx = sm;
1416 tlsconf.cert_in_cb = conf->cert_in_cb;
1417 sm->ssl_ctx = tls_init(&tlsconf);
1418 if (sm->ssl_ctx == NULL) {
1419 wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS "
1425 sm->ssl_ctx2 = tls_init(&tlsconf);
1426 if (sm->ssl_ctx2 == NULL) {
1427 wpa_printf(MSG_INFO, "SSL: Failed to initialize TLS "
1429 /* Run without separate TLS context within TLS tunnel */
1437 * eap_peer_sm_deinit - Deinitialize and free an EAP peer state machine
1438 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1440 * This function deinitializes EAP state machine and frees all allocated
1443 void eap_peer_sm_deinit(struct eap_sm *sm)
1447 eap_deinit_prev_method(sm, "EAP deinit");
1450 tls_deinit(sm->ssl_ctx2);
1451 tls_deinit(sm->ssl_ctx);
1457 * eap_peer_sm_step - Step EAP peer state machine
1458 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1459 * Returns: 1 if EAP state was changed or 0 if not
1461 * This function advances EAP state machine to a new state to match with the
1462 * current variables. This should be called whenever variables used by the EAP
1463 * state machine have changed.
1465 int eap_peer_sm_step(struct eap_sm *sm)
1469 sm->changed = FALSE;
1473 } while (sm->changed);
1479 * eap_sm_abort - Abort EAP authentication
1480 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1482 * Release system resources that have been allocated for the authentication
1483 * session without fully deinitializing the EAP state machine.
1485 void eap_sm_abort(struct eap_sm *sm)
1487 wpabuf_free(sm->lastRespData);
1488 sm->lastRespData = NULL;
1489 wpabuf_free(sm->eapRespData);
1490 sm->eapRespData = NULL;
1491 os_free(sm->eapKeyData);
1492 sm->eapKeyData = NULL;
1493 os_free(sm->eapSessionId);
1494 sm->eapSessionId = NULL;
1496 /* This is not clearly specified in the EAP statemachines draft, but
1497 * it seems necessary to make sure that some of the EAPOL variables get
1498 * cleared for the next authentication. */
1499 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
1503 #ifdef CONFIG_CTRL_IFACE
1504 static const char * eap_sm_state_txt(int state)
1507 case EAP_INITIALIZE:
1508 return "INITIALIZE";
1515 case EAP_GET_METHOD:
1516 return "GET_METHOD";
1519 case EAP_SEND_RESPONSE:
1520 return "SEND_RESPONSE";
1525 case EAP_NOTIFICATION:
1526 return "NOTIFICATION";
1527 case EAP_RETRANSMIT:
1528 return "RETRANSMIT";
1537 #endif /* CONFIG_CTRL_IFACE */
1540 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1541 static const char * eap_sm_method_state_txt(EapMethodState state)
1550 case METHOD_MAY_CONT:
1560 static const char * eap_sm_decision_txt(EapDecision decision)
1565 case DECISION_COND_SUCC:
1567 case DECISION_UNCOND_SUCC:
1568 return "UNCOND_SUCC";
1573 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1576 #ifdef CONFIG_CTRL_IFACE
1579 * eap_sm_get_status - Get EAP state machine status
1580 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1581 * @buf: Buffer for status information
1582 * @buflen: Maximum buffer length
1583 * @verbose: Whether to include verbose status information
1584 * Returns: Number of bytes written to buf.
1586 * Query EAP state machine for status information. This function fills in a
1587 * text area with current status information from the EAPOL state machine. If
1588 * the buffer (buf) is not large enough, status information will be truncated
1589 * to fit the buffer.
1591 int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
1598 len = os_snprintf(buf, buflen,
1600 eap_sm_state_txt(sm->EAP_state));
1601 if (len < 0 || (size_t) len >= buflen)
1604 if (sm->selectedMethod != EAP_TYPE_NONE) {
1609 const struct eap_method *m =
1610 eap_peer_get_eap_method(EAP_VENDOR_IETF,
1611 sm->selectedMethod);
1617 ret = os_snprintf(buf + len, buflen - len,
1618 "selectedMethod=%d (EAP-%s)\n",
1619 sm->selectedMethod, name);
1620 if (ret < 0 || (size_t) ret >= buflen - len)
1624 if (sm->m && sm->m->get_status) {
1625 len += sm->m->get_status(sm, sm->eap_method_priv,
1626 buf + len, buflen - len,
1632 ret = os_snprintf(buf + len, buflen - len,
1636 "ClientTimeout=%d\n",
1638 eap_sm_method_state_txt(sm->methodState),
1639 eap_sm_decision_txt(sm->decision),
1641 if (ret < 0 || (size_t) ret >= buflen - len)
1648 #endif /* CONFIG_CTRL_IFACE */
1651 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1652 static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
1653 const char *msg, size_t msglen)
1655 struct eap_peer_config *config;
1656 const char *txt = NULL;
1661 config = eap_get_config(sm);
1666 case WPA_CTRL_REQ_EAP_IDENTITY:
1667 config->pending_req_identity++;
1669 case WPA_CTRL_REQ_EAP_PASSWORD:
1670 config->pending_req_password++;
1672 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
1673 config->pending_req_new_password++;
1675 case WPA_CTRL_REQ_EAP_PIN:
1676 config->pending_req_pin++;
1678 case WPA_CTRL_REQ_EAP_OTP:
1680 tmp = os_malloc(msglen + 3);
1684 os_memcpy(tmp + 1, msg, msglen);
1685 tmp[msglen + 1] = ']';
1686 tmp[msglen + 2] = '\0';
1688 os_free(config->pending_req_otp);
1689 config->pending_req_otp = tmp;
1690 config->pending_req_otp_len = msglen + 3;
1692 if (config->pending_req_otp == NULL)
1694 txt = config->pending_req_otp;
1697 case WPA_CTRL_REQ_EAP_PASSPHRASE:
1698 config->pending_req_passphrase++;
1700 case WPA_CTRL_REQ_SIM:
1707 if (sm->eapol_cb->eap_param_needed)
1708 sm->eapol_cb->eap_param_needed(sm->eapol_ctx, field, txt);
1710 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1711 #define eap_sm_request(sm, type, msg, msglen) do { } while (0)
1712 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1714 const char * eap_sm_get_method_name(struct eap_sm *sm)
1723 * eap_sm_request_identity - Request identity from user (ctrl_iface)
1724 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1726 * EAP methods can call this function to request identity information for the
1727 * current network. This is normally called when the identity is not included
1728 * in the network configuration. The request will be sent to monitor programs
1729 * through the control interface.
1731 void eap_sm_request_identity(struct eap_sm *sm)
1733 eap_sm_request(sm, WPA_CTRL_REQ_EAP_IDENTITY, NULL, 0);
1738 * eap_sm_request_password - Request password from user (ctrl_iface)
1739 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1741 * EAP methods can call this function to request password information for the
1742 * current network. This is normally called when the password is not included
1743 * in the network configuration. The request will be sent to monitor programs
1744 * through the control interface.
1746 void eap_sm_request_password(struct eap_sm *sm)
1748 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSWORD, NULL, 0);
1753 * eap_sm_request_new_password - Request new password from user (ctrl_iface)
1754 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1756 * EAP methods can call this function to request new password information for
1757 * the current network. This is normally called when the EAP method indicates
1758 * that the current password has expired and password change is required. The
1759 * request will be sent to monitor programs through the control interface.
1761 void eap_sm_request_new_password(struct eap_sm *sm)
1763 eap_sm_request(sm, WPA_CTRL_REQ_EAP_NEW_PASSWORD, NULL, 0);
1768 * eap_sm_request_pin - Request SIM or smart card PIN from user (ctrl_iface)
1769 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1771 * EAP methods can call this function to request SIM or smart card PIN
1772 * information for the current network. This is normally called when the PIN is
1773 * not included in the network configuration. The request will be sent to
1774 * monitor programs through the control interface.
1776 void eap_sm_request_pin(struct eap_sm *sm)
1778 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PIN, NULL, 0);
1783 * eap_sm_request_otp - Request one time password from user (ctrl_iface)
1784 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1785 * @msg: Message to be displayed to the user when asking for OTP
1786 * @msg_len: Length of the user displayable message
1788 * EAP methods can call this function to request open time password (OTP) for
1789 * the current network. The request will be sent to monitor programs through
1790 * the control interface.
1792 void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
1794 eap_sm_request(sm, WPA_CTRL_REQ_EAP_OTP, msg, msg_len);
1799 * eap_sm_request_passphrase - Request passphrase from user (ctrl_iface)
1800 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1802 * EAP methods can call this function to request passphrase for a private key
1803 * for the current network. This is normally called when the passphrase is not
1804 * included in the network configuration. The request will be sent to monitor
1805 * programs through the control interface.
1807 void eap_sm_request_passphrase(struct eap_sm *sm)
1809 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSPHRASE, NULL, 0);
1814 * eap_sm_request_sim - Request external SIM processing
1815 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1816 * @req: EAP method specific request
1818 void eap_sm_request_sim(struct eap_sm *sm, const char *req)
1820 eap_sm_request(sm, WPA_CTRL_REQ_SIM, req, os_strlen(req));
1825 * eap_sm_notify_ctrl_attached - Notification of attached monitor
1826 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1828 * Notify EAP state machines that a monitor was attached to the control
1829 * interface to trigger re-sending of pending requests for user input.
1831 void eap_sm_notify_ctrl_attached(struct eap_sm *sm)
1833 struct eap_peer_config *config = eap_get_config(sm);
1838 /* Re-send any pending requests for user data since a new control
1839 * interface was added. This handles cases where the EAP authentication
1840 * starts immediately after system startup when the user interface is
1841 * not yet running. */
1842 if (config->pending_req_identity)
1843 eap_sm_request_identity(sm);
1844 if (config->pending_req_password)
1845 eap_sm_request_password(sm);
1846 if (config->pending_req_new_password)
1847 eap_sm_request_new_password(sm);
1848 if (config->pending_req_otp)
1849 eap_sm_request_otp(sm, NULL, 0);
1850 if (config->pending_req_pin)
1851 eap_sm_request_pin(sm);
1852 if (config->pending_req_passphrase)
1853 eap_sm_request_passphrase(sm);
1857 static int eap_allowed_phase2_type(int vendor, int type)
1859 if (vendor != EAP_VENDOR_IETF)
1861 return type != EAP_TYPE_PEAP && type != EAP_TYPE_TTLS &&
1862 type != EAP_TYPE_FAST;
1867 * eap_get_phase2_type - Get EAP type for the given EAP phase 2 method name
1868 * @name: EAP method name, e.g., MD5
1869 * @vendor: Buffer for returning EAP Vendor-Id
1870 * Returns: EAP method type or %EAP_TYPE_NONE if not found
1872 * This function maps EAP type names into EAP type numbers that are allowed for
1873 * Phase 2, i.e., for tunneled authentication. Phase 2 is used, e.g., with
1874 * EAP-PEAP, EAP-TTLS, and EAP-FAST.
1876 u32 eap_get_phase2_type(const char *name, int *vendor)
1879 u8 type = eap_peer_get_type(name, &v);
1880 if (eap_allowed_phase2_type(v, type)) {
1884 *vendor = EAP_VENDOR_IETF;
1885 return EAP_TYPE_NONE;
1890 * eap_get_phase2_types - Get list of allowed EAP phase 2 types
1891 * @config: Pointer to a network configuration
1892 * @count: Pointer to a variable to be filled with number of returned EAP types
1893 * Returns: Pointer to allocated type list or %NULL on failure
1895 * This function generates an array of allowed EAP phase 2 (tunneled) types for
1896 * the given network configuration.
1898 struct eap_method_type * eap_get_phase2_types(struct eap_peer_config *config,
1901 struct eap_method_type *buf;
1905 const struct eap_method *methods, *m;
1907 methods = eap_peer_get_methods(&mcount);
1908 if (methods == NULL)
1911 buf = os_malloc(mcount * sizeof(struct eap_method_type));
1915 for (m = methods; m; m = m->next) {
1918 if (eap_allowed_phase2_type(vendor, method)) {
1919 if (vendor == EAP_VENDOR_IETF &&
1920 method == EAP_TYPE_TLS && config &&
1921 config->private_key2 == NULL)
1923 buf[*count].vendor = vendor;
1924 buf[*count].method = method;
1934 * eap_set_fast_reauth - Update fast_reauth setting
1935 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1936 * @enabled: 1 = Fast reauthentication is enabled, 0 = Disabled
1938 void eap_set_fast_reauth(struct eap_sm *sm, int enabled)
1940 sm->fast_reauth = enabled;
1945 * eap_set_workaround - Update EAP workarounds setting
1946 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1947 * @workaround: 1 = Enable EAP workarounds, 0 = Disable EAP workarounds
1949 void eap_set_workaround(struct eap_sm *sm, unsigned int workaround)
1951 sm->workaround = workaround;
1956 * eap_get_config - Get current network configuration
1957 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1958 * Returns: Pointer to the current network configuration or %NULL if not found
1960 * EAP peer methods should avoid using this function if they can use other
1961 * access functions, like eap_get_config_identity() and
1962 * eap_get_config_password(), that do not require direct access to
1963 * struct eap_peer_config.
1965 struct eap_peer_config * eap_get_config(struct eap_sm *sm)
1967 return sm->eapol_cb->get_config(sm->eapol_ctx);
1972 * eap_get_config_identity - Get identity from the network configuration
1973 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1974 * @len: Buffer for the length of the identity
1975 * Returns: Pointer to the identity or %NULL if not found
1977 const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len)
1979 struct eap_peer_config *config = eap_get_config(sm);
1982 *len = config->identity_len;
1983 return config->identity;
1987 static int eap_get_ext_password(struct eap_sm *sm,
1988 struct eap_peer_config *config)
1992 if (config->password == NULL)
1995 name = os_zalloc(config->password_len + 1);
1998 os_memcpy(name, config->password, config->password_len);
2000 ext_password_free(sm->ext_pw_buf);
2001 sm->ext_pw_buf = ext_password_get(sm->ext_pw, name);
2004 return sm->ext_pw_buf == NULL ? -1 : 0;
2009 * eap_get_config_password - Get password from the network configuration
2010 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2011 * @len: Buffer for the length of the password
2012 * Returns: Pointer to the password or %NULL if not found
2014 const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len)
2016 struct eap_peer_config *config = eap_get_config(sm);
2020 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2021 if (eap_get_ext_password(sm, config) < 0)
2023 *len = wpabuf_len(sm->ext_pw_buf);
2024 return wpabuf_head(sm->ext_pw_buf);
2027 *len = config->password_len;
2028 return config->password;
2033 * eap_get_config_password2 - Get password from the network configuration
2034 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2035 * @len: Buffer for the length of the password
2036 * @hash: Buffer for returning whether the password is stored as a
2037 * NtPasswordHash instead of plaintext password; can be %NULL if this
2038 * information is not needed
2039 * Returns: Pointer to the password or %NULL if not found
2041 const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash)
2043 struct eap_peer_config *config = eap_get_config(sm);
2047 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2048 if (eap_get_ext_password(sm, config) < 0)
2052 *len = wpabuf_len(sm->ext_pw_buf);
2053 return wpabuf_head(sm->ext_pw_buf);
2056 *len = config->password_len;
2058 *hash = !!(config->flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH);
2059 return config->password;
2064 * eap_get_config_new_password - Get new password from network configuration
2065 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2066 * @len: Buffer for the length of the new password
2067 * Returns: Pointer to the new password or %NULL if not found
2069 const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len)
2071 struct eap_peer_config *config = eap_get_config(sm);
2074 *len = config->new_password_len;
2075 return config->new_password;
2080 * eap_get_config_otp - Get one-time password from the network configuration
2081 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2082 * @len: Buffer for the length of the one-time password
2083 * Returns: Pointer to the one-time password or %NULL if not found
2085 const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len)
2087 struct eap_peer_config *config = eap_get_config(sm);
2090 *len = config->otp_len;
2096 * eap_clear_config_otp - Clear used one-time password
2097 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2099 * This function clears a used one-time password (OTP) from the current network
2100 * configuration. This should be called when the OTP has been used and is not
2103 void eap_clear_config_otp(struct eap_sm *sm)
2105 struct eap_peer_config *config = eap_get_config(sm);
2108 os_memset(config->otp, 0, config->otp_len);
2109 os_free(config->otp);
2111 config->otp_len = 0;
2116 * eap_get_config_phase1 - Get phase1 data from the network configuration
2117 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2118 * Returns: Pointer to the phase1 data or %NULL if not found
2120 const char * eap_get_config_phase1(struct eap_sm *sm)
2122 struct eap_peer_config *config = eap_get_config(sm);
2125 return config->phase1;
2130 * eap_get_config_phase2 - Get phase2 data from the network configuration
2131 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2132 * Returns: Pointer to the phase1 data or %NULL if not found
2134 const char * eap_get_config_phase2(struct eap_sm *sm)
2136 struct eap_peer_config *config = eap_get_config(sm);
2139 return config->phase2;
2143 int eap_get_config_fragment_size(struct eap_sm *sm)
2145 struct eap_peer_config *config = eap_get_config(sm);
2148 return config->fragment_size;
2153 * eap_key_available - Get key availability (eapKeyAvailable variable)
2154 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2155 * Returns: 1 if EAP keying material is available, 0 if not
2157 int eap_key_available(struct eap_sm *sm)
2159 return sm ? sm->eapKeyAvailable : 0;
2164 * eap_notify_success - Notify EAP state machine about external success trigger
2165 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2167 * This function is called when external event, e.g., successful completion of
2168 * WPA-PSK key handshake, is indicating that EAP state machine should move to
2169 * success state. This is mainly used with security modes that do not use EAP
2170 * state machine (e.g., WPA-PSK).
2172 void eap_notify_success(struct eap_sm *sm)
2175 sm->decision = DECISION_COND_SUCC;
2176 sm->EAP_state = EAP_SUCCESS;
2182 * eap_notify_lower_layer_success - Notification of lower layer success
2183 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2185 * Notify EAP state machines that a lower layer has detected a successful
2186 * authentication. This is used to recover from dropped EAP-Success messages.
2188 void eap_notify_lower_layer_success(struct eap_sm *sm)
2193 if (eapol_get_bool(sm, EAPOL_eapSuccess) ||
2194 sm->decision == DECISION_FAIL ||
2195 (sm->methodState != METHOD_MAY_CONT &&
2196 sm->methodState != METHOD_DONE))
2199 if (sm->eapKeyData != NULL)
2200 sm->eapKeyAvailable = TRUE;
2201 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
2202 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
2203 "EAP authentication completed successfully (based on lower "
2209 * eap_get_eapSessionId - Get Session-Id from EAP state machine
2210 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2211 * @len: Pointer to variable that will be set to number of bytes in the session
2212 * Returns: Pointer to the EAP Session-Id or %NULL on failure
2214 * Fetch EAP Session-Id from the EAP state machine. The Session-Id is available
2215 * only after a successful authentication. EAP state machine continues to manage
2216 * the Session-Id and the caller must not change or free the returned data.
2218 const u8 * eap_get_eapSessionId(struct eap_sm *sm, size_t *len)
2220 if (sm == NULL || sm->eapSessionId == NULL) {
2225 *len = sm->eapSessionIdLen;
2226 return sm->eapSessionId;
2231 * eap_get_eapKeyData - Get master session key (MSK) from EAP state machine
2232 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2233 * @len: Pointer to variable that will be set to number of bytes in the key
2234 * Returns: Pointer to the EAP keying data or %NULL on failure
2236 * Fetch EAP keying material (MSK, eapKeyData) from the EAP state machine. The
2237 * key is available only after a successful authentication. EAP state machine
2238 * continues to manage the key data and the caller must not change or free the
2241 const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len)
2243 if (sm == NULL || sm->eapKeyData == NULL) {
2248 *len = sm->eapKeyDataLen;
2249 return sm->eapKeyData;
2254 * eap_get_eapKeyData - Get EAP response data
2255 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2256 * Returns: Pointer to the EAP response (eapRespData) or %NULL on failure
2258 * Fetch EAP response (eapRespData) from the EAP state machine. This data is
2259 * available when EAP state machine has processed an incoming EAP request. The
2260 * EAP state machine does not maintain a reference to the response after this
2261 * function is called and the caller is responsible for freeing the data.
2263 struct wpabuf * eap_get_eapRespData(struct eap_sm *sm)
2265 struct wpabuf *resp;
2267 if (sm == NULL || sm->eapRespData == NULL)
2270 resp = sm->eapRespData;
2271 sm->eapRespData = NULL;
2278 * eap_sm_register_scard_ctx - Notification of smart card context
2279 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2280 * @ctx: Context data for smart card operations
2282 * Notify EAP state machines of context data for smart card operations. This
2283 * context data will be used as a parameter for scard_*() functions.
2285 void eap_register_scard_ctx(struct eap_sm *sm, void *ctx)
2288 sm->scard_ctx = ctx;
2293 * eap_set_config_blob - Set or add a named configuration blob
2294 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2295 * @blob: New value for the blob
2297 * Adds a new configuration blob or replaces the current value of an existing
2300 void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob)
2302 #ifndef CONFIG_NO_CONFIG_BLOBS
2303 sm->eapol_cb->set_config_blob(sm->eapol_ctx, blob);
2304 #endif /* CONFIG_NO_CONFIG_BLOBS */
2309 * eap_get_config_blob - Get a named configuration blob
2310 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2311 * @name: Name of the blob
2312 * Returns: Pointer to blob data or %NULL if not found
2314 const struct wpa_config_blob * eap_get_config_blob(struct eap_sm *sm,
2317 #ifndef CONFIG_NO_CONFIG_BLOBS
2318 return sm->eapol_cb->get_config_blob(sm->eapol_ctx, name);
2319 #else /* CONFIG_NO_CONFIG_BLOBS */
2321 #endif /* CONFIG_NO_CONFIG_BLOBS */
2326 * eap_set_force_disabled - Set force_disabled flag
2327 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2328 * @disabled: 1 = EAP disabled, 0 = EAP enabled
2330 * This function is used to force EAP state machine to be disabled when it is
2331 * not in use (e.g., with WPA-PSK or plaintext connections).
2333 void eap_set_force_disabled(struct eap_sm *sm, int disabled)
2335 sm->force_disabled = disabled;
2340 * eap_set_external_sim - Set external_sim flag
2341 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2342 * @external_sim: Whether external SIM/USIM processing is used
2344 void eap_set_external_sim(struct eap_sm *sm, int external_sim)
2346 sm->external_sim = external_sim;
2351 * eap_notify_pending - Notify that EAP method is ready to re-process a request
2352 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2354 * An EAP method can perform a pending operation (e.g., to get a response from
2355 * an external process). Once the response is available, this function can be
2356 * used to request EAPOL state machine to retry delivering the previously
2357 * received (and still unanswered) EAP request to EAP state machine.
2359 void eap_notify_pending(struct eap_sm *sm)
2361 sm->eapol_cb->notify_pending(sm->eapol_ctx);
2366 * eap_invalidate_cached_session - Mark cached session data invalid
2367 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2369 void eap_invalidate_cached_session(struct eap_sm *sm)
2372 eap_deinit_prev_method(sm, "invalidate");
2376 int eap_is_wps_pbc_enrollee(struct eap_peer_config *conf)
2378 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2379 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2380 return 0; /* Not a WPS Enrollee */
2382 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pbc=1") == NULL)
2383 return 0; /* Not using PBC */
2389 int eap_is_wps_pin_enrollee(struct eap_peer_config *conf)
2391 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2392 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2393 return 0; /* Not a WPS Enrollee */
2395 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pin=") == NULL)
2396 return 0; /* Not using PIN */
2402 void eap_sm_set_ext_pw_ctx(struct eap_sm *sm, struct ext_password_data *ext)
2404 ext_password_free(sm->ext_pw_buf);
2405 sm->ext_pw_buf = NULL;
2411 * eap_set_anon_id - Set or add anonymous identity
2412 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2413 * @id: Anonymous identity (e.g., EAP-SIM pseudonym) or %NULL to clear
2414 * @len: Length of anonymous identity in octets
2416 void eap_set_anon_id(struct eap_sm *sm, const u8 *id, size_t len)
2418 if (sm->eapol_cb->set_anon_id)
2419 sm->eapol_cb->set_anon_id(sm->eapol_ctx, id, len);
2423 int eap_peer_was_failure_expected(struct eap_sm *sm)
2425 return sm->expected_failure;