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