Home | History | Annotate | Download | only in eap_server

Lines Matching refs:sm

37 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
40 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp);
42 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id);
43 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
44 static int eap_sm_nextId(struct eap_sm *sm, int id);
45 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
47 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
48 static int eap_sm_Policy_getDecision(struct eap_sm *sm);
49 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
87 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
94 * selected based on the specified identity. sm->user and
95 * sm->user_eap_method_index are updated for the new user when a matching user
96 * is found. sm->user can be used to get user information (e.g., password).
98 int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
103 if (sm == NULL || sm->eapol_cb == NULL ||
104 sm->eapol_cb->get_eap_user == NULL)
107 eap_user_free(sm->user);
108 sm->user = NULL;
114 if (sm->eapol_cb->get_eap_user(sm->eapol_ctx, identity,
120 sm->user = user;
121 sm->user_eap_method_index = 0;
130 sm->num_rounds = 0;
138 sm->currentId = -1;
139 sm->eap_if.eapSuccess = FALSE;
140 sm->eap_if.eapFail = FALSE;
141 sm->eap_if.eapTimeout = FALSE;
142 os_free(sm->eap_if.eapKeyData);
143 sm->eap_if.eapKeyData = NULL;
144 sm->eap_if.eapKeyDataLen = 0;
145 sm->eap_if.eapKeyAvailable = FALSE;
146 sm->eap_if.eapRestart = FALSE;
153 if (sm->m && sm->eap_method_priv) {
154 sm->m->reset(sm, sm->eap_method_priv);
155 sm->eap_method_priv = NULL;
157 sm->m = NULL;
158 sm->user_eap_method_index = 0;
160 if (sm->backend_auth) {
161 sm->currentMethod = EAP_TYPE_NONE;
163 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
164 if (sm->rxResp) {
165 sm->currentId = sm->respId;
168 sm->num_rounds = 0;
169 sm->method_pending = METHOD_PENDING_NONE;
177 if (eap_sm_Policy_doPickUp(sm, sm->respMethod)) {
178 sm->currentMethod = sm->respMethod;
179 if (sm->m && sm->eap_method_priv) {
180 sm->m->reset(sm, sm->eap_method_priv);
181 sm->eap_method_priv = NULL;
183 sm->m = eap_server_get_eap_method(EAP_VENDOR_IETF,
184 sm->currentMethod);
185 if (sm->m && sm->m->initPickUp) {
186 sm->eap_method_priv = sm->m->initPickUp(sm);
187 if (sm->eap_method_priv == NULL) {
190 sm->currentMethod);
191 sm->m = NULL;
192 sm->currentMethod = EAP_TYPE_NONE;
195 sm->m = NULL;
196 sm->currentMethod = EAP_TYPE_NONE;
206 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
207 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
208 sm->methodTimeout);
216 sm->retransCount++;
217 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
218 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
219 sm->eap_if.eapReq = TRUE;
229 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
230 sm->num_rounds++;
237 sm->eap_if.eapResp = FALSE;
238 sm->eap_if.eapNoReq = TRUE;
246 sm->retransCount = 0;
247 if (sm->eap_if.eapReqData) {
248 if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
250 sm->eap_if.eapResp = FALSE;
251 sm->eap_if.eapReq = TRUE;
253 sm->eap_if.eapResp = FALSE;
254 sm->eap_if.eapReq = FALSE;
258 sm->eap_if.eapResp = FALSE;
259 sm->eap_if.eapReq = FALSE;
260 sm->eap_if.eapNoReq = TRUE;
269 if (sm->m->check) {
270 sm->ignore = sm->m->check(sm, sm->eap_method_priv,
271 sm->eap_if.eapRespData);
280 if (sm->m == NULL) {
285 sm->currentId = eap_sm_nextId(sm, sm->currentId);
287 sm->currentId);
288 sm->lastId = sm->currentId;
289 wpabuf_free(sm->eap_if.eapReqData);
290 sm->eap_if.eapReqData = sm->m->buildReq(sm, sm->eap_method_priv,
291 sm->currentId);
292 if (sm->m->getTimeout)
293 sm->methodTimeout = sm->m->getTimeout(sm, sm->eap_method_priv);
295 sm->methodTimeout = 0;
303 sm->m->process(sm, sm->eap_method_priv, sm->eap_if.eapRespData);
304 if (sm->m->isDone(sm, sm->eap_method_priv)) {
305 eap_sm_Policy_update(sm, NULL, 0);
306 os_free(sm->eap_if.eapKeyData);
307 if (sm->m->getKey) {
308 sm->eap_if.eapKeyData = sm->m->getKey(
309 sm, sm->eap_method_priv,
310 &sm->eap_if.eapKeyDataLen);
312 sm->eap_if.eapKeyData = NULL;
313 sm->eap_if.eapKeyDataLen = 0;
315 sm->methodState = METHOD_END;
317 sm->methodState = METHOD_CONTINUE;
329 type = eap_sm_Policy_getNextMethod(sm, &vendor);
331 sm->currentMethod = type;
333 sm->currentMethod = EAP_TYPE_EXPANDED;
334 if (sm->m && sm->eap_method_priv) {
335 sm->m->reset(sm, sm->eap_method_priv);
336 sm->eap_method_priv = NULL;
338 sm->m = eap_server_get_eap_method(vendor, type);
339 if (sm->m) {
340 sm->eap_method_priv = sm->m->init(sm);
341 if (sm->eap_method_priv == NULL) {
343 "method %d", sm->currentMethod);
344 sm->m = NULL;
345 sm->currentMethod = EAP_TYPE_NONE;
348 if (sm->currentMethod == EAP_TYPE_IDENTITY ||
349 sm->currentMethod == EAP_TYPE_NOTIFICATION)
350 sm->methodState = METHOD_CONTINUE;
352 sm->methodState = METHOD_PROPOSED;
365 if (sm->eap_method_priv) {
366 sm->m->reset(sm, sm->eap_method_priv);
367 sm->eap_method_priv = NULL;
369 sm->m = NULL;
371 nak = wpabuf_head(sm->eap_if.eapRespData);
372 if (nak && wpabuf_len(sm->eap_if.eapRespData) > sizeof(*nak)) {
374 if (len > wpabuf_len(sm->eap_if.eapRespData))
375 len = wpabuf_len(sm->eap_if.eapRespData);
384 eap_sm_Policy_update(sm, nak_list, len);
392 sm->decision = eap_sm_Policy_getDecision(sm);
400 sm->eap_if.eapTimeout = TRUE;
408 wpabuf_free(sm->eap_if.eapReqData);
409 sm->eap_if.eapReqData = eap_sm_buildFailure(sm, sm->currentId);
410 wpabuf_free(sm->lastReqData);
411 sm->lastReqData = NULL;
412 sm->eap_if.eapFail = TRUE;
420 wpabuf_free(sm->eap_if.eapReqData);
421 sm->eap_if.eapReqData = eap_sm_buildSuccess(sm, sm->currentId);
422 wpabuf_free(sm->lastReqData);
423 sm->lastReqData = NULL;
424 if (sm->eap_if.eapKeyData)
425 sm->eap_if.eapKeyAvailable = TRUE;
426 sm->eap_if.eapSuccess = TRUE;
434 wpabuf_free(sm->eap_if.aaaEapRespData);
435 sm->eap_if.aaaEapRespData = NULL;
443 sm->eap_if.retransWhile = eap_sm_calculateTimeout(
444 sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
445 sm->methodTimeout);
453 sm->retransCount++;
454 if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
455 if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
456 sm->eap_if.eapReq = TRUE;
466 eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
473 sm->eap_if.eapResp = FALSE;
474 sm->eap_if.eapNoReq = TRUE;
482 sm->retransCount = 0;
483 if (sm->eap_if.eapReqData) {
484 if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
486 sm->eap_if.eapResp = FALSE;
487 sm->eap_if.eapReq = TRUE;
489 sm->eap_if.eapResp = FALSE;
490 sm->eap_if.eapReq = FALSE;
494 sm->eap_if.eapResp = FALSE;
495 sm->eap_if.eapReq = FALSE;
496 sm->eap_if.eapNoReq = TRUE;
505 if (sm->eap_if.eapRespData == NULL) {
514 * stores the identity into sm->identity.
517 eap_copy_buf(&sm->eap_if.aaaEapRespData, sm->eap_if.eapRespData);
525 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
526 sm->currentId = eap_sm_getId(sm->eap_if.eapReqData);
527 sm->methodTimeout = sm->eap_if.aaaMethodTimeout;
535 sm->eap_if.aaaFail = FALSE;
536 sm->eap_if.aaaSuccess = FALSE;
537 sm->eap_if.aaaEapReq = FALSE;
538 sm->eap_if.aaaEapNoReq = FALSE;
539 sm->eap_if.aaaEapResp = TRUE;
547 sm->eap_if.eapTimeout = TRUE;
555 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
556 sm->eap_if.eapFail = TRUE;
564 eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
566 sm->eap_if.eapKeyAvailable = sm->eap_if.aaaEapKeyAvailable;
567 if (sm->eap_if.aaaEapKeyAvailable) {
568 EAP_COPY(&sm->eap_if.eapKeyData, sm->eap_if.aaaEapKeyData);
570 os_free(sm->eap_if.eapKeyData);
571 sm->eap_if.eapKeyData = NULL;
572 sm->eap_if.eapKeyDataLen = 0;
575 sm->eap_if.eapSuccess = TRUE;
582 sm->start_reauth = TRUE;
588 if (sm->eap_if.eapRestart && sm->eap_if.portEnabled)
590 else if (!sm->eap_if.portEnabled)
592 else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
593 if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
597 sm->num_rounds++;
600 } else switch (sm->EAP_state) {
602 if (sm->backend_auth) {
603 if (!sm->rxResp)
605 else if (sm->rxResp &&
606 (sm->respMethod == EAP_TYPE_NAK ||
607 (sm->respMethod == EAP_TYPE_EXPANDED &&
608 sm->respVendor == EAP_VENDOR_IETF &&
609 sm->respVendorMethod == EAP_TYPE_NAK)))
618 if (sm->currentMethod == EAP_TYPE_NONE) {
625 if (sm->eap_if.portEnabled)
629 if (sm->eap_if.retransWhile == 0)
631 else if (sm->eap_if.eapResp)
635 if (sm->retransCount > sm->MaxRetrans)
641 if (sm->rxResp && (sm->respId == sm->currentId) &&
642 (sm->respMethod == EAP_TYPE_NAK ||
643 (sm->respMethod == EAP_TYPE_EXPANDED &&
644 sm->respVendor == EAP_VENDOR_IETF &&
645 sm->respVendorMethod == EAP_TYPE_NAK))
646 && (sm->methodState == METHOD_PROPOSED))
648 else if (sm->rxResp && (sm->respId == sm->currentId) &&
649 ((sm->respMethod == sm->currentMethod) ||
650 (sm->respMethod == EAP_TYPE_EXPANDED &&
651 sm->respVendor == EAP_VENDOR_IETF &&
652 sm->respVendorMethod == sm->currentMethod)))
658 sm->rxResp, sm->respId, sm->currentId,
659 sm->respMethod, sm->currentMethod);
670 if (sm->ignore)
685 if (sm->methodState == METHOD_END)
687 else if (sm->method_pending == METHOD_PENDING_WAIT) {
691 } else if (sm
695 sm->method_pending = METHOD_PENDING_NONE;
707 if (sm->method_pending == METHOD_PENDING_WAIT) {
711 if (sm->user_eap_method_index > 0)
712 sm->user_eap_method_index--;
713 } else if (sm->method_pending == METHOD_PENDING_CONT) {
717 sm->method_pending = METHOD_PENDING_NONE;
726 if (sm->decision == DECISION_FAILURE)
728 else if (sm->decision == DECISION_SUCCESS)
730 else if (sm->decision == DECISION_PASSTHROUGH)
743 if (sm->currentId == -1)
749 if (sm->eap_if.eapResp)
751 else if (sm->eap_if.retransWhile == 0)
755 if (sm->retransCount > sm->MaxRetrans)
761 if (sm->rxResp && (sm->respId == sm->currentId))
779 if (sm->eap_if.aaaFail)
781 else if (sm->eap_if.aaaSuccess)
783 else if (sm->eap_if.aaaEapReq)
785 else if (sm->eap_if.aaaTimeout)
798 static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
850 static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp)
856 sm->rxResp = FALSE;
857 sm->respId = -1;
858 sm->respMethod = EAP_TYPE_NONE;
859 sm->respVendor = EAP_VENDOR_IETF;
860 sm->respVendorMethod = EAP_TYPE_NONE;
879 sm->respId = hdr->identifier;
882 sm->rxResp = TRUE;
886 sm->respMethod = *pos++;
887 if (sm->respMethod == EAP_TYPE_EXPANDED) {
894 sm->respVendor = WPA_GET_BE24(pos);
896 sm->respVendorMethod = WPA_GET_BE32(pos);
902 sm->rxResp, sm->respId, sm->respMethod, sm->respVendor,
903 sm->respVendorMethod);
920 static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id)
938 static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id)
956 static int eap_sm_nextId(struct eap_sm *sm, int id)
962 if (id != sm->lastId)
971 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
978 void eap_sm_process_nak(struct eap_sm *sm, const u8 *nak_list, size_t len)
983 if (sm->user == NULL)
987 "index %d)", sm->user_eap_method_index);
990 (u8 *) sm->user->methods,
991 EAP_MAX_METHODS * sizeof(sm->user->methods[0]));
995 i = sm->user_eap_method_index;
997 (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
998 sm->user->methods[i].method != EAP_TYPE_NONE)) {
999 if (sm->user->methods[i].vendor != EAP_VENDOR_IETF)
1002 if (nak_list[j] == sm->user->methods[i].method) {
1015 os_memmove(&sm->user->methods[i], &sm->user->methods[i + 1],
1017 sizeof(sm->user->methods[0]));
1018 sm->user->methods[EAP_MAX_METHODS - 1].vendor =
1020 sm->user->methods[EAP_MAX_METHODS - 1].method = EAP_TYPE_NONE;
1024 (u8 *) sm->user->methods, EAP_MAX_METHODS *
1025 sizeof(sm->user->methods[0]));
1029 static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
1032 if (nak_list == NULL || sm == NULL || sm->user == NULL)
1035 if (sm->user->phase2) {
1038 sm->decision = DECISION_FAILURE;
1042 eap_sm_process_nak(sm, nak_list, len);
1046 static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
1049 int idx = sm->user_eap_method_index;
1058 if (sm->identity == NULL || sm->currentId == -1) {
1061 sm->update_user = TRUE;
1062 } else if (sm->user && idx < EAP_MAX_METHODS &&
1063 (sm->user->methods[idx].vendor != EAP_VENDOR_IETF ||
1064 sm->user->methods[idx].method != EAP_TYPE_NONE)) {
1065 *vendor = sm->user->methods[idx].vendor;
1066 next = sm->user->methods[idx].method;
1067 sm->user_eap_method_index++;
1078 static int eap_sm_Policy_getDecision(struct eap_sm *sm)
1080 if (!sm->eap_server && sm->identity && !sm->start_reauth) {
1085 if (sm->m && sm->currentMethod != EAP_TYPE_IDENTITY &&
1086 sm->m->isSuccess(sm, sm->eap_method_priv)) {
1089 sm->update_user = TRUE;
1093 if (sm->m && sm->m->isDone(sm, sm->eap_method_priv) &&
1094 !sm->m->isSuccess(sm, sm->eap_method_priv)) {
1097 sm->update_user = TRUE;
1101 if ((sm->user == NULL || sm->update_user) && sm->identity &&
1102 !sm->start_reauth) {
1110 if (sm->user && sm->currentMethod == EAP_TYPE_IDENTITY &&
1111 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1112 sm->user->methods[0].method == EAP_TYPE_IDENTITY)
1114 if (eap_user_get(sm, sm->identity, sm->identity_len, 0) != 0) {
1119 if (id_req && sm->user &&
1120 sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
1121 sm->user->methods[0].method == EAP_TYPE_IDENTITY) {
1124 sm->update_user = TRUE;
1127 sm->update_user = FALSE;
1129 sm->start_reauth = FALSE;
1131 if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
1132 (sm->user->methods[sm->user_eap_method_index].vendor !=
1134 sm->user->methods[sm->user_eap_method_index].method !=
1141 if (sm->identity == NULL || sm->currentId == -1) {
1153 static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
1161 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1168 int eap_server_sm_step(struct eap_sm *sm)
1172 sm->changed = FALSE;
1174 if (sm->changed)
1176 } while (sm->changed);
1204 struct eap_sm *sm;
1206 sm = os_zalloc(sizeof(*sm));
1207 if (sm == NULL)
1209 sm->eapol_ctx = eapol_ctx;
1210 sm->eapol_cb = eapol_cb;
1211 sm->MaxRetrans = 5; /* RFC 3748: max 3-5 retransmissions suggested */
1212 sm->ssl_ctx = conf->ssl_ctx;
1213 sm->eap_sim_db_priv = conf->eap_sim_db_priv;
1214 sm->backend_auth = conf->backend_auth;
1215 sm->eap_server = conf->eap_server;
1217 sm->pac_opaque_encr_key = os_malloc(16);
1218 if (sm->pac_opaque_encr_key) {
1219 os_memcpy(sm->pac_opaque_encr_key,
1224 sm->eap_fast_a_id = os_malloc(conf->eap_fast_a_id_len);
1225 if (sm->eap_fast_a_id) {
1226 os_memcpy(sm->eap_fast_a_id, conf->eap_fast_a_id,
1228 sm->eap_fast_a_id_len = conf->eap_fast_a_id_len;
1232 sm->eap_fast_a_id_info = os_strdup(conf->eap_fast_a_id_info);
1233 sm->eap_fast_prov = conf->eap_fast_prov;
1234 sm->pac_key_lifetime = conf->pac_key_lifetime;
1235 sm->pac_key_refresh_time = conf->pac_key_refresh_time;
1236 sm->eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
1237 sm->tnc = conf->tnc;
1238 sm->wps = conf->wps;
1240 sm->assoc_wps_ie = wpabuf_dup(conf->assoc_wps_ie);
1244 return sm;
1250 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1255 void eap_server_sm_deinit(struct eap_sm *sm)
1257 if (sm == NULL)
1260 if (sm->m && sm->eap_method_priv)
1261 sm->m->reset(sm, sm->eap_method_priv);
1262 wpabuf_free(sm->eap_if.eapReqData);
1263 os_free(sm->eap_if.eapKeyData);
1264 wpabuf_free(sm->lastReqData);
1265 wpabuf_free(sm->eap_if.eapRespData);
1266 os_free(sm->identity);
1267 os_free(sm->pac_opaque_encr_key);
1268 os_free(sm->eap_fast_a_id);
1269 os_free(sm->eap_fast_a_id_info);
1270 wpabuf_free(sm->eap_if.aaaEapReqData);
1271 wpabuf_free(sm->eap_if.aaaEapRespData);
1272 os_free(sm->eap_if.aaaEapKeyData);
1273 eap_user_free(sm->user);
1274 wpabuf_free(sm->assoc_wps_ie);
1275 os_free(sm);
1281 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1286 void eap_sm_notify_cached(struct eap_sm *sm)
1288 if (sm == NULL)
1291 sm->EAP_state = EAP_SUCCESS;
1297 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1301 void eap_sm_pending_cb(struct eap_sm *sm)
1303 if (sm == NULL)
1306 if (sm->method_pending == METHOD_PENDING_WAIT)
1307 sm->method_pending = METHOD_PENDING_CONT;
1313 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1316 int eap_sm_method_pending(struct eap_sm *sm)
1318 if (sm == NULL)
1320 return sm->method_pending == METHOD_PENDING_WAIT;
1326 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1330 const u8 * eap_get_identity(struct eap_sm *sm, size_t *len)
1332 *len = sm->identity_len;
1333 return sm->identity;
1339 * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1342 struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm)
1344 return &sm->eap_if;