2 * Routines for dissection of Cisco MDS Switch Internal Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from WHATEVER_FILE_YOU_USED (where "WHATEVER_FILE_YOU_USED"
12 * is a dissector file; if you just copied this from README.developer,
13 * don't bother with the "Copied from" - you don't even need to put
14 * in a "Copied from" if you copied an existing dissector, especially
15 * if the bulk of the code in the new dissector is your code)
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
50 #include <epan/value_string.h>
52 #include <epan/packet.h>
53 #include <epan/prefs.h>
55 #define MDSHDR_VERSION_OFFSET 0
57 /* Mdshdr Control bits */
58 #define MDSHDR_CTL_IDXDIRECT 1
59 #define MDSHDR_CTL_IGNACLO 2
60 #define MDSHDR_CTL_DRP 4
62 /* OFFSETS OF FIELDS */
63 #define MDSHDR_VER_OFFSET 0
64 #define MDSHDR_SOF_OFFSET 1
65 #define MDSHDR_PKTLEN_OFFSET 2
66 #define MDSHDR_DIDX_OFFSET 5
67 #define MDSHDR_SIDX_OFFSET 6
68 #define MDSHDR_VSAN_OFFSET 13
70 /* Two size definitions are sufficient */
71 #define MDSHDR_SIZE_BYTE sizeof (gchar)
72 #define MDSHDR_SIZE_INT16 sizeof (guint16)
73 #define MDSHDR_SIZE_INT32 sizeof (guint32)
75 /* Other miscellaneous defines; can't rely on sizeof structs */
76 #define MDSHDR_MAX_VERSION 0
77 #define MDSHDR_HEADER_SIZE 16
78 #define MDSHDR_TRAILER_SIZE 6
81 #define MDSHDR_SOFc1 0x1
82 #define MDSHDR_SOFi1 0x2
83 #define MDSHDR_SOFn1 0x3
84 #define MDSHDR_SOFi2 0x4
85 #define MDSHDR_SOFn2 0x5
86 #define MDSHDR_SOFi3 0x6
87 #define MDSHDR_SOFn3 0x7
88 #define MDSHDR_SOFf 0x8
89 #define MDSHDR_SOFc4 0x9
90 #define MDSHDR_SOFi4 0xa
91 #define MDSHDR_SOFn4 0xb
94 #define MDSHDR_EOFt 0x1
95 #define MDSHDR_EOFdt 0x2
96 #define MDSHDR_EOFa 0x4
97 #define MDSHDR_EOFn 0x3
98 #define MDSHDR_EOFdti 0x6
99 #define MDSHDR_EOFni 0x7
100 #define MDSHDR_EOFrt 0xa
101 #define MDSHDR_EOFrti 0xe
102 #define MDSHDR_EOF_UNKNOWN 0xb
104 /* Initialize the protocol and registered fields */
105 static int proto_mdshdr = -1;
106 static int hf_mdshdr_sof = -1;
107 static int hf_mdshdr_pkt_len = -1;
108 static int hf_mdshdr_dstidx = -1;
109 static int hf_mdshdr_srcidx = -1;
110 static int hf_mdshdr_vsan = -1;
111 static int hf_mdshdr_eof = -1;
112 static int hf_mdshdr_span = -1;
113 static int hf_mdshdr_fccrc = -1;
115 /* Initialize the subtree pointers */
116 static gint ett_mdshdr = -1;
117 static gint ett_mdshdr_hdr = -1;
118 static gint ett_mdshdr_trlr = -1;
120 static dissector_handle_t data_handle, fc_dissector_handle;
122 static gboolean decode_if_zero_etype = TRUE;
124 static const value_string sof_vals[] = {
125 {MDSHDR_SOFc1, "SOFc1"},
126 {MDSHDR_SOFi1, "SOFi1"},
127 {MDSHDR_SOFn1, "SOFn1"},
128 {MDSHDR_SOFi2, "SOFi2"},
129 {MDSHDR_SOFn2, "SOFn2"},
130 {MDSHDR_SOFi3, "SOFi3"},
131 {MDSHDR_SOFn3, "SOFn3"},
132 {MDSHDR_SOFc4, "SOFc4"},
133 {MDSHDR_SOFi4, "SOFi4"},
134 {MDSHDR_SOFn4, "SOFn4"},
135 {MDSHDR_SOFf, "SOFf"},
139 static const value_string eof_vals[] = {
140 {MDSHDR_EOFt, "EOFt"},
141 {MDSHDR_EOFdt, "EOFdt"},
142 {MDSHDR_EOFa, "EOFa"},
143 {MDSHDR_EOFn, "EOFn"},
144 {MDSHDR_EOFdti, "EOFdti"},
145 {MDSHDR_EOFni, "EOFni"},
146 {MDSHDR_EOFrt, "EOFrt"},
147 {MDSHDR_EOFrti, "EOFrti"},
148 {MDSHDR_EOF_UNKNOWN, ""},
152 void proto_reg_handoff_mdshdr(void);
154 /* Code to actually dissect the packets */
156 dissect_mdshdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
159 /* Set up structures needed to add the protocol subtree and manage it */
160 proto_item *ti_main, *ti_hdr, *ti_trlr;
161 proto_item *hidden_item;
162 proto_tree *mdshdr_tree_main, *mdshdr_tree_hdr, *mdshdr_tree_trlr;
169 int trailer_start = 0;
171 /* Make entries in Protocol column and Info column on summary display */
172 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MDS Header");
174 if (check_col (pinfo->cinfo, COL_INFO))
175 col_clear (pinfo->cinfo, COL_INFO);
177 sof = tvb_get_guint8 (tvb, offset+MDSHDR_SOF_OFFSET) & 0x0F;
178 pktlen = tvb_get_ntohs (tvb, offset+MDSHDR_PKTLEN_OFFSET) & 0x1FFF;
179 vsan = tvb_get_ntohs (tvb, offset+MDSHDR_VSAN_OFFSET) & 0x0FFF;
180 span_id = (tvb_get_ntohs (tvb, offset+MDSHDR_VSAN_OFFSET) & 0xF000) >> 12;
182 /* The Mdshdr trailer is at the end of the frame */
183 if (tvb_length (tvb) >= MDSHDR_HEADER_SIZE + pktlen) {
184 trailer_start = MDSHDR_HEADER_SIZE + pktlen - MDSHDR_TRAILER_SIZE;
186 eof = tvb_get_guint8 (tvb, trailer_start);
187 tvb_set_reported_length (tvb, MDSHDR_HEADER_SIZE+pktlen);
190 eof = MDSHDR_EOF_UNKNOWN;
193 pinfo->src_idx = (tvb_get_ntohs (tvb, MDSHDR_SIDX_OFFSET) & 0x3FF);
194 pinfo->dst_idx = (tvb_get_ntohs (tvb, MDSHDR_DIDX_OFFSET) & 0xFFC) >> 2;
198 if ((sof == MDSHDR_SOFi3) || (sof == MDSHDR_SOFi2) || (sof == MDSHDR_SOFi1)
199 || (sof == MDSHDR_SOFi4)) {
200 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
202 else if (sof == MDSHDR_SOFf) {
203 pinfo->sof_eof = PINFO_SOF_SOFF;
206 if (eof != MDSHDR_EOFn) {
207 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
209 else if (eof != MDSHDR_EOFt) {
210 pinfo->sof_eof |= PINFO_EOF_INVALID;
213 /* In the interest of speed, if "tree" is NULL, don't do any work not
214 necessary to generate protocol tree items. */
217 /* create display subtree for the protocol */
218 ti_main = proto_tree_add_protocol_format (tree, proto_mdshdr, tvb, 0,
219 MDSHDR_HEADER_SIZE+pktlen,
221 val_to_str(sof, sof_vals, "Unknown(%u)"),
222 val_to_str(eof, eof_vals, "Unknown(%u)"));
224 mdshdr_tree_main = proto_item_add_subtree (ti_main, ett_mdshdr);
226 /* Add Header part as subtree first */
227 ti_hdr = proto_tree_add_text (mdshdr_tree_main, tvb, MDSHDR_VER_OFFSET,
228 MDSHDR_HEADER_SIZE, "MDS Header");
230 mdshdr_tree_hdr = proto_item_add_subtree (ti_hdr, ett_mdshdr_hdr);
231 hidden_item = proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_sof, tvb, MDSHDR_SOF_OFFSET,
232 MDSHDR_SIZE_BYTE, 0);
233 PROTO_ITEM_SET_HIDDEN(hidden_item);
234 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_pkt_len, tvb, MDSHDR_PKTLEN_OFFSET,
235 MDSHDR_SIZE_INT16, 0);
236 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_dstidx, tvb, MDSHDR_DIDX_OFFSET,
237 MDSHDR_SIZE_INT16, 0);
238 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_srcidx, tvb, MDSHDR_SIDX_OFFSET,
239 MDSHDR_SIZE_INT16, 0);
240 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_vsan, tvb, MDSHDR_VSAN_OFFSET,
241 MDSHDR_SIZE_INT16, 0);
242 hidden_item = proto_tree_add_uint(mdshdr_tree_hdr, hf_mdshdr_span,
243 tvb, MDSHDR_VSAN_OFFSET,
244 MDSHDR_SIZE_BYTE, span_id);
245 PROTO_ITEM_SET_HIDDEN(hidden_item);
247 /* Add Mdshdr Trailer part */
248 if (tvb_length (tvb) >= MDSHDR_HEADER_SIZE + pktlen) {
249 ti_trlr = proto_tree_add_text (mdshdr_tree_main, tvb, trailer_start,
252 mdshdr_tree_trlr = proto_item_add_subtree (ti_trlr, ett_mdshdr_trlr);
254 proto_tree_add_item (mdshdr_tree_trlr, hf_mdshdr_eof, tvb,
255 trailer_start, MDSHDR_SIZE_BYTE, 0);
256 proto_tree_add_item (mdshdr_tree_trlr, hf_mdshdr_fccrc, tvb,
257 trailer_start+2, MDSHDR_SIZE_INT32, 0);
261 /* If this protocol has a sub-dissector call it here, see section 1.8 */
262 if (tvb_length (tvb) >= MDSHDR_HEADER_SIZE + pktlen) {
263 next_tvb = tvb_new_subset (tvb, MDSHDR_HEADER_SIZE, pktlen, pktlen);
266 next_tvb = tvb_new_subset (tvb, MDSHDR_HEADER_SIZE, -1, -1);
269 /* Call the Fibre Channel dissector */
270 if (fc_dissector_handle) {
271 call_dissector (fc_dissector_handle, next_tvb, pinfo, tree);
274 call_dissector (data_handle, next_tvb, pinfo, tree);
279 /* Register the protocol with Wireshark. This format is require because a script
280 * is used to build the C function that calls all the protocol registration.
284 proto_register_mdshdr(void)
287 /* Setup list of header fields See Section 1.6.1 for details*/
288 static hf_register_info hf[] = {
290 {"SOF", "mdshdr.sof", FT_UINT8, BASE_DEC, VALS(sof_vals), 0x0, NULL, HFILL}},
291 { &hf_mdshdr_pkt_len,
292 {"Packet Len", "mdshdr.plen", FT_UINT16, BASE_DEC, NULL, 0x1FFF, NULL, HFILL}},
294 {"Dst Index", "mdshdr.dstidx", FT_UINT16, BASE_HEX, NULL, 0xFFC, NULL, HFILL}},
296 {"Src Index", "mdshdr.srcidx", FT_UINT16, BASE_HEX, NULL, 0x3FF, NULL, HFILL}},
298 {"VSAN", "mdshdr.vsan", FT_UINT16, BASE_DEC, NULL, 0x0FFF, NULL, HFILL}},
300 {"EOF", "mdshdr.eof", FT_UINT8, BASE_DEC, VALS(eof_vals), 0x0, NULL, HFILL}},
302 {"SPAN Frame", "mdshdr.span", FT_UINT8, BASE_DEC, NULL, 0x0,
305 {"CRC", "mdshdr.crc", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}},
308 /* Setup protocol subtree array */
309 static gint *ett[] = {
314 module_t *mdshdr_module;
316 /* Register the protocol name and description */
317 proto_mdshdr = proto_register_protocol("MDS Header", "MDS Header", "mdshdr");
319 /* Required function calls to register the header fields and subtrees used */
320 proto_register_field_array(proto_mdshdr, hf, array_length(hf));
321 proto_register_subtree_array(ett, array_length(ett));
323 mdshdr_module = prefs_register_protocol (proto_mdshdr, proto_reg_handoff_mdshdr);
324 prefs_register_bool_preference (mdshdr_module, "decode_if_etype_zero",
325 "Decode as MDS Header if Ethertype == 0",
326 "A frame is considered for decoding as MDSHDR if either "
327 "ethertype is 0xFCFC or zero. Turn this flag off if you "
328 "you don't want ethertype zero to be decoded as MDSHDR. "
329 "This might be useful to avoid problems with test frames.",
330 &decode_if_zero_etype);
334 /* If this dissector uses sub-dissector registration add a registration routine.
335 This format is required because a script is used to find these routines and
336 create the code that calls these routines.
339 proto_reg_handoff_mdshdr(void)
341 static dissector_handle_t mdshdr_handle;
342 static gboolean registered_for_zero_etype = FALSE;
343 static gboolean mdshdr_prefs_initialized = FALSE;
345 if (!mdshdr_prefs_initialized) {
347 * This is the first time this has been called (i.e.,
348 * Wireshark/TShark is starting up), so create a handle for
349 * the MDS Header dissector, register the dissector for
350 * ethertype ETHERTYPE_FCFT, and fetch the data and Fibre
353 mdshdr_handle = create_dissector_handle (dissect_mdshdr, proto_mdshdr);
354 dissector_add ("ethertype", ETHERTYPE_FCFT, mdshdr_handle);
355 data_handle = find_dissector ("data");
356 fc_dissector_handle = find_dissector ("fc");
357 mdshdr_prefs_initialized = TRUE;
361 * Only register the dissector for ethertype 0 if the preference
364 if (decode_if_zero_etype) {
366 * The preference to register for ethertype ETHERTYPE_UNK (0)
367 * is set; if we're not registered for ethertype ETHERTYPE_UNK,
370 if (!registered_for_zero_etype) {
371 dissector_add ("ethertype", ETHERTYPE_UNK, mdshdr_handle);
372 registered_for_zero_etype = TRUE;
376 * The preference to register for ethertype ETHERTYPE_UNK (0)
377 * is not set; if we're registered for ethertype ETHERTYPE_UNK,
378 * undo that registration.
380 if (registered_for_zero_etype) {
381 dissector_delete ("ethertype", ETHERTYPE_UNK, mdshdr_handle);
382 registered_for_zero_etype = FALSE;