Fix document creation under Windows, add ethereal-filter.html to the NSIS
[obnox/wireshark/wip.git] / packet-fcip.c
1 /* packet-fcip.c
2  * Routines for FCIP dissection
3  * Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
4  *
5  * $Id: packet-fcip.c,v 1.7 2003/09/09 05:02:35 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <glib.h>
35
36 #include <epan/packet.h>
37 #include "prefs.h"
38
39 /*
40  * See:
41  *
42  *      draft-ietf-ips-fcovertcpip-12
43  *
44  *      draft-ietf-ips-fcencapsulation-08
45  */
46
47 #define FCIP_ENCAP_HEADER_LEN                    28
48 #define FCIP_MIN_HEADER_LEN                      16 /* upto frame len field */ 
49 #define FCIP_ENCAP_PROTO_VER                     0xFEFE0101
50 #define FCIP_IS_SF(pflags)                       ((pflags & 0x1) == 0x1)
51 #define FCIP_IS_CH(pflags)                       ((pflags & 0x80) == 0x80)
52
53 typedef enum {
54     FCIP_EOFn    = 0x41,
55     FCIP_EOFt    = 0x42,
56     FCIP_EOFrt   = 0x44,
57     FCIP_EOFdt   = 0x46,
58     FCIP_EOFni   = 0x49,
59     FCIP_EOFdti  = 0x4E,
60     FCIP_EOFrti  = 0x4F,
61     FCIP_EOFa    = 0x50,
62 } fcip_eof_t;
63
64 typedef enum {
65     FCIP_SOFf    = 0x28,
66     FCIP_SOFi4   = 0x29,
67     FCIP_SOFi2   = 0x2D,
68     FCIP_SOFi3   = 0x2E,
69     FCIP_SOFn4   = 0x31,
70     FCIP_SOFn2   = 0x35,
71     FCIP_SOFn3   = 0x36,
72     FCIP_SOFc4   = 0x39,
73 } fcip_sof_t;
74
75 typedef enum {
76     FCENCAP_PROTO_FCIP = 1,
77     FCENCAP_PROTO_iFCP = 2,
78 } fcencap_proto_t;
79
80 static const value_string fcip_eof_vals[] = {
81     {FCIP_EOFn, "EOFn" },
82     {FCIP_EOFt, "EOFt" },
83     {FCIP_EOFrt, "EOFrt" },
84     {FCIP_EOFdt, "EOFdt" },
85     {FCIP_EOFni, "EOFni" },
86     {FCIP_EOFdti, "EOFdti" },
87     {FCIP_EOFrti, "EOFrti" },
88     {FCIP_EOFa, "EOFa" },
89     {0, NULL},
90 };
91
92 static const value_string fcip_sof_vals[] = {
93     {FCIP_SOFf, "SOFf" },
94     {FCIP_SOFi4, "SOFi4" },
95     {FCIP_SOFi2, "SOFi2" },
96     {FCIP_SOFi3, "SOFi3" },
97     {FCIP_SOFn4, "SOFn4" },
98     {FCIP_SOFn2, "SOFn2" },
99     {FCIP_SOFn3, "SOFn3" },
100     {FCIP_SOFc4, "SOFc4" },
101     {0, NULL},
102 };
103
104 static const value_string fcencap_proto_vals[] = {
105     {FCENCAP_PROTO_FCIP, "FCIP"},
106     {FCENCAP_PROTO_iFCP, "iFCP"},
107 };
108
109 static guint fcip_header_2_bytes[2] = {FCIP_ENCAP_PROTO_VER,
110                                        FCIP_ENCAP_PROTO_VER};
111
112 static int proto_fcip          = -1;
113
114 static int hf_fcip_protocol    = -1;
115 static int hf_fcip_protocol_c  = -1;
116 static int hf_fcip_version     = -1;
117 static int hf_fcip_version_c   = -1;
118 static int hf_fcip_encap_word1 = -1;
119 static int hf_fcip_flags       = -1;
120 static int hf_fcip_flags_c     = -1;
121 static int hf_fcip_framelen    = -1;
122 static int hf_fcip_framelen_c  = -1;
123 static int hf_fcip_tsec        = -1;
124 static int hf_fcip_tusec       = -1;
125 static int hf_fcip_encap_crc   = -1;
126 static int hf_fcip_sof         = -1;
127 static int hf_fcip_sof_c       = -1;
128 static int hf_fcip_eof         = -1;
129 static int hf_fcip_eof_c       = -1;
130 static int hf_fcip_pflags_changed = -1;
131 static int hf_fcip_pflags_special = -1;
132 static int hf_fcip_pflags_c = -1;
133 static int hf_fcip_src_wwn = -1;
134 static int hf_fcip_dst_wwn = -1;
135 static int hf_fcip_conn_code = -1;
136 static int hf_fcip_katov = -1;
137 static int hf_fcip_src_entity_id = -1;
138 static int hf_fcip_conn_nonce = -1;
139 static int hf_fcip_conn_flags = -1;
140
141 static int ett_fcip            = -1;
142
143 static guint fcip_port         = 3225;
144 static gboolean fcip_desegment    = TRUE;
145
146 static dissector_handle_t data_handle;
147 static dissector_handle_t fc_handle;
148
149 /* This routine attempts to locate the position of the next header in the
150  * provided segment
151  */
152 static guint
153 get_next_fcip_header_offset (tvbuff_t *tvb, packet_info *pinfo, gint offset)
154 {
155     gint bytes_remaining = tvb_length_remaining (tvb, offset);
156     gint frame_len;
157     guint16 flen, flen1;
158     fcip_eof_t eof, eofc;
159
160     /*
161      * As per the FCIP standard, the following tests must PASS:
162      * 1)  Frame Length field validation -- 15 < Frame Length < 545;
163      * 2)  Comparison of Frame Length field to its ones complement; and
164      * 3)  A valid EOF is found in the word preceding the start of the next
165      *     FCIP header as indicated by the Frame Length field, to be tested
166      *     as follows:
167      *     1)  Bits 24-31 and 16-23 contain identical legal EOF values (the
168      *         list of legal EOF values is in the FC Frame Encapsulation
169      *         [21]); and
170      *     2)  Bits 8-15 and 0-7 contain the ones complement of the EOF
171      *         value found in bits 24-31.
172      *
173      * As per the FCIP standard, in addition, at least 3 of the following set
174      * of tests must be performed to identify that we've located the start of
175      * an FCIP frame. 
176      * a)  Protocol# ones complement field (1 test);
177      * b)  Version ones complement field (1 test);
178      * c)  Replication of encapsulation word 0 in word 1 (1 test);
179      * d)  Reserved field and its ones complement (2 tests);
180      * e)  Flags field and its ones complement (2 tests);
181      * f)  CRC field is equal to zero (1 test);
182      * g)  SOF fields and ones complement fields (4 tests);
183      * h)  Format and values of FC header (1 test);
184      * i)  CRC of FC Frame (2 tests);
185      * j)  FC Frame Encapsulation header information in the next FCIP Frame
186      *     (1 test).
187      *
188      * At least 3 of the 16 tests listed above SHALL be performed. Failure
189      * of any of the above tests actually performed SHALL indicate an
190      * encapsulation error and the FC Frame SHALL NOT be forwarded on to
191      * the FC Entity.
192      */
193
194 NXT_BYTE: while (bytes_remaining) {
195         if (bytes_remaining < FCIP_ENCAP_HEADER_LEN) {
196             if(fcip_desegment && pinfo->can_desegment) {
197                 /*
198                  * This frame doesn't have all of the data for
199                  * this message, but we can do reassembly on it.
200                  *
201                  * Tell the TCP dissector where the data for this
202                  * message starts in the data it handed us, and
203                  * how many more bytes we need, and return.
204                  */
205                 pinfo->desegment_offset = offset;
206                 pinfo->desegment_len = FCIP_ENCAP_HEADER_LEN;
207                 return -2;
208             }
209         }
210
211         /* I check that we have a valid header before checking for the frame
212          * length and the other initial tests.
213          */
214
215         /*
216          * Tests a, b and c
217          */
218         if (memcmp ((void *)tvb_get_ptr (tvb, offset, 8),
219                     (void *)fcip_header_2_bytes, 8) != 0) {
220             offset++;
221             bytes_remaining--;
222             goto NXT_BYTE;
223         }
224
225         flen = (tvb_get_ntohs (tvb, offset+12)) & 0x03FF;
226         frame_len = (tvb_get_ntohs (tvb, offset+12) & 0x03FF)*4;
227         
228         if ((flen < 15) || (flen > 545)) {
229             /* Frame length check failed. Skip byte and try again */
230             offset++;
231             bytes_remaining--;
232             goto NXT_BYTE;
233         }
234
235         flen1 = (tvb_get_ntohs (tvb, offset+14)) & 0x03FF;
236         
237         if ((flen & 0x03FF) != ((~flen1)&0x03FF)) {
238             /* frame_len and its one's complement are not the same */
239             offset++;
240             bytes_remaining--;
241             goto NXT_BYTE;
242         }
243
244         /* Valid EOF check */
245         if (tvb_bytes_exist (tvb, offset+(frame_len-1)*4, 4)) {
246             eof = (fcip_eof_t)tvb_get_guint8 (tvb, offset+(frame_len-1)*4);
247             eofc = (fcip_eof_t)tvb_get_guint8 (tvb, offset+(frame_len-1)*4+2);
248
249             if ((eof != FCIP_EOFn) && (eof != FCIP_EOFt) && (eof != FCIP_EOFrt)
250                 && (eof != FCIP_EOFdt) && (eof != FCIP_EOFni) &&
251                 (eof != FCIP_EOFdti) && (eof != FCIP_EOFrti) &&
252                 (eof != FCIP_EOFa)) {
253                 offset++;
254                 bytes_remaining--;
255                 goto NXT_BYTE;
256             }
257             
258             if ((eof != ~eofc) ||
259                 (eof != tvb_get_guint8 (tvb, offset+(frame_len-1)*4+1)) ||
260                 (eofc != tvb_get_guint8 (tvb, offset+(frame_len-1)*4+3))) {
261                 offset++;
262                 bytes_remaining--;
263                 goto NXT_BYTE;
264             }
265         }
266         
267         /* Test d */
268         if ((tvb_get_guint8 (tvb, offset+9) != 0) ||
269             (tvb_get_guint8 (tvb, offset+11) != 0xFF)) {
270             /* Failed */
271             offset++;
272             bytes_remaining--;
273             goto NXT_BYTE;
274         }
275         
276         /* Test e */
277         
278         /* Test f */
279         if (tvb_get_ntohl (tvb, offset+24)) {
280             /* Failed */
281             offset++;
282             bytes_remaining--;
283             goto NXT_BYTE;
284         }
285         
286         if (bytes_remaining >= (frame_len)) {
287             if (tvb_bytes_exist (tvb, offset+frame_len, 8)) {
288                 /* The start of the next header matches what we wish to see */ 
289                 if (memcmp ((void *)tvb_get_ptr (tvb, offset+frame_len, 8),
290                             (void *)fcip_header_2_bytes, 8) == 0) {
291                     return (offset);
292                 }
293                 else {
294                     offset++;
295                     bytes_remaining--;
296                     goto NXT_BYTE;
297                 }
298             }
299             else {
300                 return (offset);
301             }
302         }
303         else {
304             if(fcip_desegment && pinfo->can_desegment) {
305                 /*
306                  * This frame doesn't have all of the data for
307                  * this message, but we can do reassembly on it.
308                  *
309                  * Tell the TCP dissector where the data for this
310                  * message starts in the data it handed us, and
311                  * how many more bytes we need, and return.
312                  */
313                 pinfo->desegment_offset = offset;
314                 pinfo->desegment_len = frame_len - bytes_remaining;
315                 return -2;
316             }
317             else {
318                 return (offset);
319             }
320         }
321     }
322
323     return (-1);                /* Unable to find FCIP header */
324 }
325
326 static void
327 dissect_fcencap_header (tvbuff_t *tvb, proto_tree *tree, gint offset)
328 {
329     guint8 protocol = tvb_get_guint8 (tvb, offset);
330     
331     if (tree) {
332         proto_tree_add_uint (tree, hf_fcip_protocol, tvb, offset, 1, protocol);
333         proto_tree_add_item (tree, hf_fcip_version, tvb, offset+1, 1, 0);
334         proto_tree_add_item (tree, hf_fcip_protocol_c, tvb, offset+2, 1, 0);
335         proto_tree_add_item (tree, hf_fcip_version_c, tvb, offset+3, 1, 0);
336
337         if (protocol == FCENCAP_PROTO_FCIP) {
338             proto_tree_add_item (tree, hf_fcip_encap_word1, tvb, offset+4,
339                                  4, 0);
340             proto_tree_add_item (tree, hf_fcip_pflags_changed, tvb, offset+8,
341                                  1, 0);
342             proto_tree_add_item (tree, hf_fcip_pflags_special, tvb, offset+8,
343                                  1, 0);
344             proto_tree_add_item (tree, hf_fcip_pflags_c, tvb, offset+10, 1, 0);
345         }
346
347         /* XXX - break out CRCV flag. */
348         proto_tree_add_item (tree, hf_fcip_flags, tvb, offset+12, 1, 0);
349         proto_tree_add_item (tree, hf_fcip_framelen, tvb, offset+12, 2, 0);
350         proto_tree_add_item (tree, hf_fcip_flags_c, tvb, offset+14, 1, 0);
351         proto_tree_add_item (tree, hf_fcip_framelen_c, tvb, offset+14, 2, 0);
352         proto_tree_add_item (tree, hf_fcip_tsec, tvb, offset+16, 4, 0);
353         proto_tree_add_item (tree, hf_fcip_tusec, tvb, offset+20, 4, 0);
354         /* XXX - check CRC if CRCV is set? */
355         proto_tree_add_item (tree, hf_fcip_encap_crc, tvb, offset+24, 4, 0);
356     }
357 }
358
359 static void
360 dissect_fcip_sf (tvbuff_t *tvb, proto_tree *tree, gint offset)
361 {
362     if (tree) {
363         proto_tree_add_string (tree, hf_fcip_src_wwn, tvb, offset, 8,
364                                fcwwn_to_str (tvb_get_ptr (tvb, offset, 8)));
365         proto_tree_add_bytes (tree, hf_fcip_src_entity_id, tvb, offset+8, 8,
366                               tvb_get_ptr (tvb, offset+8, 8));
367         proto_tree_add_bytes (tree, hf_fcip_conn_nonce, tvb, offset+16, 8,
368                               tvb_get_ptr (tvb, offset+16, 8));
369         /* XXX - break out these flags */
370         proto_tree_add_item (tree, hf_fcip_conn_flags, tvb, offset+24, 1, 0);
371         proto_tree_add_item (tree, hf_fcip_conn_code, tvb, offset+26, 2, 0);
372         proto_tree_add_string (tree, hf_fcip_dst_wwn, tvb, offset+30, 8,
373                                fcwwn_to_str (tvb_get_ptr (tvb, offset+30, 8)));
374         proto_tree_add_item (tree, hf_fcip_katov, tvb, offset+38, 4, 0);
375     }
376 }
377
378 static gboolean
379 dissect_fcip (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
380 {
381     gint offset = 0,
382          start  = 0,
383          frame_len = 0;
384     gint bytes_remaining = tvb_length_remaining (tvb, offset);
385     guint8 pflags, sof, eof;
386    /* Set up structures needed to add the protocol subtree and manage it */
387     proto_item *ti;
388     proto_tree *fcip_tree = NULL;
389     tvbuff_t *next_tvb;
390     
391     if (!proto_is_protocol_enabled(proto_fcip))
392         return FALSE;   /* iSCSI has been disabled */
393
394     if (bytes_remaining < FCIP_ENCAP_HEADER_LEN) {
395         return FALSE;
396     }
397
398     if ((pinfo->srcport != fcip_port) && (pinfo->destport != fcip_port)) {
399         return FALSE;
400     }
401
402     while (bytes_remaining > FCIP_ENCAP_HEADER_LEN) {
403         if ((offset = get_next_fcip_header_offset (tvb, pinfo, offset)) == -1) { 
404             return FALSE;
405         }
406         else if (offset == -2) {
407             /* We need more data to desegment */
408             return (TRUE);
409         }
410
411         start = offset;
412         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
413             col_set_str(pinfo->cinfo, COL_PROTOCOL, "FCIP");
414
415         frame_len = (tvb_get_ntohs (tvb, offset+12) & 0x03FF)*4;
416
417         if (bytes_remaining < frame_len) {
418             if(fcip_desegment && pinfo->can_desegment) {
419                 /*
420                  * This frame doesn't have all of the data for
421                  * this message, but we can do reassembly on it.
422                  *
423                  * Tell the TCP dissector where the data for this
424                  * message starts in the data it handed us, and
425                  * how many more bytes we need, and return.
426                  */
427                 pinfo->desegment_offset = offset;
428                 pinfo->desegment_len = frame_len - bytes_remaining;
429                 return (TRUE);
430             }
431         }
432         
433         pflags = tvb_get_guint8 (tvb, start+8);
434         
435         if (tree) {
436             if (FCIP_IS_SF (pflags)) {
437                 ti = proto_tree_add_protocol_format (tree, proto_fcip, tvb, 0,
438                                                      FCIP_ENCAP_HEADER_LEN,
439                                                      "FCIP");
440             }
441             else if (tvb_bytes_exist (tvb, offset, offset+frame_len-4)) {
442                 sof = tvb_get_guint8 (tvb, offset+FCIP_ENCAP_HEADER_LEN);
443                 eof = tvb_get_guint8 (tvb, offset+frame_len - 4);
444
445                 ti = proto_tree_add_protocol_format (tree, proto_fcip, tvb, 0,
446                                                      FCIP_ENCAP_HEADER_LEN,
447                                                      "FCIP (%s/%s)",
448                                                      val_to_str (sof, fcip_sof_vals,
449                                                                  "0x%x"),
450                                                      val_to_str (eof, fcip_eof_vals,
451                                                                  "0x%x"));
452             }
453             else {
454                 sof = tvb_get_guint8 (tvb, offset+FCIP_ENCAP_HEADER_LEN);
455                 
456                 ti = proto_tree_add_protocol_format (tree, proto_fcip, tvb, 0,
457                                                      FCIP_ENCAP_HEADER_LEN,
458                                                      "FCIP (%s/%s)",
459                                                      val_to_str (sof, fcip_sof_vals,
460                                                                  "0x%x"),
461                                                      "NA");
462             }
463             fcip_tree = proto_item_add_subtree (ti, ett_fcip);
464             /* Dissect the Common FC Encap header */
465             dissect_fcencap_header (tvb, fcip_tree, offset);
466
467             offset += FCIP_ENCAP_HEADER_LEN;
468
469             if (!FCIP_IS_SF (pflags)) {
470                 /* print SOF */
471                 proto_tree_add_item (fcip_tree, hf_fcip_sof, tvb, offset, 1, 0);
472                 proto_tree_add_item (fcip_tree, hf_fcip_sof_c, tvb, offset+2, 1, 0);
473                 /* print EOF */
474                 
475                 offset += (frame_len-FCIP_ENCAP_HEADER_LEN-4);
476                 if (tvb_bytes_exist (tvb, offset, 4)) {
477                     proto_tree_add_item (fcip_tree, hf_fcip_eof, tvb, offset, 1, 0);
478                     proto_tree_add_item (fcip_tree, hf_fcip_eof_c, tvb, offset+2, 1, 0);
479                 }
480             }
481         }
482
483         /* Call the FC Dissector if this is carrying an FC frame */
484         if (!FCIP_IS_SF(pflags)) {
485             /* Special frame bit is not set */
486             next_tvb = tvb_new_subset (tvb, FCIP_ENCAP_HEADER_LEN+4, -1, -1);
487             if (fc_handle) {
488                 call_dissector (fc_handle, next_tvb, pinfo, tree);
489             }
490             else if (data_handle) {
491                 call_dissector (data_handle, next_tvb, pinfo, tree);
492             }
493         }
494         else {
495             if (check_col(pinfo->cinfo, COL_INFO)) 
496                 col_set_str(pinfo->cinfo, COL_INFO, "Special Frame");
497             if (FCIP_IS_CH (pflags)) {
498                 if (check_col(pinfo->cinfo, COL_INFO)) 
499                     col_append_str(pinfo->cinfo, COL_INFO, "(Changed)");
500             }
501
502             dissect_fcip_sf (tvb, fcip_tree, offset+4);
503         }
504
505         bytes_remaining -= frame_len;
506     }
507
508     return (TRUE);
509 }
510
511 void
512 proto_register_fcip (void)
513 {
514
515     /* Setup list of header fields  See Section 1.6.1 for details*/
516     static hf_register_info hf[] = {
517         { &hf_fcip_protocol,
518           { "Protocol", "fcencap.proto", FT_UINT8, BASE_DEC,
519              VALS(fcencap_proto_vals), 0, "Protocol", HFILL }},
520         { &hf_fcip_protocol_c,
521           {"Protocol (1's Complement)", "fcencap.protoc", FT_UINT8, BASE_DEC, NULL,
522            0, "Protocol (1's Complement)", HFILL}},
523         { &hf_fcip_version,
524           {"Version", "fcencap.version", FT_UINT8, BASE_DEC, NULL, 0, "",
525            HFILL}},
526         { &hf_fcip_version_c,
527           {"Version (1's Complement)", "fcencap.versionc", FT_UINT8, BASE_DEC,
528            NULL, 0, "", HFILL}},
529         { &hf_fcip_encap_word1,
530           {"FCIP Encapsulation Word1", "fcip.word1", FT_UINT32, BASE_HEX, NULL,
531            0, "", HFILL}},
532         { &hf_fcip_flags,
533           {"Flags", "fcencap.flags", FT_UINT8, BASE_HEX, NULL, 0xFC, "", HFILL}},
534         { &hf_fcip_flags_c,
535           {"Flags (1's Complement)", "fcencap.flagsc", FT_UINT8, BASE_HEX,
536            NULL, 0xFC, "", HFILL}},
537         { &hf_fcip_framelen,
538           {"Frame Length (in Words)", "fcencap.framelen", FT_UINT16, BASE_DEC,
539            NULL, 0x03FF, "", HFILL}},
540         { &hf_fcip_framelen_c,
541           {"Frame Length (1's Complement)", "fcencap.framelenc", FT_UINT16,
542            BASE_DEC, NULL, 0x03FF, "", HFILL}},
543         { &hf_fcip_tsec,
544           {"Time (secs)", "fcencap.tsec", FT_UINT32, BASE_DEC, NULL, 0, "",
545            HFILL}},
546         { &hf_fcip_tusec,
547           {"Time (fraction)", "fcencap.tusec", FT_UINT32, BASE_DEC, NULL, 0,
548            "", HFILL}},
549         { &hf_fcip_encap_crc,
550           {"CRC", "fcencap.crc", FT_UINT32, BASE_HEX, NULL, 0, "", HFILL}},
551         { &hf_fcip_sof,
552           {"SOF", "fcip.sof", FT_UINT8, BASE_HEX, VALS (&fcip_sof_vals), 0,
553            "", HFILL}},
554         { &hf_fcip_sof_c,
555           {"SOF (1's Complement)", "fcip.sofc", FT_UINT8, BASE_HEX, NULL,
556            0, "", HFILL}},
557         { &hf_fcip_eof,
558           {"EOF", "fcip.eof", FT_UINT8, BASE_HEX, VALS (&fcip_eof_vals), 0,
559            "", HFILL}},
560         { &hf_fcip_eof_c,
561           {"EOF (1's Complement)", "fcip.eofc", FT_UINT8, BASE_HEX, NULL,
562            0, "", HFILL}},
563         { &hf_fcip_pflags_changed,
564           {"Changed Flag", "fcip.pflags.ch", FT_BOOLEAN, BASE_DEC, NULL, 0x80,
565            "", HFILL}},
566         { &hf_fcip_pflags_special,
567           {"Special Frame Flag", "fcip.pflags.sf", FT_BOOLEAN, BASE_DEC, NULL,
568            0x1, "", HFILL}},
569         { &hf_fcip_pflags_c,
570           {"Pflags (1's Complement)", "fcip.pflagsc", FT_UINT8, BASE_HEX, NULL,
571            0x0, "", HFILL}},
572         { &hf_fcip_src_wwn,
573           {"Source Fabric WWN", "fcip.srcwwn", FT_STRING, BASE_HEX, NULL, 0x0, 
574            "", HFILL}},
575         { &hf_fcip_dst_wwn,
576           {"Destination Fabric WWN", "fcip.dstwwn", FT_STRING, BASE_HEX, NULL,
577            0x0, "", HFILL}},
578         { &hf_fcip_src_entity_id,
579           {"FC/FCIP Entity Id", "fcip.srcid", FT_BYTES, BASE_HEX, NULL, 0x0,
580            "", HFILL}},
581         { &hf_fcip_conn_flags,
582           {"Connection Usage Flags", "fcip.connflags", FT_UINT8, BASE_HEX,
583            NULL, 0x0, "", HFILL}},
584         { &hf_fcip_conn_code,
585           {"Connection Usage Code", "fcip.conncode", FT_UINT16, BASE_HEX, NULL,
586            0x0, "", HFILL}},
587         { &hf_fcip_katov,
588           {"K_A_TOV", "fcip.katov", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL}},
589         { &hf_fcip_conn_nonce,
590           {"Connection Nonce", "fcip.nonce", FT_BYTES, BASE_HEX, NULL, 0x0, "",
591            HFILL}},
592     };
593
594     static gint *ett[] = {
595         &ett_fcip,
596     };
597     
598     module_t *fcip_module;
599
600     /* Register the protocol name and description */
601     proto_fcip = proto_register_protocol("FCIP", "FCIP", "fcip");
602
603     /* Required function calls to register the header fields and
604      * subtrees used */
605     proto_register_field_array(proto_fcip, hf, array_length(hf));
606     proto_register_subtree_array(ett, array_length(ett));
607
608     fcip_module = prefs_register_protocol(proto_fcip, NULL);
609     prefs_register_bool_preference(fcip_module,
610                                    "desegment",
611                                    "Desegment FCIP messages",
612                                    "When enabled, FCIP messages that span multiple TCP segments are desegmented",
613                                    &fcip_desegment);
614     prefs_register_uint_preference(fcip_module,
615                                    "target_port",
616                                    "Target port",
617                                    "Port number used for FCIP",
618                                    10,
619                                    &fcip_port);
620 }
621
622
623 /*
624  * If this dissector uses sub-dissector registration add a
625  * registration routine.
626  */
627
628 /*
629  * This format is required because a script is used to find these
630  * routines and create the code that calls these routines.
631  */
632 void
633 proto_reg_handoff_fcip (void)
634 {
635     heur_dissector_add("tcp", dissect_fcip, proto_fcip);
636     data_handle = find_dissector("data");
637     fc_handle = find_dissector("fc");
638 }