2 * Routines for ROS packet dissection
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
33 #include <epan/emem.h>
38 #include "packet-ber.h"
39 #include "packet-pres.h"
40 #include "packet-ros.h"
42 #define PNAME "X.880 OSI Remote Operations Service"
46 /* Initialize the protocol and registered fields */
49 static struct SESSION_DATA_STRUCTURE* session = NULL;
51 static proto_tree *top_tree=NULL;
52 static guint32 opcode;
53 static guint32 invokeid;
55 static dissector_handle_t ros_handle = NULL;
57 typedef struct ros_conv_info_t {
58 struct ros_conv_info_t *next;
59 GHashTable *unmatched; /* unmatched operations */
60 GHashTable *matched; /* matched operations */
63 static ros_conv_info_t *ros_info_items = NULL;
65 typedef struct ros_call_response {
71 } ros_call_response_t;
73 static int hf_ros_response_in = -1;
74 static int hf_ros_response_to = -1;
75 static int hf_ros_time = -1;
78 #include "packet-ros-hf.c"
80 /* Initialize the subtree pointers */
81 static gint ett_ros = -1;
82 #include "packet-ros-ett.c"
84 static dissector_table_t ros_oid_dissector_table=NULL;
85 static GHashTable *oid_table=NULL;
86 static gint ett_ros_unknown = -1;
89 register_ros_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto _U_, const char *name, gboolean uses_rtse)
91 dissector_add_string("ros.oid", oid, dissector);
92 g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
95 /* if we are not using RTSE, then we must register ROS with BER (ACSE) */
96 register_ber_oid_dissector_handle(oid, ros_handle, proto, name);
100 call_ros_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
104 next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
105 if(!dissector_try_string(ros_oid_dissector_table, oid, next_tvb, pinfo, tree)){
106 proto_item *item=NULL;
107 proto_tree *next_tree=NULL;
109 item=proto_tree_add_text(tree, next_tvb, 0, tvb_length_remaining(tvb, offset), "ROS: Dissector for OID:%s not implemented. Contact Ethereal developers if you want this supported", oid);
111 next_tree=proto_item_add_subtree(item, ett_ros_unknown);
113 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
116 /*XXX until we change the #.REGISTER signature for _PDU()s
117 * into new_dissector_t we have to do this kludge with
118 * manually step past the content in the ANY type.
120 offset+=tvb_length_remaining(tvb, offset);
127 ros_info_hash_matched(gconstpointer k)
129 const ros_call_response_t *key = k;
131 return key->invokeId;
135 ros_info_equal_matched(gconstpointer k1, gconstpointer k2)
137 const ros_call_response_t *key1 = k1;
138 const ros_call_response_t *key2 = k2;
140 if( key1->req_frame && key2->req_frame && (key1->req_frame!=key2->req_frame) ){
143 /* a response may span multiple frames
144 if( key1->rep_frame && key2->rep_frame && (key1->rep_frame!=key2->rep_frame) ){
149 return key1->invokeId==key2->invokeId;
153 ros_info_hash_unmatched(gconstpointer k)
155 const ros_call_response_t *key = k;
157 return key->invokeId;
161 ros_info_equal_unmatched(gconstpointer k1, gconstpointer k2)
163 const ros_call_response_t *key1 = k1;
164 const ros_call_response_t *key2 = k2;
166 return key1->invokeId==key2->invokeId;
169 static ros_call_response_t *
170 ros_match_call_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint invokeId, gboolean isInvoke)
172 ros_call_response_t rcr, *rcrp=NULL;
173 ros_conv_info_t *ros_info = ros_info_items;
175 /* first see if we have already matched this */
177 rcr.invokeId=invokeId;
178 rcr.is_request = isInvoke;
181 rcr.req_frame=pinfo->fd->num;
185 rcr.rep_frame=pinfo->fd->num;
188 rcrp=g_hash_table_lookup(ros_info->matched, &rcr);
191 /* we have found a match */
192 rcrp->is_request=rcr.is_request;
196 /* we haven't found a match - try and match it up */
199 /* this a a request - add it to the unmatched list */
201 /* check that we dont already have one of those in the
202 unmatched list and if so remove it */
204 rcr.invokeId=invokeId;
206 rcrp=g_hash_table_lookup(ros_info->unmatched, &rcr);
209 g_hash_table_remove(ros_info->unmatched, rcrp);
212 /* if we cant reuse the old one, grab a new chunk */
214 rcrp=se_alloc(sizeof(ros_call_response_t));
216 rcrp->invokeId=invokeId;
217 rcrp->req_frame=pinfo->fd->num;
218 rcrp->req_time=pinfo->fd->abs_ts;
220 rcrp->is_request=TRUE;
221 g_hash_table_insert(ros_info->unmatched, rcrp, rcrp);
226 /* this is a result - it should be in our unmatched list */
228 rcr.invokeId=invokeId;
229 rcrp=g_hash_table_lookup(ros_info->unmatched, &rcr);
233 if(!rcrp->rep_frame){
234 g_hash_table_remove(ros_info->unmatched, rcrp);
235 rcrp->rep_frame=pinfo->fd->num;
236 rcrp->is_request=FALSE;
237 g_hash_table_insert(ros_info->matched, rcrp, rcrp);
243 if(rcrp){ /* we have found a match */
245 if(rcrp->is_request){
246 proto_tree_add_uint(tree, hf_ros_response_in, tvb, 0, 0, rcrp->rep_frame);
249 proto_tree_add_uint(tree, hf_ros_response_to, tvb, 0, 0, rcrp->req_frame);
250 nstime_delta(&ns, &pinfo->fd->abs_ts, &rcrp->req_time);
251 proto_tree_add_time(tree, hf_ros_time, tvb, 0, 0, &ns);
258 #include "packet-ros-fn.c"
261 * Dissect ROS PDUs inside a PPDU.
264 dissect_ros(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
268 proto_item *item=NULL;
269 proto_tree *tree=NULL;
270 conversation_t *conversation;
271 ros_conv_info_t *ros_info = NULL;
273 /* save parent_tree so subdissectors can create new top nodes */
274 top_tree=parent_tree;
276 /* do we have application context from the acse dissector? */
277 if( !pinfo->private_data ){
279 proto_tree_add_text(parent_tree, tvb, offset, -1,
280 "Internal error:can't get application context from ACSE dissector.");
284 session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
289 * Do we have a conversation for this connection?
291 conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
292 pinfo->ptype, pinfo->srcport,
294 if (conversation == NULL) {
295 /* We don't yet have a conversation, so create one. */
296 conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
297 pinfo->ptype, pinfo->srcport,
303 * Do we already have our info
305 ros_info = conversation_get_proto_data(conversation, proto_ros);
306 if (ros_info == NULL) {
308 /* No. Attach that information to the conversation. */
310 ros_info = se_alloc(sizeof(ros_conv_info_t));
311 ros_info->matched=g_hash_table_new(ros_info_hash_matched, ros_info_equal_matched);
312 ros_info->unmatched=g_hash_table_new(ros_info_hash_unmatched, ros_info_equal_unmatched);
314 conversation_add_proto_data(conversation, proto_ros, ros_info);
316 ros_info->next = ros_info_items;
317 ros_info_items = ros_info;
320 /* pinfo->private_data = ros_info; */
323 item = proto_tree_add_item(parent_tree, proto_ros, tvb, 0, -1, FALSE);
324 tree = proto_item_add_subtree(item, ett_ros);
326 if (check_col(pinfo->cinfo, COL_PROTOCOL))
327 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ROS");
328 if (check_col(pinfo->cinfo, COL_INFO))
329 col_clear(pinfo->cinfo, COL_INFO);
331 while (tvb_reported_length_remaining(tvb, offset) > 0){
333 offset=dissect_ros_ROS(FALSE, tvb, offset, pinfo , tree, -1);
334 if(offset == old_offset){
335 proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte ROS PDU");
336 offset = tvb_length(tvb);
345 ros_conv_info_t *ros_info;
347 /* Free up state attached to the ros_info structures */
348 for (ros_info = ros_info_items; ros_info != NULL; ros_info = ros_info->next) {
349 g_hash_table_destroy(ros_info->matched);
350 ros_info->matched=NULL;
351 g_hash_table_destroy(ros_info->unmatched);
352 ros_info->unmatched=NULL;
355 ros_info_items = NULL;
359 /*--- proto_register_ros -------------------------------------------*/
360 void proto_register_ros(void) {
363 static hf_register_info hf[] =
365 { &hf_ros_response_in,
366 { "Response In", "ros.response_in",
367 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
368 "The response to this remote operation invocation is in this frame", HFILL }},
369 { &hf_ros_response_to,
370 { "Response To", "ros.response_to",
371 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
372 "This is a response to the remote operation invocation in this frame", HFILL }},
374 { "Time", "ros.time",
375 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
376 "The time between the Invoke and the Response", HFILL }},
378 #include "packet-ros-hfarr.c"
381 /* List of subtrees */
382 static gint *ett[] = {
385 #include "packet-ros-ettarr.c"
388 /* Register protocol */
389 proto_ros = proto_register_protocol(PNAME, PSNAME, PFNAME);
390 register_dissector("ros", dissect_ros, proto_ros);
391 /* Register fields and subtrees */
392 proto_register_field_array(proto_ros, hf, array_length(hf));
393 proto_register_subtree_array(ett, array_length(ett));
395 ros_oid_dissector_table = register_dissector_table("ros.oid", "ROS OID Dissectors", FT_STRING, BASE_NONE);
396 oid_table=g_hash_table_new(g_str_hash, g_str_equal);
398 ros_handle = find_dissector("ros");
400 register_init_routine(ros_reinit);
404 /*--- proto_reg_handoff_ros --- */
405 void proto_reg_handoff_ros(void) {