dma: add a plain Makefile for other systems
[dragonfly.git] / contrib / tcpdump / print-lldp.c
blob36b99343ec82ad0543740e52d9aaf469e95d7c7d
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * support for the IEEE Link Discovery Protocol as per 802.1ab
17 * Original code by Hannes Gredler (hannes@juniper.net)
18 * IEEE and TIA extensions by Carles Kishimoto <carles.kishimoto@gmail.com>
21 #ifndef lint
22 static const char rcsid[] _U_ =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.7.2.3 2008-03-20 09:33:52 hannes Exp $";
24 #endif
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
30 #include <tcpdump-stdinc.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
36 #include "interface.h"
37 #include "extract.h"
38 #include "addrtoname.h"
39 #include "af.h"
40 #include "oui.h"
42 #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
43 #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
46 * TLV type codes
48 #define LLDP_END_TLV 0
49 #define LLDP_CHASSIS_ID_TLV 1
50 #define LLDP_PORT_ID_TLV 2
51 #define LLDP_TTL_TLV 3
52 #define LLDP_PORT_DESCR_TLV 4
53 #define LLDP_SYSTEM_NAME_TLV 5
54 #define LLDP_SYSTEM_DESCR_TLV 6
55 #define LLDP_SYSTEM_CAP_TLV 7
56 #define LLDP_MGMT_ADDR_TLV 8
57 #define LLDP_PRIVATE_TLV 127
59 static const struct tok lldp_tlv_values[] = {
60 { LLDP_END_TLV, "End" },
61 { LLDP_CHASSIS_ID_TLV, "Chassis ID" },
62 { LLDP_PORT_ID_TLV, "Port ID" },
63 { LLDP_TTL_TLV, "Time to Live" },
64 { LLDP_PORT_DESCR_TLV, "Port Description" },
65 { LLDP_SYSTEM_NAME_TLV, "System Name" },
66 { LLDP_SYSTEM_DESCR_TLV, "System Description" },
67 { LLDP_SYSTEM_CAP_TLV, "System Capabilities" },
68 { LLDP_MGMT_ADDR_TLV, "Management Address" },
69 { LLDP_PRIVATE_TLV, "Organization specific" },
70 { 0, NULL}
74 * Chassis ID subtypes
76 #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE 1
77 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE 2
78 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE 3
79 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE 4
80 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE 5
81 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE 6
82 #define LLDP_CHASSIS_LOCAL_SUBTYPE 7
84 static const struct tok lldp_chassis_subtype_values[] = {
85 { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE, "Chassis component"},
86 { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE, "Interface alias"},
87 { LLDP_CHASSIS_PORT_COMP_SUBTYPE, "Port component"},
88 { LLDP_CHASSIS_MAC_ADDR_SUBTYPE, "MAC address"},
89 { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE, "Network address"},
90 { LLDP_CHASSIS_INTF_NAME_SUBTYPE, "Interface name"},
91 { LLDP_CHASSIS_LOCAL_SUBTYPE, "Local"},
92 { 0, NULL}
96 * Port ID subtypes
98 #define LLDP_PORT_INTF_ALIAS_SUBTYPE 1
99 #define LLDP_PORT_PORT_COMP_SUBTYPE 2
100 #define LLDP_PORT_MAC_ADDR_SUBTYPE 3
101 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE 4
102 #define LLDP_PORT_INTF_NAME_SUBTYPE 5
103 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE 6
104 #define LLDP_PORT_LOCAL_SUBTYPE 7
106 static const struct tok lldp_port_subtype_values[] = {
107 { LLDP_PORT_INTF_ALIAS_SUBTYPE, "Interface alias"},
108 { LLDP_PORT_PORT_COMP_SUBTYPE, "Port component"},
109 { LLDP_PORT_MAC_ADDR_SUBTYPE, "MAC address"},
110 { LLDP_PORT_NETWORK_ADDR_SUBTYPE, "Network Address"},
111 { LLDP_PORT_INTF_NAME_SUBTYPE, "Interface Name"},
112 { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE, "Agent circuit ID"},
113 { LLDP_PORT_LOCAL_SUBTYPE, "Local"},
114 { 0, NULL}
118 * System Capabilities
120 #define LLDP_CAP_OTHER (1 << 0)
121 #define LLDP_CAP_REPEATER (1 << 1)
122 #define LLDP_CAP_BRIDGE (1 << 2)
123 #define LLDP_CAP_WLAN_AP (1 << 3)
124 #define LLDP_CAP_ROUTER (1 << 4)
125 #define LLDP_CAP_PHONE (1 << 5)
126 #define LLDP_CAP_DOCSIS (1 << 6)
127 #define LLDP_CAP_STATION_ONLY (1 << 7)
129 static const struct tok lldp_cap_values[] = {
130 { LLDP_CAP_OTHER, "Other"},
131 { LLDP_CAP_REPEATER, "Repeater"},
132 { LLDP_CAP_BRIDGE, "Bridge"},
133 { LLDP_CAP_WLAN_AP, "WLAN AP"},
134 { LLDP_CAP_ROUTER, "Router"},
135 { LLDP_CAP_PHONE, "Telephone"},
136 { LLDP_CAP_DOCSIS, "Docsis"},
137 { LLDP_CAP_STATION_ONLY, "Station Only"},
138 { 0, NULL}
141 #define LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID 1
142 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID 2
143 #define LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME 3
144 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY 4
146 static const struct tok lldp_8021_subtype_values[] = {
147 { LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID, "Port VLAN Id"},
148 { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID, "Port and Protocol VLAN ID"},
149 { LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME, "VLAN name"},
150 { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY, "Protocol Identity"},
151 { 0, NULL}
154 #define LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT (1 << 1)
155 #define LLDP_8021_PORT_PROTOCOL_VLAN_STATUS (1 << 2)
157 static const struct tok lldp_8021_port_protocol_id_values[] = {
158 { LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT, "supported"},
159 { LLDP_8021_PORT_PROTOCOL_VLAN_STATUS, "enabled"},
160 { 0, NULL}
163 #define LLDP_PRIVATE_8023_SUBTYPE_MACPHY 1
164 #define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER 2
165 #define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR 3
166 #define LLDP_PRIVATE_8023_SUBTYPE_MTU 4
168 static const struct tok lldp_8023_subtype_values[] = {
169 { LLDP_PRIVATE_8023_SUBTYPE_MACPHY, "MAC/PHY configuration/status"},
170 { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"},
171 { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"},
172 { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"},
173 { 0, NULL}
176 #define LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES 1
177 #define LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY 2
178 #define LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID 3
179 #define LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI 4
180 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV 5
181 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV 6
182 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV 7
183 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER 8
184 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME 9
185 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME 10
186 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID 11
188 static const struct tok lldp_tia_subtype_values[] = {
189 { LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES, "LLDP-MED Capabilities" },
190 { LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY, "Network policy" },
191 { LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID, "Location identification" },
192 { LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI, "Extended power-via-MDI" },
193 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Inventory - hardware revision" },
194 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Inventory - firmware revision" },
195 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Inventory - software revision" },
196 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Inventory - serial number" },
197 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Inventory - manufacturer name" },
198 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Inventory - model name" },
199 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Inventory - asset ID" },
200 { 0, NULL}
203 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS 1
204 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS 2
206 static const struct tok lldp_tia_location_altitude_type_values[] = {
207 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"},
208 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"},
209 { 0, NULL}
212 /* ANSI/TIA-1057 - Annex B */
213 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1 1
214 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2 2
215 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3 3
216 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4 4
217 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5 5
218 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6 6
220 static const struct tok lldp_tia_location_lci_catype_values[] = {
221 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"},
222 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"},
223 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"},
224 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"},
225 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"},
226 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"},
227 { 0, NULL}
230 static const struct tok lldp_tia_location_lci_what_values[] = {
231 { 0, "location of DHCP server"},
232 { 1, "location of the network element believed to be closest to the client"},
233 { 2, "location of the client"},
234 { 0, NULL}
238 * From RFC 3636 - dot3MauType
240 #define LLDP_MAU_TYPE_UNKNOWN 0
241 #define LLDP_MAU_TYPE_AUI 1
242 #define LLDP_MAU_TYPE_10BASE_5 2
243 #define LLDP_MAU_TYPE_FOIRL 3
244 #define LLDP_MAU_TYPE_10BASE_2 4
245 #define LLDP_MAU_TYPE_10BASE_T 5
246 #define LLDP_MAU_TYPE_10BASE_FP 6
247 #define LLDP_MAU_TYPE_10BASE_FB 7
248 #define LLDP_MAU_TYPE_10BASE_FL 8
249 #define LLDP_MAU_TYPE_10BROAD36 9
250 #define LLDP_MAU_TYPE_10BASE_T_HD 10
251 #define LLDP_MAU_TYPE_10BASE_T_FD 11
252 #define LLDP_MAU_TYPE_10BASE_FL_HD 12
253 #define LLDP_MAU_TYPE_10BASE_FL_FD 13
254 #define LLDP_MAU_TYPE_100BASE_T4 14
255 #define LLDP_MAU_TYPE_100BASE_TX_HD 15
256 #define LLDP_MAU_TYPE_100BASE_TX_FD 16
257 #define LLDP_MAU_TYPE_100BASE_FX_HD 17
258 #define LLDP_MAU_TYPE_100BASE_FX_FD 18
259 #define LLDP_MAU_TYPE_100BASE_T2_HD 19
260 #define LLDP_MAU_TYPE_100BASE_T2_FD 20
261 #define LLDP_MAU_TYPE_1000BASE_X_HD 21
262 #define LLDP_MAU_TYPE_1000BASE_X_FD 22
263 #define LLDP_MAU_TYPE_1000BASE_LX_HD 23
264 #define LLDP_MAU_TYPE_1000BASE_LX_FD 24
265 #define LLDP_MAU_TYPE_1000BASE_SX_HD 25
266 #define LLDP_MAU_TYPE_1000BASE_SX_FD 26
267 #define LLDP_MAU_TYPE_1000BASE_CX_HD 27
268 #define LLDP_MAU_TYPE_1000BASE_CX_FD 28
269 #define LLDP_MAU_TYPE_1000BASE_T_HD 29
270 #define LLDP_MAU_TYPE_1000BASE_T_FD 30
271 #define LLDP_MAU_TYPE_10GBASE_X 31
272 #define LLDP_MAU_TYPE_10GBASE_LX4 32
273 #define LLDP_MAU_TYPE_10GBASE_R 33
274 #define LLDP_MAU_TYPE_10GBASE_ER 34
275 #define LLDP_MAU_TYPE_10GBASE_LR 35
276 #define LLDP_MAU_TYPE_10GBASE_SR 36
277 #define LLDP_MAU_TYPE_10GBASE_W 37
278 #define LLDP_MAU_TYPE_10GBASE_EW 38
279 #define LLDP_MAU_TYPE_10GBASE_LW 39
280 #define LLDP_MAU_TYPE_10GBASE_SW 40
282 static const struct tok lldp_mau_types_values[] = {
283 { LLDP_MAU_TYPE_UNKNOWN, "Unknown"},
284 { LLDP_MAU_TYPE_AUI, "AUI"},
285 { LLDP_MAU_TYPE_10BASE_5, "10BASE_5"},
286 { LLDP_MAU_TYPE_FOIRL, "FOIRL"},
287 { LLDP_MAU_TYPE_10BASE_2, "10BASE2"},
288 { LLDP_MAU_TYPE_10BASE_T, "10BASET duplex mode unknown"},
289 { LLDP_MAU_TYPE_10BASE_FP, "10BASEFP"},
290 { LLDP_MAU_TYPE_10BASE_FB, "10BASEFB"},
291 { LLDP_MAU_TYPE_10BASE_FL, "10BASEFL duplex mode unknown"},
292 { LLDP_MAU_TYPE_10BROAD36, "10BROAD36"},
293 { LLDP_MAU_TYPE_10BASE_T_HD, "10BASET hdx"},
294 { LLDP_MAU_TYPE_10BASE_T_FD, "10BASET fdx"},
295 { LLDP_MAU_TYPE_10BASE_FL_HD, "10BASEFL hdx"},
296 { LLDP_MAU_TYPE_10BASE_FL_FD, "10BASEFL fdx"},
297 { LLDP_MAU_TYPE_100BASE_T4, "100BASET4"},
298 { LLDP_MAU_TYPE_100BASE_TX_HD, "100BASETX hdx"},
299 { LLDP_MAU_TYPE_100BASE_TX_FD, "100BASETX fdx"},
300 { LLDP_MAU_TYPE_100BASE_FX_HD, "100BASEFX hdx"},
301 { LLDP_MAU_TYPE_100BASE_FX_FD, "100BASEFX fdx"},
302 { LLDP_MAU_TYPE_100BASE_T2_HD, "100BASET2 hdx"},
303 { LLDP_MAU_TYPE_100BASE_T2_FD, "100BASET2 fdx"},
304 { LLDP_MAU_TYPE_1000BASE_X_HD, "1000BASEX hdx"},
305 { LLDP_MAU_TYPE_1000BASE_X_FD, "1000BASEX fdx"},
306 { LLDP_MAU_TYPE_1000BASE_LX_HD, "1000BASELX hdx"},
307 { LLDP_MAU_TYPE_1000BASE_LX_FD, "1000BASELX fdx"},
308 { LLDP_MAU_TYPE_1000BASE_SX_HD, "1000BASESX hdx"},
309 { LLDP_MAU_TYPE_1000BASE_SX_FD, "1000BASESX fdx"},
310 { LLDP_MAU_TYPE_1000BASE_CX_HD, "1000BASECX hdx"},
311 { LLDP_MAU_TYPE_1000BASE_CX_FD, "1000BASECX fdx"},
312 { LLDP_MAU_TYPE_1000BASE_T_HD, "1000BASET hdx"},
313 { LLDP_MAU_TYPE_1000BASE_T_FD, "1000BASET fdx"},
314 { LLDP_MAU_TYPE_10GBASE_X, "10GBASEX"},
315 { LLDP_MAU_TYPE_10GBASE_LX4, "10GBASELX4"},
316 { LLDP_MAU_TYPE_10GBASE_R, "10GBASER"},
317 { LLDP_MAU_TYPE_10GBASE_ER, "10GBASEER"},
318 { LLDP_MAU_TYPE_10GBASE_LR, "10GBASELR"},
319 { LLDP_MAU_TYPE_10GBASE_SR, "10GBASESR"},
320 { LLDP_MAU_TYPE_10GBASE_W, "10GBASEW"},
321 { LLDP_MAU_TYPE_10GBASE_EW, "10GBASEEW"},
322 { LLDP_MAU_TYPE_10GBASE_LW, "10GBASELW"},
323 { LLDP_MAU_TYPE_10GBASE_SW, "10GBASESW"},
324 { 0, NULL}
327 #define LLDP_8023_AUTONEGOTIATION_SUPPORT (1 << 0)
328 #define LLDP_8023_AUTONEGOTIATION_STATUS (1 << 1)
330 static const struct tok lldp_8023_autonegotiation_values[] = {
331 { LLDP_8023_AUTONEGOTIATION_SUPPORT, "supported"},
332 { LLDP_8023_AUTONEGOTIATION_STATUS, "enabled"},
333 { 0, NULL}
336 #define LLDP_TIA_CAPABILITY_MED (1 << 0)
337 #define LLDP_TIA_CAPABILITY_NETWORK_POLICY (1 << 1)
338 #define LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION (1 << 2)
339 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE (1 << 3)
340 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD (1 << 4)
341 #define LLDP_TIA_CAPABILITY_INVENTORY (1 << 5)
343 static const struct tok lldp_tia_capabilities_values[] = {
344 { LLDP_TIA_CAPABILITY_MED, "LLDP-MED capabilities"},
345 { LLDP_TIA_CAPABILITY_NETWORK_POLICY, "network policy"},
346 { LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION, "location identification"},
347 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE, "extended power via MDI-PSE"},
348 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD, "extended power via MDI-PD"},
349 { LLDP_TIA_CAPABILITY_INVENTORY, "Inventory"},
350 { 0, NULL}
353 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1 1
354 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2 2
355 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3 3
356 #define LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY 4
358 static const struct tok lldp_tia_device_type_values[] = {
359 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1, "endpoint class 1"},
360 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2, "endpoint class 2"},
361 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3, "endpoint class 3"},
362 { LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY, "network connectivity"},
363 { 0, NULL}
366 #define LLDP_TIA_APPLICATION_TYPE_VOICE 1
367 #define LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING 2
368 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE 3
369 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING 4
370 #define LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE 5
371 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING 6
372 #define LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO 7
373 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING 8
375 static const struct tok lldp_tia_application_type_values[] = {
376 { LLDP_TIA_APPLICATION_TYPE_VOICE, "voice"},
377 { LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING, "voice signaling"},
378 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE, "guest voice"},
379 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING, "guest voice signaling"},
380 { LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE, "softphone voice"},
381 { LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING, "video conferencing"},
382 { LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO, "streaming video"},
383 { LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING, "video signaling"},
384 { 0, NULL}
387 #define LLDP_TIA_NETWORK_POLICY_U_BIT (1 << 5)
388 #define LLDP_TIA_NETWORK_POLICY_T_BIT (1 << 6)
389 #define LLDP_TIA_NETWORK_POLICY_X_BIT (1 << 7)
391 static const struct tok lldp_tia_network_policy_bits_values[] = {
392 { LLDP_TIA_NETWORK_POLICY_U_BIT, "Unknown"},
393 { LLDP_TIA_NETWORK_POLICY_T_BIT, "Tagged"},
394 { LLDP_TIA_NETWORK_POLICY_X_BIT, "reserved"},
395 { 0, NULL}
398 #define LLDP_EXTRACT_NETWORK_POLICY_VLAN(x) (((x)&0x1ffe)>>1)
399 #define LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(x) (((x)&0x01ff)>>6)
400 #define LLDP_EXTRACT_NETWORK_POLICY_DSCP(x) ((x)&0x003f)
402 #define LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED 1
403 #define LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS 2
404 #define LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN 3
406 static const struct tok lldp_tia_location_data_format_values[] = {
407 { LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED, "coordinate-based LCI"},
408 { LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS, "civic address LCI"},
409 { LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN, "ECS ELIN"},
410 { 0, NULL}
413 #define LLDP_TIA_LOCATION_DATUM_WGS_84 1
414 #define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88 2
415 #define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW 3
417 static const struct tok lldp_tia_location_datum_type_values[] = {
418 { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"},
419 { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"},
420 { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"},
421 { 0, NULL}
424 #define LLDP_TIA_POWER_SOURCE_PSE 1
425 #define LLDP_TIA_POWER_SOURCE_LOCAL 2
426 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL 3
428 static const struct tok lldp_tia_power_source_values[] = {
429 { LLDP_TIA_POWER_SOURCE_PSE, "PSE - primary power source"},
430 { LLDP_TIA_POWER_SOURCE_LOCAL, "local - backup power source"},
431 { LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL, "PSE+local - reserved"},
432 { 0, NULL}
435 #define LLDP_TIA_POWER_PRIORITY_CRITICAL 1
436 #define LLDP_TIA_POWER_PRIORITY_HIGH 2
437 #define LLDP_TIA_POWER_PRIORITY_LOW 3
439 static const struct tok lldp_tia_power_priority_values[] = {
440 { LLDP_TIA_POWER_PRIORITY_CRITICAL, "critical"},
441 { LLDP_TIA_POWER_PRIORITY_HIGH, "high"},
442 { LLDP_TIA_POWER_PRIORITY_LOW, "low"},
443 { 0, NULL}
446 #define LLDP_TIA_POWER_VAL_MAX 1024
448 static const struct tok lldp_tia_inventory_values[] = {
449 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Hardware revision" },
450 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Firmware revision" },
451 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Software revision" },
452 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Serial number" },
453 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Manufacturer name" },
454 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Model name" },
455 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Asset ID" },
456 { 0, NULL}
460 * From RFC 3636 - ifMauAutoNegCapAdvertisedBits
462 #define LLDP_MAU_PMD_OTHER (1 << 15)
463 #define LLDP_MAU_PMD_10BASE_T (1 << 14)
464 #define LLDP_MAU_PMD_10BASE_T_FD (1 << 13)
465 #define LLDP_MAU_PMD_100BASE_T4 (1 << 12)
466 #define LLDP_MAU_PMD_100BASE_TX (1 << 11)
467 #define LLDP_MAU_PMD_100BASE_TX_FD (1 << 10)
468 #define LLDP_MAU_PMD_100BASE_T2 (1 << 9)
469 #define LLDP_MAU_PMD_100BASE_T2_FD (1 << 8)
470 #define LLDP_MAU_PMD_FDXPAUSE (1 << 7)
471 #define LLDP_MAU_PMD_FDXAPAUSE (1 << 6)
472 #define LLDP_MAU_PMD_FDXSPAUSE (1 << 5)
473 #define LLDP_MAU_PMD_FDXBPAUSE (1 << 4)
474 #define LLDP_MAU_PMD_1000BASE_X (1 << 3)
475 #define LLDP_MAU_PMD_1000BASE_X_FD (1 << 2)
476 #define LLDP_MAU_PMD_1000BASE_T (1 << 1)
477 #define LLDP_MAU_PMD_1000BASE_T_FD (1 << 0)
479 static const struct tok lldp_pmd_capability_values[] = {
480 { LLDP_MAU_PMD_10BASE_T, "10BASE-T hdx"},
481 { LLDP_MAU_PMD_10BASE_T_FD, "10BASE-T fdx"},
482 { LLDP_MAU_PMD_100BASE_T4, "100BASE-T4"},
483 { LLDP_MAU_PMD_100BASE_TX, "100BASE-TX hdx"},
484 { LLDP_MAU_PMD_100BASE_TX_FD, "100BASE-TX fdx"},
485 { LLDP_MAU_PMD_100BASE_T2, "100BASE-T2 hdx"},
486 { LLDP_MAU_PMD_100BASE_T2_FD, "100BASE-T2 fdx"},
487 { LLDP_MAU_PMD_FDXPAUSE, "Pause for fdx links"},
488 { LLDP_MAU_PMD_FDXAPAUSE, "Asym PAUSE for fdx"},
489 { LLDP_MAU_PMD_FDXSPAUSE, "Sym PAUSE for fdx"},
490 { LLDP_MAU_PMD_FDXBPAUSE, "Asym and Sym PAUSE for fdx"},
491 { LLDP_MAU_PMD_1000BASE_X, "1000BASE-{X LX SX CX} hdx"},
492 { LLDP_MAU_PMD_1000BASE_X_FD, "1000BASE-{X LX SX CX} fdx"},
493 { LLDP_MAU_PMD_1000BASE_T, "1000BASE-T hdx"},
494 { LLDP_MAU_PMD_1000BASE_T_FD, "1000BASE-T fdx"},
495 { 0, NULL}
498 #define LLDP_MDI_PORT_CLASS (1 << 0)
499 #define LLDP_MDI_POWER_SUPPORT (1 << 1)
500 #define LLDP_MDI_POWER_STATE (1 << 2)
501 #define LLDP_MDI_PAIR_CONTROL_ABILITY (1 << 3)
503 static const struct tok lldp_mdi_values[] = {
504 { LLDP_MDI_PORT_CLASS, "PSE"},
505 { LLDP_MDI_POWER_SUPPORT, "supported"},
506 { LLDP_MDI_POWER_STATE, "enabled"},
507 { LLDP_MDI_PAIR_CONTROL_ABILITY, "can be controlled"},
508 { 0, NULL}
511 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL 1
512 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE 2
514 static const struct tok lldp_mdi_power_pairs_values[] = {
515 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL, "signal"},
516 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE, "spare"},
517 { 0, NULL}
520 #define LLDP_MDI_POWER_CLASS0 1
521 #define LLDP_MDI_POWER_CLASS1 2
522 #define LLDP_MDI_POWER_CLASS2 3
523 #define LLDP_MDI_POWER_CLASS3 4
524 #define LLDP_MDI_POWER_CLASS4 5
526 static const struct tok lldp_mdi_power_class_values[] = {
527 { LLDP_MDI_POWER_CLASS0, "class0"},
528 { LLDP_MDI_POWER_CLASS1, "class1"},
529 { LLDP_MDI_POWER_CLASS2, "class2"},
530 { LLDP_MDI_POWER_CLASS3, "class3"},
531 { LLDP_MDI_POWER_CLASS4, "class4"},
532 { 0, NULL}
535 #define LLDP_AGGREGATION_CAPABILTIY (1 << 0)
536 #define LLDP_AGGREGATION_STATUS (1 << 1)
538 static const struct tok lldp_aggregation_values[] = {
539 { LLDP_AGGREGATION_CAPABILTIY, "supported"},
540 { LLDP_AGGREGATION_STATUS, "enabled"},
541 { 0, NULL}
545 * Interface numbering subtypes.
547 #define LLDP_INTF_NUMB_IFX_SUBTYPE 2
548 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE 3
550 static const struct tok lldp_intf_numb_subtype_values[] = {
551 { LLDP_INTF_NUMB_IFX_SUBTYPE, "Interface Index" },
552 { LLDP_INTF_NUMB_SYSPORT_SUBTYPE, "System Port Number" },
553 { 0, NULL}
556 #define LLDP_INTF_NUM_LEN 5
559 * Print IEEE private extensions. (802.1 annex F)
561 static int
562 lldp_private_8021_print(const u_char *tptr)
564 int subtype, hexdump = FALSE;
566 subtype = *(tptr+3);
568 printf("\n\t %s Subtype (%u)",
569 tok2str(lldp_8021_subtype_values, "unknown", subtype),
570 subtype);
572 switch (subtype) {
573 case LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID:
574 printf("\n\t port vlan id (PVID): %u",
575 EXTRACT_16BITS(tptr+4));
576 break;
577 case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID:
578 printf("\n\t port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)",
579 EXTRACT_16BITS(tptr+5),
580 bittok2str(lldp_8021_port_protocol_id_values, "none", *(tptr+4)),
581 *(tptr+4));
582 break;
583 case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME:
584 printf("\n\t vlan id (VID): %u",
585 EXTRACT_16BITS(tptr+4));
586 printf("\n\t vlan name: ");
587 safeputs((const char *)tptr+7, *(tptr+6));
588 break;
589 case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY:
590 printf("\n\t protocol identity: ");
591 safeputs((const char *)tptr+5, *(tptr+4));
592 break;
594 default:
595 hexdump = TRUE;
596 break;
599 return hexdump;
603 * Print IEEE private extensions. (802.3)
605 static int
606 lldp_private_8023_print(const u_char *tptr)
608 int subtype, hexdump = FALSE;
610 subtype = *(tptr+3);
612 printf("\n\t %s Subtype (%u)",
613 tok2str(lldp_8023_subtype_values, "unknown", subtype),
614 subtype);
616 switch (subtype) {
617 case LLDP_PRIVATE_8023_SUBTYPE_MACPHY:
618 printf("\n\t autonegotiation [%s] (0x%02x)",
619 bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)),
620 *(tptr+4));
621 printf("\n\t PMD autoneg capability [%s] (0x%04x)",
622 bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_16BITS(tptr+5)),
623 EXTRACT_16BITS(tptr+5));
624 printf("\n\t MAU type %s (0x%04x)",
625 tok2str(lldp_mau_types_values, "unknown", EXTRACT_16BITS(tptr+7)),
626 EXTRACT_16BITS(tptr+7));
627 break;
629 case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER:
630 printf("\n\t MDI power support [%s], power pair %s, power class %s",
631 bittok2str(lldp_mdi_values, "none", *(tptr+4)),
632 tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)),
633 tok2str(lldp_mdi_power_class_values, "unknown", *(tptr+6)));
634 break;
636 case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR:
637 printf("\n\t aggregation status [%s], aggregation port ID %u",
638 bittok2str(lldp_aggregation_values, "none", *(tptr+4)),
639 EXTRACT_32BITS(tptr+5));
640 break;
642 case LLDP_PRIVATE_8023_SUBTYPE_MTU:
643 printf("\n\t MTU size %u", EXTRACT_16BITS(tptr+4));
644 break;
646 default:
647 hexdump = TRUE;
648 break;
651 return hexdump;
655 * Extract 34bits of latitude/longitude coordinates.
657 static u_int64_t
658 lldp_extract_latlon(const u_char *tptr)
660 u_int64_t latlon;
662 latlon = *tptr & 0x3;
663 latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1);
665 return latlon;
669 * Print private TIA extensions.
671 static int
672 lldp_private_tia_print(const u_char *tptr, u_int tlv_len)
674 int subtype, hexdump = FALSE;
675 u_int8_t location_format;
676 u_int16_t power_val;
677 u_int8_t lci_len, ca_type, ca_len;
679 subtype = *(tptr+3);
681 printf("\n\t %s Subtype (%u)",
682 tok2str(lldp_tia_subtype_values, "unknown", subtype),
683 subtype);
685 switch (subtype) {
686 case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES:
687 printf("\n\t Media capabilities [%s] (0x%04x)",
688 bittok2str(lldp_tia_capabilities_values, "none",
689 EXTRACT_16BITS(tptr+4)), EXTRACT_16BITS(tptr+4));
690 printf("\n\t Device type [%s] (0x%02x)",
691 tok2str(lldp_tia_device_type_values, "unknown", *(tptr+6)),
692 *(tptr+6));
693 break;
695 case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY:
696 printf("\n\t Application type [%s] (0x%02x)",
697 tok2str(lldp_tia_application_type_values, "none", *(tptr+4)),
698 *(tptr+4));
699 printf(", Flags [%s]", bittok2str(
700 lldp_tia_network_policy_bits_values, "none", *(tptr+5)));
701 printf("\n\t Vlan id %u",
702 LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr+5)));
703 printf(", L2 priority %u",
704 LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr+6)));
705 printf(", DSCP value %u",
706 LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr+6)));
707 break;
709 case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID:
710 location_format = *(tptr+4);
711 printf("\n\t Location data format %s (0x%02x)",
712 tok2str(lldp_tia_location_data_format_values, "unknown", location_format),
713 location_format);
715 switch (location_format) {
716 case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED:
717 printf("\n\t Latitude resolution %u, latitude value %" PRIu64,
718 (*(tptr+5)>>2), lldp_extract_latlon(tptr+5));
719 printf("\n\t Longitude resolution %u, longitude value %" PRIu64,
720 (*(tptr+10)>>2), lldp_extract_latlon(tptr+10));
721 printf("\n\t Altitude type %s (%u)",
722 tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)),
723 (*(tptr+15)>>4));
724 printf("\n\t Altitude resolution %u, altitude value 0x%x",
725 (EXTRACT_16BITS(tptr+15)>>6)&0x3f,
726 ((EXTRACT_32BITS(tptr+16)&0x3fffffff)));
727 printf("\n\t Datum %s (0x%02x)",
728 tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)),
729 *(tptr+20));
730 break;
732 case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS:
733 lci_len = *(tptr+5);
734 printf("\n\t LCI length %u, LCI what %s (0x%02x), Country-code ",
735 lci_len,
736 tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)),
737 *(tptr+6));
739 /* Country code */
740 safeputs((const char *)(tptr+7), 2);
742 lci_len = lci_len-3;
743 tptr = tptr + 9;
745 /* Decode each civic address element */
746 while (lci_len > 0) {
747 ca_type = *(tptr);
748 ca_len = *(tptr+1);
750 tptr += 2;
751 lci_len -= 2;
753 printf("\n\t CA type \'%s\' (%u), length %u: ",
754 tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type),
755 ca_type, ca_len);
757 /* basic sanity check */
758 if ( ca_type == 0 || ca_len == 0) {
759 return hexdump;
762 safeputs((const char *)tptr, ca_len);
763 tptr += ca_len;
764 lci_len -= ca_len;
766 break;
768 case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN:
769 printf("\n\t ECS ELIN id ");
770 safeputs((const char *)tptr+5, tlv_len-5);
771 break;
773 default:
774 printf("\n\t Location ID ");
775 print_unknown_data(tptr+5, "\n\t ", tlv_len-5);
777 break;
779 case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI:
780 printf("\n\t Power type [%s]",
781 (*(tptr+4)&0xC0>>6) ? "PD device" : "PSE device");
782 printf(", Power source [%s]",
783 tok2str(lldp_tia_power_source_values, "none", (*(tptr+4)&0x30)>>4));
784 printf("\n\t Power priority [%s] (0x%02x)",
785 tok2str(lldp_tia_power_priority_values, "none", *(tptr+4)&0x0f),
786 *(tptr+4)&0x0f);
787 power_val = EXTRACT_16BITS(tptr+5);
788 if (power_val < LLDP_TIA_POWER_VAL_MAX) {
789 printf(", Power %.1f Watts", ((float)power_val)/10);
790 } else {
791 printf(", Power %u (Reserved)", power_val);
793 break;
795 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV:
796 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV:
797 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV:
798 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER:
799 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME:
800 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME:
801 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID:
802 printf("\n\t %s ",
803 tok2str(lldp_tia_inventory_values, "unknown", subtype));
804 safeputs((const char *)tptr+4, tlv_len-4);
805 break;
807 default:
808 hexdump = TRUE;
809 break;
812 return hexdump;
815 static char *
816 lldp_network_addr_print(const u_char *tptr) {
818 u_int8_t af;
819 static char buf[BUFSIZE];
820 const char * (*pfunc)(const u_char *);
822 af = *tptr;
823 switch (af) {
824 case AFNUM_INET:
825 pfunc = getname;
826 break;
827 #ifdef INET6
828 case AFNUM_INET6:
829 pfunc = getname6;
830 break;
831 #endif
832 case AFNUM_802:
833 pfunc = etheraddr_string;
834 break;
835 default:
836 pfunc = NULL;
837 break;
840 if (!pfunc) {
841 snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !",
842 tok2str(af_values, "Unknown", af), af);
843 } else {
844 snprintf(buf, sizeof(buf), "AFI %s (%u): %s",
845 tok2str(af_values, "Unknown", af), af, (*pfunc)(tptr+1));
848 return buf;
851 static int
852 lldp_mgmt_addr_tlv_print(const u_char *pptr, u_int len) {
854 u_int8_t mgmt_addr_len, intf_num_subtype, oid_len;
855 const u_char *tptr;
856 u_int tlen;
858 tlen = len;
859 tptr = pptr;
861 mgmt_addr_len = *tptr++;
862 tlen--;
864 if (tlen < mgmt_addr_len) {
865 return 0;
868 printf("\n\t Management Address length %u, %s",
869 mgmt_addr_len,
870 lldp_network_addr_print(tptr));
871 tptr += mgmt_addr_len;
872 tlen -= mgmt_addr_len;
874 if (tlen < LLDP_INTF_NUM_LEN) {
875 return 0;
878 intf_num_subtype = *tptr;
879 printf("\n\t %s Interface Numbering (%u): %u",
880 tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype),
881 intf_num_subtype,
882 EXTRACT_32BITS(tptr+1));
884 tptr += LLDP_INTF_NUM_LEN;
885 tlen -= LLDP_INTF_NUM_LEN;
888 * The OID is optional.
890 if (tlen) {
891 oid_len = *tptr;
893 if (oid_len) {
894 printf("\n\t OID length %u", oid_len);
895 safeputs((const char *)tptr+1, oid_len);
899 return 1;
902 void
903 lldp_print(register const u_char *pptr, register u_int len) {
905 u_int8_t subtype;
906 u_int16_t tlv, cap, ena_cap;
907 u_int oui, tlen, hexdump, tlv_type, tlv_len;
908 const u_char *tptr;
910 tptr = pptr;
911 tlen = len;
913 if (vflag) {
914 printf("LLDP, length %u", len);
917 while (tlen >= sizeof(tlv)) {
919 TCHECK2(*tptr, sizeof(tlv));
921 tlv = EXTRACT_16BITS(tptr);
923 tlv_type = LLDP_EXTRACT_TYPE(tlv);
924 tlv_len = LLDP_EXTRACT_LEN(tlv);
925 hexdump = FALSE;
927 tlen -= sizeof(tlv);
928 tptr += sizeof(tlv);
930 if (vflag) {
931 printf("\n\t%s TLV (%u), length %u",
932 tok2str(lldp_tlv_values, "Unknown", tlv_type),
933 tlv_type, tlv_len);
936 /* infinite loop check */
937 if (!tlv_type || !tlv_len) {
938 break;
941 TCHECK2(*tptr, tlv_len);
943 switch (tlv_type) {
944 case LLDP_TTL_TLV:
945 if (vflag) {
946 printf(": TTL %us", EXTRACT_16BITS(tptr));
948 break;
950 case LLDP_SYSTEM_NAME_TLV:
953 * The system name is also print in non-verbose mode
954 * similar to the CDP printer.
956 if (vflag) {
957 printf(": ");
958 safeputs((const char *)tptr, tlv_len);
959 } else {
960 printf("LLDP, name ");
961 safeputs((const char *)tptr, tlv_len);
962 printf(", length %u", len);
964 break;
966 case LLDP_PORT_DESCR_TLV:
967 if (vflag) {
968 printf(": ");
969 safeputs((const char *)tptr, tlv_len);
971 break;
973 case LLDP_SYSTEM_DESCR_TLV:
974 if (vflag) {
975 printf("\n\t ");
976 safeputs((const char *)tptr, tlv_len);
978 break;
981 case LLDP_CHASSIS_ID_TLV:
982 if (vflag) {
983 subtype = *tptr;
984 printf("\n\t Subtype %s (%u): ",
985 tok2str(lldp_chassis_subtype_values, "Unknown", subtype),
986 subtype);
988 switch (subtype) {
989 case LLDP_CHASSIS_MAC_ADDR_SUBTYPE:
990 printf("%s", etheraddr_string(tptr+1));
991 break;
993 case LLDP_CHASSIS_INTF_NAME_SUBTYPE: /* fall through */
994 case LLDP_CHASSIS_LOCAL_SUBTYPE:
995 case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE:
996 case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE:
997 case LLDP_CHASSIS_PORT_COMP_SUBTYPE:
998 safeputs((const char *)tptr+1, tlv_len-1);
999 break;
1001 case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE:
1002 printf("%s", lldp_network_addr_print(tptr+1));
1003 break;
1005 default:
1006 hexdump = TRUE;
1007 break;
1010 break;
1012 case LLDP_PORT_ID_TLV:
1013 if (vflag) {
1014 subtype = *tptr;
1015 printf("\n\t Subtype %s (%u): ",
1016 tok2str(lldp_port_subtype_values, "Unknown", subtype),
1017 subtype);
1019 switch (subtype) {
1020 case LLDP_PORT_MAC_ADDR_SUBTYPE:
1021 printf("%s", etheraddr_string(tptr+1));
1022 break;
1024 case LLDP_PORT_INTF_NAME_SUBTYPE: /* fall through */
1025 case LLDP_PORT_LOCAL_SUBTYPE:
1026 case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE:
1027 case LLDP_PORT_INTF_ALIAS_SUBTYPE:
1028 case LLDP_PORT_PORT_COMP_SUBTYPE:
1029 safeputs((const char *)tptr+1, tlv_len-1);
1030 break;
1032 case LLDP_PORT_NETWORK_ADDR_SUBTYPE:
1033 printf("%s", lldp_network_addr_print(tptr+1));
1034 break;
1036 default:
1037 hexdump = TRUE;
1038 break;
1041 break;
1043 case LLDP_PRIVATE_TLV:
1044 if (vflag) {
1045 oui = EXTRACT_24BITS(tptr);
1046 printf(": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui);
1048 switch (oui) {
1049 case OUI_IEEE_8021_PRIVATE:
1050 hexdump = lldp_private_8021_print(tptr);
1051 break;
1052 case OUI_IEEE_8023_PRIVATE:
1053 hexdump = lldp_private_8023_print(tptr);
1054 break;
1055 case OUI_TIA:
1056 hexdump = lldp_private_tia_print(tptr, tlv_len);
1057 break;
1058 default:
1059 hexdump = TRUE;
1060 break;
1063 break;
1065 case LLDP_SYSTEM_CAP_TLV:
1066 if (vflag) {
1067 cap = EXTRACT_16BITS(tptr);
1068 ena_cap = EXTRACT_16BITS(tptr+2);
1069 printf("\n\t System Capabilities [%s] (0x%04x)",
1070 bittok2str(lldp_cap_values, "none", cap), cap);
1071 printf("\n\t Enabled Capabilities [%s] (0x%04x)",
1072 bittok2str(lldp_cap_values, "none", ena_cap), ena_cap);
1074 break;
1076 case LLDP_MGMT_ADDR_TLV:
1077 if (vflag) {
1078 if (!lldp_mgmt_addr_tlv_print(tptr, tlen)) {
1079 goto trunc;
1082 break;
1084 default:
1085 hexdump = TRUE;
1086 break;
1089 /* do we also want to see a hex dump ? */
1090 if (vflag > 1 || (vflag && hexdump)) {
1091 print_unknown_data(tptr,"\n\t ", tlv_len);
1094 tlen -= tlv_len;
1095 tptr += tlv_len;
1097 return;
1098 trunc:
1099 printf("\n\t[|LLDP]");
1103 * Local Variables:
1104 * c-style: whitesmith
1105 * c-basic-offset: 4
1106 * End: