ieee8021_pae_mib_impl_auth.c
Go to the documentation of this file.
1 /**
2  * @file ieee8021_pae_mib_impl.c (dot1xPaeAuthenticator subtree)
3  * @brief Port Access Control MIB module implementation
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 SNMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mibs/mib_common.h"
39 #include "core/crypto.h"
40 #include "encoding/asn1.h"
41 #include "encoding/oid.h"
43 #include "debug.h"
44 
45 //Check TCP/IP stack configuration
46 #if (IEEE8021_PAE_MIB_SUPPORT == ENABLED && AUTHENTICATOR_SUPPORT == ENABLED)
47 
48 
49 /**
50  * @brief Set dot1xAuthConfigEntry object value
51  * @param[in] object Pointer to the MIB object descriptor
52  * @param[in] oid Object identifier (object name and instance identifier)
53  * @param[in] oidLen Length of the OID, in bytes
54  * @param[in] value Object value
55  * @param[in] valueLen Length of the object value, in bytes
56  * @param[in] commit This flag tells whether the changes shall be committed
57  * to the MIB base
58  * @return Error code
59  **/
60 
62  size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
63 {
64  error_t error;
65  size_t n;
66  uint_t dot1xPaePortNumber;
67 
68  //Point to the instance identifier
69  n = object->oidLen;
70 
71  //dot1xPaePortNumber is used as instance identifier
72  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
73  //Invalid instance identifier?
74  if(error)
75  return error;
76 
77  //Sanity check
78  if(n != oidLen)
80 
81  //dot1xAuthAdminControlledDirections object?
82  if(!strcmp(object->name, "dot1xAuthAdminControlledDirections"))
83  {
84  //This object specifies the value of the administrative controlled
85  //directions parameter for the port
88  {
89  //Not implemented
90  error = NO_ERROR;
91  }
92  else
93  {
94  //Report an error
95  error = ERROR_WRONG_VALUE;
96  }
97  }
98  //dot1xAuthAuthControlledPortControl object?
99  else if(!strcmp(object->name, "dot1xAuthAuthControlledPortControl"))
100  {
101  //This object specifies the value of the controlled port control
102  //parameter for the port
104  {
105  //The controlled port is required to be held in the Unauthorized state
107  dot1xPaePortNumber, AUTHENTICATOR_PORT_MODE_FORCE_UNAUTH, commit);
108  }
110  {
111  //The controlled port is required to be held in the Authorized state
113  dot1xPaePortNumber, AUTHENTICATOR_PORT_MODE_FORCE_AUTH, commit);
114  }
115  else if(value->integer == IEEE8021_PAE_MIB_PORT_CONTROL_AUTO)
116  {
117  //The controlled port is set to the Authorized or Unauthorized state
118  //in accordance with the outcome of an authentication exchange between
119  //the supplicant and the authentication server
121  dot1xPaePortNumber, AUTHENTICATOR_PORT_MODE_AUTO, commit);
122  }
123  else
124  {
125  //Report an error
126  error = ERROR_WRONG_VALUE;
127  }
128  }
129  //dot1xAuthQuietPeriod object?
130  else if(!strcmp(object->name, "dot1xAuthQuietPeriod"))
131  {
132  //This object specifies the value, in seconds, of the quietPeriod constant
133  //currently in use by the authenticator PAE state machine
135  dot1xPaePortNumber, value->unsigned32, commit);
136  }
137  //dot1xAuthServerTimeout object?
138  else if(!strcmp(object->name, "dot1xAuthServerTimeout"))
139  {
140  //This object specifies The value, in seconds, of the serverTimeout
141  //constant currently in use by the backend authentication state machine
143  dot1xPaePortNumber, value->unsigned32, commit);
144  }
145  //dot1xAuthReAuthPeriod object?
146  else if(!strcmp(object->name, "dot1xAuthReAuthPeriod"))
147  {
148  //This object specifies the value, in seconds, of the reAuthPeriod
149  //constant currently in use by the reauthentication timer state machine
151  dot1xPaePortNumber, value->unsigned32, commit);
152  }
153  //dot1xAuthReAuthEnabled object?
154  else if(!strcmp(object->name, "dot1xAuthReAuthEnabled"))
155  {
156  //This object specifies the enable/disable control used by the
157  //reauthentication timer state machine
158  if(value->integer == MIB_TRUTH_VALUE_TRUE)
159  {
160  //Enable reauthentication
162  dot1xPaePortNumber, TRUE, commit);
163  }
164  else if(value->integer == MIB_TRUTH_VALUE_FALSE)
165  {
166  //Disable reauthentication
168  dot1xPaePortNumber, FALSE, commit);
169  }
170  else
171  {
172  //Report an error
173  error = ERROR_WRONG_VALUE;
174  }
175  }
176  //dot1xAuthKeyTxEnabled object?
177  else if(!strcmp(object->name, "dot1xAuthKeyTxEnabled"))
178  {
179  //This object specifies the value of the keyTransmissionEnabled constant
180  //currently in use by the authenticator PAE state machine
181  if(value->integer == MIB_TRUTH_VALUE_TRUE)
182  {
183  //Enable transmission of key information
185  dot1xPaePortNumber, TRUE, commit);
186  }
187  else if(value->integer == MIB_TRUTH_VALUE_FALSE)
188  {
189  //Disable transmission of key information
191  dot1xPaePortNumber, FALSE, commit);
192  }
193  else
194  {
195  //Report an error
196  error = ERROR_WRONG_VALUE;
197  }
198  }
199  //Unknown object?
200  else
201  {
202  //The specified object does not exist
203  error = ERROR_OBJECT_NOT_FOUND;
204  }
205 
206  //Return status code
207  return error;
208 }
209 
210 
211 /**
212  * @brief Get dot1xAuthConfigEntry object value
213  * @param[in] object Pointer to the MIB object descriptor
214  * @param[in] oid Object identifier (object name and instance identifier)
215  * @param[in] oidLen Length of the OID, in bytes
216  * @param[out] value Object value
217  * @param[in,out] valueLen Length of the object value, in bytes
218  * @return Error code
219  **/
220 
222  size_t oidLen, MibVariant *value, size_t *valueLen)
223 {
224  error_t error;
225  size_t n;
226  uint_t dot1xPaePortNumber;
227  AuthenticatorContext *context;
229 
230  //Point to the instance identifier
231  n = object->oidLen;
232 
233  //dot1xPaePortNumber is used as instance identifier
234  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
235  //Invalid instance identifier?
236  if(error)
237  return error;
238 
239  //Sanity check
240  if(n != oidLen)
242 
243  //Point to the 802.1X authenticator context
245  //Sanity check
246  if(context == NULL)
248 
249  //Invalid port index?
250  if(dot1xPaePortNumber < 1 || dot1xPaePortNumber > context->numPorts)
252 
253  //Point to the port that matches the specified port index
254  port = &context->ports[dot1xPaePortNumber - 1];
255 
256  //dot1xAuthPaeState object?
257  if(!strcmp(object->name, "dot1xAuthPaeState"))
258  {
259  //This object indicates the current value of the authenticator PAE state
260  switch(port->authPaeState)
261  {
264  break;
267  break;
270  break;
273  break;
276  break;
279  break;
282  break;
285  break;
288  break;
291  break;
292  default:
293  value->integer = 0;
294  break;
295  }
296  }
297  //dot1xAuthBackendAuthState object?
298  else if(!strcmp(object->name, "dot1xAuthBackendAuthState"))
299  {
300  //This object indicates the current value of the backend authentication
301  //state machine
302  switch(port->authBackendState)
303  {
306  break;
309  break;
312  break;
315  break;
318  break;
321  break;
324  break;
327  break;
328  default:
329  value->integer = 0;
330  break;
331  }
332  }
333  //dot1xAuthAdminControlledDirections object?
334  else if(!strcmp(object->name, "dot1xAuthAdminControlledDirections"))
335  {
336  //This object indicates the current value of the administrative
337  //controlled directions parameter for the port
339  }
340  //dot1xAuthOperControlledDirections object?
341  else if(!strcmp(object->name, "dot1xAuthOperControlledDirections"))
342  {
343  //This object indicates the current value of the operational controlled
344  //directions parameter for the port
346  }
347  //dot1xAuthAuthControlledPortStatus object?
348  else if(!strcmp(object->name, "dot1xAuthAuthControlledPortStatus"))
349  {
350  //This object indicates the current value of the controlled port status
351  //parameter for the port
352  switch(port->authPortStatus)
353  {
356  break;
359  break;
360  default:
361  value->integer = 0;
362  break;
363  }
364  }
365  //dot1xAuthAuthControlledPortControl object?
366  else if(!strcmp(object->name, "dot1xAuthAuthControlledPortControl"))
367  {
368  //This object indicates the current value of the controlled port control
369  //parameter for the port
370  switch(port->portControl)
371  {
374  break;
377  break;
380  break;
381  default:
382  value->integer = 0;
383  break;
384  }
385  }
386  //dot1xAuthQuietPeriod object?
387  else if(!strcmp(object->name, "dot1xAuthQuietPeriod"))
388  {
389  //This object indicates the value, in seconds, of the quietPeriod constant
390  //currently in use by the authenticator PAE state machine
391  value->unsigned32 = port->quietPeriod;
392  }
393  //dot1xAuthServerTimeout object?
394  else if(!strcmp(object->name, "dot1xAuthServerTimeout"))
395  {
396  //This object indicates The value, in seconds, of the serverTimeout
397  //constant currently in use by the backend authentication state machine
398  value->unsigned32 = port->serverTimeout;
399  }
400  //dot1xAuthReAuthPeriod object?
401  else if(!strcmp(object->name, "dot1xAuthReAuthPeriod"))
402  {
403  //This object indicates the value, in seconds, of the reAuthPeriod
404  //constant currently in use by the reauthentication timer state machine
405  value->unsigned32 = port->reAuthPeriod;
406  }
407  //dot1xAuthReAuthEnabled object?
408  else if(!strcmp(object->name, "dot1xAuthReAuthEnabled"))
409  {
410  //This object indicates the enable/disable control used by the
411  //reauthentication timer state machine
412  if(port->reAuthEnabled)
413  {
414  value->integer = MIB_TRUTH_VALUE_TRUE;
415  }
416  else
417  {
418  value->integer = MIB_TRUTH_VALUE_FALSE;
419  }
420  }
421  //dot1xAuthKeyTxEnabled object?
422  else if(!strcmp(object->name, "dot1xAuthKeyTxEnabled"))
423  {
424  //This object indicates the value of the keyTransmissionEnabled constant
425  //currently in use by the authenticator PAE state machine
426  if(port->keyTxEnabled)
427  {
428  value->integer = MIB_TRUTH_VALUE_TRUE;
429  }
430  else
431  {
432  value->integer = MIB_TRUTH_VALUE_FALSE;
433  }
434  }
435  //Unknown object?
436  else
437  {
438  //The specified object does not exist
439  error = ERROR_OBJECT_NOT_FOUND;
440  }
441 
442  //Return status code
443  return error;
444 }
445 
446 
447 /**
448  * @brief Get next dot1xAuthConfigEntry object
449  * @param[in] object Pointer to the MIB object descriptor
450  * @param[in] oid Object identifier
451  * @param[in] oidLen Length of the OID, in bytes
452  * @param[out] nextOid OID of the next object in the MIB
453  * @param[out] nextOidLen Length of the next object identifier, in bytes
454  * @return Error code
455  **/
456 
458  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
459 {
460  error_t error;
461  uint_t i;
462  size_t n;
463  uint16_t portNum;
464  uint16_t curPortNum;
465  AuthenticatorContext *context;
466 
467  //Initialize variable
468  portNum = 0;
469 
470  //Point to the 802.1X authenticator context
472  //Make sure the context is valid
473  if(context == NULL)
474  return ERROR_OBJECT_NOT_FOUND;
475 
476  //Make sure the buffer is large enough to hold the OID prefix
477  if(*nextOidLen < object->oidLen)
478  return ERROR_BUFFER_OVERFLOW;
479 
480  //Copy OID prefix
481  osMemcpy(nextOid, object->oid, object->oidLen);
482 
483  //Loop through the ports of the bridge
484  for(i = 0; i < context->numPorts; i++)
485  {
486  //Retrieve the port number associated with the current port
487  curPortNum = context->ports[i].portIndex;
488 
489  //Append the instance identifier to the OID prefix
490  n = object->oidLen;
491 
492  //dot1xPaePortNumber is used as instance identifier
493  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
494  //Any error to report?
495  if(error)
496  return error;
497 
498  //Check whether the resulting object identifier lexicographically
499  //follows the specified OID
500  if(oidComp(nextOid, n, oid, oidLen) > 0)
501  {
502  //Save the closest object identifier that follows the specified
503  //OID in lexicographic order
504  if(portNum == 0 || curPortNum < portNum)
505  {
506  portNum = curPortNum;
507  }
508  }
509  }
510 
511  //The specified OID does not lexicographically precede the name
512  //of some object?
513  if(portNum == 0)
514  return ERROR_OBJECT_NOT_FOUND;
515 
516  //Append the instance identifier to the OID prefix
517  n = object->oidLen;
518 
519  //dot1xPaePortNumber is used as instance identifier
520  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
521  //Any error to report?
522  if(error)
523  return error;
524 
525  //Save the length of the resulting object identifier
526  *nextOidLen = n;
527  //Next object found
528  return NO_ERROR;
529 }
530 
531 
532 /**
533  * @brief Get dot1xAuthStatsEntry object value
534  * @param[in] object Pointer to the MIB object descriptor
535  * @param[in] oid Object identifier (object name and instance identifier)
536  * @param[in] oidLen Length of the OID, in bytes
537  * @param[out] value Object value
538  * @param[in,out] valueLen Length of the object value, in bytes
539  * @return Error code
540  **/
541 
543  size_t oidLen, MibVariant *value, size_t *valueLen)
544 {
545  error_t error;
546  size_t n;
547  uint_t dot1xPaePortNumber;
548  AuthenticatorContext *context;
550 
551  //Point to the instance identifier
552  n = object->oidLen;
553 
554  //dot1xPaePortNumber is used as instance identifier
555  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
556  //Invalid instance identifier?
557  if(error)
558  return error;
559 
560  //Sanity check
561  if(n != oidLen)
563 
564  //Point to the 802.1X authenticator context
566  //Sanity check
567  if(context == NULL)
569 
570  //Invalid port index?
571  if(dot1xPaePortNumber < 1 || dot1xPaePortNumber > context->numPorts)
573 
574  //Point to the port that matches the specified port index
575  port = &context->ports[dot1xPaePortNumber - 1];
576 
577  //dot1xAuthEapolFramesRx object?
578  if(!strcmp(object->name, "dot1xAuthEapolFramesRx"))
579  {
580  //Number of valid EAPOL frames of any type that have been received by this
581  //authenticator
582  value->counter32 = port->stats.eapolFramesRx;
583  }
584  //dot1xAuthEapolFramesTx object?
585  else if(!strcmp(object->name, "dot1xAuthEapolFramesTx"))
586  {
587  //Number of EAPOL frames of any type that have been transmitted by this
588  //authenticator
589  value->counter32 = port->stats.eapolFramesTx;
590  }
591  //dot1xAuthEapolStartFramesRx object?
592  else if(!strcmp(object->name, "dot1xAuthEapolStartFramesRx"))
593  {
594  //Number of EAPOL Start frames that have been received by this
595  //authenticator
596  value->counter32 = port->stats.eapolStartFramesRx;
597  }
598  //dot1xAuthEapolLogoffFramesRx object?
599  else if(!strcmp(object->name, "dot1xAuthEapolLogoffFramesRx"))
600  {
601  //Number of EAPOL Logoff frames that have been received by this
602  //authenticator
603  value->counter32 = port->stats.eapolLogoffFramesRx;
604  }
605  //dot1xAuthEapolRespIdFramesRx object?
606  else if(!strcmp(object->name, "dot1xAuthEapolRespIdFramesRx"))
607  {
608  //Number of EAP Resp/Id frames that have been received by this
609  //authenticator
610  value->counter32 = port->stats.eapolRespIdFramesRx;
611  }
612  //dot1xAuthEapolRespFramesRx object?
613  else if(!strcmp(object->name, "dot1xAuthEapolRespFramesRx"))
614  {
615  //Number of valid EAP Response frames (other than Resp/Id frames) that
616  //have been received by this authenticator
617  value->counter32 = port->stats.eapolRespFramesRx;
618  }
619  //dot1xAuthEapolReqIdFramesTx object?
620  else if(!strcmp(object->name, "dot1xAuthEapolReqIdFramesTx"))
621  {
622  //Number of EAP Req/Id frames that have been transmitted by this
623  //authenticator
624  value->counter32 = port->stats.eapolReqIdFramesTx;
625  }
626  //dot1xAuthEapolReqFramesTx object?
627  else if(!strcmp(object->name, "dot1xAuthEapolReqFramesTx"))
628  {
629  //Number of EAP Request frames (other than Rq/Id frames) that have been
630  //transmitted by this authenticator
631  value->counter32 = port->stats.eapolReqFramesTx;
632  }
633  //dot1xAuthInvalidEapolFramesRx object?
634  else if(!strcmp(object->name, "dot1xAuthInvalidEapolFramesRx"))
635  {
636  //Number of EAPOL frames that have been received by this authenticator
637  //in which the frame type is not recognized
638  value->counter32 = port->stats.invalidEapolFramesRx;
639  }
640  //dot1xAuthEapLengthErrorFramesRx object?
641  else if(!strcmp(object->name, "dot1xAuthEapLengthErrorFramesRx"))
642  {
643  //Number of EAPOL frames that have been received by this authenticator
644  //in which the Packet Body Length field is invalid
645  value->counter32 = port->stats.eapLengthErrorFramesRx;
646  }
647  //dot1xAuthLastEapolFrameVersion object?
648  else if(!strcmp(object->name, "dot1xAuthLastEapolFrameVersion"))
649  {
650  //Protocol version number carried in the most recently received EAPOL
651  //frame
652  value->unsigned32 = port->stats.lastEapolFrameVersion;
653  }
654  //dot1xAuthLastEapolFrameSource object?
655  else if(!strcmp(object->name, "dot1xAuthLastEapolFrameSource"))
656  {
657  //This object contains the source MAC address carried in the most
658  //recently received EAPOL frame
659  if(*valueLen >= sizeof(MacAddr))
660  {
661  //Copy object value
662  macCopyAddr(value->octetString, &port->supplicantMacAddr);
663  //Return object length
664  *valueLen = sizeof(MacAddr);
665  }
666  else
667  {
668  //Report an error
669  error = ERROR_BUFFER_OVERFLOW;
670  }
671  }
672  //Unknown object?
673  else
674  {
675  //The specified object does not exist
676  error = ERROR_OBJECT_NOT_FOUND;
677  }
678 
679  //Return status code
680  return error;
681 }
682 
683 
684 /**
685  * @brief Get next dot1xAuthStatsEntry object
686  * @param[in] object Pointer to the MIB object descriptor
687  * @param[in] oid Object identifier
688  * @param[in] oidLen Length of the OID, in bytes
689  * @param[out] nextOid OID of the next object in the MIB
690  * @param[out] nextOidLen Length of the next object identifier, in bytes
691  * @return Error code
692  **/
693 
695  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
696 {
697  error_t error;
698  uint_t i;
699  size_t n;
700  uint16_t portNum;
701  uint16_t curPortNum;
702  AuthenticatorContext *context;
703 
704  //Initialize variable
705  portNum = 0;
706 
707  //Point to the 802.1X authenticator context
709  //Make sure the context is valid
710  if(context == NULL)
711  return ERROR_OBJECT_NOT_FOUND;
712 
713  //Make sure the buffer is large enough to hold the OID prefix
714  if(*nextOidLen < object->oidLen)
715  return ERROR_BUFFER_OVERFLOW;
716 
717  //Copy OID prefix
718  osMemcpy(nextOid, object->oid, object->oidLen);
719 
720  //Loop through the ports of the bridge
721  for(i = 0; i < context->numPorts; i++)
722  {
723  //Retrieve the port number associated with the current port
724  curPortNum = context->ports[i].portIndex;
725 
726  //Append the instance identifier to the OID prefix
727  n = object->oidLen;
728 
729  //dot1xPaePortNumber is used as instance identifier
730  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
731  //Any error to report?
732  if(error)
733  return error;
734 
735  //Check whether the resulting object identifier lexicographically
736  //follows the specified OID
737  if(oidComp(nextOid, n, oid, oidLen) > 0)
738  {
739  //Save the closest object identifier that follows the specified
740  //OID in lexicographic order
741  if(portNum == 0 || curPortNum < portNum)
742  {
743  portNum = curPortNum;
744  }
745  }
746  }
747 
748  //The specified OID does not lexicographically precede the name
749  //of some object?
750  if(portNum == 0)
751  return ERROR_OBJECT_NOT_FOUND;
752 
753  //Append the instance identifier to the OID prefix
754  n = object->oidLen;
755 
756  //dot1xPaePortNumber is used as instance identifier
757  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
758  //Any error to report?
759  if(error)
760  return error;
761 
762  //Save the length of the resulting object identifier
763  *nextOidLen = n;
764  //Next object found
765  return NO_ERROR;
766 }
767 
768 
769 /**
770  * @brief Get dot1xAuthSessionStatsEntry object value
771  * @param[in] object Pointer to the MIB object descriptor
772  * @param[in] oid Object identifier (object name and instance identifier)
773  * @param[in] oidLen Length of the OID, in bytes
774  * @param[out] value Object value
775  * @param[in,out] valueLen Length of the object value, in bytes
776  * @return Error code
777  **/
778 
780  size_t oidLen, MibVariant *value, size_t *valueLen)
781 {
782  error_t error;
783  size_t n;
784  uint_t dot1xPaePortNumber;
785  AuthenticatorContext *context;
787 
788  //Point to the instance identifier
789  n = object->oidLen;
790 
791  //dot1xPaePortNumber is used as instance identifier
792  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
793  //Invalid instance identifier?
794  if(error)
795  return error;
796 
797  //Sanity check
798  if(n != oidLen)
800 
801  //Point to the 802.1X authenticator context
803  //Sanity check
804  if(context == NULL)
806 
807  //Invalid port index?
808  if(dot1xPaePortNumber < 1 || dot1xPaePortNumber > context->numPorts)
810 
811  //Point to the port that matches the specified port index
812  port = &context->ports[dot1xPaePortNumber - 1];
813 
814  //dot1xAuthSessionOctetsRx object?
815  if(!strcmp(object->name, "dot1xAuthSessionOctetsRx"))
816  {
817  //Number of octets received in user data frames on this port during the
818  //session
819  value->counter64 = port->sessionStats.sessionOctetsRx;
820  }
821  //dot1xAuthSessionOctetsTx object?
822  else if(!strcmp(object->name, "dot1xAuthSessionOctetsTx"))
823  {
824  //Number of octets transmitted in user data frames on this port during
825  //the session
826  value->counter64 = port->sessionStats.sessionOctetsTx;
827  }
828  //dot1xAuthSessionFramesRx object?
829  else if(!strcmp(object->name, "dot1xAuthSessionFramesRx"))
830  {
831  //Number of user data frames received on this port during the session
832  value->counter32 = port->sessionStats.sessionFramesRx;
833  }
834  //dot1xAuthSessionFramesTx object?
835  else if(!strcmp(object->name, "dot1xAuthSessionFramesTx"))
836  {
837  //Number of user data frames transmitted on this port during the session
838  value->counter32 = port->sessionStats.sessionFramesTx;
839  }
840  //dot1xAuthSessionId object?
841  else if(!strcmp(object->name, "dot1xAuthSessionId"))
842  {
843  //A unique identifier for the session, in the form of a printable ASCII
844  //string of at least three characters
845  *valueLen = 0;
846  }
847  //dot1xAuthSessionAuthenticMethod object?
848  else if(!strcmp(object->name, "dot1xAuthSessionAuthenticMethod"))
849  {
850  //Authentication method used to establish the session
852  }
853  //dot1xAuthSessionTime object?
854  else if(!strcmp(object->name, "dot1xAuthSessionTime"))
855  {
856  //Duration of the session in seconds
857  value->timeTicks = port->sessionStats.sessionTime * 100;
858  }
859  //dot1xAuthSessionTerminateCause object?
860  else if(!strcmp(object->name, "dot1xAuthSessionTerminateCause"))
861  {
862  //Reason for the session termination
863  switch(port->sessionStats.sessionTerminateCause)
864  {
867  break;
870  break;
873  break;
876  break;
879  break;
882  break;
885  break;
888  break;
889  default:
890  value->integer = 0;
891  break;
892  }
893  }
894  //dot1xAuthSessionUserName object?
895  else if(!strcmp(object->name, "dot1xAuthSessionUserName"))
896  {
897  //Retrieve the length of the user name
898  n = osStrlen(port->aaaIdentity);
899 
900  //Make sure the buffer is large enough to hold the entire object
901  if(*valueLen >= n)
902  {
903  //Copy object value
904  osMemcpy(value->octetString, port->aaaIdentity, n);
905  //Return object length
906  *valueLen = n;
907  }
908  else
909  {
910  //Report an error
911  error = ERROR_BUFFER_OVERFLOW;
912  }
913  }
914  //Unknown object?
915  else
916  {
917  //The specified object does not exist
918  error = ERROR_OBJECT_NOT_FOUND;
919  }
920 
921  //Return status code
922  return error;
923 }
924 
925 
926 /**
927  * @brief Get next dot1xAuthSessionStatsEntry object
928  * @param[in] object Pointer to the MIB object descriptor
929  * @param[in] oid Object identifier
930  * @param[in] oidLen Length of the OID, in bytes
931  * @param[out] nextOid OID of the next object in the MIB
932  * @param[out] nextOidLen Length of the next object identifier, in bytes
933  * @return Error code
934  **/
935 
937  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
938 {
939  error_t error;
940  uint_t i;
941  size_t n;
942  uint16_t portNum;
943  uint16_t curPortNum;
944  AuthenticatorContext *context;
945 
946  //Initialize variable
947  portNum = 0;
948 
949  //Point to the 802.1X authenticator context
951  //Make sure the context is valid
952  if(context == NULL)
953  return ERROR_OBJECT_NOT_FOUND;
954 
955  //Make sure the buffer is large enough to hold the OID prefix
956  if(*nextOidLen < object->oidLen)
957  return ERROR_BUFFER_OVERFLOW;
958 
959  //Copy OID prefix
960  osMemcpy(nextOid, object->oid, object->oidLen);
961 
962  //Loop through the ports of the bridge
963  for(i = 0; i < context->numPorts; i++)
964  {
965  //Retrieve the port number associated with the current port
966  curPortNum = context->ports[i].portIndex;
967 
968  //Append the instance identifier to the OID prefix
969  n = object->oidLen;
970 
971  //dot1xPaePortNumber is used as instance identifier
972  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
973  //Any error to report?
974  if(error)
975  return error;
976 
977  //Check whether the resulting object identifier lexicographically
978  //follows the specified OID
979  if(oidComp(nextOid, n, oid, oidLen) > 0)
980  {
981  //Save the closest object identifier that follows the specified
982  //OID in lexicographic order
983  if(portNum == 0 || curPortNum < portNum)
984  {
985  portNum = curPortNum;
986  }
987  }
988  }
989 
990  //The specified OID does not lexicographically precede the name
991  //of some object?
992  if(portNum == 0)
993  return ERROR_OBJECT_NOT_FOUND;
994 
995  //Append the instance identifier to the OID prefix
996  n = object->oidLen;
997 
998  //dot1xPaePortNumber is used as instance identifier
999  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
1000  //Any error to report?
1001  if(error)
1002  return error;
1003 
1004  //Save the length of the resulting object identifier
1005  *nextOidLen = n;
1006  //Next object found
1007  return NO_ERROR;
1008 }
1009 
1010 #endif
ASN.1 (Abstract Syntax Notation One)
#define AuthenticatorPort
Definition: authenticator.h:40
@ AUTHENTICATOR_TERMINATE_CAUSE_SUPPLICANT_RESTART
@ AUTHENTICATOR_TERMINATE_CAUSE_SUPPLICANT_LOGOFF
@ AUTHENTICATOR_TERMINATE_CAUSE_PORT_ADMIN_DISABLED
@ AUTHENTICATOR_TERMINATE_CAUSE_NOT_TERMINATED_YET
@ AUTHENTICATOR_TERMINATE_CAUSE_PORT_FAILURE
@ AUTHENTICATOR_TERMINATE_CAUSE_PORT_REINIT
@ AUTHENTICATOR_TERMINATE_CAUSE_AUTH_CONTROL_FORCE_UNAUTH
@ AUTHENTICATOR_TERMINATE_CAUSE_REAUTH_FAILED
#define AuthenticatorContext
Definition: authenticator.h:36
@ AUTHENTICATOR_BACKEND_STATE_IGNORE
@ AUTHENTICATOR_BACKEND_STATE_FAIL
@ AUTHENTICATOR_BACKEND_STATE_RESPONSE
@ AUTHENTICATOR_BACKEND_STATE_IDLE
@ AUTHENTICATOR_BACKEND_STATE_REQUEST
@ AUTHENTICATOR_BACKEND_STATE_TIMEOUT
@ AUTHENTICATOR_BACKEND_STATE_SUCCESS
@ AUTHENTICATOR_BACKEND_STATE_INITIALIZE
error_t authenticatorMgmtSetQuietPeriod(AuthenticatorContext *context, uint_t portIndex, uint_t quietPeriod, bool_t commit)
Set the value of the quietPeriod parameter.
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 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.
@ AUTHENTICATOR_PORT_STATUS_AUTH
@ AUTHENTICATOR_PORT_STATUS_UNAUTH
@ AUTHENTICATOR_PAE_STATE_CONNECTING
@ AUTHENTICATOR_PAE_STATE_FORCE_AUTH
@ AUTHENTICATOR_PAE_STATE_AUTHENTICATING
@ AUTHENTICATOR_PAE_STATE_RESTART
@ AUTHENTICATOR_PAE_STATE_DISCONNECTED
@ AUTHENTICATOR_PAE_STATE_INITIALIZE
@ AUTHENTICATOR_PAE_STATE_ABORTING
@ AUTHENTICATOR_PAE_STATE_AUTHENTICATED
@ AUTHENTICATOR_PAE_STATE_FORCE_UNAUTH
@ AUTHENTICATOR_PAE_STATE_HELD
@ AUTHENTICATOR_PORT_MODE_FORCE_AUTH
@ AUTHENTICATOR_PORT_MODE_AUTO
@ AUTHENTICATOR_PORT_MODE_FORCE_UNAUTH
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
General definitions for cryptographic algorithms.
Debugging facilities.
uint8_t n
uint16_t port
Definition: dns_common.h:267
error_t
Error codes.
Definition: error.h:43
@ ERROR_OBJECT_NOT_FOUND
Definition: error.h:255
@ ERROR_INSTANCE_NOT_FOUND
Definition: error.h:256
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
#define macCopyAddr(destMacAddr, srcMacAddr)
Definition: ethernet.h:127
MacAddr
Definition: ethernet.h:195
Port Access Control MIB module implementation.
error_t ieee8021PaeMibGetDot1xAuthSessionStatsEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get dot1xAuthSessionStatsEntry object value.
error_t ieee8021PaeMibGetNextDot1xAuthStatsEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next dot1xAuthStatsEntry object.
error_t ieee8021PaeMibGetDot1xAuthStatsEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get dot1xAuthStatsEntry object value.
error_t ieee8021PaeMibGetNextDot1xAuthConfigEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next dot1xAuthConfigEntry object.
error_t ieee8021PaeMibGetDot1xAuthConfigEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get dot1xAuthConfigEntry object value.
error_t ieee8021PaeMibSetDot1xAuthConfigEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
Set dot1xAuthConfigEntry object value.
error_t ieee8021PaeMibGetNextDot1xAuthSessionStatsEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next dot1xAuthSessionStatsEntry object.
Ieee8021PaeMibBase ieee8021PaeMibBase
Port Access Control MIB base.
Port Access Control MIB module.
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_RESTART
restart
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_FORCE_AUTH
forceAuth
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_AUTHENTICATING
authenticating
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_FORCE_UNAUTH
forceUnauth
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_HELD
held
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_AUTHENTICATED
authenticated
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_CONNECTING
connecting
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_ABORTING
aborting
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_INITIALIZE
initialize
@ IEEE8021_PAE_MIB_AUTH_PAE_STATE_DISCONNECTED
disconnected
@ IEEE8021_PAE_MIB_PORT_STATUS_UNAUTH
unauthorized
@ IEEE8021_PAE_MIB_PORT_STATUS_AUTH
authorized
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_SUPPLICANT_RESTART
supplicantRestart
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_PORT_REINIT
portReInit
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_PORT_FAILURE
portFailure
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_REAUTH_FAILED
reauthFailed
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_PORT_ADMIN_DISABLED
portAdminDisabled
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_AUTH_CONTROL_FORCE_UNAUTH
authControlForceUnauth
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_SUPPLICANT_LOGOFF
supplicantLogoff
@ IEEE8021_PAE_MIB_TERMINATE_CAUSE_NOT_TERMINATED_YET
notTerminatedYet
@ IEEE8021_PAE_MIB_CONTROL_DIR_IN
in
@ IEEE8021_PAE_MIB_CONTROL_DIR_BOTH
both
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_RESPONSE
response
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_IDLE
idle
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_INITIALIZE
initialize
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_FAIL
fail
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_REQUEST
request
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_SUCCESS
success
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_IGNORE
ignore
@ IEEE8021_PAE_MIB_AUTH_BACKEND_STATE_TIMEOUT
timeout
@ IEEE8021_PAE_MIB_PORT_CONTROL_FORCE_UNAUTH
forceUnauthorized
@ IEEE8021_PAE_MIB_PORT_CONTROL_AUTO
auto
@ IEEE8021_PAE_MIB_PORT_CONTROL_FORCE_AUTH
forceAuthorized
@ IEEE8021_PAE_MIB_AUTH_METHOD_REMOTE_AUTH_SERVER
remoteAuthServer
uint8_t oid[]
Definition: lldp_tlv.h:300
uint8_t oidLen
Definition: lldp_tlv.h:299
error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos, uint_t *index)
Decode instance identifier (index)
Definition: mib_common.c:64
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
Common definitions for MIB modules.
#define MibObject
Definition: mib_common.h:46
@ MIB_TRUTH_VALUE_TRUE
Definition: mib_common.h:91
@ MIB_TRUTH_VALUE_FALSE
Definition: mib_common.h:92
MibVariant
Definition: mib_common.h:196
TCP/IP stack core.
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:103
OID (Object Identifier)
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define osStrlen(s)
Definition: os_port.h:165
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
AuthenticatorContext * authContext
uint8_t value[]
Definition: tcp.h:369