2 * Routines for the disassembly of Foundry LLC messages (currently
3 * Foundry Discovery Protocol - FDP only)
5 * Copyright 2012 Joerg Mayer (see AUTHORS file)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include <epan/expert.h>
30 #include <epan/strutil.h>
31 #include "packet-llc.h"
34 void proto_register_fdp(void);
35 void proto_reg_handoff_fdp(void);
37 static int hf_llc_foundry_pid = -1;
39 static int proto_fdp = -1;
41 static int hf_fdp_version = -1;
42 static int hf_fdp_holdtime = -1;
43 static int hf_fdp_checksum = -1;
45 static int hf_fdp_tlv_type = -1;
46 static int hf_fdp_tlv_length = -1;
48 static int hf_fdp_unknown = -1;
49 static int hf_fdp_unknown_data = -1;
50 /* Port Tag element */
51 static int hf_fdp_tag = -1;
52 static int hf_fdp_tag_native = -1;
53 static int hf_fdp_tag_type = -1;
54 static int hf_fdp_tag_unknown = -1;
56 static int hf_fdp_vlanmap = -1;
57 static int hf_fdp_vlanmap_vlan = -1;
59 static int hf_fdp_string = -1;
60 static int hf_fdp_string_data = -1;
61 static int hf_fdp_string_text = -1;
63 static int hf_fdp_net = -1;
64 static int hf_fdp_net_unknown = -1;
65 static int hf_fdp_net_ip = -1;
66 static int hf_fdp_net_iplength = -1;
68 static gint ett_fdp = -1;
69 static gint ett_fdp_tlv_header = -1;
70 static gint ett_fdp_unknown = -1;
71 static gint ett_fdp_string = -1;
72 static gint ett_fdp_net = -1;
73 static gint ett_fdp_tag = -1;
74 static gint ett_fdp_vlanmap = -1;
76 static expert_field ei_fdp_tlv_length = EI_INIT;
78 #define PROTO_SHORT_NAME "FDP"
79 #define PROTO_LONG_NAME "Foundry Discovery Protocol"
81 static const value_string foundry_pid_vals[] = {
91 FDP_TYPE_CAPABILITIES = 4,
94 FDP_TYPE_VLANMAP = 0x0101,
98 static const value_string fdp_type_vals[] = {
99 { FDP_TYPE_NAME, "DeviceID"},
100 { FDP_TYPE_NET, "Net?"},
101 { FDP_TYPE_PORT, "Interface"},
102 { FDP_TYPE_CAPABILITIES, "Capabilities"},
103 { FDP_TYPE_VERSION, "Version"},
104 { FDP_TYPE_MODEL, "Platform"},
105 { FDP_TYPE_VLANMAP, "VLAN-Bitmap"},
106 { FDP_TYPE_TAG, "Tagging-Info"},
112 dissect_tlv_header(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, int length _U_, proto_tree *tree)
114 proto_tree *tlv_tree;
118 tlv_type = tvb_get_ntohs(tvb, offset);
119 tlv_length = tvb_get_ntohs(tvb, offset + 2);
121 tlv_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4,
122 ett_fdp_tlv_header, NULL, "Length %d, type %d = %s",
123 tlv_length, tlv_type,
124 val_to_str(tlv_type, fdp_type_vals, "Unknown (%d)"));
126 proto_tree_add_uint(tlv_tree, hf_fdp_tlv_type, tvb, offset, 2, tlv_type);
129 proto_tree_add_uint(tlv_tree, hf_fdp_tlv_length, tvb, offset, 2, tlv_length);
136 dissect_string_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree, const char* type_string)
138 proto_item *string_item;
139 proto_tree *string_tree;
140 guint8 *string_value;
142 string_item = proto_tree_add_protocol_format(tree, hf_fdp_string,
143 tvb, offset, length, "%s", type_string);
145 string_tree = proto_item_add_subtree(string_item, ett_fdp_string);
147 dissect_tlv_header(tvb, pinfo, offset, 4, string_tree);
151 string_value = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, length, ENC_ASCII);
152 proto_item_append_text(string_item, ": \"%s\"",
153 format_text(string_value, strlen(string_value)));
155 proto_tree_add_item(string_tree, hf_fdp_string_data, tvb, offset, length, ENC_NA);
156 proto_tree_add_item(string_tree, hf_fdp_string_text, tvb, offset, length, ENC_ASCII|ENC_NA);
162 dissect_net_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree)
164 proto_item *net_item;
165 proto_tree *net_tree;
167 net_item = proto_tree_add_protocol_format(tree, hf_fdp_net,
168 tvb, offset, length, "Net?");
170 net_tree = proto_item_add_subtree(net_item, ett_fdp_net);
172 dissect_tlv_header(tvb, pinfo, offset, 4, net_tree);
176 proto_tree_add_item(net_tree, hf_fdp_net_unknown, tvb, offset, 7, ENC_NA);
180 /* Length of IP address block in bytes */
181 proto_tree_add_item(net_tree, hf_fdp_net_iplength, tvb, offset, 2, ENC_BIG_ENDIAN);
185 while (length >= 4) {
186 proto_tree_add_item(net_tree, hf_fdp_net_ip, tvb, offset, 4, ENC_NA);
193 dissect_vlanmap_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree)
195 proto_item *vlanmap_item;
196 proto_tree *vlanmap_tree;
198 guint bitoffset, byteoffset;
200 vlanmap_item = proto_tree_add_protocol_format(tree, hf_fdp_vlanmap,
201 tvb, offset, length, "VLAN-Map");
203 vlanmap_tree = proto_item_add_subtree(vlanmap_item, ett_fdp_vlanmap);
205 dissect_tlv_header(tvb, pinfo, offset, 4, vlanmap_tree);
210 for (vlan = 1; vlan <= (guint)length*8; vlan++) {
211 byteoffset = (vlan - voffset) / 8;
212 bitoffset = (vlan - voffset) % 8;
213 if (tvb_get_guint8(tvb, offset + byteoffset) & (1 << bitoffset)) {
215 proto_tree_add_uint(vlanmap_tree, hf_fdp_vlanmap_vlan, tvb,
216 offset + byteoffset, 1, vlan);
222 dissect_tag_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree)
224 proto_item *tag_item;
225 proto_tree *tag_tree;
227 tag_item = proto_tree_add_protocol_format(tree, hf_fdp_tag,
228 tvb, offset, length, "Port tag");
230 tag_tree = proto_item_add_subtree(tag_item, ett_fdp_tag);
232 dissect_tlv_header(tvb, pinfo, offset, 4, tag_tree);
235 proto_tree_add_item(tag_tree, hf_fdp_tag_native, tvb, offset, 2, ENC_BIG_ENDIAN);
238 proto_tree_add_item(tag_tree, hf_fdp_tag_type, tvb, offset, 2, ENC_BIG_ENDIAN);
241 proto_tree_add_item(tag_tree, hf_fdp_tag_unknown, tvb, offset, length, ENC_NA);
245 dissect_unknown_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree)
247 proto_item *unknown_item;
248 proto_tree *unknown_tree;
251 tlv_type = tvb_get_ntohs(tvb, offset);
253 unknown_item = proto_tree_add_protocol_format(tree, hf_fdp_unknown,
254 tvb, offset, length, "Unknown element [%u]", tlv_type);
256 unknown_tree = proto_item_add_subtree(unknown_item, ett_fdp_unknown);
258 dissect_tlv_header(tvb, pinfo, offset, 4, unknown_tree);
262 proto_tree_add_item(unknown_tree, hf_fdp_unknown_data, tvb, offset, length, ENC_NA);
266 dissect_fdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
269 proto_tree *fdp_tree = NULL;
274 const char *type_string;
276 col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_SHORT_NAME);
277 col_set_str(pinfo->cinfo, COL_INFO, PROTO_SHORT_NAME ":");
280 data_length = tvb_reported_length_remaining(tvb, offset);
282 ti = proto_tree_add_item(tree, proto_fdp, tvb, offset, -1, ENC_NA);
283 fdp_tree = proto_item_add_subtree(ti, ett_fdp);
285 proto_tree_add_item(fdp_tree, hf_fdp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
287 proto_tree_add_item(fdp_tree, hf_fdp_holdtime, tvb, offset, 1, ENC_BIG_ENDIAN);
289 proto_tree_add_item(fdp_tree, hf_fdp_checksum, tvb, offset, 2, ENC_BIG_ENDIAN);
292 /* Decode the individual TLVs */
293 while (offset < data_length) {
294 if (data_length - offset < 4) {
295 proto_tree_add_expert_format(fdp_tree, pinfo, &ei_fdp_tlv_length, tvb, offset, 4,
296 "Too few bytes left for TLV: %u (< 4)", data_length - offset);
299 tlv_type = tvb_get_ntohs(tvb, offset);
300 tlv_length = tvb_get_ntohs(tvb, offset + 2);
302 if ((tlv_length < 4) || (tlv_length > (data_length - offset))) {
303 proto_tree_add_expert_format(fdp_tree, pinfo, &ei_fdp_tlv_length, tvb, offset, 0,
304 "TLV with invalid length: %u", tlv_length);
307 type_string = val_to_str(tlv_type, fdp_type_vals, "[%u]");
308 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", type_string);
313 case FDP_TYPE_CAPABILITIES:
314 case FDP_TYPE_VERSION:
316 dissect_string_tlv(tvb, pinfo, offset, tlv_length, fdp_tree, type_string);
319 dissect_net_tlv(tvb, pinfo, offset, tlv_length, fdp_tree);
322 dissect_tag_tlv(tvb, pinfo, offset, tlv_length, fdp_tree);
324 case FDP_TYPE_VLANMAP:
325 dissect_vlanmap_tlv(tvb, pinfo, offset, tlv_length, fdp_tree);
328 dissect_unknown_tlv(tvb, pinfo, offset, tlv_length, fdp_tree);
331 offset += tlv_length;
335 return tvb_captured_length(tvb);
339 proto_register_fdp(void)
341 static hf_register_info hf[] = {
345 { "Version?", "fdp.version", FT_UINT8, BASE_DEC, NULL,
349 { "Holdtime", "fdp.holdtime", FT_UINT8, BASE_DEC, NULL,
353 { "Checksum?", "fdp.checksum", FT_UINT16, BASE_HEX, NULL,
358 { "TLV type", "fdp.tlv.type", FT_UINT16, BASE_DEC, VALS(fdp_type_vals),
361 { &hf_fdp_tlv_length,
362 { "TLV length", "fdp.tlv.length", FT_UINT16, BASE_DEC, NULL,
365 /* Unknown element */
367 { "Unknown", "fdp.unknown", FT_PROTOCOL, BASE_NONE, NULL,
370 { &hf_fdp_unknown_data,
371 { "Unknown", "fdp.unknown.data", FT_BYTES, BASE_NONE, NULL,
376 { "DeviceID", "fdp.deviceid", FT_PROTOCOL, BASE_NONE, NULL,
379 { &hf_fdp_string_data,
380 { "Data", "fdp.string.data", FT_BYTES, BASE_NONE, NULL,
383 { &hf_fdp_string_text,
384 { "Text", "fdp.string.text", FT_STRING, BASE_NONE, NULL,
389 { "Net?", "fdp.net", FT_PROTOCOL, BASE_NONE, NULL,
392 { &hf_fdp_net_unknown,
393 { "Net Unknown?", "fdp.net.unknown", FT_BYTES, BASE_NONE, NULL,
396 { &hf_fdp_net_iplength,
397 { "Net IP Bytes?", "fdp.net.iplength", FT_UINT16, BASE_DEC, NULL,
398 0x0, "Number of bytes carrying IP addresses", HFILL }},
401 { "Net IP Address?", "fdp.net.ip", FT_IPv4, BASE_NONE, NULL,
406 { "VLAN Map", "fdp.vlanmap", FT_PROTOCOL, BASE_NONE, NULL,
409 { &hf_fdp_vlanmap_vlan,
410 { "VLAN", "fdp.vlanmap.vlan", FT_UINT16, BASE_DEC, NULL,
413 /* Port Tag element */
415 { "Tag", "fdp.tag", FT_PROTOCOL, BASE_NONE, NULL,
418 { &hf_fdp_tag_native,
419 { "Native", "fdp.tag.native", FT_UINT16, BASE_DEC, NULL,
423 { "Type", "fdp.tag.type", FT_UINT16, BASE_HEX, NULL,
426 { &hf_fdp_tag_unknown,
427 { "Unknown", "fdp.tag.unknown", FT_BYTES, BASE_NONE, NULL,
432 static hf_register_info oui_hf[] = {
433 { &hf_llc_foundry_pid,
434 { "PID", "llc.foundry_pid", FT_UINT16, BASE_HEX,
435 VALS(foundry_pid_vals), 0x0, NULL, HFILL }
439 static gint *ett[] = {
449 static ei_register_info ei[] = {
450 { &ei_fdp_tlv_length, { "fdp.tlv.length.invalid", PI_MALFORMED, PI_ERROR, "Invalid length", EXPFILL }},
453 expert_module_t* expert_fdp;
455 proto_fdp = proto_register_protocol(PROTO_LONG_NAME, PROTO_SHORT_NAME, "fdp");
457 proto_register_field_array(proto_fdp, hf, array_length(hf));
458 proto_register_subtree_array(ett, array_length(ett));
459 expert_fdp = expert_register_protocol(proto_fdp);
460 expert_register_field_array(expert_fdp, ei, array_length(ei));
462 llc_add_oui(OUI_FOUNDRY, "llc.foundry_pid", "LLC Foundry OUI PID", oui_hf, proto_fdp);
466 proto_reg_handoff_fdp(void)
468 dissector_handle_t fdp_handle;
470 fdp_handle = create_dissector_handle(dissect_fdp, proto_fdp);
471 dissector_add_uint("llc.foundry_pid", 0x2000, fdp_handle);
475 * Editor modelines - http://www.wireshark.org/tools/modelines.html
480 * indent-tabs-mode: t
483 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
484 * :indentSize=8:tabSize=8:noTabs=false: