authenticator_mgmt.c
Go to the documentation of this file.
1 /**
2  * @file authenticator_mgmt.c
3  * @brief Management of the 802.1X authenticator
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
38 #include "debug.h"
39 
40 //Check TCP/IP stack configuration
41 #if (AUTHENTICATOR_SUPPORT == ENABLED)
42 
43 
44 /**
45  * @brief Acquire exclusive access to the 802.1X authenticator context
46  * @param[in] context Pointer to the 802.1X authenticator context
47  **/
48 
50 {
51  //Acquire exclusive access
52  osAcquireMutex(&context->mutex);
53 }
54 
55 
56 /**
57  * @brief Release exclusive access to the 802.1X authenticator context
58  * @param[in] context Pointer to the 802.1X authenticator context
59  **/
60 
62 {
63  //Release exclusive access
64  osReleaseMutex(&context->mutex);
65 }
66 
67 
68 /**
69  * @brief Force the value of the initialize variable
70  * @param[in] context Pointer to the 802.1X authenticator context
71  * @param[in] portIndex Port index
72  * @param[in] initialize Value of the initialize variable
73  * @param[in] commit If this flag is TRUE, the authenticator verifies the
74  * parameter value and commits the change if the value is valid. If FALSE,
75  * the authenticator only performs the verification and does not take any
76  * further action
77  * @return Error code
78  **/
79 
81  uint_t portIndex, bool_t initialize, bool_t commit)
82 {
84 
85  //Make sure the 802.1X authenticator context is valid
86  if(context == NULL)
87  return ERROR_WRITE_FAILED;
88 
89  //Invalid port index?
90  if(portIndex < 1 || portIndex > context->numPorts)
91  return ERROR_INVALID_PORT;
92 
93  //Point to the port that matches the specified port index
94  port = &context->ports[portIndex - 1];
95 
96  //Commit phase?
97  if(commit)
98  {
99  //Setting this variable to FALSE has no effect
100  if(initialize)
101  {
102  //Initialize port
104  //Update authenticator state machines
105  authenticatorFsm(context);
106 
107  //The PACP state machines are held in their initial state until
108  //initialize is deasserted (refer to IEEE Std 802.1X-2004, section
109  //8.2.2.2)
110  port->initialize = FALSE;
111 
112  //This variable indicates how the session was terminated
113  port->sessionStats.sessionTerminateCause =
115  }
116  }
117 
118  //Successful processing
119  return NO_ERROR;
120 }
121 
122 
123 /**
124  * @brief Force the value of the reAuthenticate variable
125  * @param[in] context Pointer to the 802.1X authenticator context
126  * @param[in] portIndex Port index
127  * @param[in] reAuthenticate Value of the reAuthenticate variable
128  * @param[in] commit If this flag is TRUE, the authenticator verifies the
129  * parameter value and commits the change if the value is valid. If FALSE,
130  * the authenticator only performs the verification and does not take any
131  * further action
132  * @return Error code
133  **/
134 
136  uint_t portIndex, bool_t reAuthenticate, bool_t commit)
137 {
139 
140  //Make sure the 802.1X authenticator context is valid
141  if(context == NULL)
142  return ERROR_WRITE_FAILED;
143 
144  //Invalid port index?
145  if(portIndex < 1 || portIndex > context->numPorts)
146  return ERROR_INVALID_PORT;
147 
148  //Point to the port that matches the specified port index
149  port = &context->ports[portIndex - 1];
150 
151  //Commit phase?
152  if(commit)
153  {
154  //Setting this variable to FALSE has no effect
155  if(reAuthenticate)
156  {
157  //The reAuthenticate variable may be set TRUE by management action
158  port->reAuthenticate = TRUE;
159  //Update authenticator state machines
160  authenticatorFsm(context);
161  }
162  }
163 
164  //Successful processing
165  return NO_ERROR;
166 }
167 
168 
169 /**
170  * @brief Set the value of the AuthControlledPortControl parameter
171  * @param[in] context Pointer to the 802.1X authenticator context
172  * @param[in] portIndex Port index
173  * @param[in] portControl Value of the AuthControlledPortControl parameter
174  * @param[in] commit If this flag is TRUE, the authenticator verifies the
175  * parameter value and commits the change if the value is valid. If FALSE,
176  * the authenticator only performs the verification and does not take any
177  * further action
178  * @return Error code
179  **/
180 
182  uint_t portIndex, AuthenticatorPortMode portControl, bool_t commit)
183 {
185 
186  //Make sure the 802.1X authenticator context is valid
187  if(context == NULL)
188  return ERROR_WRITE_FAILED;
189 
190  //Invalid port index?
191  if(portIndex < 1 || portIndex > context->numPorts)
192  return ERROR_INVALID_PORT;
193 
194  //Point to the port that matches the specified port index
195  port = &context->ports[portIndex - 1];
196 
197  //Commit phase?
198  if(commit)
199  {
200  //Save the value of the parameter
201  port->portControl = portControl;
202 
203  //Update authenticator state machines
204  authenticatorFsm(context);
205  }
206 
207  //Successful processing
208  return NO_ERROR;
209 }
210 
211 
212 /**
213  * @brief Set the value of the quietPeriod parameter
214  * @param[in] context Pointer to the 802.1X authenticator context
215  * @param[in] portIndex Port index
216  * @param[in] quietPeriod Value of the quietPeriod parameter
217  * @param[in] commit If this flag is TRUE, the authenticator verifies the
218  * parameter value and commits the change if the value is valid. If FALSE,
219  * the authenticator only performs the verification and does not take any
220  * further action
221  * @return Error code
222  **/
223 
225  uint_t portIndex, uint_t quietPeriod, bool_t commit)
226 {
228 
229  //Make sure the 802.1X authenticator context is valid
230  if(context == NULL)
231  return ERROR_WRITE_FAILED;
232 
233  //Invalid port index?
234  if(portIndex < 1 || portIndex > context->numPorts)
235  return ERROR_INVALID_PORT;
236 
237  //The quietPeriod parameter can be set by management to any value in the
238  //range from 0 to 65535 s (refer to IEEE Std 802.1X-2004, section 8.2.4.1.2)
239  if(quietPeriod > AUTHENTICATOR_MAX_QUIET_PERIOD)
240  return ERROR_WRONG_VALUE;
241 
242  //Point to the port that matches the specified port index
243  port = &context->ports[portIndex - 1];
244 
245  //Commit phase?
246  if(commit)
247  {
248  //Save the value of the parameter
249  port->quietPeriod = quietPeriod;
250 
251  //Check whether the quietWhile timer is running
252  if(port->quietWhile > 0)
253  {
254  //Reinitialize quietWhile timer
255  port->quietWhile = port->quietPeriod;
256  }
257 
258  //Update authenticator state machines
259  authenticatorFsm(context);
260  }
261 
262  //Successful processing
263  return NO_ERROR;
264 }
265 
266 
267 /**
268  * @brief Set the value of the serverTimeout parameter
269  * @param[in] context Pointer to the 802.1X authenticator context
270  * @param[in] portIndex Port index
271  * @param[in] serverTimeout Value of the serverTimeout parameter
272  * @param[in] commit If this flag is TRUE, the authenticator verifies the
273  * parameter value and commits the change if the value is valid. If FALSE,
274  * the authenticator only performs the verification and does not take any
275  * further action
276  * @return Error code
277  **/
278 
280  uint_t portIndex, uint_t serverTimeout, bool_t commit)
281 {
283 
284  //Make sure the 802.1X authenticator context is valid
285  if(context == NULL)
286  return ERROR_WRITE_FAILED;
287 
288  //Invalid port index?
289  if(portIndex < 1 || portIndex > context->numPorts)
290  return ERROR_INVALID_PORT;
291 
292  //The serverTimeout parameter can be set by management to any value in the
293  //range from 1 to X s, where X is an implementation dependent value (refer
294  //to IEEE Std 802.1X-2004, section 8.2.9.1.2)
295  if(serverTimeout < AUTHENTICATOR_MIN_SERVER_TIMEOUT ||
296  serverTimeout > AUTHENTICATOR_MAX_SERVER_TIMEOUT)
297  {
298  return ERROR_WRONG_VALUE;
299  }
300 
301  //Point to the port that matches the specified port index
302  port = &context->ports[portIndex - 1];
303 
304  //Commit phase?
305  if(commit)
306  {
307  //Save the value of the parameter
308  port->serverTimeout = serverTimeout;
309 
310  //Check whether the aWhile timer is running
311  if(port->aWhile > 0)
312  {
313  //Reinitialize aWhile timer
314  port->aWhile = port->serverTimeout;
315  }
316 
317  //Update authenticator state machines
318  authenticatorFsm(context);
319  }
320 
321  //Successful processing
322  return NO_ERROR;
323 }
324 
325 
326 /**
327  * @brief Set the value of the reAuthPeriod parameter
328  * @param[in] context Pointer to the 802.1X authenticator context
329  * @param[in] portIndex Port index
330  * @param[in] reAuthPeriod Value of the reAuthPeriod parameter
331  * @param[in] commit If this flag is TRUE, the authenticator verifies the
332  * parameter value and commits the change if the value is valid. If FALSE,
333  * the authenticator only performs the verification and does not take any
334  * further action
335  * @return Error code
336  **/
337 
339  uint_t portIndex, uint_t reAuthPeriod, bool_t commit)
340 {
342 
343  //Make sure the 802.1X authenticator context is valid
344  if(context == NULL)
345  return ERROR_WRITE_FAILED;
346 
347  //Invalid port index?
348  if(portIndex < 1 || portIndex > context->numPorts)
349  return ERROR_INVALID_PORT;
350 
351  //If the value of the reAuthPeriod parameter is outside the specified range,
352  //then no action shall be taken
353  if(reAuthPeriod < AUTHENTICATOR_MIN_REAUTH_PERIOD ||
354  reAuthPeriod > AUTHENTICATOR_MAX_REAUTH_PERIOD)
355  {
356  return ERROR_WRONG_VALUE;
357  }
358 
359  //Point to the port that matches the specified port index
360  port = &context->ports[portIndex - 1];
361 
362  //Commit phase?
363  if(commit)
364  {
365  //Save the value of the parameter
366  port->reAuthPeriod = reAuthPeriod;
367 
368  //Check whether the reAuthWhen timer is running
369  if(port->reAuthWhen > 0)
370  {
371  //Reinitialize reAuthWhen timer
372  port->reAuthWhen = port->reAuthPeriod;
373  }
374 
375  //Update authenticator state machines
376  authenticatorFsm(context);
377  }
378 
379  //Successful processing
380  return NO_ERROR;
381 }
382 
383 
384 /**
385  * @brief Set the value of the reAuthEnabled parameter
386  * @param[in] context Pointer to the 802.1X authenticator context
387  * @param[in] portIndex Port index
388  * @param[in] reAuthEnabled Value of the reAuthEnabled parameter
389  * @param[in] commit If this flag is TRUE, the authenticator verifies the
390  * parameter value and commits the change if the value is valid. If FALSE,
391  * the authenticator only performs the verification and does not take any
392  * further action
393  * @return Error code
394  **/
395 
397  uint_t portIndex, bool_t reAuthEnabled, bool_t commit)
398 {
400 
401  //Make sure the 802.1X authenticator context is valid
402  if(context == NULL)
403  return ERROR_WRITE_FAILED;
404 
405  //Invalid port index?
406  if(portIndex < 1 || portIndex > context->numPorts)
407  return ERROR_INVALID_PORT;
408 
409  //Point to the port that matches the specified port index
410  port = &context->ports[portIndex - 1];
411 
412  //Commit phase?
413  if(commit)
414  {
415  //Save the value of the parameter
416  port->reAuthEnabled = reAuthEnabled;
417 
418  //Update authenticator state machines
419  authenticatorFsm(context);
420  }
421 
422  //Successful processing
423  return NO_ERROR;
424 }
425 
426 
427 /**
428  * @brief Set the value of the KeyTransmissionEnabled parameter
429  * @param[in] context Pointer to the 802.1X authenticator context
430  * @param[in] portIndex Port index
431  * @param[in] keyTxEnabled Value of the KeyTransmissionEnabled parameter
432  * @param[in] commit If this flag is TRUE, the authenticator verifies the
433  * parameter value and commits the change if the value is valid. If FALSE,
434  * the authenticator only performs the verification and does not take any
435  * further action
436  * @return Error code
437  **/
438 
440  uint_t portIndex, bool_t keyTxEnabled, bool_t commit)
441 {
443 
444  //Make sure the 802.1X authenticator context is valid
445  if(context == NULL)
446  return ERROR_WRITE_FAILED;
447 
448  //Invalid port index?
449  if(portIndex < 1 || portIndex > context->numPorts)
450  return ERROR_INVALID_PORT;
451 
452  //Point to the port that matches the specified port index
453  port = &context->ports[portIndex - 1];
454 
455  //Commit phase?
456  if(commit)
457  {
458  //Save the value of the parameter
459  port->keyTxEnabled = keyTxEnabled;
460 
461  //Update authenticator state machines
462  authenticatorFsm(context);
463  }
464 
465  //Successful processing
466  return NO_ERROR;
467 }
468 
469 #endif
802.1X authenticator
#define AUTHENTICATOR_MAX_QUIET_PERIOD
#define AUTHENTICATOR_MAX_SERVER_TIMEOUT
#define AuthenticatorPort
Definition: authenticator.h:40
@ AUTHENTICATOR_TERMINATE_CAUSE_PORT_REINIT
#define AUTHENTICATOR_MIN_REAUTH_PERIOD
#define AuthenticatorContext
Definition: authenticator.h:36
#define AUTHENTICATOR_MIN_SERVER_TIMEOUT
#define AUTHENTICATOR_MAX_REAUTH_PERIOD
void authenticatorInitPortFsm(AuthenticatorPort *port)
Initialize authenticator state machine for a given port.
void authenticatorFsm(AuthenticatorContext *context)
Authenticator state machine implementation.
Authenticator state machine.
void authenticatorMgmtLock(AuthenticatorContext *context)
Acquire exclusive access to the 802.1X authenticator context.
error_t authenticatorMgmtSetQuietPeriod(AuthenticatorContext *context, uint_t portIndex, uint_t quietPeriod, bool_t commit)
Set the value of the quietPeriod parameter.
void authenticatorMgmtUnlock(AuthenticatorContext *context)
Release exclusive access to the 802.1X authenticator context.
error_t authenticatorMgmtSetReauthenticate(AuthenticatorContext *context, uint_t portIndex, bool_t reAuthenticate, bool_t commit)
Force the value of the reAuthenticate variable.
error_t authenticatorMgmtSetServerTimeout(AuthenticatorContext *context, uint_t portIndex, uint_t serverTimeout, bool_t commit)
Set the value of the serverTimeout parameter.
error_t authenticatorMgmtSetPortControl(AuthenticatorContext *context, uint_t portIndex, AuthenticatorPortMode portControl, bool_t commit)
Set the value of the AuthControlledPortControl parameter.
error_t authenticatorMgmtSetInitialize(AuthenticatorContext *context, uint_t portIndex, bool_t initialize, bool_t commit)
Force the value of the initialize variable.
error_t authenticatorMgmtSetReAuthEnabled(AuthenticatorContext *context, uint_t portIndex, bool_t reAuthEnabled, bool_t commit)
Set the value of the reAuthEnabled parameter.
error_t authenticatorMgmtSetReAuthPeriod(AuthenticatorContext *context, uint_t portIndex, uint_t reAuthPeriod, bool_t commit)
Set the value of the reAuthPeriod parameter.
error_t authenticatorMgmtSetKeyTxEnabled(AuthenticatorContext *context, uint_t portIndex, bool_t keyTxEnabled, bool_t commit)
Set the value of the KeyTransmissionEnabled parameter.
Management of the 802.1X authenticator.
AuthenticatorPortMode
Port modes.
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
Debugging facilities.
uint16_t port
Definition: dns_common.h:267
error_t
Error codes.
Definition: error.h:43
@ ERROR_INVALID_PORT
Definition: error.h:104
@ ERROR_WRITE_FAILED
Definition: error.h:221
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ NO_ERROR
Success.
Definition: error.h:44
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.