2 * Routines for iFCP dissection
5 * Copyright 2005 Aboo Valappil (valappil_aboo@emc.com)
6 * 2006 ronnie sahlberg major refactoring
9 * Significantly based on packet-fcip.c by
10 * Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
14 * Wireshark - Network traffic analyzer
15 * By Gerald Combs <gerald@wireshark.org>
16 * Copyright 1998 Gerald Combs
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/conversation.h>
46 #include "packet-tcp.h"
48 #define iFCP_ENCAP_HEADER_LEN 28
49 #define iFCP_MIN_HEADER_LEN 16 /* upto frame len field */
74 FCENCAP_PROTO_FCIP = 1,
75 FCENCAP_PROTO_iFCP = 2
78 static const value_string ifcp_eof_vals[] = {
81 {iFCP_EOFrt, "EOFrt" },
82 {iFCP_EOFdt, "EOFdt" },
83 {iFCP_EOFni, "EOFni" },
84 {iFCP_EOFdti, "EOFdti" },
85 {iFCP_EOFrti, "EOFrti" },
90 static const value_string ifcp_sof_vals[] = {
92 {iFCP_SOFi4, "SOFi4" },
93 {iFCP_SOFi2, "SOFi2" },
94 {iFCP_SOFi3, "SOFi3" },
95 {iFCP_SOFn4, "SOFn4" },
96 {iFCP_SOFn2, "SOFn2" },
97 {iFCP_SOFn3, "SOFn3" },
98 {iFCP_SOFc4, "SOFc4" },
102 static const value_string fcencap_proto_vals[] = {
103 {FCENCAP_PROTO_iFCP, "iFCP"},
104 {FCENCAP_PROTO_iFCP, "iFCP"},
108 /* RFC 4172 section 5.3.1 shows a chart of the iFCP encapsulated Header Format.
109 * It says that bytes 4-7 MUST be zeros. In reality most vendors are putting
110 * some information in these 4 bytes, particularly Nishon.
112 static const guint8 ifcp_header_4_bytes[4] = {
113 0x02, 0x01, 0xFD, 0xFE
116 static int proto_ifcp = -1;
118 static int hf_ifcp_protocol = -1;
119 static int hf_ifcp_protocol_c = -1;
120 static int hf_ifcp_version = -1;
121 static int hf_ifcp_version_c = -1;
122 static int hf_ifcp_encap_flags_c=-1;
123 static int hf_ifcp_framelen = -1;
124 static int hf_ifcp_framelen_c = -1;
125 static int hf_ifcp_tsec = -1;
126 static int hf_ifcp_tusec = -1;
127 static int hf_ifcp_encap_crc = -1;
128 static int hf_ifcp_sof = -1;
129 static int hf_ifcp_sof_c = -1;
130 static int hf_ifcp_eof = -1;
131 static int hf_ifcp_eof_c = -1;
132 static int hf_ifcp_ls_command_acc = -1;
133 static int hf_ifcp_flags = -1;
134 static int hf_ifcp_flags_ses = -1;
135 static int hf_ifcp_flags_trp = -1;
136 static int hf_ifcp_flags_spc = -1;
137 static int hf_ifcp_common_flags = -1;
138 static int hf_ifcp_common_flags_crcv = -1;
140 static int ett_ifcp = -1;
141 static int ett_ifcp_sof = -1;
142 static int ett_ifcp_eof = -1;
143 static int ett_ifcp_flags = -1;
144 static int ett_ifcp_common_flags = -1;
145 static int ett_ifcp_protocol = -1;
146 static int ett_ifcp_version = -1;
147 static int ett_ifcp_frame_len = -1;
149 static gboolean ifcp_desegment = TRUE;
151 static dissector_handle_t ifcp_handle=NULL;
152 static dissector_handle_t data_handle=NULL;
153 static dissector_handle_t fc_handle=NULL;
156 /* This function checks the first 16 bytes of the "header" that it looks sane
157 * and returns TRUE if this looks like iFCP and FALSE if it doesnt.
160 ifcp_header_test(tvbuff_t *tvb, int offset)
164 /* we can only do this test if we have 16 bytes or more */
165 if(tvb_length_remaining(tvb, offset)<iFCP_MIN_HEADER_LEN){
170 * As per the iFCP standard, the following tests must PASS:
171 * 1) Frame Length field validation -- 15 < Frame Length < 545;
172 * 2) Comparison of Frame Length field to its ones complement; and
173 * 3) A valid EOF is found in the word preceding the start of the next
174 * iFCP header as indicated by the Frame Length field, to be tested
176 * 1) Bits 24-31 and 16-23 contain identical legal EOF values (the
177 * list of legal EOF values is in the FC Frame Encapsulation
179 * 2) Bits 8-15 and 0-7 contain the ones complement of the EOF
180 * value found in bits 24-31.
182 * As per the iFCP standard, in addition, at least 3 of the following
183 * set of tests must be performed to identify that we've located the
184 * start of an iFCP frame.
185 * a) Protocol# ones complement field (1 test);
186 * b) Version ones complement field (1 test);
187 * c) Replication of encapsulation word 0 in word 1 (1 test);
188 * d) Reserved field and its ones complement (2 tests);
189 * e) Flags field and its ones complement (2 tests);
190 * f) CRC field is equal to zero (1 test); (DONT DO THIS TEST!)
191 * g) SOF fields and ones complement fields (4 tests);
192 * h) Format and values of FC header (1 test);
193 * i) CRC of FC Frame (2 tests);
194 * j) FC Frame Encapsulation header information in the next iFCP Frame
197 * At least 3 of the 16 tests listed above SHALL be performed. Failure
198 * of any of the above tests actually performed SHALL indicate an
199 * encapsulation error and the FC Frame SHALL NOT be forwarded on to
207 if(tvb_memeql(tvb, offset, ifcp_header_4_bytes, 4) != 0){
211 /* check the frame length */
212 flen=tvb_get_ntohs(tvb, offset+12)&0x03FF;
213 if((flen < 15) || (flen > 545)){
217 /* check the complement of the frame length */
218 flen1=tvb_get_ntohs(tvb, offset+14)&0x03FF;
219 if(flen!=((~flen1)&0x03FF)){
224 /* this should be good enough for our heuristics */
229 #define IFCP_FLAGS_SES 0x04
230 #define IFCP_FLAGS_TRP 0x02
231 #define IFCP_FLAGS_SPC 0x01
233 static const true_false_string ifcp_flags_ses_tfs = {
234 "This is a SESSION CONTROL FRAME",
235 "This is a normal frame"
238 static const true_false_string ifcp_flags_trp_tfs = {
239 "Address TRANSPARENT Mode Enabled",
240 "Address TRANSLATION Mode Enabled"
243 static const true_false_string ifcp_flags_spc_tfs = {
244 "This frame requires SPECIAL PROCESSING",
245 "This is a normal frame"
249 dissect_ifcpflags(tvbuff_t *tvb, int offset, proto_tree *parent_tree)
251 proto_item *item=NULL;
252 proto_tree *tree=NULL;
256 item=proto_tree_add_item(parent_tree, hf_ifcp_flags, tvb, offset, 1, 0);
257 tree=proto_item_add_subtree (item, ett_ifcp_flags);
260 flags=tvb_get_guint8(tvb, offset);
263 proto_tree_add_boolean(tree, hf_ifcp_flags_ses, tvb, offset, 1, flags);
264 if(flags&IFCP_FLAGS_SES){
265 proto_item_append_text(item, " SES");
267 flags&=(~IFCP_FLAGS_SES);
270 proto_tree_add_boolean(tree, hf_ifcp_flags_trp, tvb, offset, 1, flags);
271 if(flags&IFCP_FLAGS_TRP){
272 proto_item_append_text(item, " TRP");
274 flags&=(~IFCP_FLAGS_TRP);
277 proto_tree_add_boolean(tree, hf_ifcp_flags_spc, tvb, offset, 1, flags);
278 if(flags&IFCP_FLAGS_SPC){
279 proto_item_append_text(item, " SPC");
281 flags&=(~IFCP_FLAGS_SPC);
289 #define IFCP_COMMON_FLAGS_CRCV 0x04
291 static const true_false_string ifcp_common_flags_crcv_tfs = {
297 dissect_commonflags(tvbuff_t *tvb, int offset, proto_tree *parent_tree)
299 proto_item *item=NULL;
300 proto_tree *tree=NULL;
304 item=proto_tree_add_item(parent_tree, hf_ifcp_common_flags, tvb, offset, 1, 0);
305 tree=proto_item_add_subtree (item, ett_ifcp_common_flags);
308 flags=tvb_get_guint8(tvb, offset);
311 proto_tree_add_boolean(tree, hf_ifcp_common_flags_crcv, tvb, offset, 1, flags);
312 if(flags&IFCP_COMMON_FLAGS_CRCV){
313 proto_item_append_text(item, " CRCV");
315 flags&=(~IFCP_COMMON_FLAGS_CRCV);
319 dissect_ifcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
321 gint offset = 0, frame_len = 0;
322 guint8 sof = 0, eof = 0;
324 proto_tree *tree = NULL;
327 proto_tree *protocol_tree=NULL;
328 proto_tree *version_tree=NULL;
329 proto_tree *frame_len_tree=NULL;
330 proto_tree *sof_tree=NULL;
331 proto_tree *eof_tree=NULL;
333 /* verify we have a full header (do we need to do this? */
334 if(tvb_length(tvb)<iFCP_ENCAP_HEADER_LEN){
338 if(check_col(pinfo->cinfo, COL_PROTOCOL)){
339 col_set_str(pinfo->cinfo, COL_PROTOCOL, "iFCP");
342 frame_len = (tvb_get_ntohs (tvb, offset+12) & 0x03FF)*4;
346 if (tvb_bytes_exist (tvb, offset, frame_len-4)) {
347 sof = tvb_get_guint8 (tvb, offset+iFCP_ENCAP_HEADER_LEN);
348 eof = tvb_get_guint8 (tvb, offset+frame_len - 4);
350 ti = proto_tree_add_protocol_format (parent_tree, proto_ifcp, tvb, offset,
351 iFCP_ENCAP_HEADER_LEN,
353 val_to_str (sof, ifcp_sof_vals,
355 val_to_str (eof, ifcp_eof_vals,
358 sof = tvb_get_guint8 (tvb, offset+iFCP_ENCAP_HEADER_LEN);
360 ti = proto_tree_add_protocol_format (parent_tree, proto_ifcp, tvb, offset,
361 iFCP_ENCAP_HEADER_LEN,
363 val_to_str (sof, ifcp_sof_vals,
367 tree = proto_item_add_subtree (ti, ett_ifcp);
372 /* The Common FC Encap header */
374 protocol = tvb_get_guint8 (tvb, offset);
375 ti=proto_tree_add_item(tree, hf_ifcp_protocol, tvb, offset, 1, 0);
377 protocol_tree=proto_item_add_subtree(ti, ett_ifcp_protocol);
382 ti=proto_tree_add_item(tree, hf_ifcp_version, tvb, offset, 1, 0);
384 version_tree=proto_item_add_subtree(ti, ett_ifcp_version);
388 /* protocol complement */
389 proto_tree_add_item(protocol_tree, hf_ifcp_protocol_c, tvb, offset, 1, 0);
392 /* version complement */
393 proto_tree_add_item(version_tree, hf_ifcp_version_c, tvb, offset, 1, 0);
396 /* 4 reserved bytes */
399 /* iFCP specific fields */
400 if(protocol==FCENCAP_PROTO_iFCP){
402 proto_tree_add_item(tree, hf_ifcp_ls_command_acc, tvb, offset, 1, 0);
406 offset=dissect_ifcpflags(tvb, offset, tree);
409 ti=proto_tree_add_item(tree, hf_ifcp_sof, tvb, offset, 1, 0);
411 sof_tree=proto_item_add_subtree(ti, ett_ifcp_sof);
416 ti=proto_tree_add_item(tree, hf_ifcp_eof, tvb, offset, 1, 0);
418 eof_tree=proto_item_add_subtree(ti, ett_ifcp_eof);
423 sof_tree=tree; /* better than nothing */
428 dissect_commonflags(tvb, offset, tree);
431 ti=proto_tree_add_item(tree, hf_ifcp_framelen, tvb, offset, 2, 0);
433 frame_len_tree=proto_item_add_subtree(ti, ett_ifcp_frame_len);
437 /* complement of flags and frame len */
438 proto_tree_add_item(frame_len_tree, hf_ifcp_encap_flags_c, tvb, offset, 1, 0);
439 proto_tree_add_item(frame_len_tree, hf_ifcp_framelen_c, tvb, offset, 2, 0);
442 /* timestamp seconds */
443 proto_tree_add_item(tree, hf_ifcp_tsec, tvb, offset, 4, 0);
446 /* timestamp fractions */
447 proto_tree_add_item(tree, hf_ifcp_tusec, tvb, offset, 4, 0);
451 proto_tree_add_item(tree, hf_ifcp_encap_crc, tvb, offset, 4, 0);
456 proto_tree_add_item(sof_tree, hf_ifcp_sof, tvb, offset, 1, 0);
458 proto_tree_add_item(sof_tree, hf_ifcp_sof, tvb, offset, 1, 0);
460 proto_tree_add_item(sof_tree, hf_ifcp_sof_c, tvb, offset, 1, 0);
462 proto_tree_add_item(sof_tree, hf_ifcp_sof_c, tvb, offset, 1, 0);
466 if(tvb_bytes_exist(tvb, frame_len-4, 4)) {
467 proto_tree_add_item(eof_tree, hf_ifcp_eof, tvb, frame_len-4, 1, 0);
468 proto_tree_add_item(eof_tree, hf_ifcp_eof, tvb, frame_len-3, 1, 0);
469 proto_tree_add_item(eof_tree, hf_ifcp_eof_c, tvb, frame_len-2, 1, 0);
470 proto_tree_add_item(eof_tree, hf_ifcp_eof_c, tvb, frame_len-1, 1, 0);
474 /* Call the FC Dissector if this is carrying an FC frame */
475 /* Set the SOF/EOF flags in the packet_info header */
482 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
485 pinfo->sof_eof = PINFO_SOF_SOFF;
489 if (eof != iFCP_EOFn) {
490 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
491 } else if (eof != iFCP_EOFt) {
492 pinfo->sof_eof |= PINFO_EOF_INVALID;
497 next_tvb=tvb_new_subset(tvb, offset, frame_len-offset-4, frame_len-offset-4);
500 call_dissector(fc_handle, next_tvb, pinfo, parent_tree);
501 } else if(data_handle){
502 call_dissector(data_handle, next_tvb, pinfo, parent_tree);
509 get_ifcp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
513 if(!ifcp_header_test(tvb, offset)){
517 pdu_len=(tvb_get_ntohs(tvb, offset+12)&0x03FF)*4;
522 dissect_ifcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
524 tcp_dissect_pdus(tvb, pinfo, parent_tree, ifcp_desegment, iFCP_MIN_HEADER_LEN, get_ifcp_pdu_len, dissect_ifcp_pdu);
528 /* This is called for those sessions where we have explicitely said
529 * this to be iFCP using "Decode As..."
530 * In this case we will not check the port number for sanity and just
531 * do as the user said.
534 dissect_ifcp_handle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
536 dissect_ifcp(tvb, pinfo, tree);
540 dissect_ifcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
542 if(!ifcp_header_test(tvb, 0)){
546 dissect_ifcp(tvb, pinfo, tree);
548 /* our heuristics are so strong that if the heuristics above passed
549 * and the dissection of the pdu did not cause any exceptions
550 * then we can set this as our conversation dissector
553 conversation_t* ifcp_conv;
555 ifcp_conv=find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
557 ifcp_conv=conversation_new(pinfo->fd->num, &pinfo->src,
558 &pinfo->dst, pinfo->ptype, pinfo->srcport,
561 /* XXX why does this not work? it doesnt result in dissect_ifcp_handle being called look into later*/
562 conversation_set_dissector(ifcp_conv, ifcp_handle);
569 proto_register_ifcp (void)
572 /* Setup list of header fields See Section 1.6.1 for details*/
573 static hf_register_info hf[] = {
575 { "Protocol", "fcencap.proto", FT_UINT8, BASE_DEC,
576 VALS(fcencap_proto_vals), 0, NULL, HFILL }},
577 { &hf_ifcp_protocol_c,
578 {"Protocol (1's Complement)", "fcencap.protoc", FT_UINT8, BASE_DEC, NULL,
581 {"Version", "fcencap.version", FT_UINT8, BASE_DEC, NULL, 0, NULL,
583 { &hf_ifcp_version_c,
584 {"Version (1's Complement)", "fcencap.versionc", FT_UINT8, BASE_DEC,
585 NULL, 0, NULL, HFILL}},
586 { &hf_ifcp_encap_flags_c,
587 {"iFCP Encapsulation Flags (1's Complement)", "ifcp.encap_flagsc", FT_UINT8, BASE_HEX,
588 NULL, 0xFC, NULL, HFILL}},
590 {"Frame Length (in Words)", "fcencap.framelen", FT_UINT16, BASE_DEC,
591 NULL, 0x03FF, NULL, HFILL}},
592 { &hf_ifcp_framelen_c,
593 {"Frame Length (1's Complement)", "fcencap.framelenc", FT_UINT16,
594 BASE_DEC, NULL, 0x03FF, NULL, HFILL}},
596 {"Time (secs)", "fcencap.tsec", FT_UINT32, BASE_DEC, NULL, 0, NULL,
599 {"Time (fraction)", "fcencap.tusec", FT_UINT32, BASE_DEC, NULL, 0,
601 { &hf_ifcp_encap_crc,
602 {"CRC", "fcencap.crc", FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL}},
604 {"SOF", "ifcp.sof", FT_UINT8, BASE_HEX, VALS (&ifcp_sof_vals), 0,
607 {"EOF", "ifcp.eof", FT_UINT8, BASE_HEX, VALS (&ifcp_eof_vals), 0,
610 {"SOF Compliment", "ifcp.sof_c", FT_UINT8, BASE_HEX, NULL , 0,
613 {"EOF Compliment", "ifcp.eof_c", FT_UINT8, BASE_HEX, NULL , 0,
615 { &hf_ifcp_ls_command_acc,
616 {"Ls Command Acc", "ifcp.ls_command_acc", FT_UINT8, BASE_HEX, NULL, 0,
618 { &hf_ifcp_common_flags,
619 {"Flags", "ifcp.common_flags", FT_UINT8, BASE_HEX , NULL, 0xfc, NULL, HFILL }},
620 { &hf_ifcp_common_flags_crcv,
621 {"CRCV", "ifcp.common_flags.crcv", FT_BOOLEAN, 8, TFS(&ifcp_common_flags_crcv_tfs), IFCP_COMMON_FLAGS_CRCV, "Is the CRC field valid?", HFILL }},
623 {"iFCP Flags", "ifcp.flags", FT_UINT8, BASE_HEX , NULL, 0, NULL, HFILL }},
624 { &hf_ifcp_flags_ses,
625 {"SES", "ifcp.flags.ses", FT_BOOLEAN, 8, TFS(&ifcp_flags_ses_tfs), IFCP_FLAGS_SES, "Is this a Session control frame", HFILL }},
626 { &hf_ifcp_flags_trp,
627 {"TRP", "ifcp.flags.trp", FT_BOOLEAN, 8, TFS(&ifcp_flags_trp_tfs), IFCP_FLAGS_TRP, "Is address transparent mode enabled", HFILL }},
628 { &hf_ifcp_flags_spc,
629 {"SPC", "ifcp.flags.spc", FT_BOOLEAN, 8, TFS(&ifcp_flags_spc_tfs), IFCP_FLAGS_SPC, "Is frame part of link service", HFILL }},
632 static gint *ett[] = {
640 &ett_ifcp_common_flags,
643 module_t *ifcp_module;
645 /* Register the protocol name and description */
646 proto_ifcp = proto_register_protocol("iFCP", "iFCP", "ifcp");
648 /* Required function calls to register the header fields and
650 proto_register_field_array(proto_ifcp, hf, array_length(hf));
651 proto_register_subtree_array(ett, array_length(ett));
653 ifcp_module = prefs_register_protocol(proto_ifcp, NULL);
654 prefs_register_bool_preference(ifcp_module,
656 "Reassemble iFCP messages spanning multiple TCP segments",
657 "Whether the iFCP dissector should reassemble messages spanning multiple TCP segments."
658 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
660 prefs_register_obsolete_preference(ifcp_module, "target_port");
665 * If this dissector uses sub-dissector registration add a
666 * registration routine.
670 * This format is required because a script is used to find these
671 * routines and create the code that calls these routines.
674 proto_reg_handoff_ifcp (void)
676 heur_dissector_add("tcp", dissect_ifcp_heur, proto_ifcp);
678 ifcp_handle = create_dissector_handle(dissect_ifcp_handle, proto_ifcp);
679 dissector_add_handle("tcp.port", ifcp_handle);
681 data_handle = find_dissector("data");
682 fc_handle = find_dissector("fc_ifcp");