libpldm: Add decode API for GetFirmwareParameters response
decode_get_firmware_parameters_resp_comp_set_info decodes the
GetFirmwareParameters response except the component parameter table.
Update agent sends GetFirmwareParameters command to acquire the
component details such as classification types and corresponding
versions of firmware device. Its defined in DSP0267 Version 1.1.0
sec:10.2.
Tested: Unit tests passed
Signed-off-by: gokulsanker <gokul.sanker.v.g@intel.com>
Change-Id: I73da32ffa494cc1242ffe310f78acf4596ed04cf
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/libpldm/tests/libpldm_firmware_update_test.cpp
index cb0ec5a..b02e8ca 100644
--- a/libpldm/tests/libpldm_firmware_update_test.cpp
+++ b/libpldm/tests/libpldm_firmware_update_test.cpp
@@ -77,3 +77,72 @@
EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
}
+
+TEST(GetFirmwareParameters, goodPathDecodeResponseComponentSetInfo)
+{
+ // Random value for capabilities during update
+ constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
+ // Random value for component count
+ constexpr uint16_t componentCount = 0xAABB;
+ // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t activeCompImageSetVerStrLen = 8;
+ // PendingCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t pendingCompImageSetVerStrLen = 8;
+ constexpr size_t payloadLen =
+ sizeof(struct pldm_get_firmware_parameters_resp) +
+ activeCompImageSetVerStrLen + pendingCompImageSetVerStrLen;
+
+ std::array<uint8_t, hdrSize + payloadLen> response{};
+ auto inResp = reinterpret_cast<struct pldm_get_firmware_parameters_resp*>(
+ response.data() + hdrSize);
+ inResp->completion_code = PLDM_SUCCESS;
+ inResp->capabilities_during_update.value =
+ htole32(capabilitiesDuringUpdate);
+ inResp->comp_count = htole16(componentCount);
+ inResp->active_comp_image_set_ver_str_type = 1;
+ inResp->active_comp_image_set_ver_str_len = activeCompImageSetVerStrLen;
+ inResp->pending_comp_image_set_ver_str_type = 1;
+ inResp->pending_comp_image_set_ver_str_len = pendingCompImageSetVerStrLen;
+
+ constexpr size_t activeCompImageSetVerStrPos =
+ hdrSize + sizeof(struct pldm_get_firmware_parameters_resp);
+ // filling default values for ActiveComponentImageSetVersionString
+ std::fill_n(response.data() + activeCompImageSetVerStrPos,
+ activeCompImageSetVerStrLen, 0xFF);
+ constexpr size_t pendingCompImageSetVerStrPos =
+ hdrSize + sizeof(struct pldm_get_firmware_parameters_resp) +
+ activeCompImageSetVerStrLen;
+ // filling default values for ActiveComponentImageSetVersionString
+ std::fill_n(response.data() + pendingCompImageSetVerStrPos,
+ pendingCompImageSetVerStrLen, 0xFF);
+
+ auto responseMsg = reinterpret_cast<pldm_msg*>(response.data());
+ struct pldm_get_firmware_parameters_resp outResp;
+ struct variable_field outActiveCompImageSetVerStr;
+ struct variable_field outPendingCompImageSetVerStr;
+
+ auto rc = decode_get_firmware_parameters_resp_comp_set_info(
+ responseMsg, payloadLen, &outResp, &outActiveCompImageSetVerStr,
+ &outPendingCompImageSetVerStr);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.capabilities_during_update.value,
+ capabilitiesDuringUpdate);
+ EXPECT_EQ(outResp.comp_count, componentCount);
+ EXPECT_EQ(inResp->active_comp_image_set_ver_str_type,
+ outResp.active_comp_image_set_ver_str_type);
+ EXPECT_EQ(inResp->active_comp_image_set_ver_str_len,
+ outResp.active_comp_image_set_ver_str_len);
+ EXPECT_EQ(0, memcmp(outActiveCompImageSetVerStr.ptr,
+ response.data() + activeCompImageSetVerStrPos,
+ outActiveCompImageSetVerStr.length));
+
+ EXPECT_EQ(inResp->pending_comp_image_set_ver_str_type,
+ outResp.pending_comp_image_set_ver_str_type);
+ EXPECT_EQ(inResp->pending_comp_image_set_ver_str_len,
+ outResp.pending_comp_image_set_ver_str_len);
+ EXPECT_EQ(0, memcmp(outPendingCompImageSetVerStr.ptr,
+ response.data() + pendingCompImageSetVerStrPos,
+ outPendingCompImageSetVerStr.length));
+}