1 /* packet-rmcp.c
2 * Routines for RMCP packet dissection
3 *
4 * Duncan Laurie <duncan@sun.com>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * Copied from packet-tftp.c
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 */
14
15 #include "config.h"
16
17 #include <epan/packet.h>
18
19 void proto_register_rmcp(void);
20 void proto_register_rsp(void);
21 void proto_reg_handoff_rmcp(void);
22 void proto_reg_handoff_rsp(void);
23
24 /*
25 * See
26 * http://www.dmtf.org/standards/standard_alert.php
27 * http://www.dmtf.org/standards/documents/ASF/DSP0136.pdf
28 * (the ASF specification includes RMCP)
29 */
30
31 static int proto_rmcp = -1;
32 static int hf_rmcp_version = -1;
33 static int hf_rmcp_reserved = -1;
34 static int hf_rmcp_sequence = -1;
35 static int hf_rmcp_class = -1;
36 static int hf_rmcp_type = -1;
37 static int hf_rmcp_trailer = -1;
38
39 static int proto_rsp = -1;
40 static int hf_rsp_session_id = -1;
41 static int hf_rsp_sequence = -1;
42
43 static gint ett_rmcp = -1;
44 static gint ett_rmcp_typeclass = -1;
45
46 static gint ett_rsp = -1;
47
48 static dissector_table_t rmcp_dissector_table;
49
50 #define UDP_PORT_RMCP 623
51 #define UDP_PORT_RMCP_SECURE 664
52
53 #define RMCP_TYPE_MASK 0x80
54 #define RMCP_TYPE_NORM 0x00
55 #define RMCP_TYPE_ACK 0x01
56
57 static const value_string rmcp_type_vals[] = {
58 { RMCP_TYPE_NORM, "Normal RMCP" },
59 { RMCP_TYPE_ACK, "RMCP ACK" },
60 { 0, NULL }
61 };
62
63 #define RMCP_CLASS_MASK 0x1f
64 #define RMCP_CLASS_ASF 0x06
65 #define RMCP_CLASS_IPMI 0x07
66 #define RMCP_CLASS_OEM 0x08
67
68 static const value_string rmcp_class_vals[] = {
69 { RMCP_CLASS_ASF, "ASF" },
70 { RMCP_CLASS_IPMI, "IPMI" },
71 { RMCP_CLASS_OEM, "OEM" },
72 { 0, NULL }
73 };
74
75 static int
dissect_rmcp(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)76 dissect_rmcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
77 {
78 proto_tree *rmcp_tree = NULL, *field_tree;
79 proto_item *ti;
80 tvbuff_t *next_tvb;
81 guint8 rmcp_class;
82 const gchar *class_str;
83 guint8 type;
84 guint len;
85
86 /*
87 * Check whether it's a known class value; if not, assume it's
88 * not RMCP.
89 */
90 if (!tvb_bytes_exist(tvb, 3, 1))
91 return 0; /* class value byte not present */
92 rmcp_class = tvb_get_guint8(tvb, 3);
93
94 /* Get the normal/ack bit from the RMCP class */
95 type = (rmcp_class & RMCP_TYPE_MASK) >> 7;
96 rmcp_class &= RMCP_CLASS_MASK;
97
98 class_str = try_val_to_str(rmcp_class, rmcp_class_vals);
99 if (class_str == NULL)
100 return 0; /* unknown class value */
101
102 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMCP");
103 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, Class: %s",
104 val_to_str(type, rmcp_type_vals, "Unknown (0x%02x)"),
105 class_str);
106
107 if (tree) {
108 ti = proto_tree_add_protocol_format(tree, proto_rmcp, tvb, 0, 4,
109 "Remote Management Control Protocol, Class: %s",
110 class_str);
111 rmcp_tree = proto_item_add_subtree(ti, ett_rmcp);
112
113 proto_tree_add_item(rmcp_tree, hf_rmcp_version, tvb, 0, 1, ENC_LITTLE_ENDIAN);
114 proto_tree_add_item(rmcp_tree, hf_rmcp_reserved, tvb, 1, 1, ENC_LITTLE_ENDIAN);
115 proto_tree_add_item(rmcp_tree, hf_rmcp_sequence, tvb, 2, 1, ENC_LITTLE_ENDIAN);
116
117 field_tree = proto_tree_add_subtree_format(rmcp_tree, tvb, 3, 1,
118 ett_rmcp_typeclass, NULL, "Type: %s, Class: %s",
119 val_to_str(type, rmcp_type_vals, "Unknown (0x%02x)"),
120 class_str);
121
122 proto_tree_add_item(field_tree, hf_rmcp_class, tvb, 3, 1, ENC_LITTLE_ENDIAN);
123 proto_tree_add_item(field_tree, hf_rmcp_type, tvb, 3, 1, ENC_LITTLE_ENDIAN);
124 }
125
126 if (!type){ /* do not expect a data block for an ACK */
127
128 next_tvb = tvb_new_subset_remaining(tvb, 4);
129
130 if (!dissector_try_uint(rmcp_dissector_table, rmcp_class, next_tvb, pinfo,
131 tree)) {
132 len = call_data_dissector(next_tvb, pinfo, tree);
133 if (len < tvb_reported_length(next_tvb)) {
134 proto_tree_add_item(tree, hf_rmcp_trailer, tvb, 4 + len, -1, ENC_NA);
135 }
136 }
137 }
138
139 return tvb_captured_length(tvb);
140 }
141
142 static int
dissect_rsp(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)143 dissect_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
144 {
145 proto_tree *rsp_tree = NULL/*, *field_tree*/;
146 proto_item *ti/*, *tf*/;
147 tvbuff_t *next_tvb;
148 int offset = 0;
149
150 if (tree) {
151 ti = proto_tree_add_protocol_format(tree, proto_rsp, tvb, offset, 8,
152 "RMCP Security-extension Protocol");
153 rsp_tree = proto_item_add_subtree(ti, ett_rsp);
154
155 proto_tree_add_item(rsp_tree, hf_rsp_session_id, tvb, offset, 4, ENC_BIG_ENDIAN);
156 offset += 4;
157 proto_tree_add_item(rsp_tree, hf_rsp_sequence, tvb, offset, 4, ENC_BIG_ENDIAN);
158 /*offset += 4;*/
159 }
160
161 /* XXX determination of RCMP message length needs to
162 * be done according to 3.2.3.3.3 of the specification.
163 * This is only valid for session ID equals 0
164 */
165 next_tvb = tvb_new_subset_remaining(tvb, 8);
166 dissect_rmcp(next_tvb, pinfo, tree, NULL);
167
168 return tvb_captured_length(tvb);
169 }
170
171 void
proto_register_rmcp(void)172 proto_register_rmcp(void)
173 {
174 static hf_register_info hf[] = {
175 { &hf_rmcp_version, {
176 "Version", "rmcp.version",
177 FT_UINT8, BASE_HEX, NULL, 0,
178 "RMCP Version", HFILL }},
179 { &hf_rmcp_reserved, {
180 "Reserved", "rmcp.reserved",
181 FT_UINT8, BASE_HEX, NULL, 0,
182 "RMCP Reserved", HFILL }},
183 { &hf_rmcp_sequence, {
184 "Sequence", "rmcp.sequence",
185 FT_UINT8, BASE_HEX, NULL, 0,
186 "RMCP Sequence", HFILL }},
187 { &hf_rmcp_class, {
188 "Class", "rmcp.class",
189 FT_UINT8, BASE_HEX,
190 VALS(rmcp_class_vals), RMCP_CLASS_MASK,
191 "RMCP Class", HFILL }},
192 { &hf_rmcp_type, {
193 "Message Type", "rmcp.type",
194 FT_UINT8, BASE_HEX,
195 VALS(rmcp_type_vals), RMCP_TYPE_MASK,
196 "RMCP Message Type", HFILL }},
197 { &hf_rmcp_trailer, {
198 "RSP Trailer", "rmcp.trailer",
199 FT_BYTES, BASE_NONE, NULL, 0,
200 NULL, HFILL }},
201 };
202 static gint *ett[] = {
203 &ett_rmcp,
204 &ett_rmcp_typeclass
205 };
206
207 proto_rmcp = proto_register_protocol(
208 "Remote Management Control Protocol", "RMCP", "rmcp");
209
210 proto_register_field_array(proto_rmcp, hf, array_length(hf));
211 proto_register_subtree_array(ett, array_length(ett));
212
213 rmcp_dissector_table = register_dissector_table(
214 "rmcp.class", "RMCP Class", proto_rmcp, FT_UINT8, BASE_HEX);
215 }
216
217 void
proto_register_rsp(void)218 proto_register_rsp(void)
219 {
220 static hf_register_info hf[] = {
221 { &hf_rsp_session_id, {
222 "Session ID", "rsp.session_id",
223 FT_UINT32, BASE_HEX, NULL, 0,
224 "RSP session ID", HFILL }},
225 { &hf_rsp_sequence, {
226 "Sequence", "rsp.sequence",
227 FT_UINT32, BASE_HEX, NULL, 0,
228 "RSP sequence", HFILL }},
229 };
230 static gint *ett[] = {
231 &ett_rsp
232 };
233
234 proto_rsp = proto_register_protocol(
235 "RMCP Security-extensions Protocol", "RSP", "rsp");
236 proto_register_field_array(proto_rsp, hf, array_length(hf));
237 proto_register_subtree_array(ett, array_length(ett));
238 }
239
240 void
proto_reg_handoff_rmcp(void)241 proto_reg_handoff_rmcp(void)
242 {
243 dissector_handle_t rmcp_handle;
244
245 rmcp_handle = create_dissector_handle(dissect_rmcp, proto_rmcp);
246 dissector_add_uint_with_preference("udp.port", UDP_PORT_RMCP, rmcp_handle);
247 }
248
249 void
proto_reg_handoff_rsp(void)250 proto_reg_handoff_rsp(void)
251 {
252 dissector_handle_t rsp_handle;
253
254 rsp_handle = create_dissector_handle(dissect_rsp, proto_rsp);
255 dissector_add_uint_with_preference("udp.port", UDP_PORT_RMCP_SECURE, rsp_handle);
256 }
257
258 /*
259 * Editor modelines - https://www.wireshark.org/tools/modelines.html
260 *
261 * Local variables:
262 * c-basic-offset: 8
263 * tab-width: 8
264 * indent-tabs-mode: t
265 * End:
266 *
267 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
268 * :indentSize=8:tabSize=8:noTabs=false:
269 */
270