Lines Matching refs:sm
30 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
33 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp);
35 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id);
36 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
37 static int eap_sm_nextId(struct eap_sm *sm, int id);
38 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
40 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
41 static int eap_sm_Policy_getDecision(struct eap_sm *sm);
42 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
45 static int eap_get_erp_send_reauth_start(struct eap_sm *sm)
47 if (sm->eapol_cb->get_erp_send_reauth_start)
48 return sm->eapol_cb->get_erp_send_reauth_start(sm->eapol_ctx);
53 static const char * eap_get_erp_domain(struct eap_sm *sm)
55 if (sm->eapol_cb->get_erp_domain)
56 return sm->eapol_cb->get_erp_domain(sm->eapol_ctx);
63 static struct eap_server_erp_key * eap_erp_get_key(struct eap_sm *sm,
66 if (sm->eapol_cb->erp_get_key)
67 return sm->eapol_cb->erp_get_key(sm->eapol_ctx, keyname);
72 static int eap_erp_add_key(struct eap_sm *sm, struct eap_server_erp_key *erp)
74 if (sm->eapol_cb->erp_add_key)
75 return sm->eapol_cb->erp_add_key(sm->eapol_ctx, erp);
82 static struct wpabuf * eap_sm_buildInitiateReauthStart(struct eap_sm *sm,
90 domain = eap_get_erp_domain(sm);
148 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
155 * selected based on the specified identity. sm->user and
156 * sm->user_eap_method_index are updated for the new user when a matching user
157 * is found. sm->user can be used to get user information (e.g., password).
159 int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
164 if (sm == NULL || sm->eapol_cb == NULL ||
165 sm->eapol_cb->get_eap_user == NULL)
168 eap_user_free(sm->user);
169 sm->user = NULL;
175 if (sm->eapol_cb->get_eap_user(sm->eapol_ctx, identity,
181 sm->user = user;
182 sm->user_eap_method_index = 0;
188 void eap_log_msg(struct eap_sm *sm, const char *fmt, ...)
194 if (sm == NULL || sm->eapol_cb == NULL || sm->eapol_cb->log_msg == NULL)
208 sm->eapol_cb->log_msg(sm->eapol_ctx, buf);
217 sm->num_rounds = 0;
225 if (sm->eap_if.eapRestart && !sm->eap_server && sm->identity) {
230 eap_server_clear_identity(sm);
233 sm->try_initiate_reauth = FALSE;
234 sm->currentId = -1;
235 sm->eap_if.eapSuccess = FALSE;
236 sm->eap_if.eapFail = FALSE;
237 sm->eap_if.eapTimeout = FALSE;
238 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
239 sm->eap_if.eapKeyData = NULL;
240 sm->eap_if.eapKeyDataLen = 0;
241 os_free(sm->eap_if.eapSessionId);
242 sm->eap_if.eapSessionId = NULL;
243 sm->eap_if.eapSessionIdLen = 0;
244 sm->eap_if.eapKeyAvailable = FALSE;
245 sm->eap_if.eapRestart = FALSE;
252 if (sm->m && sm->eap_method_priv) {
253 sm->m->reset(sm, sm->eap_method_priv);
254 sm->eap_method_priv = NULL;
256 sm->m = NULL;
257 sm->user_eap_method_index = 0;
259 if (sm->backend_auth) {
260 sm->currentMethod = EAP_TYPE_NONE;
262 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
263 if (sm->rxResp) {
264 sm->currentId = sm->respId;
267 sm->num_rounds = 0;
268 sm->method_pending = METHOD_PENDING_NONE;
270 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
271 MACSTR, MAC2STR(sm->peer_addr));
279 if (eap_sm_Policy_doPickUp(sm, sm->respMethod)) {
280 sm->currentMethod = sm->respMethod;
281 if (sm->m && sm->eap_method_priv) {
282 sm->m->reset(sm, sm->eap_method_priv);
283 sm->eap_method_priv = NULL;
285 sm->m = eap_server_get_eap_method(EAP_VENDOR_IETF,
286 sm->currentMethod);
287 if (sm->m && sm->m->initPickUp) {
288 sm->eap_method_priv = sm->m->initPickUp(sm);
289 if (sm->eap_method_priv == NULL) {
292 sm->currentMethod);
293 sm->m = NULL;
294 sm->currentMethod = EAP_TYPE_NONE;
297 sm->m = NULL;
298 sm->currentMethod = EAP_TYPE_NONE;
302 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
303 "method=%u", sm->currentMethod);
311 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
312 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
313 sm->methodTimeout);
321 sm->retransCount++;
322 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
323 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
324 sm->eap_if.eapReq = TRUE;
327 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_RETRANSMIT MACSTR,
328 MAC2STR(sm->peer_addr));
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;
638 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TIMEOUT_FAILURE MACSTR,
639 MAC2STR(sm->peer_addr));
647 wpabuf_free(sm->eap_if.eapReqData);
648 sm->eap_if.eapReqData = eap_sm_buildFailure(sm, sm->currentId);
649 wpabuf_free(sm->lastReqData);
650 sm->lastReqData = NULL;
651 sm->eap_if.eapFail = TRUE;
653 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
654 MACSTR, MAC2STR(sm->peer_addr));
662 wpabuf_free(sm->eap_if.eapReqData);
663 sm->eap_if.eapReqData = eap_sm_buildSuccess(sm, sm->currentId);
664 wpabuf_free(sm->lastReqData);
665 sm->lastReqData = NULL;
666 if (sm->eap_if.eapKeyData)
667 sm->eap_if.eapKeyAvailable = TRUE;
668 sm
670 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
671 MACSTR, MAC2STR(sm->peer_addr));
679 sm->initiate_reauth_start_sent = TRUE;
680 sm->try_initiate_reauth = TRUE;
681 sm->currentId = eap_sm_nextId(sm, sm->currentId);
684 sm->currentId);
685 sm->lastId = sm->currentId;
686 wpabuf_free(sm->eap_if.eapReqData);
687 sm->eap_if.eapReqData = eap_sm_buildInitiateReauthStart(sm,
688 sm->currentId);
689 wpabuf_free(sm->lastReqData);
690 sm->lastReqData = NULL;
696 static void erp_send_finish_reauth(struct eap_sm *sm,
747 sm->lastId = sm->currentId;
748 sm->currentId = id;
749 wpabuf_free(sm->eap_if.eapReqData);
750 sm->eap_if.eapReqData = msg;
751 wpabuf_free(sm->lastReqData);
752 sm->lastReqData = NULL;
755 sm->eap_if.eapFail = TRUE;
756 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
757 MACSTR, MAC2STR(sm->peer_addr));
761 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
762 sm->eap_if.eapKeyDataLen = 0;
763 sm->eap_if.eapKeyData = os_malloc(erp->rRK_len);
764 if (!sm->eap_if.eapKeyData)
772 sm->eap_if.eapKeyData, erp->rRK_len) < 0) {
774 bin_clear_free(sm->eap_if.eapKeyData, erp->rRK_len);
775 sm->eap_if.eapKeyData = NULL;
778 sm->eap_if.eapKeyDataLen = erp->rRK_len;
779 sm->eap_if.eapKeyAvailable = TRUE;
781 sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
782 sm->eap_if.eapSuccess = TRUE;
784 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
785 MACSTR, MAC2STR(sm->peer_addr));
806 sm->rxInitiate = FALSE;
809 sm->eap_if.eapRespData, &len);
814 hdr = wpabuf_head(sm->eap_if.eapRespData);
815 ehdr = wpabuf_head(sm->eap_if.eapRespData);
855 if (!sm->eap_server) {
864 eap_server_clear_identity(sm);
865 sm->identity = (u8 *) dup_binstr(parse.keyname,
867 if (!sm->identity)
869 sm->identity_len = parse.keyname_len;
873 erp = eap_erp_get_key(sm, nai);
978 erp_send_finish_reauth(sm, erp, ehdr->identifier, resp_flags, seq, nai);
982 sm->ignore = TRUE;
992 wpabuf_free(sm->eap_if.aaaEapRespData);
993 sm->eap_if.aaaEapRespData = NULL;
994 sm->try_initiate_reauth = FALSE;
1002 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
1003 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
1004 sm->methodTimeout);
1012 sm->retransCount++;
1013 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
1014 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
1015 sm->eap_if.eapReq = TRUE;
1018 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_RETRANSMIT2 MACSTR,
1019 MAC2STR(sm->peer_addr));
1028 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
1035 sm->eap_if.eapResp = FALSE;
1036 sm->eap_if.eapNoReq = TRUE;
1044 sm->retransCount = 0;
1045 if (sm->eap_if.eapReqData) {
1046 if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
1048 sm->eap_if.eapResp = FALSE;
1049 sm->eap_if.eapReq = TRUE;
1051 sm->eap_if.eapResp = FALSE;
1052 sm->eap_if.eapReq = FALSE;
1056 sm->eap_if.eapResp = FALSE;
1057 sm->eap_if.eapReq = FALSE;
1058 sm->eap_if.eapNoReq = TRUE;
1067 if (sm->eap_if.eapRespData == NULL) {
1076 * stores the identity into sm->identity.
1079 eap_copy_buf(&sm->eap_if.aaaEapRespData, sm->eap_if.eapRespData);
1087 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1088 sm->currentId = eap_sm_getId(sm->eap_if.eapReqData);
1089 sm->methodTimeout = sm->eap_if.aaaMethodTimeout;
1097 sm->eap_if.aaaFail = FALSE;
1098 sm->eap_if.aaaSuccess = FALSE;
1099 sm->eap_if.aaaEapReq = FALSE;
1100 sm->eap_if.aaaEapNoReq = FALSE;
1101 sm->eap_if.aaaEapResp = TRUE;
1109 sm->eap_if.eapTimeout = TRUE;
1111 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TIMEOUT_FAILURE2 MACSTR,
1112 MAC2STR(sm->peer_addr));
1120 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1121 sm->eap_if.eapFail = TRUE;
1123 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE2 MACSTR,
1124 MAC2STR(sm->peer_addr));
1132 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
1134 sm->eap_if.eapKeyAvailable = sm->eap_if.aaaEapKeyAvailable;
1135 if (sm->eap_if.aaaEapKeyAvailable) {
1136 EAP_COPY(&sm->eap_if.eapKeyData, sm->eap_if.aaaEapKeyData);
1138 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
1139 sm->eap_if.eapKeyData = NULL;
1140 sm->eap_if.eapKeyDataLen = 0;
1143 sm->eap_if.eapSuccess = TRUE;
1150 sm->start_reauth = TRUE;
1152 wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS2 MACSTR,
1153 MAC2STR(sm->peer_addr));
1159 if (sm->eap_if.eapRestart && sm->eap_if.portEnabled)
1161 else if (!sm->eap_if.portEnabled)
1163 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
1164 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
1168 sm->num_rounds++;
1171 } else switch (sm->EAP_state) {
1173 if (sm->backend_auth) {
1174 if (!sm->rxResp)
1176 else if (sm->rxResp &&
1177 (sm->respMethod == EAP_TYPE_NAK ||
1178 (sm->respMethod == EAP_TYPE_EXPANDED &&
1179 sm->respVendor == EAP_VENDOR_IETF &&
1180 sm->respVendorMethod == EAP_TYPE_NAK)))
1189 if (sm->currentMethod == EAP_TYPE_NONE) {
1196 if (sm->eap_if.portEnabled)
1200 if (sm->eap_if.retransWhile == 0) {
1201 if (sm->try_initiate_reauth) {
1202 sm->try_initiate_reauth = FALSE;
1207 } else if (sm->eap_if.eapResp)
1211 if (sm->retransCount > sm->MaxRetrans)
1217 if (sm->rxResp && (sm->respId == sm->currentId) &&
1218 (sm->respMethod == EAP_TYPE_NAK ||
1219 (sm->respMethod == EAP_TYPE_EXPANDED &&
1220 sm->respVendor == EAP_VENDOR_IETF &&
1221 sm->respVendorMethod == EAP_TYPE_NAK))
1222 && (sm->methodState == METHOD_PROPOSED))
1224 else if (sm->rxResp && (sm->respId == sm->currentId) &&
1225 ((sm->respMethod == sm->currentMethod) ||
1226 (sm->respMethod == EAP_TYPE_EXPANDED &&
1227 sm->respVendor == EAP_VENDOR_IETF &&
1228 sm->respVendorMethod == sm->currentMethod)))
1231 else if (sm->rxInitiate)
1238 sm->rxResp, sm->respId, sm->currentId,
1239 sm->respMethod, sm->currentMethod);
1240 eap_log_msg(sm, "Discard received EAP message");
1251 if (sm->ignore)
1257 if (sm->m == NULL) {
1267 if (sm->eap_if.eapNoReq && !sm->eap_if.eapReq) {
1286 if (sm->methodState == METHOD_END)
1288 else if (sm->method_pending == METHOD_PENDING_WAIT) {
1292 } else if (sm->method_pending == METHOD_PENDING_CONT) {
1296 sm->method_pending = METHOD_PENDING_NONE;
1308 if (sm->method_pending == METHOD_PENDING_WAIT) {
1312 if (sm->user_eap_method_index > 0)
1313 sm->user_eap_method_index--;
1314 } else if (sm->method_pending == METHOD_PENDING_CONT) {
1318 sm->method_pending = METHOD_PENDING_NONE;
1327 if (sm->decision == DECISION_FAILURE)
1329 else if (sm->decision == DECISION_SUCCESS)
1331 else if (sm->decision == DECISION_PASSTHROUGH)
1333 else if (sm->decision == DECISION_INITIATE_REAUTH_START)
1336 else if (sm->eap_server && sm->erp && sm->rxInitiate)
1346 if (!sm->eap_server)
1357 if (sm->currentId == -1)
1363 if (sm->eap_if.eapResp)
1365 else if (sm->eap_if.retransWhile == 0)
1369 if (sm->retransCount > sm->MaxRetrans)
1375 if (sm->rxResp && (sm->respId == sm->currentId))
1393 if (sm->eap_if.aaaFail)
1395 else if (sm->eap_if.aaaSuccess)
1397 else if (sm->eap_if.aaaEapReq)
1399 else if (sm->eap_if.aaaTimeout)
1412 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
1418 if (sm->try_initiate_reauth) {
1470 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp)
1476 sm->rxResp = FALSE;
1477 sm->rxInitiate = FALSE;
1478 sm->respId = -1;
1479 sm->respMethod = EAP_TYPE_NONE;
1480 sm->respVendor = EAP_VENDOR_IETF;
1481 sm->respVendorMethod = EAP_TYPE_NONE;
1500 sm->respId = hdr->identifier;
1503 sm->rxResp = TRUE;
1505 sm->rxInitiate = TRUE;
1509 sm->respMethod = *pos++;
1510 if (sm->respMethod == EAP_TYPE_EXPANDED) {
1517 sm->respVendor = WPA_GET_BE24(pos);
1519 sm->respVendorMethod = WPA_GET_BE32(pos);
1525 sm->rxResp, sm->rxInitiate, sm->respId, sm->respMethod,
1526 sm->respVendor, sm->respVendorMethod);
1543 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id)
1561 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id)
1579 static int eap_sm_nextId(struct eap_sm *sm, int id)
1585 if (id != sm->lastId)
1594 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1601 void eap_sm_process_nak(struct eap_sm *sm, const u8 *nak_list, size_t len)
1606 if (sm->user == NULL)
1610 "index %d)", sm->user_eap_method_index);
1613 (u8 *) sm->user->methods,
1614 EAP_MAX_METHODS * sizeof(sm->user->methods[0]));
1618 i = sm->user_eap_method_index;
1620 (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
1621 sm->user->methods[i].method != EAP_TYPE_NONE)) {
1622 if (sm->user->methods[i].vendor != EAP_VENDOR_IETF)
1625 if (nak_list[j] == sm->user->methods[i].method) {
1639 os_memmove(&sm->user->methods[i],
1640 &sm->user->methods[i + 1],
1642 sizeof(sm->user->methods[0]));
1644 sm->user->methods[EAP_MAX_METHODS - 1].vendor =
1646 sm->user->methods[EAP_MAX_METHODS - 1].method = EAP_TYPE_NONE;
1650 (u8 *) sm->user->methods, EAP_MAX_METHODS *
1651 sizeof(sm->user->methods[0]));
1655 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
1658 if (nak_list == NULL || sm == NULL || sm->user == NULL)
1661 if (sm->user->phase2) {
1664 sm->decision = DECISION_FAILURE;
1668 eap_sm_process_nak(sm, nak_list, len);
1672 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
1675 int idx = sm->user_eap_method_index;
1684 if (sm->identity == NULL || sm->currentId == -1) {
1687 sm->update_user = TRUE;
1688 } else if (sm->user && idx < EAP_MAX_METHODS &&
1689 (sm->user->methods[idx].vendor != EAP_VENDOR_IETF ||
1690 sm->user->methods[idx].method != EAP_TYPE_NONE)) {
1691 *vendor = sm->user->methods[idx].vendor;
1692 next = sm->user->methods[idx].method;
1693 sm->user_eap_method_index++;
1704 static int eap_sm_Policy_getDecision(struct eap_sm *sm)
1706 if (!sm->eap_server && sm->identity && !sm->start_reauth) {
1711 if (sm->m && sm->currentMethod != EAP_TYPE_IDENTITY &&
1712 sm->m->isSuccess(sm, sm->eap_method_priv)) {
1715 sm->update_user = TRUE;
1719 if (sm->m && sm->m->isDone(sm, sm->eap_method_priv) &&
1720 !sm->m->isSuccess(sm, sm->eap_method_priv)) {
1723 sm->update_user = TRUE;
1727 if ((sm->user == NULL || sm->update_user) && sm->identity &&
1728 !sm->start_reauth) {
1736 if (sm->user && sm->currentMethod == EAP_TYPE_IDENTITY &&
1737 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1738 sm->user->methods[0].method == EAP_TYPE_IDENTITY)
1740 if (eap_user_get(sm, sm->identity, sm->identity_len, 0) != 0) {
1745 if (id_req && sm->user &&
1746 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1747 sm->user->methods[0].method == EAP_TYPE_IDENTITY) {
1750 sm->update_user = TRUE;
1753 sm->update_user = FALSE;
1755 sm->start_reauth = FALSE;
1757 if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
1758 (sm->user->methods[sm->user_eap_method_index].vendor !=
1760 sm->user->methods[sm->user_eap_method_index].method !=
1767 if (!sm->identity && eap_get_erp_send_reauth_start(sm) &&
1768 !sm->initiate_reauth_start_sent) {
1774 if (sm->identity == NULL || sm->currentId == -1) {
1786 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
1794 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1801 int eap_server_sm_step(struct eap_sm *sm)
1805 sm->changed = FALSE;
1807 if (sm->changed)
1809 } while (sm->changed);
1839 struct eap_sm *sm;
1841 sm = os_zalloc(sizeof(*sm));
1842 if (sm == NULL)
1844 sm->eapol_ctx = eapol_ctx;
1845 sm->eapol_cb = eapol_cb;
1846 sm->MaxRetrans = 5; /* RFC 3748: max 3-5 retransmissions suggested */
1847 sm->ssl_ctx = conf->ssl_ctx;
1848 sm->msg_ctx = conf->msg_ctx;
1849 sm->eap_sim_db_priv = conf->eap_sim_db_priv;
1850 sm->backend_auth = conf->backend_auth;
1851 sm->eap_server = conf->eap_server;
1853 sm->pac_opaque_encr_key = os_malloc(16);
1854 if (sm->pac_opaque_encr_key) {
1855 os_memcpy(sm->pac_opaque_encr_key,
1860 sm->eap_fast_a_id = os_malloc(conf->eap_fast_a_id_len);
1861 if (sm->eap_fast_a_id) {
1862 os_memcpy(sm->eap_fast_a_id, conf->eap_fast_a_id,
1864 sm->eap_fast_a_id_len = conf->eap_fast_a_id_len;
1868 sm->eap_fast_a_id_info = os_strdup(conf->eap_fast_a_id_info);
1869 sm->eap_fast_prov = conf->eap_fast_prov;
1870 sm->pac_key_lifetime = conf->pac_key_lifetime;
1871 sm->pac_key_refresh_time = conf->pac_key_refresh_time;
1872 sm->eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
1873 sm->tnc = conf->tnc;
1874 sm->wps = conf->wps;
1876 sm->assoc_wps_ie = wpabuf_dup(conf->assoc_wps_ie);
1878 sm->assoc_p2p_ie = wpabuf_dup(conf->assoc_p2p_ie);
1880 os_memcpy(sm->peer_addr, conf->peer_addr, ETH_ALEN);
1881 sm->fragment_size = conf->fragment_size;
1882 sm->pwd_group = conf->pwd_group;
1883 sm->pbc_in_m1 = conf->pbc_in_m1;
1884 sm->server_id = conf->server_id;
1885 sm->server_id_len = conf->server_id_len;
1886 sm->erp = conf->erp;
1887 sm->tls_session_lifetime = conf->tls_session_lifetime;
1888 sm->tls_flags = conf->tls_flags;
1891 sm->tls_test_flags = conf->tls_test_flags;
1896 return sm;
1902 * @sm
1907 void eap_server_sm_deinit(struct eap_sm *sm)
1909 if (sm == NULL)
1912 if (sm->m && sm->eap_method_priv)
1913 sm->m->reset(sm, sm->eap_method_priv);
1914 wpabuf_free(sm->eap_if.eapReqData);
1915 bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
1916 os_free(sm->eap_if.eapSessionId);
1917 wpabuf_free(sm->lastReqData);
1918 wpabuf_free(sm->eap_if.eapRespData);
1919 os_free(sm->identity);
1920 os_free(sm->serial_num);
1921 os_free(sm->pac_opaque_encr_key);
1922 os_free(sm->eap_fast_a_id);
1923 os_free(sm->eap_fast_a_id_info);
1924 wpabuf_free(sm->eap_if.aaaEapReqData);
1925 wpabuf_free(sm->eap_if.aaaEapRespData);
1926 bin_clear_free(sm->eap_if.aaaEapKeyData, sm->eap_if.aaaEapKeyDataLen);
1927 eap_user_free(sm->user);
1928 wpabuf_free(sm->assoc_wps_ie);
1929 wpabuf_free(sm->assoc_p2p_ie);
1930 os_free(sm);
1936 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1941 void eap_sm_notify_cached(struct eap_sm *sm)
1943 if (sm == NULL)
1946 sm->EAP_state = EAP_SUCCESS;
1952 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1956 void eap_sm_pending_cb(struct eap_sm *sm)
1958 if (sm == NULL)
1961 if (sm->method_pending == METHOD_PENDING_WAIT)
1962 sm->method_pending = METHOD_PENDING_CONT;
1968 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1971 int eap_sm_method_pending(struct eap_sm *sm)
1973 if (sm == NULL)
1975 return sm->method_pending == METHOD_PENDING_WAIT;
1981 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1985 const u8 * eap_get_identity(struct eap_sm *sm, size_t *len)
1987 *len = sm->identity_len;
1988 return sm->identity;
1994 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1997 const char * eap_get_serial_num(struct eap_sm *sm)
1999 return sm->serial_num;
2005 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2008 const char * eap_get_method(struct eap_sm *sm)
2010 if (!sm || !sm->m)
2012 return sm->m->name;
2018 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2021 const char * eap_get_imsi(struct eap_sm *sm)
2023 if (!sm || sm->imsi[0] == '\0')
2025 return sm->imsi;
2029 void eap_erp_update_identity(struct eap_sm *sm, const u8 *eap, size_t len)
2055 os_free(sm->identity);
2056 sm->identity = os_malloc(parse.keyname_len);
2057 if (sm->identity) {
2058 os_memcpy(sm->identity, parse.keyname, parse.keyname_len);
2059 sm->identity_len = parse.keyname_len;
2061 sm->identity_len = 0;
2069 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2072 struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm)
2074 return &sm->eap_if;
2080 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2086 void eap_server_clear_identity(struct eap_sm *sm)
2088 os_free(sm->identity);
2089 sm->identity = NULL;
2094 void eap_server_mschap_rx_callback(struct eap_sm *sm, const char *source,