From Graeme Lunt
[obnox/wireshark/wip.git] / asn1 / rtse / packet-rtse-template.c
1 /* packet-rtse_asn1.c
2  * Routines for RTSE packet dissection
3  * Graeme Lunt 2005
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "packet-ber.h"
38 #include "packet-pres.h"
39 #include "packet-acse.h"
40 #include "packet-ros.h"
41 #include "packet-rtse.h"
42
43 #define PNAME  "X.228 OSI Reliable Transfer Service"
44 #define PSNAME "RTSE"
45 #define PFNAME "rtse"
46
47 /* Initialize the protocol and registered fields */
48 int proto_rtse = -1;
49
50 static struct SESSION_DATA_STRUCTURE* session = NULL;
51
52 static char object_identifier_id[MAX_OID_STR_LEN];
53 /* indirect_reference, used to pick up the signalling so we know what
54    kind of data is transferred in SES_DATA_TRANSFER_PDUs */
55 static guint32 indir_ref=0;
56 static guint32 app_proto=0;
57
58 static proto_tree *top_tree=NULL;
59
60 static int dissect_rtse_EXTERNAL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_);
61
62
63 #include "packet-rtse-hf.c"
64
65 /* Initialize the subtree pointers */
66 static gint ett_rtse = -1;
67 #include "packet-rtse-ett.c"
68
69
70 static dissector_table_t rtse_oid_dissector_table=NULL;
71 static GHashTable *oid_table=NULL;
72 static gint ett_rtse_unknown = -1;
73
74 void
75 register_rtse_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto _U_, const char *name)
76 {
77         dissector_add_string("rtse.oid", oid, dissector);
78         g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
79 }
80
81 static int
82 call_rtse_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
83 {
84         tvbuff_t *next_tvb;
85
86         next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
87         if(!dissector_try_string(rtse_oid_dissector_table, oid, next_tvb, pinfo, tree)){
88                 proto_item *item=NULL;
89                 proto_tree *next_tree=NULL;
90
91                 item=proto_tree_add_text(tree, next_tvb, 0, tvb_length_remaining(tvb, offset), "RTSE: Dissector for OID:%s not implemented. Contact Ethereal developers if you want this supported", oid);
92                 if(item){
93                         next_tree=proto_item_add_subtree(item, ett_rtse_unknown);
94                 }
95                 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
96         }
97
98         /*XXX until we change the #.REGISTER signature for _PDU()s 
99          * into new_dissector_t   we have to do this kludge with
100          * manually step past the content in the ANY type.
101          */
102         offset+=tvb_length_remaining(tvb, offset);
103
104         return offset;
105 }
106
107 #include "packet-rtse-fn.c"
108
109 /*
110 * Dissect RTSE PDUs inside a PPDU.
111 */
112 static void
113 dissect_rtse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
114 {
115         int offset = 0;
116         int old_offset;
117         proto_item *item=NULL;
118         proto_tree *tree=NULL;
119
120         /* save parent_tree so subdissectors can create new top nodes */
121         top_tree=parent_tree;
122
123         /* do we have application context from the acse dissector?  */
124         if( !pinfo->private_data ){
125                 if(parent_tree){
126                         proto_tree_add_text(parent_tree, tvb, offset, -1,
127                                 "Internal error:can't get application context from ACSE dissector.");
128                 } 
129                 return  ;
130         } else {
131                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
132
133         }
134
135         if(parent_tree){
136                 item = proto_tree_add_item(parent_tree, proto_rtse, tvb, 0, -1, FALSE);
137                 tree = proto_item_add_subtree(item, ett_rtse);
138         }
139         if (check_col(pinfo->cinfo, COL_PROTOCOL))
140                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSE");
141         if (check_col(pinfo->cinfo, COL_INFO))
142                 col_clear(pinfo->cinfo, COL_INFO);
143
144         while (tvb_reported_length_remaining(tvb, offset) > 0){
145                 old_offset=offset;
146                 offset=dissect_rtse_RTSE_apdus(FALSE, tvb, offset, pinfo , tree, -1);
147                 if(offset == old_offset){
148                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte RTSE PDU");
149                         offset = tvb_length(tvb);
150                         break;
151                 }
152         }
153
154         top_tree = NULL;
155 }
156
157
158 /*--- proto_register_rtse -------------------------------------------*/
159 void proto_register_rtse(void) {
160
161   /* List of fields */
162   static hf_register_info hf[] =
163   {
164 #include "packet-rtse-hfarr.c"
165   };
166
167   /* List of subtrees */
168   static gint *ett[] = {
169     &ett_rtse,
170     &ett_rtse_unknown,
171 #include "packet-rtse-ettarr.c"
172   };
173
174   /* Register protocol */
175   proto_rtse = proto_register_protocol(PNAME, PSNAME, PFNAME);
176   register_dissector("rtse", dissect_rtse, proto_rtse);
177   /* Register fields and subtrees */
178   proto_register_field_array(proto_rtse, hf, array_length(hf));
179   proto_register_subtree_array(ett, array_length(ett));
180
181   rtse_oid_dissector_table = register_dissector_table("rtse.oid", "RTSE OID Dissectors", FT_STRING, BASE_NONE);
182   oid_table=g_hash_table_new(g_str_hash, g_str_equal);
183
184 }
185
186
187 /*--- proto_reg_handoff_rtse --- */
188 void proto_reg_handoff_rtse(void) {
189 }