From Graeme Lunt
[obnox/wireshark/wip.git] / asn1 / ros / packet-ros-template.c
1 /* packet-ros_asn1.c
2  * Routines for ROS 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-ros.h"
40
41 #define PNAME  "X.880 OSI Remote Operations Service"
42 #define PSNAME "ROS"
43 #define PFNAME "ros"
44
45 /* Initialize the protocol and registered fields */
46 int proto_ros = -1;
47
48 static struct SESSION_DATA_STRUCTURE* session = NULL;
49
50 static proto_tree *top_tree=NULL;
51 static guint32 opcode;
52
53 #include "packet-ros-hf.c"
54
55 /* Initialize the subtree pointers */
56 static gint ett_ros = -1;
57 #include "packet-ros-ett.c"
58
59 static dissector_table_t ros_oid_dissector_table=NULL;
60 static GHashTable *oid_table=NULL;
61 static gint ett_ros_unknown = -1;
62
63 void
64 register_ros_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto _U_, const char *name)
65 {
66         dissector_add_string("ros.oid", oid, dissector);
67         g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
68 }
69
70 static int
71 call_ros_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
72 {
73         tvbuff_t *next_tvb;
74
75         next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
76         if(!dissector_try_string(ros_oid_dissector_table, oid, next_tvb, pinfo, tree)){
77                 proto_item *item=NULL;
78                 proto_tree *next_tree=NULL;
79
80                 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);
81                 if(item){
82                         next_tree=proto_item_add_subtree(item, ett_ros_unknown);
83                 }
84                 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
85         }
86
87         /*XXX until we change the #.REGISTER signature for _PDU()s 
88          * into new_dissector_t   we have to do this kludge with
89          * manually step past the content in the ANY type.
90          */
91         offset+=tvb_length_remaining(tvb, offset);
92
93         return offset;
94 }
95
96 #include "packet-ros-fn.c"
97
98
99 /*
100 * Dissect ROS PDUs inside a PPDU.
101 */
102 static void
103 dissect_ros(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
104 {
105         int offset = 0;
106         int old_offset;
107         proto_item *item=NULL;
108         proto_tree *tree=NULL;
109
110         /* save parent_tree so subdissectors can create new top nodes */
111         top_tree=parent_tree;
112
113         /* do we have application context from the acse dissector?  */
114         if( !pinfo->private_data ){
115                 if(parent_tree){
116                         proto_tree_add_text(parent_tree, tvb, offset, -1,
117                                 "Internal error:can't get application context from ACSE dissector.");
118                 } 
119                 return  ;
120         } else {
121                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
122
123         }
124
125         if(parent_tree){
126                 item = proto_tree_add_item(parent_tree, proto_ros, tvb, 0, -1, FALSE);
127                 tree = proto_item_add_subtree(item, ett_ros);
128         }
129         if (check_col(pinfo->cinfo, COL_PROTOCOL))
130                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ROS");
131         if (check_col(pinfo->cinfo, COL_INFO))
132                 col_clear(pinfo->cinfo, COL_INFO);
133
134         while (tvb_reported_length_remaining(tvb, offset) > 0){
135                 old_offset=offset;
136                 offset=dissect_ros_ROS(FALSE, tvb, offset, pinfo , tree, -1);
137                 if(offset == old_offset){
138                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte ROS PDU");
139                         offset = tvb_length(tvb);
140                         break;
141                 }
142         }
143 }
144
145
146 /*--- proto_register_ros -------------------------------------------*/
147 void proto_register_ros(void) {
148
149   /* List of fields */
150   static hf_register_info hf[] =
151   {
152 #include "packet-ros-hfarr.c"
153   };
154
155   /* List of subtrees */
156   static gint *ett[] = {
157     &ett_ros,
158     &ett_ros_unknown,
159 #include "packet-ros-ettarr.c"
160   };
161
162   /* Register protocol */
163   proto_ros = proto_register_protocol(PNAME, PSNAME, PFNAME);
164   register_dissector("ros", dissect_ros, proto_ros);
165   /* Register fields and subtrees */
166   proto_register_field_array(proto_ros, hf, array_length(hf));
167   proto_register_subtree_array(ett, array_length(ett));
168
169   ros_oid_dissector_table = register_dissector_table("ros.oid", "ROS OID Dissectors", FT_STRING, BASE_NONE);
170   oid_table=g_hash_table_new(g_str_hash, g_str_equal);
171 }
172
173
174 /*--- proto_reg_handoff_ros --- */
175 void proto_reg_handoff_ros(void) {
176 }