2 * Routines for Management Component Transport Protocol (MCTP) control
4 * Copyright 2022, Jeremy Kerr <jk@codeconstruct.com.au>
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
14 * MCTP control protocol provides transport-layer initialisation and
15 * management for MCTP endpoints; typically for device discovery, enumeration
16 * and address assigment.
18 * MCTP Control protocol is defined by DMTF standard DSP0236:
19 * https://www.dmtf.org/dsp/DSP0236
24 #include <epan/packet.h>
26 #include <wsutil/array.h>
27 #include "packet-mctp.h"
29 #define MCTP_CTRL_MIN_LENGTH 3
31 void proto_register_mctp_control(void);
32 void proto_reg_handoff_mctp_control(void);
34 static int proto_mctp_ctrl
;
36 static int hf_mctp_ctrl_command
;
37 static int hf_mctp_ctrl_rq
;
38 static int hf_mctp_ctrl_d
;
39 static int hf_mctp_ctrl_instance
;
40 static int hf_mctp_ctrl_cc
;
41 static int hf_mctp_ctrl_data
;
43 static int ett_mctp_ctrl
;
44 static int ett_mctp_ctrl_hdr
;
46 static const value_string command_vals
[] = {
48 { 0x01, "Set Endpoint ID" },
49 { 0x02, "Get Endpoint ID" },
50 { 0x03, "Get Endpoint UUID" },
51 { 0x04, "Get MCTP Version Support" },
52 { 0x05, "Get Message Type Support" },
56 static const value_string cc_vals
[] = {
59 { 0x02, "Error: invalid data" },
60 { 0x03, "Error: invalid length" },
61 { 0x04, "Error: not ready" },
62 { 0x05, "Error: unsupported command" },
66 static const true_false_string tfs_rq
= { "Request", "Response" };
69 dissect_mctp_ctrl(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
72 proto_tree
*mctp_ctrl_tree
, *mctp_ctrl_hdr_tree
;
73 unsigned len
, payload_start
, cmd
;
77 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MCTP Control");
78 col_clear(pinfo
->cinfo
, COL_INFO
);
80 /* Check that the packet is long enough for it to belong to us. */
81 len
= tvb_reported_length(tvb
);
83 if (len
< MCTP_CTRL_MIN_LENGTH
) {
84 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Bogus length %u, minimum %u",
85 len
, MCTP_CTRL_MIN_LENGTH
);
86 return tvb_captured_length(tvb
);
89 ti
= proto_tree_add_item(tree
, proto_mctp_ctrl
, tvb
, 0, -1, ENC_NA
);
90 mctp_ctrl_tree
= proto_item_add_subtree(ti
, ett_mctp_ctrl
);
92 hti
= proto_tree_add_item(mctp_ctrl_tree
, proto_mctp_ctrl
, tvb
, 0, -1,
94 proto_item_set_text(hti
, "MCTP Control Protocol header");
95 mctp_ctrl_hdr_tree
= proto_item_add_subtree(hti
, ett_mctp_ctrl_hdr
);
97 proto_tree_add_item_ret_boolean(mctp_ctrl_hdr_tree
, hf_mctp_ctrl_rq
,
98 tvb
, 1, 1, ENC_NA
, &rq
);
100 proto_tree_add_item(mctp_ctrl_hdr_tree
, hf_mctp_ctrl_d
,
103 proto_tree_add_item(mctp_ctrl_hdr_tree
, hf_mctp_ctrl_instance
,
106 proto_tree_add_item_ret_uint(mctp_ctrl_hdr_tree
, hf_mctp_ctrl_command
,
107 tvb
, 2, 1, ENC_NA
, &cmd
);
109 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "MCTP %s %s",
110 val_to_str_const(cmd
, command_vals
, "Control"),
111 tfs_get_string(rq
, &tfs_rq
));
117 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
118 "Bogus length %u for response, minimum 4", len
);
119 return tvb_captured_length(tvb
);
121 proto_tree_add_item(mctp_ctrl_tree
, hf_mctp_ctrl_cc
,
126 if (len
> payload_start
) {
127 proto_tree_add_item(mctp_ctrl_tree
, hf_mctp_ctrl_data
,
128 tvb
, payload_start
, -1, ENC_NA
);
131 return tvb_captured_length(tvb
);
135 proto_register_mctp_control(void)
138 /* Field definitions */
139 static hf_register_info hf
[] = {
140 { &hf_mctp_ctrl_command
,
141 { "Command", "mctpc.command",
142 FT_UINT8
, BASE_DEC
, VALS(command_vals
), 0,
147 FT_BOOLEAN
, 8, TFS(&tfs_rq
), 0x80,
151 { "Datagram", "mctpc.d",
152 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), 0x40,
155 { &hf_mctp_ctrl_instance
,
156 { "Instance ID", "mctpc.instance",
157 FT_UINT8
, BASE_HEX
, NULL
, 0x1f,
161 { "Completion code", "mctpc.cc",
162 FT_UINT8
, BASE_HEX
, VALS(cc_vals
), 0,
165 { &hf_mctp_ctrl_data
,
166 { "Data", "mctpc.data",
167 FT_BYTES
, SEP_SPACE
, NULL
, 0,
172 /* protocol subtree */
173 static int *ett
[] = {
178 proto_mctp_ctrl
= proto_register_protocol("MCTP Control Protocol",
179 "MCTP-Control", "mctpc");
181 proto_register_field_array(proto_mctp_ctrl
, hf
, array_length(hf
));
182 proto_register_subtree_array(ett
, array_length(ett
));
187 proto_reg_handoff_mctp_control(void)
189 dissector_handle_t mctp_ctrl_handle
;
190 mctp_ctrl_handle
= create_dissector_handle(dissect_mctp_ctrl
, proto_mctp_ctrl
);
191 dissector_add_uint("mctp.type", MCTP_TYPE_CONTROL
, mctp_ctrl_handle
);
195 * Editor modelines - https://www.wireshark.org/tools/modelines.html
200 * indent-tabs-mode: nil
203 * vi: set shiftwidth=4 tabstop=8 expandtab:
204 * :indentSize=4:tabSize=8:noTabs=true: