dcerpc-netlogon: maintain netlogon_auth_vars for NetrServerAuthenticateKerberos
[wireshark-sm.git] / epan / dissectors / packet-cdp.c
blob1c4bf1ce8e55d15f8a1d6fbe2357544a52d9f294
1 /* packet-cdp.c
2 * Routines for the disassembly of the "Cisco Discovery Protocol"
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/to_str.h>
17 #include <epan/in_cksum.h>
18 #include <epan/nlpid.h>
19 #include <epan/etypes.h>
20 #include <epan/cisco_pid.h>
21 #include <epan/tfs.h>
22 #include <epan/unit_strings.h>
26 * See
28 * https://web.archive.org/web/20000914194913/http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.pdf
30 * for some documentation on CDP.
32 * See
34 * http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/cdp/configuration/15-mt/cdp-15-mt-book/nm-cdp-discover.html#GUID-84FBA50B-677C-4D90-AF56-2FB96F2DC085
36 * and
38 * http://www.cisco.com/c/en/us/support/docs/switches/catalyst-4500-series-switches/13414-103.html#cdp
40 * for some more information on CDP version 2 (a superset of version 1).
42 * Also see
44 * https://web.archive.org/web/20220711213555/http://www.rhyshaden.com/cdp.htm
47 void proto_register_cdp(void);
48 void proto_reg_handoff_cdp(void);
50 static dissector_handle_t cdp_handle;
52 /* Offsets in TLV structure. */
53 #define TLV_TYPE 0
54 #define TLV_LENGTH 2
56 static int proto_cdp;
57 static int hf_cdp_version;
58 static int hf_cdp_checksum;
59 static int hf_cdp_checksum_status;
60 static int hf_cdp_ttl;
61 static int hf_cdp_tlvtype;
62 static int hf_cdp_tlvlength;
63 static int hf_cdp_nrgyz_tlvtype;
64 static int hf_cdp_nrgyz_tlvlength;
65 static int hf_cdp_deviceid;
66 static int hf_cdp_platform;
67 static int hf_cdp_portid;
68 static int hf_cdp_capabilities;
69 static int hf_cdp_capabilities_router;
70 static int hf_cdp_capabilities_trans_bridge;
71 static int hf_cdp_capabilities_src_bridge;
72 static int hf_cdp_capabilities_switch;
73 static int hf_cdp_capabilities_host;
74 static int hf_cdp_capabilities_igmp_capable;
75 static int hf_cdp_capabilities_repeater;
76 static int hf_cdp_capabilities_voip_phone;
77 static int hf_cdp_capabilities_remote;
78 static int hf_cdp_capabilities_cvta;
79 static int hf_cdp_capabilities_mac_relay;
80 static int hf_cdp_spare_poe_tlv;
81 static int hf_cdp_spare_poe_tlv_poe;
82 static int hf_cdp_spare_poe_tlv_spare_pair_arch;
83 static int hf_cdp_spare_poe_tlv_req_spare_pair_poe;
84 static int hf_cdp_spare_poe_tlv_pse_spare_pair_poe;
86 /* Generated from convert_proto_tree_add_text.pl */
87 static int hf_cdp_num_tlvs_table;
88 static int hf_cdp_encrypted_data;
89 static int hf_cdp_cluster_ip;
90 static int hf_cdp_nrgyz_reply_to_backup_server_ip;
91 static int hf_cdp_nrgyz_reply_to_port;
92 static int hf_cdp_unknown_pad;
93 static int hf_cdp_cluster_version;
94 static int hf_cdp_hello_unknown;
95 static int hf_cdp_management_id;
96 static int hf_cdp_data;
97 static int hf_cdp_nrgyz_reply_to_ip_address;
98 static int hf_cdp_nrgyz_reply_to_name;
99 static int hf_cdp_nrgyz_reply_to_domain;
100 static int hf_cdp_nrgyz_reply_to_role;
101 static int hf_cdp_nrgyz_ip_address;
102 static int hf_cdp_nrgyz_ip6_address;
103 static int hf_cdp_model_number;
104 static int hf_cdp_nrgyz_reply_to_unknown_field;
105 static int hf_cdp_len_tlv_table;
106 static int hf_cdp_vtp_management_domain;
107 static int hf_cdp_hardware_version_id;
108 static int hf_cdp_cluster_unknown;
109 static int hf_cdp_native_vlan;
110 static int hf_cdp_ip_prefix;
111 static int hf_cdp_odr_default_gateway;
112 static int hf_cdp_power_consumption;
113 static int hf_cdp_cluster_status;
114 static int hf_cdp_power_requested;
115 static int hf_cdp_trust_bitmap;
116 static int hf_cdp_seen_sequence;
117 static int hf_cdp_system_name;
118 static int hf_cdp_power_available;
119 static int hf_cdp_cluster_commander_mac;
120 static int hf_cdp_mtu;
121 static int hf_cdp_protocol_length;
122 static int hf_cdp_system_serial_number;
123 static int hf_cdp_sequence_number;
124 static int hf_cdp_duplex;
125 static int hf_cdp_voice_vlan;
126 static int hf_cdp_request_id;
127 static int hf_cdp_cluster_sub_version;
128 static int hf_cdp_oui;
129 static int hf_cdp_nrgyz_reply_to_backup_server_port;
130 static int hf_cdp_cluster_master_ip;
131 static int hf_cdp_protocol;
132 static int hf_cdp_protocol_type;
133 static int hf_cdp_address;
134 static int hf_cdp_system_object_identifier;
135 static int hf_cdp_location_unknown;
136 static int hf_cdp_nrgyz_unknown_values;
137 static int hf_cdp_address_length;
138 static int hf_cdp_protocol_id;
139 static int hf_cdp_cluster_switch_mac;
140 static int hf_cdp_location;
141 static int hf_cdp_untrusted_port_cos;
142 static int hf_cdp_number_of_addresses;
143 static int hf_cdp_cluster_management_vlan;
144 static int hf_cdp_software_version;
146 static int ett_cdp;
147 static int ett_cdp_tlv;
148 static int ett_cdp_nrgyz_tlv;
149 static int ett_cdp_address;
150 static int ett_cdp_capabilities;
151 static int ett_cdp_spare_poe_tlv;
152 static int ett_cdp_checksum;
154 static expert_field ei_cdp_invalid_data;
155 static expert_field ei_cdp_nrgyz_tlvlength;
156 static expert_field ei_cdp_checksum;
158 static int
159 dissect_address_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, int length, proto_tree *tree);
160 static void
161 dissect_capabilities(tvbuff_t *tvb, int offset, int length, proto_tree *tree);
162 static void
163 dissect_nrgyz_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, uint16_t length, uint16_t num,
164 proto_tree *tree);
165 static void
166 dissect_spare_poe_tlv(tvbuff_t *tvb, int offset, int length, proto_tree *tree);
167 static void
168 add_multi_line_string_to_tree(wmem_allocator_t *scope, proto_tree *tree, tvbuff_t *tvb, int start,
169 int len, int hf);
171 #define TYPE_DEVICE_ID 0x0001
172 #define TYPE_ADDRESS 0x0002
173 #define TYPE_PORT_ID 0x0003
174 #define TYPE_CAPABILITIES 0x0004
175 #define TYPE_IOS_VERSION 0x0005
176 #define TYPE_PLATFORM 0x0006
177 #define TYPE_IP_PREFIX 0x0007
178 #define TYPE_PROTOCOL_HELLO 0x0008 /* Protocol Hello */
179 #define TYPE_VTP_MGMT_DOMAIN 0x0009 /* VTP Domain, CTPv2 - see second URL */
180 #define TYPE_NATIVE_VLAN 0x000a /* Native VLAN, CTPv2 - see second URL */
181 #define TYPE_DUPLEX 0x000b /* Full/Half Duplex - see second URL */
182 /* 0x000c */
183 /* 0x000d */
184 #define TYPE_VOIP_VLAN_REPLY 0x000e /* VoIP VLAN reply */
185 #define TYPE_VOIP_VLAN_QUERY 0x000f /* VoIP VLAN query */
186 #define TYPE_POWER 0x0010 /* Power consumption */
187 #define TYPE_MTU 0x0011 /* MTU */
188 #define TYPE_TRUST_BITMAP 0x0012 /* Trust bitmap */
189 #define TYPE_UNTRUSTED_COS 0x0013 /* Untrusted port CoS */
190 #define TYPE_SYSTEM_NAME 0x0014 /* System Name */
191 #define TYPE_SYSTEM_OID 0x0015 /* System OID */
192 #define TYPE_MANAGEMENT_ADDR 0x0016 /* Management Address(es) */
193 #define TYPE_LOCATION 0x0017 /* Location */
194 #define TYPE_EXT_PORT_ID 0x0018 /* External Port-ID */
195 #define TYPE_POWER_REQUESTED 0x0019 /* Power Requested */
196 #define TYPE_POWER_AVAILABLE 0x001a /* Power Available */
197 #define TYPE_PORT_UNIDIR 0x001b /* Port Unidirectional */
198 #define TYPE_NRGYZ 0x001d /* EnergyWise over CDP */
199 #define TYPE_SPARE_POE 0x001f /* Spare Pair PoE */
201 #define TYPE_HP_BSSID 0x1000 /* BSSID */
202 #define TYPE_HP_SERIAL 0x1001 /* Serial number */
203 #define TYPE_HP_SSID 0x1002 /* SSID */
204 #define TYPE_HP_RADIO1_CH 0x1003 /* Radio1 channel */
205 /* 0x1004 */
206 /* 0x1005 */
207 #define TYPE_HP_SNMP_PORT 0x1006 /* SNMP listening UDP port */
208 #define TYPE_HP_MGMT_PORT 0x1007 /* Web interface TCP port */
209 #define TYPE_HP_SOURCE_MAC 0x1008 /* Sender MAC address for the AP, bouth wired and wireless */
210 #define TYPE_HP_RADIO2_CH 0x1009 /* Radio2 channel */
211 #define TYPE_HP_RADIO1_OMODE 0x100A /* Radio1 Operating mode */
212 #define TYPE_HP_RADIO2_OMODE 0x100B /* Radio2 Operating mode */
213 #define TYPE_HP_RADIO1_RMODE 0x100C /* Radio1 Radio mode */
214 #define TYPE_HP_RADIO2_RMODE 0x100D /* Radio2 Radio mode */
216 static const value_string type_vals[] = {
217 { TYPE_DEVICE_ID, "Device ID" },
218 { TYPE_ADDRESS, "Addresses" },
219 { TYPE_PORT_ID, "Port ID" },
220 { TYPE_CAPABILITIES, "Capabilities" },
221 { TYPE_IOS_VERSION, "Software version" },
222 { TYPE_PLATFORM, "Platform" },
223 { TYPE_IP_PREFIX, "IP Prefix/Gateway (used for ODR)" },
224 { TYPE_PROTOCOL_HELLO, "Protocol Hello" },
225 { TYPE_VTP_MGMT_DOMAIN, "VTP Management Domain" },
226 { TYPE_NATIVE_VLAN, "Native VLAN" },
227 { TYPE_DUPLEX, "Duplex" },
228 { TYPE_VOIP_VLAN_REPLY, "VoIP VLAN Reply" },
229 { TYPE_VOIP_VLAN_QUERY, "VoIP VLAN Query" },
230 { TYPE_POWER, "Power consumption" },
231 { TYPE_MTU, "MTU"},
232 { TYPE_TRUST_BITMAP, "Trust Bitmap" },
233 { TYPE_UNTRUSTED_COS, "Untrusted Port CoS" },
234 { TYPE_SYSTEM_NAME, "System Name" },
235 { TYPE_SYSTEM_OID, "System Object ID" },
236 { TYPE_MANAGEMENT_ADDR, "Management Address" },
237 { TYPE_LOCATION, "Location" },
238 { TYPE_EXT_PORT_ID, "External Port-ID" },
239 { TYPE_POWER_REQUESTED, "Power Requested" },
240 { TYPE_POWER_AVAILABLE, "Power Available" },
241 { TYPE_PORT_UNIDIR, "Port Unidirectional" },
242 { TYPE_NRGYZ, "EnergyWise" },
243 { TYPE_SPARE_POE, "Spare PoE" },
244 { TYPE_HP_BSSID, "BSSID" },
245 { TYPE_HP_SERIAL, "Serial number" },
246 { TYPE_HP_SSID, "SSID" },
247 { TYPE_HP_RADIO1_CH, "Radio1 channel" },
248 { TYPE_HP_SNMP_PORT, "SNMP UDP port" },
249 { TYPE_HP_MGMT_PORT, "Web TCP port" },
250 { TYPE_HP_SOURCE_MAC, "Source MAC address" },
251 { TYPE_HP_RADIO2_CH, "Radio2 channel" },
252 { TYPE_HP_RADIO1_OMODE, "Radio1 Operating mode" },
253 { TYPE_HP_RADIO2_OMODE, "Radio2 Operating mode" },
254 { TYPE_HP_RADIO1_RMODE, "Radio1 Radio mode" },
255 { TYPE_HP_RADIO2_RMODE, "Radio2 Radio mode" },
256 { 0, NULL }
259 #define TYPE_HELLO_CLUSTER_MGMT 0x0112
261 static const value_string type_hello_vals[] = {
262 { TYPE_HELLO_CLUSTER_MGMT, "Cluster Management" },
263 { 0, NULL }
266 #define TYPE_NRGYZ_ROLE 0x00000007
267 #define TYPE_NRGYZ_DOMAIN 0x00000008
268 #define TYPE_NRGYZ_NAME 0x00000009
269 #define TYPE_NRGYZ_REPLYTO 0x00000017
271 static const value_string type_nrgyz_vals[] = {
272 { TYPE_NRGYZ_ROLE, "Role" },
273 { TYPE_NRGYZ_DOMAIN, "Domain" },
274 { TYPE_NRGYZ_NAME, "Name" },
275 { TYPE_NRGYZ_REPLYTO, "Reply To" },
276 { 0, NULL }
279 static const unit_name_string units_mw = { "mW", NULL };
281 static int
282 dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
284 proto_item *ti;
285 proto_tree *cdp_tree;
286 int offset = 0;
287 uint16_t type;
288 uint16_t length, data_length;
289 proto_item *tlvi;
290 proto_tree *tlv_tree;
291 int real_length;
292 uint32_t naddresses;
293 uint32_t power_avail_len, power_avail;
294 uint32_t power_req_len, power_req;
295 bool first;
296 int addr_length;
297 vec_t cksum_vec[1];
299 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CDP");
300 col_clear(pinfo->cinfo, COL_INFO);
302 ti = proto_tree_add_item(tree, proto_cdp, tvb, offset, -1, ENC_NA);
303 cdp_tree = proto_item_add_subtree(ti, ett_cdp);
305 /* CDP header */
306 proto_tree_add_item(cdp_tree, hf_cdp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
307 offset += 1;
309 proto_tree_add_item(cdp_tree, hf_cdp_ttl, tvb, offset, 1, ENC_NA);
310 offset += 1;
312 /* Checksum display & verification code */
314 data_length = tvb_reported_length(tvb);
316 /* CDP doesn't adhere to RFC 1071 section 2. (B). It incorrectly assumes
317 * checksums are calculated on a big endian platform, therefore i.s.o.
318 * padding odd sized data with a zero byte _at the end_ it sets the last
319 * big endian _word_ to contain the last network _octet_. This byteswap
320 * has to be done on the last octet of network data before feeding it to
321 * the Internet checksum routine.
322 * CDP checksumming code has a bug in the addition of this last _word_
323 * as a signed number into the long word intermediate checksum. When
324 * reducing this long to word size checksum an off-by-one error can be
325 * made. This off-by-one error is compensated for in the last _word_ of
326 * the network data.
328 if (data_length & 1) {
329 uint8_t *padded_buffer;
330 /* Allocate new buffer */
331 padded_buffer = (uint8_t *)wmem_alloc(pinfo->pool, data_length+1);
332 tvb_memcpy(tvb, padded_buffer, 0, data_length);
333 /* Swap bytes in last word */
334 padded_buffer[data_length] = padded_buffer[data_length-1];
335 padded_buffer[data_length-1] = 0;
336 /* Compensate off-by-one error */
337 if (padded_buffer[data_length] & 0x80) {
338 padded_buffer[data_length]--;
339 padded_buffer[data_length-1]--;
341 /* Setup checksum routine data buffer */
342 SET_CKSUM_VEC_PTR(cksum_vec[0], padded_buffer, data_length+1);
343 } else {
344 /* Setup checksum routine data buffer */
345 SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, data_length);
348 proto_tree_add_checksum(cdp_tree, tvb, offset, hf_cdp_checksum, hf_cdp_checksum_status, &ei_cdp_checksum, pinfo, in_cksum(cksum_vec, 1),
349 ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM);
350 offset += 2;
352 while (tvb_reported_length_remaining(tvb, offset) != 0) {
353 tlv_tree = NULL;
354 type = tvb_get_ntohs(tvb, offset + TLV_TYPE);
355 length = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
356 if (length < 4) {
357 if (tree) {
358 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset, 4,
359 ett_cdp_tlv, NULL, "TLV with invalid length %u (< 4)",
360 length);
361 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
362 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
364 offset += 4;
365 break;
368 switch (type) {
370 case TYPE_DEVICE_ID:
371 /* Device ID */
373 col_append_fstr(pinfo->cinfo, COL_INFO,
374 "Device ID: %s ",
375 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, length - 4));
377 if (tree) {
378 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset,
379 length, ett_cdp_tlv, NULL, "Device ID: %s",
380 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, length - 4));
381 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
382 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
383 proto_tree_add_item(tlv_tree, hf_cdp_deviceid, tvb, offset + 4, length - 4, ENC_ASCII);
385 offset += length;
386 break;
388 case TYPE_PORT_ID:
389 real_length = length;
390 if ((tvb_reported_length_remaining(tvb, offset) >= length + 3) &&
391 (tvb_get_uint8(tvb, offset + real_length) != 0x00) &&
392 (tvb_get_uint8(tvb, offset + real_length) != 0x10)) {
393 /* The length in the TLV doesn't appear to be the
394 length of the TLV, as the byte just past it
395 isn't the first byte of a 2-byte big-endian
396 small integer; make the length of the TLV the length
397 in the TLV, plus 4 bytes for the TLV type and length,
398 minus 1 because that's what makes one capture work. */
399 real_length = length + 3;
402 col_append_fstr(pinfo->cinfo, COL_INFO,
403 "Port ID: %s ",
404 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4,
405 length - 4));
407 if (tree) {
408 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset,
409 real_length, ett_cdp_tlv, NULL, "Port ID: %s",
410 tvb_format_text(pinfo->pool, tvb, offset + 4, real_length - 4));
411 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
412 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
413 proto_tree_add_item(tlv_tree, hf_cdp_portid, tvb, offset + 4, real_length - 4, ENC_ASCII);
415 offset += real_length;
416 break;
418 case TYPE_ADDRESS:
419 /* Addresses */
420 if (tree) {
421 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb, offset,
422 length, ett_cdp_tlv, NULL, "Addresses");
423 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
424 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
426 offset += 4;
427 length -= 4;
428 naddresses = tvb_get_ntohl(tvb, offset);
429 proto_tree_add_item(tlv_tree, hf_cdp_number_of_addresses, tvb, offset, 4, ENC_BIG_ENDIAN);
430 offset += 4;
431 length -= 4;
432 while (naddresses != 0) {
433 addr_length = dissect_address_tlv(tvb, pinfo, offset, length,
434 tlv_tree);
435 if (addr_length < 0)
436 break;
437 offset += addr_length;
438 length -= addr_length;
440 naddresses--;
442 offset += length;
443 break;
445 case TYPE_CAPABILITIES:
446 if (tree) {
447 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb, offset,
448 length, ett_cdp_tlv, NULL, "Capabilities");
449 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
450 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
452 offset += 4;
453 length -= 4;
454 dissect_capabilities(tvb, offset, length, tlv_tree);
455 offset += length;
456 break;
458 case TYPE_IOS_VERSION:
459 if (tree) {
460 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb, offset,
461 length, ett_cdp_tlv, NULL, "Software Version");
462 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
463 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
464 add_multi_line_string_to_tree(pinfo->pool, tlv_tree, tvb, offset + 4,
465 length - 4, hf_cdp_software_version);
467 offset += length;
468 break;
470 case TYPE_PLATFORM:
471 /* ??? platform */
472 if (tree) {
473 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
474 offset, length, ett_cdp_tlv, NULL, "Platform: %s",
475 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
476 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
477 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
478 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
480 offset += length;
481 break;
483 case TYPE_IP_PREFIX:
484 if (length == 8) {
485 /* if length is 8 then this is default gw not prefix */
486 if (tree) {
487 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset,
488 length, ett_cdp_tlv, NULL, "ODR Default gateway: %s",
489 tvb_ip_to_str(pinfo->pool, tvb, offset+4));
490 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
491 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
492 proto_tree_add_item(tlv_tree, hf_cdp_odr_default_gateway, tvb, offset+4, 4, ENC_BIG_ENDIAN);
494 offset += 8;
495 } else {
496 if (tree) {
497 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset,
498 length, ett_cdp_tlv, NULL, "IP Prefixes: %d",length/5);
500 /* the actual number of prefixes is (length-4)/5
501 but if the variable is not a "float" but "integer"
502 then length/5=(length-4)/5 :) */
504 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
505 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
507 offset += 4;
508 length -= 4;
509 while (length > 0) {
510 proto_tree_add_ipv4_format_value(tlv_tree, hf_cdp_ip_prefix, tvb, offset, 5, tvb_get_ntohl(tvb, offset),
511 "%s/%u", tvb_ip_to_str(pinfo->pool, tvb, offset), tvb_get_uint8(tvb,offset+4));
512 offset += 5;
513 length -= 5;
516 break;
518 case TYPE_PROTOCOL_HELLO:
519 if (tree) {
520 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
521 offset,length, ett_cdp_tlv, NULL, "Protocol Hello: %s",
522 val_to_str(tvb_get_ntohs(tvb, offset+7), type_hello_vals, "Unknown (0x%04x)"));
523 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
524 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
525 proto_tree_add_item(tlv_tree, hf_cdp_oui, tvb, offset+4, 3, ENC_BIG_ENDIAN);
526 proto_tree_add_item(tlv_tree, hf_cdp_protocol_id, tvb, offset+7, 2, ENC_BIG_ENDIAN);
528 switch(tvb_get_ntohs(tvb, offset+7)) {
530 case TYPE_HELLO_CLUSTER_MGMT:
531 proto_tree_add_item(tlv_tree, hf_cdp_cluster_master_ip, tvb, offset+9, 4, ENC_BIG_ENDIAN);
532 proto_tree_add_item(tlv_tree, hf_cdp_cluster_ip, tvb, offset+13, 4, ENC_BIG_ENDIAN);
533 proto_tree_add_item(tlv_tree, hf_cdp_cluster_version, tvb, offset+17, 1, ENC_BIG_ENDIAN);
534 proto_tree_add_item(tlv_tree, hf_cdp_cluster_sub_version, tvb, offset+18, 1, ENC_BIG_ENDIAN);
535 proto_tree_add_item(tlv_tree, hf_cdp_cluster_status, tvb, offset+19, 1, ENC_BIG_ENDIAN);
536 proto_tree_add_item(tlv_tree, hf_cdp_cluster_unknown, tvb, offset+20, 1, ENC_BIG_ENDIAN);
537 proto_tree_add_item(tlv_tree, hf_cdp_cluster_commander_mac, tvb, offset+21, 6, ENC_NA);
538 proto_tree_add_item(tlv_tree, hf_cdp_cluster_switch_mac, tvb, offset+27, 6, ENC_NA);
539 proto_tree_add_item(tlv_tree, hf_cdp_cluster_unknown, tvb, offset+33, 1, ENC_BIG_ENDIAN);
540 proto_tree_add_item(tlv_tree, hf_cdp_cluster_management_vlan, tvb, offset+34, 2, ENC_BIG_ENDIAN);
541 break;
542 default:
543 proto_tree_add_item(tlv_tree, hf_cdp_hello_unknown, tvb, offset + 9, length - 9, ENC_NA);
544 break;
547 offset += length;
548 break;
550 case TYPE_VTP_MGMT_DOMAIN:
551 if (tree) {
552 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
553 offset, length, ett_cdp_tlv, NULL, "VTP Management Domain: %s",
554 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
555 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
556 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
557 proto_tree_add_item(tlv_tree, hf_cdp_vtp_management_domain, tvb, offset + 4, length - 4, ENC_NA|ENC_ASCII);
559 offset += length;
560 break;
562 case TYPE_NATIVE_VLAN:
563 if (tree) {
564 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
565 offset, length, ett_cdp_tlv, NULL, "Native VLAN: %u",
566 tvb_get_ntohs(tvb, offset + 4));
567 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
568 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
569 proto_tree_add_item(tlv_tree, hf_cdp_native_vlan, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
571 offset += length;
572 break;
574 case TYPE_DUPLEX:
575 if (tree) {
576 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
577 offset, length, ett_cdp_tlv, NULL, "Duplex: %s",
578 tvb_get_uint8(tvb, offset + 4) ?
579 "Full" : "Half" );
580 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
581 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
582 proto_tree_add_item(tlv_tree, hf_cdp_duplex, tvb, offset + 4, 1, ENC_NA);
584 offset += length;
585 break;
587 case TYPE_VOIP_VLAN_REPLY:
588 tlvi = NULL;
589 if (tree) {
590 uint32_t vlan_id;
592 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
593 offset, length, ett_cdp_tlv, &tlvi,
594 "VoIP VLAN Reply");
595 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
596 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
597 if (length == 6) {
599 * XXX - this doesn't appear to happen, so report it
600 * as an error.
602 proto_tree_add_item(tlv_tree, hf_cdp_data, tvb, offset + 4, 2, ENC_NA);
603 } else {
605 * XXX - the first byte appears to be a 1-byte
606 * "appliance type" code.
608 proto_tree_add_item(tlv_tree, hf_cdp_data, tvb, offset + 4, 1, ENC_NA);
609 proto_tree_add_item_ret_uint(tlv_tree, hf_cdp_voice_vlan, tvb, offset + 5, 2, ENC_BIG_ENDIAN, &vlan_id);
610 proto_item_append_text(tlvi, ": VLAN %u", vlan_id);
613 offset += length;
614 break;
616 case TYPE_VOIP_VLAN_QUERY:
617 tlvi = NULL;
618 if (tree) {
619 uint32_t vlan_id;
621 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
622 offset, length, ett_cdp_tlv, &tlvi,
623 "VoIP VLAN Query");
624 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
625 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
626 if (length == 6) {
628 * This is some unknown value; it's typically 0x20 0x00,
629 * which, as a big-endian value, is not a VLAN ID, as
630 * VLAN IDs are 12 bits long.
632 proto_tree_add_item(tlv_tree, hf_cdp_data, tvb, offset + 4, 2, ENC_NA);
633 } else {
635 * XXX - is this a 1-byte "appliance type" code?
637 proto_tree_add_item(tlv_tree, hf_cdp_data, tvb, offset + 4, 1, ENC_NA);
638 proto_tree_add_item_ret_uint(tlv_tree, hf_cdp_voice_vlan, tvb, offset + 5, 2, ENC_BIG_ENDIAN, &vlan_id);
639 proto_item_append_text(tlvi, ": VLAN %u", vlan_id);
642 offset += length;
643 break;
645 case TYPE_POWER:
646 if (tree) {
647 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
648 offset, length, ett_cdp_tlv, NULL, "Power Consumption: %u mW",
649 tvb_get_ntohs(tvb, offset + 4));
650 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
651 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
652 proto_tree_add_item(tlv_tree, hf_cdp_power_consumption, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
654 offset += length;
655 break;
657 case TYPE_MTU:
658 if (tree) {
659 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
660 offset, length, ett_cdp_tlv, NULL, "MTU: %u",
661 tvb_get_ntohl(tvb,offset + 4));
662 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
663 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
664 proto_tree_add_item(tlv_tree, hf_cdp_mtu, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
666 offset += length;
667 break;
669 case TYPE_TRUST_BITMAP:
670 if (tree) {
671 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
672 offset, length, ett_cdp_tlv, NULL, "Trust Bitmap: 0x%02X",
673 tvb_get_uint8(tvb, offset + 4));
674 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
675 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
676 proto_tree_add_item(tlv_tree, hf_cdp_trust_bitmap, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
678 offset += length;
679 break;
681 case TYPE_UNTRUSTED_COS:
682 if (tree) {
683 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
684 offset, length, ett_cdp_tlv, NULL, "Untrusted port CoS: 0x%02X",
685 tvb_get_uint8(tvb, offset + 4));
686 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
687 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
688 proto_tree_add_item(tlv_tree, hf_cdp_untrusted_port_cos, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
690 offset += length;
691 break;
693 case TYPE_SYSTEM_NAME:
694 if (tree) {
695 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
696 offset, length, ett_cdp_tlv, NULL, "System Name: %s",
697 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
698 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
699 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
700 proto_tree_add_item(tlv_tree, hf_cdp_system_name, tvb, offset + 4, length - 4, ENC_NA|ENC_ASCII);
702 offset += length;
703 break;
705 case TYPE_SYSTEM_OID:
706 if (tree) {
707 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
708 offset, length, ett_cdp_tlv, NULL, "System Object Identifier");
709 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
710 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
711 proto_tree_add_item(tlv_tree, hf_cdp_system_object_identifier, tvb, offset + 4, length - 4, ENC_NA);
713 offset += length;
714 break;
716 case TYPE_MANAGEMENT_ADDR:
717 if (tree) {
718 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
719 offset, length, ett_cdp_tlv, NULL, "Management Addresses");
720 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
721 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
723 offset += 4;
724 length -= 4;
725 naddresses = tvb_get_ntohl(tvb, offset);
726 if (tree) {
727 proto_tree_add_item(tlv_tree, hf_cdp_number_of_addresses, tvb, offset, 4, ENC_BIG_ENDIAN);
729 offset += 4;
730 length -= 4;
731 while (naddresses != 0) {
732 addr_length = dissect_address_tlv(tvb, pinfo, offset, length,
733 tlv_tree);
734 if (addr_length < 0)
735 break;
736 offset += addr_length;
737 length -= addr_length;
739 naddresses--;
741 offset += length;
742 break;
744 case TYPE_LOCATION:
745 if (tree) {
746 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
747 offset, length, ett_cdp_tlv, NULL, "Location: %s",
748 tvb_format_text(pinfo->pool, tvb, offset + 5, length - 5));
749 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
750 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
751 proto_tree_add_item(tlv_tree, hf_cdp_location_unknown, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
752 proto_tree_add_item(tlv_tree, hf_cdp_location, tvb, offset + 5, length - 5, ENC_NA|ENC_ASCII);
754 offset += length;
755 break;
757 case TYPE_POWER_REQUESTED:
758 tlvi = NULL;
759 if (tree) {
760 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
761 offset, length, ett_cdp_tlv, &tlvi,
762 "Power Request");
763 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
764 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
765 proto_tree_add_item(tlv_tree, hf_cdp_request_id, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
766 proto_tree_add_item(tlv_tree, hf_cdp_management_id, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
768 power_req_len = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
769 if (power_req_len < 8) {
770 offset += power_req_len;
771 break;
773 power_req_len -= 8;
774 /* Move offset to where the list of Power Request Values Exist */
775 offset += 8;
776 first = true;
777 while (power_req_len >= 4) {
778 proto_tree_add_item_ret_uint(tlv_tree, hf_cdp_power_requested, tvb, offset, 4, ENC_BIG_ENDIAN, &power_req);
779 if (first) {
780 proto_item_append_text(tlvi, ": %u mW", power_req);
781 first = false;
782 } else
783 proto_item_append_text(tlvi, ", %u mW", power_req);
784 power_req_len -= 4;
785 offset += 4;
787 offset += power_req_len;
788 break;
790 case TYPE_POWER_AVAILABLE:
791 tlvi = NULL;
792 if (tree) {
793 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
794 offset, length, ett_cdp_tlv, &tlvi,
795 "Power Available");
796 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
797 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
798 proto_tree_add_item(tlv_tree, hf_cdp_request_id, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
799 proto_tree_add_item(tlv_tree, hf_cdp_management_id, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
801 power_avail_len = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
802 if (power_avail_len < 8) {
803 offset += power_avail_len;
804 break;
806 power_avail_len -= 8;
807 /* Move offset to where the list of Power Available Values Exist */
808 offset += 8;
809 first = true;
810 while (power_avail_len >= 4) {
811 proto_tree_add_item_ret_uint(tlv_tree, hf_cdp_power_available, tvb, offset, 4, ENC_BIG_ENDIAN, &power_avail);
812 if (first) {
813 proto_item_append_text(tlvi, ": %u mW", power_avail);
814 first = false;
815 } else
816 proto_item_append_text(tlvi, ", %u mW", power_avail);
817 power_avail_len -= 4;
818 offset += 4;
820 offset += power_avail_len;
821 break;
823 case TYPE_NRGYZ:
824 if (tree) {
825 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
826 offset, length, ett_cdp_tlv, NULL, "EnergyWise");
827 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
828 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
829 proto_tree_add_item(tlv_tree, hf_cdp_encrypted_data, tvb, offset + 4, 20, ENC_NA);
830 proto_tree_add_item(tlv_tree, hf_cdp_seen_sequence, tvb, offset + 24, 4, ENC_BIG_ENDIAN);
831 proto_tree_add_item(tlv_tree, hf_cdp_sequence_number, tvb, offset + 28, 4, ENC_BIG_ENDIAN);
832 proto_tree_add_item(tlv_tree, hf_cdp_model_number, tvb, offset + 32, 16, ENC_NA|ENC_ASCII);
833 proto_tree_add_item(tlv_tree, hf_cdp_unknown_pad, tvb, offset + 48, 2, ENC_BIG_ENDIAN);
834 proto_tree_add_item(tlv_tree, hf_cdp_hardware_version_id, tvb, offset + 50, 3, ENC_NA|ENC_ASCII);
835 proto_tree_add_item(tlv_tree, hf_cdp_system_serial_number, tvb, offset + 53, 11, ENC_NA|ENC_ASCII);
836 proto_tree_add_item(tlv_tree, hf_cdp_nrgyz_unknown_values, tvb, offset + 64, 8, ENC_NA);
837 proto_tree_add_item(tlv_tree, hf_cdp_len_tlv_table, tvb, offset + 72, 2, ENC_BIG_ENDIAN);
838 proto_tree_add_item(tlv_tree, hf_cdp_num_tlvs_table, tvb, offset + 74, 2, ENC_BIG_ENDIAN);
840 dissect_nrgyz_tlv(tvb, pinfo, offset + 76,
841 tvb_get_ntohs(tvb, offset + 72),
842 tvb_get_ntohs(tvb, offset + 74),
843 tlv_tree);
847 offset += length;
848 break;
850 case TYPE_SPARE_POE:
851 if (tree) {
852 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb, offset, length,
853 ett_cdp_tlv, NULL, "Spare Pair PoE");
855 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
856 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
858 offset += 4;
859 length -= 4;
860 dissect_spare_poe_tlv(tvb, offset, length, tlv_tree);
861 offset += length;
862 break;
864 case TYPE_HP_BSSID:
865 /* BSSID */
866 if (tree) {
867 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
868 offset, length, ett_cdp_tlv, NULL, "BSSID: %s",
869 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
870 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
871 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
872 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
874 offset += length;
875 break;
877 case TYPE_HP_SERIAL:
878 /* Serial number */
879 if (tree) {
880 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
881 offset, length, ett_cdp_tlv, NULL, "Serial: %s",
882 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
883 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
884 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
885 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
887 offset += length;
888 break;
890 case TYPE_HP_SSID:
891 /* SSID */
892 if (tree) {
893 if (length == 4) {
894 tlv_tree = proto_tree_add_subtree(cdp_tree, tvb,
895 offset, length, ett_cdp_tlv, NULL, "SSID: [Empty]");
896 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
897 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
898 } else {
899 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
900 offset, length, ett_cdp_tlv, NULL, "SSID: %s",
901 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
902 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
903 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
904 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
907 offset += length;
908 break;
910 case TYPE_HP_RADIO1_CH:
911 /* Radio1 channel */
912 if (tree) {
913 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
914 offset, length, ett_cdp_tlv, NULL, "Radio 1 channel: %s",
915 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
916 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
917 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
918 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
920 offset += length;
921 break;
923 case TYPE_HP_SNMP_PORT:
924 /* SNMP listening UDP port */
925 if (tree) {
926 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
927 offset, length, ett_cdp_tlv, NULL, "SNMP port: %s",
928 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
929 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
930 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
931 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
933 offset += length;
934 break;
936 case TYPE_HP_MGMT_PORT:
937 /* Web interface TCP port */
938 if (tree) {
939 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
940 offset, length, ett_cdp_tlv, NULL, "Web mgmt port: %s",
941 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
942 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
943 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
944 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
946 offset += length;
947 break;
949 case TYPE_HP_SOURCE_MAC:
950 /* Sender MAC address for the AP, bouth wired and wireless */
951 if (tree) {
952 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
953 offset, length, ett_cdp_tlv, NULL, "Source MAC: %s",
954 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
955 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
956 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
957 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
959 offset += length;
960 break;
962 case TYPE_HP_RADIO2_CH:
963 /* Radio2 channel */
964 if (tree) {
965 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
966 offset, length, ett_cdp_tlv, NULL, "Radio 2 channel: %s",
967 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
968 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
969 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
970 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
972 offset += length;
973 break;
975 case TYPE_HP_RADIO1_OMODE:
976 /* Radio1 Operating mode */
977 if (tree) {
978 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
979 offset, length, ett_cdp_tlv, NULL, "Radio 1 operating mode: %s",
980 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
981 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
982 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
983 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
985 offset += length;
986 break;
988 case TYPE_HP_RADIO2_OMODE:
989 /* Radio2 Operating mode */
990 if (tree) {
991 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
992 offset, length, ett_cdp_tlv, NULL, "Radio 2 operating mode: %s",
993 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
994 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
995 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
996 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
998 offset += length;
999 break;
1001 case TYPE_HP_RADIO1_RMODE:
1002 /* Radio1 Radio mode */
1003 if (tree) {
1004 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
1005 offset, length, ett_cdp_tlv, NULL, "Radio 1 radio mode: %s",
1006 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
1007 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
1008 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
1009 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
1011 offset += length;
1012 break;
1014 case TYPE_HP_RADIO2_RMODE:
1015 /* Radio2 Radio mode */
1016 if (tree) {
1017 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb,
1018 offset, length, ett_cdp_tlv, NULL, "Radio 2 radio mode: %s",
1019 tvb_format_text(pinfo->pool, tvb, offset + 4, length - 4));
1020 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
1021 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
1022 proto_tree_add_item(tlv_tree, hf_cdp_platform, tvb, offset + 4, length - 4, ENC_ASCII);
1024 offset += length;
1025 break;
1027 default:
1028 if (tree) {
1029 tlv_tree = proto_tree_add_subtree_format(cdp_tree, tvb, offset,
1030 length, ett_cdp_tlv, NULL, "Type: %s, length: %u",
1031 val_to_str(type, type_vals, "Unknown (0x%04x)"),
1032 length);
1033 proto_tree_add_item(tlv_tree, hf_cdp_tlvtype, tvb, offset + TLV_TYPE, 2, ENC_BIG_ENDIAN);
1034 proto_tree_add_item(tlv_tree, hf_cdp_tlvlength, tvb, offset + TLV_LENGTH, 2, ENC_BIG_ENDIAN);
1035 if (length > 4) {
1036 proto_tree_add_item(tlv_tree, hf_cdp_data, tvb, offset + 4, length - 4, ENC_NA);
1037 } else {
1038 return tvb_captured_length(tvb);
1041 offset += length;
1044 call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo, cdp_tree);
1045 return tvb_captured_length(tvb);
1048 #define PROTO_TYPE_NLPID 1
1049 #define PROTO_TYPE_IEEE_802_2 2
1051 static const value_string proto_type_vals[] = {
1052 { PROTO_TYPE_NLPID, "NLPID" },
1053 { PROTO_TYPE_IEEE_802_2, "802.2" },
1054 { 0, NULL }
1057 static int
1058 dissect_address_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, int length, proto_tree *tree)
1060 proto_item *ti;
1061 proto_tree *address_tree;
1062 uint8_t protocol_type;
1063 uint8_t protocol_length;
1064 int nlpid = 0;
1065 uint16_t address_length;
1066 uint16_t etypeid = 0;
1067 int hf_addr = 0;
1069 if (length < 1)
1070 return -1;
1071 address_tree = proto_tree_add_subtree(tree, tvb, offset, length, ett_cdp_address, &ti, "Truncated address");
1072 protocol_type = tvb_get_uint8(tvb, offset);
1073 proto_tree_add_item(address_tree, hf_cdp_protocol_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1074 offset += 1;
1075 length -= 1;
1077 if (length < 1)
1078 return -1;
1079 protocol_length = tvb_get_uint8(tvb, offset);
1080 proto_tree_add_item(address_tree, hf_cdp_protocol_length, tvb, offset, 1, ENC_BIG_ENDIAN);
1081 offset += 1;
1082 length -= 1;
1084 if (length < protocol_length) {
1085 if (length != 0) {
1086 ti = proto_tree_add_item(address_tree, hf_cdp_protocol, tvb, offset, length, ENC_NA);
1087 proto_item_append_text(ti, " (truncated)");
1089 return -1;
1092 if ((protocol_type == PROTO_TYPE_NLPID) && (protocol_length == 1)) {
1093 nlpid = tvb_get_uint8(tvb, offset);
1094 proto_tree_add_bytes_format_value(address_tree, hf_cdp_protocol, tvb, offset, protocol_length, NULL, "%s",
1095 val_to_str(nlpid, nlpid_vals, "Unknown (0x%02x)"));
1096 } else if ((protocol_type == PROTO_TYPE_IEEE_802_2) && (protocol_length == 8) && (tvb_get_ntoh48(tvb, offset) == 0xAAAA03000000)) {
1097 etypeid = tvb_get_ntohs(tvb, offset + 6);
1098 proto_tree_add_bytes_format_value(address_tree, hf_cdp_protocol, tvb, offset, protocol_length, NULL, "%s",
1099 val_to_str(etypeid, etype_vals, "Unknown (0x%04x)"));
1100 } else {
1101 nlpid = -1;
1102 proto_tree_add_item(address_tree, hf_cdp_protocol, tvb, offset, protocol_length, ENC_NA);
1104 offset += protocol_length;
1105 length -= protocol_length;
1107 if (length < 2)
1108 return -1;
1109 address_length = tvb_get_ntohs(tvb, offset);
1110 proto_tree_add_item(address_tree, hf_cdp_address_length, tvb, offset, 2, ENC_BIG_ENDIAN);
1111 offset += 2;
1112 length -= 2;
1114 if (length < address_length) {
1115 if (length != 0) {
1116 ti = proto_tree_add_item(address_tree, hf_cdp_address, tvb, offset, length, ENC_NA);
1117 proto_item_append_text(ti, " (truncated)");
1119 return -1;
1121 /* XXX - the Cisco document seems to be saying that, for 802.2-format
1122 protocol types, 0xAAAA03 0x000000 0x0800 is IPv6, but 0x0800 is
1123 the Ethernet protocol type for IPv4. */
1124 if ((protocol_type == PROTO_TYPE_NLPID) && (protocol_length == 1)) {
1125 switch (nlpid) {
1127 /* XXX - dissect NLPID_ISO8473_CLNP as OSI CLNP address? */
1129 case NLPID_IP:
1130 if (address_length == 4) {
1131 /* The address is an IP address. */
1132 proto_item_set_text(ti, "IP address: %s", tvb_ip_to_str(pinfo->pool, tvb, offset));
1133 hf_addr = hf_cdp_nrgyz_ip_address;
1134 proto_tree_add_item(address_tree, hf_cdp_nrgyz_ip_address, tvb, offset, address_length, ENC_BIG_ENDIAN);
1136 break;
1139 if ((protocol_type == PROTO_TYPE_IEEE_802_2) && (protocol_length == 8) && (etypeid > 0)) {
1141 * See also:
1143 * http://www.rhyshaden.com/cdp.htm
1145 * where other Ethertypes are mentioned.
1147 switch (etypeid) {
1149 case ETHERTYPE_IPv6:
1150 if (address_length == 16) {
1151 /* The address is an IPv6 address. */
1152 proto_item_set_text(ti, "IPv6 address: %s", tvb_ip6_to_str(pinfo->pool, tvb, offset));
1153 hf_addr = hf_cdp_nrgyz_ip6_address;
1154 proto_tree_add_item(address_tree, hf_cdp_nrgyz_ip6_address, tvb, offset, address_length, ENC_NA);
1156 break;
1160 if (hf_addr == 0)
1162 proto_tree_add_item(address_tree, hf_cdp_address, tvb, offset, address_length, ENC_NA);
1163 if(address_length)
1165 proto_item_set_text(ti, "Address: %s", tvb_bytes_to_str(pinfo->pool, tvb, offset, address_length));
1169 return 2 + protocol_length + 2 + address_length;
1172 static void
1173 dissect_capabilities(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
1175 proto_item *ti;
1176 proto_tree *capabilities_tree;
1178 if (length < 4)
1179 return;
1180 ti = proto_tree_add_item(tree, hf_cdp_capabilities, tvb, offset, 4, ENC_BIG_ENDIAN);
1181 capabilities_tree = proto_item_add_subtree(ti, ett_cdp_capabilities);
1182 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_router, tvb, offset, 4, ENC_BIG_ENDIAN);
1183 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_trans_bridge, tvb, offset, 4, ENC_BIG_ENDIAN);
1184 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_src_bridge, tvb, offset, 4, ENC_BIG_ENDIAN);
1185 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_switch, tvb, offset, 4, ENC_BIG_ENDIAN);
1186 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_host, tvb, offset, 4, ENC_BIG_ENDIAN);
1187 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_igmp_capable, tvb, offset, 4, ENC_BIG_ENDIAN);
1188 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_repeater, tvb, offset, 4, ENC_BIG_ENDIAN);
1189 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_voip_phone , tvb, offset, 4, ENC_BIG_ENDIAN);
1190 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_remote, tvb, offset, 4, ENC_BIG_ENDIAN);
1191 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_cvta, tvb, offset, 4, ENC_BIG_ENDIAN);
1192 proto_tree_add_item(capabilities_tree, hf_cdp_capabilities_mac_relay, tvb, offset, 4, ENC_BIG_ENDIAN);
1195 static void
1196 dissect_nrgyz_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, uint16_t length, uint16_t num,
1197 proto_tree *tree)
1199 uint32_t tlvt, tlvl;
1200 proto_tree *etree = NULL;
1201 char const *ttext = NULL;
1203 while (num-- && (length >= 8)) {
1204 tlvt = tvb_get_ntohl(tvb, offset);
1205 tlvl = tvb_get_ntohl(tvb, offset + 4);
1207 if (length < tlvl)
1208 break;
1209 length -= tlvl;
1211 if (tlvl < 8) {
1212 proto_tree_add_expert_format(tree, pinfo, &ei_cdp_nrgyz_tlvlength, tvb, offset, 8, "TLV with invalid length %u (< 8)", tlvl);
1213 offset += 8;
1214 break;
1216 else {
1217 ttext = val_to_str(tlvt, type_nrgyz_vals, "Unknown (0x%04x)");
1218 switch (tlvt) {
1219 case TYPE_NRGYZ_ROLE:
1220 case TYPE_NRGYZ_DOMAIN:
1221 case TYPE_NRGYZ_NAME:
1222 etree = proto_tree_add_subtree_format(tree, tvb, offset,
1223 tlvl, ett_cdp_nrgyz_tlv, NULL, "EnergyWise %s: %s", ttext,
1224 tvb_format_stringzpad(pinfo->pool, tvb, offset + 8, tlvl - 8)
1226 break;
1227 case TYPE_NRGYZ_REPLYTO:
1228 etree = proto_tree_add_subtree_format(tree, tvb, offset,
1229 tlvl, ett_cdp_nrgyz_tlv, NULL, "EnergyWise %s: %s port %u",
1230 ttext,
1231 tvb_ip_to_str(pinfo->pool, tvb, offset + 12),
1232 tvb_get_ntohs(tvb, offset + 10)
1234 break;
1235 default:
1236 etree = proto_tree_add_subtree_format(tree, tvb, offset,
1237 tlvl, ett_cdp_nrgyz_tlv, NULL, "EnergyWise %s TLV", ttext);
1239 proto_tree_add_item(etree, hf_cdp_nrgyz_tlvtype, tvb, offset, 4, ENC_BIG_ENDIAN);
1240 proto_tree_add_item(etree, hf_cdp_nrgyz_tlvlength, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
1241 switch (tlvt) {
1242 case TYPE_NRGYZ_ROLE:
1243 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_role, tvb, offset + 8, tlvl - 8, ENC_NA|ENC_ASCII);
1244 break;
1245 case TYPE_NRGYZ_DOMAIN:
1246 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_domain, tvb, offset + 8, tlvl - 8, ENC_NA|ENC_ASCII);
1247 break;
1248 case TYPE_NRGYZ_NAME:
1249 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_name, tvb, offset + 8, tlvl - 8, ENC_NA|ENC_ASCII);
1250 break;
1251 case TYPE_NRGYZ_REPLYTO:
1252 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_unknown_field, tvb, offset + 8, 2, ENC_BIG_ENDIAN);
1253 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_port, tvb, offset + 10, 2, ENC_BIG_ENDIAN);
1254 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_ip_address, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
1255 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_backup_server_port, tvb, offset + 16, 2, ENC_BIG_ENDIAN);
1256 proto_tree_add_item(etree, hf_cdp_nrgyz_reply_to_backup_server_ip, tvb, offset + 18, 4, ENC_BIG_ENDIAN);
1257 break;
1258 default:
1259 if (tlvl > 8) {
1260 proto_tree_add_item(etree, hf_cdp_data, tvb, offset + 8, tlvl - 8, ENC_NA);
1263 offset += tlvl;
1266 if (length) {
1267 proto_tree_add_expert(tree, pinfo, &ei_cdp_invalid_data, tvb, offset, length);
1271 static void
1272 dissect_spare_poe_tlv(tvbuff_t *tvb, int offset, int length,
1273 proto_tree *tree)
1275 proto_item *ti;
1276 proto_tree *tlv_tree;
1278 if (length == 0) {
1279 return;
1282 ti = proto_tree_add_item(tree, hf_cdp_spare_poe_tlv, tvb, offset, 1, ENC_BIG_ENDIAN);
1283 tlv_tree = proto_item_add_subtree(ti, ett_cdp_spare_poe_tlv);
1284 proto_tree_add_item(tlv_tree, hf_cdp_spare_poe_tlv_poe, tvb, offset, 1, ENC_BIG_ENDIAN);
1285 proto_tree_add_item(tlv_tree, hf_cdp_spare_poe_tlv_spare_pair_arch, tvb, offset, 1, ENC_BIG_ENDIAN);
1286 proto_tree_add_item(tlv_tree, hf_cdp_spare_poe_tlv_req_spare_pair_poe, tvb, offset, 1, ENC_BIG_ENDIAN);
1287 proto_tree_add_item(tlv_tree, hf_cdp_spare_poe_tlv_pse_spare_pair_poe, tvb, offset, 1, ENC_BIG_ENDIAN);
1290 static void
1291 add_multi_line_string_to_tree(wmem_allocator_t *scope, proto_tree *tree, tvbuff_t *tvb, int start,
1292 int len, int hf)
1294 int next;
1295 int line_len;
1296 int data_len;
1298 while (len > 0) {
1299 line_len = tvb_find_line_end(tvb, start, len, &next, false);
1300 data_len = next - start;
1301 proto_tree_add_string(tree, hf, tvb, start, data_len, tvb_format_stringzpad(scope, tvb, start, line_len));
1302 start += data_len;
1303 len -= data_len;
1307 void
1308 proto_register_cdp(void)
1310 static hf_register_info hf[] = {
1311 { &hf_cdp_version,
1312 { "Version", "cdp.version", FT_UINT8, BASE_DEC, NULL, 0x0,
1313 NULL, HFILL }},
1315 { &hf_cdp_ttl,
1316 { "TTL", "cdp.ttl", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_second_seconds), 0x0,
1317 NULL, HFILL }},
1319 { &hf_cdp_checksum,
1320 { "Checksum", "cdp.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
1321 NULL, HFILL }},
1323 { &hf_cdp_checksum_status,
1324 { "Checksum Status", "cdp.checksum.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
1325 NULL, HFILL }},
1327 { &hf_cdp_tlvtype,
1328 { "Type", "cdp.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
1329 NULL, HFILL }},
1331 { &hf_cdp_tlvlength,
1332 { "Length", "cdp.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
1333 NULL, HFILL }},
1335 { &hf_cdp_nrgyz_tlvtype,
1336 { "TLV Type", "cdp.nrgyz.tlv.type", FT_UINT32, BASE_HEX, VALS(type_nrgyz_vals), 0x0,
1337 NULL, HFILL }},
1339 { &hf_cdp_nrgyz_tlvlength,
1340 { "TLV Length", "cdp.nrgyz.tlv.len", FT_UINT32, BASE_DEC, NULL, 0x0,
1341 NULL, HFILL }},
1343 { &hf_cdp_deviceid,
1344 {"Device ID", "cdp.deviceid", FT_STRING, BASE_NONE,
1345 NULL, 0, NULL, HFILL }},
1347 { &hf_cdp_platform,
1348 {"Platform", "cdp.platform", FT_STRING, BASE_NONE,
1349 NULL, 0, NULL, HFILL }},
1351 { &hf_cdp_portid,
1352 {"Sent through Interface", "cdp.portid", FT_STRING, BASE_NONE,
1353 NULL, 0, NULL, HFILL }},
1355 { &hf_cdp_capabilities,
1356 {"Capabilities", "cdp.capabilities", FT_UINT32, BASE_HEX,
1357 NULL, 0, NULL, HFILL }},
1359 { &hf_cdp_capabilities_router,
1360 {"Router", "cdp.capabilities.router", FT_BOOLEAN, 32,
1361 TFS(&tfs_yes_no), 0x00000001, NULL, HFILL }},
1363 { &hf_cdp_capabilities_trans_bridge,
1364 {"Transparent Bridge", "cdp.capabilities.trans_bridge", FT_BOOLEAN, 32,
1365 TFS(&tfs_yes_no), 0x00000002, NULL, HFILL }},
1367 { &hf_cdp_capabilities_src_bridge,
1368 {"Source Route Bridge", "cdp.capabilities.src_bridge", FT_BOOLEAN, 32,
1369 TFS(&tfs_yes_no), 0x00000004, NULL, HFILL }},
1371 { &hf_cdp_capabilities_switch,
1372 {"Switch", "cdp.capabilities.switch", FT_BOOLEAN, 32,
1373 TFS(&tfs_yes_no), 0x00000008, NULL, HFILL }},
1375 { &hf_cdp_capabilities_host,
1376 {"Host", "cdp.capabilities.host", FT_BOOLEAN, 32,
1377 TFS(&tfs_yes_no), 0x00000010, NULL, HFILL }},
1379 { &hf_cdp_capabilities_igmp_capable,
1380 {"IGMP capable", "cdp.capabilities.igmp_capable", FT_BOOLEAN, 32,
1381 TFS(&tfs_yes_no), 0x00000020, NULL, HFILL }},
1383 { &hf_cdp_capabilities_repeater,
1384 {"Repeater", "cdp.capabilities.repeater", FT_BOOLEAN, 32,
1385 TFS(&tfs_yes_no), 0x00000040, NULL, HFILL }},
1387 { &hf_cdp_capabilities_voip_phone,
1388 {"VoIP Phone", "cdp.capabilities.voip_phone", FT_BOOLEAN, 32,
1389 TFS(&tfs_yes_no), 0x00000080, NULL, HFILL }},
1391 { &hf_cdp_capabilities_remote,
1392 {"Remotely Managed Device", "cdp.capabilities.remote", FT_BOOLEAN, 32,
1393 TFS(&tfs_yes_no), 0x00000100, NULL, HFILL }},
1395 { &hf_cdp_capabilities_cvta,
1396 {"CVTA/STP Dispute Resolution/Cisco VT Camera", "cdp.capabilities.cvta", FT_BOOLEAN, 32,
1397 TFS(&tfs_yes_no), 0x00000200, NULL, HFILL }},
1399 { &hf_cdp_capabilities_mac_relay,
1400 {"Two Port Mac Relay", "cdp.capabilities.mac_relay", FT_BOOLEAN, 32,
1401 TFS(&tfs_yes_no), 0x00000400, NULL, HFILL }},
1403 { &hf_cdp_spare_poe_tlv,
1404 { "Spare Pair PoE", "cdp.spare_poe_tlv", FT_UINT8, BASE_HEX,
1405 NULL, 0x0, NULL, HFILL }
1408 { &hf_cdp_spare_poe_tlv_poe,
1409 { "PSE Four-Wire PoE", "cdp.spare_poe_tlv.poe", FT_BOOLEAN, 8,
1410 TFS(&tfs_supported_not_supported), 0x01, NULL, HFILL }
1413 { &hf_cdp_spare_poe_tlv_spare_pair_arch,
1414 { "PD Spare Pair Architecture", "cdp.spare_poe_tlv.spare_pair_arch", FT_BOOLEAN, 8,
1415 TFS(&tfs_shared_independent), 0x02, NULL, HFILL }
1418 { &hf_cdp_spare_poe_tlv_req_spare_pair_poe,
1419 { "PD Request Spare Pair PoE", "cdp.spare_poe_tlv.req_spare_pair_poe", FT_BOOLEAN, 8,
1420 TFS(&tfs_on_off), 0x04, NULL, HFILL }
1423 { &hf_cdp_spare_poe_tlv_pse_spare_pair_poe,
1424 { "PSE Spare Pair PoE", "cdp.spare_poe_tlv.pse_spare_pair_poe", FT_BOOLEAN, 8,
1425 TFS(&tfs_on_off), 0x08, NULL, HFILL }
1428 /* Generated from convert_proto_tree_add_text.pl */
1429 { &hf_cdp_number_of_addresses, { "Number of addresses", "cdp.number_of_addresses", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1430 { &hf_cdp_odr_default_gateway, { "ODR Default gateway", "cdp.odr_default_gateway", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1431 { &hf_cdp_ip_prefix, { "IP Prefix", "cdp.ip_prefix", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1432 { &hf_cdp_oui, { "OUI", "cdp.oui", FT_UINT24, BASE_OUI, NULL, 0x0, NULL, HFILL }},
1433 { &hf_cdp_protocol_id, { "Protocol ID", "cdp.protocol_id", FT_UINT16, BASE_HEX, VALS(type_hello_vals), 0x0, NULL, HFILL }},
1434 { &hf_cdp_cluster_master_ip, { "Cluster Master IP", "cdp.cluster.master_ip", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1435 { &hf_cdp_cluster_ip, { "IP?", "cdp.cluster.ip", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1436 { &hf_cdp_cluster_version, { "Version?", "cdp.cluster.version", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1437 { &hf_cdp_cluster_sub_version, { "Sub Version?", "cdp.cluster.sub_version", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1438 { &hf_cdp_cluster_status, { "Status?", "cdp.cluster.status", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1439 { &hf_cdp_cluster_unknown, { "UNKNOWN", "cdp.cluster.unknown", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1440 { &hf_cdp_cluster_commander_mac, { "Cluster Commander MAC", "cdp.cluster.commander_mac", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1441 { &hf_cdp_cluster_switch_mac, { "Switch's MAC", "cdp.cluster.switch_mac", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1442 { &hf_cdp_cluster_management_vlan, { "Management VLAN", "cdp.cluster.management_vlan", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1443 { &hf_cdp_hello_unknown, { "Unknown", "cdp.hello.unknown", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1444 { &hf_cdp_vtp_management_domain, { "VTP Management Domain", "cdp.vtp_management_domain", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1445 { &hf_cdp_native_vlan, { "Native VLAN", "cdp.native_vlan", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1446 { &hf_cdp_duplex, { "Duplex", "cdp.duplex", FT_BOOLEAN, BASE_NONE, TFS(&tfs_full_half), 0x0, NULL, HFILL }},
1447 { &hf_cdp_data, { "Data", "cdp.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1448 { &hf_cdp_voice_vlan, { "Voice VLAN", "cdp.voice_vlan", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1449 { &hf_cdp_power_consumption, { "Power Consumption", "cdp.power_consumption", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_mw), 0x0, NULL, HFILL }},
1450 { &hf_cdp_mtu, { "MTU", "cdp.mtu", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1451 { &hf_cdp_trust_bitmap, { "Trust Bitmap", "cdp.trust_bitmap", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1452 { &hf_cdp_untrusted_port_cos, { "Untrusted port CoS", "cdp.untrusted_port_cos", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1453 { &hf_cdp_system_name, { "System Name", "cdp.system_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1454 { &hf_cdp_system_object_identifier, { "System Object Identifier", "cdp.system_object_identifier", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1455 { &hf_cdp_location_unknown, { "UNKNOWN", "cdp.location.unknown", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1456 { &hf_cdp_location, { "Location", "cdp.location", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1457 { &hf_cdp_request_id, { "Request-ID", "cdp.request_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1458 { &hf_cdp_management_id, { "Management-ID", "cdp.management_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1459 { &hf_cdp_power_requested, { "Power Requested", "cdp.power_requested", FT_UINT32, BASE_DEC|BASE_UNIT_STRING, UNS(&units_mw), 0x0, NULL, HFILL }},
1460 { &hf_cdp_power_available, { "Power Available", "cdp.power_available", FT_UINT32, BASE_DEC|BASE_UNIT_STRING, UNS(&units_mw), 0x0, NULL, HFILL }},
1461 { &hf_cdp_encrypted_data, { "Encrypted Data", "cdp.encrypted_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1462 { &hf_cdp_seen_sequence, { "Seen Sequence?", "cdp.seen_sequence", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1463 { &hf_cdp_sequence_number, { "Sequence Number", "cdp.sequence_number", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1464 { &hf_cdp_model_number, { "Model Number", "cdp.model_number", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1465 { &hf_cdp_unknown_pad, { "Unknown Pad", "cdp.unknown_pad", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1466 { &hf_cdp_hardware_version_id, { "Hardware Version ID", "cdp.hardware_version_id", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1467 { &hf_cdp_system_serial_number, { "System Serial Number", "cdp.system_serial_number", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1468 { &hf_cdp_nrgyz_unknown_values, { "Unknown Values", "cdp.nrgyz_unknown_values", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1469 { &hf_cdp_len_tlv_table, { "Length of TLV table", "cdp.len_tlv_table", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1470 { &hf_cdp_num_tlvs_table, { "Number of TLVs in table", "cdp.num_tlvs_table", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1471 { &hf_cdp_protocol, { "Protocol", "cdp.protocol", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1472 { &hf_cdp_protocol_type, { "Protocol type", "cdp.protocol_type", FT_UINT8, BASE_HEX, VALS(proto_type_vals), 0x0, NULL, HFILL }},
1473 { &hf_cdp_protocol_length, { "Protocol length", "cdp.protocol_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1474 { &hf_cdp_address, { "Address", "cdp.address", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1475 { &hf_cdp_address_length, { "Address length", "cdp.address_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1476 { &hf_cdp_nrgyz_reply_to_unknown_field, { "Unknown Field", "cdp.nrgyz_reply_to.unknown_field", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1477 { &hf_cdp_nrgyz_reply_to_port, { "Port", "cdp.nrgyz_reply_to.port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1478 { &hf_cdp_nrgyz_ip_address, { "IP Address", "cdp.nrgyz.ip_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1479 { &hf_cdp_nrgyz_ip6_address, { "IPv6 Address", "cdp.nrgyz.ipv6_address", FT_IPv6, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1480 { &hf_cdp_nrgyz_reply_to_ip_address, { "IP Address", "cdp.nrgyz_reply_to.ip_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1481 { &hf_cdp_nrgyz_reply_to_backup_server_port, { "Backup server Port?", "cdp.nrgyz_reply_to.backup_server_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1482 { &hf_cdp_nrgyz_reply_to_backup_server_ip, { "Backup Server IP?", "cdp.nrgyz_reply_to.backup_server_ip", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1483 { &hf_cdp_nrgyz_reply_to_name, { "Name", "cdp.nrgyz_reply_to.name", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1484 { &hf_cdp_nrgyz_reply_to_domain, { "Domain", "cdp.nrgyz_reply_to.domain", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1485 { &hf_cdp_nrgyz_reply_to_role, { "Role", "cdp.nrgyz_reply_to.role", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1486 { &hf_cdp_software_version, { "Software version", "cdp.software_version", FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1489 static int *ett[] = {
1490 &ett_cdp,
1491 &ett_cdp_tlv,
1492 &ett_cdp_nrgyz_tlv,
1493 &ett_cdp_address,
1494 &ett_cdp_capabilities,
1495 &ett_cdp_checksum,
1496 &ett_cdp_spare_poe_tlv
1499 static ei_register_info ei[] = {
1500 { &ei_cdp_invalid_data, { "cdp.invalid_data", PI_MALFORMED, PI_ERROR, "Invalid bytes at end", EXPFILL }},
1501 { &ei_cdp_nrgyz_tlvlength, { "cdp.nrgyz_tlv.length.invalid", PI_MALFORMED, PI_ERROR, "TLV with invalid length", EXPFILL }},
1502 { &ei_cdp_checksum, { "cdp.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
1505 expert_module_t* expert_cdp;
1507 proto_cdp = proto_register_protocol("Cisco Discovery Protocol", "CDP", "cdp");
1508 cdp_handle = register_dissector("cdp", dissect_cdp, proto_cdp);
1510 proto_register_field_array(proto_cdp, hf, array_length(hf));
1511 proto_register_subtree_array(ett, array_length(ett));
1512 expert_cdp = expert_register_protocol(proto_cdp);
1513 expert_register_field_array(expert_cdp, ei, array_length(ei));
1516 void
1517 proto_reg_handoff_cdp(void)
1519 dissector_add_uint("llc.cisco_pid", CISCO_PID_CDP, cdp_handle);
1520 dissector_add_uint("chdlc.protocol", 0x2000, cdp_handle);
1521 dissector_add_uint("ppp.protocol", 0x0207, cdp_handle);
1522 dissector_add_uint("gre.proto", 0x2000, cdp_handle);
1526 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1528 * Local variables:
1529 * c-basic-offset: 4
1530 * tab-width: 8
1531 * indent-tabs-mode: nil
1532 * End:
1534 * vi: set shiftwidth=4 tabstop=8 expandtab:
1535 * :indentSize=4:tabSize=8:noTabs=true: