89d1846671c8306ec0989b509170eb28a6503a4c
[obnox/wireshark/wip.git] / epan / dissectors / 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$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/packet.h>
45 #include <epan/emem.h>
46 #include <epan/conversation.h>
47 #include <epan/etypes.h>
48 #include "packet-scsi.h"
49 #include "packet-fc.h"
50 #include "packet-fcswils.h"
51 #include "packet-fcct.h"
52
53 /*
54  * See the FC-SW specifications.
55  */
56
57 #define FC_SWILS_RPLY               0x0
58 #define FC_SWILS_REQ                0x1
59 #define FC_SWILS_RSCN_DEVENTRY_SIZE 20
60
61 /* Zone name has the structure:
62  * name_len (1 byte), rsvd (3 bytes), name (m bytes), fill (n bytes)
63  * name_len excludes the 4 initial bytes before the name
64  */
65 #define ZONENAME_LEN(x, y)  (tvb_get_guint8(x, y)+4)
66
67 /* Initialize the protocol and registered fields */
68 static int proto_fcswils               = -1;
69 static int hf_swils_opcode             = -1;
70 static int hf_swils_elp_rev            = -1;
71 static int hf_swils_elp_flags          = -1;
72 static int hf_swils_elp_r_a_tov        = -1;
73 static int hf_swils_elp_e_d_tov        = -1;
74 static int hf_swils_elp_req_epn        = -1;
75 static int hf_swils_elp_req_esn        = -1;
76 static int hf_swils_elp_clsf_svcp      = -1;
77 static int hf_swils_elp_clsf_rcvsz     = -1;
78 static int hf_swils_elp_clsf_conseq    = -1;
79 static int hf_swils_elp_clsf_e2e       = -1;
80 static int hf_swils_elp_clsf_openseq   = -1;
81 static int hf_swils_elp_cls1_svcp      = -1;
82 static int hf_swils_elp_cls1_rcvsz     = -1;
83 static int hf_swils_elp_cls2_svcp      = -1;
84 static int hf_swils_elp_cls2_rcvsz     = -1;
85 static int hf_swils_elp_cls3_svcp      = -1;
86 static int hf_swils_elp_cls3_rcvsz     = -1;
87 static int hf_swils_elp_isl_fc_mode    = -1;
88 static int hf_swils_elp_fcplen         = -1;
89 static int hf_swils_elp_b2bcredit      = -1;
90 static int hf_swils_elp_compat1        = -1;
91 static int hf_swils_elp_compat2        = -1;
92 static int hf_swils_elp_compat3        = -1;
93 static int hf_swils_elp_compat4        = -1;
94 static int hf_swils_efp_rec_type       = -1;
95 static int hf_swils_efp_dom_id         = -1;
96 static int hf_swils_efp_switch_name    = -1;
97 static int hf_swils_efp_mcast_grpno    = -1;
98 static int hf_swils_efp_alias_token    = -1;
99 static int hf_swils_efp_record_len     = -1;
100 static int hf_swils_efp_payload_len    = -1;
101 static int hf_swils_efp_pswitch_pri    = -1;
102 static int hf_swils_efp_pswitch_name   = -1;
103 static int hf_swils_dia_switch_name    = -1;
104 static int hf_swils_rdi_payload_len    = -1;
105 static int hf_swils_rdi_req_sname      = -1;
106 static int hf_swils_fspfh_cmd          = -1;
107 static int hf_swils_fspfh_rev          = -1;
108 static int hf_swils_fspfh_ar_num       = -1;
109 static int hf_swils_fspfh_auth_type    = -1;
110 static int hf_swils_fspfh_dom_id       = -1;
111 static int hf_swils_fspfh_auth         = -1;
112 static int hf_swils_hlo_options        = -1;
113 static int hf_swils_hlo_hloint         = -1;
114 static int hf_swils_hlo_deadint        = -1;
115 static int hf_swils_hlo_rcv_domid      = -1;
116 static int hf_swils_hlo_orig_pidx      = -1;
117 static int hf_swils_ldrec_linkid       = -1;
118 static int hf_swils_ldrec_out_pidx     = -1;
119 static int hf_swils_ldrec_nbr_pidx     = -1;
120 static int hf_swils_ldrec_link_type    = -1;
121 static int hf_swils_ldrec_link_cost    = -1;
122 static int hf_swils_lsrh_lsr_type      = -1;
123 static int hf_swils_lsrh_lsid          = -1;
124 static int hf_swils_lsrh_adv_domid     = -1;
125 static int hf_swils_lsrh_ls_incid      = -1;
126 static int hf_swils_esc_pdesc_vendorid = -1;
127 static int hf_swils_esc_swvendorid     = -1;
128 static int hf_swils_esc_protocolid     = -1;
129 static int hf_swils_rscn_evtype        = -1;
130 static int hf_swils_rscn_addrfmt       = -1;
131 static int hf_swils_rscn_detectfn      = -1;
132 static int hf_swils_rscn_affectedport  = -1;
133 static int hf_swils_rscn_portstate     = -1;
134 static int hf_swils_rscn_portid        = -1;
135 static int hf_swils_rscn_pwwn          = -1;
136 static int hf_swils_rscn_nwwn          = -1;
137 static int hf_swils_zone_activezonenm  = -1;
138 static int hf_swils_zone_objname       = -1;
139 static int hf_swils_zone_objtype       = -1;
140 static int hf_swils_zone_mbrtype       = -1;
141 static int hf_swils_zone_protocol      = -1;
142 static int hf_swils_zone_mbrid         = -1;
143 static int hf_swils_zone_status        = -1;
144 static int hf_swils_zone_reason        = -1;
145 static int hf_swils_aca_domainid       = -1;
146 static int hf_swils_sfc_opcode         = -1;
147 static int hf_swils_sfc_zonenm         = -1;
148 static int hf_swils_rjt                = -1;
149 static int hf_swils_rjtdet             = -1;
150 static int hf_swils_rjtvendor          = -1;
151 static int hf_swils_zone_mbrid_lun     = -1;
152 static int hf_swils_ess_rev = -1;
153 static int hf_swils_ess_len = -1;
154 static int hf_swils_ess_numobj = -1;
155 static int hf_swils_interconnect_list_len = -1;
156 static int hf_swils_ess_vendorname = -1;
157 static int hf_swils_ess_modelname = -1;
158 static int hf_swils_ess_relcode = -1;
159 static int hf_swils_ess_vendorspecific = -1;
160 static int hf_swils_ess_cap_type = -1;
161 static int hf_swils_ess_cap_subtype = -1;
162 static int hf_swils_ess_cap_numentries = -1;
163 static int hf_swils_ess_cap_svc = -1;
164 static int hf_swils_ess_dns_obj0h = -1;
165 static int hf_swils_ess_dns_obj1h = -1;
166 static int hf_swils_ess_dns_obj2h = -1;
167 static int hf_swils_ess_dns_obj3h = -1;
168 static int hf_swils_ess_dns_zlacc = -1;
169 static int hf_swils_ess_dns_vendor = -1;
170 static int hf_swils_ess_fctlr_rscn = -1;
171 static int hf_swils_ess_fctlr_vendor = -1;
172 static int hf_swils_ess_fcs_basic = -1;
173 static int hf_swils_ess_fcs_platform = -1;
174 static int hf_swils_ess_fcs_topology = -1;
175 static int hf_swils_ess_fcs_enhanced = -1;
176 static int hf_swils_ess_fzs_enh_supp = -1;
177 static int hf_swils_ess_fzs_enh_ena = -1;
178 static int hf_swils_ess_fzs_mr = -1;
179 static int hf_swils_ess_fzs_zsdb_supp = -1;
180 static int hf_swils_ess_fzs_zsdb_ena = -1;
181 static int hf_swils_ess_fzs_adc_supp = -1;
182 static int hf_swils_ess_fzs_hardzone = -1;
183 static int hf_swils_mrra_rev = -1;
184 static int hf_swils_mrra_size = -1;
185 static int hf_swils_mrra_vendorid = -1;
186 static int hf_swils_mrra_reply = -1;
187 static int hf_swils_mrra_reply_size = -1;
188 static int hf_swils_mrra_waittime = -1;
189 static int hf_swils_ess_cap_t10 = -1;
190 static int hf_swils_ess_cap_vendorobj = -1;
191 static int hf_swils_ess_fzs_defzone = -1;
192 static int hf_swils_ess_cap_len = -1;
193 static int hf_swils_mrra_vendorinfo = -1;
194
195
196 /* Initialize the subtree pointers */
197 static gint ett_fcswils             = -1;
198 static gint ett_fcswils_swacc       = -1;
199 static gint ett_fcswils_swrjt       = -1;
200 static gint ett_fcswils_elp         = -1;
201 static gint ett_fcswils_efp         = -1;
202 static gint ett_fcswils_efplist     = -1;
203 static gint ett_fcswils_dia         = -1;
204 static gint ett_fcswils_rdi         = -1;
205 static gint ett_fcswils_fspfhdr     = -1;
206 static gint ett_fcswils_hlo         = -1;
207 static gint ett_fcswils_lsrec       = -1;
208 static gint ett_fcswils_lsrechdr    = -1;
209 static gint ett_fcswils_ldrec       = -1;
210 static gint ett_fcswils_lsu         = -1;
211 static gint ett_fcswils_lsa         = -1;
212 static gint ett_fcswils_bf          = -1;
213 static gint ett_fcswils_rcf         = -1;
214 static gint ett_fcswils_rscn        = -1;
215 static gint ett_fcswils_rscn_dev    = -1;
216 static gint ett_fcswils_drlir       = -1;
217 static gint ett_fcswils_mr          = -1;
218 static gint ett_fcswils_zoneobjlist = -1;
219 static gint ett_fcswils_zoneobj     = -1;
220 static gint ett_fcswils_zonembr     = -1;
221 static gint ett_fcswils_aca         = -1;
222 static gint ett_fcswils_rca         = -1;
223 static gint ett_fcswils_sfc         = -1;
224 static gint ett_fcswils_ufc         = -1;
225 static gint ett_fcswils_esc         = -1;
226 static gint ett_fcswils_esc_pdesc   = -1;
227 static gint ett_fcswils_ieinfo      = -1;
228 static gint ett_fcswils_capinfo     = -1;
229
230 static const value_string fc_swils_opcode_key_val[] = {
231     {FC_SWILS_SWRJT  , "SW_RJT"},
232     {FC_SWILS_SWACC  , "SW_ACC"},
233     {FC_SWILS_ELP    , "ELP"},
234     {FC_SWILS_EFP    , "EFP"},
235     {FC_SWILS_DIA    , "DIA"},
236     {FC_SWILS_RDI    , "RDI"},
237     {FC_SWILS_HLO    , "HLO"},
238     {FC_SWILS_LSU    , "LSU"},
239     {FC_SWILS_LSA    , "LSA"},
240     {FC_SWILS_BF     , "BF"},
241     {FC_SWILS_RCF    , "RCF"},
242     {FC_SWILS_RSCN   , "SW_RSCN"},
243     {FC_SWILS_DRLIR  , "DRLIR"},
244     {FC_SWILS_DSCN   , "DSCN"},
245     {FC_SWILS_LOOPD  , "LOOPD"},
246     {FC_SWILS_MR     , "MR"},
247     {FC_SWILS_ACA    , "ACA"},
248     {FC_SWILS_RCA    , "RCA"},
249     {FC_SWILS_SFC    , "SFC"},
250     {FC_SWILS_UFC    , "UFC"},
251     {FC_SWILS_ESC    , "ESC"},
252     {FC_SWILS_ESS    , "ESS"},
253     {FC_SWILS_MRRA   , "MRRA"},
254     {FC_SWILS_AUTH_ILS, "AUTH_ILS"},
255     {0, NULL},
256 };
257
258 static const value_string fc_swils_rjt_val [] = {
259     {FC_SWILS_RJT_INVCODE   , "Invalid Cmd Code"},
260     {FC_SWILS_RJT_INVVER    , "Invalid Revision"},
261     {FC_SWILS_RJT_LOGERR    , "Logical Error"},
262     {FC_SWILS_RJT_INVSIZE   , "Invalid Size"},
263     {FC_SWILS_RJT_LOGBSY    , "Logical Busy"},
264     {FC_SWILS_RJT_PROTERR   , "Protocol Error"},
265     {FC_SWILS_RJT_GENFAIL   , "Unable to Perform"},
266     {FC_SWILS_RJT_CMDNOTSUPP, "Unsupported Cmd"},
267     {FC_SWILS_RJT_VENDUNIQ  , "Vendor Unique Err"},
268     {0, NULL},
269 };
270
271 static const value_string fc_swils_deterr_val [] = {
272     {FC_SWILS_RJT_NODET ,      "No Additional Details"},
273     {FC_SWILS_RJT_CLSF_ERR ,   "Class F Svc Param Err"},
274     {FC_SWILS_RJT_CLSN_ERR ,   "Class N Svc Param Err"},
275     {FC_SWILS_RJT_INVFC_CODE , "Unknown Flow Ctrl Code"},
276     {FC_SWILS_RJT_INVFC_PARM , "Invalid Flow Ctrl Parm"},
277     {FC_SWILS_RJT_INV_PNAME ,  "Invalid Port Name"},
278     {FC_SWILS_RJT_INV_SNAME ,  "Invalid Switch Name"},
279     {FC_SWILS_RJT_TOV_MSMTCH , "R_A_/E_D_TOV Mismatch"},
280     {FC_SWILS_RJT_INV_DIDLST,  "Invalid Domain ID List"},
281     {FC_SWILS_RJT_CMD_INPROG , "Cmd Already in Progress"},
282     {FC_SWILS_RJT_OORSRC ,     "Insufficient Resources"},
283     {FC_SWILS_RJT_NO_DID ,     "Domain ID Unavailable"},
284     {FC_SWILS_RJT_INV_DID,     "Invalid Domain ID"},
285     {FC_SWILS_RJT_NO_REQ ,     "Request Not Supported"},
286     {FC_SWILS_RJT_NOLNK_PARM , "Link Parm Not Estd."},
287     {FC_SWILS_RJT_NO_REQDID ,  "Group of Domain IDs Unavail"},
288     {FC_SWILS_RJT_EP_ISOL ,    "E_Port Isolated"},
289     {0, NULL}
290 };
291
292 static const value_string fcswils_elp_fc_val[] = {
293     {FC_SWILS_ELP_FC_VENDOR, "Vendor Unique"},
294     {FC_SWILS_ELP_FC_RRDY,   "R_RDY Flow Ctrl"},
295     {0, NULL},
296 };
297
298 static const value_string fcswils_rectype_val[] = {
299     {FC_SWILS_LRECTYPE_DOMAIN, "Domain ID Record"},
300     {FC_SWILS_LRECTYPE_MCAST, "Multicast ID Record"},
301     {0, NULL},
302 };
303
304 static const value_string fc_swils_link_type_val[] = {
305     {0x01, "P2P Link"},
306     {0xF0, "Vendor Specific"},
307     {0xF1, "Vendor Specific"},
308     {0xF2, "Vendor Specific"},
309     {0xF3, "Vendor Specific"},
310     {0xF4, "Vendor Specific"},
311     {0xF5, "Vendor Specific"},
312     {0xF6, "Vendor Specific"},
313     {0xF7, "Vendor Specific"},
314     {0xF8, "Vendor Specific"},
315     {0xF9, "Vendor Specific"},
316     {0xFA, "Vendor Specific"},
317     {0xFB, "Vendor Specific"},
318     {0xFC, "Vendor Specific"},
319     {0xFD, "Vendor Specific"},
320     {0xFE, "Vendor Specific"},
321     {0xFF, "Vendor Specific"},
322     {0, NULL},
323 };
324
325 static const value_string fc_swils_fspf_linkrec_val[] = {
326     {FC_SWILS_LSR_SLR, "Switch Link Record"},
327     {FC_SWILS_LSR_ARS, "AR Summary Record"},
328     {0, NULL},
329 };
330
331 static const value_string fc_swils_fspf_lsrflags_val[] = {
332     {0x0, "LSR is for a Topology Update"},
333     {0x1, "LSR is for Initial DB Sync | Not the last seq in DB sync"},
334     {0x2, "Last Seq in DB Sync. LSU has no LSRs"},
335     {0x3, "LSR is for Initial DB Sync | Last Seq in DB Sync"},
336     {0, NULL},
337 };
338
339 static const value_string fc_swils_rscn_portstate_val[] = {
340     {0, "No Additional Info"},
341     {1, "Port is online"},
342     {2, "Port is offline"},
343     {0, NULL},
344 };
345
346 static const value_string fc_swils_rscn_addrfmt_val[] = {
347     {0, "Port Addr Format"},
348     {1, "Area Addr Format"},
349     {2, "Domain Addr Format"},
350     {3, "Fabric Addr Format"},
351     {0, NULL},
352 };
353
354 static const value_string fc_swils_rscn_detectfn_val[] = {
355     {1, "Fabric Detected"},
356     {2, "N_Port Detected"},
357     {0, NULL},
358 };
359
360 static const value_string fc_swils_esc_protocol_val[] = {
361     {0, "Reserved"},
362     {1, "FSPF-Backbone Protocol"},
363     {2, "FSPF Protocol"},
364     {0, NULL},
365 };
366
367 static const value_string fc_swils_zoneobj_type_val[] = {
368     {0, "Reserved"},
369     {FC_SWILS_ZONEOBJ_ZONESET  , "Zone Set"},
370     {FC_SWILS_ZONEOBJ_ZONE     , "Zone"},
371     {FC_SWILS_ZONEOBJ_ZONEALIAS, "Zone Alias"},
372     {0, NULL},
373 };
374
375 const value_string fc_swils_zonembr_type_val[] = {
376     {0, "Reserved"},
377     {FC_SWILS_ZONEMBR_WWN, "WWN"},
378     {FC_SWILS_ZONEMBR_DP, "Domain/Physical Port (0x00ddpppp)"},
379     {FC_SWILS_ZONEMBR_FCID, "FC Address"},
380     {FC_SWILS_ZONEMBR_ALIAS, "Zone Alias"},
381     {FC_SWILS_ZONEMBR_WWN_LUN, "WWN+LUN"},
382     {FC_SWILS_ZONEMBR_DP_LUN, "Domain/Physical Port+LUN"},
383     {FC_SWILS_ZONEMBR_FCID_LUN, "FCID+LUN"},
384     {0, NULL},
385 };
386
387 static const value_string fc_swils_mr_rsp_val[] = {
388     {0, "Successful"},
389     {1, "Fabric Busy"},
390     {2, "Failed"},
391     {0, NULL},
392 };
393
394 static const value_string fc_swils_mr_reason_val[] = {
395     {0x0, "No Reason"},
396     {0x1, "Invalid Data Length"},
397     {0x2, "Unsupported Command"},
398     {0x3, "Reserved"},
399     {0x4, "Not Authorized"},
400     {0x5, "Invalid Request"},
401     {0x6, "Fabric Changing"},
402     {0x7, "Update Not Staged"},
403     {0x8, "Invalid Zone Set Format"},
404     {0x9, "Invalid Data"},
405     {0xA, "Cannot Merge"},
406     {0, NULL},
407 };
408
409 static const value_string fc_swils_sfc_op_val[] = {
410     {0, "Reserved"},
411     {1, "Reserved"},
412     {2, "Reserved"},
413     {3, "Activate Zone Set"},
414     {4, "Deactivate Zone Set"},
415     {0, NULL},
416 };
417
418 typedef struct _zonename {
419     guint32 namelen:8,
420             rsvd:24;
421     gchar *name;
422     gchar *pad;
423 } zonename_t;
424
425 typedef struct _fcswils_conv_key {
426     guint32 conv_idx;
427 } fcswils_conv_key_t;
428
429 typedef struct _fcswils_conv_data {
430     guint32 opcode;
431 } fcswils_conv_data_t;
432
433 GHashTable *fcswils_req_hash = NULL;
434
435 /* list of commands for each commandset */
436 typedef void (*fcswils_dissector_t)(tvbuff_t *tvb, proto_tree *tree, guint8 isreq);
437
438 typedef struct _fcswils_func_table_t {
439     fcswils_dissector_t func;
440 } fcswils_func_table_t;
441
442 static dissector_handle_t data_handle, fcsp_handle;
443
444 static gint get_zoneobj_len (tvbuff_t *tvb, gint offset);
445
446 /*
447  * Hash Functions
448  */
449 static gint
450 fcswils_equal(gconstpointer v, gconstpointer w)
451 {
452     const fcswils_conv_key_t *v1 = v;
453     const fcswils_conv_key_t *v2 = w;
454
455     return (v1->conv_idx == v2->conv_idx);
456 }
457
458 static guint
459 fcswils_hash (gconstpointer v)
460 {
461     const fcswils_conv_key_t *key = v;
462     guint val;
463
464     val = key->conv_idx;
465
466     return val;
467 }
468
469 /*
470  * Protocol initialization
471  */
472 static void
473 fcswils_init_protocol(void)
474 {
475     if (fcswils_req_hash)
476         g_hash_table_destroy (fcswils_req_hash);
477
478     fcswils_req_hash = g_hash_table_new(fcswils_hash, fcswils_equal);
479
480 }
481
482 static guint8 *
483 zonenm_to_str (tvbuff_t *tvb, gint offset)
484 {
485     int len = tvb_get_guint8 (tvb, offset);
486     return tvb_get_ephemeral_string (tvb, offset+4, len);
487 }
488
489 /* Offset points to the start of the zone object */
490 static gint
491 get_zoneobj_len (tvbuff_t *tvb, gint offset)
492 {
493     gint numrec, numrec1;
494     guint8 objtype;
495     gint i, j, len;
496
497     /* zone object structure is:
498      * type (1 byte), protocol (1 byte), rsvd (2 bytes), obj name (x bytes),
499      * num of zone mbrs (4 bytes ), list of zone members (each member if of
500      * variable length).
501      *
502      * zone member structure is:
503      * type (1 byte), rsvd (1 byte), flags (1 byte), id_len (1 byte),
504      * id (id_len bytes)
505      */
506     objtype = tvb_get_guint8 (tvb, offset);
507     len = 4 + ZONENAME_LEN (tvb, offset+4); /* length upto num_of_mbrs field */
508     numrec = tvb_get_ntohl (tvb, offset+len); /* gets us num of zone mbrs */
509
510     len += 4;                   /* + num_mbrs */
511     for (i = 0; i < numrec; i++) {
512         if (objtype == FC_SWILS_ZONEOBJ_ZONESET) {
513             len += 4 + ZONENAME_LEN (tvb, offset+4+len); /* length upto num_of_mbrs field */
514             numrec1 = tvb_get_ntohl (tvb, offset+len);
515
516             len += 4;
517             for (j = 0; j < numrec1; j++) {
518                 len += 4 + tvb_get_guint8 (tvb, offset+3+len);
519             }
520         }
521         else {
522             len += 4 + tvb_get_guint8 (tvb, offset+3+len);
523         }
524     }
525
526     return len;
527 }
528
529 #define MAX_INTERCONNECT_ELEMENT_INFO_LEN  252
530 static int
531 dissect_swils_interconnect_element_info (tvbuff_t *tvb, proto_tree *tree, int offset)
532 {
533
534     int len, max_len = MAX_INTERCONNECT_ELEMENT_INFO_LEN;
535
536     if (tree) {
537         proto_tree_add_item (tree, hf_swils_interconnect_list_len, tvb, offset+3, 1, 0);
538         len = tvb_strsize (tvb, offset+4);
539         proto_tree_add_item (tree, hf_swils_ess_vendorname, tvb, offset+4, len, FALSE);
540         offset += (4 + len);
541         max_len -= len;
542         len = tvb_strsize (tvb, offset);
543         proto_tree_add_item (tree, hf_swils_ess_modelname, tvb, offset, len, FALSE);
544         offset += len;
545         max_len -= len;
546         len = tvb_strsize (tvb, offset);
547         proto_tree_add_item (tree, hf_swils_ess_relcode, tvb, offset, len, FALSE);
548         offset += len;
549         max_len -= len;
550         while (max_len > 0) {
551             /* Vendor specific field is a set of one or more null-terminated
552              * strings
553              */
554             len = tvb_strsize (tvb, offset);
555             proto_tree_add_item (tree, hf_swils_ess_vendorspecific, tvb, offset, len, FALSE);
556             offset += len;
557             max_len -= len;
558         }
559     }
560
561     return TRUE;
562 }
563
564 static void
565 dissect_swils_ess_capability (tvbuff_t *tvb, proto_tree *tree, int offset,
566                               guint8 srvr_type)
567 {
568     if (tree) {
569         switch (srvr_type) {
570         case FCCT_GSRVR_DNS:
571             proto_tree_add_item (tree, hf_swils_ess_dns_zlacc, tvb, offset+3,
572                                  1, 0);
573             proto_tree_add_item (tree, hf_swils_ess_dns_obj3h, tvb, offset+3,
574                                  1, 0);
575             proto_tree_add_item (tree, hf_swils_ess_dns_obj2h, tvb, offset+3,
576                                  1, 0);
577             proto_tree_add_item (tree, hf_swils_ess_dns_obj1h, tvb, offset+3,
578                                  1, 0);
579             proto_tree_add_item (tree, hf_swils_ess_dns_obj0h, tvb, offset+3,
580                                  1, 0);
581             proto_tree_add_item (tree, hf_swils_ess_dns_vendor, tvb,
582                                  offset+4, 4, 0);
583             break;
584         case FCCT_GSRVR_FCTLR:
585             proto_tree_add_item (tree, hf_swils_ess_fctlr_rscn, tvb,
586                                  offset+3, 1, 0);
587             proto_tree_add_item (tree, hf_swils_ess_fctlr_vendor, tvb,
588                                  offset+4, 4, 0);
589             break;
590         case FCCT_GSRVR_FCS:
591             proto_tree_add_item (tree, hf_swils_ess_fcs_basic, tvb,
592                                  offset+3, 1, 0);
593             proto_tree_add_item (tree, hf_swils_ess_fcs_platform, tvb,
594                                  offset+3, 1, 0);
595             proto_tree_add_item (tree, hf_swils_ess_fcs_topology, tvb,
596                                  offset+3, 1, 0);
597             proto_tree_add_item (tree, hf_swils_ess_fcs_enhanced, tvb,
598                                  offset+3, 1, 0);
599             break;
600         case FCCT_GSRVR_FZS:
601             proto_tree_add_item (tree, hf_swils_ess_fzs_enh_supp, tvb,
602                                  offset+3, 1, 0);
603             proto_tree_add_item (tree, hf_swils_ess_fzs_enh_ena, tvb,
604                                  offset+3, 1, 0);
605             proto_tree_add_item (tree, hf_swils_ess_fzs_mr, tvb, offset+3,
606                                  1, 0);
607             proto_tree_add_item (tree, hf_swils_ess_fzs_defzone, tvb,
608                                  offset+3, 1, 0);
609             proto_tree_add_item (tree, hf_swils_ess_fzs_zsdb_supp, tvb,
610                                  offset+3, 1, 0);
611             proto_tree_add_item (tree, hf_swils_ess_fzs_zsdb_ena, tvb,
612                                  offset+3, 1, 0);
613             proto_tree_add_item (tree, hf_swils_ess_fzs_adc_supp, tvb,
614                                  offset+3, 1, 0);
615             proto_tree_add_item (tree, hf_swils_ess_fzs_hardzone, tvb,
616                                  offset+3, 1, 0);
617             break;
618         default:
619             break;
620         }
621     }
622
623     return;
624 }
625
626 static int
627 dissect_swils_ess_capability_obj (tvbuff_t *tvb, proto_tree *tree, int offset)
628 {
629     int i = 0, num_entries = 0, len = 0, total_len = 0;
630     guint8 type, subtype, srvr_type;
631     proto_item *ti = NULL;
632     proto_tree *capinfo_tree = NULL;
633
634     if (tree) {
635         /*
636          * Structure of capability object is: WK type (2B), WK subtype(2),
637          * rsvd (1), num_cap_entries (1), entry_1 (8) ... entry_n (8)
638          */
639         /* Compute length first to create subtree of cap object */
640         type = tvb_get_guint8 (tvb, offset);
641         if (type != FCCT_GSTYPE_VENDOR) {
642             num_entries = tvb_get_guint8 (tvb, offset+3);
643             total_len = 4 + (num_entries*8);
644             ti = proto_tree_add_text (tree, tvb, offset,
645                                       total_len, "Capability Object (%s)",
646                                       val_to_str (type, fc_ct_gstype_vals,
647                                                   "Unknown (0x%x)"));
648             capinfo_tree = proto_item_add_subtree (ti, ett_fcswils_capinfo);
649
650         } else {
651             i = tvb_get_guint8 (tvb, offset+3);
652             i += 12;
653
654             ti = proto_tree_add_text (tree, tvb, offset,
655                                       i, "Capability Object (Vendor-specific 0x%x)",
656                                       type);
657             capinfo_tree = proto_item_add_subtree (ti, ett_fcswils_capinfo);
658         }
659
660         proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_type, tvb, offset, 1, 0);
661         proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_subtype, tvb, offset+1,
662                              1, 0);
663         subtype = tvb_get_guint8 (tvb, offset+1);
664
665         if (type != FCCT_GSTYPE_VENDOR) {
666             srvr_type = get_gs_server (type, subtype);
667             proto_tree_add_uint (capinfo_tree, hf_swils_ess_cap_svc, tvb, offset, 2,
668                                  srvr_type);
669             proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_numentries, tvb,
670                                  offset+3, 1, 0);
671             offset += 4;
672             len += 4;
673
674             while ((num_entries > 0) && tvb_bytes_exist (tvb, offset, 8)) {
675                 dissect_swils_ess_capability (tvb, capinfo_tree, offset, srvr_type);
676                 num_entries--;
677                 offset += 8;
678                 len += 8;
679             }
680         } else {
681             /* Those damn T11 guys defined another format for
682              * Vendor-specific objects.
683              */
684             proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_len, tvb, offset+3,
685                                  1, 0);
686             proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_t10, tvb, offset+4,
687                                  8, 0);
688             i -= 8;          /* reduce length by t10 object size */
689             offset += 12;
690             len += 12;
691
692             while ((i > 0) && tvb_bytes_exist (tvb, offset, 8)) {
693                 proto_tree_add_item (capinfo_tree, hf_swils_ess_cap_vendorobj,
694                                      tvb, offset, 8, 0);
695                 i -= 8;
696                 offset += 8;
697                 len += 12;
698             }
699         }
700     }
701     return len;
702 }
703
704 static void
705 dissect_swils_nullpayload (tvbuff_t *tvb _U_, proto_tree *tree _U_,
706                            guint8 isreq _U_)
707 {
708     /* Common dissector for those ILSs without a payload */
709     return;
710 }
711
712 static void
713 dissect_swils_elp (tvbuff_t *tvb, proto_tree *elp_tree, guint8 isreq _U_)
714 {
715
716     /* Set up structures needed to add the protocol subtree and manage it */
717     int offset = 0;
718     const gchar *flags;
719     fcswils_elp elp;
720
721     /* Response i.e. SW_ACC for an ELP has the same format as the request */
722     /* We skip the initial 4 bytes as we don't care about the opcode */
723     tvb_memcpy (tvb, (guint8 *)&elp, 4, FC_SWILS_ELP_SIZE);
724
725     elp.r_a_tov = g_ntohl (elp.r_a_tov);
726     elp.e_d_tov = g_ntohl (elp.e_d_tov);
727     elp.isl_flwctrl_mode = g_ntohs (elp.isl_flwctrl_mode);
728     elp.flw_ctrl_parmlen = g_ntohs (elp.flw_ctrl_parmlen);
729
730     if (elp_tree) {
731         offset += 4;
732         proto_tree_add_item (elp_tree, hf_swils_elp_rev, tvb, offset++, 1, 0);
733         proto_tree_add_item (elp_tree, hf_swils_elp_flags, tvb, offset, 2, 0);
734         offset += 3;
735         proto_tree_add_uint_format (elp_tree, hf_swils_elp_r_a_tov, tvb, offset, 4,
736                                     elp.r_a_tov, "R_A_TOV: %d msecs", elp.r_a_tov);
737         offset += 4;
738         proto_tree_add_uint_format (elp_tree, hf_swils_elp_e_d_tov, tvb, offset, 4,
739                                     elp.e_d_tov, "E_D_TOV: %d msecs", elp.e_d_tov);
740         offset += 4;
741         proto_tree_add_string (elp_tree, hf_swils_elp_req_epn, tvb, offset, 8,
742                                fcwwn_to_str (elp.req_epname));
743         offset += 8;
744         proto_tree_add_string (elp_tree, hf_swils_elp_req_esn, tvb, offset, 8,
745                                fcwwn_to_str (elp.req_sname));
746         offset += 8;
747
748         flags="";
749         if (elp.clsf_svcparm[0] & 0x80) {
750             if (elp.clsf_svcparm[4] & 0x20) {
751                 flags="Class F Valid | X_ID Interlock";
752             } else {
753                 flags="Class F Valid | No X_ID Interlk";
754             }
755         } else {
756             flags="Class F Invld";
757         }
758         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_clsf_svcp, tvb, offset, 6,
759                                      &elp.clsf_svcparm[0], "Class F Svc Parameters: (%s)", flags);
760         offset += 6;
761
762         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_rcvsz, tvb, offset, 2, 0);
763         offset += 2;
764         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_conseq, tvb, offset, 2, 0);
765         offset += 2;
766         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_e2e, tvb, offset, 2, 0);
767         offset += 2;
768         proto_tree_add_item (elp_tree, hf_swils_elp_clsf_openseq, tvb, offset, 2, 0);
769         offset += 4;
770
771         flags="";
772         if (elp.cls1_svcparm[0] & 0x80) {
773 #define MAX_FLAGS_LEN 40
774             char *flagsbuf;
775             gint stroff, returned_length;
776
777             flagsbuf=ep_alloc(MAX_FLAGS_LEN);
778             stroff = 0;
779
780             returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff,
781                                           "Class 1 Valid");
782             stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
783             if (elp.cls1_svcparm[0] & 0x40) {
784                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | IMX");
785                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
786             }
787             if (elp.cls1_svcparm[0] & 0x20) {
788                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | IPS");
789                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
790             }
791             if (elp.cls1_svcparm[0] & 0x10) {
792                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | LKS");
793                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
794             }
795             flags=flagsbuf;
796         }
797         else {
798             flags="Class 1 Invalid";
799         }
800
801         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls1_svcp, tvb, offset, 2,
802                                      tvb_get_ptr (tvb, offset, 2),
803                                      "Class 1 Svc Parameters: (%s)", flags);
804         offset += 2;
805         if (elp.cls1_svcparm[0] & 0x80) {
806             proto_tree_add_item (elp_tree, hf_swils_elp_cls1_rcvsz, tvb, offset, 2, 0);
807         }
808         offset += 2;
809
810         flags="";
811         if (elp.cls2_svcparm[0] & 0x80) {
812             if (elp.cls2_svcparm[0] & 0x08) {
813                 flags="Class 2 Valid | Seq Delivery";
814             }
815             else {
816                 flags="Class 2 Valid | No Seq Delivery";
817             }
818         }
819         else {
820             flags="Class 2 Invld";
821         }
822
823         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls2_svcp, tvb, offset, 2,
824                                      &elp.cls2_svcparm[0],
825                                      "Class 2 Svc Parameters: (%s)", flags);
826         offset += 2;
827
828         if (elp.cls2_svcparm[0] & 0x80) {
829             proto_tree_add_item (elp_tree, hf_swils_elp_cls2_rcvsz, tvb, offset, 2, 0);
830         }
831         offset += 2;
832
833         flags="";
834         if (elp.cls3_svcparm[0] & 0x80) {
835             if (elp.cls3_svcparm[0] & 0x08) {
836                 flags="Class 3 Valid | Seq Delivery";
837             }
838             else {
839                 flags="Class 3 Valid | No Seq Delivery";
840             }
841         }
842         else {
843             flags="Class 3 Invld";
844         }
845         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls3_svcp, tvb, offset, 2,
846                                      &elp.cls3_svcparm[0],
847                                      "Class 3 Svc Parameters: (%s)", flags);
848         offset += 2;
849
850         if (elp.cls3_svcparm[0] & 0x80) {
851             proto_tree_add_item (elp_tree, hf_swils_elp_cls3_rcvsz, tvb, offset, 2, 0);
852         }
853         offset += 22;
854
855         proto_tree_add_string (elp_tree, hf_swils_elp_isl_fc_mode, tvb, offset, 2,
856                                val_to_str (elp.isl_flwctrl_mode, fcswils_elp_fc_val, "Vendor Unique"));
857         offset += 2;
858         proto_tree_add_item (elp_tree, hf_swils_elp_fcplen, tvb, offset, 2, 0);
859         offset += 2;
860         proto_tree_add_item (elp_tree, hf_swils_elp_b2bcredit, tvb, offset, 4, 0);
861         offset += 4;
862         proto_tree_add_item (elp_tree, hf_swils_elp_compat1, tvb, offset, 4, 0);
863         offset += 4;
864         proto_tree_add_item (elp_tree, hf_swils_elp_compat2, tvb, offset, 4, 0);
865         offset += 4;
866         proto_tree_add_item (elp_tree, hf_swils_elp_compat3, tvb, offset, 4, 0);
867         offset += 4;
868         proto_tree_add_item (elp_tree, hf_swils_elp_compat4, tvb, offset, 4, 0);
869     }
870
871 }
872
873 static void
874 dissect_swils_efp (tvbuff_t *tvb, proto_tree *efp_tree, guint8 isreq _U_)
875 {
876
877 /* Set up structures needed to add the protocol subtree and manage it */
878     proto_item *subti;
879     proto_tree *lrec_tree;
880     int num_listrec = 0,
881         offset = 0;
882     fcswils_efp efp;
883     guint8 rec_type;
884
885     offset += 1;
886     efp.reclen = tvb_get_guint8 (tvb, offset);
887     if (efp_tree)
888         proto_tree_add_uint (efp_tree, hf_swils_efp_record_len, tvb, offset, 1, efp.reclen);
889     offset += 1;
890     efp.payload_len = tvb_get_ntohs (tvb, offset);
891     if (efp.payload_len < FC_SWILS_EFP_SIZE) {
892         if (efp_tree)
893             proto_tree_add_uint_format (efp_tree, hf_swils_efp_payload_len,
894                                         tvb, offset, 2, efp.payload_len,
895                                         "Payload Len: %u (bogus, must be >= %u)",
896                                         efp.payload_len, FC_SWILS_EFP_SIZE);
897         return;
898     }
899     if (efp_tree)
900         proto_tree_add_item (efp_tree, hf_swils_efp_payload_len, tvb, offset, 2, 0);
901     offset += 5;       /* skip 3 reserved bytes, too */
902     if (efp_tree)
903         proto_tree_add_item (efp_tree, hf_swils_efp_pswitch_pri, tvb,
904                              offset, 1, FALSE);
905     offset++;
906     tvb_memcpy (tvb, efp.pswitch_name, offset, 8);
907     if (efp_tree)
908         proto_tree_add_string (efp_tree, hf_swils_efp_pswitch_name, tvb, offset,
909                                8, fcwwn_to_str (efp.pswitch_name));
910     offset += 8;
911
912     /* Add List Records now */
913     if (efp_tree) {
914         if (efp.reclen == 0) {
915             proto_tree_add_text (efp_tree, tvb, 0, 0, "Record length is zero");
916             return;
917         }
918         num_listrec = (efp.payload_len - FC_SWILS_EFP_SIZE)/efp.reclen;
919         while (num_listrec-- > 0) {
920             rec_type = tvb_get_guint8 (tvb, offset);
921             subti = proto_tree_add_text (efp_tree, tvb, offset, -1,
922                                          "%s",
923                                          val_to_str(rec_type,
924                                                     fcswils_rectype_val,
925                                                     "Unknown record type (0x%02x)"));
926             lrec_tree = proto_item_add_subtree (subti, ett_fcswils_efplist);
927             proto_tree_add_uint (lrec_tree, hf_swils_efp_rec_type, tvb, offset, 1,
928                                  rec_type);
929             switch (rec_type) {
930
931             case FC_SWILS_LRECTYPE_DOMAIN:
932                 proto_tree_add_item (lrec_tree, hf_swils_efp_dom_id, tvb, offset+1, 1, 0);
933                 proto_tree_add_string (lrec_tree, hf_swils_efp_switch_name, tvb, offset+8, 8,
934                                        fcwwn_to_str (tvb_get_ptr(tvb, offset+8, 8)));
935                 break;
936
937             case FC_SWILS_LRECTYPE_MCAST:
938                 proto_tree_add_item (lrec_tree, hf_swils_efp_mcast_grpno, tvb, offset+1, 1, 0);
939                 break;
940             }
941             offset += efp.reclen;
942         }
943     }
944 }
945
946 static void
947 dissect_swils_dia (tvbuff_t *tvb, proto_tree *dia_tree, guint8 isreq _U_)
948 {
949     /* Set up structures needed to add the protocol subtree and manage it */
950     int offset = 0;
951
952     if (dia_tree) {
953         proto_tree_add_string (dia_tree, hf_swils_dia_switch_name, tvb, offset+4,
954                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
955     }
956 }
957
958 static void
959 dissect_swils_rdi (tvbuff_t *tvb, proto_tree *rdi_tree, guint8 isreq)
960 {
961     /* Set up structures needed to add the protocol subtree and manage it */
962     int offset = 0;
963     int i, plen, numrec;
964
965     if (rdi_tree) {
966         plen = tvb_get_ntohs (tvb, offset+2);
967
968         proto_tree_add_item (rdi_tree, hf_swils_rdi_payload_len, tvb, offset+2, 2, 0);
969         proto_tree_add_string (rdi_tree, hf_swils_rdi_req_sname, tvb, offset+4,
970                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
971
972         /* 12 is the length of the initial header and 4 is the size of each
973          * domain request record.
974          */
975         numrec = (plen - 12)/4;
976         offset = 12;
977         for (i = 0; i < numrec; i++) {
978             if (isreq) {
979                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
980                                      "Requested Domain ID: %d",
981                                      tvb_get_guint8 (tvb, offset+3));
982             }
983             else {
984                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
985                                      "Granted Domain ID: %d",
986                                      tvb_get_guint8 (tvb, offset+3));
987             }
988             offset += 4;
989         }
990     }
991 }
992
993 static void
994 dissect_swils_fspf_hdr (tvbuff_t *tvb, proto_tree *tree, int offset)
995 {
996     proto_item *subti;
997     proto_tree *fspfh_tree;
998
999     if (tree) {
1000         /* 20 is the size of FSPF header */
1001         subti = proto_tree_add_text (tree, tvb, offset, 20, "FSPF Header");
1002         fspfh_tree = proto_item_add_subtree (subti, ett_fcswils_fspfhdr);
1003
1004         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_rev, tvb, offset+4,
1005                              1, 0);
1006         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_ar_num, tvb,
1007                              offset+5, 1, 0);
1008         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth_type, tvb,
1009                              offset+6, 1, 0);
1010         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_dom_id, tvb, offset+11,
1011                              1, 0);
1012         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth, tvb, offset+12,
1013                              8, 0);
1014     }
1015 }
1016
1017 static void
1018 dissect_swils_fspf_lsrechdr (tvbuff_t *tvb, proto_tree *tree, int offset)
1019 {
1020     proto_tree_add_item (tree, hf_swils_lsrh_lsr_type, tvb, offset, 1, 0);
1021     proto_tree_add_text (tree, tvb, offset+2, 2, "LSR Age: %d secs",
1022                          tvb_get_ntohs (tvb, offset+2));
1023     proto_tree_add_text (tree, tvb, offset+4, 4, "Options : 0x%x",
1024                          tvb_get_ntohl (tvb, offset+4));
1025     proto_tree_add_item (tree, hf_swils_lsrh_lsid, tvb, offset+11, 1, 0);
1026     proto_tree_add_item (tree, hf_swils_lsrh_adv_domid, tvb, offset+15, 1, 0);
1027     proto_tree_add_item (tree, hf_swils_lsrh_ls_incid, tvb, offset+16, 4, 0);
1028     proto_tree_add_text (tree, tvb, offset+20, 2, "Checksum: 0x%x",
1029                          tvb_get_ntohs (tvb, offset+20));
1030     proto_tree_add_text (tree, tvb, offset+22, 2, "LSR Length: %d",
1031                          tvb_get_ntohs (tvb, offset+22));
1032 }
1033
1034 static void
1035 dissect_swils_fspf_ldrec (tvbuff_t *tvb, proto_tree *tree, int offset)
1036 {
1037     proto_tree_add_string (tree, hf_swils_ldrec_linkid, tvb, offset, 4,
1038                            fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
1039     proto_tree_add_item (tree, hf_swils_ldrec_out_pidx, tvb, offset+5, 3, 0);
1040     proto_tree_add_item (tree, hf_swils_ldrec_nbr_pidx, tvb, offset+9, 3, 0);
1041     proto_tree_add_item (tree, hf_swils_ldrec_link_type, tvb, offset+12, 1, 0);
1042     proto_tree_add_item (tree, hf_swils_ldrec_link_cost, tvb, offset+14, 2, 0);
1043 }
1044
1045 static void
1046 dissect_swils_fspf_lsrec (tvbuff_t *tvb, proto_tree *tree, int offset,
1047                           int num_lsrec)
1048 {
1049     int i, j, num_ldrec;
1050     proto_item *subti1, *subti;
1051     proto_tree *lsrec_tree, *ldrec_tree, *lsrechdr_tree;
1052
1053     if (tree) {
1054         for (j = 0; j < num_lsrec; j++) {
1055             num_ldrec = tvb_get_ntohs (tvb, offset+26);
1056             subti = proto_tree_add_text (tree, tvb, offset, (28+num_ldrec*16),
1057                                          "Link State Record %d (Domain %d)", j,
1058                                          tvb_get_guint8 (tvb, offset+15));
1059             lsrec_tree = proto_item_add_subtree (subti, ett_fcswils_lsrec);
1060
1061             subti = proto_tree_add_text (lsrec_tree, tvb, offset, 24,
1062                                          "Link State Record Header");
1063             lsrechdr_tree = proto_item_add_subtree (subti,
1064                                                     ett_fcswils_lsrechdr);
1065
1066             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
1067             proto_tree_add_text (tree, tvb, offset+26, 2, "Number of Links: %d",
1068                                  num_ldrec);
1069             offset += 28;
1070
1071             for (i = 0; i < num_ldrec; i++) {
1072                 subti1 = proto_tree_add_text (lsrec_tree, tvb, offset, 16,
1073                                               "Link Descriptor %d "
1074                                               "(Neighbor domain %d)", i,
1075                                               tvb_get_guint8 (tvb, offset+3));
1076                 ldrec_tree = proto_item_add_subtree (subti1, ett_fcswils_ldrec);
1077                 dissect_swils_fspf_ldrec (tvb, ldrec_tree, offset);
1078                 offset += 16;
1079             }
1080         }
1081     }
1082 }
1083
1084 static void
1085 dissect_swils_hello (tvbuff_t *tvb, proto_tree *hlo_tree, guint8 isreq _U_)
1086 {
1087     /* Set up structures needed to add the protocol subtree and manage it */
1088     int offset = 0;
1089
1090     if (hlo_tree) {
1091         dissect_swils_fspf_hdr (tvb, hlo_tree, offset);
1092
1093         proto_tree_add_item (hlo_tree, hf_swils_hlo_options, tvb, offset+20, 4, 0);
1094         proto_tree_add_item (hlo_tree, hf_swils_hlo_hloint, tvb, offset+24, 4, 0);
1095         proto_tree_add_item (hlo_tree, hf_swils_hlo_deadint, tvb, offset+28, 4, 0);
1096         proto_tree_add_item (hlo_tree, hf_swils_hlo_rcv_domid, tvb, offset+35, 1, 0);
1097         proto_tree_add_item (hlo_tree, hf_swils_hlo_orig_pidx, tvb, offset+37, 3, 0);
1098     }
1099 }
1100
1101 static void
1102 dissect_swils_lsupdate (tvbuff_t *tvb, proto_tree *lsu_tree, guint8 isreq _U_)
1103 {
1104     /* Set up structures needed to add the protocol subtree and manage it */
1105     int offset = 0;
1106     int num_lsrec;
1107
1108     if (lsu_tree) {
1109         dissect_swils_fspf_hdr (tvb, lsu_tree, offset);
1110
1111         proto_tree_add_text (lsu_tree, tvb, offset+23, 1, "Flags : %s",
1112                              val_to_str (tvb_get_guint8 (tvb, offset+23),
1113                                          fc_swils_fspf_lsrflags_val, "0x%x"));
1114         num_lsrec = tvb_get_ntohl (tvb, offset+24);
1115
1116         proto_tree_add_text (lsu_tree, tvb, offset+24, 4, "Num of LSRs: %d",
1117                              num_lsrec);
1118
1119         offset = 28;
1120         dissect_swils_fspf_lsrec (tvb, lsu_tree, offset, num_lsrec);
1121     }
1122 }
1123
1124 static void
1125 dissect_swils_lsack (tvbuff_t *tvb, proto_tree *lsa_tree, guint8 isreq _U_)
1126 {
1127     /* Set up structures needed to add the protocol subtree and manage it */
1128     int offset = 0;
1129     int num_lsrechdr, i;
1130     proto_item *subti;
1131     proto_tree *lsrechdr_tree;
1132
1133     if (lsa_tree) {
1134         dissect_swils_fspf_hdr (tvb, lsa_tree, offset);
1135
1136         proto_tree_add_text (lsa_tree, tvb, offset+23, 1, "Flags : %s",
1137                              val_to_str (tvb_get_guint8 (tvb, offset+23),
1138                                          fc_swils_fspf_lsrflags_val, "0x%x"));
1139         num_lsrechdr = tvb_get_ntohl (tvb, offset+24);
1140
1141         proto_tree_add_text (lsa_tree, tvb, offset+24, 4, "Num of LSR Headers: %d",
1142                              num_lsrechdr);
1143
1144         offset = 28;
1145
1146         for (i = 0; i < num_lsrechdr; i++) {
1147             subti = proto_tree_add_text (lsa_tree, tvb, offset, 24,
1148                                          "Link State Record Header (Domain %d)",
1149                                          tvb_get_guint8 (tvb, offset+15));
1150             lsrechdr_tree = proto_item_add_subtree (subti,
1151                                                     ett_fcswils_lsrechdr);
1152             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
1153             offset += 24;
1154         }
1155     }
1156 }
1157
1158 static void
1159 dissect_swils_rscn (tvbuff_t *tvb, proto_tree *rscn_tree, guint8 isreq)
1160 {
1161     /* Set up structures needed to add the protocol subtree and manage it */
1162     int offset = 0;
1163     proto_tree *dev_tree;
1164     int addrfmt, evtype;
1165     int numrec, i;
1166     proto_item *subti;
1167
1168     if (rscn_tree) {
1169         if (!isreq)
1170             return;
1171
1172         evtype = tvb_get_guint8 (tvb, offset+4);
1173         addrfmt = evtype & 0x0F;
1174         evtype = evtype >> 4;
1175
1176         proto_tree_add_item (rscn_tree, hf_swils_rscn_evtype, tvb, offset+4,
1177                              1, 0);
1178         proto_tree_add_item (rscn_tree, hf_swils_rscn_addrfmt, tvb, offset+4,
1179                              1, 0);
1180         proto_tree_add_string (rscn_tree, hf_swils_rscn_affectedport, tvb,
1181                                offset+5, 3, fc_to_str (tvb_get_ptr (tvb,
1182                                                                     offset+5, 3)));
1183         proto_tree_add_item (rscn_tree, hf_swils_rscn_detectfn, tvb,
1184                              offset+8, 4, 0);
1185         numrec = tvb_get_ntohl (tvb, offset+12);
1186
1187         if (!tvb_bytes_exist (tvb, offset+16, FC_SWILS_RSCN_DEVENTRY_SIZE*numrec)) {
1188             /* Some older devices do not include device entry information. */
1189             return;
1190         }
1191
1192         proto_tree_add_text (rscn_tree, tvb, offset+12, 4, "Num Entries: %d",
1193                              numrec);
1194
1195         offset = 16;
1196         for (i = 0; i < numrec; i++) {
1197             subti = proto_tree_add_text (rscn_tree, tvb, offset, 20,
1198                                          "Device Entry %d", i);
1199             dev_tree = proto_item_add_subtree (rscn_tree, ett_fcswils_rscn_dev);
1200
1201             proto_tree_add_item (dev_tree, hf_swils_rscn_portstate, tvb, offset, 1, 0);
1202             proto_tree_add_string (dev_tree, hf_swils_rscn_portid, tvb, offset+1, 3,
1203                                    fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
1204             proto_tree_add_string (dev_tree, hf_swils_rscn_pwwn, tvb, offset+4, 8,
1205                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
1206             proto_tree_add_string (dev_tree, hf_swils_rscn_nwwn, tvb, offset+12, 8,
1207                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+12, 8)));
1208             offset += 20;
1209         }
1210     }
1211 }
1212
1213 /*
1214  * Merge Request contains zoning objects organized in the following format:
1215  *
1216  * Zone Set Object
1217  *      |
1218  *      +---------------- Zone Object
1219  *      |                      |
1220  *      +--                    +---------------- Zone Member
1221  *      |                      |                     |
1222  *      +--                    +----                 +-----
1223  *
1224  * So the decoding of the zone merge request is based on this structure
1225  */
1226
1227 static void
1228 dissect_swils_zone_mbr (tvbuff_t *tvb, proto_tree *zmbr_tree, int offset)
1229 {
1230     guint8 mbrtype;
1231     int idlen;
1232     char dpbuf[2+8+1];
1233     char *str;
1234
1235     mbrtype = tvb_get_guint8 (tvb, offset);
1236     proto_tree_add_uint (zmbr_tree, hf_swils_zone_mbrtype, tvb,
1237                          offset, 1, mbrtype);
1238     proto_tree_add_text (zmbr_tree, tvb, offset+2, 1, "Flags: 0x%x",
1239                          tvb_get_guint8 (tvb, offset+2));
1240     idlen = tvb_get_guint8 (tvb, offset+3);
1241     proto_tree_add_text (zmbr_tree, tvb, offset+3, 1,
1242                          "Identifier Length: %u", idlen);
1243     switch (mbrtype) {
1244     case FC_SWILS_ZONEMBR_WWN:
1245         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1246                                offset+4, 8,
1247                                fcwwn_to_str (tvb_get_ptr (tvb,
1248                                                           offset+4,
1249                                                           8)));
1250         break;
1251     case FC_SWILS_ZONEMBR_DP:
1252         g_snprintf(dpbuf, sizeof(dpbuf), "0x%08x", tvb_get_ntohl (tvb, offset+4));
1253         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1254                                offset+4, 4, dpbuf);
1255         break;
1256     case FC_SWILS_ZONEMBR_FCID:
1257         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1258                                offset+4, 4,
1259                                fc_to_str (tvb_get_ptr (tvb,
1260                                                        offset+5,
1261                                                        3)));
1262         break;
1263     case FC_SWILS_ZONEMBR_ALIAS:
1264         str = zonenm_to_str (tvb, offset+4);
1265         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1266                                offset+4, idlen, str);
1267         break;
1268     case FC_SWILS_ZONEMBR_WWN_LUN:
1269         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1270                                offset+4, 8,
1271                                fcwwn_to_str (tvb_get_ptr (tvb,
1272                                                           offset+4,
1273                                                           8)));
1274         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1275                              offset+12, 8, 0);
1276         break;
1277     case FC_SWILS_ZONEMBR_DP_LUN:
1278         g_snprintf(dpbuf, sizeof(dpbuf), "0x%08x", tvb_get_ntohl (tvb, offset+4));
1279         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1280                                offset+4, 4, dpbuf);
1281         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1282                              offset+8, 8, FALSE);
1283         break;
1284     case FC_SWILS_ZONEMBR_FCID_LUN:
1285         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1286                                offset+4, 4,
1287                                fc_to_str (tvb_get_ptr (tvb,
1288                                                        offset+5,
1289                                                        3)));
1290         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1291                              offset+8, 8, 0);
1292         break;
1293     default:
1294         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1295                                offset+4, idlen,
1296                                "Unknown member type format");
1297
1298     }
1299 }
1300
1301 static void
1302 dissect_swils_zone_obj (tvbuff_t *tvb, proto_tree *zobj_tree, int offset)
1303 {
1304     proto_tree *zmbr_tree;
1305     int mbrlen, numrec, i, objtype;
1306     char *str;
1307     proto_item *subti;
1308
1309     objtype = tvb_get_guint8 (tvb, offset);
1310
1311     proto_tree_add_item (zobj_tree, hf_swils_zone_objtype, tvb, offset,
1312                          1, 0);
1313     proto_tree_add_item (zobj_tree, hf_swils_zone_protocol, tvb,
1314                          offset+1, 1, 0);
1315     str = zonenm_to_str (tvb, offset+4);
1316     proto_tree_add_string (zobj_tree, hf_swils_zone_objname, tvb,
1317                            offset+4, ZONENAME_LEN (tvb, offset+4), str);
1318
1319     numrec = tvb_get_ntohl (tvb, offset+4+ZONENAME_LEN (tvb, offset+4));
1320     proto_tree_add_text (zobj_tree, tvb,
1321                          offset+4+ZONENAME_LEN (tvb, offset+4), 4,
1322                          "Number of Zone Members: %d", numrec);
1323
1324     offset += 8 + ZONENAME_LEN (tvb, offset+4);
1325     for (i = 0; i < numrec; i++) {
1326         if (objtype == FC_SWILS_ZONEOBJ_ZONESET) {
1327             dissect_swils_zone_obj (tvb, zobj_tree, offset);
1328             offset += get_zoneobj_len (tvb, offset);
1329         }
1330         else {
1331             mbrlen = 4 + tvb_get_guint8 (tvb, offset+3);
1332             subti = proto_tree_add_text (zobj_tree, tvb, offset, mbrlen,
1333                                          "Zone Member %d", i);
1334             zmbr_tree = proto_item_add_subtree (zobj_tree,
1335                                                 ett_fcswils_zonembr);
1336             dissect_swils_zone_mbr (tvb, zmbr_tree, offset);
1337             offset += mbrlen;
1338         }
1339     }
1340 }
1341
1342 static void
1343 dissect_swils_mergereq (tvbuff_t *tvb, proto_tree *mr_tree, guint8 isreq)
1344 {
1345     /* Set up structures needed to add the protocol subtree and manage it */
1346     int offset = 0;
1347     proto_tree *zobjlist_tree, *zobj_tree;
1348     int numrec, i, zonesetlen, objlistlen, objlen;
1349     char *str;
1350     proto_item *subti;
1351
1352     if (mr_tree) {
1353         if (isreq) {
1354             /* zonesetlen is the size of the zoneset including the zone name */
1355             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1356             proto_tree_add_text (mr_tree, tvb, offset+2, 2,
1357                                  "Active ZoneSet Length: %u", zonesetlen);
1358
1359             if (zonesetlen) {
1360                 str = zonenm_to_str (tvb, offset+4);
1361                 proto_tree_add_string (mr_tree, hf_swils_zone_activezonenm, tvb,
1362                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1363                                        str);
1364
1365                 /* objlistlen gives the size of the active zoneset object list */
1366                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1367                 /* Offset = start of the active zoneset zoning object list */
1368                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1369                 numrec = tvb_get_ntohl (tvb, offset);
1370
1371                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1372                                              "Active Zone Set");
1373                 zobjlist_tree = proto_item_add_subtree (subti,
1374                                                         ett_fcswils_zoneobjlist);
1375
1376                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1377                                      "Number of zoning objects: %d", numrec);
1378
1379                 offset += 4;
1380                 for (i = 0; i < numrec; i++) {
1381                     objlen = get_zoneobj_len (tvb, offset);
1382                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset+4,
1383                                                  objlen, "Zone Object %d", i);
1384                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1385                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1386                     offset += objlen;
1387                 }
1388             }
1389             else {
1390                 offset += 4;
1391             }
1392
1393             zonesetlen = tvb_get_ntohl (tvb, offset);
1394             proto_tree_add_text (mr_tree, tvb, offset, 4,
1395                                  "Full Zone Set Length: %d", zonesetlen);
1396
1397             if (zonesetlen) {
1398                 objlistlen = zonesetlen;
1399                 /* Offset = start of the active zoneset zoning object list */
1400                 offset += 4;
1401                 numrec = tvb_get_ntohl (tvb, offset);
1402
1403                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1404                                              "Full Zone Set");
1405
1406                 zobjlist_tree = proto_item_add_subtree (subti,
1407                                                         ett_fcswils_zoneobjlist);
1408                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1409                                      "Number of zoning objects: %d", numrec);
1410                 offset += 4;
1411                 for (i = 0; i < numrec; i++) {
1412                     objlen = get_zoneobj_len (tvb, offset);
1413                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1414                                                  objlen, "Zone Object %d", i);
1415                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1416                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1417                     offset += objlen;
1418                 }
1419             }
1420         }
1421         else {
1422             proto_tree_add_item (mr_tree, hf_swils_zone_status, tvb,
1423                                  offset+5, 1, 0);
1424             proto_tree_add_item (mr_tree, hf_swils_zone_reason, tvb,
1425                                  offset+6, 1, 0);
1426             proto_tree_add_text (mr_tree, tvb, offset+7, 1,
1427                                  "Vendor Unique: 0x%x",
1428                                  tvb_get_guint8 (tvb, offset+7));
1429         }
1430     }
1431 }
1432
1433 static void
1434 dissect_swils_aca (tvbuff_t *tvb, proto_tree *aca_tree, guint8 isreq)
1435 {
1436     /* Set up structures needed to add the protocol subtree and manage it */
1437     int offset = 0;
1438     int numrec, plen, i;
1439
1440     if (aca_tree) {
1441         if (isreq) {
1442             plen = tvb_get_ntohs (tvb, offset+2);
1443             proto_tree_add_text (aca_tree, tvb, offset+2, 2,
1444                                  "Domain ID List Length: %d", plen);
1445             numrec = plen/4;
1446             offset = 4;
1447
1448             for (i = 0; i < numrec; i++) {
1449                 proto_tree_add_uint_format (aca_tree, hf_swils_aca_domainid,
1450                                             tvb, offset+3, 1,
1451                                             tvb_get_guint8 (tvb, offset+3),
1452                                             "Domain ID %d: %d", i,
1453                                             tvb_get_guint8 (tvb, offset+3));
1454                 offset += 4;
1455             }
1456         }
1457         else {
1458             proto_tree_add_item (aca_tree, hf_swils_zone_status, tvb,
1459                                  offset+5, 1, 0);
1460             proto_tree_add_item (aca_tree, hf_swils_zone_reason, tvb,
1461                                  offset+6, 1, 0);
1462             proto_tree_add_text (aca_tree, tvb, offset+7, 1,
1463                                  "Vendor Unique: 0x%x",
1464                                  tvb_get_guint8 (tvb, offset+7));
1465         }
1466     }
1467 }
1468
1469 static void
1470 dissect_swils_rca (tvbuff_t *tvb, proto_tree *rca_tree, guint8 isreq)
1471 {
1472     /* Set up structures needed to add the protocol subtree and manage it */
1473     int offset = 0;
1474
1475     if (rca_tree) {
1476         if (!isreq) {
1477             proto_tree_add_item (rca_tree, hf_swils_zone_status, tvb,
1478                                  offset+5, 1, 0);
1479             proto_tree_add_item (rca_tree, hf_swils_zone_reason, tvb,
1480                                  offset+6, 1, 0);
1481             proto_tree_add_text (rca_tree, tvb, offset+7, 1,
1482                                  "Vendor Unique: 0x%x",
1483                                  tvb_get_guint8 (tvb, offset+7));
1484         }
1485     }
1486 }
1487
1488 static void
1489 dissect_swils_sfc (tvbuff_t *tvb, proto_tree *sfc_tree, guint8 isreq)
1490 {
1491     /* Set up structures needed to add the protocol subtree and manage it */
1492     int offset = 0;
1493     proto_tree *zobjlist_tree, *zobj_tree;
1494     int numrec, i, zonesetlen, objlistlen, objlen;
1495     char *str;
1496     proto_item *subti;
1497
1498     if (sfc_tree) {
1499         if (isreq) {
1500             proto_tree_add_item (sfc_tree, hf_swils_sfc_opcode, tvb, offset+1, 1, 0);
1501
1502             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1503             proto_tree_add_text (sfc_tree, tvb, offset+2, 2,
1504                                  "ZoneSet Length: %d", zonesetlen);
1505
1506             if (zonesetlen) {
1507                 str = zonenm_to_str (tvb, offset+4);
1508                 proto_tree_add_string (sfc_tree, hf_swils_sfc_zonenm, tvb,
1509                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1510                                        str);
1511
1512                 /* objlistlen gives the size of the active zoneset object list */
1513                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1514                 /* Offset = start of the active zoneset zoning object list */
1515                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1516                 numrec = tvb_get_ntohl (tvb, offset);
1517
1518                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1519                                              "Zone Set");
1520                 zobjlist_tree = proto_item_add_subtree (subti,
1521                                                         ett_fcswils_zoneobjlist);
1522
1523                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1524                                      "Number of zoning objects: %d", numrec);
1525
1526                 offset += 4;
1527                 for (i = 0; i < numrec; i++) {
1528                     objlen = get_zoneobj_len (tvb, offset);
1529                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1530                                                  objlen, "Zone Object %d", i);
1531                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1532                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1533                     offset += objlen;
1534                 }
1535             }
1536             else {
1537                 offset += 4;
1538             }
1539
1540             zonesetlen = tvb_get_ntohl (tvb, offset);
1541             proto_tree_add_text (sfc_tree, tvb, offset, 4,
1542                                  "Full Zone Set Length: %d", zonesetlen);
1543
1544             if (zonesetlen) {
1545                 objlistlen = zonesetlen;
1546                 /* Offset = start of the active zoneset zoning object list */
1547                 offset += 4;
1548                 numrec = tvb_get_ntohl (tvb, offset);
1549
1550                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1551                                              "Full Zone Set");
1552
1553                 zobjlist_tree = proto_item_add_subtree (subti,
1554                                                         ett_fcswils_zoneobjlist);
1555                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1556                                      "Number of zoning objects: %d", numrec);
1557                 offset += 4;
1558                 for (i = 0; i < numrec; i++) {
1559                     objlen = get_zoneobj_len (tvb, offset);
1560                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1561                                                  objlen, "Zone Object %d", i);
1562                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1563                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1564                     offset += objlen;
1565                 }
1566             }
1567         }
1568         else {
1569             proto_tree_add_item (sfc_tree, hf_swils_zone_status, tvb,
1570                                  offset+5, 1, 0);
1571             proto_tree_add_item (sfc_tree, hf_swils_zone_reason, tvb,
1572                                  offset+6, 1, 0);
1573             proto_tree_add_text (sfc_tree, tvb, offset+7, 1,
1574                                  "Vendor Unique: 0x%x",
1575                                  tvb_get_guint8 (tvb, offset+7));
1576         }
1577     }
1578 }
1579
1580 static void
1581 dissect_swils_ufc (tvbuff_t *tvb, proto_tree *ufc_tree, guint8 isreq)
1582 {
1583     /* Set up structures needed to add the protocol subtree and manage it */
1584     int offset = 0;
1585
1586     if (ufc_tree) {
1587         if (!isreq) {
1588             proto_tree_add_item (ufc_tree, hf_swils_zone_status, tvb,
1589                                  offset+5, 1, 0);
1590             proto_tree_add_item (ufc_tree, hf_swils_zone_reason, tvb,
1591                                  offset+6, 1, 0);
1592             proto_tree_add_text (ufc_tree, tvb, offset+7, 1,
1593                                  "Vendor Unique: 0x%x",
1594                                  tvb_get_guint8 (tvb, offset+7));
1595         }
1596     }
1597 }
1598
1599 static void
1600 dissect_swils_esc (tvbuff_t *tvb, proto_tree *esc_tree, guint8 isreq)
1601 {
1602     /* Set up structures needed to add the protocol subtree and manage it */
1603     int offset = 0;
1604     int i, numrec, plen;
1605     proto_tree *pdesc_tree;
1606     proto_item *subti;
1607
1608     if (esc_tree) {
1609         if (isreq) {
1610             plen = tvb_get_ntohs (tvb, offset+2);
1611             proto_tree_add_text (esc_tree, tvb, offset+2, 2,
1612                                  "Payload Length: %d", plen);
1613             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1614                                  offset+4, 8, 0);
1615             numrec = (plen - 12)/12;
1616             offset = 12;
1617
1618             for (i = 0; i < numrec; i++) {
1619                 subti = proto_tree_add_text (esc_tree, tvb, offset, 12,
1620                                              "Protocol Descriptor %d", i);
1621                 pdesc_tree = proto_item_add_subtree (subti,
1622                                                      ett_fcswils_esc_pdesc);
1623                 proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1624                                      offset, 8, 0);
1625                 proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1626                                      tvb, offset+10, 2, 0);
1627                 offset += 12;
1628             }
1629         }
1630         else {
1631             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1632                                  offset+4, 8, 0);
1633             subti = proto_tree_add_text (esc_tree, tvb, offset+12, 12,
1634                                          "Accepted Protocol Descriptor");
1635             pdesc_tree = proto_item_add_subtree (subti, ett_fcswils_esc_pdesc);
1636
1637             proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1638                                  offset+12, 8, 0);
1639             proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1640                                  tvb, offset+22, 2, 0);
1641         }
1642     }
1643 }
1644
1645 static void
1646 dissect_swils_drlir (tvbuff_t *tvb _U_, proto_tree *drlir_tree _U_,
1647                      guint8 isreq _U_)
1648 {
1649     /* Set up structures needed to add the protocol subtree and manage it */
1650     return;
1651 }
1652
1653 static void
1654 dissect_swils_swrjt (tvbuff_t *tvb, proto_tree *swrjt_tree, guint8 isreq _U_)
1655 {
1656     /* Set up structures needed to add the protocol subtree and manage it */
1657     int offset = 0;
1658
1659     if (swrjt_tree) {
1660         proto_tree_add_item (swrjt_tree, hf_swils_rjt, tvb, offset+5, 1, 0);
1661         proto_tree_add_item (swrjt_tree, hf_swils_rjtdet, tvb, offset+6, 1, 0);
1662         proto_tree_add_item (swrjt_tree, hf_swils_rjtvendor, tvb, offset+7,
1663                              1, 0);
1664     }
1665 }
1666
1667 static void
1668 dissect_swils_ess (tvbuff_t *tvb, proto_tree *ess_tree, guint8 isreq _U_)
1669 {
1670     int offset = 0;
1671     gint16 numcapobj = 0;
1672     gint len = 0;
1673     gint capobjlen = 0;
1674     proto_item *ti = NULL;
1675     proto_tree *ieinfo_tree = NULL;
1676
1677     if (!ess_tree) {
1678         return;
1679     }
1680
1681     proto_tree_add_item (ess_tree, hf_swils_ess_rev, tvb, offset+4, 4, 0);
1682     proto_tree_add_item (ess_tree, hf_swils_ess_len, tvb, offset+8, 4, 0);
1683     len = tvb_get_ntohl (tvb, offset+8);
1684
1685     ti = proto_tree_add_text (ess_tree, tvb, offset+12,
1686                               MAX_INTERCONNECT_ELEMENT_INFO_LEN+4,
1687                               "Interconnect Element Info");
1688     ieinfo_tree = proto_item_add_subtree (ti, ett_fcswils_ieinfo);
1689     dissect_swils_interconnect_element_info (tvb, ieinfo_tree, offset+12);
1690     len -= 256;                /* the interconnect obj above is 256 bytes */
1691     offset += 268;
1692
1693     proto_tree_add_item (ess_tree, hf_swils_ess_numobj, tvb, offset, 2, 0);
1694     numcapobj = tvb_get_ntohs (tvb, offset);
1695
1696     len -= 4;                  /* 2B numcapobj + 2B rsvd */
1697     offset += 4;
1698
1699     while ((len > 0) && (numcapobj > 0)) {
1700         capobjlen = dissect_swils_ess_capability_obj (tvb, ess_tree, offset);
1701         numcapobj--;
1702         len -= capobjlen;
1703         offset += capobjlen;
1704     }
1705 }
1706
1707 static void
1708 dissect_swils_mrra (tvbuff_t *tvb, proto_tree *tree, guint8 isreq)
1709 {
1710
1711     int offset = 0;
1712
1713     if (!tree) {
1714         return;
1715     }
1716
1717     if (isreq) {
1718         proto_tree_add_item (tree, hf_swils_mrra_rev, tvb, offset+4, 4, 0);
1719         proto_tree_add_item (tree, hf_swils_mrra_size, tvb, offset+8, 4, 0);
1720         proto_tree_add_item (tree, hf_swils_mrra_vendorid, tvb, offset+12, 8, 0);
1721         proto_tree_add_item (tree, hf_swils_mrra_vendorinfo, tvb, offset+20,
1722                              8, 0);
1723     } else {
1724         proto_tree_add_item (tree, hf_swils_mrra_vendorid, tvb, offset+4,
1725                              8, 0);
1726         proto_tree_add_item (tree, hf_swils_mrra_reply, tvb, offset+12,
1727                              4, 0);
1728         proto_tree_add_item (tree, hf_swils_mrra_reply_size, tvb, offset+16,
1729                              4, 0);
1730         proto_tree_add_item (tree, hf_swils_mrra_waittime, tvb, offset+20,
1731                              4, 0);
1732     }
1733
1734
1735 }
1736
1737 static fcswils_func_table_t fcswils_func_table[FC_SWILS_MAXCODE] = {
1738     /* 0x00 */ {NULL},
1739     /* 0x01 */ {dissect_swils_swrjt},
1740     /* 0x02 */ {NULL},
1741     /* 0x03 */ {NULL},
1742     /* 0x04 */ {NULL},
1743     /* 0x05 */ {NULL},
1744     /* 0x06 */ {NULL},
1745     /* 0x07 */ {NULL},
1746     /* 0x08 */ {NULL},
1747     /* 0x09 */ {NULL},
1748     /* 0x0a */ {NULL},
1749     /* 0x0b */ {NULL},
1750     /* 0x0c */ {NULL},
1751     /* 0x0d */ {NULL},
1752     /* 0x0e */ {NULL},
1753     /* 0x0f */ {NULL},
1754     /* 0x10 */ {dissect_swils_elp},
1755     /* 0x11 */ {dissect_swils_efp},
1756     /* 0x12 */ {dissect_swils_dia},
1757     /* 0x13 */ {dissect_swils_rdi},
1758     /* 0x14 */ {dissect_swils_hello},
1759     /* 0x15 */ {dissect_swils_lsupdate},
1760     /* 0x16 */ {dissect_swils_lsack},
1761     /* 0x17 */ {dissect_swils_nullpayload},
1762     /* 0x18 */ {dissect_swils_nullpayload},
1763     /* 0x19 */ {NULL},
1764     /* 0x1a */ {NULL},
1765     /* 0x1b */ {dissect_swils_rscn},
1766     /* 0x1c */ {NULL},
1767     /* 0x1d */ {NULL},
1768     /* 0x1e */ {dissect_swils_drlir},
1769     /* 0x1f */ {NULL},
1770     /* 0x20 */ {NULL /*dissect_swils_dscn*/},
1771     /* 0x21 */ {NULL /*dissect_swils_loopd*/},
1772     /* 0x22 */ {dissect_swils_mergereq},
1773     /* 0x23 */ {dissect_swils_aca},
1774     /* 0x24 */ {dissect_swils_rca},
1775     /* 0x25 */ {dissect_swils_sfc},
1776     /* 0x26 */ {dissect_swils_ufc},
1777     /* 0x27 */ {NULL},
1778     /* 0x28 */ {NULL},
1779     /* 0x29 */ {NULL},
1780     /* 0x2a */ {NULL},
1781     /* 0x2b */ {NULL},
1782     /* 0x2c */ {NULL},
1783     /* 0x2d */ {NULL},
1784     /* 0x2e */ {NULL},
1785     /* 0x2f */ {NULL},
1786     /* 0x30 */ {dissect_swils_esc},
1787     /* 0x31 */ {dissect_swils_ess},
1788     /* 0x32 */ {NULL},
1789     /* 0x33 */ {NULL},
1790     /* 0x34 */ {dissect_swils_mrra}
1791 };
1792
1793 /* Code to actually dissect the packets */
1794 static void
1795 dissect_fcswils (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1796 {
1797     proto_item *ti = NULL;
1798     guint8 opcode,
1799         failed_opcode = 0;
1800     int offset = 0;
1801     conversation_t *conversation;
1802     fcswils_conv_data_t *cdata;
1803     fcswils_conv_key_t ckey, *req_key;
1804     proto_tree *swils_tree = NULL;
1805     guint8 isreq = FC_SWILS_REQ;
1806     tvbuff_t *next_tvb;
1807
1808     /* Make entries in Protocol column and Info column on summary display */
1809     col_set_str(pinfo->cinfo, COL_PROTOCOL, "SW_ILS");
1810
1811     /* decoding of this is done by each individual opcode handler */
1812     opcode = tvb_get_guint8 (tvb, 0);
1813
1814     if (tree) {
1815         ti = proto_tree_add_protocol_format (tree, proto_fcswils, tvb, 0,
1816                                              tvb_length (tvb), "SW_ILS");
1817         swils_tree = proto_item_add_subtree (ti, ett_fcswils);
1818     }
1819
1820     /* Register conversation if this is not a response */
1821     if ((opcode != FC_SWILS_SWACC) && (opcode != FC_SWILS_SWRJT)) {
1822         conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1823                                           pinfo->ptype, pinfo->oxid,
1824                                           pinfo->rxid, NO_PORT2);
1825         if (!conversation) {
1826             conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1827                                              pinfo->ptype, pinfo->oxid,
1828                                              pinfo->rxid, NO_PORT2);
1829         }
1830
1831         ckey.conv_idx = conversation->index;
1832
1833         cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash,
1834                                                             &ckey);
1835         if (cdata) {
1836             /* Since we never free the memory used by an exchange, this maybe a
1837              * case of another request using the same exchange as a previous
1838              * req.
1839              */
1840             cdata->opcode = opcode;
1841         }
1842         else {
1843             req_key = se_alloc (sizeof(fcswils_conv_key_t));
1844             req_key->conv_idx = conversation->index;
1845
1846             cdata = se_alloc (sizeof(fcswils_conv_data_t));
1847             cdata->opcode = opcode;
1848
1849             g_hash_table_insert (fcswils_req_hash, req_key, cdata);
1850         }
1851     }
1852     else {
1853         /* Opcode is ACC or RJT */
1854         conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1855                                           pinfo->ptype, pinfo->oxid,
1856                                           pinfo->rxid, NO_PORT2);
1857         isreq = FC_SWILS_RPLY;
1858         if (!conversation) {
1859             if (tree && (opcode == FC_SWILS_SWACC)) {
1860                 /* No record of what this accept is for. Can't decode */
1861                 proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1862                                      "No record of Exchg. Unable to decode SW_ACC");
1863                 return;
1864             }
1865         }
1866         else {
1867             ckey.conv_idx = conversation->index;
1868
1869             cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash, &ckey);
1870
1871             if (cdata != NULL) {
1872                 if (opcode == FC_SWILS_SWACC)
1873                     opcode = cdata->opcode;
1874                 else
1875                     failed_opcode = cdata->opcode;
1876             }
1877
1878             if (tree) {
1879                 if ((cdata == NULL) && (opcode != FC_SWILS_SWRJT)) {
1880                     /* No record of what this accept is for. Can't decode */
1881                     proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1882                                          "No record of SW_ILS Req. Unable to decode SW_ACC");
1883                     return;
1884                 }
1885             }
1886         }
1887     }
1888
1889     if (check_col (pinfo->cinfo, COL_INFO)) {
1890         if (isreq == FC_SWILS_REQ) {
1891             col_add_str (pinfo->cinfo, COL_INFO,
1892                          val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1893         }
1894         else if (opcode == FC_SWILS_SWRJT) {
1895             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_RJT (%s)",
1896                           val_to_str (failed_opcode, fc_swils_opcode_key_val, "0x%x"));
1897         }
1898         else {
1899             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_ACC (%s)",
1900                           val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1901         }
1902     }
1903
1904     if (tree) {
1905         proto_tree_add_item (swils_tree, hf_swils_opcode, tvb, offset, 1, 0);
1906     }
1907
1908     if ((opcode < FC_SWILS_MAXCODE) && fcswils_func_table[opcode].func) {
1909          fcswils_func_table[opcode].func (tvb, swils_tree, isreq);
1910     } else if (opcode == FC_SWILS_AUTH_ILS) {
1911          /* This is treated differently */
1912          if (isreq && fcsp_handle)
1913               call_dissector (fcsp_handle, tvb, pinfo, swils_tree);
1914     } else {
1915          /* data dissector */
1916          next_tvb = tvb_new_subset_remaining (tvb, offset+4);
1917          call_dissector (data_handle, next_tvb, pinfo, tree);
1918     }
1919
1920 }
1921
1922 /* Register the protocol with Wireshark */
1923
1924 /* this format is require because a script is used to build the C function
1925    that calls all the protocol registration.
1926 */
1927
1928 void
1929 proto_register_fcswils (void)
1930 {
1931 /* Setup list of header fields  See Section 1.6.1 for details*/
1932     static hf_register_info hf[] = {
1933         { &hf_swils_opcode,
1934           {"Cmd Code", "swils.opcode",
1935            FT_UINT8, BASE_HEX, VALS (fc_swils_opcode_key_val), 0x0, NULL, HFILL}},
1936         { &hf_swils_elp_rev,
1937           {"Revision", "swils.elp.rev",
1938            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1939         { &hf_swils_elp_flags,
1940           {"Flag", "swils.elp.flag",
1941            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1942         { &hf_swils_elp_r_a_tov,
1943           {"R_A_TOV", "swils.elp.ratov",
1944            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1945         { &hf_swils_elp_e_d_tov,
1946           {"E_D_TOV", "swils.elp.edtov",
1947            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1948         { &hf_swils_elp_req_epn,
1949           {"Req Eport Name", "swils.elp.reqepn",
1950            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1951         { &hf_swils_elp_req_esn,
1952           {"Req Switch Name", "swils.elp.reqesn",
1953            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1954         { &hf_swils_elp_clsf_svcp,
1955           {"Class F Svc Param", "swils.elp.clsfp",
1956            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1957         { &hf_swils_elp_clsf_rcvsz,
1958           {"Max Class F Frame Size", "swils.elp.clsfrsz",
1959            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1960         { &hf_swils_elp_clsf_conseq,
1961           {"Class F Max Concurrent Seq", "swils.elp.clsfcs",
1962            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1963         { &hf_swils_elp_clsf_e2e,
1964           {"Class F E2E Credit", "swils.elp.cfe2e",
1965            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1966         { &hf_swils_elp_clsf_openseq,
1967           {"Class F Max Open Seq", "swils.elp.oseq",
1968            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1969         { &hf_swils_elp_cls1_svcp,
1970           {"Class 1 Svc Param", "swils.elp.cls1p",
1971            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1972         { &hf_swils_elp_cls1_rcvsz,
1973           {"Class 1 Frame Size", "swils.elp.cls1rsz",
1974            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1975         { &hf_swils_elp_cls2_svcp,
1976           {"Class 2 Svc Param", "swils.elp.cls2p",
1977            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1978         { &hf_swils_elp_cls2_rcvsz,
1979           {"Class 2 Frame Size", "swils.elp.cls1rsz",
1980            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1981         { &hf_swils_elp_cls3_svcp,
1982           {"Class 3 Svc Param", "swils.elp.cls3p",
1983            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1984         { &hf_swils_elp_cls3_rcvsz,
1985           {"Class 3 Frame Size", "swils.elp.cls1rsz",
1986            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1987         { &hf_swils_elp_isl_fc_mode,
1988           {"ISL Flow Ctrl Mode", "swils.elp.fcmode",
1989            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
1990         { &hf_swils_elp_fcplen,
1991           {"Flow Ctrl Param Len", "swils.elp.fcplen",
1992            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1993         { &hf_swils_elp_b2bcredit,
1994           {"B2B Credit", "swils.elp.b2b",
1995            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1996         { &hf_swils_elp_compat1,
1997           {"Compatibility Param 1", "swils.elp.compat1",
1998            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
1999         { &hf_swils_elp_compat2,
2000           {"Compatibility Param 2", "swils.elp.compat2",
2001            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2002         { &hf_swils_elp_compat3,
2003           {"Compatibility Param 3", "swils.elp.compat3",
2004            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2005         { &hf_swils_elp_compat4,
2006           {"Compatibility Param 4", "swils.elp.compat4",
2007            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2008         { &hf_swils_efp_rec_type,
2009           {"Record Type", "swils.efp.rectype",
2010            FT_UINT8, BASE_HEX, VALS (fcswils_rectype_val), 0x0, NULL, HFILL}},
2011         { &hf_swils_efp_dom_id,
2012           {"Domain ID", "swils.efp.domid",
2013            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2014         { &hf_swils_efp_switch_name,
2015           {"Switch Name", "swils.efp.sname",
2016            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2017         { &hf_swils_efp_mcast_grpno,
2018           {"Mcast Grp#", "swils.efp.mcastno",
2019            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2020         { &hf_swils_efp_alias_token,
2021           {"Alias Token", "swils.efp.aliastok",
2022            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2023         { &hf_swils_efp_record_len,
2024           {"Record Len", "swils.efp.recordlen",
2025            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2026         { &hf_swils_efp_payload_len,
2027           {"Payload Len", "swils.efp.payloadlen",
2028            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2029         { &hf_swils_efp_pswitch_pri,
2030           {"Principal Switch Priority", "swils.efp.psprio",
2031            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2032         { &hf_swils_efp_pswitch_name,
2033           {"Principal Switch Name", "swils.efp.psname",
2034            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2035         { &hf_swils_dia_switch_name,
2036           {"Switch Name", "swils.dia.sname",
2037            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2038         { &hf_swils_rdi_payload_len,
2039           {"Payload Len", "swils.rdi.len",
2040            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2041         { &hf_swils_rdi_req_sname,
2042           {"Req Switch Name", "swils.rdi.reqsn",
2043            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2044         { &hf_swils_fspfh_cmd,
2045           {"Command:", "swils.fspf.cmd",
2046            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2047         { &hf_swils_fspfh_rev,
2048           {"Version", "swils.fspf.ver",
2049            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2050         { &hf_swils_fspfh_ar_num,
2051           {"AR Number", "swils.fspf.arnum",
2052            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2053         { &hf_swils_fspfh_auth_type,
2054           {"Authentication Type", "swils.fspf.authtype",
2055            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2056         { &hf_swils_fspfh_dom_id,
2057           {"Originating Domain ID", "swils.fspf.origdomid",
2058            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2059         { &hf_swils_fspfh_auth,
2060           {"Authentication", "swils.fspf.auth",
2061            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2062         { &hf_swils_hlo_options,
2063           {"Options", "swils.hlo.options",
2064            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2065         { &hf_swils_hlo_hloint,
2066           {"Hello Interval (secs)", "swils.hlo.hloint",
2067            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2068         { &hf_swils_hlo_deadint,
2069           {"Dead Interval (secs)", "swils.hlo.deadint",
2070            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2071         { &hf_swils_hlo_rcv_domid,
2072           {"Recipient Domain ID", "swils.hlo.rcvdomid",
2073            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2074         { &hf_swils_hlo_orig_pidx,
2075           {"Originating Port Idx", "swils.hlo.origpidx",
2076            FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2077         { &hf_swils_lsrh_lsr_type,
2078           {"LSR Type", "swils.lsr.type",
2079            FT_UINT8, BASE_HEX, VALS (fc_swils_fspf_linkrec_val), 0x0, NULL, HFILL}},
2080         { &hf_swils_lsrh_lsid,
2081           {"Link State Id", "swils.ls.id",
2082            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2083         { &hf_swils_lsrh_adv_domid,
2084           {"Advertising Domain Id", "swils.lsr.advdomid",
2085            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2086         { &hf_swils_lsrh_ls_incid,
2087           {"LS Incarnation Number", "swils.lsr.incid",
2088            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2089         { &hf_swils_ldrec_linkid,
2090           {"Link ID", "swils.ldr.linkid",
2091            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2092         { &hf_swils_ldrec_out_pidx,
2093           {"Output Port Idx", "swils.ldr.out_portidx",
2094            FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2095         { &hf_swils_ldrec_nbr_pidx,
2096           {"Neighbor Port Idx", "swils.ldr.nbr_portidx",
2097            FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2098         { &hf_swils_ldrec_link_type,
2099           {"Link Type", "swils.ldr.linktype",
2100            FT_UINT8, BASE_HEX, VALS (fc_swils_link_type_val), 0x0, NULL, HFILL}},
2101         { &hf_swils_ldrec_link_cost,
2102           {"Link Cost", "swils.ldr.linkcost",
2103            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2104         { &hf_swils_rscn_evtype,
2105           {"Event Type", "swils.rscn.evtype",
2106            FT_UINT8, BASE_DEC, VALS (fc_swils_rscn_portstate_val), 0xF0, NULL, HFILL}},
2107         { &hf_swils_rscn_addrfmt,
2108           {"Address Format", "swils.rscn.addrfmt",
2109            FT_UINT8, BASE_DEC, VALS (fc_swils_rscn_addrfmt_val), 0x0F, NULL, HFILL}},
2110         { &hf_swils_rscn_affectedport,
2111           {"Affected Port ID", "swils.rscn.affectedport",
2112            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2113         { &hf_swils_rscn_detectfn,
2114           {"Detection Function", "swils.rscn.detectfn",
2115            FT_UINT32, BASE_HEX, VALS (fc_swils_rscn_detectfn_val), 0x0, NULL, HFILL}},
2116         { &hf_swils_rscn_portstate,
2117           {"Port State", "swils.rscn.portstate",
2118            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2119         { &hf_swils_rscn_portid,
2120           {"Port Id", "swils.rscn.portid",
2121            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2122         { &hf_swils_rscn_pwwn,
2123           {"Port WWN", "swils.rscn.pwwn",
2124            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2125         { &hf_swils_rscn_nwwn,
2126           {"Node WWN", "swils.rscn.nwwn",
2127            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2128         { &hf_swils_esc_swvendorid,
2129           {"Switch Vendor ID", "swils.esc.swvendor",
2130            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2131         { &hf_swils_esc_pdesc_vendorid,
2132           {"Vendor ID", "swils.esc.vendorid",
2133            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2134         { &hf_swils_esc_protocolid,
2135           {"Protocol ID", "swils.esc.protocol",
2136            FT_UINT16, BASE_HEX, VALS (fc_swils_esc_protocol_val), 0x0, NULL, HFILL}},
2137         { &hf_swils_zone_activezonenm,
2138           {"Active Zoneset Name", "swils.mr.activezonesetname",
2139            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2140         { &hf_swils_zone_objname,
2141           {"Zone Object Name", "swils.zone.zoneobjname",
2142            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2143         { &hf_swils_zone_objtype,
2144           {"Zone Object Type", "swils.zone.zoneobjtype",
2145            FT_UINT8, BASE_HEX, VALS (fc_swils_zoneobj_type_val), 0x0, NULL, HFILL}},
2146         { &hf_swils_zone_mbrtype,
2147           {"Zone Member Type", "swils.zone.mbrtype",
2148            FT_UINT8, BASE_HEX, VALS (fc_swils_zonembr_type_val), 0x0, NULL, HFILL}},
2149         { &hf_swils_zone_protocol,
2150           {"Zone Protocol", "swils.zone.protocol",
2151            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2152         { &hf_swils_zone_mbrid,
2153           {"Member Identifier", "swils.zone.mbrid",
2154            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2155         { &hf_swils_zone_status,
2156           {"Zone Command Status", "swils.zone.status",
2157            FT_UINT8, BASE_HEX, VALS (fc_swils_mr_rsp_val), 0x0, 
2158            "Applies to MR, ACA, RCA, SFC, UFC", HFILL}},
2159         { &hf_swils_zone_reason,
2160           {"Zone Command Reason Code", "swils.zone.reason",
2161            FT_UINT8, BASE_HEX, VALS (fc_swils_mr_reason_val), 0x0, 
2162            "Applies to MR, ACA, RCA, SFC, UFC", HFILL}},
2163         { &hf_swils_aca_domainid,
2164           {"Known Domain ID", "swils.aca.domainid",
2165            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2166         { &hf_swils_sfc_opcode,
2167           {"Operation Request", "swils.sfc.opcode",
2168            FT_UINT8, BASE_HEX, VALS (fc_swils_sfc_op_val), 0x0, NULL, HFILL}},
2169         { &hf_swils_sfc_zonenm,
2170           {"Zone Set Name", "swils.sfc.zonename",
2171            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2172         { &hf_swils_rjt,
2173           {"Reason Code", "swils.rjt.reason",
2174            FT_UINT8, BASE_HEX, VALS (fc_swils_rjt_val), 0x0, NULL, HFILL}},
2175         { &hf_swils_rjtdet,
2176           {"Reason Code Explanantion", "swils.rjt.reasonexpl",
2177            FT_UINT8, BASE_HEX, VALS (fc_swils_deterr_val), 0x0, NULL, HFILL}},
2178         { &hf_swils_rjtvendor,
2179           {"Vendor Unique Error Code", "swils.rjt.vendor",
2180            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2181         { &hf_swils_zone_mbrid_lun,
2182           {"LUN", "swils.zone.lun",
2183            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2184         { &hf_swils_ess_rev,
2185           {"Revision", "swils.ess.revision",
2186            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2187         { &hf_swils_ess_len,
2188           {"Payload Length", "swils.ess.leb",
2189            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2190         { &hf_swils_ess_numobj,
2191           {"Number of Capability Objects", "swils.ess.numobj",
2192            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2193         { &hf_swils_interconnect_list_len,
2194           {"List Length", "swils.ess.listlen",
2195            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2196         { &hf_swils_ess_vendorname,
2197           {"Vendor Name", "swils.ess.vendorname",
2198            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2199         { &hf_swils_ess_modelname,
2200           {"Model Name", "swils.ess.modelname",
2201            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2202         { &hf_swils_ess_relcode,
2203           {"Release Code", "swils.ess.relcode",
2204            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2205         { &hf_swils_ess_vendorspecific,
2206           {"Vendor Specific", "swils.ess.vendorspecific",
2207            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2208         { &hf_swils_ess_cap_type,
2209           {"Type", "swils.ess.capability.type",
2210            FT_UINT8, BASE_DEC, VALS (fc_ct_gstype_vals), 0x0, NULL, HFILL}},
2211         { &hf_swils_ess_cap_subtype,
2212           {"Subtype", "swils.ess.capability.subtype",
2213            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2214         { &hf_swils_ess_cap_numentries,
2215           {"Number of Entries", "swils.ess.capability.numentries",
2216            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2217         { &hf_swils_ess_cap_svc,
2218           {"Service Name", "swils.ess.capability.service",
2219            FT_UINT8, BASE_DEC, VALS (fc_ct_gsserver_vals), 0x0, NULL, HFILL}},
2220         { &hf_swils_ess_dns_obj0h,
2221           {"Name Server Entry Object 00h Support", "swils.ess.capability.dns.obj0h",
2222            FT_BOOLEAN, 8, NULL, 0x1, NULL, HFILL}},
2223         { &hf_swils_ess_dns_obj1h,
2224           {"Name Server Entry Object 01h Support", "swils.ess.capability.dns.obj1h",
2225            FT_BOOLEAN, 8, NULL, 0x2, NULL, HFILL}},
2226         { &hf_swils_ess_dns_obj2h,
2227           {"Name Server Entry Object 02h Support", "swils.ess.capability.dns.obj2h",
2228            FT_BOOLEAN, 8, NULL, 0x4, NULL, HFILL}},
2229         { &hf_swils_ess_dns_obj3h,
2230           {"Name Server Entry Object 03h Support", "swils.ess.capability.dns.obj3h",
2231            FT_BOOLEAN, 8, NULL, 0x8, NULL, HFILL}},
2232         { &hf_swils_ess_dns_zlacc,
2233           {"GE_PT Zero Length Accepted", "swils.ess.capability.dns.zlacc",
2234            FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL}},
2235         { &hf_swils_ess_dns_vendor,
2236           {"Vendor Specific Flags", "swils.ess.capability.dns.vendor",
2237            FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2238         { &hf_swils_ess_fctlr_rscn,
2239           {"SW_RSCN Supported", "swils.ess.capability.fctlr.rscn",
2240            FT_BOOLEAN, 8, NULL, 0x1, NULL, HFILL}},
2241         { &hf_swils_ess_fctlr_vendor,
2242           {"Vendor Specific Flags", "swils.ess.capability.fctlr.vendor",
2243            FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}},
2244         { &hf_swils_ess_fcs_basic,
2245           {"Basic Configuration Services", "swils.ess.capability.fcs.basic",
2246            FT_BOOLEAN, 8, NULL, 0x1, NULL, HFILL}},
2247         { &hf_swils_ess_fcs_platform,
2248           {"Platform Configuration Services", "swils.ess.capability.fcs.platform",
2249            FT_BOOLEAN, 8, NULL, 0x2, NULL, HFILL}},
2250         { &hf_swils_ess_fcs_topology,
2251           {"Topology Discovery Services", "swils.ess.capability.fcs.topology",
2252            FT_BOOLEAN, 8, NULL, 0x4, NULL, HFILL}},
2253         { &hf_swils_ess_fcs_enhanced,
2254           {"Enhanced Configuration Services", "swils.ess.capability.fcs.enhanced",
2255            FT_BOOLEAN, 8, NULL, 0x8, NULL, HFILL}},
2256         { &hf_swils_ess_fzs_enh_supp,
2257           {"Enhanced Zoning Supported", "swils.ess.capability.fzs.ezonesupp",
2258            FT_BOOLEAN, 8, NULL, 0x1, NULL, HFILL}},
2259         { &hf_swils_ess_fzs_enh_ena,
2260           {"Enhanced Zoning Enabled", "swils.ess.capability.fzs.ezoneena",
2261            FT_BOOLEAN, 8, NULL, 0x2, NULL, HFILL}},
2262         { &hf_swils_ess_fzs_mr,
2263           {"Merge Control Setting", "swils.ess.capability.fzs.mr",
2264            FT_BOOLEAN, 8, NULL, 0x4, NULL, HFILL}},
2265         { &hf_swils_ess_fzs_defzone,
2266           {"Default Zone Setting", "swils.ess.capability.fzs.defzone",
2267            FT_BOOLEAN, 8, NULL, 0x8, NULL, HFILL}},
2268         { &hf_swils_ess_fzs_zsdb_supp,
2269           {"Zoneset Database Supported", "swils.ess.capability.fzs.zsdbsupp",
2270            FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL}},
2271         { &hf_swils_ess_fzs_zsdb_ena,
2272           {"Zoneset Database Enabled", "swils.ess.capability.fzs.zsdbena",
2273            FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL}},
2274         { &hf_swils_ess_fzs_adc_supp,
2275           {"Active Direct Command Supported", "swils.ess.capability.fzs.adcsupp",
2276            FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL}},
2277         { &hf_swils_ess_fzs_hardzone,
2278           {"Hard Zoning Supported", "swils.ess.capability.fzs.hardzone",
2279            FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL}},
2280         { &hf_swils_ess_cap_len,
2281           {"Length", "swils.ess.capability.length",
2282            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2283         { &hf_swils_ess_cap_t10,
2284           {"T10 Vendor ID", "swils.ess.capability.t10id",
2285            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2286         { &hf_swils_ess_cap_vendorobj,
2287           {"Vendor-Specific Info", "swils.ess.capability.vendorobj",
2288            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2289         { &hf_swils_mrra_rev,
2290           {"Revision", "swils.mrra.revision",
2291            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2292         { &hf_swils_mrra_size,
2293           {"Merge Request Size", "swils.mrra.size",
2294            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2295         { &hf_swils_mrra_vendorid,
2296           {"Vendor ID", "swils.mrra.vendorid",
2297            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2298         { &hf_swils_mrra_vendorinfo,
2299           {"Vendor-Specific Info", "swils.mrra.vendorinfo",
2300            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
2301         { &hf_swils_mrra_reply,
2302           {"MRRA Response", "swils.mrra.reply",
2303            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2304         { &hf_swils_mrra_reply_size,
2305           {"Maximum Resources Available", "swils.mrra.replysize",
2306            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2307         { &hf_swils_mrra_waittime,
2308           {"Waiting Period (secs)", "swils.mrra.waittime",
2309            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
2310     };
2311
2312     /* Setup protocol subtree array */
2313     static gint *ett[] = {
2314         &ett_fcswils,
2315         &ett_fcswils_swacc,
2316         &ett_fcswils_swrjt,
2317         &ett_fcswils_elp,
2318         &ett_fcswils_efp,
2319         &ett_fcswils_efplist,
2320         &ett_fcswils_dia,
2321         &ett_fcswils_rdi,
2322         &ett_fcswils_fspfhdr,
2323         &ett_fcswils_hlo,
2324         &ett_fcswils_lsrec,
2325         &ett_fcswils_lsrechdr,
2326         &ett_fcswils_ldrec,
2327         &ett_fcswils_lsu,
2328         &ett_fcswils_lsa,
2329         &ett_fcswils_bf,
2330         &ett_fcswils_rcf,
2331         &ett_fcswils_rscn,
2332         &ett_fcswils_rscn_dev,
2333         &ett_fcswils_drlir,
2334         &ett_fcswils_mr,
2335         &ett_fcswils_zoneobjlist,
2336         &ett_fcswils_zoneobj,
2337         &ett_fcswils_zonembr,
2338         &ett_fcswils_aca,
2339         &ett_fcswils_rca,
2340         &ett_fcswils_sfc,
2341         &ett_fcswils_ufc,
2342         &ett_fcswils_esc,
2343         &ett_fcswils_esc_pdesc,
2344         &ett_fcswils_ieinfo,
2345         &ett_fcswils_capinfo
2346     };
2347
2348     /* Register the protocol name and description */
2349     proto_fcswils = proto_register_protocol("Fibre Channel SW_ILS", "FC-SWILS", "swils");
2350
2351     /* Required function calls to register the header fields and subtrees used */
2352     proto_register_field_array(proto_fcswils, hf, array_length(hf));
2353     proto_register_subtree_array(ett, array_length(ett));
2354     register_init_routine(&fcswils_init_protocol);
2355 }
2356
2357 /* If this dissector uses sub-dissector registration add a registration routine.
2358    This format is required because a script is used to find these routines and
2359    create the code that calls these routines.
2360 */
2361 void
2362 proto_reg_handoff_fcswils (void)
2363 {
2364     dissector_handle_t swils_handle;
2365
2366     swils_handle = create_dissector_handle (dissect_fcswils, proto_fcswils);
2367     dissector_add("fc.ftype", FC_FTYPE_SWILS, swils_handle);
2368
2369     data_handle = find_dissector ("data");
2370     fcsp_handle = find_dissector ("fcsp");
2371 }