Move the GSM SMS dissection to a dedicated subdissector (currently still within
[obnox/wireshark/wip.git] / packet-isns.c
1 /* packet-isns.c
2  * Routines for iSNS dissection
3  * Copyright 2003, Elipsan, Gareth Bushell <gbushell@elipsan.com>
4  *
5  * $Id: packet-isns.c,v 1.2 2003/10/02 22:44:19 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <glib.h>
43
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
46 #endif
47
48 #include <epan/packet.h>
49
50 #define ISNS_PROTO_VER 0x1
51 #define ISNS_HEADER_SIZE 12
52
53 #define ISNS_TCP_PORT 3205
54 #define ISNS_UDP_PORT 3205
55
56 static gint ett_isns_flags = -1;
57 static gint ett_isns_payload = -1;
58 static gint ett_isns_port = -1;
59 static gint ett_isns_psb = -1;
60 static gint ett_isns_isnt = -1;
61 static gint ett_scn_bitmap = -1;
62
63 static guint AddAttribute(tvbuff_t *tvb, proto_tree *tree,guint offset );
64
65 /* Initialize the protocol and registered fields */
66 static int proto_isns = -1;
67
68
69 /* Header Stuff */
70 static int hf_isns_version = -1;
71 static int hf_isns_function_id = -1;
72 static int hf_isns_pdu_length = -1;
73 static int hf_isns_flags = -1;
74 static int hf_isns_transaction_id = -1;
75 static int hf_isns_sequence_id = -1;
76 static int hf_isns_payload = -1;
77 static int hf_isns_first_pdu = -1;
78 static int hf_isns_last_pdu = -1;
79 static int hf_isns_replace = -1;
80 static int hf_isns_server = -1;
81 static int hf_isns_client = -1;
82
83 /* Payload stuff */
84 static int hf_isns_scn_bitmap                                      = -1;
85 static int hf_isns_scn_bitmap_initiator_and_self_information_only  = -1;
86 static int hf_isns_scn_bitmap_target_and_self_information_only     = -1;
87 static int hf_isns_scn_bitmap_management_registration_scn          = -1;
88 static int hf_isns_scn_bitmap_object_removed                       = -1;
89 static int hf_isns_scn_bitmap_object_added                         = -1;
90 static int hf_isns_scn_bitmap_object_updated                       = -1;
91 static int hf_isns_scn_bitmap_dd_dds_member_removed                = -1;
92 static int hf_isns_scn_bitmap_dd_dds_member_added                  = -1;
93 static int hf_isns_isnt = -1;
94 static int hf_isns_isnt_control = -1;
95 static int hf_isns_isnt_initiator = -1;
96 static int hf_isns_isnt_target = -1;
97
98 static int hf_isns_psb = -1;
99 static int hf_isns_psb_tunnel_mode = -1;
100 static int hf_isns_psb_transport_mode = -1;
101 static int hf_isns_psb_pfs = -1;
102 static int hf_isns_psb_aggressive_mode = -1;
103 static int hf_isns_psb_main_mode = -1;
104 static int hf_isns_psb_ike_ipsec = -1;
105 static int hf_isns_psb_bitmap = -1;
106
107 static int hf_isns_port = -1;
108 static int hf_isns_port_port = -1;
109 static int hf_isns_port_type = -1;
110
111 static int hf_isns_entity_protocol = -1;
112 static int hf_isns_resp_errorcode = -1;
113 static int hf_isns_attr_tag = -1;
114 static int hf_isns_attr_len = -1;
115 static int hf_isns_attr_payload = -1;
116 static int hf_isns_heartbeat_ipv6_addr = -1;
117 static int hf_isns_heartbeat_udp_port = -1;
118 static int hf_isns_heartbeat_tcp_port = -1;
119 static int hf_isns_heartbeat_interval = -1;
120 static int hf_isns_heartbeat_counter = -1;
121
122 static int hf_isns_attr_string = -1;
123 static int hf_isns_attr_ipaddr = -1;
124 static int hf_isns_attr_index = -1;
125 static int hf_isns_attr_seconds = -1;
126
127 /* Function Id's */
128 #define ISNS_FUNC_DEVATTRREG     0x0001
129 #define ISNS_FUNC_DEVATTRQRY     0x0002
130 #define ISNS_FUNC_DEVGETNEXT     0x0003
131 #define ISNS_FUNC_DEREGDEV       0x0004
132 #define ISNS_FUNC_SCNREG         0x0005
133 #define ISNS_FUNC_SCNDEREG       0x0006
134 #define ISNS_FUNC_SCNEVENT       0x0007
135 #define ISNS_FUNC_SCN            0x0008
136 #define ISNS_FUNC_DDREG          0x0009
137 #define ISNS_FUNC_DDDEREG        0x000a
138 #define ISNS_FUNC_DDSREG         0x000b
139 #define ISNS_FUNC_DDSDEREG       0x000c
140 #define ISNS_FUNC_ESI            0x000d
141 #define ISNS_FUNC_HEARTBEAT      0x000e
142
143 #define ISNS_FUNC_RSP_DEVATTRREG 0x8001
144 #define ISNS_FUNC_RSP_DEVATTRQRY 0x8002
145 #define ISNS_FUNC_RSP_DEVGETNEXT 0x8003
146 #define ISNS_FUNC_RSP_DEREGDEV   0x8004
147 #define ISNS_FUNC_RSP_SCNREG     0x8005
148 #define ISNS_FUNC_RSP_SCNDEREG   0x8006
149 #define ISNS_FUNC_RSP_SCNEVENT   0x8007
150 #define ISNS_FUNC_RSP_SCN        0x8008
151 #define ISNS_FUNC_RSP_DDREG      0x8009
152 #define ISNS_FUNC_RSP_DDDEREG    0x800a
153 #define ISNS_FUNC_RSP_DDSREG     0x800b
154 #define ISNS_FUNC_RSP_DDSDEREG   0x800c
155 #define ISNS_FUNC_RSP_ESI        0x800d
156
157 static const value_string isns_function_ids[] = {
158 /* Requests*/
159     {ISNS_FUNC_DEVATTRREG,     "DevAttrReg"},
160     {ISNS_FUNC_DEVATTRQRY,     "DevAttrQry"},
161     {ISNS_FUNC_DEVGETNEXT,     "DevGetNext"},
162     {ISNS_FUNC_DEREGDEV,       "DeregDev"},
163     {ISNS_FUNC_SCNREG,         "SCNReg"},
164     {ISNS_FUNC_SCNDEREG,       "SCNDereg"},
165     {ISNS_FUNC_SCNEVENT,       "SCNEvent"},
166     {ISNS_FUNC_SCN,            "SCN"},
167     {ISNS_FUNC_DDREG,          "DDReg"},
168     {ISNS_FUNC_DDDEREG,        "DDDereg"},
169     {ISNS_FUNC_DDSREG,         "DDSReg"},
170     {ISNS_FUNC_DDSDEREG,       "DDSDereg"},
171     {ISNS_FUNC_ESI,            "ESI"},
172     {ISNS_FUNC_HEARTBEAT,      "Heartbeat"},
173
174 /* Responses */
175     {ISNS_FUNC_RSP_DEVATTRREG, "DevAttrRegRsp"},
176     {ISNS_FUNC_RSP_DEVATTRQRY, "DevAttrQryRsp"},
177     {ISNS_FUNC_RSP_DEVGETNEXT, "DevGetNextRsp"},
178     {ISNS_FUNC_RSP_DEREGDEV,   "DeregDevRsp"},
179     {ISNS_FUNC_RSP_SCNREG,     "SCNRegRsp"},
180     {ISNS_FUNC_RSP_SCNDEREG,   "SCNDeregRsp"},
181     {ISNS_FUNC_RSP_SCNEVENT,   "SCNEventRsp"},
182     {ISNS_FUNC_RSP_SCN,        "SCNRsp"},
183     {ISNS_FUNC_RSP_DDREG,      "DDRegRsp"},
184     {ISNS_FUNC_RSP_DDDEREG,    "DDDeregRsp"},
185     {ISNS_FUNC_RSP_DDSREG,     "DDSRegRsp"},
186     {ISNS_FUNC_RSP_DDSDEREG,   "DDSDeregRsp"},
187     {ISNS_FUNC_RSP_ESI,        "ESIRsp"},
188
189     {0x0,NULL},
190 };
191
192 #define ISNS_ENTITY_PROTOCOL_NO_PROTOCOL 1
193 #define ISNS_ENTITY_PROTOCOL_ISCSI       2
194 #define ISNS_ENTITY_PROTOCOL_IFCP        3
195
196
197 static const value_string isns_entity_protocol[] = {
198     {ISNS_ENTITY_PROTOCOL_NO_PROTOCOL, "No Protocol"},
199     {ISNS_ENTITY_PROTOCOL_ISCSI,       "iSCSI"},
200     {ISNS_ENTITY_PROTOCOL_IFCP,        "iFCP"}, 
201
202     {0x0,NULL},
203 };
204
205 static const value_string isns_errorcode[] = {
206     { 0,"No Error"},
207     { 1,"Unknown Error"},
208     { 2,"Message Format Error"},
209     { 3,"Invalid Registration"},
210     { 4,"Requested ESI Period Too short"},
211     { 5,"Invalid Query"},
212     { 6,"Authentication Unknown"},
213     { 7,"Authentication Absent"},
214     { 8,"Authentication Failed"},
215     { 9,"No such Entry"},
216     {10,"Version Not Supported"},
217     {11,"Internal Bus Error"},
218     {12,"Busy Now"},
219     {13,"Option Not Understood"},
220     {14,"Invalid Update"},
221     {15,"Message Not supported"},
222     {16,"SCN Event Rejected"},
223     {17,"SCN Registration Rejected"},
224     {18,"Attribute Not Implemented"},
225     {19,"SWITCH_ID Not available"},
226     {20,"SWITCH_ID not allocated"},
227     {21,"ESI Not Available"},
228
229     {0x0,NULL}
230 };
231
232
233 #define ISNS_ATTR_TAG_DELIMITER                     0
234 #define ISNS_ATTR_TAG_ENTITY_IDENTIFIER             1
235 #define ISNS_ATTR_TAG_ENTITY_PROTOCOL               2
236 #define ISNS_ATTR_TAG_MGMT_IP_ADDRESS               3
237 #define ISNS_ATTR_TAG_TIMESTAMP                     4
238 #define ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE        5
239 #define ISNS_ATTR_TAG_REGISTRATION_PERIOD           6
240 #define ISNS_ATTR_TAG_ENTITY_INDEX                  7
241 #define ISNS_ATTR_TAG_ENTITY_NEXT_INDEX             8
242 #define ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1         11
243 #define ISNS_ATTR_TAG_ENTITY_CERTIFICATE            12
244 #define ISNS_ATTR_TAG_PORTAL_IP_ADDRESS             16
245 #define ISNS_ATTR_TAG_PORTAL_PORT                   17
246 #define ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME          18
247 #define ISNS_ATTR_TAG_ESI_INTERVAL                  19
248 #define ISNS_ATTR_TAG_ESI_PORT                      20
249 #define ISNS_ATTR_TAG_PORTAL_GROUP                  21
250 #define ISNS_ATTR_TAG_PORTAL_INDEX                  22
251 #define ISNS_ATTR_TAG_SCN_PORT                      23
252 #define ISNS_ATTR_TAG_PORTAL_NEXT_INDEX             24
253 #define ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP        27
254 #define ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1         28
255 #define ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2         29
256 #define ISNS_ATTR_TAG_PORTAL_CERTIFICATE            31
257 #define ISNS_ATTR_TAG_ISCSI_NAME                    32
258 #define ISNS_ATTR_TAG_ISCSI_NODE_TYPE               33
259 #define ISNS_ATTR_TAG_ISCSI_ALIAS                   34
260 #define ISNS_ATTR_TAG_ISCSI_SCN_BITMAP              35
261 #define ISNS_ATTR_TAG_ISCSI_NODE_INDEX              36
262 #define ISNS_ATTR_TAG_WWNN_TOKEN                    37
263 #define ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX         38
264 #define ISNS_ATTR_TAG_ISCSI_AUTH_METHOD             42
265 #define ISNS_ATTR_TAG_ISCSI_NODE_CERTIFICATE        43
266 #define ISNS_ATTR_TAG_FC_PORT_NAME_WWPN             64
267 #define ISNS_ATTR_TAG_PORT_ID                       65
268 #define ISNS_ATTR_TAG_FC_PORT_TYPE                  66
269 #define ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME            67
270 #define ISNS_ATTR_TAG_FABRIC_PORT_NAME              68
271 #define ISNS_ATTR_TAG_HARD_ADDRESS                  69
272 #define ISNS_ATTR_TAG_PORT_IP_ADDRESS               70
273 #define ISNS_ATTR_TAG_CLASS_OF_SERVICE              71
274 #define ISNS_ATTR_TAG_FC4_TYPES                     72
275 #define ISNS_ATTR_TAG_FC4_DESCRIPTOR                73
276 #define ISNS_ATTR_TAG_FC4_FEATURES                  74
277 #define ISNS_ATTR_TAG_IFCP_SCN_BITMAP               75
278 #define ISNS_ATTR_TAG_PORT_ROLE                     76
279 #define ISNS_ATTR_TAG_PERMANENT_PORT_NAME           77
280 #define ISNS_ATTR_TAG_PORT_CERTIFICATE              83
281 #define ISNS_ATTR_TAG_FC4_TYPE_CODE                 95
282 #define ISNS_ATTR_TAG_FC_NODE_NAME_WWNN             96
283 #define ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME            97
284 #define ISNS_ATTR_TAG_NODE_IP_ADDRESS               98
285 #define ISNS_ATTR_TAG_NODE_IPA                      99
286 #define ISNS_ATTR_TAG_NODE_CERTIFICATE              100
287 #define ISNS_ATTR_TAG_PROXY_ISCSI_NAME              101
288 #define ISNS_ATTR_TAG_SWITCH_NAME                   128
289 #define ISNS_ATTR_TAG_PREFERRED_ID                  129
290 #define ISNS_ATTR_TAG_ASSIGNED_ID                   130
291 #define ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID             131
292 #define ISNS_ATTR_TAG_VENDOR_OUI                    256
293 #define ISNS_ATTR_TAG_DD_SET_ID                     2049
294 #define ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME          2050
295 #define ISNS_ATTR_TAG_DD_SET_STATUS                 2051
296 #define ISNS_ATTR_TAG_DD_SET_NEXT_ID                2052
297 #define ISNS_ATTR_TAG_DD_ID                         2065
298 #define ISNS_ATTR_TAG_DD_SYMBOLIC_NAME              2066
299 #define ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX         2067
300 #define ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME          2068
301 #define ISNS_ATTR_TAG_DD_MEMBER_IFCP_NODE           2069
302 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX        2070
303 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS   2071
304 #define ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT         2072
305 #define ISNS_ATTR_TAG_DD_FEATURES                   2078
306 #define ISNS_ATTR_TAG_DD_ID_NEXT_ID                 2079
307
308
309 static const value_string isns_attribute_tags[] = {
310     {ISNS_ATTR_TAG_DELIMITER,                   "Delimiter"},
311     {ISNS_ATTR_TAG_ENTITY_IDENTIFIER,           "Entity Identifier (EID)"},
312     {ISNS_ATTR_TAG_ENTITY_PROTOCOL,             "Entity Protocol"},
313     {ISNS_ATTR_TAG_MGMT_IP_ADDRESS,             "Management IP Address"},
314     {ISNS_ATTR_TAG_TIMESTAMP,                   "Timestamp"},
315     {ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE,      "Protocol Version Range"},
316     {ISNS_ATTR_TAG_REGISTRATION_PERIOD,         "Registration Period"},
317     {ISNS_ATTR_TAG_ENTITY_INDEX,                "Entity Index"},
318     {ISNS_ATTR_TAG_ENTITY_NEXT_INDEX,           "Entity Next Index"},
319     {ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1,       "Entity ISAKMP Phase-1"},
320     {ISNS_ATTR_TAG_ENTITY_CERTIFICATE,          "Entity Certificate"},
321     {ISNS_ATTR_TAG_PORTAL_IP_ADDRESS,           "Portal IP Address"},
322     {ISNS_ATTR_TAG_PORTAL_PORT,                 "Portal TCP/UDP Port"},
323     {ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME,        "Portal Symbolic Name"},
324     {ISNS_ATTR_TAG_ESI_INTERVAL,                "ESI Interval"},
325     {ISNS_ATTR_TAG_ESI_PORT,                    "ESI Port"},
326     {ISNS_ATTR_TAG_PORTAL_GROUP,                "Portal Group Tag"},
327     {ISNS_ATTR_TAG_PORTAL_INDEX,                "Portal Index"},
328     {ISNS_ATTR_TAG_SCN_PORT,                    "SCN Port"},
329     {ISNS_ATTR_TAG_PORTAL_NEXT_INDEX,           "Portal Next Index"},
330     {ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP,      "Portal Security Bitmap"},
331     {ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1,       "Portal ISAKMP Phase-1"},
332     {ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2,       "Portal ISAKMP Phase-2"},
333     {ISNS_ATTR_TAG_PORTAL_CERTIFICATE,          "Portal Certificate"},
334     {ISNS_ATTR_TAG_ISCSI_NAME,                  "iSCSI Name"},
335     {ISNS_ATTR_TAG_ISCSI_NODE_TYPE,             "iSCSI Node Type"},
336     {ISNS_ATTR_TAG_ISCSI_ALIAS,                 "iSCSI Alias"},
337     {ISNS_ATTR_TAG_ISCSI_SCN_BITMAP,            "iSCSI SCN Bitmap"},
338     {ISNS_ATTR_TAG_ISCSI_NODE_INDEX,            "iSCSI Node Index"},
339     {ISNS_ATTR_TAG_WWNN_TOKEN,                  "WWNN Token"},
340     {ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX,       "iSCSI Node Next Index"},
341     {ISNS_ATTR_TAG_ISCSI_AUTH_METHOD,           "iSCSI AuthMethod"},
342     {ISNS_ATTR_TAG_ISCSI_NODE_CERTIFICATE,      "iSCSI Node Certificate"},
343     {ISNS_ATTR_TAG_FC_PORT_NAME_WWPN,           "FC Port Name WWPN"},
344     {ISNS_ATTR_TAG_PORT_ID,                     "Port ID"},
345     {ISNS_ATTR_TAG_FC_PORT_TYPE,                "FC Port Type"},
346     {ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME,          "Symbolic Port Name"},
347     {ISNS_ATTR_TAG_FABRIC_PORT_NAME,            "Fabric Port Name"},
348     {ISNS_ATTR_TAG_HARD_ADDRESS,                "Hard Address"},
349     {ISNS_ATTR_TAG_PORT_IP_ADDRESS,             "Port IP-Address"},
350     {ISNS_ATTR_TAG_CLASS_OF_SERVICE,            "Class of Service"},
351     {ISNS_ATTR_TAG_FC4_TYPES,                   "FC-4 Types"},
352     {ISNS_ATTR_TAG_FC4_DESCRIPTOR,              "FC-4 Descriptor"},
353     {ISNS_ATTR_TAG_FC4_FEATURES,                "FC-4 Features"},
354     {ISNS_ATTR_TAG_IFCP_SCN_BITMAP,             "iFCP SCN bitmap"},
355     {ISNS_ATTR_TAG_PORT_ROLE,                   "Port Role"},
356     {ISNS_ATTR_TAG_PERMANENT_PORT_NAME,         "Permanent Port Name"},
357     {ISNS_ATTR_TAG_PORT_CERTIFICATE,            "Port Certificate"},
358     {ISNS_ATTR_TAG_FC4_TYPE_CODE,               "FC-4 Type Code"},
359     {ISNS_ATTR_TAG_FC_NODE_NAME_WWNN,           "FC Node Name WWNN"},
360     {ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME,          "Symbolic Node Name"},
361     {ISNS_ATTR_TAG_NODE_IP_ADDRESS,             "Node IP-Address"},
362     {ISNS_ATTR_TAG_NODE_IPA,                    "Node IPA"},
363     {ISNS_ATTR_TAG_NODE_CERTIFICATE,            "Node Certificate"},
364     {ISNS_ATTR_TAG_PROXY_ISCSI_NAME,            "Proxy iSCSI Name"},
365     {ISNS_ATTR_TAG_SWITCH_NAME,                 "Switch Name"},
366     {ISNS_ATTR_TAG_PREFERRED_ID,                "Preferred ID"},
367     {ISNS_ATTR_TAG_ASSIGNED_ID,                 "Assigned ID"},
368     {ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID,           "Virtual_Fabric_ID"},
369     {ISNS_ATTR_TAG_VENDOR_OUI,                  "iSNS Server Vendor OUI"},
370     {ISNS_ATTR_TAG_DD_SET_ID,                   "DD_Set ID"},
371     {ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME,        "DD_Set Sym Name"},
372     {ISNS_ATTR_TAG_DD_SET_STATUS,               "DD_Set Status"},
373     {ISNS_ATTR_TAG_DD_SET_NEXT_ID,              "DD_Set_Next_ID"},
374     {ISNS_ATTR_TAG_DD_ID,                       "DD_ID"},
375     {ISNS_ATTR_TAG_DD_SYMBOLIC_NAME,            "DD_Symbolic Name"},
376     {ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX,       "DD_Member iSCSI Index"},
377     {ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME,        "DD_Member iSCSI Name"},
378     {ISNS_ATTR_TAG_DD_MEMBER_IFCP_NODE,         "DD_Member iFCP Node"},
379     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX,      "DD Member Portal Index"},
380     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS, "DD_Member Portal IP Addr"},
381     {ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT,       "DD Member Portal TCP/UDP"},
382     {ISNS_ATTR_TAG_DD_FEATURES,                 "DD_Features"},
383     {ISNS_ATTR_TAG_DD_ID_NEXT_ID,               "DD_ID Next ID"},
384
385     {0,NULL}
386 };
387
388
389
390
391 static const true_false_string isns_scn_bitmap_initiator_and_self_information_only = {
392     "True",
393     "False"
394 };
395 static const true_false_string isns_scn_bitmap_target_and_self_information_only    = {
396     "True",
397     "False"
398 };
399 static const true_false_string isns_scn_bitmap_management_registration_scn         = {
400     "True",
401     "False"
402 };
403 static const true_false_string isns_scn_bitmap_object_removed                      = {
404     "True",
405     "False"
406 };
407 static const true_false_string isns_scn_bitmap_object_added                        = {
408     "True",
409     "False"
410 };
411 static const true_false_string isns_scn_bitmap_object_updated                      = {
412     "True",
413     "False"
414 };
415 static const true_false_string isns_scn_bitmap_dd_dds_member_removed               = {
416     "True",
417     "False"
418 };
419 static const true_false_string isns_scn_bitmap_dd_dds_member_added                 = {
420     "True",
421     "False"
422 };
423
424 static const true_false_string isns_psb_tunnel_mode = {
425     "Preferred",
426     "No Preference"
427 };
428 static const true_false_string isns_psb_transport_mode = {
429     "Preferred",
430     "No Preference"
431 };
432 static const true_false_string isns_psb_pfs = {
433     "Enabled",
434     "Disabled"
435 };
436 static const true_false_string isns_psb_aggressive_mode = {
437     "Enabled",
438     "Disabled"
439 };
440 static const true_false_string isns_psb_main_mode = {
441     "Enabled",
442     "Disabled"
443 };
444 static const true_false_string isns_psb_ike_ipsec = {
445     "Enabled",
446     "Disabled"
447 };
448 static const true_false_string isns_psb_bitmap = {
449     "VALID",
450     "INVALID"
451 };
452
453 static const true_false_string isns_isnt_control = {
454     "Yes",
455     "No"
456 };
457 static const true_false_string isns_isnt_initiator = {
458     "Yes",
459     "No"
460 };
461 static const true_false_string isns_isnt_target = {
462     "Yes",
463     "No"
464 };
465
466 static const true_false_string isns_port_type = {
467     "UDP",
468     "TCP"
469 };
470
471 static const true_false_string isns_flag_first_pdu = {
472     "First PDU of iSNS Message",
473     "Not the first PDU of iSNS Message"
474 };
475
476 static const true_false_string isns_flag_last_pdu = {
477     "Last PDU of iSNS Message",
478     "Not the Last PDU of iSNS Message"
479 };
480
481 static const true_false_string isns_flag_replace = {
482     "Replace",
483     "Don't replace"
484 };
485
486 static const true_false_string isns_flag_server = {
487     "Sender is iSNS server",
488     "Sender is not iSNS server"
489 };
490
491 static const true_false_string isns_flag_client = {
492     "Sender is iSNS client",
493     "Sender is not iSNS client"
494 };
495
496
497 /* Initialize the subtree pointers */
498 static gint ett_isns = -1;
499
500
501 /* Code to actually dissect the packets */
502 static int
503 dissect_isns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
504 {
505     guint offset = 0;
506     guint16 function_id;
507     guint16 isns_protocol_version;
508     guint32 packet_len = tvb_length_remaining(tvb, offset);
509     char * function_id_str;
510     /* Set up structures needed to add the protocol subtree and manage it */
511     proto_item *ti = NULL;
512     proto_tree *isns_tree = NULL;
513     
514     if( packet_len < 12 )
515         return 0;
516
517     /* Make entries in Protocol column and Info column on summary display */
518     if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
519         col_set_str(pinfo->cinfo, COL_PROTOCOL, "isns");
520     if (check_col(pinfo->cinfo, COL_INFO)) 
521         col_clear(pinfo->cinfo, COL_INFO);
522
523     /* Get the function id from the packet */
524     function_id =  tvb_get_ntohs(tvb, offset + 2);
525     function_id_str = match_strval(function_id, isns_function_ids);
526     
527     /* Get the protocol version - only version one at the moment*/ 
528     isns_protocol_version = tvb_get_ntohs(tvb, offset + 0);
529     if( (function_id_str == NULL) || (isns_protocol_version != ISNS_PROTO_VER) )
530         return 0;
531     
532     /* Add the function name in the info col */
533     if (check_col(pinfo->cinfo, COL_INFO)) 
534         col_add_str(pinfo->cinfo, COL_INFO, function_id_str);
535     
536     /* In the interest of speed, if "tree" is NULL, don't do any work not
537      * necessary to generate protocol tree items. 
538      */
539     if (tree) {
540         guint16 b;      
541         proto_tree *tt;
542         proto_item *tflags;
543         proto_item *tpayload;
544
545         /* NOTE: The offset and length values in the call to
546          * "proto_tree_add_item()" define what data bytes to highlight in the hex
547          * display window when the line in the protocol tree display
548          * corresponding to that item is selected.
549          *  tvb_length(tvb) is a handy way to highlight all data from the offset to
550          *  the end of the packet. 
551          */
552
553         /* create display subtree for the protocol */
554         ti = proto_tree_add_item(tree, proto_isns, tvb, 0, -1, FALSE);
555         isns_tree = proto_item_add_subtree(ti, ett_isns);
556
557         /* OK... Sort out the header */
558         b = tvb_get_ntohs(tvb, offset);
559         proto_tree_add_uint(isns_tree, hf_isns_version, tvb, offset, 2, b);
560
561         b = tvb_get_ntohs(tvb, offset + 2);
562         proto_tree_add_uint(isns_tree, hf_isns_function_id, tvb, offset+2, 2, b);
563
564         b = tvb_get_ntohs(tvb, offset + 4);
565         proto_tree_add_uint(isns_tree, hf_isns_pdu_length, tvb, offset+4, 2, b);
566
567         /*FLAGS*/
568         b = tvb_get_ntohs(tvb, offset + 6);
569         tflags = proto_tree_add_uint(isns_tree, hf_isns_flags, tvb, offset+6, 2, b);
570         tt = proto_item_add_subtree(tflags, ett_isns_flags);
571
572         proto_tree_add_boolean(tt, hf_isns_first_pdu, tvb, offset+6, 2, b); 
573         proto_tree_add_boolean(tt, hf_isns_last_pdu, tvb, offset+6, 2, b); 
574         proto_tree_add_boolean(tt, hf_isns_replace, tvb, offset+6, 2, b); 
575         proto_tree_add_boolean(tt, hf_isns_server, tvb, offset+6, 2, b); 
576         proto_tree_add_boolean(tt, hf_isns_client, tvb, offset+6, 2, b); 
577
578         b = tvb_get_ntohs(tvb, offset + 8);
579         proto_tree_add_uint(isns_tree, hf_isns_transaction_id, tvb, offset+8, 2, b);
580
581         b = tvb_get_ntohs(tvb, offset + 10);
582         proto_tree_add_uint(isns_tree, hf_isns_sequence_id, tvb, offset+10, 2, b);
583
584         tpayload = proto_tree_add_item(isns_tree, hf_isns_payload, tvb, offset+12, packet_len - 12 , FALSE);
585         tt = proto_item_add_subtree(tpayload, ett_isns_payload);
586
587         /* Now set the offset to the start of the payload */
588         offset += ISNS_HEADER_SIZE;
589
590         /* Decode those attributes baby - Yeah!*/
591         switch (function_id)
592         {
593         case ISNS_FUNC_HEARTBEAT:
594         {
595             guint8 hb_ipv6[16];
596             guint16 port;
597             guint32 c;
598             tvb_memcpy(tvb,hb_ipv6,offset,16);
599             proto_tree_add_ipv6(tt,hf_isns_heartbeat_ipv6_addr, tvb, offset, 16, hb_ipv6);
600             offset += 16;
601
602             port = tvb_get_ntohs(tvb, offset);
603             proto_tree_add_uint(tt,hf_isns_heartbeat_tcp_port, tvb, offset, 2, port);
604             offset += 2;
605
606             port = tvb_get_ntohs(tvb, offset);
607             proto_tree_add_uint(tt,hf_isns_heartbeat_udp_port, tvb, offset, 2, port);
608             offset += 2;
609
610             c = tvb_get_ntohl(tvb, offset);
611             proto_tree_add_uint(tt,hf_isns_heartbeat_interval, tvb, offset, 4, c);
612             offset += 4;
613
614             c = tvb_get_ntohl(tvb, offset);
615             proto_tree_add_uint(tt,hf_isns_heartbeat_counter, tvb, offset, 4, c);
616             offset += 4;
617             break;
618         }
619         /* Responses */
620         case ISNS_FUNC_RSP_DEVATTRREG:
621         case ISNS_FUNC_RSP_DEVATTRQRY:
622         case ISNS_FUNC_RSP_DEVGETNEXT:
623         case ISNS_FUNC_RSP_DEREGDEV:
624         case ISNS_FUNC_RSP_SCNREG:
625         case ISNS_FUNC_RSP_SCNDEREG:
626         case ISNS_FUNC_RSP_SCNEVENT:
627         case ISNS_FUNC_RSP_SCN:
628         case ISNS_FUNC_RSP_DDREG:
629         case ISNS_FUNC_RSP_DDDEREG:
630         case ISNS_FUNC_RSP_DDSREG:
631         case ISNS_FUNC_RSP_DDSDEREG:
632         case ISNS_FUNC_RSP_ESI:
633         {
634             /* Get the Error message of the response */
635             guint32 errorcode =  tvb_get_ntohl(tvb, offset);
636             proto_tree_add_uint(tt,hf_isns_resp_errorcode, tvb, offset, 4, errorcode);
637             offset += 4;
638             /* Messages */
639         }
640         case ISNS_FUNC_DEVATTRREG:
641         case ISNS_FUNC_DEVATTRQRY:
642         case ISNS_FUNC_DEVGETNEXT: 
643         case ISNS_FUNC_DEREGDEV:
644         case ISNS_FUNC_SCNREG:
645         case ISNS_FUNC_SCNDEREG:
646         case ISNS_FUNC_SCNEVENT:
647         case ISNS_FUNC_SCN:
648         case ISNS_FUNC_DDREG:
649         case ISNS_FUNC_DDDEREG:
650         case ISNS_FUNC_DDSREG:
651         case ISNS_FUNC_DDSDEREG:
652         case ISNS_FUNC_ESI:
653         default:
654             while( offset < packet_len )
655             {
656                 offset += AddAttribute(tvb,tt,offset);
657             }
658         }
659     }
660
661     return tvb_length(tvb);
662 }
663
664 static guint
665 AddAttribute(tvbuff_t *tvb, proto_tree *tree,guint offset )
666 {
667     proto_tree *tt;
668     proto_item *attribute;
669     guint32 tag,len;
670
671     /* Get the Tag */
672     tag = tvb_get_ntohl(tvb, offset);
673
674     /* Now the Length */
675     len = tvb_get_ntohl(tvb, offset + 4);
676     
677     attribute = proto_tree_add_item(tree, hf_isns_attr_payload, tvb, offset , len + 8 , FALSE);
678     tt = proto_item_add_subtree(attribute, ett_isns_payload);
679     proto_tree_add_uint(tt,hf_isns_attr_tag, tvb, offset, 4, tag);
680     proto_tree_add_uint(tt,hf_isns_attr_len, tvb, offset + 4, 4, len);
681 #if 0    
682     fprintf(stderr,"packet_len=%i\noffset=%i\n(len <= (packet_len - (offset + 8))))=%i\n",
683             packet_len,
684             offset,
685             (len <= (packet_len - (offset + 8))));
686
687     if( (len > 0) && (len <= (packet_len - (offset + 8))))
688     {
689         fprintf(stderr,"Payload");
690         
691     }
692 #endif
693
694     if( len == 0 ) return 8;
695
696     switch( tag )
697     {
698     case ISNS_ATTR_TAG_DELIMITER:                    goto none;
699     case ISNS_ATTR_TAG_ENTITY_IDENTIFIER:            goto string;
700     case ISNS_ATTR_TAG_ENTITY_PROTOCOL:              goto entity_protocol;
701     case ISNS_ATTR_TAG_MGMT_IP_ADDRESS:              goto ip;
702     case ISNS_ATTR_TAG_TIMESTAMP:                    goto seconds;
703     case ISNS_ATTR_TAG_PROTOCOL_VERSION_RANGE:       goto version_range;
704     case ISNS_ATTR_TAG_REGISTRATION_PERIOD:          goto seconds;
705     case ISNS_ATTR_TAG_ENTITY_INDEX:                 goto identifier32;
706     case ISNS_ATTR_TAG_ENTITY_NEXT_INDEX:            goto identifier32;
707     case ISNS_ATTR_TAG_ENTITY_ISAKMP_PHASE_1:        goto will_not_decode;
708     case ISNS_ATTR_TAG_ENTITY_CERTIFICATE:           goto will_not_decode;
709     case ISNS_ATTR_TAG_PORTAL_IP_ADDRESS:            goto ip;
710     case ISNS_ATTR_TAG_PORTAL_PORT:                  goto port;
711     case ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME:         goto string;
712     case ISNS_ATTR_TAG_ESI_INTERVAL:                 goto seconds;
713     case ISNS_ATTR_TAG_ESI_PORT:                     goto port;
714     case ISNS_ATTR_TAG_PORTAL_GROUP:                 goto portal_group;
715     case ISNS_ATTR_TAG_PORTAL_INDEX:                 goto identifier32;
716     case ISNS_ATTR_TAG_SCN_PORT:                     goto port;
717     case ISNS_ATTR_TAG_PORTAL_NEXT_INDEX:            goto identifier32;
718     case ISNS_ATTR_TAG_PORTAL_SECURITY_BITMAP:       goto portal_security_bitmap;
719     case ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_1:        goto will_not_decode;
720     case ISNS_ATTR_TAG_PORTAL_ISAKMP_PHASE_2:        goto will_not_decode;
721     case ISNS_ATTR_TAG_PORTAL_CERTIFICATE:           goto will_not_decode;
722     case ISNS_ATTR_TAG_ISCSI_NAME:                   goto string;
723     case ISNS_ATTR_TAG_ISCSI_NODE_TYPE:              goto iscsi_node_type;
724     case ISNS_ATTR_TAG_ISCSI_ALIAS:                  goto string;
725     case ISNS_ATTR_TAG_ISCSI_SCN_BITMAP:             goto iscsi_scn_bitmap;
726     case ISNS_ATTR_TAG_ISCSI_NODE_INDEX:             goto identifier32;
727     case ISNS_ATTR_TAG_WWNN_TOKEN:                   goto identifier64;
728     case ISNS_ATTR_TAG_ISCSI_NODE_NEXT_INDEX:        goto identifier32;
729     case ISNS_ATTR_TAG_ISCSI_AUTH_METHOD:            goto string;
730     case ISNS_ATTR_TAG_ISCSI_NODE_CERTIFICATE:       goto will_not_decode;
731     case ISNS_ATTR_TAG_FC_PORT_NAME_WWPN:            goto identifier64;
732     case ISNS_ATTR_TAG_PORT_ID:                      goto identifier24;
733     case ISNS_ATTR_TAG_FC_PORT_TYPE:                 goto will_not_decode;
734         /*
735           0x0000           Unidentified/Null Entry 
736           0x0001           Fibre Channel N_Port 
737           0x0002           Fibre Channel NL_Port 
738           0x0003           Fibre Channel F/NL_Port 
739           0x0081           Fibre Channel F_Port 
740           0x0082           Fibre Channel FL_Port 
741           0x0084           Fibre Channel E_Port 
742           0xFF12           iFCP Port 
743         */
744     case ISNS_ATTR_TAG_SYMBOLIC_PORT_NAME:           goto string;
745     case ISNS_ATTR_TAG_FABRIC_PORT_NAME:             goto identifier64;
746     case ISNS_ATTR_TAG_HARD_ADDRESS:                 goto identifier24;
747     case ISNS_ATTR_TAG_PORT_IP_ADDRESS:              goto ip;
748     case ISNS_ATTR_TAG_CLASS_OF_SERVICE:             goto will_not_decode;
749         /*
750           bit 29             Fibre Channel Class 2 Supported
751           bit 28             Fibre Channel Class 3 Supported
752         */
753     case ISNS_ATTR_TAG_FC4_TYPES:                    goto will_not_decode;
754     case ISNS_ATTR_TAG_FC4_DESCRIPTOR:               goto string;
755     case ISNS_ATTR_TAG_FC4_FEATURES:                 goto will_not_decode;
756     case ISNS_ATTR_TAG_IFCP_SCN_BITMAP:              goto will_not_decode;
757         /*
758           bit 24              INITIATOR AND SELF INFORMATION ONLY
759           bit 25              TARGET AND SELF INFORMATION ONLY
760           bit 26              MANAGEMENT REGISTRATION/SCN
761           bit 27              OBJECT REMOVED
762           bit 28              OBJECT ADDED
763           bit 29              OBJECT UPDATED
764           bit 30              DD/DDS MEMBER REMOVED (Mgmt Reg/SCN only)
765           bit 31 (Lsb)        DD/DDS MEMBER ADDED (Mgmt Reg/SCN only)
766         */
767     case ISNS_ATTR_TAG_PORT_ROLE:                    goto will_not_decode;
768         /*
769           bit 29              Control 
770           bit 30              FCP Initiator 
771           bit 31 (Lsb)        FCP Target 
772         */
773     case ISNS_ATTR_TAG_PERMANENT_PORT_NAME:          goto identifier64;
774     case ISNS_ATTR_TAG_PORT_CERTIFICATE:             goto will_not_decode;
775     case ISNS_ATTR_TAG_FC4_TYPE_CODE:                goto will_not_decode;
776         /* 8bit type code in byte0 */
777     case ISNS_ATTR_TAG_FC_NODE_NAME_WWNN:            goto identifier64;
778     case ISNS_ATTR_TAG_SYMBOLIC_NODE_NAME:           goto string;
779     case ISNS_ATTR_TAG_NODE_IP_ADDRESS:              goto ip;
780     case ISNS_ATTR_TAG_NODE_IPA:                     goto identifier64;
781     case ISNS_ATTR_TAG_NODE_CERTIFICATE:             goto will_not_decode;
782     case ISNS_ATTR_TAG_PROXY_ISCSI_NAME:             goto string;
783     case ISNS_ATTR_TAG_SWITCH_NAME:                  goto identifier64;
784     case ISNS_ATTR_TAG_PREFERRED_ID:                 goto identifier32;
785     case ISNS_ATTR_TAG_ASSIGNED_ID:                  goto identifier32;
786     case ISNS_ATTR_TAG_VIRTUAL_FABRIC_ID:            goto string;
787     case ISNS_ATTR_TAG_VENDOR_OUI:                   goto identifier32;
788     case ISNS_ATTR_TAG_DD_SET_ID:                    goto identifier32;
789     case ISNS_ATTR_TAG_DD_SET_SYMBOLIC_NAME:         goto string;
790     case ISNS_ATTR_TAG_DD_SET_STATUS:                goto dd_set_status;
791     case ISNS_ATTR_TAG_DD_SET_NEXT_ID:               goto identifier32;
792     case ISNS_ATTR_TAG_DD_ID:                        goto identifier32;
793     case ISNS_ATTR_TAG_DD_SYMBOLIC_NAME:             goto string;
794     case ISNS_ATTR_TAG_DD_MEMBER_ISCSI_INDEX:        goto identifier32;
795     case ISNS_ATTR_TAG_DD_MEMBER_ISCSI_NAME:         goto string;
796     case ISNS_ATTR_TAG_DD_MEMBER_IFCP_NODE:          goto identifier32;
797     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_INDEX:       goto identifier32;
798     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_IP_ADDRESS:  goto ip;
799     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT:        goto port;
800     case ISNS_ATTR_TAG_DD_FEATURES:                  goto dd_features;
801     case ISNS_ATTR_TAG_DD_ID_NEXT_ID:                goto identifier32;
802     }
803
804 identifier24:
805     /* 24-bit identifier (least significant 3 bytes) */
806 identifier64:
807 none:
808     goto end;
809
810 identifier32:
811     {
812         guint32 i = tvb_get_ntohl(tvb, offset + 8);
813         proto_tree_add_uint(tt, hf_isns_attr_index, tvb, offset + 8, len, i);
814         goto end;
815     }
816     goto end;
817
818 dd_features:
819     /*
820       31 (Lsb)      Boot List Enabled (1)/Boot List Disabled (0) 
821     */
822     goto end;
823
824 dd_set_status:
825     /*
826       31 (Lsb)      DDS Enabled (1) / DDS Disabled (0) 
827     */
828     goto end;
829
830 iscsi_scn_bitmap:
831     /*
832       24              INITIATOR AND SELF INFORMATION ONLY 
833       25              TARGET AND SELF INFORMATION ONLY  
834       26              MANAGEMENT REGISTRATION/SCN 
835       27              OBJECT REMOVED 
836       28              OBJECT ADDED 
837       29              OBJECT UPDATED 
838       30              DD/DDS MEMBER REMOVED (Mgmt Reg/SCN only) 
839       31 (Lsb)        DD/DDS MEMBER ADDED (Mgmt Reg/SCN only) 
840     */
841     {
842         /*FLAGS*/
843         proto_item *tscn_bitmap;
844         proto_item *scn_bitmap_item;
845         guint32 scn_bitmap = tvb_get_ntohl(tvb, offset + 8);
846
847         scn_bitmap_item = proto_tree_add_uint(tt, hf_isns_scn_bitmap, tvb, offset+8, 4, scn_bitmap);
848         tscn_bitmap = proto_item_add_subtree(scn_bitmap_item, ett_scn_bitmap);
849
850         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_initiator_and_self_information_only, tvb, offset+8, 4, scn_bitmap);
851         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_target_and_self_information_only,    tvb, offset+8, 4, scn_bitmap);
852         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_management_registration_scn,         tvb, offset+8, 4, scn_bitmap);
853         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_object_removed,                      tvb, offset+8, 4, scn_bitmap);
854         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_object_added,                        tvb, offset+8, 4, scn_bitmap);
855         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_object_updated,                      tvb, offset+8, 4, scn_bitmap);
856         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_dd_dds_member_removed,               tvb, offset+8, 4, scn_bitmap);
857         proto_tree_add_boolean(tt, hf_isns_scn_bitmap_dd_dds_member_added,                 tvb, offset+8, 4, scn_bitmap);
858     }
859     goto end;
860
861 iscsi_node_type:
862     {
863         proto_item *tisnt;
864         proto_item *isnt_item;
865         guint32 isnt = tvb_get_ntohl(tvb, offset + 8);
866
867         isnt_item = proto_tree_add_uint(tt, hf_isns_isnt, tvb, offset+8, 4, isnt);
868         tisnt = proto_item_add_subtree(isnt_item, ett_isns_isnt);
869
870         proto_tree_add_boolean(tisnt, hf_isns_isnt_control,   tvb, offset+8, 4, isnt);
871         proto_tree_add_boolean(tisnt, hf_isns_isnt_initiator, tvb, offset+8, 4, isnt);
872         proto_tree_add_boolean(tisnt, hf_isns_isnt_target,    tvb, offset+8, 4, isnt);
873     }
874     goto end;
875
876 portal_security_bitmap:
877     {
878         proto_item *tpsb;
879         proto_item *psb_item;
880         guint32 psb = tvb_get_ntohl(tvb, offset + 8);
881
882         psb_item = proto_tree_add_uint(tt, hf_isns_psb, tvb, offset+8, 4, psb);
883         tpsb = proto_item_add_subtree(psb_item, ett_isns_psb);
884
885         proto_tree_add_boolean(tpsb, hf_isns_psb_tunnel_mode,     tvb, offset+8, 4, psb);
886         proto_tree_add_boolean(tpsb, hf_isns_psb_transport_mode,  tvb, offset+8, 4, psb);
887         proto_tree_add_boolean(tpsb, hf_isns_psb_pfs,             tvb, offset+8, 4, psb);
888         proto_tree_add_boolean(tpsb, hf_isns_psb_aggressive_mode, tvb, offset+8, 4, psb);
889         proto_tree_add_boolean(tpsb, hf_isns_psb_main_mode,       tvb, offset+8, 4, psb);
890         proto_tree_add_boolean(tpsb, hf_isns_psb_ike_ipsec,       tvb, offset+8, 4, psb);
891         proto_tree_add_boolean(tpsb, hf_isns_psb_bitmap,          tvb, offset+8, 4, psb);
892     }
893     goto end;
894
895 portal_group:
896     /*
897       16bit portal group identifier - least significant
898     */
899     goto end;
900
901 version_range:
902     /*
903       16bit minimum protocol supported - least significant
904       16bit maximum protocol supported - most significant
905     */
906     goto end;
907
908 entity_protocol:
909     proto_tree_add_uint(tt,hf_isns_entity_protocol, tvb, offset + 8, len, tag);
910     goto end;
911
912 string:
913     proto_tree_add_item(tt,hf_isns_attr_string, tvb, offset + 8, len, FALSE);
914     goto end;
915
916 ip:
917     proto_tree_add_item(tt,hf_isns_attr_ipaddr, tvb, offset + 8, len, FALSE);
918     goto end;
919
920 seconds:
921     {
922         guint32 i = tvb_get_ntohl(tvb, offset + 8);
923
924         proto_tree_add_uint(tt, hf_isns_attr_seconds, tvb, offset + 8, 4, i);
925         goto end;
926     }
927
928 port:
929     {
930         proto_item *tport;
931         proto_item *port_item;
932         guint32 port = tvb_get_ntohl(tvb, offset + 8);
933         guint16 port_type = tvb_get_ntohl(tvb, offset + 8);
934         guint16 port_port = tvb_get_ntohl(tvb, offset + 10);
935
936         port_item = proto_tree_add_uint(tt, hf_isns_port, tvb, offset+8, 4, port);
937         tport = proto_item_add_subtree(port_item, ett_isns_port);
938
939         proto_tree_add_boolean(tport, hf_isns_port_type, tvb, offset+8, 2, port_port);
940         proto_tree_add_uint(tport,hf_isns_port_port, tvb, offset+10, 2, port_type);
941     }
942     goto end;
943
944 will_not_decode:
945     goto end;
946
947 end:
948
949
950
951     
952     /* move on the offset to next attribute */
953     
954
955     return (8 + len);    
956 }
957
958
959
960 /* Register the protocol with Ethereal */
961
962 /* this format is require because a script is used to build the C function
963    that calls all the protocol registration.
964 */
965
966 void proto_register_isns(void)
967 {
968     /* Setup list of header fields  See Section 1.6.1 for details*/
969     static hf_register_info hf[] = {
970         /* The Header Stuff */
971         { &hf_isns_version,
972           { "iSNSP Version","isns.PVer",
973             FT_UINT16, BASE_DEC, NULL, 0,          
974             "iSNS Protocol Version" ,HFILL}
975         },
976         { &hf_isns_function_id,
977           { "Function ID","isns.functionid",        
978             FT_UINT16, BASE_DEC,VALS(&isns_function_ids),0,          
979             "iSNS Function ID" ,HFILL}
980         },
981         { &hf_isns_pdu_length,
982           { "PDU Length","isns.pdulength",
983             FT_UINT16, BASE_DEC,NULL,0,
984             "iSNS PDU Length" ,HFILL}
985         },
986
987         { &hf_isns_flags,
988           { "Flags","isns.flags",
989             FT_UINT16, BASE_HEX,NULL,0,
990             "iSNS Flags" ,HFILL}
991         },
992         { &hf_isns_client,
993           { "Client    ","isns.flags.client",
994             FT_BOOLEAN, 16, TFS(&isns_flag_client), 0x8000, /* bit 16 */
995             "iSNS Client" ,HFILL}
996         },
997         { &hf_isns_server,
998           { "Server    ","isns.flags.server",
999             FT_BOOLEAN, 16, TFS(&isns_flag_server), 0x4000, /* bit 17 */
1000             "iSNS Server" ,HFILL}
1001         },
1002         { &hf_isns_replace,
1003           { "Replace   ","isns.flags.replace",
1004             FT_BOOLEAN, 16, TFS(&isns_flag_replace), 0x1000, /* bit 19 */
1005             "iSNS Replace" ,HFILL}
1006         },
1007         { &hf_isns_last_pdu,
1008           { "Last PDU  ","isns.flags.lastpdu",
1009             FT_BOOLEAN, 16, TFS(&isns_flag_last_pdu), 0x0800, /* bit 20 */
1010             "iSNS Last PDU" ,HFILL}
1011         },
1012         { &hf_isns_first_pdu,
1013           { "First PDU ","isns.flags.firstpdu",
1014             FT_BOOLEAN, 16, TFS(&isns_flag_first_pdu), 0x0400, /* bit 21 */
1015             "iSNS First PDU",HFILL }
1016         },
1017
1018
1019         { &hf_isns_transaction_id,
1020           { "Transaction ID","isns.transactionid",
1021             FT_UINT16, BASE_DEC,NULL,0,
1022             "iSNS transaction ID" ,HFILL}
1023         },
1024         { &hf_isns_sequence_id,
1025           { "Sequence ID","isns.sequenceid",
1026             FT_UINT16, BASE_DEC,NULL,0,
1027             "iSNS sequence ID" ,HFILL}
1028         },
1029
1030         { &hf_isns_entity_protocol,
1031           { "Entity Protocol","isns.entity_protocol",
1032             FT_UINT32, BASE_DEC,TFS(isns_entity_protocol),0,
1033             "iSNS Entity Protocol" ,HFILL}
1034         },
1035         /* The Payload stuff */
1036
1037         { &hf_isns_port,
1038           { "Port","isns.port",
1039             FT_UINT32, BASE_HEX, NULL, 0,
1040             "Port", HFILL }
1041         },
1042
1043         { &hf_isns_port_type,
1044           { "Port Type","isns.port.port_type",
1045             FT_BOOLEAN, 16, TFS(&isns_port_type), 0x01, /* bit 15 (or bit 1 of a 16bit word) */
1046             "Port Type",HFILL }
1047         },
1048
1049         { &hf_isns_port_port,
1050           { "Port","isns.port.port",
1051             FT_UINT16, BASE_DEC, NULL, 0,
1052             "Port", HFILL }
1053         },
1054
1055
1056         { &hf_isns_psb,
1057           { "Portal Security Bitmap","isns.psb",
1058             FT_UINT32, BASE_HEX, NULL, 0,
1059             "Portal Security Bitmap", HFILL }
1060         },
1061         { &hf_isns_psb_tunnel_mode,
1062           { "Tunnel Mode     ","isns.psb.tunnel",
1063             FT_BOOLEAN, 32, TFS(&isns_psb_tunnel_mode),     0x0040, /* bit 25 */
1064             "Tunnel Mode Preferred",HFILL }
1065         },
1066         { &hf_isns_psb_transport_mode,
1067           { "Transport Mode  ","isns.psb.transport",
1068             FT_BOOLEAN, 32, TFS(&isns_psb_transport_mode),  0x0020, /* bit 26 */
1069             "Transport Mode",HFILL }
1070         },
1071         { &hf_isns_psb_pfs,
1072           { "PFS             ","isns.psb.pfs",
1073             FT_BOOLEAN, 32, TFS(&isns_psb_pfs),        0x0010, /* bit 27 */
1074             "PFS",HFILL }
1075         },
1076         { &hf_isns_psb_aggressive_mode,
1077           { "Aggressive Mode ","isns.psb.aggressive_mode",
1078             FT_BOOLEAN, 32, TFS(&isns_psb_aggressive_mode), 0x0008, /* bit 28 */
1079             "Aggressive Mode",HFILL }
1080         },
1081         { &hf_isns_psb_main_mode,
1082           { "Main Mode       ","isns.psb.main_mode",
1083             FT_BOOLEAN, 32, TFS(&isns_psb_main_mode),  0x0004, /* bit 29 */
1084             "Main Mode",HFILL }
1085         },
1086         { &hf_isns_psb_ike_ipsec,
1087           { "IKE/IPSec       ","isns.psb.ike_ipsec",
1088             FT_BOOLEAN, 32, TFS(&isns_psb_ike_ipsec),  0x0002, /* bit 30 */
1089             "IKE/IPSec",HFILL }
1090         },
1091         { &hf_isns_psb_bitmap,
1092           { "Bitmap          ","isns.psb.bitmap",
1093             FT_BOOLEAN, 32, TFS(&isns_psb_bitmap),     0x0001, /* bit 31 */
1094             "Bitmap",HFILL }
1095         },
1096
1097
1098
1099         { &hf_isns_scn_bitmap,
1100           { "iSCSI SCN Bitmap","isns.scn_bitmap",
1101             FT_UINT32, BASE_HEX, NULL, 0,
1102             "iSCSI SCN Bitmap", HFILL }
1103         },
1104         { &hf_isns_scn_bitmap_initiator_and_self_information_only,
1105           { "Initiator And Self Information Only","isns.scn_bitmap.initiator_and_self_information_only",
1106             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_initiator_and_self_information_only),     0x0080, /* bit 24 */
1107             "Initiator And Self Information Only",HFILL }
1108         },
1109         { &hf_isns_scn_bitmap_target_and_self_information_only,
1110           { "Target And Self Information Only","isns.scn_bitmap.target_and_self_information_only",
1111             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_target_and_self_information_only),     0x0040, /* bit 25 */
1112             "Target And Self Information Only",HFILL }
1113         },
1114         { &hf_isns_scn_bitmap_management_registration_scn,
1115           { "Management Registration/SCN","isns.scn_bitmap.management_registration_scn",
1116             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_management_registration_scn),     0x0020, /* bit 26 */
1117             "Management Registration/SCN",HFILL }
1118         },
1119         { &hf_isns_scn_bitmap_object_removed,
1120           { "Object Removed","isns.scn_bitmap.object_removed",
1121             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_object_removed),     0x0010, /* bit 27 */
1122             "Object Removed",HFILL }
1123         },
1124         { &hf_isns_scn_bitmap_object_added,
1125           { "Object Added","isns.scn_bitmap.object_added",
1126             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_object_added),     0x0008, /* bit 28 */
1127             "Object Added",HFILL }
1128         },
1129         { &hf_isns_scn_bitmap_object_updated,
1130           { "Object Updated","isns.scn_bitmap.object_updated",
1131             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_object_updated),     0x0004, /* bit 29 */
1132             "Object Updated",HFILL }
1133         },
1134         { &hf_isns_scn_bitmap_dd_dds_member_removed,
1135           { "DD/DDS Member Removed (Mgmt Reg/SCN only)","isns.scn_bitmap.dd_dds_member_removed",
1136             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_dd_dds_member_removed),     0x0002, /* bit 30 */
1137             "DD/DDS Member Removed (Mgmt Reg/SCN only)",HFILL }
1138         },
1139         { &hf_isns_scn_bitmap_dd_dds_member_added,
1140           { "DD/DDS Member Added (Mgmt Reg/SCN only)","isns.scn_bitmap.dd_dds_member_added",
1141             FT_BOOLEAN, 32, TFS(&isns_scn_bitmap_dd_dds_member_added),     0x0001, /* bit 31 */
1142             "DD/DDS Member Added (Mgmt Reg/SCN only)",HFILL }
1143         },
1144
1145
1146         { &hf_isns_isnt,
1147           { "iSCSI Node Type","isns.isnt",
1148             FT_UINT32, BASE_HEX, NULL, 0,
1149             "iSCSI Node Type", HFILL }
1150         },
1151         { &hf_isns_isnt_control,
1152           { "Control   ","isns.isnt.control",
1153             FT_BOOLEAN, 32, TFS(&isns_isnt_control),  0x0004, /* bit 29 */
1154             "Control",HFILL }
1155         },
1156         { &hf_isns_isnt_initiator,
1157           { "Initiator ","isns.isnt.initiator",
1158             FT_BOOLEAN, 32, TFS(&isns_isnt_initiator),  0x0002, /* bit 30 */
1159             "Initiator",HFILL }
1160         },
1161         { &hf_isns_isnt_target,
1162           { "Target    ","isns.isnt.target",
1163             FT_BOOLEAN, 32, TFS(&isns_isnt_target),     0x0001, /* bit 31 */
1164             "Target",HFILL }
1165         },
1166
1167
1168         { &hf_isns_resp_errorcode,
1169           { "ErrorCode","isns.errorcode",
1170             FT_UINT32, BASE_DEC,TFS(isns_errorcode),0,
1171             "iSNS Response Error Code" ,HFILL}
1172         },
1173
1174         { &hf_isns_attr_tag,
1175           { "Attribute Tag","isns.attr.tag",
1176             FT_UINT32, BASE_DEC,TFS(isns_attribute_tags),0,
1177             "iSNS Attribute Tag" ,HFILL}
1178         },
1179
1180         { &hf_isns_attr_len,
1181           { "Attribute Length","isns.attr.len",
1182             FT_UINT32, BASE_DEC,NULL,0,
1183             "iSNS Attribute Length" ,HFILL}
1184         },
1185
1186         { &hf_isns_attr_payload,
1187           { "Attribute Payload","isns.attr.payload",
1188             FT_BYTES, BASE_HEX,NULL,0,
1189             "iSNS Attribute Payload" ,HFILL}
1190         },
1191
1192         { &hf_isns_heartbeat_ipv6_addr,
1193           { "Heartbeat Address (ipv6)","isns.heartbeat.address",
1194             FT_IPv6, BASE_NONE, NULL, 0x0,
1195             "Server IPv6 Address", HFILL }},
1196
1197         { &hf_isns_heartbeat_tcp_port,
1198           { "Heartbeat TCP Port","isns.heartbeat.tcpport",
1199             FT_UINT16, BASE_DEC, NULL, 0x0,
1200             "Server TCP Port", HFILL }},
1201
1202         { &hf_isns_heartbeat_udp_port,
1203           { "Heartbeat UDP Port","isns.heartbeat.udpport",
1204             FT_UINT16, BASE_DEC, NULL, 0x0,
1205             "Server UDP Port", HFILL }},
1206
1207
1208         { &hf_isns_heartbeat_interval,
1209           { "Heartbeat Interval (secs)","isns.heartbeat.interval",
1210             FT_UINT32, BASE_DEC, NULL, 0x0,
1211             "Server Heartbeat interval", HFILL }},
1212
1213         { &hf_isns_heartbeat_counter,
1214           { "Heartbeat counter","isns.heartbeat.counter",
1215             FT_UINT32, BASE_DEC, NULL, 0x0,
1216             "Server Heartbeat Counter", HFILL }},
1217
1218         { &hf_isns_attr_string,
1219           { "Attribute String","isns.attrstring",
1220             FT_STRING, BASE_NONE, NULL, 0x0,
1221             "String", HFILL }},
1222
1223         { &hf_isns_attr_ipaddr,
1224           { "Attribute IP Address","isns.ipv4",
1225             FT_IPv6, BASE_NONE, NULL, 0x0,
1226             "IPv6 Address", HFILL }},
1227
1228         { &hf_isns_attr_index,
1229           { "Index","isns.index",
1230             FT_UINT32, BASE_DEC, NULL, 0x0,
1231             "Index", HFILL }},
1232
1233         { &hf_isns_attr_seconds,
1234           { "Seconds","isns.seconds",
1235             FT_UINT32, BASE_DEC, NULL, 0x0,
1236             "Seconds", HFILL }},
1237
1238         
1239         { &hf_isns_payload,
1240           { "Payload", "isns.payload",
1241             FT_BYTES, BASE_HEX, NULL, 0,
1242             "Payload" ,HFILL}
1243         }
1244     };
1245
1246 /* Setup protocol subtree array */
1247     static gint *ett[] = {
1248         &ett_isns,
1249         &ett_isns_flags,
1250         &ett_isns_payload,
1251         &ett_isns_port,
1252         &ett_isns_psb,
1253         &ett_isns_isnt,
1254         &ett_scn_bitmap
1255     };
1256
1257 /* Register the protocol name and description */
1258     proto_isns = proto_register_protocol("iSNS",
1259                                          "iSNS", "isns");
1260
1261     proto_register_field_array(proto_isns, hf, array_length(hf));
1262
1263     proto_register_subtree_array(ett, array_length(ett));
1264
1265 }
1266
1267 /* If this dissector uses sub-dissector registration add a registration routine.
1268    This format is required because a script is used to find these routines and
1269    create the code that calls these routines.
1270 */
1271
1272 void
1273 proto_reg_handoff_isns(void)
1274 {
1275     dissector_handle_t isns_handle;
1276     isns_handle = new_create_dissector_handle(dissect_isns,proto_isns);
1277     dissector_add("udp.port",ISNS_UDP_PORT,isns_handle);
1278     dissector_add("tcp.port",ISNS_TCP_PORT,isns_handle);
1279 }