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