pldm: libpldmresponder: call ccOnlyResponse when en/decoding errors
Should return ccOnlyResponse when en/decoding process encounters an
error, to avoid redundant data in response.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I8ae02f588740de1ffd6dde99c92046b7cc1d5c39
diff --git a/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index 4d0c4f9..1071324 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -56,8 +56,12 @@
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_types_resp(request->hdr.instance_id, PLDM_SUCCESS, types.data(),
- responsePtr);
+ auto rc = encode_get_types_resp(request->hdr.instance_id, PLDM_SUCCESS,
+ types.data(), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
return response;
}
@@ -74,19 +78,15 @@
if (rc != PLDM_SUCCESS)
{
- encode_get_commands_resp(request->hdr.instance_id, rc, nullptr,
- responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, rc);
}
// DSP0240 has this as a bitfield8[N], where N = 0 to 31
std::array<bitfield8_t, 32> cmds{};
if (capabilities.find(type) == capabilities.end())
{
- encode_get_commands_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_PLDM_TYPE, nullptr,
- responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request,
+ PLDM_ERROR_INVALID_PLDM_TYPE);
}
for (const auto& cmd : capabilities.at(type))
@@ -97,8 +97,12 @@
cmds[index].byte |= 1 << bit;
}
- encode_get_commands_resp(request->hdr.instance_id, PLDM_SUCCESS,
- cmds.data(), responsePtr);
+ rc = encode_get_commands_resp(request->hdr.instance_id, PLDM_SUCCESS,
+ cmds.data(), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
return response;
}
@@ -117,9 +121,7 @@
if (rc != PLDM_SUCCESS)
{
- encode_get_version_resp(request->hdr.instance_id, rc, 0, 0, nullptr, 4,
- responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, rc);
}
ver32_t version{};
@@ -127,16 +129,18 @@
if (search == versions.end())
{
- encode_get_version_resp(request->hdr.instance_id,
- PLDM_ERROR_INVALID_PLDM_TYPE, 0, 0, nullptr, 4,
- responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request,
+ PLDM_ERROR_INVALID_PLDM_TYPE);
}
memcpy(&version, &(search->second), sizeof(version));
- encode_get_version_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
- PLDM_START_AND_END, &version, sizeof(pldm_version),
- responsePtr);
+ rc = encode_get_version_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
+ PLDM_START_AND_END, &version,
+ sizeof(pldm_version), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
return response;
}
@@ -148,8 +152,12 @@
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TID_RESP_BYTES, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_tid_resp(request->hdr.instance_id, PLDM_SUCCESS, tid,
- responsePtr);
+ auto rc = encode_get_tid_resp(request->hdr.instance_id, PLDM_SUCCESS, tid,
+ responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
return response;
}
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 2d3a8ee..a92d3cd 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -157,10 +157,7 @@
std::cerr << "Error getting time, PATH=" << hostTimePath
<< " TIME INTERACE=" << timeInterface << "\n";
- encode_get_date_time_resp(request->hdr.instance_id, PLDM_ERROR, seconds,
- minutes, hours, day, month, year,
- responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
}
uint64_t timeSec = std::chrono::duration_cast<std::chrono::seconds>(
@@ -170,8 +167,14 @@
pldm::responder::utils::epochToBCDTime(timeSec, seconds, minutes, hours,
day, month, year);
- encode_get_date_time_resp(request->hdr.instance_id, PLDM_SUCCESS, seconds,
- minutes, hours, day, month, year, responsePtr);
+ auto rc = encode_get_date_time_resp(request->hdr.instance_id, PLDM_SUCCESS,
+ seconds, minutes, hours, day, month,
+ year, responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
+
return response;
}
@@ -221,15 +224,10 @@
/** @brief Construct the BIOS string table
*
- * @param[in] BIOSStringTable - the string table
- * @param[in] transferHandle - transfer handle to identify part of transfer
- * @param[in] transferOpFlag - flag to indicate which part of data being
- * transferred
- * @param[in] instanceID - instance ID to identify the command
+ * @param[in,out] BIOSStringTable - the string table
+ * @param[in] request - Request message
*/
-Response getBIOSStringTable(BIOSTable& BIOSStringTable,
- uint32_t /*transferHandle*/,
- uint8_t /*transferOpFlag*/, uint8_t instanceID)
+Response getBIOSStringTable(BIOSTable& BIOSStringTable, const pldm_msg* request)
{
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES,
@@ -237,10 +235,16 @@
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
if (!BIOSStringTable.isEmpty())
{
- encode_get_bios_table_resp(instanceID, PLDM_SUCCESS,
- 0, /* next transfer handle */
- PLDM_START_AND_END, nullptr, response.size(),
- responsePtr); // filling up the header here
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS,
+ 0, /* next transfer handle */
+ PLDM_START_AND_END, nullptr, response.size(),
+ responsePtr); // filling up the header here
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
+
BIOSStringTable.load(response);
return response;
}
@@ -279,9 +283,14 @@
stringTable.size(),
0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_bios_table_resp(
- instanceID, PLDM_SUCCESS, 0 /* nxtTransferHandle */, PLDM_START_AND_END,
- stringTable.data(), response.size(), responsePtr);
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS, 0 /* nxtTransferHandle */,
+ PLDM_START_AND_END, stringTable.data(), response.size(), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
+
return response;
}
@@ -697,19 +706,14 @@
/** @brief Construct the BIOS attribute table
*
- * @param[in] BIOSAttributeTable - the attribute table
+ * @param[in,out] BIOSAttributeTable - the attribute table
* @param[in] BIOSStringTable - the string table
- * @param[in] transferHandle - transfer handle to identify part of transfer
- * @param[in] transferOpFlag - flag to indicate which part of data being
- * transferred
- * @param[in] instanceID - instance ID to identify the command
* @param[in] biosJsonDir - path where the BIOS json files are present
+ * @param[in] request - Request message
*/
Response getBIOSAttributeTable(BIOSTable& BIOSAttributeTable,
const BIOSTable& BIOSStringTable,
- uint32_t /*transferHandle*/,
- uint8_t /*transferOpFlag*/, uint8_t instanceID,
- const char* biosJsonDir)
+ const char* biosJsonDir, const pldm_msg* request)
{
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES,
0);
@@ -734,10 +738,8 @@
if (attributeTable.empty())
{ // no available json file is found
- encode_get_bios_table_resp(instanceID, PLDM_BIOS_TABLE_UNAVAILABLE,
- nxtTransferHandle, transferFlag, nullptr,
- response.size(), responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request,
+ PLDM_BIOS_TABLE_UNAVAILABLE);
}
pldm::responder::utils::padAndChecksum(attributeTable);
BIOSAttributeTable.store(attributeTable);
@@ -745,15 +747,25 @@
PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES +
attributeTable.size());
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_bios_table_resp(instanceID, PLDM_SUCCESS, nxtTransferHandle,
- transferFlag, attributeTable.data(),
- response.size(), responsePtr);
+
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS, nxtTransferHandle,
+ transferFlag, attributeTable.data(), response.size(), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
}
else
{ // persisted table present, constructing response
- encode_get_bios_table_resp(instanceID, PLDM_SUCCESS, nxtTransferHandle,
- transferFlag, nullptr, response.size(),
- responsePtr); // filling up the header here
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS, nxtTransferHandle,
+ transferFlag, nullptr, response.size(),
+ responsePtr); // filling up the header here
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
BIOSAttributeTable.load(response);
}
@@ -796,20 +808,15 @@
/** @brief Construct the BIOS attribute value table
*
- * @param[in] BIOSAttributeValueTable - the attribute value table
+ * @param[in,out] BIOSAttributeValueTable - the attribute value table
* @param[in] BIOSAttributeTable - the attribute table
* @param[in] BIOSStringTable - the string table
- * @param[in] transferHandle - transfer handle to identify part of transfer
- * @param[in] transferOpFlag - flag to indicate which part of data being
- * transferred
- * @param[in] instanceID - instance ID to identify the command
+ * @param[in] request - Request message
*/
Response getBIOSAttributeValueTable(BIOSTable& BIOSAttributeValueTable,
const BIOSTable& BIOSAttributeTable,
const BIOSTable& BIOSStringTable,
- uint32_t& /*transferHandle*/,
- uint8_t& /*transferOpFlag*/,
- uint8_t instanceID)
+ const pldm_msg* request)
{
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES,
0);
@@ -819,9 +826,15 @@
if (!BIOSAttributeValueTable.isEmpty())
{
- encode_get_bios_table_resp(instanceID, PLDM_SUCCESS, nxtTransferHandle,
- transferFlag, nullptr, response.size(),
- responsePtr); // filling up the header here
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS, nxtTransferHandle,
+ transferFlag, nullptr, response.size(),
+ responsePtr); // filling up the header here
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
+
BIOSAttributeValueTable.load(response);
return response;
}
@@ -838,10 +851,7 @@
});
if (attributeValueTable.empty())
{
- encode_get_bios_table_resp(instanceID, PLDM_BIOS_TABLE_UNAVAILABLE,
- nxtTransferHandle, transferFlag, nullptr,
- response.size(), responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_BIOS_TABLE_UNAVAILABLE);
}
pldm::responder::utils::padAndChecksum(attributeValueTable);
BIOSAttributeValueTable.store(attributeValueTable);
@@ -849,9 +859,13 @@
response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES +
attributeValueTable.size());
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_bios_table_resp(instanceID, PLDM_SUCCESS, nxtTransferHandle,
- transferFlag, attributeValueTable.data(),
- response.size(), responsePtr);
+ auto rc = encode_get_bios_table_resp(
+ request->hdr.instance_id, PLDM_SUCCESS, nxtTransferHandle, transferFlag,
+ attributeValueTable.data(), response.size(), responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
return response;
}
@@ -930,9 +944,13 @@
valueLength,
0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_bios_current_value_by_handle_resp(
+ rc = encode_get_bios_current_value_by_handle_resp(
request->hdr.instance_id, PLDM_SUCCESS, 0, PLDM_START_AND_END, valuePtr,
valueLength, responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
return response;
}
@@ -945,15 +963,10 @@
{
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES,
0);
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
if (setupConfig(biosJsonDir) != 0)
{
- encode_get_bios_table_resp(
- request->hdr.instance_id, PLDM_BIOS_TABLE_UNAVAILABLE,
- 0 /* nxtTransferHandle */, PLDM_START_AND_END, nullptr,
- response.size(), responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_BIOS_TABLE_UNAVAILABLE);
}
uint32_t transferHandle{};
@@ -962,63 +975,55 @@
auto rc = decode_get_bios_table_req(request, payloadLength, &transferHandle,
&transferOpFlag, &tableType);
- if (rc == PLDM_SUCCESS)
+ if (rc != PLDM_SUCCESS)
{
- BIOSTable BIOSStringTable(
- (std::string(biosTablePath) + "/" + stringTableFile).c_str());
- BIOSTable BIOSAttributeTable(
- (std::string(biosTablePath) + "/" + attrTableFile).c_str());
- BIOSTable BIOSAttributeValueTable(
- (std::string(biosTablePath) + "/" + attrValTableFile).c_str());
- switch (tableType)
- {
- case PLDM_BIOS_STRING_TABLE:
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
- response = getBIOSStringTable(BIOSStringTable, transferHandle,
- transferOpFlag,
- request->hdr.instance_id);
- break;
- case PLDM_BIOS_ATTR_TABLE:
+ BIOSTable BIOSStringTable(
+ (std::string(biosTablePath) + "/" + stringTableFile).c_str());
+ BIOSTable BIOSAttributeTable(
+ (std::string(biosTablePath) + "/" + attrTableFile).c_str());
+ BIOSTable BIOSAttributeValueTable(
+ (std::string(biosTablePath) + "/" + attrValTableFile).c_str());
+ switch (tableType)
+ {
+ case PLDM_BIOS_STRING_TABLE:
- if (BIOSStringTable.isEmpty())
- {
- rc = PLDM_BIOS_TABLE_UNAVAILABLE;
- }
- else
- {
- response = getBIOSAttributeTable(
- BIOSAttributeTable, BIOSStringTable, transferHandle,
- transferOpFlag, request->hdr.instance_id, biosJsonDir);
- }
- break;
- case PLDM_BIOS_ATTR_VAL_TABLE:
- if (BIOSAttributeTable.isEmpty() || BIOSStringTable.isEmpty())
- {
- rc = PLDM_BIOS_TABLE_UNAVAILABLE;
- }
- else
- {
- response = getBIOSAttributeValueTable(
- BIOSAttributeValueTable, BIOSAttributeTable,
- BIOSStringTable, transferHandle, transferOpFlag,
- request->hdr.instance_id);
- }
- break;
- default:
- rc = PLDM_INVALID_BIOS_TABLE_TYPE;
- break;
- }
+ response = getBIOSStringTable(BIOSStringTable, request);
+ break;
+ case PLDM_BIOS_ATTR_TABLE:
+
+ if (BIOSStringTable.isEmpty())
+ {
+ rc = PLDM_BIOS_TABLE_UNAVAILABLE;
+ }
+ else
+ {
+ response = getBIOSAttributeTable(
+ BIOSAttributeTable, BIOSStringTable, biosJsonDir, request);
+ }
+ break;
+ case PLDM_BIOS_ATTR_VAL_TABLE:
+ if (BIOSAttributeTable.isEmpty() || BIOSStringTable.isEmpty())
+ {
+ rc = PLDM_BIOS_TABLE_UNAVAILABLE;
+ }
+ else
+ {
+ response = getBIOSAttributeValueTable(BIOSAttributeValueTable,
+ BIOSAttributeTable,
+ BIOSStringTable, request);
+ }
+ break;
+ default:
+ rc = PLDM_INVALID_BIOS_TABLE_TYPE;
+ break;
}
if (rc != PLDM_SUCCESS)
{
- uint32_t nxtTransferHandle{};
- uint8_t transferFlag{};
- size_t respPayloadLength{};
-
- encode_get_bios_table_resp(request->hdr.instance_id, rc,
- nxtTransferHandle, transferFlag, nullptr,
- respPayloadLength, responsePtr);
+ return CmdHandler::ccOnlyResponse(request, rc);
}
return response;
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 9c5b688..3f93ff4 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -19,9 +19,7 @@
if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
{
- encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH,
- 0, 0, 0, 0, nullptr, 0, responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
uint32_t recordHandle{};
@@ -30,9 +28,13 @@
uint16_t reqSizeBytes{};
uint16_t recordChangeNum{};
- decode_get_pdr_req(request, payloadLength, &recordHandle,
- &dataTransferHandle, &transferOpFlag, &reqSizeBytes,
- &recordChangeNum);
+ auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle,
+ &dataTransferHandle, &transferOpFlag,
+ &reqSizeBytes, &recordChangeNum);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
uint32_t nextRecordHandle{};
uint16_t respSizeBytes{};
@@ -56,26 +58,24 @@
respSizeBytes,
0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
- encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
- nextRecordHandle, 0, PLDM_START, respSizeBytes,
- recordData, 0, responsePtr);
+ rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
+ nextRecordHandle, 0, PLDM_START, respSizeBytes,
+ recordData, 0, responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
}
catch (const std::out_of_range& e)
{
- encode_get_pdr_resp(request->hdr.instance_id,
- PLDM_PLATFORM_INVALID_RECORD_HANDLE,
- nextRecordHandle, 0, PLDM_START, respSizeBytes,
- recordData, 0, responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request,
+ PLDM_PLATFORM_INVALID_RECORD_HANDLE);
}
catch (const std::exception& e)
{
std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
<< " ERROR=" << e.what() << "\n";
- encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR,
- nextRecordHandle, 0, PLDM_START, respSizeBytes,
- recordData, 0, responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
}
return response;
}
@@ -96,26 +96,34 @@
(payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
sizeof(set_effecter_state_field)))
{
- encode_set_state_effecter_states_resp(
- request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH, responsePtr);
- return response;
+ return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
int rc = decode_set_state_effecter_states_req(request, payloadLength,
&effecterId, &compEffecterCnt,
stateField.data());
- if (rc == PLDM_SUCCESS)
+ if (rc != PLDM_SUCCESS)
{
- stateField.resize(compEffecterCnt);
-
- const pldm::utils::DBusHandler dBusIntf;
- rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
- dBusIntf, effecterId, stateField);
+ return CmdHandler::ccOnlyResponse(request, rc);
}
- encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
- responsePtr);
+ stateField.resize(compEffecterCnt);
+ const pldm::utils::DBusHandler dBusIntf;
+ rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
+ dBusIntf, effecterId, stateField);
+ if (rc != PLDM_SUCCESS)
+ {
+ return CmdHandler::ccOnlyResponse(request, rc);
+ }
+
+ rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
+ responsePtr);
+ if (rc != PLDM_SUCCESS)
+ {
+ return ccOnlyResponse(request, rc);
+ }
+
return response;
}