Skip to content

Commit 120b5e8

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 <nidhin.ms@intel.com>
1 parent 7ea8652 commit 120b5e8

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/mctpd.c

Lines changed: 24 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,15 @@ static int handle_control_get_message_type_support(
992995

993996
req = (void *)buf;
994997
type_count = ctx->num_supported_msg_types;
998+
999+
for (i = 0; i < ctx->num_supported_vdm_types; i++) {
1000+
pcie_support |= ctx->supported_vdm_types[i].format ==
1001+
VID_FORMAT_PCIE;
1002+
iana_support |= ctx->supported_vdm_types[i].format ==
1003+
VID_FORMAT_IANA;
1004+
}
1005+
type_count += (pcie_support + iana_support);
1006+
9951007
// Allocate extra space for the message types
9961008
resp_len = sizeof(*resp) + type_count;
9971009
resp_buf = malloc(resp_len);
@@ -1004,13 +1016,19 @@ static int handle_control_get_message_type_support(
10041016
mctp_ctrl_msg_hdr_init_resp(&resp->ctrl_hdr, req->ctrl_hdr);
10051017
resp->completion_code = MCTP_CTRL_CC_SUCCESS;
10061018

1007-
resp->msg_type_count = type_count;
10081019
// Append message types after msg_type_count
10091020
msg_types = (uint8_t *)(resp + 1);
1010-
for (i = 0; i < type_count; i++) {
1021+
for (i = 0; i < ctx->num_supported_msg_types; i++) {
10111022
msg_types[i] = ctx->supported_msg_types[i].msg_type;
10121023
}
1024+
if (pcie_support) {
1025+
msg_types[i++] = MCTP_TYPE_VENDOR_PCIE;
1026+
}
1027+
if (iana_support) {
1028+
msg_types[i++] = MCTP_TYPE_VENDOR_IANA;
1029+
}
10131030

1031+
resp->msg_type_count = type_count;
10141032
rc = reply_message(ctx, sd, resp, resp_len, addr);
10151033
free(resp_buf);
10161034

@@ -3551,6 +3569,10 @@ static int method_register_type_support(sd_bus_message *call, void *data,
35513569
rc = sd_bus_message_read(call, "y", &msg_type);
35523570
if (rc < 0)
35533571
goto err;
3572+
if (msg_type == 0 || msg_type >= MCTP_TYPE_VENDOR_PCIE) {
3573+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
3574+
"Invalid message type %d", msg_type);
3575+
}
35543576
rc = sd_bus_message_read_array(call, 'u', (const void **)&versions,
35553577
&versions_len);
35563578
if (rc < 0)

tests/test_mctpd.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,14 +1333,24 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
13331333
async with asyncdbus.MessageBus().connect() as temp_bus:
13341334
mctp = await mctpd_mctp_base_iface_obj(temp_bus)
13351335

1336-
# Register PCIe VDM: format=0x00, VID=0xABCD, command_set=0x0001
1336+
# Register PCIe VDM: format=0x00, VID=0xABCD, command_set=1 and 2
13371337
v_type = asyncdbus.Variant('q', 0xABCD)
13381338
await mctp.call_register_vdm_type_support(0x00, v_type, 0x0001)
1339+
await mctp.call_register_vdm_type_support(0x00, v_type, 0x0002)
13391340

13401341
# Verify PCIe VDM (selector 0)
13411342
cmd = MCTPControlCommand(True, 0, 0x06, bytes([0x00]))
13421343
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1343-
assert rsp.hex(' ') == '00 06 00 ff 00 ab cd 00 01'
1344+
assert rsp.hex(' ') == '00 06 00 01 00 ab cd 00 01'
1345+
# Verify PCIe VDM (selector 1)
1346+
cmd = MCTPControlCommand(True, 0, 0x06, bytes([0x01]))
1347+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1348+
assert rsp.hex(' ') == '00 06 00 ff 00 ab cd 00 02'
1349+
1350+
# Verify GetMsgType includes VDM
1351+
cmd = MCTPControlCommand(True, 0, 0x05)
1352+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1353+
assert rsp.hex(' ') == '00 05 00 02 00 7e'
13441354

13451355
# Give mctpd a moment to process the disconnection
13461356
await trio.sleep(0.1)
@@ -1350,6 +1360,11 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
13501360
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
13511361
assert rsp.hex(' ') == '00 06 02' # Should be error again
13521362

1363+
# Verify GetMsgType has only control command
1364+
cmd = MCTPControlCommand(True, 0, 0x05)
1365+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1366+
assert rsp.hex(' ') == '00 05 00 01 00'
1367+
13531368
""" Test RegisterVDMTypeSupport error handling """
13541369
async def test_register_vdm_type_support_errors(dbus, mctpd):
13551370
mctp = await mctpd_mctp_base_iface_obj(dbus)

0 commit comments

Comments
 (0)