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