Coverage Report

Created: 2025-08-04 07:15

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