2 * Routines for CORBA MIOP packet disassembly
3 * Significantly based on packet-giop.c
4 * Copyright 2009 Alvaro Vega Garcia <avega at tid dot es>
6 * According with Unreliable Multicast Draft Adopted Specification
8 * Chapter 29: Unreliable Multicast Inter-ORB Protocol (MIOP)
9 * http://www.omg.org/technology/documents/specialized_corba.htm
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 #include <epan/packet.h>
47 #include <epan/emem.h>
48 #include <epan/expert.h>
50 #include "packet-giop.h"
51 #include "packet-tcp.h"
54 * Useful visible data/structs
57 #define MIOP_MAX_UNIQUE_ID_LENGTH 252
59 #define MIOP_HEADER_SIZE 16
62 * Set to 1 for DEBUG output - TODO make this a runtime option
68 * ------------------------------------------------------------------------------------------+
69 * Data/Variables/Structs
70 * ------------------------------------------------------------------------------------------+
74 static int proto_miop = -1;
81 static gint hf_miop_magic = -1;
82 static gint hf_miop_hdr_version = -1;
83 static gint hf_miop_flags = -1;
84 static gint hf_miop_packet_length = -1;
85 static gint hf_miop_packet_number = -1;
86 static gint hf_miop_number_of_packets = -1;
87 static gint hf_miop_unique_id_len = -1;
88 static gint hf_miop_unique_id = -1;
90 static gint ett_miop = -1;
92 #define MIOP_MAGIC "MIOP"
94 static void dissect_miop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree);
97 dissect_miop_heur (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
101 /* check magic number and version */
104 tot_len = tvb_length(tvb);
106 if (tot_len < MIOP_HEADER_SIZE) /* tot_len < 16 */
108 /* Not enough data captured to hold the GIOP header; don't try
109 to interpret it as GIOP. */
113 if ( tvb_memeql(tvb, 0, MIOP_MAGIC ,4) != 0)
116 if (pinfo->ptype != PT_UDP)
119 dissect_miop (tvb, pinfo, tree);
121 /* TODO: make reasembly */
128 /* Main entry point */
129 static void dissect_miop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
132 proto_tree *miop_tree = NULL;
141 guint16 packet_length;
143 guint number_of_packets;
144 gboolean little_endian;
146 guint32 unique_id_len;
148 emem_strbuf_t *flags_strbuf = ep_strbuf_new_label("none");
150 col_set_str (pinfo->cinfo, COL_PROTOCOL, MIOP_MAGIC);
151 /* Clear out stuff in the info column */
152 col_clear(pinfo->cinfo, COL_INFO);
154 /* Extract major and minor version numbers */
155 hdr_version = tvb_get_guint8(tvb, 4);
156 version_major = ((hdr_version & 0xf0) >> 4);
157 version_minor = (hdr_version & 0x0f);
159 if (hdr_version != 16)
161 col_add_fstr (pinfo->cinfo, COL_INFO, "Version %u.%u",
162 version_major, version_minor);
165 ti = proto_tree_add_item (tree, proto_miop, tvb, 0, -1, FALSE);
166 miop_tree = proto_item_add_subtree (ti, ett_miop);
167 proto_tree_add_text (miop_tree, tvb, 0, -1,
169 version_major, version_minor);
170 expert_add_info_format(pinfo, ti, PI_UNDECODED, PI_WARN,
171 "MIOP version %u.%u not supported",
172 version_major, version_minor);
177 flags = tvb_get_guint8(tvb, 5);
178 little_endian = flags & 0x01;
181 packet_length = tvb_get_letohs(tvb, 6);
182 packet_number = tvb_get_letohl(tvb, 8);
183 number_of_packets = tvb_get_letohl(tvb, 12);
184 unique_id_len = tvb_get_letohl(tvb, 16);
187 packet_length = tvb_get_ntohs(tvb, 6);
188 packet_number = tvb_get_ntohl(tvb, 8);
189 number_of_packets = tvb_get_ntohl(tvb, 12);
190 unique_id_len = tvb_get_ntohl(tvb, 16);
193 col_add_fstr (pinfo->cinfo, COL_INFO, "MIOP %u.%u Packet s=%d (%u of %u)",
194 version_major, version_minor, packet_length,
201 ti = proto_tree_add_item (tree, proto_miop, tvb, 0, -1, FALSE);
202 miop_tree = proto_item_add_subtree (ti, ett_miop);
204 /* XXX - Should we bail out if we don't have the right magic number? */
205 proto_tree_add_item(miop_tree, hf_miop_magic, tvb, offset, 4, FALSE);
207 proto_tree_add_uint_format(miop_tree, hf_miop_hdr_version, tvb, offset, 1, hdr_version,
208 "Version: %u.%u", version_major, version_minor);
211 ep_strbuf_printf(flags_strbuf, "little-endian");
214 ep_strbuf_append_printf(flags_strbuf, "%s%s",
215 flags_strbuf->len ? ", " : "", "last message");
217 ti = proto_tree_add_uint_format_value(miop_tree, hf_miop_flags, tvb, offset, 1,
218 flags, "0x%02x (%s)", flags, flags_strbuf->str);
220 proto_tree_add_item(miop_tree, hf_miop_packet_length, tvb, offset, 2, little_endian);
222 proto_tree_add_item(miop_tree, hf_miop_packet_number, tvb, offset, 4, little_endian);
224 proto_tree_add_item(miop_tree, hf_miop_number_of_packets, tvb, offset, 4, little_endian);
227 ti = proto_tree_add_item(miop_tree, hf_miop_unique_id_len, tvb, offset, 4, little_endian);
229 if (unique_id_len >= MIOP_MAX_UNIQUE_ID_LENGTH) {
230 expert_add_info_format(pinfo, ti, PI_MALFORMED, PI_WARN,
231 "Unique Id length (%u) exceeds max value (%u)",
232 unique_id_len, MIOP_MAX_UNIQUE_ID_LENGTH);
237 proto_tree_add_item(miop_tree, hf_miop_unique_id, tvb, offset, unique_id_len,
240 if (packet_number == 0) {
241 /* It is the first packet of the collection
242 We can call to GIOP dissector to show more about this first
243 uncompleted GIOP message
245 tvbuff_t *payload_tvb;
247 offset += unique_id_len;
248 payload_tvb = tvb_new_subset_remaining (tvb, offset);
249 dissect_giop(payload_tvb, pinfo, tree);
257 void proto_register_miop (void) {
260 /* A header field is something you can search/filter on.
262 * We create a structure to register our fields. It consists of an
263 * array of hf_register_info structures, each of which are of the format
264 * {&(field id), {name, abbrev, type, display, strings, bitmask, blurb, HFILL}}.
266 static hf_register_info hf[] = {
268 { "Magic", "miop.magic", FT_STRING, BASE_NONE, NULL, 0x0,
269 "PacketHeader magic", HFILL }},
270 { &hf_miop_hdr_version,
271 { "Version", "miop.hdr_version", FT_UINT8, BASE_HEX, NULL, 0x0,
272 "PacketHeader hdr_version", HFILL }},
274 { "Flags", "miop.flags", FT_UINT8, BASE_OCT, NULL, 0x0,
275 "PacketHeader flags", HFILL }},
276 { &hf_miop_packet_length,
277 { "Length", "miop.packet_length", FT_UINT16, BASE_DEC, NULL, 0x0,
278 "PacketHeader packet_length", HFILL }},
279 { &hf_miop_packet_number,
280 { "PacketNumber", "miop.packet_number", FT_UINT32, BASE_DEC, NULL, 0x0,
281 "PacketHeader packet_number", HFILL }},
282 { &hf_miop_number_of_packets,
283 { "NumberOfPackets", "miop.number_of_packets", FT_UINT32, BASE_DEC, NULL, 0x0,
284 "PacketHeader number_of_packets", HFILL }},
285 { &hf_miop_unique_id_len,
286 { "UniqueIdLength", "miop.unique_id_len", FT_UINT32, BASE_DEC, NULL, 0x0,
287 "UniqueId length", HFILL }},
288 { &hf_miop_unique_id,
289 { "UniqueId", "miop.unique_id", FT_BYTES, BASE_NONE, NULL, 0x0,
290 "UniqueId id", HFILL }},
294 static gint *ett[] = {
298 proto_miop = proto_register_protocol("Unreliable Multicast Inter-ORB Protocol", "MIOP",
300 proto_register_field_array (proto_miop, hf, array_length (hf));
301 proto_register_subtree_array (ett, array_length (ett));
303 register_dissector("miop", dissect_miop, proto_miop);
308 void proto_reg_handoff_miop (void) {
310 dissector_handle_t miop_handle;
312 miop_handle = find_dissector("miop");
313 dissector_add_handle("udp.port", miop_handle); /* for 'Decode As' */
315 heur_dissector_add("udp", dissect_miop_heur, proto_miop);