lldp_ext_med.c
Go to the documentation of this file.
1 /**
2  * @file lldp_ext_med.c
3  * @brief LLDP-MED extension (LLDP for Media Endpoint Devices)
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_ext_med.h"
38 #include "lldp/lldp_misc.h"
39 #include "lldp/lldp_debug.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (LLDP_SUPPORT == ENABLED && LLDP_TX_MODE_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Set LLDP-MED capabilities
48  * @param[in] context Pointer to the LLDP agent context
49  * @param[in] capabilities Bit-map of the supported set of capabilities
50  * @param[in] deviceType LLDP-MED device type
51  * @return Error code
52  **/
53 
54 error_t lldpMedSetLocalCap(LldpAgentContext *context, uint16_t capabilities,
56 {
57  error_t error;
58  size_t n;
59  LldpMedCapTlv *tlv;
60 
61  //Make sure the LLDP agent context is valid
62  if(context == NULL)
63  {
65  }
66 
67  //Acquire exclusive access to the LLDP agent context
68  osAcquireMutex(&context->mutex);
69 
70  //Point to the buffer where to format the TLV
71  tlv = (LldpMedCapTlv *) context->lldpdu.data;
72 
73  //Set LLDP-MED capabilities
74  tlv->capabilities = htons(capabilities);
75  //Set LLDP-MED device type
76  tlv->deviceType = deviceType;
77 
78  //Calculate the length of the TLV
79  n = sizeof(LldpMedCapTlv);
80 
81  //All LLDP-MED LLDPDUs shall contain exactly one LLDP-MED Capabilities TLV,
82  //and this TLV shall always be the first LLDP-MED TLV contained in the
83  //LLDPDU (refer to ANSI/TIA-1057, section 10.2.2.3)
84  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
85  LLDP_MED_SUBTYPE_LLDP_MED_CAP, 0, (uint8_t *) tlv, n, TRUE);
86 
87  //Check status code
88  if(!error)
89  {
90  //The somethingChangedLocal flag must be set whenever the value of an
91  //object has changed in the local system MIB
93  }
94 
95  //Release exclusive access to the LLDP agent context
96  osReleaseMutex(&context->mutex);
97 
98  //Return status code
99  return error;
100 }
101 
102 
103 /**
104  * @brief Set network policy
105  * @param[in] context Pointer to the LLDP agent context
106  * @param[in] portIndex Port index
107  * @param[in] appType Primary function of the application
108  * @param[in] u Unknown policy flag (U)
109  * @param[in] t Tagged flag (T)
110  * @param[in] vlanId VLAN identifier for the port
111  * @param[in] l2Priority Layer 2 priority to be used
112  * @param[in] dscpValue DSCP value to be used
113  * @return Error code
114  **/
115 
117  uint_t portIndex, LldpMedAppType appType, bool_t u, bool_t t,
118  uint16_t vlanId, uint8_t l2Priority, uint8_t dscpValue)
119 {
120  error_t error;
121  uint_t k;
122  size_t n;
123  bool_t replace;
126 
127  //Make sure the LLDP agent context is valid
128  if(context == NULL)
129  {
131  }
132 
133  //Invalid port index?
134  if(portIndex < 1 || portIndex > context->numPorts)
135  {
136  return ERROR_INVALID_PORT;
137  }
138 
139  //Acquire exclusive access to the LLDP agent context
140  osAcquireMutex(&context->mutex);
141 
142  //Point to the port that matches the specified port index
143  port = &context->ports[portIndex - 1];
144 
145  //Initialize status code
146  error = NO_ERROR;
147  //Initialize flag
148  replace = FALSE;
149 
150  //If more than one Network Policy TLV is defined within an LLDPDU, then the
151  //application type shall be different from any other Network Policy TLV
152  //in the LLDPDU (refer to ANSI/TIA-1057, section 10.2.3.8)
153  for(k = 0; !error; k++)
154  {
155  //Extract the next Network Policy TLV from the local system MIB
156  error = lldpGetOrgDefTlv(&port->txInfo, LLDP_MED_OUI,
157  LLDP_MED_SUBTYPE_NETWORK_POLICY, k, (const uint8_t **) &tlv, &n);
158 
159  //TLV found?
160  if(!error)
161  {
162  //Sanity check
163  if(n >= sizeof(LldpMedNetworkPolicyTlv))
164  {
165  //Check the application type
166  if(tlv->appType == appType)
167  {
168  //Replace the existing TLV
169  replace = TRUE;
170  break;
171  }
172  else if(tlv->appType > appType)
173  {
174  //Insert a new TLV
175  break;
176  }
177  else
178  {
179  }
180  }
181  }
182  }
183 
184  //Check status code
185  if(error == NO_ERROR || error == ERROR_NOT_FOUND)
186  {
187  //Point to the buffer where to format the TLV
188  tlv = (LldpMedNetworkPolicyTlv *) context->lldpdu.data;
189 
190  //Set application type
191  tlv->appType = appType;
192 
193  //Set flags
194  tlv->u = u;
195  tlv->t = t;
196  tlv->x = 0;
197 
198  //Set VLAN identifier
199  tlv->vlanIdH = (vlanId >> 7) & 0x1F;
200  tlv->vlanIdL = vlanId & 0x7F;
201 
202  //Set layer 2 priority
203  tlv->l2PriorityH = (l2Priority >> 2) & 0x01;
204  tlv->l2PriorityL = l2Priority & 0x03;
205 
206  //Set DSCP value
207  tlv->dscpValue = dscpValue;
208 
209  //Calculate the length of the TLV
210  n = sizeof(LldpMedNetworkPolicyTlv);
211 
212  //Set the value of the specified TLV
213  error = lldpSetOrgDefTlv(&port->txInfo, LLDP_MED_OUI,
214  LLDP_MED_SUBTYPE_NETWORK_POLICY, k, (uint8_t *) tlv, n, replace);
215 
216  //Check status code
217  if(!error)
218  {
219  //The somethingChangedLocal flag must be set whenever the value of an
220  //object has changed in the local system MIB
221  lldpSomethingChangedLocal(context);
222  }
223  }
224 
225  //Release exclusive access to the LLDP agent context
226  osReleaseMutex(&context->mutex);
227 
228  //Return status code
229  return error;
230 }
231 
232 
233 /**
234  * @brief Set location identification
235  * @param[in] context Pointer to the LLDP agent context
236  * @param[in] portIndex Port index
237  * @param[in] locationDataFormat Location ID data format
238  * @param[in] locationId Location ID
239  * @param[in] locationIdLen Length of the location ID, in bytes
240  * @return Error code
241  **/
242 
244  uint_t portIndex, LldpMedLocationDataFormat locationDataFormat,
245  const void *locationId, size_t locationIdLen)
246 {
247  error_t error;
248  uint_t k;
249  size_t n;
250  bool_t replace;
253 
254  //Check parameters
255  if(context == NULL || locationId == NULL)
257 
258  //Check the location ID data format
259  if(locationDataFormat == LLDP_MED_LOCATION_DATA_FORMAT_COORD_BASED_LCI)
260  {
261  //Check the length of the location ID
262  if(locationIdLen != 16)
263  {
265  }
266  }
267  else if(locationDataFormat == LLDP_MED_LOCATION_DATA_FORMAT_CIVIC_ADDR_LCI)
268  {
269  //Check the length of the location ID
270  if(locationIdLen < 6 || locationIdLen > 256)
271  {
273  }
274  }
275  else if(locationDataFormat == LLDP_MED_LOCATION_DATA_FORMAT_ECS_ELIN)
276  {
277  //Check the length of the location ID
278  if(locationIdLen < 10 || locationIdLen > 25)
279  {
281  }
282  }
283  else
284  {
285  //Invalid data format
287  }
288 
289  //Invalid port index?
290  if(portIndex < 1 || portIndex > context->numPorts)
291  {
292  return ERROR_INVALID_PORT;
293  }
294 
295  //Acquire exclusive access to the LLDP agent context
296  osAcquireMutex(&context->mutex);
297 
298  //Point to the port that matches the specified port index
299  port = &context->ports[portIndex - 1];
300 
301  //Initialize status code
302  error = NO_ERROR;
303  //Initialize flag
304  replace = FALSE;
305 
306  //An LLDPDU should contain no more than one Location Identification TLV for
307  //each location identifier subtype
308  for(k = 0; !error; k++)
309  {
310  //Extract the next Location Identification TLV from the local system MIB
311  error = lldpGetOrgDefTlv(&port->txInfo, LLDP_MED_OUI,
312  LLDP_MED_SUBTYPE_LOCATION_ID, k, (const uint8_t **) &tlv, &n);
313 
314  //TLV found?
315  if(!error)
316  {
317  //Sanity check
318  if(n >= sizeof(LldpMedLocationIdTlv))
319  {
320  //Check the location data format
321  if(tlv->locationDataFormat == locationDataFormat)
322  {
323  //Replace the existing TLV
324  replace = TRUE;
325  break;
326  }
327  else if(tlv->locationDataFormat > locationDataFormat)
328  {
329  //Insert a new TLV
330  break;
331  }
332  else
333  {
334  }
335  }
336  }
337  }
338 
339  //Check status code
340  if(error == NO_ERROR || error == ERROR_NOT_FOUND)
341  {
342  //Point to the buffer where to format the TLV
343  tlv = (LldpMedLocationIdTlv *) context->lldpdu.data;
344 
345  //Set location ID data format
346  tlv->locationDataFormat = locationDataFormat;
347  //Copy location ID
348  osMemcpy(tlv->locationId, locationId, locationIdLen);
349 
350  //Calculate the length of the TLV
351  n = sizeof(LldpMedLocationIdTlv) + locationIdLen;
352 
353  //Set the value of the specified TLV
354  error = lldpSetOrgDefTlv(&port->txInfo, LLDP_MED_OUI,
355  LLDP_MED_SUBTYPE_LOCATION_ID, k, (uint8_t *) tlv, n, replace);
356 
357  //Check status code
358  if(!error)
359  {
360  //The somethingChangedLocal flag must be set whenever the value of an
361  //object has changed in the local system MIB
362  lldpSomethingChangedLocal(context);
363  }
364  }
365 
366  //Release exclusive access to the LLDP agent context
367  osReleaseMutex(&context->mutex);
368 
369  //Return status code
370  return error;
371 }
372 
373 
374 /**
375  * @brief Set extended power-via-MDI
376  * @param[in] context Pointer to the LLDP agent context
377  * @param[in] portIndex Port index
378  * @param[in] powerType Binary value that represents whether LLDP-MED device is
379  * a Power Sourcing Entity (PSE) or Power Device (PD)
380  * @param[in] powerSource Binary value that represents the power source being
381  * utilized by a PSE or PD device
382  * @param[in] powerPriority Binary value that represents the priority of the PD
383  * type device to the power being supplied by the PSE type device, or the
384  * power priority associated with the PSE type device's port that is sourcing
385  * the power via MDI
386  * @param[in] powerValue Numerical value that indicates the total power in watts
387  * required by a PD device from a PSE device, or the total power a PSE device
388  * is capable of sourcing over a maximum length cable based on its current
389  * configuration
390  * @return Error code
391  **/
392 
395  LldpMedPowerPriority powerPriority, uint16_t powerValue)
396 {
397  error_t error;
398  size_t n;
401 
402  //Make sure the LLDP agent context is valid
403  if(context == NULL)
404  {
406  }
407 
408  //Invalid port index?
409  if(portIndex < 1 || portIndex > context->numPorts)
410  {
411  return ERROR_INVALID_PORT;
412  }
413 
414  //Acquire exclusive access to the LLDP agent context
415  osAcquireMutex(&context->mutex);
416 
417  //Point to the port that matches the specified port index
418  port = &context->ports[portIndex - 1];
419 
420  //Point to the buffer where to format the TLV
421  tlv = (LldpMedExtPowerViaMdiTlv *) context->lldpdu.data;
422 
423  //Set power type
424  tlv->powerType = powerType;
425  //Set power source
426  tlv->powerSource = powerSource;
427  //Set power priority
428  tlv->powerPriority = powerPriority;
429  //Set power value
430  tlv->powerValue = htons(powerValue);
431 
432  //Calculate the length of the TLV
433  n = sizeof(LldpMedExtPowerViaMdiTlv);
434 
435  //An LLDP-MED device shall advertise at most one Extended Power-Via-MDI TLV
436  //per LLDPDU (refer to ANSI/TIA-1057, section 10.2.5.5)
437  error = lldpSetOrgDefTlv(&port->txInfo, LLDP_MED_OUI,
438  LLDP_MED_SUBTYPE_EXT_POWER_VIA_MDI, 0, (uint8_t *) tlv, n, TRUE);
439 
440  //Check status code
441  if(!error)
442  {
443  //The somethingChangedLocal flag must be set whenever the value of an
444  //object has changed in the local system MIB
445  lldpSomethingChangedLocal(context);
446  }
447 
448  //Release exclusive access to the LLDP agent context
449  osReleaseMutex(&context->mutex);
450 
451  //Return status code
452  return error;
453 }
454 
455 
456 /**
457  * @brief Set hardware revision
458  * @param[in] context Pointer to the LLDP agent context
459  * @param[in] hardwareRevision Alphanumerical string that contains the hardware
460  * revision of the endpoint
461  * @return Error code
462  **/
463 
465  const char_t *hardwareRevision)
466 {
467  error_t error;
468  size_t n;
469 
470  //Check parameters
471  if(context == NULL || hardwareRevision == NULL)
472  {
474  }
475 
476  //Get the length of the hardware revision
477  n = osStrlen(hardwareRevision);
478 
479  //Check the length of the string
481  {
482  return ERROR_INVALID_LENGTH;
483  }
484 
485  //Acquire exclusive access to the LLDP agent context
486  osAcquireMutex(&context->mutex);
487 
488  //An LLDPDU shall not contain more than one Hardware Revision TLV (refer
489  //to ANSI/TIA-1057, section 10.2.6.1.3)
490  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
491  LLDP_MED_SUBTYPE_HARDWARE_REVISION, 0, (uint8_t *) hardwareRevision, n,
492  TRUE);
493 
494  //Check status code
495  if(!error)
496  {
497  //The somethingChangedLocal flag must be set whenever the value of an
498  //object has changed in the local system MIB
499  lldpSomethingChangedLocal(context);
500  }
501 
502  //Release exclusive access to the LLDP agent context
503  osReleaseMutex(&context->mutex);
504 
505  //Return status code
506  return error;
507 }
508 
509 
510 /**
511  * @brief Set firmware revision
512  * @param[in] context Pointer to the LLDP agent context
513  * @param[in] firmwareRevision Alphanumerical string that contains the firmware
514  * revision of the endpoint
515  * @return Error code
516  **/
517 
519  const char_t *firmwareRevision)
520 {
521  error_t error;
522  size_t n;
523 
524  //Check parameters
525  if(context == NULL || firmwareRevision == NULL)
526  {
528  }
529 
530  //Get the length of the firmware revision
531  n = osStrlen(firmwareRevision);
532 
533  //Check the length of the string
535  {
536  return ERROR_INVALID_LENGTH;
537  }
538 
539  //Acquire exclusive access to the LLDP agent context
540  osAcquireMutex(&context->mutex);
541 
542  //An LLDPDU shall not contain more than one Firmware Revision TLV (refer
543  //to ANSI/TIA-1057, section 10.2.6.2.3)
544  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
545  LLDP_MED_SUBTYPE_FIRMWARE_REVISION, 0, (uint8_t *) firmwareRevision, n,
546  TRUE);
547 
548  //Check status code
549  if(!error)
550  {
551  //The somethingChangedLocal flag must be set whenever the value of an
552  //object has changed in the local system MIB
553  lldpSomethingChangedLocal(context);
554  }
555 
556  //Release exclusive access to the LLDP agent context
557  osReleaseMutex(&context->mutex);
558 
559  //Return status code
560  return error;
561 }
562 
563 
564 /**
565  * @brief Set software revision
566  * @param[in] context Pointer to the LLDP agent context
567  * @param[in] softwareRevision Alphanumerical string that contains the software
568  * revision of the endpoint
569  * @return Error code
570  **/
571 
573  const char_t *softwareRevision)
574 {
575  error_t error;
576  size_t n;
577 
578  //Check parameters
579  if(context == NULL || softwareRevision == NULL)
580  {
582  }
583 
584  //Get the length of the software revision
585  n = osStrlen(softwareRevision);
586 
587  //Check the length of the string
589  {
590  return ERROR_INVALID_LENGTH;
591  }
592 
593  //Acquire exclusive access to the LLDP agent context
594  osAcquireMutex(&context->mutex);
595 
596  //An LLDPDU shall not contain more than one Software Revision TLV (refer
597  //to ANSI/TIA-1057, section 10.2.6.3.3)
598  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
599  LLDP_MED_SUBTYPE_SOFTWARE_REVISION, 0, (uint8_t *) softwareRevision, n,
600  TRUE);
601 
602  //Check status code
603  if(!error)
604  {
605  //The somethingChangedLocal flag must be set whenever the value of an
606  //object has changed in the local system MIB
607  lldpSomethingChangedLocal(context);
608  }
609 
610  //Release exclusive access to the LLDP agent context
611  osReleaseMutex(&context->mutex);
612 
613  //Return status code
614  return error;
615 }
616 
617 
618 /**
619  * @brief Set serial number
620  * @param[in] context Pointer to the LLDP agent context
621  * @param[in] serialNumber Alphanumerical string that contains the serial
622  * number of the endpoint
623  * @return Error code
624  **/
625 
627  const char_t *serialNumber)
628 {
629  error_t error;
630  size_t n;
631 
632  //Check parameters
633  if(context == NULL || serialNumber == NULL)
634  {
636  }
637 
638  //Get the length of the serial number
639  n = osStrlen(serialNumber);
640 
641  //Check the length of the string
643  {
644  return ERROR_INVALID_LENGTH;
645  }
646 
647  //Acquire exclusive access to the LLDP agent context
648  osAcquireMutex(&context->mutex);
649 
650  //An LLDPDU shall not contain more than one Serial Number TLV (refer
651  //to ANSI/TIA-1057, section 10.2.6.4.3)
652  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
653  LLDP_MED_SUBTYPE_SERIAL_NUMBER, 0, (uint8_t *) serialNumber, n, TRUE);
654 
655  //Check status code
656  if(!error)
657  {
658  //The somethingChangedLocal flag must be set whenever the value of an
659  //object has changed in the local system MIB
660  lldpSomethingChangedLocal(context);
661  }
662 
663  //Release exclusive access to the LLDP agent context
664  osReleaseMutex(&context->mutex);
665 
666  //Return status code
667  return error;
668 }
669 
670 
671 /**
672  * @brief Set manufacturer name
673  * @param[in] context Pointer to the LLDP agent context
674  * @param[in] manufacturerName Alphanumerical string that contains the
675  * manufacturer name of the endpoint
676  * @return Error code
677  **/
678 
680  const char_t *manufacturerName)
681 {
682  error_t error;
683  size_t n;
684 
685  //Check parameters
686  if(context == NULL || manufacturerName == NULL)
687  {
689  }
690 
691  //Get the length of the manufacturer name
692  n = osStrlen(manufacturerName);
693 
694  //Check the length of the string
696  {
697  return ERROR_INVALID_LENGTH;
698  }
699 
700  //Acquire exclusive access to the LLDP agent context
701  osAcquireMutex(&context->mutex);
702 
703  //An LLDPDU shall not contain more than one Manufacturer Name TLV (refer
704  //to ANSI/TIA-1057, section 10.2.6.5.3)
705  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
706  LLDP_MED_SUBTYPE_MANUFACTURER_NAME, 0, (uint8_t *) manufacturerName, n,
707  TRUE);
708 
709  //Check status code
710  if(!error)
711  {
712  //The somethingChangedLocal flag must be set whenever the value of an
713  //object has changed in the local system MIB
714  lldpSomethingChangedLocal(context);
715  }
716 
717  //Release exclusive access to the LLDP agent context
718  osReleaseMutex(&context->mutex);
719 
720  //Return status code
721  return error;
722 }
723 
724 
725 /**
726  * @brief Set model name
727  * @param[in] context Pointer to the LLDP agent context
728  * @param[in] modelName Alphanumerical string that contains the model name of
729  * the endpoint
730  * @return Error code
731  **/
732 
734  const char_t *modelName)
735 {
736  error_t error;
737  size_t n;
738 
739  //Check parameters
740  if(context == NULL || modelName == NULL)
741  {
743  }
744 
745  //Get the length of the model name
746  n = osStrlen(modelName);
747 
748  //Check the length of the string
750  {
751  return ERROR_INVALID_LENGTH;
752  }
753 
754  //Acquire exclusive access to the LLDP agent context
755  osAcquireMutex(&context->mutex);
756 
757  //An LLDPDU shall not contain more than one Model Name TLV (refer
758  //to ANSI/TIA-1057, section 10.2.6.6.3)
759  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
760  LLDP_MED_SUBTYPE_MODEL_NAME, 0, (uint8_t *) modelName, n, TRUE);
761 
762  //Check status code
763  if(!error)
764  {
765  //The somethingChangedLocal flag must be set whenever the value of an
766  //object has changed in the local system MIB
767  lldpSomethingChangedLocal(context);
768  }
769 
770  //Release exclusive access to the LLDP agent context
771  osReleaseMutex(&context->mutex);
772 
773  //Return status code
774  return error;
775 }
776 
777 
778 /**
779  * @brief Set asset identifier
780  * @param[in] context Pointer to the LLDP agent context
781  * @param[in] assetId Alphanumerical string that contains the asset identifier
782  * of the endpoint
783  * @return Error code
784  **/
785 
787  const char_t *assetId)
788 {
789  error_t error;
790  size_t n;
791 
792  //Check parameters
793  if(context == NULL || assetId == NULL)
794  {
796  }
797 
798  //Get the length of the asset identifier
799  n = osStrlen(assetId);
800 
801  //Check the length of the string
803  {
804  return ERROR_INVALID_LENGTH;
805  }
806 
807  //Acquire exclusive access to the LLDP agent context
808  osAcquireMutex(&context->mutex);
809 
810  //An LLDPDU shall not contain more than one Asset ID TLV (refer to
811  //ANSI/TIA-1057, section 10.2.6.7.3)
812  error = lldpSetOrgDefTlv(&context->txInfo, LLDP_MED_OUI,
813  LLDP_MED_SUBTYPE_ASSET_ID, 0, (uint8_t *) assetId, n, TRUE);
814 
815  //Check status code
816  if(!error)
817  {
818  //The somethingChangedLocal flag must be set whenever the value of an
819  //object has changed in the local system MIB
820  lldpSomethingChangedLocal(context);
821  }
822 
823  //Release exclusive access to the LLDP agent context
824  osReleaseMutex(&context->mutex);
825 
826  //Return status code
827  return error;
828 }
829 
830 
831 /**
832  * @brief Remove all LLDP-MED specific TLVs with specified subtype
833  * @param[in] context Pointer to the LLDP agent context
834  * @param[in] subtype TLV subtype
835  * @return Error code
836  **/
837 
840 {
841  error_t error;
842  uint_t i;
843  bool_t somethingChangedLocal;
844 
845  //Make sure the LLDP agent context is valid
846  if(context == NULL)
848 
849  //Acquire exclusive access to the LLDP agent context
850  osAcquireMutex(&context->mutex);
851 
852  //Initialize status code
853  error = NO_ERROR;
854  //Clear flag
855  somethingChangedLocal = FALSE;
856 
857  //Remove all TLVs that match the specified type
858  while(!error)
859  {
860  //Remove one TLV at a time
861  error = lldpDeleteOrgDefTlv(&context->txInfo, LLDP_MED_OUI, subtype, 0);
862 
863  //Check status code
864  if(!error)
865  {
866  somethingChangedLocal = TRUE;
867  }
868  }
869 
870  //Loop through the ports
871  for(i = 0; i < context->numPorts; i++)
872  {
873  //Initialize status code
874  error = NO_ERROR;
875 
876  //Remove all port-specific TLVs that match the specified type
877  while(!error)
878  {
879  //Remove one TLV at a time
880  error = lldpDeleteOrgDefTlv(&context->ports[i].txInfo, LLDP_MED_OUI,
881  subtype, 0);
882 
883  //Check status code
884  if(!error)
885  {
886  somethingChangedLocal = TRUE;
887  }
888  }
889  }
890 
891  //Any change in the LLDP local system MIB?
892  if(somethingChangedLocal)
893  {
894  //The somethingChangedLocal flag must be set whenever the value of an
895  //object has changed in the local system MIB
896  lldpSomethingChangedLocal(context);
897 
898  //Successful processing
899  error = NO_ERROR;
900  }
901  else
902  {
903  //Report an error
904  error = ERROR_NOT_FOUND;
905  }
906 
907  //Release exclusive access to the LLDP agent context
908  osReleaseMutex(&context->mutex);
909 
910  //Return status code
911  return error;
912 }
913 
914 #endif
LldpMedNetworkPolicyTlv
Definition: lldp_ext_med.h:219
@ LLDP_MED_SUBTYPE_EXT_POWER_VIA_MDI
Extended Power-via-MDI.
Definition: lldp_ext_med.h:59
#define htons(value)
Definition: cpu_endian.h:413
error_t lldpMedSetLocalLocationId(LldpAgentContext *context, uint_t portIndex, LldpMedLocationDataFormat locationDataFormat, const void *locationId, size_t locationIdLen)
Set location identification.
Definition: lldp_ext_med.c:243
@ LLDP_MED_SUBTYPE_FIRMWARE_REVISION
Inventory - Firmware Revision.
Definition: lldp_ext_med.h:61
int bool_t
Definition: compiler_port.h:53
@ ERROR_NOT_FOUND
Definition: error.h:147
uint8_t deviceType
Definition: lldp_ext_med.h:188
error_t lldpMedSetLocalManufacturerName(LldpAgentContext *context, const char_t *manufacturerName)
Set manufacturer name.
Definition: lldp_ext_med.c:679
uint8_t powerSource
error_t lldpMedSetLocalNetworkPolicy(LldpAgentContext *context, uint_t portIndex, LldpMedAppType appType, bool_t u, bool_t t, uint16_t vlanId, uint8_t l2Priority, uint8_t dscpValue)
Set network policy.
Definition: lldp_ext_med.c:116
LldpMedLocationIdTlv
Definition: lldp_ext_med.h:230
uint8_t powerType
@ LLDP_MED_SUBTYPE_MANUFACTURER_NAME
Inventory - Manufacturer Name.
Definition: lldp_ext_med.h:64
uint8_t t
Definition: lldp_ext_med.h:212
#define TRUE
Definition: os_port.h:50
@ LLDP_MED_SUBTYPE_SOFTWARE_REVISION
Inventory - Software Revision.
Definition: lldp_ext_med.h:62
#define LLDP_MED_MAX_INVENTORY_STRING_LEN
Definition: lldp_ext_med.h:41
LldpMedLocationDataFormat
Location data format.
Definition: lldp_ext_med.h:122
error_t lldpMedSetLocalSerialNumber(LldpAgentContext *context, const char_t *serialNumber)
Set serial number.
Definition: lldp_ext_med.c:626
@ LLDP_MED_SUBTYPE_ASSET_ID
Inventory - Asset ID.
Definition: lldp_ext_med.h:66
@ LLDP_MED_SUBTYPE_MODEL_NAME
Inventory - Model Name.
Definition: lldp_ext_med.h:65
@ ERROR_INVALID_PORT
Definition: error.h:104
#define osStrlen(s)
Definition: os_port.h:165
@ LLDP_MED_LOCATION_DATA_FORMAT_CIVIC_ADDR_LCI
Civic Address LCI.
Definition: lldp_ext_med.h:125
uint8_t locationId[]
Definition: lldp_ext_med.h:229
Data logging functions for debugging purpose (LLDP)
error_t lldpMedSetLocalExtPowerViaMdi(LldpAgentContext *context, uint_t portIndex, LldpMedPowerType powerType, LldpMedPowerSource powerSource, LldpMedPowerPriority powerPriority, uint16_t powerValue)
Set extended power-via-MDI.
Definition: lldp_ext_med.c:393
error_t lldpMedSetLocalHardwareRevision(LldpAgentContext *context, const char_t *hardwareRevision)
Set hardware revision.
Definition: lldp_ext_med.c:464
LldpMedPowerSource
Power source.
Definition: lldp_ext_med.h:148
#define FALSE
Definition: os_port.h:46
error_t lldpMedSetLocalAssetId(LldpAgentContext *context, const char_t *assetId)
Set asset identifier.
Definition: lldp_ext_med.c:786
@ LLDP_MED_LOCATION_DATA_FORMAT_COORD_BASED_LCI
Coordinate-based LCI.
Definition: lldp_ext_med.h:124
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
error_t lldpMedSetLocalFirmwareRevision(LldpAgentContext *context, const char_t *firmwareRevision)
Set firmware revision.
Definition: lldp_ext_med.c:518
error_t
Error codes.
Definition: error.h:43
LldpMedExtPowerViaMdiTlv
Definition: lldp_ext_med.h:250
error_t lldpGetOrgDefTlv(LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t **value, size_t *length)
Search an LLDPDU for an organizationally specific TLV.
Definition: lldp_tlv.c:651
@ LLDP_MED_SUBTYPE_SERIAL_NUMBER
Inventory - Serial Number.
Definition: lldp_ext_med.h:63
error_t lldpMedDeleteLocalTlv(LldpAgentContext *context, LldpMedSubtype subtype)
Remove all LLDP-MED specific TLVs with specified subtype.
Definition: lldp_ext_med.c:838
@ LLDP_MED_SUBTYPE_LLDP_MED_CAP
LLDP-MED Capabilities.
Definition: lldp_ext_med.h:56
#define LldpPortEntry
Definition: lldp.h:44
@ LLDP_MED_SUBTYPE_NETWORK_POLICY
Network Policy.
Definition: lldp_ext_med.h:57
@ ERROR_INVALID_LENGTH
Definition: error.h:111
@ LLDP_MED_SUBTYPE_HARDWARE_REVISION
Inventory - Hardware Revision.
Definition: lldp_ext_med.h:60
Helper functions for LLDP.
LldpMedDeviceType
LLDP-MED device type.
Definition: lldp_ext_med.h:90
uint8_t u
Definition: lldp_ext_med.h:213
@ LLDP_MED_OUI
LLDP-MED.
Definition: lldp_tlv.h:190
@ LLDP_MED_LOCATION_DATA_FORMAT_ECS_ELIN
ECS ELIN.
Definition: lldp_ext_med.h:126
uint16_t port
Definition: dns_common.h:267
uint8_t subtype
Definition: lldp_tlv.h:311
error_t lldpDeleteOrgDefTlv(LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index)
Remove an organizationally specific TLV from a LLDPDU.
Definition: lldp_tlv.c:719
error_t lldpMedSetLocalCap(LldpAgentContext *context, uint16_t capabilities, LldpMedDeviceType deviceType)
Set LLDP-MED capabilities.
Definition: lldp_ext_med.c:54
char char_t
Definition: compiler_port.h:48
error_t lldpMedSetLocalModelName(LldpAgentContext *context, const char_t *modelName)
Set model name.
Definition: lldp_ext_med.c:733
uint8_t dscpValue
Definition: lldp_ext_med.h:216
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
LLDP-MED extension (LLDP for Media Endpoint Devices)
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
LldpMedCapTlv
Definition: lldp_ext_med.h:189
error_t lldpSetOrgDefTlv(LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t *value, size_t length, bool_t replace)
Add or replace an organizationally specific TLV.
Definition: lldp_tlv.c:452
LldpMedAppType
Application type.
Definition: lldp_ext_med.h:104
LldpMedPowerType
Power type.
Definition: lldp_ext_med.h:135
#define LldpAgentContext
Definition: lldp.h:40
uint16_t powerValue
Definition: lldp_ext_med.h:248
error_t lldpMedSetLocalSoftwareRevision(LldpAgentContext *context, const char_t *softwareRevision)
Set software revision.
Definition: lldp_ext_med.c:572
@ LLDP_MED_SUBTYPE_LOCATION_ID
Location Identification.
Definition: lldp_ext_med.h:58
LldpMedPowerPriority
Power priority.
Definition: lldp_ext_med.h:165
LLDP (Link Layer Discovery Protocol)
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
@ NO_ERROR
Success.
Definition: error.h:44
LldpMedSubtype
LLDP-MED subtypes.
Definition: lldp_ext_med.h:54
Debugging facilities.