Skip to content

Commit c9aeda9

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 c9aeda9

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/mctpd.c

Lines changed: 23 additions & 3 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,8 +995,8 @@ static int handle_control_get_message_type_support(
992995

993996
req = (void *)buf;
994997
type_count = ctx->num_supported_msg_types;
995-
// Allocate extra space for the message types
996-
resp_len = sizeof(*resp) + type_count;
998+
// Allocate extra space for the message types. Also two byte for PCIe or IANA VDM
999+
resp_len = sizeof(*resp) + type_count + sizeof(uint16_t);
9971000
resp_buf = malloc(resp_len);
9981001
if (!resp_buf) {
9991002
warnx("Failed to allocate response buffer");
@@ -1004,13 +1007,30 @@ static int handle_control_get_message_type_support(
10041007
mctp_ctrl_msg_hdr_init_resp(&resp->ctrl_hdr, req->ctrl_hdr);
10051008
resp->completion_code = MCTP_CTRL_CC_SUCCESS;
10061009

1007-
resp->msg_type_count = type_count;
10081010
// Append message types after msg_type_count
10091011
msg_types = (uint8_t *)(resp + 1);
10101012
for (i = 0; i < type_count; i++) {
10111013
msg_types[i] = ctx->supported_msg_types[i].msg_type;
10121014
}
10131015

1016+
// Adjust response length and find VDM support
1017+
resp_len -= sizeof(uint16_t);
1018+
for (i = 0; i < ctx->num_supported_vdm_types; i++) {
1019+
if (!pcie_support &&
1020+
ctx->supported_vdm_types[i].format == VID_FORMAT_PCIE) {
1021+
pcie_support = true;
1022+
msg_types[type_count++] = MCTP_TYPE_VENDOR_PCIE;
1023+
resp_len++;
1024+
}
1025+
if (!iana_support &&
1026+
ctx->supported_vdm_types[i].format == VID_FORMAT_IANA) {
1027+
iana_support = true;
1028+
msg_types[type_count++] = MCTP_TYPE_VENDOR_IANA;
1029+
resp_len++;
1030+
}
1031+
}
1032+
1033+
resp->msg_type_count = type_count;
10141034
rc = reply_message(ctx, sd, resp, resp_len, addr);
10151035
free(resp_buf);
10161036

tests/test_mctpd.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,35 @@ async def test_get_message_types(dbus, mctpd, routed_ep):
12791279
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
12801280
assert rsp.hex(' ') == '00 04 00 01 f4 f3 f2 f1'
12811281

1282+
""" Test GetMessageTypes when VDM is registered """
1283+
async def test_get_message_types_with_vdm(dbus, mctpd, routed_ep):
1284+
ep = routed_ep
1285+
1286+
# Register VDM responder PCIe format
1287+
mctp = await mctpd_mctp_base_iface_obj(dbus)
1288+
v_type = asyncdbus.Variant('q', 0xABCD)
1289+
await mctp.call_register_vdm_type_support(0x00, v_type, 0x0001)
1290+
1291+
# Verify get message type response includes PCIe
1292+
cmd = MCTPControlCommand(True, 0, 0x05, bytes([0x00]))
1293+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1294+
assert rsp.hex(' ') == '00 05 00 02 00 7e'
1295+
1296+
# Register VDM responder IANA format
1297+
v_type = asyncdbus.Variant('u', 0x1234ABCD)
1298+
await mctp.call_register_vdm_type_support(0x01, v_type, 0x5678)
1299+
1300+
# Verify get message type response includes IANA
1301+
cmd = MCTPControlCommand(True, 0, 0x05, bytes([0x00]))
1302+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1303+
assert rsp.hex(' ') == '00 05 00 03 00 7e 7f'
1304+
1305+
await mctp.call_register_type_support(5, [0xF1F2F3F4])
1306+
# Verify get message type response includes SPDM and VDMs
1307+
cmd = MCTPControlCommand(True, 0, 0x05, bytes([0x00]))
1308+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
1309+
assert rsp.hex(' ') == '00 05 00 04 00 05 7e 7f'
1310+
12821311
""" Test RegisterVDMTypeSupport when no responders are registered """
12831312
async def test_register_vdm_type_support_empty(mctpd, routed_ep):
12841313
ep = routed_ep

0 commit comments

Comments
 (0)