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.4
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->portEnabled = FALSE;
65  context->portValid = TRUE;
66  context->suppAbort = FALSE;
67  context->suppFail = FALSE;
68  context->suppPortStatus = SUPPLICANT_PORT_STATUS_UNAUTH;
69  context->suppStart = FALSE;
70  context->suppSuccess = FALSE;
71  context->suppTimeout = FALSE;
72 
73  context->eapRestart = FALSE;
74  context->logoffSent = FALSE;
75  context->sPortMode = SUPPLICANT_PORT_MODE_FORCE_UNAUTH;
76  context->startCount = 0;
77 
78  context->eapNoResp = FALSE;
79  context->eapReq = FALSE;
80  context->eapResp = FALSE;
81 
82  context->allowNotifications = TRUE;
83  context->eapReqData = context->rxBuffer + sizeof(EapolPdu);
84  context->eapReqDataLen = 0;
85  context->idleWhile = 0;
86  context->altAccept = FALSE;
87  context->altReject = FALSE;
88  context->eapRespData = context->txBuffer + sizeof(EapolPdu);
89  context->eapRespDataLen = 0;
90  context->eapKeyData = NULL;
91  context->eapKeyAvailable = FALSE;
92 
93  context->selectedMethod = EAP_METHOD_TYPE_NONE;
94  context->methodState = EAP_METHOD_STATE_NONE;
95  context->lastId = 0;
96  context->lastRespData = context->txBuffer + sizeof(EapolPdu);
97  context->lastRespDataLen = 0;
98  context->decision = EAP_DECISION_FAIL;
99 
100  context->rxReq = FALSE;
101  context->rxSuccess = FALSE;
102  context->rxFailure = FALSE;
103  context->reqId = 0;
104  context->reqMethod = EAP_METHOD_TYPE_NONE;
105  context->ignore = FALSE;
106 
107  context->allowCanned = TRUE;
108 
109  //Initialize supplicant PAE state machine
110  supplicantPaeInitFsm(context);
111  //Initialize supplicant backend state machine
112  supplicantBackendInitFsm(context);
113  //Initialize EAP peer state machine
114  eapPeerInitFsm(context);
115 
116  //Update supplicant state machines
117  supplicantFsm(context);
118 }
119 
120 
121 /**
122  * @brief Supplicant state machine implementation
123  * @param[in] context Pointer to the 802.1X supplicant context
124  **/
125 
127 {
128  //The operation of the supplicant can be represented with three simple
129  //state machines
130  do
131  {
132  //Clear the busy flag
133  context->busy = FALSE;
134 
135  //Update the supplicant PAE state machine
136  supplicantPaeFsm(context);
137  //Update the supplicant backend state machine
138  supplicantBackendFsm(context);
139  //Update the EAP peer state machine
140  eapPeerFsm(context);
141 
142  //Transition conditions are evaluated continuously as long as the
143  //supplicant state machine is busy
144  } while(context->busy);
145 }
146 
147 
148 /**
149  * @brief Supplicant state machine error handler
150  * @param[in] context Pointer to the 802.1X supplicant context
151  **/
152 
154 {
155  //Debug message
156  TRACE_ERROR("Supplicant state machine error!\r\n");
157 }
158 
159 #endif
@ SUPPLICANT_PORT_STATUS_UNAUTH
Supplicant state machine.
void supplicantFsmError(SupplicantContext *context)
Supplicant state machine error handler.
@ SUPPLICANT_PORT_MODE_FORCE_UNAUTH
@ EAP_METHOD_TYPE_NONE
None.
Definition: eap.h:165
EapolPdu
Definition: eap.h:211
802.1X supplicant
#define TRUE
Definition: os_port.h:50
#define SupplicantContext
Definition: supplicant.h:36
Supplicant backend state machine.
#define TRACE_ERROR(...)
Definition: debug.h:75
void eapPeerFsm(SupplicantContext *context)
EAP peer state machine implementation.
Definition: eap_peer_fsm.c:82
#define FALSE
Definition: os_port.h:46
void supplicantFsm(SupplicantContext *context)
Supplicant state machine implementation.
void supplicantPaeInitFsm(SupplicantContext *context)
Supplicant PAE state machine initialization.
void eapPeerInitFsm(SupplicantContext *context)
EAP peer state machine initialization.
Definition: eap_peer_fsm.c:70
void supplicantInitFsm(SupplicantContext *context)
Supplicant state machine initialization.
void supplicantBackendFsm(SupplicantContext *context)
Supplicant backend state machine implementation.
@ EAP_DECISION_FAIL
Definition: eap_peer_fsm.h:90
void supplicantBackendInitFsm(SupplicantContext *context)
Supplicant backend state machine initialization.
Supplicant PAE state machine.
@ EAP_METHOD_STATE_NONE
void supplicantPaeFsm(SupplicantContext *context)
Supplicant PAE state machine implementation.
Debugging facilities.
EAP peer state machine.