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