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.4
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  //Update authenticator state machines
203  authenticatorFsm(context);
204  }
205 
206  //Successful processing
207  return NO_ERROR;
208 }
209 
210 
211 /**
212  * @brief Set the value of the quietPeriod parameter
213  * @param[in] context Pointer to the 802.1X authenticator context
214  * @param[in] portIndex Port index
215  * @param[in] quietPeriod Value of the quietPeriod parameter
216  * @param[in] commit If this flag is TRUE, the authenticator verifies the
217  * parameter value and commits the change if the value is valid. If FALSE,
218  * the authenticator only performs the verification and does not take any
219  * further action
220  * @return Error code
221  **/
222 
224  uint_t portIndex, uint_t quietPeriod, bool_t commit)
225 {
227 
228  //Make sure the 802.1X authenticator context is valid
229  if(context == NULL)
230  return ERROR_WRITE_FAILED;
231 
232  //Invalid port index?
233  if(portIndex < 1 || portIndex > context->numPorts)
234  return ERROR_INVALID_PORT;
235 
236  //The quietPeriod parameter can be set by management to any value in the
237  //range from 0 to 65535 s (refer to IEEE Std 802.1X-2004, section 8.2.4.1.2)
238  if(quietPeriod > AUTHENTICATOR_MAX_QUIET_PERIOD)
239  return ERROR_WRONG_VALUE;
240 
241  //Point to the port that matches the specified port index
242  port = &context->ports[portIndex - 1];
243 
244  //Commit phase?
245  if(commit)
246  {
247  //Save the value of the parameter
248  port->quietPeriod = quietPeriod;
249 
250  //Check whether the quietWhile timer is running
251  if(port->quietWhile > 0)
252  {
253  //Reinitialize quietWhile timer
254  port->quietWhile = port->quietPeriod;
255  }
256 
257  //Update authenticator state machines
258  authenticatorFsm(context);
259  }
260 
261  //Successful processing
262  return NO_ERROR;
263 }
264 
265 
266 /**
267  * @brief Set the value of the serverTimeout parameter
268  * @param[in] context Pointer to the 802.1X authenticator context
269  * @param[in] portIndex Port index
270  * @param[in] serverTimeout Value of the serverTimeout parameter
271  * @param[in] commit If this flag is TRUE, the authenticator verifies the
272  * parameter value and commits the change if the value is valid. If FALSE,
273  * the authenticator only performs the verification and does not take any
274  * further action
275  * @return Error code
276  **/
277 
279  uint_t portIndex, uint_t serverTimeout, bool_t commit)
280 {
282 
283  //Make sure the 802.1X authenticator context is valid
284  if(context == NULL)
285  return ERROR_WRITE_FAILED;
286 
287  //Invalid port index?
288  if(portIndex < 1 || portIndex > context->numPorts)
289  return ERROR_INVALID_PORT;
290 
291  //The serverTimeout parameter can be set by management to any value in the
292  //range from 1 to X s, where X is an implementation dependent value (refer
293  //to IEEE Std 802.1X-2004, section 8.2.9.1.2)
294  if(serverTimeout < AUTHENTICATOR_MIN_SERVER_TIMEOUT ||
295  serverTimeout > AUTHENTICATOR_MAX_SERVER_TIMEOUT)
296  {
297  return ERROR_WRONG_VALUE;
298  }
299 
300  //Point to the port that matches the specified port index
301  port = &context->ports[portIndex - 1];
302 
303  //Commit phase?
304  if(commit)
305  {
306  //Save the value of the parameter
307  port->serverTimeout = serverTimeout;
308 
309  //Check whether the aWhile timer is running
310  if(port->aWhile > 0)
311  {
312  //Reinitialize aWhile timer
313  port->aWhile = port->serverTimeout;
314  }
315 
316  //Update authenticator state machines
317  authenticatorFsm(context);
318  }
319 
320  //Successful processing
321  return NO_ERROR;
322 }
323 
324 
325 /**
326  * @brief Set the value of the reAuthPeriod parameter
327  * @param[in] context Pointer to the 802.1X authenticator context
328  * @param[in] portIndex Port index
329  * @param[in] reAuthPeriod Value of the reAuthPeriod parameter
330  * @param[in] commit If this flag is TRUE, the authenticator verifies the
331  * parameter value and commits the change if the value is valid. If FALSE,
332  * the authenticator only performs the verification and does not take any
333  * further action
334  * @return Error code
335  **/
336 
338  uint_t portIndex, uint_t reAuthPeriod, bool_t commit)
339 {
341 
342  //Make sure the 802.1X authenticator context is valid
343  if(context == NULL)
344  return ERROR_WRITE_FAILED;
345 
346  //Invalid port index?
347  if(portIndex < 1 || portIndex > context->numPorts)
348  return ERROR_INVALID_PORT;
349 
350  //If the value of the reAuthPeriod parameter is outside the specified range,
351  //then no action shall be taken
352  if(reAuthPeriod < AUTHENTICATOR_MIN_REAUTH_PERIOD ||
353  reAuthPeriod > AUTHENTICATOR_MAX_REAUTH_PERIOD)
354  {
355  return ERROR_WRONG_VALUE;
356  }
357 
358  //Point to the port that matches the specified port index
359  port = &context->ports[portIndex - 1];
360 
361  //Commit phase?
362  if(commit)
363  {
364  //Save the value of the parameter
365  port->reAuthPeriod = reAuthPeriod;
366 
367  //Check whether the reAuthWhen timer is running
368  if(port->reAuthWhen > 0)
369  {
370  //Reinitialize reAuthWhen timer
371  port->reAuthWhen = port->reAuthPeriod;
372  }
373 
374  //Update authenticator state machines
375  authenticatorFsm(context);
376  }
377 
378  //Successful processing
379  return NO_ERROR;
380 }
381 
382 
383 /**
384  * @brief Set the value of the reAuthEnabled parameter
385  * @param[in] context Pointer to the 802.1X authenticator context
386  * @param[in] portIndex Port index
387  * @param[in] reAuthEnabled Value of the reAuthEnabled parameter
388  * @param[in] commit If this flag is TRUE, the authenticator verifies the
389  * parameter value and commits the change if the value is valid. If FALSE,
390  * the authenticator only performs the verification and does not take any
391  * further action
392  * @return Error code
393  **/
394 
396  uint_t portIndex, bool_t reAuthEnabled, bool_t commit)
397 {
399 
400  //Make sure the 802.1X authenticator context is valid
401  if(context == NULL)
402  return ERROR_WRITE_FAILED;
403 
404  //Invalid port index?
405  if(portIndex < 1 || portIndex > context->numPorts)
406  return ERROR_INVALID_PORT;
407 
408  //Point to the port that matches the specified port index
409  port = &context->ports[portIndex - 1];
410 
411  //Commit phase?
412  if(commit)
413  {
414  //Save the value of the parameter
415  port->reAuthEnabled = reAuthEnabled;
416  //Update authenticator state machines
417  authenticatorFsm(context);
418  }
419 
420  //Successful processing
421  return NO_ERROR;
422 }
423 
424 
425 /**
426  * @brief Set the value of the KeyTransmissionEnabled parameter
427  * @param[in] context Pointer to the 802.1X authenticator context
428  * @param[in] portIndex Port index
429  * @param[in] keyTxEnabled Value of the KeyTransmissionEnabled parameter
430  * @param[in] commit If this flag is TRUE, the authenticator verifies the
431  * parameter value and commits the change if the value is valid. If FALSE,
432  * the authenticator only performs the verification and does not take any
433  * further action
434  * @return Error code
435  **/
436 
438  uint_t portIndex, bool_t keyTxEnabled, bool_t commit)
439 {
441 
442  //Make sure the 802.1X authenticator context is valid
443  if(context == NULL)
444  return ERROR_WRITE_FAILED;
445 
446  //Invalid port index?
447  if(portIndex < 1 || portIndex > context->numPorts)
448  return ERROR_INVALID_PORT;
449 
450  //Point to the port that matches the specified port index
451  port = &context->ports[portIndex - 1];
452 
453  //Commit phase?
454  if(commit)
455  {
456  //Save the value of the parameter
457  port->keyTxEnabled = keyTxEnabled;
458  //Update authenticator state machines
459  authenticatorFsm(context);
460  }
461 
462  //Successful processing
463  return NO_ERROR;
464 }
465 
466 #endif
#define AUTHENTICATOR_MIN_REAUTH_PERIOD
int bool_t
Definition: compiler_port.h:53
error_t authenticatorMgmtSetQuietPeriod(AuthenticatorContext *context, uint_t portIndex, uint_t quietPeriod, bool_t commit)
Set the value of the quietPeriod parameter.
#define TRUE
Definition: os_port.h:50
error_t authenticatorMgmtSetServerTimeout(AuthenticatorContext *context, uint_t portIndex, uint_t serverTimeout, bool_t commit)
Set the value of the serverTimeout parameter.
@ ERROR_INVALID_PORT
Definition: error.h:104
@ AUTHENTICATOR_TERMINATE_CAUSE_PORT_REINIT
error_t authenticatorMgmtSetInitialize(AuthenticatorContext *context, uint_t portIndex, bool_t initialize, bool_t commit)
Force the value of the initialize variable.
error_t authenticatorMgmtSetPortControl(AuthenticatorContext *context, uint_t portIndex, AuthenticatorPortMode portControl, bool_t commit)
Set the value of the AuthControlledPortControl parameter.
#define FALSE
Definition: os_port.h:46
802.1X authenticator
error_t authenticatorMgmtSetKeyTxEnabled(AuthenticatorContext *context, uint_t portIndex, bool_t keyTxEnabled, bool_t commit)
Set the value of the KeyTransmissionEnabled parameter.
error_t
Error codes.
Definition: error.h:43
error_t authenticatorMgmtSetReAuthPeriod(AuthenticatorContext *context, uint_t portIndex, uint_t reAuthPeriod, bool_t commit)
Set the value of the reAuthPeriod parameter.
error_t authenticatorMgmtSetReauthenticate(AuthenticatorContext *context, uint_t portIndex, bool_t reAuthenticate, bool_t commit)
Force the value of the reAuthenticate variable.
void authenticatorMgmtUnlock(AuthenticatorContext *context)
Release exclusive access to the 802.1X authenticator context.
Authenticator state machine.
Management of the 802.1X authenticator.
uint16_t port
Definition: dns_common.h:267
#define AUTHENTICATOR_MAX_QUIET_PERIOD
AuthenticatorPortMode
Port modes.
#define AuthenticatorContext
Definition: authenticator.h:36
error_t authenticatorMgmtSetReAuthEnabled(AuthenticatorContext *context, uint_t portIndex, bool_t reAuthEnabled, bool_t commit)
Set the value of the reAuthEnabled parameter.
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ ERROR_WRITE_FAILED
Definition: error.h:222
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void authenticatorFsm(AuthenticatorContext *context)
Authenticator state machine implementation.
void authenticatorInitPortFsm(AuthenticatorPort *port)
Initialize authenticator state machine for a given port.
void authenticatorMgmtLock(AuthenticatorContext *context)
Acquire exclusive access to the 802.1X authenticator context.
#define AUTHENTICATOR_MIN_SERVER_TIMEOUT
unsigned int uint_t
Definition: compiler_port.h:50
#define AuthenticatorPort
Definition: authenticator.h:40
#define AUTHENTICATOR_MAX_SERVER_TIMEOUT
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define AUTHENTICATOR_MAX_REAUTH_PERIOD