some compilers dont like unnamed unions and structs
[obnox/wireshark/wip.git] / epan / dissectors / packet-ifcp.c
1 /* packet-ifcp.c
2  * Routines for iFCP dissection
3  * RFC 3821, RFC 3643
4  *
5  * Copyright 2005   Aboo Valappil     (valappil_aboo@emc.com)
6  *           2006 ronnie sahlberg   major refactoring
7  *
8  *
9  * Significantly based on packet-fcip.c by
10  *       Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
11  *
12  * $Id$
13  *
14  * Wireshark - Network traffic analyzer
15  * By Gerald Combs <gerald@wireshark.org>
16  * Copyright 1998 Gerald Combs
17  *
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.
22  *
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.
27  *
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.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include <glib.h>
42
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/emem.h>
46 #include <epan/conversation.h>
47 #include "packet-tcp.h"
48
49 #define iFCP_ENCAP_HEADER_LEN                    28
50 #define iFCP_MIN_HEADER_LEN                      16 /* upto frame len field */ 
51
52 typedef enum {
53     iFCP_EOFn    = 0x41,
54     iFCP_EOFt    = 0x42,
55     iFCP_EOFrt   = 0x44,
56     iFCP_EOFdt   = 0x46,
57     iFCP_EOFni   = 0x49,
58     iFCP_EOFdti  = 0x4E,
59     iFCP_EOFrti  = 0x4F,
60     iFCP_EOFa    = 0x50
61 } ifcp_eof_t;
62
63 typedef enum {
64     iFCP_SOFf    = 0x28,
65     iFCP_SOFi4   = 0x29,
66     iFCP_SOFi2   = 0x2D,
67     iFCP_SOFi3   = 0x2E,
68     iFCP_SOFn4   = 0x31,
69     iFCP_SOFn2   = 0x35,
70     iFCP_SOFn3   = 0x36,
71     iFCP_SOFc4   = 0x39
72 } ifcp_sof_t;
73
74 typedef enum {
75     FCENCAP_PROTO_FCIP = 1,
76     FCENCAP_PROTO_iFCP = 2
77 } fcencap_proto_t;
78
79 static const value_string ifcp_eof_vals[] = {
80     {iFCP_EOFn, "EOFn" },
81     {iFCP_EOFt, "EOFt" },
82     {iFCP_EOFrt, "EOFrt" },
83     {iFCP_EOFdt, "EOFdt" },
84     {iFCP_EOFni, "EOFni" },
85     {iFCP_EOFdti, "EOFdti" },
86     {iFCP_EOFrti, "EOFrti" },
87     {iFCP_EOFa, "EOFa" },
88     {0, NULL},
89 };
90
91 static const value_string ifcp_sof_vals[] = {
92     {iFCP_SOFf, "SOFf" },
93     {iFCP_SOFi4, "SOFi4" },
94     {iFCP_SOFi2, "SOFi2" },
95     {iFCP_SOFi3, "SOFi3" },
96     {iFCP_SOFn4, "SOFn4" },
97     {iFCP_SOFn2, "SOFn2" },
98     {iFCP_SOFn3, "SOFn3" },
99     {iFCP_SOFc4, "SOFc4" },
100     {0, NULL},
101 };
102
103 static const value_string fcencap_proto_vals[] = {
104     {FCENCAP_PROTO_iFCP, "iFCP"},
105     {FCENCAP_PROTO_iFCP, "iFCP"},
106     {0, NULL},
107 };
108
109 static const guint8 ifcp_header_8_bytes[8] = {
110     0x02, 0x01, 0xFD, 0xFE,
111     0x00, 0x00, 0x00, 0x00
112 };
113
114 static int proto_ifcp          = -1;
115
116 static int hf_ifcp_protocol    = -1;
117 static int hf_ifcp_protocol_c  = -1;
118 static int hf_ifcp_version     = -1;
119 static int hf_ifcp_version_c   = -1;
120 static int hf_ifcp_encap_flags_c=-1;
121 static int hf_ifcp_framelen    = -1;
122 static int hf_ifcp_framelen_c  = -1;
123 static int hf_ifcp_tsec        = -1;
124 static int hf_ifcp_tusec       = -1;
125 static int hf_ifcp_encap_crc   = -1;
126 static int hf_ifcp_sof         = -1;
127 static int hf_ifcp_sof_c       = -1;
128 static int hf_ifcp_eof         = -1;
129 static int hf_ifcp_eof_c       = -1;
130 static int hf_ifcp_ls_command_acc = -1;
131 static int hf_ifcp_flags     = -1;
132 static int hf_ifcp_flags_ses = -1;
133 static int hf_ifcp_flags_trp = -1;
134 static int hf_ifcp_flags_spc = -1;
135 static int hf_ifcp_common_flags    = -1;
136 static int hf_ifcp_common_flags_crcv = -1;
137
138 static int ett_ifcp              = -1;
139 static int ett_ifcp_sof          = -1;
140 static int ett_ifcp_eof          = -1;
141 static int ett_ifcp_flags        = -1;
142 static int ett_ifcp_common_flags = -1;
143 static int ett_ifcp_protocol     = -1;
144 static int ett_ifcp_version      = -1;
145 static int ett_ifcp_frame_len    = -1;
146
147 static gboolean ifcp_desegment    = TRUE;
148
149 static dissector_handle_t ifcp_handle=NULL;
150 static dissector_handle_t data_handle=NULL;
151 static dissector_handle_t fc_handle=NULL;
152
153
154 /* This function checks the first 16 bytes of the "header" that it looks sane
155  * and returns TRUE if this looks like iFCP and FALSE if it doesnt.
156  */
157 static gboolean
158 ifcp_header_test(tvbuff_t *tvb, int offset)
159 {
160         guint16 flen, flen1;
161
162         /* we can only do this test if we have 16 bytes or more */
163         if(tvb_length_remaining(tvb, offset)<iFCP_MIN_HEADER_LEN){
164                 return FALSE;
165         }
166
167         /*
168         * As per the iFCP standard, the following tests must PASS:
169         * 1)  Frame Length field validation -- 15 < Frame Length < 545;
170         * 2)  Comparison of Frame Length field to its ones complement; and
171         * 3)  A valid EOF is found in the word preceding the start of the next
172         *     iFCP header as indicated by the Frame Length field, to be tested
173         *     as follows:
174         *     1)  Bits 24-31 and 16-23 contain identical legal EOF values (the
175         *         list of legal EOF values is in the FC Frame Encapsulation
176         *         [21]); and
177         *     2)  Bits 8-15 and 0-7 contain the ones complement of the EOF
178         *         value found in bits 24-31.
179         *
180         * As per the iFCP standard, in addition, at least 3 of the following
181         * set of tests must be performed to identify that we've located the
182         * start of an iFCP frame. 
183         * a)  Protocol# ones complement field (1 test);
184         * b)  Version ones complement field (1 test);
185         * c)  Replication of encapsulation word 0 in word 1 (1 test);
186         * d)  Reserved field and its ones complement (2 tests);
187         * e)  Flags field and its ones complement (2 tests);
188         *    f)  CRC field is equal to zero (1 test); (DONT DO THIS TEST!)
189         * g)  SOF fields and ones complement fields (4 tests);
190         * h)  Format and values of FC header (1 test);
191         * i)  CRC of FC Frame (2 tests);
192         * j)  FC Frame Encapsulation header information in the next iFCP Frame
193         *     (1 test).
194         *
195         * At least 3 of the 16 tests listed above SHALL be performed. Failure
196         * of any of the above tests actually performed SHALL indicate an
197         * encapsulation error and the FC Frame SHALL NOT be forwarded on to
198         * the FC Entity.
199         */
200
201
202         /*
203          * Tests a, b and c
204          */
205         if(tvb_memeql(tvb, offset, ifcp_header_8_bytes, 8) != 0){
206                 return FALSE;
207         }
208
209         /* check the frame length */
210         flen=tvb_get_ntohs(tvb, offset+12)&0x03FF;
211         if((flen < 15) || (flen > 545)){
212                 return FALSE;
213         }
214
215         /* check the complement of the frame length */
216         flen1=tvb_get_ntohs(tvb, offset+14)&0x03FF;
217         if(flen!=((~flen1)&0x03FF)){
218                 return FALSE;
219         }
220
221
222         /* this should be good enough for our heuristics */
223         return TRUE;
224 }
225
226
227 #define IFCP_FLAGS_SES          0x04
228 #define IFCP_FLAGS_TRP          0x02
229 #define IFCP_FLAGS_SPC          0x01
230
231 static const true_false_string ifcp_flags_ses_tfs = {
232         "This is a SESSION CONTROL FRAME",
233         "This is a normal frame"
234 };
235
236 static const true_false_string ifcp_flags_trp_tfs = {
237         "Address TRANSPARENT Mode Enabled",
238         "Address TRANSLATION Mode Enabled"
239 };
240
241 static const true_false_string ifcp_flags_spc_tfs = {
242         "This frame requires SPECIAL PROCESSING",
243         "This is a normal frame"
244 };
245
246 static int
247 dissect_ifcpflags(tvbuff_t *tvb, int offset, proto_tree *parent_tree)
248 {
249         proto_item *item=NULL;
250         proto_tree *tree=NULL;
251         guint8 flags;
252
253         if(parent_tree){
254                 item=proto_tree_add_item(parent_tree, hf_ifcp_flags, tvb, offset, 1, 0);
255                 tree=proto_item_add_subtree (item, ett_ifcp_flags);
256         }
257
258         flags=tvb_get_guint8(tvb, offset);
259
260         /* SES */
261         proto_tree_add_boolean(tree, hf_ifcp_flags_ses, tvb, offset, 1, flags);
262         if(flags&IFCP_FLAGS_SES){
263                 proto_item_append_text(item, "  SES");
264         }
265         flags&=(~IFCP_FLAGS_SES);
266
267         /* TRP */
268         proto_tree_add_boolean(tree, hf_ifcp_flags_trp, tvb, offset, 1, flags);
269         if(flags&IFCP_FLAGS_TRP){
270                 proto_item_append_text(item, "  TRP");
271         }
272         flags&=(~IFCP_FLAGS_TRP);
273
274         /* SPC */
275         proto_tree_add_boolean(tree, hf_ifcp_flags_spc, tvb, offset, 1, flags);
276         if(flags&IFCP_FLAGS_SPC){
277                 proto_item_append_text(item, "  SPC");
278         }
279         flags&=(~IFCP_FLAGS_SPC);
280
281
282         offset++;
283         return offset;
284 }
285
286
287 #define IFCP_COMMON_FLAGS_CRCV          0x04
288
289 static const true_false_string ifcp_common_flags_crcv_tfs = {
290         "CRC is VALID",
291         "Crc is NOT valid"
292 };
293
294 static void
295 dissect_commonflags(tvbuff_t *tvb, int offset, proto_tree *parent_tree)
296 {
297         proto_item *item=NULL;
298         proto_tree *tree=NULL;
299         guint8 flags;
300
301         if(parent_tree){
302                 item=proto_tree_add_item(parent_tree, hf_ifcp_common_flags, tvb, offset, 1, 0);
303                 tree=proto_item_add_subtree (item, ett_ifcp_common_flags);
304         }
305
306         flags=tvb_get_guint8(tvb, offset);
307
308         /* CRCV */
309         proto_tree_add_boolean(tree, hf_ifcp_common_flags_crcv, tvb, offset, 1, flags);
310         if(flags&IFCP_COMMON_FLAGS_CRCV){
311                 proto_item_append_text(item, "  CRCV");
312         }
313         flags&=(~IFCP_COMMON_FLAGS_CRCV);
314 }
315
316 static void
317 dissect_ifcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
318 {
319         gint offset = 0, frame_len = 0;
320         guint8 sof = 0, eof = 0;
321         proto_item *ti;
322         proto_tree *tree = NULL;
323         tvbuff_t *next_tvb;
324         guint8 protocol;
325         proto_tree *protocol_tree=NULL;    
326         proto_tree *version_tree=NULL;    
327         proto_tree *frame_len_tree=NULL;    
328         proto_tree *sof_tree=NULL;    
329         proto_tree *eof_tree=NULL;    
330
331         /* verify we have a full header  (do we need to do this? */
332         if(tvb_length(tvb)<iFCP_ENCAP_HEADER_LEN){
333                 return;
334         }
335
336         if(check_col(pinfo->cinfo, COL_PROTOCOL)){
337                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "iFCP");
338         }
339
340         frame_len = (tvb_get_ntohs (tvb, offset+12) & 0x03FF)*4;
341
342
343         if (parent_tree) {
344             if (tvb_bytes_exist (tvb, offset, frame_len-4)) {
345                 sof = tvb_get_guint8 (tvb, offset+iFCP_ENCAP_HEADER_LEN);
346                 eof = tvb_get_guint8 (tvb, offset+frame_len - 4);
347
348                 ti = proto_tree_add_protocol_format (parent_tree, proto_ifcp, tvb, offset,
349                                                      iFCP_ENCAP_HEADER_LEN,
350                                                      "iFCP (%s/%s)",
351                                                      val_to_str (sof, ifcp_sof_vals,
352                                                                  "0x%x"),
353                                                      val_to_str (eof, ifcp_eof_vals,
354                                                                  "0x%x"));
355             } else {
356                 sof = tvb_get_guint8 (tvb, offset+iFCP_ENCAP_HEADER_LEN);
357                 
358                 ti = proto_tree_add_protocol_format (parent_tree, proto_ifcp, tvb, offset,
359                                                      iFCP_ENCAP_HEADER_LEN,
360                                                      "iFCP (%s/%s)",
361                                                      val_to_str (sof, ifcp_sof_vals,
362                                                                  "0x%x"),
363                                                      "NA");
364             }
365             tree = proto_item_add_subtree (ti, ett_ifcp);
366         }
367
368
369
370         /* The Common FC Encap header */
371         /* protocol */
372         protocol = tvb_get_guint8 (tvb, offset);
373         ti=proto_tree_add_item(tree, hf_ifcp_protocol, tvb, offset, 1, 0);
374         if(ti){
375                 protocol_tree=proto_item_add_subtree(ti, ett_ifcp_protocol);
376         }
377         offset++;
378
379         /* version */
380         ti=proto_tree_add_item(tree, hf_ifcp_version, tvb, offset, 1, 0);
381         if(ti){
382                 version_tree=proto_item_add_subtree(ti, ett_ifcp_version);
383         }
384         offset++;
385
386         /* protocol complement */
387         proto_tree_add_item(protocol_tree, hf_ifcp_protocol_c, tvb, offset, 1, 0);
388         offset++;
389
390         /* version complement */
391         proto_tree_add_item(version_tree, hf_ifcp_version_c, tvb, offset, 1, 0);
392         offset++;
393
394         /* 4 reserved bytes */
395         offset+=4;
396
397         /* iFCP specific fields */
398         if(protocol==FCENCAP_PROTO_iFCP){
399                 /* LS_COMMAND_ACC */
400                 proto_tree_add_item(tree, hf_ifcp_ls_command_acc, tvb, offset, 1, 0);
401                 offset++;
402
403                 /* iFCP Flags */
404                 offset=dissect_ifcpflags(tvb, offset, tree);
405
406                 /* SOF */
407                 ti=proto_tree_add_item(tree, hf_ifcp_sof, tvb, offset, 1, 0);
408                 if(ti){
409                         sof_tree=proto_item_add_subtree(ti, ett_ifcp_sof);
410                 }
411                 offset++;
412
413                 /* EOF */
414                 ti=proto_tree_add_item(tree, hf_ifcp_eof, tvb, offset, 1, 0);
415                 if(ti){
416                         eof_tree=proto_item_add_subtree(ti, ett_ifcp_eof);
417                 }
418                 offset++;
419         } else {
420                 offset+=4;
421                 sof_tree=tree; /* better than nothing */
422                 eof_tree=tree;
423         }
424
425         /* Common Flags */
426         dissect_commonflags(tvb, offset, tree);
427
428         /* frame len */
429         ti=proto_tree_add_item(tree, hf_ifcp_framelen, tvb, offset, 2, 0);
430         if(ti){
431                 frame_len_tree=proto_item_add_subtree(ti, ett_ifcp_frame_len);
432         }
433         offset+=2;
434
435         /* complement of flags and frame len */
436         proto_tree_add_item(frame_len_tree, hf_ifcp_encap_flags_c, tvb, offset, 1, 0);
437         proto_tree_add_item(frame_len_tree, hf_ifcp_framelen_c, tvb, offset, 2, 0);
438         offset+=2;
439
440         /* timestamp seconds */
441         proto_tree_add_item(tree, hf_ifcp_tsec, tvb, offset, 4, 0);
442         offset+=4;
443
444         /* timestamp fractions */
445         proto_tree_add_item(tree, hf_ifcp_tusec, tvb, offset, 4, 0);
446         offset+=4;
447
448         /* crc */
449         proto_tree_add_item(tree, hf_ifcp_encap_crc, tvb, offset, 4, 0);
450         offset+=4;
451
452
453         /* FC SOF/-SOF */
454         proto_tree_add_item(sof_tree, hf_ifcp_sof, tvb, offset, 1, 0);
455         offset++;
456         proto_tree_add_item(sof_tree, hf_ifcp_sof, tvb, offset, 1, 0);
457         offset++;
458         proto_tree_add_item(sof_tree, hf_ifcp_sof_c, tvb, offset, 1, 0);
459         offset++;
460         proto_tree_add_item(sof_tree, hf_ifcp_sof_c, tvb, offset, 1, 0);
461         offset++;
462
463         /* FC EOF/-EOF */
464         if(tvb_bytes_exist(tvb, frame_len-4, 4)) {
465                 proto_tree_add_item(eof_tree, hf_ifcp_eof, tvb, frame_len-4, 1, 0);
466                 proto_tree_add_item(eof_tree, hf_ifcp_eof, tvb, frame_len-3, 1, 0);
467                 proto_tree_add_item(eof_tree, hf_ifcp_eof_c, tvb, frame_len-2, 1, 0);
468                 proto_tree_add_item(eof_tree, hf_ifcp_eof_c, tvb, frame_len-1, 1, 0);
469         }
470
471
472         /* Call the FC Dissector if this is carrying an FC frame */
473         /* Set the SOF/EOF flags in the packet_info header */
474         pinfo->sof_eof = 0;
475
476         switch(sof){
477         case iFCP_SOFi3:
478         case iFCP_SOFi2:
479         case iFCP_SOFi4:
480                 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
481                 break;
482         case iFCP_SOFf:
483                 pinfo->sof_eof = PINFO_SOF_SOFF;
484                 break;
485         default:
486                 if(sof){
487                         if (eof != iFCP_EOFn) {
488                                 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
489                         } else if (eof != iFCP_EOFt) {
490                                 pinfo->sof_eof |= PINFO_EOF_INVALID;
491                         }
492                 }
493         }
494             
495         next_tvb=tvb_new_subset(tvb, offset, frame_len-offset-4, frame_len-offset-4);
496
497         if(fc_handle){
498                 call_dissector(fc_handle, next_tvb, pinfo, parent_tree);
499         } else if(data_handle){
500                 call_dissector(data_handle, next_tvb, pinfo, parent_tree);
501         }
502
503         return;
504 }
505
506 static guint
507 get_ifcp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
508 {
509         guint pdu_len;
510  
511         if(!ifcp_header_test(tvb, offset)){
512                 return 0;
513         }
514
515         pdu_len=tvb_get_ntohs(tvb, offset+12)*4;
516         return pdu_len;
517 }
518
519 static void
520 dissect_ifcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
521 {
522         tcp_dissect_pdus(tvb, pinfo, parent_tree, ifcp_desegment, iFCP_MIN_HEADER_LEN, get_ifcp_pdu_len, dissect_ifcp_pdu);
523 }
524
525
526 /* This is called for those sessions where we have explicitely said
527  * this to be iFCP using "Decode As..."
528  * In this case we will not check the port number for sanity and just
529  * do as the user said.
530  */
531 static void
532 dissect_ifcp_handle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
533 {
534         dissect_ifcp(tvb, pinfo, tree);
535 }
536
537 static gboolean
538 dissect_ifcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
539 {
540         if(!ifcp_header_test(tvb, 0)){
541                 return FALSE;
542         }
543
544         dissect_ifcp(tvb, pinfo, tree);
545
546         /* our heuristics are so strong that if the heuristics above passed
547          * and the dissection of the pdu did not cause any exceptions
548          * then we can set this as our conversation dissector
549          */
550         if(ifcp_handle){
551                 conversation_t* ifcp_conv;
552
553                 ifcp_conv=find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
554                 if(!ifcp_conv){
555                         ifcp_conv=conversation_new(pinfo->fd->num, &pinfo->src,
556                                 &pinfo->dst, pinfo->ptype, pinfo->srcport,
557                                 pinfo->destport, 0);
558                 }
559                 /* XXX why does this not work? it doesnt result in dissect_ifcp_handle being called    look into later*/
560                 conversation_set_dissector(ifcp_conv, ifcp_handle);
561         }
562
563         return TRUE;
564 }
565
566 void
567 proto_register_ifcp (void)
568 {
569
570     /* Setup list of header fields  See Section 1.6.1 for details*/
571     static hf_register_info hf[] = {
572         { &hf_ifcp_protocol,
573           { "Protocol", "fcencap.proto", FT_UINT8, BASE_DEC,
574              VALS(fcencap_proto_vals), 0, "Protocol", HFILL }},
575         { &hf_ifcp_protocol_c,
576           {"Protocol (1's Complement)", "fcencap.protoc", FT_UINT8, BASE_DEC, NULL,
577            0, "Protocol (1's Complement)", HFILL}},
578         { &hf_ifcp_version,
579           {"Version", "fcencap.version", FT_UINT8, BASE_DEC, NULL, 0, "",
580            HFILL}},
581         { &hf_ifcp_version_c,
582           {"Version (1's Complement)", "fcencap.versionc", FT_UINT8, BASE_DEC,
583            NULL, 0, "", HFILL}},
584         { &hf_ifcp_encap_flags_c,
585           {"iFCP Encapsulation Flags (1's Complement)", "ifcp.encap_flagsc", FT_UINT8, BASE_HEX,
586            NULL, 0xFC, "", HFILL}},
587         { &hf_ifcp_framelen,
588           {"Frame Length (in Words)", "fcencap.framelen", FT_UINT16, BASE_DEC,
589            NULL, 0x03FF, "", HFILL}},
590         { &hf_ifcp_framelen_c,
591           {"Frame Length (1's Complement)", "fcencap.framelenc", FT_UINT16,
592            BASE_DEC, NULL, 0x03FF, "", HFILL}},
593         { &hf_ifcp_tsec,
594           {"Time (secs)", "fcencap.tsec", FT_UINT32, BASE_DEC, NULL, 0, "",
595            HFILL}},
596         { &hf_ifcp_tusec,
597           {"Time (fraction)", "fcencap.tusec", FT_UINT32, BASE_DEC, NULL, 0,
598            "", HFILL}},
599         { &hf_ifcp_encap_crc,
600           {"CRC", "fcencap.crc", FT_UINT32, BASE_HEX, NULL, 0, "", HFILL}},
601         { &hf_ifcp_sof,
602           {"SOF", "ifcp.sof", FT_UINT8, BASE_HEX, VALS (&ifcp_sof_vals), 0,
603            "", HFILL}},
604         { &hf_ifcp_eof,
605           {"EOF", "ifcp.eof", FT_UINT8, BASE_HEX, VALS (&ifcp_eof_vals), 0,
606            "", HFILL}},
607         { &hf_ifcp_sof_c,
608           {"SOF Compliment", "ifcp.sof_c", FT_UINT8, BASE_HEX, NULL , 0,
609            "", HFILL}},
610         { &hf_ifcp_eof_c,
611           {"EOF Compliment", "ifcp.eof_c", FT_UINT8, BASE_HEX, NULL , 0,
612            "", HFILL}},
613         { &hf_ifcp_ls_command_acc,
614           {"Ls Command Acc", "ifcp.ls_command_acc", FT_UINT8, BASE_HEX, NULL, 0,
615            "", HFILL}},
616         { &hf_ifcp_common_flags, 
617           {"Flags", "ifcp.common_flags", FT_UINT8, BASE_HEX , NULL, 0xfc, "", HFILL }},
618         { &hf_ifcp_common_flags_crcv, 
619           {"CRCV", "ifcp.common_flags.crcv", FT_BOOLEAN, 8, TFS(&ifcp_common_flags_crcv_tfs), IFCP_COMMON_FLAGS_CRCV, "Is the CRC field valid?", HFILL }},
620         { &hf_ifcp_flags, 
621           {"iFCP Flags", "ifcp.flags", FT_UINT8, BASE_HEX , NULL, 0, "", HFILL }},
622         { &hf_ifcp_flags_ses, 
623           {"SES", "ifcp.flags.ses", FT_BOOLEAN, 8, TFS(&ifcp_flags_ses_tfs), IFCP_FLAGS_SES, "Is this a Session control frame", HFILL }},
624         { &hf_ifcp_flags_trp, 
625           {"TRP", "ifcp.flags.trp", FT_BOOLEAN, 8, TFS(&ifcp_flags_trp_tfs), IFCP_FLAGS_TRP, "Is address transparent mode enabled", HFILL }},
626         { &hf_ifcp_flags_spc, 
627           {"SPC", "ifcp.flags.spc", FT_BOOLEAN, 8, TFS(&ifcp_flags_spc_tfs), IFCP_FLAGS_SPC, "Is frame part of link service", HFILL }},
628     };
629
630     static gint *ett[] = {
631         &ett_ifcp,
632         &ett_ifcp_sof,
633         &ett_ifcp_eof,
634         &ett_ifcp_protocol,
635         &ett_ifcp_version,
636         &ett_ifcp_frame_len,
637         &ett_ifcp_flags,
638         &ett_ifcp_common_flags,
639     };
640     
641     module_t *ifcp_module;
642
643     /* Register the protocol name and description */
644     proto_ifcp = proto_register_protocol("iFCP", "iFCP", "ifcp");
645
646     /* Required function calls to register the header fields and
647      * subtrees used */
648     proto_register_field_array(proto_ifcp, hf, array_length(hf));
649     proto_register_subtree_array(ett, array_length(ett));
650
651     ifcp_module = prefs_register_protocol(proto_ifcp, NULL);
652     prefs_register_bool_preference(ifcp_module,
653                                    "desegment",
654                                    "Reassemble iFCP messages spanning multiple TCP segments",
655                                    "Whether the iFCP dissector should reassemble messages spanning multiple TCP segments."
656                                    " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
657                                    &ifcp_desegment);
658     prefs_register_obsolete_preference(ifcp_module, "target_port");
659 }
660
661
662 /*
663  * If this dissector uses sub-dissector registration add a
664  * registration routine.
665  */
666
667 /*
668  * This format is required because a script is used to find these
669  * routines and create the code that calls these routines.
670  */
671 void
672 proto_reg_handoff_ifcp (void)
673 {
674     heur_dissector_add("tcp", dissect_ifcp_heur, proto_ifcp);
675
676     ifcp_handle = create_dissector_handle(dissect_ifcp_handle, proto_ifcp);
677     dissector_add_handle("tcp.port", ifcp_handle);
678
679     data_handle = find_dissector("data");
680     fc_handle = find_dissector("fc_ifcp");
681 }