Home | History | Annotate | Download | only in eap_server

Lines Matching refs:sm

33 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
36 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp);
38 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id);
39 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
40 static int eap_sm_nextId(struct eap_sm *sm, int id);
41 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
43 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
44 static int eap_sm_Policy_getDecision(struct eap_sm *sm);
45 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
48 static int eap_get_erp_send_reauth_start(struct eap_sm *sm)
50 if (sm->eapol_cb->get_erp_send_reauth_start)
51 return sm->eapol_cb->get_erp_send_reauth_start(sm->eapol_ctx);
56 static const char * eap_get_erp_domain(struct eap_sm *sm)
58 if (sm->eapol_cb->get_erp_domain)
59 return sm->eapol_cb->get_erp_domain(sm->eapol_ctx);
66 static struct eap_server_erp_key * eap_erp_get_key(struct eap_sm *sm,
69 if (sm->eapol_cb->erp_get_key)
70 return sm->eapol_cb->erp_get_key(sm->eapol_ctx, keyname);
75 static int eap_erp_add_key(struct eap_sm *sm, struct eap_server_erp_key *erp)
77 if (sm->eapol_cb->erp_add_key)
78 return sm->eapol_cb->erp_add_key(sm->eapol_ctx, erp);
85 static struct wpabuf * eap_sm_buildInitiateReauthStart(struct eap_sm *sm,
93 domain = eap_get_erp_domain(sm);
151 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
158 * selected based on the specified identity. sm->user and
159 * sm->user_eap_method_index are updated for the new user when a matching user
160 * is found. sm->user can be used to get user information (e.g., password).
162 int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
167 if (sm == NULL || sm->eapol_cb == NULL ||
168 sm->eapol_cb->get_eap_user == NULL)
171 eap_user_free(sm->user);
172 sm->user = NULL;
178 if (sm->eapol_cb->get_eap_user(sm->eapol_ctx, identity,
184 sm->user = user;
185 sm->user_eap_method_index = 0;
191 void eap_log_msg(struct eap_sm *sm, const char *fmt, ...)
197 if (sm == NULL || sm->eapol_cb == NULL || sm->eapol_cb->log_msg == NULL)
211 sm->eapol_cb->log_msg(sm->eapol_ctx, buf);
220 sm->num_rounds = 0;
228 if (sm->eap_if.eapRestart && !sm->eap_server && sm->identity) {
233 eap_server_clear_identity(sm);
236 sm->try_initiate_reauth = FALSE;
237 sm->currentId = -1;
238 sm->eap_if.eapSuccess = FALSE;
239 sm->eap_if.eapFail = FALSE;
240 sm->eap_if.eapTimeout = FALSE;
241 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
242 sm->eap_if.eapKeyData = NULL;
243 sm->eap_if.eapKeyDataLen = 0;
244 os_free(sm->eap_if.eapSessionId);
245 sm->eap_if.eapSessionId = NULL;
246 sm->eap_if.eapSessionIdLen = 0;
247 sm->eap_if.eapKeyAvailable = FALSE;
248 sm->eap_if.eapRestart = FALSE;
255 if (sm->m && sm->eap_method_priv) {
256 sm->m->reset(sm, sm->eap_method_priv);
257 sm->eap_method_priv = NULL;
259 sm->m = NULL;
260 sm->user_eap_method_index = 0;
262 if (sm->backend_auth) {
263 sm->currentMethod = EAP_TYPE_NONE;
265 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
266 if (sm->rxResp) {
267 sm->currentId = sm->respId;
270 sm->num_rounds = 0;
271 sm->method_pending = METHOD_PENDING_NONE;
273 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
274 MACSTR, MAC2STR(sm->peer_addr));
282 if (eap_sm_Policy_doPickUp(sm, sm->respMethod)) {
283 sm->currentMethod = sm->respMethod;
284 if (sm->m && sm->eap_method_priv) {
285 sm->m->reset(sm, sm->eap_method_priv);
286 sm->eap_method_priv = NULL;
288 sm->m = eap_server_get_eap_method(EAP_VENDOR_IETF,
289 sm->currentMethod);
290 if (sm->m && sm->m->initPickUp) {
291 sm->eap_method_priv = sm->m->initPickUp(sm);
292 if (sm->eap_method_priv == NULL) {
295 sm->currentMethod);
296 sm->m = NULL;
297 sm->currentMethod = EAP_TYPE_NONE;
300 sm->m = NULL;
301 sm->currentMethod = EAP_TYPE_NONE;
305 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
306 "method=%u", sm->currentMethod);
314 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
315 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
316 sm->methodTimeout);
324 sm->retransCount++;
325 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
326 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
327 sm->eap_if.eapReq = TRUE;
337 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
338 sm->num_rounds++;
345 sm->eap_if.eapResp = FALSE;
346 sm->eap_if.eapNoReq = TRUE;
354 sm->retransCount = 0;
355 if (sm->eap_if.eapReqData) {
356 if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
358 sm->eap_if.eapResp = FALSE;
359 sm->eap_if.eapReq = TRUE;
361 sm->eap_if.eapResp = FALSE;
362 sm->eap_if.eapReq = FALSE;
366 sm->eap_if.eapResp = FALSE;
367 sm->eap_if.eapReq = FALSE;
368 sm->eap_if.eapNoReq = TRUE;
377 if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1)) {
378 sm->ignore = TRUE;
382 if (sm->m->check) {
383 sm->ignore = sm->m->check(sm, sm->eap_method_priv,
384 sm->eap_if.eapRespData);
393 if (sm->m == NULL) {
398 sm->currentId = eap_sm_nextId(sm, sm->currentId);
400 sm->currentId);
401 sm->lastId = sm->currentId;
402 wpabuf_free(sm->eap_if.eapReqData);
403 sm->eap_if.eapReqData = sm->m->buildReq(sm, sm->eap_method_priv,
404 sm->currentId);
405 if (sm->m->getTimeout)
406 sm->methodTimeout = sm->m->getTimeout(sm, sm->eap_method_priv);
408 sm->methodTimeout = 0;
412 static void eap_server_erp_init(struct eap_sm *sm)
424 domain = eap_get_erp_domain(sm);
446 emsk = sm->m->get_emsk(sm, sm->eap_method_priv, &emsk_len);
456 if (hmac_sha256_kdf(sm->eap_if.eapSessionId, sm->eap_if.eapSessionIdLen,
490 if (eap_erp_add_key(sm, erp) == 0) {
507 if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1))
510 sm->m->process(sm, sm->eap_method_priv, sm->eap_if.eapRespData);
511 if (sm->m->isDone(sm, sm->eap_method_priv)) {
512 eap_sm_Policy_update(sm, NULL, 0);
513 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
514 if (sm->m->getKey) {
515 sm->eap_if.eapKeyData = sm->m->getKey(
516 sm, sm->eap_method_priv,
517 &sm->eap_if.eapKeyDataLen);
519 sm->eap_if.eapKeyData = NULL;
520 sm->eap_if.eapKeyDataLen = 0;
522 os_free(sm->eap_if.eapSessionId);
523 sm->eap_if.eapSessionId = NULL;
524 if (sm->m->getSessionId) {
525 sm->eap_if.eapSessionId = sm->m->getSessionId(
526 sm, sm->eap_method_priv,
527 &sm->eap_if.eapSessionIdLen);
529 sm->eap_if.eapSessionId,
530 sm->eap_if.eapSessionIdLen);
532 if (sm->erp && sm->m->get_emsk && sm->eap_if.eapSessionId)
533 eap_server_erp_init(sm);
534 sm->methodState = METHOD_END;
536 sm->methodState = METHOD_CONTINUE;
548 sm->try_initiate_reauth = FALSE;
550 type = eap_sm_Policy_getNextMethod(sm, &vendor);
552 sm->currentMethod = type;
554 sm->currentMethod = EAP_TYPE_EXPANDED;
555 if (sm->m && sm->eap_method_priv) {
556 sm->m->reset(sm, sm->eap_method_priv);
557 sm->eap_method_priv = NULL;
559 sm->m = eap_server_get_eap_method(vendor, type);
560 if (sm->m) {
561 sm->eap_method_priv = sm->m->init(sm);
562 if (sm->eap_method_priv == NULL) {
564 "method %d", sm->currentMethod);
565 sm->m = NULL;
566 sm->currentMethod = EAP_TYPE_NONE;
570 if (sm->m == NULL) {
572 eap_log_msg(sm, "Could not find suitable EAP method");
573 sm->decision = DECISION_FAILURE;
576 if (sm->currentMethod == EAP_TYPE_IDENTITY ||
577 sm->currentMethod == EAP_TYPE_NOTIFICATION)
578 sm->methodState = METHOD_CONTINUE;
580 sm->methodState = METHOD_PROPOSED;
582 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
583 "vendor=%u method=%u", vendor, sm->currentMethod);
584 eap_log_msg(sm, "Propose EAP method vendor=%u method=%u",
585 vendor, sm->currentMethod);
598 if (sm->eap_method_priv) {
599 sm->m->reset(sm, sm->eap_method_priv);
600 sm->eap_method_priv = NULL;
602 sm->m = NULL;
604 if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1))
607 nak = wpabuf_head(sm->eap_if.eapRespData);
608 if (nak && wpabuf_len(sm->eap_if.eapRespData) > sizeof(*nak)) {
610 if (len > wpabuf_len(sm->eap_if.eapRespData))
611 len = wpabuf_len(sm->eap_if.eapRespData);
620 eap_sm_Policy_update(sm, nak_list, len);
628 sm->decision = eap_sm_Policy_getDecision(sm);
636 sm->eap_if.eapTimeout = TRUE;
644 wpabuf_free(sm->eap_if.eapReqData);
645 sm->eap_if.eapReqData = eap_sm_buildFailure(sm, sm->currentId);
646 wpabuf_free(sm->lastReqData);
647 sm->lastReqData = NULL;
648 sm->eap_if.eapFail = TRUE;
650 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
651 MACSTR, MAC2STR(sm->peer_addr));
659 wpabuf_free(sm->eap_if.eapReqData);
660 sm->eap_if.eapReqData = eap_sm_buildSuccess(sm, sm->currentId);
661 wpabuf_free(sm->lastReqData);
662 sm->lastReqData = NULL;
663 if (sm->eap_if.eapKeyData)
664 sm->eap_if.eapKeyAvailable = TRUE;
665 sm->eap_if.eapSuccess = TRUE;
667 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
668 MACSTR, MAC2STR(sm->peer_addr));
676 sm->initiate_reauth_start_sent = TRUE;
677 sm->try_initiate_reauth = TRUE;
678 sm->currentId = eap_sm_nextId(sm, sm->currentId);
681 sm->currentId);
682 sm->lastId = sm->currentId;
683 wpabuf_free(sm->eap_if.eapReqData);
684 sm->eap_if.eapReqData = eap_sm_buildInitiateReauthStart(sm,
685 sm->currentId);
686 wpabuf_free(sm->lastReqData);
687 sm->lastReqData = NULL;
693 static void erp_send_finish_reauth(struct eap_sm *sm,
744 sm->lastId = sm->currentId;
745 sm->currentId = id;
746 wpabuf_free(sm->eap_if.eapReqData);
747 sm->eap_if.eapReqData = msg;
748 wpabuf_free(sm->lastReqData);
749 sm->lastReqData = NULL;
752 sm->eap_if.eapFail = TRUE;
753 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
754 MACSTR, MAC2STR(sm->peer_addr));
758 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
759 sm->eap_if.eapKeyDataLen = 0;
760 sm->eap_if.eapKeyData = os_malloc(erp->rRK_len);
761 if (!sm->eap_if.eapKeyData)
769 sm->eap_if.eapKeyData, erp->rRK_len) < 0) {
771 bin_clear_free(sm->eap_if.eapKeyData, erp->rRK_len);
772 sm->eap_if.eapKeyData = NULL;
775 sm->eap_if.eapKeyDataLen = erp->rRK_len;
776 sm->eap_if.eapKeyAvailable = TRUE;
778 sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
779 sm->eap_if.eapSuccess = TRUE;
781 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
782 MACSTR, MAC2STR(sm->peer_addr));
803 sm->rxInitiate = FALSE;
806 sm->eap_if.eapRespData, &len);
811 hdr = wpabuf_head(sm->eap_if.eapRespData);
812 ehdr = wpabuf_head(sm->eap_if.eapRespData);
852 if (!sm->eap_server) {
861 eap_server_clear_identity(sm);
862 sm->identity = (u8 *) dup_binstr(parse.keyname,
864 if (!sm->identity)
866 sm->identity_len = parse.keyname_len;
870 erp = eap_erp_get_key(sm, nai);
975 erp_send_finish_reauth(sm, erp, ehdr->identifier, resp_flags, seq, nai);
979 sm->ignore = TRUE;
989 wpabuf_free(sm->eap_if.aaaEapRespData);
990 sm->eap_if.aaaEapRespData = NULL;
991 sm->try_initiate_reauth = FALSE;
999 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
1000 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
1001 sm->methodTimeout);
1009 sm->retransCount++;
1010 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
1011 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
1012 sm->eap_if.eapReq = TRUE;
1022 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
1029 sm->eap_if.eapResp = FALSE;
1030 sm->eap_if.eapNoReq = TRUE;
1038 sm->retransCount = 0;
1039 if (sm->eap_if.eapReqData) {
1040 if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
1042 sm->eap_if.eapResp = FALSE;
1043 sm->eap_if.eapReq = TRUE;
1045 sm->eap_if.eapResp = FALSE;
1046 sm->eap_if.eapReq = FALSE;
1050 sm->eap_if.eapResp = FALSE;
1051 sm->eap_if.eapReq = FALSE;
1052 sm->eap_if.eapNoReq = TRUE;
1061 if (sm->eap_if.eapRespData == NULL) {
1070 * stores the identity into sm->identity.
1073 eap_copy_buf(&sm->eap_if.aaaEapRespData, sm->eap_if.eapRespData);
1081 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1082 sm->currentId = eap_sm_getId(sm->eap_if.eapReqData);
1083 sm->methodTimeout = sm->eap_if.aaaMethodTimeout;
1091 sm->eap_if.aaaFail = FALSE;
1092 sm->eap_if.aaaSuccess = FALSE;
1093 sm->eap_if.aaaEapReq = FALSE;
1094 sm->eap_if.aaaEapNoReq = FALSE;
1095 sm->eap_if.aaaEapResp = TRUE;
1103 sm->eap_if.eapTimeout = TRUE;
1111 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1112 sm->eap_if.eapFail = TRUE;
1120 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1122 sm->eap_if.eapKeyAvailable = sm->eap_if.aaaEapKeyAvailable;
1123 if (sm->eap_if.aaaEapKeyAvailable) {
1124 EAP_COPY(&sm->eap_if.eapKeyData, sm->eap_if.aaaEapKeyData);
1126 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
1127 sm->eap_if.eapKeyData = NULL;
1128 sm->eap_if.eapKeyDataLen = 0;
1131 sm->eap_if.eapSuccess = TRUE;
1138 sm->start_reauth = TRUE;
1144 if (sm->eap_if.eapRestart && sm->eap_if.portEnabled)
1146 else if (!sm->eap_if.portEnabled)
1148 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
1149 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
1153 sm->num_rounds++;
1156 } else switch (sm->EAP_state) {
1158 if (sm->backend_auth) {
1159 if (!sm->rxResp)
1161 else if (sm->rxResp &&
1162 (sm->respMethod == EAP_TYPE_NAK ||
1163 (sm->respMethod == EAP_TYPE_EXPANDED &&
1164 sm->respVendor == EAP_VENDOR_IETF &&
1165 sm->respVendorMethod == EAP_TYPE_NAK)))
1174 if (sm->currentMethod == EAP_TYPE_NONE) {
1181 if (sm->eap_if.portEnabled)
1185 if (sm->eap_if.retransWhile == 0) {
1186 if (sm->try_initiate_reauth) {
1187 sm->try_initiate_reauth = FALSE;
1192 } else if (sm->eap_if.eapResp)
1196 if (sm->retransCount > sm->MaxRetrans)
1202 if (sm->rxResp && (sm->respId == sm->currentId) &&
1203 (sm->respMethod == EAP_TYPE_NAK ||
1204 (sm->respMethod == EAP_TYPE_EXPANDED &&
1205 sm->respVendor == EAP_VENDOR_IETF &&
1206 sm->respVendorMethod == EAP_TYPE_NAK))
1207 && (sm->methodState == METHOD_PROPOSED))
1209 else if (sm->rxResp && (sm->respId == sm->currentId) &&
1210 ((sm->respMethod == sm->currentMethod) ||
1211 (sm->respMethod == EAP_TYPE_EXPANDED &&
1212 sm->respVendor == EAP_VENDOR_IETF &&
1213 sm->respVendorMethod == sm->currentMethod)))
1216 else if (sm->rxInitiate)
1223 sm->rxResp, sm->respId, sm->currentId,
1224 sm->respMethod, sm->currentMethod);
1225 eap_log_msg(sm, "Discard received EAP message");
1236 if (sm->ignore)
1242 if (sm->m == NULL) {
1252 if (sm->eap_if.eapNoReq && !sm->eap_if.eapReq) {
1271 if (sm->methodState == METHOD_END)
1273 else if (sm->method_pending == METHOD_PENDING_WAIT) {
1277 } else if (sm->method_pending == METHOD_PENDING_CONT) {
1281 sm->method_pending = METHOD_PENDING_NONE;
1293 if (sm->method_pending == METHOD_PENDING_WAIT) {
1297 if (sm->user_eap_method_index > 0)
1298 sm->user_eap_method_index--;
1299 } else if (sm->method_pending == METHOD_PENDING_CONT) {
1303 sm->method_pending = METHOD_PENDING_NONE;
1312 if (sm->decision == DECISION_FAILURE)
1314 else if (sm->decision == DECISION_SUCCESS)
1316 else if (sm->decision == DECISION_PASSTHROUGH)
1318 else if (sm->decision == DECISION_INITIATE_REAUTH_START)
1321 else if (sm->eap_server && sm->erp && sm->rxInitiate)
1331 if (!sm->eap_server)
1342 if (sm->currentId == -1)
1348 if (sm->eap_if.eapResp)
1350 else if (sm->eap_if.retransWhile == 0)
1354 if (sm->retransCount > sm->MaxRetrans)
1360 if (sm->rxResp && (sm->respId == sm->currentId))
1378 if (sm->eap_if.aaaFail)
1380 else if (sm->eap_if.aaaSuccess)
1382 else if (sm->eap_if.aaaEapReq)
1384 else if (sm->eap_if.aaaTimeout)
1397 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
1403 if (sm->try_initiate_reauth) {
1455 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp)
1461 sm->rxResp = FALSE;
1462 sm->rxInitiate = FALSE;
1463 sm->respId = -1;
1464 sm->respMethod = EAP_TYPE_NONE;
1465 sm->respVendor = EAP_VENDOR_IETF;
1466 sm->respVendorMethod = EAP_TYPE_NONE;
1485 sm->respId = hdr->identifier;
1488 sm->rxResp = TRUE;
1490 sm->rxInitiate = TRUE;
1494 sm->respMethod = *pos++;
1495 if (sm->respMethod == EAP_TYPE_EXPANDED) {
1502 sm->respVendor = WPA_GET_BE24(pos);
1504 sm->respVendorMethod = WPA_GET_BE32(pos);
1510 sm->rxResp, sm->rxInitiate, sm->respId, sm->respMethod,
1511 sm->respVendor, sm->respVendorMethod);
1528 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id)
1546 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id)
1564 static int eap_sm_nextId(struct eap_sm *sm, int id)
1570 if (id != sm->lastId)
1579 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1586 void eap_sm_process_nak(struct eap_sm *sm, const u8 *nak_list, size_t len)
1591 if (sm->user == NULL)
1595 "index %d)", sm->user_eap_method_index);
1598 (u8 *) sm->user->methods,
1599 EAP_MAX_METHODS * sizeof(sm->user->methods[0]));
1603 i = sm->user_eap_method_index;
1605 (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
1606 sm->user->methods[i].method != EAP_TYPE_NONE)) {
1607 if (sm->user->methods[i].vendor != EAP_VENDOR_IETF)
1610 if (nak_list[j] == sm->user->methods[i].method) {
1624 os_memmove(&sm->user->methods[i],
1625 &sm->user->methods[i + 1],
1627 sizeof(sm->user->methods[0]));
1629 sm->user->methods[EAP_MAX_METHODS - 1].vendor =
1631 sm->user->methods[EAP_MAX_METHODS - 1].method = EAP_TYPE_NONE;
1635 (u8 *) sm->user->methods, EAP_MAX_METHODS *
1636 sizeof(sm->user->methods[0]));
1640 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
1643 if (nak_list == NULL || sm == NULL || sm->user == NULL)
1646 if (sm->user->phase2) {
1649 sm->decision = DECISION_FAILURE;
1653 eap_sm_process_nak(sm, nak_list, len);
1657 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
1660 int idx = sm->user_eap_method_index;
1669 if (sm->identity == NULL || sm->currentId == -1) {
1672 sm->update_user = TRUE;
1673 } else if (sm->user && idx < EAP_MAX_METHODS &&
1674 (sm->user->methods[idx].vendor != EAP_VENDOR_IETF ||
1675 sm->user->methods[idx].method != EAP_TYPE_NONE)) {
1676 *vendor = sm->user->methods[idx].vendor;
1677 next = sm->user->methods[idx].method;
1678 sm->user_eap_method_index++;
1689 static int eap_sm_Policy_getDecision(struct eap_sm *sm)
1691 if (!sm->eap_server && sm->identity && !sm->start_reauth) {
1696 if (sm->m && sm->currentMethod != EAP_TYPE_IDENTITY &&
1697 sm->m->isSuccess(sm, sm->eap_method_priv)) {
1700 sm->update_user = TRUE;
1704 if (sm->m && sm->m->isDone(sm, sm->eap_method_priv) &&
1705 !sm->m->isSuccess(sm, sm->eap_method_priv)) {
1708 sm->update_user = TRUE;
1712 if ((sm->user == NULL || sm->update_user) && sm->identity &&
1713 !sm->start_reauth) {
1721 if (sm->user && sm->currentMethod == EAP_TYPE_IDENTITY &&
1722 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1723 sm->user->methods[0].method == EAP_TYPE_IDENTITY)
1725 if (eap_user_get(sm, sm->identity, sm->identity_len, 0) != 0) {
1730 if (id_req && sm->user &&
1731 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1732 sm->user->methods[0].method == EAP_TYPE_IDENTITY) {
1735 sm->update_user = TRUE;
1738 sm->update_user = FALSE;
1740 sm->start_reauth = FALSE;
1742 if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
1743 (sm->user->methods[sm->user_eap_method_index].vendor !=
1745 sm->user->methods[sm->user_eap_method_index].method !=
1752 if (!sm->identity && eap_get_erp_send_reauth_start(sm) &&
1753 !sm->initiate_reauth_start_sent) {
1759 if (sm->identity == NULL || sm->currentId == -1) {
1771 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
1779 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1786 int eap_server_sm_step(struct eap_sm *sm)
1790 sm->changed = FALSE;
1792 if (sm->changed)
1794 } while (sm->changed);
1822 struct eap_sm *sm;
1824 sm = os_zalloc(sizeof(*sm));
1825 if (sm == NULL)
1827 sm->eapol_ctx = eapol_ctx;
1828 sm->eapol_cb = eapol_cb;
1829 sm->MaxRetrans = 5; /* RFC 3748: max 3-5 retransmissions suggested */
1830 sm->ssl_ctx = conf->ssl_ctx;
1831 sm->msg_ctx = conf->msg_ctx;
1832 sm->eap_sim_db_priv = conf->eap_sim_db_priv;
1833 sm->backend_auth = conf->backend_auth;
1834 sm->eap_server = conf->eap_server;
1836 sm->pac_opaque_encr_key = os_malloc(16);
1837 if (sm->pac_opaque_encr_key) {
1838 os_memcpy(sm->pac_opaque_encr_key,
1843 sm->eap_fast_a_id = os_malloc(conf->eap_fast_a_id_len);
1844 if (sm->eap_fast_a_id) {
1845 os_memcpy(sm->eap_fast_a_id, conf->eap_fast_a_id,
1847 sm->eap_fast_a_id_len = conf->eap_fast_a_id_len;
1851 sm->eap_fast_a_id_info = os_strdup(conf->eap_fast_a_id_info);
1852 sm->eap_fast_prov = conf->eap_fast_prov;
1853 sm->pac_key_lifetime = conf->pac_key_lifetime;
1854 sm->pac_key_refresh_time = conf->pac_key_refresh_time;
1855 sm->eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
1856 sm->tnc = conf->tnc;
1857 sm->wps = conf->wps;
1859 sm->assoc_wps_ie = wpabuf_dup(conf->assoc_wps_ie);
1861 sm->assoc_p2p_ie = wpabuf_dup(conf->assoc_p2p_ie);
1863 os_memcpy(sm->peer_addr, conf->peer_addr, ETH_ALEN);
1864 sm->fragment_size = conf->fragment_size;
1865 sm->pwd_group = conf->pwd_group;
1866 sm->pbc_in_m1 = conf->pbc_in_m1;
1867 sm->server_id = conf->server_id;
1868 sm->server_id_len = conf->server_id_len;
1869 sm->erp = conf->erp;
1870 sm->tls_session_lifetime = conf->tls_session_lifetime;
1871 sm->tls_flags = conf->tls_flags;
1874 sm->tls_test_flags = conf->tls_test_flags;
1879 return sm;
1885 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1890 void eap_server_sm_deinit(struct eap_sm *sm)
1892 if (sm == NULL)
1895 if (sm->m && sm->eap_method_priv)
1896 sm->m->reset(sm, sm->eap_method_priv);
1897 wpabuf_free(sm->eap_if.eapReqData);
1898 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
1899 os_free(sm->eap_if.eapSessionId);
1900 wpabuf_free(sm->lastReqData);
1901 wpabuf_free(sm->eap_if.eapRespData);
1902 sm->identity);
1903 os_free(sm->pac_opaque_encr_key);
1904 os_free(sm->eap_fast_a_id);
1905 os_free(sm->eap_fast_a_id_info);
1906 wpabuf_free(sm->eap_if.aaaEapReqData);
1907 wpabuf_free(sm->eap_if.aaaEapRespData);
1908 bin_clear_free(sm->eap_if.aaaEapKeyData, sm->eap_if.aaaEapKeyDataLen);
1909 eap_user_free(sm->user);
1910 wpabuf_free(sm->assoc_wps_ie);
1911 wpabuf_free(sm->assoc_p2p_ie);
1912 os_free(sm);
1918 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1923 void eap_sm_notify_cached(struct eap_sm *sm)
1925 if (sm == NULL)
1928 sm->EAP_state = EAP_SUCCESS;
1934 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1938 void eap_sm_pending_cb(struct eap_sm *sm)
1940 if (sm == NULL)
1943 if (sm->method_pending == METHOD_PENDING_WAIT)
1944 sm->method_pending = METHOD_PENDING_CONT;
1950 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1953 int eap_sm_method_pending(struct eap_sm *sm)
1955 if (sm == NULL)
1957 return sm->method_pending == METHOD_PENDING_WAIT;
1963 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1967 const u8 * eap_get_identity(struct eap_sm *sm, size_t *len)
1969 *len = sm->identity_len;
1970 return sm->identity;
1974 void eap_erp_update_identity(struct eap_sm *sm, const u8 *eap, size_t len)
2000 os_free(sm->identity);
2001 sm->identity = os_malloc(parse.keyname_len);
2002 if (sm->identity) {
2003 os_memcpy(sm->identity, parse.keyname, parse.keyname_len);
2004 sm->identity_len = parse.keyname_len;
2006 sm->identity_len = 0;
2014 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2017 struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm)
2019 return &sm->eap_if;
2025 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2031 void eap_server_clear_identity(struct eap_sm *sm)
2033 os_free(sm->identity);
2034 sm->identity = NULL;
2039 void eap_server_mschap_rx_callback(struct eap_sm *sm, const char *source,