Fix instance id in pldm response
The instance id that is sent on the pldm request message has to
be returned in the PLDM response message to the caller, this was
defaulted in the initial coding to zero and is fixed now
Tested :
Booted a hypervisor that sends PLDM commands.
Below is the transactions recorded in the journal
Jul 03 16:24:10 w70 pldmd[3209]: Buffer Data: 09 01 8b 3f 07 01 00 00
00 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 00
Jul 03 16:24:10 w70 pldmd[3209]: Sending Msg
Jul 03 16:24:10 w70 pldmd[3209]: Buffer Data: 09 01 0b 3f 07 00 10 00
00 00
Jul 03 16:24:11 w70 pldmd[3209]: Received Msg
Jul 03 16:24:11 w70 pldmd[3209]: Buffer Data: 09 01 8c 3f 07 00 00 00
00 00 00 02 00 00 10 00 00 00 10 01 00 00 00 00 00
Jul 03 16:24:11 w70 pldmd[3209]: Sending Msg
Jul 03 16:24:11 w70 pldmd[3209]: Buffer Data: 09 01 0c 3f 07 00 00 10
00 00
Jul 03 16:24:11 w70 pldmd[3209]: Received Msg
Jul 03 16:24:11 w70 pldmd[3209]: Buffer Data: 09 01 8d 3f 07 01 00 00
00 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 00
Jul 03 16:24:11 w70 pldmd[3209]: Sending Msg
Jul 03 16:24:11 w70 pldmd[3209]: Buffer Data: 09 01 0d 3f 07 00 10 00
00 00
Signed-off-by: Jinu Joy Thomas <jinu.joy.thomas@in.ibm.com>
Change-Id: I0e6c0d5582674bc6b0dd75ceb35dd41ed9127cd3
diff --git a/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index 682b1a7..805abed 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -53,7 +53,8 @@
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_types_resp(0, PLDM_SUCCESS, types.data(), responsePtr);
+ encode_get_types_resp(request->hdr.instance_id, PLDM_SUCCESS, types.data(),
+ responsePtr);
return response;
}
@@ -71,7 +72,8 @@
if (rc != PLDM_SUCCESS)
{
- encode_get_commands_resp(0, rc, nullptr, responsePtr);
+ encode_get_commands_resp(request->hdr.instance_id, rc, nullptr,
+ responsePtr);
return response;
}
@@ -79,7 +81,8 @@
std::array<bitfield8_t, 32> cmds{};
if (capabilities.find(type) == capabilities.end())
{
- encode_get_commands_resp(0, PLDM_ERROR_INVALID_PLDM_TYPE, nullptr,
+ encode_get_commands_resp(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_PLDM_TYPE, nullptr,
responsePtr);
return response;
}
@@ -92,7 +95,8 @@
cmds[index].byte |= 1 << bit;
}
- encode_get_commands_resp(0, PLDM_SUCCESS, cmds.data(), responsePtr);
+ encode_get_commands_resp(request->hdr.instance_id, PLDM_SUCCESS,
+ cmds.data(), responsePtr);
return response;
}
@@ -111,7 +115,8 @@
if (rc != PLDM_SUCCESS)
{
- encode_get_version_resp(0, rc, 0, 0, nullptr, 4, responsePtr);
+ encode_get_version_resp(request->hdr.instance_id, rc, 0, 0, nullptr, 4,
+ responsePtr);
return response;
}
@@ -120,14 +125,16 @@
if (search == versions.end())
{
- encode_get_version_resp(0, PLDM_ERROR_INVALID_PLDM_TYPE, 0, 0, nullptr,
- 4, responsePtr);
+ encode_get_version_resp(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_PLDM_TYPE, 0, 0, nullptr, 4,
+ responsePtr);
return response;
}
memcpy(&version, &(search->second), sizeof(version));
- encode_get_version_resp(0, PLDM_SUCCESS, 0, PLDM_START_AND_END, &version,
- sizeof(pldm_version), responsePtr);
+ encode_get_version_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
+ PLDM_START_AND_END, &version, sizeof(pldm_version),
+ responsePtr);
return response;
}
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 51d5415..eab83dc 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -91,8 +91,9 @@
log<level::ERR>("Error getting time", entry("PATH=%s", bmcTimePath),
entry("TIME INTERACE=%s", timeInterface));
- encode_get_date_time_resp(0, PLDM_ERROR, seconds, minutes, hours, day,
- month, year, responsePtr);
+ encode_get_date_time_resp(request->hdr.instance_id, PLDM_ERROR, seconds,
+ minutes, hours, day, month, year,
+ responsePtr);
return response;
}
@@ -104,8 +105,8 @@
utils::epochToBCDTime(timeSec, seconds, minutes, hours, day, month, year);
- encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, hours, day,
- month, year, responsePtr);
+ encode_get_date_time_resp(request->hdr.instance_id, PLDM_SUCCESS, seconds,
+ minutes, hours, day, month, year, responsePtr);
return response;
}
diff --git a/oem/ibm/libpldmresponder/file_io.cpp b/oem/ibm/libpldmresponder/file_io.cpp
index 6b893ed..6fa9f48 100644
--- a/oem/ibm/libpldmresponder/file_io.cpp
+++ b/oem/ibm/libpldmresponder/file_io.cpp
@@ -166,7 +166,8 @@
if (payloadLength != PLDM_RW_FILE_MEM_REQ_BYTES)
{
- encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
@@ -186,7 +187,8 @@
{
log<level::ERR>("File handle does not exist in the file table",
entry("HANDLE=%d", fileHandle));
- encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -194,7 +196,8 @@
if (!fs::exists(value.fsPath))
{
log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
- encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -204,7 +207,8 @@
{
log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
entry("FILE_SIZE=%d", fileSize));
- encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
return response;
}
@@ -218,7 +222,8 @@
{
log<level::ERR>("Read length is not a multiple of DMA minSize",
entry("LENGTH=%d", length));
- encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
PLDM_INVALID_READ_LENGTH, 0, responsePtr);
return response;
}
@@ -226,7 +231,8 @@
using namespace dma;
DMA intf;
return transferAll<DMA>(&intf, PLDM_READ_FILE_INTO_MEMORY, value.fsPath,
- offset, length, address, true);
+ offset, length, address, true,
+ request->hdr.instance_id);
}
Response writeFileFromMemory(const pldm_msg* request, size_t payloadLength)
@@ -241,7 +247,8 @@
if (payloadLength != PLDM_RW_FILE_MEM_REQ_BYTES)
{
- encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
@@ -253,7 +260,8 @@
{
log<level::ERR>("Write length is not a multiple of DMA minSize",
entry("LENGTH=%d", length));
- encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
PLDM_INVALID_WRITE_LENGTH, 0, responsePtr);
return response;
}
@@ -270,7 +278,8 @@
{
log<level::ERR>("File handle does not exist in the file table",
entry("HANDLE=%d", fileHandle));
- encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -278,7 +287,8 @@
if (!fs::exists(value.fsPath))
{
log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
- encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -288,7 +298,8 @@
{
log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
entry("FILE_SIZE=%d", fileSize));
- encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ encode_rw_file_memory_resp(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
return response;
}
@@ -296,7 +307,8 @@
using namespace dma;
DMA intf;
return transferAll<DMA>(&intf, PLDM_WRITE_FILE_FROM_MEMORY, value.fsPath,
- offset, length, address, false);
+ offset, length, address, false,
+ request->hdr.instance_id);
}
Response getFileTable(const pldm_msg* request, size_t payloadLength)
@@ -311,8 +323,9 @@
if (payloadLength != PLDM_GET_FILE_TABLE_REQ_BYTES)
{
- encode_get_file_table_resp(0, PLDM_ERROR_INVALID_LENGTH, 0, 0, nullptr,
- 0, responsePtr);
+ encode_get_file_table_resp(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_LENGTH, 0, 0, nullptr, 0,
+ responsePtr);
return response;
}
@@ -321,14 +334,16 @@
&transferHandle, &transferFlag, &tableType);
if (rc)
{
- encode_get_file_table_resp(0, rc, 0, 0, nullptr, 0, responsePtr);
+ encode_get_file_table_resp(request->hdr.instance_id, rc, 0, 0, nullptr,
+ 0, responsePtr);
return response;
}
if (tableType != PLDM_FILE_ATTRIBUTE_TABLE)
{
- encode_get_file_table_resp(0, PLDM_INVALID_FILE_TABLE_TYPE, 0, 0,
- nullptr, 0, responsePtr);
+ encode_get_file_table_resp(request->hdr.instance_id,
+ PLDM_INVALID_FILE_TABLE_TYPE, 0, 0, nullptr,
+ 0, responsePtr);
return response;
}
@@ -340,13 +355,15 @@
if (attrTable.empty())
{
- encode_get_file_table_resp(0, PLDM_FILE_TABLE_UNAVAILABLE, 0, 0,
- nullptr, 0, responsePtr);
+ encode_get_file_table_resp(request->hdr.instance_id,
+ PLDM_FILE_TABLE_UNAVAILABLE, 0, 0, nullptr,
+ 0, responsePtr);
return response;
}
- encode_get_file_table_resp(0, PLDM_SUCCESS, 0, PLDM_START_AND_END,
- attrTable.data(), attrTable.size(), responsePtr);
+ encode_get_file_table_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
+ PLDM_START_AND_END, attrTable.data(),
+ attrTable.size(), responsePtr);
return response;
}
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 6025fd7..30236ce 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -77,13 +77,14 @@
* @param[in] address - DMA address on the host
* @param[in] upstream - indicates direction of the transfer; true indicates
* transfer to the host
+ * @param[in] instanceId - Message's instance id
* @return PLDM response message
*/
template <class DMAInterface>
Response transferAll(DMAInterface* intf, uint8_t command, fs::path& path,
uint32_t offset, uint32_t length, uint64_t address,
- bool upstream)
+ bool upstream, uint8_t instanceId)
{
uint32_t origLength = length;
Response response(sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES, 0);
@@ -95,7 +96,8 @@
upstream);
if (rc < 0)
{
- encode_rw_file_memory_resp(0, command, PLDM_ERROR, 0, responsePtr);
+ encode_rw_file_memory_resp(instanceId, command, PLDM_ERROR, 0,
+ responsePtr);
return response;
}
@@ -107,11 +109,12 @@
auto rc = intf->transferDataHost(path, offset, length, address, upstream);
if (rc < 0)
{
- encode_rw_file_memory_resp(0, command, PLDM_ERROR, 0, responsePtr);
+ encode_rw_file_memory_resp(instanceId, command, PLDM_ERROR, 0,
+ responsePtr);
return response;
}
- encode_rw_file_memory_resp(0, command, PLDM_SUCCESS, origLength,
+ encode_rw_file_memory_resp(instanceId, command, PLDM_SUCCESS, origLength,
responsePtr);
return response;
}
diff --git a/oem/ibm/test/libpldmresponder_fileio_test.cpp b/oem/ibm/test/libpldmresponder_fileio_test.cpp
index 7c0c129..d44854f 100644
--- a/oem/ibm/test/libpldmresponder_fileio_test.cpp
+++ b/oem/ibm/test/libpldmresponder_fileio_test.cpp
@@ -137,7 +137,7 @@
uint32_t length = minSize;
EXPECT_CALL(dmaObj, transferDataHost(path, 0, length, 0, true)).Times(1);
auto response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY,
- path, 0, length, 0, true);
+ path, 0, length, 0, true, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]),
@@ -147,7 +147,7 @@
length = maxSize;
EXPECT_CALL(dmaObj, transferDataHost(path, 0, length, 0, true)).Times(1);
response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY, path,
- 0, length, 0, true);
+ 0, length, 0, true, 0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]),
@@ -159,7 +159,7 @@
EXPECT_CALL(dmaObj, transferDataHost(path, maxSize, minSize, maxSize, true))
.Times(1);
response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY, path,
- 0, length, 0, true);
+ 0, length, 0, true, 0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]),
@@ -169,7 +169,7 @@
length = 3 * maxSize;
EXPECT_CALL(dmaObj, transferDataHost(_, _, _, _, true)).Times(3);
response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY, path,
- 0, length, 0, true);
+ 0, length, 0, true, 0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]),
@@ -179,7 +179,7 @@
length = minSize;
EXPECT_CALL(dmaObj, transferDataHost(path, 0, length, 0, false)).Times(1);
response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY, path,
- 0, length, 0, false);
+ 0, length, 0, false, 0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]),
@@ -197,7 +197,7 @@
uint32_t length = minSize;
EXPECT_CALL(dmaObj, transferDataHost(_, _, _, _, _)).WillOnce(Return(-1));
auto response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY,
- path, 0, length, 0, true);
+ path, 0, length, 0, true, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
@@ -206,7 +206,7 @@
length = maxSize + minSize;
EXPECT_CALL(dmaObj, transferDataHost(_, _, _, _, _)).WillOnce(Return(-1));
response = transferAll<MockDMA>(&dmaObj, PLDM_READ_FILE_INTO_MEMORY, path,
- 0, length, 0, true);
+ 0, length, 0, true, 0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
}