lldp_mgmt.c
Go to the documentation of this file.
1 /**
2  * @file lldp_mgmt.c
3  * @brief Management of the LLDP agent
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 LLDP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "lldp/lldp.h"
37 #include "lldp/lldp_mgmt.h"
38 #include "lldp/lldp_misc.h"
39 #include "lldp/lldp_debug.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (LLDP_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Acquire exclusive access to the LLDP agent context
48  * @param[in] context Pointer to the LLDP agent context
49  **/
50 
52 {
53  //Acquire exclusive access
54  osAcquireMutex(&context->mutex);
55 }
56 
57 
58 /**
59  * @brief Release exclusive access to the LLDP agent context
60  * @param[in] context Pointer to the LLDP agent context
61  **/
62 
64 {
65  //Release exclusive access
66  osReleaseMutex(&context->mutex);
67 }
68 
69 
70 /**
71  * @brief Set transmit interval
72  * @param[in] context Pointer to the LLDP agent context
73  * @param[in] msgTxInterval Time interval between successive transmit cycles,
74  * in seconds
75  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
76  * value and commits the change if the value is valid. If FALSE, the LLDP agent
77  * only performs the verification and does not take any further action
78  * @return Error code
79  **/
80 
82  uint_t msgTxInterval, bool_t commit)
83 {
84 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
85  //Make sure the LLDP agent context is valid
86  if(context == NULL)
87  return ERROR_WRITE_FAILED;
88 
89  //Check the value of the parameter
90  if(msgTxInterval < LLDP_MIN_MSG_TX_INTERVAL ||
91  msgTxInterval > LLDP_MAX_MSG_TX_INTERVAL)
92  {
93  return ERROR_WRONG_VALUE;
94  }
95 
96  //Commit phase?
97  if(commit)
98  {
99  //Save the value of the parameter
100  context->msgTxInterval = msgTxInterval;
101 
102  //The somethingChangedLocal flag must be set whenever the value of an
103  //object has changed in the local system MIB
104  lldpSomethingChangedLocal(context);
105  }
106 
107  //Successful processing
108  return NO_ERROR;
109 #else
110  //TX mode is not implemented
111  return ERROR_WRITE_FAILED;
112 #endif
113 }
114 
115 
116 /**
117  * @brief Set transmit hold multiplier
118  * @param[in] context Pointer to the LLDP agent context
119  * @param[in] msgTxHold Multiplier on the msgTxInterval that determines the
120  * actual TTL value used in an LLDPDU
121  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
122  * value and commits the change if the value is valid. If FALSE, the LLDP agent
123  * only performs the verification and does not take any further action
124  * @return Error code
125  **/
126 
128  bool_t commit)
129 {
130 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
131  //Make sure the LLDP agent context is valid
132  if(context == NULL)
133  return ERROR_WRITE_FAILED;
134 
135  //Check the value of the parameter
136  if(msgTxHold < LLDP_MIN_MSG_TX_HOLD ||
137  msgTxHold > LLDP_MAX_MSG_TX_HOLD)
138  {
139  return ERROR_WRONG_VALUE;
140  }
141 
142  //Commit phase?
143  if(commit)
144  {
145  //Save the value of the parameter
146  context->msgTxHold = msgTxHold;
147 
148  //The somethingChangedLocal flag must be set whenever the value of an
149  //object has changed in the local system MIB
150  lldpSomethingChangedLocal(context);
151  }
152 
153  //Successful processing
154  return NO_ERROR;
155 #else
156  //TX mode is not implemented
157  return ERROR_WRITE_FAILED;
158 #endif
159 }
160 
161 
162 /**
163  * @brief Set re-initialization delay
164  * @param[in] context Pointer to the LLDP agent context
165  * @param[in] reinitDelay Delay before re-initialization will be attempted
166  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
167  * value and commits the change if the value is valid. If FALSE, the LLDP agent
168  * only performs the verification and does not take any further action
169  * @return Error code
170  **/
171 
173  bool_t commit)
174 {
175 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
176  //Make sure the LLDP agent context is valid
177  if(context == NULL)
178  return ERROR_WRITE_FAILED;
179 
180  //Check the value of the parameter
181  if(reinitDelay < LLDP_MIN_REINIT_DELAY ||
182  reinitDelay > LLDP_MAX_REINIT_DELAY)
183  {
184  return ERROR_WRONG_VALUE;
185  }
186 
187  //Commit phase?
188  if(commit)
189  {
190  //Save the value of the parameter
191  context->reinitDelay = reinitDelay;
192  }
193 
194  //Successful processing
195  return NO_ERROR;
196 #else
197  //TX mode is not implemented
198  return ERROR_WRITE_FAILED;
199 #endif
200 }
201 
202 
203 /**
204  * @brief Set transmit delay
205  * @param[in] context Pointer to the LLDP agent context
206  * @param[in] txDelay Delay between successive LLDP frame transmissions
207  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
208  * value and commits the change if the value is valid. If FALSE, the LLDP agent
209  * only performs the verification and does not take any further action
210  * @return Error code
211  **/
212 
214  bool_t commit)
215 {
216 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
217  //Make sure the LLDP agent context is valid
218  if(context == NULL)
219  return ERROR_WRITE_FAILED;
220 
221  //Check the value of the parameter
222  if(txDelay < LLDP_MIN_TX_DELAY ||
223  txDelay > LLDP_MAX_TX_DELAY)
224  {
225  return ERROR_WRONG_VALUE;
226  }
227 
228  //Commit phase?
229  if(commit)
230  {
231  //Save the value of the parameter
232  context->txDelay = txDelay;
233  }
234 
235  //Successful processing
236  return NO_ERROR;
237 #else
238  //TX mode is not implemented
239  return ERROR_WRITE_FAILED;
240 #endif
241 }
242 
243 
244 /**
245  * @brief Set notification interval
246  * @param[in] context Pointer to the LLDP agent context
247  * @param[in] notificationInterval Notification interval
248  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
249  * value and commits the change if the value is valid. If FALSE, the LLDP agent
250  * only performs the verification and does not take any further action
251  * @return Error code
252  **/
253 
255  uint_t notificationInterval, bool_t commit)
256 {
257 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
258  //Make sure the LLDP agent context is valid
259  if(context == NULL)
260  return ERROR_WRITE_FAILED;
261 
262  //Check the value of the parameter
263  if(notificationInterval < LLDP_MIN_NOTIFICATION_INTERVAL ||
264  notificationInterval > LLDP_MAX_NOTIFICATION_INTERVAL)
265  {
266  return ERROR_WRONG_VALUE;
267  }
268 
269  //Commit phase?
270  if(commit)
271  {
272  //Save the value of the parameter
273  context->notificationInterval = notificationInterval;
274  }
275 
276  //Successful processing
277  return NO_ERROR;
278 #else
279  //RX mode is not implemented
280  return ERROR_WRITE_FAILED;
281 #endif
282 }
283 
284 
285 /**
286  * @brief Set administrative status
287  * @param[in] context Pointer to the LLDP agent context
288  * @param[in] portIndex Port index
289  * @param[in] adminStatus The administrative status indicates whether or not
290  * the local LLDP agent is enabled
291  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
292  * value and commits the change if the value is valid. If FALSE, the LLDP agent
293  * only performs the verification and does not take any further action
294  * @return Error code
295  **/
296 
298  uint_t portIndex, LldpAdminStatus adminStatus, bool_t commit)
299 {
300 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
302 
303  //Make sure the LLDP agent context is valid
304  if(context == NULL)
305  return ERROR_WRITE_FAILED;
306 
307  //Invalid port index?
308  if(portIndex < 1 || portIndex > context->numPorts)
309  return ERROR_INVALID_PORT;
310 
311  //Check the value of the parameter
312  if(adminStatus != LLDP_ADMIN_STATUS_DISABLED &&
313  adminStatus != LLDP_ADMIN_STATUS_ENABLED_TX_ONLY &&
314  adminStatus != LLDP_ADMIN_STATUS_ENABLED_RX_ONLY &&
315  adminStatus != LLDP_ADMIN_STATUS_ENABLED_TX_RX)
316  {
317  return ERROR_WRONG_VALUE;
318  }
319 
320  //Point to the port that matches the specified port index
321  port = &context->ports[portIndex - 1];
322 
323  //Commit phase?
324  if(commit)
325  {
326  //Save the value of the parameter
327  port->adminStatus = adminStatus;
328 
329  //The somethingChangedLocal flag must be set whenever the value of an
330  //object has changed in the local system MIB
331  lldpSomethingChangedLocal(context);
332  }
333 
334  //Successful processing
335  return NO_ERROR;
336 #else
337  //TX mode is not implemented
338  return ERROR_WRITE_FAILED;
339 #endif
340 }
341 
342 
343 /**
344  * @brief Enable or disable notifications
345  * @param[in] context Pointer to the LLDP agent context
346  * @param[in] portIndex Port index
347  * @param[in] notificationEnable This parameter controls whether or not
348  * notifications from the agent are enabled
349  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
350  * value and commits the change if the value is valid. If FALSE, the LLDP agent
351  * only performs the verification and does not take any further action
352  * @return Error code
353  **/
354 
356  uint_t portIndex, bool_t notificationEnable, bool_t commit)
357 {
358 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
360 
361  //Make sure the LLDP agent context is valid
362  if(context == NULL)
363  return ERROR_WRITE_FAILED;
364 
365  //Invalid port index?
366  if(portIndex < 1 || portIndex > context->numPorts)
367  return ERROR_INVALID_PORT;
368 
369  //Point to the port that matches the specified port index
370  port = &context->ports[portIndex - 1];
371 
372  //Commit phase?
373  if(commit)
374  {
375  //Save the value of the parameter
376  port->notificationEnable = notificationEnable;
377  }
378 
379  //Successful processing
380  return NO_ERROR;
381 #else
382  //RX mode is not implemented
383  return ERROR_WRITE_FAILED;
384 #endif
385 }
386 
387 
388 /**
389  * @brief Set the list of TLVs enabled for transmission
390  * @param[in] context Pointer to the LLDP agent context
391  * @param[in] portIndex Port index
392  * @param[in] mask Bit-map indicating the TLVs enabled for transmission
393  * @param[in] commit If this flag is TRUE, the LLDP agent verifies the parameter
394  * value and commits the change if the value is valid. If FALSE, the LLDP agent
395  * only performs the verification and does not take any further action
396  * @return Error code
397  **/
398 
400  uint8_t mask, bool_t commit)
401 {
402 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
404 
405  //Make sure the LLDP agent context is valid
406  if(context == NULL)
407  return ERROR_WRITE_FAILED;
408 
409  //Invalid port index?
410  if(portIndex < 1 || portIndex > context->numPorts)
411  return ERROR_INVALID_PORT;
412 
413  //Point to the port that matches the specified port index
414  port = &context->ports[portIndex - 1];
415 
416  //Commit phase?
417  if(commit)
418  {
419  //Each bit in the bitmap corresponds to a TLV type associated with a
420  //specific optional TLV
421  port->basicTlvFilter = mask & LLDP_BASIC_TLV_FILTER_ALL;
422 
423  //The somethingChangedLocal flag must be set whenever the value of an
424  //object has changed in the local system MIB
425  lldpSomethingChangedLocal(context);
426  }
427 
428  //Successful processing
429  return NO_ERROR;
430 #else
431  //TX mode is not implemented
432  return ERROR_WRITE_FAILED;
433 #endif
434 }
435 
436 
437 /**
438  * @brief Get transmit interval
439  * @param[in] context Pointer to the LLDP agent context
440  * @param[out] msgTxInterval Time interval between successive transmit cycles,
441  * in seconds
442  * @return Error code
443  **/
444 
446  uint_t *msgTxInterval)
447 {
448 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
449  //Check parameters
450  if(context == NULL || msgTxInterval == NULL)
451  return ERROR_READ_FAILED;
452 
453  //Retrieve the current value of the parameter
454  *msgTxInterval = context->msgTxInterval;
455 
456  //Successful processing
457  return NO_ERROR;
458 #else
459  //TX mode is not implemented
460  return ERROR_READ_FAILED;
461 #endif
462 }
463 
464 
465 /**
466  * @brief Get transmit hold multiplier
467  * @param[in] context Pointer to the LLDP agent context
468  * @param[out] msgTxHold Multiplier on the msgTxInterval that determines the
469  * actual TTL value used in an LLDPDU
470  * @return Error code
471  **/
472 
474 {
475 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
476  //Check parameters
477  if(context == NULL || msgTxHold == NULL)
478  return ERROR_READ_FAILED;
479 
480  //Retrieve the current value of the parameter
481  *msgTxHold = context->msgTxHold;
482 
483  //Successful processing
484  return NO_ERROR;
485 #else
486  //TX mode is not implemented
487  return ERROR_READ_FAILED;
488 #endif
489 }
490 
491 
492 /**
493  * @brief Get re-initialization delay
494  * @param[in] context Pointer to the LLDP agent context
495  * @param[out] reinitDelay Delay before re-initialization will be attempted
496  * @return Error code
497  **/
498 
500 {
501 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
502  //Check parameters
503  if(context == NULL || reinitDelay == NULL)
504  return ERROR_READ_FAILED;
505 
506  //Retrieve the current value of the parameter
507  *reinitDelay = context->reinitDelay;
508 
509  //Successful processing
510  return NO_ERROR;
511 #else
512  //TX mode is not implemented
513  return ERROR_READ_FAILED;
514 #endif
515 }
516 
517 
518 /**
519  * @brief Get transmit delay
520  * @param[in] context Pointer to the LLDP agent context
521  * @param[out] txDelay Delay between successive LLDP frame transmissions
522  * @return Error code
523  **/
524 
526 {
527 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
528  //Check parameters
529  if(context == NULL || txDelay == NULL)
530  return ERROR_READ_FAILED;
531 
532  //Retrieve the current value of the parameter
533  *txDelay = context->txDelay;
534 
535  //Successful processing
536  return NO_ERROR;
537 #else
538  //TX mode is not implemented
539  return ERROR_READ_FAILED;
540 #endif
541 }
542 
543 
544 /**
545  * @brief Get notification interval
546  * @param[in] context Pointer to the LLDP agent context
547  * @param[out] notificationInterval Notification interval
548  * @return Error code
549  **/
550 
552  uint_t *notificationInterval)
553 {
554 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
555  //Check parameters
556  if(context == NULL || notificationInterval == NULL)
557  return ERROR_READ_FAILED;
558 
559  //Retrieve the current value of the parameter
560  *notificationInterval = context->notificationInterval;
561 
562  //Successful processing
563  return NO_ERROR;
564 #else
565  //RX mode is not implemented
566  return ERROR_READ_FAILED;
567 #endif
568 }
569 
570 
571 /**
572  * @brief Get administrative status
573  * @param[in] context Pointer to the LLDP agent context
574  * @param[in] portIndex Port index
575  * @param[out] adminStatus The administrative status indicates whether or not
576  * the local LLDP agent is enabled
577  * @return Error code
578  **/
579 
581  uint_t portIndex, LldpAdminStatus *adminStatus)
582 {
583 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
585 
586  //Check parameters
587  if(context == NULL || adminStatus == NULL)
588  return ERROR_READ_FAILED;
589 
590  //Invalid port index?
591  if(portIndex < 1 || portIndex > context->numPorts)
592  return ERROR_INVALID_PORT;
593 
594  //Point to the port that matches the specified port index
595  port = &context->ports[portIndex - 1];
596 
597  //Retrieve the current value of the parameter
598  *adminStatus = port->adminStatus;
599 
600  //Successful processing
601  return NO_ERROR;
602 #else
603  //TX mode is not implemented
604  return ERROR_READ_FAILED;
605 #endif
606 }
607 
608 
609 /**
610  * @brief Check whether notifications are enabled or disabled
611  * @param[in] context Pointer to the LLDP agent context
612  * @param[in] portIndex Port index
613  * @param[out] notificationEnable This parameter controls whether or not
614  * notifications from the agent are enabled
615  * @return Error code
616  **/
617 
619  uint_t portIndex, bool_t *notificationEnable)
620 {
621 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
623 
624  //Make sure the LLDP agent context is valid
625  if(context == NULL)
626  return ERROR_WRITE_FAILED;
627 
628  //Invalid port index?
629  if(portIndex < 1 || portIndex > context->numPorts)
630  return ERROR_INVALID_PORT;
631 
632  //Point to the port that matches the specified port index
633  port = &context->ports[portIndex - 1];
634 
635  //Retrieve the current value of the parameter
636  *notificationEnable = port->notificationEnable;
637 
638  //Successful processing
639  return NO_ERROR;
640 #else
641  //RX mode is not implemented
642  return ERROR_READ_FAILED;
643 #endif
644 }
645 
646 
647 /**
648  * @brief Get the list of TLVs enabled for transmission
649  * @param[in] context Pointer to the LLDP agent context
650  * @param[in] portIndex Port index
651  * @param[out] mibBasicTlvsTxEnable Bit-map indicating the TLVs enabled for
652  * transmission
653  * @return Error code
654  **/
655 
657  uint_t portIndex, uint8_t *mibBasicTlvsTxEnable)
658 {
659 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
661 
662  //Check parameters
663  if(context == NULL || mibBasicTlvsTxEnable == NULL)
664  return ERROR_READ_FAILED;
665 
666  //Invalid port index?
667  if(portIndex < 1 || portIndex > context->numPorts)
668  return ERROR_INVALID_PORT;
669 
670  //Point to the port that matches the specified port index
671  port = &context->ports[portIndex - 1];
672 
673  //Retrieve the current value of the parameter
674  *mibBasicTlvsTxEnable = port->basicTlvFilter;
675 
676  //Successful processing
677  return NO_ERROR;
678 #else
679  //TX mode is not implemented
680  return ERROR_READ_FAILED;
681 #endif
682 }
683 
684 
685 /**
686  * @brief Extract chassis ID from local system MIB
687  * @param[in] context Pointer to the LLDP agent context
688  * @param[out] chassisIdSubtype Type of identifier used for the chassis
689  * @param[out] chassisId Administratively assigned name that identifies the chassis
690  * @param[out] chassisIdLen Length of the chassis ID, in bytes
691  * @return Error code
692  **/
693 
695  LldpChassisIdSubtype *chassisIdSubtype, const uint8_t **chassisId,
696  size_t *chassisIdLen)
697 {
698 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
699  error_t error;
700  size_t n;
701  const uint8_t *p;
702  const LldpChassisIdTlv *tlv;
703 
704  //Check parameters
705  if(context == NULL || chassisIdSubtype == NULL || chassisId == NULL ||
706  chassisIdLen == NULL)
707  {
708  return ERROR_READ_FAILED;
709  }
710 
711  //Search the local system MIB for the Chassis ID TLV
712  error = lldpGetTlv(&context->txInfo, LLDP_TLV_TYPE_CHASSIS_ID, 0, &p, &n);
713 
714  //Chassis ID TLV found?
715  if(!error && n >= sizeof(LldpChassisIdTlv))
716  {
717  //Point to the Chassis ID TLV
718  tlv = (const LldpChassisIdTlv *) p;
719 
720  //Extract the chassis ID from the local system MIB
721  *chassisIdSubtype = (LldpChassisIdSubtype) tlv->chassisIdSubtype;
722  *chassisId = tlv->chassisId;
723  *chassisIdLen = n - sizeof(LldpChassisIdTlv);
724  }
725  else
726  {
727  //The Chassis ID TLV is not present
728  *chassisIdSubtype = LLDP_CHASSIS_ID_SUBTYPE_RESERVED;
729  *chassisId = NULL;
730  *chassisIdLen = 0;
731  }
732 
733  //Successful processing
734  return NO_ERROR;
735 #else
736  //TX mode is not implemented
737  return ERROR_READ_FAILED;
738 #endif
739 }
740 
741 
742 /**
743  * @brief Extract port ID from local system MIB
744  * @param[in] context Pointer to the LLDP agent context
745  * @param[in] portIndex Port index
746  * @param[out] portIdSubtype Type of identifier used for the port
747  * @param[out] portId Administratively assigned name that identifies the port
748  * @param[out] portIdLen Length of the port ID, in bytes
749  * @return Error code
750  **/
751 
753  LldpPortIdSubtype *portIdSubtype, const uint8_t **portId,
754  size_t *portIdLen)
755 {
756 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
757  error_t error;
758  size_t n;
759  const uint8_t *p;
761  const LldpPortIdTlv *tlv;
762 
763  //Check parameters
764  if(context == NULL || portIdSubtype == NULL || portId == NULL ||
765  portIdLen == NULL)
766  {
767  return ERROR_READ_FAILED;
768  }
769 
770  //Invalid port index?
771  if(portIndex < 1 || portIndex > context->numPorts)
772  return ERROR_INVALID_PORT;
773 
774  //Point to the port that matches the specified port index
775  port = &context->ports[portIndex - 1];
776 
777  //Search the local system MIB for the Port ID TLV
778  error = lldpGetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_ID, 0, &p, &n);
779 
780  //Port ID TLV found?
781  if(!error && n >= sizeof(LldpPortIdTlv))
782  {
783  //Point to the Port ID TLV
784  tlv = (const LldpPortIdTlv *) p;
785 
786  //Extract the port ID from the remote systems MIB
787  *portIdSubtype = (LldpPortIdSubtype) tlv->portIdSubtype;
788  *portId = tlv->portId;
789  *portIdLen = n - sizeof(LldpPortIdTlv);
790  }
791  else
792  {
793  //The Port ID TLV is not present
794  *portIdSubtype = LLDP_PORT_ID_SUBTYPE_RESERVED;
795  *portId = NULL;
796  *portIdLen = 0;
797  }
798 
799  //Successful processing
800  return NO_ERROR;
801 #else
802  //TX mode is not implemented
803  return ERROR_READ_FAILED;
804 #endif
805 }
806 
807 
808 /**
809  * @brief Extract port description from local system MIB
810  * @param[in] context Pointer to the LLDP agent context
811  * @param[in] portIndex Port index
812  * @param[out] portDesc Station port's description
813  * @param[out] portDescLen Length of the port description, in bytes
814  * @return Error code
815  **/
816 
818  const char_t **portDesc, size_t *portDescLen)
819 {
820 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
821  error_t error;
822  size_t n;
823  const uint8_t *p;
825 
826  //Check parameters
827  if(context == NULL || portDesc == NULL || portDescLen == NULL)
828  return ERROR_READ_FAILED;
829 
830  //Invalid port index?
831  if(portIndex < 1 || portIndex > context->numPorts)
832  return ERROR_INVALID_PORT;
833 
834  //Point to the port that matches the specified port index
835  port = &context->ports[portIndex - 1];
836 
837  //Search the local system MIB for the Port Description TLV
838  error = lldpGetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_DESC, 0, &p, &n);
839 
840  //Port Description TLV found?
841  if(!error)
842  {
843  //Extract the port description from the local system MIB
844  *portDesc = (const char_t *) p;
845  *portDescLen = n;
846  }
847  else
848  {
849  //The Port Description TLV is not present
850  *portDesc = NULL;
851  *portDescLen = 0;
852  }
853 
854  //Successful processing
855  return NO_ERROR;
856 #else
857  //TX mode is not implemented
858  return ERROR_READ_FAILED;
859 #endif
860 }
861 
862 
863 /**
864  * @brief Extract system name from local system MIB
865  * @param[in] context Pointer to the LLDP agent context
866  * @param[out] sysName System's administratively assigned name
867  * @param[out] sysNameLen Length of the system name, in bytes
868  * @return Error code
869  **/
870 
872  const char_t **sysName, size_t *sysNameLen)
873 {
874 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
875  error_t error;
876  size_t n;
877  const uint8_t *p;
878 
879  //Check parameters
880  if(context == NULL || sysName == NULL || sysNameLen == NULL)
881  {
882  return ERROR_READ_FAILED;
883  }
884 
885  //Search the local system MIB for the System Name TLV
886  error = lldpGetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_NAME, 0, &p, &n);
887 
888  //System Name TLV found?
889  if(!error)
890  {
891  //Extract the system name from the local system MIB
892  *sysName = (const char_t *) p;
893  *sysNameLen = n;
894  }
895  else
896  {
897  //The System Name TLV is not present
898  *sysName = NULL;
899  *sysNameLen = 0;
900  }
901 
902  //Successful processing
903  return NO_ERROR;
904 #else
905  //TX mode is not implemented
906  return ERROR_READ_FAILED;
907 #endif
908 }
909 
910 
911 /**
912  * @brief Extract system description from local system MIB
913  * @param[in] context Pointer to the LLDP agent context
914  * @param[out] sysDesc Textual description of the network entity
915  * @param[out] sysDescLen Length of the system description, in bytes
916  * @return Error code
917  **/
918 
920  const char_t **sysDesc, size_t *sysDescLen)
921 {
922 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
923  error_t error;
924  size_t n;
925  const uint8_t *p;
926 
927  //Check parameters
928  if(context == NULL || sysDesc == NULL ||
929  sysDescLen == NULL)
930  {
931  return ERROR_READ_FAILED;
932  }
933 
934  //Search the local system MIB for the System Description TLV
935  error = lldpGetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_DESC, 0, &p, &n);
936 
937  //System Description TLV found?
938  if(!error)
939  {
940  //Extract the system name from the local system MIB
941  *sysDesc = (const char_t *) p;
942  *sysDescLen = n;
943  }
944  else
945  {
946  //The System Description TLV is not present
947  *sysDesc = NULL;
948  *sysDescLen = 0;
949  }
950 
951  //Successful processing
952  return NO_ERROR;
953 #else
954  //TX mode is not implemented
955  return ERROR_READ_FAILED;
956 #endif
957 }
958 
959 
960 /**
961  * @brief Extract system capabilities from local system MIB
962  * @param[in] context Pointer to the LLDP agent context
963  * @param[out] supportedCap Bit-map of the capabilities supported by the system
964  * @param[out] enabledCap Bit-map of the capabilities currently enabled
965  * @return Error code
966  **/
967 
969  uint16_t *supportedCap, uint16_t *enabledCap)
970 {
971 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
972  error_t error;
973  size_t n;
974  const uint8_t *p;
975  const LldpSysCapTlv *tlv;
976 
977  //Check parameters
978  if(context == NULL || supportedCap == NULL ||
979  enabledCap == NULL)
980  {
981  return ERROR_READ_FAILED;
982  }
983 
984  //Search the local system MIB for the System Capabilities TLV
985  error = lldpGetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_CAP, 0, &p, &n);
986 
987  //System Capabilities TLV found?
988  if(!error && n >= sizeof(LldpChassisIdTlv))
989  {
990  //Point to the System Capabilities TLV
991  tlv = (const LldpSysCapTlv *) p;
992 
993  //Extract capabilities from the local system MIB
994  *supportedCap = ntohs(tlv->supportedCap);
995  *enabledCap = ntohs(tlv->enabledCap);
996  }
997  else
998  {
999  //The System Capabilities TLV is not present
1000  *supportedCap = 0;
1001  *enabledCap = 0;
1002  }
1003 
1004  //Successful processing
1005  return NO_ERROR;
1006 #else
1007  //TX mode is not implemented
1008  return ERROR_READ_FAILED;
1009 #endif
1010 }
1011 
1012 
1013 /**
1014  * @brief Search the local system MIB for a given management address
1015  * @param[in] context Pointer to the LLDP agent context
1016  * @param[in] mgmtAddrSubtype Type of management address
1017  * @param[in] mgmtAddr Octet string indicating a particular management
1018  * address
1019  * @param[in] mgmtAddrLen Length of the management address, in bytes
1020  * @return index Zero-based index corresponding to the management address
1021  **/
1022 
1024  uint8_t mgmtAddrSubtype, const uint8_t *mgmtAddr, size_t mgmtAddrLen)
1025 {
1026 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1027  error_t error;
1028  uint_t k;
1029  int_t index;
1030  LldpTlv tlv;
1031  const LldpMgmtAddrTlv1 *part1;
1032  const LldpMgmtAddrTlv2 *part2;
1033 
1034  //Initialize index
1035  index = -1;
1036 
1037  //Get the index of the first management address
1038  for(k = 0; k < LLDP_MAX_MGMT_ADDRS; k++)
1039  {
1040  //Check whether the current management address is configured
1041  if((context->mgmtAddrMap & (1U << k)) != 0)
1042  {
1043  break;
1044  }
1045  }
1046 
1047  //Extract the first TLV
1048  error = lldpGetFirstTlv(&context->txInfo, &tlv);
1049 
1050  //Loop through the TLVs
1051  while(!error && k < LLDP_MAX_MGMT_ADDRS)
1052  {
1053  //Check TLV type
1054  if(tlv.type == LLDP_TLV_TYPE_MGMT_ADDR)
1055  {
1056  //Decode the contents of the Management Address TLV
1057  error = lldpDecodeMgmtAddrTlv(tlv.value, tlv.length, &part1, &part2);
1058  //Malformed TLV?
1059  if(error)
1060  break;
1061 
1062  //Check the management address against the specified address
1063  if(part1->mgmtAddrSubtype == mgmtAddrSubtype &&
1064  part1->mgmtAddrLen == (mgmtAddrLen + 1) &&
1065  osMemcmp(part1->mgmtAddr, mgmtAddr, mgmtAddrLen) == 0)
1066  {
1067  //A matching address has been found
1068  index = k;
1069  break;
1070  }
1071  else
1072  {
1073  //Get the index of the next management address
1074  for(k++; k < LLDP_MAX_MGMT_ADDRS; k++)
1075  {
1076  //Check whether the current management address is configured
1077  if((context->mgmtAddrMap & (1U << k)) != 0)
1078  {
1079  break;
1080  }
1081  }
1082  }
1083  }
1084 
1085  //Extract the next TLV
1086  error = lldpGetNextTlv(&context->txInfo, &tlv);
1087  }
1088 
1089  //Return the index corresponding to the management address
1090  return index;
1091 #else
1092  //TX mode is not implemented
1093  return -1;
1094 #endif
1095 }
1096 
1097 
1098 /**
1099  * @brief Extract management address from local system MIB
1100  * @param[in] context Pointer to the LLDP agent context
1101  * @param[in] index Zero-based index identifying a management address
1102  * @param[out] mgmtAddrSubtype Type of management address
1103  * @param[out] mgmtAddr Octet string indicating a particular management
1104  * address
1105  * @param[out] mgmtAddrLen Length of the management address, in bytes
1106  * @param[out] ifNumSubtype Numbering method used for defining the interface
1107  * number
1108  * @param[out] ifNum Number within the system that identifies the specific
1109  * interface associated with this management address
1110  * @param[out] oid OID that identifies the type of hardware component or
1111  * protocol entity associated with the indicated management address
1112  * @param[out] oidLen Length of the OID, in bytes
1113  * @return Error code
1114  **/
1115 
1117  LldpMgmtAddrSubtype *mgmtAddrSubtype, const uint8_t **mgmtAddr,
1118  size_t *mgmtAddrLen, LldpIfNumSubtype *ifNumSubtype, uint32_t *ifNum,
1119  const uint8_t **oid, size_t *oidLen)
1120 {
1121 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1122  error_t error;
1123  uint_t i;
1124  uint_t k;
1125  size_t n;
1126  const uint8_t *p;
1127  const LldpMgmtAddrTlv1 *part1;
1128  const LldpMgmtAddrTlv2 *part2;
1129 
1130  //Make sure the LLDP agent context is valid
1131  if(context == NULL)
1132  {
1133  return ERROR_READ_FAILED;
1134  }
1135 
1136  //Check index value
1137  if(index > LLDP_MAX_MGMT_ADDRS)
1138  {
1139  return ERROR_READ_FAILED;
1140  }
1141 
1142  //The local system MIB may contain more than one Management Address TLV
1143  for(i = 0, k = 0; i < index; i++)
1144  {
1145  //Check whether the current management address is configured
1146  if((context->mgmtAddrMap & (1U << i)) != 0)
1147  {
1148  k++;
1149  }
1150  }
1151 
1152  //Extract the management address from the local system MIB
1153  error = lldpGetTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k, &p, &n);
1154 
1155  //Check status code
1156  if(!error)
1157  {
1158  //Decode the contents of the Management Address TLV
1159  error = lldpDecodeMgmtAddrTlv(p, n, &part1, &part2);
1160 
1161  //Check status code
1162  if(!error)
1163  {
1164  //Extract the management address subtype
1165  if(mgmtAddrSubtype != NULL)
1166  {
1167  *mgmtAddrSubtype = (LldpMgmtAddrSubtype) part1->mgmtAddrSubtype;
1168  }
1169 
1170  //Extract the management address
1171  if(mgmtAddr != NULL && mgmtAddrLen != NULL)
1172  {
1173  *mgmtAddr = part1->mgmtAddr;
1174  *mgmtAddrLen = part1->mgmtAddrLen;
1175  }
1176 
1177  //Extract the interface numbering method
1178  if(ifNumSubtype != NULL)
1179  {
1180  *ifNumSubtype = (LldpIfNumSubtype) part2->ifNumSubtype;
1181  }
1182 
1183  //Extract the management address subtype
1184  if(ifNum != NULL)
1185  {
1186  *ifNum = ntohl(part2->ifNum);
1187  }
1188 
1189  //Extract the object identifier
1190  if(oid != NULL && oidLen != NULL)
1191  {
1192  *oid = part2->oid;
1193  *oidLen = part2->oidLen;
1194  }
1195  }
1196  }
1197 
1198  //Return status code
1199  return error;
1200 #else
1201  //TX mode is not implemented
1202  return ERROR_READ_FAILED;
1203 #endif
1204 }
1205 
1206 
1207 /**
1208  * @brief Search the remote systems MIB for a given entry
1209  * @param[in] context Pointer to the LLDP agent context
1210  * @param[in] timeMark Timestamp used to implement time-filtered rows
1211  * @param[in] portIndex Index value used to identify the port on which the
1212  * remote system information was received
1213  * @param[in] index Arbitrary local integer value used to identify a particular
1214  * connection
1215  * @return Pointer to the matching entry in the remote systems MIB
1216  **/
1217 
1219  uint32_t timeMark, uint_t portIndex, uint32_t index)
1220 {
1221  uint_t i;
1222  LldpNeighborEntry *entry;
1223 
1224  //Loop through the remote systems MIB
1225  for(i = 0; i < context->numNeighbors; i++)
1226  {
1227  //Point to the current entry
1228  entry = &context->neighbors[i];
1229 
1230  //Check whether the entry is valid
1231  if(entry->rxInfo.length > 0)
1232  {
1233  //Matching entry?
1234  if(entry->timeMark == timeMark && entry->portIndex == portIndex &&
1235  entry->index == index)
1236  {
1237  //Return the zero-based index of the matching entry
1238  return entry;
1239  }
1240  }
1241  }
1242 
1243  //No matching entry was found
1244  return NULL;
1245 }
1246 
1247 
1248 /**
1249  * @brief Extract chassis ID from remote systems MIB
1250  * @param[in] entry Pointer to a given entry of the remote systems MIB
1251  * @param[out] chassisIdSubtype Type of identifier used for the chassis
1252  * @param[out] chassisId Administratively assigned name that identifies the chassis
1253  * @param[out] chassisIdLen Length of the chassis ID, in bytes
1254  * @return Error code
1255  **/
1256 
1258  LldpChassisIdSubtype *chassisIdSubtype, const uint8_t **chassisId,
1259  size_t *chassisIdLen)
1260 {
1261  error_t error;
1262  size_t n;
1263  const uint8_t *p;
1264  const LldpChassisIdTlv *tlv;
1265 
1266  //Check parameters
1267  if(entry == NULL || chassisIdSubtype == NULL || chassisId == NULL ||
1268  chassisIdLen == NULL)
1269  {
1270  return ERROR_READ_FAILED;
1271  }
1272 
1273  //Search the remote systems MIB for the Chassis ID TLV
1274  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_CHASSIS_ID, 0, &p, &n);
1275 
1276  //Chassis ID TLV found?
1277  if(!error && n >= sizeof(LldpChassisIdTlv))
1278  {
1279  //Point to the Chassis ID TLV
1280  tlv = (const LldpChassisIdTlv *) p;
1281 
1282  //Extract the chassis ID from the remote systems MIB
1283  *chassisIdSubtype = (LldpChassisIdSubtype) tlv->chassisIdSubtype;
1284  *chassisId = tlv->chassisId;
1285  *chassisIdLen = n - sizeof(LldpChassisIdTlv);
1286  }
1287  else
1288  {
1289  //The Chassis ID TLV is not present
1290  *chassisIdSubtype = LLDP_CHASSIS_ID_SUBTYPE_RESERVED;
1291  *chassisId = NULL;
1292  *chassisIdLen = 0;
1293  }
1294 
1295  //Successful processing
1296  return NO_ERROR;
1297 }
1298 
1299 
1300 /**
1301  * @brief Extract port ID from remote systems MIB
1302  * @param[in] entry Pointer to a given entry of the remote systems MIB
1303  * @param[out] portIdSubtype Type of identifier used for the port
1304  * @param[out] portId Administratively assigned name that identifies the port
1305  * @param[out] portIdLen Length of the port ID, in bytes
1306  * @return Error code
1307  **/
1308 
1310  LldpPortIdSubtype *portIdSubtype, const uint8_t **portId,
1311  size_t *portIdLen)
1312 {
1313  error_t error;
1314  size_t n;
1315  const uint8_t *p;
1316  const LldpPortIdTlv *tlv;
1317 
1318  //Check parameters
1319  if(entry == NULL || portIdSubtype == NULL || portId == NULL ||
1320  portIdLen == NULL)
1321  {
1322  return ERROR_READ_FAILED;
1323  }
1324 
1325  //Search the remote systems MIB for the Port ID TLV
1326  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_PORT_ID, 0, &p, &n);
1327 
1328  //Port ID TLV found?
1329  if(!error && n >= sizeof(LldpPortIdTlv))
1330  {
1331  //Point to the Port ID TLV
1332  tlv = (const LldpPortIdTlv *) p;
1333 
1334  //Extract the port ID from the remote systems MIB
1335  *portIdSubtype = (LldpPortIdSubtype) tlv->portIdSubtype;
1336  *portId = tlv->portId;
1337  *portIdLen = n - sizeof(LldpPortIdTlv);
1338  }
1339  else
1340  {
1341  //The Port ID TLV is not present
1342  *portIdSubtype = LLDP_PORT_ID_SUBTYPE_RESERVED;
1343  *portId = NULL;
1344  *portIdLen = 0;
1345  }
1346 
1347  //Successful processing
1348  return NO_ERROR;
1349 }
1350 
1351 
1352 /**
1353  * @brief Extract port description from remote systems MIB
1354  * @param[in] entry Pointer to a given entry of the remote systems MIB
1355  * @param[out] portDesc Station port's description
1356  * @param[out] portDescLen Length of the port description, in bytes
1357  * @return Error code
1358  **/
1359 
1361  const char_t **portDesc, size_t *portDescLen)
1362 {
1363  error_t error;
1364  size_t n;
1365  const uint8_t *p;
1366 
1367  //Check parameters
1368  if(entry == NULL || portDesc == NULL || portDescLen == NULL)
1369  {
1370  return ERROR_READ_FAILED;
1371  }
1372 
1373  //Search the remote systems MIB for the Port Description TLV
1374  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_PORT_DESC, 0, &p, &n);
1375 
1376  //Port Description TLV found?
1377  if(!error)
1378  {
1379  //Extract the port description from the remote systems MIB
1380  *portDesc = (const char_t *) p;
1381  *portDescLen = n;
1382  }
1383  else
1384  {
1385  //The Port Description TLV is not present
1386  *portDesc = NULL;
1387  *portDescLen = 0;
1388  }
1389 
1390  //Successful processing
1391  return NO_ERROR;
1392 }
1393 
1394 
1395 /**
1396  * @brief Extract system name from remote systems MIB
1397  * @param[in] entry Pointer to a given entry of the remote systems MIB
1398  * @param[out] sysName System's administratively assigned name
1399  * @param[out] sysNameLen Length of the system name, in bytes
1400  * @return Error code
1401  **/
1402 
1404  const char_t **sysName, size_t *sysNameLen)
1405 {
1406  error_t error;
1407  size_t n;
1408  const uint8_t *p;
1409 
1410  //Check parameters
1411  if(entry == NULL || sysName == NULL || sysNameLen == NULL)
1412  {
1413  return ERROR_READ_FAILED;
1414  }
1415 
1416  //Search the remote systems MIB for the System Name TLV
1417  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_SYS_NAME, 0, &p, &n);
1418 
1419  //System Name TLV found?
1420  if(!error)
1421  {
1422  //Extract the system name from the remote systems MIB
1423  *sysName = (const char_t *) p;
1424  *sysNameLen = n;
1425  }
1426  else
1427  {
1428  //The System Name TLV is not present
1429  *sysName = NULL;
1430  *sysNameLen = 0;
1431  }
1432 
1433  //Successful processing
1434  return NO_ERROR;
1435 }
1436 
1437 
1438 /**
1439  * @brief Extract system description from remote systems MIB
1440  * @param[in] entry Pointer to a given entry of the remote systems MIB
1441  * @param[out] sysDesc Textual description of the network entity
1442  * @param[out] sysDescLen Length of the system description, in bytes
1443  * @return Error code
1444  **/
1445 
1447  const char_t **sysDesc, size_t *sysDescLen)
1448 {
1449  error_t error;
1450  size_t n;
1451  const uint8_t *p;
1452 
1453  //Check parameters
1454  if(entry == NULL || sysDesc == NULL || sysDescLen == NULL)
1455  {
1456  return ERROR_READ_FAILED;
1457  }
1458 
1459  //Search the remote systems MIB for the System Description TLV
1460  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_SYS_DESC, 0, &p, &n);
1461 
1462  //System Description TLV found?
1463  if(!error)
1464  {
1465  //Extract the system description from the remote systems MIB
1466  *sysDesc = (const char_t *) p;
1467  *sysDescLen = n;
1468  }
1469  else
1470  {
1471  //The System Description TLV is not present
1472  *sysDesc = NULL;
1473  *sysDescLen = 0;
1474  }
1475 
1476  //Successful processing
1477  return NO_ERROR;
1478 }
1479 
1480 
1481 /**
1482  * @brief Extract system capabilities from remote systems MIB
1483  * @param[in] entry Pointer to a given entry of the remote systems MIB
1484  * @param[out] supportedCap Bit-map of the capabilities supported by the system
1485  * @param[out] enabledCap Bit-map of the capabilities currently enabled
1486  * @return Error code
1487  **/
1488 
1490  uint16_t *supportedCap, uint16_t *enabledCap)
1491 {
1492  error_t error;
1493  size_t n;
1494  const uint8_t *p;
1495  const LldpSysCapTlv *tlv;
1496 
1497  //Check parameters
1498  if(entry == NULL || supportedCap == NULL ||
1499  enabledCap == NULL)
1500  {
1501  return ERROR_READ_FAILED;
1502  }
1503 
1504  //Search the remote systems MIB for the System Capabilities TLV
1505  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_SYS_CAP, 0, &p, &n);
1506 
1507  //System Capabilities TLV found?
1508  if(!error && n >= sizeof(LldpChassisIdTlv))
1509  {
1510  //Point to the System Capabilities TLV
1511  tlv = (const LldpSysCapTlv *) p;
1512 
1513  //Extract capabilities from the local system MIB
1514  *supportedCap = ntohs(tlv->supportedCap);
1515  *enabledCap = ntohs(tlv->enabledCap);
1516  }
1517  else
1518  {
1519  //The System Capabilities TLV is not present
1520  *supportedCap = 0;
1521  *enabledCap = 0;
1522  }
1523 
1524  //Successful processing
1525  return NO_ERROR;
1526 }
1527 
1528 
1529 /**
1530  * @brief Search the remote system MIB for a given management address
1531  * @param[in] entry Pointer to a given entry of the remote systems MIB
1532  * @param[in] mgmtAddrSubtype Type of management address
1533  * @param[in] mgmtAddr Octet string indicating a particular management
1534  * address
1535  * @param[in] mgmtAddrLen Length of the management address, in bytes
1536  * @return index Zero-based index corresponding to the management address
1537  **/
1538 
1540  uint8_t mgmtAddrSubtype, const uint8_t *mgmtAddr, size_t mgmtAddrLen)
1541 {
1542  error_t error;
1543  int_t index;
1544  LldpTlv tlv;
1545  const LldpMgmtAddrTlv1 *part1;
1546  const LldpMgmtAddrTlv2 *part2;
1547 
1548  //Initialize index
1549  index = 0;
1550 
1551  //Extract the first TLV
1552  error = lldpGetFirstTlv(&entry->rxInfo, &tlv);
1553 
1554  //Loop through the TLVs
1555  while(!error)
1556  {
1557  //Check TLV type
1558  if(tlv.type == LLDP_TLV_TYPE_MGMT_ADDR)
1559  {
1560  //Decode the contents of the Management Address TLV
1561  error = lldpDecodeMgmtAddrTlv(tlv.value, tlv.length, &part1, &part2);
1562  //Malformed TLV?
1563  if(error)
1564  break;
1565 
1566  //Check the management address against the specified address
1567  if(part1->mgmtAddrSubtype == mgmtAddrSubtype &&
1568  part1->mgmtAddrLen == (mgmtAddrLen + 1) &&
1569  osMemcmp(part1->mgmtAddr, mgmtAddr, mgmtAddrLen) == 0)
1570  {
1571  //A matching address has been found
1572  return index;
1573  }
1574  else
1575  {
1576  //Increment index
1577  index++;
1578  }
1579  }
1580 
1581  //Extract the next TLV
1582  error = lldpGetNextTlv(&entry->rxInfo, &tlv);
1583  }
1584 
1585  //The specified management address does not exist
1586  return -1;
1587 }
1588 
1589 
1590 /**
1591  * @brief Extract management address from remote systems MIB
1592  * @param[in] entry Pointer to a given entry of the remote systems MIB
1593  * @param[in] index Zero-based index identifying a management address
1594  * @param[out] mgmtAddrSubtype Type of management address
1595  * @param[out] mgmtAddr Octet string indicating a particular management
1596  * address
1597  * @param[out] mgmtAddrLen Length of the management address, in bytes
1598  * @param[out] ifNumSubtype Numbering method used for defining the interface
1599  * number
1600  * @param[out] ifNum Number within the system that identifies the specific
1601  * interface associated with this management address
1602  * @param[out] oid OID that identifies the type of hardware component or
1603  * protocol entity associated with the indicated management address
1604  * @param[out] oidLen Length of the OID, in bytes
1605  * @return Error code
1606  **/
1607 
1609  LldpMgmtAddrSubtype *mgmtAddrSubtype, const uint8_t **mgmtAddr,
1610  size_t *mgmtAddrLen, LldpIfNumSubtype *ifNumSubtype, uint32_t *ifNum,
1611  const uint8_t **oid, size_t *oidLen)
1612 {
1613  error_t error;
1614  size_t n;
1615  const uint8_t *p;
1616  const LldpMgmtAddrTlv1 *part1;
1617  const LldpMgmtAddrTlv2 *part2;
1618 
1619  //Check parameters
1620  if(entry == NULL)
1621  {
1622  return ERROR_READ_FAILED;
1623  }
1624 
1625  //Extract the management address from the remote systems MIB
1626  error = lldpGetTlv(&entry->rxInfo, LLDP_TLV_TYPE_MGMT_ADDR, index, &p, &n);
1627 
1628  //Check status code
1629  if(!error)
1630  {
1631  //Decode the contents of the Management Address TLV
1632  error = lldpDecodeMgmtAddrTlv(p, n, &part1, &part2);
1633 
1634  //Check status code
1635  if(!error)
1636  {
1637  //Extract the management address subtype
1638  if(mgmtAddrSubtype != NULL)
1639  {
1640  *mgmtAddrSubtype = (LldpMgmtAddrSubtype) part1->mgmtAddrSubtype;
1641  }
1642 
1643  //Extract the management address
1644  if(mgmtAddr != NULL && mgmtAddrLen != NULL)
1645  {
1646  *mgmtAddr = part1->mgmtAddr;
1647  *mgmtAddrLen = part1->mgmtAddrLen;
1648  }
1649 
1650  //Extract the interface numbering method
1651  if(ifNumSubtype != NULL)
1652  {
1653  *ifNumSubtype = (LldpIfNumSubtype) part2->ifNumSubtype;
1654  }
1655 
1656  //Extract the management address subtype
1657  if(ifNum != NULL)
1658  {
1659  *ifNum = ntohl(part2->ifNum);
1660  }
1661 
1662  //Extract the object identifier
1663  if(oid != NULL && oidLen != NULL)
1664  {
1665  *oid = part2->oid;
1666  *oidLen = part2->oidLen;
1667  }
1668  }
1669  }
1670 
1671  //Return status code
1672  return error;
1673 }
1674 
1675 
1676 /**
1677  * @brief Extract unknown TLV from remote systems MIB
1678  * @param[in] entry Pointer to a given entry of the remote systems MIB
1679  * @param[in] type TLV type field
1680  * @param[in] index Index identifying a particular instance of the TLV
1681  * @param[out] info TLV information string
1682  * @param[out] infoLen Length of the information string, in bytes
1683  * @return Error code
1684  **/
1685 
1687  uint8_t type, uint_t index, const uint8_t **info, size_t *infoLen)
1688 {
1689  //Search the remote systems MIB for a matching TLV
1690  return lldpGetTlv(&entry->rxInfo, type, index, info, infoLen);
1691 }
1692 
1693 
1694 /**
1695  * @brief Extract organizationally defined TLV from remote systems MIB
1696  * @param[in] entry Pointer to a given entry of the remote systems MIB
1697  * @param[in] oui Organizationally unique identifier
1698  * @param[in] subtype Organizationally defined subtype
1699  * @param[in] index Index identifying a particular instance of the TLV
1700  * @param[out] info Organizationally defined information string
1701  * @param[out] infoLen Length of the information string, in bytes
1702  * @return Error code
1703  **/
1704 
1706  uint32_t oui, uint8_t subtype, uint_t index, const uint8_t **info,
1707  size_t *infoLen)
1708 {
1709  //Search the remote systems MIB for a matching TLV
1710  return lldpGetOrgDefTlv(&entry->rxInfo, oui, subtype, index, info,
1711  infoLen);
1712 }
1713 
1714 
1715 /**
1716  * @brief Get the value of the statsFramesOutTotal statistics counter
1717  * @param[in] context Pointer to the LLDP agent context
1718  * @param[in] portIndex Port index
1719  * @param[out] statsFramesOutTotal Count of all LLDP frames transmitted through
1720  * the port
1721  * @return Error code
1722  **/
1723 
1725  uint_t portIndex, uint32_t *statsFramesOutTotal)
1726 {
1727 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1729 
1730  //Check parameters
1731  if(context == NULL || statsFramesOutTotal == NULL)
1732  return ERROR_READ_FAILED;
1733 
1734  //Invalid port index?
1735  if(portIndex < 1 || portIndex > context->numPorts)
1736  return ERROR_INVALID_PORT;
1737 
1738  //Point to the port that matches the specified port index
1739  port = &context->ports[portIndex - 1];
1740 
1741  //Retrieve the current value of the statistics counter
1742  *statsFramesOutTotal = port->statsFramesOutTotal;
1743 
1744  //Successful processing
1745  return NO_ERROR;
1746 #else
1747  //TX mode is not implemented
1748  return ERROR_READ_FAILED;
1749 #endif
1750 }
1751 
1752 
1753 /**
1754  * @brief Get the value of the statsFramesDiscardedTotal statistics counter
1755  * @param[in] context Pointer to the LLDP agent context
1756  * @param[in] portIndex Port index
1757  * @param[out] statsFramesDiscardedTotal Number of LLDP frames received by this
1758  * LLDP agent on the indicated port, and then discarded for any reason
1759  * @return Error code
1760  **/
1761 
1763  uint_t portIndex, uint32_t *statsFramesDiscardedTotal)
1764 {
1765 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1767 
1768  //Check parameters
1769  if(context == NULL || statsFramesDiscardedTotal == NULL)
1770  return ERROR_READ_FAILED;
1771 
1772  //Invalid port index?
1773  if(portIndex < 1 || portIndex > context->numPorts)
1774  return ERROR_INVALID_PORT;
1775 
1776  //Point to the port that matches the specified port index
1777  port = &context->ports[portIndex - 1];
1778 
1779  //Retrieve the current value of the statistics counter
1780  *statsFramesDiscardedTotal = port->statsFramesDiscardedTotal;
1781 
1782  //Successful processing
1783  return NO_ERROR;
1784 #else
1785  //RX mode is not implemented
1786  return ERROR_READ_FAILED;
1787 #endif
1788 }
1789 
1790 
1791 /**
1792  * @brief Get the value of the statsFramesInErrorsTotal statistics counter
1793  * @param[in] context Pointer to the LLDP agent context
1794  * @param[in] portIndex Port index
1795  * @param[out] statsFramesInErrorsTotal Number of invalid LLDP frames received
1796  * by this LLDP agent on the indicated port, while this LLDP agent is enabled
1797  * @return Error code
1798  **/
1799 
1801  uint_t portIndex, uint32_t *statsFramesInErrorsTotal)
1802 {
1803 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1805 
1806  //Check parameters
1807  if(context == NULL || statsFramesInErrorsTotal == NULL)
1808  return ERROR_READ_FAILED;
1809 
1810  //Invalid port index?
1811  if(portIndex < 1 || portIndex > context->numPorts)
1812  return ERROR_INVALID_PORT;
1813 
1814  //Point to the port that matches the specified port index
1815  port = &context->ports[portIndex - 1];
1816 
1817  //Retrieve the current value of the statistics counter
1818  *statsFramesInErrorsTotal = port->statsFramesInErrorsTotal;
1819 
1820  //Successful processing
1821  return NO_ERROR;
1822 #else
1823  //RX mode is not implemented
1824  return ERROR_READ_FAILED;
1825 #endif
1826 }
1827 
1828 
1829 /**
1830  * @brief Get the value of the statsFramesInTotal statistics counter
1831  * @param[in] context Pointer to the LLDP agent context
1832  * @param[in] portIndex Port index
1833  * @param[out] statsFramesInTotal Number of valid LLDP frames received by this
1834  * LLDP agent on the indicated port, while this LLDP agent is enabled
1835  * @return Error code
1836  **/
1837 
1839  uint_t portIndex, uint32_t *statsFramesInTotal)
1840 {
1841 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1843 
1844  //Check parameters
1845  if(context == NULL || statsFramesInTotal == NULL)
1846  return ERROR_READ_FAILED;
1847 
1848  //Invalid port index?
1849  if(portIndex < 1 || portIndex > context->numPorts)
1850  return ERROR_INVALID_PORT;
1851 
1852  //Point to the port that matches the specified port index
1853  port = &context->ports[portIndex - 1];
1854 
1855  //Retrieve the current value of the statistics counter
1856  *statsFramesInTotal = port->statsFramesInTotal;
1857 
1858  //Successful processing
1859  return NO_ERROR;
1860 #else
1861  //RX mode is not implemented
1862  return ERROR_READ_FAILED;
1863 #endif
1864 }
1865 
1866 
1867 /**
1868  * @brief Get the value of the statsTLVsDiscardedTotal statistics counter
1869  * @param[in] context Pointer to the LLDP agent context
1870  * @param[in] portIndex Port index
1871  * @param[out] statsTLVsDiscardedTotal Number of LLDP TLVs discarded for any
1872  * reason by this LLDP agent on the indicated port
1873  * @return Error code
1874  **/
1875 
1877  uint_t portIndex, uint32_t *statsTLVsDiscardedTotal)
1878 {
1879 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1881 
1882  //Check parameters
1883  if(context == NULL || statsTLVsDiscardedTotal == NULL)
1884  return ERROR_READ_FAILED;
1885 
1886  //Invalid port index?
1887  if(portIndex < 1 || portIndex > context->numPorts)
1888  return ERROR_INVALID_PORT;
1889 
1890  //Point to the port that matches the specified port index
1891  port = &context->ports[portIndex - 1];
1892 
1893  //Retrieve the current value of the statistics counter
1894  *statsTLVsDiscardedTotal = port->statsTLVsDiscardedTotal;
1895 
1896  //Successful processing
1897  return NO_ERROR;
1898 #else
1899  //RX mode is not implemented
1900  return ERROR_READ_FAILED;
1901 #endif
1902 }
1903 
1904 
1905 /**
1906  * @brief Get the value of the statsTLVsUnrecognizedTotal statistics counter
1907  * @param[in] context Pointer to the LLDP agent context
1908  * @param[in] portIndex Port index
1909  * @param[out] statsTLVsUnrecognizedTotal Number of LLDP TLVs received on the
1910  * given port that are not recognized by this LLDP agent
1911  * @return Error code
1912  **/
1913 
1915  uint_t portIndex, uint32_t *statsTLVsUnrecognizedTotal)
1916 {
1917 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1919 
1920  //Check parameters
1921  if(context == NULL || statsTLVsUnrecognizedTotal == NULL)
1922  return ERROR_READ_FAILED;
1923 
1924  //Invalid port index?
1925  if(portIndex < 1 || portIndex > context->numPorts)
1926  return ERROR_INVALID_PORT;
1927 
1928  //Point to the port that matches the specified port index
1929  port = &context->ports[portIndex - 1];
1930 
1931  //Retrieve the current value of the statistics counter
1932  *statsTLVsUnrecognizedTotal = port->statsTLVsUnrecognizedTotal;
1933 
1934  //Successful processing
1935  return NO_ERROR;
1936 #else
1937  //RX mode is not implemented
1938  return ERROR_READ_FAILED;
1939 #endif
1940 }
1941 
1942 
1943 /**
1944  * @brief Get the value of the statsAgeoutsTotal statistics counter
1945  * @param[in] context Pointer to the LLDP agent context
1946  * @param[in] portIndex Port index
1947  * @param[out] statsAgeoutsTotal Number of age-outs that occurred on a given port
1948  * @return Error code
1949  **/
1950 
1952  uint_t portIndex, uint32_t *statsAgeoutsTotal)
1953 {
1954 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1956 
1957  //Check parameters
1958  if(context == NULL || statsAgeoutsTotal == NULL)
1959  return ERROR_READ_FAILED;
1960 
1961  //Invalid port index?
1962  if(portIndex < 1 || portIndex > context->numPorts)
1963  return ERROR_INVALID_PORT;
1964 
1965  //Point to the port that matches the specified port index
1966  port = &context->ports[portIndex - 1];
1967 
1968  //Retrieve the current value of the statistics counter
1969  *statsAgeoutsTotal = port->statsAgeoutsTotal;
1970 
1971  //Successful processing
1972  return NO_ERROR;
1973 #else
1974  //RX mode is not implemented
1975  return ERROR_READ_FAILED;
1976 #endif
1977 }
1978 
1979 
1980 /**
1981  * @brief Get the value of the statsRemTablesLastChangeTime statistics counter
1982  * @param[in] context Pointer to the LLDP agent context
1983  * @param[out] statsRemTablesLastChangeTime The time at which an entry was
1984  * created, modified, or deleted in tables
1985  * @return Error code
1986  **/
1987 
1989  uint32_t *statsRemTablesLastChangeTime)
1990 {
1991 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
1992  //Check parameters
1993  if(context == NULL || statsRemTablesLastChangeTime == NULL)
1994  return ERROR_READ_FAILED;
1995 
1996  //Retrieve the current value of the statistics counter
1997  *statsRemTablesLastChangeTime = context->statsRemTablesLastChangeTime;
1998 
1999  //Successful processing
2000  return NO_ERROR;
2001 #else
2002  //RX mode is not implemented
2003  return ERROR_READ_FAILED;
2004 #endif
2005 }
2006 
2007 
2008 /**
2009  * @brief Get the value of the statsRemTablesInserts statistics counter
2010  * @param[in] context Pointer to the LLDP agent context
2011  * @param[out] statsRemTablesInserts The number of times the complete set of
2012  * information advertised by a particular MSAP has been inserted into tables
2013  * @return Error code
2014  **/
2015 
2017  uint32_t *statsRemTablesInserts)
2018 {
2019 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
2020  //Check parameters
2021  if(context == NULL || statsRemTablesInserts == NULL)
2022  return ERROR_READ_FAILED;
2023 
2024  //Retrieve the current value of the statistics counter
2025  *statsRemTablesInserts = context->statsRemTablesInserts;
2026 
2027  //Successful processing
2028  return NO_ERROR;
2029 #else
2030  //RX mode is not implemented
2031  return ERROR_READ_FAILED;
2032 #endif
2033 }
2034 
2035 
2036 /**
2037  * @brief Get the value of the statsRemTablesDeletes statistics counter
2038  * @param[in] context Pointer to the LLDP agent context
2039  * @param[out] statsRemTablesDeletes The number of times the complete set of
2040  * information advertised by a particular MSAP has been deleted from tables
2041  * @return Error code
2042  **/
2043 
2045  uint32_t *statsRemTablesDeletes)
2046 {
2047 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
2048  //Check parameters
2049  if(context == NULL || statsRemTablesDeletes == NULL)
2050  return ERROR_READ_FAILED;
2051 
2052  //Retrieve the current value of the statistics counter
2053  *statsRemTablesDeletes = context->statsRemTablesDeletes;
2054 
2055  //Successful processing
2056  return NO_ERROR;
2057 #else
2058  //RX mode is not implemented
2059  return ERROR_READ_FAILED;
2060 #endif
2061 }
2062 
2063 
2064 /**
2065  * @brief Get the value of the statsRemTablesDrops statistics counter
2066  * @param[in] context Pointer to the LLDP agent context
2067  * @param[out] statsRemTablesDrops The number of times the complete set of
2068  * information advertised by a particular MSAP could not be entered into
2069  * tables because of insufficient resources
2070  * @return Error code
2071  **/
2072 
2074  uint32_t *statsRemTablesDrops)
2075 {
2076 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
2077  //Check parameters
2078  if(context == NULL || statsRemTablesDrops == NULL)
2079  return ERROR_READ_FAILED;
2080 
2081  //Retrieve the current value of the statistics counter
2082  *statsRemTablesDrops = context->statsRemTablesDrops;
2083 
2084  //Successful processing
2085  return NO_ERROR;
2086 #else
2087  //RX mode is not implemented
2088  return ERROR_READ_FAILED;
2089 #endif
2090 }
2091 
2092 
2093 /**
2094  * @brief Get the value of the statsRemTablesAgeouts statistics counter
2095  * @param[in] context Pointer to the LLDP agent context
2096  * @param[out] statsRemTablesAgeouts The number of times the complete set of
2097  * information advertised by a particular MSAP has been deleted from tables
2098  * because the information timeliness interval has expired
2099  * @return Error code
2100  **/
2101 
2103  uint32_t *statsRemTablesAgeouts)
2104 {
2105 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
2106  //Check parameters
2107  if(context == NULL || statsRemTablesAgeouts == NULL)
2108  return ERROR_READ_FAILED;
2109 
2110  //Retrieve the current value of the statistics counter
2111  *statsRemTablesAgeouts = context->statsRemTablesAgeouts;
2112 
2113  //Successful processing
2114  return NO_ERROR;
2115 #else
2116  //RX mode is not implemented
2117  return ERROR_READ_FAILED;
2118 #endif
2119 }
2120 
2121 #endif
error_t lldpGetFirstTlv(LldpDataUnit *lldpdu, LldpTlv *tlv)
Extract the first TLV from an LLDPDU.
Definition: lldp_tlv.c:247
uint8_t type
Definition: lldp_tlv.h:202
uint32_t timeMark
Timestamp used to implement time-filtered rows.
Definition: lldp.h:262
@ LLDP_TLV_TYPE_SYS_CAP
System Capabilities.
Definition: lldp_tlv.h:100
int bool_t
Definition: compiler_port.h:53
error_t lldpMgmtGetRemoteSysName(LldpNeighborEntry *entry, const char_t **sysName, size_t *sysNameLen)
Extract system name from remote systems MIB.
Definition: lldp_mgmt.c:1403
uint8_t portId[]
Definition: lldp_tlv.h:254
error_t lldpMgmtSetReinitDelay(LldpAgentContext *context, uint_t reinitDelay, bool_t commit)
Set re-initialization delay.
Definition: lldp_mgmt.c:172
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
error_t lldpMgmtGetMsgTxInterval(LldpAgentContext *context, uint_t *msgTxInterval)
Get transmit interval.
Definition: lldp_mgmt.c:445
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
int_t lldpMgmtFindRemoteMgmtAddr(LldpNeighborEntry *entry, uint8_t mgmtAddrSubtype, const uint8_t *mgmtAddr, size_t mgmtAddrLen)
Search the remote system MIB for a given management address.
Definition: lldp_mgmt.c:1539
#define LLDP_MAX_TX_DELAY
Definition: lldp.h:132
error_t lldpMgmtGetStatsRemTablesAgeouts(LldpAgentContext *context, uint32_t *statsRemTablesAgeouts)
Get the value of the statsRemTablesAgeouts statistics counter.
Definition: lldp_mgmt.c:2102
error_t lldpMgmtSetMsgTxInterval(LldpAgentContext *context, uint_t msgTxInterval, bool_t commit)
Set transmit interval.
Definition: lldp_mgmt.c:81
uint8_t p
Definition: ndp.h:300
@ LLDP_TLV_TYPE_MGMT_ADDR
Management Address.
Definition: lldp_tlv.h:101
error_t lldpMgmtSetNotificationEnable(LldpAgentContext *context, uint_t portIndex, bool_t notificationEnable, bool_t commit)
Enable or disable notifications.
Definition: lldp_mgmt.c:355
error_t lldpGetNextTlv(LldpDataUnit *lldpdu, LldpTlv *tlv)
Extract the next TLV from an LLDPDU.
Definition: lldp_tlv.c:264
@ LLDP_BASIC_TLV_FILTER_ALL
All Basic TLVs.
Definition: lldp.h:205
error_t lldpMgmtGetRemoteMgmtAddr(LldpNeighborEntry *entry, 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 remote systems MIB.
Definition: lldp_mgmt.c:1608
error_t lldpMgmtGetStatsAgeoutsTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsAgeoutsTotal)
Get the value of the statsAgeoutsTotal statistics counter.
Definition: lldp_mgmt.c:1951
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
uint8_t type
Definition: coap_common.h:176
#define osMemcmp(p1, p2, length)
Definition: os_port.h:153
error_t lldpMgmtGetReinitDelay(LldpAgentContext *context, uint_t *reinitDelay)
Get re-initialization delay.
Definition: lldp_mgmt.c:499
void lldpMgmtUnlock(LldpAgentContext *context)
Release exclusive access to the LLDP agent context.
Definition: lldp_mgmt.c:63
@ ERROR_INVALID_PORT
Definition: error.h:104
error_t lldpMgmtGetLocalSysDesc(LldpAgentContext *context, const char_t **sysDesc, size_t *sysDescLen)
Extract system description from local system MIB.
Definition: lldp_mgmt.c:919
error_t lldpMgmtSetMsgTxHold(LldpAgentContext *context, uint_t msgTxHold, bool_t commit)
Set transmit hold multiplier.
Definition: lldp_mgmt.c:127
#define LLDP_MAX_MSG_TX_INTERVAL
Definition: lldp.h:111
error_t lldpMgmtGetStatsTLVsDiscardedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsTLVsDiscardedTotal)
Get the value of the statsTLVsDiscardedTotal statistics counter.
Definition: lldp_mgmt.c:1876
error_t lldpMgmtSetBasicTlvFilter(LldpAgentContext *context, uint_t portIndex, uint8_t mask, bool_t commit)
Set the list of TLVs enabled for transmission.
Definition: lldp_mgmt.c:399
void lldpMgmtLock(LldpAgentContext *context)
Acquire exclusive access to the LLDP agent context.
Definition: lldp_mgmt.c:51
LldpPortIdSubtype
Port ID subtypes.
Definition: lldp_tlv.h:128
error_t lldpMgmtGetStatsTLVsUnrecognizedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsTLVsUnrecognizedTotal)
Get the value of the statsTLVsUnrecognizedTotal statistics counter.
Definition: lldp_mgmt.c:1914
uint8_t oid[]
Definition: lldp_tlv.h:300
error_t lldpMgmtGetTxDelay(LldpAgentContext *context, uint_t *txDelay)
Get transmit delay.
Definition: lldp_mgmt.c:525
error_t lldpMgmtGetMibBasicTlvsTxEnable(LldpAgentContext *context, uint_t portIndex, uint8_t *mibBasicTlvsTxEnable)
Get the list of TLVs enabled for transmission.
Definition: lldp_mgmt.c:656
Data logging functions for debugging purpose (LLDP)
LldpChassisIdTlv
Definition: lldp_tlv.h:244
uint8_t mgmtAddr[]
Definition: lldp_tlv.h:287
@ LLDP_ADMIN_STATUS_DISABLED
The local LLDP agent can neither transmit or receive LLDP frames.
Definition: lldp.h:188
error_t lldpMgmtGetRemoteOrgDefInfo(LldpNeighborEntry *entry, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t **info, size_t *infoLen)
Extract organizationally defined TLV from remote systems MIB.
Definition: lldp_mgmt.c:1705
error_t lldpMgmtGetAdminStatus(LldpAgentContext *context, uint_t portIndex, LldpAdminStatus *adminStatus)
Get administrative status.
Definition: lldp_mgmt.c:580
@ LLDP_PORT_ID_SUBTYPE_RESERVED
Reserved.
Definition: lldp_tlv.h:129
error_t lldpMgmtGetRemotePortDesc(LldpNeighborEntry *entry, const char_t **portDesc, size_t *portDescLen)
Extract port description from remote systems MIB.
Definition: lldp_mgmt.c:1360
error_t lldpMgmtGetNotificationInterval(LldpAgentContext *context, uint_t *notificationInterval)
Get notification interval.
Definition: lldp_mgmt.c:551
LldpIfNumSubtype
Interface numbering subtypes.
Definition: lldp_tlv.h:175
#define LLDP_MAX_REINIT_DELAY
Definition: lldp.h:125
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 lldpMgmtGetStatsRemTablesDrops(LldpAgentContext *context, uint32_t *statsRemTablesDrops)
Get the value of the statsRemTablesDrops statistics counter.
Definition: lldp_mgmt.c:2073
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
#define LLDP_MIN_REINIT_DELAY
Definition: lldp.h:121
error_t lldpGetOrgDefTlv(LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t **value, size_t *length)
Search an LLDPDU for an organizationally specific TLV.
Definition: lldp_tlv.c:651
#define LLDP_MIN_MSG_TX_INTERVAL
Definition: lldp.h:107
#define LldpPortEntry
Definition: lldp.h:44
@ LLDP_ADMIN_STATUS_ENABLED_RX_ONLY
The local LLDP agent can only receive LLDP frames.
Definition: lldp.h:190
#define LLDP_MIN_TX_DELAY
Definition: lldp.h:128
uint8_t mask
Definition: web_socket.h:319
error_t lldpMgmtGetStatsFramesInTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesInTotal)
Get the value of the statsFramesInTotal statistics counter.
Definition: lldp_mgmt.c:1838
Helper functions for LLDP.
error_t lldpGetTlv(LldpDataUnit *lldpdu, uint8_t type, uint_t index, const uint8_t **value, size_t *length)
Search a LLDPDU for a given TLV.
Definition: lldp_tlv.c:200
error_t lldpMgmtGetLocalSysName(LldpAgentContext *context, const char_t **sysName, size_t *sysNameLen)
Extract system name from local system MIB.
Definition: lldp_mgmt.c:871
LldpPortIdTlv
Definition: lldp_tlv.h:255
@ LLDP_TLV_TYPE_SYS_NAME
System Name.
Definition: lldp_tlv.h:98
error_t lldpMgmtGetStatsFramesDiscardedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesDiscardedTotal)
Get the value of the statsFramesDiscardedTotal statistics counter.
Definition: lldp_mgmt.c:1762
#define LLDP_MIN_NOTIFICATION_INTERVAL
Definition: lldp.h:135
error_t lldpMgmtGetStatsRemTablesLastChangeTime(LldpAgentContext *context, uint32_t *statsRemTablesLastChangeTime)
Get the value of the statsRemTablesLastChangeTime statistics counter.
Definition: lldp_mgmt.c:1988
error_t lldpMgmtGetRemoteSysDesc(LldpNeighborEntry *entry, const char_t **sysDesc, size_t *sysDescLen)
Extract system description from remote systems MIB.
Definition: lldp_mgmt.c:1446
@ LLDP_CHASSIS_ID_SUBTYPE_RESERVED
Reserved.
Definition: lldp_tlv.h:112
error_t lldpMgmtGetNotificationEnable(LldpAgentContext *context, uint_t portIndex, bool_t *notificationEnable)
Check whether notifications are enabled or disabled.
Definition: lldp_mgmt.c:618
error_t lldpMgmtGetRemoteSysCap(LldpNeighborEntry *entry, uint16_t *supportedCap, uint16_t *enabledCap)
Extract system capabilities from remote systems MIB.
Definition: lldp_mgmt.c:1489
error_t lldpMgmtSetNotificationInterval(LldpAgentContext *context, uint_t notificationInterval, bool_t commit)
Set notification interval.
Definition: lldp_mgmt.c:254
uint16_t port
Definition: dns_common.h:267
#define ntohs(value)
Definition: cpu_endian.h:421
uint8_t subtype
Definition: lldp_tlv.h:311
@ LLDP_ADMIN_STATUS_ENABLED_TX_RX
Definition: lldp.h:191
@ LLDP_TLV_TYPE_CHASSIS_ID
Chassis ID.
Definition: lldp_tlv.h:94
LLDP neighbor entry.
Definition: lldp.h:260
error_t lldpMgmtGetStatsRemTablesDeletes(LldpAgentContext *context, uint32_t *statsRemTablesDeletes)
Get the value of the statsRemTablesDeletes statistics counter.
Definition: lldp_mgmt.c:2044
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
#define LLDP_MIN_MSG_TX_HOLD
Definition: lldp.h:114
uint_t portIndex
Port on which the LLDPDU was received.
Definition: lldp.h:263
error_t lldpMgmtGetStatsFramesOutTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesOutTotal)
Get the value of the statsFramesOutTotal statistics counter.
Definition: lldp_mgmt.c:1724
@ LLDP_TLV_TYPE_SYS_DESC
System Description.
Definition: lldp_tlv.h:99
error_t lldpMgmtGetRemotePortId(LldpNeighborEntry *entry, LldpPortIdSubtype *portIdSubtype, const uint8_t **portId, size_t *portIdLen)
Extract port ID from remote systems MIB.
Definition: lldp_mgmt.c:1309
#define LLDP_MAX_MGMT_ADDRS
Definition: lldp.h:101
uint8_t n
void lldpSomethingChangedLocal(LldpAgentContext *context)
Notify LLDP that an object in the LLDP local system MIB has changed.
Definition: lldp_misc.c:806
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ ERROR_READ_FAILED
Definition: error.h:223
size_t length
Definition: lldp_tlv.h:203
@ 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.
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
#define LLDP_MAX_MSG_TX_HOLD
Definition: lldp.h:118
uint32_t ifNum
Definition: lldp_tlv.h:298
uint8_t oidLen
Definition: lldp_tlv.h:299
LldpChassisIdSubtype
Chassis ID subtypes.
Definition: lldp_tlv.h:111
error_t lldpMgmtGetRemoteChassisId(LldpNeighborEntry *entry, LldpChassisIdSubtype *chassisIdSubtype, const uint8_t **chassisId, size_t *chassisIdLen)
Extract chassis ID from remote systems MIB.
Definition: lldp_mgmt.c:1257
#define LLDP_MAX_NOTIFICATION_INTERVAL
Definition: lldp.h:139
LldpAdminStatus
Administrative status.
Definition: lldp.h:187
#define LldpAgentContext
Definition: lldp.h:40
uint32_t index
Arbitrary local integer value used to identify the entry.
Definition: lldp.h:261
LldpNeighborEntry * lldpMgmtFindRemoteTableEntry(LldpAgentContext *context, uint32_t timeMark, uint_t portIndex, uint32_t index)
Search the remote systems MIB for a given entry.
Definition: lldp_mgmt.c:1218
Management of the LLDP agent.
LldpMgmtAddrTlv2
Definition: lldp_tlv.h:301
@ LLDP_TLV_TYPE_PORT_ID
Port ID.
Definition: lldp_tlv.h:95
error_t lldpMgmtSetTxDelay(LldpAgentContext *context, uint_t txDelay, bool_t commit)
Set transmit delay.
Definition: lldp_mgmt.c:213
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
uint8_t mgmtAddrSubtype
Definition: lldp_tlv.h:286
LLDP (Link Layer Discovery Protocol)
LldpMgmtAddrSubtype
Management address subtypes.
Definition: lldp_tlv.h:162
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
error_t lldpMgmtGetMsgTxHold(LldpAgentContext *context, uint_t *msgTxHold)
Get transmit hold multiplier.
Definition: lldp_mgmt.c:473
LldpSysCapTlv
Definition: lldp_tlv.h:276
LldpMgmtAddrTlv1
Definition: lldp_tlv.h:288
TLV structure.
Definition: lldp_tlv.h:200
@ LLDP_TLV_TYPE_PORT_DESC
Port Description.
Definition: lldp_tlv.h:97
#define ntohl(value)
Definition: cpu_endian.h:422
error_t lldpMgmtGetRemoteUnknownTlv(LldpNeighborEntry *entry, uint8_t type, uint_t index, const uint8_t **info, size_t *infoLen)
Extract unknown TLV from remote systems MIB.
Definition: lldp_mgmt.c:1686
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
error_t lldpMgmtGetStatsRemTablesInserts(LldpAgentContext *context, uint32_t *statsRemTablesInserts)
Get the value of the statsRemTablesInserts statistics counter.
Definition: lldp_mgmt.c:2016
error_t lldpMgmtSetAdminStatus(LldpAgentContext *context, uint_t portIndex, LldpAdminStatus adminStatus, bool_t commit)
Set administrative status.
Definition: lldp_mgmt.c:297
error_t lldpMgmtGetStatsFramesInErrorsTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesInErrorsTotal)
Get the value of the statsFramesInErrorsTotal statistics counter.
Definition: lldp_mgmt.c:1800
@ LLDP_ADMIN_STATUS_ENABLED_TX_ONLY
The local LLDP agent can only transmit LLDP frames.
Definition: lldp.h:189
LldpDataUnit rxInfo
Remote system information.
Definition: lldp.h:265
uint8_t * value
Definition: lldp_tlv.h:204