3 * Routines for FIP dissection - FCoE Initialization Protocol
4 * Copyright (c) 2008 Cisco Systems, Inc. (jeykholt@cisco.com)
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Based on packet-fcoe.c, Copyright 2006, Nuova Systems, (jre@nuovasystems.com)
13 * Based on packet-fcp.c, Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 * For FIP protocol details, see http://t11.org.
32 * This version uses preliminary details not yet standardized.
33 * Based on http://www.t11.org/ftp/t11/pub/fc/bb-5/08-543v1.pdf
34 * and http://www.t11.org/ftp/t11/pub/fc/bb-5/08-545v1.pdf
47 #include <epan/packet.h>
48 #include <epan/etypes.h>
49 #include <epan/expert.h>
51 void proto_reg_handoff_fip(void);
54 * FIP protocol information.
56 #define FIP_HEADER_LEN 10
57 #define FIP_BPW 4 /* bytes per descriptor length unit */
60 * FIP opcodes and subcodes.
63 FIP_OP_DISC = 1, /* discovery, advertisement, etc. */
64 FIP_OP_LS = 2, /* Link Service request or reply */
65 FIP_OP_CTRL = 3, /* control */
66 FIP_OP_VLAN = 4 /* VLAN request or reply */
70 * Subcodes for FIP_OP_DISC.
72 enum fip_disc_subcode {
73 FIP_SC_SOL = 1, /* solicitation */
74 FIP_SC_ADV = 2 /* advertisement */
78 * Subcodes for FIP_OP_LS.
81 FIP_SC_REQ = 1, /* request */
82 FIP_SC_REP = 2 /* reply */
85 enum fip_ctrl_subcode {
86 FIP_SC_KA = 1, /* keep-alive */
87 FIP_SC_CVL = 2 /* clear virtual link */
90 enum fip_vlan_subcode {
91 FIP_VL_REQ = 1, /* request */
92 FIP_VL_REP = 2 /* reply */
95 static const value_string fip_opcodes[] = {
96 { FIP_OP_DISC, "Discovery" },
97 { FIP_OP_LS, "Link Service" },
98 { FIP_OP_CTRL, "Control" },
99 { FIP_OP_VLAN, "VLAN" },
103 static const value_string fip_disc_subcodes[] = {
104 { FIP_SC_SOL, "Solicitation" },
105 { FIP_SC_ADV, "Advertisement" },
109 static const value_string fip_ls_subcodes[] = {
110 { FIP_SC_REQ, "ELS Request" },
111 { FIP_SC_REP, "ELS Response" },
115 static const value_string fip_ctrl_subcodes[] = {
116 { FIP_SC_KA, "Keep-Alive" },
117 { FIP_SC_CVL, "Clear Virtual Link" },
121 static const value_string fip_vlan_subcodes[] = {
122 { FIP_VL_REQ, "VLAN Request" },
123 { FIP_VL_REP, "VLAN Response" },
131 FIP_DT_PRI = 1, /* priority for forwarder selection */
132 FIP_DT_MAC = 2, /* MAC address */
133 FIP_DT_MAP_OUI = 3, /* FC-MAP OUI */
134 FIP_DT_NAME = 4, /* switch name or node name */
135 FIP_DT_FAB = 5, /* fabric descriptor */
136 FIP_DT_FCOE_SIZE = 6, /* max FCoE frame size */
137 FIP_DT_FLOGI = 7, /* FLOGI request or response */
138 FIP_DT_FDISC = 8, /* FDISC request or response */
139 FIP_DT_LOGO = 9, /* LOGO request or response */
140 FIP_DT_ELP = 10, /* ELP request or response */
141 FIP_DT_VN = 11, /* VN_Port Info */
142 FIP_DT_FKA = 12, /* FIP keep-alive / advert. period */
143 FIP_DT_VEND = 13, /* Vendor-specific TLV */
144 FIP_DT_VLAN = 14 /* VLAN number */
147 static const value_string fip_desc_types[] = {
148 { FIP_DT_PRI, "Priority" },
149 { FIP_DT_MAC, "MAC Address" },
150 { FIP_DT_MAP_OUI, "FPMA MAP OUI" },
151 { FIP_DT_NAME, "Switch or Node Name" },
152 { FIP_DT_FAB, "Fabric Descriptor" },
153 { FIP_DT_FCOE_SIZE, "Max FCoE frame size" },
154 { FIP_DT_FLOGI, "FLOGI Encapsulation" },
155 { FIP_DT_FDISC, "FDISC Encapsulation" },
156 { FIP_DT_LOGO, "LOGO Encapsulation" },
157 { FIP_DT_ELP, "ELP Encapsulation" },
158 { FIP_DT_VN, "VN_Port Info" },
159 { FIP_DT_FKA, "FKA_ADV_Period" },
160 { FIP_DT_VEND, "Vendor_ID" },
161 { FIP_DT_VLAN, "VLAN" },
166 * flags in header fip_flags.
169 FIP_FL_FPMA = 0x8000, /* supports FPMA fabric-provided MACs */
170 FIP_FL_SPMA = 0x4000, /* supports SPMA server-provided MACs */
171 FIP_FL_AVAIL = 0x0004, /* available for FLOGI */
172 FIP_FL_SOL = 0x0002, /* this is a solicited message */
173 FIP_FL_FPORT = 0x0001 /* sent from an F port */
176 static int proto_fip = -1;
177 static int hf_fip_ver = -1;
178 static int hf_fip_op = -1;
179 static int hf_fip_disc_subcode = -1;
180 static int hf_fip_ls_subcode = -1;
181 static int hf_fip_ctrl_subcode = -1;
182 static int hf_fip_vlan_subcode = -1;
183 static int hf_fip_hex_subcode = -1;
184 static int hf_fip_dlen = -1;
185 static int hf_fip_flags = -1;
186 static int hf_fip_flag_fpma = -1;
187 static int hf_fip_flag_spma = -1;
188 static int hf_fip_flag_avail = -1;
189 static int hf_fip_flag_sol = -1;
190 static int hf_fip_flag_fport = -1;
192 static const int *hf_fip_flags_fields[] = {
201 static int hf_fip_desc_type = -1;
202 static int hf_fip_desc_len = -1;
203 static int hf_fip_desc_pri = -1;
204 static int hf_fip_desc_mac = -1;
205 static int hf_fip_desc_map = -1;
206 static int hf_fip_desc_name = -1;
207 static int hf_fip_desc_fab_vfid = -1;
208 static int hf_fip_desc_fab_map = -1;
209 static int hf_fip_desc_fab_name = -1;
210 static int hf_fip_desc_fcoe_size = -1;
211 static int hf_fip_desc_vn_mac = -1;
212 static int hf_fip_desc_vn_fid = -1;
213 static int hf_fip_desc_vn_wwpn = -1;
214 static int hf_fip_desc_fka = -1;
215 static int hf_fip_desc_vend = -1;
216 static int hf_fip_desc_vend_data = -1;
217 static int hf_fip_desc_vlan = -1;
218 static int hf_fip_desc_unk = -1;
220 static int ett_fip = -1;
221 static int ett_fip_flags = -1;
222 static int ett_fip_dt_pri = -1;
223 static int ett_fip_dt_mac = -1;
224 static int ett_fip_dt_map = -1;
225 static int ett_fip_dt_name = -1;
226 static int ett_fip_dt_fab = -1;
227 static int ett_fip_dt_mdl = -1;
228 static int ett_fip_dt_caps = -1;
229 static int ett_fip_dt_vn = -1;
230 static int ett_fip_dt_fka = -1;
231 static int ett_fip_dt_vend = -1;
232 static int ett_fip_dt_vlan = -1;
233 static int ett_fip_dt_unk = -1;
235 static dissector_handle_t fc_handle;
238 * Insert common descriptor type and length fields.
241 fip_desc_type_len(proto_tree *tree, tvbuff_t *tvb)
243 proto_tree_add_item(tree, hf_fip_desc_type, tvb, 0, 1, FALSE);
244 proto_tree_add_item(tree, hf_fip_desc_len, tvb, 1, 1, FALSE);
248 dissect_fip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
255 proto_tree *fip_tree;
262 tvbuff_t *ls_tvb = NULL;
266 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FIP");
268 if (!tvb_bytes_exist(tvb, 0, FIP_HEADER_LEN)) {
269 col_set_str(pinfo->cinfo, COL_INFO, "[packet too short]");
271 proto_tree_add_protocol_format(tree, proto_fip, tvb, 0,
272 -1, "FIP [packet too short]");
276 op = tvb_get_ntohs(tvb, 2);
277 sub = tvb_get_guint8(tvb, 5);
281 info = val_to_str(sub, fip_disc_subcodes, "Discovery 0x%x");
284 info = val_to_str(sub, fip_ls_subcodes, "Link Service 0x%x");
287 info = val_to_str(sub, fip_ctrl_subcodes, "Control 0x%x");
290 info = val_to_str(sub, fip_vlan_subcodes, "VLAN 0x%x");
293 info = val_to_str(op, fip_opcodes, "Unknown op 0x%x");
297 col_set_str(pinfo->cinfo, COL_INFO, info);
299 rlen = tvb_get_ntohs(tvb, 6);
301 ti = proto_tree_add_protocol_format(tree, proto_fip, tvb, 0,
302 FIP_HEADER_LEN + rlen * FIP_BPW,
304 fip_tree = proto_item_add_subtree(ti, ett_fip);
305 proto_tree_add_item(fip_tree, hf_fip_ver, tvb, 0, 1, FALSE);
306 proto_tree_add_item(fip_tree, hf_fip_op, tvb, 2, 2, FALSE);
309 proto_tree_add_item(fip_tree, hf_fip_disc_subcode, tvb, 5, 1, FALSE);
312 proto_tree_add_item(fip_tree, hf_fip_ls_subcode, tvb, 5, 1, FALSE);
315 proto_tree_add_item(fip_tree, hf_fip_ctrl_subcode, tvb, 5, 1, FALSE);
318 proto_tree_add_item(fip_tree, hf_fip_vlan_subcode, tvb, 5, 1, FALSE);
321 proto_tree_add_item(fip_tree, hf_fip_hex_subcode, tvb, 5, 1, FALSE);
324 proto_tree_add_item(fip_tree, hf_fip_dlen, tvb, 6, 2, FALSE);
326 proto_tree_add_bitmask(fip_tree, tvb, 8, hf_fip_flags,
327 ett_fip_flags, hf_fip_flags_fields, FALSE);
329 desc_offset = FIP_HEADER_LEN;
331 proto_tree_add_text(fip_tree, tvb, desc_offset, rlen, "Descriptors:");
333 while (rlen > 0 && tvb_bytes_exist(tvb, desc_offset, 2)) {
334 dlen = tvb_get_guint8(tvb, desc_offset + 1) * FIP_BPW;
336 proto_tree_add_text(fip_tree, tvb, desc_offset, -1,
337 "Descriptor [length error]");
340 if (!tvb_bytes_exist(tvb, desc_offset, dlen) || dlen > rlen) {
343 desc_tvb = tvb_new_subset(tvb, desc_offset, dlen, -1);
344 dtype = tvb_get_guint8(desc_tvb, 0);
348 item = proto_tree_add_text(fip_tree, desc_tvb, 0, -1, "Descriptor: %s ",
349 val_to_str(dtype, fip_desc_types, "Unknown 0x%x"));
353 subtree = proto_item_add_subtree(item, ett_fip_dt_pri);
354 fip_desc_type_len(subtree, desc_tvb);
355 proto_tree_add_item(subtree, hf_fip_desc_pri, desc_tvb,
357 proto_item_append_text(item, "%u", tvb_get_guint8(desc_tvb, 3));
360 subtree = proto_item_add_subtree(item, ett_fip_dt_mac);
361 fip_desc_type_len(subtree, desc_tvb);
362 proto_tree_add_item(subtree, hf_fip_desc_mac, desc_tvb,
364 proto_item_append_text(item, "%s",
365 tvb_bytes_to_str_punct(desc_tvb, 2, 6, ':'));
368 subtree = proto_item_add_subtree(item, ett_fip_dt_map);
369 fip_desc_type_len(subtree, desc_tvb);
370 text = fc_to_str(tvb_get_ptr(desc_tvb, 5, 3));
371 proto_tree_add_string(subtree, hf_fip_desc_map, desc_tvb,
373 proto_item_append_text(item, "%s", text);
376 subtree = proto_item_add_subtree(item, ett_fip_dt_name);
377 fip_desc_type_len(subtree, desc_tvb);
378 text = fcwwn_to_str(tvb_get_ptr(desc_tvb, 4, 8));
379 proto_tree_add_string(subtree, hf_fip_desc_name,
380 desc_tvb, 4, 8, text);
381 proto_item_append_text(item, "%s", text);
384 subtree = proto_item_add_subtree(item, ett_fip_dt_fab);
385 fip_desc_type_len(subtree, desc_tvb);
386 proto_tree_add_item(subtree, hf_fip_desc_fab_vfid, desc_tvb,
388 text = fc_to_str(tvb_get_ptr(desc_tvb, 5, 3));
389 proto_tree_add_string(subtree, hf_fip_desc_fab_map, desc_tvb,
391 text = fcwwn_to_str(tvb_get_ptr(desc_tvb, 8, 8));
392 proto_tree_add_string(subtree, hf_fip_desc_fab_name,
393 desc_tvb, 8, 8, text);
394 proto_item_append_text(item, "%s", text);
396 case FIP_DT_FCOE_SIZE:
397 subtree = proto_item_add_subtree(item, ett_fip_dt_mdl);
398 fip_desc_type_len(subtree, desc_tvb);
399 proto_tree_add_item(subtree, hf_fip_desc_fcoe_size, desc_tvb,
401 proto_item_append_text(item, "%u", tvb_get_ntohs(desc_tvb, 2));
407 subtree = proto_item_add_subtree(item, ett_fip_dt_caps);
408 fip_desc_type_len(subtree, desc_tvb);
409 ls_tvb = tvb_new_subset(desc_tvb, 4, dlen - 4, -1);
410 call_dissector(fc_handle, ls_tvb, pinfo, subtree);
411 proto_item_append_text(item, "%u bytes", dlen - 4);
414 subtree = proto_item_add_subtree(item, ett_fip_dt_vn);
415 fip_desc_type_len(subtree, desc_tvb);
416 proto_tree_add_item(subtree, hf_fip_desc_vn_mac, desc_tvb,
418 proto_tree_add_item(subtree, hf_fip_desc_vn_fid, desc_tvb,
420 text = fcwwn_to_str(tvb_get_ptr(desc_tvb, 12, 8));
421 proto_tree_add_string(subtree, hf_fip_desc_vn_wwpn,
422 desc_tvb, 12, 8, text);
423 proto_item_append_text(item, "MAC %s FC_ID %6.6x",
424 tvb_bytes_to_str_punct(desc_tvb, 2, 6, ':'),
425 tvb_get_ntoh24(desc_tvb, 9));
428 subtree = proto_item_add_subtree(item, ett_fip_dt_fka);
429 fip_desc_type_len(subtree, desc_tvb);
430 val = tvb_get_ntohl(desc_tvb, 4);
431 proto_tree_add_uint_format_value(subtree, hf_fip_desc_fka,
432 desc_tvb, 4, 4, val, "%u ms", val);
433 proto_item_append_text(item, "%u ms", val);
436 subtree = proto_item_add_subtree(item, ett_fip_dt_vend);
437 fip_desc_type_len(subtree, desc_tvb);
438 proto_tree_add_item(subtree, hf_fip_desc_vend, desc_tvb,
440 if (tvb_bytes_exist(desc_tvb, 9, -1)) {
441 proto_tree_add_item(subtree, hf_fip_desc_vend_data,
442 desc_tvb, 9, -1, FALSE);
446 subtree = proto_item_add_subtree(item, ett_fip_dt_vlan);
447 fip_desc_type_len(subtree, desc_tvb);
448 proto_tree_add_item(subtree, hf_fip_desc_vlan, desc_tvb,
450 proto_item_append_text(item, "%u", tvb_get_ntohs(desc_tvb, 2));
453 subtree = proto_item_add_subtree(item, ett_fip_dt_unk);
454 fip_desc_type_len(subtree, desc_tvb);
455 proto_tree_add_item(subtree, hf_fip_desc_unk, desc_tvb,
463 proto_register_fip(void)
465 /* Setup list of header fields See Section 1.6.1 for details*/
466 static hf_register_info hf[] = {
471 {"Version", "fip.ver", FT_UINT8, BASE_DEC,
472 NULL, 0xf0, NULL, HFILL}},
474 {"Opcode", "fip.opcode", FT_UINT16, BASE_HEX,
475 VALS(fip_opcodes), 0, NULL, HFILL}},
476 { &hf_fip_disc_subcode,
477 {"Discovery Subcode", "fip.disc_subcode", FT_UINT8, BASE_HEX,
478 VALS(fip_disc_subcodes), 0, NULL, HFILL}},
479 { &hf_fip_ls_subcode,
480 {"Link Service Subcode", "fip.ls.subcode", FT_UINT8, BASE_HEX,
481 VALS(fip_ls_subcodes), 0, NULL, HFILL}},
482 { &hf_fip_ctrl_subcode,
483 {"Control Subcode", "fip.ctrl_subcode", FT_UINT8, BASE_HEX,
484 VALS(fip_ctrl_subcodes), 0, NULL, HFILL}},
485 { &hf_fip_vlan_subcode,
486 {"VLAN Subcode", "fip.vlan_subcode", FT_UINT8, BASE_HEX,
487 VALS(fip_vlan_subcodes), 0, NULL, HFILL}},
488 { &hf_fip_hex_subcode,
489 {"Unknown Subcode", "fip.subcode", FT_UINT8, BASE_HEX,
490 NULL, 0, NULL, HFILL}},
492 {"Length of Descriptors (words)", "fip.dl_len", FT_UINT16, BASE_DEC,
493 NULL, 0, NULL, HFILL}},
495 {"Flags", "fip.flags", FT_UINT16, BASE_HEX,
496 NULL, 0, NULL, HFILL}},
498 {"Fabric Provided MAC addr", "fip.flags.fpma", FT_BOOLEAN, 16,
499 NULL, FIP_FL_FPMA, NULL, HFILL}},
501 {"Server Provided MAC addr", "fip.flags.spma", FT_BOOLEAN, 16,
502 NULL, FIP_FL_SPMA, NULL, HFILL}},
503 { &hf_fip_flag_avail,
504 {"Available", "fip.flags.available", FT_BOOLEAN, 16,
505 NULL, FIP_FL_AVAIL, NULL, HFILL}},
507 {"Solicited", "fip.flags.sol", FT_BOOLEAN, 16,
508 NULL, FIP_FL_SOL, NULL, HFILL}},
509 { &hf_fip_flag_fport,
510 {"F_Port", "fip.flags.fport", FT_BOOLEAN, 16,
511 NULL, FIP_FL_FPORT, NULL, HFILL}},
513 {"Descriptor Type", "fip.desc_type", FT_UINT8, BASE_HEX,
514 VALS(fip_desc_types), 0, NULL, HFILL}},
516 {"Descriptor Length (words)", "fip.desc_len", FT_UINT8, BASE_DEC,
517 NULL, 0, NULL, HFILL}},
519 * Various descriptor fields.
522 {"Priority", "fip.pri", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL}},
524 {"MAC Address", "fip.mac", FT_ETHER, BASE_NONE, NULL,
527 {"FC-MAP-OUI", "fip.map", FT_STRING, BASE_NONE, NULL,
530 {"Switch or Node Name", "fip.name", FT_STRING, BASE_NONE, NULL,
532 { &hf_fip_desc_fab_vfid,
533 {"VFID", "fip.fab.vfid", FT_UINT16, BASE_DEC, NULL,
535 { &hf_fip_desc_fab_map,
536 {"FC-MAP", "fip.fab.map", FT_STRING, BASE_NONE, NULL,
538 { &hf_fip_desc_fab_name,
539 {"Fabric Name", "fip.fab.name", FT_STRING, BASE_NONE, NULL,
541 { &hf_fip_desc_fcoe_size,
542 {"Max FCoE frame size", "fip.fcoe_size", FT_UINT16, BASE_DEC, NULL,
544 { &hf_fip_desc_vn_mac,
545 {"VN_Port MAC Address", "fip.vn.mac", FT_ETHER, BASE_NONE, NULL,
547 { &hf_fip_desc_vn_fid,
548 {"VN_Port FC_ID", "fip.vn.fc_id", FT_UINT32, BASE_HEX, NULL,
550 { &hf_fip_desc_vn_wwpn,
551 {"Port Name", "fip.vn.pwwn", FT_STRING, BASE_NONE, NULL,
554 {"FKA_ADV_Period", "fip.fka", FT_UINT32, BASE_DEC, NULL,
557 {"Vendor-ID", "fip.vendor", FT_BYTES, BASE_NONE, NULL,
559 { &hf_fip_desc_vend_data,
560 {"Vendor-specific data", "fip.vendor.data", FT_BYTES, BASE_NONE, NULL,
563 {"VLAN", "fip.vlan", FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL}},
565 {"Unknown Descriptor", "fip.desc", FT_BYTES, BASE_NONE, NULL,
568 static gint *ett[] = {
585 /* Register the protocol name and description */
586 proto_fip = proto_register_protocol("FCoE Initialization Protocol",
589 /* Required function calls to register the header fields and
591 proto_register_field_array(proto_fip, hf, array_length(hf));
592 proto_register_subtree_array(ett, array_length(ett));
596 * This function name is required because a script is used to find these
597 * routines and create the code that calls these routines.
600 proto_reg_handoff_fip(void)
602 dissector_handle_t fip_handle;
604 fip_handle = create_dissector_handle(dissect_fip, proto_fip);
605 dissector_add("ethertype", ETHERTYPE_FIP, fip_handle);
606 fc_handle = find_dissector("fc");