From Didier Gautheron:
[obnox/wireshark/wip.git] / epan / dissectors / packet-tns.c
1 /* packet-tns.c
2  * Routines for Oracle TNS packet dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-tftp.c
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdio.h>
32
33 #include <string.h>
34 #include <glib.h>
35 #include <epan/packet.h>
36 #include "packet-tcp.h"
37 #include "packet-tns.h"
38
39 #include <epan/prefs.h>
40
41 /* desegmentation of TNS over TCP */
42 static gboolean tns_desegment = TRUE;
43
44 static int proto_tns = -1;
45 static int hf_tns_request = -1;
46 static int hf_tns_response = -1;
47 static int hf_tns_length = -1;
48 static int hf_tns_packet_checksum = -1;
49 static int hf_tns_header_checksum = -1;
50 static int hf_tns_packet_type = -1;
51 static int hf_tns_reserved_byte = -1;
52 static int hf_tns_connect = -1;
53 static int hf_tns_version = -1;
54 static int hf_tns_compat_version = -1;
55
56 static int hf_tns_service_options = -1;
57 static int hf_tns_sopt_flag_bconn = -1;
58 static int hf_tns_sopt_flag_pc = -1;
59 static int hf_tns_sopt_flag_hc = -1;
60 static int hf_tns_sopt_flag_fd = -1;
61 static int hf_tns_sopt_flag_hd = -1;
62 static int hf_tns_sopt_flag_dc1 = -1;
63 static int hf_tns_sopt_flag_dc2 = -1;
64 static int hf_tns_sopt_flag_dio = -1;
65 static int hf_tns_sopt_flag_ap = -1;
66 static int hf_tns_sopt_flag_ra = -1;
67 static int hf_tns_sopt_flag_sa = -1;
68
69 static int hf_tns_sdu_size = -1;
70 static int hf_tns_max_tdu_size = -1;
71
72 static int hf_tns_nt_proto_characteristics = -1;
73 static int hf_tns_ntp_flag_hangon = -1;
74 static int hf_tns_ntp_flag_crel = -1;
75 static int hf_tns_ntp_flag_tduio = -1;
76 static int hf_tns_ntp_flag_srun = -1;
77 static int hf_tns_ntp_flag_dtest = -1;
78 static int hf_tns_ntp_flag_cbio = -1;
79 static int hf_tns_ntp_flag_asio = -1;
80 static int hf_tns_ntp_flag_pio = -1;
81 static int hf_tns_ntp_flag_grant = -1;
82 static int hf_tns_ntp_flag_handoff = -1;
83 static int hf_tns_ntp_flag_sigio = -1;
84 static int hf_tns_ntp_flag_sigpipe = -1;
85 static int hf_tns_ntp_flag_sigurg = -1;
86 static int hf_tns_ntp_flag_urgentio = -1;
87 static int hf_tns_ntp_flag_fdio = -1;
88 static int hf_tns_ntp_flag_testop = -1;
89
90 static int hf_tns_line_turnaround = -1;
91 static int hf_tns_value_of_one = -1;
92 static int hf_tns_connect_data_length = -1;
93 static int hf_tns_connect_data_offset = -1;
94 static int hf_tns_connect_data_max = -1;
95
96 static int hf_tns_connect_flags0 = -1;
97 static int hf_tns_connect_flags1 = -1;
98 static int hf_tns_conn_flag_nareq = -1;
99 static int hf_tns_conn_flag_nalink = -1;
100 static int hf_tns_conn_flag_enablena = -1;
101 static int hf_tns_conn_flag_ichg = -1;
102 static int hf_tns_conn_flag_wantna = -1;
103
104 static int hf_tns_connect_data = -1;
105 static int hf_tns_trace_cf1 = -1;
106 static int hf_tns_trace_cf2 = -1;
107 static int hf_tns_trace_cid = -1;
108
109 static int hf_tns_accept = -1;
110 static int hf_tns_accept_data_length = -1;
111 static int hf_tns_accept_data_offset = -1;
112 static int hf_tns_accept_data = -1;
113
114 static int hf_tns_refuse = -1;
115 static int hf_tns_refuse_reason_user = -1;
116 static int hf_tns_refuse_reason_system = -1;
117 static int hf_tns_refuse_data_length = -1;
118 static int hf_tns_refuse_data = -1;
119
120 static int hf_tns_abort = -1;
121 static int hf_tns_abort_reason_user = -1;
122 static int hf_tns_abort_reason_system = -1;
123 static int hf_tns_abort_data = -1;
124
125 static int hf_tns_marker = -1;
126 static int hf_tns_marker_type = -1;
127 static int hf_tns_marker_data_byte = -1;
128 static int hf_tns_marker_data = -1;
129
130 static int hf_tns_redirect = -1;
131 static int hf_tns_redirect_data_length = -1;
132 static int hf_tns_redirect_data = -1;
133
134 static int hf_tns_control = -1;
135 static int hf_tns_control_cmd = -1;
136 static int hf_tns_control_data = -1;
137
138 static int hf_tns_data_flag = -1;
139 static int hf_tns_data_flag_send = -1;
140 static int hf_tns_data_flag_rc = -1;
141 static int hf_tns_data_flag_c = -1;
142 static int hf_tns_data_flag_reserved = -1;
143 static int hf_tns_data_flag_more = -1;
144 static int hf_tns_data_flag_eof = -1;
145 static int hf_tns_data_flag_dic = -1;
146 static int hf_tns_data_flag_rts = -1;
147 static int hf_tns_data_flag_sntt = -1;
148 static int hf_tns_data = -1;
149
150 static gint ett_tns = -1;
151 static gint ett_tns_connect = -1;
152 static gint ett_tns_accept = -1;
153 static gint ett_tns_refuse = -1;
154 static gint ett_tns_abort = -1;
155 static gint ett_tns_redirect = -1;
156 static gint ett_tns_marker = -1;
157 static gint ett_tns_attention = -1;
158 static gint ett_tns_control = -1;
159 static gint ett_tns_data = -1;
160 static gint ett_tns_data_flag = -1;
161 static gint ett_tns_sopt_flag = -1;
162 static gint ett_tns_ntp_flag = -1;
163 static gint ett_tns_conn_flag = -1;
164 static gint ett_sql = -1;
165
166 static dissector_handle_t data_handle;
167
168 #define TCP_PORT_TNS                    1521
169
170 static const value_string tns_type_vals[] = {
171         {TNS_TYPE_CONNECT,   "Connect" },
172         {TNS_TYPE_ACCEPT,    "Accept" },
173         {TNS_TYPE_ACK,       "Acknowledge" },
174         {TNS_TYPE_REFUSE,    "Refuse" },
175         {TNS_TYPE_REDIRECT,  "Redirect" },
176         {TNS_TYPE_DATA,      "Data" },
177         {TNS_TYPE_NULL,      "Null" },
178         {TNS_TYPE_ABORT,     "Abort" },
179         {TNS_TYPE_RESEND,    "Resend"},
180         {TNS_TYPE_MARKER,    "Marker"},
181         {TNS_TYPE_ATTENTION, "Attention"},
182         {TNS_TYPE_CONTROL,   "Control"},
183         {0, NULL}
184 };
185
186 static const value_string tns_marker_types[] = {
187         {0, "Data Marker - 0 Data Bytes"},
188         {1, "Data Marker - 1 Data Bytes"},
189         {2, "Attention Marker"},
190         {0, NULL}
191 };
192
193 static const value_string tns_control_cmds[] = {
194         {1, "Oracle Trace Command"},
195         {0, NULL}
196 };
197
198 void proto_reg_handoff_tns(void);
199 static guint get_tns_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset);
200 static void dissect_tns_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
201
202 static void dissect_tns_service_options(tvbuff_t *tvb, int offset,
203         proto_tree *sopt_tree)
204 {
205
206         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_bconn, tvb,
207                         offset, 2, FALSE);
208         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_pc, tvb,
209                         offset, 2, FALSE);
210         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_hc, tvb,
211                         offset, 2, FALSE);
212         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_fd, tvb,
213                         offset, 2, FALSE);
214         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_hd, tvb,
215                         offset, 2, FALSE);
216         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_dc1, tvb,
217                         offset, 2, FALSE);
218         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_dc2, tvb,
219                         offset, 2, FALSE);
220         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_dio, tvb,
221                         offset, 2, FALSE);
222         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_ap, tvb,
223                         offset, 2, FALSE);
224         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_ra, tvb,
225                         offset, 2, FALSE);
226         proto_tree_add_item(sopt_tree, hf_tns_sopt_flag_sa, tvb,
227                         offset, 2, FALSE);
228
229 }
230
231 static void dissect_tns_connect_flag(tvbuff_t *tvb, int offset,
232         proto_tree *cflag_tree)
233 {
234
235         proto_tree_add_item(cflag_tree, hf_tns_conn_flag_nareq, tvb, offset, 1, FALSE);
236         proto_tree_add_item(cflag_tree, hf_tns_conn_flag_nalink, tvb, offset, 1, FALSE);
237         proto_tree_add_item(cflag_tree, hf_tns_conn_flag_enablena, tvb, offset, 1, FALSE);
238         proto_tree_add_item(cflag_tree, hf_tns_conn_flag_ichg, tvb, offset, 1, FALSE);
239         proto_tree_add_item(cflag_tree, hf_tns_conn_flag_wantna, tvb, offset, 1, FALSE);
240 }
241
242 static void dissect_tns_data(tvbuff_t *tvb, int offset, packet_info *pinfo,
243         proto_tree *tree, proto_tree *tns_tree)
244 {
245         proto_tree *data_tree = NULL, *ti;
246         proto_item *hidden_item;
247         int is_sns = 0;
248
249         if ( tvb_bytes_exist(tvb, offset+2, 4) )
250         {
251                 if ( tvb_get_guint8(tvb, offset+2) == 0xDE &&
252                      tvb_get_guint8(tvb, offset+3) == 0xAD &&
253                      tvb_get_guint8(tvb, offset+4) == 0xBE &&
254                      tvb_get_guint8(tvb, offset+5) == 0xEF )
255                 {
256                         is_sns = 1;
257                 }
258         }
259
260         if ( tree )
261         {
262                 if ( is_sns )
263                 {
264                         ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
265                             "Secure Network Services");
266                 }
267                 else
268                 {
269                         ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
270                             "Data");
271                 }
272                 data_tree = proto_item_add_subtree(ti, ett_tns_data);
273
274                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_data, tvb, 0, 0,
275                                         TRUE);
276                 PROTO_ITEM_SET_HIDDEN(hidden_item);
277         }
278
279         if ( tree )
280         {
281                 proto_tree *df_tree = NULL;
282
283                 ti = proto_tree_add_item(data_tree, hf_tns_data_flag, tvb, offset, 2, FALSE);
284
285                 df_tree = proto_item_add_subtree(ti, ett_tns_data_flag);
286                 proto_tree_add_item(df_tree, hf_tns_data_flag_send, tvb, offset, 2, FALSE);
287                 proto_tree_add_item(df_tree, hf_tns_data_flag_rc, tvb, offset, 2, FALSE);
288                 proto_tree_add_item(df_tree, hf_tns_data_flag_c, tvb, offset, 2, FALSE);
289                 proto_tree_add_item(df_tree, hf_tns_data_flag_reserved, tvb, offset, 2, FALSE);
290                 proto_tree_add_item(df_tree, hf_tns_data_flag_more, tvb, offset, 2, FALSE);
291                 proto_tree_add_item(df_tree, hf_tns_data_flag_eof, tvb, offset, 2, FALSE);
292                 proto_tree_add_item(df_tree, hf_tns_data_flag_dic, tvb, offset, 2, FALSE);
293                 proto_tree_add_item(df_tree, hf_tns_data_flag_rts, tvb, offset, 2, FALSE);
294                 proto_tree_add_item(df_tree, hf_tns_data_flag_sntt, tvb, offset, 2, FALSE);
295         }
296         offset += 2;
297
298         if ( check_col(pinfo->cinfo, COL_INFO) )
299         {
300                 if ( is_sns )
301                 {
302                         col_append_str(pinfo->cinfo, COL_INFO, ", SNS");
303                 }
304                 else
305                 {
306                         col_append_str(pinfo->cinfo, COL_INFO, ", Data");
307                 }
308         }
309
310         if ( data_tree )
311         {
312                 call_dissector(data_handle,
313                     tvb_new_subset_remaining(tvb, offset), pinfo, data_tree);
314         }
315
316         return;
317 }
318
319 static void dissect_tns_connect(tvbuff_t *tvb, int offset, packet_info *pinfo,
320         proto_tree *tree, proto_tree *tns_tree)
321 {
322         proto_tree *connect_tree = NULL, *ti;
323         proto_item *hidden_item;
324         int cd_offset;
325         int cd_len;
326         int tns_offset = offset-8;
327
328         if ( tree )
329         {
330                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
331                     "Connect");
332                 connect_tree = proto_item_add_subtree(ti, ett_tns_connect);
333
334                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_connect, tvb,
335                                     0, 0, TRUE);
336                 PROTO_ITEM_SET_HIDDEN(hidden_item);
337         }
338
339         col_append_str(pinfo->cinfo, COL_INFO, ", Connect");
340
341         if ( connect_tree )
342         {
343                 proto_tree_add_item(connect_tree, hf_tns_version, tvb,
344                         offset, 2, FALSE);
345         }
346         offset += 2;
347
348         if ( connect_tree )
349         {
350                 proto_tree_add_item(connect_tree, hf_tns_compat_version, tvb,
351                         offset, 2, FALSE);
352         }
353         offset += 2;
354
355         if ( connect_tree )
356         {
357                 proto_tree *sopt_tree = NULL;
358
359                 ti = proto_tree_add_item(connect_tree, hf_tns_service_options, tvb,
360                         offset, 2, FALSE);
361
362                 sopt_tree = proto_item_add_subtree(ti, ett_tns_sopt_flag);
363
364                 dissect_tns_service_options(tvb, offset, sopt_tree);
365
366
367         }
368         offset += 2;
369
370         if ( connect_tree )
371         {
372                 proto_tree_add_item(connect_tree, hf_tns_sdu_size, tvb,
373                         offset, 2, FALSE);
374         }
375         offset += 2;
376
377         if ( connect_tree )
378         {
379                 proto_tree_add_item(connect_tree, hf_tns_max_tdu_size, tvb,
380                         offset, 2, FALSE);
381         }
382         offset += 2;
383
384         if ( connect_tree )
385         {
386                 proto_tree *ntp_tree = NULL;
387
388                 ti = proto_tree_add_item(connect_tree, hf_tns_nt_proto_characteristics, tvb,
389                         offset, 2, FALSE);
390
391                 ntp_tree = proto_item_add_subtree(ti, ett_tns_ntp_flag);
392
393                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_hangon, tvb, offset, 2, FALSE);
394                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_crel, tvb, offset, 2, FALSE);
395                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_tduio, tvb, offset, 2, FALSE);
396                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_srun, tvb, offset, 2, FALSE);
397                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_dtest, tvb, offset, 2, FALSE);
398                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_cbio, tvb, offset, 2, FALSE);
399                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_asio, tvb, offset, 2, FALSE);
400                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_pio, tvb, offset, 2, FALSE);
401                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_grant, tvb, offset, 2, FALSE);
402                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_handoff, tvb, offset, 2, FALSE);
403                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_sigio, tvb, offset, 2, FALSE);
404                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_sigpipe, tvb, offset, 2, FALSE);
405                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_sigurg, tvb, offset, 2, FALSE);
406                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_urgentio, tvb, offset, 2, FALSE);
407                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_fdio, tvb, offset, 2, FALSE);
408                 proto_tree_add_item(ntp_tree, hf_tns_ntp_flag_testop, tvb, offset, 2, FALSE);
409         }
410         offset += 2;
411
412         if ( connect_tree )
413         {
414                 proto_tree_add_item(connect_tree, hf_tns_line_turnaround, tvb,
415                         offset, 2, FALSE);
416         }
417         offset += 2;
418
419         if ( connect_tree )
420         {
421                 proto_tree_add_item(connect_tree, hf_tns_value_of_one, tvb,
422                         offset, 2, FALSE);
423         }
424         offset += 2;
425
426         cd_len = tvb_get_ntohs(tvb, offset);
427         if ( connect_tree )
428         {
429                 proto_tree_add_uint(connect_tree, hf_tns_connect_data_length, tvb,
430                         offset, 2, cd_len);
431         }
432         offset += 2;
433
434         cd_offset = tvb_get_ntohs(tvb, offset);
435         if ( connect_tree )
436         {
437                 proto_tree_add_uint(connect_tree, hf_tns_connect_data_offset, tvb,
438                         offset, 2, cd_offset);
439         }
440         offset += 2;
441
442         if ( connect_tree )
443         {
444                 proto_tree_add_item(connect_tree, hf_tns_connect_data_max, tvb,
445                         offset, 4, FALSE);
446         }
447         offset += 4;
448
449         if ( connect_tree )
450         {
451                 proto_tree *cflag_tree = NULL;
452
453                 ti = proto_tree_add_item(connect_tree, hf_tns_connect_flags0, tvb,
454                         offset, 1, FALSE);
455
456                 cflag_tree = proto_item_add_subtree(ti, ett_tns_conn_flag);
457
458                 dissect_tns_connect_flag(tvb, offset, cflag_tree);
459         }
460         offset += 1;
461
462         if ( connect_tree )
463         {
464                 proto_tree *cflag_tree = NULL;
465
466                 ti = proto_tree_add_item(connect_tree, hf_tns_connect_flags1, tvb,
467                         offset, 1, FALSE);
468
469                 cflag_tree = proto_item_add_subtree(ti, ett_tns_conn_flag);
470
471                 dissect_tns_connect_flag(tvb, offset, cflag_tree);
472         }
473         offset += 1;
474
475         /*
476          * XXX - sometimes it appears that this stuff isn't present
477          * in the packet.
478          */
479         if (offset + 16 <= tns_offset+cd_offset)
480         {
481                 if ( connect_tree )
482                 {
483                         proto_tree_add_item(connect_tree, hf_tns_trace_cf1, tvb,
484                                 offset, 4, FALSE);
485                 }
486                 offset += 4;
487
488                 if ( connect_tree )
489                 {
490                         proto_tree_add_item(connect_tree, hf_tns_trace_cf2, tvb,
491                                 offset, 4, FALSE);
492                 }
493                 offset += 4;
494
495                 if ( connect_tree )
496                 {
497                         proto_tree_add_item(connect_tree, hf_tns_trace_cid, tvb,
498                                 offset, 8, FALSE);
499                 }
500                 offset += 8;
501         }
502
503         if ( connect_tree && cd_len > 0)
504         {
505                 proto_tree_add_item(connect_tree, hf_tns_connect_data, tvb,
506                         tns_offset+cd_offset, -1, FALSE);
507         }
508         return;
509 }
510
511 static void dissect_tns_accept(tvbuff_t *tvb, int offset, packet_info *pinfo,
512         proto_tree *tree, proto_tree *tns_tree)
513 {
514         proto_tree *accept_tree = NULL, *ti;
515         proto_item *hidden_item;
516         int accept_offset;
517         int accept_len;
518         int tns_offset = offset-8;
519
520         if ( tree )
521         {
522                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
523                     "Accept");
524                 accept_tree = proto_item_add_subtree(ti, ett_tns_accept);
525
526                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_accept, tvb,
527                                     0, 0, TRUE);
528                 PROTO_ITEM_SET_HIDDEN(hidden_item);
529         }
530
531         col_append_str(pinfo->cinfo, COL_INFO, ", Accept");
532
533         if ( accept_tree )
534         {
535                 proto_tree_add_item(accept_tree, hf_tns_version, tvb,
536                         offset, 2, FALSE);
537         }
538         offset += 2;
539
540         if ( accept_tree )
541         {
542                 proto_tree *sopt_tree = NULL;
543
544                 ti = proto_tree_add_item(accept_tree, hf_tns_service_options,
545                         tvb, offset, 2, FALSE);
546
547                 sopt_tree = proto_item_add_subtree(ti, ett_tns_sopt_flag);
548
549                 dissect_tns_service_options(tvb, offset, sopt_tree);
550
551         }
552         offset += 2;
553
554         if ( accept_tree )
555         {
556                 proto_tree_add_item(accept_tree, hf_tns_sdu_size, tvb,
557                         offset, 2, FALSE);
558         }
559         offset += 2;
560
561         if ( accept_tree )
562         {
563                 proto_tree_add_item(accept_tree, hf_tns_max_tdu_size, tvb,
564                         offset, 2, FALSE);
565         }
566         offset += 2;
567
568         if ( accept_tree )
569         {
570                 proto_tree_add_item(accept_tree, hf_tns_value_of_one, tvb,
571                         offset, 2, FALSE);
572         }
573         offset += 2;
574
575         accept_len = tvb_get_ntohs(tvb, offset);
576         if ( accept_tree )
577         {
578                 proto_tree_add_uint(accept_tree, hf_tns_accept_data_length, tvb,
579                         offset, 2, accept_len);
580         }
581         offset += 2;
582
583         accept_offset = tvb_get_ntohs(tvb, offset);
584         if ( accept_tree )
585         {
586                 proto_tree_add_uint(accept_tree, hf_tns_accept_data_offset, tvb,
587                         offset, 2, accept_offset);
588         }
589         offset += 2;
590
591         if ( accept_tree )
592         {
593                 proto_tree *cflag_tree = NULL;
594
595                 ti = proto_tree_add_item(accept_tree, hf_tns_connect_flags0, tvb,
596                         offset, 1, FALSE);
597
598                 cflag_tree = proto_item_add_subtree(ti, ett_tns_conn_flag);
599
600                 dissect_tns_connect_flag(tvb, offset, cflag_tree);
601
602         }
603         offset += 1;
604
605         if ( accept_tree )
606         {
607                 proto_tree *cflag_tree = NULL;
608
609                 ti = proto_tree_add_item(accept_tree, hf_tns_connect_flags1, tvb,
610                         offset, 1, FALSE);
611
612                 cflag_tree = proto_item_add_subtree(ti, ett_tns_conn_flag);
613
614                 dissect_tns_connect_flag(tvb, offset, cflag_tree);
615
616         }
617         offset += 1;
618
619         if ( accept_tree && accept_len > 0)
620         {
621                 proto_tree_add_item(accept_tree, hf_tns_accept_data, tvb,
622                         tns_offset+accept_offset, -1, FALSE);
623         }
624         return;
625 }
626
627
628 static void dissect_tns_refuse(tvbuff_t *tvb, int offset, packet_info *pinfo,
629         proto_tree *tree, proto_tree *tns_tree)
630 {
631         proto_tree *refuse_tree = NULL, *ti;
632         proto_item *hidden_item;
633
634         if ( tree )
635         {
636                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
637                     "Refuse");
638                 refuse_tree = proto_item_add_subtree(ti, ett_tns_refuse);
639
640                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_refuse, tvb,
641                                     0, 0, TRUE);
642                 PROTO_ITEM_SET_HIDDEN(hidden_item);
643         }
644
645         col_append_str(pinfo->cinfo, COL_INFO, ", Refuse");
646
647         if ( refuse_tree )
648         {
649                 proto_tree_add_item(refuse_tree, hf_tns_refuse_reason_user, tvb,
650                         offset, 1, FALSE);
651         }
652         offset += 1;
653
654         if ( refuse_tree )
655         {
656                 proto_tree_add_item(refuse_tree, hf_tns_refuse_reason_system, tvb,
657                         offset, 1, FALSE);
658         }
659         offset += 1;
660
661         if ( refuse_tree )
662         {
663                 proto_tree_add_item(refuse_tree, hf_tns_refuse_data_length, tvb,
664                         offset, 2, FALSE);
665         }
666         offset += 2;
667
668         if ( refuse_tree )
669         {
670                 proto_tree_add_item(refuse_tree, hf_tns_refuse_data, tvb,
671                         offset, -1, FALSE);
672         }
673         return;
674 }
675
676
677 static void dissect_tns_abort(tvbuff_t *tvb, int offset, packet_info *pinfo,
678         proto_tree *tree, proto_tree *tns_tree)
679 {
680         proto_tree *abort_tree = NULL, *ti;
681         proto_item *hidden_item;
682
683         if ( tree )
684         {
685                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
686                     "Abort");
687                 abort_tree = proto_item_add_subtree(ti, ett_tns_abort);
688
689                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_abort, tvb,
690                                     0, 0, TRUE);
691                 PROTO_ITEM_SET_HIDDEN(hidden_item);
692         }
693
694         col_append_str(pinfo->cinfo, COL_INFO, ", Abort");
695
696         if ( abort_tree )
697         {
698                 proto_tree_add_item(abort_tree, hf_tns_abort_reason_user, tvb,
699                         offset, 1, FALSE);
700         }
701         offset += 1;
702
703         if ( abort_tree )
704         {
705                 proto_tree_add_item(abort_tree, hf_tns_abort_reason_system, tvb,
706                         offset, 1, FALSE);
707         }
708         offset += 1;
709
710         if ( abort_tree )
711         {
712                 proto_tree_add_item(abort_tree, hf_tns_abort_data, tvb,
713                         offset, -1, FALSE);
714         }
715         return;
716 }
717
718
719 static void dissect_tns_marker(tvbuff_t *tvb, int offset, packet_info *pinfo,
720         proto_tree *tree, proto_tree *tns_tree, int is_attention)
721 {
722         proto_tree *marker_tree = NULL, *ti;
723         proto_item *hidden_item;
724
725         if ( tree )
726         {
727                 if ( is_attention )
728                 {
729                         ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
730                             "Marker");
731                 }
732                 else
733                 {
734                         ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
735                             "Attention");
736                 }
737
738                 marker_tree = proto_item_add_subtree(ti, ett_tns_marker);
739                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_marker, tvb,
740                                     0, 0, TRUE);
741                 PROTO_ITEM_SET_HIDDEN(hidden_item);
742         }
743
744         if ( check_col(pinfo->cinfo, COL_INFO) )
745         {
746                 if ( is_attention )
747                 {
748                         col_append_str(pinfo->cinfo, COL_INFO, ", Marker");
749                 }
750                 else
751                 {
752                         col_append_str(pinfo->cinfo, COL_INFO, ", Attention");
753                 }
754         }
755
756         if ( marker_tree )
757         {
758                 proto_tree_add_item(marker_tree, hf_tns_marker_type, tvb,
759                         offset, 1, FALSE);
760         }
761         offset += 1;
762
763         if ( marker_tree )
764         {
765                 proto_tree_add_item(marker_tree, hf_tns_marker_data_byte, tvb,
766                         offset, 1, FALSE);
767         }
768         offset += 1;
769
770         if ( marker_tree )
771         {
772                 proto_tree_add_item(marker_tree, hf_tns_marker_data_byte, tvb,
773                         offset, 1, FALSE);
774         }
775         offset += 1;
776
777         return;
778 }
779
780 static void dissect_tns_redirect(tvbuff_t *tvb, int offset, packet_info *pinfo,
781         proto_tree *tree, proto_tree *tns_tree)
782 {
783         proto_tree *redirect_tree = NULL, *ti;
784         proto_item *hidden_item;
785
786         if ( tree )
787         {
788                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
789                     "Redirect");
790                 redirect_tree = proto_item_add_subtree(ti, ett_tns_redirect);
791
792                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_redirect, tvb,
793                                     0, 0, TRUE);
794                 PROTO_ITEM_SET_HIDDEN(hidden_item);
795         }
796
797         col_append_str(pinfo->cinfo, COL_INFO, ", Redirect");
798
799         if ( redirect_tree )
800         {
801                 proto_tree_add_item(redirect_tree, hf_tns_redirect_data_length, tvb,
802                         offset, 2, FALSE);
803         }
804         offset += 2;
805
806         if ( redirect_tree )
807         {
808                 proto_tree_add_item(redirect_tree, hf_tns_redirect_data, tvb,
809                         offset, -1, FALSE);
810         }
811         return;
812 }
813
814 static void dissect_tns_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
815         proto_tree *tree, proto_tree *tns_tree)
816 {
817         proto_tree *control_tree = NULL, *ti;
818         proto_item *hidden_item;
819
820         if ( tree )
821         {
822                 ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
823                     "Control");
824                 control_tree = proto_item_add_subtree(ti, ett_tns_control);
825
826                 hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_control, tvb,
827                                     0, 0, TRUE);
828                 PROTO_ITEM_SET_HIDDEN(hidden_item);
829         }
830
831         col_append_str(pinfo->cinfo, COL_INFO, ", Control");
832
833         if ( control_tree )
834         {
835                 proto_tree_add_item(control_tree, hf_tns_control_cmd, tvb,
836                         offset, 2, FALSE);
837         }
838         offset += 2;
839
840         if ( control_tree )
841         {
842                 proto_tree_add_item(control_tree, hf_tns_control_data, tvb,
843                         offset, -1, FALSE);
844         }
845         return;
846 }
847
848 static guint
849 get_tns_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
850 {
851         /*
852          * Get the length of the TNS message, including header
853          */
854         return tvb_get_ntohs(tvb, offset);
855 }
856
857 static int
858 dissect_tns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
859 {
860         guint8 type;
861
862         /*
863          * First, do a sanity check to make sure what we have
864          * starts with a TNS PDU.
865          */
866         if (tvb_bytes_exist(tvb, 4, 1)) {
867                 /*
868                  * Well, we have the packet type; let's make sure
869                  * it's a known type.
870                  */
871                 type = tvb_get_guint8(tvb, 4);
872                 if (type < TNS_TYPE_CONNECT || type > TNS_TYPE_MAX)
873                         return 0;       /* it's not a known type */
874         }
875
876         tcp_dissect_pdus(tvb, pinfo, tree, tns_desegment, 2,
877             get_tns_pdu_len, dissect_tns_pdu);
878         return tvb_length(tvb);
879 }
880
881 static void
882 dissect_tns_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
883 {
884         proto_tree      *tns_tree = NULL, *ti;
885         proto_item *hidden_item;
886         int offset = 0;
887         guint16 length;
888         guint16 type;
889
890         col_set_str(pinfo->cinfo, COL_PROTOCOL, "TNS");
891
892         if (check_col(pinfo->cinfo, COL_INFO))
893         {
894                 col_set_str(pinfo->cinfo, COL_INFO,
895                         (pinfo->match_port == pinfo->destport) ? "Request" : "Response");
896         }
897
898         if (tree)
899         {
900                 ti = proto_tree_add_item(tree, proto_tns, tvb, 0, -1, FALSE);
901                 tns_tree = proto_item_add_subtree(ti, ett_tns);
902
903                 if (pinfo->match_port == pinfo->destport)
904                 {
905                         hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_request,
906                                            tvb, offset, 0, TRUE);
907                 }
908                 else
909                 {
910                         hidden_item = proto_tree_add_boolean(tns_tree, hf_tns_response,
911                                             tvb, offset, 0, TRUE);
912                 }
913                 PROTO_ITEM_SET_HIDDEN(hidden_item);
914         }
915
916         length = tvb_get_ntohs(tvb, offset);
917         if (tree)
918         {
919                 proto_tree_add_uint(tns_tree, hf_tns_length, tvb,
920                         offset, 2, length);
921         }
922         offset += 2;
923
924         if ( tree )
925         {
926                 proto_tree_add_item(tns_tree, hf_tns_packet_checksum, tvb,
927                         offset, 2, FALSE);
928         }
929         offset += 2;
930
931         type = tvb_get_guint8(tvb, offset);
932         if ( tree )
933         {
934                 proto_tree_add_uint(tns_tree, hf_tns_packet_type, tvb,
935                         offset, 1, type);
936         }
937         offset += 1;
938
939         if ( check_col(pinfo->cinfo, COL_INFO))
940         {
941                 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s (%u)",
942                         val_to_str(type, tns_type_vals, "Unknown"), type);
943         }
944
945         if ( tree )
946         {
947                 proto_tree_add_item(tns_tree, hf_tns_reserved_byte, tvb,
948                         offset, 1, FALSE);
949         }
950         offset += 1;
951
952         if ( tree )
953         {
954                 proto_tree_add_item(tns_tree, hf_tns_header_checksum, tvb,
955                         offset, 2, FALSE);
956         }
957         offset += 2;
958
959         switch (type)
960         {
961                 case TNS_TYPE_CONNECT:
962                         dissect_tns_connect(tvb,offset,pinfo,tree,tns_tree);
963                         break;
964                 case TNS_TYPE_ACCEPT:
965                         dissect_tns_accept(tvb,offset,pinfo,tree,tns_tree);
966                         break;
967                 case TNS_TYPE_REFUSE:
968                         dissect_tns_refuse(tvb,offset,pinfo,tree,tns_tree);
969                         break;
970                 case TNS_TYPE_REDIRECT:
971                         dissect_tns_redirect(tvb,offset,pinfo,tree,tns_tree);
972                         break;
973                 case TNS_TYPE_ABORT:
974                         dissect_tns_abort(tvb,offset,pinfo,tree,tns_tree);
975                         break;
976                 case TNS_TYPE_MARKER:
977                         dissect_tns_marker(tvb,offset,pinfo,tree,tns_tree, 0);
978                         break;
979                 case TNS_TYPE_ATTENTION:
980                         dissect_tns_marker(tvb,offset,pinfo,tree,tns_tree, 1);
981                         break;
982                 case TNS_TYPE_CONTROL:
983                         dissect_tns_control(tvb,offset,pinfo,tree,tns_tree);
984                         break;
985                 case TNS_TYPE_DATA:
986                         dissect_tns_data(tvb,offset,pinfo,tree,tns_tree);
987                         break;
988                 default:
989                         call_dissector(data_handle,
990                             tvb_new_subset_remaining(tvb, offset), pinfo,
991                             tns_tree);
992                         break;
993         }
994 }
995
996 void proto_register_tns(void)
997 {
998         static hf_register_info hf[] = {
999                 { &hf_tns_response, {
1000                         "Response", "tns.response", FT_BOOLEAN, BASE_NONE,
1001                         NULL, 0x0, "TRUE if TNS response", HFILL }},
1002                 { &hf_tns_request, {
1003                         "Request", "tns.request", FT_BOOLEAN, BASE_NONE,
1004                         NULL, 0x0, "TRUE if TNS request", HFILL }},
1005                 { &hf_tns_length, {
1006                         "Packet Length", "tns.length", FT_UINT16, BASE_DEC,
1007                         NULL, 0x0, "Length of TNS packet", HFILL }},
1008                 { &hf_tns_packet_checksum, {
1009                         "Packet Checksum", "tns.packet_checksum", FT_UINT16, BASE_HEX,
1010                         NULL, 0x0, "Checksum of Packet Data", HFILL }},
1011                 { &hf_tns_header_checksum, {
1012                         "Header Checksum", "tns.header_checksum", FT_UINT16, BASE_HEX,
1013                         NULL, 0x0, "Checksum of Header Data", HFILL }},
1014
1015                 { &hf_tns_version, {
1016                         "Version", "tns.version", FT_UINT16, BASE_DEC,
1017                         NULL, 0x0, NULL, HFILL }},
1018                 { &hf_tns_compat_version, {
1019                         "Version (Compatible)", "tns.compat_version", FT_UINT16, BASE_DEC,
1020                         NULL, 0x0, NULL, HFILL }},
1021
1022                 { &hf_tns_service_options, {
1023                         "Service Options", "tns.service_options", FT_UINT16, BASE_HEX,
1024                         NULL, 0x0, NULL, HFILL }},
1025
1026                 { &hf_tns_sopt_flag_bconn, {
1027                         "Broken Connect Notify", "tns.so_flag.bconn", FT_BOOLEAN, 16,
1028                         NULL, 0x2000, NULL, HFILL }},
1029                 { &hf_tns_sopt_flag_pc, {
1030                         "Packet Checksum", "tns.so_flag.pc", FT_BOOLEAN, 16,
1031                         NULL, 0x1000, NULL, HFILL }},
1032                 { &hf_tns_sopt_flag_hc, {
1033                         "Header Checksum", "tns.so_flag.hc", FT_BOOLEAN, 16,
1034                         NULL, 0x0800, NULL, HFILL }},
1035                 { &hf_tns_sopt_flag_fd, {
1036                         "Full Duplex", "tns.so_flag.fd", FT_BOOLEAN, 16,
1037                         NULL, 0x0400, NULL, HFILL }},
1038                 { &hf_tns_sopt_flag_hd, {
1039                         "Half Duplex", "tns.so_flag.hd", FT_BOOLEAN, 16,
1040                         NULL, 0x0200, NULL, HFILL }},
1041                 { &hf_tns_sopt_flag_dc1, {
1042                         "Don't Care", "tns.so_flag.dc1", FT_BOOLEAN, 16,
1043                         NULL, 0x0100, NULL, HFILL }},
1044                 { &hf_tns_sopt_flag_dc2, {
1045                         "Don't Care", "tns.so_flag.dc2", FT_BOOLEAN, 16,
1046                         NULL, 0x0080, NULL, HFILL }},
1047                 { &hf_tns_sopt_flag_dio, {
1048                         "Direct IO to Transport", "tns.so_flag.dio", FT_BOOLEAN, 16,
1049                         NULL, 0x0010, NULL, HFILL }},
1050                 { &hf_tns_sopt_flag_ap, {
1051                         "Attention Processing", "tns.so_flag.ap", FT_BOOLEAN, 16,
1052                         NULL, 0x0008, NULL, HFILL }},
1053                 { &hf_tns_sopt_flag_ra, {
1054                         "Can Receive Attention", "tns.so_flag.ra", FT_BOOLEAN, 16,
1055                         NULL, 0x0004, NULL, HFILL }},
1056                 { &hf_tns_sopt_flag_sa, {
1057                         "Can Send Attention", "tns.so_flag.sa", FT_BOOLEAN, 16,
1058                         NULL, 0x0002, NULL, HFILL }},
1059
1060
1061                 { &hf_tns_sdu_size, {
1062                         "Session Data Unit Size", "tns.sdu_size", FT_UINT16, BASE_DEC,
1063                         NULL, 0x0, NULL, HFILL }},
1064                 { &hf_tns_max_tdu_size, {
1065                         "Maximum Transmission Data Unit Size", "tns.max_tdu_size", FT_UINT16, BASE_DEC,
1066                         NULL, 0x0, NULL, HFILL }},
1067
1068                 { &hf_tns_nt_proto_characteristics, {
1069                         "NT Protocol Characteristics", "tns.nt_proto_characteristics", FT_UINT16, BASE_HEX,
1070                         NULL, 0x0, NULL, HFILL }},
1071                 { &hf_tns_ntp_flag_hangon, {
1072                         "Hangon to listener connect", "tns.ntp_flag.hangon", FT_BOOLEAN, 16,
1073                         NULL, 0x8000, NULL, HFILL }},
1074                 { &hf_tns_ntp_flag_crel, {
1075                         "Confirmed release", "tns.ntp_flag.crel", FT_BOOLEAN, 16,
1076                         NULL, 0x4000, NULL, HFILL }},
1077                 { &hf_tns_ntp_flag_tduio, {
1078                         "TDU based IO", "tns.ntp_flag.tduio", FT_BOOLEAN, 16,
1079                         NULL, 0x2000, NULL, HFILL }},
1080                 { &hf_tns_ntp_flag_srun, {
1081                         "Spawner running", "tns.ntp_flag.srun", FT_BOOLEAN, 16,
1082                         NULL, 0x1000, NULL, HFILL }},
1083                 { &hf_tns_ntp_flag_dtest, {
1084                         "Data test", "tns.ntp_flag.dtest", FT_BOOLEAN, 16,
1085                         NULL, 0x0800, "Data Test", HFILL }},
1086                 { &hf_tns_ntp_flag_cbio, {
1087                         "Callback IO supported", "tns.ntp_flag.cbio", FT_BOOLEAN, 16,
1088                         NULL, 0x0400, NULL, HFILL }},
1089                 { &hf_tns_ntp_flag_asio, {
1090                         "ASync IO Supported", "tns.ntp_flag.asio", FT_BOOLEAN, 16,
1091                         NULL, 0x0200, NULL, HFILL }},
1092                 { &hf_tns_ntp_flag_pio, {
1093                         "Packet oriented IO", "tns.ntp_flag.pio", FT_BOOLEAN, 16,
1094                         NULL, 0x0100, NULL, HFILL }},
1095                 { &hf_tns_ntp_flag_grant, {
1096                         "Can grant connection to another", "tns.ntp_flag.grant", FT_BOOLEAN, 16,
1097                         NULL, 0x0080, NULL, HFILL }},
1098                 { &hf_tns_ntp_flag_handoff, {
1099                         "Can handoff connection to another", "tns.ntp_flag.handoff", FT_BOOLEAN, 16,
1100                         NULL, 0x0040, NULL, HFILL }},
1101                 { &hf_tns_ntp_flag_sigio, {
1102                         "Generate SIGIO signal", "tns.ntp_flag.sigio", FT_BOOLEAN, 16,
1103                         NULL, 0x0020, NULL, HFILL }},
1104                 { &hf_tns_ntp_flag_sigpipe, {
1105                         "Generate SIGPIPE signal", "tns.ntp_flag.sigpipe", FT_BOOLEAN, 16,
1106                         NULL, 0x0010, NULL, HFILL }},
1107                 { &hf_tns_ntp_flag_sigurg, {
1108                         "Generate SIGURG signal", "tns.ntp_flag.sigurg", FT_BOOLEAN, 16,
1109                         NULL, 0x0008, NULL, HFILL }},
1110                 { &hf_tns_ntp_flag_urgentio, {
1111                         "Urgent IO supported", "tns.ntp_flag.urgentio", FT_BOOLEAN, 16,
1112                         NULL, 0x0004, NULL, HFILL }},
1113                 { &hf_tns_ntp_flag_fdio, {
1114                         "Full duplex IO supported", "tns.ntp_flag.dfio", FT_BOOLEAN, 16,
1115                         NULL, 0x0002, NULL, HFILL }},
1116                 { &hf_tns_ntp_flag_testop, {
1117                         "Test operation", "tns.ntp_flag.testop", FT_BOOLEAN, 16,
1118                         NULL, 0x0001, NULL, HFILL }},
1119
1120
1121
1122
1123                 { &hf_tns_line_turnaround, {
1124                         "Line Turnaround Value", "tns.line_turnaround", FT_UINT16, BASE_DEC,
1125                         NULL, 0x0, NULL, HFILL }},
1126                 { &hf_tns_value_of_one, {
1127                         "Value of 1 in Hardware", "tns.value_of_one", FT_BYTES, BASE_NONE,
1128                         NULL, 0x0, NULL, HFILL }},
1129
1130                 { &hf_tns_connect, {
1131                         "Connect", "tns.connect", FT_BOOLEAN, BASE_NONE,
1132                         NULL, 0x0, NULL, HFILL }},
1133                 { &hf_tns_connect_data_length, {
1134                         "Length of Connect Data", "tns.connect_data_length", FT_UINT16, BASE_DEC,
1135                         NULL, 0x0, NULL, HFILL }},
1136                 { &hf_tns_connect_data_offset, {
1137                         "Offset to Connect Data", "tns.connect_data_offset", FT_UINT16, BASE_DEC,
1138                         NULL, 0x0, NULL, HFILL }},
1139                 { &hf_tns_connect_data_max, {
1140                         "Maximum Receivable Connect Data", "tns.connect_data_max", FT_UINT32, BASE_DEC,
1141                         NULL, 0x0, NULL, HFILL }},
1142
1143                 { &hf_tns_connect_flags0, {
1144                         "Connect Flags 0", "tns.connect_flags0", FT_UINT8, BASE_HEX,
1145                         NULL, 0x0, NULL, HFILL }},
1146                 { &hf_tns_connect_flags1, {
1147                         "Connect Flags 1", "tns.connect_flags1", FT_UINT8, BASE_HEX,
1148                         NULL, 0x0, NULL, HFILL }},
1149
1150                 { &hf_tns_conn_flag_nareq, {
1151                         "NA services required", "tns.connect_flags.nareq", FT_BOOLEAN, 8,
1152                         NULL, 0x10, NULL, HFILL }},
1153                 { &hf_tns_conn_flag_nalink, {
1154                         "NA services linked in", "tns.connect_flags.nalink", FT_BOOLEAN, 8,
1155                         NULL, 0x08, NULL, HFILL }},
1156                 { &hf_tns_conn_flag_enablena, {
1157                         "NA services enabled", "tns.connect_flags.enablena", FT_BOOLEAN, 8,
1158                         NULL, 0x04, NULL, HFILL }},
1159                 { &hf_tns_conn_flag_ichg, {
1160                         "Interchange is involved", "tns.connect_flags.ichg", FT_BOOLEAN, 8,
1161                         NULL, 0x02, NULL, HFILL }},
1162                 { &hf_tns_conn_flag_wantna, {
1163                         "NA services wanted", "tns.connect_flags.wantna", FT_BOOLEAN, 8,
1164                         NULL, 0x01, NULL, HFILL }},
1165
1166
1167                 { &hf_tns_trace_cf1, {
1168                         "Trace Cross Facility Item 1", "tns.trace_cf1", FT_UINT32, BASE_HEX,
1169                         NULL, 0x0, NULL, HFILL }},
1170                 { &hf_tns_trace_cf2, {
1171                         "Trace Cross Facility Item 2", "tns.trace_cf2", FT_UINT32, BASE_HEX,
1172                         NULL, 0x0, NULL, HFILL }},
1173                 { &hf_tns_trace_cid, {
1174                         "Trace Unique Connection ID", "tns.trace_cid", FT_UINT64, BASE_HEX,
1175                         NULL, 0x0, NULL, HFILL }},
1176                 { &hf_tns_connect_data, {
1177                         "Connect Data", "tns.connect_data", FT_STRING, BASE_NONE,
1178                         NULL, 0x0, NULL, HFILL }},
1179
1180                 { &hf_tns_accept, {
1181                         "Accept", "tns.accept", FT_BOOLEAN, BASE_NONE,
1182                         NULL, 0x0, NULL, HFILL }},
1183                 { &hf_tns_accept_data_length, {
1184                         "Accept Data Length", "tns.accept_data_length", FT_UINT16, BASE_DEC,
1185                         NULL, 0x0, "Length of Accept Data", HFILL }},
1186                 { &hf_tns_accept_data, {
1187                         "Accept Data", "tns.accept_data", FT_STRING, BASE_NONE,
1188                         NULL, 0x0, NULL, HFILL }},
1189                 { &hf_tns_accept_data_offset, {
1190                         "Offset to Accept Data", "tns.accept_data_offset", FT_UINT16, BASE_DEC,
1191                         NULL, 0x0, NULL, HFILL }},
1192
1193
1194                 { &hf_tns_refuse, {
1195                         "Refuse", "tns.refuse", FT_BOOLEAN, BASE_NONE,
1196                         NULL, 0x0, NULL, HFILL }},
1197                 { &hf_tns_refuse_reason_user, {
1198                         "Refuse Reason (User)", "tns.refuse_reason_user", FT_UINT8, BASE_HEX,
1199                         NULL, 0x0, "Refuse Reason from Application", HFILL }},
1200                 { &hf_tns_refuse_reason_system, {
1201                         "Refuse Reason (System)", "tns.refuse_reason_system", FT_UINT8, BASE_HEX,
1202                         NULL, 0x0, "Refuse Reason from System", HFILL }},
1203                 { &hf_tns_refuse_data_length, {
1204                         "Refuse Data Length", "tns.refuse_data_length", FT_UINT16, BASE_DEC,
1205                         NULL, 0x0, "Length of Refuse Data", HFILL }},
1206                 { &hf_tns_refuse_data, {
1207                         "Refuse Data", "tns.refuse_data", FT_STRING, BASE_NONE,
1208                         NULL, 0x0, NULL, HFILL }},
1209
1210                 { &hf_tns_abort, {
1211                         "Abort", "tns.abort", FT_BOOLEAN, BASE_NONE,
1212                         NULL, 0x0, NULL, HFILL }},
1213                 { &hf_tns_abort_reason_user, {
1214                         "Abort Reason (User)", "tns.abort_reason_user", FT_UINT8, BASE_HEX,
1215                         NULL, 0x0, "Abort Reason from Application", HFILL }},
1216                 { &hf_tns_abort_reason_system, {
1217                         "Abort Reason (User)", "tns.abort_reason_system", FT_UINT8, BASE_HEX,
1218                         NULL, 0x0, "Abort Reason from System", HFILL }},
1219                 { &hf_tns_abort_data, {
1220                         "Abort Data", "tns.abort_data", FT_STRING, BASE_NONE,
1221                         NULL, 0x0, NULL, HFILL }},
1222
1223                 { &hf_tns_marker, {
1224                         "Marker", "tns.marker", FT_BOOLEAN, BASE_NONE,
1225                         NULL, 0x0, NULL, HFILL }},
1226                 { &hf_tns_marker_type, {
1227                         "Marker Type", "tns.marker.type", FT_UINT8, BASE_HEX,
1228                         VALS(tns_marker_types), 0x0, NULL, HFILL }},
1229                 { &hf_tns_marker_data_byte, {
1230                         "Marker Data Byte", "tns.marker.databyte", FT_UINT8, BASE_HEX,
1231                         NULL, 0x0, NULL, HFILL }},
1232                 { &hf_tns_marker_data, {
1233                         "Marker Data", "tns.marker.data", FT_UINT16, BASE_HEX,
1234                         NULL, 0x0, NULL, HFILL }},
1235
1236                 { &hf_tns_control, {
1237                         "Control", "tns.control", FT_BOOLEAN, BASE_NONE,
1238                         NULL, 0x0, NULL, HFILL }},
1239                 { &hf_tns_control_cmd, {
1240                         "Control Command", "tns.control.cmd", FT_UINT16, BASE_HEX,
1241                         VALS(tns_control_cmds), 0x0, NULL, HFILL }},
1242                 { &hf_tns_control_data, {
1243                         "Control Data", "tns.control.data", FT_BYTES, BASE_NONE,
1244                         NULL, 0x0, NULL, HFILL }},
1245
1246                 { &hf_tns_redirect, {
1247                         "Redirect", "tns.redirect", FT_BOOLEAN, BASE_NONE,
1248                         NULL, 0x0, NULL, HFILL }},
1249                 { &hf_tns_redirect_data_length, {
1250                         "Redirect Data Length", "tns.redirect_data_length", FT_UINT16, BASE_DEC,
1251                         NULL, 0x0, "Length of Redirect Data", HFILL }},
1252                 { &hf_tns_redirect_data, {
1253                         "Redirect Data", "tns.redirect_data", FT_STRING, BASE_NONE,
1254                         NULL, 0x0, NULL, HFILL }},
1255
1256                 { &hf_tns_data, {
1257                         "Data", "tns.data", FT_BOOLEAN, BASE_NONE,
1258                         NULL, 0x0, NULL, HFILL }},
1259
1260                 { &hf_tns_data_flag, {
1261                         "Data Flag", "tns.data_flag", FT_UINT16, BASE_HEX,
1262                         NULL, 0x0, NULL, HFILL }},
1263                 { &hf_tns_data_flag_send, {
1264                         "Send Token", "tns.data_flag.send", FT_BOOLEAN, 16,
1265                         NULL, 0x1, NULL, HFILL }},
1266                 { &hf_tns_data_flag_rc, {
1267                         "Request Confirmation", "tns.data_flag.rc", FT_BOOLEAN, 16,
1268                         NULL, 0x2, NULL, HFILL }},
1269                 { &hf_tns_data_flag_c, {
1270                         "Confirmation", "tns.data_flag.c", FT_BOOLEAN, 16,
1271                         NULL, 0x4, NULL, HFILL }},
1272                 { &hf_tns_data_flag_reserved, {
1273                         "Reserved", "tns.data_flag.reserved", FT_BOOLEAN, 16,
1274                         NULL, 0x8, NULL, HFILL }},
1275                 { &hf_tns_data_flag_more, {
1276                         "More Data to Come", "tns.data_flag.more", FT_BOOLEAN, 16,
1277                         NULL, 0x20, NULL, HFILL }},
1278                 { &hf_tns_data_flag_eof, {
1279                         "End of File", "tns.data_flag.eof", FT_BOOLEAN, 16,
1280                         NULL, 0x40, NULL, HFILL }},
1281                 { &hf_tns_data_flag_dic, {
1282                         "Do Immediate Confirmation", "tns.data_flag.dic", FT_BOOLEAN, 16,
1283                         NULL, 0x80, NULL, HFILL }},
1284                 { &hf_tns_data_flag_rts, {
1285                         "Request To Send", "tns.data_flag.rts", FT_BOOLEAN, 16,
1286                         NULL, 0x100, NULL, HFILL }},
1287                 { &hf_tns_data_flag_sntt, {
1288                         "Send NT Trailer", "tns.data_flag.sntt", FT_BOOLEAN, 16,
1289                         NULL, 0x200, NULL, HFILL }},
1290
1291
1292                 { &hf_tns_reserved_byte, {
1293                         "Reserved Byte", "tns.reserved_byte", FT_BYTES, BASE_NONE,
1294                         NULL, 0x0, NULL, HFILL }},
1295                 { &hf_tns_packet_type, {
1296                         "Packet Type", "tns.type", FT_UINT8, BASE_DEC,
1297                         VALS(tns_type_vals), 0x0, "Type of TNS packet", HFILL }}
1298
1299         };
1300
1301         static gint *ett[] = {
1302                 &ett_tns,
1303                 &ett_tns_connect,
1304                 &ett_tns_accept,
1305                 &ett_tns_refuse,
1306                 &ett_tns_abort,
1307                 &ett_tns_redirect,
1308                 &ett_tns_marker,
1309                 &ett_tns_attention,
1310                 &ett_tns_control,
1311                 &ett_tns_data,
1312                 &ett_tns_data_flag,
1313                 &ett_tns_sopt_flag,
1314                 &ett_tns_ntp_flag,
1315                 &ett_tns_conn_flag,
1316                 &ett_sql
1317         };
1318         module_t *tns_module;
1319
1320         proto_tns = proto_register_protocol(
1321                 "Transparent Network Substrate Protocol", "TNS", "tns");
1322         proto_register_field_array(proto_tns, hf, array_length(hf));
1323         proto_register_subtree_array(ett, array_length(ett));
1324
1325         tns_module = prefs_register_protocol(proto_tns, NULL);
1326         prefs_register_bool_preference(tns_module, "desegment_tns_messages",
1327           "Reassemble TNS messages spanning multiple TCP segments",
1328           "Whether the TNS dissector should reassemble messages spanning multiple TCP segments. "
1329           "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1330           &tns_desegment);
1331 }
1332
1333 void
1334 proto_reg_handoff_tns(void)
1335 {
1336         dissector_handle_t tns_handle;
1337
1338         tns_handle = new_create_dissector_handle(dissect_tns, proto_tns);
1339         dissector_add("tcp.port", TCP_PORT_TNS, tns_handle);
1340         data_handle = find_dissector("data");
1341 }