oem-ibm : File I/O read-write with length 0
This commit implements pldm to dishonor file I/O read/write for length
zero. Additional changes: - Implemented check for response code of
encode/decode APIs and along with appropriate error message. - Added
check for performing read operation from a file size 0.
Tested: Functional testing passed.
Change-Id: Ibab1981202775b672b3d50040884e9db4c16d5c2
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/oem/ibm/libpldmresponder/file_io.cpp b/oem/ibm/libpldmresponder/file_io.cpp
index adce4ec..b547b5b 100644
--- a/oem/ibm/libpldmresponder/file_io.cpp
+++ b/oem/ibm/libpldmresponder/file_io.cpp
@@ -251,6 +251,97 @@
namespace oem_ibm
{
+void encodeRWResponseHandler(uint8_t instance_id, uint8_t command,
+ uint8_t completion_code, uint32_t length,
+ struct pldm_msg* msg)
+{
+ int rc = encode_rw_file_memory_resp(instance_id, command, completion_code,
+ length, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to encode response for command {COMMAND}, response code '{RC}'",
+ "COMMAND", command, "RC", rc);
+ }
+}
+
+void encodeReadResponseHandler(uint8_t instance_id, uint8_t completion_code,
+ uint32_t length, struct pldm_msg* msg)
+{
+ int rc = encode_read_file_resp(instance_id, completion_code, length, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error("Failed to encode read file response, response code '{RC}'", "RC",
+ rc);
+ }
+}
+
+void encodeWriteResponseHandler(uint8_t instance_id, uint8_t completion_code,
+ uint32_t length, struct pldm_msg* msg)
+{
+ int rc = encode_write_file_resp(instance_id, completion_code, length, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error("Failed to encode write file response, response code '{RC}'",
+ "RC", rc);
+ }
+}
+
+void encodeGetFileResponseHandler(uint8_t instance_id, uint8_t completion_code,
+ uint32_t next_transfer_handle,
+ uint8_t transfer_flag,
+ const uint8_t* table_data, size_t table_size,
+ struct pldm_msg* msg)
+{
+ int rc = encode_get_file_table_resp(instance_id, completion_code,
+ next_transfer_handle, transfer_flag,
+ table_data, table_size, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error("Failed to encode get file table response, response code '{RC}'",
+ "RC", rc);
+ }
+}
+
+void encodeRWTypeMemoryResponseHandler(uint8_t instance_id, uint8_t command,
+ uint8_t completion_code, uint32_t length,
+ struct pldm_msg* msg)
+{
+ int rc = encode_rw_file_by_type_memory_resp(instance_id, command,
+ completion_code, length, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to encode read/write file by type memory response, response code '{RC}'",
+ "RC", rc);
+ }
+}
+
+void encodeRWTypeResponseHandler(uint8_t instance_id, uint8_t command,
+ uint8_t completion_code, uint32_t length,
+ struct pldm_msg* msg)
+{
+ int rc = encode_rw_file_by_type_resp(instance_id, command, completion_code,
+ length, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to encode response for command {COMMAND}, response code '{RC}'",
+ "COMMAND", command, "RC", rc);
+ }
+}
+
+void encodeFileAckResponseHandler(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg* msg)
+{
+ int rc = encode_file_ack_resp(instance_id, completion_code, msg);
+ if (rc != PLDM_SUCCESS)
+ {
+ error("Failed to encode file ack response, response code '{RC}'", "RC",
+ rc);
+ }
+}
+
Response Handler::readFileIntoMemory(const pldm_msg* request,
size_t payloadLength)
{
@@ -261,17 +352,25 @@
Response response((sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES), 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
-
if (payloadLength != PLDM_RW_FILE_MEM_REQ_BYTES)
{
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_READ_FILE_INTO_MEMORY,
- PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
+ error(
+ "Failed to read file into memory as payload length '{LENGTH}' not equal to '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_RW_FILE_MEM_REQ_BYTES);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
- decode_rw_file_memory_req(request, payloadLength, &fileHandle, &offset,
- &length, &address);
+ int responseCode = decode_rw_file_memory_req(
+ request, payloadLength, &fileHandle, &offset, &length, &address);
+ if (responseCode != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to decode read file into memory request, response code '{RC}'",
+ "RC", responseCode);
+ }
using namespace pldm::filetable;
auto& table = buildFileTable(FILE_TABLE_JSON);
@@ -286,9 +385,9 @@
error(
"File handle '{HANDLE}' does not exist in the file table, error - {ERROR}",
"HANDLE", fileHandle, "ERROR", e);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_READ_FILE_INTO_MEMORY,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -296,21 +395,31 @@
{
error("File '{PATH}' and handle '{FILE_HANDLE}' with does not exist",
"PATH", value.fsPath, "FILE_HANDLE", fileHandle);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_READ_FILE_INTO_MEMORY,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
auto fileSize = fs::file_size(value.fsPath);
+ if (!fileSize)
+ {
+ error(
+ "Failed to PLDM_READ_FILE_INTO_MEMORY from file {PATH} with size '{SIZE}'",
+ "PATH", value.fsPath, "SIZE", fileSize);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
+ return response;
+ }
if (offset >= fileSize)
{
error(
"Offset '{OFFSET}' exceeds file size '{SIZE}' and file handle '{FILE_HANDLE}'",
"OFFSET", offset, "SIZE", fileSize, "FILE_HANDLE", fileHandle);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_READ_FILE_INTO_MEMORY,
- PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
return response;
}
@@ -319,13 +428,13 @@
length = fileSize - offset;
}
- if (length % dma::minSize)
+ if (!length || length % dma::minSize)
{
error("Packet length '{LENGTH}' is non multiple of minimum DMA size",
"LENGTH", length);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_READ_FILE_INTO_MEMORY,
- PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
@@ -349,22 +458,31 @@
if (payloadLength != PLDM_RW_FILE_MEM_REQ_BYTES)
{
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
+ error(
+ "Failed to write file from memory as payload length '{LENGTH}' not equal to '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_RW_FILE_MEM_REQ_BYTES);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
- decode_rw_file_memory_req(request, payloadLength, &fileHandle, &offset,
- &length, &address);
+ int responseCode = decode_rw_file_memory_req(
+ request, payloadLength, &fileHandle, &offset, &length, &address);
+ if (responseCode != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to decode write file from memory request, response code '{RC}'",
+ "RC", responseCode);
+ }
- if (length % dma::minSize)
+ if (!length || length % dma::minSize)
{
error("Packet length '{LENGTH}' is non multiple of minimum DMA size",
"LENGTH", length);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
@@ -381,9 +499,9 @@
error(
"File handle '{HANDLE}' does not exist in the file table, error - {ERROR}",
"HANDLE", fileHandle, "ERROR", e);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -391,22 +509,28 @@
{
error("File '{PATH}' does not exist for file handle '{FILE_HANDLE}'",
"PATH", value.fsPath, "FILE_HANDLE", fileHandle);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
auto fileSize = fs::file_size(value.fsPath);
+ if (!fileSize)
+ {
+ info(
+ "File '{PATH}' has size '{SIZE}' for command PLDM_WRITE_FILE_FROM_MEMORY",
+ "PATH", value.fsPath, "SIZE", fileSize);
+ }
if (offset >= fileSize)
{
error(
"Offset '{OFFSET}' exceeds file size {SIZE} for file '{PATH} and handle {FILE_HANDLE}",
"OFFSET", offset, "SIZE", fileSize, "PATH", value.fsPath,
"FILE_HANDLE", fileHandle);
- encode_rw_file_memory_resp(request->hdr.instance_id,
- PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
return response;
}
@@ -429,9 +553,13 @@
if (payloadLength != PLDM_GET_FILE_TABLE_REQ_BYTES)
{
- encode_get_file_table_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_LENGTH, 0, 0, nullptr, 0,
- responsePtr);
+ error(
+ "Failed to get file table as payload length '{LENGTH}' not equal to required length '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH",
+ PLDM_GET_FILE_TABLE_REQ_BYTES);
+ encodeGetFileResponseHandler(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_LENGTH, 0, 0, nullptr,
+ 0, responsePtr);
return response;
}
@@ -439,16 +567,21 @@
&transferFlag, &tableType);
if (rc)
{
- encode_get_file_table_resp(request->hdr.instance_id, rc, 0, 0, nullptr,
- 0, responsePtr);
+ error("Failed to decode get file table request, response code '{RC}'",
+ "RC", rc);
+ encodeGetFileResponseHandler(request->hdr.instance_id, rc, 0, 0,
+ nullptr, 0, responsePtr);
return response;
}
if (tableType != PLDM_FILE_ATTRIBUTE_TABLE)
{
- encode_get_file_table_resp(request->hdr.instance_id,
- PLDM_INVALID_FILE_TABLE_TYPE, 0, 0, nullptr,
- 0, responsePtr);
+ error(
+ "Failed to match table type '{TYPE}' with expected table type '{REQ_TYPE}'",
+ "TYPE", tableType, "REQ_TYPE", PLDM_FILE_ATTRIBUTE_TABLE);
+ encodeGetFileResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_TABLE_TYPE, 0, 0,
+ nullptr, 0, responsePtr);
return response;
}
@@ -460,15 +593,16 @@
if (attrTable.empty())
{
- encode_get_file_table_resp(request->hdr.instance_id,
- PLDM_FILE_TABLE_UNAVAILABLE, 0, 0, nullptr,
- 0, responsePtr);
+ error("PLDM file attribute table is empty");
+ encodeGetFileResponseHandler(request->hdr.instance_id,
+ PLDM_FILE_TABLE_UNAVAILABLE, 0, 0, nullptr,
+ 0, responsePtr);
return response;
}
- encode_get_file_table_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
- PLDM_START_AND_END, attrTable.data(),
- attrTable.size(), responsePtr);
+ encodeGetFileResponseHandler(request->hdr.instance_id, PLDM_SUCCESS, 0,
+ PLDM_START_AND_END, attrTable.data(),
+ attrTable.size(), responsePtr);
return response;
}
@@ -483,8 +617,12 @@
if (payloadLength != PLDM_READ_FILE_REQ_BYTES)
{
- encode_read_file_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_LENGTH, length, responsePtr);
+ error(
+ "Failed to read file as payload length '{LENGTH}' not equal to '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_READ_FILE_REQ_BYTES);
+ encodeReadResponseHandler(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_LENGTH, length,
+ responsePtr);
return response;
}
@@ -493,7 +631,9 @@
if (rc)
{
- encode_read_file_resp(request->hdr.instance_id, rc, 0, responsePtr);
+ error("Failed to decode read file request, response code '{RC}'", "RC",
+ rc);
+ encodeReadResponseHandler(request->hdr.instance_id, rc, 0, responsePtr);
return response;
}
@@ -511,8 +651,9 @@
"File handle '{HANDLE}' does not exist in the file table, error - {ERROR}",
"HANDLE", fileHandle, "ERROR", e);
- encode_read_file_resp(request->hdr.instance_id,
- PLDM_INVALID_FILE_HANDLE, length, responsePtr);
+ encodeReadResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_HANDLE, length,
+ responsePtr);
return response;
}
@@ -520,20 +661,31 @@
{
error("File '{PATH}' and handle {FILE_HANDLE} does not exist", "PATH",
value.fsPath, "FILE_HANDLE", fileHandle);
- encode_read_file_resp(request->hdr.instance_id,
- PLDM_INVALID_FILE_HANDLE, length, responsePtr);
+ encodeReadResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_HANDLE, length,
+ responsePtr);
return response;
}
auto fileSize = fs::file_size(value.fsPath);
+ if (!fileSize)
+ {
+ error("Failed to read file {PATH} with size '{SIZE}'", "PATH",
+ value.fsPath, "SIZE", fileSize);
+ encodeRWResponseHandler(request->hdr.instance_id,
+ PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
+ return response;
+ }
+
if (offset >= fileSize)
{
error(
"Offset '{OFFSET}' exceeds file size '{SIZE}' for file '{PATH}' and file handle '{HANDLE}'",
"OFFSET", offset, "SIZE", fileSize, "PATH", value.fsPath, "HANDLE",
fileHandle);
- encode_read_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
- length, responsePtr);
+ encodeReadResponseHandler(request->hdr.instance_id,
+ PLDM_DATA_OUT_OF_RANGE, length, responsePtr);
return response;
}
@@ -551,8 +703,8 @@
stream.seekg(offset);
stream.read(fileDataPos, length);
- encode_read_file_resp(request->hdr.instance_id, PLDM_SUCCESS, length,
- responsePtr);
+ encodeReadResponseHandler(request->hdr.instance_id, PLDM_SUCCESS, length,
+ responsePtr);
return response;
}
@@ -569,8 +721,11 @@
if (payloadLength < PLDM_WRITE_FILE_REQ_BYTES)
{
- encode_write_file_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
+ error(
+ "Failed to write file as payload length '{LENGTH}' less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_WRITE_FILE_REQ_BYTES);
+ encodeWriteResponseHandler(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
}
@@ -579,7 +734,10 @@
if (rc)
{
- encode_write_file_resp(request->hdr.instance_id, rc, 0, responsePtr);
+ error("Failed to decode write file request, response code '{RC}'", "RC",
+ rc);
+ encodeWriteResponseHandler(request->hdr.instance_id, rc, 0,
+ responsePtr);
return response;
}
@@ -596,8 +754,8 @@
error(
"File handle '{HANDLE}' does not exist in the file table, error - {ERROR}",
"HANDLE", fileHandle, "ERROR", e);
- encode_write_file_resp(request->hdr.instance_id,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeWriteResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
@@ -605,20 +763,27 @@
{
error("File '{PATH}' and handle {FILE_HANDLE} does not exist", "PATH",
value.fsPath, "FILE_HANDLE", fileHandle);
- encode_write_file_resp(request->hdr.instance_id,
- PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
+ encodeWriteResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
return response;
}
auto fileSize = fs::file_size(value.fsPath);
+
+ if (!fileSize)
+ {
+ info("File {PATH} has size '{SIZE}' for write file command", "PATH",
+ value.fsPath, "SIZE", fileSize);
+ }
+
if (offset >= fileSize)
{
error(
"Offset '{OFFSET}' exceeds file size '{SIZE}' for file '{PATH}' and handle {FILE_HANDLE}",
"OFFSET", offset, "SIZE", fileSize, "PATH", value.fsPath,
"FILE_HANDLE", fileHandle);
- encode_write_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
- 0, responsePtr);
+ encodeWriteResponseHandler(request->hdr.instance_id,
+ PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
return response;
}
@@ -630,8 +795,8 @@
stream.seekp(offset);
stream.write(fileDataPos, length);
- encode_write_file_resp(request->hdr.instance_id, PLDM_SUCCESS, length,
- responsePtr);
+ encodeWriteResponseHandler(request->hdr.instance_id, PLDM_SUCCESS, length,
+ responsePtr);
return response;
}
@@ -646,9 +811,13 @@
if (payloadLength != PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES)
{
- encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
- PLDM_ERROR_INVALID_LENGTH, 0,
- responsePtr);
+ error(
+ "Failed to read file into memory as payload length '{LENGTH}' not equal to '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH",
+ PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES);
+ encodeRWTypeMemoryResponseHandler(request->hdr.instance_id, cmd,
+ PLDM_ERROR_INVALID_LENGTH, 0,
+ responsePtr);
return response;
}
@@ -662,17 +831,21 @@
&length, &address);
if (rc != PLDM_SUCCESS)
{
- encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd, rc, 0,
- responsePtr);
+ error(
+ "Failed to decode read/write file by type memory request, response code '{RC}'",
+ "RC", rc);
+ encodeRWTypeMemoryResponseHandler(request->hdr.instance_id, cmd, rc, 0,
+ responsePtr);
return response;
}
- if (length % dma::minSize)
+ if (!length || length % dma::minSize)
{
- error("Packet length '{LENGTH}' is non multiple of minimum DMA size",
- "LENGTH", length);
- encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
- PLDM_ERROR_INVALID_LENGTH, 0,
- responsePtr);
+ error(
+ "Packet length '{LENGTH}' is non multiple of minimum DMA size for command {CMD}",
+ "LENGTH", length, "CMD", cmd);
+ encodeRWTypeMemoryResponseHandler(request->hdr.instance_id, cmd,
+ PLDM_ERROR_INVALID_LENGTH, 0,
+ responsePtr);
return response;
}
@@ -685,9 +858,9 @@
{
error("Unknown file type '{TYPE}', error - {ERROR} ", "TYPE", fileType,
"ERROR", e);
- encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
- PLDM_INVALID_FILE_TYPE, 0,
- responsePtr);
+ encodeRWTypeMemoryResponseHandler(request->hdr.instance_id, cmd,
+ PLDM_INVALID_FILE_TYPE, 0,
+ responsePtr);
return response;
}
@@ -696,8 +869,8 @@
oemPlatformHandler)
: handler->readIntoMemory(offset, length, address,
oemPlatformHandler);
- encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd, rc,
- length, responsePtr);
+ encodeRWTypeMemoryResponseHandler(request->hdr.instance_id, cmd, rc, length,
+ responsePtr);
return response;
}
@@ -722,7 +895,11 @@
if (payloadLength < PLDM_RW_FILE_BY_TYPE_REQ_BYTES)
{
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ error(
+ "Failed to write file by type as payload length '{LENGTH}' less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH",
+ PLDM_RW_FILE_BY_TYPE_REQ_BYTES);
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_WRITE_FILE_BY_TYPE,
PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
@@ -736,7 +913,9 @@
&fileHandle, &offset, &length);
if (rc != PLDM_SUCCESS)
{
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ error("Failed decoded write file by type request, response code '{RC}'",
+ "RC", rc);
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_WRITE_FILE_BY_TYPE, rc, 0,
responsePtr);
return response;
@@ -751,7 +930,7 @@
{
error("Unknown file type '{TYPE}', error - {ERROR}", "TYPE", fileType,
"ERROR", e);
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_WRITE_FILE_BY_TYPE,
PLDM_INVALID_FILE_TYPE, 0, responsePtr);
return response;
@@ -760,7 +939,7 @@
rc = handler->write(reinterpret_cast<const char*>(
request->payload + PLDM_RW_FILE_BY_TYPE_REQ_BYTES),
offset, length, oemPlatformHandler);
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_WRITE_FILE_BY_TYPE, rc, length,
responsePtr);
return response;
@@ -773,7 +952,11 @@
if (payloadLength != PLDM_RW_FILE_BY_TYPE_REQ_BYTES)
{
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ error(
+ "Failed to read file by type as payload length '{LENGTH}' less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH",
+ PLDM_RW_FILE_BY_TYPE_REQ_BYTES);
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_READ_FILE_BY_TYPE,
PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
return response;
@@ -787,7 +970,10 @@
&fileHandle, &offset, &length);
if (rc != PLDM_SUCCESS)
{
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ error(
+ "Failed to decode read file by type request, response code '{RC}'",
+ "RC", rc);
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_READ_FILE_BY_TYPE, rc, 0, responsePtr);
return response;
}
@@ -801,7 +987,7 @@
{
error("Unknown file type '{TYPE}', error - {ERROR}", "TYPE", fileType,
"ERROR", e);
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_READ_FILE_BY_TYPE,
PLDM_INVALID_FILE_TYPE, 0, responsePtr);
return response;
@@ -809,7 +995,7 @@
rc = handler->read(offset, length, response, oemPlatformHandler);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_rw_file_by_type_resp(request->hdr.instance_id,
+ encodeRWTypeResponseHandler(request->hdr.instance_id,
PLDM_READ_FILE_BY_TYPE, rc, length,
responsePtr);
return response;
@@ -822,8 +1008,11 @@
if (payloadLength != PLDM_FILE_ACK_REQ_BYTES)
{
- encode_file_ack_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_LENGTH, responsePtr);
+ error(
+ "Failed to do file ack as payload length '{LENGTH}' is less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_FILE_ACK_REQ_BYTES);
+ encodeFileAckResponseHandler(request->hdr.instance_id,
+ PLDM_ERROR_INVALID_LENGTH, responsePtr);
return response;
}
uint16_t fileType{};
@@ -834,7 +1023,7 @@
&fileHandle, &fileStatus);
if (rc != PLDM_SUCCESS)
{
- encode_file_ack_resp(request->hdr.instance_id, rc, responsePtr);
+ encodeFileAckResponseHandler(request->hdr.instance_id, rc, responsePtr);
return response;
}
@@ -848,13 +1037,13 @@
{
error("Unknown file type '{TYPE}', error - {ERROR}", "TYPE", fileType,
"ERROR", e);
- encode_file_ack_resp(request->hdr.instance_id, PLDM_INVALID_FILE_TYPE,
- responsePtr);
+ encodeFileAckResponseHandler(request->hdr.instance_id,
+ PLDM_INVALID_FILE_TYPE, responsePtr);
return response;
}
rc = handler->fileAck(fileStatus);
- encode_file_ack_resp(request->hdr.instance_id, rc, responsePtr);
+ encodeFileAckResponseHandler(request->hdr.instance_id, rc, responsePtr);
return response;
}
@@ -864,6 +1053,10 @@
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
if (payloadLength != PLDM_GET_ALERT_STATUS_REQ_BYTES)
{
+ error(
+ "Failed to get alert status as payload length '{LENGTH}' is less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH",
+ PLDM_GET_ALERT_STATUS_REQ_BYTES);
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
@@ -872,11 +1065,16 @@
auto rc = decode_get_alert_status_req(request, payloadLength, &versionId);
if (rc != PLDM_SUCCESS)
{
+ error("Failed to decode get alert status request, response code '{RC}'",
+ "RC", rc);
return CmdHandler::ccOnlyResponse(request, rc);
}
if (versionId != 0)
{
+ error(
+ "Failed to get alert status due to unsupported version ID '{VERSION}'",
+ "VERSION", versionId);
return CmdHandler::ccOnlyResponse(request,
PLDM_HOST_UNSUPPORTED_FORMAT_VERSION);
}
@@ -888,6 +1086,9 @@
PLDM_GET_ALERT_STATUS_RESP_BYTES);
if (rc != PLDM_SUCCESS)
{
+ error(
+ "Failed to encode get alert status response, response code '{RC}'",
+ "RC", rc);
return CmdHandler::ccOnlyResponse(request, rc);
}
@@ -901,6 +1102,9 @@
if (payloadLength != PLDM_NEW_FILE_REQ_BYTES)
{
+ error(
+ "Failed new file available as payload length '{LENGTH}' is less than '{REQ_LENGTH}'",
+ "LENGTH", payloadLength, "REQ_LENGTH", PLDM_NEW_FILE_REQ_BYTES);
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
uint16_t fileType{};
@@ -912,6 +1116,8 @@
if (rc != PLDM_SUCCESS)
{
+ error("Failed to decode new file request, response code '{RC}'", "RC",
+ rc);
return CmdHandler::ccOnlyResponse(request, rc);
}
@@ -929,7 +1135,14 @@
rc = handler->newFileAvailable(length);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_new_file_resp(request->hdr.instance_id, rc, responsePtr);
+ int responseCode = encode_new_file_resp(request->hdr.instance_id, rc,
+ responsePtr);
+ if (responseCode != PLDM_SUCCESS)
+ {
+ error(
+ "Failed to encode new file available response, response code '{RC}'",
+ "RC", responseCode);
+ }
return response;
}