2 * ISC OMAPI (Object Management API) dissector
3 * Copyright 2006, Jaap Keuter <jaap.keuter@xs4all.nl>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 * From the description api+protocol.
28 * All fields are 32 bit unless stated otherwise.
30 * On startup, each side sends a status message indicating what version
31 * of the protocol they are speaking. The status message looks like this:
32 * +---------+---------+
33 * | version | hlength |
34 * +---------+---------+
36 * The fixed-length header consists of:
37 * +--------+----+--------+----+-----+---------+------------+------------+-----+
38 * | authid | op | handle | id | rid | authlen | msg values | obj values | sig |
39 * +--------+----+--------+----+-----+---------+------v-----+-----v------+--v--+
40 * NOTE: real life capture shows order to be: authid, authlen, opcode, handle...
42 * The message and object values consists of:
43 * +---------+------+----------+-------+
44 * | namelen | name | valuelen | value |
45 * +---16b---+--v---+----------+---v---+
52 #include <epan/packet.h>
53 #include <epan/ptvcursor.h>
55 static int proto_omapi = -1;
56 static int hf_omapi_version = -1;
57 static int hf_omapi_hlength = -1;
58 static int hf_omapi_auth_id = -1;
59 static int hf_omapi_auth_len = -1;
60 static int hf_omapi_opcode = -1;
61 static int hf_omapi_handle = -1;
62 static int hf_omapi_id = -1;
63 static int hf_omapi_rid = -1;
64 static int hf_omapi_msg_name_len = -1; /* 16bit */
65 static int hf_omapi_msg_name = -1;
66 static int hf_omapi_msg_value_len = -1;
67 static int hf_omapi_msg_value = -1;
68 static int hf_omapi_obj_name_len = -1; /* 16bit */
69 static int hf_omapi_obj_name = -1;
70 static int hf_omapi_obj_value_len = -1;
71 static int hf_omapi_obj_value = -1;
72 static int hf_omapi_signature = -1;
74 static gint ett_omapi = -1;
76 #define OMAPI_PORT 7911
84 #define OP_NOTIFY_CANCEL 7
85 #define OP_NOTIFY_CANCELLED 8
87 static const value_string omapi_opcode_vals[] = {
89 { OP_REFRESH, "Refresh" },
90 { OP_UPDATE, "Update" },
91 { OP_NOTIFY, "Notify" },
92 { OP_ERROR, "Error" },
93 { OP_DELETE, "Delete" },
94 { OP_NOTIFY_CANCEL, "Notify cancel" },
95 { OP_NOTIFY_CANCELLED,"Notify cancelled" },
100 dissect_omapi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
103 proto_tree *omapi_tree;
111 if (check_col(pinfo->cinfo, COL_PROTOCOL))
113 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OMAPI");
116 if (check_col(pinfo->cinfo, COL_INFO))
118 col_clear(pinfo->cinfo, COL_INFO);
121 ti = proto_tree_add_item(tree, proto_omapi, tvb, 0, -1, FALSE);
122 omapi_tree = proto_item_add_subtree(ti, ett_omapi);
123 cursor = ptvcursor_new(omapi_tree, tvb, 0);
125 if (tvb_reported_length_remaining(tvb, 0) < 8)
127 /* Payload too small for OMAPI */
128 DISSECTOR_ASSERT_NOT_REACHED();
130 else if (tvb_reported_length_remaining(tvb, 0) < 24)
132 /* This is a startup message */
133 ptvcursor_add(cursor, hf_omapi_version, 4, FALSE);
134 ptvcursor_add(cursor, hf_omapi_hlength, 4, FALSE);
136 if (check_col(pinfo->cinfo, COL_INFO))
138 col_set_str(pinfo->cinfo, COL_INFO, "Status message");
140 proto_item_append_text(ti, ", Status message");
145 ptvcursor_add(cursor, hf_omapi_auth_id, 4, FALSE);
146 authlength = tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor));
147 ptvcursor_add(cursor, hf_omapi_auth_len, 4, FALSE);
149 if (check_col(pinfo->cinfo, COL_INFO))
151 col_add_str(pinfo->cinfo, COL_INFO,
152 val_to_str(tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor)), omapi_opcode_vals, "Unknown opcode (0x%04x)"));
154 proto_item_append_text(ti, ", Opcode: %s",
155 val_to_str(tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor)), omapi_opcode_vals, "Unknown opcode (0x%04x)"));
157 ptvcursor_add(cursor, hf_omapi_opcode, 4, FALSE);
158 ptvcursor_add(cursor, hf_omapi_handle, 4, FALSE);
159 ptvcursor_add(cursor, hf_omapi_id, 4, FALSE);
160 ptvcursor_add(cursor, hf_omapi_rid, 4, FALSE);
162 msglength = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
165 ptvcursor_add(cursor, hf_omapi_msg_name_len, 2, FALSE);
166 ptvcursor_add(cursor, hf_omapi_msg_name, msglength, FALSE);
167 msglength = tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor));
168 ptvcursor_add(cursor, hf_omapi_msg_value_len, 4, FALSE);
172 proto_tree_add_text(omapi_tree, tvb, 0, 0, "Empty string");
174 else if (msglength == (guint32)~0)
176 proto_tree_add_text(omapi_tree, tvb, 0, 0, "No value");
180 ptvcursor_add(cursor, hf_omapi_msg_value, msglength, FALSE);
183 msglength = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
186 proto_tree_add_text(omapi_tree, tvb, ptvcursor_current_offset(cursor), 2, "Message end tag");
187 ptvcursor_advance(cursor, 2);
189 objlength = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
192 ptvcursor_add(cursor, hf_omapi_obj_name_len, 2, FALSE);
193 ptvcursor_add(cursor, hf_omapi_obj_name, objlength, FALSE);
194 objlength = tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor));
195 ptvcursor_add(cursor, hf_omapi_obj_value_len, 4, FALSE);
199 proto_tree_add_text(omapi_tree, tvb, 0, 0, "Empty string");
201 else if (objlength == (guint32)~0)
203 proto_tree_add_text(omapi_tree, tvb, 0, 0, "No value");
207 ptvcursor_add(cursor, hf_omapi_obj_value, objlength, FALSE);
210 objlength = tvb_get_ntohs(tvb, ptvcursor_current_offset(cursor));
213 proto_tree_add_text(omapi_tree, tvb, ptvcursor_current_offset(cursor), 2, "Object end tag");
214 ptvcursor_advance(cursor, 2);
216 if (authlength > 0) {
217 ptvcursor_add(cursor, hf_omapi_signature, authlength, FALSE);
222 proto_register_omapi(void)
224 static hf_register_info hf[] = {
226 { "Version", "omapi.version",
227 FT_UINT32, BASE_DEC, NULL, 0x0,
230 { "Header length", "omapi.hlength",
231 FT_UINT32, BASE_DEC, NULL, 0x0,
234 { "Authentication ID", "omapi.authid",
235 FT_UINT32, BASE_DEC, NULL, 0x0,
237 { &hf_omapi_auth_len,
238 { "Authentication length", "omapi.authlength",
239 FT_UINT32, BASE_DEC, NULL, 0x0,
242 { "Opcode", "omapi.opcode",
243 FT_UINT32, BASE_DEC, VALS(omapi_opcode_vals), 0x0,
246 { "Handle", "omapi.handle",
247 FT_UINT32, BASE_DEC, NULL, 0x0,
251 FT_UINT32, BASE_DEC, NULL, 0x0,
254 { "Response ID", "omapi.rid",
255 FT_UINT32, BASE_DEC, NULL, 0x0,
257 { &hf_omapi_msg_name_len,
258 { "Message name length", "omapi.msg_name_length",
259 FT_UINT16, BASE_DEC, NULL, 0x0,
261 { &hf_omapi_msg_name,
262 { "Message name", "omapi.msg_name",
263 FT_STRING, BASE_NONE, NULL, 0x0,
265 { &hf_omapi_msg_value_len,
266 { "Message value length", "omapi.msg_value_length",
267 FT_UINT32, BASE_DEC, NULL, 0x0,
269 { &hf_omapi_msg_value,
270 { "Message value", "omapi.msg_value",
271 FT_STRING, BASE_NONE, NULL, 0x0,
273 { &hf_omapi_obj_name_len,
274 { "Object name length", "omapi.obj_name_length",
275 FT_UINT16, BASE_DEC, NULL, 0x0,
277 { &hf_omapi_obj_name,
278 { "Object name", "omapi.obj_name",
279 FT_STRING, BASE_NONE, NULL, 0x0,
281 { &hf_omapi_obj_value_len,
282 { "Object value length", "omapi.object_value_length",
283 FT_UINT32, BASE_DEC, NULL, 0x0,
285 { &hf_omapi_obj_value,
286 { "Object value", "omapi.obj_value",
287 FT_BYTES, BASE_NONE, NULL, 0x0,
289 { &hf_omapi_signature,
290 { "Signature", "omapi.signature",
291 FT_BYTES, BASE_NONE, NULL, 0x0,
295 static gint *ett[] = {
299 proto_omapi = proto_register_protocol("ISC Object Management API", "OMAPI", "omapi");
300 proto_register_field_array(proto_omapi, hf, array_length(hf));
301 proto_register_subtree_array(ett, array_length(ett));
305 proto_reg_handoff_omapi(void)
307 dissector_handle_t omapi_handle;
309 omapi_handle = create_dissector_handle(dissect_omapi, proto_omapi);
310 dissector_add("tcp.port", OMAPI_PORT, omapi_handle);