authenticator_reauth_timer_fsm.c
Go to the documentation of this file.
1 /**
2  * @file authenticator_reauth_timer_fsm.c
3  * @brief Reauthentication timer 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.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL AUTHENTICATOR_TRACE_LEVEL
33 
34 //Dependencies
40 #include "eap/eap_debug.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (AUTHENTICATOR_SUPPORT == ENABLED)
45 
46 //Authenticator PAE states
48 {
51 };
52 
53 
54 /**
55  * @brief Authenticator PAE state machine initialization
56  * @param[in] port Pointer to the port context
57  **/
58 
60 {
61  //Enter initial state
63 }
64 
65 
66 /**
67  * @brief Authenticator PAE state machine implementation
68  * @param[in] port Pointer to the port context
69  **/
70 
72 {
73  //A global transition can occur from any of the possible states. When the
74  //condition associated with a global transition is met, it supersedes all
75  //other exit conditions
76  if(port->portControl != AUTHENTICATOR_PORT_MODE_AUTO || port->initialize ||
77  port->authPortStatus == AUTHENTICATOR_PORT_STATUS_UNAUTH ||
78  !port->reAuthEnabled)
79  {
80  //Switch to the INITIALIZE state
83  }
84  else
85  {
86  //All exit conditions for the state are evaluated continuously until one
87  //of the conditions is met (refer to IEEE Std 802.1X-2004, section 8.2.1)
88  switch(port->reauthTimerState)
89  {
90  //INITIALIZE state?
92  //When the reAuthWhen timer expires, the state machine will then
93  //transition to the REAUTHENTICATE state
94  if(port->reAuthWhen == 0)
95  {
96  //Switch to the REAUTHENTICATE state
99  }
100 
101  break;
102 
103  //REAUTHENTICATE state?
105  //Unconditional transition (UCT) to INITIALIZE state
108 
109  break;
110 
111  //Invalid state?
112  default:
113  //Just for sanity
114  authenticatorFsmError(port->context);
115  break;
116  }
117  }
118 }
119 
120 
121 /**
122  * @brief Update authenticator PAE state
123  * @param[in] port Pointer to the port context
124  * @param[in] newState New state to switch to
125  **/
126 
129 {
131 
132  //Retrieve current state
133  oldState = port->reauthTimerState;
134 
135  //Any state change?
136  if(newState != oldState)
137  {
138  //Dump the state transition
139  TRACE_DEBUG("Port %" PRIu8 ": Reauthentication timer state machine %s -> %s\r\n",
140  port->portIndex,
145  }
146 
147  //Switch to the new state
148  port->reauthTimerState = newState;
149 
150  //On entry to a state, the procedures defined for the state are executed
151  //exactly once (refer to IEEE Std 802.1X-2004, section 8.2.1)
152  switch(newState)
153  {
154  //INITIALIZE state?
156  //The reAuthWhen timer is set to its initial value
157  port->reAuthWhen = port->reAuthPeriod;
158  break;
159 
160  //REAUTHENTICATE state?
162  //The reAuthenticate variable is set TRUE by the reauthentication timer
163  //state machine on expiry of the reAuthWhen timer
164  port->reAuthenticate = TRUE;
165  break;
166 
167  //Invalid state?
168  default:
169  //Just for sanity
170  break;
171  }
172 
173  //Any state change?
174  if(newState != oldState)
175  {
176  //Any registered callback?
177  if(port->context->reauthTimerStateChangeCallback != NULL)
178  {
179  //Invoke user callback function
180  port->context->reauthTimerStateChangeCallback(port, newState);
181  }
182  }
183 
184  //Check whether the port is enabled
185  if(port->portControl == AUTHENTICATOR_PORT_MODE_AUTO &&
186  port->authPortStatus != AUTHENTICATOR_PORT_STATUS_UNAUTH &&
187  !port->initialize && port->reAuthEnabled)
188  {
189  //The authenticator PAE state machine is busy
190  port->context->busy = TRUE;
191  }
192 }
193 
194 #endif
802.1X authenticator
#define AuthenticatorPort
Definition: authenticator.h:40
void authenticatorFsmError(AuthenticatorContext *context)
Authenticator state machine error handler.
Authenticator state machine.
Helper functions for 802.1X authenticator.
@ AUTHENTICATOR_PORT_STATUS_UNAUTH
@ AUTHENTICATOR_PORT_MODE_AUTO
Authenticator state machine procedures.
const EapParamName authenticatorReauthTimerStates[]
void authenticatorReauthTimerInitFsm(AuthenticatorPort *port)
Authenticator PAE state machine initialization.
void authenticatorReauthTimerChangeState(AuthenticatorPort *port, AuthenticatorReauthTimerState newState)
Update authenticator PAE state.
void authenticatorReauthTimerFsm(AuthenticatorPort *port)
Authenticator PAE state machine implementation.
Reauthentication timer state machine.
AuthenticatorReauthTimerState
Reauthentication timer states.
@ AUTHENTICATOR_REAUTH_TIMER_STATE_INITIALIZE
@ AUTHENTICATOR_REAUTH_TIMER_STATE_REAUTHENTICATE
Debugging facilities.
#define TRACE_DEBUG(...)
Definition: debug.h:107
uint16_t port
Definition: dns_common.h:267
const char_t * eapGetParamName(uint_t value, const EapParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: eap_debug.c:219
Data logging functions for debugging purpose (EAP)
#define arraysize(a)
Definition: os_port.h:71
#define TRUE
Definition: os_port.h:50
Parameter value/name binding.
Definition: eap_debug.h:50