HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-rmcp.c
blobdc4d5ac30daf5e85ab2d17d3e230684a77d30c89
1 /* packet-rmcp.c
2 * Routines for RMCP packet dissection
4 * Duncan Laurie <duncan@sun.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-tftp.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <glib.h>
32 #include <epan/packet.h>
35 * See
36 * http://www.dmtf.org/standards/standard_alert.php
37 * http://www.dmtf.org/standards/documents/ASF/DSP0136.pdf
38 * (the ASF specification includes RMCP)
41 static int proto_rmcp = -1;
42 static int hf_rmcp_version = -1;
43 static int hf_rmcp_sequence = -1;
44 static int hf_rmcp_class = -1;
45 static int hf_rmcp_type = -1;
47 static int proto_rsp = -1;
48 static int hf_rsp_session_id = -1;
49 static int hf_rsp_sequence = -1;
51 static gint ett_rmcp = -1;
52 static gint ett_rmcp_typeclass = -1;
54 static gint ett_rsp = -1;
56 static dissector_handle_t data_handle;
57 static dissector_table_t rmcp_dissector_table;
59 #define UDP_PORT_RMCP 623
60 #define UDP_PORT_RMCP_SECURE 664
62 #define RMCP_TYPE_MASK 0x80
63 #define RMCP_TYPE_NORM 0x00
64 #define RMCP_TYPE_ACK 0x01
66 static const value_string rmcp_type_vals[] = {
67 { RMCP_TYPE_NORM, "Normal RMCP" },
68 { RMCP_TYPE_ACK, "RMCP ACK" },
69 { 0, NULL }
72 #define RMCP_CLASS_MASK 0x1f
73 #define RMCP_CLASS_ASF 0x06
74 #define RMCP_CLASS_IPMI 0x07
75 #define RMCP_CLASS_OEM 0x08
77 static const value_string rmcp_class_vals[] = {
78 { RMCP_CLASS_ASF, "ASF" },
79 { RMCP_CLASS_IPMI, "IPMI" },
80 { RMCP_CLASS_OEM, "OEM" },
81 { 0, NULL }
84 static int
85 dissect_rmcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
87 proto_tree *rmcp_tree = NULL, *field_tree;
88 proto_item *ti, *tf;
89 tvbuff_t *next_tvb;
90 guint8 rmcp_class;
91 const gchar *class_str;
92 guint8 type;
93 guint len;
96 * Check whether it's a known class value; if not, assume it's
97 * not RMCP.
99 if (!tvb_bytes_exist(tvb, 3, 1))
100 return 0; /* class value byte not present */
101 rmcp_class = tvb_get_guint8(tvb, 3);
103 /* Get the normal/ack bit from the RMCP class */
104 type = (rmcp_class & RMCP_TYPE_MASK) >> 7;
105 rmcp_class &= RMCP_CLASS_MASK;
107 class_str = try_val_to_str(rmcp_class, rmcp_class_vals);
108 if (class_str == NULL)
109 return 0; /* unknown class value */
111 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMCP");
112 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, Class: %s",
113 val_to_str(type, rmcp_type_vals, "Unknown (0x%02x)"),
114 class_str);
116 if (tree) {
117 ti = proto_tree_add_protocol_format(tree, proto_rmcp, tvb, 0, 4,
118 "Remote Management Control Protocol, Class: %s",
119 class_str);
120 rmcp_tree = proto_item_add_subtree(ti, ett_rmcp);
122 proto_tree_add_item(rmcp_tree, hf_rmcp_version, tvb, 0, 1, ENC_LITTLE_ENDIAN);
123 proto_tree_add_item(rmcp_tree, hf_rmcp_sequence, tvb, 2, 1, ENC_LITTLE_ENDIAN);
125 tf = proto_tree_add_text(rmcp_tree, tvb, 3, 1, "Type: %s, Class: %s",
126 val_to_str(type, rmcp_type_vals, "Unknown (0x%02x)"),
127 class_str);
129 field_tree = proto_item_add_subtree(tf, ett_rmcp_typeclass);
131 proto_tree_add_item(field_tree, hf_rmcp_class, tvb, 3, 1, ENC_LITTLE_ENDIAN);
132 proto_tree_add_item(field_tree, hf_rmcp_type, tvb, 3, 1, ENC_LITTLE_ENDIAN);
135 if (!type){ /* do not expect a data block for an ACK */
137 next_tvb = tvb_new_subset_remaining(tvb, 4);
139 if (!dissector_try_uint(rmcp_dissector_table, rmcp_class, next_tvb, pinfo,
140 tree)) {
141 len = call_dissector(data_handle, next_tvb, pinfo, tree);
142 if (len < tvb_length(next_tvb)) {
143 proto_tree_add_text(tree, tvb, 4 + len, -1,
144 "RSP Trailer (%d bytes):", tvb_length(next_tvb) - len);
149 return tvb_length(tvb);
152 static int
153 dissect_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
155 proto_tree *rsp_tree = NULL/*, *field_tree*/;
156 proto_item *ti/*, *tf*/;
157 tvbuff_t *next_tvb;
158 int offset = 0;
160 if (tree) {
161 ti = proto_tree_add_protocol_format(tree, proto_rsp, tvb, offset, 8,
162 "RMCP Security-extension Protocol");
163 rsp_tree = proto_item_add_subtree(ti, ett_rsp);
165 proto_tree_add_item(rsp_tree, hf_rsp_session_id, tvb, offset, 4, ENC_BIG_ENDIAN);
166 offset += 4;
167 proto_tree_add_item(rsp_tree, hf_rsp_sequence, tvb, offset, 4, ENC_BIG_ENDIAN);
168 /*offset += 4;*/
171 /* XXX determination of RCMP message length needs to
172 * be done according to 3.2.3.3.3 of the specification.
173 * This is only valid for session ID equals 0
175 next_tvb = tvb_new_subset_remaining(tvb, 8);
176 dissect_rmcp(next_tvb, pinfo, tree, NULL);
178 return tvb_length(tvb);
181 void
182 proto_register_rmcp(void)
184 static hf_register_info hf[] = {
185 { &hf_rmcp_version, {
186 "Version", "rmcp.version",
187 FT_UINT8, BASE_HEX, NULL, 0,
188 "RMCP Version", HFILL }},
189 { &hf_rmcp_sequence, {
190 "Sequence", "rmcp.sequence",
191 FT_UINT8, BASE_HEX, NULL, 0,
192 "RMCP Sequence", HFILL }},
193 { &hf_rmcp_class, {
194 "Class", "rmcp.class",
195 FT_UINT8, BASE_HEX,
196 VALS(rmcp_class_vals), RMCP_CLASS_MASK,
197 "RMCP Class", HFILL }},
198 { &hf_rmcp_type, {
199 "Message Type", "rmcp.type",
200 FT_UINT8, BASE_HEX,
201 VALS(rmcp_type_vals), RMCP_TYPE_MASK,
202 "RMCP Message Type", HFILL }}
204 static gint *ett[] = {
205 &ett_rmcp,
206 &ett_rmcp_typeclass
209 proto_rmcp = proto_register_protocol(
210 "Remote Management Control Protocol", "RMCP", "rmcp");
212 proto_register_field_array(proto_rmcp, hf, array_length(hf));
213 proto_register_subtree_array(ett, array_length(ett));
215 rmcp_dissector_table = register_dissector_table(
216 "rmcp.class", "RMCP Class", FT_UINT8, BASE_HEX);
219 void
220 proto_register_rsp(void)
222 static hf_register_info hf[] = {
223 { &hf_rsp_session_id, {
224 "Session ID", "rsp.session_id",
225 FT_UINT32, BASE_HEX, NULL, 0,
226 "RSP session ID", HFILL }},
227 { &hf_rsp_sequence, {
228 "Sequence", "rsp.sequence",
229 FT_UINT32, BASE_HEX, NULL, 0,
230 "RSP sequence", HFILL }},
232 static gint *ett[] = {
233 &ett_rsp
236 proto_rsp = proto_register_protocol(
237 "RMCP Security-extensions Protocol", "RSP", "rsp");
238 proto_register_field_array(proto_rsp, hf, array_length(hf));
239 proto_register_subtree_array(ett, array_length(ett));
242 void
243 proto_reg_handoff_rmcp(void)
245 dissector_handle_t rmcp_handle;
247 data_handle = find_dissector("data");
249 rmcp_handle = new_create_dissector_handle(dissect_rmcp, proto_rmcp);
250 dissector_add_uint("udp.port", UDP_PORT_RMCP, rmcp_handle);
253 void
254 proto_reg_handoff_rsp(void)
256 dissector_handle_t rsp_handle;
258 rsp_handle = new_create_dissector_handle(dissect_rsp, proto_rsp);
259 dissector_add_uint("udp.port", UDP_PORT_RMCP_SECURE, rsp_handle);