2 * Routines for HPM.2 Trace Data Block disassembly
3 * By Dmitry Bazhenov <dima_b@pigeonpoint.com>
4 * Copyright 2014 Pigeon Point Systems
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <wiretap/wtap.h>
17 #include "packet-ipmi.h"
22 * http://www.picmg.org/v2internal/resourcepage2.cfm?id=12
25 /* Trace data block types. */
27 HPM2_TRACE_PACKET_DATA
= 0,
28 HPM2_CHN_STATE_NOTIFY
= 1,
29 HPM2_EMBED_ASCII_MSG
= 2
32 /* Data directions. */
34 HPM2_TRACE_DATA_OUT
= 0, /* From IPM controller */
35 HPM2_TRACE_DATA_IN
= 1 /* To IPM controller */
38 /* Redundant channel indicators. */
40 HPM2_TRACE_1ST_CHN
= 0,
41 HPM2_TRACE_2ND_CHN
= 1
44 /* IPMB local status values. */
47 HPM2_IPMB_S_ERR_SCL_HI
= 1,
48 HPM2_IPMB_S_ERR_SDA_HI
= 2,
49 HPM2_IPMB_S_ERR_SCL_LO
= 3,
50 HPM2_IPMB_S_ERR_SDA_LO
= 4,
51 HPM2_IPMB_S_SCL_TIMEOUT
= 5,
52 HPM2_IPMB_S_UNDER_TEST
= 6,
53 HPM2_IPMB_S_UNKNOWN_ERR
= 7
56 /* IPMI channel protocol types. */
58 IPMI_PROTO_IPMB_1_0
= 0x01,
59 IPMI_PROTO_ICMB_1_0
= 0x02,
60 IPMI_PROTO_IPMI_SMBUS
= 0x04,
61 IPMI_PROTO_KCS
= 0x05,
62 IPMI_PROTO_SMIC
= 0x06,
63 IPMI_PROTO_BT_10
= 0x07,
64 IPMI_PROTO_BT_15
= 0x08,
65 IPMI_PROTO_TMODE
= 0x09,
66 IPMI_PROTO_OEM_1
= 0x1C,
67 IPMI_PROTO_OEM_2
= 0x1D,
68 IPMI_PROTO_OEM_3
= 0x1E,
69 IPMI_PROTO_OEM_4
= 0x1F
72 /* IPMB override status values. */
74 HPM2_IPMB_S_ISOLATED
= 0,
75 HPM2_IPMB_S_LOCAL_CTRL
= 1
78 void proto_register_ipmi_trace(void);
79 void proto_reg_handoff_ipmi_trace(void);
81 static dissector_handle_t ipmi_trace_handle
;
83 static int proto_ipmi_trace
;
85 static dissector_table_t proto_dissector_table
;
87 static int ett_ipmi_trace
;
88 static int ett_trace_block_type
;
89 static int ett_trace_timestamp
;
90 static int ett_trace_protocol_data
;
91 static int ett_trace_ipmb_state
;
93 static int hf_trace_block_type
;
94 static int hf_trace_channel_num
;
95 static int hf_trace_packet_type
;
96 static int hf_trace_timestamp
;
97 static int hf_trace_timestamp_sec
;
98 static int hf_trace_timestamp_msec
;
99 static int hf_trace_data_type
;
100 static int hf_trace_protocol_data
;
101 static int hf_trace_dir
;
102 static int hf_trace_ipmb_red_chn
;
103 static int hf_trace_ipmb_link_num
;
104 static int hf_trace_data_len
;
105 static int hf_trace_notify_format
;
106 static int hf_trace_ipmb_state
;
107 static int hf_trace_ipmb_ovr_state
;
108 static int hf_trace_ipmb_loc_state
;
110 static const value_string str_packet_types
[] = {
111 { 0, "IPMI Trace Packet Data" },
112 { 1, "Channel State Change Notification" },
113 { 2, "Embedded ASCII message" },
117 static const value_string str_protocol_types
[] = {
127 { 0x1C, "OEM Protocol 1" },
128 { 0x1D, "OEM Protocol 2" },
129 { 0x1E, "OEM Protocol 3" },
130 { 0x1F, "OEM Protocol 4" },
134 static const value_string str_redund_chns
[] = {
135 { 0, "First channel" },
136 { 1, "Second channel" },
140 static const value_string str_trace_dirs
[] = {
141 { 0, "From IPM Controller" },
142 { 1, "To IPM Controller" },
146 static const value_string str_ipmb_notify_formats
[] = {
147 { 0, "Derived from PICMG 3.0" },
151 static const value_string str_ipmb_ovr_statuses
[] = {
152 { 0, "Override status, bus isolated" },
153 { 1, "Local Control State" },
157 static const value_string str_ipmb_loc_statuses
[] = {
159 { 1, "Unable to drive clock HI" },
160 { 2, "Unable to drive data HI" },
161 { 3, "Unable to drive clock LO" },
162 { 4, "Unable to drive data LO" },
163 { 5, "Clock low timeout" },
165 { 7, "Undiagnosed Communications Failure" },
169 static int * const bits_trace_block_type
[] = {
170 &hf_trace_channel_num
,
171 &hf_trace_packet_type
,
175 static int * const bits_ipmb_protocol_data
[] = {
176 &hf_trace_ipmb_link_num
,
177 &hf_trace_ipmb_red_chn
,
182 static int * const bits_host_protocol_data
[] = {
187 static int * const bits_chn_state_info
[] = {
188 &hf_trace_ipmb_ovr_state
,
189 &hf_trace_ipmb_loc_state
,
193 /* HPM.2 Trace Collection tree indices. */
194 static int * ipmi_trace_ett
[] = {
196 &ett_trace_block_type
,
197 &ett_trace_timestamp
,
198 &ett_trace_protocol_data
,
199 &ett_trace_ipmb_state
202 /* HPM.2 Trace Collection header fields. */
203 static hf_register_info ipmi_trace_hf
[] = {
204 { &hf_trace_block_type
, {
205 "Trace Data Block Type", "ipmi.trace.block.type",
206 FT_UINT8
, BASE_HEX
, NULL
, 0, NULL
, HFILL
} },
207 { &hf_trace_channel_num
, {
208 "IPMI Channel Number being traced", "ipmi.trace.chn.num",
209 FT_UINT8
, BASE_DEC_HEX
, NULL
, 0x0F, NULL
, HFILL
} },
210 { &hf_trace_packet_type
, {
211 "Packet Type", "ipmi.trace.packet.type",
212 FT_UINT8
, BASE_DEC
, VALS(str_packet_types
), 0x30, NULL
, HFILL
} },
213 { &hf_trace_timestamp
, {
214 "Timestamp", "ipmi.trace.stamp",
215 FT_RELATIVE_TIME
, BASE_NONE
, NULL
, 0, NULL
, HFILL
} },
216 { &hf_trace_timestamp_sec
, {
217 "Seconds part", "ipmi.trace.stamp.sec",
218 FT_UINT32
, BASE_DEC
, NULL
, 0, NULL
, HFILL
} },
219 { &hf_trace_timestamp_msec
, {
220 "Milliseconds part", "ipmi.trace.stamp.msec",
221 FT_UINT16
, BASE_DEC
, NULL
, 0, NULL
, HFILL
} },
222 { &hf_trace_data_type
, {
223 "Trace Data Type", "ipmi.trace.data.type",
224 FT_UINT8
, BASE_HEX
, VALS(str_protocol_types
), 0, NULL
, HFILL
} },
225 { &hf_trace_protocol_data
, {
226 "Additional protocol specific data", "ipmi.trace.proto.data",
227 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
} },
228 { &hf_trace_ipmb_link_num
, {
229 "Radial IPMB Link Number", "ipmi.trace.ipmb.link.num",
230 FT_UINT16
, BASE_DEC_HEX
, NULL
, 0x003F, NULL
, HFILL
} },
231 { &hf_trace_ipmb_red_chn
, {
232 "Redundant Channel Indicator", "ipmi.trace.ipmb.red.chn",
233 FT_UINT16
, BASE_DEC
, VALS(str_redund_chns
), 0x0040, NULL
, HFILL
} },
235 "Direction", "ipmi.trace.dir",
236 FT_UINT16
, BASE_DEC
, VALS(str_trace_dirs
), 0x0080, NULL
, HFILL
} },
237 { &hf_trace_data_len
, {
238 "Data length", "ipmi.trace.data.len",
239 FT_UINT8
, BASE_DEC_HEX
, NULL
, 0, NULL
, HFILL
} },
240 { &hf_trace_notify_format
, {
241 "Data format", "ipmi.trace.data.format",
242 FT_UINT8
, BASE_HEX
, VALS(str_ipmb_notify_formats
), 0, NULL
, HFILL
} },
243 { &hf_trace_ipmb_state
, {
244 "State Change Information", "ipmi.trace.ipmb.state",
245 FT_UINT8
, BASE_HEX
, NULL
, 0, NULL
, HFILL
} },
246 { &hf_trace_ipmb_ovr_state
, {
247 "IPMB Override status", "ipmi.trace.ipmb.state.ovr",
248 FT_UINT8
, BASE_DEC
, VALS(str_ipmb_ovr_statuses
), 0x8, NULL
, HFILL
} },
249 { &hf_trace_ipmb_loc_state
, {
250 "IPMB Local status", "ipmi.trace.ipmb.state.loc",
251 FT_UINT8
, BASE_DEC
, VALS(str_ipmb_loc_statuses
), 0x7, NULL
, HFILL
} },
255 dissect_ipmb_state_notify(tvbuff_t
* tvb
, proto_tree
* tree
)
257 /* add data format */
258 proto_tree_add_item(tree
, hf_trace_notify_format
,
259 tvb
, 0, 1, ENC_LITTLE_ENDIAN
);
261 /* add host-specific data */
262 proto_tree_add_bitmask(tree
, tvb
, 1,
263 hf_trace_ipmb_state
, ett_trace_ipmb_state
,
264 bits_chn_state_info
, ENC_LITTLE_ENDIAN
);
268 dissect_ipmi_trace(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
270 unsigned block_type
, chn_num
, data_type
, tmp
;
273 if (tvb_captured_length(tvb
) < 11) {
274 /* TODO: add expert info */
275 call_data_dissector(tvb
, pinfo
, tree
);
276 return tvb_captured_length(tvb
);
280 tmp
= tvb_get_uint8(tvb
, 0);
283 block_type
= (tmp
>> 4) & 3;
285 /* get channel number */
288 /* get trace data type */
289 data_type
= tvb_get_uint8(tvb
, 7);
292 col_add_fstr(pinfo
->cinfo
, COL_DEF_SRC
, "Channel %d", chn_num
);
293 col_add_str(pinfo
->cinfo
, COL_PROTOCOL
,
294 val_to_str(data_type
, str_protocol_types
,
295 "Reserved (0x%02x)"));
297 col_clear(pinfo
->cinfo
, COL_INFO
);
299 if (block_type
== HPM2_TRACE_PACKET_DATA
) {
300 col_set_str(pinfo
->cinfo
, COL_INFO
, "Trace Packet Data");
301 } else if (block_type
== HPM2_CHN_STATE_NOTIFY
) {
302 col_set_str(pinfo
->cinfo
, COL_INFO
,
303 "Channel State Change Notification");
304 } else if (block_type
== HPM2_EMBED_ASCII_MSG
) {
307 /* get data length */
308 unsigned str_len
= tvb_get_uint8(tvb
, 10);
312 str
= (char *) tvb_get_string_enc(pinfo
->pool
, tvb
, 11, str_len
, ENC_ASCII
|ENC_NA
);
314 /* print the string right inside the column */
315 col_add_str(pinfo
->cinfo
, COL_INFO
, str
);
318 col_set_str(pinfo
->cinfo
, COL_INFO
, "Reserved");
324 proto_tree
* trace_tree
;
325 proto_tree
* stamp_tree
;
328 /* add protocol label */
329 ti
= proto_tree_add_item(tree
, proto_ipmi_trace
, tvb
, 0, -1, ENC_NA
);
331 /* create protocol sub-tree */
332 trace_tree
= proto_item_add_subtree(ti
, ett_ipmi_trace
);
334 /* add block type/channel bitmask */
335 proto_tree_add_bitmask(trace_tree
, tvb
, 0, hf_trace_block_type
,
336 ett_trace_block_type
, bits_trace_block_type
,
339 /* get seconds part */
340 timestamp
.secs
= tvb_get_letohl(tvb
, 1);
342 /* get milliseconds part */
343 timestamp
.nsecs
= (int) tvb_get_letohs(tvb
, 5) * 1000000;
346 ti
= proto_tree_add_time(trace_tree
, hf_trace_timestamp
, tvb
, 1,
349 /* create timestamp sub-tree */
350 stamp_tree
= proto_item_add_subtree(ti
, ett_trace_timestamp
);
352 /* add seconds part */
353 proto_tree_add_item(stamp_tree
, hf_trace_timestamp_sec
,
354 tvb
, 1, 4, ENC_LITTLE_ENDIAN
);
356 /* add milliseconds part */
357 proto_tree_add_item(stamp_tree
, hf_trace_timestamp_msec
,
358 tvb
, 5, 2, ENC_LITTLE_ENDIAN
);
360 /* add trace data type */
361 proto_tree_add_item(trace_tree
, hf_trace_data_type
,
362 tvb
, 7, 1, ENC_LITTLE_ENDIAN
);
364 if (data_type
== IPMI_PROTO_IPMB_1_0
) {
365 /* add ipmb-specific data */
366 proto_tree_add_bitmask(trace_tree
, tvb
, 8,
367 hf_trace_protocol_data
, ett_trace_protocol_data
,
368 bits_ipmb_protocol_data
, ENC_LITTLE_ENDIAN
);
369 } else if (data_type
== IPMI_PROTO_KCS
370 || data_type
== IPMI_PROTO_SMIC
371 || data_type
== IPMI_PROTO_BT_10
372 || data_type
== IPMI_PROTO_BT_15
) {
373 /* add host-specific data */
374 proto_tree_add_bitmask(trace_tree
, tvb
, 8,
375 hf_trace_protocol_data
, ett_trace_protocol_data
,
376 bits_host_protocol_data
, ENC_LITTLE_ENDIAN
);
378 /* add protocol specific data */
379 proto_tree_add_item(trace_tree
, hf_trace_protocol_data
, tvb
,
380 8, 2, ENC_LITTLE_ENDIAN
);
384 proto_tree_add_item(trace_tree
, hf_trace_data_len
, tvb
,
385 10, 1, ENC_LITTLE_ENDIAN
);
388 /* get pointer to remaining data buffer */
389 next_tvb
= tvb_new_subset_remaining(tvb
, 11);
391 if (block_type
== HPM2_TRACE_PACKET_DATA
) {
392 ipmi_dissect_arg_t arg
;
394 /* setup IPMI protocol argument */
395 arg
.context
= IPMI_E_NONE
;
396 arg
.channel
= chn_num
;
397 arg
.flags
= tvb_get_uint8(tvb
, 8);
399 if (!dissector_try_uint_with_data(proto_dissector_table
,
400 data_type
, next_tvb
, pinfo
, tree
, true, &arg
)) {
401 call_data_dissector(next_tvb
, pinfo
, tree
);
403 } else if (block_type
== HPM2_CHN_STATE_NOTIFY
404 && data_type
== IPMI_PROTO_IPMB_1_0
) {
405 dissect_ipmb_state_notify(next_tvb
, tree
);
407 call_data_dissector(next_tvb
, pinfo
, tree
);
409 return tvb_captured_length(tvb
);
413 proto_register_ipmi_trace(void)
415 /* register protocol for HPM.2 trace data block */
416 proto_ipmi_trace
= proto_register_protocol("IPMI Trace Data Collection",
417 "ipmi-trace", "ipmi.trace");
419 /* register HPM.2 header fields */
420 proto_register_field_array(proto_ipmi_trace
, ipmi_trace_hf
,
421 array_length(ipmi_trace_hf
));
423 /* register HPM.2 sub-tree indices */
424 proto_register_subtree_array(ipmi_trace_ett
,
425 array_length(ipmi_trace_ett
));
427 /* register dissector table for IPMI messaging protocols */
428 proto_dissector_table
= register_dissector_table("ipmi.protocol",
429 "IPMI Channel Protocol Type", proto_ipmi_trace
, FT_UINT8
, BASE_HEX
);
431 ipmi_trace_handle
= register_dissector("ipmi.trace", dissect_ipmi_trace
, proto_ipmi_trace
);
435 proto_reg_handoff_ipmi_trace(void)
437 dissector_add_uint("wtap_encap", WTAP_ENCAP_IPMI_TRACE
, ipmi_trace_handle
);
439 dissector_add_uint("ipmi.protocol", IPMI_PROTO_IPMB_1_0
,
440 find_dissector("ipmb"));
441 dissector_add_uint("ipmi.protocol", IPMI_PROTO_KCS
,
442 find_dissector("kcs"));
443 dissector_add_uint("ipmi.protocol", IPMI_PROTO_TMODE
,
444 find_dissector("tmode"));
448 * Editor modelines - https://www.wireshark.org/tools/modelines.html
453 * indent-tabs-mode: t
456 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
457 * :indentSize=8:tabSize=8:noTabs=false: