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