lldp_ext_med.h
Go to the documentation of this file.
1 /**
2  * @file lldp_ext_med.h
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-2022 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.2.0
29  **/
30 
31 #ifndef _LLDP_EXT_MED_H
32 #define _LLDP_EXT_MED_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "lldp/lldp.h"
37 
38 //Minimum length of hardware revision
39 #define LLDP_MED_MIN_INVENTORY_STRING_LEN 0
40 //Maximum length of hardware revision
41 #define LLDP_MED_MAX_INVENTORY_STRING_LEN 32
42 
43 //C++ guard
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief LLDP-MED subtypes
51  **/
52 
53 typedef enum
54 {
55  LLDP_MED_SUBTYPE_RESERVED = 0, ///<Reserved
56  LLDP_MED_SUBTYPE_LLDP_MED_CAP = 1, ///<LLDP-MED Capabilities
57  LLDP_MED_SUBTYPE_NETWORK_POLICY = 2, ///<Network Policy
58  LLDP_MED_SUBTYPE_LOCATION_ID = 3, ///<Location Identification
59  LLDP_MED_SUBTYPE_EXT_POWER_VIA_MDI = 4, ///<Extended Power-via-MDI
60  LLDP_MED_SUBTYPE_HARDWARE_REVISION = 5, ///<Inventory - Hardware Revision
61  LLDP_MED_SUBTYPE_FIRMWARE_REVISION = 6, ///<Inventory - Firmware Revision
62  LLDP_MED_SUBTYPE_SOFTWARE_REVISION = 7, ///<Inventory - Software Revision
63  LLDP_MED_SUBTYPE_SERIAL_NUMBER = 8, ///<Inventory - Serial Number
64  LLDP_MED_SUBTYPE_MANUFACTURER_NAME = 9, ///<Inventory - Manufacturer Name
65  LLDP_MED_SUBTYPE_MODEL_NAME = 10, ///<Inventory - Model Name
66  LLDP_MED_SUBTYPE_ASSET_ID = 11 ///<Inventory - Asset ID
68 
69 
70 /**
71  * @brief LLDP-MED capabilities
72  **/
73 
74 typedef enum
75 {
76  LLDP_MED_CAP = 0x0001, ///<LLDP-MED capabilities
77  LLDP_MED_CAP_NETWORK_POLICY = 0x0002, ///<Network policy
78  LLDP_MED_CAP_LOCATION = 0x0004, ///<Location identification
79  LLDP_MED_CAP_EXTENDED_PSE = 0x0008, ///<Extended power via MDI - PSE
80  LLDP_MED_CAP_EXTENDED_PD = 0x0010, ///<Extended power via MDI - PD
81  LLDP_MED_CAP_INVENTORY = 0x0020 ///<Inventory
83 
84 
85 /**
86  * @brief LLDP-MED device type
87  **/
88 
89 typedef enum
90 {
91  LLDP_MED_DEVICE_TYPE_NOT_DEFINED = 0, ///<Type not defined
92  LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_1 = 1, ///<Endpoint class I
93  LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_2 = 2, ///<Endpoint class II
94  LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_3 = 3, ///<Endpoint class III
95  LLDP_MED_DEVICE_TYPE_NETWORK_CONNECTIVITY = 4 ///<Network connectivity
97 
98 
99 /**
100  * @brief Application type
101  **/
102 
103 typedef enum
104 {
105  LLDP_MED_APP_TYPE_RESERVED = 0, ///<Reserved
106  LLDP_MED_APP_TYPE_VOICE = 1, ///<Voice
107  LLDP_MED_APP_TYPE_VOICE_SIGNALING = 2, ///<Voice signaling
108  LLDP_MED_APP_TYPE_GUEST_VOICE = 3, ///<Guest Voice
109  LLDP_MED_APP_TYPE_GUEST_VOICE_SIGNALING = 4, ///<Guest Voice Signaling
110  LLDP_MED_APP_TYPE_SOFTPHONE_VOICE = 5, ///<Softphone Voice
111  LLDP_MED_APP_TYPE_VIDEO_CONFERENCING = 6, ///<Video Conferencing
112  LLDP_MED_APP_TYPE_STREAMING_VIDEO = 7, ///<Streaming Video
113  LLDP_MED_APP_TYPE_VIDEO_SIGNALING = 8 ///<Video signaling
115 
116 
117 /**
118  * @brief Location data format
119  **/
120 
121 typedef enum
122 {
124  LLDP_MED_LOCATION_DATA_FORMAT_COORD_BASED_LCI = 1, ///<Coordinate-based LCI
128 
129 
130 /**
131  * @brief Power type
132  **/
133 
134 typedef enum
135 {
136  LLDP_MED_POWER_TYPE_PSE_DEVICE = 0, ///<PSE Device
137  LLDP_MED_POWER_TYPE_PD_DEVICE = 1, ///<PD Device
139  LLDP_MED_POWER_TYPE_RESERVED_2 = 3 ///<Reserved
141 
142 
143 /**
144  * @brief Power source
145  **/
146 
147 typedef enum
148 {
149  LLDP_MED_PD_POWER_SOURCE_UNKNOWN = 0, ///<Unknown (PD device type)
150  LLDP_MED_PD_POWER_SOURCE_PSE = 1, ///<PSE (PD device type)
151  LLDP_MED_PD_POWER_SOURCE_LOCAL = 2, ///<Local (PD device type)
152  LLDP_MED_PD_POWER_SOURCE_PSE_AND_LOCAL = 3, ///<PSE and local (PD device type)
153  LLDP_MED_PSE_POWER_SOURCE_UNKNOWN = 0, ///<Unknown (PSE device type)
154  LLDP_MED_PSE_POWER_SOURCE_PRIMARY = 1, ///<Primary Power Source (PSE device type)
155  LLDP_MED_PSE_POWER_SOURCE_BACKUP = 2, ///<Backup Power Source (PSE device type)
156  LLDP_MED_PSE_POWER_SOURCE_RESERVED = 3 ///<Reserved (PSE device type)
158 
159 
160 /**
161  * @brief Power priority
162  **/
163 
164 typedef enum
165 {
169  LLDP_MED_POWER_PRIORITY_LOW = 3 ///<Low
171 
172 
173 //CodeWarrior or Win32 compiler?
174 #if defined(__CWCC__) || defined(_WIN32)
175  #pragma pack(push, 1)
176 #endif
177 
178 
179 /**
180  * @brief LLDP-MED Capabilities TLV
181  **/
182 
183 typedef __start_packed struct
184 {
185  uint16_t capabilities; //0-1
186  uint8_t deviceType; //2
188 
189 
190 /**
191  * @brief Network Policy TLV
192  **/
193 
194 typedef __start_packed struct
195 {
196 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
197  uint8_t appType; //0
198  uint8_t u : 1; //1
199  uint8_t t : 1;
200  uint8_t x : 1;
201  uint8_t vlanIdH : 5;
202  uint8_t vlanIdL : 7; //2
203  uint8_t l2PriorityH : 1;
204  uint8_t l2PriorityL : 2; //3
205  uint8_t dscpValue : 6;
206 #else
207  uint8_t appType; //0
208  uint8_t vlanIdH : 5; //1
209  uint8_t x : 1;
210  uint8_t t : 1;
211  uint8_t u : 1;
212  uint8_t l2PriorityH : 1; //2
213  uint8_t vlanIdL : 7;
214  uint8_t dscpValue : 6; //3
215  uint8_t l2PriorityL : 2;
216 #endif
218 
219 
220 /**
221  * @brief Location Identification TLV
222  **/
223 
224 typedef __start_packed struct
225 {
226  uint8_t locationDataFormat; //0-1
227  uint8_t locationId[]; //2
229 
230 
231 /**
232  * @brief Extended Power-Via-MDI TLV
233  **/
234 
235 typedef __start_packed struct
236 {
237 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
238  uint8_t powerType : 2; //0
239  uint8_t powerSource : 2;
240  uint8_t powerPriority : 4;
241  uint16_t powerValue; //1-2
242 #else
243  uint8_t powerPriority : 4; //0
244  uint8_t powerSource : 2;
245  uint8_t powerType : 2;
246  uint16_t powerValue; //1-2
247 #endif
249 
250 
251 //CodeWarrior or Win32 compiler?
252 #if defined(__CWCC__) || defined(_WIN32)
253  #pragma pack(pop)
254 #endif
255 
256 //LLDP-MED related functions
259 
262  uint16_t vlanId, uint8_t l2Priority, uint8_t dscpValue);
263 
266  const void *locationId, size_t locationIdLen);
267 
271 
273  const char_t *hardwareRevision);
274 
276  const char_t *firmwareRevision);
277 
279  const char_t *softwareRevision);
280 
282  const char_t *serialNumber);
283 
285  const char_t *manufacturerName);
286 
288  const char_t *modelName);
289 
291  const char_t *assetId);
292 
295 
296 //C++ guard
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif
@ LLDP_MED_SUBTYPE_EXT_POWER_VIA_MDI
Extended Power-via-MDI.
Definition: lldp_ext_med.h:59
@ LLDP_MED_CAP_INVENTORY
Inventory.
Definition: lldp_ext_med.h:81
error_t lldpMedSetLocalManufacturerName(LldpAgentContext *context, const char_t *manufacturerName)
Set manufacturer name.
Definition: lldp_ext_med.c:679
@ LLDP_MED_SUBTYPE_FIRMWARE_REVISION
Inventory - Firmware Revision.
Definition: lldp_ext_med.h:61
uint8_t vlanIdL
Definition: lldp_ext_med.h:213
int bool_t
Definition: compiler_port.h:48
uint8_t deviceType
Definition: lldp_ext_med.h:186
@ LLDP_MED_PD_POWER_SOURCE_UNKNOWN
Unknown (PD device type)
Definition: lldp_ext_med.h:149
@ LLDP_MED_PSE_POWER_SOURCE_UNKNOWN
Unknown (PSE device type)
Definition: lldp_ext_med.h:153
@ LLDP_MED_APP_TYPE_STREAMING_VIDEO
Streaming Video.
Definition: lldp_ext_med.h:112
uint16_t vlanId
__start_packed struct @1 LldpMedNetworkPolicyTlv
Network Policy TLV.
@ LLDP_MED_POWER_TYPE_PSE_DEVICE
PSE Device.
Definition: lldp_ext_med.h:136
@ LLDP_MED_SUBTYPE_MANUFACTURER_NAME
Inventory - Manufacturer Name.
Definition: lldp_ext_med.h:64
uint8_t x
Definition: lldp_ext_med.h:209
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
uint8_t t
Definition: lldp_ext_med.h:210
@ LLDP_MED_SUBTYPE_SOFTWARE_REVISION
Inventory - Software Revision.
Definition: lldp_ext_med.h:62
error_t lldpMedSetLocalSoftwareRevision(LldpAgentContext *context, const char_t *softwareRevision)
Set software revision.
Definition: lldp_ext_med.c:572
@ LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_1
Endpoint class I.
Definition: lldp_ext_med.h:92
LldpMedLocationDataFormat
Location data format.
Definition: lldp_ext_med.h:122
@ LLDP_MED_APP_TYPE_SOFTPHONE_VOICE
Softphone Voice.
Definition: lldp_ext_med.h:110
@ LLDP_MED_PD_POWER_SOURCE_PSE_AND_LOCAL
PSE and local (PD device type)
Definition: lldp_ext_med.h:152
@ 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
@ 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:227
@ LLDP_MED_CAP
LLDP-MED capabilities.
Definition: lldp_ext_med.h:76
error_t lldpMedSetLocalHardwareRevision(LldpAgentContext *context, const char_t *hardwareRevision)
Set hardware revision.
Definition: lldp_ext_med.c:464
uint8_t locationDataFormat
Definition: lldp_ext_med.h:226
@ LLDP_MED_APP_TYPE_VOICE_SIGNALING
Voice signaling.
Definition: lldp_ext_med.h:107
error_t lldpMedSetLocalCap(LldpAgentContext *context, uint16_t capabilities, LldpMedDeviceType deviceType)
Set LLDP-MED capabilities.
Definition: lldp_ext_med.c:54
@ LLDP_MED_APP_TYPE_RESERVED
Reserved.
Definition: lldp_ext_med.h:105
@ LLDP_MED_APP_TYPE_VOICE
Voice.
Definition: lldp_ext_med.h:106
LldpMedPowerSource
Power source.
Definition: lldp_ext_med.h:148
@ LLDP_MED_LOCATION_DATA_FORMAT_COORD_BASED_LCI
Coordinate-based LCI.
Definition: lldp_ext_med.h:124
__start_packed struct @3 LldpMedExtPowerViaMdiTlv
Extended Power-Via-MDI TLV.
error_t
Error codes.
Definition: error.h:43
@ LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_2
Endpoint class II.
Definition: lldp_ext_med.h:93
__start_packed struct @0 LldpMedCapTlv
LLDP-MED Capabilities TLV.
error_t lldpMedSetLocalAssetId(LldpAgentContext *context, const char_t *assetId)
Set asset identifier.
Definition: lldp_ext_med.c:786
@ LLDP_MED_DEVICE_TYPE_ENDPOINT_CLASS_3
Endpoint class III.
Definition: lldp_ext_med.h:94
uint8_t powerSource
Definition: lldp_ext_med.h:244
@ LLDP_MED_SUBTYPE_SERIAL_NUMBER
Inventory - Serial Number.
Definition: lldp_ext_med.h:63
@ LLDP_MED_SUBTYPE_LLDP_MED_CAP
LLDP-MED Capabilities.
Definition: lldp_ext_med.h:56
@ LLDP_MED_POWER_TYPE_PD_DEVICE
PD Device.
Definition: lldp_ext_med.h:137
@ LLDP_MED_SUBTYPE_NETWORK_POLICY
Network Policy.
Definition: lldp_ext_med.h:57
__start_packed struct _Ipv4Header __end_packed
@ LLDP_MED_SUBTYPE_HARDWARE_REVISION
Inventory - Hardware Revision.
Definition: lldp_ext_med.h:60
uint16_t capabilities
Definition: lldp_ext_med.h:185
@ LLDP_MED_APP_TYPE_GUEST_VOICE_SIGNALING
Guest Voice Signaling.
Definition: lldp_ext_med.h:109
@ LLDP_MED_POWER_TYPE_RESERVED_2
Reserved.
Definition: lldp_ext_med.h:139
LldpMedDeviceType
LLDP-MED device type.
Definition: lldp_ext_med.h:90
__start_packed struct @2 LldpMedLocationIdTlv
Location Identification TLV.
error_t lldpMedSetLocalModelName(LldpAgentContext *context, const char_t *modelName)
Set model name.
Definition: lldp_ext_med.c:733
uint8_t u
Definition: lldp_ext_med.h:211
LldpMedCap
LLDP-MED capabilities.
Definition: lldp_ext_med.h:75
@ LLDP_MED_PSE_POWER_SOURCE_BACKUP
Backup Power Source (PSE device type)
Definition: lldp_ext_med.h:155
error_t lldpMedSetLocalFirmwareRevision(LldpAgentContext *context, const char_t *firmwareRevision)
Set firmware revision.
Definition: lldp_ext_med.c:518
error_t lldpMedDeleteLocalTlv(LldpAgentContext *context, LldpMedSubtype subtype)
Remove all LLDP-MED specific TLVs with specified subtype.
Definition: lldp_ext_med.c:838
@ LLDP_MED_CAP_LOCATION
Location identification.
Definition: lldp_ext_med.h:78
@ LLDP_MED_PD_POWER_SOURCE_PSE
PSE (PD device type)
Definition: lldp_ext_med.h:150
@ LLDP_MED_CAP_EXTENDED_PD
Extended power via MDI - PD.
Definition: lldp_ext_med.h:80
@ LLDP_MED_LOCATION_DATA_FORMAT_INVALID
Invalid.
Definition: lldp_ext_med.h:123
error_t lldpMedSetLocalSerialNumber(LldpAgentContext *context, const char_t *serialNumber)
Set serial number.
Definition: lldp_ext_med.c:626
@ LLDP_MED_LOCATION_DATA_FORMAT_ECS_ELIN
ECS ELIN.
Definition: lldp_ext_med.h:126
uint8_t subtype
Definition: lldp_tlv.h:309
@ LLDP_MED_CAP_EXTENDED_PSE
Extended power via MDI - PSE.
Definition: lldp_ext_med.h:79
char char_t
Definition: compiler_port.h:43
@ LLDP_MED_DEVICE_TYPE_NETWORK_CONNECTIVITY
Network connectivity.
Definition: lldp_ext_med.h:95
@ LLDP_MED_SUBTYPE_RESERVED
Reserved.
Definition: lldp_ext_med.h:55
uint8_t dscpValue
Definition: lldp_ext_med.h:214
@ LLDP_MED_DEVICE_TYPE_NOT_DEFINED
Type not defined.
Definition: lldp_ext_med.h:91
@ LLDP_MED_APP_TYPE_VIDEO_SIGNALING
Video signaling.
Definition: lldp_ext_med.h:113
@ LLDP_MED_APP_TYPE_VIDEO_CONFERENCING
Video Conferencing.
Definition: lldp_ext_med.h:111
uint8_t vlanIdH
Definition: lldp_ext_med.h:208
@ LLDP_MED_POWER_PRIORITY_UNKNOWN
Unknown.
Definition: lldp_ext_med.h:166
LldpMedAppType
Application type.
Definition: lldp_ext_med.h:104
@ LLDP_MED_POWER_PRIORITY_CRITICAL
Critical.
Definition: lldp_ext_med.h:167
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
LldpMedPowerType
Power type.
Definition: lldp_ext_med.h:135
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
uint8_t l2PriorityH
Definition: lldp_ext_med.h:212
@ LLDP_MED_APP_TYPE_GUEST_VOICE
Guest Voice.
Definition: lldp_ext_med.h:108
#define LldpAgentContext
Definition: lldp.h:40
uint8_t powerType
Definition: lldp_ext_med.h:245
uint8_t powerPriority
Definition: lldp_ext_med.h:243
uint16_t powerValue
Definition: lldp_ext_med.h:246
uint8_t appType
Definition: lldp_ext_med.h:207
@ LLDP_MED_PD_POWER_SOURCE_LOCAL
Local (PD device type)
Definition: lldp_ext_med.h:151
@ LLDP_MED_SUBTYPE_LOCATION_ID
Location Identification.
Definition: lldp_ext_med.h:58
@ LLDP_MED_PSE_POWER_SOURCE_RESERVED
Reserved (PSE device type)
Definition: lldp_ext_med.h:156
LldpMedPowerPriority
Power priority.
Definition: lldp_ext_med.h:165
LLDP (Link Layer Discovery Protocol)
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
@ LLDP_MED_CAP_NETWORK_POLICY
Network policy.
Definition: lldp_ext_med.h:77
@ LLDP_MED_POWER_PRIORITY_LOW
Low.
Definition: lldp_ext_med.h:169
uint8_t l2PriorityL
Definition: lldp_ext_med.h:215
@ LLDP_MED_PSE_POWER_SOURCE_PRIMARY
Primary Power Source (PSE device type)
Definition: lldp_ext_med.h:154
LldpMedSubtype
LLDP-MED subtypes.
Definition: lldp_ext_med.h:54
@ LLDP_MED_POWER_PRIORITY_HIGH
High.
Definition: lldp_ext_med.h:168
@ LLDP_MED_POWER_TYPE_RESERVED_1
Reserved.
Definition: lldp_ext_med.h:138