supplicant_fsm.c
Go to the documentation of this file.
1 /**
2  * @file supplicant_fsm.c
3  * @brief Supplicant state machine
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SUPPLICANT_TRACE_LEVEL
33 
34 //Dependencies
35 #include "supplicant/supplicant.h"
39 #include "eap/eap_peer_fsm.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (SUPPLICANT_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Supplicant state machine initialization
48  * @param[in] context Pointer to the 802.1X supplicant context
49  **/
50 
52 {
53  //Initialize variables
54  context->authWhile = 0;
55  context->heldWhile = 0;
56  context->startWhen = 0;
57 
58  context->eapFail = FALSE;
59  context->eapolEap = FALSE;
60  context->eapSuccess = FALSE;
61  context->initialize = FALSE;
62  context->keyDone = FALSE;
63  context->keyRun = FALSE;
64  context->portControl = SUPPLICANT_PORT_MODE_AUTO;
65  context->portEnabled = FALSE;
66  context->portValid = TRUE;
67  context->suppAbort = FALSE;
68  context->suppFail = FALSE;
69  context->suppPortStatus = SUPPLICANT_PORT_STATUS_UNAUTH;
70  context->suppStart = FALSE;
71  context->suppSuccess = FALSE;
72  context->suppTimeout = FALSE;
73 
74  context->eapRestart = FALSE;
75  context->logoffSent = FALSE;
76  context->sPortMode = SUPPLICANT_PORT_MODE_FORCE_UNAUTH;
77  context->startCount = 0;
78  context->userLogoff = FALSE;
79 
80  context->heldPeriod = SUPPLICANT_DEFAULT_HELD_PERIOD;
81  context->startPeriod = SUPPLICANT_DEFAULT_START_PERIOD;
82  context->maxStart = SUPPLICANT_DEFAULT_MAX_START;
83 
84  context->eapNoResp = FALSE;
85  context->eapReq = FALSE;
86  context->eapResp = FALSE;
87 
88  context->authPeriod = SUPPLICANT_DEFAULT_AUTH_PERIOD;
89 
90  context->allowNotifications = TRUE;
91  context->eapReqData = context->rxBuffer + sizeof(EapolPdu);
92  context->eapReqDataLen = 0;
93  context->idleWhile = 0;
94  context->altAccept = FALSE;
95  context->altReject = FALSE;
96  context->eapRespData = context->txBuffer + sizeof(EapolPdu);
97  context->eapRespDataLen = 0;
98  context->eapKeyData = NULL;
99  context->eapKeyAvailable = FALSE;
100  context->clientTimeout = EAP_DEFAULT_CLIENT_TIMEOUT;
101 
102  context->selectedMethod = EAP_METHOD_TYPE_NONE;
103  context->methodState = EAP_METHOD_STATE_NONE;
104  context->lastId = 0;
105  context->lastRespData = context->txBuffer + sizeof(EapolPdu);
106  context->lastRespDataLen = 0;
107  context->decision = EAP_DECISION_FAIL;
108 
109  context->rxReq = FALSE;
110  context->rxSuccess = FALSE;
111  context->rxFailure = FALSE;
112  context->reqId = 0;
113  context->reqMethod = EAP_METHOD_TYPE_NONE;
114  context->ignore = FALSE;
115 
116  context->allowCanned = TRUE;
117 
118  //Initialize supplicant PAE state machine
119  supplicantPaeInitFsm(context);
120  //Initialize supplicant backend state machine
121  supplicantBackendInitFsm(context);
122  //Initialize EAP peer state machine
123  eapPeerInitFsm(context);
124 
125  //Update supplicant state machines
126  supplicantFsm(context);
127 }
128 
129 
130 /**
131  * @brief Supplicant state machine implementation
132  * @param[in] context Pointer to the 802.1X supplicant context
133  **/
134 
136 {
137  //The operation of the supplicant can be represented with three simple
138  //state machines
139  do
140  {
141  //Clear the busy flag
142  context->busy = FALSE;
143 
144  //Update the supplicant PAE state machine
145  supplicantPaeFsm(context);
146  //Update the supplicant backend state machine
147  supplicantBackendFsm(context);
148  //Update the EAP peer state machine
149  eapPeerFsm(context);
150 
151  //Transition conditions are evaluated continuously as long as the
152  //supplicant state machine is busy
153  } while(context->busy);
154 }
155 
156 
157 /**
158  * @brief Supplicant state machine error handler
159  * @param[in] context Pointer to the 802.1X supplicant context
160  **/
161 
163 {
164  //Debug message
165  TRACE_ERROR("Supplicant state machine error!\r\n");
166 }
167 
168 #endif
Debugging facilities.
#define TRACE_ERROR(...)
Definition: debug.h:75
#define EAP_DEFAULT_CLIENT_TIMEOUT
Definition: eap.h:105
EapolPdu
Definition: eap.h:211
@ EAP_METHOD_TYPE_NONE
None.
Definition: eap.h:165
@ EAP_METHOD_STATE_NONE
void eapPeerInitFsm(SupplicantContext *context)
EAP peer state machine initialization.
Definition: eap_peer_fsm.c:70
void eapPeerFsm(SupplicantContext *context)
EAP peer state machine implementation.
Definition: eap_peer_fsm.c:82
EAP peer state machine.
@ EAP_DECISION_FAIL
Definition: eap_peer_fsm.h:90
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
802.1X supplicant
#define SUPPLICANT_DEFAULT_AUTH_PERIOD
Definition: supplicant.h:121
#define SupplicantContext
Definition: supplicant.h:36
#define SUPPLICANT_DEFAULT_MAX_START
Definition: supplicant.h:114
#define SUPPLICANT_DEFAULT_HELD_PERIOD
Definition: supplicant.h:100
#define SUPPLICANT_DEFAULT_START_PERIOD
Definition: supplicant.h:107
void supplicantBackendInitFsm(SupplicantContext *context)
Supplicant backend state machine initialization.
void supplicantBackendFsm(SupplicantContext *context)
Supplicant backend state machine implementation.
Supplicant backend state machine.
void supplicantInitFsm(SupplicantContext *context)
Supplicant state machine initialization.
void supplicantFsmError(SupplicantContext *context)
Supplicant state machine error handler.
void supplicantFsm(SupplicantContext *context)
Supplicant state machine implementation.
Supplicant state machine.
void supplicantPaeFsm(SupplicantContext *context)
Supplicant PAE state machine implementation.
void supplicantPaeInitFsm(SupplicantContext *context)
Supplicant PAE state machine initialization.
Supplicant PAE state machine.
@ SUPPLICANT_PORT_STATUS_UNAUTH
@ SUPPLICANT_PORT_MODE_FORCE_UNAUTH
@ SUPPLICANT_PORT_MODE_AUTO