cbe514952c835aa247feb5e50c18950b80dd114d
[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 static gboolean open_request=FALSE;
54 /* indirect_reference, used to pick up the signalling so we know what
55    kind of data is transferred in SES_DATA_TRANSFER_PDUs */
56 static guint32 indir_ref=0;
57 static guint32 app_proto=0;
58
59 static proto_tree *top_tree=NULL;
60
61 static  dissector_handle_t rtse_handle = NULL;
62 static  dissector_handle_t ros_handle = NULL;
63
64 #include "packet-rtse-hf.c"
65
66 /* Initialize the subtree pointers */
67 static gint ett_rtse = -1;
68 #include "packet-rtse-ett.c"
69
70
71 static dissector_table_t rtse_oid_dissector_table=NULL;
72 static GHashTable *oid_table=NULL;
73 static gint ett_rtse_unknown = -1;
74
75 void
76 register_rtse_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto _U_, const char *name, gboolean uses_ros)
77 {
78
79   /* save the name - but not used */
80   g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
81
82   /* register RTSE with the BER (ACSE) */
83   register_ber_oid_dissector_handle(oid, rtse_handle, proto, name);
84
85   if(uses_ros) {
86     /* make sure we call ROS ... */
87     dissector_add_string("rtse.oid", oid, ros_handle);
88
89     /* and then tell ROS how to dissect the AS*/
90     register_ros_oid_dissector_handle(oid, dissector, proto, name, TRUE);
91
92   } else {
93     /* otherwise we just remember how to dissect the AS */
94     dissector_add_string("rtse.oid", oid, dissector);
95   }
96 }
97
98 static int
99 call_rtse_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
100 {
101         tvbuff_t *next_tvb;
102
103         next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
104         if(!dissector_try_string(rtse_oid_dissector_table, oid, next_tvb, pinfo, tree)){
105                 proto_item *item=NULL;
106                 proto_tree *next_tree=NULL;
107
108                 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);
109                 if(item){
110                         next_tree=proto_item_add_subtree(item, ett_rtse_unknown);
111                 }
112                 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
113         }
114
115         /*XXX until we change the #.REGISTER signature for _PDU()s 
116          * into new_dissector_t   we have to do this kludge with
117          * manually step past the content in the ANY type.
118          */
119         offset+=tvb_length_remaining(tvb, offset);
120
121         return offset;
122 }
123
124 #include "packet-rtse-fn.c"
125
126 /*
127 * Dissect RTSE PDUs inside a PPDU.
128 */
129 static void
130 dissect_rtse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
131 {
132         int offset = 0;
133         int old_offset;
134         proto_item *item=NULL;
135         proto_tree *tree=NULL;
136
137         /* save parent_tree so subdissectors can create new top nodes */
138         top_tree=parent_tree;
139
140         /* do we have application context from the acse dissector?  */
141         if( !pinfo->private_data ){
142                 if(parent_tree){
143                         proto_tree_add_text(parent_tree, tvb, offset, -1,
144                                 "Internal error:can't get application context from ACSE dissector.");
145                 } 
146                 return  ;
147         } else {
148                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
149
150         }
151
152         if(parent_tree){
153                 item = proto_tree_add_item(parent_tree, proto_rtse, tvb, 0, -1, FALSE);
154                 tree = proto_item_add_subtree(item, ett_rtse);
155         }
156         if (check_col(pinfo->cinfo, COL_PROTOCOL))
157                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSE");
158         if (check_col(pinfo->cinfo, COL_INFO))
159                 col_clear(pinfo->cinfo, COL_INFO);
160
161         while (tvb_reported_length_remaining(tvb, offset) > 0){
162                 old_offset=offset;
163                 offset=dissect_rtse_RTSE_apdus(FALSE, tvb, offset, pinfo , tree, -1);
164                 if(offset == old_offset){
165                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte RTSE PDU");
166                         offset = tvb_length(tvb);
167                         break;
168                 }
169         }
170
171         top_tree = NULL;
172 }
173
174
175 /*--- proto_register_rtse -------------------------------------------*/
176 void proto_register_rtse(void) {
177
178   /* List of fields */
179   static hf_register_info hf[] =
180   {
181 #include "packet-rtse-hfarr.c"
182   };
183
184   /* List of subtrees */
185   static gint *ett[] = {
186     &ett_rtse,
187     &ett_rtse_unknown,
188 #include "packet-rtse-ettarr.c"
189   };
190
191   /* Register protocol */
192   proto_rtse = proto_register_protocol(PNAME, PSNAME, PFNAME);
193   register_dissector("rtse", dissect_rtse, proto_rtse);
194   /* Register fields and subtrees */
195   proto_register_field_array(proto_rtse, hf, array_length(hf));
196   proto_register_subtree_array(ett, array_length(ett));
197
198   rtse_oid_dissector_table = register_dissector_table("rtse.oid", "RTSE OID Dissectors", FT_STRING, BASE_NONE);
199   oid_table=g_hash_table_new(g_str_hash, g_str_equal);
200
201   rtse_handle = find_dissector("rtse");
202   ros_handle = find_dissector("ros");
203
204 }
205
206
207 /*--- proto_reg_handoff_rtse --- */
208 void proto_reg_handoff_rtse(void) {
209
210
211 }