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@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 * For FCoE protocol details, see http://fcoe.com.
37 #include <epan/packet.h>
38 #include <epan/prefs.h>
39 #include <epan/crc32-tvb.h>
40 #include <epan/etypes.h>
41 #include <epan/expert.h>
43 #define FCOE_HEADER_LEN 14 /* header: version, SOF, and padding */
44 #define FCOE_TRAILER_LEN 8 /* trailer: CRC, EOF, and padding */
68 static const value_string fcoe_eof_vals[] = {
71 {FCOE_EOFrt, "EOFrt" },
72 {FCOE_EOFdt, "EOFdt" },
73 {FCOE_EOFni, "EOFni" },
74 {FCOE_EOFdti, "EOFdti" },
75 {FCOE_EOFrti, "EOFrti" },
80 static const value_string fcoe_sof_vals[] = {
82 {FCOE_SOFi4, "SOFi4" },
83 {FCOE_SOFi2, "SOFi2" },
84 {FCOE_SOFi3, "SOFi3" },
85 {FCOE_SOFn4, "SOFn4" },
86 {FCOE_SOFn2, "SOFn2" },
87 {FCOE_SOFn3, "SOFn3" },
88 {FCOE_SOFc4, "SOFc4" },
92 static int proto_fcoe = -1;
93 static int hf_fcoe_ver = -1;
94 static int hf_fcoe_len = -1;
95 static int hf_fcoe_sof = -1;
96 static int hf_fcoe_eof = -1;
97 static int hf_fcoe_crc = -1;
98 static int hf_fcoe_crc_bad = -1;
99 static int hf_fcoe_crc_good = -1;
101 static int ett_fcoe = -1;
102 static int ett_fcoe_crc = -1;
104 static dissector_handle_t data_handle;
105 static dissector_handle_t fc_handle;
108 dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
113 gint header_len = FCOE_HEADER_LEN;
117 gint bytes_remaining;
125 proto_tree *fcoe_tree;
126 proto_tree *crc_tree;
129 guint32 crc_computed = 0;
133 * For now, handle both the version defined before and after August 2007.
134 * In the newer version, byte 1 is reserved and always zero. In the old
135 * version, it'll never be zero.
137 if (tvb_get_guint8(tvb, 1)) {
139 len_sof = tvb_get_ntohs(tvb, 0);
140 frame_len = ((len_sof & 0x3ff0) >> 2) - 4;
142 sof |= (sof < 8) ? 0x30 : 0x20;
143 version = len_sof >> 14;
146 ver = ep_strdup_printf(ver, "pre-T11 ver %d ", version);
148 frame_len = tvb_reported_length_remaining(tvb, 0) -
149 FCOE_HEADER_LEN - FCOE_TRAILER_LEN;
150 sof = tvb_get_guint8(tvb, FCOE_HEADER_LEN - 1);
153 * Only version 0 is defined at this point.
154 * Don't print the version in the short summary if it is zero.
157 version = tvb_get_guint8(tvb, 0) >> 4;
159 ver = ep_strdup_printf(ver, "ver %d ", version);
161 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FCoE");
162 crc_offset = header_len + frame_len;
163 eof_offset = crc_offset + 4;
164 bytes_remaining = tvb_length_remaining(tvb, header_len);
165 if (bytes_remaining > frame_len)
166 bytes_remaining = frame_len; /* backing length */
167 next_tvb = tvb_new_subset(tvb, header_len, bytes_remaining, frame_len);
170 if (tvb_bytes_exist(tvb, eof_offset, 1)) {
171 eof = tvb_get_guint8(tvb, eof_offset);
172 eof_str = val_to_str(eof, fcoe_eof_vals, "0x%x");
179 crc_exists = tvb_bytes_exist(tvb, crc_offset, 4);
181 crc = tvb_get_ntohl(tvb, crc_offset);
182 crc_computed = crc32_802_tvb(next_tvb, frame_len);
183 if (crc != crc_computed) {
184 crc_msg = " [bad FC CRC]";
188 if ((frame_len % 4) != 0 || frame_len < 24) {
189 len_msg = " [invalid length]";
192 ti = proto_tree_add_protocol_format(tree, proto_fcoe, tvb, 0,
194 "FCoE %s(%s/%s) %d bytes%s%s", ver,
195 val_to_str(sof, fcoe_sof_vals,
197 eof_str, frame_len, crc_msg,
200 /* Dissect the FCoE header */
202 fcoe_tree = proto_item_add_subtree(ti, ett_fcoe);
203 proto_tree_add_uint(fcoe_tree, hf_fcoe_ver, tvb, 0, 1, version);
204 if (tvb_get_guint8(tvb, 1)) {
205 proto_tree_add_uint(fcoe_tree, hf_fcoe_len, tvb, 0, 2, frame_len);
207 proto_tree_add_uint(fcoe_tree, hf_fcoe_sof, tvb,
208 header_len - 1, 1, sof);
211 * Create the CRC information.
214 if (crc == crc_computed) {
215 item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
217 "CRC: %8.8x [valid]", crc);
219 item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
222 "[error: should be %8.8x]",
224 expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR,
225 "Bad FC CRC %8.8x %8.x",
228 proto_tree_set_appendix(fcoe_tree, tvb, crc_offset,
229 tvb_length_remaining (tvb, crc_offset));
231 item = proto_tree_add_text(fcoe_tree, tvb, crc_offset, 0,
234 crc_tree = proto_item_add_subtree(item, ett_fcoe_crc);
235 ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_bad, tvb,
237 crc_exists && crc != crc_computed);
238 PROTO_ITEM_SET_GENERATED(ti);
239 ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_good, tvb,
241 crc_exists && crc == crc_computed);
242 PROTO_ITEM_SET_GENERATED(ti);
247 if (tvb_bytes_exist(tvb, eof_offset, 1)) {
248 proto_tree_add_item(fcoe_tree, hf_fcoe_eof, tvb, eof_offset, 1, ENC_BIG_ENDIAN);
251 /* Set the SOF/EOF flags in the packet_info header */
253 if (sof == FCOE_SOFi3 || sof == FCOE_SOFi2 || sof == FCOE_SOFi4) {
254 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
255 } else if (sof == FCOE_SOFf) {
256 pinfo->sof_eof = PINFO_SOF_SOFF;
259 if (eof != FCOE_EOFn) {
260 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
261 } else if (eof != FCOE_EOFt) {
262 pinfo->sof_eof |= PINFO_EOF_INVALID;
265 /* Call the FC Dissector if this is carrying an FC frame */
268 call_dissector(fc_handle, next_tvb, pinfo, tree);
269 } else if (data_handle) {
270 call_dissector(data_handle, next_tvb, pinfo, tree);
275 proto_register_fcoe(void)
277 module_t *fcoe_module;
279 /* Setup list of header fields See Section 1.6.1 for details*/
280 static hf_register_info hf[] = {
282 {"SOF", "fcoe.sof", FT_UINT8, BASE_HEX, VALS(fcoe_sof_vals), 0,
285 {"EOF", "fcoe.eof", FT_UINT8, BASE_HEX, VALS(fcoe_eof_vals), 0,
288 {"Version", "fcoe.ver", FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL}},
290 {"Frame length", "fcoe.len", FT_UINT32,
291 BASE_DEC, NULL, 0, NULL, HFILL}},
293 {"CRC", "fcoe.crc", FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL}},
295 {"CRC good", "fcoe.crc_good", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
296 "True: CRC matches packet content; False: doesn't match or not checked.", HFILL }},
298 {"CRC bad", "fcoe.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
299 "True: CRC doesn't match packet content; False: matches or not checked.", HFILL }}
301 static gint *ett[] = {
306 /* Register the protocol name and description */
307 proto_fcoe = proto_register_protocol("Fibre Channel over Ethernet",
310 /* Required function calls to register the header fields and
312 proto_register_field_array(proto_fcoe, hf, array_length(hf));
313 proto_register_subtree_array(ett, array_length(ett));
315 fcoe_module = prefs_register_protocol(proto_fcoe, NULL);
317 prefs_register_obsolete_preference(fcoe_module, "ethertype");
321 proto_reg_handoff_fcoe(void)
323 dissector_handle_t fcoe_handle;
325 fcoe_handle = create_dissector_handle(dissect_fcoe, proto_fcoe);
326 dissector_add_uint("ethertype", ETHERTYPE_FCOE, fcoe_handle);
327 data_handle = find_dissector("data");
328 fc_handle = find_dissector("fc");