1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/* packet-mctp.c
* Routines for Management Component Transport Protocol (MCTP) control
* protocol disassembly
* Copyright 2022, Jeremy Kerr <jk@codeconstruct.com.au>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/*
* MCTP control protocol provides transport-layer initialisation and
* management for MCTP endpoints; typically for device discovery, enumeration
* and address assigment.
*
* MCTP Control protocol is defined by DMTF standard DSP0236:
* https://www.dmtf.org/dsp/DSP0236
*/
#include <config.h>
#include <epan/packet.h>
#include <epan/to_str.h>
#include "packet-mctp.h"
#include "packet-sll.h"
#define MCTP_CTRL_MIN_LENGTH 3
void proto_register_mctp_control(void);
void proto_reg_handoff_mctp_control(void);
static int proto_mctp_ctrl = -1;
static int hf_mctp_ctrl_command = -1;
static int hf_mctp_ctrl_rq = -1;
static int hf_mctp_ctrl_d = -1;
static int hf_mctp_ctrl_instance = -1;
static int hf_mctp_ctrl_cc = -1;
static int hf_mctp_ctrl_data = -1;
static gint ett_mctp_ctrl = -1;
static gint ett_mctp_ctrl_hdr = -1;
static const value_string command_vals[] = {
{ 0x00, "Reserved" },
{ 0x01, "Set Endpoint ID" },
{ 0x02, "Get Endpoint ID" },
{ 0x03, "Get Endpoint UUID" },
{ 0x04, "Get MCTP Version Support" },
{ 0x05, "Get Message Type Support" },
{ 0, NULL },
};
static const value_string cc_vals[] = {
{ 0x00, "Success" },
{ 0x01, "Error" },
{ 0x02, "Error: invalid data" },
{ 0x03, "Error: invalid length" },
{ 0x04, "Error: not ready" },
{ 0x05, "Error: unsupported command" },
{ 0, NULL },
};
static const true_false_string tfs_rq = { "Request", "Response" };
static int
dissect_mctp_ctrl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
void *data _U_)
{
proto_tree *mctp_ctrl_tree, *mctp_ctrl_hdr_tree;
guint len, payload_start, cmd;
proto_item *ti, *hti;
gboolean rq;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "MCTP Control");
col_clear(pinfo->cinfo, COL_INFO);
/* Check that the packet is long enough for it to belong to us. */
len = tvb_reported_length(tvb);
if (len < MCTP_CTRL_MIN_LENGTH) {
col_add_fstr(pinfo->cinfo, COL_INFO, "Bogus length %u, minimum %u",
len, MCTP_CTRL_MIN_LENGTH);
return tvb_captured_length(tvb);
}
ti = proto_tree_add_item(tree, proto_mctp_ctrl, tvb, 0, -1, ENC_NA);
mctp_ctrl_tree = proto_item_add_subtree(ti, ett_mctp_ctrl);
hti = proto_tree_add_item(mctp_ctrl_tree, proto_mctp_ctrl, tvb, 0, -1,
ENC_NA);
proto_item_set_text(hti, "MCTP Control Protocol header");
mctp_ctrl_hdr_tree = proto_item_add_subtree(hti, ett_mctp_ctrl_hdr);
proto_tree_add_item_ret_boolean(mctp_ctrl_hdr_tree, hf_mctp_ctrl_rq,
tvb, 1, 1, ENC_NA, &rq);
proto_tree_add_item(mctp_ctrl_hdr_tree, hf_mctp_ctrl_d,
tvb, 1, 1, ENC_NA);
proto_tree_add_item(mctp_ctrl_hdr_tree, hf_mctp_ctrl_instance,
tvb, 1, 1, ENC_NA);
proto_tree_add_item_ret_uint(mctp_ctrl_hdr_tree, hf_mctp_ctrl_command,
tvb, 2, 1, ENC_NA, &cmd);
col_add_fstr(pinfo->cinfo, COL_INFO, "MCTP %s %s",
val_to_str_const(cmd, command_vals, "Control"),
tfs_get_string(rq, &tfs_rq));
payload_start = 3;
if (!rq) {
if (len == 3) {
col_add_fstr(pinfo->cinfo, COL_INFO,
"Bogus length %u for response, minimum 4", len);
return tvb_captured_length(tvb);
}
proto_tree_add_item(mctp_ctrl_tree, hf_mctp_ctrl_cc,
tvb, 3, 1, ENC_NA);
payload_start++;
}
if (len > payload_start) {
proto_tree_add_item(mctp_ctrl_tree, hf_mctp_ctrl_data,
tvb, payload_start, -1, ENC_NA);
}
return tvb_captured_length(tvb);
}
void
proto_register_mctp_control(void)
{
/* *INDENT-OFF* */
/* Field definitions */
static hf_register_info hf[] = {
{ &hf_mctp_ctrl_command,
{ "Command", "mctpc.command",
FT_UINT8, BASE_DEC, VALS(command_vals), 0,
NULL, HFILL },
},
{ &hf_mctp_ctrl_rq,
{ "Rq", "mctpc.rq",
FT_BOOLEAN, 8, TFS(&tfs_rq), 0x80,
NULL, HFILL },
},
{ &hf_mctp_ctrl_d,
{ "Datagram", "mctpc.d",
FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
NULL, HFILL },
},
{ &hf_mctp_ctrl_instance,
{ "Instance ID", "mctpc.instance",
FT_UINT8, BASE_HEX, NULL, 0x1f,
NULL, HFILL },
},
{ &hf_mctp_ctrl_cc,
{ "Completion code", "mctpc.cc",
FT_UINT8, BASE_HEX, VALS(cc_vals), 0,
NULL, HFILL },
},
{ &hf_mctp_ctrl_data,
{ "Data", "mctpc.data",
FT_BYTES, SEP_SPACE, NULL, 0,
NULL, HFILL },
},
};
/* protocol subtree */
static gint *ett[] = {
&ett_mctp_ctrl,
&ett_mctp_ctrl_hdr,
};
proto_mctp_ctrl = proto_register_protocol("MCTP Control Protocol",
"MCTP-Control", "mctpc");
proto_register_field_array(proto_mctp_ctrl, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
void
proto_reg_handoff_mctp_control(void)
{
dissector_handle_t mctp_ctrl_handle;
mctp_ctrl_handle = create_dissector_handle(dissect_mctp_ctrl, proto_mctp_ctrl);
dissector_add_uint("mctp.type", MCTP_TYPE_CONTROL, mctp_ctrl_handle);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|