Fix document creation under Windows, add ethereal-filter.html to the NSIS
[obnox/wireshark/wip.git] / packet-fcswils.c
1 /* packet-fcswils
2  * Routines for FC Inter-switch link services
3  * Copyright 2001, Dinesh G Dutt <ddutt@cisco.com>
4  *
5  * $Id: packet-fcswils.c,v 1.5 2003/06/30 21:58:41 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 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <glib.h>
43
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
46 #endif
47
48 #include <epan/packet.h>
49 #include <epan/conversation.h>
50 #include "etypes.h"
51 #include "packet-fc.h"
52 #include "packet-fcswils.h"
53
54 #define FC_SWILS_RPLY               0x0
55 #define FC_SWILS_REQ                0x1
56 #define FC_SWILS_RSCN_DEVENTRY_SIZE 20
57
58 /* Zone name has the structure:
59  * name_len (1 byte), rsvd (3 bytes), name (m bytes), fill (n bytes)
60  * name_len excludes the 4 initial bytes before the name
61  */
62 #define ZONENAME_LEN(x, y)  (tvb_get_guint8(x, y)+4)
63
64 /* Initialize the protocol and registered fields */
65 static int proto_fcswils               = -1;
66 static int hf_swils_opcode             = -1;
67 static int hf_swils_elp_rev            = -1;
68 static int hf_swils_elp_flags          = -1;
69 static int hf_swils_elp_r_a_tov        = -1;
70 static int hf_swils_elp_e_d_tov        = -1;
71 static int hf_swils_elp_req_epn        = -1;
72 static int hf_swils_elp_req_esn        = -1;
73 static int hf_swils_elp_clsf_svcp      = -1;
74 static int hf_swils_elp_clsf_rcvsz     = -1;
75 static int hf_swils_elp_clsf_conseq    = -1;
76 static int hf_swils_elp_clsf_e2e       = -1;
77 static int hf_swils_elp_clsf_openseq   = -1;
78 static int hf_swils_elp_cls1_svcp      = -1;
79 static int hf_swils_elp_cls1_rcvsz     = -1;
80 static int hf_swils_elp_cls2_svcp      = -1;
81 static int hf_swils_elp_cls2_rcvsz     = -1;
82 static int hf_swils_elp_cls3_svcp      = -1;
83 static int hf_swils_elp_cls3_rcvsz     = -1;
84 static int hf_swils_elp_isl_fc_mode    = -1;
85 static int hf_swils_elp_fcplen         = -1;
86 static int hf_swils_elp_b2bcredit      = -1;
87 static int hf_swils_elp_compat1        = -1;
88 static int hf_swils_elp_compat2        = -1;
89 static int hf_swils_elp_compat3        = -1;
90 static int hf_swils_elp_compat4        = -1;
91 static int hf_swils_efp_rec_type       = -1;
92 static int hf_swils_efp_dom_id         = -1;
93 static int hf_swils_efp_switch_name    = -1;
94 static int hf_swils_efp_mcast_grpno    = -1;
95 static int hf_swils_efp_alias_token    = -1;
96 static int hf_swils_efp_payload_len    = -1;
97 static int hf_swils_efp_pswitch_pri    = -1;
98 static int hf_swils_efp_pswitch_name   = -1;
99 static int hf_swils_dia_switch_name    = -1;
100 static int hf_swils_rdi_payload_len    = -1;
101 static int hf_swils_rdi_req_sname      = -1;
102 static int hf_swils_fspfh_cmd          = -1;
103 static int hf_swils_fspfh_rev          = -1;
104 static int hf_swils_fspfh_ar_num       = -1;
105 static int hf_swils_fspfh_auth_type    = -1;
106 static int hf_swils_fspfh_dom_id       = -1;
107 static int hf_swils_fspfh_auth         = -1;
108 static int hf_swils_hlo_options        = -1;
109 static int hf_swils_hlo_hloint         = -1;
110 static int hf_swils_hlo_deadint        = -1;
111 static int hf_swils_hlo_rcv_domid      = -1;
112 static int hf_swils_hlo_orig_pidx      = -1;
113 static int hf_swils_ldrec_linkid       = -1;
114 static int hf_swils_ldrec_out_pidx     = -1;
115 static int hf_swils_ldrec_nbr_pidx     = -1;
116 static int hf_swils_ldrec_link_type    = -1;
117 static int hf_swils_ldrec_link_cost    = -1;
118 static int hf_swils_lsrh_lsr_type      = -1;
119 static int hf_swils_lsrh_lsid          = -1;
120 static int hf_swils_lsrh_adv_domid     = -1;
121 static int hf_swils_lsrh_ls_incid      = -1;
122 static int hf_swils_esc_pdesc_vendorid = -1;
123 static int hf_swils_esc_swvendorid     = -1;
124 static int hf_swils_esc_protocolid     = -1;
125 static int hf_swils_rscn_evtype        = -1;
126 static int hf_swils_rscn_addrfmt       = -1;
127 static int hf_swils_rscn_detectfn      = -1;
128 static int hf_swils_rscn_affectedport  = -1;
129 static int hf_swils_rscn_portstate     = -1;
130 static int hf_swils_rscn_portid        = -1;
131 static int hf_swils_rscn_pwwn          = -1;
132 static int hf_swils_rscn_nwwn          = -1;
133 static int hf_swils_zone_activezonenm  = -1;
134 static int hf_swils_zone_objname       = -1;
135 static int hf_swils_zone_objtype       = -1;
136 static int hf_swils_zone_mbrtype       = -1;
137 static int hf_swils_zone_protocol      = -1;
138 static int hf_swils_zone_mbrid         = -1;
139 static int hf_swils_zone_status        = -1;
140 static int hf_swils_zone_reason        = -1;
141 static int hf_swils_aca_domainid       = -1;
142 static int hf_swils_sfc_opcode         = -1;
143 static int hf_swils_sfc_zonenm         = -1;
144 static int hf_swils_rjt                = -1;
145 static int hf_swils_rjtdet             = -1;
146 static int hf_swils_rjtvendor          = -1;
147 static int hf_swils_zone_mbrid_lun     = -1;
148
149 /* Initialize the subtree pointers */
150 static gint ett_fcswils             = -1;
151 static gint ett_fcswils_swacc       = -1;
152 static gint ett_fcswils_swrjt       = -1;
153 static gint ett_fcswils_elp         = -1;
154 static gint ett_fcswils_efp         = -1;
155 static gint ett_fcswils_efplist     = -1;
156 static gint ett_fcswils_dia         = -1;
157 static gint ett_fcswils_rdi         = -1;
158 static gint ett_fcswils_fspfhdr     = -1;
159 static gint ett_fcswils_hlo         = -1;
160 static gint ett_fcswils_lsrec       = -1;
161 static gint ett_fcswils_lsrechdr    = -1;
162 static gint ett_fcswils_ldrec       = -1;
163 static gint ett_fcswils_lsu         = -1;
164 static gint ett_fcswils_lsa         = -1;
165 static gint ett_fcswils_bf          = -1;
166 static gint ett_fcswils_rcf         = -1;
167 static gint ett_fcswils_rscn        = -1;
168 static gint ett_fcswils_rscn_dev    = -1;
169 static gint ett_fcswils_drlir       = -1;
170 static gint ett_fcswils_mr          = -1;
171 static gint ett_fcswils_zoneobjlist = -1;
172 static gint ett_fcswils_zoneobj     = -1;
173 static gint ett_fcswils_zonembr     = -1;
174 static gint ett_fcswils_aca         = -1;
175 static gint ett_fcswils_rca         = -1;
176 static gint ett_fcswils_sfc         = -1;
177 static gint ett_fcswils_ufc         = -1;
178 static gint ett_fcswils_esc         = -1;
179 static gint ett_fcswils_esc_pdesc   = -1;
180
181 static const value_string fc_swils_opcode_key_val[] = {
182     {FC_SWILS_SWRJT  , "SW_RJT"},
183     {FC_SWILS_SWACC  , "SW_ACC"},
184     {FC_SWILS_ELP    , "ELP"},
185     {FC_SWILS_EFP    , "EFP"},
186     {FC_SWILS_DIA    , "DIA"},
187     {FC_SWILS_RDI    , "RDI"},
188     {FC_SWILS_HLO    , "HLO"},
189     {FC_SWILS_LSU    , "LSU"},
190     {FC_SWILS_LSA    , "LSA"},
191     {FC_SWILS_BF     , "BF"},
192     {FC_SWILS_RCF    , "RCF"},
193     {FC_SWILS_RSCN   , "SW_RSCN"},
194     {FC_SWILS_DRLIR  , "DRLIR"},
195     {FC_SWILS_DSCN   , "DSCN"},
196     {FC_SWILS_LOOPD  , "LOOPD"},
197     {FC_SWILS_MR     , "MR"},
198     {FC_SWILS_ACA    , "ACA"},
199     {FC_SWILS_RCA    , "RCA"},
200     {FC_SWILS_SFC    , "SFC"},
201     {FC_SWILS_UFC    , "UFC"},
202     {FC_SWILS_ESC    , "ESC"},
203     {0, NULL},
204 };
205
206 static const value_string fc_swils_rjt_val [] = {
207     {FC_SWILS_RJT_INVCODE   , "Invalid Cmd Code"},
208     {FC_SWILS_RJT_INVVER    , "Invalid Revision"},
209     {FC_SWILS_RJT_LOGERR    , "Logical Error"},
210     {FC_SWILS_RJT_INVSIZE   , "Invalid Size"},
211     {FC_SWILS_RJT_LOGBSY    , "Logical Busy"},
212     {FC_SWILS_RJT_PROTERR   , "Protocol Error"},
213     {FC_SWILS_RJT_GENFAIL   , "Unable to Perform"},
214     {FC_SWILS_RJT_CMDNOTSUPP, "Unsupported Cmd"},
215     {FC_SWILS_RJT_VENDUNIQ  , "Vendor Unique Err"},
216     {0, NULL},
217 };
218
219 static const value_string fc_swils_deterr_val [] = {
220     {FC_SWILS_RJT_NODET ,      "No Additional Details"},
221     {FC_SWILS_RJT_CLSF_ERR ,   "Class F Svc Param Err"},
222     {FC_SWILS_RJT_CLSN_ERR ,   "Class N Svc Param Err"},
223     {FC_SWILS_RJT_INVFC_CODE , "Unknown Flow Ctrl Code"},
224     {FC_SWILS_RJT_INVFC_PARM , "Invalid Flow Ctrl Parm"},
225     {FC_SWILS_RJT_INV_PNAME ,  "Invalid Port Name"},
226     {FC_SWILS_RJT_INV_SNAME ,  "Invalid Switch Name"},
227     {FC_SWILS_RJT_TOV_MSMTCH , "R_A_/E_D_TOV Mismatch"},
228     {FC_SWILS_RJT_INV_DIDLST,  "Invalid Domain ID List"},
229     {FC_SWILS_RJT_CMD_INPROG , "Cmd Already in Progress"},
230     {FC_SWILS_RJT_OORSRC ,     "Insufficient Resources"},
231     {FC_SWILS_RJT_NO_DID ,     "Domain ID Unavailable"},
232     {FC_SWILS_RJT_INV_DID,     "Invalid Domain ID"},
233     {FC_SWILS_RJT_NO_REQ ,     "Request Not Supported"},
234     {FC_SWILS_RJT_NOLNK_PARM , "Link Parm Not Estd."},
235     {FC_SWILS_RJT_NO_REQDID ,  "Group of Domain IDs Unavail"},
236     {FC_SWILS_RJT_EP_ISOL ,    "E_Port Isolated"},
237     {0, NULL}
238 };
239
240 static const value_string fcswils_elp_fc_val[] = {
241     {FC_SWILS_ELP_FC_VENDOR, "Vendor Unique"},
242     {FC_SWILS_ELP_FC_RRDY,   "R_RDY Flow Ctrl"},
243     {0, NULL},
244 };
245
246 static const value_string fcswils_rectype_val[] = {
247     {FC_SWILS_LRECTYPE_DOMAIN, "Domain ID List Rec"},
248     {FC_SWILS_LRECTYPE_MCAST, "Multicast ID List Rec"},
249     {0, NULL},
250 };
251
252 static const value_string fc_swils_link_type_val[] = {
253     {0x01, "P2P Link"},
254     {0xF0, "Vendor Specific"},
255     {0xF1, "Vendor Specific"},
256     {0xF2, "Vendor Specific"},
257     {0xF3, "Vendor Specific"},
258     {0xF4, "Vendor Specific"},
259     {0xF5, "Vendor Specific"},
260     {0xF6, "Vendor Specific"},
261     {0xF7, "Vendor Specific"},
262     {0xF8, "Vendor Specific"},
263     {0xF9, "Vendor Specific"},
264     {0xFA, "Vendor Specific"},
265     {0xFB, "Vendor Specific"},
266     {0xFC, "Vendor Specific"},
267     {0xFD, "Vendor Specific"},
268     {0xFE, "Vendor Specific"},
269     {0xFF, "Vendor Specific"},
270     {0, NULL},
271 };
272
273 static const value_string fc_swils_fspf_linkrec_val[] = {
274     {FC_SWILS_LSR_SLR, "Switch Link Record"},
275     {FC_SWILS_LSR_ARS, "AR Summary Record"},
276     {0, NULL},
277 };
278
279 static const value_string fc_swils_fspf_lsrflags_val[] = {
280     {0x0, "LSR is for a Topology Update"},
281     {0x1, "LSR is for Initial DB Sync | Not the last seq in DB sync"},
282     {0x2, "Last Seq in DB Sync. LSU has no LSRs"},
283     {0x3, "LSR is for Initial DB Sync | Last Seq in DB Sync"},
284     {0, NULL},
285 };
286
287 static const value_string fc_swils_rscn_portstate_val[] = {
288     {0, "No Additional Info"},
289     {1, "Port is online"},
290     {2, "Port is offline"},
291     {0, NULL},
292 };
293
294 static const value_string fc_swils_rscn_addrfmt_val[] = {
295     {0, "Port Addr Format"},
296     {1, "Area Addr Format"},
297     {2, "Domain Addr Format"},
298     {3, "Fabric Addr Format"},
299 };
300
301 static const value_string fc_swils_rscn_detectfn_val[] = {
302     {1, "Fabric Detected"},
303     {2, "N_Port Detected"},
304     {0, NULL},
305 };
306
307 static const value_string fc_swils_esc_protocol_val[] = {
308     {0, "Reserved"},
309     {1, "FSPF-Backbone Protocol"},
310     {2, "FSPF Protocol"},
311     {0, NULL},
312 };
313
314 static const value_string fc_swils_zoneobj_type_val[] = {
315     {0, "Reserved"},
316     {FC_SWILS_ZONEOBJ_ZONESET  , "Zone Set"},
317     {FC_SWILS_ZONEOBJ_ZONE     , "Zone"},
318     {FC_SWILS_ZONEOBJ_ZONEALIAS, "Zone Alias"},
319     {0, NULL},
320 };
321
322 const value_string fc_swils_zonembr_type_val[] = {
323     {0, "Reserved"},
324     {FC_SWILS_ZONEMBR_WWN, "WWN"},
325     {FC_SWILS_ZONEMBR_DP, "Domain/Physical Port (0x00ddpppp)"},
326     {FC_SWILS_ZONEMBR_FCID, "FC Address"},
327     {FC_SWILS_ZONEMBR_ALIAS, "Zone Alias"},
328     {FC_SWILS_ZONEMBR_WWN_LUN, "WWN+LUN"},
329     {FC_SWILS_ZONEMBR_DP_LUN, "Domain/Physical Port+LUN"},
330     {FC_SWILS_ZONEMBR_FCID_LUN, "FCID+LUN"},
331     {0, NULL},
332 };
333
334 static const value_string fc_swils_mr_rsp_val[] = {
335     {0, "Successful"},
336     {1, "Fabric Busy"},
337     {2, "Failed"},
338     {0, NULL},
339 };
340
341 static const value_string fc_swils_mr_reason_val[] = {
342     {0x0, "No Reason"},
343     {0x1, "Invalid Data Length"},
344     {0x2, "Unsupported Command"},
345     {0x3, "Reserved"},
346     {0x4, "Not Authorized"},
347     {0x5, "Invalid Request"},
348     {0x6, "Fabric Changing"},
349     {0x7, "Update Not Staged"},
350     {0x8, "Invalid Zone Set Format"},
351     {0x9, "Invalid Data"},
352     {0xA, "Cannot Merge"},
353     {0, NULL},
354 };
355
356 static const value_string fc_swils_sfc_op_val[] = {
357     {0, "Reserved"},
358     {1, "Reserved"},
359     {2, "Reserved"},
360     {3, "Activate Zone Set"},
361     {4, "Deactivate Zone Set"},
362     {0, NULL},
363 };
364
365 typedef struct _zonename {
366     guint32 namelen:8,
367             rsvd:24;
368     gchar *name;
369     gchar *pad;
370 } zonename_t;
371
372 typedef struct _fcswils_conv_key {
373     guint32 conv_idx;
374 } fcswils_conv_key_t;
375
376 typedef struct _fcswils_conv_data {
377     guint32 opcode;
378 } fcswils_conv_data_t;
379
380 GHashTable *fcswils_req_hash = NULL;
381 GMemChunk *fcswils_req_keys = NULL;
382 GMemChunk *fcswils_req_vals = NULL;
383 guint32 fcswils_init_count = 25;
384
385 static dissector_handle_t data_handle;
386
387 static gint get_zoneobj_len (tvbuff_t *tvb, gint offset);
388
389 /*
390  * Hash Functions
391  */
392 static gint
393 fcswils_equal(gconstpointer v, gconstpointer w)
394 {
395   fcswils_conv_key_t *v1 = (fcswils_conv_key_t *)v;
396   fcswils_conv_key_t *v2 = (fcswils_conv_key_t *)w;
397
398   return (v1->conv_idx == v2->conv_idx);
399 }
400
401 static guint
402 fcswils_hash (gconstpointer v)
403 {
404         fcswils_conv_key_t *key = (fcswils_conv_key_t *)v;
405         guint val;
406
407         val = key->conv_idx;
408
409         return val;
410 }
411
412 /*
413  * Protocol initialization
414  */
415 static void
416 fcswils_init_protocol(void)
417 {
418         if (fcswils_req_keys)
419             g_mem_chunk_destroy (fcswils_req_keys);
420         if (fcswils_req_vals)
421             g_mem_chunk_destroy (fcswils_req_vals);
422         if (fcswils_req_hash)
423             g_hash_table_destroy (fcswils_req_hash);
424
425         fcswils_req_hash = g_hash_table_new(fcswils_hash, fcswils_equal);
426         fcswils_req_keys = g_mem_chunk_new("fcswils_req_keys",
427                                            sizeof(fcswils_conv_key_t),
428                                            fcswils_init_count * sizeof(fcswils_conv_key_t),
429                                            G_ALLOC_AND_FREE);
430         fcswils_req_vals = g_mem_chunk_new("fcswils_req_vals",
431                                            sizeof(fcswils_conv_data_t),
432                                            fcswils_init_count * sizeof(fcswils_conv_data_t),
433                                            G_ALLOC_AND_FREE);
434 }
435
436 static gchar *
437 zonenm_to_str (tvbuff_t *tvb, gint offset)
438 {
439     int len = tvb_get_guint8 (tvb, offset);
440     return ((gchar *)tvb_get_ptr (tvb, offset+4, len));
441 }
442
443 /* Offset points to the start of the zone object */
444 static gint
445 get_zoneobj_len (tvbuff_t *tvb, gint offset)
446 {
447     gint numrec, numrec1;
448     guint8 objtype;
449     gint i, j, len;
450
451     /* zone object structure is:
452      * type (1 byte), protocol (1 byte), rsvd (2 bytes), obj name (x bytes),
453      * num of zone mbrs (4 bytes ), list of zone members (each member if of
454      * variable length).
455      *
456      * zone member structure is:
457      * type (1 byte), rsvd (1 byte), flags (1 byte), id_len (1 byte),
458      * id (id_len bytes)
459      */
460     objtype = tvb_get_guint8 (tvb, offset);
461     len = 4 + ZONENAME_LEN (tvb, offset+4); /* length upto num_of_mbrs field */
462     numrec = tvb_get_ntohl (tvb, offset+len); /* gets us num of zone mbrs */
463
464     len += 4;                   /* + num_mbrs */
465     for (i = 0; i < numrec; i++) {
466         if (objtype == FC_SWILS_ZONEOBJ_ZONESET) {
467             len += 4 + ZONENAME_LEN (tvb, offset+4+len); /* length upto num_of_mbrs field */
468             numrec1 = tvb_get_ntohl (tvb, offset+len);
469
470             len += 4;
471             for (j = 0; j < numrec1; j++) {
472                 len += 4 + tvb_get_guint8 (tvb, offset+3+len);
473             }
474         }
475         else if (objtype == FC_SWILS_ZONEOBJ_ZONE) {
476             len += 4 + tvb_get_guint8 (tvb, offset+3+len);
477         }
478     }
479
480     return len;
481 }
482
483 static void
484 dissect_swils_elp (tvbuff_t *tvb, proto_tree *elp_tree, guint8 isreq _U_)
485 {
486     
487     /* Set up structures needed to add the protocol subtree and manage it */
488     int offset = 0,
489         stroff = 0;
490     gchar flags[40];
491     fcswils_elp elp;
492
493     /* Response i.e. SW_ACC for an ELP has the same format as the request */
494     /* We skip the initial 4 bytes as we don't care about the opcode */
495     tvb_memcpy (tvb, (guint8 *)&elp, 4, FC_SWILS_ELP_SIZE);
496     
497     elp.r_a_tov = ntohl (elp.r_a_tov);
498     elp.e_d_tov = ntohl (elp.e_d_tov);
499     elp.isl_flwctrl_mode = ntohs (elp.isl_flwctrl_mode);
500     elp.flw_ctrl_parmlen = ntohs (elp.flw_ctrl_parmlen);
501     
502     if (elp_tree) {
503         offset += 4;
504         proto_tree_add_item (elp_tree, hf_swils_elp_rev, tvb, offset++, 1, 0);
505         proto_tree_add_item (elp_tree, hf_swils_elp_flags, tvb, offset, 2, 0);
506         offset += 3;
507         proto_tree_add_uint_format (elp_tree, hf_swils_elp_r_a_tov, tvb, offset, 4,
508                                     elp.r_a_tov, "R_A_TOV: %d msecs", elp.r_a_tov);
509         offset += 4;
510         proto_tree_add_uint_format (elp_tree, hf_swils_elp_e_d_tov, tvb, offset, 4,
511                                     elp.e_d_tov, "E_D_TOV: %d msecs", elp.e_d_tov);
512         offset += 4;
513         proto_tree_add_string (elp_tree, hf_swils_elp_req_epn, tvb, offset, 8,
514                                fcwwn_to_str (elp.req_epname));
515         offset += 8;
516         proto_tree_add_string (elp_tree, hf_swils_elp_req_esn, tvb, offset, 8,
517                                fcwwn_to_str (elp.req_sname));
518         offset += 8;
519
520         flags[0] = '\0';
521         if (elp.clsf_svcparm[0] & 0x80) {
522             strcpy (flags, "Class F Valid");
523
524             if (elp.clsf_svcparm[4] & 0x20) {
525                 strcpy (&flags[13], " | X_ID Interlock");
526             }
527             else {
528                 strcpy (&flags[13], " | No X_ID Interlk");
529             }
530         }
531         else {
532             strcpy (flags, "Class F Invld");
533         }
534         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_clsf_svcp, tvb, offset, 6, 
535                                      &elp.clsf_svcparm[0], "Class F Svc Parameters: (%s)", flags);
536         offset += 6;
537
538         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_rcvsz, tvb, offset, 2, 0);
539         offset += 2;
540         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_conseq, tvb, offset, 2, 0);
541         offset += 2;
542         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_e2e, tvb, offset, 2, 0);
543         offset += 2;
544         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_openseq, tvb, offset, 2, 0);
545         offset += 4;
546
547         flags[0] = '\0';
548         stroff = 0;
549         if (elp.cls1_svcparm[0] & 0x80) {
550             strcpy (&flags[stroff], "Class 1 Valid");
551             stroff += 13;
552             if (elp.cls1_svcparm[0] & 0x40) {
553                 strcpy (&flags[stroff], " | IMX");
554                 stroff += 6;
555             }
556             if (elp.cls1_svcparm[0] & 0x20) {
557                 strcpy (&flags[stroff], " | XPS");
558                 stroff += 6;
559             }
560             if (elp.cls1_svcparm[0] & 0x10) {
561                 strcpy (&flags[stroff], " | LKS");
562             }
563         }
564         else {
565             strcpy (&flags[0], "Class 1 Invalid");
566         }
567         
568         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls1_svcp, tvb, offset, 2,
569                                      tvb_get_ptr (tvb, offset, 2),
570                                      "Class 1 Svc Parameters: (%s)", flags);
571         offset += 2;
572         if (elp.cls1_svcparm[0] & 0x80) {
573             proto_tree_add_item (elp_tree, hf_swils_elp_cls1_rcvsz, tvb, offset, 2, 0);
574         }
575         offset += 2;
576
577         flags[0] = '\0';
578         if (elp.cls2_svcparm[0] & 0x80) {
579             strcpy (flags, "Class 2 Valid");
580
581             if (elp.cls2_svcparm[0] & 0x08) {
582                 strcpy (&flags[13], " | Seq Delivery");
583             }
584             else {
585                 strcpy (&flags[13], " | No Seq Delivery");
586             }
587         }
588         else {
589             strcpy (flags, "Class 2 Invld");
590         }
591         
592         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls2_svcp, tvb, offset, 2,
593                                      &elp.cls2_svcparm[0],
594                                      "Class 2 Svc Parameters: (%s)", flags);
595         offset += 2;
596         
597         if (elp.cls2_svcparm[0] & 0x80) {
598             proto_tree_add_item (elp_tree, hf_swils_elp_cls2_rcvsz, tvb, offset, 2, 0);
599         }
600         offset += 2;
601         
602         flags[0] = '\0';
603         if (elp.cls3_svcparm[0] & 0x80) {
604             strcpy (flags, "Class 3 Valid");
605
606             if (elp.cls3_svcparm[0] & 0x08) {
607                 strcpy (&flags[13], " | Seq Delivery");
608             }
609             else {
610                 strcpy (&flags[13], " | No Seq Delivery");
611             }
612         }
613         else {
614             strcpy (flags, "Class 3 Invld");
615         }
616         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls3_svcp, tvb, offset, 2,
617                                      &elp.cls3_svcparm[0],
618                                      "Class 3 Svc Parameters: (%s)", flags);
619         offset += 2;
620
621         if (elp.cls3_svcparm[0] & 0x80) {
622             proto_tree_add_item (elp_tree, hf_swils_elp_cls3_rcvsz, tvb, offset, 2, 0);
623         }
624         offset += 22;
625
626         proto_tree_add_string (elp_tree, hf_swils_elp_isl_fc_mode, tvb, offset, 2,
627                                val_to_str (elp.isl_flwctrl_mode, fcswils_elp_fc_val, "Vendor Unique"));
628         offset += 2;
629         proto_tree_add_item (elp_tree, hf_swils_elp_fcplen, tvb, offset, 2, 0);
630         offset += 2;
631         proto_tree_add_item (elp_tree, hf_swils_elp_b2bcredit, tvb, offset, 4, 0);
632         offset += 4;
633         proto_tree_add_item (elp_tree, hf_swils_elp_compat1, tvb, offset, 4, 0);
634         offset += 4;
635         proto_tree_add_item (elp_tree, hf_swils_elp_compat2, tvb, offset, 4, 0);
636         offset += 4;
637         proto_tree_add_item (elp_tree, hf_swils_elp_compat3, tvb, offset, 4, 0);
638         offset += 4;
639         proto_tree_add_item (elp_tree, hf_swils_elp_compat4, tvb, offset, 4, 0);
640     }
641
642 }
643
644 static void
645 dissect_swils_efp (tvbuff_t *tvb, proto_tree *efp_tree, guint8 isreq _U_)
646 {
647
648 /* Set up structures needed to add the protocol subtree and manage it */
649     proto_item *subti;
650     proto_tree *lrec_tree;
651     int num_listrec = 0,
652         offset = 0;
653     fcswils_efp efp;
654     fcswils_efp_listrec *lrec;
655     
656     tvb_memcpy (tvb, (guint8 *)&efp, offset, FC_SWILS_EFP_SIZE);
657     efp.payload_len = ntohs (efp.payload_len);
658     efp.listrec = (fcswils_efp_listrec *)tvb_get_ptr (tvb, FC_SWILS_EFP_SIZE,
659                                                       efp.payload_len - FC_SWILS_EFP_SIZE);
660     
661     if (efp_tree) {
662         offset += 2;
663         proto_tree_add_item (efp_tree, hf_swils_efp_payload_len, tvb, offset, 2, 0);
664         offset += 5;
665         proto_tree_add_item (efp_tree, hf_swils_efp_pswitch_pri, tvb,
666                              offset++, 1, 0);
667         proto_tree_add_string (efp_tree, hf_swils_efp_pswitch_name, tvb, offset,
668                                8, fcwwn_to_str (efp.pswitch_name));
669         offset += 8;
670
671         /* Add List Records now */
672         if (efp.reclen) {
673             num_listrec = (efp.payload_len - FC_SWILS_EFP_SIZE)/efp.reclen;
674         }
675         else {
676             num_listrec = 0;
677         }
678         
679         while (num_listrec--) {
680             lrec =  (fcswils_efp_listrec *)tvb_get_ptr (tvb, offset, efp.reclen);
681             if (lrec != NULL) {
682                 if (lrec->didrec.rec_type == FC_SWILS_LRECTYPE_DOMAIN) {
683                     subti = proto_tree_add_text (efp_tree, tvb, offset,
684                                                  (efp.payload_len - FC_SWILS_EFP_SIZE),
685                                                  "Domain ID Record");
686                     lrec_tree = proto_item_add_subtree (subti, ett_fcswils_efplist);
687                     proto_tree_add_item (lrec_tree, hf_swils_efp_dom_id, tvb, offset+1, 1, 0); 
688                     proto_tree_add_string (lrec_tree, hf_swils_efp_switch_name, tvb, offset+8, 8,
689                                            fcwwn_to_str (lrec->didrec.sname));
690                 }
691                 else if (lrec->didrec.rec_type == FC_SWILS_LRECTYPE_MCAST) {
692                     subti = proto_tree_add_text (efp_tree, tvb, offset,
693                                                  (efp.payload_len - FC_SWILS_EFP_SIZE),
694                                                  "Multicast ID Record");
695                     lrec_tree = proto_item_add_subtree (subti, ett_fcswils_efplist);
696                     proto_tree_add_item (lrec_tree, hf_swils_efp_mcast_grpno, tvb, offset+1, 1, 0);  
697                 }
698                 offset += efp.reclen;
699             }
700         }
701     }
702 }
703
704 static void
705 dissect_swils_dia (tvbuff_t *tvb, proto_tree *dia_tree, guint8 isreq _U_)
706 {
707     /* Set up structures needed to add the protocol subtree and manage it */
708     int offset = 0;
709
710     if (dia_tree) {
711         proto_tree_add_string (dia_tree, hf_swils_dia_switch_name, tvb, offset+4,
712                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
713     }
714 }
715
716 static void
717 dissect_swils_rdi (tvbuff_t *tvb, proto_tree *rdi_tree, guint8 isreq)
718 {
719     /* Set up structures needed to add the protocol subtree and manage it */
720     int offset = 0;
721     int i, plen, numrec;
722     
723     if (rdi_tree) {
724         plen = tvb_get_ntohs (tvb, offset+2);
725         
726         proto_tree_add_item (rdi_tree, hf_swils_rdi_payload_len, tvb, offset+2, 2, 0);
727         proto_tree_add_string (rdi_tree, hf_swils_rdi_req_sname, tvb, offset+4,
728                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
729
730         /* 12 is the length of the initial header and 4 is the size of each
731          * domain request record.
732          */
733         numrec = (plen - 12)/4;
734         offset = 12;
735         for (i = 0; i < numrec; i++) {
736             if (isreq) {
737                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
738                                      "Requested Domain ID: %d",
739                                      tvb_get_guint8 (tvb, offset+3));
740             }
741             else {
742                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
743                                      "Granted Domain ID: %d",
744                                      tvb_get_guint8 (tvb, offset+3));
745             }
746             offset += 4;
747         }
748     }
749 }
750
751 static void
752 dissect_swils_fspf_hdr (tvbuff_t *tvb, proto_tree *tree, int offset)
753 {
754     proto_item *subti;
755     proto_tree *fspfh_tree;
756     
757     if (tree) {
758         /* 20 is the size of FSPF header */
759         subti = proto_tree_add_text (tree, tvb, offset, 20, "FSPF Header");
760         fspfh_tree = proto_item_add_subtree (subti, ett_fcswils_fspfhdr);
761
762         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_rev, tvb, offset+4,
763                              1, 0);
764         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_ar_num, tvb,
765                              offset+5, 1, 0);
766         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth_type, tvb,
767                              offset+6, 1, 0);
768         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_dom_id, tvb, offset+11,
769                              1, 0);
770         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth, tvb, offset+12,
771                              8, 0);
772     }
773 }
774
775 static void
776 dissect_swils_fspf_lsrechdr (tvbuff_t *tvb, proto_tree *tree, int offset)
777 {
778     proto_tree_add_item (tree, hf_swils_lsrh_lsr_type, tvb, offset, 1, 0);
779     proto_tree_add_text (tree, tvb, offset+2, 2, "LSR Age: %d secs",
780                          tvb_get_ntohs (tvb, offset+2));
781     proto_tree_add_text (tree, tvb, offset+4, 4, "Options : 0x%x",
782                          tvb_get_ntohl (tvb, offset+4));
783     proto_tree_add_item (tree, hf_swils_lsrh_lsid, tvb, offset+11, 1, 0);
784     proto_tree_add_item (tree, hf_swils_lsrh_adv_domid, tvb, offset+15, 1, 0);
785     proto_tree_add_item (tree, hf_swils_lsrh_ls_incid, tvb, offset+16, 4, 0);
786     proto_tree_add_text (tree, tvb, offset+20, 2, "Checksum: 0x%x",
787                          tvb_get_ntohs (tvb, offset+20));
788     proto_tree_add_text (tree, tvb, offset+22, 2, "LSR Length: %d",
789                          tvb_get_ntohs (tvb, offset+22));
790 }
791
792 static void
793 dissect_swils_fspf_ldrec (tvbuff_t *tvb, proto_tree *tree, int offset)
794 {
795     proto_tree_add_string (tree, hf_swils_ldrec_linkid, tvb, offset, 4,
796                            fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
797     proto_tree_add_item (tree, hf_swils_ldrec_out_pidx, tvb, offset+5, 3, 0);
798     proto_tree_add_item (tree, hf_swils_ldrec_nbr_pidx, tvb, offset+9, 3, 0);
799     proto_tree_add_item (tree, hf_swils_ldrec_link_type, tvb, offset+12, 1, 0);
800     proto_tree_add_item (tree, hf_swils_ldrec_link_cost, tvb, offset+14, 2, 0);
801 }
802
803 static void
804 dissect_swils_fspf_lsrec (tvbuff_t *tvb, proto_tree *tree, int offset,
805                           int num_lsrec)
806 {
807     int i, j, num_ldrec;
808     proto_item *subti1, *subti;
809     proto_tree *lsrec_tree, *ldrec_tree, *lsrechdr_tree;
810
811     if (tree) {
812         for (j = 0; j < num_lsrec; j++) {
813             num_ldrec = tvb_get_ntohs (tvb, offset+26); 
814             subti = proto_tree_add_text (tree, tvb, offset, (28+num_ldrec*16),
815                                          "Link State Record %d (Domain %d)", j,
816                                          tvb_get_guint8 (tvb, offset+15));
817             lsrec_tree = proto_item_add_subtree (subti, ett_fcswils_lsrec);
818         
819             subti = proto_tree_add_text (lsrec_tree, tvb, offset, 24,
820                                          "Link State Record Header");
821             lsrechdr_tree = proto_item_add_subtree (subti,
822                                                     ett_fcswils_lsrechdr); 
823         
824             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
825             proto_tree_add_text (tree, tvb, offset+26, 2, "Number of Links: %d",
826                                  num_ldrec);
827             offset += 28;
828         
829             for (i = 0; i < num_ldrec; i++) {
830                 subti1 = proto_tree_add_text (lsrec_tree, tvb, offset, 16,
831                                               "Link Descriptor %d "
832                                               "(Neighbor domain %d)", i,
833                                               tvb_get_guint8 (tvb, offset+3));
834                 ldrec_tree = proto_item_add_subtree (subti1, ett_fcswils_ldrec);
835                 dissect_swils_fspf_ldrec (tvb, ldrec_tree, offset);
836                 offset += 16;
837             }
838         }
839     }
840 }
841
842 static void
843 dissect_swils_hello (tvbuff_t *tvb, proto_tree *hlo_tree, guint8 isreq _U_)
844 {
845     /* Set up structures needed to add the protocol subtree and manage it */
846     int offset = 0;
847
848     if (hlo_tree) {
849         dissect_swils_fspf_hdr (tvb, hlo_tree, offset);
850
851         proto_tree_add_item (hlo_tree, hf_swils_hlo_options, tvb, offset+20, 4, 0);
852         proto_tree_add_item (hlo_tree, hf_swils_hlo_hloint, tvb, offset+24, 4, 0);
853         proto_tree_add_item (hlo_tree, hf_swils_hlo_deadint, tvb, offset+28, 4, 0);
854         proto_tree_add_item (hlo_tree, hf_swils_hlo_rcv_domid, tvb, offset+35, 1, 0);
855         proto_tree_add_item (hlo_tree, hf_swils_hlo_orig_pidx, tvb, offset+37, 3, 0);
856     }
857 }
858
859 static void
860 dissect_swils_lsupdate (tvbuff_t *tvb, proto_tree *lsu_tree, guint8 isreq _U_)
861 {
862     /* Set up structures needed to add the protocol subtree and manage it */
863     int offset = 0;
864     int num_lsrec;
865
866     if (lsu_tree) {
867         dissect_swils_fspf_hdr (tvb, lsu_tree, offset);
868
869         proto_tree_add_text (lsu_tree, tvb, offset+23, 1, "Flags : %s",
870                              val_to_str (tvb_get_guint8 (tvb, offset+23),
871                                          fc_swils_fspf_lsrflags_val, "0x%x"));
872         num_lsrec = tvb_get_ntohl (tvb, offset+24);
873
874         proto_tree_add_text (lsu_tree, tvb, offset+24, 4, "Num of LSRs: %d",
875                              num_lsrec);
876
877         offset = 28;
878         dissect_swils_fspf_lsrec (tvb, lsu_tree, offset, num_lsrec);
879     }
880 }
881
882 static void
883 dissect_swils_lsack (tvbuff_t *tvb, proto_tree *lsa_tree, guint8 isreq _U_)
884 {
885     /* Set up structures needed to add the protocol subtree and manage it */
886     int offset = 0;
887     int num_lsrechdr, i;
888     proto_item *subti;
889     proto_tree *lsrechdr_tree;
890
891     if (lsa_tree) {
892         dissect_swils_fspf_hdr (tvb, lsa_tree, offset);
893
894         proto_tree_add_text (lsa_tree, tvb, offset+23, 1, "Flags : %s",
895                              val_to_str (tvb_get_guint8 (tvb, offset+23),
896                                          fc_swils_fspf_lsrflags_val, "0x%x"));
897         num_lsrechdr = tvb_get_ntohl (tvb, offset+24);
898
899         proto_tree_add_text (lsa_tree, tvb, offset+24, 4, "Num of LSR Headers: %d",
900                              num_lsrechdr);
901
902         offset = 28;
903
904         for (i = 0; i < num_lsrechdr; i++) {
905             subti = proto_tree_add_text (lsa_tree, tvb, offset, 24,
906                                          "Link State Record Header (Domain %d)",
907                                          tvb_get_guint8 (tvb, offset+15));
908             lsrechdr_tree = proto_item_add_subtree (subti,
909                                                     ett_fcswils_lsrechdr); 
910             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
911             offset += 24;
912         }
913     }
914 }
915
916 static void
917 dissect_swils_rscn (tvbuff_t *tvb, proto_tree *rscn_tree, guint8 isreq)
918 {
919     /* Set up structures needed to add the protocol subtree and manage it */
920     int offset = 0;
921     proto_tree *dev_tree;
922     int addrfmt, evtype;
923     int numrec, i;
924     proto_item *subti;
925     
926     if (rscn_tree) {
927         if (!isreq)
928             return;
929         
930         evtype = tvb_get_guint8 (tvb, offset+4);
931         addrfmt = evtype & 0x0F;
932         evtype = evtype >> 4;
933
934         proto_tree_add_item (rscn_tree, hf_swils_rscn_evtype, tvb, offset+4,
935                              1, 0);
936         proto_tree_add_item (rscn_tree, hf_swils_rscn_addrfmt, tvb, offset+4,
937                              1, 0);
938         proto_tree_add_string (rscn_tree, hf_swils_rscn_affectedport, tvb,
939                                offset+5, 3, fc_to_str (tvb_get_ptr (tvb,
940                                                                     offset+5, 3)));
941         proto_tree_add_item (rscn_tree, hf_swils_rscn_detectfn, tvb,
942                              offset+8, 4, 0);
943         numrec = tvb_get_ntohl (tvb, offset+12);
944         
945         if (!tvb_bytes_exist (tvb, offset+16, FC_SWILS_RSCN_DEVENTRY_SIZE*numrec)) {
946             /* Some older devices do not include device entry information. */
947             return;
948         }
949         
950         proto_tree_add_text (rscn_tree, tvb, offset+12, 4, "Num Entries: %d",
951                              numrec);
952
953         offset = 16;
954         for (i = 0; i < numrec; i++) {
955             subti = proto_tree_add_text (rscn_tree, tvb, offset, 20,
956                                          "Device Entry %d", i);
957             dev_tree = proto_item_add_subtree (rscn_tree, ett_fcswils_rscn_dev);
958
959             proto_tree_add_item (dev_tree, hf_swils_rscn_portstate, tvb, offset, 1, 0);
960             proto_tree_add_string (dev_tree, hf_swils_rscn_portid, tvb, offset+1, 3,
961                                    fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
962             proto_tree_add_string (dev_tree, hf_swils_rscn_pwwn, tvb, offset+4, 8,
963                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
964             proto_tree_add_string (dev_tree, hf_swils_rscn_nwwn, tvb, offset+4, 8,
965                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
966             offset += 20;
967         }
968     }
969 }
970
971 /*
972  * Merge Request contains zoning objects organized in the following format:
973  *
974  * Zone Set Object
975  *      |
976  *      +---------------- Zone Object
977  *      |                      |
978  *      +--                    +---------------- Zone Member
979  *      |                      |                     |
980  *      +--                    +----                 +-----
981  *
982  * So the decoding of the zone merge request is based on this structure
983  */
984
985 static void
986 dissect_swils_zone_mbr (tvbuff_t *tvb, proto_tree *zmbr_tree, int offset)
987 {
988     int mbrlen = 4 + tvb_get_guint8 (tvb, offset+3);
989
990     proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrtype, tvb,
991                          offset, 1, 0);
992     proto_tree_add_text (zmbr_tree, tvb, offset+2, 1, "Flags: 0x%x",
993                          tvb_get_guint8 (tvb, offset+2));
994     proto_tree_add_text (zmbr_tree, tvb, offset+3, 1,
995                          "Identifier Length: %d",
996                          tvb_get_guint8 (tvb, offset+3));
997     switch (tvb_get_guint8 (tvb, offset)) {
998     case FC_SWILS_ZONEMBR_WWN:
999         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1000                                offset+4, 8,
1001                                fcwwn_to_str (tvb_get_ptr (tvb,
1002                                                           offset+4,
1003                                                           8)));
1004         break;
1005     case FC_SWILS_ZONEMBR_DP:
1006         proto_tree_add_string_format (zmbr_tree,
1007                                       hf_swils_zone_mbrid,
1008                                       tvb, offset+4, 4, " ",
1009                                       "0x%x",
1010                                       tvb_get_ntohl (tvb,
1011                                                      offset+4));
1012         break;
1013     case FC_SWILS_ZONEMBR_FCID:
1014         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1015                                offset+4, 4,
1016                                fc_to_str (tvb_get_ptr (tvb,
1017                                                        offset+5,
1018                                                        3)));
1019         break;
1020     case FC_SWILS_ZONEMBR_ALIAS:
1021         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1022                                offset+4,
1023                                tvb_get_guint8 (tvb, offset+3),
1024                                zonenm_to_str (tvb, offset+4));
1025         break;
1026     case FC_SWILS_ZONEMBR_WWN_LUN:
1027         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1028                                offset+4, 8,
1029                                fcwwn_to_str (tvb_get_ptr (tvb,
1030                                                           offset+4,
1031                                                           8)));
1032         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1033                              offset+12, 8, 0);
1034         break;
1035     case FC_SWILS_ZONEMBR_DP_LUN:
1036         proto_tree_add_string_format (zmbr_tree,
1037                                       hf_swils_zone_mbrid,
1038                                       tvb, offset+4, 4, " ",
1039                                       "0x%x",
1040                                       tvb_get_ntohl (tvb,
1041                                                      offset+4));
1042         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1043                              offset+8, 8, 0);
1044         break;
1045     case FC_SWILS_ZONEMBR_FCID_LUN:
1046         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1047                                offset+4, 4,
1048                                fc_to_str (tvb_get_ptr (tvb,
1049                                                        offset+5,
1050                                                        3)));
1051         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1052                              offset+8, 8, 0);
1053         break;
1054     default:
1055         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1056                                offset+4, mbrlen,
1057                                "Unknown member type format");
1058             
1059     }
1060 }
1061
1062 static void
1063 dissect_swils_zone_obj (tvbuff_t *tvb, proto_tree *zobj_tree, int offset)
1064 {
1065     proto_tree *zmbr_tree;
1066     int mbrlen, numrec, i, objtype;
1067     proto_item *subti;
1068
1069     objtype = tvb_get_guint8 (tvb, offset);
1070     
1071     proto_tree_add_item (zobj_tree, hf_swils_zone_objtype, tvb, offset,
1072                          1, 0);
1073     proto_tree_add_item (zobj_tree, hf_swils_zone_protocol, tvb,
1074                          offset+1, 1, 0);
1075     proto_tree_add_string (zobj_tree, hf_swils_zone_objname, tvb,
1076                            offset+4, ZONENAME_LEN (tvb, offset+4),
1077                            zonenm_to_str (tvb, offset+4));
1078
1079     numrec = tvb_get_ntohl (tvb, offset+4+ZONENAME_LEN (tvb, offset+4));
1080     proto_tree_add_text (zobj_tree, tvb,
1081                          offset+4+ZONENAME_LEN (tvb, offset+4), 4,
1082                          "Number of Zone Members: %d", numrec);
1083
1084     offset += 8 + ZONENAME_LEN (tvb, offset+4);
1085     for (i = 0; i < numrec; i++) {
1086         if (objtype == FC_SWILS_ZONEOBJ_ZONESET) {
1087             dissect_swils_zone_obj (tvb, zobj_tree, offset);
1088             offset += get_zoneobj_len (tvb, offset);
1089         }
1090         else {
1091             mbrlen = 4 + tvb_get_guint8 (tvb, offset+3);
1092             subti = proto_tree_add_text (zobj_tree, tvb, offset, mbrlen,
1093                                          "Zone Member %d", i);
1094             zmbr_tree = proto_item_add_subtree (zobj_tree,
1095                                                 ett_fcswils_zonembr);
1096             dissect_swils_zone_mbr (tvb, zmbr_tree, offset);
1097             offset += mbrlen;
1098         }
1099     }
1100 }
1101
1102 static void
1103 dissect_swils_mergereq (tvbuff_t *tvb, proto_tree *mr_tree, guint8 isreq)
1104 {
1105     /* Set up structures needed to add the protocol subtree and manage it */
1106     int offset = 0;
1107     proto_tree *zobjlist_tree, *zobj_tree;
1108     int numrec, i, zonesetlen, objlistlen, objlen;
1109     proto_item *subti;
1110
1111     if (mr_tree) {
1112         if (isreq) {
1113             /* zonesetlen is the size of the zoneset including the zone name */ 
1114             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1115             proto_tree_add_text (mr_tree, tvb, offset+2, 2,
1116                                  "Active ZoneSet Length: %d", zonesetlen);
1117
1118             if (zonesetlen) {
1119                 proto_tree_add_string (mr_tree, hf_swils_zone_activezonenm, tvb,
1120                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1121                                        zonenm_to_str (tvb, offset+4));
1122                 
1123                 /* objlistlen gives the size of the active zoneset object list */ 
1124                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1125                 /* Offset = start of the active zoneset zoning object list */
1126                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1127                 numrec = tvb_get_ntohl (tvb, offset);
1128                 
1129                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1130                                              "Active Zone Set");
1131                 zobjlist_tree = proto_item_add_subtree (subti,
1132                                                         ett_fcswils_zoneobjlist);
1133                 
1134                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1135                                      "Number of zoning objects: %d", numrec);
1136
1137                 offset += 4;
1138                 for (i = 0; i < numrec; i++) {
1139                     objlen = get_zoneobj_len (tvb, offset);
1140                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset+4,
1141                                                  objlen, "Zone Object %d", i);
1142                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1143                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1144                     offset += objlen;
1145                 }
1146             }
1147             else {
1148                 offset += 4;
1149             }
1150             
1151             zonesetlen = tvb_get_ntohl (tvb, offset);
1152             proto_tree_add_text (mr_tree, tvb, offset, 4,
1153                                  "Full Zone Set Length: %d", zonesetlen);
1154
1155             if (zonesetlen) {
1156                 objlistlen = zonesetlen;
1157                 /* Offset = start of the active zoneset zoning object list */
1158                 offset += 4;
1159                 numrec = tvb_get_ntohl (tvb, offset);
1160                 
1161                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1162                                              "Full Zone Set");
1163                 
1164                 zobjlist_tree = proto_item_add_subtree (subti,
1165                                                         ett_fcswils_zoneobjlist);
1166                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1167                                      "Number of zoning objects: %d", numrec);
1168                 offset += 4;
1169                 for (i = 0; i < numrec; i++) {
1170                     objlen = get_zoneobj_len (tvb, offset);
1171                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1172                                                  objlen, "Zone Object %d", i);
1173                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1174                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1175                     offset += objlen;
1176                 }
1177             }
1178         }
1179         else {
1180             proto_tree_add_item (mr_tree, hf_swils_zone_status, tvb,
1181                                  offset+5, 1, 0);
1182             proto_tree_add_item (mr_tree, hf_swils_zone_reason, tvb,
1183                                  offset+6, 1, 0);
1184             proto_tree_add_text (mr_tree, tvb, offset+7, 1,
1185                                  "Vendor Unique: 0x%x",
1186                                  tvb_get_guint8 (tvb, offset+7));
1187         }
1188     }
1189 }
1190
1191 static void
1192 dissect_swils_aca (tvbuff_t *tvb, proto_tree *aca_tree, guint8 isreq)
1193 {
1194     /* Set up structures needed to add the protocol subtree and manage it */
1195     int offset = 0;
1196     int numrec, plen, i;
1197
1198     if (aca_tree) {
1199         if (isreq) {
1200             plen = tvb_get_ntohs (tvb, offset+2);
1201             proto_tree_add_text (aca_tree, tvb, offset+2, 2,
1202                                  "Domain ID List Length: %d", plen);
1203             numrec = plen/4;
1204             offset = 4;
1205         
1206             for (i = 0; i < numrec; i++) {
1207                 proto_tree_add_uint_format (aca_tree, hf_swils_aca_domainid,
1208                                             tvb, offset+3, 1, 
1209                                             tvb_get_guint8 (tvb, offset+3),
1210                                             "Domain ID %d: %d", i,
1211                                             tvb_get_guint8 (tvb, offset+3));
1212                 offset += 4;
1213             }
1214         }
1215         else {
1216             proto_tree_add_item (aca_tree, hf_swils_zone_status, tvb,
1217                                  offset+5, 1, 0);
1218             proto_tree_add_item (aca_tree, hf_swils_zone_reason, tvb,
1219                                  offset+6, 1, 0);
1220             proto_tree_add_text (aca_tree, tvb, offset+7, 1,
1221                                  "Vendor Unique: 0x%x",
1222                                  tvb_get_guint8 (tvb, offset+7));
1223         }
1224     }
1225 }
1226
1227 static void
1228 dissect_swils_rca (tvbuff_t *tvb, proto_tree *rca_tree, guint8 isreq)
1229 {
1230     /* Set up structures needed to add the protocol subtree and manage it */
1231     int offset = 0;
1232
1233     if (rca_tree) {
1234         if (!isreq) {
1235             proto_tree_add_item (rca_tree, hf_swils_zone_status, tvb,
1236                                  offset+5, 1, 0);
1237             proto_tree_add_item (rca_tree, hf_swils_zone_reason, tvb,
1238                                  offset+6, 1, 0);
1239             proto_tree_add_text (rca_tree, tvb, offset+7, 1,
1240                                  "Vendor Unique: 0x%x",
1241                                  tvb_get_guint8 (tvb, offset+7));
1242         }
1243     }
1244 }
1245
1246 static void
1247 dissect_swils_sfc (tvbuff_t *tvb, proto_tree *sfc_tree, guint8 isreq)
1248 {
1249     /* Set up structures needed to add the protocol subtree and manage it */
1250     int offset = 0;
1251     proto_tree *zobjlist_tree, *zobj_tree;
1252     int numrec, i, zonesetlen, objlistlen, objlen;
1253     proto_item *subti;
1254
1255     if (sfc_tree) {
1256         if (isreq) {
1257             proto_tree_add_item (sfc_tree, hf_swils_sfc_opcode, tvb, offset+1, 1, 0);
1258
1259             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1260             proto_tree_add_text (sfc_tree, tvb, offset+2, 2,
1261                                  "ZoneSet Length: %d", zonesetlen);
1262
1263             if (zonesetlen) {
1264                 proto_tree_add_string (sfc_tree, hf_swils_sfc_zonenm, tvb,
1265                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1266                                        zonenm_to_str (tvb, offset+4));
1267                 
1268                 /* objlistlen gives the size of the active zoneset object list */ 
1269                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1270                 /* Offset = start of the active zoneset zoning object list */
1271                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1272                 numrec = tvb_get_ntohl (tvb, offset);
1273                 
1274                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1275                                              "Zone Set");
1276                 zobjlist_tree = proto_item_add_subtree (subti,
1277                                                         ett_fcswils_zoneobjlist);
1278                 
1279                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1280                                      "Number of zoning objects: %d", numrec);
1281
1282                 offset += 4;
1283                 for (i = 0; i < numrec; i++) {
1284                     objlen = get_zoneobj_len (tvb, offset);
1285                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1286                                                  objlen, "Zone Object %d", i);
1287                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1288                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1289                     offset += objlen;
1290                 }
1291             }
1292             else {
1293                 offset += 4;
1294             }
1295
1296             zonesetlen = tvb_get_ntohl (tvb, offset);
1297             proto_tree_add_text (sfc_tree, tvb, offset, 4,
1298                                  "Full Zone Set Length: %d", zonesetlen);
1299
1300             if (zonesetlen) {
1301                 objlistlen = zonesetlen;
1302                 /* Offset = start of the active zoneset zoning object list */
1303                 offset += 4;
1304                 numrec = tvb_get_ntohl (tvb, offset);
1305                 
1306                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1307                                              "Full Zone Set");
1308                 
1309                 zobjlist_tree = proto_item_add_subtree (subti,
1310                                                         ett_fcswils_zoneobjlist);
1311                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1312                                      "Number of zoning objects: %d", numrec);
1313                 offset += 4;
1314                 for (i = 0; i < numrec; i++) {
1315                     objlen = get_zoneobj_len (tvb, offset);
1316                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1317                                                  objlen, "Zone Object %d", i);
1318                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1319                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1320                     offset += objlen;
1321                 }
1322             }
1323         }
1324         else {
1325             proto_tree_add_item (sfc_tree, hf_swils_zone_status, tvb,
1326                                  offset+5, 1, 0);
1327             proto_tree_add_item (sfc_tree, hf_swils_zone_reason, tvb,
1328                                  offset+6, 1, 0);
1329             proto_tree_add_text (sfc_tree, tvb, offset+7, 1,
1330                                  "Vendor Unique: 0x%x",
1331                                  tvb_get_guint8 (tvb, offset+7));
1332         }
1333     }
1334 }
1335
1336 static void
1337 dissect_swils_ufc (tvbuff_t *tvb, proto_tree *ufc_tree, guint8 isreq)
1338 {
1339     /* Set up structures needed to add the protocol subtree and manage it */
1340     int offset = 0;
1341
1342     if (ufc_tree) {
1343         if (!isreq) {
1344             proto_tree_add_item (ufc_tree, hf_swils_zone_status, tvb,
1345                                  offset+5, 1, 0);
1346             proto_tree_add_item (ufc_tree, hf_swils_zone_reason, tvb,
1347                                  offset+6, 1, 0);
1348             proto_tree_add_text (ufc_tree, tvb, offset+7, 1,
1349                                  "Vendor Unique: 0x%x",
1350                                  tvb_get_guint8 (tvb, offset+7));
1351         }
1352     }
1353 }
1354
1355 static void
1356 dissect_swils_esc (tvbuff_t *tvb, proto_tree *esc_tree, guint8 isreq)
1357 {
1358     /* Set up structures needed to add the protocol subtree and manage it */
1359     int offset = 0;
1360     int i, numrec, plen;
1361     proto_tree *pdesc_tree;
1362     proto_item *subti;
1363
1364     if (esc_tree) {
1365         if (isreq) {
1366             plen = tvb_get_ntohs (tvb, offset+2);
1367             proto_tree_add_text (esc_tree, tvb, offset+2, 2,
1368                                  "Payload Length: %d", plen);
1369             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1370                                  offset+4, 8, 0);
1371             numrec = (plen - 12)/12;
1372             offset = 12;
1373
1374             for (i = 0; i < numrec; i++) {
1375                 subti = proto_tree_add_text (esc_tree, tvb, offset, 12,
1376                                              "Protocol Descriptor %d", i);
1377                 pdesc_tree = proto_item_add_subtree (subti,
1378                                                      ett_fcswils_esc_pdesc);
1379                 proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1380                                      offset, 8, 0);
1381                 proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1382                                      tvb, offset+10, 2, 0);
1383                 offset += 12;
1384             }
1385         }
1386         else {
1387             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1388                                  offset+4, 8, 0);
1389             subti = proto_tree_add_text (esc_tree, tvb, offset+12, 12,
1390                                          "Accepted Protocol Descriptor");
1391             pdesc_tree = proto_item_add_subtree (subti, ett_fcswils_esc_pdesc);
1392
1393             proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1394                                  offset+12, 8, 0);
1395             proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1396                                  tvb, offset+22, 2, 0);
1397         }
1398     }
1399 }
1400
1401 static void
1402 dissect_swils_drlir (tvbuff_t *tvb _U_, proto_tree *drlir_tree _U_,
1403                      guint8 isreq _U_)
1404 {
1405     /* Set up structures needed to add the protocol subtree and manage it */
1406     return;
1407 }
1408
1409 static void
1410 dissect_swils_swrjt (tvbuff_t *tvb, proto_tree *swrjt_tree)
1411 {
1412     /* Set up structures needed to add the protocol subtree and manage it */
1413     int offset = 0;
1414
1415     if (swrjt_tree) {
1416         proto_tree_add_item (swrjt_tree, hf_swils_rjt, tvb, offset+5, 1, 0);
1417         proto_tree_add_item (swrjt_tree, hf_swils_rjtdet, tvb, offset+6, 1, 0);
1418         proto_tree_add_item (swrjt_tree, hf_swils_rjtvendor, tvb, offset+7,
1419                              1, 0);
1420     }
1421 }
1422
1423 /* Code to actually dissect the packets */
1424 static void
1425 dissect_fcswils (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1426 {
1427     proto_item *ti = NULL;
1428     guint8 opcode,
1429         failed_opcode = 0;
1430     int offset = 0;
1431     conversation_t *conversation;
1432     fcswils_conv_data_t *cdata;
1433     fcswils_conv_key_t ckey, *req_key;
1434     proto_tree *swils_tree = NULL;
1435     guint8 isreq = FC_SWILS_REQ;
1436     tvbuff_t *next_tvb;
1437
1438     /* Make entries in Protocol column and Info column on summary display */
1439     if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
1440         col_set_str(pinfo->cinfo, COL_PROTOCOL, "SW_ILS");
1441
1442     /* decoding of this is done by each individual opcode handler */
1443     opcode = tvb_get_guint8 (tvb, 0);
1444     
1445     if (tree) {
1446         ti = proto_tree_add_protocol_format (tree, proto_fcswils, tvb, 0,
1447                                              tvb_length (tvb), "SW_ILS");
1448         swils_tree = proto_item_add_subtree (ti, ett_fcswils);
1449     }
1450
1451     /* Register conversation if this is not a response */
1452     if ((opcode != FC_SWILS_SWACC) && (opcode != FC_SWILS_SWRJT)) {
1453         conversation = find_conversation (&pinfo->src, &pinfo->dst,
1454                                           pinfo->ptype, pinfo->oxid,
1455                                           pinfo->rxid, NO_PORT2);
1456         if (!conversation) {
1457             conversation = conversation_new (&pinfo->src, &pinfo->dst,
1458                                              pinfo->ptype, pinfo->oxid,
1459                                              pinfo->rxid, NO_PORT2);
1460         }
1461     
1462         ckey.conv_idx = conversation->index;
1463         
1464         cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash,
1465                                                             &ckey);
1466         if (cdata) {
1467             /* Since we never free the memory used by an exchange, this maybe a
1468              * case of another request using the same exchange as a previous
1469              * req. 
1470              */
1471             cdata->opcode = opcode;
1472         }
1473         else {
1474             req_key = g_mem_chunk_alloc (fcswils_req_keys);
1475             req_key->conv_idx = conversation->index;
1476             
1477             cdata = g_mem_chunk_alloc (fcswils_req_vals);
1478             cdata->opcode = opcode;
1479             
1480             g_hash_table_insert (fcswils_req_hash, req_key, cdata);
1481         }
1482     }
1483     else {
1484         /* Opcode is ACC or RJT */
1485         conversation = find_conversation (&pinfo->src, &pinfo->dst,
1486                                           pinfo->ptype, pinfo->oxid,
1487                                           pinfo->rxid, NO_PORT2);
1488         isreq = FC_SWILS_RPLY;
1489         if (!conversation) {
1490             if (tree && (opcode == FC_SWILS_SWACC)) {
1491                 /* No record of what this accept is for. Can't decode */
1492                 proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1493                                      "No record of Exchg. Unable to decode SW_ACC");
1494                 return;
1495             }
1496         }
1497         else {
1498             ckey.conv_idx = conversation->index;
1499
1500             cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash, &ckey);
1501
1502             if (cdata != NULL) {
1503                 if (opcode == FC_SWILS_SWACC)
1504                     opcode = cdata->opcode;
1505                 else
1506                     failed_opcode = cdata->opcode;
1507             }
1508             
1509             if (tree) {
1510                 if ((cdata == NULL) && (opcode != FC_SWILS_SWRJT)) {
1511                     /* No record of what this accept is for. Can't decode */
1512                     proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1513                                          "No record of SW_ILS Req. Unable to decode SW_ACC");
1514                     return;
1515                 }
1516             }
1517         }
1518     }
1519
1520     if (check_col (pinfo->cinfo, COL_INFO)) {
1521         if (isreq == FC_SWILS_REQ) {
1522             col_add_str (pinfo->cinfo, COL_INFO,
1523                          val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1524         }
1525         else if (opcode == FC_SWILS_SWRJT) {
1526             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_RJT (%s)",
1527                           val_to_str (failed_opcode, fc_swils_opcode_key_val, "0x%x"));
1528         }
1529         else {
1530             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_ACC (%s)",
1531                           val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1532         }
1533     }
1534
1535     if (tree) {
1536         proto_tree_add_item (swils_tree, hf_swils_opcode, tvb, offset, 1, 0);
1537     }
1538
1539     switch (opcode) {
1540     case FC_SWILS_SWRJT:
1541         dissect_swils_swrjt (tvb, swils_tree);
1542         break;
1543     case FC_SWILS_ELP:
1544         dissect_swils_elp (tvb, swils_tree, isreq);
1545         break;
1546     case FC_SWILS_EFP:
1547         dissect_swils_efp (tvb, swils_tree, isreq);
1548         break;
1549     case FC_SWILS_DIA:
1550         dissect_swils_dia (tvb, swils_tree, isreq);
1551         break;
1552     case FC_SWILS_RDI:
1553         dissect_swils_rdi (tvb, swils_tree, isreq);
1554         break;
1555     case FC_SWILS_HLO:
1556         dissect_swils_hello (tvb, swils_tree, isreq);
1557         break;
1558     case FC_SWILS_LSU:
1559         dissect_swils_lsupdate (tvb, swils_tree, isreq);
1560         break;
1561     case FC_SWILS_LSA:
1562         dissect_swils_lsack (tvb, swils_tree, isreq);
1563         break;
1564     case FC_SWILS_BF:
1565     case FC_SWILS_RCF:
1566         /* Nothing to be displayed for these two commands */
1567         break;
1568     case FC_SWILS_RSCN:
1569         dissect_swils_rscn (tvb, swils_tree, isreq);
1570         break;
1571     case FC_SWILS_DRLIR:
1572         dissect_swils_drlir (tvb, swils_tree, isreq);
1573         break;
1574     case FC_SWILS_MR:
1575         dissect_swils_mergereq (tvb, swils_tree, isreq);
1576         break;
1577     case FC_SWILS_ACA:
1578         dissect_swils_aca (tvb, swils_tree, isreq);
1579         break;
1580     case FC_SWILS_RCA:
1581         dissect_swils_rca (tvb, swils_tree, isreq);
1582         break;
1583     case FC_SWILS_SFC:
1584         dissect_swils_sfc (tvb, swils_tree, isreq);
1585         break;
1586     case FC_SWILS_UFC:
1587         dissect_swils_ufc (tvb, swils_tree, isreq);
1588         break;
1589     case FC_SWILS_ESC:
1590         dissect_swils_esc (tvb, swils_tree, isreq);
1591         break;
1592     default:
1593         next_tvb = tvb_new_subset (tvb, offset+4, -1, -1);
1594         call_dissector (data_handle, next_tvb, pinfo, tree);
1595     }
1596
1597 }
1598
1599 /* Register the protocol with Ethereal */
1600
1601 /* this format is require because a script is used to build the C function
1602    that calls all the protocol registration.
1603 */
1604
1605 void
1606 proto_register_fcswils (void)
1607 {
1608 /* Setup list of header fields  See Section 1.6.1 for details*/
1609     static hf_register_info hf[] = {
1610         { &hf_swils_opcode,
1611           {"Cmd Code", "swils.opcode", FT_UINT8, BASE_HEX,
1612            VALS (fc_swils_opcode_key_val), 0x0, "", HFILL}},
1613         { &hf_swils_elp_rev,
1614           {"Revision", "swils.elp.rev", FT_UINT8, BASE_DEC, NULL,
1615            0x0, "", HFILL}},
1616         { &hf_swils_elp_flags,
1617           {"Flag", "swils.elp.flag", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL}},
1618         { &hf_swils_elp_r_a_tov,
1619           {"R_A_TOV", "swils.elp.ratov", FT_UINT32, BASE_DEC, NULL,
1620            0x0, "", HFILL}},
1621         { &hf_swils_elp_e_d_tov,
1622           {"E_D_TOV", "swils.elp.edtov", FT_UINT32, BASE_DEC, NULL, 0x0, "",
1623            HFILL}},
1624         { &hf_swils_elp_req_epn,
1625           {"Req Eport Name", "swils.elp.reqepn", FT_STRING, BASE_HEX, NULL, 0x0,
1626            "", HFILL}},
1627         { &hf_swils_elp_req_esn,
1628           {"Req Switch Name", "swils.elp.reqesn", FT_STRING, BASE_HEX, NULL, 0x0,
1629            "", HFILL}},
1630         { &hf_swils_elp_clsf_svcp,
1631           {"Class F Svc Param", "swils.elp.clsfp", FT_BYTES, BASE_NONE, NULL, 0x0,
1632            "", HFILL}},
1633         { &hf_swils_elp_clsf_rcvsz,
1634           {"Max Class F Frame Size", "swils.elp.clsfrsz", FT_UINT16, BASE_DEC,
1635            NULL, 0x0, "", HFILL}},
1636         { &hf_swils_elp_clsf_conseq,
1637           {"Class F Max Concurrent Seq", "swils.elp.clsfcs", FT_UINT16, BASE_DEC,
1638            NULL, 0x0, "", HFILL}},
1639         { &hf_swils_elp_clsf_e2e,
1640           {"Class F E2E Credit", "swils.elp.cfe2e", FT_UINT16, BASE_DEC, NULL,
1641            0x0, "", HFILL}},
1642         { &hf_swils_elp_clsf_openseq,
1643           {"Class F Max Open Seq", "swils.elp.oseq", FT_UINT16, BASE_DEC, NULL,
1644            0x0, "", HFILL}},
1645         { &hf_swils_elp_cls1_svcp,
1646           {"Class 1 Svc Param", "swils.elp.cls1p", FT_BYTES, BASE_NONE, NULL, 0x0,
1647            "", HFILL}},
1648         { &hf_swils_elp_cls1_rcvsz,
1649           {"Class 1 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1650            0x0, "", HFILL}},
1651         { &hf_swils_elp_cls2_svcp,
1652           {"Class 2 Svc Param", "swils.elp.cls2p", FT_BYTES, BASE_HEX, NULL, 0x0,
1653            "", HFILL}},
1654         { &hf_swils_elp_cls2_rcvsz,
1655           {"Class 2 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1656            0x0, "", HFILL}},
1657         { &hf_swils_elp_cls3_svcp,
1658           {"Class 3 Svc Param", "swils.elp.cls3p", FT_BYTES, BASE_HEX, NULL, 0x0,
1659            "", HFILL}},
1660         { &hf_swils_elp_cls3_rcvsz,
1661           {"Class 3 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1662            0x0, "", HFILL}},
1663         { &hf_swils_elp_isl_fc_mode,
1664           {"ISL Flow Ctrl Mode", "swils.elp.fcmode", FT_STRING, BASE_HEX, NULL,
1665            0x0, "", HFILL}},
1666         { &hf_swils_elp_fcplen,
1667           {"Flow Ctrl Param Len", "swils.elp.fcplen", FT_UINT16, BASE_DEC, NULL,
1668            0x0, "", HFILL}},
1669         { &hf_swils_elp_b2bcredit,
1670           {"B2B Credit", "swils.elp.b2b", FT_UINT32, BASE_DEC, NULL, 0x0, "",
1671            HFILL}},
1672         { &hf_swils_elp_compat1,
1673           {"Compatability Param 1", "swils.elp.compat1", FT_UINT32, BASE_DEC, NULL,
1674            0x0, "", HFILL}},
1675         { &hf_swils_elp_compat2,
1676           {"Compatability Param 2", "swils.elp.compat2", FT_UINT32, BASE_DEC, NULL,
1677            0x0, "", HFILL}},
1678         { &hf_swils_elp_compat3,
1679           {"Compatability Param 3", "swils.elp.compat3", FT_UINT32, BASE_DEC, NULL,
1680            0x0, "", HFILL}},
1681         { &hf_swils_elp_compat4,
1682           {"Compatability Param 4", "swils.elp.compat4", FT_UINT32, BASE_DEC, NULL,
1683            0x0, "", HFILL}},
1684         { &hf_swils_efp_rec_type,
1685           {"Record Type", "swils.efp.rectype", FT_UINT8, BASE_HEX,
1686            VALS (fcswils_rectype_val), 0x0, "", HFILL}},
1687         { &hf_swils_efp_dom_id,
1688           {"Domain ID", "swils.efp.domid", FT_UINT8, BASE_HEX, NULL, 0x0,
1689            "", HFILL}},
1690         { &hf_swils_efp_switch_name,
1691           {"Switch Name", "swils.efp.sname", FT_STRING, BASE_HEX, NULL, 0x0,
1692            "", HFILL}},
1693         { &hf_swils_efp_mcast_grpno,
1694           {"Mcast Grp#", "swils.efp.mcastno", FT_UINT8, BASE_HEX, NULL, 0x0,
1695            "", HFILL}},
1696         { &hf_swils_efp_alias_token,
1697           {"Alias Token", "swils.efp.aliastok", FT_BYTES, BASE_HEX, NULL, 0x0,
1698            "", HFILL}},
1699         { &hf_swils_efp_payload_len,
1700           {"Payload Len", "swils.efp.payloadlen", FT_UINT16, BASE_DEC, NULL, 0x0,
1701            "", HFILL}},
1702         { &hf_swils_efp_pswitch_pri,
1703           {"Principal Switch Priority", "swils.efp.psprio", FT_UINT8, BASE_DEC,
1704            NULL, 0x0, "", HFILL}},
1705         { &hf_swils_efp_pswitch_name,
1706           {"Principal Switch Name", "swils.efp.psname", FT_STRING, BASE_HEX, NULL,
1707            0x0, "", HFILL}},
1708         { &hf_swils_dia_switch_name,
1709           {"Switch Name", "swils.dia.sname", FT_STRING, BASE_HEX, NULL, 0x0,
1710            "", HFILL}},
1711         { &hf_swils_rdi_payload_len,
1712           {"Payload Len", "swils.rdi.len", FT_UINT16, BASE_DEC, NULL, 0x0, "",
1713            HFILL}},
1714         { &hf_swils_rdi_req_sname,
1715           {"Req Switch Name", "swils.rdi.reqsn", FT_STRING, BASE_HEX, NULL, 0x0,
1716            "", HFILL}},
1717         { &hf_swils_fspfh_cmd,
1718           {"Command: ", "swils.fspf.cmd", FT_UINT8, BASE_HEX, NULL, 0x0,
1719            "", HFILL}},
1720         { &hf_swils_fspfh_rev,
1721           {"Version", "swils.fspf.ver", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL}},
1722         { &hf_swils_fspfh_ar_num,
1723           {"AR Number", "swils.fspf.arnum", FT_UINT8, BASE_HEX, NULL, 0x0, "",
1724            HFILL}},
1725         { &hf_swils_fspfh_auth_type,
1726           {"Authentication Type", "swils.fspf.authtype", FT_UINT8, BASE_HEX, NULL,
1727            0x0, "", HFILL}},
1728         { &hf_swils_fspfh_dom_id,
1729           {"Originating Domain ID", "swils.fspf.origdomid", FT_UINT8, BASE_DEC,
1730            NULL, 0x0, "", HFILL}},
1731         { &hf_swils_fspfh_auth,
1732           {"Authentication", "swils.fspf.auth", FT_BYTES, BASE_HEX, NULL, 0x0,
1733            "", HFILL}},
1734         { &hf_swils_hlo_options,
1735           {"Options", "swils.hlo.options", FT_BYTES, BASE_HEX, NULL, 0x0,
1736            "", HFILL}},
1737         { &hf_swils_hlo_hloint,
1738           {"Hello Interval (secs)", "swils.hlo.hloint", FT_UINT32, BASE_DEC,
1739            NULL, 0x0, "", HFILL}},
1740         { &hf_swils_hlo_deadint,
1741           {"Dead Interval (secs)", "swils.hlo.deadint", FT_UINT32, BASE_DEC,
1742            NULL, 0x0, "", HFILL}},
1743         { &hf_swils_hlo_rcv_domid,
1744           {"Recipient Domain ID", "swils.hlo.rcvdomid", FT_UINT8, BASE_DEC,
1745            NULL, 0x0, "", HFILL}},
1746         { &hf_swils_hlo_orig_pidx,
1747           {"Originating Port Idx", "swils.hlo.origpidx", FT_UINT24, BASE_HEX,
1748            NULL, 0x0, "", HFILL}},
1749         { &hf_swils_lsrh_lsr_type,
1750           {"LSR Type", "swils.lsr.type", FT_UINT8, BASE_HEX,
1751            VALS (fc_swils_fspf_linkrec_val), 0x0, "", HFILL}},
1752         { &hf_swils_lsrh_lsid,
1753           {"Link State Id", "swils.ls.id", FT_UINT8, BASE_DEC, NULL, 0x0,
1754            "", HFILL}},
1755         { &hf_swils_lsrh_adv_domid,
1756           {"Advertising Domain Id", "swils.lsr.advdomid", FT_UINT8, BASE_DEC,
1757            NULL, 0x0, "", HFILL}},
1758         { &hf_swils_lsrh_ls_incid,
1759           {"LS Incarnation Number", "swils.lsr.incid", FT_UINT32, BASE_DEC,
1760            NULL, 0x0, "", HFILL}},
1761         { &hf_swils_ldrec_linkid,
1762           {"Link ID", "swils.ldr.linkid", FT_STRING, BASE_HEX, NULL, 0x0,
1763            "", HFILL}},
1764         { &hf_swils_ldrec_out_pidx,
1765           {"Output Port Idx", "swils.ldr.out_portidx", FT_UINT24, BASE_HEX, NULL,
1766            0x0, "", HFILL}},
1767         { &hf_swils_ldrec_nbr_pidx,
1768           {"Neighbor Port Idx", "swils.ldr.nbr_portidx", FT_UINT24, BASE_HEX,
1769            NULL, 0x0, "", HFILL}},
1770         { &hf_swils_ldrec_link_type,
1771           {"Link Type", "swils.ldr.linktype", FT_UINT8, BASE_HEX,
1772            VALS (fc_swils_link_type_val), 0x0, "", HFILL}},
1773         { &hf_swils_ldrec_link_cost,
1774           {"Link Cost", "swils.ldr.linkcost", FT_UINT16, BASE_DEC, NULL, 0x0,
1775            "", HFILL}},
1776         { &hf_swils_rscn_evtype,
1777           {"Event Type", "swils.rscn.evtype", FT_UINT8, BASE_DEC,
1778            VALS (fc_swils_rscn_portstate_val), 0xF0, "", HFILL}},
1779         { &hf_swils_rscn_addrfmt,
1780           {"Address Format", "swils.rscn.addrfmt", FT_UINT8, BASE_DEC, 
1781            VALS (fc_swils_rscn_addrfmt_val), 0x0F, "", HFILL}},
1782         { &hf_swils_rscn_affectedport,
1783           {"Affected Port ID", "swils.rscn.affectedport", FT_STRING, BASE_HEX,
1784            NULL, 0x0, "", HFILL}},
1785         { &hf_swils_rscn_detectfn,
1786           {"Detection Function", "swils.rscn.detectfn", FT_UINT32, BASE_HEX,
1787            VALS (fc_swils_rscn_detectfn_val), 0x0, "", HFILL}},
1788         { &hf_swils_rscn_portstate,
1789           {"Port State", "swils.rscn.portstate", FT_UINT8, BASE_HEX, NULL, 0x0,
1790            "", HFILL}},
1791         { &hf_swils_rscn_portid,
1792           {"Port Id", "swils.rscn.portid", FT_STRING, BASE_HEX, NULL, 0x0, "",
1793            HFILL}},
1794         { &hf_swils_rscn_pwwn,
1795           {"Port WWN", "swils.rscn.pwwn", FT_STRING, BASE_HEX, NULL, 0x0, "",
1796            HFILL}},
1797         { &hf_swils_rscn_nwwn,
1798           {"Node WWN", "swils.rscn.nwwn", FT_STRING, BASE_HEX, NULL, 0x0, "",
1799            HFILL}},
1800         { &hf_swils_esc_swvendorid,
1801           {"Switch Vendor ID", "swils.esc.swvendor", FT_STRING, BASE_HEX, NULL,
1802            0x0, "", HFILL}},
1803         { &hf_swils_esc_pdesc_vendorid,
1804           {"Vendor ID", "swils.esc.vendorid", FT_STRING, BASE_HEX, NULL, 0x0,
1805            "", HFILL}},
1806         { &hf_swils_esc_protocolid,
1807           {"Protocol ID", "swils.esc.protocol", FT_UINT16, BASE_HEX,
1808            VALS (fc_swils_esc_protocol_val), 0x0, "", HFILL}},
1809         { &hf_swils_zone_activezonenm,
1810           {"Active Zoneset Name", "swils.mr.activezonesetname", FT_STRING,
1811            BASE_HEX, NULL, 0x0, "", HFILL}},
1812         { &hf_swils_zone_objname,
1813           {"Zone Object Name", "swils.zone.zoneobjname", FT_STRING, BASE_HEX,
1814            NULL, 0x0, "", HFILL}},
1815         { &hf_swils_zone_objtype,
1816           {"Zone Object Type", "swils.zone.zoneobjtype", FT_UINT8, BASE_HEX,
1817            VALS (fc_swils_zoneobj_type_val), 0x0, "", HFILL}},
1818         { &hf_swils_zone_mbrtype,
1819           {"Zone Member Type", "swils.zone.mbrtype", FT_UINT8, BASE_HEX,
1820            VALS (fc_swils_zonembr_type_val), 0x0, "", HFILL}},
1821         { &hf_swils_zone_protocol,
1822           {"Zone Protocol", "swils.zone.protocol", FT_UINT8, BASE_HEX, NULL,
1823            0x0, "", HFILL}},
1824         { &hf_swils_zone_mbrid,
1825           {"Member Identifier", "swils.zone.mbrid", FT_STRING, BASE_HEX, NULL,
1826            0x0, "", HFILL}},
1827         { &hf_swils_zone_status,
1828           {"Zone Command Status", "swils.zone.status", FT_UINT8, BASE_HEX,
1829            VALS (fc_swils_mr_rsp_val), 0x0, "Applies to MR, ACA, RCA, SFC, UFC",
1830            HFILL}},
1831         { &hf_swils_zone_reason,
1832           {"Zone Command Reason Code", "swils.zone.reason", FT_UINT8, BASE_HEX,
1833            VALS (fc_swils_mr_reason_val), 0x0, "Applies to MR, ACA, RCA, SFC, UFC",
1834            HFILL}},
1835         { &hf_swils_aca_domainid,
1836           {"Known Domain ID", "swils.aca.domainid", FT_UINT8, BASE_HEX, NULL,
1837            0x0, "", HFILL}},
1838         { &hf_swils_sfc_opcode,
1839           {"Operation Request", "swils.sfc.opcode", FT_UINT8, BASE_HEX,
1840            VALS (fc_swils_sfc_op_val), 0x0, "", HFILL}},
1841         { &hf_swils_sfc_zonenm,
1842           {"Zone Set Name", "swils.sfc.zonename", FT_STRING, BASE_HEX, NULL,
1843            0x0, "", HFILL}},
1844         { &hf_swils_rjt,
1845           {"Reason Code", "swils.rjt.reason", FT_UINT8, BASE_HEX,
1846            VALS (fc_swils_rjt_val), 0x0, "", HFILL}},
1847         { &hf_swils_rjtdet,
1848           {"Reason Code Explanantion", "swils.rjt.reasonexpl", FT_UINT8,
1849            BASE_HEX, VALS (fc_swils_deterr_val), 0x0, "", HFILL}},
1850         { &hf_swils_rjtvendor,
1851           {"Vendor Unique Error Code", "swils.rjt.vendor", FT_UINT8, BASE_HEX,
1852            NULL, 0x0, "", HFILL}},
1853         { &hf_swils_zone_mbrid_lun,
1854           {"LUN", "swils.zone.lun", FT_BYTES, BASE_HEX, NULL, 0x0, "",
1855            HFILL}},
1856     };
1857
1858     /* Setup protocol subtree array */
1859     static gint *ett[] = {
1860         &ett_fcswils,
1861         &ett_fcswils_swacc,
1862         &ett_fcswils_swrjt,
1863         &ett_fcswils_elp,
1864         &ett_fcswils_efp,
1865         &ett_fcswils_efplist,
1866         &ett_fcswils_dia,
1867         &ett_fcswils_rdi,
1868         &ett_fcswils_fspfhdr,
1869         &ett_fcswils_hlo,
1870         &ett_fcswils_lsrec,
1871         &ett_fcswils_lsrechdr,
1872         &ett_fcswils_ldrec,
1873         &ett_fcswils_lsu,
1874         &ett_fcswils_lsa,
1875         &ett_fcswils_bf,
1876         &ett_fcswils_rcf,
1877         &ett_fcswils_rscn,
1878         &ett_fcswils_rscn_dev,
1879         &ett_fcswils_drlir,
1880         &ett_fcswils_mr,
1881         &ett_fcswils_zoneobjlist,
1882         &ett_fcswils_zoneobj,
1883         &ett_fcswils_zonembr,
1884         &ett_fcswils_aca,
1885         &ett_fcswils_rca,
1886         &ett_fcswils_sfc,
1887         &ett_fcswils_ufc,
1888         &ett_fcswils_esc,
1889         &ett_fcswils_esc_pdesc,
1890     };
1891
1892     /* Register the protocol name and description */
1893     proto_fcswils = proto_register_protocol("Fibre Channel SW_ILS", "FC-SWILS", "swils");
1894
1895     /* Required function calls to register the header fields and subtrees used */
1896     proto_register_field_array(proto_fcswils, hf, array_length(hf));
1897     proto_register_subtree_array(ett, array_length(ett));
1898     register_init_routine(&fcswils_init_protocol);
1899 }
1900
1901 /* If this dissector uses sub-dissector registration add a registration routine.
1902    This format is required because a script is used to find these routines and
1903    create the code that calls these routines.
1904 */
1905 void
1906 proto_reg_handoff_fcswils (void)
1907 {
1908     dissector_handle_t swils_handle;
1909
1910     swils_handle = create_dissector_handle (dissect_fcswils, proto_fcswils);
1911     dissector_add("fc.ftype", FC_FTYPE_SWILS, swils_handle);
1912
1913     data_handle = find_dissector ("data");
1914 }
1915
1916