Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mctp-control.c
blobaf3386828f8437accf395f047db836dc6b587d8c
1 /* packet-mctp.c
2 * Routines for Management Component Transport Protocol (MCTP) control
3 * protocol disassembly
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
22 #include <config.h>
24 #include <epan/packet.h>
25 #include <epan/tfs.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[] = {
47 { 0x00, "Reserved" },
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" },
53 { 0, NULL },
56 static const value_string cc_vals[] = {
57 { 0x00, "Success" },
58 { 0x01, "Error" },
59 { 0x02, "Error: invalid data" },
60 { 0x03, "Error: invalid length" },
61 { 0x04, "Error: not ready" },
62 { 0x05, "Error: unsupported command" },
63 { 0, NULL },
66 static const true_false_string tfs_rq = { "Request", "Response" };
68 static int
69 dissect_mctp_ctrl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
70 void *data _U_)
72 proto_tree *mctp_ctrl_tree, *mctp_ctrl_hdr_tree;
73 unsigned len, payload_start, cmd;
74 proto_item *ti, *hti;
75 bool rq;
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,
93 ENC_NA);
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,
101 tvb, 1, 1, ENC_NA);
103 proto_tree_add_item(mctp_ctrl_hdr_tree, hf_mctp_ctrl_instance,
104 tvb, 1, 1, ENC_NA);
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));
113 payload_start = 3;
115 if (!rq) {
116 if (len == 3) {
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,
122 tvb, 3, 1, ENC_NA);
123 payload_start++;
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);
134 void
135 proto_register_mctp_control(void)
137 /* *INDENT-OFF* */
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,
143 NULL, HFILL },
145 { &hf_mctp_ctrl_rq,
146 { "Rq", "mctpc.rq",
147 FT_BOOLEAN, 8, TFS(&tfs_rq), 0x80,
148 NULL, HFILL },
150 { &hf_mctp_ctrl_d,
151 { "Datagram", "mctpc.d",
152 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
153 NULL, HFILL },
155 { &hf_mctp_ctrl_instance,
156 { "Instance ID", "mctpc.instance",
157 FT_UINT8, BASE_HEX, NULL, 0x1f,
158 NULL, HFILL },
160 { &hf_mctp_ctrl_cc,
161 { "Completion code", "mctpc.cc",
162 FT_UINT8, BASE_HEX, VALS(cc_vals), 0,
163 NULL, HFILL },
165 { &hf_mctp_ctrl_data,
166 { "Data", "mctpc.data",
167 FT_BYTES, SEP_SPACE, NULL, 0,
168 NULL, HFILL },
172 /* protocol subtree */
173 static int *ett[] = {
174 &ett_mctp_ctrl,
175 &ett_mctp_ctrl_hdr,
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));
186 void
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
197 * Local variables:
198 * c-basic-offset: 4
199 * tab-width: 8
200 * indent-tabs-mode: nil
201 * End:
203 * vi: set shiftwidth=4 tabstop=8 expandtab:
204 * :indentSize=4:tabSize=8:noTabs=true: