f052e20990790636674aba225e50a5b7a47a53e0
[obnox/wireshark/wip.git] / epan / dissectors / packet-isns.c
1 /* XXX fixme   can not reassemple multiple isns PDU fragments into one
2   isns PDU
3 */
4
5 /* packet-isns.c
6  * Routines for iSNS dissection
7  * Copyright 2003, Elipsan, Gareth Bushell <gbushell@elipsan.com>
8  * (c) 2004 Ronnie Sahlberg   updates
9  * (c) 2004 Ming Zhang   updates
10  *
11  * $Id$
12  *
13  * Wireshark - Network traffic analyzer
14  * By Gerald Combs <gerald@wireshark.org>
15  * Copyright 1998 Gerald Combs
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * as published by the Free Software Foundation; either version 2
20  * of the License, or (at your option) any later version.
21  * 
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  * 
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30  */
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
43 #endif
44
45 #include <glib.h>
46
47 #include <epan/packet.h>
48 #include <epan/conversation.h>
49 #include "packet-tcp.h"
50 #include <epan/prefs.h>
51
52 #define ISNS_PROTO_VER 0x1
53 #define ISNS_HEADER_SIZE 12
54
55 #define ISNS_TCP_PORT 3205
56 #define ISNS_UDP_PORT 3205
57
58 #define ISNS_OTHER_PORT 0
59 #define ISNS_ESI_PORT 1
60 #define ISNS_SCN_PORT 2
61
62
63 static dissector_handle_t isns_tcp_handle;
64 static dissector_handle_t isns_udp_handle;
65
66 static gint ett_isns_flags = -1;
67 static gint ett_isns_payload = -1;
68 static gint ett_isns_attribute = -1;
69 static gint ett_isns_port = -1;
70 static gint ett_isns_isnt = -1;
71
72 static guint AddAttribute(packet_info *pinfo, tvbuff_t *tvb, proto_tree *tree,
73                           guint offset, guint16 function_id);
74
75 /* Initialize the protocol and registered fields */
76 static int proto_isns = -1;
77
78
79 /* Header Stuff */
80 static int hf_isns_version = -1;
81 static int hf_isns_function_id = -1;
82 static int hf_isns_pdu_length = -1;
83 static int hf_isns_flags = -1;
84 static int hf_isns_transaction_id = -1;
85 static int hf_isns_sequence_id = -1;
86 static int hf_isns_payload = -1;
87 static int hf_isns_first_pdu = -1;
88 static int hf_isns_last_pdu = -1;
89 static int hf_isns_replace = -1;
90 static int hf_isns_auth = -1;
91 static int hf_isns_server = -1;
92 static int hf_isns_client = -1;
93
94 /* Payload stuff */
95 static int hf_isns_scn_bitmap                                      = -1;
96 static int hf_isns_scn_bitmap_initiator_and_self_information_only  = -1;
97 static int hf_isns_scn_bitmap_target_and_self_information_only     = -1;
98 static int hf_isns_scn_bitmap_management_registration_scn          = -1;
99 static int hf_isns_scn_bitmap_object_removed                       = -1;
100 static int hf_isns_scn_bitmap_object_added                         = -1;
101 static int hf_isns_scn_bitmap_object_updated                       = -1;
102 static int hf_isns_scn_bitmap_dd_dds_member_removed                = -1;
103 static int hf_isns_scn_bitmap_dd_dds_member_added                  = -1;
104 static int hf_isns_isnt_control = -1;
105 static int hf_isns_isnt_initiator = -1;
106 static int hf_isns_isnt_target = -1;
107
108 static int hf_isns_psb = -1;
109 static int hf_isns_psb_tunnel_mode = -1;
110 static int hf_isns_psb_transport_mode = -1;
111 static int hf_isns_psb_pfs = -1;
112 static int hf_isns_psb_aggressive_mode = -1;
113 static int hf_isns_psb_main_mode = -1;
114 static int hf_isns_psb_ike_ipsec = -1;
115 static int hf_isns_psb_bitmap = -1;
116
117 static int hf_isns_dd_member_portal_port = -1;
118 static int hf_isns_portal_port = -1;
119 static int hf_isns_esi_port = -1;
120 static int hf_isns_scn_port = -1;
121 static int hf_isns_port_type = -1;
122
123 static int hf_isns_entity_protocol = -1;
124 static int hf_isns_iscsi_node_type = -1;
125 static int hf_isns_resp_errorcode = -1;
126 static int hf_isns_attr_tag = -1;
127 static int hf_isns_attr_len = -1;
128 static int hf_isns_heartbeat_ipv6_addr = -1;
129 static int hf_isns_heartbeat_udp_port = -1;
130 static int hf_isns_heartbeat_tcp_port = -1;
131 static int hf_isns_heartbeat_interval = -1;
132 static int hf_isns_heartbeat_counter = -1;
133
134 static int hf_isns_mgmt_ip_addr = -1;
135 static int hf_isns_node_ip_addr = -1;
136 static int hf_isns_port_ip_addr = -1;
137 static int hf_isns_portal_ip_addr = -1;
138 static int hf_isns_dd_member_portal_ip_addr = -1;
139 static int hf_isns_iscsi_name = -1;
140 static int hf_isns_switch_name = -1;
141 static int hf_isns_dd_member_iscsi_name = -1;
142 static int hf_isns_virtual_fabric_id = -1;
143 static int hf_isns_proxy_iscsi_name = -1;
144 static int hf_isns_fc4_descriptor = -1;
145 static int hf_isns_iscsi_auth_method = -1;
146 static int hf_isns_iscsi_alias = -1;
147 static int hf_isns_portal_symbolic_name = -1;
148 static int hf_isns_dd_set_symbolic_name = -1;
149 static int hf_isns_dd_symbolic_name = -1;
150 static int hf_isns_symbolic_port_name = -1;
151 static int hf_isns_symbolic_node_name = -1;
152 static int hf_isns_entity_identifier = -1;
153 static int hf_isns_dd_id_next_id = -1;
154 static int hf_isns_member_iscsi_index = -1;
155 static int hf_isns_member_portal_index = -1;
156 static int hf_isns_member_fc_port_name = -1;
157 static int hf_isns_vendor_oui = -1;
158 static int hf_isns_preferred_id = -1;
159 static int hf_isns_assigned_id = -1;
160 static int hf_isns_dd_id = -1;
161 static int hf_isns_dd_set_id = -1;
162 static int hf_isns_dd_set_next_id = -1;
163 static int hf_isns_node_index = -1;
164 static int hf_isns_node_next_index = -1;
165 static int hf_isns_entity_index = -1;
166 static int hf_isns_portal_index = -1;
167 static int hf_isns_portal_next_index = -1;
168 static int hf_isns_entity_next_index = -1;
169 static int hf_isns_timestamp = -1;
170 static int hf_isns_esi_interval = -1;
171 static int hf_isns_registration_period = -1;
172 static int hf_isns_port_id = -1;
173 static int hf_isns_hard_address = -1;
174 static int hf_isns_wwnn_token = -1;
175 static int hf_isns_node_ipa = -1;
176 static int hf_isns_fc_port_name_wwpn = -1;
177 static int hf_isns_fc_node_name_wwnn = -1;
178 static int hf_isns_fabric_port_name = -1;
179 static int hf_isns_permanent_port_name = -1;
180 static int hf_isns_delimiter = -1;
181 static int hf_isns_not_decoded_yet = -1;
182 static int hf_isns_portal_group_tag = -1;
183 static int hf_isns_pg_iscsi_name = -1;
184 static int hf_isns_pg_portal_ip_addr = -1;
185 static int hf_isns_pg_portal_port = -1;
186 static int hf_isns_pg_index = -1;
187 static int hf_isns_pg_next_index = -1;
188
189
190
191 /* Desegment iSNS over TCP messages */
192 static gboolean isns_desegment = TRUE;
193
194 /* Function Id's */
195 #define ISNS_FUNC_DEVATTRREG     0x0001
196 #define ISNS_FUNC_DEVATTRQRY     0x0002
197 #define ISNS_FUNC_DEVGETNEXT     0x0003
198 #define ISNS_FUNC_DEREGDEV       0x0004
199 #define ISNS_FUNC_SCNREG         0x0005
200 #define ISNS_FUNC_SCNDEREG       0x0006
201 #define ISNS_FUNC_SCNEVENT       0x0007
202 #define ISNS_FUNC_SCN            0x0008
203 #define ISNS_FUNC_DDREG          0x0009
204 #define ISNS_FUNC_DDDEREG        0x000a
205 #define ISNS_FUNC_DDSREG         0x000b
206 #define ISNS_FUNC_DDSDEREG       0x000c
207 #define ISNS_FUNC_ESI            0x000d
208 #define ISNS_FUNC_HEARTBEAT      0x000e
209 #define ISNS_FUNC_RQSTDOMID      0x0011
210 #define ISNS_FUNC_RLSEDOMID      0x0012
211 #define ISNS_FUNC_GETDOMID       0x0013
212
213 #define ISNS_FUNC_RSP_DEVATTRREG 0x8001
214 #define ISNS_FUNC_RSP_DEVATTRQRY 0x8002
215 #define ISNS_FUNC_RSP_DEVGETNEXT 0x8003
216 #define ISNS_FUNC_RSP_DEREGDEV   0x8004
217 #define ISNS_FUNC_RSP_SCNREG     0x8005
218 #define ISNS_FUNC_RSP_SCNDEREG   0x8006
219 #define ISNS_FUNC_RSP_SCNEVENT   0x8007
220 #define ISNS_FUNC_RSP_SCN        0x8008
221 #define ISNS_FUNC_RSP_DDREG      0x8009
222 #define ISNS_FUNC_RSP_DDDEREG    0x800a
223 #define ISNS_FUNC_RSP_DDSREG     0x800b
224 #define ISNS_FUNC_RSP_DDSDEREG   0x800c
225 #define ISNS_FUNC_RSP_ESI        0x800d
226 #define ISNS_FUNC_RSP_RQSTDOMID  0x8011
227 #define ISNS_FUNC_RSP_RLSEDOMID  0x8012
228 #define ISNS_FUNC_RSP_GETDOMID   0x8013
229
230 static const value_string isns_function_ids[] = {
231 /* Requests*/
232     {ISNS_FUNC_DEVATTRREG,     "DevAttrReg"},
233     {ISNS_FUNC_DEVATTRQRY,     "DevAttrQry"},
234     {ISNS_FUNC_DEVGETNEXT,     "DevGetNext"},
235     {ISNS_FUNC_DEREGDEV,       "DeregDev"},
236     {ISNS_FUNC_SCNREG,         "SCNReg"},
237     {ISNS_FUNC_SCNDEREG,       "SCNDereg"},
238     {ISNS_FUNC_SCNEVENT,       "SCNEvent"},
239     {ISNS_FUNC_SCN,            "SCN"},
240     {ISNS_FUNC_DDREG,          "DDReg"},
241     {ISNS_FUNC_DDDEREG,        "DDDereg"},
242     {ISNS_FUNC_DDSREG,         "DDSReg"},
243     {ISNS_FUNC_DDSDEREG,       "DDSDereg"},
244     {ISNS_FUNC_ESI,            "ESI"},
245     {ISNS_FUNC_HEARTBEAT,      "Heartbeat"},
246     {ISNS_FUNC_RQSTDOMID,      "RqstDomId"},
247     {ISNS_FUNC_RLSEDOMID,      "RlseDomId"},
248     {ISNS_FUNC_GETDOMID,       "GetDomId"},
249
250 /* Responses */
251     {ISNS_FUNC_RSP_DEVATTRREG, "DevAttrRegRsp"},
252     {ISNS_FUNC_RSP_DEVATTRQRY, "DevAttrQryRsp"},
253     {ISNS_FUNC_RSP_DEVGETNEXT, "DevGetNextRsp"},
254     {ISNS_FUNC_RSP_DEREGDEV,   "DeregDevRsp"},
255     {ISNS_FUNC_RSP_SCNREG,     "SCNRegRsp"},
256     {ISNS_FUNC_RSP_SCNDEREG,   "SCNDeregRsp"},
257     {ISNS_FUNC_RSP_SCNEVENT,   "SCNEventRsp"},
258     {ISNS_FUNC_RSP_SCN,        "SCNRsp"},
259     {ISNS_FUNC_RSP_DDREG,      "DDRegRsp"},
260     {ISNS_FUNC_RSP_DDDEREG,    "DDDeregRsp"},
261     {ISNS_FUNC_RSP_DDSREG,     "DDSRegRsp"},
262     {ISNS_FUNC_RSP_DDSDEREG,   "DDSDeregRsp"},
263     {ISNS_FUNC_RSP_ESI,        "ESIRsp"},
264     {ISNS_FUNC_RSP_RQSTDOMID,  "RqstDomIdRsp"},
265     {ISNS_FUNC_RSP_RLSEDOMID,  "RlseDomIdRsp"},
266     {ISNS_FUNC_RSP_GETDOMID,   "GetDomIdRsp"},
267
268     {0x0,NULL},
269 };
270
271 #define ISNS_ENTITY_PROTOCOL_NO_PROTOCOL 1
272 #define ISNS_ENTITY_PROTOCOL_ISCSI       2
273 #define ISNS_ENTITY_PROTOCOL_IFCP        3
274
275
276 static const value_string isns_entity_protocol[] = {
277     {ISNS_ENTITY_PROTOCOL_NO_PROTOCOL, "No Protocol"},
278     {ISNS_ENTITY_PROTOCOL_ISCSI,       "iSCSI"},
279     {ISNS_ENTITY_PROTOCOL_IFCP,        "iFCP"}, 
280
281     {0x0,NULL},
282 };
283
284 static const value_string isns_errorcode[] = {
285     { 0,"No Error"},
286     { 1,"Unknown Error"},
287     { 2,"Message Format Error"},
288     { 3,"Invalid Registration"},
289     { 4,"RESERVED"},
290     { 5,"Invalid Query"},
291     { 6,"Source Unknown"},
292     { 7,"Source Absent"},
293     { 8,"Source Unauthorized"},
294     { 9,"No such Entry"},
295     {10,"Version Not Supported"},
296     {11,"Internal Error"},
297     {12,"Busy"},
298     {13,"Option Not Understood"},
299     {14,"Invalid Update"},
300     {15,"Message (FUNCTION_ID) Not supported"},
301     {16,"SCN Event Rejected"},
302     {17,"SCN Registration Rejected"},
303     {18,"Attribute Not Implemented"},
304     {19,"FC_DOMAIN_ID Not available"},
305     {20,"FC_DOMAIN_ID not allocated"},
306     {21,"ESI Not Available"},
307     {22,"Invalid Deregistration"},
308     {23,"Registration Feature Not Supported"},
309         
310     {0x0,NULL}
311 };
312
313
314 #define ISNS_ATTR_TAG_DELIMITER                     0
315 #define ISNS_ATTR_TAG_ENTITY_IDENTIFIER             1
316 #define ISNS_ATTR_TAG_ENTITY_PROTOCOL               2
317 #define ISNS_ATTR_TAG_MGMT_IP_ADDRESS               3
318 #define ISNS_ATTR_TAG_TIMESTAMP                     4
319 #define ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE        5
320 #define ISNS_ATTR_TAG_REGISTRATION_PERIOD           6
321 #define ISNS_ATTR_TAG_ENTITY_INDEX                  7
322 #define ISNS_ATTR_TAG_ENTITY_NEXT_INDEX             8
323 #define ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1         11
324 #define ISNS_ATTR_TAG_ENTITY_CERTIFICATE            12
325 #define ISNS_ATTR_TAG_PORTAL_IP_ADDRESS             16
326 #define ISNS_ATTR_TAG_PORTAL_PORT                   17
327 #define ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME          18
328 #define ISNS_ATTR_TAG_ESI_INTERVAL                  19
329 #define ISNS_ATTR_TAG_ESI_PORT                      20
330 #define ISNS_ATTR_TAG_PORTAL_INDEX                  22
331 #define ISNS_ATTR_TAG_SCN_PORT                      23
332 #define ISNS_ATTR_TAG_PORTAL_NEXT_INDEX             24
333 #define ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP        27
334 #define ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1         28
335 #define ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2         29
336 #define ISNS_ATTR_TAG_PORTAL_CERTIFICATE            31
337 #define ISNS_ATTR_TAG_ISCSI_NAME                    32
338 #define ISNS_ATTR_TAG_ISCSI_NODE_TYPE               33
339 #define ISNS_ATTR_TAG_ISCSI_ALIAS                   34
340 #define ISNS_ATTR_TAG_ISCSI_SCN_BITMAP              35
341 #define ISNS_ATTR_TAG_ISCSI_NODE_INDEX              36
342 #define ISNS_ATTR_TAG_WWNN_TOKEN                    37
343 #define ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX         38
344 #define ISNS_ATTR_TAG_ISCSI_AUTH_METHOD             42
345 #define ISNS_ATTR_TAG_PG_ISCSI_NAME                 48
346 #define ISNS_ATTR_TAG_PG_PORTAL_IP_ADDR             49
347 #define ISNS_ATTR_TAG_PG_PORTAL_PORT                50
348 #define ISNS_ATTR_TAG_PORTAL_GROUP_TAG              51
349 #define ISNS_ATTR_TAG_PORTAL_GROUP_INDEX            52
350 #define ISNS_ATTR_TAG_PORTAL_GROUP_NEXT_INDEX       53
351 #define ISNS_ATTR_TAG_FC_PORT_NAME_WWPN             64
352 #define ISNS_ATTR_TAG_PORT_ID                       65
353 #define ISNS_ATTR_TAG_FC_PORT_TYPE                  66
354 #define ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME            67
355 #define ISNS_ATTR_TAG_FABRIC_PORT_NAME              68
356 #define ISNS_ATTR_TAG_HARD_ADDRESS                  69
357 #define ISNS_ATTR_TAG_PORT_IP_ADDRESS               70
358 #define ISNS_ATTR_TAG_CLASS_OF_SERVICE              71
359 #define ISNS_ATTR_TAG_FC4_TYPES                     72
360 #define ISNS_ATTR_TAG_FC4_DESCRIPTOR                73
361 #define ISNS_ATTR_TAG_FC4_FEATURES                  74
362 #define ISNS_ATTR_TAG_IFCP_SCN_BITMAP               75
363 #define ISNS_ATTR_TAG_PORT_ROLE                     76
364 #define ISNS_ATTR_TAG_PERMANENT_PORT_NAME           77
365 #define ISNS_ATTR_TAG_FC4_TYPE_CODE                 95
366 #define ISNS_ATTR_TAG_FC_NODE_NAME_WWNN             96
367 #define ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME            97
368 #define ISNS_ATTR_TAG_NODE_IP_ADDRESS               98
369 #define ISNS_ATTR_TAG_NODE_IPA                      99
370 #define ISNS_ATTR_TAG_PROXY_ISCSI_NAME              101
371 #define ISNS_ATTR_TAG_SWITCH_NAME                   128
372 #define ISNS_ATTR_TAG_PREFERRED_ID                  129
373 #define ISNS_ATTR_TAG_ASSIGNED_ID                   130
374 #define ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID             131
375 #define ISNS_ATTR_TAG_VENDOR_OUI                    256
376 #define ISNS_ATTR_TAG_DD_SET_ID                     2049
377 #define ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME          2050
378 #define ISNS_ATTR_TAG_DD_SET_STATUS                 2051
379 #define ISNS_ATTR_TAG_DD_SET_NEXT_ID                2052
380 #define ISNS_ATTR_TAG_DD_ID                         2065
381 #define ISNS_ATTR_TAG_DD_SYMBOLIC_NAME              2066
382 #define ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX         2067
383 #define ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME          2068
384 #define ISNS_ATTR_TAG_DD_MEMBER_FC_PORT_NAME        2069
385 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX        2070
386 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS   2071
387 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT         2072
388 #define ISNS_ATTR_TAG_DD_FEATURES                   2078
389 #define ISNS_ATTR_TAG_DD_ID_NEXT_ID                 2079
390
391
392 static const value_string isns_attribute_tags[] = {
393     {ISNS_ATTR_TAG_DELIMITER,                   "Delimiter"},
394     {ISNS_ATTR_TAG_ENTITY_IDENTIFIER,           "Entity Identifier (EID)"},
395     {ISNS_ATTR_TAG_ENTITY_PROTOCOL,             "Entity Protocol"},
396     {ISNS_ATTR_TAG_MGMT_IP_ADDRESS,             "Management IP Address"},
397     {ISNS_ATTR_TAG_TIMESTAMP,                   "Timestamp"},
398     {ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE,      "Protocol Version Range"},
399     {ISNS_ATTR_TAG_REGISTRATION_PERIOD,         "Registration Period"},
400     {ISNS_ATTR_TAG_ENTITY_INDEX,                "Entity Index"},
401     {ISNS_ATTR_TAG_ENTITY_NEXT_INDEX,           "Entity Next Index"},
402     {ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1,       "Entity ISAKMP Phase-1"},
403     {ISNS_ATTR_TAG_ENTITY_CERTIFICATE,          "Entity Certificate"},
404     {ISNS_ATTR_TAG_PORTAL_IP_ADDRESS,           "Portal IP Address"},
405     {ISNS_ATTR_TAG_PORTAL_PORT,                 "Portal TCP/UDP Port"},
406     {ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME,        "Portal Symbolic Name"},
407     {ISNS_ATTR_TAG_ESI_INTERVAL,                "ESI Interval"},
408     {ISNS_ATTR_TAG_ESI_PORT,                    "ESI Port"},
409     {ISNS_ATTR_TAG_PORTAL_INDEX,                "Portal Index"},
410     {ISNS_ATTR_TAG_SCN_PORT,                    "SCN Port"},
411     {ISNS_ATTR_TAG_PORTAL_NEXT_INDEX,           "Portal Next Index"},
412     {ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP,      "Portal Security Bitmap"},
413     {ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1,       "Portal ISAKMP Phase-1"},
414     {ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2,       "Portal ISAKMP Phase-2"},
415     {ISNS_ATTR_TAG_PORTAL_CERTIFICATE,          "Portal Certificate"},
416     {ISNS_ATTR_TAG_ISCSI_NAME,                  "iSCSI Name"},
417     {ISNS_ATTR_TAG_ISCSI_NODE_TYPE,             "iSCSI Node Type"},
418     {ISNS_ATTR_TAG_ISCSI_ALIAS,                 "iSCSI Alias"},
419     {ISNS_ATTR_TAG_ISCSI_SCN_BITMAP,            "iSCSI SCN Bitmap"},
420     {ISNS_ATTR_TAG_ISCSI_NODE_INDEX,            "iSCSI Node Index"},
421     {ISNS_ATTR_TAG_WWNN_TOKEN,                  "WWNN Token"},
422     {ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX,       "iSCSI Node Next Index"},
423     {ISNS_ATTR_TAG_ISCSI_AUTH_METHOD,           "iSCSI AuthMethod"},
424     {ISNS_ATTR_TAG_PG_ISCSI_NAME,               "PG iSCSI Name"},
425     {ISNS_ATTR_TAG_PG_PORTAL_IP_ADDR,           "PG Portal IP Addr"},
426     {ISNS_ATTR_TAG_PG_PORTAL_PORT,              "PG Portal Port"},
427     {ISNS_ATTR_TAG_PORTAL_GROUP_TAG,            "Portal Group Tag"},
428     {ISNS_ATTR_TAG_PORTAL_GROUP_INDEX,          "PG Index"},
429     {ISNS_ATTR_TAG_PORTAL_GROUP_NEXT_INDEX,     "PG Next Index"},
430     {ISNS_ATTR_TAG_FC_PORT_NAME_WWPN,           "FC Port Name WWPN"},
431     {ISNS_ATTR_TAG_PORT_ID,                     "Port ID"},
432     {ISNS_ATTR_TAG_FC_PORT_TYPE,                "FC Port Type"},
433     {ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME,          "Symbolic Port Name"},
434     {ISNS_ATTR_TAG_FABRIC_PORT_NAME,            "Fabric Port Name"},
435     {ISNS_ATTR_TAG_HARD_ADDRESS,                "Hard Address"},
436     {ISNS_ATTR_TAG_PORT_IP_ADDRESS,             "Port IP-Address"},
437     {ISNS_ATTR_TAG_CLASS_OF_SERVICE,            "Class of Service"},
438     {ISNS_ATTR_TAG_FC4_TYPES,                   "FC-4 Types"},
439     {ISNS_ATTR_TAG_FC4_DESCRIPTOR,              "FC-4 Descriptor"},
440     {ISNS_ATTR_TAG_FC4_FEATURES,                "FC-4 Features"},
441     {ISNS_ATTR_TAG_IFCP_SCN_BITMAP,             "iFCP SCN bitmap"},
442     {ISNS_ATTR_TAG_PORT_ROLE,                   "Port Role"},
443     {ISNS_ATTR_TAG_PERMANENT_PORT_NAME,         "Permanent Port Name"},
444     {ISNS_ATTR_TAG_FC4_TYPE_CODE,               "FC-4 Type Code"},
445     {ISNS_ATTR_TAG_FC_NODE_NAME_WWNN,           "FC Node Name WWNN"},
446     {ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME,          "Symbolic Node Name"},
447     {ISNS_ATTR_TAG_NODE_IP_ADDRESS,             "Node IP-Address"},
448     {ISNS_ATTR_TAG_NODE_IPA,                    "Node IPA"},
449     {ISNS_ATTR_TAG_PROXY_ISCSI_NAME,            "Proxy iSCSI Name"},
450     {ISNS_ATTR_TAG_SWITCH_NAME,                 "Switch Name"},
451     {ISNS_ATTR_TAG_PREFERRED_ID,                "Preferred ID"},
452     {ISNS_ATTR_TAG_ASSIGNED_ID,                 "Assigned ID"},
453     {ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID,           "Virtual_Fabric_ID"},
454     {ISNS_ATTR_TAG_VENDOR_OUI,                  "iSNS Server Vendor OUI"},
455     {ISNS_ATTR_TAG_DD_SET_ID,                   "DD_Set ID"},
456     {ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME,        "DD_Set Sym Name"},
457     {ISNS_ATTR_TAG_DD_SET_STATUS,               "DD_Set Status"},
458     {ISNS_ATTR_TAG_DD_SET_NEXT_ID,              "DD_Set_Next_ID"},
459     {ISNS_ATTR_TAG_DD_ID,                       "DD_ID"},
460     {ISNS_ATTR_TAG_DD_SYMBOLIC_NAME,            "DD_Symbolic Name"},
461     {ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX,       "DD_Member iSCSI Index"},
462     {ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME,        "DD_Member iSCSI Name"},
463     {ISNS_ATTR_TAG_DD_MEMBER_FC_PORT_NAME,      "DD_Member FC Port Name"},
464     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX,      "DD Member Portal Index"},
465     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS, "DD_Member Portal IP Addr"},
466     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT,       "DD Member Portal TCP/UDP"},
467     {ISNS_ATTR_TAG_DD_FEATURES,                 "DD_Features"},
468     {ISNS_ATTR_TAG_DD_ID_NEXT_ID,               "DD_ID Next ID"},
469
470     {0,NULL}
471 };
472
473
474 /* iSNS flags */
475 #define ISNS_FLAGS_CLIENT       0x8000
476 #define ISNS_FLAGS_SERVER       0x4000
477 #define ISNS_FLAGS_AUTH         0x2000
478 #define ISNS_FLAGS_REPLACE      0x1000
479 #define ISNS_FLAGS_LAST_PDU     0x0800
480 #define ISNS_FLAGS_FIRST_PDU    0x0400
481
482
483 #define tfs_isns_scn_bitmap_initiator_and_self_information_only tfs_true_false
484 #define tfs_isns_scn_bitmap_target_and_self_information_only    tfs_true_false
485 #define tfs_isns_scn_bitmap_management_registration_scn         tfs_true_false
486 #define tfs_isns_scn_bitmap_object_removed                      tfs_true_false
487 #define tfs_isns_scn_bitmap_object_added                        tfs_true_false
488 #define tfs_isns_scn_bitmap_object_updated                      tfs_true_false
489 #define tfs_isns_scn_bitmap_dd_dds_member_removed               tfs_true_false
490 #define tfs_isns_scn_bitmap_dd_dds_member_added                 tfs_true_false
491
492 static const true_false_string tfs_isns_preferred = {
493     "Preferred",
494     "No Preference"
495 };
496
497 #define tfs_isns_psb_tunnel_mode    tfs_isns_preferred
498 #define tfs_isns_psb_transport_mode tfs_isns_preferred
499
500 #define tfs_isns_psb_pfs             tfs_enabled_disabled
501 #define tfs_isns_psb_aggressive_mode tfs_enabled_disabled
502 #define tfs_isns_psb_main_mode       tfs_enabled_disabled
503 #define tfs_isns_psb_ike_ipsec       tfs_enabled_disabled
504
505 static const true_false_string tfs_isns_psb_bitmap = {
506     "VALID",
507     "INVALID"
508 };
509
510 #define tfs_isns_isnt_control   tfs_yes_no
511 #define tfs_isns_isnt_initiator tfs_yes_no
512 #define tfs_isns_isnt_target    tfs_yes_no
513
514 static const true_false_string tfs_isns_port_type = {
515     "UDP",
516     "TCP"
517 };
518
519 static const true_false_string tfs_isns_flag_first_pdu = {
520     "First PDU of iSNS Message",
521     "Not the first PDU of iSNS Message"
522 };
523
524 static const true_false_string tfs_isns_flag_last_pdu = {
525     "Last PDU of iSNS Message",
526     "Not the Last PDU of iSNS Message"
527 };
528
529 static const true_false_string tfs_isns_flag_replace = {
530     "Replace",
531     "Don't replace"
532 };
533
534 static const true_false_string tfs_isns_flag_auth = {
535     "Authentication Block is PRESENT",
536     "No authentication block"
537 };
538
539 static const true_false_string tfs_isns_flag_server = {
540     "Sender is iSNS server",
541     "Sender is not iSNS server"
542 };
543
544 static const true_false_string tfs_isns_flag_client = {
545     "Sender is iSNS client",
546     "Sender is not iSNS client"
547 };
548
549
550 /* Initialize the subtree pointers */
551 static gint ett_isns = -1;
552
553
554 /* Code to actually dissect the packets */
555 static void
556 dissect_isns_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
557 {
558     guint offset = 0;
559     guint16 function_id;
560     guint16 isns_protocol_version;
561     guint32 packet_len = tvb_length(tvb);
562     /* Set up structures needed to add the protocol subtree and manage it */
563     proto_item *ti = NULL;
564     proto_tree *isns_tree = NULL;
565     
566     /* Make entries in Protocol column and Info column on summary display */
567     col_set_str(pinfo->cinfo, COL_PROTOCOL, "iSNS");
568     col_clear(pinfo->cinfo, COL_INFO);
569
570     /* Get the protocol version - only version one at the moment*/ 
571     isns_protocol_version = tvb_get_ntohs(tvb, offset + 0);
572     
573     /* Get the function id from the packet */
574     function_id =  tvb_get_ntohs(tvb, offset + 2);
575     
576     /* Add the function name in the info col */
577     if (check_col(pinfo->cinfo, COL_INFO)) 
578         col_add_str(pinfo->cinfo, COL_INFO,
579                     val_to_str(function_id, isns_function_ids,
580                                "Unknown function ID 0x%04x"));
581     
582     /* In the interest of speed, if "tree" is NULL, don't do any work not
583      * necessary to generate protocol tree items. 
584      */
585     if (tree) {
586         guint16 b;      
587         guint16 flags;  
588         proto_tree *tt;
589         proto_item *tflags;
590         proto_item *tpayload;
591
592         /* NOTE: The offset and length values in the call to
593          * "proto_tree_add_item()" define what data bytes to highlight in the hex
594          * display window when the line in the protocol tree display
595          * corresponding to that item is selected.
596          *  tvb_length(tvb) is a handy way to highlight all data from the offset to
597          *  the end of the packet. 
598          */
599
600         /* create display subtree for the protocol */
601         ti = proto_tree_add_item(tree, proto_isns, tvb, 0, -1, FALSE);
602         isns_tree = proto_item_add_subtree(ti, ett_isns);
603
604         /* OK... Sort out the header */
605         b = tvb_get_ntohs(tvb, offset);
606         proto_tree_add_uint(isns_tree, hf_isns_version, tvb, offset, 2, b);
607
608         b = tvb_get_ntohs(tvb, offset + 2);
609         proto_tree_add_uint(isns_tree, hf_isns_function_id, tvb, offset+2, 2, b);
610
611         b = tvb_get_ntohs(tvb, offset + 4);
612         proto_tree_add_uint(isns_tree, hf_isns_pdu_length, tvb, offset+4, 2, b);
613
614         /*FLAGS*/
615         flags = tvb_get_ntohs(tvb, offset + 6);
616         tflags = proto_tree_add_uint(isns_tree, hf_isns_flags, tvb, offset+6, 2, flags);
617         tt = proto_item_add_subtree(tflags, ett_isns_flags);
618
619         proto_tree_add_boolean(tt, hf_isns_client, tvb, offset+6, 2, flags);
620         proto_tree_add_boolean(tt, hf_isns_server, tvb, offset+6, 2, flags);
621         proto_tree_add_boolean(tt, hf_isns_auth, tvb, offset+6, 2, flags);
622         proto_tree_add_boolean(tt, hf_isns_replace, tvb, offset+6, 2, flags);
623         proto_tree_add_boolean(tt, hf_isns_last_pdu, tvb, offset+6, 2, flags);
624         proto_tree_add_boolean(tt, hf_isns_first_pdu, tvb, offset+6, 2, flags);
625
626         b = tvb_get_ntohs(tvb, offset + 8);
627         proto_tree_add_uint(isns_tree, hf_isns_transaction_id, tvb, offset+8, 2, b);
628
629         b = tvb_get_ntohs(tvb, offset + 10);
630         proto_tree_add_uint(isns_tree, hf_isns_sequence_id, tvb, offset+10, 2, b);
631
632         tpayload = proto_tree_add_item(isns_tree, hf_isns_payload, tvb, offset+12, packet_len - 12 , FALSE);
633         tt = proto_item_add_subtree(tpayload, ett_isns_payload);
634
635         /* Now set the offset to the start of the payload */
636         offset += ISNS_HEADER_SIZE;
637
638         /* Decode those attributes baby - Yeah!*/
639         switch (function_id)
640         {
641         case ISNS_FUNC_HEARTBEAT:
642         {
643             guint8 hb_ipv6[16];
644             guint16 port;
645             guint32 c;
646             tvb_memcpy(tvb,hb_ipv6,offset,16);
647             proto_tree_add_ipv6(tt,hf_isns_heartbeat_ipv6_addr, tvb, offset, 16, hb_ipv6);
648             offset += 16;
649
650             port = tvb_get_ntohs(tvb, offset);
651             proto_tree_add_uint(tt,hf_isns_heartbeat_tcp_port, tvb, offset, 2, port);
652             offset += 2;
653
654             port = tvb_get_ntohs(tvb, offset);
655             proto_tree_add_uint(tt,hf_isns_heartbeat_udp_port, tvb, offset, 2, port);
656             offset += 2;
657
658             c = tvb_get_ntohl(tvb, offset);
659             proto_tree_add_uint(tt,hf_isns_heartbeat_interval, tvb, offset, 4, c);
660             offset += 4;
661
662             c = tvb_get_ntohl(tvb, offset);
663             proto_tree_add_uint(tt,hf_isns_heartbeat_counter, tvb, offset, 4, c);
664             offset += 4;
665             break;
666         }
667         /* Responses */
668         case ISNS_FUNC_RSP_DEVATTRREG:
669         case ISNS_FUNC_RSP_DEVATTRQRY:
670         case ISNS_FUNC_RSP_DEVGETNEXT:
671         case ISNS_FUNC_RSP_DEREGDEV:
672         case ISNS_FUNC_RSP_SCNREG:
673         case ISNS_FUNC_RSP_SCNDEREG:
674         case ISNS_FUNC_RSP_SCNEVENT:
675         case ISNS_FUNC_RSP_SCN:
676         case ISNS_FUNC_RSP_DDREG:
677         case ISNS_FUNC_RSP_DDDEREG:
678         case ISNS_FUNC_RSP_DDSREG:
679         case ISNS_FUNC_RSP_DDSDEREG:
680         case ISNS_FUNC_RSP_ESI:
681         case ISNS_FUNC_RSP_RQSTDOMID:
682         case ISNS_FUNC_RSP_RLSEDOMID:
683         case ISNS_FUNC_RSP_GETDOMID:
684         {
685             /* Get the Error message of the response */
686             guint32 errorcode =  tvb_get_ntohl(tvb, offset);
687             proto_tree_add_uint(tt,hf_isns_resp_errorcode, tvb, offset, 4, errorcode);
688             offset += 4;
689             /* Messages */
690         }
691         case ISNS_FUNC_DEVATTRREG:
692         case ISNS_FUNC_DEVATTRQRY:
693         case ISNS_FUNC_DEVGETNEXT: 
694         case ISNS_FUNC_DEREGDEV:
695         case ISNS_FUNC_SCNREG:
696         case ISNS_FUNC_SCNDEREG:
697         case ISNS_FUNC_SCNEVENT:
698         case ISNS_FUNC_SCN:
699         case ISNS_FUNC_DDREG:
700         case ISNS_FUNC_DDDEREG:
701         case ISNS_FUNC_DDSREG:
702         case ISNS_FUNC_DDSDEREG:
703         case ISNS_FUNC_ESI:
704         case ISNS_FUNC_RQSTDOMID:
705         case ISNS_FUNC_RLSEDOMID:
706         case ISNS_FUNC_GETDOMID:
707         default:
708             /* we can only look at the attributes for the first PDU */
709             if(!(flags&ISNS_FLAGS_FIRST_PDU)){
710                 proto_tree_add_text(tt, tvb, offset, packet_len-offset, "This is not the first PDU. The attributes are not decoded");
711                 return;
712             }
713
714             while( offset < packet_len )
715             {
716                 offset = AddAttribute(pinfo, tvb, tt, offset, function_id);
717             }
718         }
719     }
720
721     return;
722 }
723
724 static guint
725 get_isns_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
726 {
727     guint16 isns_len;
728
729     isns_len = tvb_get_ntohs(tvb, offset+4);
730     return (isns_len+ISNS_HEADER_SIZE);
731 }
732
733 static int
734 dissect_isns_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
735 {       
736         gint length = tvb_length(tvb);
737         guint16 isns_protocol_version;
738         guint16 function_id;
739
740         if (length < ISNS_HEADER_SIZE) {
741                 /*
742                  * Not enough room to see if this is valid iSNS.
743                  */
744                 return 0;
745         }
746
747         /* Get the protocol version - only version one at the moment*/ 
748         isns_protocol_version = tvb_get_ntohs(tvb, 0);
749         if (isns_protocol_version != ISNS_PROTO_VER)
750                 return 0;
751
752         /* Get the function id from the packet */
753         function_id =  tvb_get_ntohs(tvb, 2);
754         if (match_strval(function_id, isns_function_ids) == NULL) {
755                 /* Unknown function ID */
756                 return 0;
757         }
758
759         tcp_dissect_pdus(tvb, pinfo, tree, isns_desegment, 12, get_isns_pdu_len,
760                 dissect_isns_pdu);
761         return length;
762 }
763
764 static int
765 dissect_isns_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
766 {       
767         gint length = tvb_length(tvb);
768         guint16 isns_protocol_version;
769         guint16 function_id;
770
771         if (length < ISNS_HEADER_SIZE) {
772                 /*
773                  * Not enough room to see if this is valid iSNS.
774                  */
775                 return 0;
776         }
777
778         /* Get the protocol version - only version one at the moment*/ 
779         isns_protocol_version = tvb_get_ntohs(tvb, 0);
780         if (isns_protocol_version != ISNS_PROTO_VER)
781                 return 0;
782
783         /* Get the function id from the packet */
784         function_id =  tvb_get_ntohs(tvb, 2);
785         if (match_strval(function_id, isns_function_ids) == NULL) {
786                 /* Unknown function ID */
787                 return 0;
788         }
789
790         dissect_isns_pdu(tvb, pinfo, tree);
791         return length;
792 }
793
794
795 static guint
796 dissect_isns_attr_ip_address(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
797 {
798         proto_item *item=NULL;
799         proto_tree *tree=NULL;
800
801         if(parent_tree){
802                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
803                 tree = proto_item_add_subtree(item, ett_isns_attribute);
804         }
805
806         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
807         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
808
809         return offset+8+len;
810 }
811
812 static guint
813 dissect_isns_attr_string(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
814 {
815         proto_item *item=NULL;
816         proto_tree *tree=NULL;
817
818         if(parent_tree){
819                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
820                 tree = proto_item_add_subtree(item, ett_isns_attribute);
821         }
822
823         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
824         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
825
826         return offset+8+len;
827 }
828
829 static guint
830 dissect_isns_attr_integer(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len, guint16 function_id)
831 {
832         proto_item *item=NULL;
833         proto_tree *tree=NULL;
834
835         /*
836          * 5.6.5.1
837          * in a DevAttrReg , the PGT (tag 51) may be sent as 0 length
838          * which then means that we wish to register the portal group tag
839          * as NULL.
840          * (At least) some servers will respond with PGT as a 0 length 
841          * value in these instances in the DevAttrRegRsp (eventhough I can
842          * not find this mentioned in the standard) so allow it for the 
843          * response as well.
844          */
845         if(len){
846                 if(parent_tree){
847                         item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
848                         tree = proto_item_add_subtree(item, ett_isns_attribute);
849                 }
850         } else if((tag==ISNS_ATTR_TAG_PORTAL_GROUP_TAG)&&((function_id==ISNS_FUNC_DEVATTRREG)||(function_id==ISNS_FUNC_RSP_DEVATTRREG))){
851                 /* 5.6.5.1 */
852                 if(parent_tree){
853                         item=proto_tree_add_uint_format(parent_tree, hf_isns_portal_group_tag, tvb, offset, 8, 0, "PG Tag: <NULL>");
854                         tree = proto_item_add_subtree(item, ett_isns_attribute);
855                 }
856         } else {
857                 if(parent_tree){
858                         item=proto_tree_add_text(parent_tree, tvb, offset, 8, "Oops, you surprised me here. a 0 byte integer.");
859                         tree = proto_item_add_subtree(item, ett_isns_attribute);
860                 }
861         }
862
863         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
864         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
865
866         return offset+8+len;
867 }
868
869 static guint
870 dissect_isns_attr_port(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len,
871                        guint16 isns_port_type, packet_info *pinfo)
872 {
873         proto_item *tree=NULL;
874         proto_item *item=NULL;
875         guint16 port = tvb_get_ntohs(tvb, offset + 10);
876         guint16 isudp = tvb_get_ntohs(tvb, offset + 8)&0x01;
877         conversation_t *conversation;
878
879         if(parent_tree){
880             item = proto_tree_add_uint(parent_tree, hf_index, tvb, offset+8, 4, port);
881             tree = proto_item_add_subtree(item, ett_isns_port);
882         }
883
884         proto_tree_add_boolean(tree, hf_isns_port_type, tvb, offset+8, 2, isudp);
885
886         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
887         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
888
889         if ((isns_port_type == ISNS_ESI_PORT) || (isns_port_type == ISNS_SCN_PORT)) {
890             if (isudp) {
891                 conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
892                                                   port, 0, NO_PORT_B);
893                 if (conversation == NULL) {
894                     conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst,
895                                                      PT_UDP, port, 0, NO_PORT2_FORCE);
896                     conversation_set_dissector (conversation, isns_udp_handle);
897                 }
898             }
899             else {
900                 conversation = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_TCP,
901                                                   port, 0, NO_PORT_B);
902                 if (conversation == NULL) {
903                     conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst,
904                                                      PT_TCP, port, 0, NO_PORT2_FORCE);
905                     conversation_set_dissector (conversation, isns_tcp_handle);
906                 }
907             }
908         }
909
910         return offset+8+len;
911 }
912
913 static guint
914 dissect_isns_attr_none(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
915 {
916         proto_item *tree=NULL;
917         proto_item *item=NULL;
918
919         if(parent_tree){
920                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, 8, FALSE);
921                 tree = proto_item_add_subtree(item, ett_isns_port);
922         }
923
924         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
925         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
926
927         return offset+8+len;
928 }
929
930 static guint
931 dissect_isns_attr_not_decoded_yet(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
932 {
933         proto_item *tree=NULL;
934         proto_item *item=NULL;
935
936         if(parent_tree){
937                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
938                 tree = proto_item_add_subtree(item, ett_isns_port);
939         }
940
941         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
942         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
943
944         return offset+8+len;
945 }
946
947 static guint
948 dissect_isns_attr_iscsi_node_type(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
949 {
950         proto_item *item=NULL;
951         proto_tree *tree=NULL;
952         guint32 node_type=tvb_get_ntohl(tvb, offset + 8);
953
954         if(parent_tree){
955                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
956                 tree = proto_item_add_subtree(item, ett_isns_attribute);
957         }
958
959         proto_tree_add_boolean(tree, hf_isns_isnt_control,   tvb, offset+8, 4, node_type);
960         if(node_type&0x00000004){
961                 proto_item_append_text(item, " Control");
962         }
963         proto_tree_add_boolean(tree, hf_isns_isnt_initiator, tvb, offset+8, 4, node_type);
964         if(node_type&0x00000002){
965                 proto_item_append_text(item, " Initiator");
966         }
967         proto_tree_add_boolean(tree, hf_isns_isnt_target,    tvb, offset+8, 4, node_type);
968         if(node_type&0x00000001){
969                 proto_item_append_text(item, " Target");
970         }
971
972         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
973         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
974
975         return offset+8+len;
976 }
977
978
979
980 static guint
981 dissect_isns_attr_portal_security_bitmap(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
982 {
983         proto_item *item=NULL;
984         proto_tree *tree=NULL;
985         guint32 psb=tvb_get_ntohl(tvb, offset + 8);
986
987         if(parent_tree){
988                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
989                 tree = proto_item_add_subtree(item, ett_isns_attribute);
990         }
991
992         proto_tree_add_boolean(tree, hf_isns_psb_tunnel_mode,     tvb, offset+8, 4, psb);
993         proto_tree_add_boolean(tree, hf_isns_psb_transport_mode,  tvb, offset+8, 4, psb);
994         proto_tree_add_boolean(tree, hf_isns_psb_pfs,             tvb, offset+8, 4, psb);
995         proto_tree_add_boolean(tree, hf_isns_psb_aggressive_mode, tvb, offset+8, 4, psb);
996         proto_tree_add_boolean(tree, hf_isns_psb_main_mode,       tvb, offset+8, 4, psb);
997         proto_tree_add_boolean(tree, hf_isns_psb_ike_ipsec,       tvb, offset+8, 4, psb);
998         proto_tree_add_boolean(tree, hf_isns_psb_bitmap,          tvb, offset+8, 4, psb);
999
1000         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
1001         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
1002
1003         return offset+8+len;
1004 }
1005
1006
1007
1008 static guint
1009 dissect_isns_attr_scn_bitmap(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
1010 {
1011         proto_item *item=NULL;
1012         proto_tree *tree=NULL;
1013         guint32 scn_bitmap=tvb_get_ntohl(tvb, offset + 8);
1014
1015         if(parent_tree){
1016                 item=proto_tree_add_item(parent_tree, hf_index, tvb, offset + 8, len, FALSE);
1017                 tree = proto_item_add_subtree(item, ett_isns_attribute);
1018         }
1019
1020
1021         /*
1022          24              INITIATOR AND SELF INFORMATION ONLY 
1023          25              TARGET AND SELF INFORMATION ONLY  
1024          26              MANAGEMENT REGISTRATION/SCN 
1025          27              OBJECT REMOVED 
1026          28              OBJECT ADDED 
1027          29              OBJECT UPDATED 
1028          30              DD/DDS MEMBER REMOVED (Mgmt Reg/SCN only) 
1029          31 (Lsb)        DD/DDS MEMBER ADDED (Mgmt Reg/SCN only) 
1030         */
1031         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_initiator_and_self_information_only, tvb, offset+8, 4, scn_bitmap);
1032         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_target_and_self_information_only,    tvb, offset+8, 4, scn_bitmap);
1033         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_management_registration_scn,         tvb, offset+8, 4, scn_bitmap);
1034         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_object_removed,                      tvb, offset+8, 4, scn_bitmap);
1035         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_object_added,                        tvb, offset+8, 4, scn_bitmap);
1036         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_object_updated,                      tvb, offset+8, 4, scn_bitmap);
1037         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_dd_dds_member_removed,               tvb, offset+8, 4, scn_bitmap);
1038         proto_tree_add_boolean(tree, hf_isns_scn_bitmap_dd_dds_member_added,                 tvb, offset+8, 4, scn_bitmap);
1039
1040         proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
1041         proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
1042
1043         return offset+8+len;
1044 }
1045
1046
1047
1048
1049 static guint
1050 AddAttribute(packet_info *pinfo, tvbuff_t *tvb, proto_tree *tree, guint offset,
1051              guint16 function_id)
1052 {
1053     guint32 tag,len;
1054
1055
1056     /* Get the Tag */
1057     tag = tvb_get_ntohl(tvb, offset);
1058
1059     /* Now the Length */
1060     len = tvb_get_ntohl(tvb, offset + 4);
1061
1062     if (!len) {
1063         if (tree) {
1064             proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
1065             proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
1066         }
1067         return (offset+8);
1068     }
1069     
1070     tvb_ensure_bytes_exist(tvb, offset, len+8);
1071
1072     switch( tag )
1073     {
1074     case ISNS_ATTR_TAG_DELIMITER:
1075         dissect_isns_attr_none(tvb, offset, tree, hf_isns_delimiter, tag, len);
1076         break;
1077     case ISNS_ATTR_TAG_ENTITY_IDENTIFIER:
1078         dissect_isns_attr_string(tvb, offset, tree, hf_isns_entity_identifier, tag, len);
1079         break;
1080     case ISNS_ATTR_TAG_ENTITY_PROTOCOL:
1081     if(len != 4) THROW(ReportedBoundsError);
1082         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_entity_protocol, tag, len, function_id);
1083         break;
1084     case ISNS_ATTR_TAG_MGMT_IP_ADDRESS:
1085     if(len != 16) THROW(ReportedBoundsError);
1086         dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_mgmt_ip_addr, tag, len);
1087         break;
1088     case ISNS_ATTR_TAG_TIMESTAMP:
1089     if(len != 8) THROW(ReportedBoundsError);
1090         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_timestamp, tag, len, function_id);
1091         break;
1092     case ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE:
1093         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1094         break;
1095     case ISNS_ATTR_TAG_REGISTRATION_PERIOD:
1096     if(len != 4) THROW(ReportedBoundsError);
1097         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_registration_period, tag, len, function_id);
1098         break;
1099     case ISNS_ATTR_TAG_ENTITY_INDEX:
1100     if(len != 4) THROW(ReportedBoundsError);
1101         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_entity_index, tag, len, function_id);
1102         break;
1103     case ISNS_ATTR_TAG_ENTITY_NEXT_INDEX:
1104     if(len != 4) THROW(ReportedBoundsError);
1105         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_entity_next_index, tag, len, function_id);
1106         break;
1107     case ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1:
1108         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1109         break;
1110     case ISNS_ATTR_TAG_ENTITY_CERTIFICATE:
1111         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1112         break;
1113     case ISNS_ATTR_TAG_PORTAL_IP_ADDRESS:
1114         switch(len){
1115         case 64:
1116                 proto_tree_add_text(tree, tvb, offset, -1, "Broken iSNS implementation. The PORTAL_IP_ADDRESS tag should be 16 bytes in length");
1117         case 16:
1118                 dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_portal_ip_addr, tag, 16);
1119                 break;
1120         default:
1121                 THROW(ReportedBoundsError);
1122         }
1123         break;
1124     case ISNS_ATTR_TAG_PORTAL_PORT:
1125     if(len != 4) THROW(ReportedBoundsError);
1126         dissect_isns_attr_port(tvb, offset, tree, hf_isns_portal_port, tag, len, ISNS_OTHER_PORT, pinfo);
1127         break;
1128     case ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME:
1129         dissect_isns_attr_string(tvb, offset, tree, hf_isns_portal_symbolic_name, tag, len);
1130         break;
1131     case ISNS_ATTR_TAG_ESI_INTERVAL:
1132     if(len != 4) THROW(ReportedBoundsError);
1133         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_esi_interval, tag, len, function_id);
1134         break;
1135     case ISNS_ATTR_TAG_ESI_PORT:
1136     if(len != 4) THROW(ReportedBoundsError);
1137         dissect_isns_attr_port(tvb, offset, tree, hf_isns_esi_port, tag, len, ISNS_ESI_PORT, pinfo);
1138         break;
1139     case ISNS_ATTR_TAG_PORTAL_INDEX:
1140     if(len != 4) THROW(ReportedBoundsError);
1141         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_index, tag, len, function_id);
1142         break;
1143     case ISNS_ATTR_TAG_SCN_PORT:
1144     if(len != 4) THROW(ReportedBoundsError);
1145         dissect_isns_attr_port(tvb, offset, tree, hf_isns_scn_port, tag, len, ISNS_SCN_PORT, pinfo);
1146         break;
1147     case ISNS_ATTR_TAG_PORTAL_NEXT_INDEX:
1148     if(len != 4) THROW(ReportedBoundsError);
1149         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_next_index, tag, len, function_id);
1150         break;
1151     case ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP:
1152     if(len != 4) THROW(ReportedBoundsError);
1153         dissect_isns_attr_portal_security_bitmap(tvb, offset, tree, hf_isns_psb, tag, len);
1154         break;
1155     case ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1:
1156         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1157         break;
1158     case ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2:
1159         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1160         break;
1161     case ISNS_ATTR_TAG_PORTAL_CERTIFICATE:
1162         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1163         break;
1164     case ISNS_ATTR_TAG_ISCSI_NAME:
1165         dissect_isns_attr_string(tvb, offset, tree, hf_isns_iscsi_name, tag, len);
1166         break;
1167     case ISNS_ATTR_TAG_ISCSI_NODE_TYPE:
1168     if(len != 4) THROW(ReportedBoundsError);
1169         dissect_isns_attr_iscsi_node_type(tvb, offset, tree, hf_isns_iscsi_node_type, tag, len);
1170         break;
1171     case ISNS_ATTR_TAG_ISCSI_ALIAS:
1172         dissect_isns_attr_string(tvb, offset, tree, hf_isns_iscsi_alias, tag, len);
1173         break;
1174     case ISNS_ATTR_TAG_ISCSI_SCN_BITMAP:
1175     if(len != 4) THROW(ReportedBoundsError);
1176         dissect_isns_attr_scn_bitmap(tvb, offset, tree, hf_isns_scn_bitmap, tag, len);
1177         break;
1178     case ISNS_ATTR_TAG_ISCSI_NODE_INDEX:
1179     if(len != 4) THROW(ReportedBoundsError);
1180         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_node_index, tag, len, function_id);
1181         break;
1182     case ISNS_ATTR_TAG_WWNN_TOKEN:
1183     if(len != 8) THROW(ReportedBoundsError);
1184         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_wwnn_token, tag, len, function_id);
1185         break;
1186     case ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX:
1187     if(len != 4) THROW(ReportedBoundsError);
1188         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_node_next_index, tag, len, function_id);
1189         break;
1190     case ISNS_ATTR_TAG_ISCSI_AUTH_METHOD:
1191         dissect_isns_attr_string(tvb, offset, tree, hf_isns_iscsi_auth_method, tag, len);
1192         break;
1193     case ISNS_ATTR_TAG_PG_ISCSI_NAME:
1194         dissect_isns_attr_string(tvb, offset, tree, hf_isns_pg_iscsi_name, tag, len);
1195         break;
1196     case ISNS_ATTR_TAG_PG_PORTAL_IP_ADDR:
1197         switch(len){
1198         case 64:
1199                 proto_tree_add_text(tree, tvb, offset, -1, "Broken iSNS implementation. The PG_PORTAL_IP_ADDRESS tag should be 16 bytes in length");
1200         case 16:
1201                 dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_pg_portal_ip_addr, tag, 16);
1202                 break;
1203         default:
1204                 THROW(ReportedBoundsError);
1205         }
1206         break;
1207     case ISNS_ATTR_TAG_PG_PORTAL_PORT:
1208     if(len != 4) THROW(ReportedBoundsError);
1209         dissect_isns_attr_port(tvb, offset, tree, hf_isns_pg_portal_port, tag, len, ISNS_OTHER_PORT, pinfo);
1210         break;
1211     case ISNS_ATTR_TAG_PORTAL_GROUP_TAG:
1212     if(len != 4) THROW(ReportedBoundsError);
1213         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_group_tag, tag, len, function_id);
1214         break;
1215     case ISNS_ATTR_TAG_PORTAL_GROUP_INDEX:
1216     if(len != 4) THROW(ReportedBoundsError);
1217         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_pg_index, tag, len, function_id);
1218         break;
1219     case ISNS_ATTR_TAG_PORTAL_GROUP_NEXT_INDEX:
1220     if(len != 4) THROW(ReportedBoundsError);
1221         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_pg_next_index, tag, len, function_id);
1222         break;
1223     case ISNS_ATTR_TAG_FC_PORT_NAME_WWPN:
1224     if(len != 8) THROW(ReportedBoundsError);
1225         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_fc_port_name_wwpn, tag, len, function_id);
1226         break;
1227     case ISNS_ATTR_TAG_PORT_ID:
1228     if(len != 3) THROW(ReportedBoundsError);
1229         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_port_id, tag, len, function_id);
1230         break;
1231     case ISNS_ATTR_TAG_FC_PORT_TYPE:
1232         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1233         break;
1234         /*
1235           0x0000           Unidentified/Null Entry 
1236           0x0001           Fibre Channel N_Port 
1237           0x0002           Fibre Channel NL_Port 
1238           0x0003           Fibre Channel F/NL_Port 
1239           0x0081           Fibre Channel F_Port 
1240           0x0082           Fibre Channel FL_Port 
1241           0x0084           Fibre Channel E_Port 
1242           0xFF12           iFCP Port 
1243         */
1244     case ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME:
1245         dissect_isns_attr_string(tvb, offset, tree, hf_isns_symbolic_port_name, tag, len);
1246         break;
1247     case ISNS_ATTR_TAG_FABRIC_PORT_NAME:
1248     if(len != 8) THROW(ReportedBoundsError);
1249         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_fabric_port_name, tag, len, function_id);
1250         break;
1251     case ISNS_ATTR_TAG_HARD_ADDRESS:
1252     if(len != 3) THROW(ReportedBoundsError);
1253         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_hard_address, tag, len, function_id);
1254         break;
1255     case ISNS_ATTR_TAG_PORT_IP_ADDRESS:
1256     if(len != 16) THROW(ReportedBoundsError);
1257         dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_port_ip_addr, tag, len);
1258         break;
1259     case ISNS_ATTR_TAG_CLASS_OF_SERVICE:
1260         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1261         break;
1262         /*
1263           bit 29             Fibre Channel Class 2 Supported
1264           bit 28             Fibre Channel Class 3 Supported
1265         */
1266     case ISNS_ATTR_TAG_FC4_TYPES:
1267         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1268         break;
1269     case ISNS_ATTR_TAG_FC4_DESCRIPTOR:
1270         dissect_isns_attr_string(tvb, offset, tree, hf_isns_fc4_descriptor, tag, len);
1271         break;
1272     case ISNS_ATTR_TAG_FC4_FEATURES:
1273         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1274         break;
1275     case ISNS_ATTR_TAG_IFCP_SCN_BITMAP:
1276         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1277         break;
1278         /*
1279           bit 24              INITIATOR AND SELF INFORMATION ONLY
1280           bit 25              TARGET AND SELF INFORMATION ONLY
1281           bit 26              MANAGEMENT REGISTRATION/SCN
1282           bit 27              OBJECT REMOVED
1283           bit 28              OBJECT ADDED
1284           bit 29              OBJECT UPDATED
1285           bit 30              DD/DDS MEMBER REMOVED (Mgmt Reg/SCN only)
1286           bit 31 (Lsb)        DD/DDS MEMBER ADDED (Mgmt Reg/SCN only)
1287         */
1288     case ISNS_ATTR_TAG_PORT_ROLE:
1289         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1290         break;
1291         /*
1292           bit 29              Control 
1293           bit 30              FCP Initiator 
1294           bit 31 (Lsb)        FCP Target 
1295         */
1296     case ISNS_ATTR_TAG_PERMANENT_PORT_NAME:
1297     if(len != 8) THROW(ReportedBoundsError);
1298         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_permanent_port_name, tag, len, function_id);
1299         break;
1300     case ISNS_ATTR_TAG_FC4_TYPE_CODE:
1301         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1302         break;
1303         /* 8bit type code in byte0 */
1304     case ISNS_ATTR_TAG_FC_NODE_NAME_WWNN:
1305     if(len != 8) THROW(ReportedBoundsError);
1306         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_fc_node_name_wwnn, tag, len, function_id);
1307         break;
1308     case ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME:
1309         dissect_isns_attr_string(tvb, offset, tree, hf_isns_symbolic_node_name, tag, len);
1310         break;
1311     case ISNS_ATTR_TAG_NODE_IP_ADDRESS:
1312     if(len != 16) THROW(ReportedBoundsError);
1313         dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_node_ip_addr, tag, len);
1314         break;
1315     case ISNS_ATTR_TAG_NODE_IPA:
1316     if(len != 8) THROW(ReportedBoundsError);
1317         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_node_ipa, tag, len, function_id);
1318         break;
1319     case ISNS_ATTR_TAG_PROXY_ISCSI_NAME:
1320         dissect_isns_attr_string(tvb, offset, tree, hf_isns_proxy_iscsi_name, tag, len);
1321         break;
1322     case ISNS_ATTR_TAG_SWITCH_NAME:
1323     if(len != 8) THROW(ReportedBoundsError);
1324         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_switch_name, tag, len, function_id);
1325         break;
1326     case ISNS_ATTR_TAG_PREFERRED_ID:
1327     if(len != 4) THROW(ReportedBoundsError);
1328         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_preferred_id, tag, len, function_id);
1329         break;
1330     case ISNS_ATTR_TAG_ASSIGNED_ID:
1331     if(len != 4) THROW(ReportedBoundsError);
1332         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_assigned_id, tag, len, function_id);
1333         break;
1334     case ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID:
1335         dissect_isns_attr_string(tvb, offset, tree, hf_isns_virtual_fabric_id, tag, len);
1336         break;
1337     case ISNS_ATTR_TAG_VENDOR_OUI:
1338     if(len != 4) THROW(ReportedBoundsError);
1339         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_vendor_oui, tag, len, function_id);
1340         break;
1341     case ISNS_ATTR_TAG_DD_SET_ID:
1342     if(len != 4) THROW(ReportedBoundsError);
1343         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_dd_set_id, tag, len, function_id);
1344         break;
1345     case ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME:
1346         dissect_isns_attr_string(tvb, offset, tree, hf_isns_dd_set_symbolic_name, tag, len);
1347         break;
1348     case ISNS_ATTR_TAG_DD_SET_STATUS:
1349         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1350         break;
1351     case ISNS_ATTR_TAG_DD_SET_NEXT_ID:
1352     if(len != 4) THROW(ReportedBoundsError);
1353         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_dd_set_next_id, tag, len, function_id);
1354         break;
1355     case ISNS_ATTR_TAG_DD_ID:
1356     if(len != 4) THROW(ReportedBoundsError);
1357         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_dd_id, tag, len, function_id);
1358         break;
1359     case ISNS_ATTR_TAG_DD_SYMBOLIC_NAME:
1360         dissect_isns_attr_string(tvb, offset, tree, hf_isns_dd_symbolic_name, tag, len);
1361         break;
1362     case ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX:
1363     if(len != 4) THROW(ReportedBoundsError);
1364         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_member_iscsi_index, tag, len, function_id);
1365         break;
1366     case ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME:
1367         dissect_isns_attr_string(tvb, offset, tree, hf_isns_dd_member_iscsi_name, tag, len);
1368         break;
1369     case ISNS_ATTR_TAG_DD_MEMBER_FC_PORT_NAME:
1370     if(len != 4) THROW(ReportedBoundsError);
1371         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_member_fc_port_name, tag, len, function_id);
1372         break;
1373     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX:
1374     if(len != 4) THROW(ReportedBoundsError);
1375         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_member_portal_index, tag, len, function_id);
1376         break;
1377     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS:
1378     if(len != 16) THROW(ReportedBoundsError);
1379         dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_dd_member_portal_ip_addr, tag, len);
1380         break;
1381     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT:
1382     if(len != 4) THROW(ReportedBoundsError);
1383         dissect_isns_attr_port(tvb, offset, tree, hf_isns_dd_member_portal_port,
1384                                         tag, len, ISNS_OTHER_PORT, pinfo);
1385         break;
1386     case ISNS_ATTR_TAG_DD_FEATURES:
1387         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1388         break;
1389     case ISNS_ATTR_TAG_DD_ID_NEXT_ID:
1390     if(len != 4) THROW(ReportedBoundsError);
1391         dissect_isns_attr_integer(tvb, offset, tree, hf_isns_dd_id_next_id, tag, len, function_id);
1392         break;
1393     default:
1394         dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
1395     }
1396
1397     
1398     /* move on the offset to next attribute */
1399
1400     return offset+len+8;
1401 }
1402
1403
1404
1405 /* Register the protocol with Wireshark */
1406
1407 /* this format is require because a script is used to build the C function
1408    that calls all the protocol registration.
1409 */
1410
1411 void proto_register_isns(void)
1412 {
1413     /* Setup list of header fields  See Section 1.6.1 for details*/
1414     static hf_register_info hf[] = {
1415         /* The Header Stuff */
1416         { &hf_isns_version,
1417           { "iSNSP Version","isns.PVer",
1418             FT_UINT16, BASE_DEC, NULL, 0,          
1419             "iSNS Protocol Version" ,HFILL}
1420         },
1421         { &hf_isns_function_id,
1422           { "Function ID","isns.functionid",        
1423             FT_UINT16, BASE_DEC,VALS(isns_function_ids),0,          
1424             "iSNS Function ID" ,HFILL}
1425         },
1426         { &hf_isns_pdu_length,
1427           { "PDU Length","isns.pdulength",
1428             FT_UINT16, BASE_DEC,NULL,0,
1429             "iSNS PDU Length" ,HFILL}
1430         },
1431
1432         { &hf_isns_flags,
1433           { "Flags","isns.flags",
1434             FT_UINT16, BASE_HEX,NULL,0,
1435             "iSNS Flags" ,HFILL}
1436         },
1437         { &hf_isns_client,
1438           { "Client","isns.flags.client",
1439             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_client), ISNS_FLAGS_CLIENT,
1440             "iSNS Client" ,HFILL}
1441         },
1442         { &hf_isns_server,
1443           { "Server","isns.flags.server",
1444             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_server), ISNS_FLAGS_SERVER,
1445             "iSNS Server" ,HFILL}
1446         },
1447         { &hf_isns_auth,
1448           { "Auth","isns.flags.authentication_block",
1449             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_auth), ISNS_FLAGS_AUTH,
1450             "is iSNS Authentication Block present?" ,HFILL}
1451         },
1452         { &hf_isns_replace,
1453           { "Replace","isns.flags.replace",
1454             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_replace), ISNS_FLAGS_REPLACE,
1455             "iSNS Replace" ,HFILL}
1456         },
1457         { &hf_isns_last_pdu,
1458           { "Last PDU","isns.flags.lastpdu",
1459             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_last_pdu), ISNS_FLAGS_LAST_PDU,
1460             "iSNS Last PDU" ,HFILL}
1461         },
1462         { &hf_isns_first_pdu,
1463           { "First PDU","isns.flags.firstpdu",
1464             FT_BOOLEAN, 16, TFS(&tfs_isns_flag_first_pdu), ISNS_FLAGS_FIRST_PDU,
1465             "iSNS First PDU",HFILL }
1466         },
1467
1468
1469         { &hf_isns_transaction_id,
1470           { "Transaction ID","isns.transactionid",
1471             FT_UINT16, BASE_DEC,NULL,0,
1472             "iSNS transaction ID" ,HFILL}
1473         },
1474         { &hf_isns_sequence_id,
1475           { "Sequence ID","isns.sequenceid",
1476             FT_UINT16, BASE_DEC,NULL,0,
1477             "iSNS sequence ID" ,HFILL}
1478         },
1479
1480         { &hf_isns_entity_protocol,
1481           { "Entity Protocol","isns.entity_protocol",
1482             FT_UINT32, BASE_DEC,VALS(isns_entity_protocol),0,
1483             "iSNS Entity Protocol" ,HFILL}
1484         },
1485         /* The Payload stuff */
1486
1487         { &hf_isns_dd_member_portal_port,
1488           { "DD Member Portal Port","isns.dd_member_portal_port",
1489             FT_UINT32, BASE_DEC, NULL, 0,
1490             "TCP/UDP DD Member Portal Port", HFILL }
1491         },
1492
1493         { &hf_isns_iscsi_node_type,
1494           { "iSCSI Node Type","isns.iscsi.node_type",
1495             FT_UINT32, BASE_HEX, NULL, 0,
1496             NULL, HFILL }
1497         },
1498
1499         { &hf_isns_esi_port,
1500           { "ESI Port","isns.esi_port",
1501             FT_UINT32, BASE_DEC, NULL, 0,
1502             "TCP/UDP ESI Port", HFILL }
1503         },
1504
1505         { &hf_isns_scn_port,
1506           { "SCN Port","isns.scn_port",
1507             FT_UINT32, BASE_DEC, NULL, 0,
1508             "TCP/UDP SCN Port", HFILL }
1509         },
1510
1511         { &hf_isns_portal_port,
1512           { "Portal Port","isns.portal_port",
1513             FT_UINT32, BASE_DEC, NULL, 0,
1514             "TCP/UDP Portal Port", HFILL }
1515         },
1516
1517         { &hf_isns_pg_portal_port,
1518           { "PG Portal Port","isns.pg.portal_port",
1519             FT_UINT32, BASE_DEC, NULL, 0,
1520             "PG Portal TCP/UDP Port", HFILL }
1521         },
1522
1523         { &hf_isns_port_type,
1524           { "Port Type","isns.port.port_type",
1525             FT_BOOLEAN, 16, TFS(&tfs_isns_port_type), 0x01, /* bit 15 (or bit 1 of a 16bit word) */
1526             NULL,HFILL }
1527         },
1528
1529         { &hf_isns_psb,
1530           { "Portal Security Bitmap","isns.psb",
1531             FT_UINT32, BASE_HEX, NULL, 0,
1532             NULL, HFILL }
1533         },
1534         { &hf_isns_psb_tunnel_mode,
1535           { "Tunnel Mode","isns.psb.tunnel",
1536             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_tunnel_mode),     0x0040, /* bit 25 */
1537             "Tunnel Mode Preferred",HFILL }
1538         },
1539         { &hf_isns_psb_transport_mode,
1540           { "Transport Mode","isns.psb.transport",
1541             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_transport_mode),  0x0020, /* bit 26 */
1542             NULL,HFILL }
1543         },
1544         { &hf_isns_psb_pfs,
1545           { "PFS","isns.psb.pfs",
1546             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_pfs),        0x0010, /* bit 27 */
1547             NULL,HFILL }
1548         },
1549         { &hf_isns_psb_aggressive_mode,
1550           { "Aggressive Mode","isns.psb.aggressive_mode",
1551             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_aggressive_mode), 0x0008, /* bit 28 */
1552             NULL,HFILL }
1553         },
1554         { &hf_isns_psb_main_mode,
1555           { "Main Mode","isns.psb.main_mode",
1556             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_main_mode),  0x0004, /* bit 29 */
1557             NULL,HFILL }
1558         },
1559         { &hf_isns_psb_ike_ipsec,
1560           { "IKE/IPSec","isns.psb.ike_ipsec",
1561             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_ike_ipsec),  0x0002, /* bit 30 */
1562             NULL,HFILL }
1563         },
1564         { &hf_isns_psb_bitmap,
1565           { "Bitmap","isns.psb.bitmap",
1566             FT_BOOLEAN, 32, TFS(&tfs_isns_psb_bitmap),     0x0001, /* bit 31 */
1567             NULL,HFILL }
1568         },
1569
1570
1571
1572         { &hf_isns_scn_bitmap,
1573           { "iSCSI SCN Bitmap","isns.scn_bitmap",
1574             FT_UINT32, BASE_HEX, NULL, 0,
1575             NULL, HFILL }
1576         },
1577         { &hf_isns_scn_bitmap_initiator_and_self_information_only,
1578           { "Initiator And Self Information Only","isns.scn_bitmap.initiator_and_self_information_only",
1579             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_initiator_and_self_information_only),     0x0080, /* bit 24 */
1580             NULL,HFILL }
1581         },
1582         { &hf_isns_scn_bitmap_target_and_self_information_only,
1583           { "Target And Self Information Only","isns.scn_bitmap.target_and_self_information_only",
1584             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_target_and_self_information_only),     0x0040, /* bit 25 */
1585             NULL,HFILL }
1586         },
1587         { &hf_isns_scn_bitmap_management_registration_scn,
1588           { "Management Registration/SCN","isns.scn_bitmap.management_registration_scn",
1589             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_management_registration_scn),     0x0020, /* bit 26 */
1590             NULL,HFILL }
1591         },
1592         { &hf_isns_scn_bitmap_object_removed,
1593           { "Object Removed","isns.scn_bitmap.object_removed",
1594             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_object_removed),     0x0010, /* bit 27 */
1595             NULL,HFILL }
1596         },
1597         { &hf_isns_scn_bitmap_object_added,
1598           { "Object Added","isns.scn_bitmap.object_added",
1599             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_object_added),     0x0008, /* bit 28 */
1600             NULL,HFILL }
1601         },
1602         { &hf_isns_scn_bitmap_object_updated,
1603           { "Object Updated","isns.scn_bitmap.object_updated",
1604             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_object_updated),     0x0004, /* bit 29 */
1605             NULL,HFILL }
1606         },
1607         { &hf_isns_scn_bitmap_dd_dds_member_removed,
1608           { "DD/DDS Member Removed (Mgmt Reg/SCN only)","isns.scn_bitmap.dd_dds_member_removed",
1609             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_dd_dds_member_removed),     0x0002, /* bit 30 */
1610             NULL,HFILL }
1611         },
1612         { &hf_isns_scn_bitmap_dd_dds_member_added,
1613           { "DD/DDS Member Added (Mgmt Reg/SCN only)","isns.scn_bitmap.dd_dds_member_added",
1614             FT_BOOLEAN, 32, TFS(&tfs_isns_scn_bitmap_dd_dds_member_added),     0x0001, /* bit 31 */
1615             NULL,HFILL }
1616         },
1617
1618
1619         { &hf_isns_isnt_control,
1620           { "Control","isns.isnt.control",
1621             FT_BOOLEAN, 32, TFS(&tfs_isns_isnt_control),  0x0004, /* bit 29 */
1622             NULL,HFILL }
1623         },
1624         { &hf_isns_isnt_initiator,
1625           { "Initiator","isns.isnt.initiator",
1626             FT_BOOLEAN, 32, TFS(&tfs_isns_isnt_initiator),  0x0002, /* bit 30 */
1627             NULL,HFILL }
1628         },
1629         { &hf_isns_isnt_target,
1630           { "Target","isns.isnt.target",
1631             FT_BOOLEAN, 32, TFS(&tfs_isns_isnt_target),     0x0001, /* bit 31 */
1632             NULL,HFILL }
1633         },
1634
1635
1636         { &hf_isns_resp_errorcode,
1637           { "ErrorCode","isns.errorcode",
1638             FT_UINT32, BASE_DEC,VALS(isns_errorcode),0,
1639             "iSNS Response Error Code" ,HFILL}
1640         },
1641
1642         { &hf_isns_attr_tag,
1643           { "Attribute Tag","isns.attr.tag",
1644             FT_UINT32, BASE_DEC,VALS(isns_attribute_tags),0,
1645             "iSNS Attribute Tag" ,HFILL}
1646         },
1647
1648         { &hf_isns_attr_len,
1649           { "Attribute Length","isns.attr.len",
1650             FT_UINT32, BASE_DEC,NULL,0,
1651             "iSNS Attribute Length" ,HFILL}
1652         },
1653
1654         { &hf_isns_delimiter,
1655           { "Delimiter","isns.delimiter",
1656             FT_NONE, BASE_NONE, NULL,0,
1657             "iSNS Delimiter" ,HFILL}
1658         },
1659
1660         { &hf_isns_not_decoded_yet,
1661           { "Not Decoded Yet","isns.not_decoded_yet",
1662             FT_NONE, BASE_NONE, NULL,0,
1663             "This tag is not yet decoded by wireshark" ,HFILL}
1664         },
1665
1666         { &hf_isns_heartbeat_ipv6_addr,
1667           { "Heartbeat Address (ipv6)","isns.heartbeat.address",
1668             FT_IPv6, BASE_NONE, NULL, 0x0,
1669             "Server IPv6 Address", HFILL }},
1670
1671         { &hf_isns_heartbeat_tcp_port,
1672           { "Heartbeat TCP Port","isns.heartbeat.tcpport",
1673             FT_UINT16, BASE_DEC, NULL, 0x0,
1674             "Server TCP Port", HFILL }},
1675
1676         { &hf_isns_heartbeat_udp_port,
1677           { "Heartbeat UDP Port","isns.heartbeat.udpport",
1678             FT_UINT16, BASE_DEC, NULL, 0x0,
1679             "Server UDP Port", HFILL }},
1680
1681
1682         { &hf_isns_heartbeat_interval,
1683           { "Heartbeat Interval (secs)","isns.heartbeat.interval",
1684             FT_UINT32, BASE_DEC, NULL, 0x0,
1685             "Server Heartbeat interval", HFILL }},
1686
1687         { &hf_isns_heartbeat_counter,
1688           { "Heartbeat counter","isns.heartbeat.counter",
1689             FT_UINT32, BASE_DEC, NULL, 0x0,
1690             "Server Heartbeat Counter", HFILL }},
1691
1692         { &hf_isns_iscsi_name,
1693           { "iSCSI Name","isns.iscsi_name",
1694             FT_STRING, BASE_NONE, NULL, 0x0,
1695             "iSCSI Name of device", HFILL }},
1696
1697         { &hf_isns_dd_member_iscsi_name,
1698           { "DD Member iSCSI Name","isns.dd_member.iscsi_name",
1699             FT_STRING, BASE_NONE, NULL, 0x0,
1700             "DD Member iSCSI Name of device", HFILL }},
1701
1702         { &hf_isns_virtual_fabric_id,
1703           { "Virtual Fabric ID","isns.virtual_fabric_id",
1704             FT_STRING, BASE_NONE, NULL, 0x0,
1705             "Virtual fabric ID", HFILL }},
1706
1707         { &hf_isns_proxy_iscsi_name,
1708           { "Proxy iSCSI Name","isns.proxy_iscsi_name",
1709             FT_STRING, BASE_NONE, NULL, 0x0,
1710             NULL, HFILL }},
1711
1712         { &hf_isns_fc4_descriptor,
1713           { "FC4 Descriptor","isns.fc4_descriptor",
1714             FT_STRING, BASE_NONE, NULL, 0x0,
1715             "FC4 Descriptor of this device", HFILL }},
1716
1717         { &hf_isns_iscsi_auth_method,
1718           { "iSCSI Auth Method","isns.iscsi_auth_method",
1719             FT_STRING, BASE_NONE, NULL, 0x0,
1720             "Authentication Method required by this device", HFILL }},
1721
1722         { &hf_isns_iscsi_alias,
1723           { "iSCSI Alias","isns.iscsi_alias",
1724             FT_STRING, BASE_NONE, NULL, 0x0,
1725             "iSCSI Alias of device", HFILL }},
1726
1727         { &hf_isns_portal_symbolic_name,
1728           { "Portal Symbolic Name","isns.portal.symbolic_name",
1729             FT_STRING, BASE_NONE, NULL, 0x0,
1730             "Symbolic name of this portal", HFILL }},
1731
1732         { &hf_isns_dd_set_symbolic_name,
1733           { "DD Set Symbolic Name","isns.dd_set.symbolic_name",
1734             FT_STRING, BASE_NONE, NULL, 0x0,
1735             "Symbolic name of this DD Set", HFILL }},
1736
1737         { &hf_isns_dd_symbolic_name,
1738           { "DD Symbolic Name","isns.dd.symbolic_name",
1739             FT_STRING, BASE_NONE, NULL, 0x0,
1740             "Symbolic name of this DD", HFILL }},
1741
1742         { &hf_isns_symbolic_port_name,
1743           { "Symbolic Port Name","isns.port.symbolic_name",
1744             FT_STRING, BASE_NONE, NULL, 0x0,
1745             "Symbolic name of this port", HFILL }},
1746
1747         { &hf_isns_symbolic_node_name,
1748           { "Symbolic Node Name","isns.node.symbolic_name",
1749             FT_STRING, BASE_NONE, NULL, 0x0,
1750             "Symbolic name of this node", HFILL }},
1751
1752         { &hf_isns_entity_identifier,
1753           { "Entity Identifier","isns.entity_identifier",
1754             FT_STRING, BASE_NONE, NULL, 0x0,
1755             "Entity Identifier of this object", HFILL }},
1756
1757         { &hf_isns_mgmt_ip_addr,
1758           { "Management IP Address","isns.mgmt.ip_address",
1759             FT_IPv6, BASE_NONE, NULL, 0x0,
1760             "Management IPv4/IPv6 Address", HFILL }},
1761
1762         { &hf_isns_node_ip_addr,
1763           { "Node IP Address","isns.node.ip_address",
1764             FT_IPv6, BASE_NONE, NULL, 0x0,
1765             "Node IPv4/IPv6 Address", HFILL }},
1766
1767         { &hf_isns_port_ip_addr,
1768           { "Port IP Address","isns.port.ip_address",
1769             FT_IPv6, BASE_NONE, NULL, 0x0,
1770             "Port IPv4/IPv6 Address", HFILL }},
1771
1772         { &hf_isns_portal_ip_addr,
1773           { "Portal IP Address","isns.portal.ip_address",
1774             FT_IPv6, BASE_NONE, NULL, 0x0,
1775             "Portal IPv4/IPv6 Address", HFILL }},
1776
1777         { &hf_isns_dd_member_portal_ip_addr,
1778           { "DD Member Portal IP Address","isns.dd.member_portal.ip_address",
1779             FT_IPv6, BASE_NONE, NULL, 0x0,
1780             "DD Member Portal IPv4/IPv6 Address", HFILL }},
1781
1782         { &hf_isns_pg_iscsi_name,
1783           { "PG iSCSI Name","isns.pg_iscsi_name",
1784             FT_STRING, BASE_NONE, NULL, 0x0,
1785             NULL, HFILL }},
1786
1787         { &hf_isns_pg_portal_ip_addr,
1788           { "PG Portal IP Address","isns.pg_portal.ip_address",
1789             FT_IPv6, BASE_NONE, NULL, 0x0,
1790             "PG Portal IPv4/IPv6 Address", HFILL }},
1791
1792         { &hf_isns_pg_index,
1793           { "PG Index","isns.pg_index",
1794             FT_UINT32, BASE_DEC, NULL, 0x0,
1795             NULL, HFILL }},
1796
1797         { &hf_isns_pg_next_index,
1798           { "PG Next Index","isns.pg_next_index",
1799             FT_UINT32, BASE_DEC, NULL, 0x0,
1800             NULL, HFILL }},
1801
1802         { &hf_isns_dd_id_next_id,
1803           { "DD ID Next ID","isns.index",
1804             FT_UINT32, BASE_DEC, NULL, 0x0,
1805             NULL, HFILL }},
1806
1807         { &hf_isns_member_iscsi_index,
1808           { "Member iSCSI Index","isns.member_iscsi_index",
1809             FT_UINT32, BASE_DEC, NULL, 0x0,
1810             NULL, HFILL }},
1811
1812         { &hf_isns_member_portal_index,
1813           { "Member Portal Index","isns.member_portal_index",
1814             FT_UINT32, BASE_DEC, NULL, 0x0,
1815             NULL, HFILL }},
1816
1817         { &hf_isns_member_fc_port_name,
1818           { "Member FC Port Name","isns.member_fc_port_name",
1819             FT_UINT32, BASE_DEC, NULL, 0x0,
1820             NULL, HFILL }},
1821
1822         { &hf_isns_vendor_oui,
1823           { "Vendor OUI","isns.index",
1824             FT_UINT32, BASE_DEC, NULL, 0x0,
1825             NULL, HFILL }},
1826
1827         { &hf_isns_preferred_id,
1828           { "Preferred ID","isns.preferred_id",
1829             FT_UINT32, BASE_DEC, NULL, 0x0,
1830             NULL, HFILL }},
1831
1832         { &hf_isns_dd_set_id,
1833           { "DD Set ID","isns.dd_set_id",
1834             FT_UINT32, BASE_DEC, NULL, 0x0,
1835             NULL, HFILL }},
1836
1837         { &hf_isns_dd_id,
1838           { "DD ID","isns.dd_id",
1839             FT_UINT32, BASE_DEC, NULL, 0x0,
1840             NULL, HFILL }},
1841
1842         { &hf_isns_port_id,
1843           { "Port ID","isns.port_id",
1844             FT_UINT24, BASE_HEX, NULL, 0x0,
1845             NULL, HFILL }},
1846
1847         { &hf_isns_hard_address,
1848           { "Hard Address","isns.hard_address",
1849             FT_UINT24, BASE_HEX, NULL, 0x0,
1850             NULL, HFILL }},
1851
1852         { &hf_isns_wwnn_token,
1853           { "WWNN Token","isns.wwnn_token",
1854             FT_UINT64, BASE_HEX, NULL, 0x0,
1855             NULL, HFILL }},
1856
1857         { &hf_isns_fc_port_name_wwpn,
1858           { "FC Port Name WWPN","isns.fc_port_name_wwpn",
1859             FT_UINT64, BASE_HEX, NULL, 0x0,
1860             NULL, HFILL }},
1861
1862         { &hf_isns_fc_node_name_wwnn,
1863           { "FC Node Name WWNN","isns.fc_node_name_wwnn",
1864             FT_UINT64, BASE_HEX, NULL, 0x0,
1865             NULL, HFILL }},
1866
1867         { &hf_isns_node_ipa,
1868           { "Node IPA","isns.node_ipa",
1869             FT_UINT64, BASE_HEX, NULL, 0x0,
1870             NULL, HFILL }},
1871
1872         { &hf_isns_fabric_port_name,
1873           { "Fabric Port Name","isns.fabric_port_name",
1874             FT_UINT64, BASE_HEX, NULL, 0x0,
1875             NULL, HFILL }},
1876
1877         { &hf_isns_permanent_port_name,
1878           { "Permanent Port Name","isns.permanent_port_name",
1879             FT_UINT64, BASE_HEX, NULL, 0x0,
1880             NULL, HFILL }},
1881
1882         { &hf_isns_switch_name,
1883           { "Switch Name","isns.switch_name",
1884             FT_UINT64, BASE_HEX, NULL, 0x0,
1885             NULL, HFILL }},
1886
1887         { &hf_isns_dd_set_next_id,
1888           { "DD Set Next ID","isns.dd_set_next_id",
1889             FT_UINT32, BASE_DEC, NULL, 0x0,
1890             NULL, HFILL }},
1891
1892         { &hf_isns_assigned_id,
1893           { "Assigned ID","isns.assigned_id",
1894             FT_UINT32, BASE_DEC, NULL, 0x0,
1895             NULL, HFILL }},
1896
1897         { &hf_isns_node_index,
1898           { "Node Index","isns.node.index",
1899             FT_UINT32, BASE_DEC, NULL, 0x0,
1900             NULL, HFILL }},
1901
1902         { &hf_isns_node_next_index,
1903           { "Node Next Index","isns.node.next_index",
1904             FT_UINT32, BASE_DEC, NULL, 0x0,
1905             "Node INext ndex", HFILL }},
1906
1907         { &hf_isns_portal_index,
1908           { "Portal Index","isns.portal.index",
1909             FT_UINT32, BASE_DEC, NULL, 0x0,
1910             NULL, HFILL }},
1911
1912         { &hf_isns_portal_next_index,
1913           { "Portal Next Index","isns.portal.next_index",
1914             FT_UINT32, BASE_DEC, NULL, 0x0,
1915             NULL, HFILL }},
1916
1917         { &hf_isns_entity_index,
1918           { "Entity Index","isns.entity.index",
1919             FT_UINT32, BASE_DEC, NULL, 0x0,
1920             NULL, HFILL }},
1921
1922         { &hf_isns_entity_next_index,
1923           { "Entity Next Index","isns.entity.next_index",
1924             FT_UINT32, BASE_DEC, NULL, 0x0,
1925             "Next Entity Index", HFILL }},
1926
1927         { &hf_isns_timestamp,
1928           { "Timestamp","isns.timestamp",
1929             FT_UINT64, BASE_DEC, NULL, 0x0,
1930             "Timestamp in Seconds", HFILL }},
1931
1932         { &hf_isns_esi_interval,
1933           { "ESI Interval","isns.esi_interval",
1934             FT_UINT32, BASE_DEC, NULL, 0x0,
1935             "ESI Interval in Seconds", HFILL }},
1936
1937         { &hf_isns_registration_period,
1938           { "Registration Period","isns.registration_period",
1939             FT_UINT32, BASE_DEC, NULL, 0x0,
1940             "Registration Period in Seconds", HFILL }},
1941
1942         { &hf_isns_portal_group_tag,
1943           { "PG Tag","isns.portal_group_tag",
1944             FT_UINT32, BASE_DEC, NULL, 0x0,
1945             "Portal Group Tag", HFILL }},
1946
1947         { &hf_isns_payload,
1948           { "Payload", "isns.payload",
1949             FT_BYTES, BASE_NONE, NULL, 0,
1950             NULL ,HFILL}
1951         }
1952     };
1953
1954 /* Setup protocol subtree array */
1955     static gint *ett[] = {
1956         &ett_isns,
1957         &ett_isns_flags,
1958         &ett_isns_payload,
1959         &ett_isns_attribute,
1960         &ett_isns_port,
1961         &ett_isns_isnt
1962     };
1963     module_t *isns_module;
1964
1965 /* Register the protocol name and description */
1966     proto_isns = proto_register_protocol("iSNS",
1967                                          "iSNS", "isns");
1968     proto_register_field_array(proto_isns, hf, array_length(hf));
1969     proto_register_subtree_array(ett, array_length(ett));
1970
1971     /* Register preferences */
1972     isns_module = prefs_register_protocol(proto_isns, NULL);
1973     prefs_register_bool_preference(isns_module, "desegment",
1974         "Reassemble iSNS messages spanning multiple TCP segments",
1975         "Whether the iSNS dissector should reassemble messages spanning multiple TCP segments."
1976         " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1977     &isns_desegment);
1978 }
1979
1980 /* If this dissector uses sub-dissector registration add a registration routine.
1981    This format is required because a script is used to find these routines and
1982    create the code that calls these routines.
1983 */
1984
1985 void
1986 proto_reg_handoff_isns(void)
1987 {
1988     isns_tcp_handle = new_create_dissector_handle(dissect_isns_tcp,proto_isns);
1989     isns_udp_handle = new_create_dissector_handle(dissect_isns_udp,proto_isns);
1990
1991     dissector_add("tcp.port",ISNS_TCP_PORT,isns_tcp_handle);
1992     dissector_add("udp.port",ISNS_UDP_PORT,isns_udp_handle);
1993 }