xref: /freebsd/contrib/tcpdump/print-lldp.c (revision b0b1dbdd)
1 /*
2  * Copyright (c) 1998-2007 The TCPDUMP project
3  *
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.
14  *
15  * Original code by Hannes Gredler (hannes@juniper.net)
16  * IEEE and TIA extensions by Carles Kishimoto <carles.kishimoto@gmail.com>
17  * DCBX extensions by Kaladhar Musunuru <kaladharm@sourceforge.net>
18  */
19 
20 /* \summary: IEEE 802.1ab Link Layer Discovery Protocol (LLDP) printer */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include <netdissect-stdinc.h>
27 
28 #include <stdio.h>
29 
30 #include "netdissect.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33 #include "af.h"
34 #include "oui.h"
35 
36 #define	LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
37 #define	LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
38 
39 /*
40  * TLV type codes
41  */
42 #define LLDP_END_TLV             0
43 #define LLDP_CHASSIS_ID_TLV      1
44 #define LLDP_PORT_ID_TLV         2
45 #define LLDP_TTL_TLV             3
46 #define LLDP_PORT_DESCR_TLV      4
47 #define LLDP_SYSTEM_NAME_TLV     5
48 #define LLDP_SYSTEM_DESCR_TLV    6
49 #define LLDP_SYSTEM_CAP_TLV      7
50 #define LLDP_MGMT_ADDR_TLV       8
51 #define LLDP_PRIVATE_TLV       127
52 
53 static const struct tok lldp_tlv_values[] = {
54     { LLDP_END_TLV, "End" },
55     { LLDP_CHASSIS_ID_TLV, "Chassis ID" },
56     { LLDP_PORT_ID_TLV, "Port ID" },
57     { LLDP_TTL_TLV, "Time to Live" },
58     { LLDP_PORT_DESCR_TLV, "Port Description" },
59     { LLDP_SYSTEM_NAME_TLV, "System Name" },
60     { LLDP_SYSTEM_DESCR_TLV, "System Description" },
61     { LLDP_SYSTEM_CAP_TLV, "System Capabilities" },
62     { LLDP_MGMT_ADDR_TLV, "Management Address" },
63     { LLDP_PRIVATE_TLV, "Organization specific" },
64     { 0, NULL}
65 };
66 
67 /*
68  * Chassis ID subtypes
69  */
70 #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE  1
71 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE    2
72 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE     3
73 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE      4
74 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE  5
75 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE     6
76 #define LLDP_CHASSIS_LOCAL_SUBTYPE         7
77 
78 static const struct tok lldp_chassis_subtype_values[] = {
79     { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE, "Chassis component"},
80     { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE, "Interface alias"},
81     { LLDP_CHASSIS_PORT_COMP_SUBTYPE, "Port component"},
82     { LLDP_CHASSIS_MAC_ADDR_SUBTYPE, "MAC address"},
83     { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE, "Network address"},
84     { LLDP_CHASSIS_INTF_NAME_SUBTYPE, "Interface name"},
85     { LLDP_CHASSIS_LOCAL_SUBTYPE, "Local"},
86     { 0, NULL}
87 };
88 
89 /*
90  * Port ID subtypes
91  */
92 #define LLDP_PORT_INTF_ALIAS_SUBTYPE       1
93 #define LLDP_PORT_PORT_COMP_SUBTYPE        2
94 #define LLDP_PORT_MAC_ADDR_SUBTYPE         3
95 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE     4
96 #define LLDP_PORT_INTF_NAME_SUBTYPE        5
97 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE    6
98 #define LLDP_PORT_LOCAL_SUBTYPE            7
99 
100 static const struct tok lldp_port_subtype_values[] = {
101     { LLDP_PORT_INTF_ALIAS_SUBTYPE, "Interface alias"},
102     { LLDP_PORT_PORT_COMP_SUBTYPE, "Port component"},
103     { LLDP_PORT_MAC_ADDR_SUBTYPE, "MAC address"},
104     { LLDP_PORT_NETWORK_ADDR_SUBTYPE, "Network Address"},
105     { LLDP_PORT_INTF_NAME_SUBTYPE, "Interface Name"},
106     { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE, "Agent circuit ID"},
107     { LLDP_PORT_LOCAL_SUBTYPE, "Local"},
108     { 0, NULL}
109 };
110 
111 /*
112  * System Capabilities
113  */
114 #define LLDP_CAP_OTHER              (1 <<  0)
115 #define LLDP_CAP_REPEATER           (1 <<  1)
116 #define LLDP_CAP_BRIDGE             (1 <<  2)
117 #define LLDP_CAP_WLAN_AP            (1 <<  3)
118 #define LLDP_CAP_ROUTER             (1 <<  4)
119 #define LLDP_CAP_PHONE              (1 <<  5)
120 #define LLDP_CAP_DOCSIS             (1 <<  6)
121 #define LLDP_CAP_STATION_ONLY       (1 <<  7)
122 
123 static const struct tok lldp_cap_values[] = {
124     { LLDP_CAP_OTHER, "Other"},
125     { LLDP_CAP_REPEATER, "Repeater"},
126     { LLDP_CAP_BRIDGE, "Bridge"},
127     { LLDP_CAP_WLAN_AP, "WLAN AP"},
128     { LLDP_CAP_ROUTER, "Router"},
129     { LLDP_CAP_PHONE, "Telephone"},
130     { LLDP_CAP_DOCSIS, "Docsis"},
131     { LLDP_CAP_STATION_ONLY, "Station Only"},
132     { 0, NULL}
133 };
134 
135 #define LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID		1
136 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID	2
137 #define LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME		3
138 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY	4
139 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION 8
140 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION       9
141 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION     10
142 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION      11
143 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY   12
144 #define LLDP_PRIVATE_8021_SUBTYPE_EVB                    13
145 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP 			 14
146 
147 static const struct tok lldp_8021_subtype_values[] = {
148     { LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID, "Port VLAN Id"},
149     { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID, "Port and Protocol VLAN ID"},
150     { LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME, "VLAN name"},
151     { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY, "Protocol Identity"},
152     { LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION, "Congestion Notification"},
153     { LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION, "ETS Configuration"},
154     { LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION, "ETS Recommendation"},
155     { LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION, "Priority Flow Control Configuration"},
156     { LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY, "Application Priority"},
157     { LLDP_PRIVATE_8021_SUBTYPE_EVB, "EVB"},
158     { LLDP_PRIVATE_8021_SUBTYPE_CDCP,"CDCP"},
159     { 0, NULL}
160 };
161 
162 #define LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT       (1 <<  1)
163 #define LLDP_8021_PORT_PROTOCOL_VLAN_STATUS        (1 <<  2)
164 
165 static const struct tok lldp_8021_port_protocol_id_values[] = {
166     { LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT, "supported"},
167     { LLDP_8021_PORT_PROTOCOL_VLAN_STATUS, "enabled"},
168     { 0, NULL}
169 };
170 
171 #define LLDP_PRIVATE_8023_SUBTYPE_MACPHY        1
172 #define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER      2
173 #define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR      3
174 #define LLDP_PRIVATE_8023_SUBTYPE_MTU           4
175 
176 static const struct tok lldp_8023_subtype_values[] = {
177     { LLDP_PRIVATE_8023_SUBTYPE_MACPHY,	"MAC/PHY configuration/status"},
178     { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"},
179     { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"},
180     { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"},
181     { 0, NULL}
182 };
183 
184 #define LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES                   1
185 #define LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY                 2
186 #define LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID                       3
187 #define LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI             4
188 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV         5
189 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV         6
190 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV         7
191 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER        8
192 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME    9
193 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME           10
194 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID             11
195 
196 static const struct tok lldp_tia_subtype_values[] = {
197     { LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES, "LLDP-MED Capabilities" },
198     { LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY, "Network policy" },
199     { LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID, "Location identification" },
200     { LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI, "Extended power-via-MDI" },
201     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Inventory - hardware revision" },
202     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Inventory - firmware revision" },
203     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Inventory - software revision" },
204     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Inventory - serial number" },
205     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Inventory - manufacturer name" },
206     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Inventory - model name" },
207     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Inventory - asset ID" },
208     { 0, NULL}
209 };
210 
211 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS       1
212 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS       2
213 
214 static const struct tok lldp_tia_location_altitude_type_values[] = {
215     { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"},
216     { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"},
217     { 0, NULL}
218 };
219 
220 /* ANSI/TIA-1057 - Annex B */
221 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1		1
222 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2		2
223 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3		3
224 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4		4
225 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5		5
226 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6		6
227 
228 static const struct tok lldp_tia_location_lci_catype_values[] = {
229     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"},
230     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"},
231     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"},
232     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"},
233     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"},
234     { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"},
235     { 0, NULL}
236 };
237 
238 static const struct tok lldp_tia_location_lci_what_values[] = {
239     { 0, "location of DHCP server"},
240     { 1, "location of the network element believed to be closest to the client"},
241     { 2, "location of the client"},
242     { 0, NULL}
243 };
244 
245 /*
246  * From RFC 3636 - dot3MauType
247  */
248 #define		LLDP_MAU_TYPE_UNKNOWN		0
249 #define		LLDP_MAU_TYPE_AUI		1
250 #define		LLDP_MAU_TYPE_10BASE_5		2
251 #define		LLDP_MAU_TYPE_FOIRL		3
252 #define		LLDP_MAU_TYPE_10BASE_2		4
253 #define		LLDP_MAU_TYPE_10BASE_T		5
254 #define		LLDP_MAU_TYPE_10BASE_FP		6
255 #define		LLDP_MAU_TYPE_10BASE_FB		7
256 #define		LLDP_MAU_TYPE_10BASE_FL		8
257 #define		LLDP_MAU_TYPE_10BROAD36		9
258 #define		LLDP_MAU_TYPE_10BASE_T_HD	10
259 #define		LLDP_MAU_TYPE_10BASE_T_FD	11
260 #define		LLDP_MAU_TYPE_10BASE_FL_HD	12
261 #define		LLDP_MAU_TYPE_10BASE_FL_FD	13
262 #define		LLDP_MAU_TYPE_100BASE_T4	14
263 #define		LLDP_MAU_TYPE_100BASE_TX_HD	15
264 #define		LLDP_MAU_TYPE_100BASE_TX_FD	16
265 #define		LLDP_MAU_TYPE_100BASE_FX_HD	17
266 #define		LLDP_MAU_TYPE_100BASE_FX_FD	18
267 #define		LLDP_MAU_TYPE_100BASE_T2_HD	19
268 #define		LLDP_MAU_TYPE_100BASE_T2_FD	20
269 #define		LLDP_MAU_TYPE_1000BASE_X_HD	21
270 #define		LLDP_MAU_TYPE_1000BASE_X_FD	22
271 #define		LLDP_MAU_TYPE_1000BASE_LX_HD	23
272 #define		LLDP_MAU_TYPE_1000BASE_LX_FD	24
273 #define		LLDP_MAU_TYPE_1000BASE_SX_HD	25
274 #define		LLDP_MAU_TYPE_1000BASE_SX_FD	26
275 #define		LLDP_MAU_TYPE_1000BASE_CX_HD	27
276 #define		LLDP_MAU_TYPE_1000BASE_CX_FD	28
277 #define		LLDP_MAU_TYPE_1000BASE_T_HD	29
278 #define		LLDP_MAU_TYPE_1000BASE_T_FD	30
279 #define		LLDP_MAU_TYPE_10GBASE_X		31
280 #define		LLDP_MAU_TYPE_10GBASE_LX4	32
281 #define		LLDP_MAU_TYPE_10GBASE_R		33
282 #define		LLDP_MAU_TYPE_10GBASE_ER	34
283 #define		LLDP_MAU_TYPE_10GBASE_LR	35
284 #define		LLDP_MAU_TYPE_10GBASE_SR	36
285 #define		LLDP_MAU_TYPE_10GBASE_W		37
286 #define		LLDP_MAU_TYPE_10GBASE_EW	38
287 #define		LLDP_MAU_TYPE_10GBASE_LW	39
288 #define		LLDP_MAU_TYPE_10GBASE_SW	40
289 
290 static const struct tok lldp_mau_types_values[] = {
291     { LLDP_MAU_TYPE_UNKNOWN,            "Unknown"},
292     { LLDP_MAU_TYPE_AUI,                "AUI"},
293     { LLDP_MAU_TYPE_10BASE_5,           "10BASE_5"},
294     { LLDP_MAU_TYPE_FOIRL,              "FOIRL"},
295     { LLDP_MAU_TYPE_10BASE_2,           "10BASE2"},
296     { LLDP_MAU_TYPE_10BASE_T,           "10BASET duplex mode unknown"},
297     { LLDP_MAU_TYPE_10BASE_FP,          "10BASEFP"},
298     { LLDP_MAU_TYPE_10BASE_FB,          "10BASEFB"},
299     { LLDP_MAU_TYPE_10BASE_FL,          "10BASEFL duplex mode unknown"},
300     { LLDP_MAU_TYPE_10BROAD36,          "10BROAD36"},
301     { LLDP_MAU_TYPE_10BASE_T_HD,        "10BASET hdx"},
302     { LLDP_MAU_TYPE_10BASE_T_FD,        "10BASET fdx"},
303     { LLDP_MAU_TYPE_10BASE_FL_HD,       "10BASEFL hdx"},
304     { LLDP_MAU_TYPE_10BASE_FL_FD,       "10BASEFL fdx"},
305     { LLDP_MAU_TYPE_100BASE_T4,         "100BASET4"},
306     { LLDP_MAU_TYPE_100BASE_TX_HD,      "100BASETX hdx"},
307     { LLDP_MAU_TYPE_100BASE_TX_FD,      "100BASETX fdx"},
308     { LLDP_MAU_TYPE_100BASE_FX_HD,      "100BASEFX hdx"},
309     { LLDP_MAU_TYPE_100BASE_FX_FD,      "100BASEFX fdx"},
310     { LLDP_MAU_TYPE_100BASE_T2_HD,      "100BASET2 hdx"},
311     { LLDP_MAU_TYPE_100BASE_T2_FD,      "100BASET2 fdx"},
312     { LLDP_MAU_TYPE_1000BASE_X_HD,      "1000BASEX hdx"},
313     { LLDP_MAU_TYPE_1000BASE_X_FD,      "1000BASEX fdx"},
314     { LLDP_MAU_TYPE_1000BASE_LX_HD,     "1000BASELX hdx"},
315     { LLDP_MAU_TYPE_1000BASE_LX_FD,     "1000BASELX fdx"},
316     { LLDP_MAU_TYPE_1000BASE_SX_HD,     "1000BASESX hdx"},
317     { LLDP_MAU_TYPE_1000BASE_SX_FD,     "1000BASESX fdx"},
318     { LLDP_MAU_TYPE_1000BASE_CX_HD,     "1000BASECX hdx"},
319     { LLDP_MAU_TYPE_1000BASE_CX_FD,     "1000BASECX fdx"},
320     { LLDP_MAU_TYPE_1000BASE_T_HD,      "1000BASET hdx"},
321     { LLDP_MAU_TYPE_1000BASE_T_FD,      "1000BASET fdx"},
322     { LLDP_MAU_TYPE_10GBASE_X,          "10GBASEX"},
323     { LLDP_MAU_TYPE_10GBASE_LX4,        "10GBASELX4"},
324     { LLDP_MAU_TYPE_10GBASE_R,          "10GBASER"},
325     { LLDP_MAU_TYPE_10GBASE_ER,         "10GBASEER"},
326     { LLDP_MAU_TYPE_10GBASE_LR,         "10GBASELR"},
327     { LLDP_MAU_TYPE_10GBASE_SR,         "10GBASESR"},
328     { LLDP_MAU_TYPE_10GBASE_W,          "10GBASEW"},
329     { LLDP_MAU_TYPE_10GBASE_EW,         "10GBASEEW"},
330     { LLDP_MAU_TYPE_10GBASE_LW,         "10GBASELW"},
331     { LLDP_MAU_TYPE_10GBASE_SW,         "10GBASESW"},
332     { 0, NULL}
333 };
334 
335 #define LLDP_8023_AUTONEGOTIATION_SUPPORT       (1 <<  0)
336 #define LLDP_8023_AUTONEGOTIATION_STATUS        (1 <<  1)
337 
338 static const struct tok lldp_8023_autonegotiation_values[] = {
339     { LLDP_8023_AUTONEGOTIATION_SUPPORT, "supported"},
340     { LLDP_8023_AUTONEGOTIATION_STATUS, "enabled"},
341     { 0, NULL}
342 };
343 
344 #define LLDP_TIA_CAPABILITY_MED                         (1 <<  0)
345 #define LLDP_TIA_CAPABILITY_NETWORK_POLICY              (1 <<  1)
346 #define LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION     (1 <<  2)
347 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE      (1 <<  3)
348 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD       (1 <<  4)
349 #define LLDP_TIA_CAPABILITY_INVENTORY                   (1 <<  5)
350 
351 static const struct tok lldp_tia_capabilities_values[] = {
352     { LLDP_TIA_CAPABILITY_MED, "LLDP-MED capabilities"},
353     { LLDP_TIA_CAPABILITY_NETWORK_POLICY, "network policy"},
354     { LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION, "location identification"},
355     { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE, "extended power via MDI-PSE"},
356     { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD, "extended power via MDI-PD"},
357     { LLDP_TIA_CAPABILITY_INVENTORY, "Inventory"},
358     { 0, NULL}
359 };
360 
361 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1           1
362 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2           2
363 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3           3
364 #define LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY       4
365 
366 static const struct tok lldp_tia_device_type_values[] = {
367     { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1, "endpoint class 1"},
368     { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2, "endpoint class 2"},
369     { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3, "endpoint class 3"},
370     { LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY, "network connectivity"},
371     { 0, NULL}
372 };
373 
374 #define LLDP_TIA_APPLICATION_TYPE_VOICE                 1
375 #define LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING       2
376 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE           3
377 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING 4
378 #define LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE       5
379 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING    6
380 #define LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO       7
381 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING       8
382 
383 static const struct tok lldp_tia_application_type_values[] = {
384     { LLDP_TIA_APPLICATION_TYPE_VOICE, "voice"},
385     { LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING, "voice signaling"},
386     { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE, "guest voice"},
387     { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING, "guest voice signaling"},
388     { LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE, "softphone voice"},
389     { LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING, "video conferencing"},
390     { LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO, "streaming video"},
391     { LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING, "video signaling"},
392     { 0, NULL}
393 };
394 
395 #define LLDP_TIA_NETWORK_POLICY_X_BIT           (1 << 5)
396 #define LLDP_TIA_NETWORK_POLICY_T_BIT           (1 << 6)
397 #define LLDP_TIA_NETWORK_POLICY_U_BIT           (1 << 7)
398 
399 static const struct tok lldp_tia_network_policy_bits_values[] = {
400     { LLDP_TIA_NETWORK_POLICY_U_BIT, "Unknown"},
401     { LLDP_TIA_NETWORK_POLICY_T_BIT, "Tagged"},
402     { LLDP_TIA_NETWORK_POLICY_X_BIT, "reserved"},
403     { 0, NULL}
404 };
405 
406 #define LLDP_EXTRACT_NETWORK_POLICY_VLAN(x)           (((x)&0x1ffe)>>1)
407 #define LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(x)    (((x)&0x01ff)>>6)
408 #define LLDP_EXTRACT_NETWORK_POLICY_DSCP(x)           ((x)&0x003f)
409 
410 #define LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED  1
411 #define LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS     2
412 #define LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN          3
413 
414 static const struct tok lldp_tia_location_data_format_values[] = {
415     { LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED, "coordinate-based LCI"},
416     { LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS, "civic address LCI"},
417     { LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN, "ECS ELIN"},
418     { 0, NULL}
419 };
420 
421 #define LLDP_TIA_LOCATION_DATUM_WGS_84          1
422 #define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88  2
423 #define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW     3
424 
425 static const struct tok lldp_tia_location_datum_type_values[] = {
426     { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"},
427     { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"},
428     { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"},
429     { 0, NULL}
430 };
431 
432 #define LLDP_TIA_POWER_SOURCE_PSE               1
433 #define LLDP_TIA_POWER_SOURCE_LOCAL             2
434 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL     3
435 
436 static const struct tok lldp_tia_power_source_values[] = {
437     { LLDP_TIA_POWER_SOURCE_PSE, "PSE - primary power source"},
438     { LLDP_TIA_POWER_SOURCE_LOCAL, "local - backup power source"},
439     { LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL, "PSE+local - reserved"},
440     { 0, NULL}
441 };
442 
443 #define LLDP_TIA_POWER_PRIORITY_CRITICAL        1
444 #define LLDP_TIA_POWER_PRIORITY_HIGH            2
445 #define LLDP_TIA_POWER_PRIORITY_LOW             3
446 
447 static const struct tok lldp_tia_power_priority_values[] = {
448     { LLDP_TIA_POWER_PRIORITY_CRITICAL, "critical"},
449     { LLDP_TIA_POWER_PRIORITY_HIGH, "high"},
450     { LLDP_TIA_POWER_PRIORITY_LOW, "low"},
451     { 0, NULL}
452 };
453 
454 #define LLDP_TIA_POWER_VAL_MAX               1024
455 
456 static const struct tok lldp_tia_inventory_values[] = {
457     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Hardware revision" },
458     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Firmware revision" },
459     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Software revision" },
460     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Serial number" },
461     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Manufacturer name" },
462     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Model name" },
463     { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Asset ID" },
464     { 0, NULL}
465 };
466 
467 /*
468  * From RFC 3636 - ifMauAutoNegCapAdvertisedBits
469  */
470 #define	 LLDP_MAU_PMD_OTHER			(1 <<  15)
471 #define	 LLDP_MAU_PMD_10BASE_T			(1 <<  14)
472 #define	 LLDP_MAU_PMD_10BASE_T_FD		(1 <<  13)
473 #define	 LLDP_MAU_PMD_100BASE_T4		(1 <<  12)
474 #define	 LLDP_MAU_PMD_100BASE_TX		(1 <<  11)
475 #define	 LLDP_MAU_PMD_100BASE_TX_FD		(1 <<  10)
476 #define	 LLDP_MAU_PMD_100BASE_T2		(1 <<  9)
477 #define	 LLDP_MAU_PMD_100BASE_T2_FD		(1 <<  8)
478 #define	 LLDP_MAU_PMD_FDXPAUSE			(1 <<  7)
479 #define	 LLDP_MAU_PMD_FDXAPAUSE			(1 <<  6)
480 #define	 LLDP_MAU_PMD_FDXSPAUSE			(1 <<  5)
481 #define	 LLDP_MAU_PMD_FDXBPAUSE			(1 <<  4)
482 #define	 LLDP_MAU_PMD_1000BASE_X		(1 <<  3)
483 #define	 LLDP_MAU_PMD_1000BASE_X_FD		(1 <<  2)
484 #define	 LLDP_MAU_PMD_1000BASE_T		(1 <<  1)
485 #define	 LLDP_MAU_PMD_1000BASE_T_FD		(1 <<  0)
486 
487 static const struct tok lldp_pmd_capability_values[] = {
488     { LLDP_MAU_PMD_10BASE_T,		"10BASE-T hdx"},
489     { LLDP_MAU_PMD_10BASE_T_FD,	        "10BASE-T fdx"},
490     { LLDP_MAU_PMD_100BASE_T4,		"100BASE-T4"},
491     { LLDP_MAU_PMD_100BASE_TX,		"100BASE-TX hdx"},
492     { LLDP_MAU_PMD_100BASE_TX_FD,	"100BASE-TX fdx"},
493     { LLDP_MAU_PMD_100BASE_T2,		"100BASE-T2 hdx"},
494     { LLDP_MAU_PMD_100BASE_T2_FD,	"100BASE-T2 fdx"},
495     { LLDP_MAU_PMD_FDXPAUSE,		"Pause for fdx links"},
496     { LLDP_MAU_PMD_FDXAPAUSE,		"Asym PAUSE for fdx"},
497     { LLDP_MAU_PMD_FDXSPAUSE,		"Sym PAUSE for fdx"},
498     { LLDP_MAU_PMD_FDXBPAUSE,		"Asym and Sym PAUSE for fdx"},
499     { LLDP_MAU_PMD_1000BASE_X,		"1000BASE-{X LX SX CX} hdx"},
500     { LLDP_MAU_PMD_1000BASE_X_FD,	"1000BASE-{X LX SX CX} fdx"},
501     { LLDP_MAU_PMD_1000BASE_T,		"1000BASE-T hdx"},
502     { LLDP_MAU_PMD_1000BASE_T_FD,	"1000BASE-T fdx"},
503     { 0, NULL}
504 };
505 
506 #define	LLDP_MDI_PORT_CLASS			(1 <<  0)
507 #define	LLDP_MDI_POWER_SUPPORT			(1 <<  1)
508 #define LLDP_MDI_POWER_STATE			(1 <<  2)
509 #define LLDP_MDI_PAIR_CONTROL_ABILITY		(1 <<  3)
510 
511 static const struct tok lldp_mdi_values[] = {
512     { LLDP_MDI_PORT_CLASS, 		"PSE"},
513     { LLDP_MDI_POWER_SUPPORT, 		"supported"},
514     { LLDP_MDI_POWER_STATE, 		"enabled"},
515     { LLDP_MDI_PAIR_CONTROL_ABILITY, 	"can be controlled"},
516     { 0, NULL}
517 };
518 
519 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL	1
520 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE	2
521 
522 static const struct tok lldp_mdi_power_pairs_values[] = {
523     { LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL,	"signal"},
524     { LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE,	"spare"},
525     { 0, NULL}
526 };
527 
528 #define LLDP_MDI_POWER_CLASS0		1
529 #define LLDP_MDI_POWER_CLASS1		2
530 #define LLDP_MDI_POWER_CLASS2		3
531 #define LLDP_MDI_POWER_CLASS3		4
532 #define LLDP_MDI_POWER_CLASS4		5
533 
534 static const struct tok lldp_mdi_power_class_values[] = {
535     { LLDP_MDI_POWER_CLASS0,     "class0"},
536     { LLDP_MDI_POWER_CLASS1,     "class1"},
537     { LLDP_MDI_POWER_CLASS2,     "class2"},
538     { LLDP_MDI_POWER_CLASS3,     "class3"},
539     { LLDP_MDI_POWER_CLASS4,     "class4"},
540     { 0, NULL}
541 };
542 
543 #define LLDP_AGGREGATION_CAPABILTIY     (1 <<  0)
544 #define LLDP_AGGREGATION_STATUS         (1 <<  1)
545 
546 static const struct tok lldp_aggregation_values[] = {
547     { LLDP_AGGREGATION_CAPABILTIY, "supported"},
548     { LLDP_AGGREGATION_STATUS, "enabled"},
549     { 0, NULL}
550 };
551 
552 /*
553  * DCBX protocol subtypes.
554  */
555 #define LLDP_DCBX_SUBTYPE_1                1
556 #define LLDP_DCBX_SUBTYPE_2                2
557 
558 static const struct tok lldp_dcbx_subtype_values[] = {
559     { LLDP_DCBX_SUBTYPE_1, "DCB Capability Exchange Protocol Rev 1" },
560     { LLDP_DCBX_SUBTYPE_2, "DCB Capability Exchange Protocol Rev 1.01" },
561     { 0, NULL}
562 };
563 
564 #define LLDP_DCBX_CONTROL_TLV                1
565 #define LLDP_DCBX_PRIORITY_GROUPS_TLV        2
566 #define LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV  3
567 #define LLDP_DCBX_APPLICATION_TLV            4
568 
569 /*
570  * Interface numbering subtypes.
571  */
572 #define LLDP_INTF_NUMB_IFX_SUBTYPE         2
573 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE     3
574 
575 static const struct tok lldp_intf_numb_subtype_values[] = {
576     { LLDP_INTF_NUMB_IFX_SUBTYPE, "Interface Index" },
577     { LLDP_INTF_NUMB_SYSPORT_SUBTYPE, "System Port Number" },
578     { 0, NULL}
579 };
580 
581 #define LLDP_INTF_NUM_LEN                  5
582 
583 #define LLDP_EVB_MODE_NOT_SUPPORTED	0
584 #define LLDP_EVB_MODE_EVB_BRIDGE	1
585 #define LLDP_EVB_MODE_EVB_STATION	2
586 #define LLDP_EVB_MODE_RESERVED		3
587 
588 static const struct tok lldp_evb_mode_values[]={
589     { LLDP_EVB_MODE_NOT_SUPPORTED, "Not Supported"},
590     { LLDP_EVB_MODE_EVB_BRIDGE, "EVB Bridge"},
591     { LLDP_EVB_MODE_EVB_STATION, "EVB Staion"},
592     { LLDP_EVB_MODE_RESERVED, "Reserved for future Standardization"},
593 };
594 
595 #define NO_OF_BITS 8
596 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION_LENGTH  6
597 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION_LENGTH       25
598 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION_LENGTH      25
599 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION_LENGTH        6
600 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH 5
601 #define LLDP_PRIVATE_8021_SUBTYPE_EVB_LENGTH                      9
602 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP_MIN_LENGTH                 8
603 
604 #define LLDP_IANA_SUBTYPE_MUDURL 1
605 
606 static const struct tok lldp_iana_subtype_values[] =   {
607     { LLDP_IANA_SUBTYPE_MUDURL, "MUD-URL" },
608     { 0, NULL }
609 };
610 
611 
612 static void
613 print_ets_priority_assignment_table(netdissect_options *ndo,
614                                     const u_char *ptr)
615 {
616     ND_PRINT((ndo, "\n\t    Priority Assignment Table"));
617     ND_PRINT((ndo, "\n\t     Priority : 0   1   2   3   4   5   6   7"));
618     ND_PRINT((ndo, "\n\t     Value    : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
619             ptr[0]>>4,ptr[0]&0x0f,ptr[1]>>4,ptr[1]&0x0f,ptr[2]>>4,
620             ptr[2] & 0x0f, ptr[3] >> 4, ptr[3] & 0x0f));
621 }
622 
623 static void
624 print_tc_bandwidth_table(netdissect_options *ndo,
625                          const u_char *ptr)
626 {
627     ND_PRINT((ndo, "\n\t    TC Bandwidth Table"));
628     ND_PRINT((ndo, "\n\t     TC%%   : 0   1   2   3   4   5   6   7"));
629     ND_PRINT((ndo, "\n\t     Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
630              ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]));
631 }
632 
633 static void
634 print_tsa_assignment_table(netdissect_options *ndo,
635                            const u_char *ptr)
636 {
637     ND_PRINT((ndo, "\n\t    TSA Assignment Table"));
638     ND_PRINT((ndo, "\n\t     Traffic Class: 0   1   2   3   4   5   6   7"));
639     ND_PRINT((ndo, "\n\t     Value        : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
640              ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]));
641 }
642 
643 /*
644  * Print IEEE 802.1 private extensions. (802.1AB annex E)
645  */
646 static int
647 lldp_private_8021_print(netdissect_options *ndo,
648                         const u_char *tptr, u_int tlv_len)
649 {
650     int subtype, hexdump = FALSE;
651     u_int sublen;
652     u_int tval;
653     uint8_t i;
654 
655     if (tlv_len < 4) {
656         return hexdump;
657     }
658     subtype = *(tptr+3);
659 
660     ND_PRINT((ndo, "\n\t  %s Subtype (%u)",
661            tok2str(lldp_8021_subtype_values, "unknown", subtype),
662            subtype));
663 
664     switch (subtype) {
665     case LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID:
666         if (tlv_len < 6) {
667             return hexdump;
668         }
669         ND_PRINT((ndo, "\n\t    port vlan id (PVID): %u",
670                EXTRACT_16BITS(tptr + 4)));
671         break;
672     case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID:
673         if (tlv_len < 7) {
674             return hexdump;
675         }
676         ND_PRINT((ndo, "\n\t    port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)",
677                EXTRACT_16BITS(tptr+5),
678 	       bittok2str(lldp_8021_port_protocol_id_values, "none", *(tptr+4)),
679 	       *(tptr + 4)));
680         break;
681     case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME:
682         if (tlv_len < 6) {
683             return hexdump;
684         }
685         ND_PRINT((ndo, "\n\t    vlan id (VID): %u", EXTRACT_16BITS(tptr + 4)));
686         if (tlv_len < 7) {
687             return hexdump;
688         }
689         sublen = *(tptr+6);
690         if (tlv_len < 7+sublen) {
691             return hexdump;
692         }
693         ND_PRINT((ndo, "\n\t    vlan name: "));
694         safeputs(ndo, tptr + 7, sublen);
695         break;
696     case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY:
697         if (tlv_len < 5) {
698             return hexdump;
699         }
700         sublen = *(tptr+4);
701         if (tlv_len < 5+sublen) {
702             return hexdump;
703         }
704         ND_PRINT((ndo, "\n\t    protocol identity: "));
705         safeputs(ndo, tptr + 5, sublen);
706         break;
707     case LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION:
708         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION_LENGTH){
709         	return hexdump;
710         }
711         tval=*(tptr+4);
712         ND_PRINT((ndo, "\n\t    Pre-Priority CNPV Indicator"));
713         ND_PRINT((ndo, "\n\t     Priority : 0  1  2  3  4  5  6  7"));
714         ND_PRINT((ndo, "\n\t     Value    : "));
715         for(i=0;i<NO_OF_BITS;i++)
716             ND_PRINT((ndo, "%-2d ", (tval >> i) & 0x01));
717         tval=*(tptr+5);
718         ND_PRINT((ndo, "\n\t    Pre-Priority Ready Indicator"));
719         ND_PRINT((ndo, "\n\t     Priority : 0  1  2  3  4  5  6  7"));
720         ND_PRINT((ndo, "\n\t     Value    : "));
721         for(i=0;i<NO_OF_BITS;i++)
722             ND_PRINT((ndo, "%-2d ", (tval >> i) & 0x01));
723         break;
724 
725     case LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION:
726         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION_LENGTH) {
727             return hexdump;
728         }
729         tval=*(tptr+4);
730         ND_PRINT((ndo, "\n\t    Willing:%d, CBS:%d, RES:%d, Max TCs:%d",
731         	tval >> 7, (tval >> 6) & 0x02, (tval >> 3) & 0x07, tval & 0x07));
732 
733         /*Print Priority Assignment Table*/
734         print_ets_priority_assignment_table(ndo, tptr + 5);
735 
736         /*Print TC Bandwidth Table*/
737         print_tc_bandwidth_table(ndo, tptr + 9);
738 
739         /* Print TSA Assignment Table */
740         print_tsa_assignment_table(ndo, tptr + 17);
741 
742         break;
743 
744     case LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION:
745         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION_LENGTH) {
746         	return hexdump;
747         }
748         ND_PRINT((ndo, "\n\t    RES: %d", *(tptr + 4)));
749         /*Print Priority Assignment Table */
750         print_ets_priority_assignment_table(ndo, tptr + 5);
751         /*Print TC Bandwidth Table */
752         print_tc_bandwidth_table(ndo, tptr + 9);
753         /* Print TSA Assignment Table */
754         print_tsa_assignment_table(ndo, tptr + 17);
755         break;
756 
757     case LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION:
758         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION_LENGTH) {
759             return hexdump;
760         }
761         tval=*(tptr+4);
762         ND_PRINT((ndo, "\n\t    Willing: %d, MBC: %d, RES: %d, PFC cap:%d ",
763         	tval >> 7, (tval >> 6) & 0x01, (tval >> 4) & 0x03, (tval & 0x0f)));
764         ND_PRINT((ndo, "\n\t    PFC Enable"));
765         tval=*(tptr+5);
766         ND_PRINT((ndo, "\n\t     Priority : 0  1  2  3  4  5  6  7"));
767         ND_PRINT((ndo, "\n\t     Value    : "));
768         for(i=0;i<NO_OF_BITS;i++)
769             ND_PRINT((ndo, "%-2d ", (tval >> i) & 0x01));
770         break;
771 
772     case LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY:
773         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH) {
774             return hexdump;
775         }
776         ND_PRINT((ndo, "\n\t    RES: %d", *(tptr + 4)));
777         if(tlv_len<=LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH){
778         	return hexdump;
779         }
780         /*  Length of Application Priority Table */
781         sublen=tlv_len-5;
782         if(sublen%3!=0){
783         	return hexdump;
784         }
785         i=0;
786         ND_PRINT((ndo, "\n\t    Application Priority Table"));
787         while(i<sublen) {
788         	tval=*(tptr+i+5);
789         	ND_PRINT((ndo, "\n\t      Priority: %d, RES: %d, Sel: %d",
790         		 tval >> 5, (tval >> 3) & 0x03, (tval & 0x07)));
791         	ND_PRINT((ndo, "Protocol ID: %d", EXTRACT_16BITS(tptr + i + 5)));
792         	i=i+3;
793         }
794         break;
795     case LLDP_PRIVATE_8021_SUBTYPE_EVB:
796         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_EVB_LENGTH){
797         	return hexdump;
798         }
799         ND_PRINT((ndo, "\n\t    EVB Bridge Status"));
800         tval=*(tptr+4);
801         ND_PRINT((ndo, "\n\t      RES: %d, BGID: %d, RRCAP: %d, RRCTR: %d",
802         	tval >> 3, (tval >> 2) & 0x01, (tval >> 1) & 0x01, tval & 0x01));
803         ND_PRINT((ndo, "\n\t    EVB Station Status"));
804         tval=*(tptr+5);
805         ND_PRINT((ndo, "\n\t      RES: %d, SGID: %d, RRREQ: %d,RRSTAT: %d",
806         	tval >> 4, (tval >> 3) & 0x01, (tval >> 2) & 0x01, tval & 0x03));
807         tval=*(tptr+6);
808         ND_PRINT((ndo, "\n\t    R: %d, RTE: %d, ",tval >> 5, tval & 0x1f));
809         tval=*(tptr+7);
810         ND_PRINT((ndo, "EVB Mode: %s [%d]",
811         	tok2str(lldp_evb_mode_values, "unknown", tval >> 6), tval >> 6));
812         ND_PRINT((ndo, "\n\t    ROL: %d, RWD: %d, ", (tval >> 5) & 0x01, tval & 0x1f));
813         tval=*(tptr+8);
814         ND_PRINT((ndo, "RES: %d, ROL: %d, RKA: %d", tval >> 6, (tval >> 5) & 0x01, tval & 0x1f));
815         break;
816 
817     case LLDP_PRIVATE_8021_SUBTYPE_CDCP:
818         if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_CDCP_MIN_LENGTH){
819         	return hexdump;
820         }
821         tval=*(tptr+4);
822         ND_PRINT((ndo, "\n\t    Role: %d, RES: %d, Scomp: %d ",
823         	tval >> 7, (tval >> 4) & 0x07, (tval >> 3) & 0x01));
824         ND_PRINT((ndo, "ChnCap: %d", EXTRACT_16BITS(tptr + 6) & 0x0fff));
825         sublen=tlv_len-8;
826         if(sublen%3!=0) {
827         	return hexdump;
828         }
829         i=0;
830         while(i<sublen) {
831         	tval=EXTRACT_24BITS(tptr+i+8);
832         	ND_PRINT((ndo, "\n\t    SCID: %d, SVID: %d",
833         		tval >> 12, tval & 0x000fff));
834         	i=i+3;
835         }
836         break;
837 
838     default:
839         hexdump = TRUE;
840         break;
841     }
842 
843     return hexdump;
844 }
845 
846 /*
847  * Print IEEE 802.3 private extensions. (802.3bc)
848  */
849 static int
850 lldp_private_8023_print(netdissect_options *ndo,
851                         const u_char *tptr, u_int tlv_len)
852 {
853     int subtype, hexdump = FALSE;
854 
855     if (tlv_len < 4) {
856         return hexdump;
857     }
858     subtype = *(tptr+3);
859 
860     ND_PRINT((ndo, "\n\t  %s Subtype (%u)",
861            tok2str(lldp_8023_subtype_values, "unknown", subtype),
862            subtype));
863 
864     switch (subtype) {
865     case LLDP_PRIVATE_8023_SUBTYPE_MACPHY:
866         if (tlv_len < 9) {
867             return hexdump;
868         }
869         ND_PRINT((ndo, "\n\t    autonegotiation [%s] (0x%02x)",
870                bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)),
871                *(tptr + 4)));
872         ND_PRINT((ndo, "\n\t    PMD autoneg capability [%s] (0x%04x)",
873                bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_16BITS(tptr+5)),
874                EXTRACT_16BITS(tptr + 5)));
875         ND_PRINT((ndo, "\n\t    MAU type %s (0x%04x)",
876                tok2str(lldp_mau_types_values, "unknown", EXTRACT_16BITS(tptr+7)),
877                EXTRACT_16BITS(tptr + 7)));
878         break;
879 
880     case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER:
881         if (tlv_len < 7) {
882             return hexdump;
883         }
884         ND_PRINT((ndo, "\n\t    MDI power support [%s], power pair %s, power class %s",
885                bittok2str(lldp_mdi_values, "none", *(tptr+4)),
886                tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)),
887                tok2str(lldp_mdi_power_class_values, "unknown", *(tptr + 6))));
888         break;
889 
890     case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR:
891         if (tlv_len < 9) {
892             return hexdump;
893         }
894         ND_PRINT((ndo, "\n\t    aggregation status [%s], aggregation port ID %u",
895                bittok2str(lldp_aggregation_values, "none", *(tptr+4)),
896                EXTRACT_32BITS(tptr + 5)));
897         break;
898 
899     case LLDP_PRIVATE_8023_SUBTYPE_MTU:
900         ND_PRINT((ndo, "\n\t    MTU size %u", EXTRACT_16BITS(tptr + 4)));
901         break;
902 
903     default:
904         hexdump = TRUE;
905         break;
906     }
907 
908     return hexdump;
909 }
910 
911 /*
912  * Extract 34bits of latitude/longitude coordinates.
913  */
914 static uint64_t
915 lldp_extract_latlon(const u_char *tptr)
916 {
917     uint64_t latlon;
918 
919     latlon = *tptr & 0x3;
920     latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1);
921 
922     return latlon;
923 }
924 
925 /* objects defined in IANA subtype 00 00 5e
926  * (right now there is only one)
927  */
928 
929 
930 static int
931 lldp_private_iana_print(netdissect_options *ndo,
932                         const u_char *tptr, u_int tlv_len)
933 {
934     int subtype, hexdump = FALSE;
935 
936     if (tlv_len < 8) {
937         return hexdump;
938     }
939     subtype = *(tptr+3);
940 
941     ND_PRINT((ndo, "\n\t  %s Subtype (%u)",
942            tok2str(lldp_iana_subtype_values, "unknown", subtype),
943            subtype));
944 
945     switch (subtype) {
946     case LLDP_IANA_SUBTYPE_MUDURL:
947         ND_PRINT((ndo, "\n\t  MUD-URL="));
948         (void)fn_printn(ndo, tptr+4, tlv_len-4, NULL);
949         break;
950     default:
951         hexdump=TRUE;
952     }
953 
954     return hexdump;
955 }
956 
957 
958 
959 /*
960  * Print private TIA extensions.
961  */
962 static int
963 lldp_private_tia_print(netdissect_options *ndo,
964                        const u_char *tptr, u_int tlv_len)
965 {
966     int subtype, hexdump = FALSE;
967     uint8_t location_format;
968     uint16_t power_val;
969     u_int lci_len;
970     uint8_t ca_type, ca_len;
971 
972     if (tlv_len < 4) {
973         return hexdump;
974     }
975     subtype = *(tptr+3);
976 
977     ND_PRINT((ndo, "\n\t  %s Subtype (%u)",
978            tok2str(lldp_tia_subtype_values, "unknown", subtype),
979            subtype));
980 
981     switch (subtype) {
982     case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES:
983         if (tlv_len < 7) {
984             return hexdump;
985         }
986         ND_PRINT((ndo, "\n\t    Media capabilities [%s] (0x%04x)",
987                bittok2str(lldp_tia_capabilities_values, "none",
988                           EXTRACT_16BITS(tptr + 4)), EXTRACT_16BITS(tptr + 4)));
989         ND_PRINT((ndo, "\n\t    Device type [%s] (0x%02x)",
990                tok2str(lldp_tia_device_type_values, "unknown", *(tptr+6)),
991                *(tptr + 6)));
992         break;
993 
994     case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY:
995         if (tlv_len < 8) {
996             return hexdump;
997         }
998         ND_PRINT((ndo, "\n\t    Application type [%s] (0x%02x)",
999                tok2str(lldp_tia_application_type_values, "none", *(tptr+4)),
1000                *(tptr + 4)));
1001         ND_PRINT((ndo, ", Flags [%s]", bittok2str(
1002                    lldp_tia_network_policy_bits_values, "none", *(tptr + 5))));
1003         ND_PRINT((ndo, "\n\t    Vlan id %u",
1004                LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr + 5))));
1005         ND_PRINT((ndo, ", L2 priority %u",
1006                LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr + 6))));
1007         ND_PRINT((ndo, ", DSCP value %u",
1008                LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr + 6))));
1009         break;
1010 
1011     case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID:
1012         if (tlv_len < 5) {
1013             return hexdump;
1014         }
1015         location_format = *(tptr+4);
1016         ND_PRINT((ndo, "\n\t    Location data format %s (0x%02x)",
1017                tok2str(lldp_tia_location_data_format_values, "unknown", location_format),
1018                location_format));
1019 
1020         switch (location_format) {
1021         case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED:
1022             if (tlv_len < 21) {
1023                 return hexdump;
1024             }
1025             ND_PRINT((ndo, "\n\t    Latitude resolution %u, latitude value %" PRIu64,
1026                    (*(tptr + 5) >> 2), lldp_extract_latlon(tptr + 5)));
1027             ND_PRINT((ndo, "\n\t    Longitude resolution %u, longitude value %" PRIu64,
1028                    (*(tptr + 10) >> 2), lldp_extract_latlon(tptr + 10)));
1029             ND_PRINT((ndo, "\n\t    Altitude type %s (%u)",
1030                    tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)),
1031                    (*(tptr + 15) >> 4)));
1032             ND_PRINT((ndo, "\n\t    Altitude resolution %u, altitude value 0x%x",
1033                    (EXTRACT_16BITS(tptr+15)>>6)&0x3f,
1034                    ((EXTRACT_32BITS(tptr + 16) & 0x3fffffff))));
1035             ND_PRINT((ndo, "\n\t    Datum %s (0x%02x)",
1036                    tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)),
1037                    *(tptr + 20)));
1038             break;
1039 
1040         case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS:
1041             if (tlv_len < 6) {
1042                 return hexdump;
1043             }
1044             lci_len = *(tptr+5);
1045             if (lci_len < 3) {
1046                 return hexdump;
1047             }
1048             if (tlv_len < 7+lci_len) {
1049                 return hexdump;
1050             }
1051             ND_PRINT((ndo, "\n\t    LCI length %u, LCI what %s (0x%02x), Country-code ",
1052                    lci_len,
1053                    tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)),
1054                    *(tptr + 6)));
1055 
1056             /* Country code */
1057             safeputs(ndo, tptr + 7, 2);
1058 
1059             lci_len = lci_len-3;
1060             tptr = tptr + 9;
1061 
1062             /* Decode each civic address element */
1063             while (lci_len > 0) {
1064                 if (lci_len < 2) {
1065                     return hexdump;
1066                 }
1067 		ca_type = *(tptr);
1068                 ca_len = *(tptr+1);
1069 
1070 		tptr += 2;
1071                 lci_len -= 2;
1072 
1073                 ND_PRINT((ndo, "\n\t      CA type \'%s\' (%u), length %u: ",
1074                        tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type),
1075                        ca_type, ca_len));
1076 
1077 		/* basic sanity check */
1078 		if ( ca_type == 0 || ca_len == 0) {
1079                     return hexdump;
1080 		}
1081 		if (lci_len < ca_len) {
1082 		    return hexdump;
1083 		}
1084 
1085                 safeputs(ndo, tptr, ca_len);
1086                 tptr += ca_len;
1087                 lci_len -= ca_len;
1088             }
1089             break;
1090 
1091         case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN:
1092             ND_PRINT((ndo, "\n\t    ECS ELIN id "));
1093             safeputs(ndo, tptr + 5, tlv_len - 5);
1094             break;
1095 
1096         default:
1097             ND_PRINT((ndo, "\n\t    Location ID "));
1098             print_unknown_data(ndo, tptr + 5, "\n\t      ", tlv_len - 5);
1099         }
1100         break;
1101 
1102     case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI:
1103         if (tlv_len < 7) {
1104             return hexdump;
1105         }
1106         ND_PRINT((ndo, "\n\t    Power type [%s]",
1107                (*(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device"));
1108         ND_PRINT((ndo, ", Power source [%s]",
1109                tok2str(lldp_tia_power_source_values, "none", (*(tptr + 4) & 0x30) >> 4)));
1110         ND_PRINT((ndo, "\n\t    Power priority [%s] (0x%02x)",
1111                tok2str(lldp_tia_power_priority_values, "none", *(tptr+4)&0x0f),
1112                *(tptr + 4) & 0x0f));
1113         power_val = EXTRACT_16BITS(tptr+5);
1114         if (power_val < LLDP_TIA_POWER_VAL_MAX) {
1115             ND_PRINT((ndo, ", Power %.1f Watts", ((float)power_val) / 10));
1116         } else {
1117             ND_PRINT((ndo, ", Power %u (Reserved)", power_val));
1118         }
1119         break;
1120 
1121     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV:
1122     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV:
1123     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV:
1124     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER:
1125     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME:
1126     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME:
1127     case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID:
1128         ND_PRINT((ndo, "\n\t  %s ",
1129                tok2str(lldp_tia_inventory_values, "unknown", subtype)));
1130         safeputs(ndo, tptr + 4, tlv_len - 4);
1131         break;
1132 
1133     default:
1134         hexdump = TRUE;
1135         break;
1136     }
1137 
1138     return hexdump;
1139 }
1140 
1141 /*
1142  * Print DCBX Protocol fields (V 1.01).
1143  */
1144 static int
1145 lldp_private_dcbx_print(netdissect_options *ndo,
1146                         const u_char *pptr, u_int len)
1147 {
1148     int subtype, hexdump = FALSE;
1149     uint8_t tval;
1150     uint16_t tlv;
1151     uint32_t i, pgval, uval;
1152     u_int tlen, tlv_type, tlv_len;
1153     const u_char *tptr, *mptr;
1154 
1155     if (len < 4) {
1156         return hexdump;
1157     }
1158     subtype = *(pptr+3);
1159 
1160     ND_PRINT((ndo, "\n\t  %s Subtype (%u)",
1161            tok2str(lldp_dcbx_subtype_values, "unknown", subtype),
1162            subtype));
1163 
1164     /* by passing old version */
1165     if (subtype == LLDP_DCBX_SUBTYPE_1)
1166 	return TRUE;
1167 
1168     tptr = pptr + 4;
1169     tlen = len - 4;
1170 
1171     while (tlen >= sizeof(tlv)) {
1172 
1173         ND_TCHECK2(*tptr, sizeof(tlv));
1174 
1175         tlv = EXTRACT_16BITS(tptr);
1176 
1177         tlv_type = LLDP_EXTRACT_TYPE(tlv);
1178         tlv_len = LLDP_EXTRACT_LEN(tlv);
1179         hexdump = FALSE;
1180 
1181         tlen -= sizeof(tlv);
1182         tptr += sizeof(tlv);
1183 
1184         /* loop check */
1185         if (!tlv_type || !tlv_len) {
1186             break;
1187         }
1188 
1189         ND_TCHECK2(*tptr, tlv_len);
1190         if (tlen < tlv_len) {
1191             goto trunc;
1192         }
1193 
1194 	/* decode every tlv */
1195         switch (tlv_type) {
1196         case LLDP_DCBX_CONTROL_TLV:
1197             if (tlv_len < 10) {
1198                 goto trunc;
1199             }
1200 	    ND_PRINT((ndo, "\n\t    Control - Protocol Control (type 0x%x, length %d)",
1201 		LLDP_DCBX_CONTROL_TLV, tlv_len));
1202 	    ND_PRINT((ndo, "\n\t      Oper_Version: %d", *tptr));
1203 	    ND_PRINT((ndo, "\n\t      Max_Version: %d", *(tptr + 1)));
1204 	    ND_PRINT((ndo, "\n\t      Sequence Number: %d", EXTRACT_32BITS(tptr + 2)));
1205 	    ND_PRINT((ndo, "\n\t      Acknowledgement Number: %d",
1206 					EXTRACT_32BITS(tptr + 6)));
1207 	    break;
1208         case LLDP_DCBX_PRIORITY_GROUPS_TLV:
1209             if (tlv_len < 17) {
1210                 goto trunc;
1211             }
1212 	    ND_PRINT((ndo, "\n\t    Feature - Priority Group (type 0x%x, length %d)",
1213 		LLDP_DCBX_PRIORITY_GROUPS_TLV, tlv_len));
1214 	    ND_PRINT((ndo, "\n\t      Oper_Version: %d", *tptr));
1215 	    ND_PRINT((ndo, "\n\t      Max_Version: %d", *(tptr + 1)));
1216 	    ND_PRINT((ndo, "\n\t      Info block(0x%02X): ", *(tptr + 2)));
1217 	    tval = *(tptr+2);
1218 	    ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d",
1219 		(tval &  0x80) ? 1 : 0, (tval &  0x40) ? 1 : 0,
1220 		(tval &  0x20) ? 1 : 0));
1221 	    ND_PRINT((ndo, "\n\t      SubType: %d", *(tptr + 3)));
1222 	    ND_PRINT((ndo, "\n\t      Priority Allocation"));
1223 
1224 	    /*
1225 	     * Array of 8 4-bit priority group ID values; we fetch all
1226 	     * 32 bits and extract each nibble.
1227 	     */
1228 	    pgval = EXTRACT_32BITS(tptr+4);
1229 	    for (i = 0; i <= 7; i++) {
1230 		ND_PRINT((ndo, "\n\t          PgId_%d: %d",
1231 			i, (pgval >> (28 - 4 * i)) & 0xF));
1232 	    }
1233 	    ND_PRINT((ndo, "\n\t      Priority Group Allocation"));
1234 	    for (i = 0; i <= 7; i++)
1235 		ND_PRINT((ndo, "\n\t          Pg percentage[%d]: %d", i, *(tptr + 8 + i)));
1236 	    ND_PRINT((ndo, "\n\t      NumTCsSupported: %d", *(tptr + 8 + 8)));
1237 	    break;
1238         case LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV:
1239             if (tlv_len < 6) {
1240                 goto trunc;
1241             }
1242 	    ND_PRINT((ndo, "\n\t    Feature - Priority Flow Control"));
1243 	    ND_PRINT((ndo, " (type 0x%x, length %d)",
1244 		LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV, tlv_len));
1245 	    ND_PRINT((ndo, "\n\t      Oper_Version: %d", *tptr));
1246 	    ND_PRINT((ndo, "\n\t      Max_Version: %d", *(tptr + 1)));
1247 	    ND_PRINT((ndo, "\n\t      Info block(0x%02X): ", *(tptr + 2)));
1248 	    tval = *(tptr+2);
1249 	    ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d",
1250 		(tval &  0x80) ? 1 : 0, (tval &  0x40) ? 1 : 0,
1251 		(tval &  0x20) ? 1 : 0));
1252 	    ND_PRINT((ndo, "\n\t      SubType: %d", *(tptr + 3)));
1253 	    tval = *(tptr+4);
1254 	    ND_PRINT((ndo, "\n\t      PFC Config (0x%02X)", *(tptr + 4)));
1255 	    for (i = 0; i <= 7; i++)
1256 		ND_PRINT((ndo, "\n\t          Priority Bit %d: %s",
1257 		    i, (tval & (1 << i)) ? "Enabled" : "Disabled"));
1258 	    ND_PRINT((ndo, "\n\t      NumTCPFCSupported: %d", *(tptr + 5)));
1259 	    break;
1260         case LLDP_DCBX_APPLICATION_TLV:
1261             if (tlv_len < 4) {
1262                 goto trunc;
1263             }
1264 	    ND_PRINT((ndo, "\n\t    Feature - Application (type 0x%x, length %d)",
1265 		LLDP_DCBX_APPLICATION_TLV, tlv_len));
1266 	    ND_PRINT((ndo, "\n\t      Oper_Version: %d", *tptr));
1267 	    ND_PRINT((ndo, "\n\t      Max_Version: %d", *(tptr + 1)));
1268 	    ND_PRINT((ndo, "\n\t      Info block(0x%02X): ", *(tptr + 2)));
1269 	    tval = *(tptr+2);
1270 	    ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d",
1271 		(tval &  0x80) ? 1 : 0, (tval &  0x40) ? 1 : 0,
1272 		(tval &  0x20) ? 1 : 0));
1273 	    ND_PRINT((ndo, "\n\t      SubType: %d", *(tptr + 3)));
1274 	    tval = tlv_len - 4;
1275 	    mptr = tptr + 4;
1276 	    while (tval >= 6) {
1277 		ND_PRINT((ndo, "\n\t      Application Value"));
1278 		ND_PRINT((ndo, "\n\t          Application Protocol ID: 0x%04x",
1279 			EXTRACT_16BITS(mptr)));
1280 		uval = EXTRACT_24BITS(mptr+2);
1281 		ND_PRINT((ndo, "\n\t          SF (0x%x) Application Protocol ID is %s",
1282 			(uval >> 22),
1283 			(uval >> 22) ? "Socket Number" : "L2 EtherType"));
1284 		ND_PRINT((ndo, "\n\t          OUI: 0x%06x", uval & 0x3fffff));
1285 		ND_PRINT((ndo, "\n\t          User Priority Map: 0x%02x", *(mptr + 5)));
1286 		tval = tval - 6;
1287 		mptr = mptr + 6;
1288 	    }
1289 	    break;
1290 	default:
1291 	    hexdump = TRUE;
1292 	    break;
1293 	}
1294 
1295         /* do we also want to see a hex dump ? */
1296         if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) {
1297 	    print_unknown_data(ndo, tptr, "\n\t    ", tlv_len);
1298         }
1299 
1300         tlen -= tlv_len;
1301         tptr += tlv_len;
1302     }
1303 
1304  trunc:
1305     return hexdump;
1306 }
1307 
1308 static char *
1309 lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len)
1310 {
1311     uint8_t af;
1312     static char buf[BUFSIZE];
1313     const char * (*pfunc)(netdissect_options *, const u_char *);
1314 
1315     if (len < 1)
1316       return NULL;
1317     len--;
1318     af = *tptr;
1319     switch (af) {
1320     case AFNUM_INET:
1321         if (len < 4)
1322           return NULL;
1323         /* This cannot be assigned to ipaddr_string(), which is a macro. */
1324         pfunc = getname;
1325         break;
1326     case AFNUM_INET6:
1327         if (len < 16)
1328           return NULL;
1329         /* This cannot be assigned to ip6addr_string(), which is a macro. */
1330         pfunc = getname6;
1331         break;
1332     case AFNUM_802:
1333         if (len < 6)
1334           return NULL;
1335         pfunc = etheraddr_string;
1336         break;
1337     default:
1338         pfunc = NULL;
1339         break;
1340     }
1341 
1342     if (!pfunc) {
1343         snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !",
1344                  tok2str(af_values, "Unknown", af), af);
1345     } else {
1346         snprintf(buf, sizeof(buf), "AFI %s (%u): %s",
1347                  tok2str(af_values, "Unknown", af), af, (*pfunc)(ndo, tptr+1));
1348     }
1349 
1350     return buf;
1351 }
1352 
1353 static int
1354 lldp_mgmt_addr_tlv_print(netdissect_options *ndo,
1355                          const u_char *pptr, u_int len)
1356 {
1357     uint8_t mgmt_addr_len, intf_num_subtype, oid_len;
1358     const u_char *tptr;
1359     u_int tlen;
1360     char *mgmt_addr;
1361 
1362     tlen = len;
1363     tptr = pptr;
1364 
1365     if (tlen < 1) {
1366         return 0;
1367     }
1368     mgmt_addr_len = *tptr++;
1369     tlen--;
1370 
1371     if (tlen < mgmt_addr_len) {
1372         return 0;
1373     }
1374 
1375     mgmt_addr = lldp_network_addr_print(ndo, tptr, mgmt_addr_len);
1376     if (mgmt_addr == NULL) {
1377         return 0;
1378     }
1379     ND_PRINT((ndo, "\n\t  Management Address length %u, %s",
1380            mgmt_addr_len, mgmt_addr));
1381     tptr += mgmt_addr_len;
1382     tlen -= mgmt_addr_len;
1383 
1384     if (tlen < LLDP_INTF_NUM_LEN) {
1385         return 0;
1386     }
1387 
1388     intf_num_subtype = *tptr;
1389     ND_PRINT((ndo, "\n\t  %s Interface Numbering (%u): %u",
1390            tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype),
1391            intf_num_subtype,
1392            EXTRACT_32BITS(tptr + 1)));
1393 
1394     tptr += LLDP_INTF_NUM_LEN;
1395     tlen -= LLDP_INTF_NUM_LEN;
1396 
1397     /*
1398      * The OID is optional.
1399      */
1400     if (tlen) {
1401         oid_len = *tptr;
1402 
1403         if (tlen < oid_len) {
1404             return 0;
1405         }
1406         if (oid_len) {
1407             ND_PRINT((ndo, "\n\t  OID length %u", oid_len));
1408             safeputs(ndo, tptr + 1, oid_len);
1409         }
1410     }
1411 
1412     return 1;
1413 }
1414 
1415 void
1416 lldp_print(netdissect_options *ndo,
1417            register const u_char *pptr, register u_int len)
1418 {
1419     uint8_t subtype;
1420     uint16_t tlv, cap, ena_cap;
1421     u_int oui, tlen, hexdump, tlv_type, tlv_len;
1422     const u_char *tptr;
1423     char *network_addr;
1424 
1425     tptr = pptr;
1426     tlen = len;
1427 
1428     ND_PRINT((ndo, "LLDP, length %u", len));
1429 
1430     while (tlen >= sizeof(tlv)) {
1431 
1432         ND_TCHECK2(*tptr, sizeof(tlv));
1433 
1434         tlv = EXTRACT_16BITS(tptr);
1435 
1436         tlv_type = LLDP_EXTRACT_TYPE(tlv);
1437         tlv_len = LLDP_EXTRACT_LEN(tlv);
1438         hexdump = FALSE;
1439 
1440         tlen -= sizeof(tlv);
1441         tptr += sizeof(tlv);
1442 
1443         if (ndo->ndo_vflag) {
1444             ND_PRINT((ndo, "\n\t%s TLV (%u), length %u",
1445                    tok2str(lldp_tlv_values, "Unknown", tlv_type),
1446                    tlv_type, tlv_len));
1447         }
1448 
1449         /* infinite loop check */
1450         if (!tlv_type || !tlv_len) {
1451             break;
1452         }
1453 
1454         ND_TCHECK2(*tptr, tlv_len);
1455         if (tlen < tlv_len) {
1456             goto trunc;
1457         }
1458 
1459         switch (tlv_type) {
1460 
1461         case LLDP_CHASSIS_ID_TLV:
1462             if (ndo->ndo_vflag) {
1463                 if (tlv_len < 2) {
1464                     goto trunc;
1465                 }
1466                 subtype = *tptr;
1467                 ND_PRINT((ndo, "\n\t  Subtype %s (%u): ",
1468                        tok2str(lldp_chassis_subtype_values, "Unknown", subtype),
1469                        subtype));
1470 
1471                 switch (subtype) {
1472                 case LLDP_CHASSIS_MAC_ADDR_SUBTYPE:
1473                     if (tlv_len < 1+6) {
1474                         goto trunc;
1475                     }
1476                     ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr + 1)));
1477                     break;
1478 
1479                 case LLDP_CHASSIS_INTF_NAME_SUBTYPE: /* fall through */
1480                 case LLDP_CHASSIS_LOCAL_SUBTYPE:
1481                 case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE:
1482                 case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE:
1483                 case LLDP_CHASSIS_PORT_COMP_SUBTYPE:
1484                     safeputs(ndo, tptr + 1, tlv_len - 1);
1485                     break;
1486 
1487                 case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE:
1488                     network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1);
1489                     if (network_addr == NULL) {
1490                         goto trunc;
1491                     }
1492                     ND_PRINT((ndo, "%s", network_addr));
1493                     break;
1494 
1495                 default:
1496                     hexdump = TRUE;
1497                     break;
1498                 }
1499             }
1500             break;
1501 
1502         case LLDP_PORT_ID_TLV:
1503             if (ndo->ndo_vflag) {
1504                 if (tlv_len < 2) {
1505                     goto trunc;
1506                 }
1507                 subtype = *tptr;
1508                 ND_PRINT((ndo, "\n\t  Subtype %s (%u): ",
1509                        tok2str(lldp_port_subtype_values, "Unknown", subtype),
1510                        subtype));
1511 
1512                 switch (subtype) {
1513                 case LLDP_PORT_MAC_ADDR_SUBTYPE:
1514                     if (tlv_len < 1+6) {
1515                         goto trunc;
1516                     }
1517                     ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr + 1)));
1518                     break;
1519 
1520                 case LLDP_PORT_INTF_NAME_SUBTYPE: /* fall through */
1521                 case LLDP_PORT_LOCAL_SUBTYPE:
1522                 case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE:
1523                 case LLDP_PORT_INTF_ALIAS_SUBTYPE:
1524                 case LLDP_PORT_PORT_COMP_SUBTYPE:
1525                     safeputs(ndo, tptr + 1, tlv_len - 1);
1526                     break;
1527 
1528                 case LLDP_PORT_NETWORK_ADDR_SUBTYPE:
1529                     network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1);
1530                     if (network_addr == NULL) {
1531                         goto trunc;
1532                     }
1533                     ND_PRINT((ndo, "%s", network_addr));
1534                     break;
1535 
1536                 default:
1537                     hexdump = TRUE;
1538                     break;
1539                 }
1540             }
1541             break;
1542 
1543         case LLDP_TTL_TLV:
1544             if (ndo->ndo_vflag) {
1545                 if (tlv_len < 2) {
1546                     goto trunc;
1547                 }
1548                 ND_PRINT((ndo, ": TTL %us", EXTRACT_16BITS(tptr)));
1549             }
1550             break;
1551 
1552         case LLDP_PORT_DESCR_TLV:
1553             if (ndo->ndo_vflag) {
1554                 ND_PRINT((ndo, ": "));
1555                 safeputs(ndo, tptr, tlv_len);
1556             }
1557             break;
1558 
1559         case LLDP_SYSTEM_NAME_TLV:
1560             /*
1561              * The system name is also print in non-verbose mode
1562              * similar to the CDP printer.
1563              */
1564             ND_PRINT((ndo, ": "));
1565             safeputs(ndo, tptr, tlv_len);
1566             break;
1567 
1568         case LLDP_SYSTEM_DESCR_TLV:
1569             if (ndo->ndo_vflag) {
1570                 ND_PRINT((ndo, "\n\t  "));
1571                 safeputs(ndo, tptr, tlv_len);
1572             }
1573             break;
1574 
1575         case LLDP_SYSTEM_CAP_TLV:
1576             if (ndo->ndo_vflag) {
1577                 /*
1578                  * XXX - IEEE Std 802.1AB-2009 says the first octet
1579                  * if a chassis ID subtype, with the system
1580                  * capabilities and enabled capabilities following
1581                  * it.
1582                  */
1583                 if (tlv_len < 4) {
1584                     goto trunc;
1585                 }
1586                 cap = EXTRACT_16BITS(tptr);
1587                 ena_cap = EXTRACT_16BITS(tptr+2);
1588                 ND_PRINT((ndo, "\n\t  System  Capabilities [%s] (0x%04x)",
1589                        bittok2str(lldp_cap_values, "none", cap), cap));
1590                 ND_PRINT((ndo, "\n\t  Enabled Capabilities [%s] (0x%04x)",
1591                        bittok2str(lldp_cap_values, "none", ena_cap), ena_cap));
1592             }
1593             break;
1594 
1595         case LLDP_MGMT_ADDR_TLV:
1596             if (ndo->ndo_vflag) {
1597                 if (!lldp_mgmt_addr_tlv_print(ndo, tptr, tlv_len)) {
1598                     goto trunc;
1599                 }
1600             }
1601             break;
1602 
1603         case LLDP_PRIVATE_TLV:
1604             if (ndo->ndo_vflag) {
1605                 if (tlv_len < 3) {
1606                     goto trunc;
1607                 }
1608                 oui = EXTRACT_24BITS(tptr);
1609                 ND_PRINT((ndo, ": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui));
1610 
1611                 switch (oui) {
1612                 case OUI_IEEE_8021_PRIVATE:
1613                     hexdump = lldp_private_8021_print(ndo, tptr, tlv_len);
1614                     break;
1615                 case OUI_IEEE_8023_PRIVATE:
1616                     hexdump = lldp_private_8023_print(ndo, tptr, tlv_len);
1617                     break;
1618 		case OUI_IANA:
1619                     hexdump = lldp_private_iana_print(ndo, tptr, tlv_len);
1620                     break;
1621                 case OUI_TIA:
1622                     hexdump = lldp_private_tia_print(ndo, tptr, tlv_len);
1623                     break;
1624                 case OUI_DCBX:
1625                     hexdump = lldp_private_dcbx_print(ndo, tptr, tlv_len);
1626                     break;
1627                 default:
1628                     hexdump = TRUE;
1629                     break;
1630                 }
1631             }
1632             break;
1633 
1634         default:
1635             hexdump = TRUE;
1636             break;
1637         }
1638 
1639         /* do we also want to see a hex dump ? */
1640         if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) {
1641             print_unknown_data(ndo, tptr, "\n\t  ", tlv_len);
1642         }
1643 
1644         tlen -= tlv_len;
1645         tptr += tlv_len;
1646     }
1647     return;
1648  trunc:
1649     ND_PRINT((ndo, "\n\t[|LLDP]"));
1650 }
1651 
1652 /*
1653  * Local Variables:
1654  * c-style: whitesmith
1655  * c-basic-offset: 4
1656  * End:
1657  */
1658