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);
85 static void eapol_auth_tx_canned_eap(struct eapol_state_machine *sm,
93 eap.identifier = ++sm->last_eap_id;
96 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
99 sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
102 sm->dot1xAuthEapolFramesTx++;
106 static void eapol_auth_tx_req(struct eapol_state_machine *sm)
108 if (sm->eap_if->eapReqData == NULL ||
109 wpabuf_len(sm->eap_if->eapReqData) < sizeof(struct eap_hdr)) {
110 eapol_auth_logger(sm->eapol, sm->addr,
117 if (sm->flags & EAPOL_SM_WAIT_START) {
120 MAC2STR(sm->addr));
124 sm->last_eap_id = eap_get_id(sm->eap_if->eapReqData);
125 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
127 sm->last_eap_id);
128 sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
130 wpabuf_head(sm->eap_if->eapReqData),
131 wpabuf_len(sm->eap_if->eapReqData));
132 sm->dot1xAuthEapolFramesTx++;
133 if (eap_get_type(sm->eap_if->eapReqData) == EAP_TYPE_IDENTITY)
134 sm->dot1xAuthEapolReqIdFramesTx++;
136 sm->dot1xAuthEapolReqFramesTx++;
200 sm->portMode = Auto;
212 sm->keyRun = FALSE;
218 int from_initialize = sm->auth_pae_state == AUTH_PAE_INITIALIZE;
220 if (sm->eapolLogoff) {
221 if (sm->auth_pae_state == AUTH_PAE_CONNECTING)
222 sm->authEapLogoffsWhileConnecting++;
223 else if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED)
224 sm->authAuthEapLogoffWhileAuthenticated++;
229 sm->authPortStatus = Unauthorized;
231 sm->reAuthCount = 0;
232 sm->eapolLogoff = FALSE;
234 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
235 sm->flags & EAPOL_SM_PREAUTH,
236 sm->remediation);
243 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED) {
244 if (sm->reAuthenticate)
245 sm->authAuthReauthsWhileAuthenticated++;
246 if (sm->eapolStart)
247 sm->authAuthEapStartsWhileAuthenticated++;
248 if (sm->eapolLogoff)
249 sm->authAuthEapLogoffWhileAuthenticated++;
254 sm->eap_if->eapRestart = TRUE;
260 if (sm->auth_pae_state != AUTH_PAE_CONNECTING)
261 sm->authEntersConnecting++;
265 sm->reAuthenticate = FALSE;
266 sm->reAuthCount++;
272 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authFail)
273 sm->authAuthFailWhileAuthenticating++;
277 sm->authPortStatus = Unauthorized;
279 sm->quietWhile = sm->quietPeriod;
280 sm->eapolLogoff = FALSE;
282 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_WARNING,
284 sm->eap_type_authsrv,
285 eap_server_get_name(0, sm->eap_type_authsrv));
286 if (sm->eap_type_authsrv != sm->eap_type_supp) {
287 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
289 "%d (%s)", sm->eap_type_supp,
290 eap_server_get_name(0, sm->eap_type_supp));
292 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
293 sm->flags & EAPOL_SM_PREAUTH, sm->remediation);
301 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authSuccess)
302 sm->authAuthSuccessesWhileAuthenticating++;
306 sm->authPortStatus = Authorized;
308 sm->reAuthCount = 0;
309 if (sm->flags & EAPOL_SM_PREAUTH)
311 else if (sm->flags & EAPOL_SM_FROM_PMKSA_CACHE)
313 eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
315 sm->eap_type_authsrv,
316 eap_server_get_name(0, sm->eap_type_authsrv),
318 sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 1,
319 sm->flags & EAPOL_SM_PREAUTH, sm->remediation);
327 sm->eapolStart = FALSE;
328 sm->authSuccess = FALSE;
329 sm->authFail = FALSE;
330 sm->authTimeout = FALSE;
331 sm->authStart = TRUE;
332 sm->keyRun = FALSE;
333 sm->keyDone = FALSE;
339 if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING) {
340 if (sm->authTimeout)
341 sm->authAuthTimeoutsWhileAuthenticating++;
342 if (sm->eapolStart)
343 sm->authAuthEapStartsWhileAuthenticating++;
344 if (sm->eapolLogoff)
345 sm->authAuthEapLogoffWhileAuthenticating++;
350 sm->authAbort = TRUE;
351 sm->keyRun = FALSE;
352 sm->keyDone = FALSE;
360 sm->authPortStatus = Authorized;
362 sm->portMode = ForceAuthorized;
363 sm->eapolStart = FALSE;
372 sm->authPortStatus = Unauthorized;
374 sm->portMode = ForceUnauthorized;
375 sm->eapolStart = FALSE;
382 if ((sm->portControl == Auto && sm->portMode != sm->portControl) ||
383 sm->initialize || !sm->eap_if->portEnabled)
385 else if (sm->portControl == ForceAuthorized &&
386 sm->portMode != sm->portControl &&
387 !(sm->initialize || !sm->eap_if->portEnabled))
389 else if (sm->portControl == ForceUnauthorized &&
390 sm->portMode != sm->portControl &&
391 !(sm->initialize || !sm->eap_if->portEnabled))
394 switch (sm->auth_pae_state) {
402 if (!sm->eap_if->eapRestart)
406 if (sm->quietWhile == 0)
410 if (sm->eapolLogoff || sm->reAuthCount > sm->reAuthMax)
412 else if ((sm->eap_if->eapReq &&
413 sm->reAuthCount <= sm->reAuthMax) ||
414 sm->eap_if->eapSuccess || sm->eap_if->eapFail)
418 if (sm->eapolStart || sm->reAuthenticate)
420 else if (sm->eapolLogoff || !sm->portValid)
424 if (sm->authSuccess && sm->portValid)
426 else if (sm->authFail ||
427 (sm->keyDone && !sm->portValid))
429 else if (sm->eapolStart || sm->eapolLogoff ||
430 sm->authTimeout)
434 if (sm->eapolLogoff && !sm->authAbort)
436 else if (!sm->eapolLogoff && !sm->authAbort)
440 if (sm->eapolStart)
444 if (sm->eapolStart)
460 sm->eap_if->eapNoReq = FALSE;
461 sm->authAbort = FALSE;
470 sm->eap_if->eapReq = FALSE;
471 sm->backendOtherRequestsToSupplicant++;
484 sm->eapolEap = FALSE;
492 sm->authTimeout = FALSE;
493 sm->eapolEap = FALSE;
494 sm->eap_if->eapNoReq = FALSE;
495 sm->aWhile = sm->serverTimeout;
496 sm->eap_if->eapResp = TRUE;
498 sm->backendResponses++;
507 sm->authSuccess = TRUE;
508 sm->keyRun = TRUE;
517 sm->authFail = TRUE;
525 sm->authTimeout = TRUE;
533 sm->authStart = FALSE;
541 sm->eap_if->eapNoReq = FALSE;
547 if (sm->portControl != Auto || sm->initialize || sm->authAbort) {
552 switch (sm->be_auth_state) {
557 if (sm->eapolEap)
559 else if (sm->eap_if->eapReq)
561 else if (sm->eap_if->eapTimeout)
565 if (sm->eap_if->eapNoReq)
567 if (sm->eap_if->eapReq) {
568 sm->backendAccessChallenges++;
570 } else if (sm->aWhile == 0)
572 else if (sm->eap_if->eapFail) {
573 sm->backendAuthFails++;
575 } else if (sm->eap_if->eapSuccess) {
576 sm->backendAuthSuccesses++;
590 if (sm->eap_if->eapFail && sm->authStart)
592 else if (sm->eap_if->eapReq && sm->authStart)
594 else if (sm->eap_if->eapSuccess && sm->authStart)
598 if (sm->eapolEap)
600 else if (sm->eap_if->eapReq)
602 else if (sm->eap_if->eapTimeout)
616 sm->reAuthWhen = sm->reAuthPeriod;
624 sm->reAuthenticate = TRUE;
625 sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
632 if (sm->portControl != Auto || sm->initialize ||
633 sm->authPortStatus == Unauthorized || !sm->reAuthEnabled) {
638 switch (sm->reauth_timer_state) {
640 if (sm->reAuthWhen == 0)
664 sm
665 sm->keyDone = TRUE;
671 if (sm->initialize || sm->portControl != Auto) {
676 switch (sm->auth_key_tx_state) {
678 if (sm->keyTxEnabled && sm->eap_if->eapKeyAvailable &&
679 sm->keyRun && !(sm->flags & EAPOL_SM_USES_WPA))
683 if (!sm->keyTxEnabled || !sm->keyRun)
685 else if (sm->eap_if->eapKeyAvailable)
706 sm->rxKey = FALSE;
712 if (sm->initialize || !sm->eap_if->portEnabled) {
717 switch (sm->key_rx_state) {
719 if (sm->rxKey)
723 if (sm->rxKey)
736 sm->operControlledDirections = Both;
743 sm->operControlledDirections = sm->adminControlledDirections;
749 if (sm->initialize) {
754 switch (sm->ctrl_dir_state) {
756 if (sm->eap_if->portEnabled && sm->operEdge)
760 if (sm->operControlledDirections !=
761 sm->adminControlledDirections)
763 if (!sm->eap_if->portEnabled || !sm->operEdge)
777 struct eapol_state_machine *sm;
783 sm = os_zalloc(sizeof(*sm));
784 if (sm == NULL) {
789 sm->radius_identifier = -1;
790 os_memcpy(sm->addr, addr, ETH_ALEN);
791 sm->flags = flags;
793 sm->eapol = eapol;
794 sm->sta = sta_ctx;
797 sm->auth_pae_state = AUTH_PAE_INITIALIZE;
798 sm->quietPeriod = AUTH_PAE_DEFAULT_quietPeriod;
799 sm->reAuthMax = AUTH_PAE_DEFAULT_reAuthMax;
801 sm->be_auth_state = BE_AUTH_INITIALIZE;
802 sm->serverTimeout = BE_AUTH_DEFAULT_serverTimeout;
804 sm->reauth_timer_state = REAUTH_TIMER_INITIALIZE;
805 sm->reAuthPeriod = eapol->conf.eap_reauth_period;
806 sm->reAuthEnabled = eapol->conf.eap_reauth_period > 0 ? TRUE : FALSE;
808 sm->auth_key_tx_state = AUTH_KEY_TX_NO_KEY_TRANSMIT;
810 sm->key_rx_state = KEY_RX_NO_KEY_RECEIVE;
812 sm->ctrl_dir_state = CTRL_DIR_IN_OR_BOTH;
814 sm->portControl = Auto;
818 sm->keyTxEnabled = TRUE;
820 sm->keyTxEnabled = FALSE;
822 sm->portValid = FALSE;
824 sm->portValid = TRUE;
852 sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
853 if (sm->eap == NULL) {
854 eapol_auth_free(sm);
857 sm->eap_if = eap_get_interface(sm->eap);
859 eapol_auth_initialize(sm);
862 sm->identity = (u8 *) os_strdup(identity);
863 if (sm->identity)
864 sm->identity_len = os_strlen(identity);
867 sm->radius_cui = wpabuf_alloc_copy(radius_cui,
871 if (radius_gen_session_id((u8 *) &sm->acct_multi_session_id,
872 sizeof(sm->acct_multi_session_id)) < 0) {
873 eapol_auth_free(sm);
878 return sm;
882 void eapol_auth_free(struct eapol_state_machine *sm)
884 if (sm == NULL)
887 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
888 eloop_cancel_timeout(eapol_sm_step_cb, sm, NULL);
889 if (sm->eap)
890 eap_server_sm_deinit(sm->eap);
892 wpabuf_free(sm->radius_cui);
893 os_free(sm->identity);
894 os_free(sm);
905 static void eapol_sm_step_run(struct eapol_state_machine *sm)
907 struct eapol_authenticator *eapol = sm->eapol;
913 os_memcpy(addr, sm->addr, ETH_ALEN);
922 prev_auth_pae = sm->auth_pae_state;
923 prev_be_auth = sm->be_auth_state;
924 prev_reauth_timer = sm->reauth_timer_state;
925 prev_auth_key_tx = sm->auth_key_tx_state;
926 prev_key_rx = sm->key_rx_state;
927 prev_ctrl_dir = sm->ctrl_dir_state;
930 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
932 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
934 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
936 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
938 if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
941 if (prev_auth_pae != sm->auth_pae_state ||
942 prev_be_auth != sm->be_auth_state ||
943 prev_reauth_timer != sm->reauth_timer_state ||
944 prev_auth_key_tx != sm->auth_key_tx_state ||
945 prev_key_rx != sm->key_rx_state ||
946 prev_ctrl_dir != sm->ctrl_dir_state) {
950 eapol_auth_step(sm);
954 if (eapol_sm_sta_entry_alive(eapol, addr) && sm->eap) {
955 if (eap_server_sm_step(sm->eap)) {
959 eapol_auth_step(sm);
964 if (sm->eap_if->aaaEapResp) {
965 sm->eap_if->aaaEapResp = FALSE;
966 if (sm->eap_if->aaaEapRespData == NULL) {
971 sm->eapol->cb.aaa_send(
972 sm->eapol->conf.ctx, sm->sta,
973 wpabuf_head(sm->eap_if->aaaEapRespData),
974 wpabuf_len(sm->eap_if->aaaEapRespData));
979 sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
986 struct eapol_state_machine *sm = eloop_ctx;
987 eapol_sm_step_run(sm);
993 * @sm: EAPOL state machine
998 void eapol_auth_step(struct eapol_state_machine *sm)
1006 eloop_register_timeout(0, 0, eapol_sm_step_cb, sm, NULL);
1010 static void eapol_auth_initialize(struct eapol_state_machine *sm)
1012 sm->initializing = TRUE;
1015 sm->initialize = TRUE;
1016 eapol_sm_step_run(sm);
1017 sm->initialize = FALSE;
1018 eapol_sm_step_run(sm);
1019 sm->initializing = FALSE;
1022 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
1023 eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);
1031 struct eapol_state_machine *sm = ctx;
1034 ret = sm->eapol->cb.get_eap_user(sm->eapol->conf.ctx, identity,
1037 sm->remediation = 1;
1044 struct eapol_state_machine *sm = ctx;
1045 *len = sm->eapol->conf.eap_req_id_text_len;
1046 return sm->eapol->conf.eap_req_id_text;
1052 struct eapol_state_machine *sm = ctx;
1053 return sm->eapol->conf.erp_send_reauth_start;
1059 struct eapol_state_machine *sm = ctx;
1060 return sm->eapol->conf.erp_domain;
1067 struct eapol_state_machine *sm = ctx;
1068 return sm->eapol->cb.erp_get_key(sm->eapol->conf.ctx, keyname);
1074 struct eapol_state_machine *sm = ctx;
1075 return sm->eapol->cb.erp_add_key(sm->eapol->conf.ctx, erp);
1091 int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx)
1093 if (sm == NULL || ctx == NULL || ctx != sm->eap)
1096 eap_sm_pending_cb(sm->eap);
1097 eapol_auth_step(sm);
1103 void eapol_auth_reauthenticate(struct eapol_state_machine *sm)
1106 MACSTR, MAC2STR(sm->addr));
1107 sm->reAuthenticate = TRUE;
1108 eapol_auth_step(sm);
1112 int eapol_auth_set_conf(struct eapol_state_machine *sm, const char *param,
1117 MAC2STR(sm->addr), param, value);
1121 sm->adminControlledDirections = Both;
1123 sm->adminControlledDirections = In;
1126 eapol_auth_step(sm);
1132 sm->portControl = ForceAuthorized;
1134 sm->portControl = ForceUnauthorized;
1136 sm->portControl = Auto;
1139 eapol_auth_step(sm);
1144 sm->quietPeriod = atoi(value);
1149 sm->serverTimeout = atoi(value);
1154 sm->reAuthPeriod = atoi(value);
1160 sm->reAuthEnabled = TRUE;
1162 sm->reAuthEnabled = FALSE;
1165 eapol_auth_step(sm);
1171 sm->keyTxEnabled = TRUE;
1173 sm->keyTxEnabled = FALSE;
1176 eapol_auth_step(sm);