3 * Routines for FCoE dissection - Fibre Channel over Ethernet
4 * Copyright (c) 2006 Nuova Systems, Inc. (jre@nuovasystems.com)
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * Based on packet-fcip.c, Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * For FCoE protocol details, see http://fcoe.com.
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/crc32.h>
46 #include <epan/etypes.h>
47 #include <epan/expert.h>
49 #define FCOE_HEADER_LEN 14 /* header: version, SOF, and padding */
50 #define FCOE_TRAILER_LEN 8 /* trailer: CRC, EOF, and padding */
74 static const value_string fcoe_eof_vals[] = {
77 {FCOE_EOFrt, "EOFrt" },
78 {FCOE_EOFdt, "EOFdt" },
79 {FCOE_EOFni, "EOFni" },
80 {FCOE_EOFdti, "EOFdti" },
81 {FCOE_EOFrti, "EOFrti" },
86 static const value_string fcoe_sof_vals[] = {
88 {FCOE_SOFi4, "SOFi4" },
89 {FCOE_SOFi2, "SOFi2" },
90 {FCOE_SOFi3, "SOFi3" },
91 {FCOE_SOFn4, "SOFn4" },
92 {FCOE_SOFn2, "SOFn2" },
93 {FCOE_SOFn3, "SOFn3" },
94 {FCOE_SOFc4, "SOFc4" },
98 static int proto_fcoe = -1;
99 static int hf_fcoe_ver = -1;
100 static int hf_fcoe_len = -1;
101 static int hf_fcoe_sof = -1;
102 static int hf_fcoe_eof = -1;
103 static int hf_fcoe_crc = -1;
104 static int hf_fcoe_crc_bad = -1;
105 static int hf_fcoe_crc_good = -1;
107 static int ett_fcoe = -1;
108 static int ett_fcoe_crc = -1;
110 static dissector_handle_t data_handle;
111 static dissector_handle_t fc_handle;
114 dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
119 gint header_len = FCOE_HEADER_LEN;
123 gint bytes_remaining;
131 proto_tree *fcoe_tree = NULL;
132 proto_tree *crc_tree;
135 guint32 crc_computed = 0;
139 * For now, handle both the version defined before and after August 2007.
140 * In the newer version, byte 1 is reserved and always zero. In the old
141 * version, it'll never be zero.
143 if (tvb_get_guint8(tvb, 1)) {
145 len_sof = tvb_get_ntohs(tvb, 0);
146 frame_len = ((len_sof & 0x3ff0) >> 2) - 4;
148 sof |= (sof < 8) ? 0x30 : 0x20;
149 version = len_sof >> 14;
152 ver = ep_strdup_printf(ver, "pre-T11 ver %d ", version);
154 frame_len = tvb_reported_length_remaining(tvb, 0) -
155 FCOE_HEADER_LEN - FCOE_TRAILER_LEN;
156 sof = tvb_get_guint8(tvb, FCOE_HEADER_LEN - 1);
159 * Only version 0 is defined at this point.
160 * Don't print the version in the short summary if it is zero.
163 version = tvb_get_guint8(tvb, 0) >> 4;
165 ver = ep_strdup_printf(ver, "ver %d ", version);
167 if (check_col(pinfo->cinfo, COL_PROTOCOL))
168 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FCoE");
169 crc_offset = header_len + frame_len;
170 eof_offset = crc_offset + 4;
171 bytes_remaining = tvb_length_remaining(tvb, header_len);
172 if (bytes_remaining > frame_len)
173 bytes_remaining = frame_len; /* backing length */
174 next_tvb = tvb_new_subset(tvb, header_len, bytes_remaining, frame_len);
179 if (tvb_bytes_exist(tvb, eof_offset, 1)) {
180 eof = tvb_get_guint8(tvb, eof_offset);
181 eof_str = val_to_str(eof, fcoe_eof_vals, "0x%x");
188 crc_exists = tvb_bytes_exist(tvb, crc_offset, 4);
190 crc = tvb_get_ntohl(tvb, crc_offset);
191 crc_computed = crc32_802_tvb(next_tvb, frame_len);
192 if (crc != crc_computed) {
193 crc_msg = " [bad FC CRC]";
197 if ((frame_len % 4) != 0 || frame_len < 24) {
198 len_msg = " [invalid length]";
201 ti = proto_tree_add_protocol_format(tree, proto_fcoe, tvb, 0,
203 "FCoE %s(%s/%s) %d bytes%s%s", ver,
204 val_to_str(sof, fcoe_sof_vals,
206 eof_str, frame_len, crc_msg,
209 /* Dissect the FCoE header */
211 fcoe_tree = proto_item_add_subtree(ti, ett_fcoe);
212 proto_tree_add_uint(fcoe_tree, hf_fcoe_ver, tvb, 0, 1, version);
213 if (tvb_get_guint8(tvb, 1)) {
214 proto_tree_add_uint(fcoe_tree, hf_fcoe_len, tvb, 0, 2, frame_len);
216 proto_tree_add_uint(fcoe_tree, hf_fcoe_sof, tvb,
217 header_len - 1, 1, sof);
220 * Create the CRC information.
223 if (crc == crc_computed) {
224 item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
226 "CRC: %8.8x [valid]", crc);
228 item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
231 "[error: should be %8.8x]",
233 expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR,
234 "Bad FC CRC %8.8x %8.x",
237 proto_tree_set_appendix(fcoe_tree, tvb, crc_offset,
238 tvb_length_remaining (tvb, crc_offset));
240 item = proto_tree_add_text(fcoe_tree, tvb, crc_offset, 0,
243 crc_tree = proto_item_add_subtree(item, ett_fcoe_crc);
244 ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_bad, tvb,
246 crc_exists && crc != crc_computed);
247 PROTO_ITEM_SET_GENERATED(ti);
248 ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_good, tvb,
250 crc_exists && crc == crc_computed);
251 PROTO_ITEM_SET_GENERATED(ti);
256 if (tvb_bytes_exist(tvb, eof_offset, 1)) {
257 proto_tree_add_item(fcoe_tree, hf_fcoe_eof, tvb, eof_offset, 1, 0);
261 /* Set the SOF/EOF flags in the packet_info header */
263 if (sof == FCOE_SOFi3 || sof == FCOE_SOFi2 || sof == FCOE_SOFi4) {
264 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
265 } else if (sof == FCOE_SOFf) {
266 pinfo->sof_eof = PINFO_SOF_SOFF;
269 if (eof != FCOE_EOFn) {
270 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
271 } else if (eof != FCOE_EOFt) {
272 pinfo->sof_eof |= PINFO_EOF_INVALID;
275 /* Call the FC Dissector if this is carrying an FC frame */
278 call_dissector(fc_handle, next_tvb, pinfo, tree);
279 } else if (data_handle) {
280 call_dissector(data_handle, next_tvb, pinfo, tree);
285 proto_register_fcoe(void)
287 module_t *fcoe_module;
289 /* Setup list of header fields See Section 1.6.1 for details*/
290 static hf_register_info hf[] = {
292 {"SOF", "fcoe.sof", FT_UINT8, BASE_HEX, VALS(&fcoe_sof_vals), 0,
295 {"EOF", "fcoe.eof", FT_UINT8, BASE_HEX, VALS(&fcoe_eof_vals), 0,
298 {"Version", "fcoe.ver", FT_UINT32, BASE_DEC, NULL, 0, "", HFILL}},
300 {"Frame length", "fcoe.len", FT_UINT32,
301 BASE_DEC, NULL, 0, "", HFILL}},
303 {"CRC", "fcoe.crc", FT_UINT32, BASE_HEX, NULL, 0, "", HFILL}},
305 {"CRC good", "fcoe.crc_good", FT_BOOLEAN, BASE_NONE, NULL, 0,
306 "True: CRC matches packet content; "
307 "False: doesn't match or not checked.", HFILL }},
309 {"CRC bad", "fcoe.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0,
310 "True: CRC doesn't match packet content; "
311 "False: matches or not checked.", HFILL }}
313 static gint *ett[] = {
318 /* Register the protocol name and description */
319 proto_fcoe = proto_register_protocol("Fibre Channel over Ethernet",
322 /* Required function calls to register the header fields and
324 proto_register_field_array(proto_fcoe, hf, array_length(hf));
325 proto_register_subtree_array(ett, array_length(ett));
327 fcoe_module = prefs_register_protocol(proto_fcoe, NULL);
329 prefs_register_obsolete_preference(fcoe_module, "ethertype");
333 * This function name is required because a script is used to find these
334 * routines and create the code that calls these routines.
337 proto_reg_handoff_fcoe(void)
339 dissector_handle_t fcoe_handle;
341 fcoe_handle = create_dissector_handle(dissect_fcoe, proto_fcoe);
342 dissector_add("ethertype", ETHERTYPE_FCOE, fcoe_handle);
343 data_handle = find_dissector("data");
344 fc_handle = find_dissector("fc");