2 * Routines for dissection of Cisco MDS Switch Internal Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
5 * $Id: packet-mdshdr.c,v 1.4 2003/03/05 07:41:23 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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 #ifdef NEED_SNPRINTF_H
51 # include "snprintf.h"
54 #include <epan/value_string.h>
56 #include <epan/packet.h>
59 #define MDSHDR_VERSION_OFFSET 0
61 /* Mdshdr Control bits */
62 #define MDSHDR_CTL_IDXDIRECT 1
63 #define MDSHDR_CTL_IGNACLO 2
64 #define MDSHDR_CTL_DRP 4
66 /* OFFSETS OF FIELDS */
67 #define MDSHDR_VER_OFFSET 0
68 #define MDSHDR_SOF_OFFSET 1
69 #define MDSHDR_PKTLEN_OFFSET 2
70 #define MDSHDR_DIDX_OFFSET 5
71 #define MDSHDR_SIDX_OFFSET 6
72 #define MDSHDR_VSAN_OFFSET 13
74 /* Two size definitions are sufficient */
75 #define MDSHDR_SIZE_BYTE sizeof (gchar)
76 #define MDSHDR_SIZE_INT16 sizeof (guint16)
77 #define MDSHDR_SIZE_INT32 sizeof (guint32)
79 /* Other miscellaneous defines; can't rely on sizeof structs */
80 #define MDSHDR_MAX_VERSION 0
81 #define MDSHDR_HEADER_SIZE 16
82 #define MDSHDR_TRAILER_SIZE 6
85 #define MDSHDR_SOFc1 0x1
86 #define MDSHDR_SOFi1 0x2
87 #define MDSHDR_SOFn1 0x3
88 #define MDSHDR_SOFi2 0x4
89 #define MDSHDR_SOFn2 0x5
90 #define MDSHDR_SOFi3 0x6
91 #define MDSHDR_SOFn3 0x7
92 #define MDSHDR_SOFf 0x8
93 #define MDSHDR_SOFc4 0x9
94 #define MDSHDR_SOFi4 0xa
95 #define MDSHDR_SOFn4 0xb
98 #define MDSHDR_EOFt 0x1
99 #define MDSHDR_EOFdt 0x2
100 #define MDSHDR_EOFa 0x4
101 #define MDSHDR_EOFn 0x3
102 #define MDSHDR_EOFdti 0x6
103 #define MDSHDR_EOFni 0x7
104 #define MDSHDR_EOFrt 0xa
105 #define MDSHDR_EOFrti 0xe
106 #define MDSHDR_EOF_UNKNOWN 0xb
108 /* Initialize the protocol and registered fields */
109 static int proto_mdshdr = -1;
110 static int hf_mdshdr_sof = -1;
111 static int hf_mdshdr_pkt_len = -1;
112 static int hf_mdshdr_dstidx = -1;
113 static int hf_mdshdr_srcidx = -1;
114 static int hf_mdshdr_vsan = -1;
115 static int hf_mdshdr_eof = -1;
116 static int hf_mdshdr_span = -1;
118 /* Initialize the subtree pointers */
119 static gint ett_mdshdr = -1;
120 static gint ett_mdshdr_hdr = -1;
121 static gint ett_mdshdr_trlr = -1;
123 static dissector_handle_t data_handle, fc_dissector_handle;
125 static const value_string sof_vals[] = {
126 {MDSHDR_SOFc1, "SOFc1"},
127 {MDSHDR_SOFi1, "SOFi1"},
128 {MDSHDR_SOFn1, "SOFn1"},
129 {MDSHDR_SOFi2, "SOFi2"},
130 {MDSHDR_SOFn2, "SOFn2"},
131 {MDSHDR_SOFi3, "SOFi3"},
132 {MDSHDR_SOFn3, "SOFn3"},
133 {MDSHDR_SOFc4, "SOFc4"},
134 {MDSHDR_SOFi4, "SOFi4"},
135 {MDSHDR_SOFn4, "SOFn4"},
136 {MDSHDR_SOFf, "SOFf"},
140 static const value_string eof_vals[] = {
141 {MDSHDR_EOFt, "EOFt"},
142 {MDSHDR_EOFdt, "EOFdt"},
143 {MDSHDR_EOFa, "EOFa"},
144 {MDSHDR_EOFn, "EOFn"},
145 {MDSHDR_EOFdti, "EOFdti"},
146 {MDSHDR_EOFni, "EOFni"},
147 {MDSHDR_EOFrt, "EOFrt"},
148 {MDSHDR_EOFrti, "EOFrti"},
149 {MDSHDR_EOF_UNKNOWN, ""},
153 static const gchar * sof_strings[] = {
154 "Null", "SOFc1", "SOFi1", "SOFn1", "SOFi2", "SOFn2", "SOFi3", "SOFn3",
155 "SOFf", "SOFc4", "SOFi4", "SOFn4",
158 static const gchar *eof_strings[] = {
159 "Null", "EOFt", "EOFdt", "EOFn", "EOFa", "", "EOFdti", "EOFni",
160 "", "", "EOFrt", "", "", "", "EOFrti",
163 /* Code to actually dissect the packets */
165 dissect_mdshdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
168 /* Set up structures needed to add the protocol subtree and manage it */
169 proto_item *ti_main, *ti_hdr, *ti_trlr;
170 proto_tree *mdshdr_tree_main, *mdshdr_tree_hdr, *mdshdr_tree_trlr;
177 int trailer_start = 0;
179 /* Make entries in Protocol column and Info column on summary display */
180 if (check_col(pinfo->cinfo, COL_PROTOCOL))
181 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MDS Header");
183 if (check_col (pinfo->cinfo, COL_INFO))
184 col_clear (pinfo->cinfo, COL_INFO);
186 sof = tvb_get_guint8 (tvb, offset+MDSHDR_SOF_OFFSET) & 0x0F;
187 pktlen = tvb_get_ntohs (tvb, offset+MDSHDR_PKTLEN_OFFSET) & 0x1FFF;
188 vsan = tvb_get_ntohs (tvb, offset+MDSHDR_VSAN_OFFSET) & 0x0FFF;
189 span_id = (tvb_get_ntohs (tvb, offset+MDSHDR_VSAN_OFFSET) & 0xF000) >> 12;
191 /* The Mdshdr trailer is at the end of the frame */
192 if (tvb_bytes_exist (tvb, 0, MDSHDR_HEADER_SIZE + pktlen)) {
193 trailer_start = MDSHDR_HEADER_SIZE + pktlen - MDSHDR_TRAILER_SIZE;
195 eof = tvb_get_guint8 (tvb, trailer_start);
197 tvb_set_reported_length (tvb, MDSHDR_HEADER_SIZE+pktlen);
200 eof = MDSHDR_EOF_UNKNOWN;
203 pinfo->src_idx = (tvb_get_ntohs (tvb, MDSHDR_SIDX_OFFSET) & 0x3FF);
204 pinfo->dst_idx = (tvb_get_ntohs (tvb, MDSHDR_DIDX_OFFSET) & 0xFFC) >> 6;
207 /* In the interest of speed, if "tree" is NULL, don't do any work not
208 necessary to generate protocol tree items. */
211 /* create display subtree for the protocol */
212 ti_main = proto_tree_add_protocol_format (tree, proto_mdshdr, tvb, 0,
213 MDSHDR_HEADER_SIZE+pktlen,
215 sof_strings[sof], eof_strings[eof]);
217 mdshdr_tree_main = proto_item_add_subtree (ti_main, ett_mdshdr);
219 /* Add Header part as subtree first */
220 ti_hdr = proto_tree_add_text (mdshdr_tree_main, tvb, MDSHDR_VER_OFFSET,
221 MDSHDR_HEADER_SIZE, "MDS Header");
223 mdshdr_tree_hdr = proto_item_add_subtree (ti_hdr, ett_mdshdr_hdr);
224 proto_tree_add_item_hidden (mdshdr_tree_hdr, hf_mdshdr_sof, tvb, MDSHDR_SOF_OFFSET,
225 MDSHDR_SIZE_BYTE, 0);
226 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_pkt_len, tvb, MDSHDR_PKTLEN_OFFSET,
227 MDSHDR_SIZE_INT16, 0);
228 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_dstidx, tvb, MDSHDR_DIDX_OFFSET,
229 MDSHDR_SIZE_INT16, 0);
230 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_srcidx, tvb, MDSHDR_SIDX_OFFSET,
231 MDSHDR_SIZE_INT16, 0);
232 proto_tree_add_item (mdshdr_tree_hdr, hf_mdshdr_vsan, tvb, MDSHDR_VSAN_OFFSET,
233 MDSHDR_SIZE_INT16, 0);
234 proto_tree_add_uint_hidden(mdshdr_tree_hdr, hf_mdshdr_span,
235 tvb, MDSHDR_VSAN_OFFSET,
236 MDSHDR_SIZE_BYTE, span_id);
238 /* Add Mdshdr Trailer part */
239 if (tvb_bytes_exist (tvb, 0, MDSHDR_HEADER_SIZE+pktlen)) {
240 ti_trlr = proto_tree_add_text (mdshdr_tree_main, tvb, trailer_start,
243 mdshdr_tree_trlr = proto_item_add_subtree (ti_trlr, ett_mdshdr_trlr);
245 proto_tree_add_item (mdshdr_tree_trlr, hf_mdshdr_eof, tvb,
246 trailer_start, MDSHDR_SIZE_BYTE, 0);
250 /* If this protocol has a sub-dissector call it here, see section 1.8 */
251 if (tvb_bytes_exist (tvb, 0, MDSHDR_HEADER_SIZE+pktlen)) {
252 next_tvb = tvb_new_subset (tvb, MDSHDR_HEADER_SIZE, pktlen, pktlen);
255 next_tvb = tvb_new_subset (tvb, MDSHDR_HEADER_SIZE, -1, -1);
258 /* Call the Fibre Channel dissector */
259 if (fc_dissector_handle) {
260 call_dissector (fc_dissector_handle, next_tvb, pinfo, tree);
263 call_dissector (data_handle, next_tvb, pinfo, tree);
268 /* Register the protocol with Ethereal. This format is require because a script
269 * is used to build the C function that calls all the protocol registration.
273 proto_register_mdshdr(void)
276 /* Setup list of header fields See Section 1.6.1 for details*/
277 static hf_register_info hf[] = {
279 {"SOF", "mdshdr.sof", FT_UINT8, BASE_DEC, VALS(sof_vals), 0x0, "", HFILL}},
280 { &hf_mdshdr_pkt_len,
281 {"Packet Len", "mdshdr.plen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL}},
283 {"Dst Index", "mdshdr.dstidx", FT_UINT16, BASE_HEX, NULL, 0xFFC, "", HFILL}},
285 {"Src Index", "mdshdr.srcidx", FT_UINT16, BASE_HEX, NULL, 0x3FF, "", HFILL}},
287 {"VSAN", "mdshdr.vsan", FT_UINT16, BASE_DEC, NULL, 0x0FFF, "", HFILL}},
289 {"EOF", "mdshdr.eof", FT_UINT8, BASE_DEC, VALS(eof_vals), 0x0, "", HFILL}},
291 {"SPAN Frame", "mdshdr.span", FT_UINT8, BASE_DEC, NULL, 0x0,
295 /* Setup protocol subtree array */
296 static gint *ett[] = {
302 /* Register the protocol name and description */
303 proto_mdshdr = proto_register_protocol("MDS Header", "mdshdr", "mdshdr");
305 /* Required function calls to register the header fields and subtrees used */
306 proto_register_field_array(proto_mdshdr, hf, array_length(hf));
307 proto_register_subtree_array(ett, array_length(ett));
311 /* If this dissector uses sub-dissector registration add a registration routine.
312 This format is required because a script is used to find these routines and
313 create the code that calls these routines.
316 proto_reg_handoff_mdshdr(void)
318 dissector_handle_t mdshdr_handle;
320 mdshdr_handle = create_dissector_handle (dissect_mdshdr, proto_mdshdr);
321 dissector_add ("ethertype", ETHERTYPE_UNK, mdshdr_handle);
322 dissector_add ("ethertype", ETHERTYPE_FCFT, mdshdr_handle);
324 data_handle = find_dissector ("data");
325 fc_dissector_handle = find_dissector ("fc");