Update calls to proto_tree_add_bytes_format to reflect r27047.
[metze/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                                     "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             size_t stroff, returned_length;
776
777             flagsbuf=ep_alloc(MAX_FLAGS_LEN);
778             stroff = 0;
779             flagsbuf[stroff]=0;
780
781             returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff,
782                 "Class 1 Valid");
783             stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
784             if (elp.cls1_svcparm[0] & 0x40) {
785                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | IMX");
786                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
787             }
788             if (elp.cls1_svcparm[0] & 0x20) {
789                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | IPS");
790                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
791             }
792             if (elp.cls1_svcparm[0] & 0x10) {
793                 returned_length = g_snprintf (flagsbuf+stroff, MAX_FLAGS_LEN-stroff, " | LKS");
794                 stroff += MIN(returned_length, MAX_FLAGS_LEN-stroff);
795             }
796             flags=flagsbuf;
797         }
798         else {
799             flags="Class 1 Invalid";
800         }
801
802         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls1_svcp, 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                                      "Class 2 Svc Parameters: (%s)", flags);
825         offset += 2;
826
827         if (elp.cls2_svcparm[0] & 0x80) {
828             proto_tree_add_item (elp_tree, hf_swils_elp_cls2_rcvsz, tvb, offset, 2, 0);
829         }
830         offset += 2;
831
832         flags="";
833         if (elp.cls3_svcparm[0] & 0x80) {
834             if (elp.cls3_svcparm[0] & 0x08) {
835                 flags="Class 3 Valid | Seq Delivery";
836             }
837             else {
838                 flags="Class 3 Valid | No Seq Delivery";
839             }
840         }
841         else {
842             flags="Class 3 Invld";
843         }
844         proto_tree_add_bytes_format (elp_tree, hf_swils_elp_cls3_svcp, tvb, offset, 2,
845                                      "Class 3 Svc Parameters: (%s)", flags);
846         offset += 2;
847
848         if (elp.cls3_svcparm[0] & 0x80) {
849             proto_tree_add_item (elp_tree, hf_swils_elp_cls3_rcvsz, tvb, offset, 2, 0);
850         }
851         offset += 22;
852
853         proto_tree_add_string (elp_tree, hf_swils_elp_isl_fc_mode, tvb, offset, 2,
854                                val_to_str (elp.isl_flwctrl_mode, fcswils_elp_fc_val, "Vendor Unique"));
855         offset += 2;
856         proto_tree_add_item (elp_tree, hf_swils_elp_fcplen, tvb, offset, 2, 0);
857         offset += 2;
858         proto_tree_add_item (elp_tree, hf_swils_elp_b2bcredit, tvb, offset, 4, 0);
859         offset += 4;
860         proto_tree_add_item (elp_tree, hf_swils_elp_compat1, tvb, offset, 4, 0);
861         offset += 4;
862         proto_tree_add_item (elp_tree, hf_swils_elp_compat2, tvb, offset, 4, 0);
863         offset += 4;
864         proto_tree_add_item (elp_tree, hf_swils_elp_compat3, tvb, offset, 4, 0);
865         offset += 4;
866         proto_tree_add_item (elp_tree, hf_swils_elp_compat4, tvb, offset, 4, 0);
867     }
868
869 }
870
871 static void
872 dissect_swils_efp (tvbuff_t *tvb, proto_tree *efp_tree, guint8 isreq _U_)
873 {
874
875 /* Set up structures needed to add the protocol subtree and manage it */
876     proto_item *subti;
877     proto_tree *lrec_tree;
878     int num_listrec = 0,
879         offset = 0;
880     fcswils_efp efp;
881     guint8 rec_type;
882
883     offset += 1;
884     efp.reclen = tvb_get_guint8 (tvb, offset);
885     if (efp_tree)
886         proto_tree_add_uint (efp_tree, hf_swils_efp_record_len, tvb, offset, 1, efp.reclen);
887     offset += 1;
888     efp.payload_len = tvb_get_ntohs (tvb, offset);
889     if (efp.payload_len < FC_SWILS_EFP_SIZE) {
890         if (efp_tree)
891             proto_tree_add_uint_format (efp_tree, hf_swils_efp_payload_len,
892                                         tvb, offset, 2, efp.payload_len,
893                                         "Payload Len: %u (bogus, must be >= %u)",
894                                         efp.payload_len, FC_SWILS_EFP_SIZE);
895         return;
896     }
897     if (efp_tree)
898         proto_tree_add_item (efp_tree, hf_swils_efp_payload_len, tvb, offset, 2, 0);
899     offset += 5;        /* skip 3 reserved bytes, too */
900     if (efp_tree)
901         proto_tree_add_item (efp_tree, hf_swils_efp_pswitch_pri, tvb,
902                              offset, 1, FALSE);
903     offset++;
904     tvb_memcpy (tvb, efp.pswitch_name, offset, 8);
905     if (efp_tree)
906         proto_tree_add_string (efp_tree, hf_swils_efp_pswitch_name, tvb, offset,
907                                8, fcwwn_to_str (efp.pswitch_name));
908     offset += 8;
909
910     /* Add List Records now */
911     if (efp_tree) {
912         if (efp.reclen == 0) {
913             proto_tree_add_text (efp_tree, tvb, 0, 0, "Record length is zero");
914             return;
915         }
916         num_listrec = (efp.payload_len - FC_SWILS_EFP_SIZE)/efp.reclen;
917         while (num_listrec-- > 0) {
918             rec_type = tvb_get_guint8 (tvb, offset);
919             subti = proto_tree_add_text (efp_tree, tvb, offset, -1,
920                                          "%s",
921                                          val_to_str(rec_type,
922                                                     fcswils_rectype_val,
923                                                     "Unknown record type (0x%02x)"));
924             lrec_tree = proto_item_add_subtree (subti, ett_fcswils_efplist);
925             proto_tree_add_uint (lrec_tree, hf_swils_efp_rec_type, tvb, offset, 1,
926                                  rec_type);
927             switch (rec_type) {
928
929             case FC_SWILS_LRECTYPE_DOMAIN:
930                 proto_tree_add_item (lrec_tree, hf_swils_efp_dom_id, tvb, offset+1, 1, 0);
931                 proto_tree_add_string (lrec_tree, hf_swils_efp_switch_name, tvb, offset+8, 8,
932                                        fcwwn_to_str (tvb_get_ptr(tvb, offset+8, 8)));
933                 break;
934
935             case FC_SWILS_LRECTYPE_MCAST:
936                 proto_tree_add_item (lrec_tree, hf_swils_efp_mcast_grpno, tvb, offset+1, 1, 0);
937                 break;
938             }
939             offset += efp.reclen;
940         }
941     }
942 }
943
944 static void
945 dissect_swils_dia (tvbuff_t *tvb, proto_tree *dia_tree, guint8 isreq _U_)
946 {
947     /* Set up structures needed to add the protocol subtree and manage it */
948     int offset = 0;
949
950     if (dia_tree) {
951         proto_tree_add_string (dia_tree, hf_swils_dia_switch_name, tvb, offset+4,
952                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
953     }
954 }
955
956 static void
957 dissect_swils_rdi (tvbuff_t *tvb, proto_tree *rdi_tree, guint8 isreq)
958 {
959     /* Set up structures needed to add the protocol subtree and manage it */
960     int offset = 0;
961     int i, plen, numrec;
962
963     if (rdi_tree) {
964         plen = tvb_get_ntohs (tvb, offset+2);
965
966         proto_tree_add_item (rdi_tree, hf_swils_rdi_payload_len, tvb, offset+2, 2, 0);
967         proto_tree_add_string (rdi_tree, hf_swils_rdi_req_sname, tvb, offset+4,
968                                8, fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
969
970         /* 12 is the length of the initial header and 4 is the size of each
971          * domain request record.
972          */
973         numrec = (plen - 12)/4;
974         offset = 12;
975         for (i = 0; i < numrec; i++) {
976             if (isreq) {
977                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
978                                      "Requested Domain ID: %d",
979                                      tvb_get_guint8 (tvb, offset+3));
980             }
981             else {
982                 proto_tree_add_text (rdi_tree, tvb, offset+3, 1,
983                                      "Granted Domain ID: %d",
984                                      tvb_get_guint8 (tvb, offset+3));
985             }
986             offset += 4;
987         }
988     }
989 }
990
991 static void
992 dissect_swils_fspf_hdr (tvbuff_t *tvb, proto_tree *tree, int offset)
993 {
994     proto_item *subti;
995     proto_tree *fspfh_tree;
996
997     if (tree) {
998         /* 20 is the size of FSPF header */
999         subti = proto_tree_add_text (tree, tvb, offset, 20, "FSPF Header");
1000         fspfh_tree = proto_item_add_subtree (subti, ett_fcswils_fspfhdr);
1001
1002         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_rev, tvb, offset+4,
1003                              1, 0);
1004         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_ar_num, tvb,
1005                              offset+5, 1, 0);
1006         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth_type, tvb,
1007                              offset+6, 1, 0);
1008         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_dom_id, tvb, offset+11,
1009                              1, 0);
1010         proto_tree_add_item (fspfh_tree, hf_swils_fspfh_auth, tvb, offset+12,
1011                              8, 0);
1012     }
1013 }
1014
1015 static void
1016 dissect_swils_fspf_lsrechdr (tvbuff_t *tvb, proto_tree *tree, int offset)
1017 {
1018     proto_tree_add_item (tree, hf_swils_lsrh_lsr_type, tvb, offset, 1, 0);
1019     proto_tree_add_text (tree, tvb, offset+2, 2, "LSR Age: %d secs",
1020                          tvb_get_ntohs (tvb, offset+2));
1021     proto_tree_add_text (tree, tvb, offset+4, 4, "Options : 0x%x",
1022                          tvb_get_ntohl (tvb, offset+4));
1023     proto_tree_add_item (tree, hf_swils_lsrh_lsid, tvb, offset+11, 1, 0);
1024     proto_tree_add_item (tree, hf_swils_lsrh_adv_domid, tvb, offset+15, 1, 0);
1025     proto_tree_add_item (tree, hf_swils_lsrh_ls_incid, tvb, offset+16, 4, 0);
1026     proto_tree_add_text (tree, tvb, offset+20, 2, "Checksum: 0x%x",
1027                          tvb_get_ntohs (tvb, offset+20));
1028     proto_tree_add_text (tree, tvb, offset+22, 2, "LSR Length: %d",
1029                          tvb_get_ntohs (tvb, offset+22));
1030 }
1031
1032 static void
1033 dissect_swils_fspf_ldrec (tvbuff_t *tvb, proto_tree *tree, int offset)
1034 {
1035     proto_tree_add_string (tree, hf_swils_ldrec_linkid, tvb, offset, 4,
1036                            fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
1037     proto_tree_add_item (tree, hf_swils_ldrec_out_pidx, tvb, offset+5, 3, 0);
1038     proto_tree_add_item (tree, hf_swils_ldrec_nbr_pidx, tvb, offset+9, 3, 0);
1039     proto_tree_add_item (tree, hf_swils_ldrec_link_type, tvb, offset+12, 1, 0);
1040     proto_tree_add_item (tree, hf_swils_ldrec_link_cost, tvb, offset+14, 2, 0);
1041 }
1042
1043 static void
1044 dissect_swils_fspf_lsrec (tvbuff_t *tvb, proto_tree *tree, int offset,
1045                           int num_lsrec)
1046 {
1047     int i, j, num_ldrec;
1048     proto_item *subti1, *subti;
1049     proto_tree *lsrec_tree, *ldrec_tree, *lsrechdr_tree;
1050
1051     if (tree) {
1052         for (j = 0; j < num_lsrec; j++) {
1053             num_ldrec = tvb_get_ntohs (tvb, offset+26);
1054             subti = proto_tree_add_text (tree, tvb, offset, (28+num_ldrec*16),
1055                                          "Link State Record %d (Domain %d)", j,
1056                                          tvb_get_guint8 (tvb, offset+15));
1057             lsrec_tree = proto_item_add_subtree (subti, ett_fcswils_lsrec);
1058
1059             subti = proto_tree_add_text (lsrec_tree, tvb, offset, 24,
1060                                          "Link State Record Header");
1061             lsrechdr_tree = proto_item_add_subtree (subti,
1062                                                     ett_fcswils_lsrechdr);
1063
1064             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
1065             proto_tree_add_text (tree, tvb, offset+26, 2, "Number of Links: %d",
1066                                  num_ldrec);
1067             offset += 28;
1068
1069             for (i = 0; i < num_ldrec; i++) {
1070                 subti1 = proto_tree_add_text (lsrec_tree, tvb, offset, 16,
1071                                               "Link Descriptor %d "
1072                                               "(Neighbor domain %d)", i,
1073                                               tvb_get_guint8 (tvb, offset+3));
1074                 ldrec_tree = proto_item_add_subtree (subti1, ett_fcswils_ldrec);
1075                 dissect_swils_fspf_ldrec (tvb, ldrec_tree, offset);
1076                 offset += 16;
1077             }
1078         }
1079     }
1080 }
1081
1082 static void
1083 dissect_swils_hello (tvbuff_t *tvb, proto_tree *hlo_tree, guint8 isreq _U_)
1084 {
1085     /* Set up structures needed to add the protocol subtree and manage it */
1086     int offset = 0;
1087
1088     if (hlo_tree) {
1089         dissect_swils_fspf_hdr (tvb, hlo_tree, offset);
1090
1091         proto_tree_add_item (hlo_tree, hf_swils_hlo_options, tvb, offset+20, 4, 0);
1092         proto_tree_add_item (hlo_tree, hf_swils_hlo_hloint, tvb, offset+24, 4, 0);
1093         proto_tree_add_item (hlo_tree, hf_swils_hlo_deadint, tvb, offset+28, 4, 0);
1094         proto_tree_add_item (hlo_tree, hf_swils_hlo_rcv_domid, tvb, offset+35, 1, 0);
1095         proto_tree_add_item (hlo_tree, hf_swils_hlo_orig_pidx, tvb, offset+37, 3, 0);
1096     }
1097 }
1098
1099 static void
1100 dissect_swils_lsupdate (tvbuff_t *tvb, proto_tree *lsu_tree, guint8 isreq _U_)
1101 {
1102     /* Set up structures needed to add the protocol subtree and manage it */
1103     int offset = 0;
1104     int num_lsrec;
1105
1106     if (lsu_tree) {
1107         dissect_swils_fspf_hdr (tvb, lsu_tree, offset);
1108
1109         proto_tree_add_text (lsu_tree, tvb, offset+23, 1, "Flags : %s",
1110                              val_to_str (tvb_get_guint8 (tvb, offset+23),
1111                                          fc_swils_fspf_lsrflags_val, "0x%x"));
1112         num_lsrec = tvb_get_ntohl (tvb, offset+24);
1113
1114         proto_tree_add_text (lsu_tree, tvb, offset+24, 4, "Num of LSRs: %d",
1115                              num_lsrec);
1116
1117         offset = 28;
1118         dissect_swils_fspf_lsrec (tvb, lsu_tree, offset, num_lsrec);
1119     }
1120 }
1121
1122 static void
1123 dissect_swils_lsack (tvbuff_t *tvb, proto_tree *lsa_tree, guint8 isreq _U_)
1124 {
1125     /* Set up structures needed to add the protocol subtree and manage it */
1126     int offset = 0;
1127     int num_lsrechdr, i;
1128     proto_item *subti;
1129     proto_tree *lsrechdr_tree;
1130
1131     if (lsa_tree) {
1132         dissect_swils_fspf_hdr (tvb, lsa_tree, offset);
1133
1134         proto_tree_add_text (lsa_tree, tvb, offset+23, 1, "Flags : %s",
1135                              val_to_str (tvb_get_guint8 (tvb, offset+23),
1136                                          fc_swils_fspf_lsrflags_val, "0x%x"));
1137         num_lsrechdr = tvb_get_ntohl (tvb, offset+24);
1138
1139         proto_tree_add_text (lsa_tree, tvb, offset+24, 4, "Num of LSR Headers: %d",
1140                              num_lsrechdr);
1141
1142         offset = 28;
1143
1144         for (i = 0; i < num_lsrechdr; i++) {
1145             subti = proto_tree_add_text (lsa_tree, tvb, offset, 24,
1146                                          "Link State Record Header (Domain %d)",
1147                                          tvb_get_guint8 (tvb, offset+15));
1148             lsrechdr_tree = proto_item_add_subtree (subti,
1149                                                     ett_fcswils_lsrechdr);
1150             dissect_swils_fspf_lsrechdr (tvb, lsrechdr_tree, offset);
1151             offset += 24;
1152         }
1153     }
1154 }
1155
1156 static void
1157 dissect_swils_rscn (tvbuff_t *tvb, proto_tree *rscn_tree, guint8 isreq)
1158 {
1159     /* Set up structures needed to add the protocol subtree and manage it */
1160     int offset = 0;
1161     proto_tree *dev_tree;
1162     int addrfmt, evtype;
1163     int numrec, i;
1164     proto_item *subti;
1165
1166     if (rscn_tree) {
1167         if (!isreq)
1168             return;
1169
1170         evtype = tvb_get_guint8 (tvb, offset+4);
1171         addrfmt = evtype & 0x0F;
1172         evtype = evtype >> 4;
1173
1174         proto_tree_add_item (rscn_tree, hf_swils_rscn_evtype, tvb, offset+4,
1175                              1, 0);
1176         proto_tree_add_item (rscn_tree, hf_swils_rscn_addrfmt, tvb, offset+4,
1177                              1, 0);
1178         proto_tree_add_string (rscn_tree, hf_swils_rscn_affectedport, tvb,
1179                                offset+5, 3, fc_to_str (tvb_get_ptr (tvb,
1180                                                                     offset+5, 3)));
1181         proto_tree_add_item (rscn_tree, hf_swils_rscn_detectfn, tvb,
1182                              offset+8, 4, 0);
1183         numrec = tvb_get_ntohl (tvb, offset+12);
1184
1185         if (!tvb_bytes_exist (tvb, offset+16, FC_SWILS_RSCN_DEVENTRY_SIZE*numrec)) {
1186             /* Some older devices do not include device entry information. */
1187             return;
1188         }
1189
1190         proto_tree_add_text (rscn_tree, tvb, offset+12, 4, "Num Entries: %d",
1191                              numrec);
1192
1193         offset = 16;
1194         for (i = 0; i < numrec; i++) {
1195             subti = proto_tree_add_text (rscn_tree, tvb, offset, 20,
1196                                          "Device Entry %d", i);
1197             dev_tree = proto_item_add_subtree (rscn_tree, ett_fcswils_rscn_dev);
1198
1199             proto_tree_add_item (dev_tree, hf_swils_rscn_portstate, tvb, offset, 1, 0);
1200             proto_tree_add_string (dev_tree, hf_swils_rscn_portid, tvb, offset+1, 3,
1201                                    fc_to_str (tvb_get_ptr (tvb, offset+1, 3)));
1202             proto_tree_add_string (dev_tree, hf_swils_rscn_pwwn, tvb, offset+4, 8,
1203                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+4, 8)));
1204             proto_tree_add_string (dev_tree, hf_swils_rscn_nwwn, tvb, offset+12, 8,
1205                                    fcwwn_to_str (tvb_get_ptr (tvb, offset+12, 8)));
1206             offset += 20;
1207         }
1208     }
1209 }
1210
1211 /*
1212  * Merge Request contains zoning objects organized in the following format:
1213  *
1214  * Zone Set Object
1215  *      |
1216  *      +---------------- Zone Object
1217  *      |                      |
1218  *      +--                    +---------------- Zone Member
1219  *      |                      |                     |
1220  *      +--                    +----                 +-----
1221  *
1222  * So the decoding of the zone merge request is based on this structure
1223  */
1224
1225 static void
1226 dissect_swils_zone_mbr (tvbuff_t *tvb, proto_tree *zmbr_tree, int offset)
1227 {
1228     guint8 mbrtype;
1229     int idlen;
1230     char dpbuf[2+8+1];
1231     char *str;
1232
1233     mbrtype = tvb_get_guint8 (tvb, offset);
1234     proto_tree_add_uint (zmbr_tree, hf_swils_zone_mbrtype, tvb,
1235                          offset, 1, mbrtype);
1236     proto_tree_add_text (zmbr_tree, tvb, offset+2, 1, "Flags: 0x%x",
1237                          tvb_get_guint8 (tvb, offset+2));
1238     idlen = tvb_get_guint8 (tvb, offset+3);
1239     proto_tree_add_text (zmbr_tree, tvb, offset+3, 1,
1240                          "Identifier Length: %u", idlen);
1241     switch (mbrtype) {
1242     case FC_SWILS_ZONEMBR_WWN:
1243         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1244                                offset+4, 8,
1245                                fcwwn_to_str (tvb_get_ptr (tvb,
1246                                                           offset+4,
1247                                                           8)));
1248         break;
1249     case FC_SWILS_ZONEMBR_DP:
1250         g_snprintf(dpbuf, sizeof(dpbuf), "0x%08x", tvb_get_ntohl (tvb, offset+4));
1251         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1252                                offset+4, 4, dpbuf);
1253         break;
1254     case FC_SWILS_ZONEMBR_FCID:
1255         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1256                                offset+4, 4,
1257                                fc_to_str (tvb_get_ptr (tvb,
1258                                                        offset+5,
1259                                                        3)));
1260         break;
1261     case FC_SWILS_ZONEMBR_ALIAS:
1262         str = zonenm_to_str (tvb, offset+4);
1263         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1264                                offset+4, idlen, str);
1265         break;
1266     case FC_SWILS_ZONEMBR_WWN_LUN:
1267         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1268                                offset+4, 8,
1269                                fcwwn_to_str (tvb_get_ptr (tvb,
1270                                                           offset+4,
1271                                                           8)));
1272         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1273                              offset+12, 8, 0);
1274         break;
1275     case FC_SWILS_ZONEMBR_DP_LUN:
1276         g_snprintf(dpbuf, sizeof(dpbuf), "0x%08x", tvb_get_ntohl (tvb, offset+4));
1277         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1278                                offset+4, 4, dpbuf);
1279         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1280                              offset+8, 8, FALSE);
1281         break;
1282     case FC_SWILS_ZONEMBR_FCID_LUN:
1283         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1284                                offset+4, 4,
1285                                fc_to_str (tvb_get_ptr (tvb,
1286                                                        offset+5,
1287                                                        3)));
1288         proto_tree_add_item (zmbr_tree, hf_swils_zone_mbrid_lun, tvb,
1289                              offset+8, 8, 0);
1290         break;
1291     default:
1292         proto_tree_add_string (zmbr_tree, hf_swils_zone_mbrid, tvb,
1293                                offset+4, idlen,
1294                                "Unknown member type format");
1295
1296     }
1297 }
1298
1299 static void
1300 dissect_swils_zone_obj (tvbuff_t *tvb, proto_tree *zobj_tree, int offset)
1301 {
1302     proto_tree *zmbr_tree;
1303     int mbrlen, numrec, i, objtype;
1304     char *str;
1305     proto_item *subti;
1306
1307     objtype = tvb_get_guint8 (tvb, offset);
1308
1309     proto_tree_add_item (zobj_tree, hf_swils_zone_objtype, tvb, offset,
1310                          1, 0);
1311     proto_tree_add_item (zobj_tree, hf_swils_zone_protocol, tvb,
1312                          offset+1, 1, 0);
1313     str = zonenm_to_str (tvb, offset+4);
1314     proto_tree_add_string (zobj_tree, hf_swils_zone_objname, tvb,
1315                            offset+4, ZONENAME_LEN (tvb, offset+4), str);
1316
1317     numrec = tvb_get_ntohl (tvb, offset+4+ZONENAME_LEN (tvb, offset+4));
1318     proto_tree_add_text (zobj_tree, tvb,
1319                          offset+4+ZONENAME_LEN (tvb, offset+4), 4,
1320                          "Number of Zone Members: %d", numrec);
1321
1322     offset += 8 + ZONENAME_LEN (tvb, offset+4);
1323     for (i = 0; i < numrec; i++) {
1324         if (objtype == FC_SWILS_ZONEOBJ_ZONESET) {
1325             dissect_swils_zone_obj (tvb, zobj_tree, offset);
1326             offset += get_zoneobj_len (tvb, offset);
1327         }
1328         else {
1329             mbrlen = 4 + tvb_get_guint8 (tvb, offset+3);
1330             subti = proto_tree_add_text (zobj_tree, tvb, offset, mbrlen,
1331                                          "Zone Member %d", i);
1332             zmbr_tree = proto_item_add_subtree (zobj_tree,
1333                                                 ett_fcswils_zonembr);
1334             dissect_swils_zone_mbr (tvb, zmbr_tree, offset);
1335             offset += mbrlen;
1336         }
1337     }
1338 }
1339
1340 static void
1341 dissect_swils_mergereq (tvbuff_t *tvb, proto_tree *mr_tree, guint8 isreq)
1342 {
1343     /* Set up structures needed to add the protocol subtree and manage it */
1344     int offset = 0;
1345     proto_tree *zobjlist_tree, *zobj_tree;
1346     int numrec, i, zonesetlen, objlistlen, objlen;
1347     char *str;
1348     proto_item *subti;
1349
1350     if (mr_tree) {
1351         if (isreq) {
1352             /* zonesetlen is the size of the zoneset including the zone name */
1353             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1354             proto_tree_add_text (mr_tree, tvb, offset+2, 2,
1355                                  "Active ZoneSet Length: %u", zonesetlen);
1356
1357             if (zonesetlen) {
1358                 str = zonenm_to_str (tvb, offset+4);
1359                 proto_tree_add_string (mr_tree, hf_swils_zone_activezonenm, tvb,
1360                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1361                                        str);
1362
1363                 /* objlistlen gives the size of the active zoneset object list */
1364                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1365                 /* Offset = start of the active zoneset zoning object list */
1366                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1367                 numrec = tvb_get_ntohl (tvb, offset);
1368
1369                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1370                                              "Active Zone Set");
1371                 zobjlist_tree = proto_item_add_subtree (subti,
1372                                                         ett_fcswils_zoneobjlist);
1373
1374                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1375                                      "Number of zoning objects: %d", numrec);
1376
1377                 offset += 4;
1378                 for (i = 0; i < numrec; i++) {
1379                     objlen = get_zoneobj_len (tvb, offset);
1380                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset+4,
1381                                                  objlen, "Zone Object %d", i);
1382                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1383                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1384                     offset += objlen;
1385                 }
1386             }
1387             else {
1388                 offset += 4;
1389             }
1390
1391             zonesetlen = tvb_get_ntohl (tvb, offset);
1392             proto_tree_add_text (mr_tree, tvb, offset, 4,
1393                                  "Full Zone Set Length: %d", zonesetlen);
1394
1395             if (zonesetlen) {
1396                 objlistlen = zonesetlen;
1397                 /* Offset = start of the active zoneset zoning object list */
1398                 offset += 4;
1399                 numrec = tvb_get_ntohl (tvb, offset);
1400
1401                 subti = proto_tree_add_text (mr_tree, tvb, offset, objlistlen,
1402                                              "Full Zone Set");
1403
1404                 zobjlist_tree = proto_item_add_subtree (subti,
1405                                                         ett_fcswils_zoneobjlist);
1406                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1407                                      "Number of zoning objects: %d", numrec);
1408                 offset += 4;
1409                 for (i = 0; i < numrec; i++) {
1410                     objlen = get_zoneobj_len (tvb, offset);
1411                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1412                                                  objlen, "Zone Object %d", i);
1413                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1414                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1415                     offset += objlen;
1416                 }
1417             }
1418         }
1419         else {
1420             proto_tree_add_item (mr_tree, hf_swils_zone_status, tvb,
1421                                  offset+5, 1, 0);
1422             proto_tree_add_item (mr_tree, hf_swils_zone_reason, tvb,
1423                                  offset+6, 1, 0);
1424             proto_tree_add_text (mr_tree, tvb, offset+7, 1,
1425                                  "Vendor Unique: 0x%x",
1426                                  tvb_get_guint8 (tvb, offset+7));
1427         }
1428     }
1429 }
1430
1431 static void
1432 dissect_swils_aca (tvbuff_t *tvb, proto_tree *aca_tree, guint8 isreq)
1433 {
1434     /* Set up structures needed to add the protocol subtree and manage it */
1435     int offset = 0;
1436     int numrec, plen, i;
1437
1438     if (aca_tree) {
1439         if (isreq) {
1440             plen = tvb_get_ntohs (tvb, offset+2);
1441             proto_tree_add_text (aca_tree, tvb, offset+2, 2,
1442                                  "Domain ID List Length: %d", plen);
1443             numrec = plen/4;
1444             offset = 4;
1445
1446             for (i = 0; i < numrec; i++) {
1447                 proto_tree_add_uint_format (aca_tree, hf_swils_aca_domainid,
1448                                             tvb, offset+3, 1,
1449                                             tvb_get_guint8 (tvb, offset+3),
1450                                             "Domain ID %d: %d", i,
1451                                             tvb_get_guint8 (tvb, offset+3));
1452                 offset += 4;
1453             }
1454         }
1455         else {
1456             proto_tree_add_item (aca_tree, hf_swils_zone_status, tvb,
1457                                  offset+5, 1, 0);
1458             proto_tree_add_item (aca_tree, hf_swils_zone_reason, tvb,
1459                                  offset+6, 1, 0);
1460             proto_tree_add_text (aca_tree, tvb, offset+7, 1,
1461                                  "Vendor Unique: 0x%x",
1462                                  tvb_get_guint8 (tvb, offset+7));
1463         }
1464     }
1465 }
1466
1467 static void
1468 dissect_swils_rca (tvbuff_t *tvb, proto_tree *rca_tree, guint8 isreq)
1469 {
1470     /* Set up structures needed to add the protocol subtree and manage it */
1471     int offset = 0;
1472
1473     if (rca_tree) {
1474         if (!isreq) {
1475             proto_tree_add_item (rca_tree, hf_swils_zone_status, tvb,
1476                                  offset+5, 1, 0);
1477             proto_tree_add_item (rca_tree, hf_swils_zone_reason, tvb,
1478                                  offset+6, 1, 0);
1479             proto_tree_add_text (rca_tree, tvb, offset+7, 1,
1480                                  "Vendor Unique: 0x%x",
1481                                  tvb_get_guint8 (tvb, offset+7));
1482         }
1483     }
1484 }
1485
1486 static void
1487 dissect_swils_sfc (tvbuff_t *tvb, proto_tree *sfc_tree, guint8 isreq)
1488 {
1489     /* Set up structures needed to add the protocol subtree and manage it */
1490     int offset = 0;
1491     proto_tree *zobjlist_tree, *zobj_tree;
1492     int numrec, i, zonesetlen, objlistlen, objlen;
1493     char *str;
1494     proto_item *subti;
1495
1496     if (sfc_tree) {
1497         if (isreq) {
1498             proto_tree_add_item (sfc_tree, hf_swils_sfc_opcode, tvb, offset+1, 1, 0);
1499
1500             zonesetlen = tvb_get_ntohs (tvb, offset+2);
1501             proto_tree_add_text (sfc_tree, tvb, offset+2, 2,
1502                                  "ZoneSet Length: %d", zonesetlen);
1503
1504             if (zonesetlen) {
1505                 str = zonenm_to_str (tvb, offset+4);
1506                 proto_tree_add_string (sfc_tree, hf_swils_sfc_zonenm, tvb,
1507                                        offset+4, ZONENAME_LEN (tvb, offset+4),
1508                                        str);
1509
1510                 /* objlistlen gives the size of the active zoneset object list */
1511                 objlistlen = zonesetlen - ZONENAME_LEN (tvb, offset+4);
1512                 /* Offset = start of the active zoneset zoning object list */
1513                 offset = offset + (4 + ZONENAME_LEN (tvb, offset+4));
1514                 numrec = tvb_get_ntohl (tvb, offset);
1515
1516                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1517                                              "Zone Set");
1518                 zobjlist_tree = proto_item_add_subtree (subti,
1519                                                         ett_fcswils_zoneobjlist);
1520
1521                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1522                                      "Number of zoning objects: %d", numrec);
1523
1524                 offset += 4;
1525                 for (i = 0; i < numrec; i++) {
1526                     objlen = get_zoneobj_len (tvb, offset);
1527                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1528                                                  objlen, "Zone Object %d", i);
1529                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1530                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1531                     offset += objlen;
1532                 }
1533             }
1534             else {
1535                 offset += 4;
1536             }
1537
1538             zonesetlen = tvb_get_ntohl (tvb, offset);
1539             proto_tree_add_text (sfc_tree, tvb, offset, 4,
1540                                  "Full Zone Set Length: %d", zonesetlen);
1541
1542             if (zonesetlen) {
1543                 objlistlen = zonesetlen;
1544                 /* Offset = start of the active zoneset zoning object list */
1545                 offset += 4;
1546                 numrec = tvb_get_ntohl (tvb, offset);
1547
1548                 subti = proto_tree_add_text (sfc_tree, tvb, offset, objlistlen,
1549                                              "Full Zone Set");
1550
1551                 zobjlist_tree = proto_item_add_subtree (subti,
1552                                                         ett_fcswils_zoneobjlist);
1553                 proto_tree_add_text (zobjlist_tree, tvb, offset, 4,
1554                                      "Number of zoning objects: %d", numrec);
1555                 offset += 4;
1556                 for (i = 0; i < numrec; i++) {
1557                     objlen = get_zoneobj_len (tvb, offset);
1558                     subti = proto_tree_add_text (zobjlist_tree, tvb, offset,
1559                                                  objlen, "Zone Object %d", i);
1560                     zobj_tree = proto_item_add_subtree (subti, ett_fcswils_zoneobj);
1561                     dissect_swils_zone_obj (tvb, zobj_tree, offset);
1562                     offset += objlen;
1563                 }
1564             }
1565         }
1566         else {
1567             proto_tree_add_item (sfc_tree, hf_swils_zone_status, tvb,
1568                                  offset+5, 1, 0);
1569             proto_tree_add_item (sfc_tree, hf_swils_zone_reason, tvb,
1570                                  offset+6, 1, 0);
1571             proto_tree_add_text (sfc_tree, tvb, offset+7, 1,
1572                                  "Vendor Unique: 0x%x",
1573                                  tvb_get_guint8 (tvb, offset+7));
1574         }
1575     }
1576 }
1577
1578 static void
1579 dissect_swils_ufc (tvbuff_t *tvb, proto_tree *ufc_tree, guint8 isreq)
1580 {
1581     /* Set up structures needed to add the protocol subtree and manage it */
1582     int offset = 0;
1583
1584     if (ufc_tree) {
1585         if (!isreq) {
1586             proto_tree_add_item (ufc_tree, hf_swils_zone_status, tvb,
1587                                  offset+5, 1, 0);
1588             proto_tree_add_item (ufc_tree, hf_swils_zone_reason, tvb,
1589                                  offset+6, 1, 0);
1590             proto_tree_add_text (ufc_tree, tvb, offset+7, 1,
1591                                  "Vendor Unique: 0x%x",
1592                                  tvb_get_guint8 (tvb, offset+7));
1593         }
1594     }
1595 }
1596
1597 static void
1598 dissect_swils_esc (tvbuff_t *tvb, proto_tree *esc_tree, guint8 isreq)
1599 {
1600     /* Set up structures needed to add the protocol subtree and manage it */
1601     int offset = 0;
1602     int i, numrec, plen;
1603     proto_tree *pdesc_tree;
1604     proto_item *subti;
1605
1606     if (esc_tree) {
1607         if (isreq) {
1608             plen = tvb_get_ntohs (tvb, offset+2);
1609             proto_tree_add_text (esc_tree, tvb, offset+2, 2,
1610                                  "Payload Length: %d", plen);
1611             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1612                                  offset+4, 8, 0);
1613             numrec = (plen - 12)/12;
1614             offset = 12;
1615
1616             for (i = 0; i < numrec; i++) {
1617                 subti = proto_tree_add_text (esc_tree, tvb, offset, 12,
1618                                              "Protocol Descriptor %d", i);
1619                 pdesc_tree = proto_item_add_subtree (subti,
1620                                                      ett_fcswils_esc_pdesc);
1621                 proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1622                                      offset, 8, 0);
1623                 proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1624                                      tvb, offset+10, 2, 0);
1625                 offset += 12;
1626             }
1627         }
1628         else {
1629             proto_tree_add_item (esc_tree, hf_swils_esc_swvendorid, tvb,
1630                                  offset+4, 8, 0);
1631             subti = proto_tree_add_text (esc_tree, tvb, offset+12, 12,
1632                                          "Accepted Protocol Descriptor");
1633             pdesc_tree = proto_item_add_subtree (subti, ett_fcswils_esc_pdesc);
1634
1635             proto_tree_add_item (pdesc_tree, hf_swils_esc_pdesc_vendorid, tvb,
1636                                  offset+12, 8, 0);
1637             proto_tree_add_item (pdesc_tree, hf_swils_esc_protocolid,
1638                                  tvb, offset+22, 2, 0);
1639         }
1640     }
1641 }
1642
1643 static void
1644 dissect_swils_drlir (tvbuff_t *tvb _U_, proto_tree *drlir_tree _U_,
1645                      guint8 isreq _U_)
1646 {
1647     /* Set up structures needed to add the protocol subtree and manage it */
1648     return;
1649 }
1650
1651 static void
1652 dissect_swils_swrjt (tvbuff_t *tvb, proto_tree *swrjt_tree, guint8 isreq _U_)
1653 {
1654     /* Set up structures needed to add the protocol subtree and manage it */
1655     int offset = 0;
1656
1657     if (swrjt_tree) {
1658         proto_tree_add_item (swrjt_tree, hf_swils_rjt, tvb, offset+5, 1, 0);
1659         proto_tree_add_item (swrjt_tree, hf_swils_rjtdet, tvb, offset+6, 1, 0);
1660         proto_tree_add_item (swrjt_tree, hf_swils_rjtvendor, tvb, offset+7,
1661                              1, 0);
1662     }
1663 }
1664
1665 static void
1666 dissect_swils_ess (tvbuff_t *tvb, proto_tree *ess_tree, guint8 isreq _U_)
1667 {
1668      int offset = 0;
1669      gint16 numcapobj = 0;
1670      gint len = 0;
1671      gint capobjlen = 0;
1672      proto_item *ti = NULL;
1673      proto_tree *ieinfo_tree = NULL;
1674
1675      if (!ess_tree) {
1676           return;
1677      }
1678
1679      proto_tree_add_item (ess_tree, hf_swils_ess_rev, tvb, offset+4, 4, 0);
1680      proto_tree_add_item (ess_tree, hf_swils_ess_len, tvb, offset+8, 4, 0);
1681      len = tvb_get_ntohl (tvb, offset+8);
1682
1683      ti = proto_tree_add_text (ess_tree, tvb, offset+12,
1684                                MAX_INTERCONNECT_ELEMENT_INFO_LEN+4,
1685                                "Interconnect Element Info");
1686      ieinfo_tree = proto_item_add_subtree (ti, ett_fcswils_ieinfo);
1687      dissect_swils_interconnect_element_info (tvb, ieinfo_tree, offset+12);
1688      len -= 256;                /* the interconnect obj above is 256 bytes */
1689      offset += 268;
1690
1691      proto_tree_add_item (ess_tree, hf_swils_ess_numobj, tvb, offset, 2, 0);
1692      numcapobj = tvb_get_ntohs (tvb, offset);
1693
1694      len -= 4;                  /* 2B numcapobj + 2B rsvd */
1695      offset += 4;
1696
1697      while ((len > 0) && (numcapobj > 0)) {
1698           capobjlen = dissect_swils_ess_capability_obj (tvb, ess_tree, offset);
1699           numcapobj--;
1700           len -= capobjlen;
1701           offset += capobjlen;
1702      }
1703 }
1704
1705 static void
1706 dissect_swils_mrra (tvbuff_t *tvb, proto_tree *tree, guint8 isreq)
1707 {
1708
1709      int offset = 0;
1710
1711      if (!tree) {
1712           return;
1713      }
1714
1715      if (isreq) {
1716           proto_tree_add_item (tree, hf_swils_mrra_rev, tvb, offset+4, 4, 0);
1717           proto_tree_add_item (tree, hf_swils_mrra_size, tvb, offset+8, 4, 0);
1718           proto_tree_add_item (tree, hf_swils_mrra_vendorid, tvb, offset+12, 8, 0);
1719           proto_tree_add_item (tree, hf_swils_mrra_vendorinfo, tvb, offset+20,
1720                                8, 0);
1721      } else {
1722           proto_tree_add_item (tree, hf_swils_mrra_vendorid, tvb, offset+4,
1723                                8, 0);
1724           proto_tree_add_item (tree, hf_swils_mrra_reply, tvb, offset+12,
1725                                4, 0);
1726           proto_tree_add_item (tree, hf_swils_mrra_reply_size, tvb, offset+16,
1727                                4, 0);
1728           proto_tree_add_item (tree, hf_swils_mrra_waittime, tvb, offset+20,
1729                                4, 0);
1730      }
1731
1732
1733 }
1734
1735 static fcswils_func_table_t fcswils_func_table[FC_SWILS_MAXCODE] = {
1736      /* 0x00 */ {NULL},
1737      /* 0x01 */ {dissect_swils_swrjt},
1738      /* 0x02 */ {NULL},
1739      /* 0x03 */ {NULL},
1740      /* 0x04 */ {NULL},
1741      /* 0x05 */ {NULL},
1742      /* 0x06 */ {NULL},
1743      /* 0x07 */ {NULL},
1744      /* 0x08 */ {NULL},
1745      /* 0x09 */ {NULL},
1746      /* 0x0a */ {NULL},
1747      /* 0x0b */ {NULL},
1748      /* 0x0c */ {NULL},
1749      /* 0x0d */ {NULL},
1750      /* 0x0e */ {NULL},
1751      /* 0x0f */ {NULL},
1752      /* 0x10 */ {dissect_swils_elp},
1753      /* 0x11 */ {dissect_swils_efp},
1754      /* 0x12 */ {dissect_swils_dia},
1755      /* 0x13 */ {dissect_swils_rdi},
1756      /* 0x14 */ {dissect_swils_hello},
1757      /* 0x15 */ {dissect_swils_lsupdate},
1758      /* 0x16 */ {dissect_swils_lsack},
1759      /* 0x17 */ {dissect_swils_nullpayload},
1760      /* 0x18 */ {dissect_swils_nullpayload},
1761      /* 0x19 */ {NULL},
1762      /* 0x1a */ {NULL},
1763      /* 0x1b */ {dissect_swils_rscn},
1764      /* 0x1c */ {NULL},
1765      /* 0x1d */ {NULL},
1766      /* 0x1e */ {dissect_swils_drlir},
1767      /* 0x1f */ {NULL},
1768      /* 0x20 */ {NULL /*dissect_swils_dscn*/},
1769      /* 0x21 */ {NULL /*dissect_swils_loopd*/},
1770      /* 0x22 */ {dissect_swils_mergereq},
1771      /* 0x23 */ {dissect_swils_aca},
1772      /* 0x24 */ {dissect_swils_rca},
1773      /* 0x25 */ {dissect_swils_sfc},
1774      /* 0x26 */ {dissect_swils_ufc},
1775      /* 0x27 */ {NULL},
1776      /* 0x28 */ {NULL},
1777      /* 0x29 */ {NULL},
1778      /* 0x2a */ {NULL},
1779      /* 0x2b */ {NULL},
1780      /* 0x2c */ {NULL},
1781      /* 0x2d */ {NULL},
1782      /* 0x2e */ {NULL},
1783      /* 0x2f */ {NULL},
1784      /* 0x30 */ {dissect_swils_esc},
1785      /* 0x31 */ {dissect_swils_ess},
1786      /* 0x32 */ {NULL},
1787      /* 0x33 */ {NULL},
1788      /* 0x34 */ {dissect_swils_mrra}
1789 };
1790
1791 /* Code to actually dissect the packets */
1792 static void
1793 dissect_fcswils (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1794 {
1795     proto_item *ti = NULL;
1796     guint8 opcode,
1797         failed_opcode = 0;
1798     int offset = 0;
1799     conversation_t *conversation;
1800     fcswils_conv_data_t *cdata;
1801     fcswils_conv_key_t ckey, *req_key;
1802     proto_tree *swils_tree = NULL;
1803     guint8 isreq = FC_SWILS_REQ;
1804     tvbuff_t *next_tvb;
1805
1806     /* Make entries in Protocol column and Info column on summary display */
1807     if (check_col(pinfo->cinfo, COL_PROTOCOL))
1808         col_set_str(pinfo->cinfo, COL_PROTOCOL, "SW_ILS");
1809
1810     /* decoding of this is done by each individual opcode handler */
1811     opcode = tvb_get_guint8 (tvb, 0);
1812
1813     if (tree) {
1814         ti = proto_tree_add_protocol_format (tree, proto_fcswils, tvb, 0,
1815                                              tvb_length (tvb), "SW_ILS");
1816         swils_tree = proto_item_add_subtree (ti, ett_fcswils);
1817     }
1818
1819     /* Register conversation if this is not a response */
1820     if ((opcode != FC_SWILS_SWACC) && (opcode != FC_SWILS_SWRJT)) {
1821         conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1822                                           pinfo->ptype, pinfo->oxid,
1823                                           pinfo->rxid, NO_PORT2);
1824         if (!conversation) {
1825             conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1826                                              pinfo->ptype, pinfo->oxid,
1827                                              pinfo->rxid, NO_PORT2);
1828         }
1829
1830         ckey.conv_idx = conversation->index;
1831
1832         cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash,
1833                                                             &ckey);
1834         if (cdata) {
1835             /* Since we never free the memory used by an exchange, this maybe a
1836              * case of another request using the same exchange as a previous
1837              * req.
1838              */
1839             cdata->opcode = opcode;
1840         }
1841         else {
1842             req_key = se_alloc (sizeof(fcswils_conv_key_t));
1843             req_key->conv_idx = conversation->index;
1844
1845             cdata = se_alloc (sizeof(fcswils_conv_data_t));
1846             cdata->opcode = opcode;
1847
1848             g_hash_table_insert (fcswils_req_hash, req_key, cdata);
1849         }
1850     }
1851     else {
1852         /* Opcode is ACC or RJT */
1853         conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
1854                                           pinfo->ptype, pinfo->oxid,
1855                                           pinfo->rxid, NO_PORT2);
1856         isreq = FC_SWILS_RPLY;
1857         if (!conversation) {
1858             if (tree && (opcode == FC_SWILS_SWACC)) {
1859                 /* No record of what this accept is for. Can't decode */
1860                 proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1861                                      "No record of Exchg. Unable to decode SW_ACC");
1862                 return;
1863             }
1864         }
1865         else {
1866             ckey.conv_idx = conversation->index;
1867
1868             cdata = (fcswils_conv_data_t *)g_hash_table_lookup (fcswils_req_hash, &ckey);
1869
1870             if (cdata != NULL) {
1871                 if (opcode == FC_SWILS_SWACC)
1872                     opcode = cdata->opcode;
1873                 else
1874                     failed_opcode = cdata->opcode;
1875             }
1876
1877             if (tree) {
1878                 if ((cdata == NULL) && (opcode != FC_SWILS_SWRJT)) {
1879                     /* No record of what this accept is for. Can't decode */
1880                     proto_tree_add_text (swils_tree, tvb, 0, tvb_length (tvb),
1881                                          "No record of SW_ILS Req. Unable to decode SW_ACC");
1882                     return;
1883                 }
1884             }
1885         }
1886     }
1887
1888     if (check_col (pinfo->cinfo, COL_INFO)) {
1889         if (isreq == FC_SWILS_REQ) {
1890             col_add_str (pinfo->cinfo, COL_INFO,
1891                          val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1892         }
1893         else if (opcode == FC_SWILS_SWRJT) {
1894             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_RJT (%s)",
1895                           val_to_str (failed_opcode, fc_swils_opcode_key_val, "0x%x"));
1896         }
1897         else {
1898             col_add_fstr (pinfo->cinfo, COL_INFO, "SW_ACC (%s)",
1899                           val_to_str (opcode, fc_swils_opcode_key_val, "0x%x"));
1900         }
1901     }
1902
1903     if (tree) {
1904         proto_tree_add_item (swils_tree, hf_swils_opcode, tvb, offset, 1, 0);
1905     }
1906
1907     if ((opcode < FC_SWILS_MAXCODE) && fcswils_func_table[opcode].func) {
1908          fcswils_func_table[opcode].func (tvb, swils_tree, isreq);
1909     } else if (opcode == FC_SWILS_AUTH_ILS) {
1910          /* This is treated differently */
1911          if (isreq && fcsp_handle)
1912               call_dissector (fcsp_handle, tvb, pinfo, swils_tree);
1913     } else {
1914          /* data dissector */
1915          next_tvb = tvb_new_subset (tvb, offset+4, -1, -1);
1916          call_dissector (data_handle, next_tvb, pinfo, tree);
1917     }
1918
1919 }
1920
1921 /* Register the protocol with Wireshark */
1922
1923 /* this format is require because a script is used to build the C function
1924    that calls all the protocol registration.
1925 */
1926
1927 void
1928 proto_register_fcswils (void)
1929 {
1930 /* Setup list of header fields  See Section 1.6.1 for details*/
1931     static hf_register_info hf[] = {
1932         { &hf_swils_opcode,
1933           {"Cmd Code", "swils.opcode", FT_UINT8, BASE_HEX,
1934            VALS (fc_swils_opcode_key_val), 0x0, "", HFILL}},
1935         { &hf_swils_elp_rev,
1936           {"Revision", "swils.elp.rev", FT_UINT8, BASE_DEC, NULL,
1937            0x0, "", HFILL}},
1938         { &hf_swils_elp_flags,
1939           {"Flag", "swils.elp.flag", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL}},
1940         { &hf_swils_elp_r_a_tov,
1941           {"R_A_TOV", "swils.elp.ratov", FT_UINT32, BASE_DEC, NULL,
1942            0x0, "", HFILL}},
1943         { &hf_swils_elp_e_d_tov,
1944           {"E_D_TOV", "swils.elp.edtov", FT_UINT32, BASE_DEC, NULL, 0x0, "",
1945            HFILL}},
1946         { &hf_swils_elp_req_epn,
1947           {"Req Eport Name", "swils.elp.reqepn", FT_STRING, BASE_HEX, NULL, 0x0,
1948            "", HFILL}},
1949         { &hf_swils_elp_req_esn,
1950           {"Req Switch Name", "swils.elp.reqesn", FT_STRING, BASE_HEX, NULL, 0x0,
1951            "", HFILL}},
1952         { &hf_swils_elp_clsf_svcp,
1953           {"Class F Svc Param", "swils.elp.clsfp", FT_BYTES, BASE_NONE, NULL, 0x0,
1954            "", HFILL}},
1955         { &hf_swils_elp_clsf_rcvsz,
1956           {"Max Class F Frame Size", "swils.elp.clsfrsz", FT_UINT16, BASE_DEC,
1957            NULL, 0x0, "", HFILL}},
1958         { &hf_swils_elp_clsf_conseq,
1959           {"Class F Max Concurrent Seq", "swils.elp.clsfcs", FT_UINT16, BASE_DEC,
1960            NULL, 0x0, "", HFILL}},
1961         { &hf_swils_elp_clsf_e2e,
1962           {"Class F E2E Credit", "swils.elp.cfe2e", FT_UINT16, BASE_DEC, NULL,
1963            0x0, "", HFILL}},
1964         { &hf_swils_elp_clsf_openseq,
1965           {"Class F Max Open Seq", "swils.elp.oseq", FT_UINT16, BASE_DEC, NULL,
1966            0x0, "", HFILL}},
1967         { &hf_swils_elp_cls1_svcp,
1968           {"Class 1 Svc Param", "swils.elp.cls1p", FT_BYTES, BASE_NONE, NULL, 0x0,
1969            "", HFILL}},
1970         { &hf_swils_elp_cls1_rcvsz,
1971           {"Class 1 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1972            0x0, "", HFILL}},
1973         { &hf_swils_elp_cls2_svcp,
1974           {"Class 2 Svc Param", "swils.elp.cls2p", FT_BYTES, BASE_HEX, NULL, 0x0,
1975            "", HFILL}},
1976         { &hf_swils_elp_cls2_rcvsz,
1977           {"Class 2 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1978            0x0, "", HFILL}},
1979         { &hf_swils_elp_cls3_svcp,
1980           {"Class 3 Svc Param", "swils.elp.cls3p", FT_BYTES, BASE_HEX, NULL, 0x0,
1981            "", HFILL}},
1982         { &hf_swils_elp_cls3_rcvsz,
1983           {"Class 3 Frame Size", "swils.elp.cls1rsz", FT_UINT16, BASE_DEC, NULL,
1984            0x0, "", HFILL}},
1985         { &hf_swils_elp_isl_fc_mode,
1986           {"ISL Flow Ctrl Mode", "swils.elp.fcmode", FT_STRING, BASE_HEX, NULL,
1987            0x0, "", HFILL}},
1988         { &hf_swils_elp_fcplen,
1989           {"Flow Ctrl Param Len", "swils.elp.fcplen", FT_UINT16, BASE_DEC, NULL,
1990            0x0, "", HFILL}},
1991         { &hf_swils_elp_b2bcredit,
1992           {"B2B Credit", "swils.elp.b2b", FT_UINT32, BASE_DEC, NULL, 0x0, "",
1993            HFILL}},
1994         { &hf_swils_elp_compat1,
1995           {"Compatibility Param 1", "swils.elp.compat1", FT_UINT32, BASE_DEC, NULL,
1996            0x0, "", HFILL}},
1997         { &hf_swils_elp_compat2,
1998           {"Compatibility Param 2", "swils.elp.compat2", FT_UINT32, BASE_DEC, NULL,
1999            0x0, "", HFILL}},
2000         { &hf_swils_elp_compat3,
2001           {"Compatibility Param 3", "swils.elp.compat3", FT_UINT32, BASE_DEC, NULL,
2002            0x0, "", HFILL}},
2003         { &hf_swils_elp_compat4,
2004           {"Compatibility Param 4", "swils.elp.compat4", FT_UINT32, BASE_DEC, NULL,
2005            0x0, "", HFILL}},
2006         { &hf_swils_efp_rec_type,
2007           {"Record Type", "swils.efp.rectype", FT_UINT8, BASE_HEX,
2008            VALS (fcswils_rectype_val), 0x0, "", HFILL}},
2009         { &hf_swils_efp_dom_id,
2010           {"Domain ID", "swils.efp.domid", FT_UINT8, BASE_HEX, NULL, 0x0,
2011            "", HFILL}},
2012         { &hf_swils_efp_switch_name,
2013           {"Switch Name", "swils.efp.sname", FT_STRING, BASE_HEX, NULL, 0x0,
2014            "", HFILL}},
2015         { &hf_swils_efp_mcast_grpno,
2016           {"Mcast Grp#", "swils.efp.mcastno", FT_UINT8, BASE_HEX, NULL, 0x0,
2017            "", HFILL}},
2018         { &hf_swils_efp_alias_token,
2019           {"Alias Token", "swils.efp.aliastok", FT_BYTES, BASE_HEX, NULL, 0x0,
2020            "", HFILL}},
2021         { &hf_swils_efp_record_len,
2022           {"Record Len", "swils.efp.recordlen", FT_UINT8, BASE_DEC, NULL, 0x0,
2023            "", HFILL}},
2024         { &hf_swils_efp_payload_len,
2025           {"Payload Len", "swils.efp.payloadlen", FT_UINT16, BASE_DEC, NULL, 0x0,
2026            "", HFILL}},
2027         { &hf_swils_efp_pswitch_pri,
2028           {"Principal Switch Priority", "swils.efp.psprio", FT_UINT8, BASE_DEC,
2029            NULL, 0x0, "", HFILL}},
2030         { &hf_swils_efp_pswitch_name,
2031           {"Principal Switch Name", "swils.efp.psname", FT_STRING, BASE_HEX, NULL,
2032            0x0, "", HFILL}},
2033         { &hf_swils_dia_switch_name,
2034           {"Switch Name", "swils.dia.sname", FT_STRING, BASE_HEX, NULL, 0x0,
2035            "", HFILL}},
2036         { &hf_swils_rdi_payload_len,
2037           {"Payload Len", "swils.rdi.len", FT_UINT16, BASE_DEC, NULL, 0x0, "",
2038            HFILL}},
2039         { &hf_swils_rdi_req_sname,
2040           {"Req Switch Name", "swils.rdi.reqsn", FT_STRING, BASE_HEX, NULL, 0x0,
2041            "", HFILL}},
2042         { &hf_swils_fspfh_cmd,
2043           {"Command: ", "swils.fspf.cmd", FT_UINT8, BASE_HEX, NULL, 0x0,
2044            "", HFILL}},
2045         { &hf_swils_fspfh_rev,
2046           {"Version", "swils.fspf.ver", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL}},
2047         { &hf_swils_fspfh_ar_num,
2048           {"AR Number", "swils.fspf.arnum", FT_UINT8, BASE_HEX, NULL, 0x0, "",
2049            HFILL}},
2050         { &hf_swils_fspfh_auth_type,
2051           {"Authentication Type", "swils.fspf.authtype", FT_UINT8, BASE_HEX, NULL,
2052            0x0, "", HFILL}},
2053         { &hf_swils_fspfh_dom_id,
2054           {"Originating Domain ID", "swils.fspf.origdomid", FT_UINT8, BASE_DEC,
2055            NULL, 0x0, "", HFILL}},
2056         { &hf_swils_fspfh_auth,
2057           {"Authentication", "swils.fspf.auth", FT_BYTES, BASE_HEX, NULL, 0x0,
2058            "", HFILL}},
2059         { &hf_swils_hlo_options,
2060           {"Options", "swils.hlo.options", FT_BYTES, BASE_HEX, NULL, 0x0,
2061            "", HFILL}},
2062         { &hf_swils_hlo_hloint,
2063           {"Hello Interval (secs)", "swils.hlo.hloint", FT_UINT32, BASE_DEC,
2064            NULL, 0x0, "", HFILL}},
2065         { &hf_swils_hlo_deadint,
2066           {"Dead Interval (secs)", "swils.hlo.deadint", FT_UINT32, BASE_DEC,
2067            NULL, 0x0, "", HFILL}},
2068         { &hf_swils_hlo_rcv_domid,
2069           {"Recipient Domain ID", "swils.hlo.rcvdomid", FT_UINT8, BASE_DEC,
2070            NULL, 0x0, "", HFILL}},
2071         { &hf_swils_hlo_orig_pidx,
2072           {"Originating Port Idx", "swils.hlo.origpidx", FT_UINT24, BASE_HEX,
2073            NULL, 0x0, "", HFILL}},
2074         { &hf_swils_lsrh_lsr_type,
2075           {"LSR Type", "swils.lsr.type", FT_UINT8, BASE_HEX,
2076            VALS (fc_swils_fspf_linkrec_val), 0x0, "", HFILL}},
2077         { &hf_swils_lsrh_lsid,
2078           {"Link State Id", "swils.ls.id", FT_UINT8, BASE_DEC, NULL, 0x0,
2079            "", HFILL}},
2080         { &hf_swils_lsrh_adv_domid,
2081           {"Advertising Domain Id", "swils.lsr.advdomid", FT_UINT8, BASE_DEC,
2082            NULL, 0x0, "", HFILL}},
2083         { &hf_swils_lsrh_ls_incid,
2084           {"LS Incarnation Number", "swils.lsr.incid", FT_UINT32, BASE_DEC,
2085            NULL, 0x0, "", HFILL}},
2086         { &hf_swils_ldrec_linkid,
2087           {"Link ID", "swils.ldr.linkid", FT_STRING, BASE_HEX, NULL, 0x0,
2088            "", HFILL}},
2089         { &hf_swils_ldrec_out_pidx,
2090           {"Output Port Idx", "swils.ldr.out_portidx", FT_UINT24, BASE_HEX, NULL,
2091            0x0, "", HFILL}},
2092         { &hf_swils_ldrec_nbr_pidx,
2093           {"Neighbor Port Idx", "swils.ldr.nbr_portidx", FT_UINT24, BASE_HEX,
2094            NULL, 0x0, "", HFILL}},
2095         { &hf_swils_ldrec_link_type,
2096           {"Link Type", "swils.ldr.linktype", FT_UINT8, BASE_HEX,
2097            VALS (fc_swils_link_type_val), 0x0, "", HFILL}},
2098         { &hf_swils_ldrec_link_cost,
2099           {"Link Cost", "swils.ldr.linkcost", FT_UINT16, BASE_DEC, NULL, 0x0,
2100            "", HFILL}},
2101         { &hf_swils_rscn_evtype,
2102           {"Event Type", "swils.rscn.evtype", FT_UINT8, BASE_DEC,
2103            VALS (fc_swils_rscn_portstate_val), 0xF0, "", HFILL}},
2104         { &hf_swils_rscn_addrfmt,
2105           {"Address Format", "swils.rscn.addrfmt", FT_UINT8, BASE_DEC,
2106            VALS (fc_swils_rscn_addrfmt_val), 0x0F, "", HFILL}},
2107         { &hf_swils_rscn_affectedport,
2108           {"Affected Port ID", "swils.rscn.affectedport", FT_STRING, BASE_HEX,
2109            NULL, 0x0, "", HFILL}},
2110         { &hf_swils_rscn_detectfn,
2111           {"Detection Function", "swils.rscn.detectfn", FT_UINT32, BASE_HEX,
2112            VALS (fc_swils_rscn_detectfn_val), 0x0, "", HFILL}},
2113         { &hf_swils_rscn_portstate,
2114           {"Port State", "swils.rscn.portstate", FT_UINT8, BASE_HEX, NULL, 0x0,
2115            "", HFILL}},
2116         { &hf_swils_rscn_portid,
2117           {"Port Id", "swils.rscn.portid", FT_STRING, BASE_HEX, NULL, 0x0, "",
2118            HFILL}},
2119         { &hf_swils_rscn_pwwn,
2120           {"Port WWN", "swils.rscn.pwwn", FT_STRING, BASE_HEX, NULL, 0x0, "",
2121            HFILL}},
2122         { &hf_swils_rscn_nwwn,
2123           {"Node WWN", "swils.rscn.nwwn", FT_STRING, BASE_HEX, NULL, 0x0, "",
2124            HFILL}},
2125         { &hf_swils_esc_swvendorid,
2126           {"Switch Vendor ID", "swils.esc.swvendor", FT_STRING, BASE_HEX, NULL,
2127            0x0, "", HFILL}},
2128         { &hf_swils_esc_pdesc_vendorid,
2129           {"Vendor ID", "swils.esc.vendorid", FT_STRING, BASE_HEX, NULL, 0x0,
2130            "", HFILL}},
2131         { &hf_swils_esc_protocolid,
2132           {"Protocol ID", "swils.esc.protocol", FT_UINT16, BASE_HEX,
2133            VALS (fc_swils_esc_protocol_val), 0x0, "", HFILL}},
2134         { &hf_swils_zone_activezonenm,
2135           {"Active Zoneset Name", "swils.mr.activezonesetname", FT_STRING,
2136            BASE_HEX, NULL, 0x0, "", HFILL}},
2137         { &hf_swils_zone_objname,
2138           {"Zone Object Name", "swils.zone.zoneobjname", FT_STRING, BASE_HEX,
2139            NULL, 0x0, "", HFILL}},
2140         { &hf_swils_zone_objtype,
2141           {"Zone Object Type", "swils.zone.zoneobjtype", FT_UINT8, BASE_HEX,
2142            VALS (fc_swils_zoneobj_type_val), 0x0, "", HFILL}},
2143         { &hf_swils_zone_mbrtype,
2144           {"Zone Member Type", "swils.zone.mbrtype", FT_UINT8, BASE_HEX,
2145            VALS (fc_swils_zonembr_type_val), 0x0, "", HFILL}},
2146         { &hf_swils_zone_protocol,
2147           {"Zone Protocol", "swils.zone.protocol", FT_UINT8, BASE_HEX, NULL,
2148            0x0, "", HFILL}},
2149         { &hf_swils_zone_mbrid,
2150           {"Member Identifier", "swils.zone.mbrid", FT_STRING, BASE_HEX, NULL,
2151            0x0, "", HFILL}},
2152         { &hf_swils_zone_status,
2153           {"Zone Command Status", "swils.zone.status", FT_UINT8, BASE_HEX,
2154            VALS (fc_swils_mr_rsp_val), 0x0, "Applies to MR, ACA, RCA, SFC, UFC",
2155            HFILL}},
2156         { &hf_swils_zone_reason,
2157           {"Zone Command Reason Code", "swils.zone.reason", FT_UINT8, BASE_HEX,
2158            VALS (fc_swils_mr_reason_val), 0x0, "Applies to MR, ACA, RCA, SFC, UFC",
2159            HFILL}},
2160         { &hf_swils_aca_domainid,
2161           {"Known Domain ID", "swils.aca.domainid", FT_UINT8, BASE_HEX, NULL,
2162            0x0, "", HFILL}},
2163         { &hf_swils_sfc_opcode,
2164           {"Operation Request", "swils.sfc.opcode", FT_UINT8, BASE_HEX,
2165            VALS (fc_swils_sfc_op_val), 0x0, "", HFILL}},
2166         { &hf_swils_sfc_zonenm,
2167           {"Zone Set Name", "swils.sfc.zonename", FT_STRING, BASE_HEX, NULL,
2168            0x0, "", HFILL}},
2169         { &hf_swils_rjt,
2170           {"Reason Code", "swils.rjt.reason", FT_UINT8, BASE_HEX,
2171            VALS (fc_swils_rjt_val), 0x0, "", HFILL}},
2172         { &hf_swils_rjtdet,
2173           {"Reason Code Explanantion", "swils.rjt.reasonexpl", FT_UINT8,
2174            BASE_HEX, VALS (fc_swils_deterr_val), 0x0, "", HFILL}},
2175         { &hf_swils_rjtvendor,
2176           {"Vendor Unique Error Code", "swils.rjt.vendor", FT_UINT8, BASE_HEX,
2177            NULL, 0x0, "", HFILL}},
2178         { &hf_swils_zone_mbrid_lun,
2179           {"LUN", "swils.zone.lun", FT_BYTES, BASE_HEX, NULL, 0x0, "",
2180            HFILL}},
2181         { &hf_swils_ess_rev,
2182           {"Revision", "swils.ess.revision", FT_UINT32, BASE_DEC, NULL, 0x0, "",
2183            HFILL}},
2184         { &hf_swils_ess_len,
2185           {"Payload Length", "swils.ess.leb", FT_UINT32, BASE_DEC, NULL, 0x0,
2186            "", HFILL}},
2187         { &hf_swils_ess_numobj,
2188           {"Number of Capability Objects", "swils.ess.numobj", FT_UINT16, BASE_DEC,
2189            NULL, 0x0, "", HFILL}},
2190         { &hf_swils_interconnect_list_len,
2191           {"List Length", "swils.ess.listlen", FT_UINT8, BASE_DEC, NULL, 0x0, "",
2192            HFILL}},
2193         { &hf_swils_ess_vendorname,
2194           {"Vendor Name", "swils.ess.vendorname", FT_STRING, BASE_DEC, NULL,
2195            0x0, "", HFILL}},
2196         { &hf_swils_ess_modelname,
2197           {"Model Name", "swils.ess.modelname", FT_STRING, BASE_DEC, NULL, 0x0,
2198            "", HFILL}},
2199         { &hf_swils_ess_relcode,
2200           {"Release Code", "swils.ess.relcode", FT_STRING, BASE_DEC, NULL, 0x0,
2201            "", HFILL}},
2202         { &hf_swils_ess_vendorspecific,
2203           {"Vendor Specific", "swils.ess.vendorspecific", FT_STRING, BASE_HEX,
2204            NULL, 0x0, "", HFILL}},
2205         { &hf_swils_ess_cap_type,
2206           {"Type", "swils.ess.capability.type", FT_UINT8, BASE_DEC,
2207            VALS (fc_ct_gstype_vals), 0x0, "", HFILL}},
2208         { &hf_swils_ess_cap_subtype,
2209           {"Subtype", "swils.ess.capability.subtype", FT_UINT8, BASE_DEC, NULL,
2210            0x0, "", HFILL}},
2211         { &hf_swils_ess_cap_numentries,
2212           {"Number of Entries", "swils.ess.capability.numentries", FT_UINT8,
2213            BASE_DEC, NULL, 0x0, "", HFILL}},
2214         { &hf_swils_ess_cap_svc,
2215           {"Service Name", "swils.ess.capability.service", FT_UINT8, BASE_DEC,
2216            VALS (fc_ct_gsserver_vals), 0x0, "", HFILL}},
2217         { &hf_swils_ess_dns_obj0h,
2218           {"Name Server Entry Object 00h Support", "swils.ess.capability.dns.obj0h",
2219            FT_BOOLEAN, BASE_HEX, NULL, 0x1, "", HFILL}},
2220         { &hf_swils_ess_dns_obj1h,
2221           {"Name Server Entry Object 01h Support", "swils.ess.capability.dns.obj1h",
2222            FT_BOOLEAN, BASE_HEX, NULL, 0x2, "", HFILL}},
2223         { &hf_swils_ess_dns_obj2h,
2224           {"Name Server Entry Object 02h Support", "swils.ess.capability.dns.obj2h",
2225            FT_BOOLEAN, BASE_HEX, NULL, 0x4, "", HFILL}},
2226         { &hf_swils_ess_dns_obj3h,
2227           {"Name Server Entry Object 03h Support", "swils.ess.capability.dns.obj3h",
2228            FT_BOOLEAN, BASE_HEX, NULL, 0x8, "", HFILL}},
2229         { &hf_swils_ess_dns_zlacc,
2230           {"GE_PT Zero Length Accepted", "swils.ess.capability.dns.zlacc",
2231            FT_BOOLEAN, BASE_HEX, NULL, 0x10, "", HFILL}},
2232         { &hf_swils_ess_dns_vendor,
2233           {"Vendor Specific Flags", "swils.ess.capability.dns.vendor", FT_UINT32,
2234            BASE_HEX, NULL, 0x0, "", HFILL}},
2235         { &hf_swils_ess_fctlr_rscn,
2236           {"SW_RSCN Supported", "swils.ess.capability.fctlr.rscn", FT_BOOLEAN,
2237            BASE_HEX, NULL, 0x1, "", HFILL}},
2238         { &hf_swils_ess_fctlr_vendor,
2239           {"Vendor Specific Flags", "swils.ess.capability.fctlr.vendor",
2240            FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL}},
2241         { &hf_swils_ess_fcs_basic,
2242           {"Basic Configuration Services", "swils.ess.capability.fcs.basic",
2243            FT_BOOLEAN, BASE_HEX, NULL, 0x1, "", HFILL}},
2244         { &hf_swils_ess_fcs_platform,
2245           {"Platform Configuration Services",
2246            "swils.ess.capability.fcs.platform", FT_BOOLEAN, BASE_HEX, NULL,
2247            0x2, "", HFILL}},
2248         { &hf_swils_ess_fcs_topology,
2249           {"Topology Discovery Services", "swils.ess.capability.fcs.topology",
2250            FT_BOOLEAN, BASE_HEX, NULL, 0x4, "", HFILL}},
2251         { &hf_swils_ess_fcs_enhanced,
2252           {"Enhanced Configuration Services",
2253            "swils.ess.capability.fcs.enhanced", FT_BOOLEAN, BASE_HEX, NULL, 0x8,
2254            "", HFILL}},
2255         { &hf_swils_ess_fzs_enh_supp,
2256           {"Enhanced Zoning Supported", "swils.ess.capability.fzs.ezonesupp",
2257            FT_BOOLEAN, BASE_HEX, NULL, 0x1, "", HFILL}},
2258         { &hf_swils_ess_fzs_enh_ena,
2259           {"Enhanced Zoning Enabled", "swils.ess.capability.fzs.ezoneena",
2260            FT_BOOLEAN, BASE_HEX, NULL, 0x2, "", HFILL}},
2261         { &hf_swils_ess_fzs_mr,
2262           {"Merge Control Setting", "swils.ess.capability.fzs.mr", FT_BOOLEAN,
2263            BASE_HEX, NULL, 0x4, "", HFILL}},
2264         { &hf_swils_ess_fzs_defzone,
2265           {"Default Zone Setting", "swils.ess.capability.fzs.defzone",
2266            FT_BOOLEAN, BASE_HEX, NULL, 0x8, "", HFILL}},
2267         { &hf_swils_ess_fzs_zsdb_supp,
2268           {"Zoneset Database Supported", "swils.ess.capability.fzs.zsdbsupp",
2269            FT_BOOLEAN, BASE_HEX, NULL, 0x10, "", HFILL}},
2270         { &hf_swils_ess_fzs_zsdb_ena,
2271           {"Zoneset Database Enabled", "swils.ess.capability.fzs.zsdbena",
2272            FT_BOOLEAN, BASE_HEX, NULL, 0x20, "", HFILL}},
2273         { &hf_swils_ess_fzs_adc_supp,
2274           {"Active Direct Command Supported",
2275            "swils.ess.capability.fzs.adcsupp", FT_BOOLEAN, BASE_HEX, NULL,
2276            0x40, "", HFILL}},
2277         { &hf_swils_ess_fzs_hardzone,
2278           {"Hard Zoning Supported", "swils.ess.capability.fzs.hardzone",
2279            FT_BOOLEAN, BASE_HEX, NULL, 0x80, "", HFILL}},
2280         { &hf_swils_ess_cap_len,
2281           {"Length", "swils.ess.capability.length", FT_UINT8, BASE_DEC, NULL,
2282            0x0, "", HFILL}},
2283         { &hf_swils_ess_cap_t10,
2284           {"T10 Vendor ID", "swils.ess.capability.t10id", FT_STRING, BASE_HEX,
2285            NULL, 0x0, "", HFILL}},
2286         { &hf_swils_ess_cap_vendorobj,
2287           {"Vendor-Specific Info", "swils.ess.capability.vendorobj", FT_BYTES,
2288            BASE_HEX, NULL, 0x0, "", HFILL}},
2289         { &hf_swils_mrra_rev,
2290           {"Revision", "swils.mrra.revision", FT_UINT32, BASE_DEC, NULL,
2291            0x0, "", HFILL}},
2292         { &hf_swils_mrra_size,
2293           {"Merge Request Size", "swils.mrra.size", FT_UINT32, BASE_DEC, NULL,
2294            0x0, "", HFILL}},
2295         { &hf_swils_mrra_vendorid,
2296           {"Vendor ID", "swils.mrra.vendorid", FT_STRING, BASE_HEX,
2297            NULL, 0x0, "", HFILL}},
2298         { &hf_swils_mrra_vendorinfo,
2299           {"Vendor-Specific Info", "swils.mrra.vendorinfo", FT_BYTES, BASE_HEX,
2300            NULL, 0x0, "", HFILL}},
2301         { &hf_swils_mrra_reply,
2302           {"MRRA Response", "swils.mrra.reply", FT_UINT32, BASE_DEC, NULL, 0x0,
2303            "", HFILL}},
2304         { &hf_swils_mrra_reply_size,
2305           {"Maximum Resources Available", "swils.mrra.replysize", FT_UINT32,
2306            BASE_DEC, NULL, 0x0, "", HFILL}},
2307         { &hf_swils_mrra_waittime,
2308           {"Waiting Period (secs)", "swils.mrra.waittime", FT_UINT32, BASE_DEC,
2309            NULL, 0x0, "", 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 }