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_sm_free_key(struct eap_sm *sm)
98 bin_clear_free(sm->eapKeyData, sm->eapKeyDataLen);
99 sm->eapKeyData = NULL;
104 static void eap_deinit_prev_method(struct eap_sm *sm, const char *txt)
106 ext_password_free(sm->ext_pw_buf);
107 sm->ext_pw_buf = NULL;
109 if (sm->m == NULL || sm->eap_method_priv == NULL)
112 wpa_printf(MSG_DEBUG, "EAP: deinitialize previously used EAP method "
113 "(%d, %s) at %s", sm->selectedMethod, sm->m->name, txt);
114 sm->m->deinit(sm, sm->eap_method_priv);
115 sm->eap_method_priv = NULL;
121 * eap_allowed_method - Check whether EAP method is allowed
122 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
123 * @vendor: Vendor-Id for expanded types or 0 = IETF for legacy types
125 * Returns: 1 = allowed EAP method, 0 = not allowed
127 int eap_allowed_method(struct eap_sm *sm, int vendor, u32 method)
129 struct eap_peer_config *config = eap_get_config(sm);
131 struct eap_method_type *m;
133 if (config == NULL || config->eap_methods == NULL)
136 m = config->eap_methods;
137 for (i = 0; m[i].vendor != EAP_VENDOR_IETF ||
138 m[i].method != EAP_TYPE_NONE; i++) {
139 if (m[i].vendor == vendor && m[i].method == method)
147 * This state initializes state machine variables when the machine is
148 * activated (portEnabled = TRUE). This is also used when re-starting
149 * authentication (eapRestart == TRUE).
151 SM_STATE(EAP, INITIALIZE)
153 SM_ENTRY(EAP, INITIALIZE);
154 if (sm->fast_reauth && sm->m && sm->m->has_reauth_data &&
155 sm->m->has_reauth_data(sm, sm->eap_method_priv) &&
157 sm->last_config == eap_get_config(sm)) {
158 wpa_printf(MSG_DEBUG, "EAP: maintaining EAP method data for "
159 "fast reauthentication");
160 sm->m->deinit_for_reauth(sm, sm->eap_method_priv);
162 sm->last_config = eap_get_config(sm);
163 eap_deinit_prev_method(sm, "INITIALIZE");
165 sm->selectedMethod = EAP_TYPE_NONE;
166 sm->methodState = METHOD_NONE;
167 sm->allowNotifications = TRUE;
168 sm->decision = DECISION_FAIL;
169 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
170 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
171 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
172 eapol_set_bool(sm, EAPOL_eapFail, FALSE);
174 os_free(sm->eapSessionId);
175 sm->eapSessionId = NULL;
176 sm->eapKeyAvailable = FALSE;
177 eapol_set_bool(sm, EAPOL_eapRestart, FALSE);
178 sm->lastId = -1; /* new session - make sure this does not match with
179 * the first EAP-Packet */
181 * RFC 4137 does not reset eapResp and eapNoResp here. However, this
182 * seemed to be able to trigger cases where both were set and if EAPOL
183 * state machine uses eapNoResp first, it may end up not sending a real
184 * reply correctly. This occurred when the workaround in FAIL state set
185 * eapNoResp = TRUE.. Maybe that workaround needs to be fixed to do
188 eapol_set_bool(sm, EAPOL_eapResp, FALSE);
189 eapol_set_bool(sm, EAPOL_eapNoResp, FALSE);
191 sm->prev_failure = 0;
192 sm->expected_failure = 0;
197 * This state is reached whenever service from the lower layer is interrupted
198 * or unavailable (portEnabled == FALSE). Immediate transition to INITIALIZE
199 * occurs when the port becomes enabled.
201 SM_STATE(EAP, DISABLED)
203 SM_ENTRY(EAP, DISABLED);
206 * RFC 4137 does not describe clearing of idleWhile here, but doing so
207 * allows the timer tick to be stopped more quickly when EAP is not in
210 eapol_set_int(sm, EAPOL_idleWhile, 0);
215 * The state machine spends most of its time here, waiting for something to
216 * happen. This state is entered unconditionally from INITIALIZE, DISCARD, and
217 * SEND_RESPONSE states.
226 * This state is entered when an EAP packet is received (eapReq == TRUE) to
227 * parse the packet header.
229 SM_STATE(EAP, RECEIVED)
231 const struct wpabuf *eapReqData;
233 SM_ENTRY(EAP, RECEIVED);
234 eapReqData = eapol_get_eapReqData(sm);
235 /* parse rxReq, rxSuccess, rxFailure, reqId, reqMethod */
236 eap_sm_parseEapReq(sm, eapReqData);
242 * This state is entered when a request for a new type comes in. Either the
243 * correct method is started, or a Nak response is built.
245 SM_STATE(EAP, GET_METHOD)
249 const struct eap_method *eap_method;
251 SM_ENTRY(EAP, GET_METHOD);
253 if (sm->reqMethod == EAP_TYPE_EXPANDED)
254 method = sm->reqVendorMethod;
256 method = sm->reqMethod;
258 eap_method = eap_peer_get_eap_method(sm->reqVendor, method);
260 if (!eap_sm_allowMethod(sm, sm->reqVendor, method)) {
261 wpa_printf(MSG_DEBUG, "EAP: vendor %u method %u not allowed",
262 sm->reqVendor, method);
263 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
264 "vendor=%u method=%u -> NAK",
265 sm->reqVendor, method);
266 eap_notify_status(sm, "refuse proposed method",
267 eap_method ? eap_method->name : "unknown");
271 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
272 "vendor=%u method=%u", sm->reqVendor, method);
274 eap_notify_status(sm, "accept proposed method",
275 eap_method ? eap_method->name : "unknown");
277 * RFC 4137 does not define specific operation for fast
278 * re-authentication (session resumption). The design here is to allow
279 * the previously used method data to be maintained for
280 * re-authentication if the method support session resumption.
281 * Otherwise, the previously used method data is freed and a new method
284 if (sm->fast_reauth &&
285 sm->m && sm->m->vendor == sm->reqVendor &&
286 sm->m->method == method &&
287 sm->m->has_reauth_data &&
288 sm->m->has_reauth_data(sm, sm->eap_method_priv)) {
289 wpa_printf(MSG_DEBUG, "EAP: Using previous method data"
290 " for fast re-authentication");
293 eap_deinit_prev_method(sm, "GET_METHOD");
297 sm->selectedMethod = sm->reqMethod;
301 wpa_printf(MSG_DEBUG, "EAP: Could not find selected method: "
302 "vendor %d method %d",
303 sm->reqVendor, method);
307 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
309 wpa_printf(MSG_DEBUG, "EAP: Initialize selected EAP method: "
310 "vendor %u method %u (%s)",
311 sm->reqVendor, method, sm->m->name);
313 sm->eap_method_priv = sm->m->init_for_reauth(
314 sm, sm->eap_method_priv);
316 sm->eap_method_priv = sm->m->init(sm);
318 if (sm->eap_method_priv == NULL) {
319 struct eap_peer_config *config = eap_get_config(sm);
320 wpa_msg(sm->msg_ctx, MSG_INFO,
321 "EAP: Failed to initialize EAP method: vendor %u "
323 sm->reqVendor, method, sm->m->name);
325 sm->methodState = METHOD_NONE;
326 sm->selectedMethod = EAP_TYPE_NONE;
327 if (sm->reqMethod == EAP_TYPE_TLS && config &&
328 (config->pending_req_pin ||
329 config->pending_req_passphrase)) {
331 * Return without generating Nak in order to allow
332 * entering of PIN code or passphrase to retry the
333 * current EAP packet.
335 wpa_printf(MSG_DEBUG, "EAP: Pending PIN/passphrase "
336 "request - skip Nak");
343 sm->methodState = METHOD_INIT;
344 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_METHOD
345 "EAP vendor %u method %u (%s) selected",
346 sm->reqVendor, method, sm->m->name);
350 wpabuf_free(sm->eapRespData);
351 sm->eapRespData = NULL;
352 sm->eapRespData = eap_sm_buildNak(sm, sm->reqId);
357 * The method processing happens here. The request from the authenticator is
358 * processed, and an appropriate response packet is built.
360 SM_STATE(EAP, METHOD)
362 struct wpabuf *eapReqData;
363 struct eap_method_ret ret;
366 SM_ENTRY(EAP, METHOD);
368 wpa_printf(MSG_WARNING, "EAP::METHOD - method not selected");
372 eapReqData = eapol_get_eapReqData(sm);
373 if (sm->m->vendor == EAP_VENDOR_IETF && sm->m->method == EAP_TYPE_LEAP)
374 min_len = 0; /* LEAP uses EAP-Success without payload */
375 if (!eap_hdr_len_valid(eapReqData, min_len))
379 * Get ignore, methodState, decision, allowNotifications, and
380 * eapRespData. RFC 4137 uses three separate method procedure (check,
381 * process, and buildResp) in this state. These have been combined into
382 * a single function call to m->process() in order to optimize EAP
383 * method implementation interface a bit. These procedures are only
384 * used from within this METHOD state, so there is no need to keep
385 * these as separate C functions.
387 * The RFC 4137 procedures return values as follows:
388 * ignore = m.check(eapReqData)
389 * (methodState, decision, allowNotifications) = m.process(eapReqData)
390 * eapRespData = m.buildResp(reqId)
392 os_memset(&ret, 0, sizeof(ret));
393 ret.ignore = sm->ignore;
394 ret.methodState = sm->methodState;
395 ret.decision = sm->decision;
396 ret.allowNotifications = sm->allowNotifications;
397 wpabuf_free(sm->eapRespData);
398 sm->eapRespData = NULL;
399 sm->eapRespData = sm->m->process(sm, sm->eap_method_priv, &ret,
401 wpa_printf(MSG_DEBUG, "EAP: method process -> ignore=%s "
402 "methodState=%s decision=%s eapRespData=%p",
403 ret.ignore ? "TRUE" : "FALSE",
404 eap_sm_method_state_txt(ret.methodState),
405 eap_sm_decision_txt(ret.decision),
408 sm->ignore = ret.ignore;
411 sm->methodState = ret.methodState;
412 sm->decision = ret.decision;
413 sm->allowNotifications = ret.allowNotifications;
415 if (sm->m->isKeyAvailable && sm->m->getKey &&
416 sm->m->isKeyAvailable(sm, sm->eap_method_priv)) {
418 sm->eapKeyData = sm->m->getKey(sm, sm->eap_method_priv,
420 os_free(sm->eapSessionId);
421 sm->eapSessionId = NULL;
422 if (sm->m->getSessionId) {
423 sm->eapSessionId = sm->m->getSessionId(
424 sm, sm->eap_method_priv,
425 &sm->eapSessionIdLen);
426 wpa_hexdump(MSG_DEBUG, "EAP: Session-Id",
427 sm->eapSessionId, sm->eapSessionIdLen);
434 * This state signals the lower layer that a response packet is ready to be
437 SM_STATE(EAP, SEND_RESPONSE)
439 SM_ENTRY(EAP, SEND_RESPONSE);
440 wpabuf_free(sm->lastRespData);
441 if (sm->eapRespData) {
443 os_memcpy(sm->last_md5, sm->req_md5, 16);
444 sm->lastId = sm->reqId;
445 sm->lastRespData = wpabuf_dup(sm->eapRespData);
446 eapol_set_bool(sm, EAPOL_eapResp, TRUE);
448 wpa_printf(MSG_DEBUG, "EAP: No eapRespData available");
449 sm->lastRespData = NULL;
451 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
452 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
457 * This state signals the lower layer that the request was discarded, and no
458 * response packet will be sent at this time.
460 SM_STATE(EAP, DISCARD)
462 SM_ENTRY(EAP, DISCARD);
463 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
464 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
469 * Handles requests for Identity method and builds a response.
471 SM_STATE(EAP, IDENTITY)
473 const struct wpabuf *eapReqData;
475 SM_ENTRY(EAP, IDENTITY);
476 eapReqData = eapol_get_eapReqData(sm);
477 if (!eap_hdr_len_valid(eapReqData, 1))
479 eap_sm_processIdentity(sm, eapReqData);
480 wpabuf_free(sm->eapRespData);
481 sm->eapRespData = NULL;
482 sm->eapRespData = eap_sm_buildIdentity(sm, sm->reqId, 0);
487 * Handles requests for Notification method and builds a response.
489 SM_STATE(EAP, NOTIFICATION)
491 const struct wpabuf *eapReqData;
493 SM_ENTRY(EAP, NOTIFICATION);
494 eapReqData = eapol_get_eapReqData(sm);
495 if (!eap_hdr_len_valid(eapReqData, 1))
497 eap_sm_processNotify(sm, eapReqData);
498 wpabuf_free(sm->eapRespData);
499 sm->eapRespData = NULL;
500 sm->eapRespData = eap_sm_buildNotify(sm->reqId);
505 * This state retransmits the previous response packet.
507 SM_STATE(EAP, RETRANSMIT)
509 SM_ENTRY(EAP, RETRANSMIT);
510 wpabuf_free(sm->eapRespData);
511 if (sm->lastRespData)
512 sm->eapRespData = wpabuf_dup(sm->lastRespData);
514 sm->eapRespData = NULL;
519 * This state is entered in case of a successful completion of authentication
520 * and state machine waits here until port is disabled or EAP authentication is
523 SM_STATE(EAP, SUCCESS)
525 SM_ENTRY(EAP, SUCCESS);
526 if (sm->eapKeyData != NULL)
527 sm->eapKeyAvailable = TRUE;
528 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
531 * RFC 4137 does not clear eapReq here, but this seems to be required
532 * to avoid processing the same request twice when state machine is
535 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
538 * RFC 4137 does not set eapNoResp here, but this seems to be required
539 * to get EAPOL Supplicant backend state machine into SUCCESS state. In
540 * addition, either eapResp or eapNoResp is required to be set after
541 * processing the received EAP frame.
543 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
545 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
546 "EAP authentication completed successfully");
551 * This state is entered in case of a failure and state machine waits here
552 * until port is disabled or EAP authentication is restarted.
554 SM_STATE(EAP, FAILURE)
556 SM_ENTRY(EAP, FAILURE);
557 eapol_set_bool(sm, EAPOL_eapFail, TRUE);
560 * RFC 4137 does not clear eapReq here, but this seems to be required
561 * to avoid processing the same request twice when state machine is
564 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
567 * RFC 4137 does not set eapNoResp here. However, either eapResp or
568 * eapNoResp is required to be set after processing the received EAP
571 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
573 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
574 "EAP authentication failed");
576 sm->prev_failure = 1;
580 static int eap_success_workaround(struct eap_sm *sm, int reqId, int lastId)
583 * At least Microsoft IAS and Meetinghouse Aegis seem to be sending
584 * EAP-Success/Failure with lastId + 1 even though RFC 3748 and
585 * RFC 4137 require that reqId == lastId. In addition, it looks like
586 * Ringmaster v2.1.2.0 would be using lastId + 2 in EAP-Success.
588 * Accept this kind of Id if EAP workarounds are enabled. These are
589 * unauthenticated plaintext messages, so this should have minimal
590 * security implications (bit easier to fake EAP-Success/Failure).
592 if (sm->workaround && (reqId == ((lastId + 1) & 0xff) ||
593 reqId == ((lastId + 2) & 0xff))) {
594 wpa_printf(MSG_DEBUG, "EAP: Workaround for unexpected "
595 "identifier field in EAP Success: "
596 "reqId=%d lastId=%d (these are supposed to be "
597 "same)", reqId, lastId);
600 wpa_printf(MSG_DEBUG, "EAP: EAP-Success Id mismatch - reqId=%d "
601 "lastId=%d", reqId, lastId);
607 * RFC 4137 - Appendix A.1: EAP Peer State Machine - State transitions
610 static void eap_peer_sm_step_idle(struct eap_sm *sm)
613 * The first three transitions are from RFC 4137. The last two are
614 * local additions to handle special cases with LEAP and PEAP server
615 * not sending EAP-Success in some cases.
617 if (eapol_get_bool(sm, EAPOL_eapReq))
618 SM_ENTER(EAP, RECEIVED);
619 else if ((eapol_get_bool(sm, EAPOL_altAccept) &&
620 sm->decision != DECISION_FAIL) ||
621 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
622 sm->decision == DECISION_UNCOND_SUCC))
623 SM_ENTER(EAP, SUCCESS);
624 else if (eapol_get_bool(sm, EAPOL_altReject) ||
625 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
626 sm->decision != DECISION_UNCOND_SUCC) ||
627 (eapol_get_bool(sm, EAPOL_altAccept) &&
628 sm->methodState != METHOD_CONT &&
629 sm->decision == DECISION_FAIL))
630 SM_ENTER(EAP, FAILURE);
631 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
632 sm->leap_done && sm->decision != DECISION_FAIL &&
633 sm->methodState == METHOD_DONE)
634 SM_ENTER(EAP, SUCCESS);
635 else if (sm->selectedMethod == EAP_TYPE_PEAP &&
636 sm->peap_done && sm->decision != DECISION_FAIL &&
637 sm->methodState == METHOD_DONE)
638 SM_ENTER(EAP, SUCCESS);
642 static int eap_peer_req_is_duplicate(struct eap_sm *sm)
646 duplicate = (sm->reqId == sm->lastId) && sm->rxReq;
647 if (sm->workaround && duplicate &&
648 os_memcmp(sm->req_md5, sm->last_md5, 16) != 0) {
650 * RFC 4137 uses (reqId == lastId) as the only verification for
651 * duplicate EAP requests. However, this misses cases where the
652 * AS is incorrectly using the same id again; and
653 * unfortunately, such implementations exist. Use MD5 hash as
654 * an extra verification for the packets being duplicate to
655 * workaround these issues.
657 wpa_printf(MSG_DEBUG, "EAP: AS used the same Id again, but "
658 "EAP packets were not identical");
659 wpa_printf(MSG_DEBUG, "EAP: workaround - assume this is not a "
668 static void eap_peer_sm_step_received(struct eap_sm *sm)
670 int duplicate = eap_peer_req_is_duplicate(sm);
673 * Two special cases below for LEAP are local additions to work around
674 * odd LEAP behavior (EAP-Success in the middle of authentication and
675 * then swapped roles). Other transitions are based on RFC 4137.
677 if (sm->rxSuccess && sm->decision != DECISION_FAIL &&
678 (sm->reqId == sm->lastId ||
679 eap_success_workaround(sm, sm->reqId, sm->lastId)))
680 SM_ENTER(EAP, SUCCESS);
681 else if (sm->methodState != METHOD_CONT &&
683 sm->decision != DECISION_UNCOND_SUCC) ||
684 (sm->rxSuccess && sm->decision == DECISION_FAIL &&
685 (sm->selectedMethod != EAP_TYPE_LEAP ||
686 sm->methodState != METHOD_MAY_CONT))) &&
687 (sm->reqId == sm->lastId ||
688 eap_success_workaround(sm, sm->reqId, sm->lastId)))
689 SM_ENTER(EAP, FAILURE);
690 else if (sm->rxReq && duplicate)
691 SM_ENTER(EAP, RETRANSMIT);
692 else if (sm->rxReq && !duplicate &&
693 sm->reqMethod == EAP_TYPE_NOTIFICATION &&
694 sm->allowNotifications)
695 SM_ENTER(EAP, NOTIFICATION);
696 else if (sm->rxReq && !duplicate &&
697 sm->selectedMethod == EAP_TYPE_NONE &&
698 sm->reqMethod == EAP_TYPE_IDENTITY)
699 SM_ENTER(EAP, IDENTITY);
700 else if (sm->rxReq && !duplicate &&
701 sm->selectedMethod == EAP_TYPE_NONE &&
702 sm->reqMethod != EAP_TYPE_IDENTITY &&
703 sm->reqMethod != EAP_TYPE_NOTIFICATION)
704 SM_ENTER(EAP, GET_METHOD);
705 else if (sm->rxReq && !duplicate &&
706 sm->reqMethod == sm->selectedMethod &&
707 sm->methodState != METHOD_DONE)
708 SM_ENTER(EAP, METHOD);
709 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
710 (sm->rxSuccess || sm->rxResp))
711 SM_ENTER(EAP, METHOD);
713 SM_ENTER(EAP, DISCARD);
717 static void eap_peer_sm_step_local(struct eap_sm *sm)
719 switch (sm->EAP_state) {
724 if (eapol_get_bool(sm, EAPOL_portEnabled) &&
726 SM_ENTER(EAP, INITIALIZE);
729 eap_peer_sm_step_idle(sm);
732 eap_peer_sm_step_received(sm);
735 if (sm->selectedMethod == sm->reqMethod)
736 SM_ENTER(EAP, METHOD);
738 SM_ENTER(EAP, SEND_RESPONSE);
742 * Note: RFC 4137 uses methodState == DONE && decision == FAIL
743 * as the condition. eapRespData == NULL here is used to allow
744 * final EAP method response to be sent without having to change
745 * all methods to either use methodState MAY_CONT or leaving
746 * decision to something else than FAIL in cases where the only
747 * expected response is EAP-Failure.
750 SM_ENTER(EAP, DISCARD);
751 else if (sm->methodState == METHOD_DONE &&
752 sm->decision == DECISION_FAIL && !sm->eapRespData)
753 SM_ENTER(EAP, FAILURE);
755 SM_ENTER(EAP, SEND_RESPONSE);
757 case EAP_SEND_RESPONSE:
764 SM_ENTER(EAP, SEND_RESPONSE);
766 case EAP_NOTIFICATION:
767 SM_ENTER(EAP, SEND_RESPONSE);
770 SM_ENTER(EAP, SEND_RESPONSE);
782 /* Global transitions */
783 if (eapol_get_bool(sm, EAPOL_eapRestart) &&
784 eapol_get_bool(sm, EAPOL_portEnabled))
785 SM_ENTER_GLOBAL(EAP, INITIALIZE);
786 else if (!eapol_get_bool(sm, EAPOL_portEnabled) || sm->force_disabled)
787 SM_ENTER_GLOBAL(EAP, DISABLED);
788 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
789 /* RFC 4137 does not place any limit on number of EAP messages
790 * in an authentication session. However, some error cases have
791 * ended up in a state were EAP messages were sent between the
792 * peer and server in a loop (e.g., TLS ACK frame in both
793 * direction). Since this is quite undesired outcome, limit the
794 * total number of EAP round-trips and abort authentication if
795 * this limit is exceeded.
797 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
798 wpa_msg(sm->msg_ctx, MSG_INFO, "EAP: more than %d "
799 "authentication rounds - abort",
800 EAP_MAX_AUTH_ROUNDS);
802 SM_ENTER_GLOBAL(EAP, FAILURE);
805 /* Local transitions */
806 eap_peer_sm_step_local(sm);
811 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
814 if (!eap_allowed_method(sm, vendor, method)) {
815 wpa_printf(MSG_DEBUG, "EAP: configuration does not allow: "
816 "vendor %u method %u", vendor, method);
819 if (eap_peer_get_eap_method(vendor, method))
821 wpa_printf(MSG_DEBUG, "EAP: not included in build: "
822 "vendor %u method %u", vendor, method);
827 static struct wpabuf * eap_sm_build_expanded_nak(
828 struct eap_sm *sm, int id, const struct eap_method *methods,
833 const struct eap_method *m;
835 wpa_printf(MSG_DEBUG, "EAP: Building expanded EAP-Nak");
837 /* RFC 3748 - 5.3.2: Expanded Nak */
838 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_EXPANDED,
839 8 + 8 * (count + 1), EAP_CODE_RESPONSE, id);
843 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
844 wpabuf_put_be32(resp, EAP_TYPE_NAK);
846 for (m = methods; m; m = m->next) {
847 if (sm->reqVendor == m->vendor &&
848 sm->reqVendorMethod == m->method)
849 continue; /* do not allow the current method again */
850 if (eap_allowed_method(sm, m->vendor, m->method)) {
851 wpa_printf(MSG_DEBUG, "EAP: allowed type: "
852 "vendor=%u method=%u",
853 m->vendor, m->method);
854 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
855 wpabuf_put_be24(resp, m->vendor);
856 wpabuf_put_be32(resp, m->method);
862 wpa_printf(MSG_DEBUG, "EAP: no more allowed methods");
863 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
864 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
865 wpabuf_put_be32(resp, EAP_TYPE_NONE);
868 eap_update_len(resp);
874 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id)
878 int found = 0, expanded_found = 0;
880 const struct eap_method *methods, *m;
882 wpa_printf(MSG_DEBUG, "EAP: Building EAP-Nak (requested type %u "
883 "vendor=%u method=%u not allowed)", sm->reqMethod,
884 sm->reqVendor, sm->reqVendorMethod);
885 methods = eap_peer_get_methods(&count);
888 if (sm->reqMethod == EAP_TYPE_EXPANDED)
889 return eap_sm_build_expanded_nak(sm, id, methods, count);
891 /* RFC 3748 - 5.3.1: Legacy Nak */
892 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NAK,
893 sizeof(struct eap_hdr) + 1 + count + 1,
894 EAP_CODE_RESPONSE, id);
898 start = wpabuf_put(resp, 0);
899 for (m = methods; m; m = m->next) {
900 if (m->vendor == EAP_VENDOR_IETF && m->method == sm->reqMethod)
901 continue; /* do not allow the current method again */
902 if (eap_allowed_method(sm, m->vendor, m->method)) {
903 if (m->vendor != EAP_VENDOR_IETF) {
907 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
909 wpabuf_put_u8(resp, m->method);
914 wpabuf_put_u8(resp, EAP_TYPE_NONE);
915 wpa_hexdump(MSG_DEBUG, "EAP: allowed methods", start, found);
917 eap_update_len(resp);
923 static void eap_sm_processIdentity(struct eap_sm *sm, const struct wpabuf *req)
928 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
929 "EAP authentication started");
930 eap_notify_status(sm, "started", "");
932 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req,
938 * RFC 3748 - 5.1: Identity
939 * Data field may contain a displayable message in UTF-8. If this
940 * includes NUL-character, only the data before that should be
941 * displayed. Some EAP implementasitons may piggy-back additional
942 * options after the NUL.
944 /* TODO: could save displayable message so that it can be shown to the
945 * user in case of interaction is required */
946 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Identity data",
954 * Rules for figuring out MNC length based on IMSI for SIM cards that do not
955 * include MNC length field.
957 static int mnc_len_from_imsi(const char *imsi)
962 os_memcpy(mcc_str, imsi, 3);
967 return 2; /* Networks in Switzerland use 2-digit MNC */
969 return 2; /* Networks in Finland use 2-digit MNC */
975 static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
976 size_t max_len, size_t *imsi_len)
981 if (*imsi_len + 36 > max_len) {
982 wpa_printf(MSG_WARNING, "No room for realm in IMSI buffer");
986 /* MNC (2 or 3 digits) */
987 mnc_len = scard_get_mnc_len(sm->scard_ctx);
989 mnc_len = mnc_len_from_imsi(imsi);
991 wpa_printf(MSG_INFO, "Failed to get MNC length from (U)SIM "
1000 } else if (mnc_len == 3) {
1007 pos = imsi + *imsi_len;
1008 pos += os_snprintf(pos, imsi + max_len - pos,
1009 "@wlan.mnc%s.mcc%c%c%c.3gppnetwork.org",
1010 mnc, imsi[0], imsi[1], imsi[2]);
1011 *imsi_len = pos - imsi;
1017 static int eap_sm_imsi_identity(struct eap_sm *sm,
1018 struct eap_peer_config *conf)
1020 enum { EAP_SM_SIM, EAP_SM_AKA, EAP_SM_AKA_PRIME } method = EAP_SM_SIM;
1023 struct eap_method_type *m = conf->eap_methods;
1026 imsi_len = sizeof(imsi);
1027 if (scard_get_imsi(sm->scard_ctx, imsi, &imsi_len)) {
1028 wpa_printf(MSG_WARNING, "Failed to get IMSI from SIM");
1032 wpa_hexdump_ascii(MSG_DEBUG, "IMSI", (u8 *) imsi, imsi_len);
1035 wpa_printf(MSG_WARNING, "Too short IMSI for SIM identity");
1039 if (eap_sm_append_3gpp_realm(sm, imsi, sizeof(imsi), &imsi_len) < 0) {
1040 wpa_printf(MSG_WARNING, "Could not add realm to SIM identity");
1043 wpa_hexdump_ascii(MSG_DEBUG, "IMSI + realm", (u8 *) imsi, imsi_len);
1045 for (i = 0; m && (m[i].vendor != EAP_VENDOR_IETF ||
1046 m[i].method != EAP_TYPE_NONE); i++) {
1047 if (m[i].vendor == EAP_VENDOR_IETF &&
1048 m[i].method == EAP_TYPE_AKA_PRIME) {
1049 method = EAP_SM_AKA_PRIME;
1053 if (m[i].vendor == EAP_VENDOR_IETF &&
1054 m[i].method == EAP_TYPE_AKA) {
1055 method = EAP_SM_AKA;
1060 os_free(conf->identity);
1061 conf->identity = os_malloc(1 + imsi_len);
1062 if (conf->identity == NULL) {
1063 wpa_printf(MSG_WARNING, "Failed to allocate buffer for "
1064 "IMSI-based identity");
1070 conf->identity[0] = '1';
1073 conf->identity[0] = '0';
1075 case EAP_SM_AKA_PRIME:
1076 conf->identity[0] = '6';
1079 os_memcpy(conf->identity + 1, imsi, imsi_len);
1080 conf->identity_len = 1 + imsi_len;
1085 #endif /* PCSC_FUNCS */
1088 static int eap_sm_set_scard_pin(struct eap_sm *sm,
1089 struct eap_peer_config *conf)
1092 if (scard_set_pin(sm->scard_ctx, conf->pin)) {
1094 * Make sure the same PIN is not tried again in order to avoid
1100 wpa_printf(MSG_WARNING, "PIN validation failed");
1101 eap_sm_request_pin(sm);
1105 #else /* PCSC_FUNCS */
1107 #endif /* PCSC_FUNCS */
1110 static int eap_sm_get_scard_identity(struct eap_sm *sm,
1111 struct eap_peer_config *conf)
1114 if (eap_sm_set_scard_pin(sm, conf))
1117 return eap_sm_imsi_identity(sm, conf);
1118 #else /* PCSC_FUNCS */
1120 #endif /* PCSC_FUNCS */
1125 * eap_sm_buildIdentity - Build EAP-Identity/Response for the current network
1126 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1127 * @id: EAP identifier for the packet
1128 * @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
1129 * Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
1132 * This function allocates and builds an EAP-Identity/Response packet for the
1133 * current network. The caller is responsible for freeing the returned data.
1135 struct wpabuf * eap_sm_buildIdentity(struct eap_sm *sm, int id, int encrypted)
1137 struct eap_peer_config *config = eap_get_config(sm);
1138 struct wpabuf *resp;
1140 size_t identity_len;
1142 if (config == NULL) {
1143 wpa_printf(MSG_WARNING, "EAP: buildIdentity: configuration "
1144 "was not available");
1148 if (sm->m && sm->m->get_identity &&
1149 (identity = sm->m->get_identity(sm, sm->eap_method_priv,
1150 &identity_len)) != NULL) {
1151 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using method re-auth "
1152 "identity", identity, identity_len);
1153 } else if (!encrypted && config->anonymous_identity) {
1154 identity = config->anonymous_identity;
1155 identity_len = config->anonymous_identity_len;
1156 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using anonymous identity",
1157 identity, identity_len);
1159 identity = config->identity;
1160 identity_len = config->identity_len;
1161 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using real identity",
1162 identity, identity_len);
1165 if (identity == NULL) {
1166 wpa_printf(MSG_WARNING, "EAP: buildIdentity: identity "
1167 "configuration was not available");
1169 if (eap_sm_get_scard_identity(sm, config) < 0)
1171 identity = config->identity;
1172 identity_len = config->identity_len;
1173 wpa_hexdump_ascii(MSG_DEBUG, "permanent identity from "
1174 "IMSI", identity, identity_len);
1176 eap_sm_request_identity(sm);
1179 } else if (config->pcsc) {
1180 if (eap_sm_set_scard_pin(sm, config) < 0)
1184 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, identity_len,
1185 EAP_CODE_RESPONSE, id);
1189 wpabuf_put_data(resp, identity, identity_len);
1195 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req)
1201 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, req,
1205 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Notification data",
1208 msg = os_malloc(msg_len + 1);
1211 for (i = 0; i < msg_len; i++)
1212 msg[i] = isprint(pos[i]) ? (char) pos[i] : '_';
1213 msg[msg_len] = '\0';
1214 wpa_msg(sm->msg_ctx, MSG_INFO, "%s%s",
1215 WPA_EVENT_EAP_NOTIFICATION, msg);
1220 static struct wpabuf * eap_sm_buildNotify(int id)
1222 struct wpabuf *resp;
1224 wpa_printf(MSG_DEBUG, "EAP: Generating EAP-Response Notification");
1225 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, 0,
1226 EAP_CODE_RESPONSE, id);
1234 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req)
1236 const struct eap_hdr *hdr;
1240 sm->rxReq = sm->rxResp = sm->rxSuccess = sm->rxFailure = FALSE;
1242 sm->reqMethod = EAP_TYPE_NONE;
1243 sm->reqVendor = EAP_VENDOR_IETF;
1244 sm->reqVendorMethod = EAP_TYPE_NONE;
1246 if (req == NULL || wpabuf_len(req) < sizeof(*hdr))
1249 hdr = wpabuf_head(req);
1250 plen = be_to_host16(hdr->length);
1251 if (plen > wpabuf_len(req)) {
1252 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
1253 "(len=%lu plen=%lu)",
1254 (unsigned long) wpabuf_len(req),
1255 (unsigned long) plen);
1259 sm->reqId = hdr->identifier;
1261 if (sm->workaround) {
1263 addr[0] = wpabuf_head(req);
1264 md5_vector(1, addr, &plen, sm->req_md5);
1267 switch (hdr->code) {
1268 case EAP_CODE_REQUEST:
1269 if (plen < sizeof(*hdr) + 1) {
1270 wpa_printf(MSG_DEBUG, "EAP: Too short EAP-Request - "
1275 pos = (const u8 *) (hdr + 1);
1276 sm->reqMethod = *pos++;
1277 if (sm->reqMethod == EAP_TYPE_EXPANDED) {
1278 if (plen < sizeof(*hdr) + 8) {
1279 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
1280 "expanded EAP-Packet (plen=%lu)",
1281 (unsigned long) plen);
1284 sm->reqVendor = WPA_GET_BE24(pos);
1286 sm->reqVendorMethod = WPA_GET_BE32(pos);
1288 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Request id=%d "
1289 "method=%u vendor=%u vendorMethod=%u",
1290 sm->reqId, sm->reqMethod, sm->reqVendor,
1291 sm->reqVendorMethod);
1293 case EAP_CODE_RESPONSE:
1294 if (sm->selectedMethod == EAP_TYPE_LEAP) {
1296 * LEAP differs from RFC 4137 by using reversed roles
1297 * for mutual authentication and because of this, we
1298 * need to accept EAP-Response frames if LEAP is used.
1300 if (plen < sizeof(*hdr) + 1) {
1301 wpa_printf(MSG_DEBUG, "EAP: Too short "
1302 "EAP-Response - no Type field");
1306 pos = (const u8 *) (hdr + 1);
1307 sm->reqMethod = *pos;
1308 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Response for "
1309 "LEAP method=%d id=%d",
1310 sm->reqMethod, sm->reqId);
1313 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Response");
1315 case EAP_CODE_SUCCESS:
1316 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Success");
1317 eap_notify_status(sm, "completion", "success");
1318 sm->rxSuccess = TRUE;
1320 case EAP_CODE_FAILURE:
1321 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Failure");
1322 eap_notify_status(sm, "completion", "failure");
1323 sm->rxFailure = TRUE;
1326 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Packet with unknown "
1327 "code %d", hdr->code);
1333 static void eap_peer_sm_tls_event(void *ctx, enum tls_event ev,
1334 union tls_event_data *data)
1336 struct eap_sm *sm = ctx;
1337 char *hash_hex = NULL;
1340 case TLS_CERT_CHAIN_SUCCESS:
1341 eap_notify_status(sm, "remote certificate verification",
1344 case TLS_CERT_CHAIN_FAILURE:
1345 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TLS_CERT_ERROR
1346 "reason=%d depth=%d subject='%s' err='%s'",
1347 data->cert_fail.reason,
1348 data->cert_fail.depth,
1349 data->cert_fail.subject,
1350 data->cert_fail.reason_txt);
1351 eap_notify_status(sm, "remote certificate verification",
1352 data->cert_fail.reason_txt);
1354 case TLS_PEER_CERTIFICATE:
1355 if (!sm->eapol_cb->notify_cert)
1358 if (data->peer_cert.hash) {
1359 size_t len = data->peer_cert.hash_len * 2 + 1;
1360 hash_hex = os_malloc(len);
1362 wpa_snprintf_hex(hash_hex, len,
1363 data->peer_cert.hash,
1364 data->peer_cert.hash_len);
1368 sm->eapol_cb->notify_cert(sm->eapol_ctx,
1369 data->peer_cert.depth,
1370 data->peer_cert.subject,
1371 hash_hex, data->peer_cert.cert);
1374 if (data->alert.is_local)
1375 eap_notify_status(sm, "local TLS alert",
1376 data->alert.description);
1378 eap_notify_status(sm, "remote TLS alert",
1379 data->alert.description);
1388 * eap_peer_sm_init - Allocate and initialize EAP peer state machine
1389 * @eapol_ctx: Context data to be used with eapol_cb calls
1390 * @eapol_cb: Pointer to EAPOL callback functions
1391 * @msg_ctx: Context data for wpa_msg() calls
1392 * @conf: EAP configuration
1393 * Returns: Pointer to the allocated EAP state machine or %NULL on failure
1395 * This function allocates and initializes an EAP state machine. In addition,
1396 * this initializes TLS library for the new EAP state machine. eapol_cb pointer
1397 * will be in use until eap_peer_sm_deinit() is used to deinitialize this EAP
1398 * state machine. Consequently, the caller must make sure that this data
1399 * structure remains alive while the EAP state machine is active.
1401 struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
1402 struct eapol_callbacks *eapol_cb,
1403 void *msg_ctx, struct eap_config *conf)
1406 struct tls_config tlsconf;
1408 sm = os_zalloc(sizeof(*sm));
1411 sm->eapol_ctx = eapol_ctx;
1412 sm->eapol_cb = eapol_cb;
1413 sm->msg_ctx = msg_ctx;
1414 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
1415 sm->wps = conf->wps;
1417 os_memset(&tlsconf, 0, sizeof(tlsconf));
1418 tlsconf.opensc_engine_path = conf->opensc_engine_path;
1419 tlsconf.pkcs11_engine_path = conf->pkcs11_engine_path;
1420 tlsconf.pkcs11_module_path = conf->pkcs11_module_path;
1421 tlsconf.openssl_ciphers = conf->openssl_ciphers;
1423 tlsconf.fips_mode = 1;
1424 #endif /* CONFIG_FIPS */
1425 tlsconf.event_cb = eap_peer_sm_tls_event;
1426 tlsconf.cb_ctx = sm;
1427 tlsconf.cert_in_cb = conf->cert_in_cb;
1428 sm->ssl_ctx = tls_init(&tlsconf);
1429 if (sm->ssl_ctx == NULL) {
1430 wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS "
1436 sm->ssl_ctx2 = tls_init(&tlsconf);
1437 if (sm->ssl_ctx2 == NULL) {
1438 wpa_printf(MSG_INFO, "SSL: Failed to initialize TLS "
1440 /* Run without separate TLS context within TLS tunnel */
1448 * eap_peer_sm_deinit - Deinitialize and free an EAP peer state machine
1449 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1451 * This function deinitializes EAP state machine and frees all allocated
1454 void eap_peer_sm_deinit(struct eap_sm *sm)
1458 eap_deinit_prev_method(sm, "EAP deinit");
1461 tls_deinit(sm->ssl_ctx2);
1462 tls_deinit(sm->ssl_ctx);
1468 * eap_peer_sm_step - Step EAP peer state machine
1469 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1470 * Returns: 1 if EAP state was changed or 0 if not
1472 * This function advances EAP state machine to a new state to match with the
1473 * current variables. This should be called whenever variables used by the EAP
1474 * state machine have changed.
1476 int eap_peer_sm_step(struct eap_sm *sm)
1480 sm->changed = FALSE;
1484 } while (sm->changed);
1490 * eap_sm_abort - Abort EAP authentication
1491 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1493 * Release system resources that have been allocated for the authentication
1494 * session without fully deinitializing the EAP state machine.
1496 void eap_sm_abort(struct eap_sm *sm)
1498 wpabuf_free(sm->lastRespData);
1499 sm->lastRespData = NULL;
1500 wpabuf_free(sm->eapRespData);
1501 sm->eapRespData = NULL;
1502 eap_sm_free_key(sm);
1503 os_free(sm->eapSessionId);
1504 sm->eapSessionId = NULL;
1506 /* This is not clearly specified in the EAP statemachines draft, but
1507 * it seems necessary to make sure that some of the EAPOL variables get
1508 * cleared for the next authentication. */
1509 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
1513 #ifdef CONFIG_CTRL_IFACE
1514 static const char * eap_sm_state_txt(int state)
1517 case EAP_INITIALIZE:
1518 return "INITIALIZE";
1525 case EAP_GET_METHOD:
1526 return "GET_METHOD";
1529 case EAP_SEND_RESPONSE:
1530 return "SEND_RESPONSE";
1535 case EAP_NOTIFICATION:
1536 return "NOTIFICATION";
1537 case EAP_RETRANSMIT:
1538 return "RETRANSMIT";
1547 #endif /* CONFIG_CTRL_IFACE */
1550 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1551 static const char * eap_sm_method_state_txt(EapMethodState state)
1560 case METHOD_MAY_CONT:
1570 static const char * eap_sm_decision_txt(EapDecision decision)
1575 case DECISION_COND_SUCC:
1577 case DECISION_UNCOND_SUCC:
1578 return "UNCOND_SUCC";
1583 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1586 #ifdef CONFIG_CTRL_IFACE
1589 * eap_sm_get_status - Get EAP state machine status
1590 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1591 * @buf: Buffer for status information
1592 * @buflen: Maximum buffer length
1593 * @verbose: Whether to include verbose status information
1594 * Returns: Number of bytes written to buf.
1596 * Query EAP state machine for status information. This function fills in a
1597 * text area with current status information from the EAPOL state machine. If
1598 * the buffer (buf) is not large enough, status information will be truncated
1599 * to fit the buffer.
1601 int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
1608 len = os_snprintf(buf, buflen,
1610 eap_sm_state_txt(sm->EAP_state));
1611 if (len < 0 || (size_t) len >= buflen)
1614 if (sm->selectedMethod != EAP_TYPE_NONE) {
1619 const struct eap_method *m =
1620 eap_peer_get_eap_method(EAP_VENDOR_IETF,
1621 sm->selectedMethod);
1627 ret = os_snprintf(buf + len, buflen - len,
1628 "selectedMethod=%d (EAP-%s)\n",
1629 sm->selectedMethod, name);
1630 if (ret < 0 || (size_t) ret >= buflen - len)
1634 if (sm->m && sm->m->get_status) {
1635 len += sm->m->get_status(sm, sm->eap_method_priv,
1636 buf + len, buflen - len,
1642 ret = os_snprintf(buf + len, buflen - len,
1646 "ClientTimeout=%d\n",
1648 eap_sm_method_state_txt(sm->methodState),
1649 eap_sm_decision_txt(sm->decision),
1651 if (ret < 0 || (size_t) ret >= buflen - len)
1658 #endif /* CONFIG_CTRL_IFACE */
1661 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1662 static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
1663 const char *msg, size_t msglen)
1665 struct eap_peer_config *config;
1666 const char *txt = NULL;
1671 config = eap_get_config(sm);
1676 case WPA_CTRL_REQ_EAP_IDENTITY:
1677 config->pending_req_identity++;
1679 case WPA_CTRL_REQ_EAP_PASSWORD:
1680 config->pending_req_password++;
1682 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
1683 config->pending_req_new_password++;
1685 case WPA_CTRL_REQ_EAP_PIN:
1686 config->pending_req_pin++;
1688 case WPA_CTRL_REQ_EAP_OTP:
1690 tmp = os_malloc(msglen + 3);
1694 os_memcpy(tmp + 1, msg, msglen);
1695 tmp[msglen + 1] = ']';
1696 tmp[msglen + 2] = '\0';
1698 os_free(config->pending_req_otp);
1699 config->pending_req_otp = tmp;
1700 config->pending_req_otp_len = msglen + 3;
1702 if (config->pending_req_otp == NULL)
1704 txt = config->pending_req_otp;
1707 case WPA_CTRL_REQ_EAP_PASSPHRASE:
1708 config->pending_req_passphrase++;
1710 case WPA_CTRL_REQ_SIM:
1717 if (sm->eapol_cb->eap_param_needed)
1718 sm->eapol_cb->eap_param_needed(sm->eapol_ctx, field, txt);
1720 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1721 #define eap_sm_request(sm, type, msg, msglen) do { } while (0)
1722 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1724 const char * eap_sm_get_method_name(struct eap_sm *sm)
1733 * eap_sm_request_identity - Request identity from user (ctrl_iface)
1734 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1736 * EAP methods can call this function to request identity information for the
1737 * current network. This is normally called when the identity is not included
1738 * in the network configuration. The request will be sent to monitor programs
1739 * through the control interface.
1741 void eap_sm_request_identity(struct eap_sm *sm)
1743 eap_sm_request(sm, WPA_CTRL_REQ_EAP_IDENTITY, NULL, 0);
1748 * eap_sm_request_password - Request password from user (ctrl_iface)
1749 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1751 * EAP methods can call this function to request password information for the
1752 * current network. This is normally called when the password is not included
1753 * in the network configuration. The request will be sent to monitor programs
1754 * through the control interface.
1756 void eap_sm_request_password(struct eap_sm *sm)
1758 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSWORD, NULL, 0);
1763 * eap_sm_request_new_password - Request new password from user (ctrl_iface)
1764 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1766 * EAP methods can call this function to request new password information for
1767 * the current network. This is normally called when the EAP method indicates
1768 * that the current password has expired and password change is required. The
1769 * request will be sent to monitor programs through the control interface.
1771 void eap_sm_request_new_password(struct eap_sm *sm)
1773 eap_sm_request(sm, WPA_CTRL_REQ_EAP_NEW_PASSWORD, NULL, 0);
1778 * eap_sm_request_pin - Request SIM or smart card PIN from user (ctrl_iface)
1779 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1781 * EAP methods can call this function to request SIM or smart card PIN
1782 * information for the current network. This is normally called when the PIN is
1783 * not included in the network configuration. The request will be sent to
1784 * monitor programs through the control interface.
1786 void eap_sm_request_pin(struct eap_sm *sm)
1788 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PIN, NULL, 0);
1793 * eap_sm_request_otp - Request one time password from user (ctrl_iface)
1794 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1795 * @msg: Message to be displayed to the user when asking for OTP
1796 * @msg_len: Length of the user displayable message
1798 * EAP methods can call this function to request open time password (OTP) for
1799 * the current network. The request will be sent to monitor programs through
1800 * the control interface.
1802 void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
1804 eap_sm_request(sm, WPA_CTRL_REQ_EAP_OTP, msg, msg_len);
1809 * eap_sm_request_passphrase - Request passphrase from user (ctrl_iface)
1810 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1812 * EAP methods can call this function to request passphrase for a private key
1813 * for the current network. This is normally called when the passphrase is not
1814 * included in the network configuration. The request will be sent to monitor
1815 * programs through the control interface.
1817 void eap_sm_request_passphrase(struct eap_sm *sm)
1819 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSPHRASE, NULL, 0);
1824 * eap_sm_request_sim - Request external SIM processing
1825 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1826 * @req: EAP method specific request
1828 void eap_sm_request_sim(struct eap_sm *sm, const char *req)
1830 eap_sm_request(sm, WPA_CTRL_REQ_SIM, req, os_strlen(req));
1835 * eap_sm_notify_ctrl_attached - Notification of attached monitor
1836 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1838 * Notify EAP state machines that a monitor was attached to the control
1839 * interface to trigger re-sending of pending requests for user input.
1841 void eap_sm_notify_ctrl_attached(struct eap_sm *sm)
1843 struct eap_peer_config *config = eap_get_config(sm);
1848 /* Re-send any pending requests for user data since a new control
1849 * interface was added. This handles cases where the EAP authentication
1850 * starts immediately after system startup when the user interface is
1851 * not yet running. */
1852 if (config->pending_req_identity)
1853 eap_sm_request_identity(sm);
1854 if (config->pending_req_password)
1855 eap_sm_request_password(sm);
1856 if (config->pending_req_new_password)
1857 eap_sm_request_new_password(sm);
1858 if (config->pending_req_otp)
1859 eap_sm_request_otp(sm, NULL, 0);
1860 if (config->pending_req_pin)
1861 eap_sm_request_pin(sm);
1862 if (config->pending_req_passphrase)
1863 eap_sm_request_passphrase(sm);
1867 static int eap_allowed_phase2_type(int vendor, int type)
1869 if (vendor != EAP_VENDOR_IETF)
1871 return type != EAP_TYPE_PEAP && type != EAP_TYPE_TTLS &&
1872 type != EAP_TYPE_FAST;
1877 * eap_get_phase2_type - Get EAP type for the given EAP phase 2 method name
1878 * @name: EAP method name, e.g., MD5
1879 * @vendor: Buffer for returning EAP Vendor-Id
1880 * Returns: EAP method type or %EAP_TYPE_NONE if not found
1882 * This function maps EAP type names into EAP type numbers that are allowed for
1883 * Phase 2, i.e., for tunneled authentication. Phase 2 is used, e.g., with
1884 * EAP-PEAP, EAP-TTLS, and EAP-FAST.
1886 u32 eap_get_phase2_type(const char *name, int *vendor)
1889 u8 type = eap_peer_get_type(name, &v);
1890 if (eap_allowed_phase2_type(v, type)) {
1894 *vendor = EAP_VENDOR_IETF;
1895 return EAP_TYPE_NONE;
1900 * eap_get_phase2_types - Get list of allowed EAP phase 2 types
1901 * @config: Pointer to a network configuration
1902 * @count: Pointer to a variable to be filled with number of returned EAP types
1903 * Returns: Pointer to allocated type list or %NULL on failure
1905 * This function generates an array of allowed EAP phase 2 (tunneled) types for
1906 * the given network configuration.
1908 struct eap_method_type * eap_get_phase2_types(struct eap_peer_config *config,
1911 struct eap_method_type *buf;
1915 const struct eap_method *methods, *m;
1917 methods = eap_peer_get_methods(&mcount);
1918 if (methods == NULL)
1921 buf = os_malloc(mcount * sizeof(struct eap_method_type));
1925 for (m = methods; m; m = m->next) {
1928 if (eap_allowed_phase2_type(vendor, method)) {
1929 if (vendor == EAP_VENDOR_IETF &&
1930 method == EAP_TYPE_TLS && config &&
1931 config->private_key2 == NULL)
1933 buf[*count].vendor = vendor;
1934 buf[*count].method = method;
1944 * eap_set_fast_reauth - Update fast_reauth setting
1945 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1946 * @enabled: 1 = Fast reauthentication is enabled, 0 = Disabled
1948 void eap_set_fast_reauth(struct eap_sm *sm, int enabled)
1950 sm->fast_reauth = enabled;
1955 * eap_set_workaround - Update EAP workarounds setting
1956 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1957 * @workaround: 1 = Enable EAP workarounds, 0 = Disable EAP workarounds
1959 void eap_set_workaround(struct eap_sm *sm, unsigned int workaround)
1961 sm->workaround = workaround;
1966 * eap_get_config - Get current network configuration
1967 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1968 * Returns: Pointer to the current network configuration or %NULL if not found
1970 * EAP peer methods should avoid using this function if they can use other
1971 * access functions, like eap_get_config_identity() and
1972 * eap_get_config_password(), that do not require direct access to
1973 * struct eap_peer_config.
1975 struct eap_peer_config * eap_get_config(struct eap_sm *sm)
1977 return sm->eapol_cb->get_config(sm->eapol_ctx);
1982 * eap_get_config_identity - Get identity from the network configuration
1983 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1984 * @len: Buffer for the length of the identity
1985 * Returns: Pointer to the identity or %NULL if not found
1987 const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len)
1989 struct eap_peer_config *config = eap_get_config(sm);
1992 *len = config->identity_len;
1993 return config->identity;
1997 static int eap_get_ext_password(struct eap_sm *sm,
1998 struct eap_peer_config *config)
2002 if (config->password == NULL)
2005 name = os_zalloc(config->password_len + 1);
2008 os_memcpy(name, config->password, config->password_len);
2010 ext_password_free(sm->ext_pw_buf);
2011 sm->ext_pw_buf = ext_password_get(sm->ext_pw, name);
2014 return sm->ext_pw_buf == NULL ? -1 : 0;
2019 * eap_get_config_password - Get password from the network configuration
2020 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2021 * @len: Buffer for the length of the password
2022 * Returns: Pointer to the password or %NULL if not found
2024 const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len)
2026 struct eap_peer_config *config = eap_get_config(sm);
2030 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2031 if (eap_get_ext_password(sm, config) < 0)
2033 *len = wpabuf_len(sm->ext_pw_buf);
2034 return wpabuf_head(sm->ext_pw_buf);
2037 *len = config->password_len;
2038 return config->password;
2043 * eap_get_config_password2 - Get password from the network configuration
2044 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2045 * @len: Buffer for the length of the password
2046 * @hash: Buffer for returning whether the password is stored as a
2047 * NtPasswordHash instead of plaintext password; can be %NULL if this
2048 * information is not needed
2049 * Returns: Pointer to the password or %NULL if not found
2051 const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash)
2053 struct eap_peer_config *config = eap_get_config(sm);
2057 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2058 if (eap_get_ext_password(sm, config) < 0)
2062 *len = wpabuf_len(sm->ext_pw_buf);
2063 return wpabuf_head(sm->ext_pw_buf);
2066 *len = config->password_len;
2068 *hash = !!(config->flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH);
2069 return config->password;
2074 * eap_get_config_new_password - Get new password from network configuration
2075 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2076 * @len: Buffer for the length of the new password
2077 * Returns: Pointer to the new password or %NULL if not found
2079 const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len)
2081 struct eap_peer_config *config = eap_get_config(sm);
2084 *len = config->new_password_len;
2085 return config->new_password;
2090 * eap_get_config_otp - Get one-time password from the network configuration
2091 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2092 * @len: Buffer for the length of the one-time password
2093 * Returns: Pointer to the one-time password or %NULL if not found
2095 const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len)
2097 struct eap_peer_config *config = eap_get_config(sm);
2100 *len = config->otp_len;
2106 * eap_clear_config_otp - Clear used one-time password
2107 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2109 * This function clears a used one-time password (OTP) from the current network
2110 * configuration. This should be called when the OTP has been used and is not
2113 void eap_clear_config_otp(struct eap_sm *sm)
2115 struct eap_peer_config *config = eap_get_config(sm);
2118 os_memset(config->otp, 0, config->otp_len);
2119 os_free(config->otp);
2121 config->otp_len = 0;
2126 * eap_get_config_phase1 - Get phase1 data from the network configuration
2127 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2128 * Returns: Pointer to the phase1 data or %NULL if not found
2130 const char * eap_get_config_phase1(struct eap_sm *sm)
2132 struct eap_peer_config *config = eap_get_config(sm);
2135 return config->phase1;
2140 * eap_get_config_phase2 - Get phase2 data from the network configuration
2141 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2142 * Returns: Pointer to the phase1 data or %NULL if not found
2144 const char * eap_get_config_phase2(struct eap_sm *sm)
2146 struct eap_peer_config *config = eap_get_config(sm);
2149 return config->phase2;
2153 int eap_get_config_fragment_size(struct eap_sm *sm)
2155 struct eap_peer_config *config = eap_get_config(sm);
2158 return config->fragment_size;
2163 * eap_key_available - Get key availability (eapKeyAvailable variable)
2164 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2165 * Returns: 1 if EAP keying material is available, 0 if not
2167 int eap_key_available(struct eap_sm *sm)
2169 return sm ? sm->eapKeyAvailable : 0;
2174 * eap_notify_success - Notify EAP state machine about external success trigger
2175 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2177 * This function is called when external event, e.g., successful completion of
2178 * WPA-PSK key handshake, is indicating that EAP state machine should move to
2179 * success state. This is mainly used with security modes that do not use EAP
2180 * state machine (e.g., WPA-PSK).
2182 void eap_notify_success(struct eap_sm *sm)
2185 sm->decision = DECISION_COND_SUCC;
2186 sm->EAP_state = EAP_SUCCESS;
2192 * eap_notify_lower_layer_success - Notification of lower layer success
2193 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2195 * Notify EAP state machines that a lower layer has detected a successful
2196 * authentication. This is used to recover from dropped EAP-Success messages.
2198 void eap_notify_lower_layer_success(struct eap_sm *sm)
2203 if (eapol_get_bool(sm, EAPOL_eapSuccess) ||
2204 sm->decision == DECISION_FAIL ||
2205 (sm->methodState != METHOD_MAY_CONT &&
2206 sm->methodState != METHOD_DONE))
2209 if (sm->eapKeyData != NULL)
2210 sm->eapKeyAvailable = TRUE;
2211 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
2212 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
2213 "EAP authentication completed successfully (based on lower "
2219 * eap_get_eapSessionId - Get Session-Id from EAP state machine
2220 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2221 * @len: Pointer to variable that will be set to number of bytes in the session
2222 * Returns: Pointer to the EAP Session-Id or %NULL on failure
2224 * Fetch EAP Session-Id from the EAP state machine. The Session-Id is available
2225 * only after a successful authentication. EAP state machine continues to manage
2226 * the Session-Id and the caller must not change or free the returned data.
2228 const u8 * eap_get_eapSessionId(struct eap_sm *sm, size_t *len)
2230 if (sm == NULL || sm->eapSessionId == NULL) {
2235 *len = sm->eapSessionIdLen;
2236 return sm->eapSessionId;
2241 * eap_get_eapKeyData - Get master session key (MSK) from EAP state machine
2242 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2243 * @len: Pointer to variable that will be set to number of bytes in the key
2244 * Returns: Pointer to the EAP keying data or %NULL on failure
2246 * Fetch EAP keying material (MSK, eapKeyData) from the EAP state machine. The
2247 * key is available only after a successful authentication. EAP state machine
2248 * continues to manage the key data and the caller must not change or free the
2251 const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len)
2253 if (sm == NULL || sm->eapKeyData == NULL) {
2258 *len = sm->eapKeyDataLen;
2259 return sm->eapKeyData;
2264 * eap_get_eapKeyData - Get EAP response data
2265 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2266 * Returns: Pointer to the EAP response (eapRespData) or %NULL on failure
2268 * Fetch EAP response (eapRespData) from the EAP state machine. This data is
2269 * available when EAP state machine has processed an incoming EAP request. The
2270 * EAP state machine does not maintain a reference to the response after this
2271 * function is called and the caller is responsible for freeing the data.
2273 struct wpabuf * eap_get_eapRespData(struct eap_sm *sm)
2275 struct wpabuf *resp;
2277 if (sm == NULL || sm->eapRespData == NULL)
2280 resp = sm->eapRespData;
2281 sm->eapRespData = NULL;
2288 * eap_sm_register_scard_ctx - Notification of smart card context
2289 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2290 * @ctx: Context data for smart card operations
2292 * Notify EAP state machines of context data for smart card operations. This
2293 * context data will be used as a parameter for scard_*() functions.
2295 void eap_register_scard_ctx(struct eap_sm *sm, void *ctx)
2298 sm->scard_ctx = ctx;
2303 * eap_set_config_blob - Set or add a named configuration blob
2304 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2305 * @blob: New value for the blob
2307 * Adds a new configuration blob or replaces the current value of an existing
2310 void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob)
2312 #ifndef CONFIG_NO_CONFIG_BLOBS
2313 sm->eapol_cb->set_config_blob(sm->eapol_ctx, blob);
2314 #endif /* CONFIG_NO_CONFIG_BLOBS */
2319 * eap_get_config_blob - Get a named configuration blob
2320 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2321 * @name: Name of the blob
2322 * Returns: Pointer to blob data or %NULL if not found
2324 const struct wpa_config_blob * eap_get_config_blob(struct eap_sm *sm,
2327 #ifndef CONFIG_NO_CONFIG_BLOBS
2328 return sm->eapol_cb->get_config_blob(sm->eapol_ctx, name);
2329 #else /* CONFIG_NO_CONFIG_BLOBS */
2331 #endif /* CONFIG_NO_CONFIG_BLOBS */
2336 * eap_set_force_disabled - Set force_disabled flag
2337 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2338 * @disabled: 1 = EAP disabled, 0 = EAP enabled
2340 * This function is used to force EAP state machine to be disabled when it is
2341 * not in use (e.g., with WPA-PSK or plaintext connections).
2343 void eap_set_force_disabled(struct eap_sm *sm, int disabled)
2345 sm->force_disabled = disabled;
2350 * eap_set_external_sim - Set external_sim flag
2351 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2352 * @external_sim: Whether external SIM/USIM processing is used
2354 void eap_set_external_sim(struct eap_sm *sm, int external_sim)
2356 sm->external_sim = external_sim;
2361 * eap_notify_pending - Notify that EAP method is ready to re-process a request
2362 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2364 * An EAP method can perform a pending operation (e.g., to get a response from
2365 * an external process). Once the response is available, this function can be
2366 * used to request EAPOL state machine to retry delivering the previously
2367 * received (and still unanswered) EAP request to EAP state machine.
2369 void eap_notify_pending(struct eap_sm *sm)
2371 sm->eapol_cb->notify_pending(sm->eapol_ctx);
2376 * eap_invalidate_cached_session - Mark cached session data invalid
2377 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2379 void eap_invalidate_cached_session(struct eap_sm *sm)
2382 eap_deinit_prev_method(sm, "invalidate");
2386 int eap_is_wps_pbc_enrollee(struct eap_peer_config *conf)
2388 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2389 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2390 return 0; /* Not a WPS Enrollee */
2392 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pbc=1") == NULL)
2393 return 0; /* Not using PBC */
2399 int eap_is_wps_pin_enrollee(struct eap_peer_config *conf)
2401 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2402 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2403 return 0; /* Not a WPS Enrollee */
2405 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pin=") == NULL)
2406 return 0; /* Not using PIN */
2412 void eap_sm_set_ext_pw_ctx(struct eap_sm *sm, struct ext_password_data *ext)
2414 ext_password_free(sm->ext_pw_buf);
2415 sm->ext_pw_buf = NULL;
2421 * eap_set_anon_id - Set or add anonymous identity
2422 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2423 * @id: Anonymous identity (e.g., EAP-SIM pseudonym) or %NULL to clear
2424 * @len: Length of anonymous identity in octets
2426 void eap_set_anon_id(struct eap_sm *sm, const u8 *id, size_t len)
2428 if (sm->eapol_cb->set_anon_id)
2429 sm->eapol_cb->set_anon_id(sm->eapol_ctx, id, len);
2433 int eap_peer_was_failure_expected(struct eap_sm *sm)
2435 return sm->expected_failure;