From Ronnie Sahlberg:
[obnox/wireshark/wip.git] / packet-tns.c
index e0bd7da91f394dd085ea14ae3aac064116230e6c..d0af57b63c886875205a7f52d5b5a803668e0d1b 100644 (file)
@@ -1,10 +1,10 @@
 /* packet-tns.c
- * Routines for MSX tns packet dissection
+ * Routines for Oracle TNS packet dissection
  *
- * $Id: packet-tns.c,v 1.12 2001/01/09 06:31:44 guy Exp $
+ * $Id: packet-tns.c,v 1.28 2002/01/24 09:20:52 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-tftp.c
@@ -40,7 +40,7 @@
 
 #include <string.h>
 #include <glib.h>
-#include "packet.h"
+#include <epan/packet.h>
 #include "packet-tns.h"
 
 static int proto_tns = -1;
@@ -51,295 +51,972 @@ static int hf_tns_packet_checksum = -1;
 static int hf_tns_header_checksum = -1;
 static int hf_tns_packet_type = -1;
 static int hf_tns_reserved_byte = -1;
-static int hf_tns_data_flag = -1;
-static int hf_tns_sns = -1;
 static int hf_tns_connect = -1;
 static int hf_tns_version = -1;
 static int hf_tns_compat_version = -1;
 static int hf_tns_service_options = -1;
+static int hf_tns_sdu_size = -1;
+static int hf_tns_max_tdu_size = -1;
+static int hf_tns_nt_proto_characteristics = -1;
+static int hf_tns_line_turnaround = -1;
+static int hf_tns_value_of_one = -1;
+static int hf_tns_connect_data_length = -1;
+static int hf_tns_connect_data_offset = -1;
+static int hf_tns_connect_data_max = -1;
+static int hf_tns_connect_flags0 = -1;
+static int hf_tns_connect_flags1 = -1;
+static int hf_tns_connect_data = -1;
+static int hf_tns_trace_cf1 = -1;
+static int hf_tns_trace_cf2 = -1;
+static int hf_tns_trace_cid = -1;
+
+static int hf_tns_accept = -1;
+static int hf_tns_accept_data_length = -1;
+static int hf_tns_accept_data_offset = -1;
+static int hf_tns_accept_data = -1;
+
+static int hf_tns_refuse = -1;
+static int hf_tns_refuse_reason_user = -1;
+static int hf_tns_refuse_reason_system = -1;
+static int hf_tns_refuse_data_length = -1;
+static int hf_tns_refuse_data = -1;
+
+static int hf_tns_abort = -1;
+static int hf_tns_abort_reason_user = -1;
+static int hf_tns_abort_reason_system = -1;
+static int hf_tns_abort_data = -1;
+
+static int hf_tns_marker = -1;
+static int hf_tns_marker_type = -1;
+static int hf_tns_marker_data_byte = -1;
+static int hf_tns_marker_data = -1;
+
+static int hf_tns_redirect = -1;
+static int hf_tns_redirect_data_length = -1;
+static int hf_tns_redirect_data = -1;
+
+static int hf_tns_control = -1;
+static int hf_tns_control_cmd = -1;
+static int hf_tns_control_data = -1;
+
+static int hf_tns_data_flag = -1;
+static int hf_tns_data_flag_send = -1;
+static int hf_tns_data_flag_rc = -1;
+static int hf_tns_data_flag_c = -1;
+static int hf_tns_data_flag_reserved = -1;
+static int hf_tns_data_flag_more = -1;
+static int hf_tns_data_flag_eof = -1;
+static int hf_tns_data_flag_dic = -1;
+static int hf_tns_data_flag_rts = -1;
+static int hf_tns_data_flag_sntt = -1;
+static int hf_tns_data = -1;
 
 static gint ett_tns = -1;
-static gint ett_tns_sns = -1;
 static gint ett_tns_connect = -1;
+static gint ett_tns_accept = -1;
+static gint ett_tns_refuse = -1;
+static gint ett_tns_abort = -1;
+static gint ett_tns_redirect = -1;
+static gint ett_tns_marker = -1;
+static gint ett_tns_attention = -1;
+static gint ett_tns_control = -1;
+static gint ett_tns_data = -1;
+static gint ett_tns_data_flag = -1;
 static gint ett_sql = -1;
 
+static dissector_handle_t data_handle;
+
 #define TCP_PORT_TNS                   1521
 
 static const value_string tns_type_vals[] = {
-               {TNS_TYPE_CONNECT, "Connect" },
-               {TNS_TYPE_ACCEPT, "Accept" },
-               {TNS_TYPE_DATA, "Data" },
-               {TNS_TYPE_RESEND, "Resend"},
-               {0, NULL}
+       {TNS_TYPE_CONNECT,   "Connect" },
+       {TNS_TYPE_ACCEPT,    "Accept" },
+       {TNS_TYPE_ACK,       "Acknowledge" },
+       {TNS_TYPE_REFUSE,    "Refuse" },
+       {TNS_TYPE_REDIRECT,  "Redirect" },
+       {TNS_TYPE_DATA,      "Data" },
+       {TNS_TYPE_NULL,      "Null" },
+       {TNS_TYPE_ABORT,     "Abort" },
+       {TNS_TYPE_RESEND,    "Resend"},
+       {TNS_TYPE_MARKER,    "Marker"},
+       {TNS_TYPE_ATTENTION, "Attention"},
+       {TNS_TYPE_CONTROL,   "Control"},
+       {0, NULL}
 };
 
+static const value_string tns_marker_types[] = {
+       {0, "Data Marker - 0 Data Bytes"},
+       {1, "Data Marker - 1 Data Bytes"},
+       {2, "Attention Marker"},
+       {0, NULL}
+};
 
-/* Handy macro for checking for truncated packet */
-#define TRUNC(length) if ( ! BYTES_ARE_IN_FRAME(offset, length)) { \
-                       old_dissect_data(pd,offset,fd,tree); return; }
+static const value_string tns_control_cmds[] = {
+       {1, "Oracle Trace Command"},
+       {0, NULL}
+};
 
-static void dissect_tns_sns(const u_char *pd, int offset, frame_data *fd, 
+static void dissect_tns_data(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree *tree, proto_tree *tns_tree)
 {
-       proto_tree *sns_tree = NULL, *ti;
-
-       if ( tree )
-       {
-               ti = proto_tree_add_text(tns_tree, NullTVB, offset, END_OF_FRAME, "Secure Network Services");
-               sns_tree = proto_item_add_subtree(ti, ett_tns_sns);
-
-               proto_tree_add_boolean_hidden(tns_tree, hf_tns_sns, NullTVB, 0, 0, TRUE);
-       }
-               
-       if ( check_col(fd, COL_INFO) )
+       proto_tree *data_tree = NULL, *ti;
+       int is_sns = 0;
+       
+       if ( tvb_bytes_exist(tvb, offset+2, 4) )
        {
-               col_append_fstr(fd, COL_INFO, ", SNS");
+               if ( tvb_get_guint8(tvb, offset+2) == 0xDE &&
+                    tvb_get_guint8(tvb, offset+3) == 0xAD &&
+                    tvb_get_guint8(tvb, offset+4) == 0xBE &&
+                    tvb_get_guint8(tvb, offset+5) == 0xEF )
+               {
+                       is_sns = 1;
+               }
        }
 
-       if ( sns_tree )
+       if ( tree )
        {
-               old_dissect_data(pd,offset,fd,sns_tree);
-       }
-}
+               if ( is_sns )
+               {
+                       ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                           "Secure Network Services");
+               }
+               else
+               {
+                       ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                           "Data");            
+               }
+               data_tree = proto_item_add_subtree(ti, ett_tns_data);
 
-static void dissect_tns_data(const u_char *pd, int offset, frame_data *fd, 
-       proto_tree *tree, proto_tree *tns_tree)
-{
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_data, tvb, 0, 0,
+                               TRUE);
+       }
 
-       TRUNC(2);
        if ( tree )
        {
-               proto_tree_add_uint(tns_tree, hf_tns_data_flag, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree *df_tree = NULL;
+               
+               ti = proto_tree_add_item(data_tree, hf_tns_data_flag, tvb, offset, 2, FALSE);
+               
+               df_tree = proto_item_add_subtree(ti, ett_tns_data_flag);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_send, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_rc, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_c, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_reserved, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_more, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_eof, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_dic, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_rts, tvb, offset, 2, FALSE);
+               proto_tree_add_item(df_tree, hf_tns_data_flag_sntt, tvb, offset, 2, FALSE);
        }
        offset += 2;
 
-       if ( BYTES_ARE_IN_FRAME(offset, 4) )
+       if ( check_col(pinfo->cinfo, COL_INFO) )
        {
-               if ( pd[offset] == 0xDE && pd[offset+1] == 0xAD &&
-                       pd[offset+2] == 0xBE && pd[offset+3] == 0xEF )
+               if ( is_sns )
                {
-                       dissect_tns_sns(pd,offset,fd,tree,tns_tree);
-                       return;
+                       col_append_fstr(pinfo->cinfo, COL_INFO, ", SNS");
                }
+               else
+               {
+                       col_append_fstr(pinfo->cinfo, COL_INFO, ", Data");
+               }       
        }
        
-       old_dissect_data(pd,offset,fd,tree);
+       if ( data_tree )
+       {
+               call_dissector(data_handle,tvb_new_subset(tvb,offset,-1,tvb_reported_length_remaining(tvb,offset)),pinfo,data_tree);
+       }
+
        return;
 }
 
-static void dissect_tns_connect(const u_char *pd, int offset, frame_data *fd, 
+static void dissect_tns_connect(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree *tree, proto_tree *tns_tree)
 {
        proto_tree *connect_tree = NULL, *ti;
+       int cd_offset;
+       int cd_len;
+       int tns_offset = offset-8;
 
        if ( tree )
        {
-               ti = proto_tree_add_text(tns_tree, NullTVB, offset, END_OF_FRAME, "Connect");
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Connect");
                connect_tree = proto_item_add_subtree(ti, ett_tns_connect);
 
-               proto_tree_add_boolean_hidden(tns_tree, hf_tns_connect, NullTVB, 0, 0, TRUE);
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_connect, tvb,
+                   0, 0, TRUE);
        }
                
-       if ( check_col(fd, COL_INFO) )
+       if ( check_col(pinfo->cinfo, COL_INFO) )
        {
-               col_append_fstr(fd, COL_INFO, ", Connect");
+               col_append_str(pinfo->cinfo, COL_INFO, ", Connect");
        }
 
-       TRUNC(2);
        if ( connect_tree )
        {
-               proto_tree_add_uint(connect_tree, hf_tns_version, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree_add_item(connect_tree, hf_tns_version, tvb,
+                       offset, 2, FALSE);
        }
        offset += 2;
        
-       TRUNC(2);
        if ( connect_tree )
        {
-               proto_tree_add_uint(connect_tree, hf_tns_compat_version, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree_add_item(connect_tree, hf_tns_compat_version, tvb,
+                       offset, 2, FALSE);
        }
        offset += 2;
 
-       TRUNC(2);
        if ( connect_tree )
        {
                /* need to break down w/ bitfield */
-               proto_tree_add_uint(connect_tree, hf_tns_service_options, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree_add_item(connect_tree, hf_tns_service_options, tvb,
+                       offset, 2, FALSE);
        }
        offset += 2;
 
        if ( connect_tree )
        {
-               old_dissect_data(pd,offset,fd,connect_tree);
+               proto_tree_add_item(connect_tree, hf_tns_sdu_size, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_max_tdu_size, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_nt_proto_characteristics, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_line_turnaround, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_value_of_one, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       cd_len = tvb_get_ntohs(tvb, offset);
+       if ( connect_tree )
+       {
+               proto_tree_add_uint(connect_tree, hf_tns_connect_data_length, tvb,
+                       offset, 2, cd_len);
+       }
+       offset += 2;
+
+       cd_offset = tvb_get_ntohs(tvb, offset);
+       if ( connect_tree )
+       {
+               proto_tree_add_uint(connect_tree, hf_tns_connect_data_offset, tvb,
+                       offset, 2, cd_offset);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_connect_data_max, tvb,
+                       offset, 4, FALSE);
+       }
+       offset += 4;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_connect_flags0, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_connect_flags1, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_trace_cf1, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_trace_cf2, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree )
+       {
+               proto_tree_add_item(connect_tree, hf_tns_trace_cid, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( connect_tree && cd_len > 0)
+       {
+               proto_tree_add_item(connect_tree, hf_tns_connect_data, tvb,
+                       tns_offset+cd_offset,
+                       tvb_length_remaining(tvb, tns_offset+cd_offset), FALSE);
        }
        return;
 }
 
-static void dissect_tns_accept(const u_char *pd, int offset, frame_data *fd, 
+static void dissect_tns_accept(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree *tree, proto_tree *tns_tree)
 {
-       old_dissect_data(pd,offset,fd,tns_tree);
+       proto_tree *accept_tree = NULL, *ti;
+       int accept_offset;
+       int accept_len;
+       int tns_offset = offset-8;
+
+       if ( tree )
+       {
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Accept");
+               accept_tree = proto_item_add_subtree(ti, ett_tns_accept);
+
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_accept, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               col_append_str(pinfo->cinfo, COL_INFO, ", Accept");
+       }
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_version, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+       
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_service_options, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_sdu_size, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_max_tdu_size, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_value_of_one, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       accept_len = tvb_get_ntohs(tvb, offset);
+       if ( accept_tree )
+       {
+               proto_tree_add_uint(accept_tree, hf_tns_accept_data_length, tvb,
+                       offset, 2, accept_len);
+       }
+       offset += 2;
+
+       accept_offset = tvb_get_ntohs(tvb, offset);
+       if ( accept_tree )
+       {
+               proto_tree_add_uint(accept_tree, hf_tns_accept_data_offset, tvb,
+                       offset, 2, accept_offset);
+       }
+       offset += 2;
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_connect_flags0, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( accept_tree )
+       {
+               proto_tree_add_item(accept_tree, hf_tns_connect_flags1, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( accept_tree && accept_len > 0)
+       {
+               proto_tree_add_item(accept_tree, hf_tns_accept_data, tvb,
+                       tns_offset+accept_offset,
+                       tvb_length_remaining(tvb, tns_offset+accept_offset), FALSE);
+       }
        return;
 }
 
 
+static void dissect_tns_refuse(tvbuff_t *tvb, int offset, packet_info *pinfo,
+       proto_tree *tree, proto_tree *tns_tree)
+{
+       proto_tree *refuse_tree = NULL, *ti;
+
+       if ( tree )
+       {
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Refuse");
+               refuse_tree = proto_item_add_subtree(ti, ett_tns_refuse);
+
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_refuse, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               col_append_str(pinfo->cinfo, COL_INFO, ", Refuse");
+       }
+
+       if ( refuse_tree )
+       {
+               proto_tree_add_item(refuse_tree, hf_tns_refuse_reason_user, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( refuse_tree )
+       {
+               proto_tree_add_item(refuse_tree, hf_tns_refuse_reason_system, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( refuse_tree )
+       {
+               proto_tree_add_item(refuse_tree, hf_tns_refuse_data_length, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( refuse_tree )
+       {
+               proto_tree_add_item(refuse_tree, hf_tns_refuse_data, tvb,
+                       offset, tvb_length_remaining(tvb, offset), FALSE);
+       }
+       return;
+}
+
+
+static void dissect_tns_abort(tvbuff_t *tvb, int offset, packet_info *pinfo,
+       proto_tree *tree, proto_tree *tns_tree)
+{
+       proto_tree *abort_tree = NULL, *ti;
+
+       if ( tree )
+       {
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Abort");
+               abort_tree = proto_item_add_subtree(ti, ett_tns_abort);
+
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_abort, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               col_append_str(pinfo->cinfo, COL_INFO, ", Abort");
+       }
+
+       if ( abort_tree )
+       {
+               proto_tree_add_item(abort_tree, hf_tns_abort_reason_user, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( abort_tree )
+       {
+               proto_tree_add_item(abort_tree, hf_tns_abort_reason_system, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( abort_tree )
+       {
+               proto_tree_add_item(abort_tree, hf_tns_abort_data, tvb,
+                       offset, tvb_length_remaining(tvb,offset), FALSE);
+       }
+       return;
+}
+
+
+static void dissect_tns_marker(tvbuff_t *tvb, int offset, packet_info *pinfo,
+       proto_tree *tree, proto_tree *tns_tree, int is_attention)
+{
+       proto_tree *marker_tree = NULL, *ti;
+
+       if ( tree )
+       {
+               if ( is_attention )
+               {
+                       ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                           "Marker");
+               }
+               else
+               {
+                       ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                           "Attention");
+               }
+
+               marker_tree = proto_item_add_subtree(ti, ett_tns_marker);
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_marker, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               if ( is_attention )
+               {
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Marker");
+               }
+               else
+               {
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Attention");
+               }
+       }
+
+       if ( marker_tree )
+       {
+               proto_tree_add_item(marker_tree, hf_tns_marker_type, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( marker_tree )
+       {
+               proto_tree_add_item(marker_tree, hf_tns_marker_data_byte, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       if ( marker_tree )
+       {
+               proto_tree_add_item(marker_tree, hf_tns_marker_data_byte, tvb,
+                       offset, 1, FALSE);
+       }
+       offset += 1;
+
+       return;
+}
+
+static void dissect_tns_redirect(tvbuff_t *tvb, int offset, packet_info *pinfo,
+       proto_tree *tree, proto_tree *tns_tree)
+{
+       proto_tree *redirect_tree = NULL, *ti;
+
+       if ( tree )
+       {
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Redirect");
+               redirect_tree = proto_item_add_subtree(ti, ett_tns_redirect);
+
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_redirect, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               col_append_str(pinfo->cinfo, COL_INFO, ", Redirect");
+       }
+
+       if ( redirect_tree )
+       {
+               proto_tree_add_item(redirect_tree, hf_tns_redirect_data_length, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( redirect_tree )
+       {
+               proto_tree_add_item(redirect_tree, hf_tns_redirect_data, tvb,
+                       offset, tvb_length_remaining(tvb, offset), FALSE);
+       }
+       return;
+}
+
+static void dissect_tns_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
+       proto_tree *tree, proto_tree *tns_tree)
+{
+       proto_tree *control_tree = NULL, *ti;
+
+       if ( tree )
+       {
+               ti = proto_tree_add_text(tns_tree, tvb, offset, -1,
+                   "Control");
+               control_tree = proto_item_add_subtree(ti, ett_tns_control);
+
+               proto_tree_add_boolean_hidden(tns_tree, hf_tns_control, tvb,
+                   0, 0, TRUE);
+       }
+               
+       if ( check_col(pinfo->cinfo, COL_INFO) )
+       {
+               col_append_str(pinfo->cinfo, COL_INFO, ", Control");
+       }
+
+       if ( control_tree )
+       {
+               proto_tree_add_item(control_tree, hf_tns_control_cmd, tvb,
+                       offset, 2, FALSE);
+       }
+       offset += 2;
+
+       if ( control_tree )
+       {
+               proto_tree_add_item(control_tree, hf_tns_control_data, tvb,
+                       offset, tvb_length_remaining(tvb, offset), FALSE);
+       }
+       return;
+}
+
+
+
 static void
-dissect_tns(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_tns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        proto_tree      *tns_tree = NULL, *ti;
+       int offset = 0;
        guint16 length;
        guint16 type;
 
-       OLD_CHECK_DISPLAY_AS_DATA(proto_tns, pd, offset, fd, tree);
-
-       if (check_col(fd, COL_PROTOCOL))
-               col_set_str(fd, COL_PROTOCOL, "TNS");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "TNS");
 
-       if (check_col(fd, COL_INFO))
+       if (check_col(pinfo->cinfo, COL_INFO))
        {
-               col_add_fstr(fd, COL_INFO, "%s", 
-                       (pi.match_port == pi.destport) ? "Request" : "Response");         
+               col_add_str(pinfo->cinfo, COL_INFO,
+                       (pinfo->match_port == pinfo->destport) ? "Request" : "Response");         
        }
 
        if (tree) 
        {
-               ti = proto_tree_add_item(tree, proto_tns, NullTVB, offset, END_OF_FRAME, FALSE);
+               ti = proto_tree_add_item(tree, proto_tns, tvb, 0, -1, FALSE);
                tns_tree = proto_item_add_subtree(ti, ett_tns);
 
-               if (pi.match_port == pi.destport)
+               if (pinfo->match_port == pinfo->destport)
                {
-                       proto_tree_add_boolean_hidden(tns_tree, hf_tns_request, NullTVB,
-                          offset, END_OF_FRAME, TRUE);
-                       proto_tree_add_text(tns_tree, NullTVB, offset, 
-                               END_OF_FRAME, "Request: <opaque data>" );
+                       proto_tree_add_boolean_hidden(tns_tree, hf_tns_request,
+                          tvb, offset, 0, TRUE);
                }
                else
                {
-                       proto_tree_add_boolean_hidden(tns_tree, hf_tns_response, NullTVB,
-                               offset, END_OF_FRAME, TRUE);
-                       proto_tree_add_text(tns_tree, NullTVB, offset, 
-                               END_OF_FRAME, "Response: <opaque data>");
+                       proto_tree_add_boolean_hidden(tns_tree, hf_tns_response,
+                           tvb, offset, 0, TRUE);
                }
        }
 
-               /* check to make sure length is present */
-       if ( ! BYTES_ARE_IN_FRAME(offset, 2)) return;
-
-       length = pntohs(&pd[offset]);
+       length = tvb_get_ntohs(tvb, offset);
        if (tree)
        {
-               proto_tree_add_uint(tns_tree, hf_tns_length, NullTVB,
+               proto_tree_add_uint(tns_tree, hf_tns_length, tvb,
                        offset, 2, length);
        }
-       TRUNC(length);
        offset += 2;
 
-       TRUNC(2);
        if ( tree )
        {
-               proto_tree_add_uint(tns_tree, hf_tns_packet_checksum, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree_add_item(tns_tree, hf_tns_packet_checksum, tvb,
+                       offset, 2, FALSE);
        }
        offset += 2;
 
-       TRUNC(2);
-       type = pd[offset];
+       type = tvb_get_guint8(tvb, offset);
        if ( tree )
        {
-               proto_tree_add_uint(tns_tree, hf_tns_packet_type, NullTVB,
+               proto_tree_add_uint(tns_tree, hf_tns_packet_type, tvb,
                        offset, 1, type);
        }
        offset += 1;
 
-       if ( check_col(fd, COL_INFO))
+       if ( check_col(pinfo->cinfo, COL_INFO))
        {
-               col_append_fstr(fd, COL_INFO, ", %s (%d)",
+               col_append_fstr(pinfo->cinfo, COL_INFO, ", %s (%u)",
                        val_to_str(type, tns_type_vals, "Unknown"), type);
        }
 
-       TRUNC(1);
        if ( tree )
        {
-               proto_tree_add_bytes(tns_tree, hf_tns_reserved_byte, NullTVB,
-                       offset, 1, &pd[offset]);
+               proto_tree_add_item(tns_tree, hf_tns_reserved_byte, tvb,
+                       offset, 1, FALSE);
        }
        offset += 1;
 
-       TRUNC(2);
        if ( tree )
        {
-               proto_tree_add_uint(tns_tree, hf_tns_header_checksum, NullTVB,
-                       offset, 2, pntohs(&pd[offset]));
+               proto_tree_add_item(tns_tree, hf_tns_header_checksum, tvb,
+                       offset, 2, FALSE);
        }
        offset += 2;
 
        switch (type)
        {
                case TNS_TYPE_CONNECT:
-                       dissect_tns_connect(pd,offset,fd,tree,tns_tree);
+                       dissect_tns_connect(tvb,offset,pinfo,tree,tns_tree);
                        break;
                case TNS_TYPE_ACCEPT:
-                       dissect_tns_accept(pd,offset,fd,tree,tns_tree);
+                       dissect_tns_accept(tvb,offset,pinfo,tree,tns_tree);
+                       break;
+               case TNS_TYPE_REFUSE:
+                       dissect_tns_refuse(tvb,offset,pinfo,tree,tns_tree);
+                       break;
+               case TNS_TYPE_REDIRECT:
+                       dissect_tns_redirect(tvb,offset,pinfo,tree,tns_tree);
+                       break;
+               case TNS_TYPE_ABORT:
+                       dissect_tns_abort(tvb,offset,pinfo,tree,tns_tree);
+                       break;
+               case TNS_TYPE_MARKER:
+                       dissect_tns_marker(tvb,offset,pinfo,tree,tns_tree, 0);
+                       break;
+               case TNS_TYPE_ATTENTION:
+                       dissect_tns_marker(tvb,offset,pinfo,tree,tns_tree, 1);
+                       break;
+               case TNS_TYPE_CONTROL:
+                       dissect_tns_control(tvb,offset,pinfo,tree,tns_tree);
                        break;
                case TNS_TYPE_DATA:
-                       dissect_tns_data(pd,offset,fd,tree,tns_tree);
+                       dissect_tns_data(tvb,offset,pinfo,tree,tns_tree);
                        break;
                default:
-                       old_dissect_data(pd,offset,fd,tns_tree);
+                       call_dissector(data_handle,tvb_new_subset(tvb,offset,-1,tvb_reported_length_remaining(tvb,offset)),pinfo,tns_tree);
        }
 }
 
 void proto_register_tns(void)
 {
        static hf_register_info hf[] = {
-               { &hf_tns_sns, { 
-                       "Secure Network Services", "tns.sns", FT_BOOLEAN, BASE_NONE, 
-                       NULL, 0x0, "Secure Network Services" }},
-               { &hf_tns_connect, { 
-                       "Connect", "tns.connect", FT_BOOLEAN, BASE_NONE, 
-                       NULL, 0x0, "Connect" }},
                { &hf_tns_response, { 
                        "Response", "tns.response", FT_BOOLEAN, BASE_NONE, 
-                       NULL, 0x0, "TRUE if TNS response" }},
+                       NULL, 0x0, "TRUE if TNS response", HFILL }},
                { &hf_tns_request, { 
                        "Request", "tns.request", FT_BOOLEAN, BASE_NONE, 
-                       NULL, 0x0, "TRUE if TNS request" }},
+                       NULL, 0x0, "TRUE if TNS request", HFILL }},
                { &hf_tns_length, {     
-                       "Packet Length", "tns.length", FT_UINT32, BASE_NONE
-                       NULL, 0x0, "Length of TNS packet" }},
+                       "Packet Length", "tns.length", FT_UINT16, BASE_DEC
+                       NULL, 0x0, "Length of TNS packet", HFILL }},
                { &hf_tns_packet_checksum, {    
                        "Packet Checksum", "tns.packet_checksum", FT_UINT16, BASE_HEX, 
-                       NULL, 0x0, "Checksum of Packet Data" }},
+                       NULL, 0x0, "Checksum of Packet Data", HFILL }},
                { &hf_tns_header_checksum, {    
                        "Header Checksum", "tns.header_checksum", FT_UINT16, BASE_HEX, 
-                       NULL, 0x0, "Checksum of Header Data" }},
-               { &hf_tns_data_flag, {  
-                       "Data Flag", "tns.data_flag", FT_UINT16, BASE_HEX, 
-                       NULL, 0x0, "Data Flag" }},
+                       NULL, 0x0, "Checksum of Header Data", HFILL }},
+                       
                { &hf_tns_version, {    
                        "Version", "tns.version", FT_UINT16, BASE_DEC, 
-                       NULL, 0x0, "Version" }},
+                       NULL, 0x0, "Version", HFILL }},
                { &hf_tns_compat_version, {     
                        "Version (Compatible)", "tns.compat_version", FT_UINT16, BASE_DEC, 
-                       NULL, 0x0, "Version (Compatible)" }},
+                       NULL, 0x0, "Version (Compatible)", HFILL }},
                { &hf_tns_service_options, {    
                        "Service Options", "tns.service_options", FT_UINT16, BASE_HEX, 
-                       NULL, 0x0, "Service Options" }},
+                       NULL, 0x0, "Service Options", HFILL }},
+               { &hf_tns_sdu_size, {   
+                       "Session Data Unit Size", "tns.sdu_size", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Session Data Unit Size", HFILL }},
+               { &hf_tns_max_tdu_size, {       
+                       "Maximum Transmission Data Unit Size", "tns.max_tdu_size", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Maximum Transmission Data Unit Size", HFILL }},
+               { &hf_tns_nt_proto_characteristics, {   
+                       "NT Protocol Characteristics", "tns.nt_proto_characteristics", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "NT Protocol Characteristics", HFILL }},
+               { &hf_tns_line_turnaround, {    
+                       "Line Turnaround Value", "tns.line_turnaround", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Line Turnaround Value", HFILL }},
+               { &hf_tns_value_of_one, {       
+                       "Value of 1 in Hardware", "tns.value_of_one", FT_BYTES, BASE_NONE, 
+                       NULL, 0x0, "Value of 1 in Hardware", HFILL }},          
+
+               { &hf_tns_connect, { 
+                       "Connect", "tns.connect", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Connect", HFILL }},
+               { &hf_tns_connect_data_length, {        
+                       "Length of Connect Data", "tns.connect_data_length", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Length of Connect Data", HFILL }},
+               { &hf_tns_connect_data_offset, {        
+                       "Offset to Connect Data", "tns.connect_data_offset", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Offset to Connect Data", HFILL }},
+               { &hf_tns_connect_data_max, {   
+                       "Maximum Receivable Connect Data", "tns.connect_data_max", FT_UINT32, BASE_DEC, 
+                       NULL, 0x0, "Maximum Receivable Connect Data", HFILL }},
+               { &hf_tns_connect_flags0, {     
+                       "Connect Flags 0", "tns.connect_flags0", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Connect Flags 0", HFILL }},
+               { &hf_tns_connect_flags1, {     
+                       "Connect Flags 1", "tns.connect_flags1", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Connect Flags 1", HFILL }},
+               { &hf_tns_trace_cf1, {  
+                       "Trace Cross Facility Item 1", "tns.trace_cf1", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Trace Cross Facility Item 1", HFILL }},
+               { &hf_tns_trace_cf2, {  
+                       "Trace Cross Facility Item 2", "tns.trace_cf2", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Trace Cross Facility Item 2", HFILL }},
+               { &hf_tns_trace_cid, {  
+                       "Trace Unique Connection ID", "tns.trace_cid", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Trace Unique Connection ID", HFILL }},
+               { &hf_tns_connect_data, {       
+                       "Connect Data", "tns.connect_data", FT_STRING, BASE_NONE, 
+                       NULL, 0x0, "Connect Data", HFILL }},
+
+               { &hf_tns_accept, { 
+                       "Accept", "tns.accept", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Accept", HFILL }},          
+               { &hf_tns_accept_data_length, {         
+                       "Accept Data Length", "tns.accept_data_length", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Length of Accept Data", HFILL }},
+               { &hf_tns_accept_data, {        
+                       "Accept Data", "tns.accept_data", FT_STRING, BASE_NONE, 
+                       NULL, 0x0, "Accept Data", HFILL }},
+               { &hf_tns_accept_data_offset, {         
+                       "Offset to Accept Data", "tns.accept_data_offset", FT_UINT16, BASE_DEC, 
+                       NULL, 0x0, "Offset to Accept Data", HFILL }},
+
+
+               { &hf_tns_refuse, { 
+                       "Refuse", "tns.refuse", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Refuse", HFILL }},          
+               { &hf_tns_refuse_reason_user, {         
+                       "Refuse Reason (User)", "tns.refuse_reason_user", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Refuse Reason from Application", HFILL }},
+               { &hf_tns_refuse_reason_system, {       
+                       "Refuse Reason (User)", "tns.refuse_reason_system", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Refuse Reason from System", HFILL }},
+               { &hf_tns_refuse_data_length, {         
+                       "Refuse Data Length", "tns.refuse_data_length", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Length of Refuse Data", HFILL }},
+               { &hf_tns_refuse_data, {        
+                       "Refuse Data", "tns.refuse_data", FT_STRING, BASE_NONE, 
+                       NULL, 0x0, "Refuse Data", HFILL }},
+
+               { &hf_tns_abort, { 
+                       "Abort", "tns.abort", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Abort", HFILL }},           
+               { &hf_tns_abort_reason_user, {  
+                       "Abort Reason (User)", "tns.abort_reason_user", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Abort Reason from Application", HFILL }},
+               { &hf_tns_abort_reason_system, {        
+                       "Abort Reason (User)", "tns.abort_reason_system", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Abort Reason from System", HFILL }},
+               { &hf_tns_abort_data, {         
+                       "Abort Data", "tns.abort_data", FT_STRING, BASE_NONE, 
+                       NULL, 0x0, "Abort Data", HFILL }},
+
+               { &hf_tns_marker, { 
+                       "Marker", "tns.marker", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Marker", HFILL }},                          
+               { &hf_tns_marker_type, {        
+                       "Marker Type", "tns.marker.type", FT_UINT8, BASE_HEX, 
+                       VALS(tns_marker_types), 0x0, "Marker Type", HFILL }},
+               { &hf_tns_marker_data_byte, {   
+                       "Marker Data Byte", "tns.marker.databyte", FT_UINT8, BASE_HEX, 
+                       NULL, 0x0, "Marker Data Byte", HFILL }},
+               { &hf_tns_marker_data, {        
+                       "Marker Data", "tns.marker.data", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Marker Data", HFILL }},
+
+               { &hf_tns_control, { 
+                       "Control", "tns.control", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Control", HFILL }},         
+               { &hf_tns_control_cmd, {        
+                       "Control Command", "tns.control.cmd", FT_UINT16, BASE_HEX, 
+                       VALS(tns_control_cmds), 0x0, "Control Command", HFILL }},
+               { &hf_tns_control_data, {       
+                       "Control Data", "tns.control.data", FT_BYTES, BASE_HEX, 
+                       NULL, 0x0, "Control Data", HFILL }},
+
+               { &hf_tns_redirect, { 
+                       "Redirect", "tns.redirect", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Redirect", HFILL }},                
+               { &hf_tns_redirect_data_length, {       
+                       "Redirect Data Length", "tns.redirect_data_length", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Length of Redirect Data", HFILL }},
+               { &hf_tns_redirect_data, {      
+                       "Redirect Data", "tns.redirect_data", FT_STRING, BASE_NONE, 
+                       NULL, 0x0, "Redirect Data", HFILL }},
+
+               { &hf_tns_data, { 
+                       "Data", "tns.data", FT_BOOLEAN, BASE_NONE, 
+                       NULL, 0x0, "Data", HFILL }},            
+               { &hf_tns_data_flag, {  
+                       "Data Flag", "tns.data_flag", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "Data Flag", HFILL }},
+               { &hf_tns_data_flag_send, {     
+                       "Send Token", "tns.data_flag.send", FT_UINT16, BASE_BIN, 
+                       NULL, 0x1, "Send Token", HFILL }},
+               { &hf_tns_data_flag_rc, {       
+                       "Request Confirmation", "tns.data_flag.rc", FT_UINT16, BASE_BIN, 
+                       NULL, 0x2, "Request Confirmation", HFILL }},
+               { &hf_tns_data_flag_c, {        
+                       "Confirmation", "tns.data_flag.c", FT_UINT16, BASE_BIN, 
+                       NULL, 0x4, "Confirmation", HFILL }},
+               { &hf_tns_data_flag_reserved, {         
+                       "Reserved", "tns.data_flag.reserved", FT_UINT16, BASE_BIN, 
+                       NULL, 0x8, "Reserved", HFILL }},
+               { &hf_tns_data_flag_more, {     
+                       "More Data to Come", "tns.data_flag.more", FT_UINT16, BASE_BIN, 
+                       NULL, 0x20, "More Data to Come", HFILL }},
+               { &hf_tns_data_flag_eof, {      
+                       "End of File", "tns.data_flag.eof", FT_UINT16, BASE_BIN, 
+                       NULL, 0x40, "End of File", HFILL }},
+               { &hf_tns_data_flag_dic, {      
+                       "Do Immediate Confirmation", "tns.data_flag.dic", FT_UINT16, BASE_BIN, 
+                       NULL, 0x80, "Do Immediate Confirmation", HFILL }},
+               { &hf_tns_data_flag_rts, {      
+                       "Request To Send", "tns.data_flag.rts", FT_UINT16, BASE_BIN, 
+                       NULL, 0x100, "Request To Send", HFILL }},
+               { &hf_tns_data_flag_sntt, {     
+                       "Send NT Trailer", "tns.data_flag.sntt", FT_UINT16, BASE_BIN, 
+                       NULL, 0x200, "Send NT Trailer", HFILL }},
+
+
                { &hf_tns_reserved_byte, {      
                        "Reserved Byte", "tns.reserved_byte", FT_BYTES, BASE_HEX, 
-                       NULL, 0x0, "Reserved Byte" }},
+                       NULL, 0x0, "Reserved Byte", HFILL }},
                { &hf_tns_packet_type, {        
-                       "Packet Type", "tns.type", FT_UINT8, BASE_NONE, 
-                       VALS(tns_type_vals), 0x0, "Type of TNS packet" }}       
+                       "Packet Type", "tns.type", FT_UINT8, BASE_DEC, 
+                       VALS(tns_type_vals), 0x0, "Type of TNS packet", HFILL }}        
+
        };
 
        static gint *ett[] = {
                &ett_tns,
-               &ett_tns_sns,
                &ett_tns_connect,
+               &ett_tns_accept,
+               &ett_tns_refuse,
+               &ett_tns_abort,
+               &ett_tns_redirect,
+               &ett_tns_marker,
+               &ett_tns_attention,
+               &ett_tns_control,
+               &ett_tns_data,
+               &ett_tns_data_flag,
                &ett_sql
        };
        proto_tns = proto_register_protocol(
@@ -351,5 +1028,9 @@ void proto_register_tns(void)
 void
 proto_reg_handoff_tns(void)
 {
-       old_dissector_add("tcp.port", TCP_PORT_TNS, dissect_tns, proto_tns);
+       dissector_handle_t tns_handle;
+
+       tns_handle = create_dissector_handle(dissect_tns, proto_tns);
+       dissector_add("tcp.port", TCP_PORT_TNS, tns_handle);
+       data_handle = find_dissector("data");
 }