2 * EAP peer state machines (RFC 4137)
3 * Copyright (c) 2004-2012, 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;
186 * This state is reached whenever service from the lower layer is interrupted
187 * or unavailable (portEnabled == FALSE). Immediate transition to INITIALIZE
188 * occurs when the port becomes enabled.
190 SM_STATE(EAP, DISABLED)
192 SM_ENTRY(EAP, DISABLED);
195 * RFC 4137 does not describe clearing of idleWhile here, but doing so
196 * allows the timer tick to be stopped more quickly when EAP is not in
199 eapol_set_int(sm, EAPOL_idleWhile, 0);
204 * The state machine spends most of its time here, waiting for something to
205 * happen. This state is entered unconditionally from INITIALIZE, DISCARD, and
206 * SEND_RESPONSE states.
215 * This state is entered when an EAP packet is received (eapReq == TRUE) to
216 * parse the packet header.
218 SM_STATE(EAP, RECEIVED)
220 const struct wpabuf *eapReqData;
222 SM_ENTRY(EAP, RECEIVED);
223 eapReqData = eapol_get_eapReqData(sm);
224 /* parse rxReq, rxSuccess, rxFailure, reqId, reqMethod */
225 eap_sm_parseEapReq(sm, eapReqData);
231 * This state is entered when a request for a new type comes in. Either the
232 * correct method is started, or a Nak response is built.
234 SM_STATE(EAP, GET_METHOD)
238 const struct eap_method *eap_method;
240 SM_ENTRY(EAP, GET_METHOD);
242 if (sm->reqMethod == EAP_TYPE_EXPANDED)
243 method = sm->reqVendorMethod;
245 method = sm->reqMethod;
247 eap_method = eap_peer_get_eap_method(sm->reqVendor, method);
249 if (!eap_sm_allowMethod(sm, sm->reqVendor, method)) {
250 wpa_printf(MSG_DEBUG, "EAP: vendor %u method %u not allowed",
251 sm->reqVendor, method);
252 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
253 "vendor=%u method=%u -> NAK",
254 sm->reqVendor, method);
255 eap_notify_status(sm, "refuse proposed method",
256 eap_method ? eap_method->name : "unknown");
260 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
261 "vendor=%u method=%u", sm->reqVendor, method);
263 eap_notify_status(sm, "accept proposed method",
264 eap_method ? eap_method->name : "unknown");
266 * RFC 4137 does not define specific operation for fast
267 * re-authentication (session resumption). The design here is to allow
268 * the previously used method data to be maintained for
269 * re-authentication if the method support session resumption.
270 * Otherwise, the previously used method data is freed and a new method
273 if (sm->fast_reauth &&
274 sm->m && sm->m->vendor == sm->reqVendor &&
275 sm->m->method == method &&
276 sm->m->has_reauth_data &&
277 sm->m->has_reauth_data(sm, sm->eap_method_priv)) {
278 wpa_printf(MSG_DEBUG, "EAP: Using previous method data"
279 " for fast re-authentication");
282 eap_deinit_prev_method(sm, "GET_METHOD");
286 sm->selectedMethod = sm->reqMethod;
290 wpa_printf(MSG_DEBUG, "EAP: Could not find selected method: "
291 "vendor %d method %d",
292 sm->reqVendor, method);
296 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
298 wpa_printf(MSG_DEBUG, "EAP: Initialize selected EAP method: "
299 "vendor %u method %u (%s)",
300 sm->reqVendor, method, sm->m->name);
302 sm->eap_method_priv = sm->m->init_for_reauth(
303 sm, sm->eap_method_priv);
305 sm->eap_method_priv = sm->m->init(sm);
307 if (sm->eap_method_priv == NULL) {
308 struct eap_peer_config *config = eap_get_config(sm);
309 wpa_msg(sm->msg_ctx, MSG_INFO,
310 "EAP: Failed to initialize EAP method: vendor %u "
312 sm->reqVendor, method, sm->m->name);
314 sm->methodState = METHOD_NONE;
315 sm->selectedMethod = EAP_TYPE_NONE;
316 if (sm->reqMethod == EAP_TYPE_TLS && config &&
317 (config->pending_req_pin ||
318 config->pending_req_passphrase)) {
320 * Return without generating Nak in order to allow
321 * entering of PIN code or passphrase to retry the
322 * current EAP packet.
324 wpa_printf(MSG_DEBUG, "EAP: Pending PIN/passphrase "
325 "request - skip Nak");
332 sm->methodState = METHOD_INIT;
333 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_METHOD
334 "EAP vendor %u method %u (%s) selected",
335 sm->reqVendor, method, sm->m->name);
339 wpabuf_free(sm->eapRespData);
340 sm->eapRespData = NULL;
341 sm->eapRespData = eap_sm_buildNak(sm, sm->reqId);
346 * The method processing happens here. The request from the authenticator is
347 * processed, and an appropriate response packet is built.
349 SM_STATE(EAP, METHOD)
351 struct wpabuf *eapReqData;
352 struct eap_method_ret ret;
355 SM_ENTRY(EAP, METHOD);
357 wpa_printf(MSG_WARNING, "EAP::METHOD - method not selected");
361 eapReqData = eapol_get_eapReqData(sm);
362 if (sm->m->vendor == EAP_VENDOR_IETF && sm->m->method == EAP_TYPE_LEAP)
363 min_len = 0; /* LEAP uses EAP-Success without payload */
364 if (!eap_hdr_len_valid(eapReqData, min_len))
368 * Get ignore, methodState, decision, allowNotifications, and
369 * eapRespData. RFC 4137 uses three separate method procedure (check,
370 * process, and buildResp) in this state. These have been combined into
371 * a single function call to m->process() in order to optimize EAP
372 * method implementation interface a bit. These procedures are only
373 * used from within this METHOD state, so there is no need to keep
374 * these as separate C functions.
376 * The RFC 4137 procedures return values as follows:
377 * ignore = m.check(eapReqData)
378 * (methodState, decision, allowNotifications) = m.process(eapReqData)
379 * eapRespData = m.buildResp(reqId)
381 os_memset(&ret, 0, sizeof(ret));
382 ret.ignore = sm->ignore;
383 ret.methodState = sm->methodState;
384 ret.decision = sm->decision;
385 ret.allowNotifications = sm->allowNotifications;
386 wpabuf_free(sm->eapRespData);
387 sm->eapRespData = NULL;
388 sm->eapRespData = sm->m->process(sm, sm->eap_method_priv, &ret,
390 wpa_printf(MSG_DEBUG, "EAP: method process -> ignore=%s "
391 "methodState=%s decision=%s",
392 ret.ignore ? "TRUE" : "FALSE",
393 eap_sm_method_state_txt(ret.methodState),
394 eap_sm_decision_txt(ret.decision));
396 sm->ignore = ret.ignore;
399 sm->methodState = ret.methodState;
400 sm->decision = ret.decision;
401 sm->allowNotifications = ret.allowNotifications;
403 if (sm->m->isKeyAvailable && sm->m->getKey &&
404 sm->m->isKeyAvailable(sm, sm->eap_method_priv)) {
405 os_free(sm->eapKeyData);
406 sm->eapKeyData = sm->m->getKey(sm, sm->eap_method_priv,
408 os_free(sm->eapSessionId);
409 sm->eapSessionId = NULL;
410 if (sm->m->getSessionId) {
411 sm->eapSessionId = sm->m->getSessionId(
412 sm, sm->eap_method_priv,
413 &sm->eapSessionIdLen);
414 wpa_hexdump(MSG_DEBUG, "EAP: Session-Id",
415 sm->eapSessionId, sm->eapSessionIdLen);
422 * This state signals the lower layer that a response packet is ready to be
425 SM_STATE(EAP, SEND_RESPONSE)
427 SM_ENTRY(EAP, SEND_RESPONSE);
428 wpabuf_free(sm->lastRespData);
429 if (sm->eapRespData) {
431 os_memcpy(sm->last_md5, sm->req_md5, 16);
432 sm->lastId = sm->reqId;
433 sm->lastRespData = wpabuf_dup(sm->eapRespData);
434 eapol_set_bool(sm, EAPOL_eapResp, TRUE);
436 sm->lastRespData = NULL;
437 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
438 eapol_set_int(sm, EAPOL_idleWhile, sm->ClientTimeout);
443 * This state signals the lower layer that the request was discarded, and no
444 * response packet will be sent at this time.
446 SM_STATE(EAP, DISCARD)
448 SM_ENTRY(EAP, DISCARD);
449 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
450 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
455 * Handles requests for Identity method and builds a response.
457 SM_STATE(EAP, IDENTITY)
459 const struct wpabuf *eapReqData;
461 SM_ENTRY(EAP, IDENTITY);
462 eapReqData = eapol_get_eapReqData(sm);
463 if (!eap_hdr_len_valid(eapReqData, 1))
465 eap_sm_processIdentity(sm, eapReqData);
466 wpabuf_free(sm->eapRespData);
467 sm->eapRespData = NULL;
468 sm->eapRespData = eap_sm_buildIdentity(sm, sm->reqId, 0);
473 * Handles requests for Notification method and builds a response.
475 SM_STATE(EAP, NOTIFICATION)
477 const struct wpabuf *eapReqData;
479 SM_ENTRY(EAP, NOTIFICATION);
480 eapReqData = eapol_get_eapReqData(sm);
481 if (!eap_hdr_len_valid(eapReqData, 1))
483 eap_sm_processNotify(sm, eapReqData);
484 wpabuf_free(sm->eapRespData);
485 sm->eapRespData = NULL;
486 sm->eapRespData = eap_sm_buildNotify(sm->reqId);
491 * This state retransmits the previous response packet.
493 SM_STATE(EAP, RETRANSMIT)
495 SM_ENTRY(EAP, RETRANSMIT);
496 wpabuf_free(sm->eapRespData);
497 if (sm->lastRespData)
498 sm->eapRespData = wpabuf_dup(sm->lastRespData);
500 sm->eapRespData = NULL;
505 * This state is entered in case of a successful completion of authentication
506 * and state machine waits here until port is disabled or EAP authentication is
509 SM_STATE(EAP, SUCCESS)
511 SM_ENTRY(EAP, SUCCESS);
512 if (sm->eapKeyData != NULL)
513 sm->eapKeyAvailable = TRUE;
514 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
517 * RFC 4137 does not clear eapReq here, but this seems to be required
518 * to avoid processing the same request twice when state machine is
521 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
524 * RFC 4137 does not set eapNoResp here, but this seems to be required
525 * to get EAPOL Supplicant backend state machine into SUCCESS state. In
526 * addition, either eapResp or eapNoResp is required to be set after
527 * processing the received EAP frame.
529 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
531 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
532 "EAP authentication completed successfully");
537 * This state is entered in case of a failure and state machine waits here
538 * until port is disabled or EAP authentication is restarted.
540 SM_STATE(EAP, FAILURE)
542 SM_ENTRY(EAP, FAILURE);
543 eapol_set_bool(sm, EAPOL_eapFail, TRUE);
546 * RFC 4137 does not clear eapReq here, but this seems to be required
547 * to avoid processing the same request twice when state machine is
550 eapol_set_bool(sm, EAPOL_eapReq, FALSE);
553 * RFC 4137 does not set eapNoResp here. However, either eapResp or
554 * eapNoResp is required to be set after processing the received EAP
557 eapol_set_bool(sm, EAPOL_eapNoResp, TRUE);
559 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
560 "EAP authentication failed");
562 sm->prev_failure = 1;
566 static int eap_success_workaround(struct eap_sm *sm, int reqId, int lastId)
569 * At least Microsoft IAS and Meetinghouse Aegis seem to be sending
570 * EAP-Success/Failure with lastId + 1 even though RFC 3748 and
571 * RFC 4137 require that reqId == lastId. In addition, it looks like
572 * Ringmaster v2.1.2.0 would be using lastId + 2 in EAP-Success.
574 * Accept this kind of Id if EAP workarounds are enabled. These are
575 * unauthenticated plaintext messages, so this should have minimal
576 * security implications (bit easier to fake EAP-Success/Failure).
578 if (sm->workaround && (reqId == ((lastId + 1) & 0xff) ||
579 reqId == ((lastId + 2) & 0xff))) {
580 wpa_printf(MSG_DEBUG, "EAP: Workaround for unexpected "
581 "identifier field in EAP Success: "
582 "reqId=%d lastId=%d (these are supposed to be "
583 "same)", reqId, lastId);
586 wpa_printf(MSG_DEBUG, "EAP: EAP-Success Id mismatch - reqId=%d "
587 "lastId=%d", reqId, lastId);
593 * RFC 4137 - Appendix A.1: EAP Peer State Machine - State transitions
596 static void eap_peer_sm_step_idle(struct eap_sm *sm)
599 * The first three transitions are from RFC 4137. The last two are
600 * local additions to handle special cases with LEAP and PEAP server
601 * not sending EAP-Success in some cases.
603 if (eapol_get_bool(sm, EAPOL_eapReq))
604 SM_ENTER(EAP, RECEIVED);
605 else if ((eapol_get_bool(sm, EAPOL_altAccept) &&
606 sm->decision != DECISION_FAIL) ||
607 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
608 sm->decision == DECISION_UNCOND_SUCC))
609 SM_ENTER(EAP, SUCCESS);
610 else if (eapol_get_bool(sm, EAPOL_altReject) ||
611 (eapol_get_int(sm, EAPOL_idleWhile) == 0 &&
612 sm->decision != DECISION_UNCOND_SUCC) ||
613 (eapol_get_bool(sm, EAPOL_altAccept) &&
614 sm->methodState != METHOD_CONT &&
615 sm->decision == DECISION_FAIL))
616 SM_ENTER(EAP, FAILURE);
617 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
618 sm->leap_done && sm->decision != DECISION_FAIL &&
619 sm->methodState == METHOD_DONE)
620 SM_ENTER(EAP, SUCCESS);
621 else if (sm->selectedMethod == EAP_TYPE_PEAP &&
622 sm->peap_done && sm->decision != DECISION_FAIL &&
623 sm->methodState == METHOD_DONE)
624 SM_ENTER(EAP, SUCCESS);
628 static int eap_peer_req_is_duplicate(struct eap_sm *sm)
632 duplicate = (sm->reqId == sm->lastId) && sm->rxReq;
633 if (sm->workaround && duplicate &&
634 os_memcmp(sm->req_md5, sm->last_md5, 16) != 0) {
636 * RFC 4137 uses (reqId == lastId) as the only verification for
637 * duplicate EAP requests. However, this misses cases where the
638 * AS is incorrectly using the same id again; and
639 * unfortunately, such implementations exist. Use MD5 hash as
640 * an extra verification for the packets being duplicate to
641 * workaround these issues.
643 wpa_printf(MSG_DEBUG, "EAP: AS used the same Id again, but "
644 "EAP packets were not identical");
645 wpa_printf(MSG_DEBUG, "EAP: workaround - assume this is not a "
654 static void eap_peer_sm_step_received(struct eap_sm *sm)
656 int duplicate = eap_peer_req_is_duplicate(sm);
659 * Two special cases below for LEAP are local additions to work around
660 * odd LEAP behavior (EAP-Success in the middle of authentication and
661 * then swapped roles). Other transitions are based on RFC 4137.
663 if (sm->rxSuccess && sm->decision != DECISION_FAIL &&
664 (sm->reqId == sm->lastId ||
665 eap_success_workaround(sm, sm->reqId, sm->lastId)))
666 SM_ENTER(EAP, SUCCESS);
667 else if (sm->methodState != METHOD_CONT &&
669 sm->decision != DECISION_UNCOND_SUCC) ||
670 (sm->rxSuccess && sm->decision == DECISION_FAIL &&
671 (sm->selectedMethod != EAP_TYPE_LEAP ||
672 sm->methodState != METHOD_MAY_CONT))) &&
673 (sm->reqId == sm->lastId ||
674 eap_success_workaround(sm, sm->reqId, sm->lastId)))
675 SM_ENTER(EAP, FAILURE);
676 else if (sm->rxReq && duplicate)
677 SM_ENTER(EAP, RETRANSMIT);
678 else if (sm->rxReq && !duplicate &&
679 sm->reqMethod == EAP_TYPE_NOTIFICATION &&
680 sm->allowNotifications)
681 SM_ENTER(EAP, NOTIFICATION);
682 else if (sm->rxReq && !duplicate &&
683 sm->selectedMethod == EAP_TYPE_NONE &&
684 sm->reqMethod == EAP_TYPE_IDENTITY)
685 SM_ENTER(EAP, IDENTITY);
686 else if (sm->rxReq && !duplicate &&
687 sm->selectedMethod == EAP_TYPE_NONE &&
688 sm->reqMethod != EAP_TYPE_IDENTITY &&
689 sm->reqMethod != EAP_TYPE_NOTIFICATION)
690 SM_ENTER(EAP, GET_METHOD);
691 else if (sm->rxReq && !duplicate &&
692 sm->reqMethod == sm->selectedMethod &&
693 sm->methodState != METHOD_DONE)
694 SM_ENTER(EAP, METHOD);
695 else if (sm->selectedMethod == EAP_TYPE_LEAP &&
696 (sm->rxSuccess || sm->rxResp))
697 SM_ENTER(EAP, METHOD);
699 SM_ENTER(EAP, DISCARD);
703 static void eap_peer_sm_step_local(struct eap_sm *sm)
705 switch (sm->EAP_state) {
710 if (eapol_get_bool(sm, EAPOL_portEnabled) &&
712 SM_ENTER(EAP, INITIALIZE);
715 eap_peer_sm_step_idle(sm);
718 eap_peer_sm_step_received(sm);
721 if (sm->selectedMethod == sm->reqMethod)
722 SM_ENTER(EAP, METHOD);
724 SM_ENTER(EAP, SEND_RESPONSE);
728 SM_ENTER(EAP, DISCARD);
730 SM_ENTER(EAP, SEND_RESPONSE);
732 case EAP_SEND_RESPONSE:
739 SM_ENTER(EAP, SEND_RESPONSE);
741 case EAP_NOTIFICATION:
742 SM_ENTER(EAP, SEND_RESPONSE);
745 SM_ENTER(EAP, SEND_RESPONSE);
757 /* Global transitions */
758 if (eapol_get_bool(sm, EAPOL_eapRestart) &&
759 eapol_get_bool(sm, EAPOL_portEnabled))
760 SM_ENTER_GLOBAL(EAP, INITIALIZE);
761 else if (!eapol_get_bool(sm, EAPOL_portEnabled) || sm->force_disabled)
762 SM_ENTER_GLOBAL(EAP, DISABLED);
763 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
764 /* RFC 4137 does not place any limit on number of EAP messages
765 * in an authentication session. However, some error cases have
766 * ended up in a state were EAP messages were sent between the
767 * peer and server in a loop (e.g., TLS ACK frame in both
768 * direction). Since this is quite undesired outcome, limit the
769 * total number of EAP round-trips and abort authentication if
770 * this limit is exceeded.
772 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
773 wpa_msg(sm->msg_ctx, MSG_INFO, "EAP: more than %d "
774 "authentication rounds - abort",
775 EAP_MAX_AUTH_ROUNDS);
777 SM_ENTER_GLOBAL(EAP, FAILURE);
780 /* Local transitions */
781 eap_peer_sm_step_local(sm);
786 static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
789 if (!eap_allowed_method(sm, vendor, method)) {
790 wpa_printf(MSG_DEBUG, "EAP: configuration does not allow: "
791 "vendor %u method %u", vendor, method);
794 if (eap_peer_get_eap_method(vendor, method))
796 wpa_printf(MSG_DEBUG, "EAP: not included in build: "
797 "vendor %u method %u", vendor, method);
802 static struct wpabuf * eap_sm_build_expanded_nak(
803 struct eap_sm *sm, int id, const struct eap_method *methods,
808 const struct eap_method *m;
810 wpa_printf(MSG_DEBUG, "EAP: Building expanded EAP-Nak");
812 /* RFC 3748 - 5.3.2: Expanded Nak */
813 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_EXPANDED,
814 8 + 8 * (count + 1), EAP_CODE_RESPONSE, id);
818 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
819 wpabuf_put_be32(resp, EAP_TYPE_NAK);
821 for (m = methods; m; m = m->next) {
822 if (sm->reqVendor == m->vendor &&
823 sm->reqVendorMethod == m->method)
824 continue; /* do not allow the current method again */
825 if (eap_allowed_method(sm, m->vendor, m->method)) {
826 wpa_printf(MSG_DEBUG, "EAP: allowed type: "
827 "vendor=%u method=%u",
828 m->vendor, m->method);
829 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
830 wpabuf_put_be24(resp, m->vendor);
831 wpabuf_put_be32(resp, m->method);
837 wpa_printf(MSG_DEBUG, "EAP: no more allowed methods");
838 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
839 wpabuf_put_be24(resp, EAP_VENDOR_IETF);
840 wpabuf_put_be32(resp, EAP_TYPE_NONE);
843 eap_update_len(resp);
849 static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id)
853 int found = 0, expanded_found = 0;
855 const struct eap_method *methods, *m;
857 wpa_printf(MSG_DEBUG, "EAP: Building EAP-Nak (requested type %u "
858 "vendor=%u method=%u not allowed)", sm->reqMethod,
859 sm->reqVendor, sm->reqVendorMethod);
860 methods = eap_peer_get_methods(&count);
863 if (sm->reqMethod == EAP_TYPE_EXPANDED)
864 return eap_sm_build_expanded_nak(sm, id, methods, count);
866 /* RFC 3748 - 5.3.1: Legacy Nak */
867 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NAK,
868 sizeof(struct eap_hdr) + 1 + count + 1,
869 EAP_CODE_RESPONSE, id);
873 start = wpabuf_put(resp, 0);
874 for (m = methods; m; m = m->next) {
875 if (m->vendor == EAP_VENDOR_IETF && m->method == sm->reqMethod)
876 continue; /* do not allow the current method again */
877 if (eap_allowed_method(sm, m->vendor, m->method)) {
878 if (m->vendor != EAP_VENDOR_IETF) {
882 wpabuf_put_u8(resp, EAP_TYPE_EXPANDED);
884 wpabuf_put_u8(resp, m->method);
889 wpabuf_put_u8(resp, EAP_TYPE_NONE);
890 wpa_hexdump(MSG_DEBUG, "EAP: allowed methods", start, found);
892 eap_update_len(resp);
898 static void eap_sm_processIdentity(struct eap_sm *sm, const struct wpabuf *req)
903 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
904 "EAP authentication started");
905 eap_notify_status(sm, "started", "");
907 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req,
913 * RFC 3748 - 5.1: Identity
914 * Data field may contain a displayable message in UTF-8. If this
915 * includes NUL-character, only the data before that should be
916 * displayed. Some EAP implementasitons may piggy-back additional
917 * options after the NUL.
919 /* TODO: could save displayable message so that it can be shown to the
920 * user in case of interaction is required */
921 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Identity data",
929 * Rules for figuring out MNC length based on IMSI for SIM cards that do not
930 * include MNC length field.
932 static int mnc_len_from_imsi(const char *imsi)
937 os_memcpy(mcc_str, imsi, 3);
942 return 2; /* Networks in Switzerland use 2-digit MNC */
944 return 2; /* Networks in Finland use 2-digit MNC */
950 static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
951 size_t max_len, size_t *imsi_len)
956 if (*imsi_len + 36 > max_len) {
957 wpa_printf(MSG_WARNING, "No room for realm in IMSI buffer");
961 /* MNC (2 or 3 digits) */
962 mnc_len = scard_get_mnc_len(sm->scard_ctx);
964 mnc_len = mnc_len_from_imsi(imsi);
966 wpa_printf(MSG_INFO, "Failed to get MNC length from (U)SIM "
975 } else if (mnc_len == 3) {
982 pos = imsi + *imsi_len;
983 pos += os_snprintf(pos, imsi + max_len - pos,
984 "@wlan.mnc%s.mcc%c%c%c.3gppnetwork.org",
985 mnc, imsi[0], imsi[1], imsi[2]);
986 *imsi_len = pos - imsi;
992 static int eap_sm_imsi_identity(struct eap_sm *sm,
993 struct eap_peer_config *conf)
995 enum { EAP_SM_SIM, EAP_SM_AKA, EAP_SM_AKA_PRIME } method = EAP_SM_SIM;
998 struct eap_method_type *m = conf->eap_methods;
1001 imsi_len = sizeof(imsi);
1002 if (scard_get_imsi(sm->scard_ctx, imsi, &imsi_len)) {
1003 wpa_printf(MSG_WARNING, "Failed to get IMSI from SIM");
1007 wpa_hexdump_ascii(MSG_DEBUG, "IMSI", (u8 *) imsi, imsi_len);
1010 wpa_printf(MSG_WARNING, "Too short IMSI for SIM identity");
1014 if (eap_sm_append_3gpp_realm(sm, imsi, sizeof(imsi), &imsi_len) < 0) {
1015 wpa_printf(MSG_WARNING, "Could not add realm to SIM identity");
1018 wpa_hexdump_ascii(MSG_DEBUG, "IMSI + realm", (u8 *) imsi, imsi_len);
1020 for (i = 0; m && (m[i].vendor != EAP_VENDOR_IETF ||
1021 m[i].method != EAP_TYPE_NONE); i++) {
1022 if (m[i].vendor == EAP_VENDOR_IETF &&
1023 m[i].method == EAP_TYPE_AKA_PRIME) {
1024 method = EAP_SM_AKA_PRIME;
1028 if (m[i].vendor == EAP_VENDOR_IETF &&
1029 m[i].method == EAP_TYPE_AKA) {
1030 method = EAP_SM_AKA;
1035 os_free(conf->identity);
1036 conf->identity = os_malloc(1 + imsi_len);
1037 if (conf->identity == NULL) {
1038 wpa_printf(MSG_WARNING, "Failed to allocate buffer for "
1039 "IMSI-based identity");
1045 conf->identity[0] = '1';
1048 conf->identity[0] = '0';
1050 case EAP_SM_AKA_PRIME:
1051 conf->identity[0] = '6';
1054 os_memcpy(conf->identity + 1, imsi, imsi_len);
1055 conf->identity_len = 1 + imsi_len;
1060 #endif /* PCSC_FUNCS */
1063 static int eap_sm_set_scard_pin(struct eap_sm *sm,
1064 struct eap_peer_config *conf)
1067 if (scard_set_pin(sm->scard_ctx, conf->pin)) {
1069 * Make sure the same PIN is not tried again in order to avoid
1075 wpa_printf(MSG_WARNING, "PIN validation failed");
1076 eap_sm_request_pin(sm);
1080 #else /* PCSC_FUNCS */
1082 #endif /* PCSC_FUNCS */
1085 static int eap_sm_get_scard_identity(struct eap_sm *sm,
1086 struct eap_peer_config *conf)
1089 if (eap_sm_set_scard_pin(sm, conf))
1092 return eap_sm_imsi_identity(sm, conf);
1093 #else /* PCSC_FUNCS */
1095 #endif /* PCSC_FUNCS */
1100 * eap_sm_buildIdentity - Build EAP-Identity/Response for the current network
1101 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1102 * @id: EAP identifier for the packet
1103 * @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
1104 * Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
1107 * This function allocates and builds an EAP-Identity/Response packet for the
1108 * current network. The caller is responsible for freeing the returned data.
1110 struct wpabuf * eap_sm_buildIdentity(struct eap_sm *sm, int id, int encrypted)
1112 struct eap_peer_config *config = eap_get_config(sm);
1113 struct wpabuf *resp;
1115 size_t identity_len;
1117 if (config == NULL) {
1118 wpa_printf(MSG_WARNING, "EAP: buildIdentity: configuration "
1119 "was not available");
1123 if (sm->m && sm->m->get_identity &&
1124 (identity = sm->m->get_identity(sm, sm->eap_method_priv,
1125 &identity_len)) != NULL) {
1126 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using method re-auth "
1127 "identity", identity, identity_len);
1128 } else if (!encrypted && config->anonymous_identity) {
1129 identity = config->anonymous_identity;
1130 identity_len = config->anonymous_identity_len;
1131 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using anonymous identity",
1132 identity, identity_len);
1134 identity = config->identity;
1135 identity_len = config->identity_len;
1136 wpa_hexdump_ascii(MSG_DEBUG, "EAP: using real identity",
1137 identity, identity_len);
1140 if (identity == NULL) {
1141 wpa_printf(MSG_WARNING, "EAP: buildIdentity: identity "
1142 "configuration was not available");
1144 if (eap_sm_get_scard_identity(sm, config) < 0)
1146 identity = config->identity;
1147 identity_len = config->identity_len;
1148 wpa_hexdump_ascii(MSG_DEBUG, "permanent identity from "
1149 "IMSI", identity, identity_len);
1151 eap_sm_request_identity(sm);
1154 } else if (config->pcsc) {
1155 if (eap_sm_set_scard_pin(sm, config) < 0)
1159 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, identity_len,
1160 EAP_CODE_RESPONSE, id);
1164 wpabuf_put_data(resp, identity, identity_len);
1170 static void eap_sm_processNotify(struct eap_sm *sm, const struct wpabuf *req)
1176 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, req,
1180 wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Request Notification data",
1183 msg = os_malloc(msg_len + 1);
1186 for (i = 0; i < msg_len; i++)
1187 msg[i] = isprint(pos[i]) ? (char) pos[i] : '_';
1188 msg[msg_len] = '\0';
1189 wpa_msg(sm->msg_ctx, MSG_INFO, "%s%s",
1190 WPA_EVENT_EAP_NOTIFICATION, msg);
1195 static struct wpabuf * eap_sm_buildNotify(int id)
1197 struct wpabuf *resp;
1199 wpa_printf(MSG_DEBUG, "EAP: Generating EAP-Response Notification");
1200 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_NOTIFICATION, 0,
1201 EAP_CODE_RESPONSE, id);
1209 static void eap_sm_parseEapReq(struct eap_sm *sm, const struct wpabuf *req)
1211 const struct eap_hdr *hdr;
1215 sm->rxReq = sm->rxResp = sm->rxSuccess = sm->rxFailure = FALSE;
1217 sm->reqMethod = EAP_TYPE_NONE;
1218 sm->reqVendor = EAP_VENDOR_IETF;
1219 sm->reqVendorMethod = EAP_TYPE_NONE;
1221 if (req == NULL || wpabuf_len(req) < sizeof(*hdr))
1224 hdr = wpabuf_head(req);
1225 plen = be_to_host16(hdr->length);
1226 if (plen > wpabuf_len(req)) {
1227 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
1228 "(len=%lu plen=%lu)",
1229 (unsigned long) wpabuf_len(req),
1230 (unsigned long) plen);
1234 sm->reqId = hdr->identifier;
1236 if (sm->workaround) {
1238 addr[0] = wpabuf_head(req);
1239 md5_vector(1, addr, &plen, sm->req_md5);
1242 switch (hdr->code) {
1243 case EAP_CODE_REQUEST:
1244 if (plen < sizeof(*hdr) + 1) {
1245 wpa_printf(MSG_DEBUG, "EAP: Too short EAP-Request - "
1250 pos = (const u8 *) (hdr + 1);
1251 sm->reqMethod = *pos++;
1252 if (sm->reqMethod == EAP_TYPE_EXPANDED) {
1253 if (plen < sizeof(*hdr) + 8) {
1254 wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
1255 "expanded EAP-Packet (plen=%lu)",
1256 (unsigned long) plen);
1259 sm->reqVendor = WPA_GET_BE24(pos);
1261 sm->reqVendorMethod = WPA_GET_BE32(pos);
1263 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Request id=%d "
1264 "method=%u vendor=%u vendorMethod=%u",
1265 sm->reqId, sm->reqMethod, sm->reqVendor,
1266 sm->reqVendorMethod);
1268 case EAP_CODE_RESPONSE:
1269 if (sm->selectedMethod == EAP_TYPE_LEAP) {
1271 * LEAP differs from RFC 4137 by using reversed roles
1272 * for mutual authentication and because of this, we
1273 * need to accept EAP-Response frames if LEAP is used.
1275 if (plen < sizeof(*hdr) + 1) {
1276 wpa_printf(MSG_DEBUG, "EAP: Too short "
1277 "EAP-Response - no Type field");
1281 pos = (const u8 *) (hdr + 1);
1282 sm->reqMethod = *pos;
1283 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Response for "
1284 "LEAP method=%d id=%d",
1285 sm->reqMethod, sm->reqId);
1288 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Response");
1290 case EAP_CODE_SUCCESS:
1291 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Success");
1292 eap_notify_status(sm, "completion", "success");
1293 sm->rxSuccess = TRUE;
1295 case EAP_CODE_FAILURE:
1296 wpa_printf(MSG_DEBUG, "EAP: Received EAP-Failure");
1297 eap_notify_status(sm, "completion", "failure");
1298 sm->rxFailure = TRUE;
1301 wpa_printf(MSG_DEBUG, "EAP: Ignored EAP-Packet with unknown "
1302 "code %d", hdr->code);
1308 static void eap_peer_sm_tls_event(void *ctx, enum tls_event ev,
1309 union tls_event_data *data)
1311 struct eap_sm *sm = ctx;
1312 char *hash_hex = NULL;
1315 case TLS_CERT_CHAIN_SUCCESS:
1316 eap_notify_status(sm, "remote certificate verification",
1319 case TLS_CERT_CHAIN_FAILURE:
1320 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TLS_CERT_ERROR
1321 "reason=%d depth=%d subject='%s' err='%s'",
1322 data->cert_fail.reason,
1323 data->cert_fail.depth,
1324 data->cert_fail.subject,
1325 data->cert_fail.reason_txt);
1326 eap_notify_status(sm, "remote certificate verification",
1327 data->cert_fail.reason_txt);
1329 case TLS_PEER_CERTIFICATE:
1330 if (!sm->eapol_cb->notify_cert)
1333 if (data->peer_cert.hash) {
1334 size_t len = data->peer_cert.hash_len * 2 + 1;
1335 hash_hex = os_malloc(len);
1337 wpa_snprintf_hex(hash_hex, len,
1338 data->peer_cert.hash,
1339 data->peer_cert.hash_len);
1343 sm->eapol_cb->notify_cert(sm->eapol_ctx,
1344 data->peer_cert.depth,
1345 data->peer_cert.subject,
1346 hash_hex, data->peer_cert.cert);
1349 if (data->alert.is_local)
1350 eap_notify_status(sm, "local TLS alert",
1351 data->alert.description);
1353 eap_notify_status(sm, "remote TLS alert",
1354 data->alert.description);
1363 * eap_peer_sm_init - Allocate and initialize EAP peer state machine
1364 * @eapol_ctx: Context data to be used with eapol_cb calls
1365 * @eapol_cb: Pointer to EAPOL callback functions
1366 * @msg_ctx: Context data for wpa_msg() calls
1367 * @conf: EAP configuration
1368 * Returns: Pointer to the allocated EAP state machine or %NULL on failure
1370 * This function allocates and initializes an EAP state machine. In addition,
1371 * this initializes TLS library for the new EAP state machine. eapol_cb pointer
1372 * will be in use until eap_peer_sm_deinit() is used to deinitialize this EAP
1373 * state machine. Consequently, the caller must make sure that this data
1374 * structure remains alive while the EAP state machine is active.
1376 struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
1377 struct eapol_callbacks *eapol_cb,
1378 void *msg_ctx, struct eap_config *conf)
1381 struct tls_config tlsconf;
1383 sm = os_zalloc(sizeof(*sm));
1386 sm->eapol_ctx = eapol_ctx;
1387 sm->eapol_cb = eapol_cb;
1388 sm->msg_ctx = msg_ctx;
1389 sm->ClientTimeout = EAP_CLIENT_TIMEOUT_DEFAULT;
1390 sm->wps = conf->wps;
1392 os_memset(&tlsconf, 0, sizeof(tlsconf));
1393 tlsconf.opensc_engine_path = conf->opensc_engine_path;
1394 tlsconf.pkcs11_engine_path = conf->pkcs11_engine_path;
1395 tlsconf.pkcs11_module_path = conf->pkcs11_module_path;
1397 tlsconf.fips_mode = 1;
1398 #endif /* CONFIG_FIPS */
1399 tlsconf.event_cb = eap_peer_sm_tls_event;
1400 tlsconf.cb_ctx = sm;
1401 tlsconf.cert_in_cb = conf->cert_in_cb;
1402 sm->ssl_ctx = tls_init(&tlsconf);
1403 if (sm->ssl_ctx == NULL) {
1404 wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS "
1410 sm->ssl_ctx2 = tls_init(&tlsconf);
1411 if (sm->ssl_ctx2 == NULL) {
1412 wpa_printf(MSG_INFO, "SSL: Failed to initialize TLS "
1414 /* Run without separate TLS context within TLS tunnel */
1422 * eap_peer_sm_deinit - Deinitialize and free an EAP peer state machine
1423 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1425 * This function deinitializes EAP state machine and frees all allocated
1428 void eap_peer_sm_deinit(struct eap_sm *sm)
1432 eap_deinit_prev_method(sm, "EAP deinit");
1435 tls_deinit(sm->ssl_ctx2);
1436 tls_deinit(sm->ssl_ctx);
1442 * eap_peer_sm_step - Step EAP peer state machine
1443 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1444 * Returns: 1 if EAP state was changed or 0 if not
1446 * This function advances EAP state machine to a new state to match with the
1447 * current variables. This should be called whenever variables used by the EAP
1448 * state machine have changed.
1450 int eap_peer_sm_step(struct eap_sm *sm)
1454 sm->changed = FALSE;
1458 } while (sm->changed);
1464 * eap_sm_abort - Abort EAP authentication
1465 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1467 * Release system resources that have been allocated for the authentication
1468 * session without fully deinitializing the EAP state machine.
1470 void eap_sm_abort(struct eap_sm *sm)
1472 wpabuf_free(sm->lastRespData);
1473 sm->lastRespData = NULL;
1474 wpabuf_free(sm->eapRespData);
1475 sm->eapRespData = NULL;
1476 os_free(sm->eapKeyData);
1477 sm->eapKeyData = NULL;
1478 os_free(sm->eapSessionId);
1479 sm->eapSessionId = NULL;
1481 /* This is not clearly specified in the EAP statemachines draft, but
1482 * it seems necessary to make sure that some of the EAPOL variables get
1483 * cleared for the next authentication. */
1484 eapol_set_bool(sm, EAPOL_eapSuccess, FALSE);
1488 #ifdef CONFIG_CTRL_IFACE
1489 static const char * eap_sm_state_txt(int state)
1492 case EAP_INITIALIZE:
1493 return "INITIALIZE";
1500 case EAP_GET_METHOD:
1501 return "GET_METHOD";
1504 case EAP_SEND_RESPONSE:
1505 return "SEND_RESPONSE";
1510 case EAP_NOTIFICATION:
1511 return "NOTIFICATION";
1512 case EAP_RETRANSMIT:
1513 return "RETRANSMIT";
1522 #endif /* CONFIG_CTRL_IFACE */
1525 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1526 static const char * eap_sm_method_state_txt(EapMethodState state)
1535 case METHOD_MAY_CONT:
1545 static const char * eap_sm_decision_txt(EapDecision decision)
1550 case DECISION_COND_SUCC:
1552 case DECISION_UNCOND_SUCC:
1553 return "UNCOND_SUCC";
1558 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1561 #ifdef CONFIG_CTRL_IFACE
1564 * eap_sm_get_status - Get EAP state machine status
1565 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1566 * @buf: Buffer for status information
1567 * @buflen: Maximum buffer length
1568 * @verbose: Whether to include verbose status information
1569 * Returns: Number of bytes written to buf.
1571 * Query EAP state machine for status information. This function fills in a
1572 * text area with current status information from the EAPOL state machine. If
1573 * the buffer (buf) is not large enough, status information will be truncated
1574 * to fit the buffer.
1576 int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
1583 len = os_snprintf(buf, buflen,
1585 eap_sm_state_txt(sm->EAP_state));
1586 if (len < 0 || (size_t) len >= buflen)
1589 if (sm->selectedMethod != EAP_TYPE_NONE) {
1594 const struct eap_method *m =
1595 eap_peer_get_eap_method(EAP_VENDOR_IETF,
1596 sm->selectedMethod);
1602 ret = os_snprintf(buf + len, buflen - len,
1603 "selectedMethod=%d (EAP-%s)\n",
1604 sm->selectedMethod, name);
1605 if (ret < 0 || (size_t) ret >= buflen - len)
1609 if (sm->m && sm->m->get_status) {
1610 len += sm->m->get_status(sm, sm->eap_method_priv,
1611 buf + len, buflen - len,
1617 ret = os_snprintf(buf + len, buflen - len,
1621 "ClientTimeout=%d\n",
1623 eap_sm_method_state_txt(sm->methodState),
1624 eap_sm_decision_txt(sm->decision),
1626 if (ret < 0 || (size_t) ret >= buflen - len)
1633 #endif /* CONFIG_CTRL_IFACE */
1636 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1637 static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
1638 const char *msg, size_t msglen)
1640 struct eap_peer_config *config;
1641 char *txt = NULL, *tmp;
1645 config = eap_get_config(sm);
1650 case WPA_CTRL_REQ_EAP_IDENTITY:
1651 config->pending_req_identity++;
1653 case WPA_CTRL_REQ_EAP_PASSWORD:
1654 config->pending_req_password++;
1656 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
1657 config->pending_req_new_password++;
1659 case WPA_CTRL_REQ_EAP_PIN:
1660 config->pending_req_pin++;
1662 case WPA_CTRL_REQ_EAP_OTP:
1664 tmp = os_malloc(msglen + 3);
1668 os_memcpy(tmp + 1, msg, msglen);
1669 tmp[msglen + 1] = ']';
1670 tmp[msglen + 2] = '\0';
1672 os_free(config->pending_req_otp);
1673 config->pending_req_otp = tmp;
1674 config->pending_req_otp_len = msglen + 3;
1676 if (config->pending_req_otp == NULL)
1678 txt = config->pending_req_otp;
1681 case WPA_CTRL_REQ_EAP_PASSPHRASE:
1682 config->pending_req_passphrase++;
1688 if (sm->eapol_cb->eap_param_needed)
1689 sm->eapol_cb->eap_param_needed(sm->eapol_ctx, field, txt);
1691 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1692 #define eap_sm_request(sm, type, msg, msglen) do { } while (0)
1693 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1695 const char * eap_sm_get_method_name(struct eap_sm *sm)
1704 * eap_sm_request_identity - Request identity from user (ctrl_iface)
1705 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1707 * EAP methods can call this function to request identity information for the
1708 * current network. This is normally called when the identity is not included
1709 * in the network configuration. The request will be sent to monitor programs
1710 * through the control interface.
1712 void eap_sm_request_identity(struct eap_sm *sm)
1714 eap_sm_request(sm, WPA_CTRL_REQ_EAP_IDENTITY, NULL, 0);
1719 * eap_sm_request_password - Request password from user (ctrl_iface)
1720 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1722 * EAP methods can call this function to request password information for the
1723 * current network. This is normally called when the password is not included
1724 * in the network configuration. The request will be sent to monitor programs
1725 * through the control interface.
1727 void eap_sm_request_password(struct eap_sm *sm)
1729 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSWORD, NULL, 0);
1734 * eap_sm_request_new_password - Request new password from user (ctrl_iface)
1735 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1737 * EAP methods can call this function to request new password information for
1738 * the current network. This is normally called when the EAP method indicates
1739 * that the current password has expired and password change is required. The
1740 * request will be sent to monitor programs through the control interface.
1742 void eap_sm_request_new_password(struct eap_sm *sm)
1744 eap_sm_request(sm, WPA_CTRL_REQ_EAP_NEW_PASSWORD, NULL, 0);
1749 * eap_sm_request_pin - Request SIM or smart card PIN from user (ctrl_iface)
1750 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1752 * EAP methods can call this function to request SIM or smart card PIN
1753 * information for the current network. This is normally called when the PIN is
1754 * not included in the network configuration. The request will be sent to
1755 * monitor programs through the control interface.
1757 void eap_sm_request_pin(struct eap_sm *sm)
1759 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PIN, NULL, 0);
1764 * eap_sm_request_otp - Request one time password from user (ctrl_iface)
1765 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1766 * @msg: Message to be displayed to the user when asking for OTP
1767 * @msg_len: Length of the user displayable message
1769 * EAP methods can call this function to request open time password (OTP) for
1770 * the current network. The request will be sent to monitor programs through
1771 * the control interface.
1773 void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
1775 eap_sm_request(sm, WPA_CTRL_REQ_EAP_OTP, msg, msg_len);
1780 * eap_sm_request_passphrase - Request passphrase from user (ctrl_iface)
1781 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1783 * EAP methods can call this function to request passphrase for a private key
1784 * for the current network. This is normally called when the passphrase is not
1785 * included in the network configuration. The request will be sent to monitor
1786 * programs through the control interface.
1788 void eap_sm_request_passphrase(struct eap_sm *sm)
1790 eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSPHRASE, NULL, 0);
1795 * eap_sm_notify_ctrl_attached - Notification of attached monitor
1796 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1798 * Notify EAP state machines that a monitor was attached to the control
1799 * interface to trigger re-sending of pending requests for user input.
1801 void eap_sm_notify_ctrl_attached(struct eap_sm *sm)
1803 struct eap_peer_config *config = eap_get_config(sm);
1808 /* Re-send any pending requests for user data since a new control
1809 * interface was added. This handles cases where the EAP authentication
1810 * starts immediately after system startup when the user interface is
1811 * not yet running. */
1812 if (config->pending_req_identity)
1813 eap_sm_request_identity(sm);
1814 if (config->pending_req_password)
1815 eap_sm_request_password(sm);
1816 if (config->pending_req_new_password)
1817 eap_sm_request_new_password(sm);
1818 if (config->pending_req_otp)
1819 eap_sm_request_otp(sm, NULL, 0);
1820 if (config->pending_req_pin)
1821 eap_sm_request_pin(sm);
1822 if (config->pending_req_passphrase)
1823 eap_sm_request_passphrase(sm);
1827 static int eap_allowed_phase2_type(int vendor, int type)
1829 if (vendor != EAP_VENDOR_IETF)
1831 return type != EAP_TYPE_PEAP && type != EAP_TYPE_TTLS &&
1832 type != EAP_TYPE_FAST;
1837 * eap_get_phase2_type - Get EAP type for the given EAP phase 2 method name
1838 * @name: EAP method name, e.g., MD5
1839 * @vendor: Buffer for returning EAP Vendor-Id
1840 * Returns: EAP method type or %EAP_TYPE_NONE if not found
1842 * This function maps EAP type names into EAP type numbers that are allowed for
1843 * Phase 2, i.e., for tunneled authentication. Phase 2 is used, e.g., with
1844 * EAP-PEAP, EAP-TTLS, and EAP-FAST.
1846 u32 eap_get_phase2_type(const char *name, int *vendor)
1849 u8 type = eap_peer_get_type(name, &v);
1850 if (eap_allowed_phase2_type(v, type)) {
1854 *vendor = EAP_VENDOR_IETF;
1855 return EAP_TYPE_NONE;
1860 * eap_get_phase2_types - Get list of allowed EAP phase 2 types
1861 * @config: Pointer to a network configuration
1862 * @count: Pointer to a variable to be filled with number of returned EAP types
1863 * Returns: Pointer to allocated type list or %NULL on failure
1865 * This function generates an array of allowed EAP phase 2 (tunneled) types for
1866 * the given network configuration.
1868 struct eap_method_type * eap_get_phase2_types(struct eap_peer_config *config,
1871 struct eap_method_type *buf;
1875 const struct eap_method *methods, *m;
1877 methods = eap_peer_get_methods(&mcount);
1878 if (methods == NULL)
1881 buf = os_malloc(mcount * sizeof(struct eap_method_type));
1885 for (m = methods; m; m = m->next) {
1888 if (eap_allowed_phase2_type(vendor, method)) {
1889 if (vendor == EAP_VENDOR_IETF &&
1890 method == EAP_TYPE_TLS && config &&
1891 config->private_key2 == NULL)
1893 buf[*count].vendor = vendor;
1894 buf[*count].method = method;
1904 * eap_set_fast_reauth - Update fast_reauth setting
1905 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1906 * @enabled: 1 = Fast reauthentication is enabled, 0 = Disabled
1908 void eap_set_fast_reauth(struct eap_sm *sm, int enabled)
1910 sm->fast_reauth = enabled;
1915 * eap_set_workaround - Update EAP workarounds setting
1916 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1917 * @workaround: 1 = Enable EAP workarounds, 0 = Disable EAP workarounds
1919 void eap_set_workaround(struct eap_sm *sm, unsigned int workaround)
1921 sm->workaround = workaround;
1926 * eap_get_config - Get current network configuration
1927 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1928 * Returns: Pointer to the current network configuration or %NULL if not found
1930 * EAP peer methods should avoid using this function if they can use other
1931 * access functions, like eap_get_config_identity() and
1932 * eap_get_config_password(), that do not require direct access to
1933 * struct eap_peer_config.
1935 struct eap_peer_config * eap_get_config(struct eap_sm *sm)
1937 return sm->eapol_cb->get_config(sm->eapol_ctx);
1942 * eap_get_config_identity - Get identity from the network configuration
1943 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1944 * @len: Buffer for the length of the identity
1945 * Returns: Pointer to the identity or %NULL if not found
1947 const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len)
1949 struct eap_peer_config *config = eap_get_config(sm);
1952 *len = config->identity_len;
1953 return config->identity;
1957 static int eap_get_ext_password(struct eap_sm *sm,
1958 struct eap_peer_config *config)
1962 if (config->password == NULL)
1965 name = os_zalloc(config->password_len + 1);
1968 os_memcpy(name, config->password, config->password_len);
1970 ext_password_free(sm->ext_pw_buf);
1971 sm->ext_pw_buf = ext_password_get(sm->ext_pw, name);
1974 return sm->ext_pw_buf == NULL ? -1 : 0;
1979 * eap_get_config_password - Get password from the network configuration
1980 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
1981 * @len: Buffer for the length of the password
1982 * Returns: Pointer to the password or %NULL if not found
1984 const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len)
1986 struct eap_peer_config *config = eap_get_config(sm);
1990 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1991 if (eap_get_ext_password(sm, config) < 0)
1993 *len = wpabuf_len(sm->ext_pw_buf);
1994 return wpabuf_head(sm->ext_pw_buf);
1997 *len = config->password_len;
1998 return config->password;
2003 * eap_get_config_password2 - Get password from the network configuration
2004 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2005 * @len: Buffer for the length of the password
2006 * @hash: Buffer for returning whether the password is stored as a
2007 * NtPasswordHash instead of plaintext password; can be %NULL if this
2008 * information is not needed
2009 * Returns: Pointer to the password or %NULL if not found
2011 const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash)
2013 struct eap_peer_config *config = eap_get_config(sm);
2017 if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
2018 if (eap_get_ext_password(sm, config) < 0)
2020 *len = wpabuf_len(sm->ext_pw_buf);
2021 return wpabuf_head(sm->ext_pw_buf);
2024 *len = config->password_len;
2026 *hash = !!(config->flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH);
2027 return config->password;
2032 * eap_get_config_new_password - Get new password from network configuration
2033 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2034 * @len: Buffer for the length of the new password
2035 * Returns: Pointer to the new password or %NULL if not found
2037 const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len)
2039 struct eap_peer_config *config = eap_get_config(sm);
2042 *len = config->new_password_len;
2043 return config->new_password;
2048 * eap_get_config_otp - Get one-time password from the network configuration
2049 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2050 * @len: Buffer for the length of the one-time password
2051 * Returns: Pointer to the one-time password or %NULL if not found
2053 const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len)
2055 struct eap_peer_config *config = eap_get_config(sm);
2058 *len = config->otp_len;
2064 * eap_clear_config_otp - Clear used one-time password
2065 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2067 * This function clears a used one-time password (OTP) from the current network
2068 * configuration. This should be called when the OTP has been used and is not
2071 void eap_clear_config_otp(struct eap_sm *sm)
2073 struct eap_peer_config *config = eap_get_config(sm);
2076 os_memset(config->otp, 0, config->otp_len);
2077 os_free(config->otp);
2079 config->otp_len = 0;
2084 * eap_get_config_phase1 - Get phase1 data from the network configuration
2085 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2086 * Returns: Pointer to the phase1 data or %NULL if not found
2088 const char * eap_get_config_phase1(struct eap_sm *sm)
2090 struct eap_peer_config *config = eap_get_config(sm);
2093 return config->phase1;
2098 * eap_get_config_phase2 - Get phase2 data from the network configuration
2099 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2100 * Returns: Pointer to the phase1 data or %NULL if not found
2102 const char * eap_get_config_phase2(struct eap_sm *sm)
2104 struct eap_peer_config *config = eap_get_config(sm);
2107 return config->phase2;
2111 int eap_get_config_fragment_size(struct eap_sm *sm)
2113 struct eap_peer_config *config = eap_get_config(sm);
2116 return config->fragment_size;
2121 * eap_key_available - Get key availability (eapKeyAvailable variable)
2122 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2123 * Returns: 1 if EAP keying material is available, 0 if not
2125 int eap_key_available(struct eap_sm *sm)
2127 return sm ? sm->eapKeyAvailable : 0;
2132 * eap_notify_success - Notify EAP state machine about external success trigger
2133 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2135 * This function is called when external event, e.g., successful completion of
2136 * WPA-PSK key handshake, is indicating that EAP state machine should move to
2137 * success state. This is mainly used with security modes that do not use EAP
2138 * state machine (e.g., WPA-PSK).
2140 void eap_notify_success(struct eap_sm *sm)
2143 sm->decision = DECISION_COND_SUCC;
2144 sm->EAP_state = EAP_SUCCESS;
2150 * eap_notify_lower_layer_success - Notification of lower layer success
2151 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2153 * Notify EAP state machines that a lower layer has detected a successful
2154 * authentication. This is used to recover from dropped EAP-Success messages.
2156 void eap_notify_lower_layer_success(struct eap_sm *sm)
2161 if (eapol_get_bool(sm, EAPOL_eapSuccess) ||
2162 sm->decision == DECISION_FAIL ||
2163 (sm->methodState != METHOD_MAY_CONT &&
2164 sm->methodState != METHOD_DONE))
2167 if (sm->eapKeyData != NULL)
2168 sm->eapKeyAvailable = TRUE;
2169 eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);
2170 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
2171 "EAP authentication completed successfully (based on lower "
2177 * eap_get_eapSessionId - Get Session-Id from EAP state machine
2178 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2179 * @len: Pointer to variable that will be set to number of bytes in the session
2180 * Returns: Pointer to the EAP Session-Id or %NULL on failure
2182 * Fetch EAP Session-Id from the EAP state machine. The Session-Id is available
2183 * only after a successful authentication. EAP state machine continues to manage
2184 * the Session-Id and the caller must not change or free the returned data.
2186 const u8 * eap_get_eapSessionId(struct eap_sm *sm, size_t *len)
2188 if (sm == NULL || sm->eapSessionId == NULL) {
2193 *len = sm->eapSessionIdLen;
2194 return sm->eapSessionId;
2199 * eap_get_eapKeyData - Get master session key (MSK) from EAP state machine
2200 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2201 * @len: Pointer to variable that will be set to number of bytes in the key
2202 * Returns: Pointer to the EAP keying data or %NULL on failure
2204 * Fetch EAP keying material (MSK, eapKeyData) from the EAP state machine. The
2205 * key is available only after a successful authentication. EAP state machine
2206 * continues to manage the key data and the caller must not change or free the
2209 const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len)
2211 if (sm == NULL || sm->eapKeyData == NULL) {
2216 *len = sm->eapKeyDataLen;
2217 return sm->eapKeyData;
2222 * eap_get_eapKeyData - Get EAP response data
2223 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2224 * Returns: Pointer to the EAP response (eapRespData) or %NULL on failure
2226 * Fetch EAP response (eapRespData) from the EAP state machine. This data is
2227 * available when EAP state machine has processed an incoming EAP request. The
2228 * EAP state machine does not maintain a reference to the response after this
2229 * function is called and the caller is responsible for freeing the data.
2231 struct wpabuf * eap_get_eapRespData(struct eap_sm *sm)
2233 struct wpabuf *resp;
2235 if (sm == NULL || sm->eapRespData == NULL)
2238 resp = sm->eapRespData;
2239 sm->eapRespData = NULL;
2246 * eap_sm_register_scard_ctx - Notification of smart card context
2247 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2248 * @ctx: Context data for smart card operations
2250 * Notify EAP state machines of context data for smart card operations. This
2251 * context data will be used as a parameter for scard_*() functions.
2253 void eap_register_scard_ctx(struct eap_sm *sm, void *ctx)
2256 sm->scard_ctx = ctx;
2261 * eap_set_config_blob - Set or add a named configuration blob
2262 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2263 * @blob: New value for the blob
2265 * Adds a new configuration blob or replaces the current value of an existing
2268 void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob)
2270 #ifndef CONFIG_NO_CONFIG_BLOBS
2271 sm->eapol_cb->set_config_blob(sm->eapol_ctx, blob);
2272 #endif /* CONFIG_NO_CONFIG_BLOBS */
2277 * eap_get_config_blob - Get a named configuration blob
2278 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2279 * @name: Name of the blob
2280 * Returns: Pointer to blob data or %NULL if not found
2282 const struct wpa_config_blob * eap_get_config_blob(struct eap_sm *sm,
2285 #ifndef CONFIG_NO_CONFIG_BLOBS
2286 return sm->eapol_cb->get_config_blob(sm->eapol_ctx, name);
2287 #else /* CONFIG_NO_CONFIG_BLOBS */
2289 #endif /* CONFIG_NO_CONFIG_BLOBS */
2294 * eap_set_force_disabled - Set force_disabled flag
2295 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2296 * @disabled: 1 = EAP disabled, 0 = EAP enabled
2298 * This function is used to force EAP state machine to be disabled when it is
2299 * not in use (e.g., with WPA-PSK or plaintext connections).
2301 void eap_set_force_disabled(struct eap_sm *sm, int disabled)
2303 sm->force_disabled = disabled;
2308 * eap_notify_pending - Notify that EAP method is ready to re-process a request
2309 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2311 * An EAP method can perform a pending operation (e.g., to get a response from
2312 * an external process). Once the response is available, this function can be
2313 * used to request EAPOL state machine to retry delivering the previously
2314 * received (and still unanswered) EAP request to EAP state machine.
2316 void eap_notify_pending(struct eap_sm *sm)
2318 sm->eapol_cb->notify_pending(sm->eapol_ctx);
2323 * eap_invalidate_cached_session - Mark cached session data invalid
2324 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2326 void eap_invalidate_cached_session(struct eap_sm *sm)
2329 eap_deinit_prev_method(sm, "invalidate");
2333 int eap_is_wps_pbc_enrollee(struct eap_peer_config *conf)
2335 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2336 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2337 return 0; /* Not a WPS Enrollee */
2339 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pbc=1") == NULL)
2340 return 0; /* Not using PBC */
2346 int eap_is_wps_pin_enrollee(struct eap_peer_config *conf)
2348 if (conf->identity_len != WSC_ID_ENROLLEE_LEN ||
2349 os_memcmp(conf->identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN))
2350 return 0; /* Not a WPS Enrollee */
2352 if (conf->phase1 == NULL || os_strstr(conf->phase1, "pin=") == NULL)
2353 return 0; /* Not using PIN */
2359 void eap_sm_set_ext_pw_ctx(struct eap_sm *sm, struct ext_password_data *ext)
2361 ext_password_free(sm->ext_pw_buf);
2362 sm->ext_pw_buf = NULL;
2368 * eap_set_anon_id - Set or add anonymous identity
2369 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
2370 * @id: Anonymous identity (e.g., EAP-SIM pseudonym) or %NULL to clear
2371 * @len: Length of anonymous identity in octets
2373 void eap_set_anon_id(struct eap_sm *sm, const u8 *id, size_t len)
2375 if (sm->eapol_cb->set_anon_id)
2376 sm->eapol_cb->set_anon_id(sm->eapol_ctx, id, len);