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 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/packet.h>
17 #include <epan/expert.h>
18 #include <epan/strutil.h>
19 #include "packet-llc.h"
22 void proto_register_fdp(void);
23 void proto_reg_handoff_fdp(void);
25 static dissector_handle_t fdp_handle
;
27 static int hf_llc_foundry_pid
;
31 static int hf_fdp_version
;
32 static int hf_fdp_holdtime
;
33 static int hf_fdp_checksum
;
35 static int hf_fdp_tlv_type
;
36 static int hf_fdp_tlv_length
;
38 static int hf_fdp_unknown
;
39 static int hf_fdp_unknown_data
;
40 /* Port Tag element */
41 static int hf_fdp_tag
;
42 static int hf_fdp_tag_native
;
43 static int hf_fdp_tag_type
;
44 static int hf_fdp_tag_unknown
;
46 static int hf_fdp_vlanmap
;
47 static int hf_fdp_vlanmap_vlan
;
49 static int hf_fdp_string
;
50 static int hf_fdp_string_data
;
51 static int hf_fdp_string_text
;
53 static int hf_fdp_net
;
54 static int hf_fdp_net_unknown
;
55 static int hf_fdp_net_ip
;
56 static int hf_fdp_net_iplength
;
59 static int ett_fdp_tlv_header
;
60 static int ett_fdp_unknown
;
61 static int ett_fdp_string
;
62 static int ett_fdp_net
;
63 static int ett_fdp_tag
;
64 static int ett_fdp_vlanmap
;
66 static expert_field ei_fdp_tlv_length
;
68 #define PROTO_SHORT_NAME "FDP"
69 #define PROTO_LONG_NAME "Foundry Discovery Protocol"
71 static const value_string foundry_pid_vals
[] = {
81 FDP_TYPE_CAPABILITIES
= 4,
84 FDP_TYPE_VLANMAP
= 0x0101,
88 static const value_string fdp_type_vals
[] = {
89 { FDP_TYPE_NAME
, "DeviceID"},
90 { FDP_TYPE_NET
, "Net?"},
91 { FDP_TYPE_PORT
, "Interface"},
92 { FDP_TYPE_CAPABILITIES
, "Capabilities"},
93 { FDP_TYPE_VERSION
, "Version"},
94 { FDP_TYPE_MODEL
, "Platform"},
95 { FDP_TYPE_VLANMAP
, "VLAN-Bitmap"},
96 { FDP_TYPE_TAG
, "Tagging-Info"},
102 dissect_tlv_header(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int offset
, int length _U_
, proto_tree
*tree
)
104 proto_tree
*tlv_tree
;
108 tlv_type
= tvb_get_ntohs(tvb
, offset
);
109 tlv_length
= tvb_get_ntohs(tvb
, offset
+ 2);
111 tlv_tree
= proto_tree_add_subtree_format(tree
, tvb
, offset
, 4,
112 ett_fdp_tlv_header
, NULL
, "Length %d, type %d = %s",
113 tlv_length
, tlv_type
,
114 val_to_str(tlv_type
, fdp_type_vals
, "Unknown (%d)"));
116 proto_tree_add_uint(tlv_tree
, hf_fdp_tlv_type
, tvb
, offset
, 2, tlv_type
);
119 proto_tree_add_uint(tlv_tree
, hf_fdp_tlv_length
, tvb
, offset
, 2, tlv_length
);
126 dissect_string_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
, proto_tree
*tree
, const char* type_string
)
128 proto_item
*string_item
;
129 proto_tree
*string_tree
;
130 const uint8_t *string_value
;
132 string_item
= proto_tree_add_protocol_format(tree
, hf_fdp_string
,
133 tvb
, offset
, length
, "%s", type_string
);
135 string_tree
= proto_item_add_subtree(string_item
, ett_fdp_string
);
137 dissect_tlv_header(tvb
, pinfo
, offset
, 4, string_tree
);
141 proto_tree_add_item(string_tree
, hf_fdp_string_data
, tvb
, offset
, length
, ENC_NA
);
142 proto_tree_add_item_ret_string(string_tree
, hf_fdp_string_text
, tvb
, offset
, length
, ENC_ASCII
|ENC_NA
, pinfo
->pool
, &string_value
);
143 proto_item_append_text(string_item
, ": \"%s\"",
144 format_text(pinfo
->pool
, string_value
, strlen(string_value
)));
150 dissect_net_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
, proto_tree
*tree
)
152 proto_item
*net_item
;
153 proto_tree
*net_tree
;
155 net_item
= proto_tree_add_protocol_format(tree
, hf_fdp_net
,
156 tvb
, offset
, length
, "Net?");
158 net_tree
= proto_item_add_subtree(net_item
, ett_fdp_net
);
160 dissect_tlv_header(tvb
, pinfo
, offset
, 4, net_tree
);
164 proto_tree_add_item(net_tree
, hf_fdp_net_unknown
, tvb
, offset
, 7, ENC_NA
);
168 /* Length of IP address block in bytes */
169 proto_tree_add_item(net_tree
, hf_fdp_net_iplength
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
173 while (length
>= 4) {
174 proto_tree_add_item(net_tree
, hf_fdp_net_ip
, tvb
, offset
, 4, ENC_NA
);
181 dissect_vlanmap_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
, proto_tree
*tree
)
183 proto_item
*vlanmap_item
;
184 proto_tree
*vlanmap_tree
;
185 unsigned vlan
, voffset
;
186 unsigned bitoffset
, byteoffset
;
188 vlanmap_item
= proto_tree_add_protocol_format(tree
, hf_fdp_vlanmap
,
189 tvb
, offset
, length
, "VLAN-Map");
191 vlanmap_tree
= proto_item_add_subtree(vlanmap_item
, ett_fdp_vlanmap
);
193 dissect_tlv_header(tvb
, pinfo
, offset
, 4, vlanmap_tree
);
198 for (vlan
= 1; vlan
<= (unsigned)length
*8; vlan
++) {
199 byteoffset
= (vlan
- voffset
) / 8;
200 bitoffset
= (vlan
- voffset
) % 8;
201 if (tvb_get_uint8(tvb
, offset
+ byteoffset
) & (1 << bitoffset
)) {
203 proto_tree_add_uint(vlanmap_tree
, hf_fdp_vlanmap_vlan
, tvb
,
204 offset
+ byteoffset
, 1, vlan
);
210 dissect_tag_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
, proto_tree
*tree
)
212 proto_item
*tag_item
;
213 proto_tree
*tag_tree
;
215 tag_item
= proto_tree_add_protocol_format(tree
, hf_fdp_tag
,
216 tvb
, offset
, length
, "Port tag");
218 tag_tree
= proto_item_add_subtree(tag_item
, ett_fdp_tag
);
220 dissect_tlv_header(tvb
, pinfo
, offset
, 4, tag_tree
);
223 proto_tree_add_item(tag_tree
, hf_fdp_tag_native
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
226 proto_tree_add_item(tag_tree
, hf_fdp_tag_type
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
229 proto_tree_add_item(tag_tree
, hf_fdp_tag_unknown
, tvb
, offset
, length
, ENC_NA
);
233 dissect_unknown_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
, proto_tree
*tree
)
235 proto_item
*unknown_item
;
236 proto_tree
*unknown_tree
;
239 tlv_type
= tvb_get_ntohs(tvb
, offset
);
241 unknown_item
= proto_tree_add_protocol_format(tree
, hf_fdp_unknown
,
242 tvb
, offset
, length
, "Unknown element [%u]", tlv_type
);
244 unknown_tree
= proto_item_add_subtree(unknown_item
, ett_fdp_unknown
);
246 dissect_tlv_header(tvb
, pinfo
, offset
, 4, unknown_tree
);
250 proto_tree_add_item(unknown_tree
, hf_fdp_unknown_data
, tvb
, offset
, length
, ENC_NA
);
254 dissect_fdp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
257 proto_tree
*fdp_tree
= NULL
;
262 const char *type_string
;
264 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, PROTO_SHORT_NAME
);
265 col_set_str(pinfo
->cinfo
, COL_INFO
, PROTO_SHORT_NAME
":");
268 data_length
= tvb_reported_length_remaining(tvb
, offset
);
270 ti
= proto_tree_add_item(tree
, proto_fdp
, tvb
, offset
, -1, ENC_NA
);
271 fdp_tree
= proto_item_add_subtree(ti
, ett_fdp
);
273 proto_tree_add_item(fdp_tree
, hf_fdp_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
275 proto_tree_add_item(fdp_tree
, hf_fdp_holdtime
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
277 proto_tree_add_checksum(fdp_tree
, tvb
, offset
, hf_fdp_checksum
, -1, NULL
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
280 /* Decode the individual TLVs */
281 while (offset
< data_length
) {
282 if (data_length
- offset
< 4) {
283 proto_tree_add_expert_format(fdp_tree
, pinfo
, &ei_fdp_tlv_length
, tvb
, offset
, 4,
284 "Too few bytes left for TLV: %u (< 4)", data_length
- offset
);
287 tlv_type
= tvb_get_ntohs(tvb
, offset
);
288 tlv_length
= tvb_get_ntohs(tvb
, offset
+ 2);
290 if ((tlv_length
< 4) || (tlv_length
> (data_length
- offset
))) {
291 proto_tree_add_expert_format(fdp_tree
, pinfo
, &ei_fdp_tlv_length
, tvb
, offset
, 0,
292 "TLV with invalid length: %u", tlv_length
);
295 type_string
= val_to_str(tlv_type
, fdp_type_vals
, "[%u]");
296 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " %s", type_string
);
301 case FDP_TYPE_CAPABILITIES
:
302 case FDP_TYPE_VERSION
:
304 dissect_string_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
, type_string
);
307 dissect_net_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
310 dissect_tag_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
312 case FDP_TYPE_VLANMAP
:
313 dissect_vlanmap_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
316 dissect_unknown_tlv(tvb
, pinfo
, offset
, tlv_length
, fdp_tree
);
319 offset
+= tlv_length
;
323 return tvb_captured_length(tvb
);
327 proto_register_fdp(void)
329 static hf_register_info hf
[] = {
333 { "Version?", "fdp.version", FT_UINT8
, BASE_DEC
, NULL
,
337 { "Holdtime", "fdp.holdtime", FT_UINT8
, BASE_DEC
, NULL
,
341 { "Checksum?", "fdp.checksum", FT_UINT16
, BASE_HEX
, NULL
,
346 { "TLV type", "fdp.tlv.type", FT_UINT16
, BASE_DEC
, VALS(fdp_type_vals
),
349 { &hf_fdp_tlv_length
,
350 { "TLV length", "fdp.tlv.length", FT_UINT16
, BASE_DEC
, NULL
,
353 /* Unknown element */
355 { "Unknown", "fdp.unknown", FT_PROTOCOL
, BASE_NONE
, NULL
,
358 { &hf_fdp_unknown_data
,
359 { "Unknown", "fdp.unknown.data", FT_BYTES
, BASE_NONE
, NULL
,
364 { "DeviceID", "fdp.deviceid", FT_PROTOCOL
, BASE_NONE
, NULL
,
367 { &hf_fdp_string_data
,
368 { "Data", "fdp.string.data", FT_BYTES
, BASE_NONE
, NULL
,
371 { &hf_fdp_string_text
,
372 { "Text", "fdp.string.text", FT_STRING
, BASE_NONE
, NULL
,
377 { "Net?", "fdp.net", FT_PROTOCOL
, BASE_NONE
, NULL
,
380 { &hf_fdp_net_unknown
,
381 { "Net Unknown?", "fdp.net.unknown", FT_BYTES
, BASE_NONE
, NULL
,
384 { &hf_fdp_net_iplength
,
385 { "Net IP Bytes?", "fdp.net.iplength", FT_UINT16
, BASE_DEC
, NULL
,
386 0x0, "Number of bytes carrying IP addresses", HFILL
}},
389 { "Net IP Address?", "fdp.net.ip", FT_IPv4
, BASE_NONE
, NULL
,
394 { "VLAN Map", "fdp.vlanmap", FT_PROTOCOL
, BASE_NONE
, NULL
,
397 { &hf_fdp_vlanmap_vlan
,
398 { "VLAN", "fdp.vlanmap.vlan", FT_UINT16
, BASE_DEC
, NULL
,
401 /* Port Tag element */
403 { "Tag", "fdp.tag", FT_PROTOCOL
, BASE_NONE
, NULL
,
406 { &hf_fdp_tag_native
,
407 { "Native", "fdp.tag.native", FT_UINT16
, BASE_DEC
, NULL
,
411 { "Type", "fdp.tag.type", FT_UINT16
, BASE_HEX
, NULL
,
414 { &hf_fdp_tag_unknown
,
415 { "Unknown", "fdp.tag.unknown", FT_BYTES
, BASE_NONE
, NULL
,
420 static hf_register_info oui_hf
[] = {
421 { &hf_llc_foundry_pid
,
422 { "PID", "llc.foundry_pid", FT_UINT16
, BASE_HEX
,
423 VALS(foundry_pid_vals
), 0x0, NULL
, HFILL
}
427 static int *ett
[] = {
437 static ei_register_info ei
[] = {
438 { &ei_fdp_tlv_length
, { "fdp.tlv.length.invalid", PI_MALFORMED
, PI_ERROR
, "Invalid length", EXPFILL
}},
441 expert_module_t
* expert_fdp
;
443 proto_fdp
= proto_register_protocol(PROTO_LONG_NAME
, PROTO_SHORT_NAME
, "fdp");
445 proto_register_field_array(proto_fdp
, hf
, array_length(hf
));
446 proto_register_subtree_array(ett
, array_length(ett
));
447 expert_fdp
= expert_register_protocol(proto_fdp
);
448 expert_register_field_array(expert_fdp
, ei
, array_length(ei
));
450 llc_add_oui(OUI_FOUNDRY
, "llc.foundry_pid", "LLC Foundry OUI PID", oui_hf
, proto_fdp
);
452 fdp_handle
= register_dissector("fdp", dissect_fdp
, proto_fdp
);
456 proto_reg_handoff_fdp(void)
458 dissector_add_uint("llc.foundry_pid", 0x2000, fdp_handle
);
462 * Editor modelines - https://www.wireshark.org/tools/modelines.html
467 * indent-tabs-mode: t
470 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
471 * :indentSize=8:tabSize=8:noTabs=false: