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