ieee8021_pae_mib_impl_sys.c
Go to the documentation of this file.
1 /**
2  * @file ieee8021_pae_mib_impl.c (dot1xPaeSystem 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.4
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 dot1xPaeSystemAuthControl 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 #if (IEEE8021_PAE_MIB_SET_SUPPORT == ENABLED)
65  error_t error;
66 
67  //This object forces the administrative enable/disable state for port
68  //access control
71  {
72  //Not implemented
73  error = NO_ERROR;
74  }
75  else
76  {
77  //Report an error
78  error = ERROR_WRONG_VALUE;
79  }
80 
81  //Return status code
82  return error;
83 #else
84  //SET operation is not supported
85  return ERROR_WRITE_FAILED;
86 #endif
87 }
88 
89 
90 /**
91  * @brief Get dot1xPaeSystemAuthControl object value
92  * @param[in] object Pointer to the MIB object descriptor
93  * @param[in] oid Object identifier (object name and instance identifier)
94  * @param[in] oidLen Length of the OID, in bytes
95  * @param[out] value Object value
96  * @param[in,out] valueLen Length of the object value, in bytes
97  * @return Error code
98  **/
99 
101  size_t oidLen, MibVariant *value, size_t *valueLen)
102 {
103  //Return the administrative enable/disable state for port access control
104  if(ieee8021PaeMibBase.authContext->running)
105  {
107  }
108  else
109  {
111  }
112 
113  //Successful processing
114  return NO_ERROR;
115 }
116 
117 
118 /**
119  * @brief Set dot1xPaePortEntry object value
120  * @param[in] object Pointer to the MIB object descriptor
121  * @param[in] oid Object identifier (object name and instance identifier)
122  * @param[in] oidLen Length of the OID, in bytes
123  * @param[in] value Object value
124  * @param[in] valueLen Length of the object value, in bytes
125  * @param[in] commit This flag tells whether the changes shall be committed
126  * to the MIB base
127  * @return Error code
128  **/
129 
131  size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
132 {
133 #if (IEEE8021_PAE_MIB_SET_SUPPORT == ENABLED)
134  error_t error;
135  size_t n;
136  uint_t dot1xPaePortNumber;
137 
138  //Point to the instance identifier
139  n = object->oidLen;
140 
141  //dot1xPaePortNumber is used as instance identifier
142  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
143  //Invalid instance identifier?
144  if(error)
145  return error;
146 
147  //Sanity check
148  if(n != oidLen)
150 
151  //dot1xPaePortInitialize object?
152  if(osStrcmp(object->name, "dot1xPaePortInitialize") == 0)
153  {
154  //Initialization control for this port
155  if(value->integer == MIB_TRUTH_VALUE_TRUE)
156  {
157  //Setting this attribute TRUE causes the port to be initialized
159  dot1xPaePortNumber, TRUE, commit);
160  }
161  else if(value->integer == MIB_TRUTH_VALUE_FALSE)
162  {
163  //Setting this attribute FALSE has no effect
164  error = NO_ERROR;
165  }
166  else
167  {
168  //Report an error
169  error = ERROR_WRONG_VALUE;
170  }
171  }
172  //dot1xPaePortReauthenticate object?
173  else if(osStrcmp(object->name, "dot1xPaePortReauthenticate") == 0)
174  {
175  //Reauthentication control for this port
176  if(value->integer == MIB_TRUTH_VALUE_TRUE)
177  {
178  //Setting this attribute TRUE causes the authenticator PAE state
179  //machine for the port to reauthenticate the supplicant
181  dot1xPaePortNumber, TRUE, commit);
182  }
183  else if(value->integer == MIB_TRUTH_VALUE_FALSE)
184  {
185  //Setting this attribute FALSE has no effect
186  error = NO_ERROR;
187  }
188  else
189  {
190  //Report an error
191  error = ERROR_WRONG_VALUE;
192  }
193  }
194  //Unknown object?
195  else
196  {
197  //The specified object does not exist
198  error = ERROR_OBJECT_NOT_FOUND;
199  }
200 
201  //Return status code
202  return error;
203 #else
204  //SET operation is not supported
205  return ERROR_WRITE_FAILED;
206 #endif
207 }
208 
209 
210 /**
211  * @brief Get dot1xPaePortEntry object value
212  * @param[in] object Pointer to the MIB object descriptor
213  * @param[in] oid Object identifier (object name and instance identifier)
214  * @param[in] oidLen Length of the OID, in bytes
215  * @param[out] value Object value
216  * @param[in,out] valueLen Length of the object value, in bytes
217  * @return Error code
218  **/
219 
221  size_t oidLen, MibVariant *value, size_t *valueLen)
222 {
223  error_t error;
224  size_t n;
225  uint_t dot1xPaePortNumber;
226 
227  //Point to the instance identifier
228  n = object->oidLen;
229 
230  //dot1xPaePortNumber is used as instance identifier
231  error = mibDecodeIndex(oid, oidLen, &n, &dot1xPaePortNumber);
232  //Invalid instance identifier?
233  if(error)
234  return error;
235 
236  //Sanity check
237  if(n != oidLen)
239 
240  //dot1xPaePortProtocolVersion object?
241  if(osStrcmp(object->name, "dot1xPaePortProtocolVersion") == 0)
242  {
243  //This object indicates the protocol version associated with this port
244  value->unsigned32 = EAPOL_VERSION_2;
245  }
246  //dot1xPaePortCapabilities object?
247  else if(osStrcmp(object->name, "dot1xPaePortCapabilities") == 0)
248  {
249  //This object indicates the PAE functionality that this port supports
250  //and that may be managed through this MIB
252  //Return object length
253  *valueLen = sizeof(uint8_t);
254  }
255  //dot1xPaePortInitialize object?
256  else if(osStrcmp(object->name, "dot1xPaePortInitialize") == 0)
257  {
258  //The attribute value reverts to FALSE once initialization has completed
259  value->integer = 0;
260  }
261  //dot1xPaePortReauthenticate object?
262  else if(osStrcmp(object->name, "dot1xPaePortReauthenticate") == 0)
263  {
264  //This attribute always returns FALSE when it is read
265  value->integer = 0;
266  }
267  //Unknown object?
268  else
269  {
270  //The specified object does not exist
271  error = ERROR_OBJECT_NOT_FOUND;
272  }
273 
274  //Return status code
275  return error;
276 }
277 
278 
279 /**
280  * @brief Get next dot1xPaePortEntry object
281  * @param[in] object Pointer to the MIB object descriptor
282  * @param[in] oid Object identifier
283  * @param[in] oidLen Length of the OID, in bytes
284  * @param[out] nextOid OID of the next object in the MIB
285  * @param[out] nextOidLen Length of the next object identifier, in bytes
286  * @return Error code
287  **/
288 
290  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
291 {
292  error_t error;
293  uint_t i;
294  size_t n;
295  uint16_t portNum;
296  uint16_t curPortNum;
297  AuthenticatorContext *context;
298 
299  //Initialize variable
300  portNum = 0;
301 
302  //Point to the 802.1X authenticator context
304  //Make sure the context is valid
305  if(context == NULL)
306  return ERROR_OBJECT_NOT_FOUND;
307 
308  //Make sure the buffer is large enough to hold the OID prefix
309  if(*nextOidLen < object->oidLen)
310  return ERROR_BUFFER_OVERFLOW;
311 
312  //Copy OID prefix
313  osMemcpy(nextOid, object->oid, object->oidLen);
314 
315  //Loop through the ports of the bridge
316  for(i = 0; i < context->numPorts; i++)
317  {
318  //Retrieve the port number associated with the current port
319  curPortNum = context->ports[i].portIndex;
320 
321  //Append the instance identifier to the OID prefix
322  n = object->oidLen;
323 
324  //dot1xPaePortNumber is used as instance identifier
325  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
326  //Any error to report?
327  if(error)
328  return error;
329 
330  //Check whether the resulting object identifier lexicographically
331  //follows the specified OID
332  if(oidComp(nextOid, n, oid, oidLen) > 0)
333  {
334  //Save the closest object identifier that follows the specified
335  //OID in lexicographic order
336  if(portNum == 0 || curPortNum < portNum)
337  {
338  portNum = curPortNum;
339  }
340  }
341  }
342 
343  //The specified OID does not lexicographically precede the name
344  //of some object?
345  if(portNum == 0)
346  return ERROR_OBJECT_NOT_FOUND;
347 
348  //Append the instance identifier to the OID prefix
349  n = object->oidLen;
350 
351  //dot1xPaePortNumber is used as instance identifier
352  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
353  //Any error to report?
354  if(error)
355  return error;
356 
357  //Save the length of the resulting object identifier
358  *nextOidLen = n;
359  //Next object found
360  return NO_ERROR;
361 }
362 
363 #endif
Port Access Control MIB module implementation.
@ IEEE8021_PAE_MIB_SYS_AUTH_CONTROL_DISABLED
disabled
int bool_t
Definition: compiler_port.h:53
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
@ EAPOL_VERSION_2
IEEE 802.1X-2004.
Definition: eap.h:123
OID (Object Identifier)
@ IEEE8021_PAE_MIB_SYS_AUTH_CONTROL_ENABLED
enabled
#define TRUE
Definition: os_port.h:50
@ MIB_TRUTH_VALUE_TRUE
Definition: mib_common.h:91
#define osStrcmp(s1, s2)
Definition: os_port.h:171
error_t authenticatorMgmtSetInitialize(AuthenticatorContext *context, uint_t portIndex, bool_t initialize, bool_t commit)
Force the value of the initialize variable.
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:103
uint8_t oid[]
Definition: lldp_tlv.h:300
AuthenticatorContext * authContext
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
Ieee8021PaeMibBase ieee8021PaeMibBase
Port Access Control MIB base.
error_t
Error codes.
Definition: error.h:43
@ ERROR_INSTANCE_NOT_FOUND
Definition: error.h:257
error_t ieee8021PaeMibSetDot1xPaePortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
Set dot1xPaePortEntry object value.
error_t ieee8021PaeMibGetDot1xPaeSystemAuthControl(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get dot1xPaeSystemAuthControl object value.
General definitions for cryptographic algorithms.
@ IEEE8021_PAE_MIB_PORT_CAP_AUTH
Authenticator functions are supported.
error_t authenticatorMgmtSetReauthenticate(AuthenticatorContext *context, uint_t portIndex, bool_t reAuthenticate, bool_t commit)
Force the value of the reAuthenticate variable.
Management of the 802.1X authenticator.
#define AuthenticatorContext
Definition: authenticator.h:36
@ MIB_TRUTH_VALUE_FALSE
Definition: mib_common.h:92
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
Common definitions for MIB modules.
uint8_t n
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ ERROR_WRITE_FAILED
Definition: error.h:222
error_t ieee8021PaeMibGetNextDot1xPaePortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next dot1xPaePortEntry object.
@ ERROR_OBJECT_NOT_FOUND
Definition: error.h:256
error_t ieee8021PaeMibGetDot1xPaePortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get dot1xPaePortEntry object value.
#define MibObject
Definition: mib_common.h:46
uint8_t value[]
Definition: tcp.h:369
uint8_t oidLen
Definition: lldp_tlv.h:299
uint8_t reverseInt8(uint8_t value)
Reverse bit order in a byte.
Definition: cpu_endian.c:90
error_t ieee8021PaeMibSetDot1xPaeSystemAuthControl(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
Set dot1xPaeSystemAuthControl object value.
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
MibVariant
Definition: mib_common.h:196
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
Port Access Control MIB module.
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
ASN.1 (Abstract Syntax Notation One)