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.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL LLDP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "lldp/lldp.h"
37 #include "lldp/lldp_mgmt.h"
38 #include "lldp/lldp_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  break;
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  break;
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 #if (NET_RTOS_SUPPORT == ENABLED)
374  //Stop the LLDP agent
375  context->stop = TRUE;
376  //Send a signal to the task to abort any blocking operation
377  osSetEvent(&context->event);
378 
379  //Wait for the task to terminate
380  while(context->running)
381  {
382  osDelayTask(1);
383  }
384 #endif
385 
386  //Remove the LLDP multicast address from the static MAC table
387  lldpDropMulticastAddr(context);
388 
389  //Close the raw socket
390  socketClose(context->socket);
391  context->socket = NULL;
392  }
393 
394  //Successful processing
395  return NO_ERROR;
396 }
397 
398 
399 /**
400  * @brief Set port address
401  * @param[in] context Pointer to the LLDP agent context
402  * @param[in] portIndex Port index
403  * @param[in] macAddr MAC address of the individual MAC entity for the port
404  * @return Error code
405  **/
406 
408  const MacAddr *macAddr)
409 {
410 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
412 
413  //Check parameters
414  if(context == NULL || macAddr == NULL)
416 
417  //Invalid port index?
418  if(portIndex < 1 || portIndex > context->numPorts)
419  return ERROR_INVALID_PORT;
420 
421  //Acquire exclusive access to the LLDP agent context
422  osAcquireMutex(&context->mutex);
423 
424  //Point to the port that matches the specified port index
425  port = &context->ports[portIndex - 1];
426 
427  //Set the MAC address of the individual MAC entity for the port
428  port->macAddr = *macAddr;
429 
430  //Release exclusive access to the LLDP agent context
431  osReleaseMutex(&context->mutex);
432 
433  //Successful processing
434  return NO_ERROR;
435 #else
436  //TX mode is not implemented
437  return ERROR_NOT_IMPLEMENTED;
438 #endif
439 }
440 
441 
442 /**
443  * @brief Set transmit interval
444  * @param[in] context Pointer to the LLDP agent context
445  * @param[in] msgTxInterval Time interval between successive transmit
446  * cycles, in seconds
447  * @return Error code
448  **/
449 
451 {
452  error_t error;
453 
454  //Make sure the LLDP agent context is valid
455  if(context != NULL)
456  {
457  //Acquire exclusive access to the LLDP agent context
458  osAcquireMutex(&context->mutex);
459  //Perform management operation
460  error = lldpMgmtSetMsgTxInterval(context, msgTxInterval, TRUE);
461  //Release exclusive access to the LLDP agent context
462  osReleaseMutex(&context->mutex);
463  }
464  else
465  {
466  //Report an error
467  error = ERROR_INVALID_PARAMETER;
468  }
469 
470  //Return status code
471  return error;
472 }
473 
474 
475 /**
476  * @brief Set transmit hold multiplier
477  * @param[in] context Pointer to the LLDP agent context
478  * @param[in] msgTxHold Multiplier on the msgTxInterval that determines the
479  * actual TTL value used in an LLDPDU
480  * @return Error code
481  **/
482 
484 {
485  error_t error;
486 
487  //Make sure the LLDP agent context is valid
488  if(context != NULL)
489  {
490  //Acquire exclusive access to the LLDP agent context
491  osAcquireMutex(&context->mutex);
492  //Perform management operation
493  error = lldpMgmtSetMsgTxHold(context, msgTxHold, TRUE);
494  //Release exclusive access to the LLDP agent context
495  osReleaseMutex(&context->mutex);
496  }
497  else
498  {
499  //Report an error
500  error = ERROR_INVALID_PARAMETER;
501  }
502 
503  //Return status code
504  return error;
505 }
506 
507 
508 /**
509  * @brief Set re-initialization delay
510  * @param[in] context Pointer to the LLDP agent context
511  * @param[in] reinitDelay Delay before re-initialization will be attempted
512  * @return Error code
513  **/
514 
516 {
517  error_t error;
518 
519  //Make sure the LLDP agent context is valid
520  if(context != NULL)
521  {
522  //Acquire exclusive access to the LLDP agent context
523  osAcquireMutex(&context->mutex);
524  //Perform management operation
525  error = lldpMgmtSetReinitDelay(context, reinitDelay, TRUE);
526  //Release exclusive access to the LLDP agent context
527  osReleaseMutex(&context->mutex);
528  }
529  else
530  {
531  //Report an error
532  error = ERROR_INVALID_PARAMETER;
533  }
534 
535  //Return status code
536  return error;
537 }
538 
539 
540 /**
541  * @brief Set transmit delay
542  * @param[in] context Pointer to the LLDP agent context
543  * @param[in] txDelay Delay between successive LLDP frame transmissions
544  * @return Error code
545  **/
546 
548 {
549  error_t error;
550 
551  //Make sure the LLDP agent context is valid
552  if(context != NULL)
553  {
554  //Acquire exclusive access to the LLDP agent context
555  osAcquireMutex(&context->mutex);
556  //Perform management operation
557  error = lldpMgmtSetTxDelay(context, txDelay, TRUE);
558  //Release exclusive access to the LLDP agent context
559  osReleaseMutex(&context->mutex);
560  }
561  else
562  {
563  //Report an error
564  error = ERROR_INVALID_PARAMETER;
565  }
566 
567  //Return status code
568  return error;
569 }
570 
571 
572 /**
573  * @brief Set administrative status
574  * @param[in] context Pointer to the LLDP agent context
575  * @param[in] portIndex Port index
576  * @param[in] adminStatus The administrative status indicates whether or not
577  * the local LLDP agent is enabled
578  * @return Error code
579  **/
580 
582  LldpAdminStatus adminStatus)
583 {
584  error_t error;
585 
586  //Make sure the LLDP agent context is valid
587  if(context != NULL)
588  {
589  //Acquire exclusive access to the LLDP agent context
590  osAcquireMutex(&context->mutex);
591  //Perform management operation
592  error = lldpMgmtSetAdminStatus(context, portIndex, adminStatus, TRUE);
593  //Release exclusive access to the LLDP agent context
594  osReleaseMutex(&context->mutex);
595  }
596  else
597  {
598  //Report an error
599  error = ERROR_INVALID_PARAMETER;
600  }
601 
602  //Return status code
603  return error;
604 }
605 
606 
607 /**
608  * @brief Set the list of TLVs enabled for transmission
609  * @param[in] context Pointer to the LLDP agent context
610  * @param[in] portIndex Port index
611  * @param[in] mask Bit-map indicating the TLVs enabled for transmission
612  * @return Error code
613  **/
614 
616  uint8_t mask)
617 {
618  error_t error;
619 
620  //Make sure the LLDP agent context is valid
621  if(context != NULL)
622  {
623  //Acquire exclusive access to the LLDP agent context
624  osAcquireMutex(&context->mutex);
625  //Perform management operation
626  error = lldpMgmtSetBasicTlvFilter(context, portIndex, mask, TRUE);
627  //Release exclusive access to the LLDP agent context
628  osReleaseMutex(&context->mutex);
629  }
630  else
631  {
632  //Report an error
633  error = ERROR_INVALID_PARAMETER;
634  }
635 
636  //Return status code
637  return error;
638 }
639 
640 
641 /**
642  * @brief Set the list of management addresses enabled for transmission
643  * @param[in] context Pointer to the LLDP agent context
644  * @param[in] portIndex Port index
645  * @param[in] mask Bit-map indicating the management addresses enabled for
646  * transmission
647  * @return Error code
648  **/
649 
651  uint32_t mask)
652 {
653 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
655 
656  //Make sure the LLDP agent context is valid
657  if(context == NULL)
659 
660  //Invalid port index?
661  if(portIndex < 1 || portIndex > context->numPorts)
662  return ERROR_INVALID_PORT;
663 
664  //Acquire exclusive access to the LLDP agent context
665  osAcquireMutex(&context->mutex);
666 
667  //Point to the port that matches the specified port index
668  port = &context->ports[portIndex - 1];
669 
670  //Each bit in the bitmap corresponds to a given management address
671  port->mgmtAddrFilter = mask & LLDP_MGMT_ADDR_FILTER_ALL;
672 
673  //The somethingChangedLocal flag must be set whenever the value of an
674  //object has changed in the local system MIB
675  lldpSomethingChangedLocal(context);
676 
677  //Release exclusive access to the LLDP agent context
678  osReleaseMutex(&context->mutex);
679 
680  //Successful processing
681  return NO_ERROR;
682 #else
683  //TX mode is not implemented
684  return ERROR_NOT_IMPLEMENTED;
685 #endif
686 }
687 
688 
689 /**
690  * @brief Set chassis ID
691  * @param[in] context Pointer to the LLDP agent context
692  * @param[in] chassisIdSubtype Type of identifier used for the chassis
693  * @param[in] chassisId Administratively assigned name that identifies the chassis
694  * @param[in] chassisIdLen Length of the chassis ID, in bytes
695  * @return Error code
696  **/
697 
699  LldpChassisIdSubtype chassisIdSubtype, const void *chassisId,
700  size_t chassisIdLen)
701 {
702 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
703  error_t error;
704  size_t n;
705  LldpChassisIdTlv *tlv;
706 
707  //Check parameters
708  if(context == NULL || chassisId == NULL)
710 
711  //Check the length of the chassis ID
712  if(chassisIdLen < LLDP_MIN_CHASSIS_ID_LEN ||
713  chassisIdLen > LLDP_MAX_CHASSIS_ID_LEN)
714  {
715  return ERROR_INVALID_LENGTH;
716  }
717 
718  //Acquire exclusive access to the LLDP agent context
719  osAcquireMutex(&context->mutex);
720 
721  //Point to the buffer where to format the TLV
722  tlv = (LldpChassisIdTlv *) context->lldpdu.data;
723 
724  //Set chassis ID subtype
725  tlv->chassisIdSubtype = chassisIdSubtype;
726  //Copy chassis ID
727  osMemcpy(tlv->chassisId, chassisId, chassisIdLen);
728 
729  //Calculate the length of the TLV
730  n = sizeof(LldpChassisIdTlv) + chassisIdLen;
731 
732  //Set the value of the specified TLV
733  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_CHASSIS_ID, 0,
734  (uint8_t *) tlv, n, TRUE);
735 
736  //Check status code
737  if(!error)
738  {
739  //The somethingChangedLocal flag must be set whenever the value of an
740  //object has changed in the local system MIB
741  lldpSomethingChangedLocal(context);
742  }
743 
744  //Release exclusive access to the LLDP agent context
745  osReleaseMutex(&context->mutex);
746 
747  //Return status code
748  return error;
749 #else
750  //TX mode is not implemented
751  return ERROR_NOT_IMPLEMENTED;
752 #endif
753 }
754 
755 
756 /**
757  * @brief Set port ID
758  * @param[in] context Pointer to the LLDP agent context
759  * @param[in] portIndex Port index
760  * @param[in] portIdSubtype Type of identifier used for the port
761  * @param[in] portId Administratively assigned name that identifies the port
762  * @param[in] portIdLen Length of the port ID, in bytes
763  * @return Error code
764  **/
765 
767  LldpPortIdSubtype portIdSubtype, const void *portId, size_t portIdLen)
768 {
769 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
770  error_t error;
771  size_t n;
773  LldpPortIdTlv *tlv;
774 
775  //Check parameters
776  if(context == NULL || portId == NULL)
778 
779  //Invalid port index?
780  if(portIndex < 1 || portIndex > context->numPorts)
781  return ERROR_INVALID_PORT;
782 
783  //Check the length of the port ID
784  if(portIdLen < LLDP_MIN_PORT_ID_LEN || portIdLen > LLDP_MAX_PORT_ID_LEN)
785  {
786  return ERROR_INVALID_LENGTH;
787  }
788 
789  //Acquire exclusive access to the LLDP agent context
790  osAcquireMutex(&context->mutex);
791 
792  //Point to the port that matches the specified port index
793  port = &context->ports[portIndex - 1];
794 
795  //Point to the buffer where to format the TLV
796  tlv = (LldpPortIdTlv *) context->lldpdu.data;
797 
798  //Set port ID subtype
799  tlv->portIdSubtype = portIdSubtype;
800  //Copy port ID
801  osMemcpy(tlv->portId, portId, portIdLen);
802 
803  //Calculate the length of the TLV
804  n = sizeof(LldpPortIdTlv) + portIdLen;
805 
806  //Set the value of the specified TLV
807  error = lldpSetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_ID, 0,
808  (uint8_t *) tlv, n, TRUE);
809 
810  //Check status code
811  if(!error)
812  {
813  //The somethingChangedLocal flag must be set whenever the value of an
814  //object has changed in the local system MIB
815  lldpSomethingChangedLocal(context);
816  }
817 
818  //Release exclusive access to the LLDP agent context
819  osReleaseMutex(&context->mutex);
820 
821  //Return status code
822  return error;
823 #else
824  //TX mode is not implemented
825  return ERROR_NOT_IMPLEMENTED;
826 #endif
827 }
828 
829 
830 /**
831  * @brief Set port description
832  * @param[in] context Pointer to the LLDP agent context
833  * @param[in] portIndex Port index
834  * @param[in] portDesc Station port's description
835  * @return Error code
836  **/
837 
839  const char_t *portDesc)
840 {
841 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
842  error_t error;
843  size_t n;
845 
846  //Check parameters
847  if(context == NULL || portDesc == NULL)
849 
850  //Invalid port index?
851  if(portIndex < 1 || portIndex > context->numPorts)
852  return ERROR_INVALID_PORT;
853 
854  //Get the length of the port's description
855  n = osStrlen(portDesc);
856 
857  //Check the length of the string
858  if(n < LLDP_MIN_PORT_DESC_LEN || n > LLDP_MAX_PORT_DESC_LEN)
859  {
860  return ERROR_INVALID_LENGTH;
861  }
862 
863  //Acquire exclusive access to the LLDP agent context
864  osAcquireMutex(&context->mutex);
865 
866  //Point to the port that matches the specified port index
867  port = &context->ports[portIndex - 1];
868 
869  //Set the value of the specified TLV
870  error = lldpSetTlv(&port->txInfo, LLDP_TLV_TYPE_PORT_DESC, 0,
871  (uint8_t *) portDesc, n, TRUE);
872 
873  //Check status code
874  if(!error)
875  {
876  //The somethingChangedLocal flag must be set whenever the value of an
877  //object has changed in the local system MIB
878  lldpSomethingChangedLocal(context);
879  }
880 
881  //Release exclusive access to the LLDP agent context
882  osReleaseMutex(&context->mutex);
883 
884  //Return status code
885  return error;
886 #else
887  //TX mode is not implemented
888  return ERROR_NOT_IMPLEMENTED;
889 #endif
890 }
891 
892 
893 /**
894  * @brief Set system name
895  * @param[in] context Pointer to the LLDP agent context
896  * @param[in] sysName System's administratively assigned name
897  * @return Error code
898  **/
899 
901 {
902 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
903  error_t error;
904  size_t n;
905 
906  //Check parameters
907  if(context == NULL || sysName == NULL)
909 
910  //Get the length of the system name
911  n = osStrlen(sysName);
912 
913  //Check the length of the string
914  if(n < LLDP_MIN_SYS_NAME_LEN ||
916  {
917  return ERROR_INVALID_LENGTH;
918  }
919 
920  //Acquire exclusive access to the LLDP agent context
921  osAcquireMutex(&context->mutex);
922 
923  //Set the value of the specified TLV
924  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_NAME, 0,
925  (uint8_t *) sysName, n, TRUE);
926 
927  //Check status code
928  if(!error)
929  {
930  //The somethingChangedLocal flag must be set whenever the value of an
931  //object has changed in the local system MIB
932  lldpSomethingChangedLocal(context);
933  }
934 
935  //Release exclusive access to the LLDP agent context
936  osReleaseMutex(&context->mutex);
937 
938  //Return status code
939  return error;
940 #else
941  //TX mode is not implemented
942  return ERROR_NOT_IMPLEMENTED;
943 #endif
944 }
945 
946 
947 /**
948  * @brief Set system description
949  * @param[in] context Pointer to the LLDP agent context
950  * @param[in] sysDesc Textual description of the network entity
951  * @return Error code
952  **/
953 
955 {
956 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
957  error_t error;
958  size_t n;
959 
960  //Check parameters
961  if(context == NULL || sysDesc == NULL)
963 
964  //Get the length of the system description
965  n = osStrlen(sysDesc);
966 
967  //Check the length of the string
968  if(n < LLDP_MIN_SYS_DESC_LEN ||
970  {
971  return ERROR_INVALID_LENGTH;
972  }
973 
974  //Acquire exclusive access to the LLDP agent context
975  osAcquireMutex(&context->mutex);
976 
977  //Set the value of the specified TLV
978  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_DESC, 0,
979  (uint8_t *) sysDesc, n, TRUE);
980 
981  //Check status code
982  if(!error)
983  {
984  //The somethingChangedLocal flag must be set whenever the value of an
985  //object has changed in the local system MIB
986  lldpSomethingChangedLocal(context);
987  }
988 
989  //Release exclusive access to the LLDP agent context
990  osReleaseMutex(&context->mutex);
991 
992  //Return status code
993  return error;
994 #else
995  //TX mode is not implemented
996  return ERROR_NOT_IMPLEMENTED;
997 #endif
998 }
999 
1000 
1001 /**
1002  * @brief Set system capabilities
1003  * @param[in] context Pointer to the LLDP agent context
1004  * @param[in] supportedCap Bit-map of the capabilities supported by the system
1005  * @param[in] enabledCap Bit-map of the capabilities currently enabled
1006  * @return Error code
1007  **/
1008 
1009 error_t lldpSetLocalSysCap(LldpAgentContext *context, uint16_t supportedCap,
1010  uint16_t enabledCap)
1011 {
1012 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1013  error_t error;
1014  size_t n;
1015  LldpSysCapTlv *tlv;
1016 
1017  //Make sure the LLDP agent context is valid
1018  if(context == NULL)
1019  return ERROR_INVALID_PARAMETER;
1020 
1021  //Acquire exclusive access to the LLDP agent context
1022  osAcquireMutex(&context->mutex);
1023 
1024  //Point to the buffer where to format the TLV
1025  tlv = (LldpSysCapTlv *) context->lldpdu.data;
1026 
1027  //Set supported capabilities
1028  tlv->supportedCap = htons(supportedCap);
1029  //Set enabled capabilities
1030  tlv->enabledCap = htons(enabledCap);
1031 
1032  //Calculate the length of the TLV
1033  n = sizeof(LldpSysCapTlv);
1034 
1035  //Set the value of the specified TLV
1036  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_SYS_CAP, 0,
1037  (uint8_t *) tlv, n, TRUE);
1038 
1039  //Check status code
1040  if(!error)
1041  {
1042  //The somethingChangedLocal flag must be set whenever the value of an
1043  //object has changed in the local system MIB
1044  lldpSomethingChangedLocal(context);
1045  }
1046 
1047  //Release exclusive access to the LLDP agent context
1048  osReleaseMutex(&context->mutex);
1049 
1050  //Return status code
1051  return error;
1052 #else
1053  //TX mode is not implemented
1054  return ERROR_NOT_IMPLEMENTED;
1055 #endif
1056 }
1057 
1058 
1059 /**
1060  * @brief Set management address
1061  * @param[in] context Pointer to the LLDP agent context
1062  * @param[in] index Zero-based index identifying a management address
1063  * @param[in] mgmtAddrSubtype Type of management address
1064  * @param[in] mgmtAddr Octet string indicating a particular management
1065  * address
1066  * @param[in] mgmtAddrLen Length of the management address, in bytes
1067  * @param[in] ifNumSubtype Numbering method used for defining the interface
1068  * number
1069  * @param[in] ifNum Number within the system that identifies the specific
1070  * interface associated with this management address
1071  * @param[in] oid OID that identifies the type of hardware component or
1072  * protocol entity associated with the indicated management address
1073  * @param[in] oidLen Length of the OID, in bytes
1074  * @return Error code
1075  **/
1076 
1079  size_t mgmtAddrLen, LldpIfNumSubtype ifNumSubtype, uint32_t ifNum,
1080  const uint8_t *oid, size_t oidLen)
1081 {
1082 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1083  error_t error;
1084  uint_t i;
1085  uint_t k;
1086  size_t n;
1087  LldpMgmtAddrTlv1 *tlv1;
1088  LldpMgmtAddrTlv2 *tlv2;
1089 
1090  //Make sure the LLDP agent context is valid
1091  if(context == NULL)
1092  return ERROR_INVALID_PARAMETER;
1093 
1094  //Check index value
1095  if(index > LLDP_MAX_MGMT_ADDRS)
1096  return ERROR_INVALID_PARAMETER;
1097 
1098  //Make sure the management address is valid
1099  if(mgmtAddr == NULL && mgmtAddrLen != 0)
1100  return ERROR_INVALID_PARAMETER;
1101 
1102  //Check the length of the management address
1103  if(mgmtAddrLen > LLDP_MAX_MGMT_ADDR_LEN)
1104  return ERROR_INVALID_LENGTH;
1105 
1106  //Make sure the object identifier is valid
1107  if(oid == NULL && oidLen != 0)
1108  return ERROR_INVALID_PARAMETER;
1109 
1110  //Check the length of the object identifier
1111  if(oidLen > LLDP_MAX_OID_LEN)
1112  return ERROR_INVALID_LENGTH;
1113 
1114  //Acquire exclusive access to the LLDP agent context
1115  osAcquireMutex(&context->mutex);
1116 
1117  //An individual LLDPDU may contain more than one Management Address
1118  //TLV (refer to IEEE 802.1AB-2005, section 9.5.9.9)
1119  for(i = 0, k = 0; i < index; i++)
1120  {
1121  //Check whether the current management address is configured
1122  if((context->mgmtAddrMap & (1U << i)) != 0)
1123  {
1124  k++;
1125  }
1126  }
1127 
1128  //Valid management address?
1129  if(mgmtAddrLen > 0)
1130  {
1131  //Point to the buffer where to format the first part of the TLV
1132  tlv1 = (LldpMgmtAddrTlv1 *) context->lldpdu.data;
1133 
1134  //The management address string length shall contain the length management
1135  //address subtype and management address fields
1136  tlv1->mgmtAddrLen = mgmtAddrLen + 1;
1137 
1138  //Set management address subtype
1139  tlv1->mgmtAddrSubtype = mgmtAddrSubtype;
1140  //Copy management address
1141  osMemcpy(tlv1->mgmtAddr, mgmtAddr, mgmtAddrLen);
1142 
1143  //Point to the buffer where to format the second part of the TLV
1144  tlv2 = (LldpMgmtAddrTlv2 *) (tlv1->mgmtAddr + mgmtAddrLen);
1145 
1146  //Set interface numbering subtype
1147  tlv2->ifNumSubtype = ifNumSubtype;
1148  //Set interface number
1149  tlv2->ifNum = htonl(ifNum);
1150  //Set OID string length
1151  tlv2->oidLen = oidLen;
1152  //Copy object identifier
1153  osMemcpy(tlv2->oid, oid, oidLen);
1154 
1155  //Calculate the length of the TLV
1156  n = sizeof(LldpMgmtAddrTlv1) + mgmtAddrLen + sizeof(LldpMgmtAddrTlv2) +
1157  oidLen;
1158 
1159  //Check whether the TLV already exists
1160  if((context->mgmtAddrMap & (1U << index)) != 0)
1161  {
1162  //Replace existing TLV
1163  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k,
1164  (uint8_t *) tlv1, n, TRUE);
1165  }
1166  else
1167  {
1168  //Add a new TLV
1169  error = lldpSetTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k,
1170  (uint8_t *) tlv1, n, FALSE);
1171  }
1172 
1173  //Check status code
1174  if(!error)
1175  {
1176  //The management address is now configured
1177  context->mgmtAddrMap |= (1U << index);
1178  }
1179  }
1180  else
1181  {
1182  //Remove the specified TLV from the local system information
1183  error = lldpDeleteTlv(&context->txInfo, LLDP_TLV_TYPE_MGMT_ADDR, k);
1184 
1185  //The management address is no longer used
1186  context->mgmtAddrMap &= ~(1U << index);
1187  }
1188 
1189  //Check status code
1190  if(!error)
1191  {
1192  //The somethingChangedLocal flag must be set whenever the value of an
1193  //object has changed in the local system MIB
1194  lldpSomethingChangedLocal(context);
1195  }
1196 
1197  //Release exclusive access to the LLDP agent context
1198  osReleaseMutex(&context->mutex);
1199 
1200  //Return status code
1201  return error;
1202 #else
1203  //TX mode is not implemented
1204  return ERROR_NOT_IMPLEMENTED;
1205 #endif
1206 }
1207 
1208 
1209 /**
1210  * @brief Remove all TLVs with specified type
1211  * @param[in] context Pointer to the LLDP agent context
1212  * @param[in] type TLV type
1213  * @return Error code
1214  **/
1215 
1217 {
1218 #if (LLDP_TX_MODE_SUPPORT == ENABLED)
1219  error_t error;
1220  uint_t i;
1221  bool_t somethingChangedLocal;
1222 
1223  //Make sure the LLDP agent context is valid
1224  if(context == NULL)
1225  return ERROR_INVALID_PARAMETER;
1226 
1227  //Check TLV type
1228  if(type != LLDP_TLV_TYPE_PORT_DESC &&
1234  {
1235  return ERROR_INVALID_TYPE;
1236  }
1237 
1238  //Acquire exclusive access to the LLDP agent context
1239  osAcquireMutex(&context->mutex);
1240 
1241  //Initialize status code
1242  error = NO_ERROR;
1243  //Clear flag
1244  somethingChangedLocal = FALSE;
1245 
1246  //Remove all TLVs that match the specified type
1247  while(!error)
1248  {
1249  //Remove one TLV at a time
1250  error = lldpDeleteTlv(&context->txInfo, type, 0);
1251 
1252  //Check status code
1253  if(!error)
1254  {
1255  somethingChangedLocal = TRUE;
1256  }
1257  }
1258 
1259  //Loop through the ports
1260  for(i = 0; i < context->numPorts; i++)
1261  {
1262  //Initialize status code
1263  error = NO_ERROR;
1264 
1265  //Remove all port-specific TLVs that match the specified type
1266  while(!error)
1267  {
1268  //Remove one TLV at a time
1269  error = lldpDeleteTlv(&context->ports[i].txInfo, type, 0);
1270 
1271  //Check status code
1272  if(!error)
1273  {
1274  somethingChangedLocal = TRUE;
1275  }
1276  }
1277  }
1278 
1279  //Any change in the LLDP local system MIB?
1280  if(somethingChangedLocal)
1281  {
1282  //The somethingChangedLocal flag must be set whenever the value of an
1283  //object has changed in the local system MIB
1284  lldpSomethingChangedLocal(context);
1285 
1286  //Successful processing
1287  error = NO_ERROR;
1288  }
1289  else
1290  {
1291  //Report an error
1292  error = ERROR_NOT_FOUND;
1293  }
1294 
1295  //Release exclusive access to the LLDP agent context
1296  osReleaseMutex(&context->mutex);
1297 
1298  //Return status code
1299  return error;
1300 #else
1301  //TX mode is not implemented
1302  return ERROR_NOT_IMPLEMENTED;
1303 #endif
1304 }
1305 
1306 
1307 /**
1308  * @brief LLDP agent task
1309  * @param[in] context Pointer to the LLDP agent context
1310  **/
1311 
1313 {
1314  systime_t time;
1315  systime_t timeout;
1316  SocketEventDesc eventDesc;
1317 
1318 #if (NET_RTOS_SUPPORT == ENABLED)
1319  //Task prologue
1320  osEnterTask();
1321 
1322  //Main loop
1323  while(1)
1324  {
1325 #endif
1326  //Get current time
1327  time = osGetSystemTime();
1328 
1329  //Maximum time to wait for an incoming datagram
1330  if((time - context->timestamp) < LLDP_TICK_INTERVAL)
1331  {
1332  timeout = context->timestamp + LLDP_TICK_INTERVAL - time;
1333  }
1334  else
1335  {
1336  timeout = 0;
1337  }
1338 
1339  //Specify the events the application is interested in
1340  eventDesc.socket = context->socket;
1341  eventDesc.eventMask = SOCKET_EVENT_RX_READY;
1342  eventDesc.eventFlags = 0;
1343 
1344  //Wait for an event
1345  socketPoll(&eventDesc, 1, &context->event, timeout);
1346 
1347  //Stop request?
1348  if(context->stop)
1349  {
1350  //Stop SNMP agent operation
1351  context->running = FALSE;
1352  //Task epilogue
1353  osExitTask();
1354  //Kill ourselves
1356  }
1357 
1358  //Any LLDP frame received?
1359  if(eventDesc.eventFlags != 0)
1360  {
1361  //Acquire exclusive access to the LLDP agent context
1362  osAcquireMutex(&context->mutex);
1363  //Frame reception process
1364  lldpProcessFrame(context);
1365  //Release exclusive access to the LLDP agent context
1366  osReleaseMutex(&context->mutex);
1367  }
1368 
1369  //Get current time
1370  time = osGetSystemTime();
1371 
1372  //All LLDP timers have a resolution of one second
1373  if((time - context->timestamp) >= LLDP_TICK_INTERVAL)
1374  {
1375  //Acquire exclusive access to the LLDP agent context
1376  osAcquireMutex(&context->mutex);
1377  //Handle periodic operations
1378  lldpTick(context);
1379  //Release exclusive access to the LLDP agent context
1380  osReleaseMutex(&context->mutex);
1381 
1382  //Save current time
1383  context->timestamp = time;
1384  }
1385 #if (NET_RTOS_SUPPORT == ENABLED)
1386  }
1387 #endif
1388 }
1389 
1390 
1391 /**
1392  * @brief Release LLDP agent context
1393  * @param[in] context Pointer to the LLDP agent context
1394  **/
1395 
1397 {
1398  //Make sure the LLDP agent context is valid
1399  if(context != NULL)
1400  {
1401  //Free previously allocated resources
1402  osDeleteMutex(&context->mutex);
1403  osDeleteEvent(&context->event);
1404 
1405  //Clear LLDP agent context
1406  osMemset(context, 0, sizeof(LldpAgentContext));
1407  }
1408 }
1409 
1410 #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:53
#define LLDP_TICK_INTERVAL
Definition: lldp.h:87
@ ERROR_NOT_FOUND
Definition: error.h:147
#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:547
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:361
@ 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:2062
@ 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:650
#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:165
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:426
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:615
@ LLDP_TLV_TYPE_END_OF_LLDPDU
End Of LLDPDU.
Definition: lldp_tlv.h:93
@ ETH_TYPE_LLDP
Definition: ethernet.h:171
#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:766
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:141
error_t lldpSetPortAddr(LldpAgentContext *context, uint_t portIndex, const MacAddr *macAddr)
Set port address.
Definition: lldp.c:407
#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:231
error_t lldpStart(LldpAgentContext *context)
Start LLDP agent.
Definition: lldp.c:268
@ 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:954
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:698
void lldpTask(LldpAgentContext *context)
LLDP agent task.
Definition: lldp.c:1312
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:450
#define LLDP_TASK_PRIORITY
Definition: lldp.h:82
#define LldpPortEntry
Definition: lldp.h:44
@ ERROR_INVALID_LENGTH
Definition: error.h:111
NetInterface * netGetDefaultInterface(void)
Get default network interface.
Definition: net.c:467
@ 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:581
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:95
error_t lldpSetLocalSysName(LldpAgentContext *context, const char_t *sysName)
Set system name.
Definition: lldp.c:900
Socket * socketOpen(uint_t type, uint_t protocol)
Create a socket (UDP or TCP)
Definition: socket.c:125
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:429
#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:2149
#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:1077
MacAddr
Definition: ethernet.h:195
#define LLDP_MGMT_ADDR_FILTER_ALL
Definition: lldp.h:174
uint32_t systime_t
System time.
uint16_t port
Definition: dns_common.h:267
@ LLDP_ADMIN_STATUS_ENABLED_TX_RX
Definition: lldp.h:191
void lldpDeinit(LldpAgentContext *context)
Release LLDP agent context.
Definition: lldp.c:1396
@ 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:48
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.
#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:1009
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:515
#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:427
error_t lldpSetMsgTxHold(LldpAgentContext *context, uint_t msgTxHold)
Set transmit hold multiplier.
Definition: lldp.c:483
unsigned int uint_t
Definition: compiler_port.h:50
#define osMemset(p, value, length)
Definition: os_port.h:135
TCP/IP stack core.
error_t lldpDeleteLocalTlv(LldpAgentContext *context, LldpTlvType type)
Remove all TLVs with specified type.
Definition: lldp.c:1216
error_t lldpSetLocalPortDesc(LldpAgentContext *context, uint_t portIndex, const char_t *portDesc)
Set port description.
Definition: lldp.c:838
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:148
#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:428
@ ERROR_ALREADY_RUNNING
Definition: error.h:293
@ 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.