Home | History | Annotate | Download | only in eapol_supp

Lines Matching refs:sm

188 static void eapol_sm_txLogoff(struct eapol_sm *sm);
189 static void eapol_sm_txStart(struct eapol_sm *sm);
190 static void eapol_sm_processKey(struct eapol_sm *sm);
191 static void eapol_sm_getSuppRsp(struct eapol_sm *sm);
192 static void eapol_sm_txSuppRsp(struct eapol_sm *sm);
193 static void eapol_sm_abortSupp(struct eapol_sm *sm);
194 static void eapol_sm_abort_cached(struct eapol_sm *sm);
202 struct eapol_sm *sm = timeout_ctx;
204 if (sm->authWhile > 0) {
205 sm->authWhile--;
206 if (sm->authWhile == 0)
209 if (sm->heldWhile > 0) {
210 sm->heldWhile--;
211 if (sm->heldWhile == 0)
214 if (sm->startWhen > 0) {
215 sm->startWhen--;
216 if (sm->startWhen == 0)
219 if (sm->idleWhile > 0) {
220 sm->idleWhile--;
221 if (sm->idleWhile == 0)
225 if (sm->authWhile | sm->heldWhile | sm->startWhen | sm->idleWhile) {
227 sm);
230 sm->timer_tick_enabled = 0;
232 eapol_sm_step(sm);
236 static void eapol_enable_timer_tick(struct eapol_sm *sm)
238 if (sm->timer_tick_enabled)
241 sm->timer_tick_enabled = 1;
242 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
243 eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);
250 eapol_sm_txLogoff(sm);
251 sm->logoffSent = TRUE;
252 sm->suppPortStatus = Unauthorized;
259 sm->sPortMode = Auto;
260 sm->startCount = 0;
261 sm->logoffSent = FALSE;
262 sm->suppPortStatus = Unauthorized;
263 sm->suppAbort = TRUE;
265 sm->unicast_key_received = FALSE;
266 sm->broadcast_key_received = FALSE;
272 int send_start = sm->SUPP_PAE_state == SUPP_PAE_CONNECTING;
275 sm->startWhen = sm->startPeriod;
276 sm->startCount++;
287 sm->startWhen = 1;
289 sm->startWhen = 3;
292 eapol_enable_timer_tick(sm);
293 sm->eapolEap = FALSE;
295 eapol_sm_txStart(sm);
302 sm->startCount = 0;
303 sm->suppSuccess = FALSE;
304 sm->suppFail = FALSE;
305 sm->suppTimeout = FALSE;
306 sm->keyRun = FALSE;
307 sm->keyDone = FALSE;
308 sm->suppStart = TRUE;
315 sm->heldWhile = sm->heldPeriod;
316 eapol_enable_timer_tick(sm);
317 sm->suppPortStatus = Unauthorized;
318 sm->cb_status = EAPOL_CB_FAILURE;
325 sm->suppPortStatus = Authorized;
326 sm->cb_status = EAPOL_CB_SUCCESS;
333 sm->eapRestart = TRUE;
340 sm->suppPortStatus = Authorized;
341 sm->sPortMode = ForceAuthorized;
348 sm->suppPortStatus = Unauthorized;
349 sm->sPortMode = ForceUnauthorized;
350 eapol_sm_txLogoff(sm);
356 if ((sm->userLogoff && !sm->logoffSent) &&
357 !(sm->initialize || !sm->portEnabled))
359 else if (((sm->portControl == Auto) &&
360 (sm->sPortMode != sm->portControl)) ||
361 sm->initialize || !sm->portEnabled)
363 else if ((sm->portControl == ForceAuthorized) &&
364 (sm->sPortMode != sm->portControl) &&
365 !(sm->initialize || !sm->portEnabled))
367 else if ((sm->portControl == ForceUnauthorized) &&
368 (sm->sPortMode != sm->portControl) &&
369 !(sm->initialize || !sm->portEnabled))
371 else switch (sm->SUPP_PAE_state) {
375 if (!sm->userLogoff)
382 if (sm->startWhen == 0 && sm->startCount < sm->maxStart)
384 else if (sm->startWhen == 0 &&
385 sm->startCount >= sm->maxStart &&
386 sm->portValid)
388 else if (sm->eapSuccess || sm->eapFail)
390 else if (sm->eapolEap)
392 else if (sm->startWhen == 0 &&
393 sm->startCount >= sm->maxStart &&
394 !sm->portValid)
398 if (sm->eapSuccess && !sm->portValid &&
399 sm->conf.accept_802_1x_keys &&
400 sm->conf.required_keys == 0) {
404 sm->portValid = TRUE;
405 if (sm->ctx->eapol_done_cb)
406 sm->ctx->eapol_done_cb(sm->ctx->ctx);
408 if (sm->eapSuccess && sm->portValid)
410 else if (sm->eapFail || (sm->keyDone && !sm->portValid))
412 else if (sm->suppTimeout)
416 if (sm->heldWhile == 0)
418 else if (sm->eapolEap)
422 if (sm->eapolEap && sm->portValid)
424 else if (!sm->portValid)
428 if (!sm->eapRestart)
448 eapol_sm_processKey(sm);
449 sm->rxKey = FALSE;
455 if (sm->initialize || !sm->portEnabled)
457 switch (sm->KEY_RX_state) {
461 if (sm->rxKey)
465 if (sm->rxKey)
475 sm->authWhile = 0;
476 sm->eapReq = TRUE;
477 eapol_sm_getSuppRsp(sm);
484 eapol_sm_txSuppRsp(sm);
485 sm->eapResp = FALSE;
492 sm->keyRun = TRUE;
493 sm->suppSuccess = TRUE;
495 if (eap_key_available(sm->eap)) {
498 sm->replay_counter_valid = FALSE;
506 sm->suppFail = TRUE;
513 sm->suppTimeout = TRUE;
520 sm->suppStart = FALSE;
521 sm->initial_req = TRUE;
528 eapol_sm_abortSupp(sm);
529 sm->suppAbort = FALSE;
536 sm->authWhile = sm->authPeriod;
537 eapol_enable_timer_tick(sm);
538 sm->eapolEap = FALSE;
539 sm->eapNoResp = FALSE;
540 sm->initial_req = FALSE;
546 if (sm->initialize || sm->suppAbort)
548 else switch (sm->SUPP_BE_state) {
566 if (sm->eapResp && sm->eapNoResp) {
570 if (sm->eapResp)
572 else if (sm->eapNoResp)
574 else if (sm->eapFail)
576 else if (sm->eapSuccess)
592 if (sm->eapFail && sm->suppStart)
594 else if (sm->eapolEap && sm->suppStart)
596 else if (sm->eapSuccess && sm->suppStart)
603 if (sm->eapolEap)
605 else if (sm->eapFail)
607 else if (sm->authWhile == 0)
609 else if (sm->eapSuccess)
616 static void eapol_sm_txLogoff(struct eapol_sm *sm)
619 sm->ctx->eapol_send(sm->ctx->eapol_send_ctx,
621 sm->dot1xSuppEapolLogoffFramesTx++;
622 sm->dot1xSuppEapolFramesTx++;
626 static void eapol_sm_txStart(struct eapol_sm *sm)
629 sm->ctx->eapol_send(sm->ctx->eapol_send_ctx,
631 sm->dot1xSuppEapolStartFramesTx++;
632 sm->dot1xSuppEapolFramesTx++;
645 static void eapol_sm_processKey(struct eapol_sm *sm)
656 if (sm->last_rx_key == NULL)
659 if (!sm->conf.accept_802_1x_keys) {
666 hdr = (struct ieee802_1x_hdr *) sm->last_rx_key;
668 if (sizeof(*hdr) + be_to_host16(hdr->length) > sm->last_rx_key_len) {
678 eapol_sm_notify_lower_layer_success(sm, 1);
681 res = eapol_sm_get_key(sm, (u8 *) &keydata, sizeof(keydata));
689 res = eapol_sm_get_key(sm, (u8 *) &keydata, 16);
705 if (sm->replay_counter_valid &&
706 os_memcmp(sm->last_replay_counter, key->replay_counter,
711 sm->last_replay_counter,
722 sm->last_rx_key, sizeof(*hdr) + be_to_host16(hdr->length),
770 sm->replay_counter_valid = TRUE;
771 os_memcpy(sm->last_replay_counter, key->replay_counter,
780 if (sm->ctx->set_wep_key &&
781 sm->ctx->set_wep_key(sm->ctx->ctx,
789 sm->unicast_key_received = TRUE;
791 sm->broadcast_key_received = TRUE;
793 if ((sm->unicast_key_received ||
794 !(sm->conf.required_keys & EAPOL_REQUIRE_KEY_UNICAST)) &&
795 (sm->broadcast_key_received ||
796 !(sm->conf.required_keys & EAPOL_REQUIRE_KEY_BROADCAST)))
800 sm->portValid = TRUE;
801 if (sm->ctx->eapol_done_cb)
802 sm->ctx->eapol_done_cb(sm->ctx->ctx);
808 static void eapol_sm_getSuppRsp(struct eapol_sm *sm)
818 static void eapol_sm_txSuppRsp(struct eapol_sm *sm)
823 resp = eap_get_eapRespData(sm->eap);
831 sm->ctx->eapol_send(sm->ctx->eapol_send_ctx,
838 if (sm->initial_req)
839 sm->dot1xSuppEapolReqIdFramesRx++;
841 sm->dot1xSuppEapolReqFramesRx++;
842 sm->dot1xSuppEapolRespFramesTx++;
843 sm->dot1xSuppEapolFramesTx++;
847 static void eapol_sm_abortSupp(struct eapol_sm *sm)
851 os_free(sm->last_rx_key);
852 sm->last_rx_key = NULL;
853 wpabuf_free(sm->eapReqData);
854 sm->eapReqData = NULL;
855 eap_sm_abort(sm->eap);
867 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
873 void eapol_sm_step(struct eapol_sm *sm)
882 sm->changed = FALSE;
886 if (eap_peer_sm_step(sm->eap))
887 sm->changed = TRUE;
888 if (!sm->changed)
892 if (sm->changed) {
895 eloop_cancel_timeout(eapol_sm_step_timeout, NULL, sm);
896 eloop_register_timeout(0, 0, eapol_sm_step_timeout, NULL, sm);
899 if (sm->ctx->cb && sm->cb_status != EAPOL_CB_IN_PROGRESS) {
900 int success = sm->cb_status == EAPOL_CB_SUCCESS ? 1 : 0;
901 sm->cb_status = EAPOL_CB_IN_PROGRESS;
902 sm->ctx->cb(sm, success, sm->ctx->cb_ctx);
985 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
994 void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
997 if (sm == NULL)
1000 sm->heldPeriod = heldPeriod;
1002 sm->authPeriod = authPeriod;
1004 sm->startPeriod = startPeriod;
1006 sm->maxStart = maxStart;
1013 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1024 int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
1028 if (sm == NULL)
1034 eapol_supp_pae_state(sm->SUPP_PAE_state),
1035 eapol_port_status(sm->suppPortStatus));
1047 sm->heldPeriod,
1048 sm->authPeriod,
1049 sm->startPeriod,
1050 sm->maxStart,
1051 eapol_port_control(sm->portControl),
1052 eapol_supp_be_state(sm->SUPP_BE_state));
1058 len += eap_sm_get_status(sm->eap, buf + len, buflen - len, verbose);
1066 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1076 int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen)
1081 if (sm == NULL)
1091 sm->SUPP_PAE_state,
1092 sm->heldPeriod,
1093 sm->authPeriod,
1094 sm->startPeriod,
1095 sm->maxStart,
1096 sm->suppPortStatus == Authorized ?
1098 sm->SUPP_BE_state);
1116 sm->dot1xSuppEapolFramesRx,
1117 sm->dot1xSuppEapolFramesTx,
1118 sm->dot1xSuppEapolStartFramesTx,
1119 sm->dot1xSuppEapolLogoffFramesTx,
1120 sm->dot1xSuppEapolRespFramesTx,
1121 sm->dot1xSuppEapolReqIdFramesRx,
1122 sm->dot1xSuppEapolReqFramesRx,
1123 sm->dot1xSuppInvalidEapolFramesRx,
1124 sm->dot1xSuppEapLengthErrorFramesRx,
1125 sm->dot1xSuppLastEapolFrameVersion,
1126 MAC2STR(sm->dot1xSuppLastEapolFrameSource));
1139 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1146 int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
1155 if (sm == NULL)
1157 sm->dot1xSuppEapolFramesRx++;
1159 sm->dot1xSuppInvalidEapolFramesRx++;
1163 sm->dot1xSuppLastEapolFrameVersion = hdr->version;
1164 os_memcpy(sm->dot1xSuppLastEapolFrameSource, src, ETH_ALEN);
1170 sm->dot1xSuppEapLengthErrorFramesRx++;
1174 if (sm->conf.workaround &&
1202 if (sm->cached_pmk) {
1207 eapol_sm_abort_cached(sm);
1209 sm->eapReqData);
1210 sm->eapReqData = wpabuf_alloc_copy(hdr + 1, plen);
1211 if (sm->eapReqData) {
1214 sm->eapolEap = TRUE;
1215 eapol_sm_step(sm);
1238 os_free(sm->last_rx_key);
1239 sm->last_rx_key = os_malloc(data_len);
1240 if (sm->last_rx_key) {
1243 os_memcpy(sm->last_rx_key, buf, data_len);
1244 sm->last_rx_key_len = data_len;
1245 sm->rxKey = TRUE;
1246 eapol_sm_step(sm);
1252 sm->dot1xSuppInvalidEapolFramesRx++;
1262 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1267 void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
1269 if (sm)
1270 sm->dot1xSuppEapolFramesTx++;
1276 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1281 void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled)
1283 if (sm == NULL)
1287 sm->portEnabled = enabled;
1288 eapol_sm_step(sm);
1294 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1299 void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid)
1301 if (sm == NULL)
1305 sm->portValid = valid;
1306 eapol_sm_step(sm);
1312 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1321 void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success)
1323 if (sm == NULL)
1327 sm->eapSuccess = success;
1328 sm->altAccept = success;
1330 eap_notify_success(sm->eap);
1331 eapol_sm_step(sm);
1337 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1343 void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
1345 if (sm == NULL)
1349 sm->eapFail = fail;
1350 sm->altReject = fail;
1351 eapol_sm_step(sm);
1357 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1367 void eapol_sm_notify_config(struct eapol_sm *sm,
1371 if (sm == NULL)
1374 sm->config = config;
1379 sm->conf.accept_802_1x_keys = conf->accept_802_1x_keys;
1380 sm->conf.required_keys = conf->required_keys;
1381 sm->conf.fast_reauth = conf->fast_reauth;
1382 sm->conf.workaround = conf->workaround;
1383 if (sm->eap) {
1384 eap_set_fast_reauth(sm->eap, conf->fast_reauth);
1385 eap_set_workaround(sm->eap, conf->workaround);
1386 eap_set_force_disabled(sm->eap, conf->eap_disabled);
1393 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1402 int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
1407 if (sm == NULL || !eap_key_available(sm->eap)) {
1411 eap_key = eap_get_eapKeyData(sm->eap, &eap_len);
1431 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1436 void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
1438 if (sm) {
1439 sm->userLogoff = logoff;
1440 eapol_sm_step(sm);
1447 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1452 void eapol_sm_notify_cached(struct eapol_sm *sm)
1454 if (sm == NULL)
1457 sm->SUPP_PAE_state = SUPP_PAE_AUTHENTICATED;
1458 sm->suppPortStatus = Authorized;
1459 sm->portValid = TRUE;
1460 eap_notify_success(sm->eap);
1461 eapol_sm_step(sm);
1467 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1472 void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm, int attempt)
1474 if (sm == NULL)
1478 sm->cached_pmk = TRUE;
1481 sm->cached_pmk = FALSE;
1486 static void eapol_sm_abort_cached(struct eapol_sm *sm)
1490 if (sm == NULL)
1492 sm->cached_pmk = FALSE;
1493 sm->SUPP_PAE_state = SUPP_PAE_CONNECTING;
1494 sm->suppPortStatus = Unauthorized;
1498 sm->startWhen = 3;
1499 eapol_enable_timer_tick(sm);
1501 if (sm->ctx->aborted_cached)
1502 sm->ctx->aborted_cached(sm->ctx->ctx);
1508 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1514 void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx)
1516 if (sm) {
1517 sm->ctx->scard_ctx = ctx;
1518 eap_register_scard_ctx(sm->eap, ctx);
1525 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1530 void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl)
1532 if (sm == NULL)
1536 sm->portControl = portControl;
1537 eapol_sm_step(sm);
1543 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1548 void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
1550 if (sm == NULL)
1552 eap_sm_notify_ctrl_attached(sm->eap);
1558 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1563 void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
1565 if (sm == NULL)
1567 if (sm->eapReqData && !sm->eapReq) {
1571 sm->eapolEap = TRUE;
1572 sm->eapReq = TRUE;
1573 eapol_sm_step(sm);
1580 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1585 void eapol_sm_request_reauth(struct eapol_sm *sm)
1587 if (sm == NULL || sm->SUPP_PAE_state != SUPP_PAE_AUTHENTICATED)
1589 eapol_sm_txStart(sm);
1595 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1603 void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm)
1605 if (sm == NULL)
1607 eap_notify_lower_layer_success(sm->eap);
1609 eapol_sm_step(sm);
1615 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1617 void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
1619 if (sm)
1620 eap_invalidate_cached_session(sm->eap);
1626 struct eapol_sm *sm = ctx;
1627 return sm ? sm->config : NULL;
1633 struct eapol_sm *sm = ctx;
1634 if (sm == NULL || sm->eapReqData == NULL)
1637 return sm->eapReqData;
1643 struct eapol_sm *sm = ctx;
1644 if (sm == NULL)
1648 return sm->eapSuccess;
1650 return sm->eapRestart;
1652 return sm->eapFail;
1654 return sm->eapResp;
1656 return sm->eapNoResp;
1658 return sm->eapReq;
1660 return sm->portEnabled;
1662 return sm->altAccept;
1664 return sm->altReject;
1673 struct eapol_sm *sm = ctx;
1674 if (sm == NULL)
1678 sm->eapSuccess = value;
1681 sm->eapRestart = value;
1684 sm->eapFail = value;
1687 sm->eapResp = value;
1690 sm->eapNoResp = value;
1693 sm->eapReq = value;
1696 sm->portEnabled = value;
1699 sm->altAccept = value;
1702 sm->altReject = value;
1710 struct eapol_sm *sm = ctx;
1711 if (sm == NULL)
1715 return sm->idleWhile;
1724 struct eapol_sm *sm = ctx;
1725 if (sm == NULL)
1729 sm->idleWhile = value;
1730 eapol_enable_timer_tick(sm);
1739 struct eapol_sm *sm = ctx;
1740 if (sm && sm->ctx && sm->ctx->set_config_blob)
1741 sm->ctx->set_config_blob(sm->ctx->ctx, blob);
1750 struct eapol_sm *sm = ctx;
1751 if (sm && sm->ctx && sm->ctx->get_config_blob)
1752 return sm->ctx->get_config_blob(sm->ctx->ctx, name);
1763 struct eapol_sm *sm = ctx;
1764 if (sm == NULL)
1766 if (sm->eapReqData && !sm->eapReq) {
1769 sm->eapolEap = TRUE;
1770 sm->eapReq = TRUE;
1771 eapol_sm_step(sm);
1780 struct eapol_sm *sm = ctx;
1782 if (sm->ctx->eap_param_needed)
1783 sm->ctx->eap_param_needed(sm->ctx->ctx, field, txt);
1815 struct eapol_sm *sm;
1817 sm = os_zalloc(sizeof(*sm));
1818 if (sm == NULL)
1820 sm->ctx = ctx;
1822 sm->portControl = Auto;
1825 sm->heldPeriod = 60;
1826 sm->startPeriod = 30;
1827 sm->maxStart = 3;
1830 sm->authPeriod = 30;
1840 sm->eap = eap_peer_sm_init(sm, &eapol_cb, sm->ctx->msg_ctx, &conf);
1841 if (sm->eap == NULL) {
1842 os_free(sm);
1847 sm->initialize = TRUE;
1848 eapol_sm_step(sm);
1849 sm->initialize = FALSE;
1850 eapol_sm_step(sm);
1852 sm->timer_tick_enabled = 1;
1853 eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);
1855 return sm;
1861 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
1865 void eapol_sm_deinit(struct eapol_sm *sm)
1867 if (sm == NULL)
1869 eloop_cancel_timeout(eapol_sm_step_timeout, NULL, sm);
1870 eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
1871 eap_peer_sm_deinit(sm->eap);
1872 os_free(sm->last_rx_key);
1873 wpabuf_free(sm->eapReqData);
1874 os_free(sm->ctx);
1875 os_free(sm);