Home | History | Annotate | Download | only in eapol_auth

Lines Matching refs:sm

23 #define STATE_MACHINE_ADDR sm->addr
30 sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 1)
32 sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 0)
35 #define txCannedFail() eapol_auth_tx_canned_eap(sm, 0)
36 #define txCannedSuccess() eapol_auth_tx_canned_eap(sm, 1)
37 #define txReq() eapol_auth_tx_req(sm)
38 #define abortAuth() sm->eapol->cb.abort_auth(sm->eapol->conf.ctx, sm->sta)
39 #define txKey() sm->eapol->cb.tx_key(sm->eapol->conf.ctx, sm->sta)
43 static void eapol_sm_step_run(struct eapol_state_machine *sm);
45 static void eapol_auth_initialize(struct eapol_state_machine *sm);
84 static void eapol_auth_tx_canned_eap(struct eapol_state_machine *sm,
92 eap.identifier = ++sm->last_eap_id;
95 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
98 sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
101 sm->dot1xAuthEapolFramesTx++;
105 static void eapol_auth_tx_req(struct eapol_state_machine *sm)
107 if (sm->eap_if->eapReqData == NULL ||
108 wpabuf_len(sm->eap_if->eapReqData) < sizeof(struct eap_hdr)) {
109 eapol_auth_logger(sm->eapol, sm->addr,
116 if (sm->flags & EAPOL_SM_WAIT_START) {
119 MAC2STR(sm->addr));
123 sm->last_eap_id = eap_get_id(sm->eap_if->eapReqData);
124 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
126 sm->last_eap_id);
127 sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
129 wpabuf_head(sm->eap_if->eapReqData),
130 wpabuf_len(sm->eap_if->eapReqData));
131 sm->dot1xAuthEapolFramesTx++;
132 if (eap_get_type(sm->eap_if->eapReqData) == EAP_TYPE_IDENTITY)
133 sm->dot1xAuthEapolReqIdFramesTx++;
135 sm->dot1xAuthEapolReqFramesTx++;
199 sm->portMode = Auto;
205 int from_initialize = sm->auth_pae_state == AUTH_PAE_INITIALIZE;
207 if (sm->eapolLogoff) {
208 if (sm->auth_pae_state == AUTH_PAE_CONNECTING)
209 sm->authEapLogoffsWhileConnecting++;
210 else if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED)
211 sm->authAuthEapLogoffWhileAuthenticated++;
216 sm->authPortStatus = Unauthorized;
218 sm->reAuthCount = 0;
219 sm->eapolLogoff = FALSE;
221 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
222 sm->flags & EAPOL_SM_PREAUTH);
229 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED) {
230 if (sm->reAuthenticate)
231 sm->authAuthReauthsWhileAuthenticated++;
232 if (sm->eapolStart)
233 sm->authAuthEapStartsWhileAuthenticated++;
234 if (sm->eapolLogoff)
235 sm->authAuthEapLogoffWhileAuthenticated++;
240 sm->eap_if->eapRestart = TRUE;
246 if (sm->auth_pae_state != AUTH_PAE_CONNECTING)
247 sm->authEntersConnecting++;
251 sm->reAuthenticate = FALSE;
252 sm->reAuthCount++;
258 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authFail)
259 sm->authAuthFailWhileAuthenticating++;
263 sm->authPortStatus = Unauthorized;
265 sm->quietWhile = sm->quietPeriod;
266 sm->eapolLogoff = FALSE;
268 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_WARNING,
270 sm->eap_type_authsrv,
271 eap_server_get_name(0, sm->eap_type_authsrv));
272 if (sm->eap_type_authsrv != sm->eap_type_supp) {
273 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
275 "%d (%s)", sm->eap_type_supp,
276 eap_server_get_name(0, sm->eap_type_supp));
278 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
279 sm->flags & EAPOL_SM_PREAUTH);
287 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authSuccess)
288 sm->authAuthSuccessesWhileAuthenticating++;
292 sm->authPortStatus = Authorized;
294 sm->reAuthCount = 0;
295 if (sm->flags & EAPOL_SM_PREAUTH)
297 else if (sm->flags & EAPOL_SM_FROM_PMKSA_CACHE)
299 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
301 sm->eap_type_authsrv,
302 eap_server_get_name(0, sm->eap_type_authsrv),
304 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 1,
305 sm->flags & EAPOL_SM_PREAUTH);
313 sm->eapolStart = FALSE;
314 sm->authSuccess = FALSE;
315 sm->authFail = FALSE;
316 sm->authTimeout = FALSE;
317 sm->authStart = TRUE;
318 sm->keyRun = FALSE;
319 sm->keyDone = FALSE;
325 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING) {
326 if (sm->authTimeout)
327 sm->authAuthTimeoutsWhileAuthenticating++;
328 if (sm->eapolStart)
329 sm->authAuthEapStartsWhileAuthenticating++;
330 if (sm->eapolLogoff)
331 sm->authAuthEapLogoffWhileAuthenticating++;
336 sm->authAbort = TRUE;
337 sm->keyRun = FALSE;
338 sm->keyDone = FALSE;
346 sm->authPortStatus = Authorized;
348 sm->portMode = ForceAuthorized;
349 sm->eapolStart = FALSE;
358 sm->authPortStatus = Unauthorized;
360 sm->portMode = ForceUnauthorized;
361 sm->eapolStart = FALSE;
368 if ((sm->portControl == Auto && sm->portMode != sm->portControl) ||
369 sm->initialize || !sm->eap_if->portEnabled)
371 else if (sm->portControl == ForceAuthorized &&
372 sm->portMode != sm->portControl &&
373 !(sm->initialize || !sm->eap_if->portEnabled))
375 else if (sm->portControl == ForceUnauthorized &&
376 sm->portMode != sm->portControl &&
377 !(sm->initialize || !sm->eap_if->portEnabled))
380 switch (sm->auth_pae_state) {
388 if (!sm->eap_if->eapRestart)
392 if (sm->quietWhile == 0)
396 if (sm->eapolLogoff || sm->reAuthCount > sm->reAuthMax)
398 else if ((sm->eap_if->eapReq &&
399 sm->reAuthCount <= sm->reAuthMax) ||
400 sm->eap_if->eapSuccess || sm->eap_if->eapFail)
404 if (sm->eapolStart || sm->reAuthenticate)
406 else if (sm->eapolLogoff || !sm->portValid)
410 if (sm->authSuccess && sm->portValid)
412 else if (sm->authFail ||
413 (sm->keyDone && !sm->portValid))
415 else if (sm->eapolStart || sm->eapolLogoff ||
416 sm->authTimeout)
420 if (sm->eapolLogoff && !sm->authAbort)
422 else if (!sm->eapolLogoff && !sm->authAbort)
426 if (sm->eapolStart)
430 if (sm->eapolStart)
446 sm->eap_if->eapNoReq = FALSE;
447 sm->authAbort = FALSE;
456 sm->eap_if->eapReq = FALSE;
457 sm->backendOtherRequestsToSupplicant++;
470 sm->eapolEap = FALSE;
478 sm->authTimeout = FALSE;
479 sm->eapolEap = FALSE;
480 sm->eap_if->eapNoReq = FALSE;
481 sm->aWhile = sm->serverTimeout;
482 sm->eap_if->eapResp = TRUE;
484 sm->backendResponses++;
493 sm->authSuccess = TRUE;
494 sm->keyRun = TRUE;
503 sm->authFail = TRUE;
511 sm->authTimeout = TRUE;
519 sm->authStart = FALSE;
527 sm->eap_if->eapNoReq = FALSE;
533 if (sm->portControl != Auto || sm->initialize || sm->authAbort) {
538 switch (sm->be_auth_state) {
543 if (sm->eapolEap)
545 else if (sm->eap_if->eapReq)
547 else if (sm->eap_if->eapTimeout)
551 if (sm->eap_if->eapNoReq)
553 if (sm->eap_if->eapReq) {
554 sm->backendAccessChallenges++;
556 } else if (sm->aWhile == 0)
558 else if (sm->eap_if->eapFail) {
559 sm->backendAuthFails++;
561 } else if (sm->eap_if->eapSuccess) {
562 sm->backendAuthSuccesses++;
576 if (sm->eap_if->eapFail && sm->authStart)
578 else if (sm->eap_if->eapReq && sm->authStart)
580 else if (sm->eap_if->eapSuccess && sm->authStart)
584 if (sm->eapolEap)
586 else if (sm->eap_if->eapReq)
588 else if (sm->eap_if->eapTimeout)
602 sm->reAuthWhen = sm->reAuthPeriod;
610 sm->reAuthenticate = TRUE;
611 sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
618 if (sm->portControl != Auto || sm->initialize ||
619 sm->authPortStatus == Unauthorized || !sm->reAuthEnabled) {
624 switch (sm->reauth_timer_state) {
626 if (sm->reAuthWhen == 0)
650 sm->eap_if->eapKeyAvailable = FALSE;
651 sm->keyDone = TRUE;
657 if (sm->initialize || sm->portControl != Auto) {
662 switch (sm->auth_key_tx_state) {
664 if (sm->keyTxEnabled && sm->eap_if->eapKeyAvailable &&
665 sm->keyRun && !(sm->flags & EAPOL_SM_USES_WPA))
669 if (!sm->keyTxEnabled || !sm->keyRun)
671 else if (sm->eap_if->eapKeyAvailable)
692 sm->rxKey = FALSE;
698 if (sm->initialize || !sm->eap_if->portEnabled) {
703 switch (sm->key_rx_state) {
705 if (sm->rxKey)
709 if (sm->rxKey)
722 sm->operControlledDirections = Both;
729 sm->operControlledDirections = sm->adminControlledDirections;
735 if (sm->initialize) {
740 switch (sm->ctrl_dir_state) {
742 if (sm->eap_if->portEnabled && sm->operEdge)
746 if (sm->operControlledDirections !=
747 sm->adminControlledDirections)
749 if (!sm->eap_if->portEnabled || !sm->operEdge)
763 struct eapol_state_machine *sm;
769 sm = os_zalloc(sizeof(*sm));
770 if (sm == NULL) {
775 sm->radius_identifier = -1;
776 os_memcpy(sm->addr, addr, ETH_ALEN);
777 sm->flags = flags;
779 sm->eapol = eapol;
780 sm->sta = sta_ctx;
783 sm->auth_pae_state = AUTH_PAE_INITIALIZE;
784 sm->quietPeriod = AUTH_PAE_DEFAULT_quietPeriod;
785 sm->reAuthMax = AUTH_PAE_DEFAULT_reAuthMax;
787 sm->be_auth_state = BE_AUTH_INITIALIZE;
788 sm->serverTimeout = BE_AUTH_DEFAULT_serverTimeout;
790 sm->reauth_timer_state = REAUTH_TIMER_INITIALIZE;
791 sm->reAuthPeriod = eapol->conf.eap_reauth_period;
792 sm->reAuthEnabled = eapol->conf.eap_reauth_period > 0 ? TRUE : FALSE;
794 sm->auth_key_tx_state = AUTH_KEY_TX_NO_KEY_TRANSMIT;
796 sm->key_rx_state = KEY_RX_NO_KEY_RECEIVE;
798 sm->ctrl_dir_state = CTRL_DIR_IN_OR_BOTH;
800 sm->portControl = Auto;
804 sm->keyTxEnabled = TRUE;
806 sm->keyTxEnabled = FALSE;
808 sm->portValid = FALSE;
810 sm->portValid = TRUE;
833 sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
834 if (sm->eap == NULL) {
835 eapol_auth_free(sm);
838 sm->eap_if = eap_get_interface(sm->eap);
840 eapol_auth_initialize(sm);
843 sm->identity = (u8 *) os_strdup(identity);
844 if (sm->identity)
845 sm->identity_len = os_strlen(identity);
848 sm->radius_cui = wpabuf_alloc_copy(radius_cui,
851 return sm;
855 void eapol_auth_free(struct eapol_state_machine *sm)
857 if (sm == NULL)
860 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
861 eloop_cancel_timeout(eapol_sm_step_cb, sm, NULL);
862 if (sm->eap)
863 eap_server_sm_deinit(sm->eap);
864 os_free(sm);
875 static void eapol_sm_step_run(struct eapol_state_machine *sm)
877 struct eapol_authenticator *eapol = sm->eapol;
883 os_memcpy(addr, sm->addr, ETH_ALEN);
892 prev_auth_pae = sm->auth_pae_state;
893 prev_be_auth = sm->be_auth_state;
894 prev_reauth_timer = sm->reauth_timer_state;
895 prev_auth_key_tx = sm->auth_key_tx_state;
896 prev_key_rx = sm->key_rx_state;
897 prev_ctrl_dir = sm->ctrl_dir_state;
900 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
902 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
904 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
906 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
908 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
911 if (prev_auth_pae != sm->auth_pae_state ||
912 prev_be_auth != sm->be_auth_state ||
913 prev_reauth_timer != sm->reauth_timer_state ||
914 prev_auth_key_tx != sm->auth_key_tx_state ||
915 prev_key_rx != sm->key_rx_state ||
916 prev_ctrl_dir != sm->ctrl_dir_state) {
920 eapol_auth_step(sm);
924 if (eapol_sm_sta_entry_alive(eapol, addr) && sm->eap) {
925 if (eap_server_sm_step(sm->eap)) {
929 eapol_auth_step(sm);
934 if (sm->eap_if->aaaEapResp) {
935 sm->eap_if->aaaEapResp = FALSE;
936 if (sm->eap_if->aaaEapRespData == NULL) {
941 sm->eapol->cb.aaa_send(
942 sm->eapol->conf.ctx, sm->sta,
943 wpabuf_head(sm->eap_if->aaaEapRespData),
944 wpabuf_len(sm->eap_if->aaaEapRespData));
949 sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
956 struct eapol_state_machine *sm = eloop_ctx;
957 eapol_sm_step_run(sm);
963 * @sm: EAPOL state machine
968 void eapol_auth_step(struct eapol_state_machine *sm)
976 eloop_register_timeout(0, 0, eapol_sm_step_cb, sm, NULL);
980 static void eapol_auth_initialize(struct eapol_state_machine *sm)
982 sm->initializing = TRUE;
985 sm->initialize = TRUE;
986 eapol_sm_step_run(sm);
987 sm->initialize = FALSE;
988 eapol_sm_step_run(sm);
989 sm->initializing = FALSE;
992 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
993 eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);
1001 struct eapol_state_machine *sm = ctx;
1002 return sm->eapol->cb.get_eap_user(sm->eapol->conf.ctx, identity,
1009 struct eapol_state_machine *sm = ctx;
1010 *len = sm->eapol->conf.eap_req_id_text_len;
1011 return sm->eapol->conf.eap_req_id_text;
1022 int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx)
1024 if (sm == NULL || ctx == NULL || ctx != sm->eap)
1027 eap_sm_pending_cb(sm->eap);
1028 eapol_auth_step(sm);