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