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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include <epan/packet.h>
37 #include <epan/wmem/wmem.h>
38 #include <epan/expert.h>
40 #include "packet-giop.h"
41 #include "packet-tcp.h"
44 * Useful visible data/structs
47 #define MIOP_MAX_UNIQUE_ID_LENGTH 252
49 #define MIOP_HEADER_SIZE 16
52 * Set to 1 for DEBUG output - TODO make this a runtime option
58 * ------------------------------------------------------------------------------------------+
59 * Data/Variables/Structs
60 * ------------------------------------------------------------------------------------------+
64 static int proto_miop
= -1;
71 static gint hf_miop_magic
= -1;
72 static gint hf_miop_hdr_version
= -1;
73 static gint hf_miop_flags
= -1;
74 static gint hf_miop_packet_length
= -1;
75 static gint hf_miop_packet_number
= -1;
76 static gint hf_miop_number_of_packets
= -1;
77 static gint hf_miop_unique_id_len
= -1;
78 static gint hf_miop_unique_id
= -1;
80 static gint ett_miop
= -1;
82 static expert_field ei_miop_version_not_supported
= EI_INIT
;
83 static expert_field ei_miop_unique_id_len_exceed_max_value
= EI_INIT
;
85 #define MIOP_MAGIC 0x4d494f50 /* "MIOP" */
87 static void dissect_miop (tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
);
90 dissect_miop_heur (tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * data _U_
) {
95 /* check magic number and version */
98 tot_len
= tvb_length(tvb
);
100 if (tot_len
< MIOP_HEADER_SIZE
) /* tot_len < 16 */
102 /* Not enough data captured to hold the GIOP header; don't try
103 to interpret it as GIOP. */
107 magic
= tvb_get_ntohl(tvb
,0);
108 if(magic
!= MIOP_MAGIC
){
109 /* Not a MIOP packet. */
113 if (pinfo
->ptype
!= PT_UDP
)
116 dissect_miop (tvb
, pinfo
, tree
);
118 /* TODO: make reasembly */
125 /* Main entry point */
126 static void dissect_miop (tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
) {
129 proto_tree
*miop_tree
= NULL
;
138 guint16 packet_length
;
140 guint number_of_packets
;
143 guint32 unique_id_len
;
145 wmem_strbuf_t
*flags_strbuf
= wmem_strbuf_new_label(wmem_packet_scope());
146 wmem_strbuf_append(flags_strbuf
, "none");
148 col_set_str (pinfo
->cinfo
, COL_PROTOCOL
, "MIOP");
149 /* Clear out stuff in the info column */
150 col_clear(pinfo
->cinfo
, COL_INFO
);
152 /* Extract major and minor version numbers */
153 hdr_version
= tvb_get_guint8(tvb
, 4);
154 version_major
= ((hdr_version
& 0xf0) >> 4);
155 version_minor
= (hdr_version
& 0x0f);
157 if (hdr_version
!= 16)
159 col_add_fstr (pinfo
->cinfo
, COL_INFO
, "Version %u.%u",
160 version_major
, version_minor
);
162 ti
= proto_tree_add_item (tree
, proto_miop
, tvb
, 0, -1, ENC_NA
);
163 miop_tree
= proto_item_add_subtree (ti
, ett_miop
);
164 proto_tree_add_expert_format(miop_tree
, pinfo
, &ei_miop_version_not_supported
,
166 "MIOP version %u.%u not supported",
167 version_major
, version_minor
);
171 flags
= tvb_get_guint8(tvb
, 5);
172 byte_order
= (flags
& 0x01) ? ENC_LITTLE_ENDIAN
: ENC_BIG_ENDIAN
;
174 if (byte_order
== ENC_BIG_ENDIAN
) {
175 packet_length
= tvb_get_ntohs(tvb
, 6);
176 packet_number
= tvb_get_ntohl(tvb
, 8);
177 number_of_packets
= tvb_get_ntohl(tvb
, 12);
178 unique_id_len
= tvb_get_ntohl(tvb
, 16);
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 col_add_fstr (pinfo
->cinfo
, COL_INFO
, "MIOP %u.%u Packet s=%d (%u of %u)",
188 version_major
, version_minor
, packet_length
,
195 ti
= proto_tree_add_item (tree
, proto_miop
, tvb
, 0, -1, ENC_NA
);
196 miop_tree
= proto_item_add_subtree (ti
, ett_miop
);
198 /* XXX - Should we bail out if we don't have the right magic number? */
199 proto_tree_add_item(miop_tree
, hf_miop_magic
, tvb
, offset
, 4, ENC_ASCII
|ENC_NA
);
201 proto_tree_add_uint_format_value(miop_tree
, hf_miop_hdr_version
, tvb
, offset
, 1, hdr_version
,
202 "%u.%u", version_major
, version_minor
);
205 wmem_strbuf_truncate(flags_strbuf
, 0);
206 wmem_strbuf_append(flags_strbuf
, "little-endian");
209 wmem_strbuf_append_printf(flags_strbuf
, "%s%s",
210 wmem_strbuf_get_len(flags_strbuf
) ? ", " : "", "last message");
212 proto_tree_add_uint_format_value(miop_tree
, hf_miop_flags
, tvb
, offset
, 1,
213 flags
, "0x%02x (%s)", flags
, wmem_strbuf_get_str(flags_strbuf
));
215 proto_tree_add_item(miop_tree
, hf_miop_packet_length
, tvb
, offset
, 2, byte_order
);
217 proto_tree_add_item(miop_tree
, hf_miop_packet_number
, tvb
, offset
, 4, byte_order
);
219 proto_tree_add_item(miop_tree
, hf_miop_number_of_packets
, tvb
, offset
, 4, byte_order
);
222 ti
= proto_tree_add_item(miop_tree
, hf_miop_unique_id_len
, tvb
, offset
, 4, byte_order
);
224 if (unique_id_len
>= MIOP_MAX_UNIQUE_ID_LENGTH
) {
225 expert_add_info_format(pinfo
, ti
, &ei_miop_unique_id_len_exceed_max_value
,
226 "Unique Id length (%u) exceeds max value (%u)",
227 unique_id_len
, MIOP_MAX_UNIQUE_ID_LENGTH
);
232 proto_tree_add_item(miop_tree
, hf_miop_unique_id
, tvb
, offset
, unique_id_len
,
235 if (packet_number
== 0) {
236 /* It is the first packet of the collection
237 We can call to GIOP dissector to show more about this first
238 uncompleted GIOP message
240 tvbuff_t
*payload_tvb
;
242 offset
+= unique_id_len
;
243 payload_tvb
= tvb_new_subset_remaining (tvb
, offset
);
244 dissect_giop(payload_tvb
, pinfo
, tree
);
252 void proto_register_miop (void) {
255 /* A header field is something you can search/filter on.
257 * We create a structure to register our fields. It consists of an
258 * array of hf_register_info structures, each of which are of the format
259 * {&(field id), {name, abbrev, type, display, strings, bitmask, blurb, HFILL}}.
261 static hf_register_info hf
[] = {
263 { "Magic", "miop.magic", FT_STRING
, BASE_NONE
, NULL
, 0x0,
264 "PacketHeader magic", HFILL
}},
265 { &hf_miop_hdr_version
,
266 { "Version", "miop.hdr_version", FT_UINT8
, BASE_HEX
, NULL
, 0x0,
267 "PacketHeader hdr_version", HFILL
}},
269 { "Flags", "miop.flags", FT_UINT8
, BASE_OCT
, NULL
, 0x0,
270 "PacketHeader flags", HFILL
}},
271 { &hf_miop_packet_length
,
272 { "Length", "miop.packet_length", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
273 "PacketHeader packet_length", HFILL
}},
274 { &hf_miop_packet_number
,
275 { "PacketNumber", "miop.packet_number", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
276 "PacketHeader packet_number", HFILL
}},
277 { &hf_miop_number_of_packets
,
278 { "NumberOfPackets", "miop.number_of_packets", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
279 "PacketHeader number_of_packets", HFILL
}},
280 { &hf_miop_unique_id_len
,
281 { "UniqueIdLength", "miop.unique_id_len", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
282 "UniqueId length", HFILL
}},
283 { &hf_miop_unique_id
,
284 { "UniqueId", "miop.unique_id", FT_BYTES
, BASE_NONE
, NULL
, 0x0,
285 "UniqueId id", HFILL
}},
289 static gint
*ett
[] = {
293 static ei_register_info ei
[] = {
294 { &ei_miop_version_not_supported
, { "miop.version.not_supported", PI_UNDECODED
, PI_WARN
, "MIOP version not supported", EXPFILL
}},
295 { &ei_miop_unique_id_len_exceed_max_value
, { "miop.unique_id_len.exceed_max_value", PI_MALFORMED
, PI_WARN
, "Unique Id length exceeds max value", EXPFILL
}},
298 expert_module_t
* expert_miop
;
300 proto_miop
= proto_register_protocol("Unreliable Multicast Inter-ORB Protocol", "MIOP", "miop");
301 proto_register_field_array (proto_miop
, hf
, array_length (hf
));
302 proto_register_subtree_array (ett
, array_length (ett
));
303 expert_miop
= expert_register_protocol(proto_miop
);
304 expert_register_field_array(expert_miop
, ei
, array_length(ei
));
306 register_dissector("miop", dissect_miop
, proto_miop
);
311 void proto_reg_handoff_miop (void) {
313 dissector_handle_t miop_handle
;
315 miop_handle
= find_dissector("miop");
316 dissector_add_handle("udp.port", miop_handle
); /* for 'Decode As' */
318 heur_dissector_add("udp", dissect_miop_heur
, proto_miop
);
323 * Editor modelines - http://www.wireshark.org/tools/modelines.html
328 * indent-tabs-mode: nil
331 * vi: set shiftwidth=2 tabstop=8 expandtab:
332 * :indentSize=2:tabSize=8:noTabs=true: