2 * Routines for the disassembly of Foundry LLC messages (currently
3 * Foundry Discovery Protocol - FDP only)
7 * Copyright 2012 Joerg Mayer (see AUTHORS file)
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <epan/strutil.h>
33 #include <epan/in_cksum.h>
34 #include "packet-llc.h"
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 #define PROTO_SHORT_NAME "FDP"
77 #define PROTO_LONG_NAME "Foundry Discovery Protocol"
79 static const value_string foundry_pid_vals
[] = {
89 FDP_TYPE_CAPABILITIES
= 4,
92 FDP_TYPE_VLANMAP
= 0x0101,
96 static const value_string fdp_type_vals
[] = {
97 { FDP_TYPE_NAME
, "DeviceID"},
98 { FDP_TYPE_NET
, "Net?"},
99 { FDP_TYPE_PORT
, "Interface"},
100 { FDP_TYPE_CAPABILITIES
, "Capabilities"},
101 { FDP_TYPE_VERSION
, "Version"},
102 { FDP_TYPE_MODEL
, "Platform"},
103 { FDP_TYPE_VLANMAP
, "VLAN-Bitmap"},
104 { FDP_TYPE_TAG
, "Tagging-Info"},
110 dissect_tlv_header(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int offset
, int length _U_
, proto_tree
*tree
)
112 proto_item
*tlv_item
;
113 proto_tree
*tlv_tree
;
117 tlv_type
= tvb_get_ntohs(tvb
, offset
);
118 tlv_length
= tvb_get_ntohs(tvb
, offset
+ 2);
120 tlv_item
= proto_tree_add_text(tree
, tvb
, offset
, 4,
121 "Length %d, type %d = %s",
122 tlv_length
, tlv_type
,
123 val_to_str(tlv_type
, fdp_type_vals
, "Unknown (%d)"));
125 tlv_tree
= proto_item_add_subtree(tlv_item
, ett_fdp_tlv_header
);
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(wmem_packet_scope(), tvb
, offset
, length
);
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
);
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
)
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_NA
);
287 proto_tree_add_item(fdp_tree
, hf_fdp_holdtime
, tvb
, offset
, 1, ENC_NA
);
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_text(fdp_tree
, tvb
, offset
, 4,
296 "Too few bytes left for TLV: %u (< 4)",
297 data_length
- offset
);
300 tlv_type
= tvb_get_ntohs(tvb
, offset
);
301 tlv_length
= tvb_get_ntohs(tvb
, offset
+ 2);
303 if ((tlv_length
< 4) || (tlv_length
> (data_length
- offset
))) {
304 proto_tree_add_text(fdp_tree
, tvb
, offset
, 0,
305 "TLV with invalid length: %u", tlv_length
);
308 type_string
= val_to_str(tlv_type
, fdp_type_vals
, "[%u]");
309 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " %s", type_string
);
314 case FDP_TYPE_CAPABILITIES
:
315 case FDP_TYPE_VERSION
:
317 dissect_string_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
, type_string
);
320 dissect_net_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
323 dissect_tag_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
325 case FDP_TYPE_VLANMAP
:
326 dissect_vlanmap_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
329 dissect_unknown_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
332 offset
+= tlv_length
;
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_UINT16
, 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
,
431 static gint
*ett
[] = {
441 proto_fdp
= proto_register_protocol(PROTO_LONG_NAME
,
442 PROTO_SHORT_NAME
, "fdp");
443 proto_register_field_array(proto_fdp
, hf
, array_length(hf
));
444 proto_register_subtree_array(ett
, array_length(ett
));
448 proto_reg_handoff_fdp(void)
450 dissector_handle_t fdp_handle
;
452 fdp_handle
= create_dissector_handle(dissect_fdp
, proto_fdp
);
453 dissector_add_uint("llc.foundry_pid", 0x2000, fdp_handle
);
457 proto_register_foundry_oui(void)
459 static hf_register_info hf
[] = {
460 { &hf_llc_foundry_pid
,
461 { "PID", "llc.foundry_pid", FT_UINT16
, BASE_HEX
,
462 VALS(foundry_pid_vals
), 0x0, NULL
, HFILL
}
466 llc_add_oui(OUI_FOUNDRY
, "llc.foundry_pid", "LLC Foundry OUI PID", hf
);