2 * Routines for RTSE 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/prefs.h>
34 #include <epan/reassemble.h>
35 #include <epan/asn1.h>
36 #include <epan/expert.h>
41 #include "packet-ber.h"
42 #include "packet-pres.h"
43 #include "packet-acse.h"
44 #include "packet-ros.h"
45 #include "packet-rtse.h"
47 #define PNAME "X.228 OSI Reliable Transfer Service"
51 /* Initialize the protocol and registered fields */
54 static struct SESSION_DATA_STRUCTURE* session = NULL;
56 static gboolean open_request=FALSE;
57 static guint32 app_proto=0;
59 static proto_tree *top_tree=NULL;
62 static gboolean rtse_reassemble = TRUE;
64 #include "packet-rtse-hf.c"
66 /* Initialize the subtree pointers */
67 static gint ett_rtse = -1;
68 #include "packet-rtse-ett.c"
71 static dissector_table_t rtse_oid_dissector_table=NULL;
72 static GHashTable *oid_table=NULL;
73 static gint ett_rtse_unknown = -1;
75 static GHashTable *rtse_segment_table = NULL;
76 static GHashTable *rtse_reassembled_table = NULL;
78 static int hf_rtse_fragments = -1;
79 static int hf_rtse_fragment = -1;
80 static int hf_rtse_fragment_overlap = -1;
81 static int hf_rtse_fragment_overlap_conflicts = -1;
82 static int hf_rtse_fragment_multiple_tails = -1;
83 static int hf_rtse_fragment_too_long_fragment = -1;
84 static int hf_rtse_fragment_error = -1;
85 static int hf_rtse_reassembled_in = -1;
87 static gint ett_rtse_fragment = -1;
88 static gint ett_rtse_fragments = -1;
90 static const fragment_items rtse_frag_items = {
91 /* Fragment subtrees */
97 &hf_rtse_fragment_overlap,
98 &hf_rtse_fragment_overlap_conflicts,
99 &hf_rtse_fragment_multiple_tails,
100 &hf_rtse_fragment_too_long_fragment,
101 &hf_rtse_fragment_error,
102 /* Reassembled in field */
103 &hf_rtse_reassembled_in,
109 register_rtse_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto, const char *name, gboolean uses_ros)
111 /* XXX: Note that this fcn is called from proto_reg_handoff in *other* dissectors ... */
113 static dissector_handle_t rtse_handle = NULL;
114 static dissector_handle_t ros_handle = NULL;
116 if (rtse_handle == NULL)
117 rtse_handle = find_dissector("rtse");
118 if (ros_handle == NULL)
119 ros_handle = find_dissector("ros");
121 /* save the name - but not used */
122 g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
124 /* register RTSE with the BER (ACSE) */
125 register_ber_oid_dissector_handle(oid, rtse_handle, proto, name);
128 /* make sure we call ROS ... */
129 dissector_add_string("rtse.oid", oid, ros_handle);
131 /* and then tell ROS how to dissect the AS*/
132 register_ros_oid_dissector_handle(oid, dissector, proto, name, TRUE);
135 /* otherwise we just remember how to dissect the AS */
136 dissector_add_string("rtse.oid", oid, dissector);
141 call_rtse_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
145 next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
146 if(!dissector_try_string(rtse_oid_dissector_table, oid, next_tvb, pinfo, tree)){
147 proto_item *item=proto_tree_add_text(tree, next_tvb, 0, tvb_length_remaining(tvb, offset), "RTSE: Dissector for OID:%s not implemented. Contact Wireshark developers if you want this supported", oid);
148 proto_tree *next_tree=proto_item_add_subtree(item, ett_rtse_unknown);
150 expert_add_info_format (pinfo, item, PI_UNDECODED, PI_WARN,
151 "RTSE: Dissector for OID %s not implemented", oid);
152 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
155 /*XXX until we change the #.REGISTER signature for _PDU()s
156 * into new_dissector_t we have to do this kludge with
157 * manually step past the content in the ANY type.
159 offset+=tvb_length_remaining(tvb, offset);
165 call_rtse_external_type_callback(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_)
167 const char *oid = NULL;
169 if (actx->external.indirect_ref_present) {
170 oid = (const char *)find_oid_by_pres_ctx_id(actx->pinfo, actx->external.indirect_reference);
171 } else if (actx->external.direct_ref_present) {
172 oid = actx->external.direct_reference;
176 offset = call_rtse_oid_callback(oid, tvb, offset, actx->pinfo, top_tree ? top_tree : tree);
181 #include "packet-rtse-fn.c"
184 * Dissect RTSE PDUs inside a PPDU.
187 dissect_rtse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
191 proto_item *item=NULL;
192 proto_tree *tree=NULL;
193 proto_tree *next_tree=NULL;
194 tvbuff_t *next_tvb = NULL;
195 tvbuff_t *data_tvb = NULL;
196 fragment_data *frag_msg = NULL;
197 guint32 fragment_length;
199 gboolean data_handled = FALSE;
200 conversation_t *conversation = NULL;
202 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
204 /* save parent_tree so subdissectors can create new top nodes */
205 top_tree=parent_tree;
207 /* do we have application context from the acse dissector? */
208 if( !pinfo->private_data ){
210 proto_tree_add_text(parent_tree, tvb, offset, -1,
211 "Internal error:can't get application context from ACSE dissector.");
215 session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
219 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSE");
220 if (check_col(pinfo->cinfo, COL_INFO))
221 col_clear(pinfo->cinfo, COL_INFO);
223 if (rtse_reassemble &&
224 ((session->spdu_type == SES_DATA_TRANSFER) ||
225 (session->spdu_type == SES_MAJOR_SYNC_POINT))) {
226 /* Use conversation index as fragment id */
227 conversation = find_conversation (pinfo->fd->num,
228 &pinfo->src, &pinfo->dst, pinfo->ptype,
229 pinfo->srcport, pinfo->destport, 0);
230 if (conversation != NULL) {
231 rtse_id = conversation->index;
233 session->rtse_reassemble = TRUE;
235 if (rtse_reassemble && session->spdu_type == SES_MAJOR_SYNC_POINT) {
236 frag_msg = fragment_end_seq_next (pinfo, rtse_id, rtse_segment_table,
237 rtse_reassembled_table);
238 next_tvb = process_reassembled_data (tvb, offset, pinfo, "Reassembled RTSE",
239 frag_msg, &rtse_frag_items, NULL, parent_tree);
242 item = proto_tree_add_item(parent_tree, proto_rtse, next_tvb ? next_tvb : tvb, 0, -1, FALSE);
243 tree = proto_item_add_subtree(item, ett_rtse);
245 if (rtse_reassemble && session->spdu_type == SES_DATA_TRANSFER) {
246 /* strip off the OCTET STRING encoding - including any CONSTRUCTED OCTET STRING */
247 dissect_ber_octet_string(FALSE, &asn1_ctx, NULL, tvb, offset, 0, &data_tvb);
250 fragment_length = tvb_length_remaining (data_tvb, 0);
251 proto_tree_add_text(tree, data_tvb, 0, (fragment_length) ? -1 : 0,
252 "RTSE segment data (%u byte%s)", fragment_length,
253 plurality(fragment_length, "", "s"));
254 frag_msg = fragment_add_seq_next (data_tvb, 0, pinfo,
255 rtse_id, rtse_segment_table,
256 rtse_reassembled_table, fragment_length, TRUE);
257 if (frag_msg && pinfo->fd->num != frag_msg->reassembled_in) {
258 /* Add a "Reassembled in" link if not reassembled in this frame */
259 proto_tree_add_uint (tree, *(rtse_frag_items.hf_reassembled_in),
260 data_tvb, 0, 0, frag_msg->reassembled_in);
262 pinfo->fragmented = TRUE;
265 fragment_length = tvb_length_remaining (tvb, offset);
268 if (check_col(pinfo->cinfo, COL_INFO))
269 col_append_fstr(pinfo->cinfo, COL_INFO, "[RTSE fragment, %u byte%s]",
270 fragment_length, plurality(fragment_length, "", "s"));
271 } else if (rtse_reassemble && session->spdu_type == SES_MAJOR_SYNC_POINT) {
273 /* ROS won't do this for us */
274 session->ros_op = (ROS_OP_INVOKE | ROS_OP_ARGUMENT);
275 offset=dissect_ber_external_type(FALSE, tree, next_tvb, 0, &asn1_ctx, -1, call_rtse_external_type_callback);
277 offset = tvb_length (tvb);
279 pinfo->fragmented = FALSE;
284 while (tvb_reported_length_remaining(tvb, offset) > 0){
286 offset=dissect_rtse_RTSE_apdus(TRUE, tvb, offset, &asn1_ctx, tree, -1);
287 if(offset == old_offset){
288 item = proto_tree_add_text(tree, tvb, offset, -1, "Unknown RTSE PDU");
291 expert_add_info_format (pinfo, item, PI_UNDECODED, PI_WARN, "Unknown RTSE PDU");
292 next_tree=proto_item_add_subtree(item, ett_rtse_unknown);
293 dissect_unknown_ber(pinfo, tvb, offset, next_tree);
296 offset = tvb_length(tvb);
305 static void rtse_reassemble_init (void)
307 fragment_table_init (&rtse_segment_table);
308 reassembled_table_init (&rtse_reassembled_table);
311 /*--- proto_register_rtse -------------------------------------------*/
312 void proto_register_rtse(void) {
315 static hf_register_info hf[] =
317 /* Fragment entries */
318 { &hf_rtse_fragments,
319 { "RTSE fragments", "rtse.fragments", FT_NONE, BASE_NONE,
320 NULL, 0x00, "Message fragments", HFILL } },
322 { "RTSE fragment", "rtse.fragment", FT_FRAMENUM, BASE_NONE,
323 NULL, 0x00, "Message fragment", HFILL } },
324 { &hf_rtse_fragment_overlap,
325 { "RTSE fragment overlap", "rtse.fragment.overlap", FT_BOOLEAN,
326 BASE_NONE, NULL, 0x0, "Message fragment overlap", HFILL } },
327 { &hf_rtse_fragment_overlap_conflicts,
328 { "RTSE fragment overlapping with conflicting data",
329 "rtse.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, NULL,
330 0x0, "Message fragment overlapping with conflicting data", HFILL } },
331 { &hf_rtse_fragment_multiple_tails,
332 { "RTSE has multiple tail fragments",
333 "rtse.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
334 NULL, 0x0, "Message has multiple tail fragments", HFILL } },
335 { &hf_rtse_fragment_too_long_fragment,
336 { "RTSE fragment too long", "rtse.fragment.too_long_fragment",
337 FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Message fragment too long",
339 { &hf_rtse_fragment_error,
340 { "RTSE defragmentation error", "rtse.fragment.error", FT_FRAMENUM,
341 BASE_NONE, NULL, 0x00, "Message defragmentation error", HFILL } },
342 { &hf_rtse_reassembled_in,
343 { "Reassembled RTSE in frame", "rtse.reassembled.in", FT_FRAMENUM, BASE_NONE,
344 NULL, 0x00, "This RTSE packet is reassembled in this frame", HFILL } },
346 #include "packet-rtse-hfarr.c"
349 /* List of subtrees */
350 static gint *ett[] = {
355 #include "packet-rtse-ettarr.c"
358 module_t *rtse_module;
360 /* Register protocol */
361 proto_rtse = proto_register_protocol(PNAME, PSNAME, PFNAME);
362 register_dissector("rtse", dissect_rtse, proto_rtse);
363 /* Register fields and subtrees */
364 proto_register_field_array(proto_rtse, hf, array_length(hf));
365 proto_register_subtree_array(ett, array_length(ett));
366 register_init_routine (&rtse_reassemble_init);
367 rtse_module = prefs_register_protocol_subtree("OSI", proto_rtse, NULL);
369 prefs_register_bool_preference(rtse_module, "reassemble",
370 "Reassemble segmented RTSE datagrams",
371 "Whether segmented RTSE datagrams should be reassembled."
372 " To use this option, you must also enable"
373 " \"Allow subdissectors to reassemble TCP streams\""
374 " in the TCP protocol settings.", &rtse_reassemble);
376 rtse_oid_dissector_table = register_dissector_table("rtse.oid", "RTSE OID Dissectors", FT_STRING, BASE_NONE);
377 oid_table=g_hash_table_new(g_str_hash, g_str_equal);
383 /*--- proto_reg_handoff_rtse --- */
384 void proto_reg_handoff_rtse(void) {