1 /* packet-ipmi-session.c
2 * Routines for dissection of IPMI session wrapper (v1.5 and v2.0)
3 * Copyright 2007-2008, Alexey Neyman, Pigeon Point Systems <avn@pigeonpoint.com>
4 * Copyright Duncan Laurie <duncan@sun.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Partially copied from packet-ipmi.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.
32 #include <epan/packet.h>
34 void proto_register_ipmi_session(void);
35 void proto_reg_handoff_ipmi_session(void);
37 #define RMCP_CLASS_IPMI 0x07
39 static int proto_ipmi_session = -1;
41 static gint ett_ipmi_session = -1;
42 static gint ett_ipmi_session_payloadtype = -1;
44 /* IPMI session header */
45 static int hf_ipmi_session_id = -1;
46 static int hf_ipmi_session_authtype = -1;
47 static int hf_ipmi_session_payloadtype = -1;
48 static int hf_ipmi_session_payloadtype_auth = -1;
49 static int hf_ipmi_session_payloadtype_enc = -1;
50 static int hf_ipmi_session_oem_iana = -1;
51 static int hf_ipmi_session_oem_payload_id = -1;
52 static int hf_ipmi_session_sequence = -1;
53 static int hf_ipmi_session_authcode = -1;
54 static int hf_ipmi_session_msg_len_1b = -1;
55 static int hf_ipmi_session_msg_len_2b = -1;
56 static int hf_ipmi_session_trailer = -1;
58 static dissector_handle_t ipmi_handle;
59 static dissector_handle_t data_handle;
61 #define IPMI_AUTH_NONE 0x00
62 #define IPMI_AUTH_MD2 0x01
63 #define IPMI_AUTH_MD5 0x02
64 #define IPMI_AUTH_PASSWORD 0x04
65 #define IPMI_AUTH_OEM 0x05
66 #define IPMI_AUTH_RMCPP 0x06
68 static const value_string ipmi_authtype_vals[] = {
69 { IPMI_AUTH_NONE, "NONE" },
70 { IPMI_AUTH_MD2, "MD2" },
71 { IPMI_AUTH_MD5, "MD5" },
72 { IPMI_AUTH_PASSWORD, "PASSWORD" },
73 { IPMI_AUTH_OEM, "OEM" },
74 { IPMI_AUTH_RMCPP, "RMCP+"},
78 #define IPMI_IPMI_MESSAGE 0
79 #define IPMI_OEM_EXPLICIT 2
81 static const value_string ipmi_payload_vals[] = {
82 { IPMI_IPMI_MESSAGE, "IPMI Message" },
83 { 0x01, "SOL (serial over LAN)" },
84 { IPMI_OEM_EXPLICIT, "OEM Explicit" },
85 /* Session Setup Payload Types */
86 { 0x10, "RMCP+ Open Session Request" },
87 { 0x11, "RMCP+ Open Session Response" },
88 { 0x12, "RAKP Message 1" },
89 { 0x13, "RAKP Message 2" },
90 { 0x14, "RAKP Message 3" },
91 { 0x15, "RAKP Message 4" },
92 /* OEM Payload Type Handles */
93 { 0x20, "OEM0 (OEM Payload)" },
94 { 0x21, "OEM1 (OEM Payload)" },
95 { 0x22, "OEM2 (OEM Payload)" },
96 { 0x23, "OEM3 (OEM Payload)" },
97 { 0x24, "OEM4 (OEM Payload)" },
98 { 0x25, "OEM5 (OEM Payload)" },
99 { 0x26, "OEM6 (OEM Payload)" },
100 { 0x27, "OEM7 (OEM Payload)" },
104 static const true_false_string ipmi_payload_aut_val = {
105 "Payload is authenticated",
106 "Payload is unauthenticated"
109 static const true_false_string ipmi_payload_enc_val = {
110 "Payload is encrypted",
111 "Payload is unencrypted"
115 dissect_ipmi_session(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
117 proto_tree *sess_tree = NULL, *s_tree;
118 proto_item *ti = NULL;
121 guint8 authtype, payloadtype = 0;
122 guint32 msg_start, msg_len, offset = 0;
123 gboolean payloadtype_auth = 0, payloadtype_enc = 0;
125 /* session authtype, 0=no authcode present, 6=RMCP+ */
126 authtype = tvb_get_guint8(tvb, 0);
127 if (authtype == IPMI_AUTH_RMCPP) {
128 /* Fetch additional info before trying to interpret
129 the packet. It may not be IPMI at all! */
130 payloadtype = tvb_get_guint8(tvb, 1);
131 payloadtype_auth = (payloadtype >> 6) & 1;
132 payloadtype_enc = (payloadtype >> 7);
135 /* IPMI v2.0 packets have session ID BEFORE the session
136 sequence number; just after authentification and payload
137 types. The OEM Explicit payload type has 6 more bytes
138 (IANA + Payload ID) before the session ID. */
139 if (payloadtype == IPMI_OEM_EXPLICIT) {
140 session_id = tvb_get_letohl(tvb, 8);
142 msg_len = tvb_get_letohs(tvb, 16);
144 session_id = tvb_get_letohl(tvb, 2);
146 msg_len = tvb_get_letohs(tvb, 10);
149 /* IPMI v1.5 packets have session ID AFTER the session
150 sequence number. They also have 1 byte for payload
152 session_id = tvb_get_letohl(tvb, 5);
153 if (authtype == IPMI_AUTH_NONE) {
155 msg_len = tvb_get_guint8(tvb, 9);
158 msg_len = tvb_get_guint8(tvb, 25);
162 /* Later it will be overridden with sub-dissector, if any */
163 if (authtype == IPMI_AUTH_RMCPP) {
164 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMCP+");
166 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPMI");
169 col_add_fstr(pinfo->cinfo, COL_INFO, "Session ID 0x%x", session_id);
170 if (authtype == IPMI_AUTH_RMCPP) {
171 col_append_fstr(pinfo->cinfo, COL_INFO, ", payload type: %s",
172 val_to_str_const(payloadtype, ipmi_payload_vals, "Unknown"));
177 ti = proto_tree_add_protocol_format(tree, proto_ipmi_session,
178 tvb, 0, tvb_length(tvb),
179 "IPMI v%s Session Wrapper, session ID 0x%x",
180 authtype == IPMI_AUTH_RMCPP ? "2.0+" : "1.5",
182 sess_tree = proto_item_add_subtree(ti, ett_ipmi_session);
183 proto_tree_add_item(sess_tree, hf_ipmi_session_authtype, tvb, offset, 1, ENC_LITTLE_ENDIAN);
186 if (authtype == IPMI_AUTH_RMCPP) {
188 ti = proto_tree_add_text(sess_tree, tvb, offset, 1,
189 "Payload type: %s (0x%02x), %sencrypted, %sauthenticated",
190 val_to_str_const(payloadtype, ipmi_payload_vals, "Unknown"),
192 payloadtype_enc ? "" : "not ",
193 payloadtype_auth ? "" : "not ");
194 s_tree = proto_item_add_subtree(ti, ett_ipmi_session_payloadtype);
195 proto_tree_add_item(s_tree, hf_ipmi_session_payloadtype_enc, tvb, offset, 1, ENC_LITTLE_ENDIAN);
196 proto_tree_add_item(s_tree, hf_ipmi_session_payloadtype_auth, tvb, offset, 1, ENC_LITTLE_ENDIAN);
197 proto_tree_add_item(s_tree, hf_ipmi_session_payloadtype, tvb, offset, 1, ENC_LITTLE_ENDIAN);
200 if (payloadtype == IPMI_OEM_EXPLICIT) {
201 proto_tree_add_item(sess_tree, hf_ipmi_session_oem_iana, tvb, offset, 4, ENC_NA);
203 proto_tree_add_item(sess_tree, hf_ipmi_session_oem_payload_id, tvb, offset, 2, ENC_NA);
206 proto_tree_add_item(sess_tree, hf_ipmi_session_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
208 proto_tree_add_item(sess_tree, hf_ipmi_session_sequence, tvb, offset, 4, ENC_LITTLE_ENDIAN);
210 proto_tree_add_item(sess_tree, hf_ipmi_session_msg_len_2b, tvb, offset, 2, ENC_LITTLE_ENDIAN);
214 proto_tree_add_item(sess_tree, hf_ipmi_session_sequence, tvb, offset, 4, ENC_LITTLE_ENDIAN);
216 proto_tree_add_item(sess_tree, hf_ipmi_session_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
218 if (authtype != IPMI_AUTH_NONE) {
219 proto_tree_add_item(sess_tree, hf_ipmi_session_authcode,
220 tvb, offset, 16, ENC_NA);
223 proto_tree_add_item(sess_tree, hf_ipmi_session_msg_len_1b, tvb, offset, 1, ENC_LITTLE_ENDIAN);
228 /* If we can parse the embedded message, do so */
229 next_tvb = tvb_new_subset(tvb, msg_start, msg_len, -1);
230 if (payloadtype_enc) {
231 /* This is RMCP+, and payload is encrypted. In this case,
232 there is a 'confidentiality header/trailer', whose lengths
233 are unknown to us. These lengths are negotiated during
234 session open process and are retained over a session.
235 Since we are stateless (and more, we may have no session
236 open packet in the capture we parse), we cannot even
237 decipher where a message starts. Just print them as data.
239 call_dissector(data_handle, next_tvb, pinfo, tree);
240 } else if (authtype != IPMI_AUTH_RMCPP || payloadtype == IPMI_IPMI_MESSAGE) {
241 /* This is an IPMI message, either v1.5 or v2.0+. For now,
242 we don't need to distinguish these kinds. */
243 call_dissector(ipmi_handle, next_tvb, pinfo, tree);
245 /* All other RMCP+ payload types fall here: session open/close
246 requests, RAKP messages, SOL. We cannot parse them yet, thus
247 just output as data. */
248 call_dissector(data_handle, next_tvb, pinfo, tree);
252 /* Account for the message we just parsed. */
255 /* Show the rest of the session wrapper as binary data */
256 if (offset < tvb_length(tvb)) {
257 proto_tree_add_item(sess_tree, hf_ipmi_session_trailer,
258 tvb, offset, tvb_length(tvb) - offset, ENC_NA);
261 return tvb_length(tvb);
265 proto_register_ipmi_session(void)
267 static hf_register_info hf[] = {
268 { &hf_ipmi_session_authtype, {
269 "Authentication Type", "ipmi_session.authtype",
270 FT_UINT8, BASE_HEX, VALS(ipmi_authtype_vals), 0, NULL, HFILL }},
271 { &hf_ipmi_session_payloadtype,{
272 "Payload Type", "ipmi_session.payloadtype",
273 FT_UINT8, BASE_HEX, VALS(ipmi_payload_vals), 0x3f, NULL, HFILL }},
274 { &hf_ipmi_session_payloadtype_auth,{
275 "Authenticated","ipmi_session.payloadtype.auth",
276 FT_BOOLEAN,8, TFS(&ipmi_payload_aut_val), 0x40, NULL, HFILL }},
277 { &hf_ipmi_session_payloadtype_enc,{
278 "Encryption","ipmi_session.payloadtype.enc",
279 FT_BOOLEAN,8, TFS(&ipmi_payload_enc_val), 0x80, NULL, HFILL }},
280 { &hf_ipmi_session_oem_iana, {
281 "OEM IANA", "ipmi_session.oem.iana",
282 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
283 { &hf_ipmi_session_oem_payload_id, {
284 "OEM Payload ID", "ipmi_session.oem.payloadid",
285 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
286 { &hf_ipmi_session_sequence, {
287 "Session Sequence Number", "ipmi_session.sequence",
288 FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }},
289 { &hf_ipmi_session_id, {
290 "Session ID", "ipmi_session.id",
291 FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }},
292 { &hf_ipmi_session_authcode, {
293 "Authentication Code", "ipmi_session.authcode",
294 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
295 { &hf_ipmi_session_msg_len_1b, {
296 "Message Length", "ipmi_session.msg.len",
297 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
298 { &hf_ipmi_session_msg_len_2b, {
299 "Message Length", "ipmi_session.msg.len",
300 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
301 { &hf_ipmi_session_trailer, {
302 "IPMI Session Wrapper (trailer)", "ipmi_session.trailer",
303 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
306 static gint *ett[] = { &ett_ipmi_session, &ett_ipmi_session_payloadtype };
308 proto_ipmi_session = proto_register_protocol(
309 "Intelligent Platform Management Interface (Session Wrapper)", "IPMI Session",
311 proto_register_field_array(proto_ipmi_session, hf, array_length(hf));
312 proto_register_subtree_array(ett, array_length(ett));
316 proto_reg_handoff_ipmi_session(void)
318 dissector_handle_t ipmi_session_handle;
320 ipmi_session_handle = new_create_dissector_handle(dissect_ipmi_session, proto_ipmi_session);
321 dissector_add_uint("rmcp.class", RMCP_CLASS_IPMI, ipmi_session_handle);
323 data_handle = find_dissector("data");
324 ipmi_handle = find_dissector("ipmi");