authenticator_fsm.c
Go to the documentation of this file.
1 /**
2  * @file authenticator_fsm.c
3  * @brief Authenticator 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 CycloneEAP 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.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL AUTHENTICATOR_TRACE_LEVEL
33 
34 //Dependencies
41 #include "eap/eap_full_auth_fsm.h"
42 #include "debug.h"
43 
44 //Check TCP/IP stack configuration
45 #if (AUTHENTICATOR_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Authenticator state machine initialization
50  * @param[in] context Pointer to the 802.1X authenticator context
51  **/
52 
54 {
55  uint_t i;
56 
57  //The state machines are defined on a per-port basis (refer to IEEE Std
58  //802.1X-2004, section 8.2)
59  for(i = 0; i < context->numPorts; i++)
60  {
61  //Initialize current port
62  authenticatorInitPortFsm(&context->ports[i]);
63  }
64 
65  //Update authenticator state machines
66  authenticatorFsm(context);
67 
68  //The PACP state machines are held in their initial state until initialize
69  //is deasserted (refer to IEEE Std 802.1X-2004, section 8.2.2.2)
70  for(i = 0; i < context->numPorts; i++)
71  {
72  context->ports[i].initialize = FALSE;
73  }
74 }
75 
76 
77 /**
78  * @brief Initialize authenticator state machine for a given port
79  * @param[in] port Pointer to the port context
80  **/
81 
83 {
84  AuthenticatorContext *context;
85 
86  //Point to the 802.1X authenticator context
87  context = port->context;
88 
89  //Initialize variables
90  port->aWhile = 0;
91  port->quietWhile = 0;
92  port->reAuthWhen = 0;
93 
94  port->authAbort = FALSE;
95  port->authFail = FALSE;
96  port->authPortStatus = AUTHENTICATOR_PORT_STATUS_UNKNOWN;
97  port->authStart = FALSE;
98  port->authTimeout = FALSE;
99  port->authSuccess = FALSE;
100  port->eapFail = FALSE;
101  port->eapolEap = FALSE;
102  port->eapSuccess = FALSE;
103  port->eapTimeout = FALSE;
104 
105  port->initialize = TRUE;
106  port->keyDone = FALSE;
107  port->keyRun = FALSE;
108  port->portValid = TRUE;
109  port->reAuthenticate = FALSE;
110 
111  port->eapolLogoff = FALSE;
112  port->eapolStart = FALSE;
113  port->eapRestart = FALSE;
115  port->reAuthCount = 0;
116 
117  port->eapNoReq = FALSE;
118  port->eapReq = FALSE;
119  port->eapResp = FALSE;
120 
121  port->eapRespData = context->rxBuffer + sizeof(EapolPdu);
122  port->eapRespDataLen = 0;
123  port->retransWhile = 0;
124 
125  port->eapReqData = port->eapTxBuffer + sizeof(EapolPdu);
126  port->eapReqDataLen = 0;
127  port->eapKeyData = NULL;
128  port->eapKeyAvailable = 0;
129 
130  port->currentMethod = EAP_METHOD_TYPE_NONE;
131  port->currentId = EAP_CURRENT_ID_NONE;
132  port->methodState = EAP_METHOD_STATE_NONE;
133  port->retransCount = 0;
134  port->methodTimeout = 0;
135 
136  port->rxResp = FALSE;
137  port->respId = EAP_CURRENT_ID_NONE;
138  port->respMethod = EAP_METHOD_TYPE_NONE;
139  port->ignore = FALSE;
140  port->decision = EAP_DECISION_FAILURE;
141 
142  port->aaaEapReq = FALSE;
143  port->aaaEapNoReq = FALSE;
144  port->aaaSuccess = FALSE;
145  port->aaaFail = FALSE;
146  port->aaaEapReqData = port->eapTxBuffer + sizeof(EapolPdu);
147  port->aaaEapReqDataLen = 0;
148  port->aaaEapKeyData = NULL;
149  port->aaaEapKeyAvailable = FALSE;
150  port->aaaMethodTimeout = AUTHENTICATOR_DEFAULT_METHOD_TIMEOUT;
151 
152  port->aaaEapResp = FALSE;
153  port->aaaEapRespData = NULL;
154  port->aaaEapRespDataLen = 0;
155  port->aaaIdentity[0] = '\0';
156  port->aaaTimeout = FALSE;
157 
158  port->aaaReqId = 0;
159  port->aaaReqData = port->aaaTxBuffer;
160  port->aaaReqDataLen = 0;
161  port->aaaRetransTimer = 0;
162  port->aaaRetransCount = 0;
163 
164  //Initialize authenticator PAE state machine
166  //Initialize backend authentication state machine
168  //Initialize reauthentication timer state machine
170  //Initialize EAP full authenticator state machine
172 }
173 
174 
175 /**
176  * @brief Authenticator state machine implementation
177  * @param[in] context Pointer to the 802.1X authenticator context
178  **/
179 
181 {
182  uint_t i;
184 
185  //The behavior of the 802.1X authenticator is specified by a number of
186  //cooperating state machines
187  do
188  {
189  //Clear the busy flag
190  context->busy = FALSE;
191 
192  //The state machines are defined on a per-port basis (refer to IEEE Std
193  //802.1X-2004, section 8.2)
194  for(i = 0; i < context->numPorts; i++)
195  {
196  //Point to the current port
197  port = &context->ports[i];
198 
199  //Update the authenticator PAE state machine
201  //Update the backend authentication state machine
203  //Update the reauthentication timer state machine
205  //Update the EAP full authenticator state machine
207 
208  //Check the state of the EAP full authenticator state machine
209  if(port->eapFullAuthState == EAP_FULL_AUTH_STATE_AAA_IDLE)
210  {
211  //Any EAP response available for processing by the AAA server?
212  if(port->aaaEapResp)
213  {
214  //Forward the EAP response to the AAA server
217 
218  //Clear flags
219  port->aaaEapResp = FALSE;
220  port->aaaTimeout = FALSE;
221  }
222  else if(port->aaaRetransTimer == 0)
223  {
224  //Check retransmission counter
225  if(port->aaaRetransCount < AUTHENTICATOR_MAX_RADIUS_RETRANS)
226  {
227  //Retransmit RADIUS Access-Request packet
229  }
230  else
231  {
232  //Set the aaaTimeout flag if, after a configurable amount of
233  //time, there is no response from the AAA layer
234  port->aaaTimeout = TRUE;
235  context->busy = TRUE;
236  }
237  }
238  else
239  {
240  //Just for sanity
241  }
242  }
243  }
244 
245  //Transition conditions are evaluated continuously as long as the
246  //authenticator state machine is busy
247  } while(context->busy);
248 }
249 
250 
251 /**
252  * @brief Authenticator state machine error handler
253  * @param[in] context Pointer to the 802.1X authenticator context
254  **/
255 
257 {
258  //Debug message
259  TRACE_ERROR("Authenticator state machine error!\r\n");
260 }
261 
262 #endif
@ EAP_METHOD_TYPE_NONE
None.
Definition: eap.h:165
error_t authenticatorSendRadiusRequest(AuthenticatorPort *port)
Send RADIUS Access-Request packet.
EapolPdu
Definition: eap.h:211
#define TRUE
Definition: os_port.h:50
void eapFullAuthInitFsm(AuthenticatorPort *port)
EAP full authenticator state machine initialization.
void authenticatorInitFsm(AuthenticatorContext *context)
Authenticator state machine initialization.
void eapFullAuthFsm(AuthenticatorPort *port)
EAP full authenticator state machine implementation.
void authenticatorReauthTimerInitFsm(AuthenticatorPort *port)
Authenticator PAE state machine initialization.
void authenticatorBackendFsm(AuthenticatorPort *port)
Backend authentication state machine implementation.
#define AUTHENTICATOR_DEFAULT_METHOD_TIMEOUT
#define TRACE_ERROR(...)
Definition: debug.h:75
Helper functions for 802.1X authenticator.
#define FALSE
Definition: os_port.h:46
802.1X authenticator
Backend authentication state machine.
void authenticatorReauthTimerFsm(AuthenticatorPort *port)
Authenticator PAE state machine implementation.
Authenticator PAE state machine.
void authenticatorPaeInitFsm(AuthenticatorPort *port)
Authenticator PAE state machine initialization.
error_t authenticatorBuildRadiusRequest(AuthenticatorPort *port)
Build RADIUS Access-Request packet.
void authenticatorFsmError(AuthenticatorContext *context)
Authenticator state machine error handler.
@ AUTHENTICATOR_PORT_MODE_FORCE_UNAUTH
#define AUTHENTICATOR_MAX_RADIUS_RETRANS
Authenticator state machine.
void authenticatorPaeFsm(AuthenticatorPort *port)
Authenticator PAE state machine implementation.
uint16_t port
Definition: dns_common.h:267
Reauthentication timer state machine.
#define AuthenticatorContext
Definition: authenticator.h:36
@ EAP_FULL_AUTH_STATE_AAA_IDLE
EAP full authenticator state machine.
void authenticatorFsm(AuthenticatorContext *context)
Authenticator state machine implementation.
#define EAP_CURRENT_ID_NONE
void authenticatorBackendInitFsm(AuthenticatorPort *port)
Backend authentication state machine initialization.
void authenticatorInitPortFsm(AuthenticatorPort *port)
Initialize authenticator state machine for a given port.
@ EAP_METHOD_STATE_NONE
unsigned int uint_t
Definition: compiler_port.h:50
#define AuthenticatorPort
Definition: authenticator.h:40
@ EAP_DECISION_FAILURE
Debugging facilities.
@ AUTHENTICATOR_PORT_STATUS_UNKNOWN