lldp_mib_impl_local.c
Go to the documentation of this file.
1 /**
2  * @file lldp_mib_impl_local.c
3  * @brief LLDP MIB module implementation (lldpLocalSystemData subtree)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-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 SNMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mibs/mib_common.h"
37 #include "mibs/lldp_mib_module.h"
38 #include "mibs/lldp_mib_impl.h"
40 #include "core/crypto.h"
41 #include "encoding/asn1.h"
42 #include "encoding/oid.h"
43 #include "lldp/lldp_mgmt.h"
44 #include "debug.h"
45 
46 //Check TCP/IP stack configuration
47 #if (LLDP_MIB_SUPPORT == ENABLED && LLDP_TX_MODE_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief Get lldpLocChassisIdSubtype object value
52  * @param[in] object Pointer to the MIB object descriptor
53  * @param[in] oid Object identifier (object name and instance identifier)
54  * @param[in] oidLen Length of the OID, in bytes
55  * @param[out] value Object value
56  * @param[in,out] valueLen Length of the object value, in bytes
57  * @return Error code
58  **/
59 
61  size_t oidLen, MibVariant *value, size_t *valueLen)
62 {
63  error_t error;
64  LldpChassisIdSubtype chassisIdSubtype;
65  const uint8_t *chassisId;
66  size_t chassisIdLen;
67 
68  //This object indicates the type of chassis identifier encoding used in
69  //the associated lldpLocChassisId object
71  &chassisIdSubtype, &chassisId, &chassisIdLen);
72 
73  //Check status code
74  if(!error)
75  {
76  //Return object value
77  value->integer = (int32_t) chassisIdSubtype;
78  }
79 
80  //Return status code
81  return error;
82 }
83 
84 
85 /**
86  * @brief Get lldpLocChassisId object value
87  * @param[in] object Pointer to the MIB object descriptor
88  * @param[in] oid Object identifier (object name and instance identifier)
89  * @param[in] oidLen Length of the OID, in bytes
90  * @param[out] value Object value
91  * @param[in,out] valueLen Length of the object value, in bytes
92  * @return Error code
93  **/
94 
95 error_t lldpMibGetLldpLocChassisId(const MibObject *object, const uint8_t *oid,
96  size_t oidLen, MibVariant *value, size_t *valueLen)
97 {
98  error_t error;
99  LldpChassisIdSubtype chassisIdSubtype;
100  const uint8_t *chassisId;
101  size_t chassisIdLen;
102 
103  //This object identifies the chassis component associated with the local
104  //system
106  &chassisIdSubtype, &chassisId, &chassisIdLen);
107 
108  //Check status code
109  if(!error)
110  {
111  //Make sure the buffer is large enough to hold the entire object
112  if(*valueLen >= chassisIdLen)
113  {
114  //Copy object value
115  osMemcpy(value->octetString, chassisId, chassisIdLen);
116  //Return object length
117  *valueLen = chassisIdLen;
118  }
119  else
120  {
121  //Report an error
122  error = ERROR_BUFFER_OVERFLOW;
123  }
124  }
125 
126  //Return status code
127  return error;
128 }
129 
130 
131 /**
132  * @brief Get lldpLocSysName object value
133  * @param[in] object Pointer to the MIB object descriptor
134  * @param[in] oid Object identifier (object name and instance identifier)
135  * @param[in] oidLen Length of the OID, in bytes
136  * @param[out] value Object value
137  * @param[in,out] valueLen Length of the object value, in bytes
138  * @return Error code
139  **/
140 
141 error_t lldpMibGetLldpLocSysName(const MibObject *object, const uint8_t *oid,
142  size_t oidLen, MibVariant *value, size_t *valueLen)
143 {
144  error_t error;
145  const char_t *sysName;
146  size_t sysNameLen;
147 
148  //This object identifies the system name of the local system
150  &sysName, &sysNameLen);
151 
152  //Check status code
153  if(!error)
154  {
155  //Make sure the buffer is large enough to hold the entire object
156  if(*valueLen >= sysNameLen)
157  {
158  //Copy object value
159  osMemcpy(value->octetString, sysName, sysNameLen);
160  //Return object length
161  *valueLen = sysNameLen;
162  }
163  else
164  {
165  //Report an error
166  error = ERROR_BUFFER_OVERFLOW;
167  }
168  }
169 
170  //Return status code
171  return error;
172 }
173 
174 
175 /**
176  * @brief Get lldpLocSysDesc object value
177  * @param[in] object Pointer to the MIB object descriptor
178  * @param[in] oid Object identifier (object name and instance identifier)
179  * @param[in] oidLen Length of the OID, in bytes
180  * @param[out] value Object value
181  * @param[in,out] valueLen Length of the object value, in bytes
182  * @return Error code
183  **/
184 
185 error_t lldpMibGetLldpLocSysDesc(const MibObject *object, const uint8_t *oid,
186  size_t oidLen, MibVariant *value, size_t *valueLen)
187 {
188  error_t error;
189  const char_t *sysDesc;
190  size_t sysDescLen;
191 
192  //This object identifies the system description of the local system
194  &sysDesc, &sysDescLen);
195 
196  //Check status code
197  if(!error)
198  {
199  //Make sure the buffer is large enough to hold the entire object
200  if(*valueLen >= sysDescLen)
201  {
202  //Copy object value
203  osMemcpy(value->octetString, sysDesc, sysDescLen);
204  //Return object length
205  *valueLen = sysDescLen;
206  }
207  else
208  {
209  //Report an error
210  error = ERROR_BUFFER_OVERFLOW;
211  }
212  }
213 
214  //Return status code
215  return error;
216 }
217 
218 
219 /**
220  * @brief Get lldpLocSysCapSupported object value
221  * @param[in] object Pointer to the MIB object descriptor
222  * @param[in] oid Object identifier (object name and instance identifier)
223  * @param[in] oidLen Length of the OID, in bytes
224  * @param[out] value Object value
225  * @param[in,out] valueLen Length of the object value, in bytes
226  * @return Error code
227  **/
228 
230  size_t oidLen, MibVariant *value, size_t *valueLen)
231 {
232  error_t error;
233  uint16_t supportedCap;
234  uint16_t enabledCap;
235 
236  //This object identifies which system capabilities are supported on the
237  //local system
239  &supportedCap, &enabledCap);
240 
241  //Check status code
242  if(!error)
243  {
244  //Each bit in the bitmap corresponds to a given capability
245  if(supportedCap != 0)
246  {
247  //Make sure the buffer is large enough to hold the entire object
248  if(*valueLen >= sizeof(uint8_t))
249  {
250  //Copy object value
251  value->octetString[0] = reverseInt8((uint8_t) supportedCap);
252  //Return object length
253  *valueLen = sizeof(uint8_t);
254  }
255  else
256  {
257  //Report an error
258  error = ERROR_BUFFER_OVERFLOW;
259  }
260  }
261  else
262  {
263  //An empty set means that no enumerated values are set
264  *valueLen = 0;
265  }
266  }
267 
268  //Return status code
269  return error;
270 }
271 
272 
273 /**
274  * @brief Get lldpLocSysCapEnabled object value
275  * @param[in] object Pointer to the MIB object descriptor
276  * @param[in] oid Object identifier (object name and instance identifier)
277  * @param[in] oidLen Length of the OID, in bytes
278  * @param[out] value Object value
279  * @param[in,out] valueLen Length of the object value, in bytes
280  * @return Error code
281  **/
282 
283 error_t lldpMibGetLldpLocSysCapEnabled(const MibObject *object, const uint8_t *oid,
284  size_t oidLen, MibVariant *value, size_t *valueLen)
285 {
286  error_t error;
287  uint16_t supportedCap;
288  uint16_t enabledCap;
289 
290  //This object identifies which system capabilities are enabled on the
291  //local system
293  &supportedCap, &enabledCap);
294 
295  //Check status code
296  if(!error)
297  {
298  //Each bit in the bitmap corresponds to a given capability
299  if(enabledCap != 0)
300  {
301  //Make sure the buffer is large enough to hold the entire object
302  if(*valueLen >= sizeof(uint8_t))
303  {
304  //Copy object value
305  value->octetString[0] = reverseInt8((uint8_t) enabledCap);
306  //Return object length
307  *valueLen = sizeof(uint8_t);
308  }
309  else
310  {
311  //Report an error
312  error = ERROR_BUFFER_OVERFLOW;
313  }
314  }
315  else
316  {
317  //An empty set means that no enumerated values are set
318  *valueLen = 0;
319  }
320  }
321 
322  //Return status code
323  return error;
324 }
325 
326 
327 /**
328  * @brief Get lldpLocPortEntry object value
329  * @param[in] object Pointer to the MIB object descriptor
330  * @param[in] oid Object identifier (object name and instance identifier)
331  * @param[in] oidLen Length of the OID, in bytes
332  * @param[out] value Object value
333  * @param[in,out] valueLen Length of the object value, in bytes
334  * @return Error code
335  **/
336 
337 error_t lldpMibGetLldpLocPortEntry(const MibObject *object, const uint8_t *oid,
338  size_t oidLen, MibVariant *value, size_t *valueLen)
339 {
340  error_t error;
341  size_t n;
342  uint_t lldpLocPortNum;
343 
344  //Point to the instance identifier
345  n = object->oidLen;
346 
347  //lldpLocPortNum is used as instance identifier
348  error = mibDecodeIndex(oid, oidLen, &n, &lldpLocPortNum);
349  //Invalid instance identifier?
350  if(error)
351  return error;
352 
353  //Sanity check
354  if(n != oidLen)
356 
357  //lldpLocPortIdSubtype object?
358  if(osStrcmp(object->name, "lldpLocPortIdSubtype") == 0)
359  {
360  LldpPortIdSubtype portIdSubtype;
361  const uint8_t *portId;
362  size_t portIdLen;
363 
364  //This object indicates the type of port identifier encoding used in
365  //the associated lldpLocPortId object
367  lldpLocPortNum, &portIdSubtype, &portId, &portIdLen);
368 
369  //Check status code
370  if(!error)
371  {
372  //Return object value
373  value->integer = (int32_t) portIdSubtype;
374  }
375  }
376  //lldpLocPortId object?
377  else if(osStrcmp(object->name, "lldpLocPortId") == 0)
378  {
379  LldpPortIdSubtype portIdSubtype;
380  const uint8_t *portId;
381  size_t portIdLen;
382 
383  //This object identifies the port component associated with a given port
384  //in the local system
386  lldpLocPortNum, &portIdSubtype, &portId, &portIdLen);
387 
388  //Check status code
389  if(!error)
390  {
391  //Make sure the buffer is large enough to hold the entire object
392  if(*valueLen >= portIdLen)
393  {
394  //Copy object value
395  osMemcpy(value->octetString, portId, portIdLen);
396  //Return object length
397  *valueLen = portIdLen;
398  }
399  else
400  {
401  //Report an error
402  error = ERROR_BUFFER_OVERFLOW;
403  }
404  }
405  }
406  //lldpLocPortDesc object?
407  else if(osStrcmp(object->name, "lldpLocPortDesc") == 0)
408  {
409  const char_t *portDesc;
410  size_t portDescLen;
411 
412  //This object identifies the station's port description associated with
413  //the local system
415  lldpLocPortNum, &portDesc, &portDescLen);
416 
417  //Check status code
418  if(!error)
419  {
420  //Make sure the buffer is large enough to hold the entire object
421  if(*valueLen >= portDescLen)
422  {
423  //Copy object value
424  osMemcpy(value->octetString, portDesc, portDescLen);
425  //Return object length
426  *valueLen = portDescLen;
427  }
428  else
429  {
430  //Report an error
431  error = ERROR_BUFFER_OVERFLOW;
432  }
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 lldpLocPortEntry 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 
457 error_t lldpMibGetNextLldpLocPortEntry(const MibObject *object, const uint8_t *oid,
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  LldpAgentContext *context;
466 
467  //Initialize variable
468  portNum = 0;
469 
470  //Point to the LLDP agent context
471  context = lldpMibBase.lldpAgentContext;
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  //lldpLocPortNum 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  //lldpLocPortNum 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 lldpLocManAddrEntry 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 
542 error_t lldpMibGetLldpLocManAddrEntry(const MibObject *object, const uint8_t *oid,
543  size_t oidLen, MibVariant *value, size_t *valueLen)
544 {
545  error_t error;
546  size_t n;
547  int_t index;
548  uint_t lldpLocManAddrSubtype;
549  uint8_t lldpLocManAddr[LLDP_MAX_MGMT_ADDR_LEN];
550  size_t lldpLocManAddrLen;
551  LldpAgentContext *context;
552  LldpIfNumSubtype ifNumSubtype;
553  uint32_t ifNum;
554  const uint8_t *addrOid;
555  size_t addrOidLen;
556 
557  //Point to the LLDP agent context
558  context = lldpMibBase.lldpAgentContext;
559  //Make sure the context is valid
560  if(context == NULL)
561  return ERROR_OBJECT_NOT_FOUND;
562 
563  //Point to the instance identifier
564  n = object->oidLen;
565 
566  //lldpLocManAddrSubtype is used as 1st instance identifier
567  error = mibDecodeIndex(oid, oidLen, &n, &lldpLocManAddrSubtype);
568  //Invalid instance identifier?
569  if(error)
570  return error;
571 
572  //lldpLocManAddr is used as 2nd instance identifier
573  error = mibDecodeOctetString(oid, oidLen, &n, lldpLocManAddr,
574  LLDP_MAX_MGMT_ADDR_LEN, &lldpLocManAddrLen, FALSE);
575  //Invalid instance identifier?
576  if(error)
577  return error;
578 
579  //Sanity check
580  if(n != oidLen)
582 
583  //Search the local system MIB for a matching address
584  index = lldpMgmtFindLocalMgmtAddr(context, lldpLocManAddrSubtype,
585  lldpLocManAddr, lldpLocManAddrLen);
586  //No matching address found?
587  if(index < 0)
589 
590  //Extract the management address from the local system MIB
591  error = lldpMgmtGetLocalMgmtAddr(context, index, NULL, NULL, NULL,
592  &ifNumSubtype, &ifNum, &addrOid, &addrOidLen);
593  //No matching address found?
594  if(error)
596 
597  //lldpLocManAddrLen object?
598  if(osStrcmp(object->name, "lldpLocManAddrLen") == 0)
599  {
600  //This objects indicates the total length of the management address
601  //subtype and the management address fields in LLDPDUs transmitted by
602  //the local LLDP agent
603  //Get object value
604  value->integer = lldpLocManAddrLen + 1;
605  }
606  //lldpLocManAddrIfSubtype object?
607  else if(osStrcmp(object->name, "lldpLocManAddrIfSubtype") == 0)
608  {
609  //This object identifies the interface numbering method used for defining
610  //the interface number, associated with the local system
611  if(ifNumSubtype == LLDP_IF_NUM_SUBTYPE_IF_INDEX)
612  {
613  //interface identifier based on the ifIndex MIB object
615  }
616  else if(ifNumSubtype == LLDP_IF_NUM_SUBTYPE_SYS_PORT_NUM)
617  {
618  //interface identifier based on the system port numbering convention
620  }
621  else
622  {
623  //The interface is not known
625  }
626  }
627  //lldpLocManAddrIfId object?
628  else if(osStrcmp(object->name, "lldpLocManAddrIfId") == 0)
629  {
630  //This object identifies the interface number regarding the management
631  //address component associated with the local system
632  value->integer = ifNum;
633  }
634  //lldpLocManAddrOID object?
635  else if(osStrcmp(object->name, "lldpLocManAddrOID") == 0)
636  {
637  //Make sure the buffer is large enough to hold the entire object
638  if(*valueLen >= addrOidLen)
639  {
640  //Copy object value
641  osMemcpy(value->octetString, addrOid, addrOidLen);
642  //Return object length
643  *valueLen = addrOidLen;
644  }
645  else
646  {
647  //Report an error
648  error = ERROR_BUFFER_OVERFLOW;
649  }
650  }
651  //Unknown object?
652  else
653  {
654  //The specified object does not exist
655  error = ERROR_OBJECT_NOT_FOUND;
656  }
657 
658  //Return status code
659  return error;
660 }
661 
662 
663 /**
664  * @brief Get next lldpLocManAddrEntry object
665  * @param[in] object Pointer to the MIB object descriptor
666  * @param[in] oid Object identifier
667  * @param[in] oidLen Length of the OID, in bytes
668  * @param[out] nextOid OID of the next object in the MIB
669  * @param[out] nextOidLen Length of the next object identifier, in bytes
670  * @return Error code
671  **/
672 
674  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
675 {
676  error_t error;
677  size_t n;
678  bool_t acceptable;
679  LldpTlv tlv;
680  LldpAgentContext *context;
681  const LldpMgmtAddrTlv1 *addr;
682  const LldpMgmtAddrTlv1 *nextAddr;
683 
684  //Initialize variables
685  nextAddr = NULL;
686 
687  //Point to the LLDP agent context
688  context = lldpMibBase.lldpAgentContext;
689  //Make sure the context is valid
690  if(context == NULL)
691  return ERROR_OBJECT_NOT_FOUND;
692 
693  //Make sure the buffer is large enough to hold the OID prefix
694  if(*nextOidLen < object->oidLen)
695  return ERROR_BUFFER_OVERFLOW;
696 
697  //Copy OID prefix
698  osMemcpy(nextOid, object->oid, object->oidLen);
699 
700  //Extract the first TLV
701  error = lldpGetFirstTlv(&context->txInfo, &tlv);
702 
703  //Loop through the local system MIB
704  while(!error)
705  {
706  //Check TLV type
707  if(tlv.type == LLDP_TLV_TYPE_MGMT_ADDR)
708  {
709  //Decode the contents of the Management Address TLV
710  error = lldpDecodeMgmtAddrTlv(tlv.value, tlv.length, &addr, NULL);
711  //Malformed TLV?
712  if(error)
713  {
714  break;
715  }
716 
717  //Append the instance identifier to the OID prefix
718  n = object->oidLen;
719 
720  //lldpLocManAddrSubtype is used as 1st instance identifier
721  error = mibEncodeIndex(nextOid, *nextOidLen, &n,
722  addr->mgmtAddrSubtype);
723  //Invalid instance identifier?
724  if(error)
725  return error;
726 
727  //lldpLocManAddr is used as 5th instance identifier
728  error = mibEncodeOctetString(nextOid, *nextOidLen, &n,
729  addr->mgmtAddr, addr->mgmtAddrLen - 1, FALSE);
730  //Invalid instance identifier?
731  if(error)
732  return error;
733 
734  //Check whether the resulting object identifier lexicographically
735  //follows the specified OID
736  if(oidComp(nextOid, n, oid, oidLen) > 0)
737  {
738  //Perform lexicographic comparison
739  if(nextAddr == NULL)
740  {
741  acceptable = TRUE;
742  }
743  else if(addr->mgmtAddrSubtype < nextAddr->mgmtAddrSubtype)
744  {
745  acceptable = TRUE;
746  }
747  else if(addr->mgmtAddrSubtype > nextAddr->mgmtAddrSubtype)
748  {
749  acceptable = FALSE;
750  }
751  else if(addr->mgmtAddrLen < nextAddr->mgmtAddrLen)
752  {
753  acceptable = TRUE;
754  }
755  else if(addr->mgmtAddrLen > nextAddr->mgmtAddrLen)
756  {
757  acceptable = FALSE;
758  }
759  else if(osMemcmp(addr->mgmtAddr, nextAddr->mgmtAddr,
760  nextAddr->mgmtAddrLen) < 0)
761  {
762  acceptable = TRUE;
763  }
764  else
765  {
766  acceptable = FALSE;
767  }
768 
769  //Save the closest object identifier that follows the specified
770  //OID in lexicographic order
771  if(acceptable)
772  {
773  nextAddr = addr;
774  }
775  }
776  }
777 
778  //Extract the next TLV
779  error = lldpGetNextTlv(&context->txInfo, &tlv);
780  }
781 
782  //The specified OID does not lexicographically precede the name
783  //of some object?
784  if(nextAddr == NULL)
785  return ERROR_OBJECT_NOT_FOUND;
786 
787  //Append the instance identifier to the OID prefix
788  n = object->oidLen;
789 
790  //lldpLocManAddrSubtype is used as 1st instance identifier
791  error = mibEncodeIndex(nextOid, *nextOidLen, &n, nextAddr->mgmtAddrSubtype);
792  //Invalid instance identifier?
793  if(error)
794  return error;
795 
796  //lldpLocManAddr is used as 5th instance identifier
797  error = mibEncodeOctetString(nextOid, *nextOidLen, &n, nextAddr->mgmtAddr,
798  nextAddr->mgmtAddrLen - 1, FALSE);
799  //Invalid instance identifier?
800  if(error)
801  return error;
802 
803  //Save the length of the resulting object identifier
804  *nextOidLen = n;
805  //Next object found
806  return NO_ERROR;
807 }
808 
809 #endif
error_t lldpGetFirstTlv(LldpDataUnit *lldpdu, LldpTlv *tlv)
Extract the first TLV from an LLDPDU.
Definition: lldp_tlv.c:247
error_t lldpMibGetNextLldpLocPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next lldpLocPortEntry object.
uint8_t type
Definition: lldp_tlv.h:202
int bool_t
Definition: compiler_port.h:53
uint8_t portId[]
Definition: lldp_tlv.h:254
uint16_t enabledCap
Definition: lldp_tlv.h:275
uint8_t chassisId[]
Definition: lldp_tlv.h:243
signed int int_t
Definition: compiler_port.h:49
LLDP MIB module implementation (lldpLocalSystemData subtree)
error_t lldpMibGetLldpLocSysCapSupported(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocSysCapSupported object value.
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
error_t lldpMgmtGetLocalChassisId(LldpAgentContext *context, LldpChassisIdSubtype *chassisIdSubtype, const uint8_t **chassisId, size_t *chassisIdLen)
Extract chassis ID from local system MIB.
Definition: lldp_mgmt.c:694
OID (Object Identifier)
error_t lldpMibGetNextLldpLocManAddrEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next lldpLocManAddrEntry object.
error_t lldpMibGetLldpLocChassisIdSubtype(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocChassisIdSubtype object value.
#define TRUE
Definition: os_port.h:50
error_t lldpMibGetLldpLocSysName(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocSysName object value.
@ LLDP_TLV_TYPE_MGMT_ADDR
Management Address.
Definition: lldp_tlv.h:101
error_t lldpGetNextTlv(LldpDataUnit *lldpdu, LldpTlv *tlv)
Extract the next TLV from an LLDPDU.
Definition: lldp_tlv.c:264
error_t lldpMgmtGetLocalPortDesc(LldpAgentContext *context, uint_t portIndex, const char_t **portDesc, size_t *portDescLen)
Extract port description from local system MIB.
Definition: lldp_mgmt.c:817
#define osMemcmp(p1, p2, length)
Definition: os_port.h:153
#define osStrcmp(s1, s2)
Definition: os_port.h:171
LldpAgentContext * lldpAgentContext
error_t lldpMgmtGetLocalSysDesc(LldpAgentContext *context, const char_t **sysDesc, size_t *sysDescLen)
Extract system description from local system MIB.
Definition: lldp_mgmt.c:919
LldpPortIdSubtype
Port ID subtypes.
Definition: lldp_tlv.h:128
@ LLDP_IF_NUM_SUBTYPE_SYS_PORT_NUM
System port number.
Definition: lldp_tlv.h:178
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
@ LLDP_MIB_MAN_ADDR_IF_SUBTYPE_UNKNOWN
Unknown.
#define FALSE
Definition: os_port.h:46
LldpIfNumSubtype
Interface numbering subtypes.
Definition: lldp_tlv.h:175
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
error_t lldpMgmtGetLocalMgmtAddr(LldpAgentContext *context, uint_t index, LldpMgmtAddrSubtype *mgmtAddrSubtype, const uint8_t **mgmtAddr, size_t *mgmtAddrLen, LldpIfNumSubtype *ifNumSubtype, uint32_t *ifNum, const uint8_t **oid, size_t *oidLen)
Extract management address from local system MIB.
Definition: lldp_mgmt.c:1116
error_t
Error codes.
Definition: error.h:43
int_t lldpMgmtFindLocalMgmtAddr(LldpAgentContext *context, uint8_t mgmtAddrSubtype, const uint8_t *mgmtAddr, size_t mgmtAddrLen)
Search the local system MIB for a given management address.
Definition: lldp_mgmt.c:1023
@ ERROR_INSTANCE_NOT_FOUND
Definition: error.h:257
error_t lldpMibGetLldpLocChassisId(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocChassisId object value.
LLDP MIB module.
General definitions for cryptographic algorithms.
error_t lldpMgmtGetLocalSysName(LldpAgentContext *context, const char_t **sysName, size_t *sysNameLen)
Extract system name from local system MIB.
Definition: lldp_mgmt.c:871
error_t lldpMibGetLldpLocPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocPortEntry object value.
@ LLDP_MIB_MAN_ADDR_IF_SUBTYPE_IF_INDEX
Interface index.
error_t lldpMibGetLldpLocSysDesc(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocSysDesc object value.
@ LLDP_MIB_MAN_ADDR_IF_SUBTYPE_SYS_PORT_NUM
System port number.
char char_t
Definition: compiler_port.h:48
error_t lldpMgmtGetLocalSysCap(LldpAgentContext *context, uint16_t *supportedCap, uint16_t *enabledCap)
Extract system capabilities from local system MIB.
Definition: lldp_mgmt.c:968
@ LLDP_IF_NUM_SUBTYPE_IF_INDEX
Interface index.
Definition: lldp_tlv.h:177
error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos, const uint8_t *data, size_t dataLen, bool_t implied)
Encode instance identifier (octet string)
Definition: mib_common.c:182
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
size_t length
Definition: lldp_tlv.h:203
@ ERROR_OBJECT_NOT_FOUND
Definition: error.h:256
error_t lldpDecodeMgmtAddrTlv(const uint8_t *value, size_t length, const LldpMgmtAddrTlv1 **mgmtAddr1, const LldpMgmtAddrTlv2 **mgmtAddr2)
Decode the contents of a Management Address TLV.
Definition: lldp_tlv.c:380
uint32_t ifNum
Definition: lldp_tlv.h:298
#define MibObject
Definition: mib_common.h:46
uint8_t value[]
Definition: tcp.h:369
error_t lldpMibGetLldpLocSysCapEnabled(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocSysCapEnabled object value.
uint8_t oidLen
Definition: lldp_tlv.h:299
LldpChassisIdSubtype
Chassis ID subtypes.
Definition: lldp_tlv.h:111
uint8_t reverseInt8(uint8_t value)
Reverse bit order in a byte.
Definition: cpu_endian.c:90
#define LldpAgentContext
Definition: lldp.h:40
Management of the LLDP agent.
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
LldpMibBase lldpMibBase
LLDP MIB base.
Ipv4Addr addr
Definition: nbns_common.h:123
error_t lldpMgmtGetLocalPortId(LldpAgentContext *context, uint_t portIndex, LldpPortIdSubtype *portIdSubtype, const uint8_t **portId, size_t *portIdLen)
Extract port ID from local system MIB.
Definition: lldp_mgmt.c:752
MibVariant
Definition: mib_common.h:196
#define LLDP_MAX_MGMT_ADDR_LEN
Definition: lldp_tlv.h:74
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos, uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied)
Decode instance identifier (octet string)
Definition: mib_common.c:225
LLDP MIB module implementation.
LldpMgmtAddrTlv1
Definition: lldp_tlv.h:288
TLV structure.
Definition: lldp_tlv.h:200
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
error_t lldpMibGetLldpLocManAddrEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpLocManAddrEntry object value.
ASN.1 (Abstract Syntax Notation One)
uint8_t * value
Definition: lldp_tlv.h:204