Skip to content

Commit b65f632

Browse files
committed
mctpd: update get msg type if vdm is registered
If VDM type support is registered using dbus call RegisterVDMTypeSupport then add 7E and 7F based on the format in GetMsgType control command response Signed-off-by: Nidhin MS <[email protected]>
1 parent 7ea8652 commit b65f632

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/mctpd.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static const char *conf_file_default = MCTPD_CONF_FILE_DEFAULT;
6161

6262
static const mctp_eid_t eid_alloc_min = 0x08;
6363
static const mctp_eid_t eid_alloc_max = 0xfe;
64+
static const uint8_t MCTP_TYPE_VENDOR_PCIE = 0x7e;
65+
static const uint8_t MCTP_TYPE_VENDOR_IANA = 0x7f;
6466

6567
// arbitrary sanity
6668
static size_t MAX_PEER_SIZE = 1000000;
@@ -981,6 +983,7 @@ static int handle_control_get_message_type_support(
981983
{
982984
struct mctp_ctrl_resp_get_msg_type_support *resp = NULL;
983985
struct mctp_ctrl_cmd_get_msg_type_support *req = NULL;
986+
bool pcie_support = false, iana_support = false;
984987
size_t i, resp_len, type_count;
985988
uint8_t *resp_buf, *msg_types;
986989
int rc;
@@ -992,6 +995,21 @@ static int handle_control_get_message_type_support(
992995

993996
req = (void *)buf;
994997
type_count = ctx->num_supported_msg_types;
998+
for (i = 0; i < ctx->num_supported_msg_types; i++) {
999+
pcie_support |= (ctx->supported_msg_types[i].msg_type ==
1000+
MCTP_TYPE_VENDOR_PCIE);
1001+
iana_support |= (ctx->supported_msg_types[i].msg_type ==
1002+
MCTP_TYPE_VENDOR_IANA);
1003+
}
1004+
1005+
for (i = 0; i < ctx->num_supported_vdm_types; i++) {
1006+
pcie_support |= ctx->supported_vdm_types[i].format ==
1007+
VID_FORMAT_PCIE;
1008+
iana_support |= ctx->supported_vdm_types[i].format ==
1009+
VID_FORMAT_IANA;
1010+
}
1011+
type_count += (pcie_support + iana_support);
1012+
9951013
// Allocate extra space for the message types
9961014
resp_len = sizeof(*resp) + type_count;
9971015
resp_buf = malloc(resp_len);
@@ -1004,13 +1022,19 @@ static int handle_control_get_message_type_support(
10041022
mctp_ctrl_msg_hdr_init_resp(&resp->ctrl_hdr, req->ctrl_hdr);
10051023
resp->completion_code = MCTP_CTRL_CC_SUCCESS;
10061024

1007-
resp->msg_type_count = type_count;
10081025
// Append message types after msg_type_count
10091026
msg_types = (uint8_t *)(resp + 1);
1010-
for (i = 0; i < type_count; i++) {
1027+
for (i = 0; i < ctx->num_supported_msg_types; i++) {
10111028
msg_types[i] = ctx->supported_msg_types[i].msg_type;
10121029
}
1030+
if (pcie_support) {
1031+
msg_types[i++] = MCTP_TYPE_VENDOR_PCIE;
1032+
}
1033+
if (iana_support) {
1034+
msg_types[i++] = MCTP_TYPE_VENDOR_IANA;
1035+
}
10131036

1037+
resp->msg_type_count = type_count;
10141038
rc = reply_message(ctx, sd, resp, resp_len, addr);
10151039
free(resp_buf);
10161040

tests/test_mctpd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,11 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
13421342
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
13431343
assert rsp.hex(' ') == '00 06 00 ff 00 ab cd 00 01'
13441344

1345+
# Verify GetMsgType includes VDM
1346+
cmd = MCTPControlCommand(True, 0, 0x05)
1347+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1348+
assert rsp.hex(' ') == '00 05 00 02 00 7e'
1349+
13451350
# Give mctpd a moment to process the disconnection
13461351
await trio.sleep(0.1)
13471352

@@ -1350,6 +1355,11 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
13501355
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
13511356
assert rsp.hex(' ') == '00 06 02' # Should be error again
13521357

1358+
# Verify GetMsgType has only control command
1359+
cmd = MCTPControlCommand(True, 0, 0x05)
1360+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1361+
assert rsp.hex(' ') == '00 05 00 01 00'
1362+
13531363
""" Test RegisterVDMTypeSupport error handling """
13541364
async def test_register_vdm_type_support_errors(dbus, mctpd):
13551365
mctp = await mctpd_mctp_base_iface_obj(dbus)

0 commit comments

Comments
 (0)