lldp.c
Go to the documentation of this file.
1 /**
2  * @file lldp.c
3  * @brief LLDP (Link Layer Discovery Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.0
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_fsm.h"
39 #include "lldp/lldp_misc.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (LLDP_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Initialize settings with default values
48  * @param[out] settings Structure that contains LLDP agent settings
49  **/
50 
52 {
53  //Default task parameters
54  settings->task = OS_TASK_DEFAULT_PARAMS;
56  settings->task.priority = LLDP_TASK_PRIORITY;
57 
58  //Underlying network interface
59  settings->interface = NULL;
60 
61  //Number of ports
62  settings->numPorts = 0;
63  //Port table
64  settings->ports = NULL;
65 
66  //Maximum number of entries in the neighbor table
67  settings->numNeighbors = 0;
68  //Neighbor table
69  settings->neighbors = NULL;
70 
71  //LLDP frame transmission callback function
72  settings->sendCallback = NULL;
73  //LLDP frame reception callback function
74  settings->receiveCallback = NULL;
75  //Tick callback function
76  settings->tickCallback = NULL;
77 }
78 
79 
80 /**
81  * @brief LLDP agent initialization
82  * @param[in] context Pointer to the LLDP agent context
83  * @param[in] settings LLDP agent specific settings
84  * @return Error code
85  **/
86 
88  const LldpAgentSettings *settings)
89 {
90  error_t error;
91  uint_t i;
92  size_t n;
94  LldpChassisIdTlv *chassisIdTlv;
95  LldpPortIdTlv *portIdTlv;
96 
97  //Debug message
98  TRACE_INFO("Initializing LLDP agent...\r\n");
99 
100  //Ensure the parameters are valid
101  if(context == NULL || settings == NULL)
103 
104  //The LLDP agent must be bound to a valid interface
105  if(settings->interface == NULL)
107 
108  //Check the port table
109  if(settings->numPorts == 0 || settings->ports == NULL)
111 
112  //The neighbor table is not used in TX-only mode
113  if(settings->numNeighbors != 0 && settings->neighbors == NULL)
115 
116  //Clear the LLDP agent context
117  osMemset(context, 0, sizeof(LldpAgentContext));
118 
119  //Initialize task parameters
120  context->taskParams = settings->task;
121  context->taskId = OS_INVALID_TASK_ID;
122 
123  //Attach TCP/IP stack context
124  context->netContext = settings->interface->netContext;
125 
126  //Save user settings
127  context->interface = settings->interface;
128  context->numPorts = settings->numPorts;
129  context->ports = settings->ports;
130  context->numNeighbors = settings->numNeighbors;
131  context->neighbors = settings->neighbors;
132  context->sendCallback = settings->sendCallback;
133  context->receiveCallback = settings->receiveCallback;
134  context->tickCallback = settings->tickCallback;
135 
136 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
137  //Appropriate values shall be set for the timing parameters
138  context->reinitDelay = LLDP_DEFAULT_REINIT_DELAY;
139  context->msgTxHold = LLDP_DEFAULT_MSG_TX_HOLD;
140  context->msgTxInterval = LLDP_DEFAULT_MSG_TX_INTERVAL;
141  context->txDelay = LLDP_DEFAULT_TX_DELAY;
142 
143  //Initialize local system MIB
144  lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_END_OF_LLDPDU, 0, NULL, 0, TRUE);
145 
146  //Point to the buffer where to format the Chassis ID TLV
147  chassisIdTlv = (LldpChassisIdTlv *) context->lldpdu.data;
148 
149  //By default, the chassis ID is the MAC address of the underlying interface
150  chassisIdTlv->chassisIdSubtype = LLDP_CHASSIS_ID_SUBTYPE_MAC_ADDR;
151  macCopyAddr(chassisIdTlv->chassisId, &context->interface->macAddr);
152 
153  //Set the value of the Chassis ID TLV
154  lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_CHASSIS_ID, 0,
155  (uint8_t *) chassisIdTlv, sizeof(LldpChassisIdTlv) + sizeof(MacAddr),
156  TRUE);
157 #endif
158 
159 #if (LLDP_RX_MODE_SUPPORT == ENABLED)
160  //If notification transmission is enabled for particular ports, the
161  //suggested default throttling period is 5 seconds.
162  context->notificationInterval = LLDP_DEFAULT_NOTIFICATION_INTERVAL;
163 #endif
164 
165  //Initialize port table
166  for(i = 0; i < context->numPorts; i++)
167  {
168  //Point to the current entry
169  port = &context->ports[i];
170 
171  //Clear port entry
172  osMemset(port, 0, sizeof(LldpPortEntry));
173 
174  //Attach LLDP agent context to each port
175  port->context = context;
176  //Set port index
177  port->portIndex = i + 1;
178 
179 #if (LLDP_TX_MODE_SUPPORT == ENABLED && LLDP_RX_MODE_SUPPORT == ENABLED)
180  //The local LLDP agent can both transmit and receive LLDP frames
181  port->adminStatus = LLDP_ADMIN_STATUS_ENABLED_TX_RX;
182 #elif (LLDP_TX_MODE_SUPPORT == ENABLED)
183  //The local LLDP agent can only transmit LLDP frames
185 #elif (LLDP_RX_MODE_SUPPORT == ENABLED)
186  //The local LLDP agent can only receive LLDP frames
188 #else
189  //The local LLDP agent can neither transmit or receive LLDP frames
190  port->adminStatus = LLDP_ADMIN_STATUS_DISABLED;
191 #endif
192 
193  //Set operational state
194  port->portEnabled = FALSE;
195 
196 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
197  //Each port must assigned a unique MAC address
199 
200  //Bit-map indicating the basic TLVs enabled for transmission
201  port->basicTlvFilter = LLDP_BASIC_TLV_FILTER_ALL;
202  //Bit-map indicating the management addresses enabled for transmission
203  port->mgmtAddrFilter = LLDP_MGMT_ADDR_FILTER_ALL;
204 
205  //Point to the buffer where to format the Port ID TLV
206  portIdTlv = (LldpPortIdTlv *) context->lldpdu.data;
207 
208  //By default, the port identifier is locally assigned
209  portIdTlv->portIdSubtype = LLDP_PORT_ID_SUBTYPE_LOCALLY_ASSIGNED;
210  n = osSprintf((char_t *) portIdTlv->portId, "%u", port->portIndex);
211 
212  //Set the value of the Port ID TLV
214  (uint8_t *) portIdTlv, sizeof(LldpPortIdTlv) + n, TRUE);
215 #endif
216  }
217 
218  //Initialize neighbor table
219  for(i = 0; i < context->numNeighbors; i++)
220  {
221  //Clear neighbor entry
222  osMemset(&context->neighbors[i], 0, sizeof(LldpNeighborEntry));
223  }
224 
225  //Initialize LLDP state machine
226  lldpInitFsm(context);
227 
228  //Start of exception handling block
229  do
230  {
231  //Create a mutex to prevent simultaneous access to LLDP agent context
232  if(!osCreateMutex(&context->mutex))
233  {
234  //Failed to create mutex
235  error = ERROR_OUT_OF_RESOURCES;
236  break;
237  }
238 
239  //Create an event object to poll the state of the raw socket
240  if(!osCreateEvent(&context->event))
241  {
242  //Failed to create event
243  error = ERROR_OUT_OF_RESOURCES;
244  break;
245  }
246 
247  //Successful initialization
248  error = NO_ERROR;
249 
250  //End of exception handling block
251  } while(0);
252 
253  //Any error to report?
254  if(error)
255  {
256  //Clean up side effects
257  lldpDeinit(context);
258  }
259 
260  //Successful initialization
261  return NO_ERROR;
262 }
263 
264 
265 /**
266  * @brief Start LLDP agent
267  * @param[in] context Pointer to the LLDP agent context
268  * @return Error code
269  **/
270 
272 {
273  error_t error;
274 
275  //Make sure the LLDP agent context is valid
276  if(context == NULL)
278 
279  //Debug message
280  TRACE_INFO("Starting LLDP agent...\r\n");
281 
282  //Make sure the LLDP agent is not already running
283  if(context->running)
284  return ERROR_ALREADY_RUNNING;
285 
286  //Start of exception handling block
287  do
288  {
289  //Open a raw socket
290  context->socket = socketOpenEx(context->netContext, SOCKET_TYPE_RAW_ETH,
291  ETH_TYPE_LLDP);
292  //Failed to open socket?
293  if(context->socket == NULL)
294  {
295  //Report an error
296  error = ERROR_OPEN_FAILED;
297  break;
298  }
299 
300  //Force the socket to operate in non-blocking mode
301  error = socketSetTimeout(context->socket, 0);
302  //Any error to report?
303  if(error)
304  break;
305 
306  //Associate the socket with the relevant interface
307  error = socketBindToInterface(context->socket, context->interface);
308  //Unable to bind the socket to the desired interface?
309  if(error)
310  break;
311 
312  //Add the LLDP multicast address to the static MAC table
313  error = lldpAcceptMulticastAddr(context);
314  //Any error to report?
315  if(error)
316  break;
317 
318  //Start the LLDP agent
319  context->stop = FALSE;
320  context->running = TRUE;
321 
322  //Save current time
323  context->timestamp = osGetSystemTime();
324 
325  //Create a task
326  context->taskId = osCreateTask("LLDP Agent", (OsTaskCode) lldpTask,
327  context, &context->taskParams);
328 
329  //Failed to create task?
330  if(context->taskId == OS_INVALID_TASK_ID)
331  {
332  //Report an error
333  error = ERROR_OUT_OF_RESOURCES;
334  break;
335  }
336 
337  //End of exception handling block
338  } while(0);
339 
340  //Any error to report?
341  if(error)
342  {
343  //Clean up side effects
344  context->running = FALSE;
345 
346  //Remove the LLDP multicast address from the static MAC table
347  lldpDropMulticastAddr(context);
348 
349  //Close the raw socket
350  socketClose(context->socket);
351  context->socket = NULL;
352  }
353 
354  //Return status code
355  return error;
356 }
357 
358 
359 /**
360  * @brief Stop LLDP agent
361  * @param[in] context Pointer to the LLDP agent context
362  * @return Error code
363  **/
364 
366 {
367  //Make sure the LLDP agent context is valid
368  if(context == NULL)
370 
371  //Debug message
372  TRACE_INFO("Stopping LLDP agent...\r\n");
373 
374  //Check whether the LLDP agent is running
375  if(context->running)
376  {
377 #if (NET_RTOS_SUPPORT == ENABLED)
378  //Stop the LLDP agent
379  context->stop = TRUE;
380  //Send a signal to the task to abort any blocking operation
381  osSetEvent(&context->event);
382 
383  //Wait for the task to terminate
384  while(context->running)
385  {
386  osDelayTask(1);
387  }
388 #endif
389 
390  //Remove the LLDP multicast address from the static MAC table
391  lldpDropMulticastAddr(context);
392 
393  //Close the raw socket
394  socketClose(context->socket);
395  context->socket = NULL;
396  }
397 
398  //Successful processing
399  return NO_ERROR;
400 }
401 
402 
403 /**
404  * @brief Set port address
405  * @param[in] context Pointer to the LLDP agent context
406  * @param[in] portIndex Port index
407  * @param[in] macAddr MAC address of the individual MAC entity for the port
408  * @return Error code
409  **/
410 
412  const MacAddr *macAddr)
413 {
414 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
416 
417  //Check parameters
418  if(context == NULL || macAddr == NULL)
420 
421  //Invalid port index?
422  if(portIndex < 1 || portIndex > context->numPorts)
423  return ERROR_INVALID_PORT;
424 
425  //Acquire exclusive access to the LLDP agent context
426  osAcquireMutex(&context->mutex);
427 
428  //Point to the port that matches the specified port index
429  port = &context->ports[portIndex - 1];
430 
431  //Set the MAC address of the individual MAC entity for the port
432  port->macAddr = *macAddr;
433 
434  //Release exclusive access to the LLDP agent context
435  osReleaseMutex(&context->mutex);
436 
437  //Successful processing
438  return NO_ERROR;
439 #else
440  //TX mode is not implemented
441  return ERROR_NOT_IMPLEMENTED;
442 #endif
443 }
444 
445 
446 /**
447  * @brief Set transmit interval
448  * @param[in] context Pointer to the LLDP agent context
449  * @param[in] msgTxInterval Time interval between successive transmit
450  * cycles, in seconds
451  * @return Error code
452  **/
453 
455 {
456  error_t error;
457 
458  //Make sure the LLDP agent context is valid
459  if(context != NULL)
460  {
461  //Acquire exclusive access to the LLDP agent context
462  osAcquireMutex(&context->mutex);
463  //Perform management operation
464  error = lldpMgmtSetMsgTxInterval(context, msgTxInterval, TRUE);
465  //Release exclusive access to the LLDP agent context
466  osReleaseMutex(&context->mutex);
467  }
468  else
469  {
470  //Report an error
471  error = ERROR_INVALID_PARAMETER;
472  }
473 
474  //Return status code
475  return error;
476 }
477 
478 
479 /**
480  * @brief Set transmit hold multiplier
481  * @param[in] context Pointer to the LLDP agent context
482  * @param[in] msgTxHold Multiplier on the msgTxInterval that determines the
483  * actual TTL value used in an LLDPDU
484  * @return Error code
485  **/
486 
488 {
489  error_t error;
490 
491  //Make sure the LLDP agent context is valid
492  if(context != NULL)
493  {
494  //Acquire exclusive access to the LLDP agent context
495  osAcquireMutex(&context->mutex);
496  //Perform management operation
497  error = lldpMgmtSetMsgTxHold(context, msgTxHold, TRUE);
498  //Release exclusive access to the LLDP agent context
499  osReleaseMutex(&context->mutex);
500  }
501  else
502  {
503  //Report an error
504  error = ERROR_INVALID_PARAMETER;
505  }
506 
507  //Return status code
508  return error;
509 }
510 
511 
512 /**
513  * @brief Set re-initialization delay
514  * @param[in] context Pointer to the LLDP agent context
515  * @param[in] reinitDelay Delay before re-initialization will be attempted
516  * @return Error code
517  **/
518 
520 {
521  error_t error;
522 
523  //Make sure the LLDP agent context is valid
524  if(context != NULL)
525  {
526  //Acquire exclusive access to the LLDP agent context
527  osAcquireMutex(&context->mutex);
528  //Perform management operation
529  error = lldpMgmtSetReinitDelay(context, reinitDelay, TRUE);
530  //Release exclusive access to the LLDP agent context
531  osReleaseMutex(&context->mutex);
532  }
533  else
534  {
535  //Report an error
536  error = ERROR_INVALID_PARAMETER;
537  }
538 
539  //Return status code
540  return error;
541 }
542 
543 
544 /**
545  * @brief Set transmit delay
546  * @param[in] context Pointer to the LLDP agent context
547  * @param[in] txDelay Delay between successive LLDP frame transmissions
548  * @return Error code
549  **/
550 
552 {
553  error_t error;
554 
555  //Make sure the LLDP agent context is valid
556  if(context != NULL)
557  {
558  //Acquire exclusive access to the LLDP agent context
559  osAcquireMutex(&context->mutex);
560  //Perform management operation
561  error = lldpMgmtSetTxDelay(context, txDelay, TRUE);
562  //Release exclusive access to the LLDP agent context
563  osReleaseMutex(&context->mutex);
564  }
565  else
566  {
567  //Report an error
568  error = ERROR_INVALID_PARAMETER;
569  }
570 
571  //Return status code
572  return error;
573 }
574 
575 
576 /**
577  * @brief Set administrative status
578  * @param[in] context Pointer to the LLDP agent context
579  * @param[in] portIndex Port index
580  * @param[in] adminStatus The administrative status indicates whether or not
581  * the local LLDP agent is enabled
582  * @return Error code
583  **/
584 
586  LldpAdminStatus adminStatus)
587 {
588  error_t error;
589 
590  //Make sure the LLDP agent context is valid
591  if(context != NULL)
592  {
593  //Acquire exclusive access to the LLDP agent context
594  osAcquireMutex(&context->mutex);
595  //Perform management operation
596  error = lldpMgmtSetAdminStatus(context, portIndex, adminStatus, TRUE);
597  //Release exclusive access to the LLDP agent context
598  osReleaseMutex(&context->mutex);
599  }
600  else
601  {
602  //Report an error
603  error = ERROR_INVALID_PARAMETER;
604  }
605 
606  //Return status code
607  return error;
608 }
609 
610 
611 /**
612  * @brief Set the list of TLVs enabled for transmission
613  * @param[in] context Pointer to the LLDP agent context
614  * @param[in] portIndex Port index
615  * @param[in] mask Bit-map indicating the TLVs enabled for transmission
616  * @return Error code
617  **/
618 
620  uint8_t mask)
621 {
622  error_t error;
623 
624  //Make sure the LLDP agent context is valid
625  if(context != NULL)
626  {
627  //Acquire exclusive access to the LLDP agent context
628  osAcquireMutex(&context->mutex);
629  //Perform management operation
630  error = lldpMgmtSetBasicTlvFilter(context, portIndex, mask, TRUE);
631  //Release exclusive access to the LLDP agent context
632  osReleaseMutex(&context->mutex);
633  }
634  else
635  {
636  //Report an error
637  error = ERROR_INVALID_PARAMETER;
638  }
639 
640  //Return status code
641  return error;
642 }
643 
644 
645 /**
646  * @brief Set the list of management addresses enabled for transmission
647  * @param[in] context Pointer to the LLDP agent context
648  * @param[in] portIndex Port index
649  * @param[in] mask Bit-map indicating the management addresses enabled for
650  * transmission
651  * @return Error code
652  **/
653 
655  uint32_t mask)
656 {
657 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
659 
660  //Make sure the LLDP agent context is valid
661  if(context == NULL)
663 
664  //Invalid port index?
665  if(portIndex < 1 || portIndex > context->numPorts)
666  return ERROR_INVALID_PORT;
667 
668  //Acquire exclusive access to the LLDP agent context
669  osAcquireMutex(&context->mutex);
670 
671  //Point to the port that matches the specified port index
672  port = &context->ports[portIndex - 1];
673 
674  //Each bit in the bitmap corresponds to a given management address
675  port->mgmtAddrFilter = mask & LLDP_MGMT_ADDR_FILTER_ALL;
676 
677  //The somethingChangedLocal flag must be set whenever the value of an
678  //object has changed in the local system MIB
679  lldpSomethingChangedLocal(context);
680 
681  //Release exclusive access to the LLDP agent context
682  osReleaseMutex(&context->mutex);
683 
684  //Successful processing
685  return NO_ERROR;
686 #else
687  //TX mode is not implemented
688  return ERROR_NOT_IMPLEMENTED;
689 #endif
690 }
691 
692 
693 /**
694  * @brief Set chassis ID
695  * @param[in] context Pointer to the LLDP agent context
696  * @param[in] chassisIdSubtype Type of identifier used for the chassis
697  * @param[in] chassisId Administratively assigned name that identifies the chassis
698  * @param[in] chassisIdLen Length of the chassis ID, in bytes
699  * @return Error code
700  **/
701 
703  LldpChassisIdSubtype chassisIdSubtype, const void *chassisId,
704  size_t chassisIdLen)
705 {
706 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
707  error_t error;
708  size_t n;
709  LldpChassisIdTlv *tlv;
710 
711  //Check parameters
712  if(context == NULL || chassisId == NULL)
714 
715  //Check the length of the chassis ID
716  if(chassisIdLen < LLDP_MIN_CHASSIS_ID_LEN ||
717  chassisIdLen > LLDP_MAX_CHASSIS_ID_LEN)
718  {
719  return ERROR_INVALID_LENGTH;
720  }
721 
722  //Acquire exclusive access to the LLDP agent context
723  osAcquireMutex(&context->mutex);
724 
725  //Point to the buffer where to format the TLV
726  tlv = (LldpChassisIdTlv *) context->lldpdu.data;
727 
728  //Set chassis ID subtype
729  tlv->chassisIdSubtype = chassisIdSubtype;
730  //Copy chassis ID
731  osMemcpy(tlv->chassisId, chassisId, chassisIdLen);
732 
733  //Calculate the length of the TLV
734  n = sizeof(LldpChassisIdTlv) + chassisIdLen;
735 
736  //Set the value of the specified TLV
737  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_CHASSIS_ID, 0,
738  (uint8_t *) tlv, n, TRUE);
739 
740  //Check status code
741  if(!error)
742  {
743  //The somethingChangedLocal flag must be set whenever the value of an
744  //object has changed in the local system MIB
745  lldpSomethingChangedLocal(context);
746  }
747 
748  //Release exclusive access to the LLDP agent context
749  osReleaseMutex(&context->mutex);
750 
751  //Return status code
752  return error;
753 #else
754  //TX mode is not implemented
755  return ERROR_NOT_IMPLEMENTED;
756 #endif
757 }
758 
759 
760 /**
761  * @brief Set port ID
762  * @param[in] context Pointer to the LLDP agent context
763  * @param[in] portIndex Port index
764  * @param[in] portIdSubtype Type of identifier used for the port
765  * @param[in] portId Administratively assigned name that identifies the port
766  * @param[in] portIdLen Length of the port ID, in bytes
767  * @return Error code
768  **/
769 
771  LldpPortIdSubtype portIdSubtype, const void *portId, size_t portIdLen)
772 {
773 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
774  error_t error;
775  size_t n;
777  LldpPortIdTlv *tlv;
778 
779  //Check parameters
780  if(context == NULL || portId == NULL)
782 
783  //Invalid port index?
784  if(portIndex < 1 || portIndex > context->numPorts)
785  return ERROR_INVALID_PORT;
786 
787  //Check the length of the port ID
788  if(portIdLen < LLDP_MIN_PORT_ID_LEN || portIdLen > LLDP_MAX_PORT_ID_LEN)
789  {
790  return ERROR_INVALID_LENGTH;
791  }
792 
793  //Acquire exclusive access to the LLDP agent context
794  osAcquireMutex(&context->mutex);
795 
796  //Point to the port that matches the specified port index
797  port = &context->ports[portIndex - 1];
798 
799  //Point to the buffer where to format the TLV
800  tlv = (LldpPortIdTlv *) context->lldpdu.data;
801 
802  //Set port ID subtype
803  tlv->portIdSubtype = portIdSubtype;
804  //Copy port ID
805  osMemcpy(tlv->portId, portId, portIdLen);
806 
807  //Calculate the length of the TLV
808  n = sizeof(LldpPortIdTlv) + portIdLen;
809 
810  //Set the value of the specified TLV
811  error = lldpSetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_ID, 0,
812  (uint8_t *) tlv, n, TRUE);
813 
814  //Check status code
815  if(!error)
816  {
817  //The somethingChangedLocal flag must be set whenever the value of an
818  //object has changed in the local system MIB
819  lldpSomethingChangedLocal(context);
820  }
821 
822  //Release exclusive access to the LLDP agent context
823  osReleaseMutex(&context->mutex);
824 
825  //Return status code
826  return error;
827 #else
828  //TX mode is not implemented
829  return ERROR_NOT_IMPLEMENTED;
830 #endif
831 }
832 
833 
834 /**
835  * @brief Set port description
836  * @param[in] context Pointer to the LLDP agent context
837  * @param[in] portIndex Port index
838  * @param[in] portDesc Station port's description
839  * @return Error code
840  **/
841 
843  const char_t *portDesc)
844 {
845 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
846  error_t error;
847  size_t n;
849 
850  //Check parameters
851  if(context == NULL || portDesc == NULL)
853 
854  //Invalid port index?
855  if(portIndex < 1 || portIndex > context->numPorts)
856  return ERROR_INVALID_PORT;
857 
858  //Get the length of the port's description
859  n = osStrlen(portDesc);
860 
861  //Check the length of the string
862  if(n < LLDP_MIN_PORT_DESC_LEN || n > LLDP_MAX_PORT_DESC_LEN)
863  {
864  return ERROR_INVALID_LENGTH;
865  }
866 
867  //Acquire exclusive access to the LLDP agent context
868  osAcquireMutex(&context->mutex);
869 
870  //Point to the port that matches the specified port index
871  port = &context->ports[portIndex - 1];
872 
873  //Set the value of the specified TLV
874  error = lldpSetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_DESC, 0,
875  (uint8_t *) portDesc, n, TRUE);
876 
877  //Check status code
878  if(!error)
879  {
880  //The somethingChangedLocal flag must be set whenever the value of an
881  //object has changed in the local system MIB
882  lldpSomethingChangedLocal(context);
883  }
884 
885  //Release exclusive access to the LLDP agent context
886  osReleaseMutex(&context->mutex);
887 
888  //Return status code
889  return error;
890 #else
891  //TX mode is not implemented
892  return ERROR_NOT_IMPLEMENTED;
893 #endif
894 }
895 
896 
897 /**
898  * @brief Set system name
899  * @param[in] context Pointer to the LLDP agent context
900  * @param[in] sysName System's administratively assigned name
901  * @return Error code
902  **/
903 
905 {
906 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
907  error_t error;
908  size_t n;
909 
910  //Check parameters
911  if(context == NULL || sysName == NULL)
913 
914  //Get the length of the system name
915  n = osStrlen(sysName);
916 
917  //Check the length of the string
918  if(n < LLDP_MIN_SYS_NAME_LEN ||
920  {
921  return ERROR_INVALID_LENGTH;
922  }
923 
924  //Acquire exclusive access to the LLDP agent context
925  osAcquireMutex(&context->mutex);
926 
927  //Set the value of the specified TLV
928  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_NAME, 0,
929  (uint8_t *) sysName, n, TRUE);
930 
931  //Check status code
932  if(!error)
933  {
934  //The somethingChangedLocal flag must be set whenever the value of an
935  //object has changed in the local system MIB
936  lldpSomethingChangedLocal(context);
937  }
938 
939  //Release exclusive access to the LLDP agent context
940  osReleaseMutex(&context->mutex);
941 
942  //Return status code
943  return error;
944 #else
945  //TX mode is not implemented
946  return ERROR_NOT_IMPLEMENTED;
947 #endif
948 }
949 
950 
951 /**
952  * @brief Set system description
953  * @param[in] context Pointer to the LLDP agent context
954  * @param[in] sysDesc Textual description of the network entity
955  * @return Error code
956  **/
957 
959 {
960 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
961  error_t error;
962  size_t n;
963 
964  //Check parameters
965  if(context == NULL || sysDesc == NULL)
967 
968  //Get the length of the system description
969  n = osStrlen(sysDesc);
970 
971  //Check the length of the string
972  if(n < LLDP_MIN_SYS_DESC_LEN ||
974  {
975  return ERROR_INVALID_LENGTH;
976  }
977 
978  //Acquire exclusive access to the LLDP agent context
979  osAcquireMutex(&context->mutex);
980 
981  //Set the value of the specified TLV
982  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_DESC, 0,
983  (uint8_t *) sysDesc, n, TRUE);
984 
985  //Check status code
986  if(!error)
987  {
988  //The somethingChangedLocal flag must be set whenever the value of an
989  //object has changed in the local system MIB
990  lldpSomethingChangedLocal(context);
991  }
992 
993  //Release exclusive access to the LLDP agent context
994  osReleaseMutex(&context->mutex);
995 
996  //Return status code
997  return error;
998 #else
999  //TX mode is not implemented
1000  return ERROR_NOT_IMPLEMENTED;
1001 #endif
1002 }
1003 
1004 
1005 /**
1006  * @brief Set system capabilities
1007  * @param[in] context Pointer to the LLDP agent context
1008  * @param[in] supportedCap Bit-map of the capabilities supported by the system
1009  * @param[in] enabledCap Bit-map of the capabilities currently enabled
1010  * @return Error code
1011  **/
1012 
1013 error_t lldpSetLocalSysCap(LldpAgentContext *context, uint16_t supportedCap,
1014  uint16_t enabledCap)
1015 {
1016 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1017  error_t error;
1018  size_t n;
1019  LldpSysCapTlv *tlv;
1020 
1021  //Make sure the LLDP agent context is valid
1022  if(context == NULL)
1023  return ERROR_INVALID_PARAMETER;
1024 
1025  //Acquire exclusive access to the LLDP agent context
1026  osAcquireMutex(&context->mutex);
1027 
1028  //Point to the buffer where to format the TLV
1029  tlv = (LldpSysCapTlv *) context->lldpdu.data;
1030 
1031  //Set supported capabilities
1032  tlv->supportedCap = htons(supportedCap);
1033  //Set enabled capabilities
1034  tlv->enabledCap = htons(enabledCap);
1035 
1036  //Calculate the length of the TLV
1037  n = sizeof(LldpSysCapTlv);
1038 
1039  //Set the value of the specified TLV
1040  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_CAP, 0,
1041  (uint8_t *) tlv, n, TRUE);
1042 
1043  //Check status code
1044  if(!error)
1045  {
1046  //The somethingChangedLocal flag must be set whenever the value of an
1047  //object has changed in the local system MIB
1048  lldpSomethingChangedLocal(context);
1049  }
1050 
1051  //Release exclusive access to the LLDP agent context
1052  osReleaseMutex(&context->mutex);
1053 
1054  //Return status code
1055  return error;
1056 #else
1057  //TX mode is not implemented
1058  return ERROR_NOT_IMPLEMENTED;
1059 #endif
1060 }
1061 
1062 
1063 /**
1064  * @brief Set management address
1065  * @param[in] context Pointer to the LLDP agent context
1066  * @param[in] index Zero-based index identifying a management address
1067  * @param[in] mgmtAddrSubtype Type of management address
1068  * @param[in] mgmtAddr Octet string indicating a particular management
1069  * address
1070  * @param[in] mgmtAddrLen Length of the management address, in bytes
1071  * @param[in] ifNumSubtype Numbering method used for defining the interface
1072  * number
1073  * @param[in] ifNum Number within the system that identifies the specific
1074  * interface associated with this management address
1075  * @param[in] oid OID that identifies the type of hardware component or
1076  * protocol entity associated with the indicated management address
1077  * @param[in] oidLen Length of the OID, in bytes
1078  * @return Error code
1079  **/
1080 
1083  size_t mgmtAddrLen, LldpIfNumSubtype ifNumSubtype, uint32_t ifNum,
1084  const uint8_t *oid, size_t oidLen)
1085 {
1086 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1087  error_t error;
1088  uint_t i;
1089  uint_t k;
1090  size_t n;
1091  LldpMgmtAddrTlv1 *tlv1;
1092  LldpMgmtAddrTlv2 *tlv2;
1093 
1094  //Make sure the LLDP agent context is valid
1095  if(context == NULL)
1096  return ERROR_INVALID_PARAMETER;
1097 
1098  //Check index value
1099  if(index > LLDP_MAX_MGMT_ADDRS)
1100  return ERROR_INVALID_PARAMETER;
1101 
1102  //Make sure the management address is valid
1103  if(mgmtAddr == NULL && mgmtAddrLen != 0)
1104  return ERROR_INVALID_PARAMETER;
1105 
1106  //Check the length of the management address
1107  if(mgmtAddrLen > LLDP_MAX_MGMT_ADDR_LEN)
1108  return ERROR_INVALID_LENGTH;
1109 
1110  //Make sure the object identifier is valid
1111  if(oid == NULL && oidLen != 0)
1112  return ERROR_INVALID_PARAMETER;
1113 
1114  //Check the length of the object identifier
1115  if(oidLen > LLDP_MAX_OID_LEN)
1116  return ERROR_INVALID_LENGTH;
1117 
1118  //Acquire exclusive access to the LLDP agent context
1119  osAcquireMutex(&context->mutex);
1120 
1121  //An individual LLDPDU may contain more than one Management Address
1122  //TLV (refer to IEEE 802.1AB-2005, section 9.5.9.9)
1123  for(i = 0, k = 0; i < index; i++)
1124  {
1125  //Check whether the current management address is configured
1126  if((context->mgmtAddrMap & (1U << i)) != 0)
1127  {
1128  k++;
1129  }
1130  }
1131 
1132  //Valid management address?
1133  if(mgmtAddrLen > 0)
1134  {
1135  //Point to the buffer where to format the first part of the TLV
1136  tlv1 = (LldpMgmtAddrTlv1 *) context->lldpdu.data;
1137 
1138  //The management address string length shall contain the length management
1139  //address subtype and management address fields
1140  tlv1->mgmtAddrLen = mgmtAddrLen + 1;
1141 
1142  //Set management address subtype
1143  tlv1->mgmtAddrSubtype = mgmtAddrSubtype;
1144  //Copy management address
1145  osMemcpy(tlv1->mgmtAddr, mgmtAddr, mgmtAddrLen);
1146 
1147  //Point to the buffer where to format the second part of the TLV
1148  tlv2 = (LldpMgmtAddrTlv2 *) (tlv1->mgmtAddr + mgmtAddrLen);
1149 
1150  //Set interface numbering subtype
1151  tlv2->ifNumSubtype = ifNumSubtype;
1152  //Set interface number
1153  tlv2->ifNum = htonl(ifNum);
1154  //Set OID string length
1155  tlv2->oidLen = oidLen;
1156  //Copy object identifier
1157  osMemcpy(tlv2->oid, oid, oidLen);
1158 
1159  //Calculate the length of the TLV
1160  n = sizeof(LldpMgmtAddrTlv1) + mgmtAddrLen + sizeof(LldpMgmtAddrTlv2) +
1161  oidLen;
1162 
1163  //Check whether the TLV already exists
1164  if((context->mgmtAddrMap & (1U << index)) != 0)
1165  {
1166  //Replace existing TLV
1167  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k,
1168  (uint8_t *) tlv1, n, TRUE);
1169  }
1170  else
1171  {
1172  //Add a new TLV
1173  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k,
1174  (uint8_t *) tlv1, n, FALSE);
1175  }
1176 
1177  //Check status code
1178  if(!error)
1179  {
1180  //The management address is now configured
1181  context->mgmtAddrMap |= (1U << index);
1182  }
1183  }
1184  else
1185  {
1186  //Remove the specified TLV from the local system information
1187  error = lldpDeleteTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k);
1188 
1189  //The management address is no longer used
1190  context->mgmtAddrMap &= ~(1U << index);
1191  }
1192 
1193  //Check status code
1194  if(!error)
1195  {
1196  //The somethingChangedLocal flag must be set whenever the value of an
1197  //object has changed in the local system MIB
1198  lldpSomethingChangedLocal(context);
1199  }
1200 
1201  //Release exclusive access to the LLDP agent context
1202  osReleaseMutex(&context->mutex);
1203 
1204  //Return status code
1205  return error;
1206 #else
1207  //TX mode is not implemented
1208  return ERROR_NOT_IMPLEMENTED;
1209 #endif
1210 }
1211 
1212 
1213 /**
1214  * @brief Remove all TLVs with specified type
1215  * @param[in] context Pointer to the LLDP agent context
1216  * @param[in] type TLV type
1217  * @return Error code
1218  **/
1219 
1221 {
1222 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1223  error_t error;
1224  uint_t i;
1225  bool_t somethingChangedLocal;
1226 
1227  //Make sure the LLDP agent context is valid
1228  if(context == NULL)
1229  return ERROR_INVALID_PARAMETER;
1230 
1231  //Check TLV type
1232  if(type != LLDP_TLV_TYPE_PORT_DESC &&
1238  {
1239  return ERROR_INVALID_TYPE;
1240  }
1241 
1242  //Acquire exclusive access to the LLDP agent context
1243  osAcquireMutex(&context->mutex);
1244 
1245  //Initialize status code
1246  error = NO_ERROR;
1247  //Clear flag
1248  somethingChangedLocal = FALSE;
1249 
1250  //Remove all TLVs that match the specified type
1251  while(!error)
1252  {
1253  //Remove one TLV at a time
1254  error = lldpDeleteTlv(&context->txInfo, type, 0);
1255 
1256  //Check status code
1257  if(!error)
1258  {
1259  somethingChangedLocal = TRUE;
1260  }
1261  }
1262 
1263  //Loop through the ports
1264  for(i = 0; i < context->numPorts; i++)
1265  {
1266  //Initialize status code
1267  error = NO_ERROR;
1268 
1269  //Remove all port-specific TLVs that match the specified type
1270  while(!error)
1271  {
1272  //Remove one TLV at a time
1273  error = lldpDeleteTlv(&context->ports[i].txInfo, type, 0);
1274 
1275  //Check status code
1276  if(!error)
1277  {
1278  somethingChangedLocal = TRUE;
1279  }
1280  }
1281  }
1282 
1283  //Any change in the LLDP local system MIB?
1284  if(somethingChangedLocal)
1285  {
1286  //The somethingChangedLocal flag must be set whenever the value of an
1287  //object has changed in the local system MIB
1288  lldpSomethingChangedLocal(context);
1289 
1290  //Successful processing
1291  error = NO_ERROR;
1292  }
1293  else
1294  {
1295  //Report an error
1296  error = ERROR_NOT_FOUND;
1297  }
1298 
1299  //Release exclusive access to the LLDP agent context
1300  osReleaseMutex(&context->mutex);
1301 
1302  //Return status code
1303  return error;
1304 #else
1305  //TX mode is not implemented
1306  return ERROR_NOT_IMPLEMENTED;
1307 #endif
1308 }
1309 
1310 
1311 /**
1312  * @brief LLDP agent task
1313  * @param[in] context Pointer to the LLDP agent context
1314  **/
1315 
1317 {
1318  systime_t time;
1319  systime_t timeout;
1320  SocketEventDesc eventDesc;
1321 
1322 #if (NET_RTOS_SUPPORT == ENABLED)
1323  //Task prologue
1324  osEnterTask();
1325 
1326  //Main loop
1327  while(1)
1328  {
1329 #endif
1330  //Get current time
1331  time = osGetSystemTime();
1332 
1333  //Maximum time to wait for an incoming datagram
1334  if((time - context->timestamp) < LLDP_TICK_INTERVAL)
1335  {
1336  timeout = context->timestamp + LLDP_TICK_INTERVAL - time;
1337  }
1338  else
1339  {
1340  timeout = 0;
1341  }
1342 
1343  //Specify the events the application is interested in
1344  eventDesc.socket = context->socket;
1345  eventDesc.eventMask = SOCKET_EVENT_RX_READY;
1346  eventDesc.eventFlags = 0;
1347 
1348  //Wait for an event
1349  socketPoll(&eventDesc, 1, &context->event, timeout);
1350 
1351  //Stop request?
1352  if(context->stop)
1353  {
1354  //Stop LLDP agent operation
1355  context->running = FALSE;
1356  //Task epilogue
1357  osExitTask();
1358  //Kill ourselves
1360  }
1361 
1362  //Any LLDP frame received?
1363  if(eventDesc.eventFlags != 0)
1364  {
1365  //Acquire exclusive access to the LLDP agent context
1366  osAcquireMutex(&context->mutex);
1367  //Frame reception process
1368  lldpProcessFrame(context);
1369  //Release exclusive access to the LLDP agent context
1370  osReleaseMutex(&context->mutex);
1371  }
1372 
1373  //Get current time
1374  time = osGetSystemTime();
1375 
1376  //All LLDP timers have a resolution of one second
1377  if((time - context->timestamp) >= LLDP_TICK_INTERVAL)
1378  {
1379  //Acquire exclusive access to the LLDP agent context
1380  osAcquireMutex(&context->mutex);
1381  //Handle periodic operations
1382  lldpTick(context);
1383  //Release exclusive access to the LLDP agent context
1384  osReleaseMutex(&context->mutex);
1385 
1386  //Save current time
1387  context->timestamp = time;
1388  }
1389 #if (NET_RTOS_SUPPORT == ENABLED)
1390  }
1391 #endif
1392 }
1393 
1394 
1395 /**
1396  * @brief Release LLDP agent context
1397  * @param[in] context Pointer to the LLDP agent context
1398  **/
1399 
1401 {
1402  //Make sure the LLDP agent context is valid
1403  if(context != NULL)
1404  {
1405  //Free previously allocated resources
1406  osDeleteMutex(&context->mutex);
1407  osDeleteEvent(&context->event);
1408 
1409  //Clear LLDP agent context
1410  osMemset(context, 0, sizeof(LldpAgentContext));
1411  }
1412 }
1413 
1414 #endif
error_t lldpDropMulticastAddr(LldpAgentContext *context)
Remove the LLDP multicast address from the static MAC table.
Definition: lldp_misc.c:635
#define htons(value)
Definition: cpu_endian.h:413
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
@ LLDP_TLV_TYPE_SYS_CAP
System Capabilities.
Definition: lldp_tlv.h:100
#define LLDP_MIN_SYS_DESC_LEN
Definition: lldp_tlv.h:67
int bool_t
Definition: compiler_port.h:63
#define LLDP_TICK_INTERVAL
Definition: lldp.h:87
@ ERROR_NOT_FOUND
Definition: error.h:148
#define LLDP_DEFAULT_NOTIFICATION_INTERVAL
Definition: lldp.h:137
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
uint8_t portId[]
Definition: lldp_tlv.h:254
error_t lldpSetTxDelay(LldpAgentContext *context, uint_t txDelay)
Set transmit delay.
Definition: lldp.c:551
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
#define osExitTask()
uint8_t chassisId[]
Definition: lldp_tlv.h:243
error_t lldpDeleteTlv(LldpDataUnit *lldpdu, uint8_t type, uint_t index)
Remove a TLV from a LLDPDU.
Definition: lldp_tlv.c:320
error_t lldpStop(LldpAgentContext *context)
Stop LLDP agent.
Definition: lldp.c:365
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
void lldpProcessFrame(LldpAgentContext *context)
Process incoming LLDP frame.
Definition: lldp_misc.c:170
error_t lldpMgmtSetMsgTxInterval(LldpAgentContext *context, uint_t msgTxInterval, bool_t commit)
Set transmit interval.
Definition: lldp_mgmt.c:81
#define LLDP_MAX_SYS_NAME_LEN
Definition: lldp_tlv.h:64
OsTaskParameters task
Task parameters.
Definition: lldp.h:317
#define TRUE
Definition: os_port.h:50
#define OS_INVALID_TASK_ID
void socketClose(Socket *socket)
Close an existing socket.
Definition: socket.c:2094
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
@ LLDP_TLV_TYPE_MGMT_ADDR
Management Address.
Definition: lldp_tlv.h:101
#define LLDP_MAX_OID_LEN
Definition: lldp_tlv.h:79
#define LLDP_MIN_SYS_NAME_LEN
Definition: lldp_tlv.h:62
@ LLDP_BASIC_TLV_FILTER_ALL
All Basic TLVs.
Definition: lldp.h:205
error_t lldpSetMgmtAddrFilter(LldpAgentContext *context, uint_t portIndex, uint32_t mask)
Set the list of management addresses enabled for transmission.
Definition: lldp.c:654
#define LLDP_MAX_PORT_ID_LEN
Definition: lldp_tlv.h:54
@ LLDP_TLV_TYPE_ORG_DEFINED
Organizationally Specific TLVs.
Definition: lldp_tlv.h:102
uint8_t type
Definition: coap_common.h:176
LLDP state machine.
@ ERROR_INVALID_PORT
Definition: error.h:104
NetInterface * interface
Underlying network interface.
Definition: lldp.h:318
LldpReceiveCallback receiveCallback
LLDP frame reception callback function.
Definition: lldp.h:324
#define osStrlen(s)
Definition: os_port.h:168
error_t lldpMgmtSetMsgTxHold(LldpAgentContext *context, uint_t msgTxHold, bool_t commit)
Set transmit hold multiplier.
Definition: lldp_mgmt.c:127
LldpNeighborEntry * neighbors
Neighbor table.
Definition: lldp.h:322
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
LldpTlvType
TLV type values.
Definition: lldp_tlv.h:92
LldpPortIdSubtype
Port ID subtypes.
Definition: lldp_tlv.h:128
#define OS_SELF_TASK_ID
LldpSendCallback sendCallback
LLDP frame transmission callback function.
Definition: lldp.h:323
uint8_t oid[]
Definition: lldp_tlv.h:300
Structure describing socket events.
Definition: socket.h:433
error_t lldpSetTlv(LldpDataUnit *lldpdu, uint8_t type, uint_t index, const uint8_t *value, size_t length, bool_t replace)
Add or replace a TLV.
Definition: lldp_tlv.c:56
#define macCopyAddr(destMacAddr, srcMacAddr)
Definition: ethernet.h:127
uint_t numPorts
Number of ports.
Definition: lldp.h:319
error_t lldpSetBasicTlvFilter(LldpAgentContext *context, uint_t portIndex, uint8_t mask)
Set the list of TLVs enabled for transmission.
Definition: lldp.c:619
@ LLDP_TLV_TYPE_END_OF_LLDPDU
End Of LLDPDU.
Definition: lldp_tlv.h:93
@ ETH_TYPE_LLDP
Definition: ethernet.h:173
#define LLDP_DEFAULT_REINIT_DELAY
Definition: lldp.h:123
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_OPEN_FAILED
Definition: error.h:75
@ LLDP_CHASSIS_ID_SUBTYPE_MAC_ADDR
MAC address.
Definition: lldp_tlv.h:116
error_t lldpSetLocalPortId(LldpAgentContext *context, uint_t portIndex, LldpPortIdSubtype portIdSubtype, const void *portId, size_t portIdLen)
Set port ID.
Definition: lldp.c:770
void osDeleteTask(OsTaskId taskId)
Delete a task.
#define FALSE
Definition: os_port.h:46
LldpIfNumSubtype
Interface numbering subtypes.
Definition: lldp_tlv.h:175
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define htonl(value)
Definition: cpu_endian.h:414
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
error_t lldpSetPortAddr(LldpAgentContext *context, uint_t portIndex, const MacAddr *macAddr)
Set port address.
Definition: lldp.c:411
#define LLDP_MIN_CHASSIS_ID_LEN
Definition: lldp_tlv.h:47
error_t
Error codes.
Definition: error.h:43
#define osSprintf(dest,...)
Definition: os_port.h:234
error_t lldpStart(LldpAgentContext *context)
Start LLDP agent.
Definition: lldp.c:271
@ LLDP_PORT_ID_SUBTYPE_LOCALLY_ASSIGNED
Locally assigned.
Definition: lldp_tlv.h:136
#define LLDP_MAX_CHASSIS_ID_LEN
Definition: lldp_tlv.h:49
error_t lldpSetLocalSysDesc(LldpAgentContext *context, const char_t *sysDesc)
Set system description.
Definition: lldp.c:958
void(* OsTaskCode)(void *arg)
Task routine.
void lldpGetDefaultSettings(LldpAgentSettings *settings)
Initialize settings with default values.
Definition: lldp.c:51
error_t lldpSetLocalChassisId(LldpAgentContext *context, LldpChassisIdSubtype chassisIdSubtype, const void *chassisId, size_t chassisIdLen)
Set chassis ID.
Definition: lldp.c:702
void lldpTask(LldpAgentContext *context)
LLDP agent task.
Definition: lldp.c:1316
LldpTickCallback tickCallback
Tick callback function.
Definition: lldp.h:325
void osDeleteEvent(OsEvent *event)
Delete an event object.
error_t lldpSetMsgTxInterval(LldpAgentContext *context, uint_t msgTxInterval)
Set transmit interval.
Definition: lldp.c:454
#define LLDP_TASK_PRIORITY
Definition: lldp.h:82
#define LldpPortEntry
Definition: lldp.h:44
@ ERROR_INVALID_LENGTH
Definition: error.h:111
@ LLDP_ADMIN_STATUS_ENABLED_RX_ONLY
The local LLDP agent can only receive LLDP frames.
Definition: lldp.h:190
LldpPortEntry * ports
Port table.
Definition: lldp.h:320
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
uint8_t mask
Definition: web_socket.h:319
Helper functions for LLDP.
@ ERROR_INVALID_TYPE
Definition: error.h:115
error_t lldpSetAdminStatus(LldpAgentContext *context, uint_t portIndex, LldpAdminStatus adminStatus)
Set administrative status.
Definition: lldp.c:585
void lldpTick(LldpAgentContext *context)
LLDP agent timer handler.
Definition: lldp_misc.c:58
LldpPortIdTlv
Definition: lldp_tlv.h:255
#define TRACE_INFO(...)
Definition: debug.h:105
error_t lldpSetLocalSysName(LldpAgentContext *context, const char_t *sysName)
Set system name.
Definition: lldp.c:904
void lldpInitFsm(LldpAgentContext *context)
LLDP state machine initialization.
Definition: lldp_fsm.c:52
LLDP agent settings.
Definition: lldp.h:316
#define osEnterTask()
@ LLDP_TLV_TYPE_SYS_NAME
System Name.
Definition: lldp_tlv.h:98
uint_t eventFlags
Returned events.
Definition: socket.h:436
#define LLDP_DEFAULT_MSG_TX_HOLD
Definition: lldp.h:116
error_t socketPoll(SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
Wait for one of a set of sockets to become ready to perform I/O.
Definition: socket.c:2182
#define socketBindToInterface
Definition: net_legacy.h:193
error_t lldpSetLocalMgmtAddr(LldpAgentContext *context, uint_t index, LldpMgmtAddrSubtype mgmtAddrSubtype, const void *mgmtAddr, size_t mgmtAddrLen, LldpIfNumSubtype ifNumSubtype, uint32_t ifNum, const uint8_t *oid, size_t oidLen)
Set management address.
Definition: lldp.c:1081
MacAddr
Definition: ethernet.h:197
#define LLDP_MGMT_ADDR_FILTER_ALL
Definition: lldp.h:174
uint32_t systime_t
System time.
uint16_t port
Definition: dns_common.h:270
@ LLDP_ADMIN_STATUS_ENABLED_TX_RX
Definition: lldp.h:191
void lldpDeinit(LldpAgentContext *context)
Release LLDP agent context.
Definition: lldp.c:1400
@ LLDP_TLV_TYPE_CHASSIS_ID
Chassis ID.
Definition: lldp_tlv.h:94
LLDP neighbor entry.
Definition: lldp.h:260
char char_t
Definition: compiler_port.h:55
uint32_t time
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
@ LLDP_TLV_TYPE_SYS_DESC
System Description.
Definition: lldp_tlv.h:99
uint_t numNeighbors
Maximum number of entries in the neighbor table.
Definition: lldp.h:321
@ SOCKET_EVENT_RX_READY
Definition: socket.h:179
#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
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Socket * socketOpenEx(NetContext *context, uint_t type, uint_t protocol)
Create a socket.
Definition: socket.c:146
#define LLDP_MAX_PORT_DESC_LEN
Definition: lldp_tlv.h:59
error_t lldpSetLocalSysCap(LldpAgentContext *context, uint16_t supportedCap, uint16_t enabledCap)
Set system capabilities.
Definition: lldp.c:1013
uint32_t ifNum
Definition: lldp_tlv.h:298
bool_t osCreateEvent(OsEvent *event)
Create an event object.
uint8_t oidLen
Definition: lldp_tlv.h:299
LldpChassisIdSubtype
Chassis ID subtypes.
Definition: lldp_tlv.h:111
LldpAdminStatus
Administrative status.
Definition: lldp.h:187
@ SOCKET_TYPE_RAW_ETH
Definition: socket.h:95
#define LldpAgentContext
Definition: lldp.h:40
Management of the LLDP agent.
error_t lldpAcceptMulticastAddr(LldpAgentContext *context)
Add the LLDP multicast address to the static MAC table.
Definition: lldp_misc.c:580
void osDelayTask(systime_t delay)
Delay routine.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
LldpMgmtAddrTlv2
Definition: lldp_tlv.h:301
error_t lldpSetReinitDelay(LldpAgentContext *context, uint_t reinitDelay)
Set re-initialization delay.
Definition: lldp.c:519
#define LLDP_DEFAULT_MSG_TX_INTERVAL
Definition: lldp.h:109
@ 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
void lldpGeneratePortAddr(LldpPortEntry *port)
Port's MAC address generation.
Definition: lldp_misc.c:689
uint8_t mgmtAddrSubtype
Definition: lldp_tlv.h:286
LLDP (Link Layer Discovery Protocol)
#define LLDP_MAX_MGMT_ADDR_LEN
Definition: lldp_tlv.h:74
LldpMgmtAddrSubtype
Management address subtypes.
Definition: lldp_tlv.h:162
Socket * socket
Handle to a socket to monitor.
Definition: socket.h:434
error_t lldpSetMsgTxHold(LldpAgentContext *context, uint_t msgTxHold)
Set transmit hold multiplier.
Definition: lldp.c:487
unsigned int uint_t
Definition: compiler_port.h:57
#define osMemset(p, value, length)
Definition: os_port.h:138
TCP/IP stack core.
error_t lldpDeleteLocalTlv(LldpAgentContext *context, LldpTlvType type)
Remove all TLVs with specified type.
Definition: lldp.c:1220
error_t lldpSetLocalPortDesc(LldpAgentContext *context, uint_t portIndex, const char_t *portDesc)
Set port description.
Definition: lldp.c:842
error_t lldpInit(LldpAgentContext *context, const LldpAgentSettings *settings)
LLDP agent initialization.
Definition: lldp.c:87
LldpSysCapTlv
Definition: lldp_tlv.h:276
#define LLDP_MAX_SYS_DESC_LEN
Definition: lldp_tlv.h:69
LldpMgmtAddrTlv1
Definition: lldp_tlv.h:288
#define LLDP_DEFAULT_TX_DELAY
Definition: lldp.h:130
error_t socketSetTimeout(Socket *socket, systime_t timeout)
Set timeout value for blocking operations.
Definition: socket.c:169
#define LLDP_TASK_STACK_SIZE
Definition: lldp.h:75
@ LLDP_TLV_TYPE_PORT_DESC
Port Description.
Definition: lldp_tlv.h:97
uint_t eventMask
Requested events.
Definition: socket.h:435
@ ERROR_ALREADY_RUNNING
Definition: error.h:294
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
error_t lldpMgmtSetAdminStatus(LldpAgentContext *context, uint_t portIndex, LldpAdminStatus adminStatus, bool_t commit)
Set administrative status.
Definition: lldp_mgmt.c:297
@ LLDP_ADMIN_STATUS_ENABLED_TX_ONLY
The local LLDP agent can only transmit LLDP frames.
Definition: lldp.h:189
systime_t osGetSystemTime(void)
Retrieve system time.