dos2unix conversion
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I78a4c2f28285ea30d66895b352402bfd12f95c00
diff --git a/common/types.hpp b/common/types.hpp
index 213feeb..318dc7e 100644
--- a/common/types.hpp
+++ b/common/types.hpp
@@ -1,55 +1,55 @@
-#pragma once
-
-#include <stdint.h>
-
-#include <set>
-#include <string>
-#include <variant>
-#include <vector>
-
-namespace pldm
-{
-
-using Request = std::vector<uint8_t>;
-using Response = std::vector<uint8_t>;
-
-namespace dbus
-{
-
-using ObjectPath = std::string;
-using Service = std::string;
-using Interface = std::string;
-using Interfaces = std::vector<std::string>;
-using Property = std::string;
-using PropertyType = std::string;
-using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
- int64_t, uint64_t, double, std::string>;
-
-} // namespace dbus
-
-namespace pdr
-{
-
-using EID = uint8_t;
-using TerminusHandle = uint16_t;
-using TerminusID = uint8_t;
-using SensorID = uint16_t;
-using EntityType = uint16_t;
-using EntityInstance = uint16_t;
-using ContainerID = uint16_t;
-using StateSetId = uint16_t;
-using CompositeCount = uint8_t;
-using SensorOffset = uint8_t;
-using EventState = uint8_t;
-
-//!< Subset of the State Set that is supported by a effecter/sensor
-using PossibleStates = std::set<uint8_t>;
-//!< Subset of the State Set that is supported by each effecter/sensor in a
-//!< composite efffecter/sensor
-using CompositeSensorStates = std::vector<PossibleStates>;
-using EntityInfo = std::tuple<ContainerID, EntityType, EntityInstance>;
-using SensorInfo = std::tuple<EntityInfo, CompositeSensorStates>;
-
-} // namespace pdr
-
-} // namespace pldm
+#pragma once
+
+#include <stdint.h>
+
+#include <set>
+#include <string>
+#include <variant>
+#include <vector>
+
+namespace pldm
+{
+
+using Request = std::vector<uint8_t>;
+using Response = std::vector<uint8_t>;
+
+namespace dbus
+{
+
+using ObjectPath = std::string;
+using Service = std::string;
+using Interface = std::string;
+using Interfaces = std::vector<std::string>;
+using Property = std::string;
+using PropertyType = std::string;
+using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
+ int64_t, uint64_t, double, std::string>;
+
+} // namespace dbus
+
+namespace pdr
+{
+
+using EID = uint8_t;
+using TerminusHandle = uint16_t;
+using TerminusID = uint8_t;
+using SensorID = uint16_t;
+using EntityType = uint16_t;
+using EntityInstance = uint16_t;
+using ContainerID = uint16_t;
+using StateSetId = uint16_t;
+using CompositeCount = uint8_t;
+using SensorOffset = uint8_t;
+using EventState = uint8_t;
+
+//!< Subset of the State Set that is supported by a effecter/sensor
+using PossibleStates = std::set<uint8_t>;
+//!< Subset of the State Set that is supported by each effecter/sensor in a
+//!< composite efffecter/sensor
+using CompositeSensorStates = std::vector<PossibleStates>;
+using EntityInfo = std::tuple<ContainerID, EntityType, EntityInstance>;
+using SensorInfo = std::tuple<EntityInfo, CompositeSensorStates>;
+
+} // namespace pdr
+
+} // namespace pldm
diff --git a/libpldm/entity.h b/libpldm/entity.h
index 40372ff..9bc50eb 100644
--- a/libpldm/entity.h
+++ b/libpldm/entity.h
@@ -1,152 +1,152 @@
-#ifndef ENTITY_H
-#define ENTITY_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** @brief PLDM Entity ID Codes in DSP0249_1.1.0 specification
- */
-enum pldm_entity_id_codes {
- PLDM_ENTITY_UNSPECIFIED = 0,
- PLDM_ENTITY_OTHER = 1,
-
- /* Miscellaneous Entities */
- PLDM_ENTITY_NETWORK = 2,
- PLDM_ENTITY_GROUP = 3,
- PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE = 4,
- PLDM_ENTITY_EXTERNAL_ENVIRONMENT = 5,
- PLDM_ENTITY_COMM_CHANNEL = 6,
- PLDM_ENTITY_TERMINUS = 7,
- PLDM_ENTITY_PLATFORM_EVENT_LOG = 8,
-
- /* Human Interface Entities */
- PLDM_ENTITY_KEYPAD = 15,
- PLDM_ENTITY_SWITCH = 16,
- PLDM_ENTITY_PUSHBUTTON = 17,
- PLDM_ENTITY_DISPLAY = 18,
- PLDM_ENTITY_INDICATOR = 19,
-
- /* Software/Firmware Entities */
- PLDM_ENTITY_SYS_MGMT_SW = 30,
- PLDM_ENTITY_SYS_FIRMWARE = 31,
- PLDM_ENTITY_OPERATING_SYS = 32,
- PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER = 33,
- PLDM_ENTITY_OS_LOADER = 34,
- PLDM_ENTITY_DEVICE_DRIVER = 35,
- PLDM_ENTITY_MGMT_CONTROLLER_FW = 36,
-
- /* Chassis/Enclosure Entities */
- PLDM_ENTITY_SYSTEM_CHASSIS = 45,
- PLDM_ENTITY_SUB_CHASSIS = 46,
- PLDM_ENTITY_DISK_DRIVE_BAY = 47,
- PLDM_ENTITY_PERIPHERAL_BAY = 48,
- PLDM_ENTITY_DEVICE_BAY = 49,
- PLDM_ENTITY_DOOR = 50,
- PLDM_ENTITY_ACCESS_PANEL = 51,
- PLDM_ENTITY_COVER = 52,
-
- /* Board/Card/Module Entities */
- PLDM_ENTITY_BOARD = 60,
- PLDM_ENTITY_CARD = 61,
- PLDM_ENTITY_MODULE = 62,
- PLDM_ENTITY_SYS_MGMT_MODULE = 63,
- PLDM_ENTITY_SYS_BOARD = 64,
- PLDM_ENTITY_MEMORY_BOARD = 65,
- PLDM_ENTITY_MEMORY_MODULE = 66,
- PLDM_ENTITY_PROC_MODULE = 67,
- PLDM_ENTITY_ADD_IN_CARD = 68,
- PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD = 69,
- PLDM_ENTITY_BACK_PANEL_BOARD = 70,
- PLDM_ENTITY_POWER_MGMT = 71,
- PLDM_ENTITY_POWER_SYS_BOARD = 72,
- PLDM_ENTITY_DRIVE_BACKPLANE = 73,
- PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD = 74,
- PLDM_ENTITY_OTHER_SYS_BOARD = 75,
- PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD = 76,
- PLDM_ENTITY_PROCESSING_BLADE = 77,
- PLDM_ENTITY_CONNECTIVITY_SWITCH = 78,
- PLDM_ENTITY_PROC_MEMORY_MODULE = 79,
- PLDM_ENTITY_IO_MODULE = 80,
- PLDM_ENTITY_PROC_IO_MODULE = 81,
-
- /* Cooling Entities */
- PLDM_ENTITY_COOLING_DEVICE = 90,
- PLDM_ENTITY_COOLING_SUBSYSTEM = 91,
- PLDM_ENTITY_COOLING_UNIT = 92,
- PLDM_ENTITY_FAN = 93,
- PLDM_ENTITY_PELTIER_COOLING_DEVICE = 94,
- PLDM_ENTITY_LIQUID_COOLING_DEVICE = 95,
- PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM = 96,
-
- /* Storage Device Entities */
- PLDM_ENTITY_OTHER_STORAGE_DEVICE = 105,
- PLDM_ENTITY_FLOPPY_DRIVE = 106,
- PLDM_ENTITY_FIXED_DISK_HARD_DRIVE = 107,
- PLDM_ENTITY_CD_DRIVE = 108,
- PLDM_ENTITY_CD_DVD_DRIVE = 109,
- PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE = 110,
- PLDM_ENTITY_SOLID_STATE_SRIVE = 111,
-
- /* Power Entities */
- PLDM_ENTITY_POWER_SUPPLY = 120,
- PLDM_ENTITY_BATTERY = 121,
- PLDM_ENTITY_SUPER_CAPACITOR = 122,
- PLDM_ENTITY_POWER_CONVERTER = 123,
- PLDM_ENTITY_DC_DC_CONVERTER = 124,
- PLDM_ENTITY_AC_MAINS_POWER_SUPPLY = 125,
- PLDM_ENTITY_DC_MAINS_POWER_SUPPLY = 126,
-
- /* Chip Entities */
- PLDM_ENTITY_PROC = 135,
- PLDM_ENTITY_CHIPSET_COMPONENT = 136,
- PLDM_ENTITY_MGMT_CONTROLLER = 137,
- PLDM_ENTITY_PERIPHERAL_CONTROLLER = 138,
- PLDM_ENTITY_SEEPROM = 139,
- PLDM_ENTITY_NVRAM_CHIP = 140,
- PLDM_ENTITY_FLASH_MEMORY_CHIP = 141,
- PLDM_ENTITY_MEMORY_CHIP = 142,
- PLDM_ENTITY_MEMORY_CONTROLLER = 143,
- PLDM_ENTITY_NETWORK_CONTROLLER = 144,
- PLDM_ENTITY_IO_CONTROLLER = 145,
- PLDM_ENTITY_SOUTH_BRIDGE = 146,
- PLDM_ENTITY_REAL_TIME_CLOCK = 147,
- PLDM_ENTITY_FPGA_CPLD_DEVICE = 148,
- /* Bus Entities */
- PLDM_ENTITY_OTHER_BUS = 160,
- PLDM_ENTITY_SYS_BUS = 161,
- PLDM_ENTITY_I2C_BUS = 162,
- PLDM_ENTITY_SMBUS_BUS = 163,
- PLDM_ENTITY_SPI_BUS = 164,
- PLDM_ENTITY_PCI_BUS = 165,
- PLDM_ENTITY_PCI_EXPRESS_BUS = 166,
- PLDM_ENTITY_PECI_BUS = 167,
- PLDM_ENTITY_LPC_BUS = 168,
- PLDM_ENTITY_USB_BUS = 169,
- PLDM_ENTITY_FIREWIRE_BUS = 170,
- PLDM_ENTITY_SCSI_BUS = 171,
- PLDM_ENTITY_SATA_SAS_BUS = 172,
- PLDM_ENTITY_PROC_FRONT_SIDE_BUS = 173,
- PLDM_ENTITY_INTER_PROC_BUS = 174,
-
- /* Connectors/Cables */
- PLDM_ENTITY_CONNECTOR = 185,
- PLDM_ENTITY_SLOT = 186,
- PLDM_ENTITY_CABLE = 187,
- PLDM_ENTITY_INTERCONNECT = 188,
- PLDM_ENTITY_PLUG = 189,
- PLDM_ENTITY_SOCKET = 190,
-
- /* Logical */
- PLDM_ENTITY_SYSTEM_LOGICAL = 11521,
-
- /* OEM ranges */
- PLDM_OEM_ENTITY_TYPE_START = 24576,
- PLDM_OEM_ENTITY_TYPE_END = 32767,
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ENTITY_H */
+#ifndef ENTITY_H
+#define ENTITY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief PLDM Entity ID Codes in DSP0249_1.1.0 specification
+ */
+enum pldm_entity_id_codes {
+ PLDM_ENTITY_UNSPECIFIED = 0,
+ PLDM_ENTITY_OTHER = 1,
+
+ /* Miscellaneous Entities */
+ PLDM_ENTITY_NETWORK = 2,
+ PLDM_ENTITY_GROUP = 3,
+ PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE = 4,
+ PLDM_ENTITY_EXTERNAL_ENVIRONMENT = 5,
+ PLDM_ENTITY_COMM_CHANNEL = 6,
+ PLDM_ENTITY_TERMINUS = 7,
+ PLDM_ENTITY_PLATFORM_EVENT_LOG = 8,
+
+ /* Human Interface Entities */
+ PLDM_ENTITY_KEYPAD = 15,
+ PLDM_ENTITY_SWITCH = 16,
+ PLDM_ENTITY_PUSHBUTTON = 17,
+ PLDM_ENTITY_DISPLAY = 18,
+ PLDM_ENTITY_INDICATOR = 19,
+
+ /* Software/Firmware Entities */
+ PLDM_ENTITY_SYS_MGMT_SW = 30,
+ PLDM_ENTITY_SYS_FIRMWARE = 31,
+ PLDM_ENTITY_OPERATING_SYS = 32,
+ PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER = 33,
+ PLDM_ENTITY_OS_LOADER = 34,
+ PLDM_ENTITY_DEVICE_DRIVER = 35,
+ PLDM_ENTITY_MGMT_CONTROLLER_FW = 36,
+
+ /* Chassis/Enclosure Entities */
+ PLDM_ENTITY_SYSTEM_CHASSIS = 45,
+ PLDM_ENTITY_SUB_CHASSIS = 46,
+ PLDM_ENTITY_DISK_DRIVE_BAY = 47,
+ PLDM_ENTITY_PERIPHERAL_BAY = 48,
+ PLDM_ENTITY_DEVICE_BAY = 49,
+ PLDM_ENTITY_DOOR = 50,
+ PLDM_ENTITY_ACCESS_PANEL = 51,
+ PLDM_ENTITY_COVER = 52,
+
+ /* Board/Card/Module Entities */
+ PLDM_ENTITY_BOARD = 60,
+ PLDM_ENTITY_CARD = 61,
+ PLDM_ENTITY_MODULE = 62,
+ PLDM_ENTITY_SYS_MGMT_MODULE = 63,
+ PLDM_ENTITY_SYS_BOARD = 64,
+ PLDM_ENTITY_MEMORY_BOARD = 65,
+ PLDM_ENTITY_MEMORY_MODULE = 66,
+ PLDM_ENTITY_PROC_MODULE = 67,
+ PLDM_ENTITY_ADD_IN_CARD = 68,
+ PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD = 69,
+ PLDM_ENTITY_BACK_PANEL_BOARD = 70,
+ PLDM_ENTITY_POWER_MGMT = 71,
+ PLDM_ENTITY_POWER_SYS_BOARD = 72,
+ PLDM_ENTITY_DRIVE_BACKPLANE = 73,
+ PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD = 74,
+ PLDM_ENTITY_OTHER_SYS_BOARD = 75,
+ PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD = 76,
+ PLDM_ENTITY_PROCESSING_BLADE = 77,
+ PLDM_ENTITY_CONNECTIVITY_SWITCH = 78,
+ PLDM_ENTITY_PROC_MEMORY_MODULE = 79,
+ PLDM_ENTITY_IO_MODULE = 80,
+ PLDM_ENTITY_PROC_IO_MODULE = 81,
+
+ /* Cooling Entities */
+ PLDM_ENTITY_COOLING_DEVICE = 90,
+ PLDM_ENTITY_COOLING_SUBSYSTEM = 91,
+ PLDM_ENTITY_COOLING_UNIT = 92,
+ PLDM_ENTITY_FAN = 93,
+ PLDM_ENTITY_PELTIER_COOLING_DEVICE = 94,
+ PLDM_ENTITY_LIQUID_COOLING_DEVICE = 95,
+ PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM = 96,
+
+ /* Storage Device Entities */
+ PLDM_ENTITY_OTHER_STORAGE_DEVICE = 105,
+ PLDM_ENTITY_FLOPPY_DRIVE = 106,
+ PLDM_ENTITY_FIXED_DISK_HARD_DRIVE = 107,
+ PLDM_ENTITY_CD_DRIVE = 108,
+ PLDM_ENTITY_CD_DVD_DRIVE = 109,
+ PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE = 110,
+ PLDM_ENTITY_SOLID_STATE_SRIVE = 111,
+
+ /* Power Entities */
+ PLDM_ENTITY_POWER_SUPPLY = 120,
+ PLDM_ENTITY_BATTERY = 121,
+ PLDM_ENTITY_SUPER_CAPACITOR = 122,
+ PLDM_ENTITY_POWER_CONVERTER = 123,
+ PLDM_ENTITY_DC_DC_CONVERTER = 124,
+ PLDM_ENTITY_AC_MAINS_POWER_SUPPLY = 125,
+ PLDM_ENTITY_DC_MAINS_POWER_SUPPLY = 126,
+
+ /* Chip Entities */
+ PLDM_ENTITY_PROC = 135,
+ PLDM_ENTITY_CHIPSET_COMPONENT = 136,
+ PLDM_ENTITY_MGMT_CONTROLLER = 137,
+ PLDM_ENTITY_PERIPHERAL_CONTROLLER = 138,
+ PLDM_ENTITY_SEEPROM = 139,
+ PLDM_ENTITY_NVRAM_CHIP = 140,
+ PLDM_ENTITY_FLASH_MEMORY_CHIP = 141,
+ PLDM_ENTITY_MEMORY_CHIP = 142,
+ PLDM_ENTITY_MEMORY_CONTROLLER = 143,
+ PLDM_ENTITY_NETWORK_CONTROLLER = 144,
+ PLDM_ENTITY_IO_CONTROLLER = 145,
+ PLDM_ENTITY_SOUTH_BRIDGE = 146,
+ PLDM_ENTITY_REAL_TIME_CLOCK = 147,
+ PLDM_ENTITY_FPGA_CPLD_DEVICE = 148,
+ /* Bus Entities */
+ PLDM_ENTITY_OTHER_BUS = 160,
+ PLDM_ENTITY_SYS_BUS = 161,
+ PLDM_ENTITY_I2C_BUS = 162,
+ PLDM_ENTITY_SMBUS_BUS = 163,
+ PLDM_ENTITY_SPI_BUS = 164,
+ PLDM_ENTITY_PCI_BUS = 165,
+ PLDM_ENTITY_PCI_EXPRESS_BUS = 166,
+ PLDM_ENTITY_PECI_BUS = 167,
+ PLDM_ENTITY_LPC_BUS = 168,
+ PLDM_ENTITY_USB_BUS = 169,
+ PLDM_ENTITY_FIREWIRE_BUS = 170,
+ PLDM_ENTITY_SCSI_BUS = 171,
+ PLDM_ENTITY_SATA_SAS_BUS = 172,
+ PLDM_ENTITY_PROC_FRONT_SIDE_BUS = 173,
+ PLDM_ENTITY_INTER_PROC_BUS = 174,
+
+ /* Connectors/Cables */
+ PLDM_ENTITY_CONNECTOR = 185,
+ PLDM_ENTITY_SLOT = 186,
+ PLDM_ENTITY_CABLE = 187,
+ PLDM_ENTITY_INTERCONNECT = 188,
+ PLDM_ENTITY_PLUG = 189,
+ PLDM_ENTITY_SOCKET = 190,
+
+ /* Logical */
+ PLDM_ENTITY_SYSTEM_LOGICAL = 11521,
+
+ /* OEM ranges */
+ PLDM_OEM_ENTITY_TYPE_START = 24576,
+ PLDM_OEM_ENTITY_TYPE_END = 32767,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ENTITY_H */
diff --git a/libpldm/firmware_update.c b/libpldm/firmware_update.c
index fd66549..1aa0ed1 100644
--- a/libpldm/firmware_update.c
+++ b/libpldm/firmware_update.c
@@ -1,1565 +1,1565 @@
-#include "firmware_update.h"
-#include <endian.h>
-#include <string.h>
-
-/** @brief Check whether string type value is valid
- *
- * @return true if string type value is valid, false if not
- */
-static bool is_string_type_valid(uint8_t string_type)
-{
- switch (string_type) {
- case PLDM_STR_TYPE_UNKNOWN:
- return false;
- case PLDM_STR_TYPE_ASCII:
- case PLDM_STR_TYPE_UTF_8:
- case PLDM_STR_TYPE_UTF_16:
- case PLDM_STR_TYPE_UTF_16LE:
- case PLDM_STR_TYPE_UTF_16BE:
- return true;
- default:
- return false;
- }
-}
-
-/** @brief Return the length of the descriptor type described in firmware update
- * specification
- *
- * @return length of the descriptor type if descriptor type is valid else
- * return 0
- */
-static uint16_t get_descriptor_type_length(uint16_t descriptor_type)
-{
- switch (descriptor_type) {
-
- case PLDM_FWUP_PCI_VENDOR_ID:
- return PLDM_FWUP_PCI_VENDOR_ID_LENGTH;
- case PLDM_FWUP_IANA_ENTERPRISE_ID:
- return PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH;
- case PLDM_FWUP_UUID:
- return PLDM_FWUP_UUID_LENGTH;
- case PLDM_FWUP_PNP_VENDOR_ID:
- return PLDM_FWUP_PNP_VENDOR_ID_LENGTH;
- case PLDM_FWUP_ACPI_VENDOR_ID:
- return PLDM_FWUP_ACPI_VENDOR_ID_LENGTH;
- case PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID:
- return PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH;
- case PLDM_FWUP_SCSI_VENDOR_ID:
- return PLDM_FWUP_SCSI_VENDOR_ID_LENGTH;
- case PLDM_FWUP_PCI_DEVICE_ID:
- return PLDM_FWUP_PCI_DEVICE_ID_LENGTH;
- case PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID:
- return PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH;
- case PLDM_FWUP_PCI_SUBSYSTEM_ID:
- return PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH;
- case PLDM_FWUP_PCI_REVISION_ID:
- return PLDM_FWUP_PCI_REVISION_ID_LENGTH;
- case PLDM_FWUP_PNP_PRODUCT_IDENTIFIER:
- return PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH;
- case PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER:
- return PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH;
- case PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING:
- return PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH;
- case PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING:
- return PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH;
- case PLDM_FWUP_SCSI_PRODUCT_ID:
- return PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH;
- case PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE:
- return PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH;
- default:
- return 0;
- }
-}
-
-/** @brief Check whether ComponentResponse is valid
- *
- * @return true if ComponentResponse is valid, false if not
- */
-static bool is_comp_resp_valid(uint8_t comp_resp)
-{
- switch (comp_resp) {
- case PLDM_CR_COMP_CAN_BE_UPDATED:
- case PLDM_CR_COMP_MAY_BE_UPDATEABLE:
- return true;
-
- default:
- return false;
- }
-}
-
-/** @brief Check whether ComponentResponseCode is valid
- *
- * @return true if ComponentResponseCode is valid, false if not
- */
-static bool is_comp_resp_code_valid(uint8_t comp_resp_code)
-{
- switch (comp_resp_code) {
- case PLDM_CRC_COMP_CAN_BE_UPDATED:
- case PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL:
- case PLDM_CRC_COMP_COMPARISON_STAMP_LOWER:
- case PLDM_CRC_INVALID_COMP_COMPARISON_STAMP:
- case PLDM_CRC_COMP_CONFLICT:
- case PLDM_CRC_COMP_PREREQUISITES_NOT_MET:
- case PLDM_CRC_COMP_NOT_SUPPORTED:
- case PLDM_CRC_COMP_SECURITY_RESTRICTIONS:
- case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET:
- case PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY:
- case PLDM_CRC_COMP_VER_STR_IDENTICAL:
- case PLDM_CRC_COMP_VER_STR_LOWER:
- return true;
-
- default:
- if (comp_resp_code >=
- PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN &&
- comp_resp_code <=
- PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) {
- return true;
- }
- return false;
- }
-}
-
-/** @brief Check whether ComponentCompatibilityResponse is valid
- *
- * @return true if ComponentCompatibilityResponse is valid, false if not
- */
-static bool is_comp_compatibility_resp_valid(uint8_t comp_compatibility_resp)
-{
- switch (comp_compatibility_resp) {
- case PLDM_CCR_COMP_CAN_BE_UPDATED:
- case PLDM_CCR_COMP_CANNOT_BE_UPDATED:
- return true;
-
- default:
- return false;
- }
-}
-
-/** @brief Check whether ComponentCompatibilityResponse Code is valid
- *
- * @return true if ComponentCompatibilityResponse Code is valid, false if not
- */
-static bool
-is_comp_compatibility_resp_code_valid(uint8_t comp_compatibility_resp_code)
-{
- switch (comp_compatibility_resp_code) {
- case PLDM_CCRC_NO_RESPONSE_CODE:
- case PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL:
- case PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER:
- case PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP:
- case PLDM_CCRC_COMP_CONFLICT:
- case PLDM_CCRC_COMP_PREREQUISITES_NOT_MET:
- case PLDM_CCRC_COMP_NOT_SUPPORTED:
- case PLDM_CCRC_COMP_SECURITY_RESTRICTIONS:
- case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET:
- case PLDM_CCRC_COMP_INFO_NO_MATCH:
- case PLDM_CCRC_COMP_VER_STR_IDENTICAL:
- case PLDM_CCRC_COMP_VER_STR_LOWER:
- return true;
-
- default:
- if (comp_compatibility_resp_code >=
- PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN &&
- comp_compatibility_resp_code <=
- PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) {
- return true;
- }
- return false;
- }
-}
-
-/** @brief Check whether SelfContainedActivationRequest is valid
- *
- * @return true if SelfContainedActivationRequest is valid, false if not
- */
-static bool
-is_self_contained_activation_req_valid(bool8_t self_contained_activation_req)
-{
- switch (self_contained_activation_req) {
- case PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS:
- case PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS:
- return true;
-
- default:
- return false;
- }
-}
-
-/** @brief Check if current or previous status in GetStatus command response is
- * valid
- *
- * @param[in] state - current or previous different state machine state of
- * the FD
- * @return true if state is valid, false if not
- */
-static bool is_state_valid(uint8_t state)
-{
- switch (state) {
- case PLDM_FD_STATE_IDLE:
- case PLDM_FD_STATE_LEARN_COMPONENTS:
- case PLDM_FD_STATE_READY_XFER:
- case PLDM_FD_STATE_DOWNLOAD:
- case PLDM_FD_STATE_VERIFY:
- case PLDM_FD_STATE_APPLY:
- case PLDM_FD_STATE_ACTIVATE:
- return true;
-
- default:
- return false;
- }
-}
-
-/** @brief Check if aux state in GetStatus command response is valid
- *
- * @param[in] aux_state - provides additional information to the UA to describe
- * the current operation state of the FD/FDP
- *
- * @return true if aux state is valid, false if not
- */
-static bool is_aux_state_valid(uint8_t aux_state)
-{
- switch (aux_state) {
- case PLDM_FD_OPERATION_IN_PROGRESS:
- case PLDM_FD_OPERATION_SUCCESSFUL:
- case PLDM_FD_OPERATION_FAILED:
- case PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER:
- return true;
-
- default:
- return false;
- }
-}
-
-/** @brief Check if aux state status in GetStatus command response is valid
- *
- * @param[in] aux_state_status - aux state status
- *
- * @return true if aux state status is valid, false if not
- */
-static bool is_aux_state_status_valid(uint8_t aux_state_status)
-{
- if (aux_state_status == PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS ||
- aux_state_status == PLDM_FD_TIMEOUT ||
- aux_state_status == PLDM_FD_GENERIC_ERROR) {
- return true;
- } else if (aux_state_status >=
- PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START &&
- aux_state_status <= PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END) {
- return true;
- }
-
- return false;
-}
-
-/** @brief Check if reason code in GetStatus command response is valid
- *
- * @param[in] reason_code - provides the reason for why the current state
- * entered the IDLE state
- *
- * @return true if reason code is valid, false if not
- */
-static bool is_reason_code_valid(uint8_t reason_code)
-{
-
- switch (reason_code) {
- case PLDM_FD_INITIALIZATION:
- case PLDM_FD_ACTIVATE_FW:
- case PLDM_FD_CANCEL_UPDATE:
- case PLDM_FD_TIMEOUT_LEARN_COMPONENT:
- case PLDM_FD_TIMEOUT_READY_XFER:
- case PLDM_FD_TIMEOUT_DOWNLOAD:
- case PLDM_FD_TIMEOUT_VERIFY:
- case PLDM_FD_TIMEOUT_APPLY:
- return true;
-
- default:
- if (reason_code >= PLDM_FD_STATUS_VENDOR_DEFINED_MIN) {
- return true;
- }
- return false;
- }
-}
-
-/** @brief Check if non functioning component indication in CancelUpdate
- * response is valid
- *
- * @return true if non functioning component indication is valid, false if not
- */
-static bool is_non_functioning_component_indication_valid(
- bool8_t non_functioning_component_indication)
-{
- switch (non_functioning_component_indication) {
- case PLDM_FWUP_COMPONENTS_FUNCTIONING:
- case PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING:
- return true;
-
- default:
- return false;
- }
-}
-
-int decode_pldm_package_header_info(
- const uint8_t *data, size_t length,
- struct pldm_package_header_information *package_header_info,
- struct variable_field *package_version_str)
-{
- if (data == NULL || package_header_info == NULL ||
- package_version_str == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_package_header_information)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_package_header_information *data_header =
- (struct pldm_package_header_information *)(data);
-
- if (!is_string_type_valid(data_header->package_version_string_type) ||
- (data_header->package_version_string_length == 0)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_package_header_information) +
- data_header->package_version_string_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if ((data_header->component_bitmap_bit_length %
- PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- memcpy(package_header_info->uuid, data_header->uuid,
- sizeof(data_header->uuid));
- package_header_info->package_header_format_version =
- data_header->package_header_format_version;
- package_header_info->package_header_size =
- le16toh(data_header->package_header_size);
- memcpy(package_header_info->timestamp104, data_header->timestamp104,
- sizeof(data_header->timestamp104));
- package_header_info->component_bitmap_bit_length =
- le16toh(data_header->component_bitmap_bit_length);
- package_header_info->package_version_string_type =
- data_header->package_version_string_type;
- package_header_info->package_version_string_length =
- data_header->package_version_string_length;
- package_version_str->ptr =
- data + sizeof(struct pldm_package_header_information);
- package_version_str->length =
- package_header_info->package_version_string_length;
-
- return PLDM_SUCCESS;
-}
-
-int decode_firmware_device_id_record(
- const uint8_t *data, size_t length, uint16_t component_bitmap_bit_length,
- struct pldm_firmware_device_id_record *fw_device_id_record,
- struct variable_field *applicable_components,
- struct variable_field *comp_image_set_version_str,
- struct variable_field *record_descriptors,
- struct variable_field *fw_device_pkg_data)
-{
- if (data == NULL || fw_device_id_record == NULL ||
- applicable_components == NULL ||
- comp_image_set_version_str == NULL || record_descriptors == NULL ||
- fw_device_pkg_data == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_firmware_device_id_record)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if ((component_bitmap_bit_length %
- PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_firmware_device_id_record *data_record =
- (struct pldm_firmware_device_id_record *)(data);
-
- if (!is_string_type_valid(
- data_record->comp_image_set_version_string_type) ||
- (data_record->comp_image_set_version_string_length == 0)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- fw_device_id_record->record_length =
- le16toh(data_record->record_length);
- fw_device_id_record->descriptor_count = data_record->descriptor_count;
- fw_device_id_record->device_update_option_flags.value =
- le32toh(data_record->device_update_option_flags.value);
- fw_device_id_record->comp_image_set_version_string_type =
- data_record->comp_image_set_version_string_type;
- fw_device_id_record->comp_image_set_version_string_length =
- data_record->comp_image_set_version_string_length;
- fw_device_id_record->fw_device_pkg_data_length =
- le16toh(data_record->fw_device_pkg_data_length);
-
- if (length < fw_device_id_record->record_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- uint16_t applicable_components_length =
- component_bitmap_bit_length / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE;
- uint16_t calc_min_record_length =
- sizeof(struct pldm_firmware_device_id_record) +
- applicable_components_length +
- data_record->comp_image_set_version_string_length +
- PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN +
- fw_device_id_record->fw_device_pkg_data_length;
-
- if (fw_device_id_record->record_length < calc_min_record_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- applicable_components->ptr =
- data + sizeof(struct pldm_firmware_device_id_record);
- applicable_components->length = applicable_components_length;
-
- comp_image_set_version_str->ptr =
- applicable_components->ptr + applicable_components->length;
- comp_image_set_version_str->length =
- fw_device_id_record->comp_image_set_version_string_length;
-
- record_descriptors->ptr = comp_image_set_version_str->ptr +
- comp_image_set_version_str->length;
- record_descriptors->length =
- fw_device_id_record->record_length -
- sizeof(struct pldm_firmware_device_id_record) -
- applicable_components_length -
- fw_device_id_record->comp_image_set_version_string_length -
- fw_device_id_record->fw_device_pkg_data_length;
-
- if (fw_device_id_record->fw_device_pkg_data_length) {
- fw_device_pkg_data->ptr =
- record_descriptors->ptr + record_descriptors->length;
- fw_device_pkg_data->length =
- fw_device_id_record->fw_device_pkg_data_length;
- }
-
- return PLDM_SUCCESS;
-}
-
-int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
- uint16_t *descriptor_type,
- struct variable_field *descriptor_data)
-{
- uint16_t descriptor_length = 0;
-
- if (data == NULL || descriptor_type == NULL ||
- descriptor_data == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_descriptor_tlv *entry =
- (struct pldm_descriptor_tlv *)(data);
-
- *descriptor_type = le16toh(entry->descriptor_type);
- descriptor_length = le16toh(entry->descriptor_length);
- if (*descriptor_type != PLDM_FWUP_VENDOR_DEFINED) {
- if (descriptor_length !=
- get_descriptor_type_length(*descriptor_type)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
- }
-
- if (length < (sizeof(*descriptor_type) + sizeof(descriptor_length) +
- descriptor_length)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- descriptor_data->ptr = entry->descriptor_data;
- descriptor_data->length = descriptor_length;
-
- return PLDM_SUCCESS;
-}
-
-int decode_vendor_defined_descriptor_value(
- const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
- struct variable_field *descriptor_title_str,
- struct variable_field *descriptor_data)
-{
- if (data == NULL || descriptor_title_str_type == NULL ||
- descriptor_title_str == NULL || descriptor_data == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_vendor_defined_descriptor_title_data)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_vendor_defined_descriptor_title_data *entry =
- (struct pldm_vendor_defined_descriptor_title_data *)(data);
- if (!is_string_type_valid(
- entry->vendor_defined_descriptor_title_str_type) ||
- (entry->vendor_defined_descriptor_title_str_len == 0)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- // Assuming atleast 1 byte of VendorDefinedDescriptorData
- if (length < (sizeof(struct pldm_vendor_defined_descriptor_title_data) +
- entry->vendor_defined_descriptor_title_str_len)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- *descriptor_title_str_type =
- entry->vendor_defined_descriptor_title_str_type;
- descriptor_title_str->ptr = entry->vendor_defined_descriptor_title_str;
- descriptor_title_str->length =
- entry->vendor_defined_descriptor_title_str_len;
-
- descriptor_data->ptr =
- descriptor_title_str->ptr + descriptor_title_str->length;
- descriptor_data->length =
- length - sizeof(entry->vendor_defined_descriptor_title_str_type) -
- sizeof(entry->vendor_defined_descriptor_title_str_len) -
- descriptor_title_str->length;
-
- return PLDM_SUCCESS;
-}
-
-int decode_pldm_comp_image_info(
- const uint8_t *data, size_t length,
- struct pldm_component_image_information *pldm_comp_image_info,
- struct variable_field *comp_version_str)
-{
- if (data == NULL || pldm_comp_image_info == NULL ||
- comp_version_str == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_component_image_information)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_component_image_information *data_header =
- (struct pldm_component_image_information *)(data);
-
- if (!is_string_type_valid(data_header->comp_version_string_type) ||
- (data_header->comp_version_string_length == 0)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_component_image_information) +
- data_header->comp_version_string_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- pldm_comp_image_info->comp_classification =
- le16toh(data_header->comp_classification);
- pldm_comp_image_info->comp_identifier =
- le16toh(data_header->comp_identifier);
- pldm_comp_image_info->comp_comparison_stamp =
- le32toh(data_header->comp_comparison_stamp);
- pldm_comp_image_info->comp_options.value =
- le16toh(data_header->comp_options.value);
- pldm_comp_image_info->requested_comp_activation_method.value =
- le16toh(data_header->requested_comp_activation_method.value);
- pldm_comp_image_info->comp_location_offset =
- le32toh(data_header->comp_location_offset);
- pldm_comp_image_info->comp_size = le32toh(data_header->comp_size);
- pldm_comp_image_info->comp_version_string_type =
- data_header->comp_version_string_type;
- pldm_comp_image_info->comp_version_string_length =
- data_header->comp_version_string_length;
-
- if ((pldm_comp_image_info->comp_options.bits.bit1 == false &&
- pldm_comp_image_info->comp_comparison_stamp !=
- PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (pldm_comp_image_info->comp_location_offset == 0 ||
- pldm_comp_image_info->comp_size == 0) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- comp_version_str->ptr =
- data + sizeof(struct pldm_component_image_information);
- comp_version_str->length =
- pldm_comp_image_info->comp_version_string_length;
-
- return PLDM_SUCCESS;
-}
-
-int encode_query_device_identifiers_req(uint8_t instance_id,
- size_t payload_length,
- struct pldm_msg *msg)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
- PLDM_QUERY_DEVICE_IDENTIFIERS, msg);
-}
-
-int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint32_t *device_identifiers_len,
- uint8_t *descriptor_count,
- uint8_t **descriptor_data)
-{
- if (msg == NULL || completion_code == NULL ||
- device_identifiers_len == NULL || descriptor_count == NULL ||
- descriptor_data == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (PLDM_SUCCESS != *completion_code) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length <
- sizeof(struct pldm_query_device_identifiers_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_query_device_identifiers_resp *response =
- (struct pldm_query_device_identifiers_resp *)msg->payload;
- *device_identifiers_len = le32toh(response->device_identifiers_len);
-
- if (*device_identifiers_len < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if (payload_length !=
- sizeof(struct pldm_query_device_identifiers_resp) +
- *device_identifiers_len) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
- *descriptor_count = response->descriptor_count;
-
- if (*descriptor_count == 0) {
- return PLDM_ERROR_INVALID_DATA;
- }
- *descriptor_data =
- (uint8_t *)(msg->payload +
- sizeof(struct pldm_query_device_identifiers_resp));
- return PLDM_SUCCESS;
-}
-
-int encode_get_firmware_parameters_req(uint8_t instance_id,
- size_t payload_length,
- struct pldm_msg *msg)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
- PLDM_GET_FIRMWARE_PARAMETERS, msg);
-}
-
-int decode_get_firmware_parameters_resp(
- const struct pldm_msg *msg, size_t payload_length,
- struct pldm_get_firmware_parameters_resp *resp_data,
- struct variable_field *active_comp_image_set_ver_str,
- struct variable_field *pending_comp_image_set_ver_str,
- struct variable_field *comp_parameter_table)
-{
- if (msg == NULL || resp_data == NULL ||
- active_comp_image_set_ver_str == NULL ||
- pending_comp_image_set_ver_str == NULL ||
- comp_parameter_table == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- resp_data->completion_code = msg->payload[0];
- if (PLDM_SUCCESS != resp_data->completion_code) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length < sizeof(struct pldm_get_firmware_parameters_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_get_firmware_parameters_resp *response =
- (struct pldm_get_firmware_parameters_resp *)msg->payload;
-
- if (!is_string_type_valid(
- response->active_comp_image_set_ver_str_type) ||
- (response->active_comp_image_set_ver_str_len == 0)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (response->pending_comp_image_set_ver_str_len == 0) {
- if (response->pending_comp_image_set_ver_str_type !=
- PLDM_STR_TYPE_UNKNOWN) {
- return PLDM_ERROR_INVALID_DATA;
- }
- } else {
- if (!is_string_type_valid(
- response->pending_comp_image_set_ver_str_type)) {
- return PLDM_ERROR_INVALID_DATA;
- }
- }
-
- size_t partial_response_length =
- sizeof(struct pldm_get_firmware_parameters_resp) +
- response->active_comp_image_set_ver_str_len +
- response->pending_comp_image_set_ver_str_len;
-
- if (payload_length < partial_response_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- resp_data->capabilities_during_update.value =
- le32toh(response->capabilities_during_update.value);
- resp_data->comp_count = le16toh(response->comp_count);
- resp_data->active_comp_image_set_ver_str_type =
- response->active_comp_image_set_ver_str_type;
- resp_data->active_comp_image_set_ver_str_len =
- response->active_comp_image_set_ver_str_len;
- resp_data->pending_comp_image_set_ver_str_type =
- response->pending_comp_image_set_ver_str_type;
- resp_data->pending_comp_image_set_ver_str_len =
- response->pending_comp_image_set_ver_str_len;
-
- active_comp_image_set_ver_str->ptr =
- msg->payload + sizeof(struct pldm_get_firmware_parameters_resp);
- active_comp_image_set_ver_str->length =
- resp_data->active_comp_image_set_ver_str_len;
-
- if (resp_data->pending_comp_image_set_ver_str_len != 0) {
- pending_comp_image_set_ver_str->ptr =
- msg->payload +
- sizeof(struct pldm_get_firmware_parameters_resp) +
- resp_data->active_comp_image_set_ver_str_len;
- pending_comp_image_set_ver_str->length =
- resp_data->pending_comp_image_set_ver_str_len;
- } else {
- pending_comp_image_set_ver_str->ptr = NULL;
- pending_comp_image_set_ver_str->length = 0;
- }
-
- if (payload_length > partial_response_length && resp_data->comp_count) {
- comp_parameter_table->ptr =
- msg->payload +
- sizeof(struct pldm_get_firmware_parameters_resp) +
- resp_data->active_comp_image_set_ver_str_len +
- resp_data->pending_comp_image_set_ver_str_len;
- comp_parameter_table->length =
- payload_length - partial_response_length;
- } else {
- comp_parameter_table->ptr = NULL;
- comp_parameter_table->length = 0;
- }
-
- return PLDM_SUCCESS;
-}
-
-int decode_get_firmware_parameters_resp_comp_entry(
- const uint8_t *data, size_t length,
- struct pldm_component_parameter_entry *component_data,
- struct variable_field *active_comp_ver_str,
- struct variable_field *pending_comp_ver_str)
-{
- if (data == NULL || component_data == NULL ||
- active_comp_ver_str == NULL || pending_comp_ver_str == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (length < sizeof(struct pldm_component_parameter_entry)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_component_parameter_entry *entry =
- (struct pldm_component_parameter_entry *)(data);
- if (entry->active_comp_ver_str_len == 0) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- size_t entry_length = sizeof(struct pldm_component_parameter_entry) +
- entry->active_comp_ver_str_len +
- entry->pending_comp_ver_str_len;
-
- if (length < entry_length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- component_data->comp_classification =
- le16toh(entry->comp_classification);
- component_data->comp_identifier = le16toh(entry->comp_identifier);
- component_data->comp_classification_index =
- entry->comp_classification_index;
- component_data->active_comp_comparison_stamp =
- le32toh(entry->active_comp_comparison_stamp);
- component_data->active_comp_ver_str_type =
- entry->active_comp_ver_str_type;
- component_data->active_comp_ver_str_len =
- entry->active_comp_ver_str_len;
- memcpy(component_data->active_comp_release_date,
- entry->active_comp_release_date,
- sizeof(entry->active_comp_release_date));
- component_data->pending_comp_comparison_stamp =
- le32toh(entry->pending_comp_comparison_stamp);
- component_data->pending_comp_ver_str_type =
- entry->pending_comp_ver_str_type;
- component_data->pending_comp_ver_str_len =
- entry->pending_comp_ver_str_len;
- memcpy(component_data->pending_comp_release_date,
- entry->pending_comp_release_date,
- sizeof(entry->pending_comp_release_date));
- component_data->comp_activation_methods.value =
- le16toh(entry->comp_activation_methods.value);
- component_data->capabilities_during_update.value =
- le32toh(entry->capabilities_during_update.value);
-
- active_comp_ver_str->ptr =
- data + sizeof(struct pldm_component_parameter_entry);
- active_comp_ver_str->length = entry->active_comp_ver_str_len;
-
- if (entry->pending_comp_ver_str_len != 0) {
-
- pending_comp_ver_str->ptr =
- data + sizeof(struct pldm_component_parameter_entry) +
- entry->active_comp_ver_str_len;
- pending_comp_ver_str->length = entry->pending_comp_ver_str_len;
- } else {
- pending_comp_ver_str->ptr = NULL;
- pending_comp_ver_str->length = 0;
- }
- return PLDM_SUCCESS;
-}
-
-int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size,
- uint16_t num_of_comp,
- uint8_t max_outstanding_transfer_req,
- uint16_t pkg_data_len,
- uint8_t comp_image_set_ver_str_type,
- uint8_t comp_image_set_ver_str_len,
- const struct variable_field *comp_img_set_ver_str,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (comp_img_set_ver_str == NULL || comp_img_set_ver_str->ptr == NULL ||
- msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(struct pldm_request_update_req) +
- comp_img_set_ver_str->length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if ((comp_image_set_ver_str_len == 0) ||
- (comp_image_set_ver_str_len != comp_img_set_ver_str->length)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if ((max_transfer_size < PLDM_FWUP_BASELINE_TRANSFER_SIZE) ||
- (max_outstanding_transfer_req < PLDM_FWUP_MIN_OUTSTANDING_REQ)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (!is_string_type_valid(comp_image_set_ver_str_type)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_REQUEST_UPDATE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- struct pldm_request_update_req *request =
- (struct pldm_request_update_req *)msg->payload;
-
- request->max_transfer_size = htole32(max_transfer_size);
- request->num_of_comp = htole16(num_of_comp);
- request->max_outstanding_transfer_req = max_outstanding_transfer_req;
- request->pkg_data_len = htole16(pkg_data_len);
- request->comp_image_set_ver_str_type = comp_image_set_ver_str_type;
- request->comp_image_set_ver_str_len = comp_image_set_ver_str_len;
-
- memcpy(msg->payload + sizeof(struct pldm_request_update_req),
- comp_img_set_ver_str->ptr, comp_img_set_ver_str->length);
-
- return PLDM_SUCCESS;
-}
-
-int decode_request_update_resp(const struct pldm_msg *msg,
- size_t payload_length, uint8_t *completion_code,
- uint16_t *fd_meta_data_len,
- uint8_t *fd_will_send_pkg_data)
-{
- if (msg == NULL || completion_code == NULL ||
- fd_meta_data_len == NULL || fd_will_send_pkg_data == NULL ||
- !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_request_update_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_request_update_resp *response =
- (struct pldm_request_update_resp *)msg->payload;
-
- *fd_meta_data_len = le16toh(response->fd_meta_data_len);
- *fd_will_send_pkg_data = response->fd_will_send_pkg_data;
-
- return PLDM_SUCCESS;
-}
-
-int encode_pass_component_table_req(
- uint8_t instance_id, uint8_t transfer_flag, uint16_t comp_classification,
- uint16_t comp_identifier, uint8_t comp_classification_index,
- uint32_t comp_comparison_stamp, uint8_t comp_ver_str_type,
- uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(struct pldm_pass_component_table_req) +
- comp_ver_str->length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if ((comp_ver_str_len == 0) ||
- (comp_ver_str_len != comp_ver_str->length)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (!is_transfer_flag_valid(transfer_flag)) {
- return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
- }
-
- if (!is_string_type_valid(comp_ver_str_type)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_PASS_COMPONENT_TABLE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- struct pldm_pass_component_table_req *request =
- (struct pldm_pass_component_table_req *)msg->payload;
-
- request->transfer_flag = transfer_flag;
- request->comp_classification = htole16(comp_classification);
- request->comp_identifier = htole16(comp_identifier);
- request->comp_classification_index = comp_classification_index;
- request->comp_comparison_stamp = htole32(comp_comparison_stamp);
- request->comp_ver_str_type = comp_ver_str_type;
- request->comp_ver_str_len = comp_ver_str_len;
-
- memcpy(msg->payload + sizeof(struct pldm_pass_component_table_req),
- comp_ver_str->ptr, comp_ver_str->length);
-
- return PLDM_SUCCESS;
-}
-
-int decode_pass_component_table_resp(const struct pldm_msg *msg,
- const size_t payload_length,
- uint8_t *completion_code,
- uint8_t *comp_resp,
- uint8_t *comp_resp_code)
-{
- if (msg == NULL || completion_code == NULL || comp_resp == NULL ||
- comp_resp_code == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_pass_component_table_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_pass_component_table_resp *response =
- (struct pldm_pass_component_table_resp *)msg->payload;
-
- if (!is_comp_resp_valid(response->comp_resp)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (!is_comp_resp_code_valid(response->comp_resp_code)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *comp_resp = response->comp_resp;
- *comp_resp_code = response->comp_resp_code;
-
- return PLDM_SUCCESS;
-}
-
-int encode_update_component_req(
- uint8_t instance_id, uint16_t comp_classification, uint16_t comp_identifier,
- uint8_t comp_classification_index, uint32_t comp_comparison_stamp,
- uint32_t comp_image_size, bitfield32_t update_option_flags,
- uint8_t comp_ver_str_type, uint8_t comp_ver_str_len,
- const struct variable_field *comp_ver_str, struct pldm_msg *msg,
- size_t payload_length)
-{
- if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length !=
- sizeof(struct pldm_update_component_req) + comp_ver_str->length) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if (!comp_image_size) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if ((comp_ver_str_len == 0) ||
- (comp_ver_str_len != comp_ver_str->length)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (!is_string_type_valid(comp_ver_str_type)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_UPDATE_COMPONENT;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- struct pldm_update_component_req *request =
- (struct pldm_update_component_req *)msg->payload;
-
- request->comp_classification = htole16(comp_classification);
- request->comp_identifier = htole16(comp_identifier);
- request->comp_classification_index = comp_classification_index;
- request->comp_comparison_stamp = htole32(comp_comparison_stamp);
- request->comp_image_size = htole32(comp_image_size);
- request->update_option_flags.value = htole32(update_option_flags.value);
- request->comp_ver_str_type = comp_ver_str_type;
- request->comp_ver_str_len = comp_ver_str_len;
-
- memcpy(msg->payload + sizeof(struct pldm_update_component_req),
- comp_ver_str->ptr, comp_ver_str->length);
-
- return PLDM_SUCCESS;
-}
-
-int decode_update_component_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint8_t *comp_compatability_resp,
- uint8_t *comp_compatability_resp_code,
- bitfield32_t *update_option_flags_enabled,
- uint16_t *time_before_req_fw_data)
-{
- if (msg == NULL || completion_code == NULL ||
- comp_compatability_resp == NULL ||
- comp_compatability_resp_code == NULL ||
- update_option_flags_enabled == NULL ||
- time_before_req_fw_data == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_update_component_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_update_component_resp *response =
- (struct pldm_update_component_resp *)msg->payload;
-
- if (!is_comp_compatibility_resp_valid(
- response->comp_compatability_resp)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (!is_comp_compatibility_resp_code_valid(
- response->comp_compatability_resp_code)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *comp_compatability_resp = response->comp_compatability_resp;
- *comp_compatability_resp_code = response->comp_compatability_resp_code;
- update_option_flags_enabled->value =
- le32toh(response->update_option_flags_enabled.value);
- *time_before_req_fw_data = le16toh(response->time_before_req_fw_data);
-
- return PLDM_SUCCESS;
-}
-
-int decode_request_firmware_data_req(const struct pldm_msg *msg,
- size_t payload_length, uint32_t *offset,
- uint32_t *length)
-{
- if (msg == NULL || offset == NULL || length == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (payload_length != sizeof(struct pldm_request_firmware_data_req)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
- struct pldm_request_firmware_data_req *request =
- (struct pldm_request_firmware_data_req *)msg->payload;
- *offset = le32toh(request->offset);
- *length = le32toh(request->length);
-
- if (*length < PLDM_FWUP_BASELINE_TRANSFER_SIZE) {
- return PLDM_FWUP_INVALID_TRANSFER_LENGTH;
- }
-
- return PLDM_SUCCESS;
-}
-
-int encode_request_firmware_data_resp(uint8_t instance_id,
- uint8_t completion_code,
- struct pldm_msg *msg,
- size_t payload_length)
-{
- if (msg == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_RESPONSE;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_REQUEST_FIRMWARE_DATA;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- msg->payload[0] = completion_code;
-
- return PLDM_SUCCESS;
-}
-
-int decode_transfer_complete_req(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *transfer_result)
-{
- if (msg == NULL || transfer_result == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(*transfer_result)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- *transfer_result = msg->payload[0];
- return PLDM_SUCCESS;
-}
-
-int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(completion_code)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_RESPONSE;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_TRANSFER_COMPLETE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- msg->payload[0] = completion_code;
-
- return PLDM_SUCCESS;
-}
-
-int decode_verify_complete_req(const struct pldm_msg *msg,
- size_t payload_length, uint8_t *verify_result)
-{
- if (msg == NULL || verify_result == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(*verify_result)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- *verify_result = msg->payload[0];
- return PLDM_SUCCESS;
-}
-
-int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(completion_code)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_RESPONSE;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_VERIFY_COMPLETE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- msg->payload[0] = completion_code;
-
- return PLDM_SUCCESS;
-}
-
-int decode_apply_complete_req(
- const struct pldm_msg *msg, size_t payload_length, uint8_t *apply_result,
- bitfield16_t *comp_activation_methods_modification)
-{
- if (msg == NULL || apply_result == NULL ||
- comp_activation_methods_modification == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(struct pldm_apply_complete_req)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_apply_complete_req *request =
- (struct pldm_apply_complete_req *)msg->payload;
-
- *apply_result = request->apply_result;
- comp_activation_methods_modification->value =
- le16toh(request->comp_activation_methods_modification.value);
-
- if ((*apply_result != PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD) &&
- comp_activation_methods_modification->value) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- return PLDM_SUCCESS;
-}
-
-int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(completion_code)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_RESPONSE;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_APPLY_COMPLETE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- msg->payload[0] = completion_code;
-
- return PLDM_SUCCESS;
-}
-
-int encode_activate_firmware_req(uint8_t instance_id,
- bool8_t self_contained_activation_req,
- struct pldm_msg *msg, size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(struct pldm_activate_firmware_req)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- if (!is_self_contained_activation_req_valid(
- self_contained_activation_req)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_ACTIVATE_FIRMWARE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- struct pldm_activate_firmware_req *request =
- (struct pldm_activate_firmware_req *)msg->payload;
-
- request->self_contained_activation_req = self_contained_activation_req;
-
- return PLDM_SUCCESS;
-}
-
-int decode_activate_firmware_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint16_t *estimated_time_activation)
-{
- if (msg == NULL || completion_code == NULL ||
- estimated_time_activation == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_activate_firmware_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_activate_firmware_resp *response =
- (struct pldm_activate_firmware_resp *)msg->payload;
-
- *estimated_time_activation =
- le16toh(response->estimated_time_activation);
-
- return PLDM_SUCCESS;
-}
-
-int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg,
- size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != PLDM_GET_STATUS_REQ_BYTES) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_GET_STATUS;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- return PLDM_SUCCESS;
-}
-
-int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length,
- uint8_t *completion_code, uint8_t *current_state,
- uint8_t *previous_state, uint8_t *aux_state,
- uint8_t *aux_state_status, uint8_t *progress_percent,
- uint8_t *reason_code,
- bitfield32_t *update_option_flags_enabled)
-{
- if (msg == NULL || completion_code == NULL || current_state == NULL ||
- previous_state == NULL || aux_state == NULL ||
- aux_state_status == NULL || progress_percent == NULL ||
- reason_code == NULL || update_option_flags_enabled == NULL ||
- !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_get_status_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
- struct pldm_get_status_resp *response =
- (struct pldm_get_status_resp *)msg->payload;
-
- if (!is_state_valid(response->current_state)) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (!is_state_valid(response->previous_state)) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (!is_aux_state_valid(response->aux_state)) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (!is_aux_state_status_valid(response->aux_state_status)) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (response->progress_percent > PLDM_FWUP_MAX_PROGRESS_PERCENT) {
- return PLDM_ERROR_INVALID_DATA;
- }
- if (!is_reason_code_valid(response->reason_code)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if ((response->current_state == PLDM_FD_STATE_IDLE) ||
- (response->current_state == PLDM_FD_STATE_LEARN_COMPONENTS) ||
- (response->current_state == PLDM_FD_STATE_READY_XFER)) {
- if (response->aux_state !=
- PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER) {
- return PLDM_ERROR_INVALID_DATA;
- }
- }
-
- *current_state = response->current_state;
- *previous_state = response->previous_state;
- *aux_state = response->aux_state;
- *aux_state_status = response->aux_state_status;
- *progress_percent = response->progress_percent;
- *reason_code = response->reason_code;
- update_option_flags_enabled->value =
- le32toh(response->update_option_flags_enabled.value);
-
- return PLDM_SUCCESS;
-}
-
-int encode_cancel_update_component_req(uint8_t instance_id,
- struct pldm_msg *msg,
- size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_CANCEL_UPDATE_COMPONENT;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- return PLDM_SUCCESS;
-}
-
-int decode_cancel_update_component_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code)
-{
- if (msg == NULL || completion_code == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != sizeof(*completion_code)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- *completion_code = msg->payload[0];
- return PLDM_SUCCESS;
-}
-
-int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg,
- size_t payload_length)
-{
- if (msg == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length != PLDM_CANCEL_UPDATE_REQ_BYTES) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.instance = instance_id;
- header.msg_type = PLDM_REQUEST;
- header.pldm_type = PLDM_FWUP;
- header.command = PLDM_CANCEL_UPDATE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc) {
- return rc;
- }
-
- return PLDM_SUCCESS;
-}
-
-int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length,
- uint8_t *completion_code,
- bool8_t *non_functioning_component_indication,
- bitfield64_t *non_functioning_component_bitmap)
-{
- if (msg == NULL || completion_code == NULL ||
- non_functioning_component_indication == NULL ||
- non_functioning_component_bitmap == NULL || !payload_length) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *completion_code = msg->payload[0];
- if (*completion_code != PLDM_SUCCESS) {
- return PLDM_SUCCESS;
- }
-
- if (payload_length != sizeof(struct pldm_cancel_update_resp)) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
- struct pldm_cancel_update_resp *response =
- (struct pldm_cancel_update_resp *)msg->payload;
-
- if (!is_non_functioning_component_indication_valid(
- response->non_functioning_component_indication)) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- *non_functioning_component_indication =
- response->non_functioning_component_indication;
-
- if (*non_functioning_component_indication) {
- non_functioning_component_bitmap->value =
- le64toh(response->non_functioning_component_bitmap);
- }
-
- return PLDM_SUCCESS;
-}
+#include "firmware_update.h"
+#include <endian.h>
+#include <string.h>
+
+/** @brief Check whether string type value is valid
+ *
+ * @return true if string type value is valid, false if not
+ */
+static bool is_string_type_valid(uint8_t string_type)
+{
+ switch (string_type) {
+ case PLDM_STR_TYPE_UNKNOWN:
+ return false;
+ case PLDM_STR_TYPE_ASCII:
+ case PLDM_STR_TYPE_UTF_8:
+ case PLDM_STR_TYPE_UTF_16:
+ case PLDM_STR_TYPE_UTF_16LE:
+ case PLDM_STR_TYPE_UTF_16BE:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/** @brief Return the length of the descriptor type described in firmware update
+ * specification
+ *
+ * @return length of the descriptor type if descriptor type is valid else
+ * return 0
+ */
+static uint16_t get_descriptor_type_length(uint16_t descriptor_type)
+{
+ switch (descriptor_type) {
+
+ case PLDM_FWUP_PCI_VENDOR_ID:
+ return PLDM_FWUP_PCI_VENDOR_ID_LENGTH;
+ case PLDM_FWUP_IANA_ENTERPRISE_ID:
+ return PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH;
+ case PLDM_FWUP_UUID:
+ return PLDM_FWUP_UUID_LENGTH;
+ case PLDM_FWUP_PNP_VENDOR_ID:
+ return PLDM_FWUP_PNP_VENDOR_ID_LENGTH;
+ case PLDM_FWUP_ACPI_VENDOR_ID:
+ return PLDM_FWUP_ACPI_VENDOR_ID_LENGTH;
+ case PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID:
+ return PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH;
+ case PLDM_FWUP_SCSI_VENDOR_ID:
+ return PLDM_FWUP_SCSI_VENDOR_ID_LENGTH;
+ case PLDM_FWUP_PCI_DEVICE_ID:
+ return PLDM_FWUP_PCI_DEVICE_ID_LENGTH;
+ case PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID:
+ return PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH;
+ case PLDM_FWUP_PCI_SUBSYSTEM_ID:
+ return PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH;
+ case PLDM_FWUP_PCI_REVISION_ID:
+ return PLDM_FWUP_PCI_REVISION_ID_LENGTH;
+ case PLDM_FWUP_PNP_PRODUCT_IDENTIFIER:
+ return PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH;
+ case PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER:
+ return PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH;
+ case PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING:
+ return PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH;
+ case PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING:
+ return PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH;
+ case PLDM_FWUP_SCSI_PRODUCT_ID:
+ return PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH;
+ case PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE:
+ return PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH;
+ default:
+ return 0;
+ }
+}
+
+/** @brief Check whether ComponentResponse is valid
+ *
+ * @return true if ComponentResponse is valid, false if not
+ */
+static bool is_comp_resp_valid(uint8_t comp_resp)
+{
+ switch (comp_resp) {
+ case PLDM_CR_COMP_CAN_BE_UPDATED:
+ case PLDM_CR_COMP_MAY_BE_UPDATEABLE:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/** @brief Check whether ComponentResponseCode is valid
+ *
+ * @return true if ComponentResponseCode is valid, false if not
+ */
+static bool is_comp_resp_code_valid(uint8_t comp_resp_code)
+{
+ switch (comp_resp_code) {
+ case PLDM_CRC_COMP_CAN_BE_UPDATED:
+ case PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL:
+ case PLDM_CRC_COMP_COMPARISON_STAMP_LOWER:
+ case PLDM_CRC_INVALID_COMP_COMPARISON_STAMP:
+ case PLDM_CRC_COMP_CONFLICT:
+ case PLDM_CRC_COMP_PREREQUISITES_NOT_MET:
+ case PLDM_CRC_COMP_NOT_SUPPORTED:
+ case PLDM_CRC_COMP_SECURITY_RESTRICTIONS:
+ case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET:
+ case PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY:
+ case PLDM_CRC_COMP_VER_STR_IDENTICAL:
+ case PLDM_CRC_COMP_VER_STR_LOWER:
+ return true;
+
+ default:
+ if (comp_resp_code >=
+ PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN &&
+ comp_resp_code <=
+ PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) {
+ return true;
+ }
+ return false;
+ }
+}
+
+/** @brief Check whether ComponentCompatibilityResponse is valid
+ *
+ * @return true if ComponentCompatibilityResponse is valid, false if not
+ */
+static bool is_comp_compatibility_resp_valid(uint8_t comp_compatibility_resp)
+{
+ switch (comp_compatibility_resp) {
+ case PLDM_CCR_COMP_CAN_BE_UPDATED:
+ case PLDM_CCR_COMP_CANNOT_BE_UPDATED:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/** @brief Check whether ComponentCompatibilityResponse Code is valid
+ *
+ * @return true if ComponentCompatibilityResponse Code is valid, false if not
+ */
+static bool
+is_comp_compatibility_resp_code_valid(uint8_t comp_compatibility_resp_code)
+{
+ switch (comp_compatibility_resp_code) {
+ case PLDM_CCRC_NO_RESPONSE_CODE:
+ case PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL:
+ case PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER:
+ case PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP:
+ case PLDM_CCRC_COMP_CONFLICT:
+ case PLDM_CCRC_COMP_PREREQUISITES_NOT_MET:
+ case PLDM_CCRC_COMP_NOT_SUPPORTED:
+ case PLDM_CCRC_COMP_SECURITY_RESTRICTIONS:
+ case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET:
+ case PLDM_CCRC_COMP_INFO_NO_MATCH:
+ case PLDM_CCRC_COMP_VER_STR_IDENTICAL:
+ case PLDM_CCRC_COMP_VER_STR_LOWER:
+ return true;
+
+ default:
+ if (comp_compatibility_resp_code >=
+ PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN &&
+ comp_compatibility_resp_code <=
+ PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) {
+ return true;
+ }
+ return false;
+ }
+}
+
+/** @brief Check whether SelfContainedActivationRequest is valid
+ *
+ * @return true if SelfContainedActivationRequest is valid, false if not
+ */
+static bool
+is_self_contained_activation_req_valid(bool8_t self_contained_activation_req)
+{
+ switch (self_contained_activation_req) {
+ case PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS:
+ case PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/** @brief Check if current or previous status in GetStatus command response is
+ * valid
+ *
+ * @param[in] state - current or previous different state machine state of
+ * the FD
+ * @return true if state is valid, false if not
+ */
+static bool is_state_valid(uint8_t state)
+{
+ switch (state) {
+ case PLDM_FD_STATE_IDLE:
+ case PLDM_FD_STATE_LEARN_COMPONENTS:
+ case PLDM_FD_STATE_READY_XFER:
+ case PLDM_FD_STATE_DOWNLOAD:
+ case PLDM_FD_STATE_VERIFY:
+ case PLDM_FD_STATE_APPLY:
+ case PLDM_FD_STATE_ACTIVATE:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/** @brief Check if aux state in GetStatus command response is valid
+ *
+ * @param[in] aux_state - provides additional information to the UA to describe
+ * the current operation state of the FD/FDP
+ *
+ * @return true if aux state is valid, false if not
+ */
+static bool is_aux_state_valid(uint8_t aux_state)
+{
+ switch (aux_state) {
+ case PLDM_FD_OPERATION_IN_PROGRESS:
+ case PLDM_FD_OPERATION_SUCCESSFUL:
+ case PLDM_FD_OPERATION_FAILED:
+ case PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/** @brief Check if aux state status in GetStatus command response is valid
+ *
+ * @param[in] aux_state_status - aux state status
+ *
+ * @return true if aux state status is valid, false if not
+ */
+static bool is_aux_state_status_valid(uint8_t aux_state_status)
+{
+ if (aux_state_status == PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS ||
+ aux_state_status == PLDM_FD_TIMEOUT ||
+ aux_state_status == PLDM_FD_GENERIC_ERROR) {
+ return true;
+ } else if (aux_state_status >=
+ PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START &&
+ aux_state_status <= PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END) {
+ return true;
+ }
+
+ return false;
+}
+
+/** @brief Check if reason code in GetStatus command response is valid
+ *
+ * @param[in] reason_code - provides the reason for why the current state
+ * entered the IDLE state
+ *
+ * @return true if reason code is valid, false if not
+ */
+static bool is_reason_code_valid(uint8_t reason_code)
+{
+
+ switch (reason_code) {
+ case PLDM_FD_INITIALIZATION:
+ case PLDM_FD_ACTIVATE_FW:
+ case PLDM_FD_CANCEL_UPDATE:
+ case PLDM_FD_TIMEOUT_LEARN_COMPONENT:
+ case PLDM_FD_TIMEOUT_READY_XFER:
+ case PLDM_FD_TIMEOUT_DOWNLOAD:
+ case PLDM_FD_TIMEOUT_VERIFY:
+ case PLDM_FD_TIMEOUT_APPLY:
+ return true;
+
+ default:
+ if (reason_code >= PLDM_FD_STATUS_VENDOR_DEFINED_MIN) {
+ return true;
+ }
+ return false;
+ }
+}
+
+/** @brief Check if non functioning component indication in CancelUpdate
+ * response is valid
+ *
+ * @return true if non functioning component indication is valid, false if not
+ */
+static bool is_non_functioning_component_indication_valid(
+ bool8_t non_functioning_component_indication)
+{
+ switch (non_functioning_component_indication) {
+ case PLDM_FWUP_COMPONENTS_FUNCTIONING:
+ case PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+int decode_pldm_package_header_info(
+ const uint8_t *data, size_t length,
+ struct pldm_package_header_information *package_header_info,
+ struct variable_field *package_version_str)
+{
+ if (data == NULL || package_header_info == NULL ||
+ package_version_str == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_package_header_information)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_package_header_information *data_header =
+ (struct pldm_package_header_information *)(data);
+
+ if (!is_string_type_valid(data_header->package_version_string_type) ||
+ (data_header->package_version_string_length == 0)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_package_header_information) +
+ data_header->package_version_string_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if ((data_header->component_bitmap_bit_length %
+ PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ memcpy(package_header_info->uuid, data_header->uuid,
+ sizeof(data_header->uuid));
+ package_header_info->package_header_format_version =
+ data_header->package_header_format_version;
+ package_header_info->package_header_size =
+ le16toh(data_header->package_header_size);
+ memcpy(package_header_info->timestamp104, data_header->timestamp104,
+ sizeof(data_header->timestamp104));
+ package_header_info->component_bitmap_bit_length =
+ le16toh(data_header->component_bitmap_bit_length);
+ package_header_info->package_version_string_type =
+ data_header->package_version_string_type;
+ package_header_info->package_version_string_length =
+ data_header->package_version_string_length;
+ package_version_str->ptr =
+ data + sizeof(struct pldm_package_header_information);
+ package_version_str->length =
+ package_header_info->package_version_string_length;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_firmware_device_id_record(
+ const uint8_t *data, size_t length, uint16_t component_bitmap_bit_length,
+ struct pldm_firmware_device_id_record *fw_device_id_record,
+ struct variable_field *applicable_components,
+ struct variable_field *comp_image_set_version_str,
+ struct variable_field *record_descriptors,
+ struct variable_field *fw_device_pkg_data)
+{
+ if (data == NULL || fw_device_id_record == NULL ||
+ applicable_components == NULL ||
+ comp_image_set_version_str == NULL || record_descriptors == NULL ||
+ fw_device_pkg_data == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_firmware_device_id_record)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if ((component_bitmap_bit_length %
+ PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_firmware_device_id_record *data_record =
+ (struct pldm_firmware_device_id_record *)(data);
+
+ if (!is_string_type_valid(
+ data_record->comp_image_set_version_string_type) ||
+ (data_record->comp_image_set_version_string_length == 0)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ fw_device_id_record->record_length =
+ le16toh(data_record->record_length);
+ fw_device_id_record->descriptor_count = data_record->descriptor_count;
+ fw_device_id_record->device_update_option_flags.value =
+ le32toh(data_record->device_update_option_flags.value);
+ fw_device_id_record->comp_image_set_version_string_type =
+ data_record->comp_image_set_version_string_type;
+ fw_device_id_record->comp_image_set_version_string_length =
+ data_record->comp_image_set_version_string_length;
+ fw_device_id_record->fw_device_pkg_data_length =
+ le16toh(data_record->fw_device_pkg_data_length);
+
+ if (length < fw_device_id_record->record_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ uint16_t applicable_components_length =
+ component_bitmap_bit_length / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE;
+ uint16_t calc_min_record_length =
+ sizeof(struct pldm_firmware_device_id_record) +
+ applicable_components_length +
+ data_record->comp_image_set_version_string_length +
+ PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN +
+ fw_device_id_record->fw_device_pkg_data_length;
+
+ if (fw_device_id_record->record_length < calc_min_record_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ applicable_components->ptr =
+ data + sizeof(struct pldm_firmware_device_id_record);
+ applicable_components->length = applicable_components_length;
+
+ comp_image_set_version_str->ptr =
+ applicable_components->ptr + applicable_components->length;
+ comp_image_set_version_str->length =
+ fw_device_id_record->comp_image_set_version_string_length;
+
+ record_descriptors->ptr = comp_image_set_version_str->ptr +
+ comp_image_set_version_str->length;
+ record_descriptors->length =
+ fw_device_id_record->record_length -
+ sizeof(struct pldm_firmware_device_id_record) -
+ applicable_components_length -
+ fw_device_id_record->comp_image_set_version_string_length -
+ fw_device_id_record->fw_device_pkg_data_length;
+
+ if (fw_device_id_record->fw_device_pkg_data_length) {
+ fw_device_pkg_data->ptr =
+ record_descriptors->ptr + record_descriptors->length;
+ fw_device_pkg_data->length =
+ fw_device_id_record->fw_device_pkg_data_length;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
+ uint16_t *descriptor_type,
+ struct variable_field *descriptor_data)
+{
+ uint16_t descriptor_length = 0;
+
+ if (data == NULL || descriptor_type == NULL ||
+ descriptor_data == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_descriptor_tlv *entry =
+ (struct pldm_descriptor_tlv *)(data);
+
+ *descriptor_type = le16toh(entry->descriptor_type);
+ descriptor_length = le16toh(entry->descriptor_length);
+ if (*descriptor_type != PLDM_FWUP_VENDOR_DEFINED) {
+ if (descriptor_length !=
+ get_descriptor_type_length(*descriptor_type)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ }
+
+ if (length < (sizeof(*descriptor_type) + sizeof(descriptor_length) +
+ descriptor_length)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ descriptor_data->ptr = entry->descriptor_data;
+ descriptor_data->length = descriptor_length;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_vendor_defined_descriptor_value(
+ const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
+ struct variable_field *descriptor_title_str,
+ struct variable_field *descriptor_data)
+{
+ if (data == NULL || descriptor_title_str_type == NULL ||
+ descriptor_title_str == NULL || descriptor_data == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_vendor_defined_descriptor_title_data)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_vendor_defined_descriptor_title_data *entry =
+ (struct pldm_vendor_defined_descriptor_title_data *)(data);
+ if (!is_string_type_valid(
+ entry->vendor_defined_descriptor_title_str_type) ||
+ (entry->vendor_defined_descriptor_title_str_len == 0)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ // Assuming atleast 1 byte of VendorDefinedDescriptorData
+ if (length < (sizeof(struct pldm_vendor_defined_descriptor_title_data) +
+ entry->vendor_defined_descriptor_title_str_len)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ *descriptor_title_str_type =
+ entry->vendor_defined_descriptor_title_str_type;
+ descriptor_title_str->ptr = entry->vendor_defined_descriptor_title_str;
+ descriptor_title_str->length =
+ entry->vendor_defined_descriptor_title_str_len;
+
+ descriptor_data->ptr =
+ descriptor_title_str->ptr + descriptor_title_str->length;
+ descriptor_data->length =
+ length - sizeof(entry->vendor_defined_descriptor_title_str_type) -
+ sizeof(entry->vendor_defined_descriptor_title_str_len) -
+ descriptor_title_str->length;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_pldm_comp_image_info(
+ const uint8_t *data, size_t length,
+ struct pldm_component_image_information *pldm_comp_image_info,
+ struct variable_field *comp_version_str)
+{
+ if (data == NULL || pldm_comp_image_info == NULL ||
+ comp_version_str == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_component_image_information)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_component_image_information *data_header =
+ (struct pldm_component_image_information *)(data);
+
+ if (!is_string_type_valid(data_header->comp_version_string_type) ||
+ (data_header->comp_version_string_length == 0)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_component_image_information) +
+ data_header->comp_version_string_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ pldm_comp_image_info->comp_classification =
+ le16toh(data_header->comp_classification);
+ pldm_comp_image_info->comp_identifier =
+ le16toh(data_header->comp_identifier);
+ pldm_comp_image_info->comp_comparison_stamp =
+ le32toh(data_header->comp_comparison_stamp);
+ pldm_comp_image_info->comp_options.value =
+ le16toh(data_header->comp_options.value);
+ pldm_comp_image_info->requested_comp_activation_method.value =
+ le16toh(data_header->requested_comp_activation_method.value);
+ pldm_comp_image_info->comp_location_offset =
+ le32toh(data_header->comp_location_offset);
+ pldm_comp_image_info->comp_size = le32toh(data_header->comp_size);
+ pldm_comp_image_info->comp_version_string_type =
+ data_header->comp_version_string_type;
+ pldm_comp_image_info->comp_version_string_length =
+ data_header->comp_version_string_length;
+
+ if ((pldm_comp_image_info->comp_options.bits.bit1 == false &&
+ pldm_comp_image_info->comp_comparison_stamp !=
+ PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (pldm_comp_image_info->comp_location_offset == 0 ||
+ pldm_comp_image_info->comp_size == 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ comp_version_str->ptr =
+ data + sizeof(struct pldm_component_image_information);
+ comp_version_str->length =
+ pldm_comp_image_info->comp_version_string_length;
+
+ return PLDM_SUCCESS;
+}
+
+int encode_query_device_identifiers_req(uint8_t instance_id,
+ size_t payload_length,
+ struct pldm_msg *msg)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
+ PLDM_QUERY_DEVICE_IDENTIFIERS, msg);
+}
+
+int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint32_t *device_identifiers_len,
+ uint8_t *descriptor_count,
+ uint8_t **descriptor_data)
+{
+ if (msg == NULL || completion_code == NULL ||
+ device_identifiers_len == NULL || descriptor_count == NULL ||
+ descriptor_data == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (PLDM_SUCCESS != *completion_code) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length <
+ sizeof(struct pldm_query_device_identifiers_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_query_device_identifiers_resp *response =
+ (struct pldm_query_device_identifiers_resp *)msg->payload;
+ *device_identifiers_len = le32toh(response->device_identifiers_len);
+
+ if (*device_identifiers_len < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if (payload_length !=
+ sizeof(struct pldm_query_device_identifiers_resp) +
+ *device_identifiers_len) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ *descriptor_count = response->descriptor_count;
+
+ if (*descriptor_count == 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ *descriptor_data =
+ (uint8_t *)(msg->payload +
+ sizeof(struct pldm_query_device_identifiers_resp));
+ return PLDM_SUCCESS;
+}
+
+int encode_get_firmware_parameters_req(uint8_t instance_id,
+ size_t payload_length,
+ struct pldm_msg *msg)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
+ PLDM_GET_FIRMWARE_PARAMETERS, msg);
+}
+
+int decode_get_firmware_parameters_resp(
+ const struct pldm_msg *msg, size_t payload_length,
+ struct pldm_get_firmware_parameters_resp *resp_data,
+ struct variable_field *active_comp_image_set_ver_str,
+ struct variable_field *pending_comp_image_set_ver_str,
+ struct variable_field *comp_parameter_table)
+{
+ if (msg == NULL || resp_data == NULL ||
+ active_comp_image_set_ver_str == NULL ||
+ pending_comp_image_set_ver_str == NULL ||
+ comp_parameter_table == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ resp_data->completion_code = msg->payload[0];
+ if (PLDM_SUCCESS != resp_data->completion_code) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length < sizeof(struct pldm_get_firmware_parameters_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_get_firmware_parameters_resp *response =
+ (struct pldm_get_firmware_parameters_resp *)msg->payload;
+
+ if (!is_string_type_valid(
+ response->active_comp_image_set_ver_str_type) ||
+ (response->active_comp_image_set_ver_str_len == 0)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (response->pending_comp_image_set_ver_str_len == 0) {
+ if (response->pending_comp_image_set_ver_str_type !=
+ PLDM_STR_TYPE_UNKNOWN) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ } else {
+ if (!is_string_type_valid(
+ response->pending_comp_image_set_ver_str_type)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ }
+
+ size_t partial_response_length =
+ sizeof(struct pldm_get_firmware_parameters_resp) +
+ response->active_comp_image_set_ver_str_len +
+ response->pending_comp_image_set_ver_str_len;
+
+ if (payload_length < partial_response_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ resp_data->capabilities_during_update.value =
+ le32toh(response->capabilities_during_update.value);
+ resp_data->comp_count = le16toh(response->comp_count);
+ resp_data->active_comp_image_set_ver_str_type =
+ response->active_comp_image_set_ver_str_type;
+ resp_data->active_comp_image_set_ver_str_len =
+ response->active_comp_image_set_ver_str_len;
+ resp_data->pending_comp_image_set_ver_str_type =
+ response->pending_comp_image_set_ver_str_type;
+ resp_data->pending_comp_image_set_ver_str_len =
+ response->pending_comp_image_set_ver_str_len;
+
+ active_comp_image_set_ver_str->ptr =
+ msg->payload + sizeof(struct pldm_get_firmware_parameters_resp);
+ active_comp_image_set_ver_str->length =
+ resp_data->active_comp_image_set_ver_str_len;
+
+ if (resp_data->pending_comp_image_set_ver_str_len != 0) {
+ pending_comp_image_set_ver_str->ptr =
+ msg->payload +
+ sizeof(struct pldm_get_firmware_parameters_resp) +
+ resp_data->active_comp_image_set_ver_str_len;
+ pending_comp_image_set_ver_str->length =
+ resp_data->pending_comp_image_set_ver_str_len;
+ } else {
+ pending_comp_image_set_ver_str->ptr = NULL;
+ pending_comp_image_set_ver_str->length = 0;
+ }
+
+ if (payload_length > partial_response_length && resp_data->comp_count) {
+ comp_parameter_table->ptr =
+ msg->payload +
+ sizeof(struct pldm_get_firmware_parameters_resp) +
+ resp_data->active_comp_image_set_ver_str_len +
+ resp_data->pending_comp_image_set_ver_str_len;
+ comp_parameter_table->length =
+ payload_length - partial_response_length;
+ } else {
+ comp_parameter_table->ptr = NULL;
+ comp_parameter_table->length = 0;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int decode_get_firmware_parameters_resp_comp_entry(
+ const uint8_t *data, size_t length,
+ struct pldm_component_parameter_entry *component_data,
+ struct variable_field *active_comp_ver_str,
+ struct variable_field *pending_comp_ver_str)
+{
+ if (data == NULL || component_data == NULL ||
+ active_comp_ver_str == NULL || pending_comp_ver_str == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (length < sizeof(struct pldm_component_parameter_entry)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_component_parameter_entry *entry =
+ (struct pldm_component_parameter_entry *)(data);
+ if (entry->active_comp_ver_str_len == 0) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ size_t entry_length = sizeof(struct pldm_component_parameter_entry) +
+ entry->active_comp_ver_str_len +
+ entry->pending_comp_ver_str_len;
+
+ if (length < entry_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ component_data->comp_classification =
+ le16toh(entry->comp_classification);
+ component_data->comp_identifier = le16toh(entry->comp_identifier);
+ component_data->comp_classification_index =
+ entry->comp_classification_index;
+ component_data->active_comp_comparison_stamp =
+ le32toh(entry->active_comp_comparison_stamp);
+ component_data->active_comp_ver_str_type =
+ entry->active_comp_ver_str_type;
+ component_data->active_comp_ver_str_len =
+ entry->active_comp_ver_str_len;
+ memcpy(component_data->active_comp_release_date,
+ entry->active_comp_release_date,
+ sizeof(entry->active_comp_release_date));
+ component_data->pending_comp_comparison_stamp =
+ le32toh(entry->pending_comp_comparison_stamp);
+ component_data->pending_comp_ver_str_type =
+ entry->pending_comp_ver_str_type;
+ component_data->pending_comp_ver_str_len =
+ entry->pending_comp_ver_str_len;
+ memcpy(component_data->pending_comp_release_date,
+ entry->pending_comp_release_date,
+ sizeof(entry->pending_comp_release_date));
+ component_data->comp_activation_methods.value =
+ le16toh(entry->comp_activation_methods.value);
+ component_data->capabilities_during_update.value =
+ le32toh(entry->capabilities_during_update.value);
+
+ active_comp_ver_str->ptr =
+ data + sizeof(struct pldm_component_parameter_entry);
+ active_comp_ver_str->length = entry->active_comp_ver_str_len;
+
+ if (entry->pending_comp_ver_str_len != 0) {
+
+ pending_comp_ver_str->ptr =
+ data + sizeof(struct pldm_component_parameter_entry) +
+ entry->active_comp_ver_str_len;
+ pending_comp_ver_str->length = entry->pending_comp_ver_str_len;
+ } else {
+ pending_comp_ver_str->ptr = NULL;
+ pending_comp_ver_str->length = 0;
+ }
+ return PLDM_SUCCESS;
+}
+
+int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size,
+ uint16_t num_of_comp,
+ uint8_t max_outstanding_transfer_req,
+ uint16_t pkg_data_len,
+ uint8_t comp_image_set_ver_str_type,
+ uint8_t comp_image_set_ver_str_len,
+ const struct variable_field *comp_img_set_ver_str,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (comp_img_set_ver_str == NULL || comp_img_set_ver_str->ptr == NULL ||
+ msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(struct pldm_request_update_req) +
+ comp_img_set_ver_str->length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if ((comp_image_set_ver_str_len == 0) ||
+ (comp_image_set_ver_str_len != comp_img_set_ver_str->length)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if ((max_transfer_size < PLDM_FWUP_BASELINE_TRANSFER_SIZE) ||
+ (max_outstanding_transfer_req < PLDM_FWUP_MIN_OUTSTANDING_REQ)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!is_string_type_valid(comp_image_set_ver_str_type)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_REQUEST_UPDATE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ struct pldm_request_update_req *request =
+ (struct pldm_request_update_req *)msg->payload;
+
+ request->max_transfer_size = htole32(max_transfer_size);
+ request->num_of_comp = htole16(num_of_comp);
+ request->max_outstanding_transfer_req = max_outstanding_transfer_req;
+ request->pkg_data_len = htole16(pkg_data_len);
+ request->comp_image_set_ver_str_type = comp_image_set_ver_str_type;
+ request->comp_image_set_ver_str_len = comp_image_set_ver_str_len;
+
+ memcpy(msg->payload + sizeof(struct pldm_request_update_req),
+ comp_img_set_ver_str->ptr, comp_img_set_ver_str->length);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_request_update_resp(const struct pldm_msg *msg,
+ size_t payload_length, uint8_t *completion_code,
+ uint16_t *fd_meta_data_len,
+ uint8_t *fd_will_send_pkg_data)
+{
+ if (msg == NULL || completion_code == NULL ||
+ fd_meta_data_len == NULL || fd_will_send_pkg_data == NULL ||
+ !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_request_update_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_request_update_resp *response =
+ (struct pldm_request_update_resp *)msg->payload;
+
+ *fd_meta_data_len = le16toh(response->fd_meta_data_len);
+ *fd_will_send_pkg_data = response->fd_will_send_pkg_data;
+
+ return PLDM_SUCCESS;
+}
+
+int encode_pass_component_table_req(
+ uint8_t instance_id, uint8_t transfer_flag, uint16_t comp_classification,
+ uint16_t comp_identifier, uint8_t comp_classification_index,
+ uint32_t comp_comparison_stamp, uint8_t comp_ver_str_type,
+ uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(struct pldm_pass_component_table_req) +
+ comp_ver_str->length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if ((comp_ver_str_len == 0) ||
+ (comp_ver_str_len != comp_ver_str->length)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!is_transfer_flag_valid(transfer_flag)) {
+ return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
+ }
+
+ if (!is_string_type_valid(comp_ver_str_type)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_PASS_COMPONENT_TABLE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ struct pldm_pass_component_table_req *request =
+ (struct pldm_pass_component_table_req *)msg->payload;
+
+ request->transfer_flag = transfer_flag;
+ request->comp_classification = htole16(comp_classification);
+ request->comp_identifier = htole16(comp_identifier);
+ request->comp_classification_index = comp_classification_index;
+ request->comp_comparison_stamp = htole32(comp_comparison_stamp);
+ request->comp_ver_str_type = comp_ver_str_type;
+ request->comp_ver_str_len = comp_ver_str_len;
+
+ memcpy(msg->payload + sizeof(struct pldm_pass_component_table_req),
+ comp_ver_str->ptr, comp_ver_str->length);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_pass_component_table_resp(const struct pldm_msg *msg,
+ const size_t payload_length,
+ uint8_t *completion_code,
+ uint8_t *comp_resp,
+ uint8_t *comp_resp_code)
+{
+ if (msg == NULL || completion_code == NULL || comp_resp == NULL ||
+ comp_resp_code == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_pass_component_table_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_pass_component_table_resp *response =
+ (struct pldm_pass_component_table_resp *)msg->payload;
+
+ if (!is_comp_resp_valid(response->comp_resp)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!is_comp_resp_code_valid(response->comp_resp_code)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *comp_resp = response->comp_resp;
+ *comp_resp_code = response->comp_resp_code;
+
+ return PLDM_SUCCESS;
+}
+
+int encode_update_component_req(
+ uint8_t instance_id, uint16_t comp_classification, uint16_t comp_identifier,
+ uint8_t comp_classification_index, uint32_t comp_comparison_stamp,
+ uint32_t comp_image_size, bitfield32_t update_option_flags,
+ uint8_t comp_ver_str_type, uint8_t comp_ver_str_len,
+ const struct variable_field *comp_ver_str, struct pldm_msg *msg,
+ size_t payload_length)
+{
+ if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length !=
+ sizeof(struct pldm_update_component_req) + comp_ver_str->length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if (!comp_image_size) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if ((comp_ver_str_len == 0) ||
+ (comp_ver_str_len != comp_ver_str->length)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!is_string_type_valid(comp_ver_str_type)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_UPDATE_COMPONENT;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ struct pldm_update_component_req *request =
+ (struct pldm_update_component_req *)msg->payload;
+
+ request->comp_classification = htole16(comp_classification);
+ request->comp_identifier = htole16(comp_identifier);
+ request->comp_classification_index = comp_classification_index;
+ request->comp_comparison_stamp = htole32(comp_comparison_stamp);
+ request->comp_image_size = htole32(comp_image_size);
+ request->update_option_flags.value = htole32(update_option_flags.value);
+ request->comp_ver_str_type = comp_ver_str_type;
+ request->comp_ver_str_len = comp_ver_str_len;
+
+ memcpy(msg->payload + sizeof(struct pldm_update_component_req),
+ comp_ver_str->ptr, comp_ver_str->length);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_update_component_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint8_t *comp_compatability_resp,
+ uint8_t *comp_compatability_resp_code,
+ bitfield32_t *update_option_flags_enabled,
+ uint16_t *time_before_req_fw_data)
+{
+ if (msg == NULL || completion_code == NULL ||
+ comp_compatability_resp == NULL ||
+ comp_compatability_resp_code == NULL ||
+ update_option_flags_enabled == NULL ||
+ time_before_req_fw_data == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_update_component_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_update_component_resp *response =
+ (struct pldm_update_component_resp *)msg->payload;
+
+ if (!is_comp_compatibility_resp_valid(
+ response->comp_compatability_resp)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!is_comp_compatibility_resp_code_valid(
+ response->comp_compatability_resp_code)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *comp_compatability_resp = response->comp_compatability_resp;
+ *comp_compatability_resp_code = response->comp_compatability_resp_code;
+ update_option_flags_enabled->value =
+ le32toh(response->update_option_flags_enabled.value);
+ *time_before_req_fw_data = le16toh(response->time_before_req_fw_data);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_request_firmware_data_req(const struct pldm_msg *msg,
+ size_t payload_length, uint32_t *offset,
+ uint32_t *length)
+{
+ if (msg == NULL || offset == NULL || length == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (payload_length != sizeof(struct pldm_request_firmware_data_req)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ struct pldm_request_firmware_data_req *request =
+ (struct pldm_request_firmware_data_req *)msg->payload;
+ *offset = le32toh(request->offset);
+ *length = le32toh(request->length);
+
+ if (*length < PLDM_FWUP_BASELINE_TRANSFER_SIZE) {
+ return PLDM_FWUP_INVALID_TRANSFER_LENGTH;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int encode_request_firmware_data_resp(uint8_t instance_id,
+ uint8_t completion_code,
+ struct pldm_msg *msg,
+ size_t payload_length)
+{
+ if (msg == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_REQUEST_FIRMWARE_DATA;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ msg->payload[0] = completion_code;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_transfer_complete_req(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *transfer_result)
+{
+ if (msg == NULL || transfer_result == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(*transfer_result)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ *transfer_result = msg->payload[0];
+ return PLDM_SUCCESS;
+}
+
+int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(completion_code)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_TRANSFER_COMPLETE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ msg->payload[0] = completion_code;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_verify_complete_req(const struct pldm_msg *msg,
+ size_t payload_length, uint8_t *verify_result)
+{
+ if (msg == NULL || verify_result == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(*verify_result)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ *verify_result = msg->payload[0];
+ return PLDM_SUCCESS;
+}
+
+int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(completion_code)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_VERIFY_COMPLETE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ msg->payload[0] = completion_code;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_apply_complete_req(
+ const struct pldm_msg *msg, size_t payload_length, uint8_t *apply_result,
+ bitfield16_t *comp_activation_methods_modification)
+{
+ if (msg == NULL || apply_result == NULL ||
+ comp_activation_methods_modification == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(struct pldm_apply_complete_req)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_apply_complete_req *request =
+ (struct pldm_apply_complete_req *)msg->payload;
+
+ *apply_result = request->apply_result;
+ comp_activation_methods_modification->value =
+ le16toh(request->comp_activation_methods_modification.value);
+
+ if ((*apply_result != PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD) &&
+ comp_activation_methods_modification->value) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(completion_code)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_APPLY_COMPLETE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ msg->payload[0] = completion_code;
+
+ return PLDM_SUCCESS;
+}
+
+int encode_activate_firmware_req(uint8_t instance_id,
+ bool8_t self_contained_activation_req,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(struct pldm_activate_firmware_req)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ if (!is_self_contained_activation_req_valid(
+ self_contained_activation_req)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_ACTIVATE_FIRMWARE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ struct pldm_activate_firmware_req *request =
+ (struct pldm_activate_firmware_req *)msg->payload;
+
+ request->self_contained_activation_req = self_contained_activation_req;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_activate_firmware_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint16_t *estimated_time_activation)
+{
+ if (msg == NULL || completion_code == NULL ||
+ estimated_time_activation == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_activate_firmware_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_activate_firmware_resp *response =
+ (struct pldm_activate_firmware_resp *)msg->payload;
+
+ *estimated_time_activation =
+ le16toh(response->estimated_time_activation);
+
+ return PLDM_SUCCESS;
+}
+
+int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg,
+ size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_GET_STATUS_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_GET_STATUS;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code, uint8_t *current_state,
+ uint8_t *previous_state, uint8_t *aux_state,
+ uint8_t *aux_state_status, uint8_t *progress_percent,
+ uint8_t *reason_code,
+ bitfield32_t *update_option_flags_enabled)
+{
+ if (msg == NULL || completion_code == NULL || current_state == NULL ||
+ previous_state == NULL || aux_state == NULL ||
+ aux_state_status == NULL || progress_percent == NULL ||
+ reason_code == NULL || update_option_flags_enabled == NULL ||
+ !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_get_status_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ struct pldm_get_status_resp *response =
+ (struct pldm_get_status_resp *)msg->payload;
+
+ if (!is_state_valid(response->current_state)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (!is_state_valid(response->previous_state)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (!is_aux_state_valid(response->aux_state)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (!is_aux_state_status_valid(response->aux_state_status)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (response->progress_percent > PLDM_FWUP_MAX_PROGRESS_PERCENT) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ if (!is_reason_code_valid(response->reason_code)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if ((response->current_state == PLDM_FD_STATE_IDLE) ||
+ (response->current_state == PLDM_FD_STATE_LEARN_COMPONENTS) ||
+ (response->current_state == PLDM_FD_STATE_READY_XFER)) {
+ if (response->aux_state !=
+ PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ }
+
+ *current_state = response->current_state;
+ *previous_state = response->previous_state;
+ *aux_state = response->aux_state;
+ *aux_state_status = response->aux_state_status;
+ *progress_percent = response->progress_percent;
+ *reason_code = response->reason_code;
+ update_option_flags_enabled->value =
+ le32toh(response->update_option_flags_enabled.value);
+
+ return PLDM_SUCCESS;
+}
+
+int encode_cancel_update_component_req(uint8_t instance_id,
+ struct pldm_msg *msg,
+ size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_CANCEL_UPDATE_COMPONENT;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int decode_cancel_update_component_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code)
+{
+ if (msg == NULL || completion_code == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != sizeof(*completion_code)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ *completion_code = msg->payload[0];
+ return PLDM_SUCCESS;
+}
+
+int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg,
+ size_t payload_length)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_CANCEL_UPDATE_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_FWUP;
+ header.command = PLDM_CANCEL_UPDATE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ return PLDM_SUCCESS;
+}
+
+int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code,
+ bool8_t *non_functioning_component_indication,
+ bitfield64_t *non_functioning_component_bitmap)
+{
+ if (msg == NULL || completion_code == NULL ||
+ non_functioning_component_indication == NULL ||
+ non_functioning_component_bitmap == NULL || !payload_length) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (*completion_code != PLDM_SUCCESS) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != sizeof(struct pldm_cancel_update_resp)) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ struct pldm_cancel_update_resp *response =
+ (struct pldm_cancel_update_resp *)msg->payload;
+
+ if (!is_non_functioning_component_indication_valid(
+ response->non_functioning_component_indication)) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *non_functioning_component_indication =
+ response->non_functioning_component_indication;
+
+ if (*non_functioning_component_indication) {
+ non_functioning_component_bitmap->value =
+ le64toh(response->non_functioning_component_bitmap);
+ }
+
+ return PLDM_SUCCESS;
+}
diff --git a/libpldm/firmware_update.h b/libpldm/firmware_update.h
index ed403bb..a47d80b 100644
--- a/libpldm/firmware_update.h
+++ b/libpldm/firmware_update.h
@@ -1,1132 +1,1132 @@
-#ifndef FW_UPDATE_H
-#define FW_UPDATE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "base.h"
-#include "stdbool.h"
-#include "utils.h"
-
-#define PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE 8
-#define PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP 0xFFFFFFFF
-#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
-/** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
- * 2 bytes for descriptor length and atleast 1 byte of descriptor data
- */
-#define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
-#define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
-#define PLDM_FWUP_BASELINE_TRANSFER_SIZE 32
-#define PLDM_FWUP_MIN_OUTSTANDING_REQ 1
-#define PLDM_GET_STATUS_REQ_BYTES 0
-/* Maximum progress percentage value*/
-#define PLDM_FWUP_MAX_PROGRESS_PERCENT 0x65
-#define PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES 0
-#define PLDM_CANCEL_UPDATE_REQ_BYTES 0
-
-/** @brief PLDM Firmware update commands
- */
-enum pldm_firmware_update_commands {
- PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
- PLDM_GET_FIRMWARE_PARAMETERS = 0x02,
- PLDM_REQUEST_UPDATE = 0x10,
- PLDM_PASS_COMPONENT_TABLE = 0x13,
- PLDM_UPDATE_COMPONENT = 0x14,
- PLDM_REQUEST_FIRMWARE_DATA = 0x15,
- PLDM_TRANSFER_COMPLETE = 0x16,
- PLDM_VERIFY_COMPLETE = 0x17,
- PLDM_APPLY_COMPLETE = 0x18,
- PLDM_ACTIVATE_FIRMWARE = 0x1A,
- PLDM_GET_STATUS = 0x1B,
- PLDM_CANCEL_UPDATE_COMPONENT = 0x1C,
- PLDM_CANCEL_UPDATE = 0x1D
-};
-
-/** @brief PLDM Firmware update completion codes
- */
-enum pldm_firmware_update_completion_codes {
- PLDM_FWUP_NOT_IN_UPDATE_MODE = 0x80,
- PLDM_FWUP_ALREADY_IN_UPDATE_MODE = 0x81,
- PLDM_FWUP_DATA_OUT_OF_RANGE = 0x82,
- PLDM_FWUP_INVALID_TRANSFER_LENGTH = 0x83,
- PLDM_FWUP_INVALID_STATE_FOR_COMMAND = 0x84,
- PLDM_FWUP_INCOMPLETE_UPDATE = 0x85,
- PLDM_FWUP_BUSY_IN_BACKGROUND = 0x86,
- PLDM_FWUP_CANCEL_PENDING = 0x87,
- PLDM_FWUP_COMMAND_NOT_EXPECTED = 0x87,
- PLDM_FWUP_RETRY_REQUEST_FW_DATA = 0x89,
- PLDM_FWUP_UNABLE_TO_INITIATE_UPDATE = 0x8A,
- PLDM_FWUP_ACTIVATION_NOT_REQUIRED = 0x8B,
- PLDM_FWUP_SELF_CONTAINED_ACTIVATION_NOT_PERMITTED = 0x8C,
- PLDM_FWUP_NO_DEVICE_METADATA = 0x8D,
- PLDM_FWUP_RETRY_REQUEST_UPDATE = 0x8E,
- PLDM_FWUP_NO_PACKAGE_DATA = 0x8F,
- PLDM_FWUP_INVALID_TRANSFER_HANDLE = 0x90,
- PLDM_FWUP_INVALID_TRANSFER_OPERATION_FLAG = 0x91,
- PLDM_FWUP_ACTIVATE_PENDING_IMAGE_NOT_PERMITTED = 0x92,
- PLDM_FWUP_PACKAGE_DATA_ERROR = 0x93
-};
-
-/** @brief String type values defined in the PLDM firmware update specification
- */
-enum pldm_firmware_update_string_type {
- PLDM_STR_TYPE_UNKNOWN = 0,
- PLDM_STR_TYPE_ASCII = 1,
- PLDM_STR_TYPE_UTF_8 = 2,
- PLDM_STR_TYPE_UTF_16 = 3,
- PLDM_STR_TYPE_UTF_16LE = 4,
- PLDM_STR_TYPE_UTF_16BE = 5
-};
-
-/** @brief Descriptor types defined in PLDM firmware update specification
- */
-enum pldm_firmware_update_descriptor_types {
- PLDM_FWUP_PCI_VENDOR_ID = 0x0000,
- PLDM_FWUP_IANA_ENTERPRISE_ID = 0x0001,
- PLDM_FWUP_UUID = 0x0002,
- PLDM_FWUP_PNP_VENDOR_ID = 0x0003,
- PLDM_FWUP_ACPI_VENDOR_ID = 0x0004,
- PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID = 0x0005,
- PLDM_FWUP_SCSI_VENDOR_ID = 0x0006,
- PLDM_FWUP_PCI_DEVICE_ID = 0x0100,
- PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID = 0x0101,
- PLDM_FWUP_PCI_SUBSYSTEM_ID = 0x0102,
- PLDM_FWUP_PCI_REVISION_ID = 0x0103,
- PLDM_FWUP_PNP_PRODUCT_IDENTIFIER = 0x0104,
- PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER = 0x0105,
- PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING = 0x0106,
- PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING = 0x0107,
- PLDM_FWUP_SCSI_PRODUCT_ID = 0x0108,
- PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE = 0x0109,
- PLDM_FWUP_VENDOR_DEFINED = 0xFFFF
-};
-
-/** @brief Descriptor types length defined in PLDM firmware update specification
- */
-enum pldm_firmware_update_descriptor_types_length {
- PLDM_FWUP_PCI_VENDOR_ID_LENGTH = 2,
- PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH = 4,
- PLDM_FWUP_UUID_LENGTH = 16,
- PLDM_FWUP_PNP_VENDOR_ID_LENGTH = 3,
- PLDM_FWUP_ACPI_VENDOR_ID_LENGTH = 4,
- PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH = 3,
- PLDM_FWUP_SCSI_VENDOR_ID_LENGTH = 8,
- PLDM_FWUP_PCI_DEVICE_ID_LENGTH = 2,
- PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH = 2,
- PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH = 2,
- PLDM_FWUP_PCI_REVISION_ID_LENGTH = 1,
- PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH = 4,
- PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH = 4,
- PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH = 40,
- PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH = 10,
- PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH = 16,
- PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH = 4
-};
-
-/** @brief ComponentClassification values defined in firmware update
- * specification
- */
-enum pldm_component_classification_values {
- PLDM_COMP_UNKNOWN = 0x0000,
- PLDM_COMP_OTHER = 0x0001,
- PLDM_COMP_DRIVER = 0x0002,
- PLDM_COMP_CONFIGURATION_SOFTWARE = 0x0003,
- PLDM_COMP_APPLICATION_SOFTWARE = 0x0004,
- PLDM_COMP_INSTRUMENTATION = 0x0005,
- PLDM_COMP_FIRMWARE_OR_BIOS = 0x0006,
- PLDM_COMP_DIAGNOSTIC_SOFTWARE = 0x0007,
- PLDM_COMP_OPERATING_SYSTEM = 0x0008,
- PLDM_COMP_MIDDLEWARE = 0x0009,
- PLDM_COMP_FIRMWARE = 0x000A,
- PLDM_COMP_BIOS_OR_FCODE = 0x000B,
- PLDM_COMP_SUPPORT_OR_SERVICEPACK = 0x000C,
- PLDM_COMP_SOFTWARE_BUNDLE = 0x000D,
- PLDM_COMP_DOWNSTREAM_DEVICE = 0xFFFF
-};
-
-/** @brief ComponentActivationMethods is the bit position in the bitfield that
- * provides the capability of the FD for firmware activation. Multiple
- * activation methods can be supported.
- */
-enum pldm_comp_activation_methods {
- PLDM_ACTIVATION_AUTOMATIC = 0,
- PLDM_ACTIVATION_SELF_CONTAINED = 1,
- PLDM_ACTIVATION_MEDIUM_SPECIFIC_RESET = 2,
- PLDM_ACTIVATION_SYSTEM_REBOOT = 3,
- PLDM_ACTIVATION_DC_POWER_CYCLE = 4,
- PLDM_ACTIVATION_AC_POWER_CYCLE = 5,
- PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE = 6,
- PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE_SET = 7
-};
-
-/** @brief ComponentResponse values in the response of PassComponentTable
- */
-enum pldm_component_responses {
- PLDM_CR_COMP_CAN_BE_UPDATED = 0,
- PLDM_CR_COMP_MAY_BE_UPDATEABLE = 1
-};
-
-/** @brief ComponentResponseCode values in the response of PassComponentTable
- */
-enum pldm_component_response_codes {
- PLDM_CRC_COMP_CAN_BE_UPDATED = 0x00,
- PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
- PLDM_CRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
- PLDM_CRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
- PLDM_CRC_COMP_CONFLICT = 0x04,
- PLDM_CRC_COMP_PREREQUISITES_NOT_MET = 0x05,
- PLDM_CRC_COMP_NOT_SUPPORTED = 0x06,
- PLDM_CRC_COMP_SECURITY_RESTRICTIONS = 0x07,
- PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
- PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY = 0x09,
- PLDM_CRC_COMP_VER_STR_IDENTICAL = 0x0A,
- PLDM_CRC_COMP_VER_STR_LOWER = 0x0B,
- PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xD0,
- PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xEF
-};
-
-/** @brief ComponentCompatibilityResponse values in the response of
- * UpdateComponent
- */
-enum pldm_component_compatability_responses {
- PLDM_CCR_COMP_CAN_BE_UPDATED = 0,
- PLDM_CCR_COMP_CANNOT_BE_UPDATED = 1
-};
-
-/** @brief ComponentCompatibilityResponse Code values in the response of
- * UpdateComponent
- */
-enum pldm_component_compatability_response_codes {
- PLDM_CCRC_NO_RESPONSE_CODE = 0x00,
- PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
- PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
- PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
- PLDM_CCRC_COMP_CONFLICT = 0x04,
- PLDM_CCRC_COMP_PREREQUISITES_NOT_MET = 0x05,
- PLDM_CCRC_COMP_NOT_SUPPORTED = 0x06,
- PLDM_CCRC_COMP_SECURITY_RESTRICTIONS = 0x07,
- PLDM_CCRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
- PLDM_CCRC_COMP_INFO_NO_MATCH = 0x09,
- PLDM_CCRC_COMP_VER_STR_IDENTICAL = 0x0A,
- PLDM_CCRC_COMP_VER_STR_LOWER = 0x0B,
- PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xD0,
- PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xEF
-};
-
-/** @brief Common error codes in TransferComplete, VerifyComplete and
- * ApplyComplete request
- */
-enum pldm_firmware_update_common_error_codes {
- PLDM_FWUP_TIME_OUT = 0x09,
- PLDM_FWUP_GENERIC_ERROR = 0x0A
-};
-
-/** @brief TransferResult values in the request of TransferComplete
- */
-enum pldm_firmware_update_transfer_result_values {
- PLDM_FWUP_TRANSFER_SUCCESS = 0x00,
- PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT = 0x02,
- PLDM_FWUP_TRANSFER_ERROR_VERSION_MISMATCH = 0x02,
- PLDM_FWUP_FD_ABORTED_TRANSFER = 0x03,
- PLDM_FWUP_FD_ABORTED_TRANSFER_LOW_POWER_STATE = 0x0B,
- PLDM_FWUP_FD_ABORTED_TRANSFER_RESET_NEEDED = 0x0C,
- PLDM_FWUP_FD_ABORTED_TRANSFER_STORAGE_ISSUE = 0x0D,
- PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MIN = 0x70,
- PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MAX = 0x8F
-};
-
-/**@brief VerifyResult values in the request of VerifyComplete
- */
-enum pldm_firmware_update_verify_result_values {
- PLDM_FWUP_VERIFY_SUCCESS = 0x00,
- PLDM_FWUP_VERIFY_ERROR_VERIFICATION_FAILURE = 0x01,
- PLDM_FWUP_VERIFY_ERROR_VERSION_MISMATCH = 0x02,
- PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS = 0x03,
- PLDM_FWUP_VERIFY_ERROR_IMAGE_INCOMPLETE = 0x04,
- PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MIN = 0x90,
- PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MAX = 0xAF
-};
-
-/**@brief ApplyResult values in the request of ApplyComplete
- */
-enum pldm_firmware_update_apply_result_values {
- PLDM_FWUP_APPLY_SUCCESS = 0x00,
- PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD = 0x01,
- PLDM_FWUP_APPLY_FAILURE_MEMORY_ISSUE = 0x02,
- PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MIN = 0xB0,
- PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MAX = 0xCF
-};
-
-/** @brief SelfContainedActivationRequest in the request of ActivateFirmware
- */
-enum pldm_self_contained_activation_req {
- PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS = false,
- PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS = true
-};
-
-/** @brief Current state/previous state of the FD or FDP returned in GetStatus
- * response
- */
-enum pldm_firmware_device_states {
- PLDM_FD_STATE_IDLE = 0,
- PLDM_FD_STATE_LEARN_COMPONENTS = 1,
- PLDM_FD_STATE_READY_XFER = 2,
- PLDM_FD_STATE_DOWNLOAD = 3,
- PLDM_FD_STATE_VERIFY = 4,
- PLDM_FD_STATE_APPLY = 5,
- PLDM_FD_STATE_ACTIVATE = 6
-};
-
-/** @brief Firmware device aux state in GetStatus response
- */
-enum pldm_get_status_aux_states {
- PLDM_FD_OPERATION_IN_PROGRESS = 0,
- PLDM_FD_OPERATION_SUCCESSFUL = 1,
- PLDM_FD_OPERATION_FAILED = 2,
- PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER = 3
-};
-
-/** @brief Firmware device aux state status in GetStatus response
- */
-enum pldm_get_status_aux_state_status_values {
- PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS = 0x00,
- PLDM_FD_TIMEOUT = 0x09,
- PLDM_FD_GENERIC_ERROR = 0x0A,
- PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START = 0x70,
- PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END = 0xEF
-};
-
-/** @brief Firmware device reason code in GetStatus response
- */
-enum pldm_get_status_reason_code_values {
- PLDM_FD_INITIALIZATION = 0,
- PLDM_FD_ACTIVATE_FW = 1,
- PLDM_FD_CANCEL_UPDATE = 2,
- PLDM_FD_TIMEOUT_LEARN_COMPONENT = 3,
- PLDM_FD_TIMEOUT_READY_XFER = 4,
- PLDM_FD_TIMEOUT_DOWNLOAD = 5,
- PLDM_FD_TIMEOUT_VERIFY = 6,
- PLDM_FD_TIMEOUT_APPLY = 7,
- PLDM_FD_STATUS_VENDOR_DEFINED_MIN = 200,
- PLDM_FD_STATUS_VENDOR_DEFINED_MAX = 255
-};
-
-/** @brief Components functional indicator in CancelUpdate response
- */
-enum pldm_firmware_update_non_functioning_component_indication {
- PLDM_FWUP_COMPONENTS_FUNCTIONING = 0,
- PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING = 1
-};
-
-/** @struct pldm_package_header_information
- *
- * Structure representing fixed part of package header information
- */
-struct pldm_package_header_information {
- uint8_t uuid[PLDM_FWUP_UUID_LENGTH];
- uint8_t package_header_format_version;
- uint16_t package_header_size;
- uint8_t timestamp104[PLDM_TIMESTAMP104_SIZE];
- uint16_t component_bitmap_bit_length;
- uint8_t package_version_string_type;
- uint8_t package_version_string_length;
-} __attribute__((packed));
-
-/** @struct pldm_firmware_device_id_record
- *
- * Structure representing firmware device ID record
- */
-struct pldm_firmware_device_id_record {
- uint16_t record_length;
- uint8_t descriptor_count;
- bitfield32_t device_update_option_flags;
- uint8_t comp_image_set_version_string_type;
- uint8_t comp_image_set_version_string_length;
- uint16_t fw_device_pkg_data_length;
-} __attribute__((packed));
-
-/** @struct pldm_descriptor_tlv
- *
- * Structure representing descriptor type, length and value
- */
-struct pldm_descriptor_tlv {
- uint16_t descriptor_type;
- uint16_t descriptor_length;
- uint8_t descriptor_data[1];
-} __attribute__((packed));
-
-/** @struct pldm_vendor_defined_descriptor_title_data
- *
- * Structure representing vendor defined descriptor title sections
- */
-struct pldm_vendor_defined_descriptor_title_data {
- uint8_t vendor_defined_descriptor_title_str_type;
- uint8_t vendor_defined_descriptor_title_str_len;
- uint8_t vendor_defined_descriptor_title_str[1];
-} __attribute__((packed));
-
-/** @struct pldm_component_image_information
- *
- * Structure representing fixed part of individual component information in
- * PLDM firmware update package
- */
-struct pldm_component_image_information {
- uint16_t comp_classification;
- uint16_t comp_identifier;
- uint32_t comp_comparison_stamp;
- bitfield16_t comp_options;
- bitfield16_t requested_comp_activation_method;
- uint32_t comp_location_offset;
- uint32_t comp_size;
- uint8_t comp_version_string_type;
- uint8_t comp_version_string_length;
-} __attribute__((packed));
-
-/** @struct pldm_query_device_identifiers_resp
- *
- * Structure representing query device identifiers response.
- */
-struct pldm_query_device_identifiers_resp {
- uint8_t completion_code;
- uint32_t device_identifiers_len;
- uint8_t descriptor_count;
-} __attribute__((packed));
-
-/** @struct pldm_get_firmware_parameters_resp
- *
- * Structure representing the fixed part of GetFirmwareParameters response
- */
-struct pldm_get_firmware_parameters_resp {
- uint8_t completion_code;
- bitfield32_t capabilities_during_update;
- uint16_t comp_count;
- uint8_t active_comp_image_set_ver_str_type;
- uint8_t active_comp_image_set_ver_str_len;
- uint8_t pending_comp_image_set_ver_str_type;
- uint8_t pending_comp_image_set_ver_str_len;
-} __attribute__((packed));
-
-/** @struct pldm_component_parameter_entry
- *
- * Structure representing component parameter table entry.
- */
-struct pldm_component_parameter_entry {
- uint16_t comp_classification;
- uint16_t comp_identifier;
- uint8_t comp_classification_index;
- uint32_t active_comp_comparison_stamp;
- uint8_t active_comp_ver_str_type;
- uint8_t active_comp_ver_str_len;
- uint8_t active_comp_release_date[8];
- uint32_t pending_comp_comparison_stamp;
- uint8_t pending_comp_ver_str_type;
- uint8_t pending_comp_ver_str_len;
- uint8_t pending_comp_release_date[8];
- bitfield16_t comp_activation_methods;
- bitfield32_t capabilities_during_update;
-} __attribute__((packed));
-
-/** @struct pldm_request_update_req
- *
- * Structure representing fixed part of Request Update request
- */
-struct pldm_request_update_req {
- uint32_t max_transfer_size;
- uint16_t num_of_comp;
- uint8_t max_outstanding_transfer_req;
- uint16_t pkg_data_len;
- uint8_t comp_image_set_ver_str_type;
- uint8_t comp_image_set_ver_str_len;
-} __attribute__((packed));
-
-/** @struct pldm_request_update_resp
- *
- * Structure representing Request Update response
- */
-struct pldm_request_update_resp {
- uint8_t completion_code;
- uint16_t fd_meta_data_len;
- uint8_t fd_will_send_pkg_data;
-} __attribute__((packed));
-
-/** @struct pldm_pass_component_table_req
- *
- * Structure representing PassComponentTable request
- */
-struct pldm_pass_component_table_req {
- uint8_t transfer_flag;
- uint16_t comp_classification;
- uint16_t comp_identifier;
- uint8_t comp_classification_index;
- uint32_t comp_comparison_stamp;
- uint8_t comp_ver_str_type;
- uint8_t comp_ver_str_len;
-} __attribute__((packed));
-
-/** @struct pldm_pass_component_table_resp
- *
- * Structure representing PassComponentTable response
- */
-struct pldm_pass_component_table_resp {
- uint8_t completion_code;
- uint8_t comp_resp;
- uint8_t comp_resp_code;
-} __attribute__((packed));
-
-/** @struct pldm_update_component_req
- *
- * Structure representing UpdateComponent request
- */
-struct pldm_update_component_req {
- uint16_t comp_classification;
- uint16_t comp_identifier;
- uint8_t comp_classification_index;
- uint32_t comp_comparison_stamp;
- uint32_t comp_image_size;
- bitfield32_t update_option_flags;
- uint8_t comp_ver_str_type;
- uint8_t comp_ver_str_len;
-} __attribute__((packed));
-
-/** @struct pldm_update_component_resp
- *
- * Structure representing UpdateComponent response
- */
-struct pldm_update_component_resp {
- uint8_t completion_code;
- uint8_t comp_compatability_resp;
- uint8_t comp_compatability_resp_code;
- bitfield32_t update_option_flags_enabled;
- uint16_t time_before_req_fw_data;
-} __attribute__((packed));
-
-/** @struct pldm_request_firmware_data_req
- *
- * Structure representing RequestFirmwareData request.
- */
-struct pldm_request_firmware_data_req {
- uint32_t offset;
- uint32_t length;
-} __attribute__((packed));
-
-/** @struct pldm_apply_complete_req
- *
- * Structure representing ApplyComplete request.
- */
-struct pldm_apply_complete_req {
- uint8_t apply_result;
- bitfield16_t comp_activation_methods_modification;
-} __attribute__((packed));
-
-/** @struct pldm_activate_firmware_req
- *
- * Structure representing ActivateFirmware request
- */
-struct pldm_activate_firmware_req {
- bool8_t self_contained_activation_req;
-} __attribute__((packed));
-
-/** @struct activate_firmware_resp
- *
- * Structure representing Activate Firmware response
- */
-struct pldm_activate_firmware_resp {
- uint8_t completion_code;
- uint16_t estimated_time_activation;
-} __attribute__((packed));
-
-/** @struct pldm_get_status_resp
- *
- * Structure representing GetStatus response.
- */
-struct pldm_get_status_resp {
- uint8_t completion_code;
- uint8_t current_state;
- uint8_t previous_state;
- uint8_t aux_state;
- uint8_t aux_state_status;
- uint8_t progress_percent;
- uint8_t reason_code;
- bitfield32_t update_option_flags_enabled;
-} __attribute__((packed));
-
-/** @struct pldm_cancel_update_resp
- *
- * Structure representing CancelUpdate response.
- */
-struct pldm_cancel_update_resp {
- uint8_t completion_code;
- bool8_t non_functioning_component_indication;
- uint64_t non_functioning_component_bitmap;
-} __attribute__((packed));
-
-/** @brief Decode the PLDM package header information
- *
- * @param[in] data - pointer to package header information
- * @param[in] length - available length in the firmware update package
- * @param[out] package_header_info - pointer to fixed part of PLDM package
- * header information
- * @param[out] package_version_str - pointer to package version string
- *
- * @return pldm_completion_codes
- */
-int decode_pldm_package_header_info(
- const uint8_t *data, size_t length,
- struct pldm_package_header_information *package_header_info,
- struct variable_field *package_version_str);
-
-/** @brief Decode individual firmware device ID record
- *
- * @param[in] data - pointer to firmware device ID record
- * @param[in] length - available length in the firmware update package
- * @param[in] component_bitmap_bit_length - ComponentBitmapBitLengthfield
- * parsed from the package header info
- * @param[out] fw_device_id_record - pointer to fixed part of firmware device
- * id record
- * @param[out] applicable_components - pointer to ApplicableComponents
- * @param[out] comp_image_set_version_str - pointer to
- * ComponentImageSetVersionString
- * @param[out] record_descriptors - pointer to RecordDescriptors
- * @param[out] fw_device_pkg_data - pointer to FirmwareDevicePackageData
- *
- * @return pldm_completion_codes
- */
-int decode_firmware_device_id_record(
- const uint8_t *data, size_t length, uint16_t component_bitmap_bit_length,
- struct pldm_firmware_device_id_record *fw_device_id_record,
- struct variable_field *applicable_components,
- struct variable_field *comp_image_set_version_str,
- struct variable_field *record_descriptors,
- struct variable_field *fw_device_pkg_data);
-
-/** @brief Decode the record descriptor entries in the firmware update package
- * and the Descriptors in the QueryDeviceIDentifiers command
- *
- * @param[in] data - pointer to descriptor entry
- * @param[in] length - remaining length of the descriptor data
- * @param[out] descriptor_type - pointer to descriptor type
- * @param[out] descriptor_data - pointer to descriptor data
- *
- * @return pldm_completion_codes
- */
-int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
- uint16_t *descriptor_type,
- struct variable_field *descriptor_data);
-
-/** @brief Decode the vendor defined descriptor value
- *
- * @param[in] data - pointer to vendor defined descriptor value
- * @param[in] length - length of the vendor defined descriptor value
- * @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
- * title string type
- * @param[out] descriptor_title_str - pointer to vendor defined descriptor
- * title string
- * @param[out] descriptor_data - pointer to vendor defined descriptor data
- *
- * @return pldm_completion_codes
- */
-int decode_vendor_defined_descriptor_value(
- const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
- struct variable_field *descriptor_title_str,
- struct variable_field *descriptor_data);
-
-/** @brief Decode individual component image information
- *
- * @param[in] data - pointer to component image information
- * @param[in] length - available length in the firmware update package
- * @param[out] pldm_comp_image_info - pointer to fixed part of component image
- * information
- * @param[out] comp_version_str - pointer to component version string
- *
- * @return pldm_completion_codes
- */
-int decode_pldm_comp_image_info(
- const uint8_t *data, size_t length,
- struct pldm_component_image_information *pldm_comp_image_info,
- struct variable_field *comp_version_str);
-
-/** @brief Create a PLDM request message for QueryDeviceIdentifiers
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] payload_length - Length of the request message payload
- * @param[in,out] msg - Message will be written to this
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_query_device_identifiers_req(uint8_t instance_id,
- size_t payload_length,
- struct pldm_msg *msg);
-
-/** @brief Decode QueryDeviceIdentifiers response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to response msg's PLDM completion code
- * @param[out] device_identifiers_len - Pointer to device identifiers length
- * @param[out] descriptor_count - Pointer to descriptor count
- * @param[out] descriptor_data - Pointer to descriptor data
- *
- * @return pldm_completion_codes
- */
-int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint32_t *device_identifiers_len,
- uint8_t *descriptor_count,
- uint8_t **descriptor_data);
-
-/** @brief Create a PLDM request message for GetFirmwareParameters
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] payload_length - Length of the request message payload
- * @param[in,out] msg - Message will be written to this
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_get_firmware_parameters_req(uint8_t instance_id,
- size_t payload_length,
- struct pldm_msg *msg);
-
-/** @brief Decode GetFirmwareParameters response
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] resp_data - Pointer to get firmware parameters response
- * @param[out] active_comp_image_set_ver_str - Pointer to active component
- * image set version string
- * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
- * image set version string
- * @param[out] comp_parameter_table - Pointer to component parameter table
- *
- * @return pldm_completion_codes
- */
-int decode_get_firmware_parameters_resp(
- const struct pldm_msg *msg, size_t payload_length,
- struct pldm_get_firmware_parameters_resp *resp_data,
- struct variable_field *active_comp_image_set_ver_str,
- struct variable_field *pending_comp_image_set_ver_str,
- struct variable_field *comp_parameter_table);
-
-/** @brief Decode component entries in the component parameter table which is
- * part of the response of GetFirmwareParameters command
- *
- * @param[in] data - Component entry
- * @param[in] length - Length of component entry
- * @param[out] component_data - Pointer to component parameter table
- * @param[out] active_comp_ver_str - Pointer to active component version string
- * @param[out] pending_comp_ver_str - Pointer to pending component version
- * string
- *
- * @return pldm_completion_codes
- */
-int decode_get_firmware_parameters_resp_comp_entry(
- const uint8_t *data, size_t length,
- struct pldm_component_parameter_entry *component_data,
- struct variable_field *active_comp_ver_str,
- struct variable_field *pending_comp_ver_str);
-
-/** @brief Create PLDM request message for RequestUpdate
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] max_transfer_size - Maximum size of the variable payload allowed
- * to be requested via RequestFirmwareData
- * command
- * @param[in] num_of_comp - Total number of components that will be passed to
- * the FD during the update
- * @param[in] max_outstanding_transfer_req - Total number of outstanding
- * RequestFirmwareData
- * commands that can be sent by the FD
- * @param[in] pkg_data_len - Value of the FirmwareDevicePackageDataLength field
- * present in firmware package header
- * @param[in] comp_image_set_ver_str_type - StringType of
- * ComponentImageSetVersionString
- * @param[in] comp_image_set_ver_str_len - The length of the
- * ComponentImageSetVersionString
- * @param[in] comp_img_set_ver_str - Component Image Set version information
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size,
- uint16_t num_of_comp,
- uint8_t max_outstanding_transfer_req,
- uint16_t pkg_data_len,
- uint8_t comp_image_set_ver_str_type,
- uint8_t comp_image_set_ver_str_len,
- const struct variable_field *comp_img_set_ver_str,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Decode a RequestUpdate response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to hold the completion code
- * @param[out] fd_meta_data_len - Pointer to hold the length of FD metadata
- * @param[out] fd_will_send_pkg_data - Pointer to hold information whether FD
- * will send GetPackageData command
- * @return pldm_completion_codes
- */
-int decode_request_update_resp(const struct pldm_msg *msg,
- size_t payload_length, uint8_t *completion_code,
- uint16_t *fd_meta_data_len,
- uint8_t *fd_will_send_pkg_data);
-
-/** @brief Create PLDM request message for PassComponentTable
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] transfer_flag - TransferFlag
- * @param[in] comp_classification - ComponentClassification
- * @param[in] comp_identifier - ComponentIdentifier
- * @param[in] comp_classification_index - ComponentClassificationIndex
- * @param[in] comp_comparison_stamp - ComponentComparisonStamp
- * @param[in] comp_ver_str_type - ComponentVersionStringType
- * @param[in] comp_ver_str_len - ComponentVersionStringLength
- * @param[in] comp_ver_str - ComponentVersionString
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- * information
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_pass_component_table_req(
- uint8_t instance_id, uint8_t transfer_flag, uint16_t comp_classification,
- uint16_t comp_identifier, uint8_t comp_classification_index,
- uint32_t comp_comparison_stamp, uint8_t comp_ver_str_type,
- uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Decode PassComponentTable response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to hold completion code
- * @param[out] comp_resp - Pointer to hold component response
- * @param[out] comp_resp_code - Pointer to hold component response code
- *
- * @return pldm_completion_codes
- */
-int decode_pass_component_table_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint8_t *comp_resp,
- uint8_t *comp_resp_code);
-
-/** @brief Create PLDM request message for UpdateComponent
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] comp_classification - ComponentClassification
- * @param[in] comp_identifier - ComponentIdentifier
- * @param[in] comp_classification_index - ComponentClassificationIndex
- * @param[in] comp_comparison_stamp - ComponentComparisonStamp
- * @param[in] comp_image_size - ComponentImageSize
- * @param[in] update_option_flags - UpdateOptionFlags
- * @param[in] comp_ver_str_type - ComponentVersionStringType
- * @param[in] comp_ver_str_len - ComponentVersionStringLength
- * @param[in] comp_ver_str - ComponentVersionString
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- * information
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_update_component_req(
- uint8_t instance_id, uint16_t comp_classification, uint16_t comp_identifier,
- uint8_t comp_classification_index, uint32_t comp_comparison_stamp,
- uint32_t comp_image_size, bitfield32_t update_option_flags,
- uint8_t comp_ver_str_type, uint8_t comp_ver_str_len,
- const struct variable_field *comp_ver_str, struct pldm_msg *msg,
- size_t payload_length);
-
-/** @brief Decode UpdateComponent response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to hold completion code
- * @param[out] comp_compatability_resp - Pointer to hold component
- * compatibility response
- * @param[out] comp_compatability_resp_code - Pointer to hold component
- * compatibility response code
- * @param[out] update_option_flags_enabled - Pointer to hold
- * UpdateOptionsFlagEnabled
- * @param[out] time_before_req_fw_data - Pointer to hold the estimated time
- * before sending RequestFirmwareData
- *
- * @return pldm_completion_codes
- */
-int decode_update_component_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint8_t *comp_compatability_resp,
- uint8_t *comp_compatability_resp_code,
- bitfield32_t *update_option_flags_enabled,
- uint16_t *time_before_req_fw_data);
-
-/** @brief Decode RequestFirmwareData request message
- *
- * @param[in] msg - Request message
- * @param[in] payload_length - Length of request message payload
- * @param[out] offset - Pointer to hold offset
- * @param[out] length - Pointer to hold the size of the component image
- * segment requested by the FD/FDP
- *
- * @return pldm_completion_codes
- */
-int decode_request_firmware_data_req(const struct pldm_msg *msg,
- size_t payload_length, uint32_t *offset,
- uint32_t *length);
-
-/** @brief Create PLDM response message for RequestFirmwareData
- *
- * The ComponentImagePortion is not encoded in the PLDM response message
- * by encode_request_firmware_data_resp to avoid an additional copy. Populating
- * ComponentImagePortion in the PLDM response message is handled by the user
- * of this API. The payload_length validation considers only the
- * CompletionCode.
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] completion_code - CompletionCode
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of response message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_request_firmware_data_resp(uint8_t instance_id,
- uint8_t completion_code,
- struct pldm_msg *msg,
- size_t payload_length);
-
-/** @brief Decode TransferComplete request message
- *
- * @param[in] msg - Request message
- * @param[in] payload_length - Length of request message payload
- * @param[out] transfer_result - Pointer to hold TransferResult
- *
- * @return pldm_completion_codes
- */
-int decode_transfer_complete_req(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *transfer_result);
-
-/** @brief Create PLDM response message for TransferComplete
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] completion_code - CompletionCode
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of response message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Decode VerifyComplete request message
- *
- * @param[in] msg - Request message
- * @param[in] payload_length - Length of request message payload
- * @param[in] verify_result - Pointer to hold VerifyResult
- *
- * @return pldm_completion_codes
- */
-int decode_verify_complete_req(const struct pldm_msg *msg,
- size_t payload_length, uint8_t *verify_result);
-
-/** @brief Create PLDM response message for VerifyComplete
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] completion_code - CompletionCode
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of response message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Decode ApplyComplete request message
- *
- * @param[in] msg - Request message
- * @param[in] payload_length - Length of request message payload
- * @param[in] apply_result - Pointer to hold ApplyResult
- * @param[in] comp_activation_methods_modification - Pointer to hold the
- * ComponentActivationMethodsModification
- *
- * @return pldm_completion_codes
- */
-int decode_apply_complete_req(
- const struct pldm_msg *msg, size_t payload_length, uint8_t *apply_result,
- bitfield16_t *comp_activation_methods_modification);
-
-/** @brief Create PLDM response message for ApplyComplete
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] completion_code - CompletionCode
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of response message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Create PLDM request message for ActivateFirmware
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] self_contained_activation_req SelfContainedActivationRequest
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_activate_firmware_req(uint8_t instance_id,
- bool8_t self_contained_activation_req,
- struct pldm_msg *msg, size_t payload_length);
-
-/** @brief Decode ActivateFirmware response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to hold CompletionCode
- * @param[out] estimated_time_activation - Pointer to hold
- * EstimatedTimeForSelfContainedActivation
- *
- * @return pldm_completion_codes
- */
-int decode_activate_firmware_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code,
- uint16_t *estimated_time_activation);
-
-/** @brief Create PLDM request message for GetStatus
- *
- * @param[in] instance_id - Message's instance id
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg,
- size_t payload_length);
-
-/** @brief Decode GetStatus response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to completion code
- * @param[out] current_state - Pointer to current state machine state
- * @param[out] previous_state - Pointer to previous different state machine
- * state
- * @param[out] aux_state - Pointer to current operation state of FD/FDP
- * @param[out] aux_state_status - Pointer to aux state status
- * @param[out] progress_percent - Pointer to progress percentage
- * @param[out] reason_code - Pointer to reason for entering current state
- * @param[out] update_option_flags_enabled - Pointer to update option flags
- * enabled
- *
- * @return pldm_completion_codes
- */
-int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length,
- uint8_t *completion_code, uint8_t *current_state,
- uint8_t *previous_state, uint8_t *aux_state,
- uint8_t *aux_state_status, uint8_t *progress_percent,
- uint8_t *reason_code,
- bitfield32_t *update_option_flags_enabled);
-
-/** @brief Create PLDM request message for CancelUpdateComponent
- *
- * @param[in] instance_id - Message's instance id
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_cancel_update_component_req(uint8_t instance_id,
- struct pldm_msg *msg,
- size_t payload_length);
-
-/** @brief Decode CancelUpdateComponent response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to the completion code
- *
- * @return pldm_completion_codes
- */
-int decode_cancel_update_component_resp(const struct pldm_msg *msg,
- size_t payload_length,
- uint8_t *completion_code);
-
-/** @brief Create PLDM request message for CancelUpdate
- *
- * @param[in] instance_id - Message's instance id
- * @param[in,out] msg - Message will be written to this
- * @param[in] payload_length - Length of request message payload
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg,
- size_t payload_length);
-
-/** @brief Decode CancelUpdate response message
- *
- * @param[in] msg - Response message
- * @param[in] payload_length - Length of response message payload
- * @param[out] completion_code - Pointer to completion code
- * @param[out] non_functioning_component_indication - Pointer to non
- functioning
- * component indication
- * @param[out] non_functioning_component_bitmap - Pointer to non
- functioning
- * component bitmap
- *
- * @return pldm_completion_codes
- */
-int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length,
- uint8_t *completion_code,
- bool8_t *non_functioning_component_indication,
- bitfield64_t *non_functioning_component_bitmap);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // End of FW_UPDATE_H
+#ifndef FW_UPDATE_H
+#define FW_UPDATE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "base.h"
+#include "stdbool.h"
+#include "utils.h"
+
+#define PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE 8
+#define PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP 0xFFFFFFFF
+#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
+/** @brief Minimum length of device descriptor, 2 bytes for descriptor type,
+ * 2 bytes for descriptor length and atleast 1 byte of descriptor data
+ */
+#define PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN 5
+#define PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES 0
+#define PLDM_FWUP_BASELINE_TRANSFER_SIZE 32
+#define PLDM_FWUP_MIN_OUTSTANDING_REQ 1
+#define PLDM_GET_STATUS_REQ_BYTES 0
+/* Maximum progress percentage value*/
+#define PLDM_FWUP_MAX_PROGRESS_PERCENT 0x65
+#define PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES 0
+#define PLDM_CANCEL_UPDATE_REQ_BYTES 0
+
+/** @brief PLDM Firmware update commands
+ */
+enum pldm_firmware_update_commands {
+ PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01,
+ PLDM_GET_FIRMWARE_PARAMETERS = 0x02,
+ PLDM_REQUEST_UPDATE = 0x10,
+ PLDM_PASS_COMPONENT_TABLE = 0x13,
+ PLDM_UPDATE_COMPONENT = 0x14,
+ PLDM_REQUEST_FIRMWARE_DATA = 0x15,
+ PLDM_TRANSFER_COMPLETE = 0x16,
+ PLDM_VERIFY_COMPLETE = 0x17,
+ PLDM_APPLY_COMPLETE = 0x18,
+ PLDM_ACTIVATE_FIRMWARE = 0x1A,
+ PLDM_GET_STATUS = 0x1B,
+ PLDM_CANCEL_UPDATE_COMPONENT = 0x1C,
+ PLDM_CANCEL_UPDATE = 0x1D
+};
+
+/** @brief PLDM Firmware update completion codes
+ */
+enum pldm_firmware_update_completion_codes {
+ PLDM_FWUP_NOT_IN_UPDATE_MODE = 0x80,
+ PLDM_FWUP_ALREADY_IN_UPDATE_MODE = 0x81,
+ PLDM_FWUP_DATA_OUT_OF_RANGE = 0x82,
+ PLDM_FWUP_INVALID_TRANSFER_LENGTH = 0x83,
+ PLDM_FWUP_INVALID_STATE_FOR_COMMAND = 0x84,
+ PLDM_FWUP_INCOMPLETE_UPDATE = 0x85,
+ PLDM_FWUP_BUSY_IN_BACKGROUND = 0x86,
+ PLDM_FWUP_CANCEL_PENDING = 0x87,
+ PLDM_FWUP_COMMAND_NOT_EXPECTED = 0x87,
+ PLDM_FWUP_RETRY_REQUEST_FW_DATA = 0x89,
+ PLDM_FWUP_UNABLE_TO_INITIATE_UPDATE = 0x8A,
+ PLDM_FWUP_ACTIVATION_NOT_REQUIRED = 0x8B,
+ PLDM_FWUP_SELF_CONTAINED_ACTIVATION_NOT_PERMITTED = 0x8C,
+ PLDM_FWUP_NO_DEVICE_METADATA = 0x8D,
+ PLDM_FWUP_RETRY_REQUEST_UPDATE = 0x8E,
+ PLDM_FWUP_NO_PACKAGE_DATA = 0x8F,
+ PLDM_FWUP_INVALID_TRANSFER_HANDLE = 0x90,
+ PLDM_FWUP_INVALID_TRANSFER_OPERATION_FLAG = 0x91,
+ PLDM_FWUP_ACTIVATE_PENDING_IMAGE_NOT_PERMITTED = 0x92,
+ PLDM_FWUP_PACKAGE_DATA_ERROR = 0x93
+};
+
+/** @brief String type values defined in the PLDM firmware update specification
+ */
+enum pldm_firmware_update_string_type {
+ PLDM_STR_TYPE_UNKNOWN = 0,
+ PLDM_STR_TYPE_ASCII = 1,
+ PLDM_STR_TYPE_UTF_8 = 2,
+ PLDM_STR_TYPE_UTF_16 = 3,
+ PLDM_STR_TYPE_UTF_16LE = 4,
+ PLDM_STR_TYPE_UTF_16BE = 5
+};
+
+/** @brief Descriptor types defined in PLDM firmware update specification
+ */
+enum pldm_firmware_update_descriptor_types {
+ PLDM_FWUP_PCI_VENDOR_ID = 0x0000,
+ PLDM_FWUP_IANA_ENTERPRISE_ID = 0x0001,
+ PLDM_FWUP_UUID = 0x0002,
+ PLDM_FWUP_PNP_VENDOR_ID = 0x0003,
+ PLDM_FWUP_ACPI_VENDOR_ID = 0x0004,
+ PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID = 0x0005,
+ PLDM_FWUP_SCSI_VENDOR_ID = 0x0006,
+ PLDM_FWUP_PCI_DEVICE_ID = 0x0100,
+ PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID = 0x0101,
+ PLDM_FWUP_PCI_SUBSYSTEM_ID = 0x0102,
+ PLDM_FWUP_PCI_REVISION_ID = 0x0103,
+ PLDM_FWUP_PNP_PRODUCT_IDENTIFIER = 0x0104,
+ PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER = 0x0105,
+ PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING = 0x0106,
+ PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING = 0x0107,
+ PLDM_FWUP_SCSI_PRODUCT_ID = 0x0108,
+ PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE = 0x0109,
+ PLDM_FWUP_VENDOR_DEFINED = 0xFFFF
+};
+
+/** @brief Descriptor types length defined in PLDM firmware update specification
+ */
+enum pldm_firmware_update_descriptor_types_length {
+ PLDM_FWUP_PCI_VENDOR_ID_LENGTH = 2,
+ PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH = 4,
+ PLDM_FWUP_UUID_LENGTH = 16,
+ PLDM_FWUP_PNP_VENDOR_ID_LENGTH = 3,
+ PLDM_FWUP_ACPI_VENDOR_ID_LENGTH = 4,
+ PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH = 3,
+ PLDM_FWUP_SCSI_VENDOR_ID_LENGTH = 8,
+ PLDM_FWUP_PCI_DEVICE_ID_LENGTH = 2,
+ PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH = 2,
+ PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH = 2,
+ PLDM_FWUP_PCI_REVISION_ID_LENGTH = 1,
+ PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH = 4,
+ PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH = 4,
+ PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH = 40,
+ PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH = 10,
+ PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH = 16,
+ PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH = 4
+};
+
+/** @brief ComponentClassification values defined in firmware update
+ * specification
+ */
+enum pldm_component_classification_values {
+ PLDM_COMP_UNKNOWN = 0x0000,
+ PLDM_COMP_OTHER = 0x0001,
+ PLDM_COMP_DRIVER = 0x0002,
+ PLDM_COMP_CONFIGURATION_SOFTWARE = 0x0003,
+ PLDM_COMP_APPLICATION_SOFTWARE = 0x0004,
+ PLDM_COMP_INSTRUMENTATION = 0x0005,
+ PLDM_COMP_FIRMWARE_OR_BIOS = 0x0006,
+ PLDM_COMP_DIAGNOSTIC_SOFTWARE = 0x0007,
+ PLDM_COMP_OPERATING_SYSTEM = 0x0008,
+ PLDM_COMP_MIDDLEWARE = 0x0009,
+ PLDM_COMP_FIRMWARE = 0x000A,
+ PLDM_COMP_BIOS_OR_FCODE = 0x000B,
+ PLDM_COMP_SUPPORT_OR_SERVICEPACK = 0x000C,
+ PLDM_COMP_SOFTWARE_BUNDLE = 0x000D,
+ PLDM_COMP_DOWNSTREAM_DEVICE = 0xFFFF
+};
+
+/** @brief ComponentActivationMethods is the bit position in the bitfield that
+ * provides the capability of the FD for firmware activation. Multiple
+ * activation methods can be supported.
+ */
+enum pldm_comp_activation_methods {
+ PLDM_ACTIVATION_AUTOMATIC = 0,
+ PLDM_ACTIVATION_SELF_CONTAINED = 1,
+ PLDM_ACTIVATION_MEDIUM_SPECIFIC_RESET = 2,
+ PLDM_ACTIVATION_SYSTEM_REBOOT = 3,
+ PLDM_ACTIVATION_DC_POWER_CYCLE = 4,
+ PLDM_ACTIVATION_AC_POWER_CYCLE = 5,
+ PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE = 6,
+ PLDM_SUPPORTS_ACTIVATE_PENDING_IMAGE_SET = 7
+};
+
+/** @brief ComponentResponse values in the response of PassComponentTable
+ */
+enum pldm_component_responses {
+ PLDM_CR_COMP_CAN_BE_UPDATED = 0,
+ PLDM_CR_COMP_MAY_BE_UPDATEABLE = 1
+};
+
+/** @brief ComponentResponseCode values in the response of PassComponentTable
+ */
+enum pldm_component_response_codes {
+ PLDM_CRC_COMP_CAN_BE_UPDATED = 0x00,
+ PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
+ PLDM_CRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
+ PLDM_CRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
+ PLDM_CRC_COMP_CONFLICT = 0x04,
+ PLDM_CRC_COMP_PREREQUISITES_NOT_MET = 0x05,
+ PLDM_CRC_COMP_NOT_SUPPORTED = 0x06,
+ PLDM_CRC_COMP_SECURITY_RESTRICTIONS = 0x07,
+ PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
+ PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY = 0x09,
+ PLDM_CRC_COMP_VER_STR_IDENTICAL = 0x0A,
+ PLDM_CRC_COMP_VER_STR_LOWER = 0x0B,
+ PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xD0,
+ PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xEF
+};
+
+/** @brief ComponentCompatibilityResponse values in the response of
+ * UpdateComponent
+ */
+enum pldm_component_compatability_responses {
+ PLDM_CCR_COMP_CAN_BE_UPDATED = 0,
+ PLDM_CCR_COMP_CANNOT_BE_UPDATED = 1
+};
+
+/** @brief ComponentCompatibilityResponse Code values in the response of
+ * UpdateComponent
+ */
+enum pldm_component_compatability_response_codes {
+ PLDM_CCRC_NO_RESPONSE_CODE = 0x00,
+ PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL = 0x01,
+ PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER = 0x02,
+ PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP = 0x03,
+ PLDM_CCRC_COMP_CONFLICT = 0x04,
+ PLDM_CCRC_COMP_PREREQUISITES_NOT_MET = 0x05,
+ PLDM_CCRC_COMP_NOT_SUPPORTED = 0x06,
+ PLDM_CCRC_COMP_SECURITY_RESTRICTIONS = 0x07,
+ PLDM_CCRC_INCOMPLETE_COMP_IMAGE_SET = 0x08,
+ PLDM_CCRC_COMP_INFO_NO_MATCH = 0x09,
+ PLDM_CCRC_COMP_VER_STR_IDENTICAL = 0x0A,
+ PLDM_CCRC_COMP_VER_STR_LOWER = 0x0B,
+ PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN = 0xD0,
+ PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX = 0xEF
+};
+
+/** @brief Common error codes in TransferComplete, VerifyComplete and
+ * ApplyComplete request
+ */
+enum pldm_firmware_update_common_error_codes {
+ PLDM_FWUP_TIME_OUT = 0x09,
+ PLDM_FWUP_GENERIC_ERROR = 0x0A
+};
+
+/** @brief TransferResult values in the request of TransferComplete
+ */
+enum pldm_firmware_update_transfer_result_values {
+ PLDM_FWUP_TRANSFER_SUCCESS = 0x00,
+ PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT = 0x02,
+ PLDM_FWUP_TRANSFER_ERROR_VERSION_MISMATCH = 0x02,
+ PLDM_FWUP_FD_ABORTED_TRANSFER = 0x03,
+ PLDM_FWUP_FD_ABORTED_TRANSFER_LOW_POWER_STATE = 0x0B,
+ PLDM_FWUP_FD_ABORTED_TRANSFER_RESET_NEEDED = 0x0C,
+ PLDM_FWUP_FD_ABORTED_TRANSFER_STORAGE_ISSUE = 0x0D,
+ PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MIN = 0x70,
+ PLDM_FWUP_VENDOR_TRANSFER_RESULT_RANGE_MAX = 0x8F
+};
+
+/**@brief VerifyResult values in the request of VerifyComplete
+ */
+enum pldm_firmware_update_verify_result_values {
+ PLDM_FWUP_VERIFY_SUCCESS = 0x00,
+ PLDM_FWUP_VERIFY_ERROR_VERIFICATION_FAILURE = 0x01,
+ PLDM_FWUP_VERIFY_ERROR_VERSION_MISMATCH = 0x02,
+ PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS = 0x03,
+ PLDM_FWUP_VERIFY_ERROR_IMAGE_INCOMPLETE = 0x04,
+ PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MIN = 0x90,
+ PLDM_FWUP_VENDOR_VERIFY_RESULT_RANGE_MAX = 0xAF
+};
+
+/**@brief ApplyResult values in the request of ApplyComplete
+ */
+enum pldm_firmware_update_apply_result_values {
+ PLDM_FWUP_APPLY_SUCCESS = 0x00,
+ PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD = 0x01,
+ PLDM_FWUP_APPLY_FAILURE_MEMORY_ISSUE = 0x02,
+ PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MIN = 0xB0,
+ PLDM_FWUP_VENDOR_APPLY_RESULT_RANGE_MAX = 0xCF
+};
+
+/** @brief SelfContainedActivationRequest in the request of ActivateFirmware
+ */
+enum pldm_self_contained_activation_req {
+ PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS = false,
+ PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS = true
+};
+
+/** @brief Current state/previous state of the FD or FDP returned in GetStatus
+ * response
+ */
+enum pldm_firmware_device_states {
+ PLDM_FD_STATE_IDLE = 0,
+ PLDM_FD_STATE_LEARN_COMPONENTS = 1,
+ PLDM_FD_STATE_READY_XFER = 2,
+ PLDM_FD_STATE_DOWNLOAD = 3,
+ PLDM_FD_STATE_VERIFY = 4,
+ PLDM_FD_STATE_APPLY = 5,
+ PLDM_FD_STATE_ACTIVATE = 6
+};
+
+/** @brief Firmware device aux state in GetStatus response
+ */
+enum pldm_get_status_aux_states {
+ PLDM_FD_OPERATION_IN_PROGRESS = 0,
+ PLDM_FD_OPERATION_SUCCESSFUL = 1,
+ PLDM_FD_OPERATION_FAILED = 2,
+ PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER = 3
+};
+
+/** @brief Firmware device aux state status in GetStatus response
+ */
+enum pldm_get_status_aux_state_status_values {
+ PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS = 0x00,
+ PLDM_FD_TIMEOUT = 0x09,
+ PLDM_FD_GENERIC_ERROR = 0x0A,
+ PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START = 0x70,
+ PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END = 0xEF
+};
+
+/** @brief Firmware device reason code in GetStatus response
+ */
+enum pldm_get_status_reason_code_values {
+ PLDM_FD_INITIALIZATION = 0,
+ PLDM_FD_ACTIVATE_FW = 1,
+ PLDM_FD_CANCEL_UPDATE = 2,
+ PLDM_FD_TIMEOUT_LEARN_COMPONENT = 3,
+ PLDM_FD_TIMEOUT_READY_XFER = 4,
+ PLDM_FD_TIMEOUT_DOWNLOAD = 5,
+ PLDM_FD_TIMEOUT_VERIFY = 6,
+ PLDM_FD_TIMEOUT_APPLY = 7,
+ PLDM_FD_STATUS_VENDOR_DEFINED_MIN = 200,
+ PLDM_FD_STATUS_VENDOR_DEFINED_MAX = 255
+};
+
+/** @brief Components functional indicator in CancelUpdate response
+ */
+enum pldm_firmware_update_non_functioning_component_indication {
+ PLDM_FWUP_COMPONENTS_FUNCTIONING = 0,
+ PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING = 1
+};
+
+/** @struct pldm_package_header_information
+ *
+ * Structure representing fixed part of package header information
+ */
+struct pldm_package_header_information {
+ uint8_t uuid[PLDM_FWUP_UUID_LENGTH];
+ uint8_t package_header_format_version;
+ uint16_t package_header_size;
+ uint8_t timestamp104[PLDM_TIMESTAMP104_SIZE];
+ uint16_t component_bitmap_bit_length;
+ uint8_t package_version_string_type;
+ uint8_t package_version_string_length;
+} __attribute__((packed));
+
+/** @struct pldm_firmware_device_id_record
+ *
+ * Structure representing firmware device ID record
+ */
+struct pldm_firmware_device_id_record {
+ uint16_t record_length;
+ uint8_t descriptor_count;
+ bitfield32_t device_update_option_flags;
+ uint8_t comp_image_set_version_string_type;
+ uint8_t comp_image_set_version_string_length;
+ uint16_t fw_device_pkg_data_length;
+} __attribute__((packed));
+
+/** @struct pldm_descriptor_tlv
+ *
+ * Structure representing descriptor type, length and value
+ */
+struct pldm_descriptor_tlv {
+ uint16_t descriptor_type;
+ uint16_t descriptor_length;
+ uint8_t descriptor_data[1];
+} __attribute__((packed));
+
+/** @struct pldm_vendor_defined_descriptor_title_data
+ *
+ * Structure representing vendor defined descriptor title sections
+ */
+struct pldm_vendor_defined_descriptor_title_data {
+ uint8_t vendor_defined_descriptor_title_str_type;
+ uint8_t vendor_defined_descriptor_title_str_len;
+ uint8_t vendor_defined_descriptor_title_str[1];
+} __attribute__((packed));
+
+/** @struct pldm_component_image_information
+ *
+ * Structure representing fixed part of individual component information in
+ * PLDM firmware update package
+ */
+struct pldm_component_image_information {
+ uint16_t comp_classification;
+ uint16_t comp_identifier;
+ uint32_t comp_comparison_stamp;
+ bitfield16_t comp_options;
+ bitfield16_t requested_comp_activation_method;
+ uint32_t comp_location_offset;
+ uint32_t comp_size;
+ uint8_t comp_version_string_type;
+ uint8_t comp_version_string_length;
+} __attribute__((packed));
+
+/** @struct pldm_query_device_identifiers_resp
+ *
+ * Structure representing query device identifiers response.
+ */
+struct pldm_query_device_identifiers_resp {
+ uint8_t completion_code;
+ uint32_t device_identifiers_len;
+ uint8_t descriptor_count;
+} __attribute__((packed));
+
+/** @struct pldm_get_firmware_parameters_resp
+ *
+ * Structure representing the fixed part of GetFirmwareParameters response
+ */
+struct pldm_get_firmware_parameters_resp {
+ uint8_t completion_code;
+ bitfield32_t capabilities_during_update;
+ uint16_t comp_count;
+ uint8_t active_comp_image_set_ver_str_type;
+ uint8_t active_comp_image_set_ver_str_len;
+ uint8_t pending_comp_image_set_ver_str_type;
+ uint8_t pending_comp_image_set_ver_str_len;
+} __attribute__((packed));
+
+/** @struct pldm_component_parameter_entry
+ *
+ * Structure representing component parameter table entry.
+ */
+struct pldm_component_parameter_entry {
+ uint16_t comp_classification;
+ uint16_t comp_identifier;
+ uint8_t comp_classification_index;
+ uint32_t active_comp_comparison_stamp;
+ uint8_t active_comp_ver_str_type;
+ uint8_t active_comp_ver_str_len;
+ uint8_t active_comp_release_date[8];
+ uint32_t pending_comp_comparison_stamp;
+ uint8_t pending_comp_ver_str_type;
+ uint8_t pending_comp_ver_str_len;
+ uint8_t pending_comp_release_date[8];
+ bitfield16_t comp_activation_methods;
+ bitfield32_t capabilities_during_update;
+} __attribute__((packed));
+
+/** @struct pldm_request_update_req
+ *
+ * Structure representing fixed part of Request Update request
+ */
+struct pldm_request_update_req {
+ uint32_t max_transfer_size;
+ uint16_t num_of_comp;
+ uint8_t max_outstanding_transfer_req;
+ uint16_t pkg_data_len;
+ uint8_t comp_image_set_ver_str_type;
+ uint8_t comp_image_set_ver_str_len;
+} __attribute__((packed));
+
+/** @struct pldm_request_update_resp
+ *
+ * Structure representing Request Update response
+ */
+struct pldm_request_update_resp {
+ uint8_t completion_code;
+ uint16_t fd_meta_data_len;
+ uint8_t fd_will_send_pkg_data;
+} __attribute__((packed));
+
+/** @struct pldm_pass_component_table_req
+ *
+ * Structure representing PassComponentTable request
+ */
+struct pldm_pass_component_table_req {
+ uint8_t transfer_flag;
+ uint16_t comp_classification;
+ uint16_t comp_identifier;
+ uint8_t comp_classification_index;
+ uint32_t comp_comparison_stamp;
+ uint8_t comp_ver_str_type;
+ uint8_t comp_ver_str_len;
+} __attribute__((packed));
+
+/** @struct pldm_pass_component_table_resp
+ *
+ * Structure representing PassComponentTable response
+ */
+struct pldm_pass_component_table_resp {
+ uint8_t completion_code;
+ uint8_t comp_resp;
+ uint8_t comp_resp_code;
+} __attribute__((packed));
+
+/** @struct pldm_update_component_req
+ *
+ * Structure representing UpdateComponent request
+ */
+struct pldm_update_component_req {
+ uint16_t comp_classification;
+ uint16_t comp_identifier;
+ uint8_t comp_classification_index;
+ uint32_t comp_comparison_stamp;
+ uint32_t comp_image_size;
+ bitfield32_t update_option_flags;
+ uint8_t comp_ver_str_type;
+ uint8_t comp_ver_str_len;
+} __attribute__((packed));
+
+/** @struct pldm_update_component_resp
+ *
+ * Structure representing UpdateComponent response
+ */
+struct pldm_update_component_resp {
+ uint8_t completion_code;
+ uint8_t comp_compatability_resp;
+ uint8_t comp_compatability_resp_code;
+ bitfield32_t update_option_flags_enabled;
+ uint16_t time_before_req_fw_data;
+} __attribute__((packed));
+
+/** @struct pldm_request_firmware_data_req
+ *
+ * Structure representing RequestFirmwareData request.
+ */
+struct pldm_request_firmware_data_req {
+ uint32_t offset;
+ uint32_t length;
+} __attribute__((packed));
+
+/** @struct pldm_apply_complete_req
+ *
+ * Structure representing ApplyComplete request.
+ */
+struct pldm_apply_complete_req {
+ uint8_t apply_result;
+ bitfield16_t comp_activation_methods_modification;
+} __attribute__((packed));
+
+/** @struct pldm_activate_firmware_req
+ *
+ * Structure representing ActivateFirmware request
+ */
+struct pldm_activate_firmware_req {
+ bool8_t self_contained_activation_req;
+} __attribute__((packed));
+
+/** @struct activate_firmware_resp
+ *
+ * Structure representing Activate Firmware response
+ */
+struct pldm_activate_firmware_resp {
+ uint8_t completion_code;
+ uint16_t estimated_time_activation;
+} __attribute__((packed));
+
+/** @struct pldm_get_status_resp
+ *
+ * Structure representing GetStatus response.
+ */
+struct pldm_get_status_resp {
+ uint8_t completion_code;
+ uint8_t current_state;
+ uint8_t previous_state;
+ uint8_t aux_state;
+ uint8_t aux_state_status;
+ uint8_t progress_percent;
+ uint8_t reason_code;
+ bitfield32_t update_option_flags_enabled;
+} __attribute__((packed));
+
+/** @struct pldm_cancel_update_resp
+ *
+ * Structure representing CancelUpdate response.
+ */
+struct pldm_cancel_update_resp {
+ uint8_t completion_code;
+ bool8_t non_functioning_component_indication;
+ uint64_t non_functioning_component_bitmap;
+} __attribute__((packed));
+
+/** @brief Decode the PLDM package header information
+ *
+ * @param[in] data - pointer to package header information
+ * @param[in] length - available length in the firmware update package
+ * @param[out] package_header_info - pointer to fixed part of PLDM package
+ * header information
+ * @param[out] package_version_str - pointer to package version string
+ *
+ * @return pldm_completion_codes
+ */
+int decode_pldm_package_header_info(
+ const uint8_t *data, size_t length,
+ struct pldm_package_header_information *package_header_info,
+ struct variable_field *package_version_str);
+
+/** @brief Decode individual firmware device ID record
+ *
+ * @param[in] data - pointer to firmware device ID record
+ * @param[in] length - available length in the firmware update package
+ * @param[in] component_bitmap_bit_length - ComponentBitmapBitLengthfield
+ * parsed from the package header info
+ * @param[out] fw_device_id_record - pointer to fixed part of firmware device
+ * id record
+ * @param[out] applicable_components - pointer to ApplicableComponents
+ * @param[out] comp_image_set_version_str - pointer to
+ * ComponentImageSetVersionString
+ * @param[out] record_descriptors - pointer to RecordDescriptors
+ * @param[out] fw_device_pkg_data - pointer to FirmwareDevicePackageData
+ *
+ * @return pldm_completion_codes
+ */
+int decode_firmware_device_id_record(
+ const uint8_t *data, size_t length, uint16_t component_bitmap_bit_length,
+ struct pldm_firmware_device_id_record *fw_device_id_record,
+ struct variable_field *applicable_components,
+ struct variable_field *comp_image_set_version_str,
+ struct variable_field *record_descriptors,
+ struct variable_field *fw_device_pkg_data);
+
+/** @brief Decode the record descriptor entries in the firmware update package
+ * and the Descriptors in the QueryDeviceIDentifiers command
+ *
+ * @param[in] data - pointer to descriptor entry
+ * @param[in] length - remaining length of the descriptor data
+ * @param[out] descriptor_type - pointer to descriptor type
+ * @param[out] descriptor_data - pointer to descriptor data
+ *
+ * @return pldm_completion_codes
+ */
+int decode_descriptor_type_length_value(const uint8_t *data, size_t length,
+ uint16_t *descriptor_type,
+ struct variable_field *descriptor_data);
+
+/** @brief Decode the vendor defined descriptor value
+ *
+ * @param[in] data - pointer to vendor defined descriptor value
+ * @param[in] length - length of the vendor defined descriptor value
+ * @param[out] descriptor_title_str_type - pointer to vendor defined descriptor
+ * title string type
+ * @param[out] descriptor_title_str - pointer to vendor defined descriptor
+ * title string
+ * @param[out] descriptor_data - pointer to vendor defined descriptor data
+ *
+ * @return pldm_completion_codes
+ */
+int decode_vendor_defined_descriptor_value(
+ const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type,
+ struct variable_field *descriptor_title_str,
+ struct variable_field *descriptor_data);
+
+/** @brief Decode individual component image information
+ *
+ * @param[in] data - pointer to component image information
+ * @param[in] length - available length in the firmware update package
+ * @param[out] pldm_comp_image_info - pointer to fixed part of component image
+ * information
+ * @param[out] comp_version_str - pointer to component version string
+ *
+ * @return pldm_completion_codes
+ */
+int decode_pldm_comp_image_info(
+ const uint8_t *data, size_t length,
+ struct pldm_component_image_information *pldm_comp_image_info,
+ struct variable_field *comp_version_str);
+
+/** @brief Create a PLDM request message for QueryDeviceIdentifiers
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] payload_length - Length of the request message payload
+ * @param[in,out] msg - Message will be written to this
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_query_device_identifiers_req(uint8_t instance_id,
+ size_t payload_length,
+ struct pldm_msg *msg);
+
+/** @brief Decode QueryDeviceIdentifiers response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to response msg's PLDM completion code
+ * @param[out] device_identifiers_len - Pointer to device identifiers length
+ * @param[out] descriptor_count - Pointer to descriptor count
+ * @param[out] descriptor_data - Pointer to descriptor data
+ *
+ * @return pldm_completion_codes
+ */
+int decode_query_device_identifiers_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint32_t *device_identifiers_len,
+ uint8_t *descriptor_count,
+ uint8_t **descriptor_data);
+
+/** @brief Create a PLDM request message for GetFirmwareParameters
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] payload_length - Length of the request message payload
+ * @param[in,out] msg - Message will be written to this
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_get_firmware_parameters_req(uint8_t instance_id,
+ size_t payload_length,
+ struct pldm_msg *msg);
+
+/** @brief Decode GetFirmwareParameters response
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] resp_data - Pointer to get firmware parameters response
+ * @param[out] active_comp_image_set_ver_str - Pointer to active component
+ * image set version string
+ * @param[out] pending_comp_image_set_ver_str - Pointer to pending component
+ * image set version string
+ * @param[out] comp_parameter_table - Pointer to component parameter table
+ *
+ * @return pldm_completion_codes
+ */
+int decode_get_firmware_parameters_resp(
+ const struct pldm_msg *msg, size_t payload_length,
+ struct pldm_get_firmware_parameters_resp *resp_data,
+ struct variable_field *active_comp_image_set_ver_str,
+ struct variable_field *pending_comp_image_set_ver_str,
+ struct variable_field *comp_parameter_table);
+
+/** @brief Decode component entries in the component parameter table which is
+ * part of the response of GetFirmwareParameters command
+ *
+ * @param[in] data - Component entry
+ * @param[in] length - Length of component entry
+ * @param[out] component_data - Pointer to component parameter table
+ * @param[out] active_comp_ver_str - Pointer to active component version string
+ * @param[out] pending_comp_ver_str - Pointer to pending component version
+ * string
+ *
+ * @return pldm_completion_codes
+ */
+int decode_get_firmware_parameters_resp_comp_entry(
+ const uint8_t *data, size_t length,
+ struct pldm_component_parameter_entry *component_data,
+ struct variable_field *active_comp_ver_str,
+ struct variable_field *pending_comp_ver_str);
+
+/** @brief Create PLDM request message for RequestUpdate
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] max_transfer_size - Maximum size of the variable payload allowed
+ * to be requested via RequestFirmwareData
+ * command
+ * @param[in] num_of_comp - Total number of components that will be passed to
+ * the FD during the update
+ * @param[in] max_outstanding_transfer_req - Total number of outstanding
+ * RequestFirmwareData
+ * commands that can be sent by the FD
+ * @param[in] pkg_data_len - Value of the FirmwareDevicePackageDataLength field
+ * present in firmware package header
+ * @param[in] comp_image_set_ver_str_type - StringType of
+ * ComponentImageSetVersionString
+ * @param[in] comp_image_set_ver_str_len - The length of the
+ * ComponentImageSetVersionString
+ * @param[in] comp_img_set_ver_str - Component Image Set version information
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size,
+ uint16_t num_of_comp,
+ uint8_t max_outstanding_transfer_req,
+ uint16_t pkg_data_len,
+ uint8_t comp_image_set_ver_str_type,
+ uint8_t comp_image_set_ver_str_len,
+ const struct variable_field *comp_img_set_ver_str,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Decode a RequestUpdate response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to hold the completion code
+ * @param[out] fd_meta_data_len - Pointer to hold the length of FD metadata
+ * @param[out] fd_will_send_pkg_data - Pointer to hold information whether FD
+ * will send GetPackageData command
+ * @return pldm_completion_codes
+ */
+int decode_request_update_resp(const struct pldm_msg *msg,
+ size_t payload_length, uint8_t *completion_code,
+ uint16_t *fd_meta_data_len,
+ uint8_t *fd_will_send_pkg_data);
+
+/** @brief Create PLDM request message for PassComponentTable
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] transfer_flag - TransferFlag
+ * @param[in] comp_classification - ComponentClassification
+ * @param[in] comp_identifier - ComponentIdentifier
+ * @param[in] comp_classification_index - ComponentClassificationIndex
+ * @param[in] comp_comparison_stamp - ComponentComparisonStamp
+ * @param[in] comp_ver_str_type - ComponentVersionStringType
+ * @param[in] comp_ver_str_len - ComponentVersionStringLength
+ * @param[in] comp_ver_str - ComponentVersionString
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ * information
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_pass_component_table_req(
+ uint8_t instance_id, uint8_t transfer_flag, uint16_t comp_classification,
+ uint16_t comp_identifier, uint8_t comp_classification_index,
+ uint32_t comp_comparison_stamp, uint8_t comp_ver_str_type,
+ uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Decode PassComponentTable response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to hold completion code
+ * @param[out] comp_resp - Pointer to hold component response
+ * @param[out] comp_resp_code - Pointer to hold component response code
+ *
+ * @return pldm_completion_codes
+ */
+int decode_pass_component_table_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint8_t *comp_resp,
+ uint8_t *comp_resp_code);
+
+/** @brief Create PLDM request message for UpdateComponent
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] comp_classification - ComponentClassification
+ * @param[in] comp_identifier - ComponentIdentifier
+ * @param[in] comp_classification_index - ComponentClassificationIndex
+ * @param[in] comp_comparison_stamp - ComponentComparisonStamp
+ * @param[in] comp_image_size - ComponentImageSize
+ * @param[in] update_option_flags - UpdateOptionFlags
+ * @param[in] comp_ver_str_type - ComponentVersionStringType
+ * @param[in] comp_ver_str_len - ComponentVersionStringLength
+ * @param[in] comp_ver_str - ComponentVersionString
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ * information
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_update_component_req(
+ uint8_t instance_id, uint16_t comp_classification, uint16_t comp_identifier,
+ uint8_t comp_classification_index, uint32_t comp_comparison_stamp,
+ uint32_t comp_image_size, bitfield32_t update_option_flags,
+ uint8_t comp_ver_str_type, uint8_t comp_ver_str_len,
+ const struct variable_field *comp_ver_str, struct pldm_msg *msg,
+ size_t payload_length);
+
+/** @brief Decode UpdateComponent response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to hold completion code
+ * @param[out] comp_compatability_resp - Pointer to hold component
+ * compatibility response
+ * @param[out] comp_compatability_resp_code - Pointer to hold component
+ * compatibility response code
+ * @param[out] update_option_flags_enabled - Pointer to hold
+ * UpdateOptionsFlagEnabled
+ * @param[out] time_before_req_fw_data - Pointer to hold the estimated time
+ * before sending RequestFirmwareData
+ *
+ * @return pldm_completion_codes
+ */
+int decode_update_component_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint8_t *comp_compatability_resp,
+ uint8_t *comp_compatability_resp_code,
+ bitfield32_t *update_option_flags_enabled,
+ uint16_t *time_before_req_fw_data);
+
+/** @brief Decode RequestFirmwareData request message
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[out] offset - Pointer to hold offset
+ * @param[out] length - Pointer to hold the size of the component image
+ * segment requested by the FD/FDP
+ *
+ * @return pldm_completion_codes
+ */
+int decode_request_firmware_data_req(const struct pldm_msg *msg,
+ size_t payload_length, uint32_t *offset,
+ uint32_t *length);
+
+/** @brief Create PLDM response message for RequestFirmwareData
+ *
+ * The ComponentImagePortion is not encoded in the PLDM response message
+ * by encode_request_firmware_data_resp to avoid an additional copy. Populating
+ * ComponentImagePortion in the PLDM response message is handled by the user
+ * of this API. The payload_length validation considers only the
+ * CompletionCode.
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - CompletionCode
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of response message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_request_firmware_data_resp(uint8_t instance_id,
+ uint8_t completion_code,
+ struct pldm_msg *msg,
+ size_t payload_length);
+
+/** @brief Decode TransferComplete request message
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[out] transfer_result - Pointer to hold TransferResult
+ *
+ * @return pldm_completion_codes
+ */
+int decode_transfer_complete_req(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *transfer_result);
+
+/** @brief Create PLDM response message for TransferComplete
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - CompletionCode
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of response message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Decode VerifyComplete request message
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[in] verify_result - Pointer to hold VerifyResult
+ *
+ * @return pldm_completion_codes
+ */
+int decode_verify_complete_req(const struct pldm_msg *msg,
+ size_t payload_length, uint8_t *verify_result);
+
+/** @brief Create PLDM response message for VerifyComplete
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - CompletionCode
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of response message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Decode ApplyComplete request message
+ *
+ * @param[in] msg - Request message
+ * @param[in] payload_length - Length of request message payload
+ * @param[in] apply_result - Pointer to hold ApplyResult
+ * @param[in] comp_activation_methods_modification - Pointer to hold the
+ * ComponentActivationMethodsModification
+ *
+ * @return pldm_completion_codes
+ */
+int decode_apply_complete_req(
+ const struct pldm_msg *msg, size_t payload_length, uint8_t *apply_result,
+ bitfield16_t *comp_activation_methods_modification);
+
+/** @brief Create PLDM response message for ApplyComplete
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - CompletionCode
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of response message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Create PLDM request message for ActivateFirmware
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] self_contained_activation_req SelfContainedActivationRequest
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_activate_firmware_req(uint8_t instance_id,
+ bool8_t self_contained_activation_req,
+ struct pldm_msg *msg, size_t payload_length);
+
+/** @brief Decode ActivateFirmware response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to hold CompletionCode
+ * @param[out] estimated_time_activation - Pointer to hold
+ * EstimatedTimeForSelfContainedActivation
+ *
+ * @return pldm_completion_codes
+ */
+int decode_activate_firmware_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code,
+ uint16_t *estimated_time_activation);
+
+/** @brief Create PLDM request message for GetStatus
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg,
+ size_t payload_length);
+
+/** @brief Decode GetStatus response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to completion code
+ * @param[out] current_state - Pointer to current state machine state
+ * @param[out] previous_state - Pointer to previous different state machine
+ * state
+ * @param[out] aux_state - Pointer to current operation state of FD/FDP
+ * @param[out] aux_state_status - Pointer to aux state status
+ * @param[out] progress_percent - Pointer to progress percentage
+ * @param[out] reason_code - Pointer to reason for entering current state
+ * @param[out] update_option_flags_enabled - Pointer to update option flags
+ * enabled
+ *
+ * @return pldm_completion_codes
+ */
+int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code, uint8_t *current_state,
+ uint8_t *previous_state, uint8_t *aux_state,
+ uint8_t *aux_state_status, uint8_t *progress_percent,
+ uint8_t *reason_code,
+ bitfield32_t *update_option_flags_enabled);
+
+/** @brief Create PLDM request message for CancelUpdateComponent
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_cancel_update_component_req(uint8_t instance_id,
+ struct pldm_msg *msg,
+ size_t payload_length);
+
+/** @brief Decode CancelUpdateComponent response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to the completion code
+ *
+ * @return pldm_completion_codes
+ */
+int decode_cancel_update_component_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code);
+
+/** @brief Create PLDM request message for CancelUpdate
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in,out] msg - Message will be written to this
+ * @param[in] payload_length - Length of request message payload
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg,
+ size_t payload_length);
+
+/** @brief Decode CancelUpdate response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to completion code
+ * @param[out] non_functioning_component_indication - Pointer to non
+ functioning
+ * component indication
+ * @param[out] non_functioning_component_bitmap - Pointer to non
+ functioning
+ * component bitmap
+ *
+ * @return pldm_completion_codes
+ */
+int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code,
+ bool8_t *non_functioning_component_indication,
+ bitfield64_t *non_functioning_component_bitmap);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // End of FW_UPDATE_H
diff --git a/libpldm/state_set.h b/libpldm/state_set.h
index aa0849d..23fd91c 100644
--- a/libpldm/state_set.h
+++ b/libpldm/state_set.h
@@ -1,236 +1,236 @@
-#ifndef STATE_SET_H
-#define STATE_SET_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** @brief PLDM State Set IDs in DSP0249_1.1.0 specification
- */
-enum pldm_state_set_ids {
-
- /* Table 1 - General State Sets */
- PLDM_STATE_SET_HEALTH_STATE = 1,
- PLDM_STATE_SET_AVAILABILITY = 2,
- PLDM_STATE_SET_PREDICTIVE_CONDITION = 3,
- PLDM_STATE_SET_REDUNDANCY_STATUS = 4,
- PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND = 5,
- PLDM_STATE_SET_GROUP_RESOURCE_LEVEL = 6,
- PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE = 7,
- PLDM_STATE_SET_OPERATIONAL_STATUS = 8,
- PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS = 9,
- PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS = 10,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS = 11,
- PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS = 12,
- PLDM_STATE_SET_PRESENCE = 13,
- PLDM_STATE_SET_PERFORMANCE = 14,
- PLDM_STATE_SET_CONFIGURATION_STATE = 15,
- PLDM_STATE_SET_CHANGED_CONFIGURATION = 16,
- PLDM_STATE_SET_IDENTIFY_STATE = 17,
- PLDM_STATE_SET_VERSION = 18,
- PLDM_STATE_SET_ALARM_STATE = 19,
- PLDM_STATE_SET_DEVICE_INITIALIZATION = 20,
- PLDM_STATE_SET_THERMAL_TRIP = 21,
-
- /* Table 2 - Communication State Sets */
- PLDM_STATE_SET_HEARTBEAT = 32,
- PLDM_STATE_SET_LINK_STATE = 33,
-
- /* Table 3 - General Sensor State Sets */
- PLDM_STATE_SET_SMOKE_STATE = 64,
- PLDM_STATE_SET_HUMIDITY_STATE = 65,
- PLDM_STATE_SET_DOOR_STATE = 66,
- PLDM_STATE_SET_SWITCH_STATE = 67,
-
- /* Table 4 - Security-Related State Sets */
- PLDM_STATE_SET_LOCK_STATE = 96,
- PLDM_STATE_SET_PHYSICAL_SECURITY = 97,
- PLDM_STATE_SET_DOCK_AUTHORIZATION = 98,
- PLDM_STATE_SET_HW_SECURITY = 99,
- PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION = 100,
- PLDM_STATE_SET_COMM_LEASH_STATUS = 101,
- PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS = 102,
- PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY = 103,
- PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL = 104,
- PLDM_STATE_SET_SESSION_AUDIT = 105,
-
- /* Table 5 - Software-Related State Sets */
- PLDM_STATE_SET_SW_TERMINATION_STATUS = 129,
-
- /* Table 6 - Redundant Storage Media (RAID) State Sets */
- PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY = 160,
-
- /* Table 7 - Boot-Related State Sets */
- PLDM_STATE_SET_BOOT_RESTART_CAUSE = 192,
- PLDM_STATE_SET_BOOT_RESTART_REQUEST = 193,
- PLDM_STATE_SET_ENTITY_BOOT_STATUS = 194,
- PLDM_STATE_SET_BOOT_ERROR_STATUS = 195,
- PLDM_STATE_SET_BOOT_PROGRESS = 196,
- PLDM_STATE_SET_SYS_FIRMWARE_HANG = 197,
- PLDM_STATE_SET_POST_ERRORS = 198,
-
- /* Table 8 - Monitored System-Related State Sets */
- PLDM_STATE_SET_LOG_FILL_STATUS = 225,
- PLDM_STATE_SET_LOG_FILTER_STATUS = 226,
- PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE = 227,
- PLDM_STATE_SET_INTERRUPT_REQUESTED = 228,
- PLDM_STATE_SET_INTERRUPT_RECEIVED = 229,
- PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED = 230,
- PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED = 231,
- PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED = 232,
- PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED = 233,
- PLDM_STATE_SET_FATAL_NMI_REQUESTED = 234,
- PLDM_STATE_SET_FATAL_NMI_RECEIVED = 235,
- PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED = 236,
- PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED = 237,
- PLDM_STATE_SET_SMI_REQUESTED = 238,
- PLDM_STATE_SET_SMI_RECEIVED = 238,
- PLDM_STATE_SET_PCI_PERR_REQUESTED = 239,
- PLDM_STATE_SET_PCI_PERR_RECEIVED = 240,
- PLDM_STATE_SET_PCI_SERR_REQUESTED = 241,
- PLDM_STATE_SET_PCI_SERR_RECEIVED = 242,
- PLDM_STATE_SET_BUS_ERROR_STATUS = 243,
- PLDM_STATE_SET_WATCHDOG_STATUS = 244,
-
- /* Table 9 - Power-Related State Sets */
- PLDM_STATE_SET_POWER_SUPPLY_STATE = 256,
- PLDM_STATE_SET_DEVICE_POWER_STATE = 257,
- PLDM_STATE_SET_ACPI_POWER_STATE = 258,
- PLDM_STATE_SET_BACKUP_POWER_SOURCE = 259,
- PLDM_STATE_SET_SYSTEM_POWER_STATE = 260,
- PLDM_STATE_SET_BATTERY_ACTIVITY = 261,
- PLDM_STATE_SET_BATTERY_STATE = 262,
-
- /* Table 10 - Processor-Related State Sets */
- PLDM_STATE_SET_PROC_POWER_STATE = 288,
- PLDM_STATE_SET_POWER_PERFORMANCE_STATE = 289,
- PLDM_STATE_SET_PROC_ERROR_STATUS = 290,
- PLDM_STATE_SET_BIST_FAILURE_STATUS = 291,
- PLDM_STATE_SET_IBIST_FAILURE_STATUS = 292,
- PLDM_STATE_SET_PROC_HANG_IN_POST = 293,
- PLDM_STATE_SET_PROC_STARTUP_FAILURE = 294,
- PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR = 295,
- PLDM_STATE_SET_MACHINE_CHECK_ERROR = 296,
- PLDM_STATE_SET_CORRECTED_MACHINE_CHECK = 297,
-
- /* Table 11 - Memory-Related State Sets */
- PLDM_STATE_SET_CACHE_STATUS = 320,
- PLDM_STATE_SET_MEMORY_ERROR_STATUS = 321,
- PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS = 322,
-
- /* Table 12 - Storage Device State Sets */
- PLDM_STATE_SET_ERROR_DETECTION_STATUS = 330,
- PLDM_STATE_SET_STUCK_BIT_STATUS = 331,
- PLDM_STATE_SET_SCRUB_STATUS = 332,
-
- /* Table 13 - Slot/Module State Sets */
- PLDM_STATE_SET_SLOT_OCCUPANCY = 352,
- PLDM_STATE_SET_SLOT_STATE = 353,
-};
-
-/* @brief List of states for the Health State state set (ID 1).
- */
-enum pldm_state_set_health_state_values {
- PLDM_STATE_SET_HEALTH_STATE_NORMAL = 1,
- PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL = 2,
- PLDM_STATE_SET_HEALTH_STATE_CRITICAL = 3,
- PLDM_STATE_SET_HEALTH_STATE_FATAL = 4,
- PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL = 5,
- PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL = 6,
- PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL = 7,
- PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL = 8,
- PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL = 9,
- PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL = 10,
-};
-
-/* @brief List of states for the State Set Availability (ID 2),
- */
-enum pldm_state_set_availability_values {
- PLDM_STATE_SET_AVAILABILITY_REBOOTING = 8
-};
-
-/* @brief List of states for the Operational Fault status (ID 10).
- */
-enum pldm_state_set_operational_fault_status_values {
- PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL = 1,
- PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED = 2,
-};
-
-/* @brief List of states for the Operational Running Status state set (ID 11).
- */
-enum pldm_state_set_operational_running_status_values {
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING = 1,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING = 2,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED = 3,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE = 4,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED = 5,
- PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT = 6
-};
-
-/* @brief List of states for the Set Identify state (ID 17).
- */
-enum pldm_state_set_identify_state_values {
- PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED = 1,
- PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED = 2,
-};
-
-/* @brief List of states for the Set Thermal Trip state set (ID 21).
- */
-enum pldm_state_set_thermal_trip_values {
- PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL = 1,
- PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP = 2,
-};
-
-/* @brief List of states for the Software-related state set (ID 129).
- */
-enum pldm_software_termination_status_values {
- PLDM_SW_TERM_NORMAL = 1,
- PLDM_SW_TERM_SOFTWARE_TERMINATION_DETECTED = 2,
- PLDM_SW_TERM_CRITICAL_STOP_DURING_LOAD_INITIALIZATION = 3,
- PLDM_SW_TERM_RUN_TIME_CRITICAL_STOP = 4,
- PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED = 5,
- PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED = 6,
- PLDM_SW_TERM_GRACEFUL_SHUTDOWN = 7,
- PLDM_SW_TERM_TERMINATION_REQUEST_FAILED = 8,
-};
-
-/* @brief List of states for the Boot Restart Cause state set (ID 192).
- */
-enum pldm_state_set_boot_restart_cause_values {
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_POWERED_UP = 1,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_HARD_RESET = 2,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET = 3,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_MANUAL_HARD_RESET = 4,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_MANUAL_WARM_RESET = 5,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_SYSTEM_RESTART = 6,
- PLDM_STATE_SET_BOOT_RESTART_CAUSE_WATCHDOG_TIMEOUT = 7
-};
-
-/* @brief List of states for the Boot Progress state set (ID 196).
- */
-enum pldm_state_set_boot_progress_state_values {
- PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE = 1,
- PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED = 2,
- PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION = 3,
- PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION = 5,
- PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG = 9,
- PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS = 21,
- PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION = 22,
- PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION = 26,
-};
-
-/* @brief List of states for the System Power State set (ID 260).
- */
-enum pldm_state_set_system_power_state_values {
- PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL = 9
-};
-
-/* OEM ranges */
-#define PLDM_OEM_STATE_SET_ID_START 32768
-#define PLDM_OEM_STATE_SET_ID_END 65535
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* STATE_SET_H */
+#ifndef STATE_SET_H
+#define STATE_SET_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief PLDM State Set IDs in DSP0249_1.1.0 specification
+ */
+enum pldm_state_set_ids {
+
+ /* Table 1 - General State Sets */
+ PLDM_STATE_SET_HEALTH_STATE = 1,
+ PLDM_STATE_SET_AVAILABILITY = 2,
+ PLDM_STATE_SET_PREDICTIVE_CONDITION = 3,
+ PLDM_STATE_SET_REDUNDANCY_STATUS = 4,
+ PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND = 5,
+ PLDM_STATE_SET_GROUP_RESOURCE_LEVEL = 6,
+ PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE = 7,
+ PLDM_STATE_SET_OPERATIONAL_STATUS = 8,
+ PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS = 9,
+ PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS = 10,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS = 11,
+ PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS = 12,
+ PLDM_STATE_SET_PRESENCE = 13,
+ PLDM_STATE_SET_PERFORMANCE = 14,
+ PLDM_STATE_SET_CONFIGURATION_STATE = 15,
+ PLDM_STATE_SET_CHANGED_CONFIGURATION = 16,
+ PLDM_STATE_SET_IDENTIFY_STATE = 17,
+ PLDM_STATE_SET_VERSION = 18,
+ PLDM_STATE_SET_ALARM_STATE = 19,
+ PLDM_STATE_SET_DEVICE_INITIALIZATION = 20,
+ PLDM_STATE_SET_THERMAL_TRIP = 21,
+
+ /* Table 2 - Communication State Sets */
+ PLDM_STATE_SET_HEARTBEAT = 32,
+ PLDM_STATE_SET_LINK_STATE = 33,
+
+ /* Table 3 - General Sensor State Sets */
+ PLDM_STATE_SET_SMOKE_STATE = 64,
+ PLDM_STATE_SET_HUMIDITY_STATE = 65,
+ PLDM_STATE_SET_DOOR_STATE = 66,
+ PLDM_STATE_SET_SWITCH_STATE = 67,
+
+ /* Table 4 - Security-Related State Sets */
+ PLDM_STATE_SET_LOCK_STATE = 96,
+ PLDM_STATE_SET_PHYSICAL_SECURITY = 97,
+ PLDM_STATE_SET_DOCK_AUTHORIZATION = 98,
+ PLDM_STATE_SET_HW_SECURITY = 99,
+ PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION = 100,
+ PLDM_STATE_SET_COMM_LEASH_STATUS = 101,
+ PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS = 102,
+ PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY = 103,
+ PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL = 104,
+ PLDM_STATE_SET_SESSION_AUDIT = 105,
+
+ /* Table 5 - Software-Related State Sets */
+ PLDM_STATE_SET_SW_TERMINATION_STATUS = 129,
+
+ /* Table 6 - Redundant Storage Media (RAID) State Sets */
+ PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY = 160,
+
+ /* Table 7 - Boot-Related State Sets */
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE = 192,
+ PLDM_STATE_SET_BOOT_RESTART_REQUEST = 193,
+ PLDM_STATE_SET_ENTITY_BOOT_STATUS = 194,
+ PLDM_STATE_SET_BOOT_ERROR_STATUS = 195,
+ PLDM_STATE_SET_BOOT_PROGRESS = 196,
+ PLDM_STATE_SET_SYS_FIRMWARE_HANG = 197,
+ PLDM_STATE_SET_POST_ERRORS = 198,
+
+ /* Table 8 - Monitored System-Related State Sets */
+ PLDM_STATE_SET_LOG_FILL_STATUS = 225,
+ PLDM_STATE_SET_LOG_FILTER_STATUS = 226,
+ PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE = 227,
+ PLDM_STATE_SET_INTERRUPT_REQUESTED = 228,
+ PLDM_STATE_SET_INTERRUPT_RECEIVED = 229,
+ PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED = 230,
+ PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED = 231,
+ PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED = 232,
+ PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED = 233,
+ PLDM_STATE_SET_FATAL_NMI_REQUESTED = 234,
+ PLDM_STATE_SET_FATAL_NMI_RECEIVED = 235,
+ PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED = 236,
+ PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED = 237,
+ PLDM_STATE_SET_SMI_REQUESTED = 238,
+ PLDM_STATE_SET_SMI_RECEIVED = 238,
+ PLDM_STATE_SET_PCI_PERR_REQUESTED = 239,
+ PLDM_STATE_SET_PCI_PERR_RECEIVED = 240,
+ PLDM_STATE_SET_PCI_SERR_REQUESTED = 241,
+ PLDM_STATE_SET_PCI_SERR_RECEIVED = 242,
+ PLDM_STATE_SET_BUS_ERROR_STATUS = 243,
+ PLDM_STATE_SET_WATCHDOG_STATUS = 244,
+
+ /* Table 9 - Power-Related State Sets */
+ PLDM_STATE_SET_POWER_SUPPLY_STATE = 256,
+ PLDM_STATE_SET_DEVICE_POWER_STATE = 257,
+ PLDM_STATE_SET_ACPI_POWER_STATE = 258,
+ PLDM_STATE_SET_BACKUP_POWER_SOURCE = 259,
+ PLDM_STATE_SET_SYSTEM_POWER_STATE = 260,
+ PLDM_STATE_SET_BATTERY_ACTIVITY = 261,
+ PLDM_STATE_SET_BATTERY_STATE = 262,
+
+ /* Table 10 - Processor-Related State Sets */
+ PLDM_STATE_SET_PROC_POWER_STATE = 288,
+ PLDM_STATE_SET_POWER_PERFORMANCE_STATE = 289,
+ PLDM_STATE_SET_PROC_ERROR_STATUS = 290,
+ PLDM_STATE_SET_BIST_FAILURE_STATUS = 291,
+ PLDM_STATE_SET_IBIST_FAILURE_STATUS = 292,
+ PLDM_STATE_SET_PROC_HANG_IN_POST = 293,
+ PLDM_STATE_SET_PROC_STARTUP_FAILURE = 294,
+ PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR = 295,
+ PLDM_STATE_SET_MACHINE_CHECK_ERROR = 296,
+ PLDM_STATE_SET_CORRECTED_MACHINE_CHECK = 297,
+
+ /* Table 11 - Memory-Related State Sets */
+ PLDM_STATE_SET_CACHE_STATUS = 320,
+ PLDM_STATE_SET_MEMORY_ERROR_STATUS = 321,
+ PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS = 322,
+
+ /* Table 12 - Storage Device State Sets */
+ PLDM_STATE_SET_ERROR_DETECTION_STATUS = 330,
+ PLDM_STATE_SET_STUCK_BIT_STATUS = 331,
+ PLDM_STATE_SET_SCRUB_STATUS = 332,
+
+ /* Table 13 - Slot/Module State Sets */
+ PLDM_STATE_SET_SLOT_OCCUPANCY = 352,
+ PLDM_STATE_SET_SLOT_STATE = 353,
+};
+
+/* @brief List of states for the Health State state set (ID 1).
+ */
+enum pldm_state_set_health_state_values {
+ PLDM_STATE_SET_HEALTH_STATE_NORMAL = 1,
+ PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL = 2,
+ PLDM_STATE_SET_HEALTH_STATE_CRITICAL = 3,
+ PLDM_STATE_SET_HEALTH_STATE_FATAL = 4,
+ PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL = 5,
+ PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL = 6,
+ PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL = 7,
+ PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL = 8,
+ PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL = 9,
+ PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL = 10,
+};
+
+/* @brief List of states for the State Set Availability (ID 2),
+ */
+enum pldm_state_set_availability_values {
+ PLDM_STATE_SET_AVAILABILITY_REBOOTING = 8
+};
+
+/* @brief List of states for the Operational Fault status (ID 10).
+ */
+enum pldm_state_set_operational_fault_status_values {
+ PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL = 1,
+ PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED = 2,
+};
+
+/* @brief List of states for the Operational Running Status state set (ID 11).
+ */
+enum pldm_state_set_operational_running_status_values {
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING = 1,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING = 2,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED = 3,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE = 4,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED = 5,
+ PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT = 6
+};
+
+/* @brief List of states for the Set Identify state (ID 17).
+ */
+enum pldm_state_set_identify_state_values {
+ PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED = 1,
+ PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED = 2,
+};
+
+/* @brief List of states for the Set Thermal Trip state set (ID 21).
+ */
+enum pldm_state_set_thermal_trip_values {
+ PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL = 1,
+ PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP = 2,
+};
+
+/* @brief List of states for the Software-related state set (ID 129).
+ */
+enum pldm_software_termination_status_values {
+ PLDM_SW_TERM_NORMAL = 1,
+ PLDM_SW_TERM_SOFTWARE_TERMINATION_DETECTED = 2,
+ PLDM_SW_TERM_CRITICAL_STOP_DURING_LOAD_INITIALIZATION = 3,
+ PLDM_SW_TERM_RUN_TIME_CRITICAL_STOP = 4,
+ PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED = 5,
+ PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED = 6,
+ PLDM_SW_TERM_GRACEFUL_SHUTDOWN = 7,
+ PLDM_SW_TERM_TERMINATION_REQUEST_FAILED = 8,
+};
+
+/* @brief List of states for the Boot Restart Cause state set (ID 192).
+ */
+enum pldm_state_set_boot_restart_cause_values {
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_POWERED_UP = 1,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_HARD_RESET = 2,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET = 3,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_MANUAL_HARD_RESET = 4,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_MANUAL_WARM_RESET = 5,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_SYSTEM_RESTART = 6,
+ PLDM_STATE_SET_BOOT_RESTART_CAUSE_WATCHDOG_TIMEOUT = 7
+};
+
+/* @brief List of states for the Boot Progress state set (ID 196).
+ */
+enum pldm_state_set_boot_progress_state_values {
+ PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE = 1,
+ PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED = 2,
+ PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION = 3,
+ PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION = 5,
+ PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG = 9,
+ PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS = 21,
+ PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION = 22,
+ PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION = 26,
+};
+
+/* @brief List of states for the System Power State set (ID 260).
+ */
+enum pldm_state_set_system_power_state_values {
+ PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL = 9
+};
+
+/* OEM ranges */
+#define PLDM_OEM_STATE_SET_ID_START 32768
+#define PLDM_OEM_STATE_SET_ID_END 65535
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* STATE_SET_H */
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/libpldm/tests/libpldm_firmware_update_test.cpp
index 746dfd6..9343b89 100644
--- a/libpldm/tests/libpldm_firmware_update_test.cpp
+++ b/libpldm/tests/libpldm_firmware_update_test.cpp
@@ -1,2922 +1,2922 @@
-#include <bitset>
-#include <cstring>
-
-#include "libpldm/base.h"
-#include "libpldm/firmware_update.h"
-
-#include <gtest/gtest.h>
-
-constexpr auto hdrSize = sizeof(pldm_msg_hdr);
-
-TEST(DecodePackageHeaderInfo, goodPath)
-{
- // Package header identifier for Version 1.0.x
- constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43,
- 0x98, 0x00, 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02};
- // Package header version for DSP0267 version 1.0.x
- constexpr uint8_t pkgHeaderFormatRevision = 0x01;
- // Random PackageHeaderSize
- constexpr uint16_t pkgHeaderSize = 303;
- // PackageReleaseDateTime - "25/12/2021 00:00:00"
- std::array<uint8_t, PLDM_TIMESTAMP104_SIZE> timestamp104{
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00};
- constexpr uint16_t componentBitmapBitLength = 8;
- // PackageVersionString
- constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
- constexpr size_t packagerHeaderSize =
- sizeof(pldm_package_header_information) + packageVersionStr.size();
-
- constexpr std::array<uint8_t, packagerHeaderSize> packagerHeaderInfo{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00, 0xa0, 0x2F,
- 0x05, 0x9a, 0xca, 0x02, 0x01, 0x2f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b,
- 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
- pldm_package_header_information pkgHeader{};
- variable_field packageVersion{};
-
- auto rc = decode_pldm_package_header_info(packagerHeaderInfo.data(),
- packagerHeaderInfo.size(),
- &pkgHeader, &packageVersion);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(true,
- std::equal(pkgHeader.uuid, pkgHeader.uuid + PLDM_FWUP_UUID_LENGTH,
- uuid.begin(), uuid.end()));
- EXPECT_EQ(pkgHeader.package_header_format_version, pkgHeaderFormatRevision);
- EXPECT_EQ(pkgHeader.package_header_size, pkgHeaderSize);
- EXPECT_EQ(true, std::equal(pkgHeader.timestamp104,
- pkgHeader.timestamp104 + PLDM_TIMESTAMP104_SIZE,
- timestamp104.begin(), timestamp104.end()));
- EXPECT_EQ(pkgHeader.component_bitmap_bit_length, componentBitmapBitLength);
- EXPECT_EQ(pkgHeader.package_version_string_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(pkgHeader.package_version_string_length,
- packageVersionStr.size());
- std::string packageVersionString(
- reinterpret_cast<const char*>(packageVersion.ptr),
- packageVersion.length);
- EXPECT_EQ(packageVersionString, packageVersionStr);
-}
-
-TEST(DecodePackageHeaderInfo, errorPaths)
-{
- int rc = 0;
- constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
- constexpr size_t packagerHeaderSize =
- sizeof(pldm_package_header_information) + packageVersionStr.size();
-
- // Invalid Package Version String Type - 0x06
- constexpr std::array<uint8_t, packagerHeaderSize>
- invalidPackagerHeaderInfo1{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
- 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
- 0x07, 0x00, 0x08, 0x00, 0x06, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
- 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
-
- pldm_package_header_information packageHeader{};
- variable_field packageVersion{};
-
- rc = decode_pldm_package_header_info(nullptr,
- invalidPackagerHeaderInfo1.size(),
- &packageHeader, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
- invalidPackagerHeaderInfo1.size(),
- nullptr, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
- invalidPackagerHeaderInfo1.size(),
- &packageHeader, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_package_header_info(
- invalidPackagerHeaderInfo1.data(),
- sizeof(pldm_package_header_information) - 1, &packageHeader,
- &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
- invalidPackagerHeaderInfo1.size(),
- &packageHeader, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid Package Version String Length - 0x00
- constexpr std::array<uint8_t, packagerHeaderSize>
- invalidPackagerHeaderInfo2{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
- 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
- 0x07, 0x00, 0x08, 0x00, 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e,
- 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo2.data(),
- invalidPackagerHeaderInfo2.size(),
- &packageHeader, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Package version string length less than in the header information
- constexpr std::array<uint8_t, packagerHeaderSize - 1>
- invalidPackagerHeaderInfo3{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
- 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
- 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
- 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e};
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo3.data(),
- invalidPackagerHeaderInfo3.size(),
- &packageHeader, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // ComponentBitmapBitLength not a multiple of 8
- constexpr std::array<uint8_t, packagerHeaderSize>
- invalidPackagerHeaderInfo4{
- 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
- 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
- 0x07, 0x00, 0x09, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
- 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
- rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo4.data(),
- invalidPackagerHeaderInfo4.size(),
- &packageHeader, &packageVersion);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(DecodeFirmwareDeviceIdRecord, goodPath)
-{
- constexpr uint8_t descriptorCount = 1;
- // Continue component updates after failure
- constexpr std::bitset<32> deviceUpdateFlag{1};
- constexpr uint16_t componentBitmapBitLength = 16;
- // Applicable Components - 1,2,5,8,9
- std::vector<std::bitset<8>> applicableComponentsBitfield{0x93, 0x01};
- // ComponentImageSetVersionString
- constexpr std::string_view imageSetVersionStr{"VersionString1"};
- // Initial descriptor - UUID
- constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
- 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
- 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
- constexpr uint16_t fwDevicePkgDataLen = 2;
- // FirmwareDevicePackageData
- constexpr std::array<uint8_t, fwDevicePkgDataLen> fwDevicePkgData{0xab,
- 0xcd};
- // Size of the firmware device ID record
- constexpr uint16_t recordLen =
- sizeof(pldm_firmware_device_id_record) +
- (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
- imageSetVersionStr.size() + sizeof(pldm_descriptor_tlv) - 1 +
- uuid.size() + fwDevicePkgData.size();
- // Firmware device ID record
- constexpr std::array<uint8_t, recordLen> record{
- 0x31, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02,
- 0x00, 0x93, 0x01, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
- 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x02, 0x00, 0x10,
- 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0,
- 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xab, 0xcd};
-
- pldm_firmware_device_id_record deviceIdRecHeader{};
- variable_field applicableComponents{};
- variable_field outCompImageSetVersionStr{};
- variable_field recordDescriptors{};
- variable_field outFwDevicePkgData{};
-
- auto rc = decode_firmware_device_id_record(
- record.data(), record.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
- EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
- EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
- deviceUpdateFlag);
- EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
- PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
- imageSetVersionStr.size());
- EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, fwDevicePkgDataLen);
-
- EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
- EXPECT_EQ(true,
- std::equal(applicableComponents.ptr,
- applicableComponents.ptr + applicableComponents.length,
- applicableComponentsBitfield.begin(),
- applicableComponentsBitfield.end()));
-
- EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
- std::string compImageSetVersionStr(
- reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
- outCompImageSetVersionStr.length);
- EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
-
- uint16_t descriptorType = 0;
- uint16_t descriptorLen = 0;
- variable_field descriptorData{};
- // DescriptorCount is 1, so decode_descriptor_type_length_value called once
- rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
- recordDescriptors.length,
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
- sizeof(descriptorLen) +
- descriptorData.length);
- EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
- EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
- EXPECT_EQ(true, std::equal(descriptorData.ptr,
- descriptorData.ptr + descriptorData.length,
- uuid.begin(), uuid.end()));
-
- EXPECT_EQ(outFwDevicePkgData.length, fwDevicePkgData.size());
- EXPECT_EQ(true,
- std::equal(outFwDevicePkgData.ptr,
- outFwDevicePkgData.ptr + outFwDevicePkgData.length,
- fwDevicePkgData.begin(), fwDevicePkgData.end()));
-}
-
-TEST(DecodeFirmwareDeviceIdRecord, goodPathNofwDevicePkgData)
-{
- constexpr uint8_t descriptorCount = 1;
- // Continue component updates after failure
- constexpr std::bitset<32> deviceUpdateFlag{1};
- constexpr uint16_t componentBitmapBitLength = 8;
- // Applicable Components - 1,2
- std::vector<std::bitset<8>> applicableComponentsBitfield{0x03};
- // ComponentImageSetVersionString
- constexpr std::string_view imageSetVersionStr{"VersionString1"};
- // Initial descriptor - UUID
- constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
- 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
- 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
- constexpr uint16_t fwDevicePkgDataLen = 0;
-
- // Size of the firmware device ID record
- constexpr uint16_t recordLen =
- sizeof(pldm_firmware_device_id_record) +
- (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
- imageSetVersionStr.size() +
- sizeof(pldm_descriptor_tlv().descriptor_type) +
- sizeof(pldm_descriptor_tlv().descriptor_length) + uuid.size() +
- fwDevicePkgDataLen;
- // Firmware device ID record
- constexpr std::array<uint8_t, recordLen> record{
- 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00, 0x03,
- 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e,
- 0x67, 0x31, 0x02, 0x00, 0x10, 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d,
- 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
-
- pldm_firmware_device_id_record deviceIdRecHeader{};
- variable_field applicableComponents{};
- variable_field outCompImageSetVersionStr{};
- variable_field recordDescriptors{};
- variable_field outFwDevicePkgData{};
-
- auto rc = decode_firmware_device_id_record(
- record.data(), record.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
- EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
- EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
- deviceUpdateFlag);
- EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
- PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
- imageSetVersionStr.size());
- EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, 0);
-
- EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
- EXPECT_EQ(true,
- std::equal(applicableComponents.ptr,
- applicableComponents.ptr + applicableComponents.length,
- applicableComponentsBitfield.begin(),
- applicableComponentsBitfield.end()));
-
- EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
- std::string compImageSetVersionStr(
- reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
- outCompImageSetVersionStr.length);
- EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
-
- uint16_t descriptorType = 0;
- uint16_t descriptorLen = 0;
- variable_field descriptorData{};
- // DescriptorCount is 1, so decode_descriptor_type_length_value called once
- rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
- recordDescriptors.length,
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
- sizeof(descriptorLen) +
- descriptorData.length);
- EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
- EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
- EXPECT_EQ(true, std::equal(descriptorData.ptr,
- descriptorData.ptr + descriptorData.length,
- uuid.begin(), uuid.end()));
-
- EXPECT_EQ(outFwDevicePkgData.ptr, nullptr);
- EXPECT_EQ(outFwDevicePkgData.length, 0);
-}
-
-TEST(DecodeFirmwareDeviceIdRecord, ErrorPaths)
-{
- constexpr uint16_t componentBitmapBitLength = 8;
- // Invalid ComponentImageSetVersionStringType
- constexpr std::array<uint8_t, 11> invalidRecord1{
- 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
-
- int rc = 0;
- pldm_firmware_device_id_record deviceIdRecHeader{};
- variable_field applicableComponents{};
- variable_field outCompImageSetVersionStr{};
- variable_field recordDescriptors{};
- variable_field outFwDevicePkgData{};
-
- rc = decode_firmware_device_id_record(
- nullptr, invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- nullptr, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, nullptr, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, nullptr, &recordDescriptors,
- &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- nullptr, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size() - 1,
- componentBitmapBitLength, &deviceIdRecHeader, &applicableComponents,
- &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(),
- componentBitmapBitLength + 1, &deviceIdRecHeader, &applicableComponents,
- &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_firmware_device_id_record(
- invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid ComponentImageSetVersionStringLength
- constexpr std::array<uint8_t, 11> invalidRecord2{
- 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
- rc = decode_firmware_device_id_record(
- invalidRecord2.data(), invalidRecord2.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // invalidRecord3 size is less than RecordLength
- constexpr std::array<uint8_t, 11> invalidRecord3{
- 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00};
- rc = decode_firmware_device_id_record(
- invalidRecord3.data(), invalidRecord3.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // RecordLength is less than the calculated RecordLength
- constexpr std::array<uint8_t, 11> invalidRecord4{
- 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02, 0x00};
- rc = decode_firmware_device_id_record(
- invalidRecord4.data(), invalidRecord4.size(), componentBitmapBitLength,
- &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
- &recordDescriptors, &outFwDevicePkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(DecodeDescriptors, goodPath3Descriptors)
-{
- // In the descriptor data there are 3 descriptor entries
- // 1) IANA enterprise ID
- constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
- 0x0a, 0x0b, 0x0c, 0xd};
- // 2) UUID
- constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
- 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
- 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
- // 3) Vendor Defined
- constexpr std::string_view vendorTitle{"OpenBMC"};
- constexpr size_t vendorDescriptorLen = 2;
- constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
- 0x01, 0x02};
-
- constexpr size_t vendorDefinedDescriptorLen =
- sizeof(pldm_vendor_defined_descriptor_title_data()
- .vendor_defined_descriptor_title_str_type) +
- sizeof(pldm_vendor_defined_descriptor_title_data()
- .vendor_defined_descriptor_title_str_len) +
- vendorTitle.size() + vendorDescriptorData.size();
-
- constexpr size_t descriptorsLength =
- 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
- sizeof(pldm_descriptor_tlv().descriptor_length)) +
- iana.size() + uuid.size() + vendorDefinedDescriptorLen;
-
- constexpr std::array<uint8_t, descriptorsLength> descriptors{
- 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
- 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
- 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
- 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
-
- size_t descriptorCount = 1;
- size_t descriptorsRemainingLength = descriptorsLength;
- int rc = 0;
-
- while (descriptorsRemainingLength && (descriptorCount <= 3))
- {
- uint16_t descriptorType = 0;
- uint16_t descriptorLen = 0;
- variable_field descriptorData{};
-
- rc = decode_descriptor_type_length_value(
- descriptors.data() + descriptorsLength - descriptorsRemainingLength,
- descriptorsRemainingLength, &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- if (descriptorCount == 1)
- {
- EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
- EXPECT_EQ(descriptorData.length,
- PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
- EXPECT_EQ(true,
- std::equal(descriptorData.ptr,
- descriptorData.ptr + descriptorData.length,
- iana.begin(), iana.end()));
- }
- else if (descriptorCount == 2)
- {
- EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
- EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
- EXPECT_EQ(true,
- std::equal(descriptorData.ptr,
- descriptorData.ptr + descriptorData.length,
- uuid.begin(), uuid.end()));
- }
- else if (descriptorCount == 3)
- {
- EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
- EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
-
- uint8_t descriptorTitleStrType = 0;
- variable_field descriptorTitleStr{};
- variable_field vendorDefinedDescriptorData{};
-
- rc = decode_vendor_defined_descriptor_value(
- descriptorData.ptr, descriptorData.length,
- &descriptorTitleStrType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
- std::string vendorTitleStr(
- reinterpret_cast<const char*>(descriptorTitleStr.ptr),
- descriptorTitleStr.length);
- EXPECT_EQ(vendorTitleStr, vendorTitle);
-
- EXPECT_EQ(vendorDefinedDescriptorData.length,
- vendorDescriptorData.size());
- EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
- vendorDefinedDescriptorData.ptr +
- vendorDefinedDescriptorData.length,
- vendorDescriptorData.begin(),
- vendorDescriptorData.end()));
- }
-
- descriptorsRemainingLength -= sizeof(descriptorType) +
- sizeof(descriptorLen) +
- descriptorData.length;
- descriptorCount++;
- }
-}
-
-TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
-{
- int rc = 0;
- // IANA Enterprise ID descriptor length incorrect
- constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
- 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
- uint16_t descriptorType = 0;
- variable_field descriptorData{};
-
- rc = decode_descriptor_type_length_value(nullptr,
- invalidIANADescriptor1.size(),
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
- invalidIANADescriptor1.size(),
- nullptr, &descriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
- invalidIANADescriptor1.size(),
- &descriptorType, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_descriptor_type_length_value(
- invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
- invalidIANADescriptor1.size(),
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // IANA Enterprise ID descriptor data less than length
- std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
- 0x0a, 0x0b, 0x0c};
- rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
- invalidIANADescriptor2.size(),
- &descriptorType, &descriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
-{
- int rc = 0;
- // VendorDefinedDescriptorTitleStringType is invalid
- constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
- 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
- uint8_t descriptorStringType = 0;
- variable_field descriptorTitleStr{};
- variable_field vendorDefinedDescriptorData{};
-
- rc = decode_vendor_defined_descriptor_value(
- nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
- &descriptorTitleStr, &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
- &descriptorStringType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
- nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
- &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
- &descriptorStringType, &descriptorTitleStr, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(),
- sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
- &descriptorStringType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
- &descriptorStringType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // VendorDefinedDescriptorTitleStringLength is 0
- std::array<uint8_t, 9> invalidVendorDescriptor2{
- 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
- &descriptorStringType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // VendorDefinedDescriptorData not present in the data
- std::array<uint8_t, 9> invalidVendorDescriptor3{
- 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
- rc = decode_vendor_defined_descriptor_value(
- invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
- &descriptorStringType, &descriptorTitleStr,
- &vendorDefinedDescriptorData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(DecodeComponentImageInfo, goodPath)
-{
- // Firmware
- constexpr uint16_t compClassification = 16;
- constexpr uint16_t compIdentifier = 300;
- constexpr uint32_t compComparisonStamp = 0xFFFFFFFF;
- // Force update
- constexpr std::bitset<16> compOptions{1};
- // System reboot[Bit position 3] & Medium-specific reset[Bit position 2]
- constexpr std::bitset<16> reqCompActivationMethod{0x0c};
- // Random ComponentLocationOffset
- constexpr uint32_t compLocOffset = 357;
- // Random ComponentSize
- constexpr uint32_t compSize = 27;
- // ComponentVersionString
- constexpr std::string_view compVersionStr{"VersionString1"};
- constexpr size_t compImageInfoSize =
- sizeof(pldm_component_image_information) + compVersionStr.size();
-
- constexpr std::array<uint8_t, compImageInfoSize> compImageInfo{
- 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
- 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
- pldm_component_image_information outCompImageInfo{};
- variable_field outCompVersionStr{};
-
- auto rc =
- decode_pldm_comp_image_info(compImageInfo.data(), compImageInfo.size(),
- &outCompImageInfo, &outCompVersionStr);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outCompImageInfo.comp_classification, compClassification);
- EXPECT_EQ(outCompImageInfo.comp_identifier, compIdentifier);
- EXPECT_EQ(outCompImageInfo.comp_comparison_stamp, compComparisonStamp);
- EXPECT_EQ(outCompImageInfo.comp_options.value, compOptions);
- EXPECT_EQ(outCompImageInfo.requested_comp_activation_method.value,
- reqCompActivationMethod);
- EXPECT_EQ(outCompImageInfo.comp_location_offset, compLocOffset);
- EXPECT_EQ(outCompImageInfo.comp_size, compSize);
- EXPECT_EQ(outCompImageInfo.comp_version_string_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outCompImageInfo.comp_version_string_length,
- compVersionStr.size());
-
- EXPECT_EQ(outCompVersionStr.length,
- outCompImageInfo.comp_version_string_length);
- std::string componentVersionString(
- reinterpret_cast<const char*>(outCompVersionStr.ptr),
- outCompVersionStr.length);
- EXPECT_EQ(componentVersionString, compVersionStr);
-}
-
-TEST(DecodeComponentImageInfo, errorPaths)
-{
- int rc = 0;
- // ComponentVersionString
- constexpr std::string_view compVersionStr{"VersionString1"};
- constexpr size_t compImageInfoSize =
- sizeof(pldm_component_image_information) + compVersionStr.size();
- // Invalid ComponentVersionStringType - 0x06
- constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo1{
- 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
- 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
- pldm_component_image_information outCompImageInfo{};
- variable_field outCompVersionStr{};
-
- rc = decode_pldm_comp_image_info(nullptr, invalidCompImageInfo1.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
- invalidCompImageInfo1.size(), nullptr,
- &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
- invalidCompImageInfo1.size(),
- &outCompImageInfo, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
- sizeof(pldm_component_image_information) -
- 1,
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
- invalidCompImageInfo1.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid ComponentVersionStringLength - 0x00
- constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo2{
- 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
- 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
- rc = decode_pldm_comp_image_info(invalidCompImageInfo2.data(),
- invalidCompImageInfo2.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Use Component Comparison Stamp is not set, but ComponentComparisonStamp
- // is not 0xFFFFFFFF
- constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo3{
- 0x10, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00,
- 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
- invalidCompImageInfo3.size() - 1,
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
- invalidCompImageInfo3.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid ComponentLocationOffset - 0
- constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo4{
- 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
- rc = decode_pldm_comp_image_info(invalidCompImageInfo4.data(),
- invalidCompImageInfo4.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid ComponentSize - 0
- constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo5{
- 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
- 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
- rc = decode_pldm_comp_image_info(invalidCompImageInfo5.data(),
- invalidCompImageInfo5.size(),
- &outCompImageInfo, &outCompVersionStr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
- auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
-
- uint8_t instanceId = 0x01;
-
- auto rc = encode_query_device_identifiers_req(
- instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
- EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
- EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
- EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
-}
-
-TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
-{
- // descriptorDataLen is not fixed here taking it as 6
- constexpr uint8_t descriptorDataLen = 6;
- std::array<uint8_t, hdrSize +
- sizeof(struct pldm_query_device_identifiers_resp) +
- descriptorDataLen>
- responseMsg{};
- auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
- responseMsg.data() + hdrSize);
-
- inResp->completion_code = PLDM_SUCCESS;
- inResp->device_identifiers_len = htole32(descriptorDataLen);
- inResp->descriptor_count = 1;
-
- // filling descriptor data
- std::fill_n(responseMsg.data() + hdrSize +
- sizeof(struct pldm_query_device_identifiers_resp),
- descriptorDataLen, 0xFF);
-
- auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
- uint8_t completionCode = PLDM_SUCCESS;
- uint32_t deviceIdentifiersLen = 0;
- uint8_t descriptorCount = 0;
- uint8_t* outDescriptorData = nullptr;
-
- auto rc = decode_query_device_identifiers_resp(
- response, responseMsg.size() - hdrSize, &completionCode,
- &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
- EXPECT_EQ(descriptorCount, inResp->descriptor_count);
- EXPECT_EQ(true,
- std::equal(outDescriptorData,
- outDescriptorData + deviceIdentifiersLen,
- responseMsg.begin() + hdrSize +
- sizeof(struct pldm_query_device_identifiers_resp),
- responseMsg.end()));
-}
-
-TEST(GetFirmwareParameters, goodPathEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
- auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
- uint8_t instanceId = 0x01;
-
- auto rc = encode_get_firmware_parameters_req(
- instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
- EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
- EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
- EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
-}
-
-TEST(GetFirmwareParameters, decodeResponse)
-{
- // CapabilitiesDuringUpdate of the firmware device
- // Firmware device downgrade restrictions [Bit position 8] &
- // Firmware Device Partial Updates [Bit position 3]
- constexpr std::bitset<32> fdCapabilities{0x00000104};
- constexpr uint16_t compCount = 1;
- constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
- constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
-
- // constexpr uint16_t compClassification = 16;
- // constexpr uint16_t compIdentifier = 300;
- // constexpr uint8_t compClassificationIndex = 20;
- // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
- // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
- // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
- // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
- // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
- // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
- constexpr std::string_view activeCompVersion{"VersionString3"};
- constexpr std::string_view pendingCompVersion{"VersionString4"};
- // ComponentActivationMethods
- // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
- constexpr std::bitset<16> compActivationMethod{0x12};
- // CapabilitiesDuringUpdate of the firmware component
- // Component downgrade capability [Bit position 2]
- constexpr std::bitset<32> compCapabilities{0x02};
-
- constexpr size_t compParamTableSize =
- sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
- pendingCompVersion.size();
-
- constexpr std::array<uint8_t, compParamTableSize> compParamTable{
- 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
- 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
- 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
- 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
- 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
-
- constexpr size_t getFwParamsPayloadLen =
- sizeof(pldm_get_firmware_parameters_resp) +
- activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
- compParamTableSize;
-
- constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
- getFwParamsResponse{
- 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
- 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
- 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
- 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
- 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
- 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
- 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
- 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
- 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
- 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
- pldm_get_firmware_parameters_resp outResp{};
- variable_field outActiveCompImageSetVersion{};
- variable_field outPendingCompImageSetVersion{};
- variable_field outCompParameterTable{};
-
- auto rc = decode_get_firmware_parameters_resp(
- responseMsg, getFwParamsPayloadLen, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
- EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
- EXPECT_EQ(outResp.comp_count, compCount);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
- activeCompImageSetVersion.size());
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
- pendingCompImageSetVersion.size());
- std::string activeCompImageSetVersionStr(
- reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
- outActiveCompImageSetVersion.length);
- EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
- std::string pendingCompImageSetVersionStr(
- reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
- outPendingCompImageSetVersion.length);
- EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
- EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
- EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
- outCompParameterTable.ptr +
- outCompParameterTable.length,
- compParamTable.begin(), compParamTable.end()));
-}
-
-TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
-{
- // CapabilitiesDuringUpdate of the firmware device
- // FD Host Functionality during Firmware Update [Bit position 2] &
- // Component Update Failure Retry Capability [Bit position 1]
- constexpr std::bitset<32> fdCapabilities{0x06};
- constexpr uint16_t compCount = 0;
- constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
- constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
-
- constexpr size_t getFwParamsPayloadLen =
- sizeof(pldm_get_firmware_parameters_resp) +
- activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
-
- constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
- getFwParamsResponse{
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
- 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
- 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
- pldm_get_firmware_parameters_resp outResp{};
- variable_field outActiveCompImageSetVersion{};
- variable_field outPendingCompImageSetVersion{};
- variable_field outCompParameterTable{};
-
- auto rc = decode_get_firmware_parameters_resp(
- responseMsg, getFwParamsPayloadLen, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
- EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
- EXPECT_EQ(outResp.comp_count, compCount);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
- activeCompImageSetVersion.size());
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
- pendingCompImageSetVersion.size());
- std::string activeCompImageSetVersionStr(
- reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
- outActiveCompImageSetVersion.length);
- EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
- std::string pendingCompImageSetVersionStr(
- reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
- outPendingCompImageSetVersion.length);
- EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
- EXPECT_EQ(outCompParameterTable.ptr, nullptr);
- EXPECT_EQ(outCompParameterTable.length, 0);
-}
-
-TEST(GetFirmwareParameters,
- decodeResponseNoPendingCompImageVersionStrZeroCompCount)
-{
- // CapabilitiesDuringUpdate of the firmware device
- // FD Host Functionality during Firmware Update [Bit position 2] &
- // Component Update Failure Retry Capability [Bit position 1]
- constexpr std::bitset<32> fdCapabilities{0x06};
- constexpr uint16_t compCount = 0;
- constexpr std::string_view activeCompImageSetVersion{"VersionString"};
-
- constexpr size_t getFwParamsPayloadLen =
- sizeof(pldm_get_firmware_parameters_resp) +
- activeCompImageSetVersion.size();
-
- constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
- getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
- 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
- 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
- pldm_get_firmware_parameters_resp outResp{};
- variable_field outActiveCompImageSetVersion{};
- variable_field outPendingCompImageSetVersion{};
- variable_field outCompParameterTable{};
-
- auto rc = decode_get_firmware_parameters_resp(
- responseMsg, getFwParamsPayloadLen, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
- EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
- EXPECT_EQ(outResp.comp_count, compCount);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
- EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
- activeCompImageSetVersion.size());
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
- PLDM_STR_TYPE_UNKNOWN);
- EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
- std::string activeCompImageSetVersionStr(
- reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
- outActiveCompImageSetVersion.length);
- EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
- EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
- EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
- EXPECT_EQ(outCompParameterTable.ptr, nullptr);
- EXPECT_EQ(outCompParameterTable.length, 0);
-}
-
-TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
-{
- constexpr std::array<uint8_t, hdrSize + sizeof(uint8_t)>
- getFwParamsResponse{0x00, 0x00, 0x00, 0x01};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
- pldm_get_firmware_parameters_resp outResp{};
- variable_field outActiveCompImageSetVersion{};
- variable_field outPendingCompImageSetVersion{};
- variable_field outCompParameterTable{};
-
- auto rc = decode_get_firmware_parameters_resp(
- responseMsg, getFwParamsResponse.size(), &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
-}
-
-TEST(GetFirmwareParameters, errorPathdecodeResponse)
-{
- int rc = 0;
- // Invalid ActiveComponentImageSetVersionStringType
- constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
- pldm_get_firmware_parameters_resp outResp{};
- variable_field outActiveCompImageSetVersion{};
- variable_field outPendingCompImageSetVersion{};
- variable_field outCompParameterTable{};
-
- rc = decode_get_firmware_parameters_resp(
- nullptr, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, nullptr,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
- nullptr, &outPendingCompImageSetVersion, &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
- &outPendingCompImageSetVersion, &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - 1 - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid ActiveComponentImageSetVersionStringLength
- constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
- responseMsg =
- reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse2.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid PendingComponentImageSetVersionStringType &
- // PendingComponentImageSetVersionStringLength
- constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
- responseMsg =
- reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse3.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Invalid PendingComponentImageSetVersionStringType &
- // PendingComponentImageSetVersionStringLength
- constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
- responseMsg =
- reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse4.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Total payload length less than expected
- constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
- responseMsg =
- reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
- rc = decode_get_firmware_parameters_resp(
- responseMsg, invalidGetFwParamsResponse5.size() - hdrSize, &outResp,
- &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
- &outCompParameterTable);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
-{
- // Random value for component classification
- constexpr uint16_t compClassification = 0x0A0B;
- // Random value for component classification
- constexpr uint16_t compIdentifier = 0x0C0D;
- // Random value for component classification
- constexpr uint32_t timestamp = 0X12345678;
- // Random value for component activation methods
- constexpr uint16_t compActivationMethods = 0xBBDD;
- // Random value for capabilities during update
- constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
-
- // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
- constexpr uint8_t activeCompVerStrLen = 8;
- // PendingCompImageSetVerStrLen is not fixed here taking it as 8
- constexpr uint8_t pendingCompVerStrLen = 8;
- constexpr size_t entryLength =
- sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
- pendingCompVerStrLen;
- std::array<uint8_t, entryLength> entry{};
-
- auto inEntry =
- reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
-
- inEntry->comp_classification = htole16(compClassification);
- inEntry->comp_identifier = htole16(compIdentifier);
- inEntry->comp_classification_index = 0x0F;
- inEntry->active_comp_comparison_stamp = htole32(timestamp);
- inEntry->active_comp_ver_str_type = 1;
- inEntry->active_comp_ver_str_len = activeCompVerStrLen;
- std::fill_n(inEntry->active_comp_release_date,
- sizeof(inEntry->active_comp_release_date), 0xFF);
- inEntry->pending_comp_comparison_stamp = htole32(timestamp);
- inEntry->pending_comp_ver_str_type = 1;
- inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
- std::fill_n(inEntry->pending_comp_release_date,
- sizeof(inEntry->pending_comp_release_date), 0xFF);
- inEntry->comp_activation_methods.value = htole16(compActivationMethods);
- inEntry->capabilities_during_update.value =
- htole32(capabilitiesDuringUpdate);
- constexpr auto activeCompVerStrPos =
- sizeof(struct pldm_component_parameter_entry);
- std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
- constexpr auto pendingCompVerStrPos =
- activeCompVerStrPos + activeCompVerStrLen;
- std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
- 0xBB);
-
- struct pldm_component_parameter_entry outEntry;
- struct variable_field outActiveCompVerStr;
- struct variable_field outPendingCompVerStr;
-
- auto rc = decode_get_firmware_parameters_resp_comp_entry(
- entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
- &outPendingCompVerStr);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- EXPECT_EQ(outEntry.comp_classification, compClassification);
- EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
- EXPECT_EQ(inEntry->comp_classification_index,
- outEntry.comp_classification_index);
- EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
- EXPECT_EQ(inEntry->active_comp_ver_str_type,
- outEntry.active_comp_ver_str_type);
- EXPECT_EQ(inEntry->active_comp_ver_str_len,
- outEntry.active_comp_ver_str_len);
- EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
- outEntry.active_comp_release_date,
- sizeof(inEntry->active_comp_release_date)));
- EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
- EXPECT_EQ(inEntry->pending_comp_ver_str_type,
- outEntry.pending_comp_ver_str_type);
- EXPECT_EQ(inEntry->pending_comp_ver_str_len,
- outEntry.pending_comp_ver_str_len);
- EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
- outEntry.pending_comp_release_date,
- sizeof(inEntry->pending_comp_release_date)));
- EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
- EXPECT_EQ(outEntry.capabilities_during_update.value,
- capabilitiesDuringUpdate);
-
- EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
- entry.data() + activeCompVerStrPos,
- outActiveCompVerStr.length));
- EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
- entry.data() + pendingCompVerStrPos,
- outPendingCompVerStr.length));
-}
-
-TEST(RequestUpdate, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 1;
- constexpr uint32_t maxTransferSize = 512;
- constexpr uint16_t numOfComp = 3;
- constexpr uint8_t maxOutstandingTransferReq = 2;
- constexpr uint16_t pkgDataLen = 0x1234;
- constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
- constexpr uint8_t compImgSetVerStrLen =
- static_cast<uint8_t>(compImgSetVerStr.size());
- variable_field compImgSetVerStrInfo{};
- compImgSetVerStrInfo.ptr =
- reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
- compImgSetVerStrInfo.length = compImgSetVerStrLen;
-
- std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
- compImgSetVerStrLen>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, requestMsg,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
- compImgSetVerStrLen>
- outRequest{0x81, 0x05, 0x10, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00,
- 0x02, 0x34, 0x12, 0x01, 0x0b, 0x30, 0x70, 0x65, 0x6e,
- 0x42, 0x6d, 0x63, 0x76, 0x31, 0x2e, 0x30};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(RequestUpdate, errorPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 1;
- uint32_t maxTransferSize = 512;
- constexpr uint16_t numOfComp = 3;
- uint8_t maxOutstandingTransferReq = 2;
- constexpr uint16_t pkgDataLen = 0x1234;
- constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
- uint8_t compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
- variable_field compImgSetVerStrInfo{};
- compImgSetVerStrInfo.ptr =
- reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
- compImgSetVerStrInfo.length = compImgSetVerStrLen;
-
- std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
- compImgSetVerStr.size()>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen, nullptr,
- requestMsg,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- compImgSetVerStrInfo.ptr = nullptr;
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, requestMsg,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- compImgSetVerStrInfo.ptr =
- reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
-
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_request_update_req(instanceId, maxTransferSize, numOfComp,
- maxOutstandingTransferReq, pkgDataLen,
- PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, requestMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- compImgSetVerStrLen = 0;
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, 0, &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
-
- compImgSetVerStrInfo.length = 0xFFFF;
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- compImgSetVerStrInfo.length = compImgSetVerStrLen;
-
- maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE - 1;
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE;
-
- maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ - 1;
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
- &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ;
-
- rc = encode_request_update_req(
- instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
- pkgDataLen, PLDM_STR_TYPE_UNKNOWN, compImgSetVerStrLen,
- &compImgSetVerStrInfo, nullptr,
- sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(RequestUpdate, goodPathDecodeResponse)
-{
- constexpr uint16_t fdMetaDataLen = 1024;
- constexpr uint8_t fdWillSendPkgData = 1;
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_request_update_resp)>
- requestUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01};
-
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(requestUpdateResponse1.data());
- uint8_t outCompletionCode = 0;
- uint16_t outFdMetaDataLen = 0;
- uint8_t outFdWillSendPkgData = 0;
-
- auto rc = decode_request_update_resp(
- responseMsg1, requestUpdateResponse1.size() - hdrSize,
- &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outCompletionCode, PLDM_SUCCESS);
- EXPECT_EQ(outFdMetaDataLen, fdMetaDataLen);
- EXPECT_EQ(outFdWillSendPkgData, fdWillSendPkgData);
-
- outCompletionCode = 0;
- outFdMetaDataLen = 0;
- outFdWillSendPkgData = 0;
-
- constexpr std::array<uint8_t, hdrSize + sizeof(outCompletionCode)>
- requestUpdateResponse2{0x00, 0x00, 0x00, 0x81};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(requestUpdateResponse2.data());
- rc = decode_request_update_resp(
- responseMsg2, requestUpdateResponse2.size() - hdrSize,
- &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outCompletionCode, PLDM_FWUP_ALREADY_IN_UPDATE_MODE);
-}
-
-TEST(RequestUpdate, errorPathDecodeResponse)
-{
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_request_update_resp) - 1>
- requestUpdateResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
-
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(requestUpdateResponse.data());
- uint8_t outCompletionCode = 0;
- uint16_t outFdMetaDataLen = 0;
- uint8_t outFdWillSendPkgData = 0;
-
- auto rc = decode_request_update_resp(
- nullptr, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
- &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_update_resp(
- responseMsg, requestUpdateResponse.size() - hdrSize, nullptr,
- &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_update_resp(
- responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
- nullptr, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_update_resp(
- responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
- &outFdMetaDataLen, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_update_resp(responseMsg, 0, &outCompletionCode,
- &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_update_resp(
- responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
- &outFdMetaDataLen, &outFdWillSendPkgData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(PassComponentTable, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 1;
- constexpr uint16_t compIdentifier = 400;
- constexpr uint8_t compClassificationIndex = 40;
- constexpr uint32_t compComparisonStamp = 0x12345678;
- constexpr std::string_view compVerStr = "0penBmcv1.1";
- constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
- variable_field compVerStrInfo{};
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
- compVerStrInfo.length = compVerStrLen;
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
- outRequest{0x81, 0x05, 0x13, 0x05, 0x0A, 0x00, 0x90, 0x01, 0x28,
- 0x78, 0x56, 0x34, 0x12, 0x01, 0x0B, 0x30, 0x70, 0x65,
- 0x6E, 0x42, 0x6D, 0x63, 0x76, 0x31, 0x2E, 0x31};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(PassComponentTable, errorPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 1;
- constexpr uint16_t compIdentifier = 400;
- constexpr uint8_t compClassificationIndex = 40;
- constexpr uint32_t compComparisonStamp = 0x12345678;
- constexpr std::string_view compVerStr = "0penBmcv1.1";
- constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
- variable_field compVerStrInfo{};
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
- compVerStrInfo.length = compVerStrLen;
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, nullptr, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- compVerStrInfo.ptr = nullptr;
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, nullptr,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req));
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII, 0,
- &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen - 1, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END + 1, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_INVALID_TRANSFER_OPERATION_FLAG);
-
- rc = encode_pass_component_table_req(
- instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
- compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_UNKNOWN,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_pass_component_table_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(PassComponentTable, goodPathDecodeResponse)
-{
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
-
- uint8_t completionCode = 0;
- uint8_t compResp = 0;
- uint8_t compRespCode = 0;
-
- auto rc = decode_pass_component_table_resp(
- responseMsg1, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
- EXPECT_EQ(compRespCode, PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL);
-
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0xD0};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
- rc = decode_pass_component_table_resp(
- responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
- EXPECT_EQ(compRespCode, PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN);
-
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse3{0x00, 0x00, 0x00, 0x80};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
-
- rc = decode_pass_component_table_resp(
- responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
-}
-
-TEST(PassComponentTable, errorPathDecodeResponse)
-{
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp) - 1>
- passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
-
- uint8_t completionCode = 0;
- uint8_t compResp = 0;
- uint8_t compRespCode = 0;
-
- auto rc = decode_pass_component_table_resp(
- nullptr, sizeof(pldm_pass_component_table_resp) - 1, &completionCode,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pass_component_table_resp(
- responseMsg1, sizeof(pldm_pass_component_table_resp) - 1, nullptr,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pass_component_table_resp(
- responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
- &completionCode, nullptr, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pass_component_table_resp(
- responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
- &completionCode, &compResp, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pass_component_table_resp(responseMsg1, 0, &completionCode,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_pass_component_table_resp(
- responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
- &completionCode, &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
- rc = decode_pass_component_table_resp(
- responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
- rc = decode_pass_component_table_resp(
- responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_pass_component_table_resp)>
- passCompTableResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0};
- auto responseMsg4 =
- reinterpret_cast<const pldm_msg*>(passCompTableResponse4.data());
- rc = decode_pass_component_table_resp(
- responseMsg4, sizeof(pldm_pass_component_table_resp), &completionCode,
- &compResp, &compRespCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(UpdateComponent, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 2;
- constexpr uint16_t compIdentifier = 500;
- constexpr uint8_t compClassificationIndex = 50;
- constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
- constexpr uint32_t compImageSize = 4096;
- constexpr bitfield32_t updateOptionFlags{1};
- constexpr std::string_view compVerStr = "OpenBmcv2.2";
- constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
- variable_field compVerStrInfo{};
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
- compVerStrInfo.length = compVerStrLen;
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
- outRequest{0x82, 0x05, 0x14, 0x0A, 0x00, 0xF4, 0x01, 0x32, 0xEF,
- 0xCD, 0xAB, 0x89, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x01, 0x0B, 0x4f, 0x70, 0x65, 0x6E, 0x42,
- 0x6D, 0x63, 0x76, 0x32, 0x2E, 0x32};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(UpdateComponent, errorPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 2;
- constexpr uint16_t compIdentifier = 500;
- constexpr uint8_t compClassificationIndex = 50;
- constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
- constexpr uint32_t compImageSize = 4096;
- constexpr bitfield32_t updateOptionFlags{1};
- constexpr std::string_view compVerStr = "OpenBmcv2.2";
- constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
- variable_field compVerStrInfo{};
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
- compVerStrInfo.length = compVerStrLen;
-
- std::array<uint8_t,
- hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
- request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen, nullptr, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- compVerStrInfo.ptr = nullptr;
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, nullptr,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req));
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, 0, updateOptionFlags, PLDM_STR_TYPE_ASCII,
- compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, 0, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_ASCII, compVerStrLen - 1, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_update_component_req(
- instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
- compComparisonStamp, compImageSize, updateOptionFlags,
- PLDM_STR_TYPE_UNKNOWN, compVerStrLen, &compVerStrInfo, requestMsg,
- sizeof(pldm_update_component_req) + compVerStrLen);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(UpdateComponent, goodPathDecodeResponse)
-{
- constexpr std::bitset<32> forceUpdateComp{1};
- constexpr uint16_t timeBeforeSendingReqFwData100s = 100;
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
-
- uint8_t completionCode = 0;
- uint8_t compCompatibilityResp = 0;
- uint8_t compCompatibilityRespCode = 0;
- bitfield32_t updateOptionFlagsEnabled{};
- uint16_t timeBeforeReqFWData = 0;
-
- auto rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CAN_BE_UPDATED);
- EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_NO_RESPONSE_CODE);
- EXPECT_EQ(updateOptionFlagsEnabled.value, forceUpdateComp);
- EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData100s);
-
- constexpr std::bitset<32> noFlags{};
- constexpr uint16_t timeBeforeSendingReqFwData0s = 0;
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
- rc = decode_update_component_resp(
- responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CANNOT_BE_UPDATED);
- EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_COMP_INFO_NO_MATCH);
- EXPECT_EQ(updateOptionFlagsEnabled.value, noFlags);
- EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData0s);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse3{0x00, 0x00, 0x00, 0x80};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
-
- rc = decode_update_component_resp(
- responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
-}
-
-TEST(UpdateComponent, errorPathDecodeResponse)
-{
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_update_component_resp) - 1>
- updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
- 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
-
- uint8_t completionCode = 0;
- uint8_t compCompatibilityResp = 0;
- uint8_t compCompatibilityRespCode = 0;
- bitfield32_t updateOptionFlagsEnabled{};
- uint16_t timeBeforeReqFWData = 0;
-
- auto rc = decode_update_component_resp(
- nullptr, sizeof(pldm_update_component_resp) - 1, &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, nullptr,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
- nullptr, &compCompatibilityRespCode, &updateOptionFlagsEnabled,
- &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
- &compCompatibilityResp, nullptr, &updateOptionFlagsEnabled,
- &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode, nullptr,
- &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, 0, &completionCode, &compCompatibilityResp,
- &compCompatibilityRespCode, &updateOptionFlagsEnabled,
- &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_update_component_resp(
- responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
- rc = decode_update_component_resp(
- responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
- 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
- rc = decode_update_component_resp(
- responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
- updateComponentResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
- 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
- auto responseMsg4 =
- reinterpret_cast<const pldm_msg*>(updateComponentResponse4.data());
- rc = decode_update_component_resp(
- responseMsg4, sizeof(pldm_update_component_resp), &completionCode,
- &compCompatibilityResp, &compCompatibilityRespCode,
- &updateOptionFlagsEnabled, &timeBeforeReqFWData);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(RequestFirmwareData, goodPathDecodeRequest)
-{
- constexpr uint32_t offset = 300;
- constexpr uint32_t length = 255;
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_request_firmware_data_req)>
- reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
- 0x00, 0xFF, 0x00, 0x00, 0x00};
- auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
-
- uint32_t outOffset = 0;
- uint32_t outLength = 0;
- auto rc = decode_request_firmware_data_req(
- requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
- &outLength);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outOffset, offset);
- EXPECT_EQ(outLength, length);
-}
-
-TEST(RequestFirmwareData, errorPathDecodeRequest)
-{
- constexpr std::array<uint8_t,
- hdrSize + sizeof(pldm_request_firmware_data_req)>
- reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
- 0x00, 0x1F, 0x00, 0x00, 0x00};
- auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
-
- uint32_t outOffset = 0;
- uint32_t outLength = 0;
- auto rc = decode_request_firmware_data_req(
- nullptr, sizeof(pldm_request_firmware_data_req), &outOffset,
- &outLength);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_firmware_data_req(
- requestMsg, sizeof(pldm_request_firmware_data_req), nullptr,
- &outLength);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_firmware_data_req(
- requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
- nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_request_firmware_data_req(
- requestMsg, sizeof(pldm_request_firmware_data_req) - 1, &outOffset,
- &outLength);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = decode_request_firmware_data_req(
- requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
- &outLength);
- EXPECT_EQ(rc, PLDM_FWUP_INVALID_TRANSFER_LENGTH);
-}
-
-TEST(RequestFirmwareData, goodPathEncodeResponse)
-{
- constexpr uint8_t instanceId = 3;
- constexpr uint8_t completionCode = PLDM_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode) +
- PLDM_FWUP_BASELINE_TRANSFER_SIZE>
- outReqFwDataResponse1{0x03, 0x05, 0x15, 0x00, 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
- 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
- 0x1D, 0x1E, 0x1F, 0x20};
- std::array<uint8_t, hdrSize + sizeof(completionCode) +
- PLDM_FWUP_BASELINE_TRANSFER_SIZE>
- reqFwDataResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
- 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
- 0x1D, 0x1E, 0x1F, 0x20};
- auto responseMsg1 = reinterpret_cast<pldm_msg*>(reqFwDataResponse1.data());
- auto rc = encode_request_firmware_data_resp(
- instanceId, completionCode, responseMsg1,
- sizeof(completionCode) + PLDM_FWUP_BASELINE_TRANSFER_SIZE);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(reqFwDataResponse1, outReqFwDataResponse1);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outReqFwDataResponse2{0x03, 0x05, 0x15, 0x82};
- std::array<uint8_t, hdrSize + sizeof(completionCode)> reqFwDataResponse2{
- 0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 = reinterpret_cast<pldm_msg*>(reqFwDataResponse2.data());
- rc = encode_request_firmware_data_resp(
- instanceId, PLDM_FWUP_DATA_OUT_OF_RANGE, responseMsg2,
- sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(reqFwDataResponse2, outReqFwDataResponse2);
-}
-
-TEST(RequestFirmwareData, errorPathEncodeResponse)
-{
- std::array<uint8_t, hdrSize> reqFwDataResponse{0x00, 0x00, 0x00};
- auto responseMsg = reinterpret_cast<pldm_msg*>(reqFwDataResponse.data());
- auto rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, nullptr, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, responseMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(TransferComplete, goodPathDecodeRequest)
-{
- constexpr uint8_t transferResult = PLDM_FWUP_TRANSFER_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
- transferCompleteReq1{0x00, 0x00, 0x00, 0x00};
- auto requestMsg1 =
- reinterpret_cast<const pldm_msg*>(transferCompleteReq1.data());
- uint8_t outTransferResult = 0;
-
- auto rc = decode_transfer_complete_req(requestMsg1, sizeof(transferResult),
- &outTransferResult);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outTransferResult, transferResult);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
- transferCompleteReq2{0x00, 0x00, 0x00, 0x02};
- auto requestMsg2 =
- reinterpret_cast<const pldm_msg*>(transferCompleteReq2.data());
- rc = decode_transfer_complete_req(requestMsg2, sizeof(transferResult),
- &outTransferResult);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outTransferResult, PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT);
-}
-
-TEST(TransferComplete, errorPathDecodeRequest)
-{
- constexpr std::array<uint8_t, hdrSize> transferCompleteReq{0x00, 0x00,
- 0x00};
- auto requestMsg =
- reinterpret_cast<const pldm_msg*>(transferCompleteReq.data());
- uint8_t outTransferResult = 0;
-
- auto rc = decode_transfer_complete_req(nullptr, 0, &outTransferResult);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_transfer_complete_req(requestMsg, 0, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_transfer_complete_req(requestMsg, 0, &outTransferResult);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(TransferComplete, goodPathEncodeResponse)
-{
- constexpr uint8_t instanceId = 4;
- constexpr uint8_t completionCode = PLDM_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outTransferCompleteResponse1{0x04, 0x05, 0x16, 0x00};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- transferCompleteResponse1{0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<pldm_msg*>(transferCompleteResponse1.data());
- auto rc = encode_transfer_complete_resp(
- instanceId, completionCode, responseMsg1, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(transferCompleteResponse1, outTransferCompleteResponse1);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outTransferCompleteResponse2{0x04, 0x05, 0x16, 0x87};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- transferCompleteResponse2{0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<pldm_msg*>(transferCompleteResponse2.data());
- rc = encode_transfer_complete_resp(instanceId,
- PLDM_FWUP_COMMAND_NOT_EXPECTED,
- responseMsg2, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(transferCompleteResponse2, outTransferCompleteResponse2);
-}
-
-TEST(TransferComplete, errorPathEncodeResponse)
-{
- std::array<uint8_t, hdrSize> transferCompleteResponse{0x00, 0x00, 0x00};
- auto responseMsg =
- reinterpret_cast<pldm_msg*>(transferCompleteResponse.data());
- auto rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(VerifyComplete, goodPathDecodeRequest)
-{
- constexpr uint8_t verifyResult = PLDM_FWUP_VERIFY_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
- verifyCompleteReq1{0x00, 0x00, 0x00, 0x00};
- auto requestMsg1 =
- reinterpret_cast<const pldm_msg*>(verifyCompleteReq1.data());
- uint8_t outVerifyResult = 0;
-
- auto rc = decode_verify_complete_req(requestMsg1, sizeof(verifyResult),
- &outVerifyResult);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outVerifyResult, verifyResult);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
- verifyCompleteReq2{0x00, 0x00, 0x00, 0x03};
- auto requestMsg2 =
- reinterpret_cast<const pldm_msg*>(verifyCompleteReq2.data());
- rc = decode_verify_complete_req(requestMsg2, sizeof(verifyResult),
- &outVerifyResult);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outVerifyResult, PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS);
-}
-
-TEST(VerifyComplete, errorPathDecodeRequest)
-{
- constexpr std::array<uint8_t, hdrSize> verifyCompleteReq{0x00, 0x00, 0x00};
- auto requestMsg =
- reinterpret_cast<const pldm_msg*>(verifyCompleteReq.data());
- uint8_t outVerifyResult = 0;
-
- auto rc = decode_verify_complete_req(nullptr, 0, &outVerifyResult);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_verify_complete_req(requestMsg, 0, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_verify_complete_req(requestMsg, 0, &outVerifyResult);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(VerifyComplete, goodPathEncodeResponse)
-{
- constexpr uint8_t instanceId = 5;
- constexpr uint8_t completionCode = PLDM_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outVerifyCompleteResponse1{0x05, 0x05, 0x17, 0x00};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- verifyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<pldm_msg*>(verifyCompleteResponse1.data());
- auto rc = encode_verify_complete_resp(instanceId, completionCode,
- responseMsg1, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(verifyCompleteResponse1, outVerifyCompleteResponse1);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outVerifyCompleteResponse2{0x05, 0x05, 0x17, 0x87};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- verifyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<pldm_msg*>(verifyCompleteResponse2.data());
- rc = encode_verify_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
- responseMsg2, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(verifyCompleteResponse2, outVerifyCompleteResponse2);
-}
-
-TEST(VerifyComplete, errorPathEncodeResponse)
-{
- std::array<uint8_t, hdrSize> verifyCompleteResponse{0x00, 0x00, 0x00};
- auto responseMsg =
- reinterpret_cast<pldm_msg*>(verifyCompleteResponse.data());
- auto rc = encode_verify_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_verify_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ApplyComplete, goodPathDecodeRequest)
-{
- constexpr uint8_t applyResult1 =
- PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD;
- // DC power cycle [Bit position 4] & AC power cycle [Bit position 5]
- constexpr std::bitset<16> compActivationModification1{0x30};
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
- applyCompleteReq1{0x00, 0x00, 0x00, 0x01, 0x30, 0x00};
- auto requestMsg1 =
- reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
- uint8_t outApplyResult = 0;
- bitfield16_t outCompActivationModification{};
- auto rc = decode_apply_complete_req(
- requestMsg1, sizeof(pldm_apply_complete_req), &outApplyResult,
- &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outApplyResult, applyResult1);
- EXPECT_EQ(outCompActivationModification.value, compActivationModification1);
-
- constexpr uint8_t applyResult2 = PLDM_FWUP_APPLY_SUCCESS;
- constexpr std::bitset<16> compActivationModification2{};
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
- applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto requestMsg2 =
- reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
- rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
- &outApplyResult,
- &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(outApplyResult, applyResult2);
- EXPECT_EQ(outCompActivationModification.value, compActivationModification2);
-}
-
-TEST(ApplyComplete, errorPathDecodeRequest)
-{
- constexpr std::array<uint8_t, hdrSize> applyCompleteReq1{0x00, 0x00, 0x00};
- auto requestMsg1 =
- reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
- uint8_t outApplyResult = 0;
- bitfield16_t outCompActivationModification{};
-
- auto rc = decode_apply_complete_req(
- nullptr, sizeof(pldm_apply_complete_req), &outApplyResult,
- &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
- nullptr, &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
- &outApplyResult, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_apply_complete_req(requestMsg1, 0, &outApplyResult,
- &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
- applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
- auto requestMsg2 =
- reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
- rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
- &outApplyResult,
- &outCompActivationModification);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(ApplyComplete, goodPathEncodeResponse)
-{
- constexpr uint8_t instanceId = 6;
- constexpr uint8_t completionCode = PLDM_SUCCESS;
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outApplyCompleteResponse1{0x06, 0x05, 0x18, 0x00};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- applyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<pldm_msg*>(applyCompleteResponse1.data());
- auto rc = encode_apply_complete_resp(instanceId, completionCode,
- responseMsg1, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(applyCompleteResponse1, outApplyCompleteResponse1);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- outApplyCompleteResponse2{0x06, 0x05, 0x18, 0x87};
- std::array<uint8_t, hdrSize + sizeof(completionCode)>
- applyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<pldm_msg*>(applyCompleteResponse2.data());
- rc = encode_apply_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
- responseMsg2, sizeof(completionCode));
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(applyCompleteResponse2, outApplyCompleteResponse2);
-}
-
-TEST(ApplyComplete, errorPathEncodeResponse)
-{
- std::array<uint8_t, hdrSize> applyCompleteResponse{0x00, 0x00, 0x00};
- auto responseMsg =
- reinterpret_cast<pldm_msg*>(applyCompleteResponse.data());
- auto rc = encode_apply_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_apply_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ActivateFirmware, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 7;
-
- std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_activate_firmware_req(
- instanceId, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg,
- sizeof(pldm_activate_firmware_req));
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)>
- outRequest{0x87, 0x05, 0x1A, 0x01};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(ActivateFirmware, errorPathEncodeRequest)
-{
- std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_activate_firmware_req(
- 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, nullptr,
- sizeof(pldm_activate_firmware_req));
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_activate_firmware_req(
- 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, 0);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- rc = encode_activate_firmware_req(0, 2, requestMsg,
- sizeof(pldm_activate_firmware_req));
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(ActivateFirmware, goodPathDecodeResponse)
-{
- constexpr uint16_t estimatedTimeForActivation100s = 100;
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
- activateFirmwareResponse1{0x00, 0x00, 0x00, 0x00, 0x64, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(activateFirmwareResponse1.data());
-
- uint8_t completionCode = 0;
- uint16_t estimatedTimeForActivation = 0;
-
- auto rc = decode_activate_firmware_resp(
- responseMsg1, sizeof(pldm_activate_firmware_resp), &completionCode,
- &estimatedTimeForActivation);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(estimatedTimeForActivation, estimatedTimeForActivation100s);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- activateFirmwareResponse2{0x00, 0x00, 0x00, 0x85};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(activateFirmwareResponse2.data());
-
- rc = decode_activate_firmware_resp(responseMsg2, sizeof(completionCode),
- &completionCode,
- &estimatedTimeForActivation);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_FWUP_INCOMPLETE_UPDATE);
-}
-
-TEST(ActivateFirmware, errorPathDecodeResponse)
-{
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
- activateFirmwareResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(activateFirmwareResponse.data());
-
- uint8_t completionCode = 0;
- uint16_t estimatedTimeForActivation = 0;
-
- auto rc = decode_activate_firmware_resp(
- nullptr, sizeof(pldm_activate_firmware_resp), &completionCode,
- &estimatedTimeForActivation);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_activate_firmware_resp(responseMsg,
- sizeof(pldm_activate_firmware_resp),
- nullptr, &estimatedTimeForActivation);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_activate_firmware_resp(responseMsg,
- sizeof(pldm_activate_firmware_resp),
- &completionCode, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_activate_firmware_resp(responseMsg, 0, &completionCode,
- &estimatedTimeForActivation);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_activate_firmware_resp(
- responseMsg, sizeof(pldm_activate_firmware_resp) - 1, &completionCode,
- &estimatedTimeForActivation);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetStatus, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 8;
- std::array<uint8_t, hdrSize> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_get_status_req(instanceId, requestMsg,
- PLDM_GET_STATUS_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- constexpr std::array<uint8_t, hdrSize> outRequest{0x88, 0x05, 0x1B};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(GetStatus, errorPathEncodeRequest)
-{
- std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_get_status_req(0, nullptr, PLDM_GET_STATUS_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_get_status_req(0, requestMsg, PLDM_GET_STATUS_REQ_BYTES + 1);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetStatus, goodPathDecodeResponse)
-{
- constexpr std::bitset<32> updateOptionFlagsEnabled1{0};
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03,
- 0x09, 0x65, 0x05, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
-
- uint8_t completionCode = 0;
- uint8_t currentState = 0;
- uint8_t previousState = 0;
- uint8_t auxState = 0;
- uint8_t auxStateStatus = 0;
- uint8_t progressPercent = 0;
- uint8_t reasonCode = 0;
- bitfield32_t updateOptionFlagsEnabled{0};
-
- auto rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(currentState, PLDM_FD_STATE_IDLE);
- EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
- EXPECT_EQ(auxState, PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER);
- EXPECT_EQ(auxStateStatus, PLDM_FD_TIMEOUT);
- EXPECT_EQ(progressPercent, PLDM_FWUP_MAX_PROGRESS_PERCENT);
- EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
- EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled1);
-
- // Bit position 0 - Force update of component – FD will perform a force
- // update of the component.
- constexpr std::bitset<32> updateOptionFlagsEnabled2{1};
- constexpr uint8_t progressPercent2 = 50;
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00,
- 0x70, 0x32, 0x05, 0x01, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
-
- rc = decode_get_status_resp(
- responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(currentState, PLDM_FD_STATE_VERIFY);
- EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
- EXPECT_EQ(auxState, PLDM_FD_OPERATION_IN_PROGRESS);
- EXPECT_EQ(auxStateStatus, PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START);
- EXPECT_EQ(progressPercent, progressPercent2);
- EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
- EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled2);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- getStatusResponse3{0x00, 0x00, 0x00, 0x04};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
- rc = decode_get_status_resp(
- responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_ERROR_NOT_READY);
-}
-
-TEST(GetStatus, errorPathDecodeResponse)
-{
- uint8_t completionCode = 0;
- uint8_t currentState = 0;
- uint8_t previousState = 0;
- uint8_t auxState = 0;
- uint8_t auxStateStatus = 0;
- uint8_t progressPercent = 0;
- uint8_t reasonCode = 0;
- bitfield32_t updateOptionFlagsEnabled{0};
-
- constexpr std::array<uint8_t, hdrSize> getStatusResponse1{0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
-
- auto rc = decode_get_status_resp(
- nullptr, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, nullptr,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- nullptr, &previousState, &auxState, &auxStateStatus, &progressPercent,
- &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, nullptr, &auxState, &auxStateStatus, &progressPercent,
- &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, nullptr, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, nullptr, &progressPercent,
- &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus, nullptr,
- &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, nullptr, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_status_resp(
- responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp) - 1>
- getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
- rc = decode_get_status_resp(
- responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse3{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
- rc = decode_get_status_resp(
- responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg4 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse4.data());
- rc = decode_get_status_resp(
- responseMsg4, getStatusResponse4.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse5{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg5 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse5.data());
- rc = decode_get_status_resp(
- responseMsg5, getStatusResponse5.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse6{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg6 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse6.data());
- rc = decode_get_status_resp(
- responseMsg6, getStatusResponse6.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse7{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg7 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse7.data());
- rc = decode_get_status_resp(
- responseMsg7, getStatusResponse7.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse8{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xC7, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg8 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse8.data());
- rc = decode_get_status_resp(
- responseMsg8, getStatusResponse8.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // AuxState is not PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER when the state is
- // IDLE
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
- getStatusResponse9{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg9 =
- reinterpret_cast<const pldm_msg*>(getStatusResponse9.data());
- rc = decode_get_status_resp(
- responseMsg9, getStatusResponse9.size() - hdrSize, &completionCode,
- ¤tState, &previousState, &auxState, &auxStateStatus,
- &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(CancelUpdateComponent, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 9;
- std::array<uint8_t, hdrSize> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_cancel_update_component_req(
- instanceId, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- constexpr std::array<uint8_t, hdrSize> outRequest{0x89, 0x05, 0x1C};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(CancelUpdateComponent, errorPathEncodeRequest)
-{
- std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_cancel_update_component_req(
- 0, nullptr, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_cancel_update_component_req(
- 0, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES + 1);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(CancelUpdateComponent, testGoodDecodeResponse)
-{
- uint8_t completionCode = 0;
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- cancelUpdateComponentResponse1{0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 = reinterpret_cast<const pldm_msg*>(
- cancelUpdateComponentResponse1.data());
- auto rc = decode_cancel_update_component_resp(
- responseMsg1, cancelUpdateComponentResponse1.size() - hdrSize,
- &completionCode);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- cancelUpdateComponentResponse2{0x00, 0x00, 0x00, 0x86};
- auto responseMsg2 = reinterpret_cast<const pldm_msg*>(
- cancelUpdateComponentResponse2.data());
- rc = decode_cancel_update_component_resp(
- responseMsg2, cancelUpdateComponentResponse2.size() - hdrSize,
- &completionCode);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
-}
-
-TEST(CancelUpdateComponent, testBadDecodeResponse)
-{
- uint8_t completionCode = 0;
- constexpr std::array<uint8_t, hdrSize> cancelUpdateComponentResponse{
- 0x00, 0x00, 0x00};
- auto responseMsg =
- reinterpret_cast<const pldm_msg*>(cancelUpdateComponentResponse.data());
-
- auto rc = decode_cancel_update_component_resp(
- nullptr, cancelUpdateComponentResponse.size() - hdrSize,
- &completionCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_component_resp(
- responseMsg, cancelUpdateComponentResponse.size() - hdrSize, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_component_resp(
- responseMsg, cancelUpdateComponentResponse.size() - hdrSize,
- &completionCode);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(CancelUpdate, goodPathEncodeRequest)
-{
- constexpr uint8_t instanceId = 10;
- std::array<uint8_t, hdrSize> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc = encode_cancel_update_req(instanceId, requestMsg,
- PLDM_CANCEL_UPDATE_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- constexpr std::array<uint8_t, hdrSize> outRequest{0x8A, 0x05, 0x1D};
- EXPECT_EQ(request, outRequest);
-}
-
-TEST(CancelUpdate, errorPathEncodeRequest)
-{
- std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
- auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
-
- auto rc =
- encode_cancel_update_req(0, nullptr, PLDM_CANCEL_UPDATE_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = encode_cancel_update_req(0, requestMsg,
- PLDM_CANCEL_UPDATE_REQ_BYTES + 1);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(CancelUpdate, goodPathDecodeResponse)
-{
- constexpr std::bitset<64> nonFunctioningComponentBitmap1{0};
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
- cancelUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
- uint8_t completionCode = 0;
- bool8_t nonFunctioningComponentIndication = 0;
- bitfield64_t nonFunctioningComponentBitmap{0};
- auto rc = decode_cancel_update_resp(
- responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(nonFunctioningComponentIndication,
- PLDM_FWUP_COMPONENTS_FUNCTIONING);
- EXPECT_EQ(nonFunctioningComponentBitmap.value,
- nonFunctioningComponentBitmap1);
-
- constexpr std::bitset<64> nonFunctioningComponentBitmap2{0x0101};
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
- cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
- rc = decode_cancel_update_resp(
- responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_SUCCESS);
- EXPECT_EQ(nonFunctioningComponentIndication,
- PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING);
- EXPECT_EQ(nonFunctioningComponentBitmap.value,
- nonFunctioningComponentBitmap2);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- cancelUpdateResponse3{0x00, 0x00, 0x00, 0x86};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
- rc = decode_cancel_update_resp(
- responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
-}
-
-TEST(CancelUpdate, errorPathDecodeResponse)
-{
- constexpr std::array<uint8_t, hdrSize> cancelUpdateResponse1{0x00, 0x00,
- 0x00};
- auto responseMsg1 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
- uint8_t completionCode = 0;
- bool8_t nonFunctioningComponentIndication = 0;
- bitfield64_t nonFunctioningComponentBitmap{0};
-
- auto rc = decode_cancel_update_resp(
- nullptr, cancelUpdateResponse1.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_resp(
- responseMsg1, cancelUpdateResponse1.size() - hdrSize, nullptr,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_resp(
- responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
- nullptr, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_resp(
- responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, nullptr);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_cancel_update_resp(
- responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
- cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00};
- auto responseMsg2 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
- rc = decode_cancel_update_resp(
- responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
- cancelUpdateResponse3{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- auto responseMsg3 =
- reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
- rc = decode_cancel_update_resp(
- responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
- &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
+#include <bitset>
+#include <cstring>
+
+#include "libpldm/base.h"
+#include "libpldm/firmware_update.h"
+
+#include <gtest/gtest.h>
+
+constexpr auto hdrSize = sizeof(pldm_msg_hdr);
+
+TEST(DecodePackageHeaderInfo, goodPath)
+{
+ // Package header identifier for Version 1.0.x
+ constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43,
+ 0x98, 0x00, 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02};
+ // Package header version for DSP0267 version 1.0.x
+ constexpr uint8_t pkgHeaderFormatRevision = 0x01;
+ // Random PackageHeaderSize
+ constexpr uint16_t pkgHeaderSize = 303;
+ // PackageReleaseDateTime - "25/12/2021 00:00:00"
+ std::array<uint8_t, PLDM_TIMESTAMP104_SIZE> timestamp104{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00};
+ constexpr uint16_t componentBitmapBitLength = 8;
+ // PackageVersionString
+ constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
+ constexpr size_t packagerHeaderSize =
+ sizeof(pldm_package_header_information) + packageVersionStr.size();
+
+ constexpr std::array<uint8_t, packagerHeaderSize> packagerHeaderInfo{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00, 0xa0, 0x2F,
+ 0x05, 0x9a, 0xca, 0x02, 0x01, 0x2f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b,
+ 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
+ pldm_package_header_information pkgHeader{};
+ variable_field packageVersion{};
+
+ auto rc = decode_pldm_package_header_info(packagerHeaderInfo.data(),
+ packagerHeaderInfo.size(),
+ &pkgHeader, &packageVersion);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(true,
+ std::equal(pkgHeader.uuid, pkgHeader.uuid + PLDM_FWUP_UUID_LENGTH,
+ uuid.begin(), uuid.end()));
+ EXPECT_EQ(pkgHeader.package_header_format_version, pkgHeaderFormatRevision);
+ EXPECT_EQ(pkgHeader.package_header_size, pkgHeaderSize);
+ EXPECT_EQ(true, std::equal(pkgHeader.timestamp104,
+ pkgHeader.timestamp104 + PLDM_TIMESTAMP104_SIZE,
+ timestamp104.begin(), timestamp104.end()));
+ EXPECT_EQ(pkgHeader.component_bitmap_bit_length, componentBitmapBitLength);
+ EXPECT_EQ(pkgHeader.package_version_string_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(pkgHeader.package_version_string_length,
+ packageVersionStr.size());
+ std::string packageVersionString(
+ reinterpret_cast<const char*>(packageVersion.ptr),
+ packageVersion.length);
+ EXPECT_EQ(packageVersionString, packageVersionStr);
+}
+
+TEST(DecodePackageHeaderInfo, errorPaths)
+{
+ int rc = 0;
+ constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
+ constexpr size_t packagerHeaderSize =
+ sizeof(pldm_package_header_information) + packageVersionStr.size();
+
+ // Invalid Package Version String Type - 0x06
+ constexpr std::array<uint8_t, packagerHeaderSize>
+ invalidPackagerHeaderInfo1{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
+ 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
+ 0x07, 0x00, 0x08, 0x00, 0x06, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
+ 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
+
+ pldm_package_header_information packageHeader{};
+ variable_field packageVersion{};
+
+ rc = decode_pldm_package_header_info(nullptr,
+ invalidPackagerHeaderInfo1.size(),
+ &packageHeader, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
+ invalidPackagerHeaderInfo1.size(),
+ nullptr, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
+ invalidPackagerHeaderInfo1.size(),
+ &packageHeader, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_package_header_info(
+ invalidPackagerHeaderInfo1.data(),
+ sizeof(pldm_package_header_information) - 1, &packageHeader,
+ &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
+ invalidPackagerHeaderInfo1.size(),
+ &packageHeader, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid Package Version String Length - 0x00
+ constexpr std::array<uint8_t, packagerHeaderSize>
+ invalidPackagerHeaderInfo2{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
+ 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
+ 0x07, 0x00, 0x08, 0x00, 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e,
+ 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo2.data(),
+ invalidPackagerHeaderInfo2.size(),
+ &packageHeader, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Package version string length less than in the header information
+ constexpr std::array<uint8_t, packagerHeaderSize - 1>
+ invalidPackagerHeaderInfo3{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
+ 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
+ 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
+ 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e};
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo3.data(),
+ invalidPackagerHeaderInfo3.size(),
+ &packageHeader, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // ComponentBitmapBitLength not a multiple of 8
+ constexpr std::array<uint8_t, packagerHeaderSize>
+ invalidPackagerHeaderInfo4{
+ 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
+ 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
+ 0x07, 0x00, 0x09, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
+ 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
+ rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo4.data(),
+ invalidPackagerHeaderInfo4.size(),
+ &packageHeader, &packageVersion);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(DecodeFirmwareDeviceIdRecord, goodPath)
+{
+ constexpr uint8_t descriptorCount = 1;
+ // Continue component updates after failure
+ constexpr std::bitset<32> deviceUpdateFlag{1};
+ constexpr uint16_t componentBitmapBitLength = 16;
+ // Applicable Components - 1,2,5,8,9
+ std::vector<std::bitset<8>> applicableComponentsBitfield{0x93, 0x01};
+ // ComponentImageSetVersionString
+ constexpr std::string_view imageSetVersionStr{"VersionString1"};
+ // Initial descriptor - UUID
+ constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
+ 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
+ 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
+ constexpr uint16_t fwDevicePkgDataLen = 2;
+ // FirmwareDevicePackageData
+ constexpr std::array<uint8_t, fwDevicePkgDataLen> fwDevicePkgData{0xab,
+ 0xcd};
+ // Size of the firmware device ID record
+ constexpr uint16_t recordLen =
+ sizeof(pldm_firmware_device_id_record) +
+ (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
+ imageSetVersionStr.size() + sizeof(pldm_descriptor_tlv) - 1 +
+ uuid.size() + fwDevicePkgData.size();
+ // Firmware device ID record
+ constexpr std::array<uint8_t, recordLen> record{
+ 0x31, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02,
+ 0x00, 0x93, 0x01, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
+ 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x02, 0x00, 0x10,
+ 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0,
+ 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xab, 0xcd};
+
+ pldm_firmware_device_id_record deviceIdRecHeader{};
+ variable_field applicableComponents{};
+ variable_field outCompImageSetVersionStr{};
+ variable_field recordDescriptors{};
+ variable_field outFwDevicePkgData{};
+
+ auto rc = decode_firmware_device_id_record(
+ record.data(), record.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
+ EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
+ EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
+ deviceUpdateFlag);
+ EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
+ PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
+ imageSetVersionStr.size());
+ EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, fwDevicePkgDataLen);
+
+ EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
+ EXPECT_EQ(true,
+ std::equal(applicableComponents.ptr,
+ applicableComponents.ptr + applicableComponents.length,
+ applicableComponentsBitfield.begin(),
+ applicableComponentsBitfield.end()));
+
+ EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
+ std::string compImageSetVersionStr(
+ reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
+ outCompImageSetVersionStr.length);
+ EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
+
+ uint16_t descriptorType = 0;
+ uint16_t descriptorLen = 0;
+ variable_field descriptorData{};
+ // DescriptorCount is 1, so decode_descriptor_type_length_value called once
+ rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
+ recordDescriptors.length,
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
+ sizeof(descriptorLen) +
+ descriptorData.length);
+ EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
+ EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
+ EXPECT_EQ(true, std::equal(descriptorData.ptr,
+ descriptorData.ptr + descriptorData.length,
+ uuid.begin(), uuid.end()));
+
+ EXPECT_EQ(outFwDevicePkgData.length, fwDevicePkgData.size());
+ EXPECT_EQ(true,
+ std::equal(outFwDevicePkgData.ptr,
+ outFwDevicePkgData.ptr + outFwDevicePkgData.length,
+ fwDevicePkgData.begin(), fwDevicePkgData.end()));
+}
+
+TEST(DecodeFirmwareDeviceIdRecord, goodPathNofwDevicePkgData)
+{
+ constexpr uint8_t descriptorCount = 1;
+ // Continue component updates after failure
+ constexpr std::bitset<32> deviceUpdateFlag{1};
+ constexpr uint16_t componentBitmapBitLength = 8;
+ // Applicable Components - 1,2
+ std::vector<std::bitset<8>> applicableComponentsBitfield{0x03};
+ // ComponentImageSetVersionString
+ constexpr std::string_view imageSetVersionStr{"VersionString1"};
+ // Initial descriptor - UUID
+ constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
+ 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
+ 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
+ constexpr uint16_t fwDevicePkgDataLen = 0;
+
+ // Size of the firmware device ID record
+ constexpr uint16_t recordLen =
+ sizeof(pldm_firmware_device_id_record) +
+ (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
+ imageSetVersionStr.size() +
+ sizeof(pldm_descriptor_tlv().descriptor_type) +
+ sizeof(pldm_descriptor_tlv().descriptor_length) + uuid.size() +
+ fwDevicePkgDataLen;
+ // Firmware device ID record
+ constexpr std::array<uint8_t, recordLen> record{
+ 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00, 0x03,
+ 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e,
+ 0x67, 0x31, 0x02, 0x00, 0x10, 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d,
+ 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
+
+ pldm_firmware_device_id_record deviceIdRecHeader{};
+ variable_field applicableComponents{};
+ variable_field outCompImageSetVersionStr{};
+ variable_field recordDescriptors{};
+ variable_field outFwDevicePkgData{};
+
+ auto rc = decode_firmware_device_id_record(
+ record.data(), record.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
+ EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
+ EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
+ deviceUpdateFlag);
+ EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
+ PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
+ imageSetVersionStr.size());
+ EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, 0);
+
+ EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
+ EXPECT_EQ(true,
+ std::equal(applicableComponents.ptr,
+ applicableComponents.ptr + applicableComponents.length,
+ applicableComponentsBitfield.begin(),
+ applicableComponentsBitfield.end()));
+
+ EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
+ std::string compImageSetVersionStr(
+ reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
+ outCompImageSetVersionStr.length);
+ EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
+
+ uint16_t descriptorType = 0;
+ uint16_t descriptorLen = 0;
+ variable_field descriptorData{};
+ // DescriptorCount is 1, so decode_descriptor_type_length_value called once
+ rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
+ recordDescriptors.length,
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
+ sizeof(descriptorLen) +
+ descriptorData.length);
+ EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
+ EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
+ EXPECT_EQ(true, std::equal(descriptorData.ptr,
+ descriptorData.ptr + descriptorData.length,
+ uuid.begin(), uuid.end()));
+
+ EXPECT_EQ(outFwDevicePkgData.ptr, nullptr);
+ EXPECT_EQ(outFwDevicePkgData.length, 0);
+}
+
+TEST(DecodeFirmwareDeviceIdRecord, ErrorPaths)
+{
+ constexpr uint16_t componentBitmapBitLength = 8;
+ // Invalid ComponentImageSetVersionStringType
+ constexpr std::array<uint8_t, 11> invalidRecord1{
+ 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
+
+ int rc = 0;
+ pldm_firmware_device_id_record deviceIdRecHeader{};
+ variable_field applicableComponents{};
+ variable_field outCompImageSetVersionStr{};
+ variable_field recordDescriptors{};
+ variable_field outFwDevicePkgData{};
+
+ rc = decode_firmware_device_id_record(
+ nullptr, invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ nullptr, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, nullptr, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, nullptr, &recordDescriptors,
+ &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ nullptr, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size() - 1,
+ componentBitmapBitLength, &deviceIdRecHeader, &applicableComponents,
+ &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(),
+ componentBitmapBitLength + 1, &deviceIdRecHeader, &applicableComponents,
+ &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_firmware_device_id_record(
+ invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid ComponentImageSetVersionStringLength
+ constexpr std::array<uint8_t, 11> invalidRecord2{
+ 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
+ rc = decode_firmware_device_id_record(
+ invalidRecord2.data(), invalidRecord2.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // invalidRecord3 size is less than RecordLength
+ constexpr std::array<uint8_t, 11> invalidRecord3{
+ 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00};
+ rc = decode_firmware_device_id_record(
+ invalidRecord3.data(), invalidRecord3.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // RecordLength is less than the calculated RecordLength
+ constexpr std::array<uint8_t, 11> invalidRecord4{
+ 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02, 0x00};
+ rc = decode_firmware_device_id_record(
+ invalidRecord4.data(), invalidRecord4.size(), componentBitmapBitLength,
+ &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
+ &recordDescriptors, &outFwDevicePkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(DecodeDescriptors, goodPath3Descriptors)
+{
+ // In the descriptor data there are 3 descriptor entries
+ // 1) IANA enterprise ID
+ constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
+ 0x0a, 0x0b, 0x0c, 0xd};
+ // 2) UUID
+ constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
+ 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
+ 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
+ // 3) Vendor Defined
+ constexpr std::string_view vendorTitle{"OpenBMC"};
+ constexpr size_t vendorDescriptorLen = 2;
+ constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
+ 0x01, 0x02};
+
+ constexpr size_t vendorDefinedDescriptorLen =
+ sizeof(pldm_vendor_defined_descriptor_title_data()
+ .vendor_defined_descriptor_title_str_type) +
+ sizeof(pldm_vendor_defined_descriptor_title_data()
+ .vendor_defined_descriptor_title_str_len) +
+ vendorTitle.size() + vendorDescriptorData.size();
+
+ constexpr size_t descriptorsLength =
+ 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
+ sizeof(pldm_descriptor_tlv().descriptor_length)) +
+ iana.size() + uuid.size() + vendorDefinedDescriptorLen;
+
+ constexpr std::array<uint8_t, descriptorsLength> descriptors{
+ 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
+ 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
+ 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
+ 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
+
+ size_t descriptorCount = 1;
+ size_t descriptorsRemainingLength = descriptorsLength;
+ int rc = 0;
+
+ while (descriptorsRemainingLength && (descriptorCount <= 3))
+ {
+ uint16_t descriptorType = 0;
+ uint16_t descriptorLen = 0;
+ variable_field descriptorData{};
+
+ rc = decode_descriptor_type_length_value(
+ descriptors.data() + descriptorsLength - descriptorsRemainingLength,
+ descriptorsRemainingLength, &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ if (descriptorCount == 1)
+ {
+ EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
+ EXPECT_EQ(descriptorData.length,
+ PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
+ EXPECT_EQ(true,
+ std::equal(descriptorData.ptr,
+ descriptorData.ptr + descriptorData.length,
+ iana.begin(), iana.end()));
+ }
+ else if (descriptorCount == 2)
+ {
+ EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
+ EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
+ EXPECT_EQ(true,
+ std::equal(descriptorData.ptr,
+ descriptorData.ptr + descriptorData.length,
+ uuid.begin(), uuid.end()));
+ }
+ else if (descriptorCount == 3)
+ {
+ EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
+ EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
+
+ uint8_t descriptorTitleStrType = 0;
+ variable_field descriptorTitleStr{};
+ variable_field vendorDefinedDescriptorData{};
+
+ rc = decode_vendor_defined_descriptor_value(
+ descriptorData.ptr, descriptorData.length,
+ &descriptorTitleStrType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
+ std::string vendorTitleStr(
+ reinterpret_cast<const char*>(descriptorTitleStr.ptr),
+ descriptorTitleStr.length);
+ EXPECT_EQ(vendorTitleStr, vendorTitle);
+
+ EXPECT_EQ(vendorDefinedDescriptorData.length,
+ vendorDescriptorData.size());
+ EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
+ vendorDefinedDescriptorData.ptr +
+ vendorDefinedDescriptorData.length,
+ vendorDescriptorData.begin(),
+ vendorDescriptorData.end()));
+ }
+
+ descriptorsRemainingLength -= sizeof(descriptorType) +
+ sizeof(descriptorLen) +
+ descriptorData.length;
+ descriptorCount++;
+ }
+}
+
+TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
+{
+ int rc = 0;
+ // IANA Enterprise ID descriptor length incorrect
+ constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
+ 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
+ uint16_t descriptorType = 0;
+ variable_field descriptorData{};
+
+ rc = decode_descriptor_type_length_value(nullptr,
+ invalidIANADescriptor1.size(),
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
+ invalidIANADescriptor1.size(),
+ nullptr, &descriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
+ invalidIANADescriptor1.size(),
+ &descriptorType, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_descriptor_type_length_value(
+ invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
+ invalidIANADescriptor1.size(),
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // IANA Enterprise ID descriptor data less than length
+ std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
+ 0x0a, 0x0b, 0x0c};
+ rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
+ invalidIANADescriptor2.size(),
+ &descriptorType, &descriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
+{
+ int rc = 0;
+ // VendorDefinedDescriptorTitleStringType is invalid
+ constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
+ 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
+ uint8_t descriptorStringType = 0;
+ variable_field descriptorTitleStr{};
+ variable_field vendorDefinedDescriptorData{};
+
+ rc = decode_vendor_defined_descriptor_value(
+ nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
+ &descriptorTitleStr, &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
+ &descriptorStringType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
+ nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
+ &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
+ &descriptorStringType, &descriptorTitleStr, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(),
+ sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
+ &descriptorStringType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
+ &descriptorStringType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // VendorDefinedDescriptorTitleStringLength is 0
+ std::array<uint8_t, 9> invalidVendorDescriptor2{
+ 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
+ &descriptorStringType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // VendorDefinedDescriptorData not present in the data
+ std::array<uint8_t, 9> invalidVendorDescriptor3{
+ 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
+ rc = decode_vendor_defined_descriptor_value(
+ invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
+ &descriptorStringType, &descriptorTitleStr,
+ &vendorDefinedDescriptorData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(DecodeComponentImageInfo, goodPath)
+{
+ // Firmware
+ constexpr uint16_t compClassification = 16;
+ constexpr uint16_t compIdentifier = 300;
+ constexpr uint32_t compComparisonStamp = 0xFFFFFFFF;
+ // Force update
+ constexpr std::bitset<16> compOptions{1};
+ // System reboot[Bit position 3] & Medium-specific reset[Bit position 2]
+ constexpr std::bitset<16> reqCompActivationMethod{0x0c};
+ // Random ComponentLocationOffset
+ constexpr uint32_t compLocOffset = 357;
+ // Random ComponentSize
+ constexpr uint32_t compSize = 27;
+ // ComponentVersionString
+ constexpr std::string_view compVersionStr{"VersionString1"};
+ constexpr size_t compImageInfoSize =
+ sizeof(pldm_component_image_information) + compVersionStr.size();
+
+ constexpr std::array<uint8_t, compImageInfoSize> compImageInfo{
+ 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
+ 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+ pldm_component_image_information outCompImageInfo{};
+ variable_field outCompVersionStr{};
+
+ auto rc =
+ decode_pldm_comp_image_info(compImageInfo.data(), compImageInfo.size(),
+ &outCompImageInfo, &outCompVersionStr);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outCompImageInfo.comp_classification, compClassification);
+ EXPECT_EQ(outCompImageInfo.comp_identifier, compIdentifier);
+ EXPECT_EQ(outCompImageInfo.comp_comparison_stamp, compComparisonStamp);
+ EXPECT_EQ(outCompImageInfo.comp_options.value, compOptions);
+ EXPECT_EQ(outCompImageInfo.requested_comp_activation_method.value,
+ reqCompActivationMethod);
+ EXPECT_EQ(outCompImageInfo.comp_location_offset, compLocOffset);
+ EXPECT_EQ(outCompImageInfo.comp_size, compSize);
+ EXPECT_EQ(outCompImageInfo.comp_version_string_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outCompImageInfo.comp_version_string_length,
+ compVersionStr.size());
+
+ EXPECT_EQ(outCompVersionStr.length,
+ outCompImageInfo.comp_version_string_length);
+ std::string componentVersionString(
+ reinterpret_cast<const char*>(outCompVersionStr.ptr),
+ outCompVersionStr.length);
+ EXPECT_EQ(componentVersionString, compVersionStr);
+}
+
+TEST(DecodeComponentImageInfo, errorPaths)
+{
+ int rc = 0;
+ // ComponentVersionString
+ constexpr std::string_view compVersionStr{"VersionString1"};
+ constexpr size_t compImageInfoSize =
+ sizeof(pldm_component_image_information) + compVersionStr.size();
+ // Invalid ComponentVersionStringType - 0x06
+ constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo1{
+ 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
+ 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+ pldm_component_image_information outCompImageInfo{};
+ variable_field outCompVersionStr{};
+
+ rc = decode_pldm_comp_image_info(nullptr, invalidCompImageInfo1.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
+ invalidCompImageInfo1.size(), nullptr,
+ &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
+ invalidCompImageInfo1.size(),
+ &outCompImageInfo, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
+ sizeof(pldm_component_image_information) -
+ 1,
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
+ invalidCompImageInfo1.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid ComponentVersionStringLength - 0x00
+ constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo2{
+ 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
+ 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo2.data(),
+ invalidCompImageInfo2.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Use Component Comparison Stamp is not set, but ComponentComparisonStamp
+ // is not 0xFFFFFFFF
+ constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo3{
+ 0x10, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00,
+ 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
+ invalidCompImageInfo3.size() - 1,
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
+ invalidCompImageInfo3.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid ComponentLocationOffset - 0
+ constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo4{
+ 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo4.data(),
+ invalidCompImageInfo4.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid ComponentSize - 0
+ constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo5{
+ 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
+ 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
+ 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
+ rc = decode_pldm_comp_image_info(invalidCompImageInfo5.data(),
+ invalidCompImageInfo5.size(),
+ &outCompImageInfo, &outCompVersionStr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ uint8_t instanceId = 0x01;
+
+ auto rc = encode_query_device_identifiers_req(
+ instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
+ EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
+ EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
+ EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
+}
+
+TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
+{
+ // descriptorDataLen is not fixed here taking it as 6
+ constexpr uint8_t descriptorDataLen = 6;
+ std::array<uint8_t, hdrSize +
+ sizeof(struct pldm_query_device_identifiers_resp) +
+ descriptorDataLen>
+ responseMsg{};
+ auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
+ responseMsg.data() + hdrSize);
+
+ inResp->completion_code = PLDM_SUCCESS;
+ inResp->device_identifiers_len = htole32(descriptorDataLen);
+ inResp->descriptor_count = 1;
+
+ // filling descriptor data
+ std::fill_n(responseMsg.data() + hdrSize +
+ sizeof(struct pldm_query_device_identifiers_resp),
+ descriptorDataLen, 0xFF);
+
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint32_t deviceIdentifiersLen = 0;
+ uint8_t descriptorCount = 0;
+ uint8_t* outDescriptorData = nullptr;
+
+ auto rc = decode_query_device_identifiers_resp(
+ response, responseMsg.size() - hdrSize, &completionCode,
+ &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
+ EXPECT_EQ(descriptorCount, inResp->descriptor_count);
+ EXPECT_EQ(true,
+ std::equal(outDescriptorData,
+ outDescriptorData + deviceIdentifiersLen,
+ responseMsg.begin() + hdrSize +
+ sizeof(struct pldm_query_device_identifiers_resp),
+ responseMsg.end()));
+}
+
+TEST(GetFirmwareParameters, goodPathEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ uint8_t instanceId = 0x01;
+
+ auto rc = encode_get_firmware_parameters_req(
+ instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
+ EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
+ EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
+ EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
+}
+
+TEST(GetFirmwareParameters, decodeResponse)
+{
+ // CapabilitiesDuringUpdate of the firmware device
+ // Firmware device downgrade restrictions [Bit position 8] &
+ // Firmware Device Partial Updates [Bit position 3]
+ constexpr std::bitset<32> fdCapabilities{0x00000104};
+ constexpr uint16_t compCount = 1;
+ constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
+ constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
+
+ // constexpr uint16_t compClassification = 16;
+ // constexpr uint16_t compIdentifier = 300;
+ // constexpr uint8_t compClassificationIndex = 20;
+ // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
+ // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
+ // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
+ // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
+ // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
+ constexpr std::string_view activeCompVersion{"VersionString3"};
+ constexpr std::string_view pendingCompVersion{"VersionString4"};
+ // ComponentActivationMethods
+ // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
+ constexpr std::bitset<16> compActivationMethod{0x12};
+ // CapabilitiesDuringUpdate of the firmware component
+ // Component downgrade capability [Bit position 2]
+ constexpr std::bitset<32> compCapabilities{0x02};
+
+ constexpr size_t compParamTableSize =
+ sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
+ pendingCompVersion.size();
+
+ constexpr std::array<uint8_t, compParamTableSize> compParamTable{
+ 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
+ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
+ 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
+ 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
+ 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
+
+ constexpr size_t getFwParamsPayloadLen =
+ sizeof(pldm_get_firmware_parameters_resp) +
+ activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
+ compParamTableSize;
+
+ constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
+ getFwParamsResponse{
+ 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
+ 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
+ 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
+ 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
+ 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
+ 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
+ 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
+ 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
+ pldm_get_firmware_parameters_resp outResp{};
+ variable_field outActiveCompImageSetVersion{};
+ variable_field outPendingCompImageSetVersion{};
+ variable_field outCompParameterTable{};
+
+ auto rc = decode_get_firmware_parameters_resp(
+ responseMsg, getFwParamsPayloadLen, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
+ EXPECT_EQ(outResp.comp_count, compCount);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
+ activeCompImageSetVersion.size());
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
+ pendingCompImageSetVersion.size());
+ std::string activeCompImageSetVersionStr(
+ reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
+ outActiveCompImageSetVersion.length);
+ EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
+ std::string pendingCompImageSetVersionStr(
+ reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
+ outPendingCompImageSetVersion.length);
+ EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
+ EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
+ EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
+ outCompParameterTable.ptr +
+ outCompParameterTable.length,
+ compParamTable.begin(), compParamTable.end()));
+}
+
+TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
+{
+ // CapabilitiesDuringUpdate of the firmware device
+ // FD Host Functionality during Firmware Update [Bit position 2] &
+ // Component Update Failure Retry Capability [Bit position 1]
+ constexpr std::bitset<32> fdCapabilities{0x06};
+ constexpr uint16_t compCount = 0;
+ constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
+ constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
+
+ constexpr size_t getFwParamsPayloadLen =
+ sizeof(pldm_get_firmware_parameters_resp) +
+ activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
+
+ constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
+ getFwParamsResponse{
+ 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
+ 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
+ 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
+ pldm_get_firmware_parameters_resp outResp{};
+ variable_field outActiveCompImageSetVersion{};
+ variable_field outPendingCompImageSetVersion{};
+ variable_field outCompParameterTable{};
+
+ auto rc = decode_get_firmware_parameters_resp(
+ responseMsg, getFwParamsPayloadLen, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
+ EXPECT_EQ(outResp.comp_count, compCount);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
+ activeCompImageSetVersion.size());
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
+ pendingCompImageSetVersion.size());
+ std::string activeCompImageSetVersionStr(
+ reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
+ outActiveCompImageSetVersion.length);
+ EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
+ std::string pendingCompImageSetVersionStr(
+ reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
+ outPendingCompImageSetVersion.length);
+ EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
+ EXPECT_EQ(outCompParameterTable.ptr, nullptr);
+ EXPECT_EQ(outCompParameterTable.length, 0);
+}
+
+TEST(GetFirmwareParameters,
+ decodeResponseNoPendingCompImageVersionStrZeroCompCount)
+{
+ // CapabilitiesDuringUpdate of the firmware device
+ // FD Host Functionality during Firmware Update [Bit position 2] &
+ // Component Update Failure Retry Capability [Bit position 1]
+ constexpr std::bitset<32> fdCapabilities{0x06};
+ constexpr uint16_t compCount = 0;
+ constexpr std::string_view activeCompImageSetVersion{"VersionString"};
+
+ constexpr size_t getFwParamsPayloadLen =
+ sizeof(pldm_get_firmware_parameters_resp) +
+ activeCompImageSetVersion.size();
+
+ constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
+ getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
+ 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
+ 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
+ pldm_get_firmware_parameters_resp outResp{};
+ variable_field outActiveCompImageSetVersion{};
+ variable_field outPendingCompImageSetVersion{};
+ variable_field outCompParameterTable{};
+
+ auto rc = decode_get_firmware_parameters_resp(
+ responseMsg, getFwParamsPayloadLen, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
+ EXPECT_EQ(outResp.comp_count, compCount);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
+ EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
+ activeCompImageSetVersion.size());
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
+ PLDM_STR_TYPE_UNKNOWN);
+ EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
+ std::string activeCompImageSetVersionStr(
+ reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
+ outActiveCompImageSetVersion.length);
+ EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
+ EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
+ EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
+ EXPECT_EQ(outCompParameterTable.ptr, nullptr);
+ EXPECT_EQ(outCompParameterTable.length, 0);
+}
+
+TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
+{
+ constexpr std::array<uint8_t, hdrSize + sizeof(uint8_t)>
+ getFwParamsResponse{0x00, 0x00, 0x00, 0x01};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
+ pldm_get_firmware_parameters_resp outResp{};
+ variable_field outActiveCompImageSetVersion{};
+ variable_field outPendingCompImageSetVersion{};
+ variable_field outCompParameterTable{};
+
+ auto rc = decode_get_firmware_parameters_resp(
+ responseMsg, getFwParamsResponse.size(), &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
+}
+
+TEST(GetFirmwareParameters, errorPathdecodeResponse)
+{
+ int rc = 0;
+ // Invalid ActiveComponentImageSetVersionStringType
+ constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
+ pldm_get_firmware_parameters_resp outResp{};
+ variable_field outActiveCompImageSetVersion{};
+ variable_field outPendingCompImageSetVersion{};
+ variable_field outCompParameterTable{};
+
+ rc = decode_get_firmware_parameters_resp(
+ nullptr, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, nullptr,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
+ nullptr, &outPendingCompImageSetVersion, &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
+ &outPendingCompImageSetVersion, &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - 1 - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid ActiveComponentImageSetVersionStringLength
+ constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
+ responseMsg =
+ reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse2.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid PendingComponentImageSetVersionStringType &
+ // PendingComponentImageSetVersionStringLength
+ constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
+ 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
+ responseMsg =
+ reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse3.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Invalid PendingComponentImageSetVersionStringType &
+ // PendingComponentImageSetVersionStringLength
+ constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
+ 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
+ responseMsg =
+ reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse4.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Total payload length less than expected
+ constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
+ 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
+ responseMsg =
+ reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
+ rc = decode_get_firmware_parameters_resp(
+ responseMsg, invalidGetFwParamsResponse5.size() - hdrSize, &outResp,
+ &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
+ &outCompParameterTable);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
+{
+ // Random value for component classification
+ constexpr uint16_t compClassification = 0x0A0B;
+ // Random value for component classification
+ constexpr uint16_t compIdentifier = 0x0C0D;
+ // Random value for component classification
+ constexpr uint32_t timestamp = 0X12345678;
+ // Random value for component activation methods
+ constexpr uint16_t compActivationMethods = 0xBBDD;
+ // Random value for capabilities during update
+ constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
+
+ // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t activeCompVerStrLen = 8;
+ // PendingCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t pendingCompVerStrLen = 8;
+ constexpr size_t entryLength =
+ sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
+ pendingCompVerStrLen;
+ std::array<uint8_t, entryLength> entry{};
+
+ auto inEntry =
+ reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
+
+ inEntry->comp_classification = htole16(compClassification);
+ inEntry->comp_identifier = htole16(compIdentifier);
+ inEntry->comp_classification_index = 0x0F;
+ inEntry->active_comp_comparison_stamp = htole32(timestamp);
+ inEntry->active_comp_ver_str_type = 1;
+ inEntry->active_comp_ver_str_len = activeCompVerStrLen;
+ std::fill_n(inEntry->active_comp_release_date,
+ sizeof(inEntry->active_comp_release_date), 0xFF);
+ inEntry->pending_comp_comparison_stamp = htole32(timestamp);
+ inEntry->pending_comp_ver_str_type = 1;
+ inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
+ std::fill_n(inEntry->pending_comp_release_date,
+ sizeof(inEntry->pending_comp_release_date), 0xFF);
+ inEntry->comp_activation_methods.value = htole16(compActivationMethods);
+ inEntry->capabilities_during_update.value =
+ htole32(capabilitiesDuringUpdate);
+ constexpr auto activeCompVerStrPos =
+ sizeof(struct pldm_component_parameter_entry);
+ std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
+ constexpr auto pendingCompVerStrPos =
+ activeCompVerStrPos + activeCompVerStrLen;
+ std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
+ 0xBB);
+
+ struct pldm_component_parameter_entry outEntry;
+ struct variable_field outActiveCompVerStr;
+ struct variable_field outPendingCompVerStr;
+
+ auto rc = decode_get_firmware_parameters_resp_comp_entry(
+ entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
+ &outPendingCompVerStr);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ EXPECT_EQ(outEntry.comp_classification, compClassification);
+ EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
+ EXPECT_EQ(inEntry->comp_classification_index,
+ outEntry.comp_classification_index);
+ EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
+ EXPECT_EQ(inEntry->active_comp_ver_str_type,
+ outEntry.active_comp_ver_str_type);
+ EXPECT_EQ(inEntry->active_comp_ver_str_len,
+ outEntry.active_comp_ver_str_len);
+ EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
+ outEntry.active_comp_release_date,
+ sizeof(inEntry->active_comp_release_date)));
+ EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
+ EXPECT_EQ(inEntry->pending_comp_ver_str_type,
+ outEntry.pending_comp_ver_str_type);
+ EXPECT_EQ(inEntry->pending_comp_ver_str_len,
+ outEntry.pending_comp_ver_str_len);
+ EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
+ outEntry.pending_comp_release_date,
+ sizeof(inEntry->pending_comp_release_date)));
+ EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
+ EXPECT_EQ(outEntry.capabilities_during_update.value,
+ capabilitiesDuringUpdate);
+
+ EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
+ entry.data() + activeCompVerStrPos,
+ outActiveCompVerStr.length));
+ EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
+ entry.data() + pendingCompVerStrPos,
+ outPendingCompVerStr.length));
+}
+
+TEST(RequestUpdate, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 1;
+ constexpr uint32_t maxTransferSize = 512;
+ constexpr uint16_t numOfComp = 3;
+ constexpr uint8_t maxOutstandingTransferReq = 2;
+ constexpr uint16_t pkgDataLen = 0x1234;
+ constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
+ constexpr uint8_t compImgSetVerStrLen =
+ static_cast<uint8_t>(compImgSetVerStr.size());
+ variable_field compImgSetVerStrInfo{};
+ compImgSetVerStrInfo.ptr =
+ reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
+ compImgSetVerStrInfo.length = compImgSetVerStrLen;
+
+ std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
+ compImgSetVerStrLen>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, requestMsg,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
+ compImgSetVerStrLen>
+ outRequest{0x81, 0x05, 0x10, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00,
+ 0x02, 0x34, 0x12, 0x01, 0x0b, 0x30, 0x70, 0x65, 0x6e,
+ 0x42, 0x6d, 0x63, 0x76, 0x31, 0x2e, 0x30};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(RequestUpdate, errorPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 1;
+ uint32_t maxTransferSize = 512;
+ constexpr uint16_t numOfComp = 3;
+ uint8_t maxOutstandingTransferReq = 2;
+ constexpr uint16_t pkgDataLen = 0x1234;
+ constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
+ uint8_t compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
+ variable_field compImgSetVerStrInfo{};
+ compImgSetVerStrInfo.ptr =
+ reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
+ compImgSetVerStrInfo.length = compImgSetVerStrLen;
+
+ std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
+ compImgSetVerStr.size()>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen, nullptr,
+ requestMsg,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ compImgSetVerStrInfo.ptr = nullptr;
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, requestMsg,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ compImgSetVerStrInfo.ptr =
+ reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
+
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_request_update_req(instanceId, maxTransferSize, numOfComp,
+ maxOutstandingTransferReq, pkgDataLen,
+ PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, requestMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ compImgSetVerStrLen = 0;
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, 0, &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
+
+ compImgSetVerStrInfo.length = 0xFFFF;
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ compImgSetVerStrInfo.length = compImgSetVerStrLen;
+
+ maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE - 1;
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE;
+
+ maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ - 1;
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ;
+
+ rc = encode_request_update_req(
+ instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
+ pkgDataLen, PLDM_STR_TYPE_UNKNOWN, compImgSetVerStrLen,
+ &compImgSetVerStrInfo, nullptr,
+ sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(RequestUpdate, goodPathDecodeResponse)
+{
+ constexpr uint16_t fdMetaDataLen = 1024;
+ constexpr uint8_t fdWillSendPkgData = 1;
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_request_update_resp)>
+ requestUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01};
+
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(requestUpdateResponse1.data());
+ uint8_t outCompletionCode = 0;
+ uint16_t outFdMetaDataLen = 0;
+ uint8_t outFdWillSendPkgData = 0;
+
+ auto rc = decode_request_update_resp(
+ responseMsg1, requestUpdateResponse1.size() - hdrSize,
+ &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outCompletionCode, PLDM_SUCCESS);
+ EXPECT_EQ(outFdMetaDataLen, fdMetaDataLen);
+ EXPECT_EQ(outFdWillSendPkgData, fdWillSendPkgData);
+
+ outCompletionCode = 0;
+ outFdMetaDataLen = 0;
+ outFdWillSendPkgData = 0;
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(outCompletionCode)>
+ requestUpdateResponse2{0x00, 0x00, 0x00, 0x81};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(requestUpdateResponse2.data());
+ rc = decode_request_update_resp(
+ responseMsg2, requestUpdateResponse2.size() - hdrSize,
+ &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outCompletionCode, PLDM_FWUP_ALREADY_IN_UPDATE_MODE);
+}
+
+TEST(RequestUpdate, errorPathDecodeResponse)
+{
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_request_update_resp) - 1>
+ requestUpdateResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
+
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(requestUpdateResponse.data());
+ uint8_t outCompletionCode = 0;
+ uint16_t outFdMetaDataLen = 0;
+ uint8_t outFdWillSendPkgData = 0;
+
+ auto rc = decode_request_update_resp(
+ nullptr, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
+ &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_update_resp(
+ responseMsg, requestUpdateResponse.size() - hdrSize, nullptr,
+ &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_update_resp(
+ responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
+ nullptr, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_update_resp(
+ responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
+ &outFdMetaDataLen, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_update_resp(responseMsg, 0, &outCompletionCode,
+ &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_update_resp(
+ responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
+ &outFdMetaDataLen, &outFdWillSendPkgData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(PassComponentTable, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 1;
+ constexpr uint16_t compIdentifier = 400;
+ constexpr uint8_t compClassificationIndex = 40;
+ constexpr uint32_t compComparisonStamp = 0x12345678;
+ constexpr std::string_view compVerStr = "0penBmcv1.1";
+ constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
+ variable_field compVerStrInfo{};
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+ compVerStrInfo.length = compVerStrLen;
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
+ outRequest{0x81, 0x05, 0x13, 0x05, 0x0A, 0x00, 0x90, 0x01, 0x28,
+ 0x78, 0x56, 0x34, 0x12, 0x01, 0x0B, 0x30, 0x70, 0x65,
+ 0x6E, 0x42, 0x6D, 0x63, 0x76, 0x31, 0x2E, 0x31};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(PassComponentTable, errorPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 1;
+ constexpr uint16_t compIdentifier = 400;
+ constexpr uint8_t compClassificationIndex = 40;
+ constexpr uint32_t compComparisonStamp = 0x12345678;
+ constexpr std::string_view compVerStr = "0penBmcv1.1";
+ constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
+ variable_field compVerStrInfo{};
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+ compVerStrInfo.length = compVerStrLen;
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, nullptr, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ compVerStrInfo.ptr = nullptr;
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, nullptr,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req));
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII, 0,
+ &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen - 1, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END + 1, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_INVALID_TRANSFER_OPERATION_FLAG);
+
+ rc = encode_pass_component_table_req(
+ instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
+ compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_UNKNOWN,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_pass_component_table_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(PassComponentTable, goodPathDecodeResponse)
+{
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint8_t compResp = 0;
+ uint8_t compRespCode = 0;
+
+ auto rc = decode_pass_component_table_resp(
+ responseMsg1, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
+ EXPECT_EQ(compRespCode, PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL);
+
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0xD0};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
+ rc = decode_pass_component_table_resp(
+ responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
+ EXPECT_EQ(compRespCode, PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN);
+
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse3{0x00, 0x00, 0x00, 0x80};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
+
+ rc = decode_pass_component_table_resp(
+ responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
+}
+
+TEST(PassComponentTable, errorPathDecodeResponse)
+{
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp) - 1>
+ passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint8_t compResp = 0;
+ uint8_t compRespCode = 0;
+
+ auto rc = decode_pass_component_table_resp(
+ nullptr, sizeof(pldm_pass_component_table_resp) - 1, &completionCode,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pass_component_table_resp(
+ responseMsg1, sizeof(pldm_pass_component_table_resp) - 1, nullptr,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pass_component_table_resp(
+ responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
+ &completionCode, nullptr, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pass_component_table_resp(
+ responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
+ &completionCode, &compResp, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pass_component_table_resp(responseMsg1, 0, &completionCode,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_pass_component_table_resp(
+ responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
+ &completionCode, &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
+ rc = decode_pass_component_table_resp(
+ responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
+ rc = decode_pass_component_table_resp(
+ responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_pass_component_table_resp)>
+ passCompTableResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0};
+ auto responseMsg4 =
+ reinterpret_cast<const pldm_msg*>(passCompTableResponse4.data());
+ rc = decode_pass_component_table_resp(
+ responseMsg4, sizeof(pldm_pass_component_table_resp), &completionCode,
+ &compResp, &compRespCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(UpdateComponent, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 2;
+ constexpr uint16_t compIdentifier = 500;
+ constexpr uint8_t compClassificationIndex = 50;
+ constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
+ constexpr uint32_t compImageSize = 4096;
+ constexpr bitfield32_t updateOptionFlags{1};
+ constexpr std::string_view compVerStr = "OpenBmcv2.2";
+ constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
+ variable_field compVerStrInfo{};
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+ compVerStrInfo.length = compVerStrLen;
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
+ outRequest{0x82, 0x05, 0x14, 0x0A, 0x00, 0xF4, 0x01, 0x32, 0xEF,
+ 0xCD, 0xAB, 0x89, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00,
+ 0x00, 0x00, 0x01, 0x0B, 0x4f, 0x70, 0x65, 0x6E, 0x42,
+ 0x6D, 0x63, 0x76, 0x32, 0x2E, 0x32};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(UpdateComponent, errorPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 2;
+ constexpr uint16_t compIdentifier = 500;
+ constexpr uint8_t compClassificationIndex = 50;
+ constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
+ constexpr uint32_t compImageSize = 4096;
+ constexpr bitfield32_t updateOptionFlags{1};
+ constexpr std::string_view compVerStr = "OpenBmcv2.2";
+ constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
+ variable_field compVerStrInfo{};
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+ compVerStrInfo.length = compVerStrLen;
+
+ std::array<uint8_t,
+ hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
+ request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen, nullptr, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ compVerStrInfo.ptr = nullptr;
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, nullptr,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req));
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, 0, updateOptionFlags, PLDM_STR_TYPE_ASCII,
+ compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, 0, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_ASCII, compVerStrLen - 1, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_update_component_req(
+ instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
+ compComparisonStamp, compImageSize, updateOptionFlags,
+ PLDM_STR_TYPE_UNKNOWN, compVerStrLen, &compVerStrInfo, requestMsg,
+ sizeof(pldm_update_component_req) + compVerStrLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(UpdateComponent, goodPathDecodeResponse)
+{
+ constexpr std::bitset<32> forceUpdateComp{1};
+ constexpr uint16_t timeBeforeSendingReqFwData100s = 100;
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint8_t compCompatibilityResp = 0;
+ uint8_t compCompatibilityRespCode = 0;
+ bitfield32_t updateOptionFlagsEnabled{};
+ uint16_t timeBeforeReqFWData = 0;
+
+ auto rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CAN_BE_UPDATED);
+ EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_NO_RESPONSE_CODE);
+ EXPECT_EQ(updateOptionFlagsEnabled.value, forceUpdateComp);
+ EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData100s);
+
+ constexpr std::bitset<32> noFlags{};
+ constexpr uint16_t timeBeforeSendingReqFwData0s = 0;
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
+ rc = decode_update_component_resp(
+ responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CANNOT_BE_UPDATED);
+ EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_COMP_INFO_NO_MATCH);
+ EXPECT_EQ(updateOptionFlagsEnabled.value, noFlags);
+ EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData0s);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse3{0x00, 0x00, 0x00, 0x80};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
+
+ rc = decode_update_component_resp(
+ responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
+}
+
+TEST(UpdateComponent, errorPathDecodeResponse)
+{
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_update_component_resp) - 1>
+ updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
+ 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint8_t compCompatibilityResp = 0;
+ uint8_t compCompatibilityRespCode = 0;
+ bitfield32_t updateOptionFlagsEnabled{};
+ uint16_t timeBeforeReqFWData = 0;
+
+ auto rc = decode_update_component_resp(
+ nullptr, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, nullptr,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ nullptr, &compCompatibilityRespCode, &updateOptionFlagsEnabled,
+ &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ &compCompatibilityResp, nullptr, &updateOptionFlagsEnabled,
+ &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode, nullptr,
+ &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, 0, &completionCode, &compCompatibilityResp,
+ &compCompatibilityRespCode, &updateOptionFlagsEnabled,
+ &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_update_component_resp(
+ responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
+ rc = decode_update_component_resp(
+ responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
+ 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
+ rc = decode_update_component_resp(
+ responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
+ updateComponentResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
+ 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
+ auto responseMsg4 =
+ reinterpret_cast<const pldm_msg*>(updateComponentResponse4.data());
+ rc = decode_update_component_resp(
+ responseMsg4, sizeof(pldm_update_component_resp), &completionCode,
+ &compCompatibilityResp, &compCompatibilityRespCode,
+ &updateOptionFlagsEnabled, &timeBeforeReqFWData);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(RequestFirmwareData, goodPathDecodeRequest)
+{
+ constexpr uint32_t offset = 300;
+ constexpr uint32_t length = 255;
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_request_firmware_data_req)>
+ reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
+ 0x00, 0xFF, 0x00, 0x00, 0x00};
+ auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
+
+ uint32_t outOffset = 0;
+ uint32_t outLength = 0;
+ auto rc = decode_request_firmware_data_req(
+ requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
+ &outLength);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outOffset, offset);
+ EXPECT_EQ(outLength, length);
+}
+
+TEST(RequestFirmwareData, errorPathDecodeRequest)
+{
+ constexpr std::array<uint8_t,
+ hdrSize + sizeof(pldm_request_firmware_data_req)>
+ reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
+ 0x00, 0x1F, 0x00, 0x00, 0x00};
+ auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
+
+ uint32_t outOffset = 0;
+ uint32_t outLength = 0;
+ auto rc = decode_request_firmware_data_req(
+ nullptr, sizeof(pldm_request_firmware_data_req), &outOffset,
+ &outLength);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_firmware_data_req(
+ requestMsg, sizeof(pldm_request_firmware_data_req), nullptr,
+ &outLength);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_firmware_data_req(
+ requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
+ nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_request_firmware_data_req(
+ requestMsg, sizeof(pldm_request_firmware_data_req) - 1, &outOffset,
+ &outLength);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = decode_request_firmware_data_req(
+ requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
+ &outLength);
+ EXPECT_EQ(rc, PLDM_FWUP_INVALID_TRANSFER_LENGTH);
+}
+
+TEST(RequestFirmwareData, goodPathEncodeResponse)
+{
+ constexpr uint8_t instanceId = 3;
+ constexpr uint8_t completionCode = PLDM_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode) +
+ PLDM_FWUP_BASELINE_TRANSFER_SIZE>
+ outReqFwDataResponse1{0x03, 0x05, 0x15, 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
+ 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
+ 0x1D, 0x1E, 0x1F, 0x20};
+ std::array<uint8_t, hdrSize + sizeof(completionCode) +
+ PLDM_FWUP_BASELINE_TRANSFER_SIZE>
+ reqFwDataResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
+ 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
+ 0x1D, 0x1E, 0x1F, 0x20};
+ auto responseMsg1 = reinterpret_cast<pldm_msg*>(reqFwDataResponse1.data());
+ auto rc = encode_request_firmware_data_resp(
+ instanceId, completionCode, responseMsg1,
+ sizeof(completionCode) + PLDM_FWUP_BASELINE_TRANSFER_SIZE);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(reqFwDataResponse1, outReqFwDataResponse1);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outReqFwDataResponse2{0x03, 0x05, 0x15, 0x82};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)> reqFwDataResponse2{
+ 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 = reinterpret_cast<pldm_msg*>(reqFwDataResponse2.data());
+ rc = encode_request_firmware_data_resp(
+ instanceId, PLDM_FWUP_DATA_OUT_OF_RANGE, responseMsg2,
+ sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(reqFwDataResponse2, outReqFwDataResponse2);
+}
+
+TEST(RequestFirmwareData, errorPathEncodeResponse)
+{
+ std::array<uint8_t, hdrSize> reqFwDataResponse{0x00, 0x00, 0x00};
+ auto responseMsg = reinterpret_cast<pldm_msg*>(reqFwDataResponse.data());
+ auto rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, nullptr, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, responseMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(TransferComplete, goodPathDecodeRequest)
+{
+ constexpr uint8_t transferResult = PLDM_FWUP_TRANSFER_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
+ transferCompleteReq1{0x00, 0x00, 0x00, 0x00};
+ auto requestMsg1 =
+ reinterpret_cast<const pldm_msg*>(transferCompleteReq1.data());
+ uint8_t outTransferResult = 0;
+
+ auto rc = decode_transfer_complete_req(requestMsg1, sizeof(transferResult),
+ &outTransferResult);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outTransferResult, transferResult);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
+ transferCompleteReq2{0x00, 0x00, 0x00, 0x02};
+ auto requestMsg2 =
+ reinterpret_cast<const pldm_msg*>(transferCompleteReq2.data());
+ rc = decode_transfer_complete_req(requestMsg2, sizeof(transferResult),
+ &outTransferResult);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outTransferResult, PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT);
+}
+
+TEST(TransferComplete, errorPathDecodeRequest)
+{
+ constexpr std::array<uint8_t, hdrSize> transferCompleteReq{0x00, 0x00,
+ 0x00};
+ auto requestMsg =
+ reinterpret_cast<const pldm_msg*>(transferCompleteReq.data());
+ uint8_t outTransferResult = 0;
+
+ auto rc = decode_transfer_complete_req(nullptr, 0, &outTransferResult);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_transfer_complete_req(requestMsg, 0, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_transfer_complete_req(requestMsg, 0, &outTransferResult);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(TransferComplete, goodPathEncodeResponse)
+{
+ constexpr uint8_t instanceId = 4;
+ constexpr uint8_t completionCode = PLDM_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outTransferCompleteResponse1{0x04, 0x05, 0x16, 0x00};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ transferCompleteResponse1{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<pldm_msg*>(transferCompleteResponse1.data());
+ auto rc = encode_transfer_complete_resp(
+ instanceId, completionCode, responseMsg1, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(transferCompleteResponse1, outTransferCompleteResponse1);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outTransferCompleteResponse2{0x04, 0x05, 0x16, 0x87};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ transferCompleteResponse2{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<pldm_msg*>(transferCompleteResponse2.data());
+ rc = encode_transfer_complete_resp(instanceId,
+ PLDM_FWUP_COMMAND_NOT_EXPECTED,
+ responseMsg2, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(transferCompleteResponse2, outTransferCompleteResponse2);
+}
+
+TEST(TransferComplete, errorPathEncodeResponse)
+{
+ std::array<uint8_t, hdrSize> transferCompleteResponse{0x00, 0x00, 0x00};
+ auto responseMsg =
+ reinterpret_cast<pldm_msg*>(transferCompleteResponse.data());
+ auto rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(VerifyComplete, goodPathDecodeRequest)
+{
+ constexpr uint8_t verifyResult = PLDM_FWUP_VERIFY_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
+ verifyCompleteReq1{0x00, 0x00, 0x00, 0x00};
+ auto requestMsg1 =
+ reinterpret_cast<const pldm_msg*>(verifyCompleteReq1.data());
+ uint8_t outVerifyResult = 0;
+
+ auto rc = decode_verify_complete_req(requestMsg1, sizeof(verifyResult),
+ &outVerifyResult);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outVerifyResult, verifyResult);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
+ verifyCompleteReq2{0x00, 0x00, 0x00, 0x03};
+ auto requestMsg2 =
+ reinterpret_cast<const pldm_msg*>(verifyCompleteReq2.data());
+ rc = decode_verify_complete_req(requestMsg2, sizeof(verifyResult),
+ &outVerifyResult);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outVerifyResult, PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS);
+}
+
+TEST(VerifyComplete, errorPathDecodeRequest)
+{
+ constexpr std::array<uint8_t, hdrSize> verifyCompleteReq{0x00, 0x00, 0x00};
+ auto requestMsg =
+ reinterpret_cast<const pldm_msg*>(verifyCompleteReq.data());
+ uint8_t outVerifyResult = 0;
+
+ auto rc = decode_verify_complete_req(nullptr, 0, &outVerifyResult);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_verify_complete_req(requestMsg, 0, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_verify_complete_req(requestMsg, 0, &outVerifyResult);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(VerifyComplete, goodPathEncodeResponse)
+{
+ constexpr uint8_t instanceId = 5;
+ constexpr uint8_t completionCode = PLDM_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outVerifyCompleteResponse1{0x05, 0x05, 0x17, 0x00};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ verifyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<pldm_msg*>(verifyCompleteResponse1.data());
+ auto rc = encode_verify_complete_resp(instanceId, completionCode,
+ responseMsg1, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(verifyCompleteResponse1, outVerifyCompleteResponse1);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outVerifyCompleteResponse2{0x05, 0x05, 0x17, 0x87};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ verifyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<pldm_msg*>(verifyCompleteResponse2.data());
+ rc = encode_verify_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
+ responseMsg2, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(verifyCompleteResponse2, outVerifyCompleteResponse2);
+}
+
+TEST(VerifyComplete, errorPathEncodeResponse)
+{
+ std::array<uint8_t, hdrSize> verifyCompleteResponse{0x00, 0x00, 0x00};
+ auto responseMsg =
+ reinterpret_cast<pldm_msg*>(verifyCompleteResponse.data());
+ auto rc = encode_verify_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_verify_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ApplyComplete, goodPathDecodeRequest)
+{
+ constexpr uint8_t applyResult1 =
+ PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD;
+ // DC power cycle [Bit position 4] & AC power cycle [Bit position 5]
+ constexpr std::bitset<16> compActivationModification1{0x30};
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
+ applyCompleteReq1{0x00, 0x00, 0x00, 0x01, 0x30, 0x00};
+ auto requestMsg1 =
+ reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
+ uint8_t outApplyResult = 0;
+ bitfield16_t outCompActivationModification{};
+ auto rc = decode_apply_complete_req(
+ requestMsg1, sizeof(pldm_apply_complete_req), &outApplyResult,
+ &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outApplyResult, applyResult1);
+ EXPECT_EQ(outCompActivationModification.value, compActivationModification1);
+
+ constexpr uint8_t applyResult2 = PLDM_FWUP_APPLY_SUCCESS;
+ constexpr std::bitset<16> compActivationModification2{};
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
+ applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto requestMsg2 =
+ reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
+ rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
+ &outApplyResult,
+ &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(outApplyResult, applyResult2);
+ EXPECT_EQ(outCompActivationModification.value, compActivationModification2);
+}
+
+TEST(ApplyComplete, errorPathDecodeRequest)
+{
+ constexpr std::array<uint8_t, hdrSize> applyCompleteReq1{0x00, 0x00, 0x00};
+ auto requestMsg1 =
+ reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
+ uint8_t outApplyResult = 0;
+ bitfield16_t outCompActivationModification{};
+
+ auto rc = decode_apply_complete_req(
+ nullptr, sizeof(pldm_apply_complete_req), &outApplyResult,
+ &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
+ nullptr, &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
+ &outApplyResult, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_apply_complete_req(requestMsg1, 0, &outApplyResult,
+ &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
+ applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
+ auto requestMsg2 =
+ reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
+ rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
+ &outApplyResult,
+ &outCompActivationModification);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(ApplyComplete, goodPathEncodeResponse)
+{
+ constexpr uint8_t instanceId = 6;
+ constexpr uint8_t completionCode = PLDM_SUCCESS;
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outApplyCompleteResponse1{0x06, 0x05, 0x18, 0x00};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ applyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<pldm_msg*>(applyCompleteResponse1.data());
+ auto rc = encode_apply_complete_resp(instanceId, completionCode,
+ responseMsg1, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(applyCompleteResponse1, outApplyCompleteResponse1);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ outApplyCompleteResponse2{0x06, 0x05, 0x18, 0x87};
+ std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ applyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<pldm_msg*>(applyCompleteResponse2.data());
+ rc = encode_apply_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
+ responseMsg2, sizeof(completionCode));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(applyCompleteResponse2, outApplyCompleteResponse2);
+}
+
+TEST(ApplyComplete, errorPathEncodeResponse)
+{
+ std::array<uint8_t, hdrSize> applyCompleteResponse{0x00, 0x00, 0x00};
+ auto responseMsg =
+ reinterpret_cast<pldm_msg*>(applyCompleteResponse.data());
+ auto rc = encode_apply_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_apply_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ActivateFirmware, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 7;
+
+ std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_activate_firmware_req(
+ instanceId, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg,
+ sizeof(pldm_activate_firmware_req));
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)>
+ outRequest{0x87, 0x05, 0x1A, 0x01};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(ActivateFirmware, errorPathEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_activate_firmware_req(
+ 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, nullptr,
+ sizeof(pldm_activate_firmware_req));
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_activate_firmware_req(
+ 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = encode_activate_firmware_req(0, 2, requestMsg,
+ sizeof(pldm_activate_firmware_req));
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(ActivateFirmware, goodPathDecodeResponse)
+{
+ constexpr uint16_t estimatedTimeForActivation100s = 100;
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
+ activateFirmwareResponse1{0x00, 0x00, 0x00, 0x00, 0x64, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(activateFirmwareResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint16_t estimatedTimeForActivation = 0;
+
+ auto rc = decode_activate_firmware_resp(
+ responseMsg1, sizeof(pldm_activate_firmware_resp), &completionCode,
+ &estimatedTimeForActivation);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(estimatedTimeForActivation, estimatedTimeForActivation100s);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ activateFirmwareResponse2{0x00, 0x00, 0x00, 0x85};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(activateFirmwareResponse2.data());
+
+ rc = decode_activate_firmware_resp(responseMsg2, sizeof(completionCode),
+ &completionCode,
+ &estimatedTimeForActivation);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_FWUP_INCOMPLETE_UPDATE);
+}
+
+TEST(ActivateFirmware, errorPathDecodeResponse)
+{
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
+ activateFirmwareResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(activateFirmwareResponse.data());
+
+ uint8_t completionCode = 0;
+ uint16_t estimatedTimeForActivation = 0;
+
+ auto rc = decode_activate_firmware_resp(
+ nullptr, sizeof(pldm_activate_firmware_resp), &completionCode,
+ &estimatedTimeForActivation);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_activate_firmware_resp(responseMsg,
+ sizeof(pldm_activate_firmware_resp),
+ nullptr, &estimatedTimeForActivation);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_activate_firmware_resp(responseMsg,
+ sizeof(pldm_activate_firmware_resp),
+ &completionCode, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_activate_firmware_resp(responseMsg, 0, &completionCode,
+ &estimatedTimeForActivation);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_activate_firmware_resp(
+ responseMsg, sizeof(pldm_activate_firmware_resp) - 1, &completionCode,
+ &estimatedTimeForActivation);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetStatus, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 8;
+ std::array<uint8_t, hdrSize> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_get_status_req(instanceId, requestMsg,
+ PLDM_GET_STATUS_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ constexpr std::array<uint8_t, hdrSize> outRequest{0x88, 0x05, 0x1B};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(GetStatus, errorPathEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_get_status_req(0, nullptr, PLDM_GET_STATUS_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_get_status_req(0, requestMsg, PLDM_GET_STATUS_REQ_BYTES + 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetStatus, goodPathDecodeResponse)
+{
+ constexpr std::bitset<32> updateOptionFlagsEnabled1{0};
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03,
+ 0x09, 0x65, 0x05, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
+
+ uint8_t completionCode = 0;
+ uint8_t currentState = 0;
+ uint8_t previousState = 0;
+ uint8_t auxState = 0;
+ uint8_t auxStateStatus = 0;
+ uint8_t progressPercent = 0;
+ uint8_t reasonCode = 0;
+ bitfield32_t updateOptionFlagsEnabled{0};
+
+ auto rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(currentState, PLDM_FD_STATE_IDLE);
+ EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
+ EXPECT_EQ(auxState, PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER);
+ EXPECT_EQ(auxStateStatus, PLDM_FD_TIMEOUT);
+ EXPECT_EQ(progressPercent, PLDM_FWUP_MAX_PROGRESS_PERCENT);
+ EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
+ EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled1);
+
+ // Bit position 0 - Force update of component – FD will perform a force
+ // update of the component.
+ constexpr std::bitset<32> updateOptionFlagsEnabled2{1};
+ constexpr uint8_t progressPercent2 = 50;
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00,
+ 0x70, 0x32, 0x05, 0x01, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
+
+ rc = decode_get_status_resp(
+ responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(currentState, PLDM_FD_STATE_VERIFY);
+ EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
+ EXPECT_EQ(auxState, PLDM_FD_OPERATION_IN_PROGRESS);
+ EXPECT_EQ(auxStateStatus, PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START);
+ EXPECT_EQ(progressPercent, progressPercent2);
+ EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
+ EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled2);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ getStatusResponse3{0x00, 0x00, 0x00, 0x04};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
+ rc = decode_get_status_resp(
+ responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_ERROR_NOT_READY);
+}
+
+TEST(GetStatus, errorPathDecodeResponse)
+{
+ uint8_t completionCode = 0;
+ uint8_t currentState = 0;
+ uint8_t previousState = 0;
+ uint8_t auxState = 0;
+ uint8_t auxStateStatus = 0;
+ uint8_t progressPercent = 0;
+ uint8_t reasonCode = 0;
+ bitfield32_t updateOptionFlagsEnabled{0};
+
+ constexpr std::array<uint8_t, hdrSize> getStatusResponse1{0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
+
+ auto rc = decode_get_status_resp(
+ nullptr, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, nullptr,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ nullptr, &previousState, &auxState, &auxStateStatus, &progressPercent,
+ &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, nullptr, &auxState, &auxStateStatus, &progressPercent,
+ &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, nullptr, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, nullptr, &progressPercent,
+ &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus, nullptr,
+ &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, nullptr, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_status_resp(
+ responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp) - 1>
+ getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
+ rc = decode_get_status_resp(
+ responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse3{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
+ rc = decode_get_status_resp(
+ responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg4 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse4.data());
+ rc = decode_get_status_resp(
+ responseMsg4, getStatusResponse4.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse5{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg5 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse5.data());
+ rc = decode_get_status_resp(
+ responseMsg5, getStatusResponse5.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse6{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg6 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse6.data());
+ rc = decode_get_status_resp(
+ responseMsg6, getStatusResponse6.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse7{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg7 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse7.data());
+ rc = decode_get_status_resp(
+ responseMsg7, getStatusResponse7.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse8{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xC7, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg8 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse8.data());
+ rc = decode_get_status_resp(
+ responseMsg8, getStatusResponse8.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // AuxState is not PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER when the state is
+ // IDLE
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
+ getStatusResponse9{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg9 =
+ reinterpret_cast<const pldm_msg*>(getStatusResponse9.data());
+ rc = decode_get_status_resp(
+ responseMsg9, getStatusResponse9.size() - hdrSize, &completionCode,
+ ¤tState, &previousState, &auxState, &auxStateStatus,
+ &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(CancelUpdateComponent, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 9;
+ std::array<uint8_t, hdrSize> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_cancel_update_component_req(
+ instanceId, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ constexpr std::array<uint8_t, hdrSize> outRequest{0x89, 0x05, 0x1C};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(CancelUpdateComponent, errorPathEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_cancel_update_component_req(
+ 0, nullptr, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_cancel_update_component_req(
+ 0, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES + 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(CancelUpdateComponent, testGoodDecodeResponse)
+{
+ uint8_t completionCode = 0;
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ cancelUpdateComponentResponse1{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 = reinterpret_cast<const pldm_msg*>(
+ cancelUpdateComponentResponse1.data());
+ auto rc = decode_cancel_update_component_resp(
+ responseMsg1, cancelUpdateComponentResponse1.size() - hdrSize,
+ &completionCode);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ cancelUpdateComponentResponse2{0x00, 0x00, 0x00, 0x86};
+ auto responseMsg2 = reinterpret_cast<const pldm_msg*>(
+ cancelUpdateComponentResponse2.data());
+ rc = decode_cancel_update_component_resp(
+ responseMsg2, cancelUpdateComponentResponse2.size() - hdrSize,
+ &completionCode);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
+}
+
+TEST(CancelUpdateComponent, testBadDecodeResponse)
+{
+ uint8_t completionCode = 0;
+ constexpr std::array<uint8_t, hdrSize> cancelUpdateComponentResponse{
+ 0x00, 0x00, 0x00};
+ auto responseMsg =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateComponentResponse.data());
+
+ auto rc = decode_cancel_update_component_resp(
+ nullptr, cancelUpdateComponentResponse.size() - hdrSize,
+ &completionCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_component_resp(
+ responseMsg, cancelUpdateComponentResponse.size() - hdrSize, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_component_resp(
+ responseMsg, cancelUpdateComponentResponse.size() - hdrSize,
+ &completionCode);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(CancelUpdate, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 10;
+ std::array<uint8_t, hdrSize> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_cancel_update_req(instanceId, requestMsg,
+ PLDM_CANCEL_UPDATE_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ constexpr std::array<uint8_t, hdrSize> outRequest{0x8A, 0x05, 0x1D};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(CancelUpdate, errorPathEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc =
+ encode_cancel_update_req(0, nullptr, PLDM_CANCEL_UPDATE_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_cancel_update_req(0, requestMsg,
+ PLDM_CANCEL_UPDATE_REQ_BYTES + 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(CancelUpdate, goodPathDecodeResponse)
+{
+ constexpr std::bitset<64> nonFunctioningComponentBitmap1{0};
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
+ cancelUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
+ uint8_t completionCode = 0;
+ bool8_t nonFunctioningComponentIndication = 0;
+ bitfield64_t nonFunctioningComponentBitmap{0};
+ auto rc = decode_cancel_update_resp(
+ responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(nonFunctioningComponentIndication,
+ PLDM_FWUP_COMPONENTS_FUNCTIONING);
+ EXPECT_EQ(nonFunctioningComponentBitmap.value,
+ nonFunctioningComponentBitmap1);
+
+ constexpr std::bitset<64> nonFunctioningComponentBitmap2{0x0101};
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
+ cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
+ rc = decode_cancel_update_resp(
+ responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_SUCCESS);
+ EXPECT_EQ(nonFunctioningComponentIndication,
+ PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING);
+ EXPECT_EQ(nonFunctioningComponentBitmap.value,
+ nonFunctioningComponentBitmap2);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ cancelUpdateResponse3{0x00, 0x00, 0x00, 0x86};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
+ rc = decode_cancel_update_resp(
+ responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
+}
+
+TEST(CancelUpdate, errorPathDecodeResponse)
+{
+ constexpr std::array<uint8_t, hdrSize> cancelUpdateResponse1{0x00, 0x00,
+ 0x00};
+ auto responseMsg1 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
+ uint8_t completionCode = 0;
+ bool8_t nonFunctioningComponentIndication = 0;
+ bitfield64_t nonFunctioningComponentBitmap{0};
+
+ auto rc = decode_cancel_update_resp(
+ nullptr, cancelUpdateResponse1.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_resp(
+ responseMsg1, cancelUpdateResponse1.size() - hdrSize, nullptr,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_resp(
+ responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
+ nullptr, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_resp(
+ responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_cancel_update_resp(
+ responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
+ cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00};
+ auto responseMsg2 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
+ rc = decode_cancel_update_resp(
+ responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
+ cancelUpdateResponse3{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ auto responseMsg3 =
+ reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
+ rc = decode_cancel_update_resp(
+ responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
+ &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
diff --git a/libpldmresponder/event_parser.cpp b/libpldmresponder/event_parser.cpp
index e38102c..990ff7c 100644
--- a/libpldmresponder/event_parser.cpp
+++ b/libpldmresponder/event_parser.cpp
@@ -1,156 +1,156 @@
-#include "event_parser.hpp"
-
-#include <xyz/openbmc_project/Common/error.hpp>
-
-#include <filesystem>
-#include <fstream>
-#include <iostream>
-#include <set>
-
-namespace pldm::responder::events
-{
-
-namespace fs = std::filesystem;
-using InternalFailure =
- sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-
-const Json emptyJson{};
-const std::vector<Json> emptyJsonList{};
-const std::vector<std::string> emptyStringVec{};
-
-const std::set<std::string_view> supportedDbusPropertyTypes = {
- "bool", "uint8_t", "int16_t", "uint16_t", "int32_t",
- "uint32_t", "int64_t", "uint64_t", "double", "string"};
-
-StateSensorHandler::StateSensorHandler(const std::string& dirPath)
-{
- fs::path dir(dirPath);
- if (!fs::exists(dir) || fs::is_empty(dir))
- {
- std::cerr << "Event config directory does not exist or empty, DIR="
- << dirPath << "\n";
- return;
- }
-
- for (auto& file : fs::directory_iterator(dirPath))
- {
- std::ifstream jsonFile(file.path());
-
- auto data = Json::parse(jsonFile, nullptr, false);
- if (data.is_discarded())
- {
- std::cerr << "Parsing Event state sensor JSON file failed, FILE="
- << file.path();
- continue;
- }
-
- auto entries = data.value("entries", emptyJsonList);
- for (const auto& entry : entries)
- {
- StateSensorEntry stateSensorEntry{};
- stateSensorEntry.containerId =
- static_cast<uint16_t>(entry.value("containerID", 0));
- stateSensorEntry.entityType =
- static_cast<uint16_t>(entry.value("entityType", 0));
- stateSensorEntry.entityInstance =
- static_cast<uint16_t>(entry.value("entityInstance", 0));
- stateSensorEntry.sensorOffset =
- static_cast<uint8_t>(entry.value("sensorOffset", 0));
-
- pldm::utils::DBusMapping dbusInfo{};
-
- auto dbus = entry.value("dbus", emptyJson);
- dbusInfo.objectPath = dbus.value("object_path", "");
- dbusInfo.interface = dbus.value("interface", "");
- dbusInfo.propertyName = dbus.value("property_name", "");
- dbusInfo.propertyType = dbus.value("property_type", "");
- if (dbusInfo.objectPath.empty() || dbusInfo.interface.empty() ||
- dbusInfo.propertyName.empty() ||
- (supportedDbusPropertyTypes.find(dbusInfo.propertyType) ==
- supportedDbusPropertyTypes.end()))
- {
- std::cerr << "Invalid dbus config,"
- << " OBJPATH=" << dbusInfo.objectPath << " INTERFACE="
- << dbusInfo.interface << " PROPERTY_NAME="
- << dbusInfo.propertyName
- << " PROPERTY_TYPE=" << dbusInfo.propertyType << "\n";
- continue;
- }
-
- auto eventStates = entry.value("event_states", emptyJsonList);
- auto propertyValues = dbus.value("property_values", emptyJsonList);
- if ((eventStates.size() == 0) || (propertyValues.size() == 0) ||
- (eventStates.size() != propertyValues.size()))
- {
- std::cerr << "Invalid event state JSON config,"
- << " EVENT_STATE_SIZE=" << eventStates.size()
- << " PROPERTY_VALUE_SIZE=" << propertyValues.size()
- << "\n";
- continue;
- }
-
- auto eventStateMap = mapStateToDBusVal(eventStates, propertyValues,
- dbusInfo.propertyType);
- eventMap.emplace(
- stateSensorEntry,
- std::make_tuple(std::move(dbusInfo), std::move(eventStateMap)));
- }
- }
-}
-
-StateToDBusValue StateSensorHandler::mapStateToDBusVal(
- const Json& eventStates, const Json& propertyValues, std::string_view type)
-{
- StateToDBusValue eventStateMap{};
- auto stateIt = eventStates.begin();
- auto propIt = propertyValues.begin();
-
- for (; stateIt != eventStates.end(); ++stateIt, ++propIt)
- {
- auto propValue = utils::jsonEntryToDbusVal(type, propIt.value());
- eventStateMap.emplace((*stateIt).get<uint8_t>(), std::move(propValue));
- }
-
- return eventStateMap;
-}
-
-int StateSensorHandler::eventAction(const StateSensorEntry& entry,
- pdr::EventState state)
-{
- try
- {
- const auto& [dbusMapping, eventStateMap] = eventMap.at(entry);
- utils::PropertyValue propValue{};
- try
- {
- propValue = eventStateMap.at(state);
- }
- catch (const std::out_of_range& e)
- {
- std::cerr << "Invalid event state" << static_cast<unsigned>(state)
- << '\n';
- return PLDM_ERROR_INVALID_DATA;
- }
-
- try
- {
- pldm::utils::DBusHandler().setDbusProperty(dbusMapping, propValue);
- }
- catch (const std::exception& e)
- {
- std::cerr << "Error setting property, ERROR=" << e.what()
- << " PROPERTY=" << dbusMapping.propertyName
- << " INTERFACE=" << dbusMapping.interface << " PATH="
- << dbusMapping.objectPath << "\n";
- return PLDM_ERROR;
- }
- }
- catch (const std::out_of_range& e)
- {
- // There is no BMC action for this PLDM event
- return PLDM_SUCCESS;
- }
- return PLDM_SUCCESS;
-}
-
+#include "event_parser.hpp"
+
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <set>
+
+namespace pldm::responder::events
+{
+
+namespace fs = std::filesystem;
+using InternalFailure =
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+
+const Json emptyJson{};
+const std::vector<Json> emptyJsonList{};
+const std::vector<std::string> emptyStringVec{};
+
+const std::set<std::string_view> supportedDbusPropertyTypes = {
+ "bool", "uint8_t", "int16_t", "uint16_t", "int32_t",
+ "uint32_t", "int64_t", "uint64_t", "double", "string"};
+
+StateSensorHandler::StateSensorHandler(const std::string& dirPath)
+{
+ fs::path dir(dirPath);
+ if (!fs::exists(dir) || fs::is_empty(dir))
+ {
+ std::cerr << "Event config directory does not exist or empty, DIR="
+ << dirPath << "\n";
+ return;
+ }
+
+ for (auto& file : fs::directory_iterator(dirPath))
+ {
+ std::ifstream jsonFile(file.path());
+
+ auto data = Json::parse(jsonFile, nullptr, false);
+ if (data.is_discarded())
+ {
+ std::cerr << "Parsing Event state sensor JSON file failed, FILE="
+ << file.path();
+ continue;
+ }
+
+ auto entries = data.value("entries", emptyJsonList);
+ for (const auto& entry : entries)
+ {
+ StateSensorEntry stateSensorEntry{};
+ stateSensorEntry.containerId =
+ static_cast<uint16_t>(entry.value("containerID", 0));
+ stateSensorEntry.entityType =
+ static_cast<uint16_t>(entry.value("entityType", 0));
+ stateSensorEntry.entityInstance =
+ static_cast<uint16_t>(entry.value("entityInstance", 0));
+ stateSensorEntry.sensorOffset =
+ static_cast<uint8_t>(entry.value("sensorOffset", 0));
+
+ pldm::utils::DBusMapping dbusInfo{};
+
+ auto dbus = entry.value("dbus", emptyJson);
+ dbusInfo.objectPath = dbus.value("object_path", "");
+ dbusInfo.interface = dbus.value("interface", "");
+ dbusInfo.propertyName = dbus.value("property_name", "");
+ dbusInfo.propertyType = dbus.value("property_type", "");
+ if (dbusInfo.objectPath.empty() || dbusInfo.interface.empty() ||
+ dbusInfo.propertyName.empty() ||
+ (supportedDbusPropertyTypes.find(dbusInfo.propertyType) ==
+ supportedDbusPropertyTypes.end()))
+ {
+ std::cerr << "Invalid dbus config,"
+ << " OBJPATH=" << dbusInfo.objectPath << " INTERFACE="
+ << dbusInfo.interface << " PROPERTY_NAME="
+ << dbusInfo.propertyName
+ << " PROPERTY_TYPE=" << dbusInfo.propertyType << "\n";
+ continue;
+ }
+
+ auto eventStates = entry.value("event_states", emptyJsonList);
+ auto propertyValues = dbus.value("property_values", emptyJsonList);
+ if ((eventStates.size() == 0) || (propertyValues.size() == 0) ||
+ (eventStates.size() != propertyValues.size()))
+ {
+ std::cerr << "Invalid event state JSON config,"
+ << " EVENT_STATE_SIZE=" << eventStates.size()
+ << " PROPERTY_VALUE_SIZE=" << propertyValues.size()
+ << "\n";
+ continue;
+ }
+
+ auto eventStateMap = mapStateToDBusVal(eventStates, propertyValues,
+ dbusInfo.propertyType);
+ eventMap.emplace(
+ stateSensorEntry,
+ std::make_tuple(std::move(dbusInfo), std::move(eventStateMap)));
+ }
+ }
+}
+
+StateToDBusValue StateSensorHandler::mapStateToDBusVal(
+ const Json& eventStates, const Json& propertyValues, std::string_view type)
+{
+ StateToDBusValue eventStateMap{};
+ auto stateIt = eventStates.begin();
+ auto propIt = propertyValues.begin();
+
+ for (; stateIt != eventStates.end(); ++stateIt, ++propIt)
+ {
+ auto propValue = utils::jsonEntryToDbusVal(type, propIt.value());
+ eventStateMap.emplace((*stateIt).get<uint8_t>(), std::move(propValue));
+ }
+
+ return eventStateMap;
+}
+
+int StateSensorHandler::eventAction(const StateSensorEntry& entry,
+ pdr::EventState state)
+{
+ try
+ {
+ const auto& [dbusMapping, eventStateMap] = eventMap.at(entry);
+ utils::PropertyValue propValue{};
+ try
+ {
+ propValue = eventStateMap.at(state);
+ }
+ catch (const std::out_of_range& e)
+ {
+ std::cerr << "Invalid event state" << static_cast<unsigned>(state)
+ << '\n';
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ try
+ {
+ pldm::utils::DBusHandler().setDbusProperty(dbusMapping, propValue);
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << "Error setting property, ERROR=" << e.what()
+ << " PROPERTY=" << dbusMapping.propertyName
+ << " INTERFACE=" << dbusMapping.interface << " PATH="
+ << dbusMapping.objectPath << "\n";
+ return PLDM_ERROR;
+ }
+ }
+ catch (const std::out_of_range& e)
+ {
+ // There is no BMC action for this PLDM event
+ return PLDM_SUCCESS;
+ }
+ return PLDM_SUCCESS;
+}
+
} // namespace pldm::responder::events
\ No newline at end of file
diff --git a/libpldmresponder/event_parser.hpp b/libpldmresponder/event_parser.hpp
index 49f2233..57d0ae1 100644
--- a/libpldmresponder/event_parser.hpp
+++ b/libpldmresponder/event_parser.hpp
@@ -1,121 +1,121 @@
-#pragma once
-
-#include "common/types.hpp"
-#include "common/utils.hpp"
-
-#include <nlohmann/json.hpp>
-
-#include <filesystem>
-#include <map>
-#include <string>
-#include <tuple>
-#include <vector>
-
-namespace pldm::responder::events
-{
-
-/** @struct StateSensorEntry
- *
- * StateSensorEntry is a key to uniquely identify a state sensor, so that a
- * D-Bus action can be defined for PlatformEventMessage command with
- * sensorEvent type. This struct is used as a key in a std::map so implemented
- * operator== and operator<.
- */
-struct StateSensorEntry
-{
- pdr::ContainerID containerId;
- pdr::EntityType entityType;
- pdr::EntityInstance entityInstance;
- pdr::SensorOffset sensorOffset;
-
- bool operator==(const StateSensorEntry& e) const
- {
- return ((containerId == e.containerId) &&
- (entityType == e.entityType) &&
- (entityInstance == e.entityInstance) &&
- (sensorOffset == e.sensorOffset));
- }
-
- bool operator<(const StateSensorEntry& e) const
- {
- return (
- (containerId < e.containerId) ||
- ((containerId == e.containerId) && (entityType < e.entityType)) ||
- ((containerId == e.containerId) && (entityType == e.entityType) &&
- (entityInstance < e.entityInstance)) ||
- ((containerId == e.containerId) && (entityType == e.entityType) &&
- (entityInstance == e.entityInstance) &&
- (sensorOffset < e.sensorOffset)));
- }
-};
-
-using StateToDBusValue = std::map<pdr::EventState, pldm::utils::PropertyValue>;
-using EventDBusInfo = std::tuple<pldm::utils::DBusMapping, StateToDBusValue>;
-using EventMap = std::map<StateSensorEntry, EventDBusInfo>;
-using Json = nlohmann::json;
-
-/** @class StateSensorHandler
- *
- * @brief Parses the event state sensor configuration JSON file and build
- * the lookup data structure, which can map the event state for a
- * sensor in the PlatformEventMessage command to a D-Bus property and
- * the property value.
- */
-class StateSensorHandler
-{
- public:
- StateSensorHandler() = delete;
-
- /** @brief Parse the event state sensor configuration JSON file and build
- * the lookup data stucture.
- *
- * @param[in] dirPath - directory path which has the config JSONs
- */
- explicit StateSensorHandler(const std::string& dirPath);
- virtual ~StateSensorHandler() = default;
- StateSensorHandler(const StateSensorHandler&) = default;
- StateSensorHandler& operator=(const StateSensorHandler&) = default;
- StateSensorHandler(StateSensorHandler&&) = default;
- StateSensorHandler& operator=(StateSensorHandler&&) = default;
-
- /** @brief If the StateSensorEntry and EventState is valid, the D-Bus
- * property corresponding to the StateSensorEntry is set based on
- * the EventState
- *
- * @param[in] entry - state sensor entry
- * @param[in] state - event state
- *
- * @return PLDM completion code
- */
- int eventAction(const StateSensorEntry& entry, pdr::EventState state);
-
- /** @brief Helper API to get D-Bus information for a StateSensorEntry
- *
- * @param[in] entry - state sensor entry
- *
- * @return D-Bus information corresponding to the SensorEntry
- */
- const EventDBusInfo& getEventInfo(const StateSensorEntry& entry) const
- {
- return eventMap.at(entry);
- }
-
- private:
- EventMap eventMap; //!< a map of StateSensorEntry to D-Bus information
-
- /** @brief Create a map of EventState to D-Bus property values from
- * the information provided in the event state configuration
- * JSON
- *
- * @param[in] eventStates - a JSON array of event states
- * @param[in] propertyValues - a JSON array of D-Bus property values
- * @param[in] type - the type of D-Bus property
- *
- * @return a map of EventState to D-Bus property values
- */
- StateToDBusValue mapStateToDBusVal(const Json& eventStates,
- const Json& propertyValues,
- std::string_view type);
-};
-
+#pragma once
+
+#include "common/types.hpp"
+#include "common/utils.hpp"
+
+#include <nlohmann/json.hpp>
+
+#include <filesystem>
+#include <map>
+#include <string>
+#include <tuple>
+#include <vector>
+
+namespace pldm::responder::events
+{
+
+/** @struct StateSensorEntry
+ *
+ * StateSensorEntry is a key to uniquely identify a state sensor, so that a
+ * D-Bus action can be defined for PlatformEventMessage command with
+ * sensorEvent type. This struct is used as a key in a std::map so implemented
+ * operator== and operator<.
+ */
+struct StateSensorEntry
+{
+ pdr::ContainerID containerId;
+ pdr::EntityType entityType;
+ pdr::EntityInstance entityInstance;
+ pdr::SensorOffset sensorOffset;
+
+ bool operator==(const StateSensorEntry& e) const
+ {
+ return ((containerId == e.containerId) &&
+ (entityType == e.entityType) &&
+ (entityInstance == e.entityInstance) &&
+ (sensorOffset == e.sensorOffset));
+ }
+
+ bool operator<(const StateSensorEntry& e) const
+ {
+ return (
+ (containerId < e.containerId) ||
+ ((containerId == e.containerId) && (entityType < e.entityType)) ||
+ ((containerId == e.containerId) && (entityType == e.entityType) &&
+ (entityInstance < e.entityInstance)) ||
+ ((containerId == e.containerId) && (entityType == e.entityType) &&
+ (entityInstance == e.entityInstance) &&
+ (sensorOffset < e.sensorOffset)));
+ }
+};
+
+using StateToDBusValue = std::map<pdr::EventState, pldm::utils::PropertyValue>;
+using EventDBusInfo = std::tuple<pldm::utils::DBusMapping, StateToDBusValue>;
+using EventMap = std::map<StateSensorEntry, EventDBusInfo>;
+using Json = nlohmann::json;
+
+/** @class StateSensorHandler
+ *
+ * @brief Parses the event state sensor configuration JSON file and build
+ * the lookup data structure, which can map the event state for a
+ * sensor in the PlatformEventMessage command to a D-Bus property and
+ * the property value.
+ */
+class StateSensorHandler
+{
+ public:
+ StateSensorHandler() = delete;
+
+ /** @brief Parse the event state sensor configuration JSON file and build
+ * the lookup data stucture.
+ *
+ * @param[in] dirPath - directory path which has the config JSONs
+ */
+ explicit StateSensorHandler(const std::string& dirPath);
+ virtual ~StateSensorHandler() = default;
+ StateSensorHandler(const StateSensorHandler&) = default;
+ StateSensorHandler& operator=(const StateSensorHandler&) = default;
+ StateSensorHandler(StateSensorHandler&&) = default;
+ StateSensorHandler& operator=(StateSensorHandler&&) = default;
+
+ /** @brief If the StateSensorEntry and EventState is valid, the D-Bus
+ * property corresponding to the StateSensorEntry is set based on
+ * the EventState
+ *
+ * @param[in] entry - state sensor entry
+ * @param[in] state - event state
+ *
+ * @return PLDM completion code
+ */
+ int eventAction(const StateSensorEntry& entry, pdr::EventState state);
+
+ /** @brief Helper API to get D-Bus information for a StateSensorEntry
+ *
+ * @param[in] entry - state sensor entry
+ *
+ * @return D-Bus information corresponding to the SensorEntry
+ */
+ const EventDBusInfo& getEventInfo(const StateSensorEntry& entry) const
+ {
+ return eventMap.at(entry);
+ }
+
+ private:
+ EventMap eventMap; //!< a map of StateSensorEntry to D-Bus information
+
+ /** @brief Create a map of EventState to D-Bus property values from
+ * the information provided in the event state configuration
+ * JSON
+ *
+ * @param[in] eventStates - a JSON array of event states
+ * @param[in] propertyValues - a JSON array of D-Bus property values
+ * @param[in] type - the type of D-Bus property
+ *
+ * @return a map of EventState to D-Bus property values
+ */
+ StateToDBusValue mapStateToDBusVal(const Json& eventStates,
+ const Json& propertyValues,
+ std::string_view type);
+};
+
} // namespace pldm::responder::events
\ No newline at end of file
diff --git a/libpldmresponder/examples/effecter/dbus_to_host_effecter.json b/libpldmresponder/examples/effecter/dbus_to_host_effecter.json
index f389c40..3fbcb82 100644
--- a/libpldmresponder/examples/effecter/dbus_to_host_effecter.json
+++ b/libpldmresponder/examples/effecter/dbus_to_host_effecter.json
@@ -1,118 +1,118 @@
-{
- "entries": [
- {
- #mctp eid is needed for communicating with the host
- "mctp_eid": 9,
- "effecter_info": {
- #a 0xFFFF means effecter id is not hard coded and will be
- #fetched from the PDR
- "effecterID": 0xFFFF,
- "containerID": 1,
- "entityType": 32801,
- # entity type 33 means Phyp will set value 32801
- # this is because the MSB is set to indicate
- #virtual entity
- "entityInstance": 1,
- "compositeEffecterCount": 3
- },
- "effecters": [
- {
- # Following are the D-Bus information under each effecter
- #which are monitored for a property change signal
-
- #if there is a property change, the corresponding
- #state value is picked up to set the host effecter
-
- "dbus_info": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example1.value",
- "property_name": "value1",
- "property_type": "string",
- "property_values": [
- "xyz.openbmc_project.State.On",
- "xyz.openbmc_project.State.Off"
- ]
- },
- "state" : {
- "id" : 197,
- # This should be of same size and order as
- # property_values
- "state_values": [
- 0,
- 1
- ]
- }
- },
- {
- "dbus_info": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example1.value",
- "property_name": "value2",
- "property_type": "uint8_t",
- "property_values": [
- 9,
- 10
- ]
- },
- "state" : {
- "id" : 12,
- "state_values": [
- 2,
- 3
- ]
- }
- },
- {
- "dbus_info": {
- "object_path": "/abc/def/xyz",
- "interface": "xyz.openbmc_project.example3.value",
- "property_name": "value3",
- "property_type": "bool",
- "property_values": [
- false,
- true
- ]
- },
- "state" : {
- "id" : 12,
- "state_values": [
- 0,
- 1
- ]
- }
- }
- ]
- },
- {
- "mctp_eid": 10,
- "effecter_info": {
- "effecterID": 10,
- "containerID": 0,
- "entityType": 33,
- "entityInstance": 0,
- "compositeEffecterCount": 1
- },
- "effecters": [
- {
- "dbus_info": {
- "object_path": "/def/abc/xyz",
- "interface": "xyz.openbmc_project.example4.value",
- "property_name": "value4",
- "property_type": "string",
- "property_values": [
- "xyz.openbmc_project.State.Enabled",
- "xyz.openbmc_project.State.Disabled"
- ]
- },
- "state" : {
- "id" : 15,
- "state_values": [
- 3,
- 4
- ]
- }
- }
- ]
- }
- ]
-}
+{
+ "entries": [
+ {
+ #mctp eid is needed for communicating with the host
+ "mctp_eid": 9,
+ "effecter_info": {
+ #a 0xFFFF means effecter id is not hard coded and will be
+ #fetched from the PDR
+ "effecterID": 0xFFFF,
+ "containerID": 1,
+ "entityType": 32801,
+ # entity type 33 means Phyp will set value 32801
+ # this is because the MSB is set to indicate
+ #virtual entity
+ "entityInstance": 1,
+ "compositeEffecterCount": 3
+ },
+ "effecters": [
+ {
+ # Following are the D-Bus information under each effecter
+ #which are monitored for a property change signal
+
+ #if there is a property change, the corresponding
+ #state value is picked up to set the host effecter
+
+ "dbus_info": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example1.value",
+ "property_name": "value1",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.State.On",
+ "xyz.openbmc_project.State.Off"
+ ]
+ },
+ "state" : {
+ "id" : 197,
+ # This should be of same size and order as
+ # property_values
+ "state_values": [
+ 0,
+ 1
+ ]
+ }
+ },
+ {
+ "dbus_info": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example1.value",
+ "property_name": "value2",
+ "property_type": "uint8_t",
+ "property_values": [
+ 9,
+ 10
+ ]
+ },
+ "state" : {
+ "id" : 12,
+ "state_values": [
+ 2,
+ 3
+ ]
+ }
+ },
+ {
+ "dbus_info": {
+ "object_path": "/abc/def/xyz",
+ "interface": "xyz.openbmc_project.example3.value",
+ "property_name": "value3",
+ "property_type": "bool",
+ "property_values": [
+ false,
+ true
+ ]
+ },
+ "state" : {
+ "id" : 12,
+ "state_values": [
+ 0,
+ 1
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "mctp_eid": 10,
+ "effecter_info": {
+ "effecterID": 10,
+ "containerID": 0,
+ "entityType": 33,
+ "entityInstance": 0,
+ "compositeEffecterCount": 1
+ },
+ "effecters": [
+ {
+ "dbus_info": {
+ "object_path": "/def/abc/xyz",
+ "interface": "xyz.openbmc_project.example4.value",
+ "property_name": "value4",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.State.Enabled",
+ "xyz.openbmc_project.State.Disabled"
+ ]
+ },
+ "state" : {
+ "id" : 15,
+ "state_values": [
+ 3,
+ 4
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/libpldmresponder/examples/events/event_state_sensor.json b/libpldmresponder/examples/events/event_state_sensor.json
index 47713b8..6ab566e 100644
--- a/libpldmresponder/examples/events/event_state_sensor.json
+++ b/libpldmresponder/examples/events/event_state_sensor.json
@@ -1,69 +1,69 @@
-# Each entry is to uniquely identify a remote state sensor(there are separate
-# entry for each sensor in a composite sensor) and the supported event states.
-# The "dbus" section contains information about the corresponding D-Bus
-# property for the sensor and "property_values" are the D-Bus property values
-# for each corresponding entry in the "event_states"
-{
- "entries": [
- {
- "containerID": 1,
- "entityType": 64,
- "entityInstance": 1,
- "sensorOffset": 0,
- "event_states": [
- 0,
- 1
- ],
- "dbus": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example1.value",
- "property_name": "value1",
- "property_type": "string",
- "property_values": [
- "xyz.openbmc_project.State.On",
- "xyz.openbmc_project.State.Off"
- ]
- }
- },
- {
- "containerID": 1,
- "entityType": 64,
- "entityInstance": 1,
- "sensorOffset": 1,
- "event_states": [
- 2,
- 3
- ],
- "dbus": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example2.value",
- "property_name": "value2",
- "property_type": "uint8_t",
- "property_values": [
- 9,
- 10
- ]
- }
- },
- {
- "containerID": 1,
- "entityType": 67,
- "entityInstance": 1,
- "sensorOffset": 0,
- "event_states": [
- 0,
- 1
- ],
- "dbus": {
- "object_path": "/xyz/abc/ghi",
- "interface": "xyz.openbmc_project.example3.value",
- "property_name": "value3",
- "property_type": "bool",
- "property_values": [
- false,
- true
- ]
- }
- }
- ]
-}
+# Each entry is to uniquely identify a remote state sensor(there are separate
+# entry for each sensor in a composite sensor) and the supported event states.
+# The "dbus" section contains information about the corresponding D-Bus
+# property for the sensor and "property_values" are the D-Bus property values
+# for each corresponding entry in the "event_states"
+{
+ "entries": [
+ {
+ "containerID": 1,
+ "entityType": 64,
+ "entityInstance": 1,
+ "sensorOffset": 0,
+ "event_states": [
+ 0,
+ 1
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example1.value",
+ "property_name": "value1",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.State.On",
+ "xyz.openbmc_project.State.Off"
+ ]
+ }
+ },
+ {
+ "containerID": 1,
+ "entityType": 64,
+ "entityInstance": 1,
+ "sensorOffset": 1,
+ "event_states": [
+ 2,
+ 3
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example2.value",
+ "property_name": "value2",
+ "property_type": "uint8_t",
+ "property_values": [
+ 9,
+ 10
+ ]
+ }
+ },
+ {
+ "containerID": 1,
+ "entityType": 67,
+ "entityInstance": 1,
+ "sensorOffset": 0,
+ "event_states": [
+ 0,
+ 1
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/ghi",
+ "interface": "xyz.openbmc_project.example3.value",
+ "property_name": "value3",
+ "property_type": "bool",
+ "property_values": [
+ false,
+ true
+ ]
+ }
+ }
+ ]
+}
diff --git a/libpldmresponder/test/event_jsons/good/event_state_sensor.json b/libpldmresponder/test/event_jsons/good/event_state_sensor.json
index f10a319..9dc613c 100644
--- a/libpldmresponder/test/event_jsons/good/event_state_sensor.json
+++ b/libpldmresponder/test/event_jsons/good/event_state_sensor.json
@@ -1,66 +1,66 @@
-{
- "entries": [
- {
- "containerID": 1,
- "entityType": 64,
- "entityInstance": 1,
- "sensorOffset": 0,
- "event_states": [
- 0,
- 1,
- 2
- ],
- "dbus": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example1.value",
- "property_name": "value1",
- "property_type": "string",
- "property_values": [
- "xyz.openbmc_project.State.Normal",
- "xyz.openbmc_project.State.Critical",
- "xyz.openbmc_project.State.Fatal"
- ]
- }
- },
- {
- "containerID": 1,
- "entityType": 64,
- "entityInstance": 1,
- "sensorOffset": 1,
- "event_states": [
- 2,
- 3
- ],
- "dbus": {
- "object_path": "/xyz/abc/def",
- "interface": "xyz.openbmc_project.example2.value",
- "property_name": "value2",
- "property_type": "uint8_t",
- "property_values": [
- 9,
- 10
- ]
- }
- },
- {
- "containerID": 2,
- "entityType": 67,
- "entityInstance": 2,
- "sensorOffset": 0,
- "event_states": [
- 0,
- 1
- ],
- "dbus": {
- "object_path": "/xyz/abc/ghi",
- "interface": "xyz.openbmc_project.example3.value",
- "property_name": "value3",
- "property_type": "bool",
- "property_values": [
- false,
- true
- ]
- }
- }
- ]
-}
+{
+ "entries": [
+ {
+ "containerID": 1,
+ "entityType": 64,
+ "entityInstance": 1,
+ "sensorOffset": 0,
+ "event_states": [
+ 0,
+ 1,
+ 2
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example1.value",
+ "property_name": "value1",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.State.Normal",
+ "xyz.openbmc_project.State.Critical",
+ "xyz.openbmc_project.State.Fatal"
+ ]
+ }
+ },
+ {
+ "containerID": 1,
+ "entityType": 64,
+ "entityInstance": 1,
+ "sensorOffset": 1,
+ "event_states": [
+ 2,
+ 3
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/def",
+ "interface": "xyz.openbmc_project.example2.value",
+ "property_name": "value2",
+ "property_type": "uint8_t",
+ "property_values": [
+ 9,
+ 10
+ ]
+ }
+ },
+ {
+ "containerID": 2,
+ "entityType": 67,
+ "entityInstance": 2,
+ "sensorOffset": 0,
+ "event_states": [
+ 0,
+ 1
+ ],
+ "dbus": {
+ "object_path": "/xyz/abc/ghi",
+ "interface": "xyz.openbmc_project.example3.value",
+ "property_name": "value3",
+ "property_type": "bool",
+ "property_values": [
+ false,
+ true
+ ]
+ }
+ }
+ ]
+}
diff --git a/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json b/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
index e7ddc2b..b32f207 100644
--- a/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
+++ b/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
@@ -1,48 +1,48 @@
-{
- "entries": [
- {
- "containerID": 0,
- "entityType": 57346,
- "entityInstance": 0,
- "sensorOffset": 1,
- "event_states": [
- 1,
- 2,
- 3
- ],
- "dbus": {
- "object_path": "/xyz/openbmc_project/network/hypervisor/eth0/ipv4/addr0",
- "interface": "xyz.openbmc_project.Object.Enable",
- "property_name": "Enabled",
- "property_type": "bool",
- "property_values": [
- true,
- false,
- false
- ]
- }
- },
- {
- "containerID": 0,
- "entityType": 57346,
- "entityInstance": 1,
- "sensorOffset": 1,
- "event_states": [
- 1,
- 2,
- 3
- ],
- "dbus": {
- "object_path": "/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0",
- "interface": "xyz.openbmc_project.Object.Enable",
- "property_name": "Enabled",
- "property_type": "bool",
- "property_values": [
- true,
- false,
- false
- ]
- }
- }
- ]
-}
+{
+ "entries": [
+ {
+ "containerID": 0,
+ "entityType": 57346,
+ "entityInstance": 0,
+ "sensorOffset": 1,
+ "event_states": [
+ 1,
+ 2,
+ 3
+ ],
+ "dbus": {
+ "object_path": "/xyz/openbmc_project/network/hypervisor/eth0/ipv4/addr0",
+ "interface": "xyz.openbmc_project.Object.Enable",
+ "property_name": "Enabled",
+ "property_type": "bool",
+ "property_values": [
+ true,
+ false,
+ false
+ ]
+ }
+ },
+ {
+ "containerID": 0,
+ "entityType": 57346,
+ "entityInstance": 1,
+ "sensorOffset": 1,
+ "event_states": [
+ 1,
+ 2,
+ 3
+ ],
+ "dbus": {
+ "object_path": "/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0",
+ "interface": "xyz.openbmc_project.Object.Enable",
+ "property_name": "Enabled",
+ "property_type": "bool",
+ "property_values": [
+ true,
+ false,
+ false
+ ]
+ }
+ }
+ ]
+}
diff --git a/oem/ibm/libpldm/platform_oem_ibm.c b/oem/ibm/libpldm/platform_oem_ibm.c
index 7090f95..db7090a 100644
--- a/oem/ibm/libpldm/platform_oem_ibm.c
+++ b/oem/ibm/libpldm/platform_oem_ibm.c
@@ -1,50 +1,50 @@
-#include "platform_oem_ibm.h"
-#include "platform.h"
-#include <string.h>
-
-int encode_bios_attribute_update_event_req(uint8_t instance_id,
- uint8_t format_version, uint8_t tid,
- uint8_t num_handles,
- const uint8_t *list_of_handles,
- size_t payload_length,
- struct pldm_msg *msg)
-{
- if (format_version != 1) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (msg == NULL || list_of_handles == NULL) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (num_handles == 0) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- if (payload_length !=
- (PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(num_handles) +
- (num_handles * sizeof(uint16_t)))) {
- return PLDM_ERROR_INVALID_LENGTH;
- }
-
- struct pldm_header_info header = {0};
- header.msg_type = PLDM_REQUEST;
- header.instance = instance_id;
- header.pldm_type = PLDM_PLATFORM;
- header.command = PLDM_PLATFORM_EVENT_MESSAGE;
- uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
- if (rc != PLDM_SUCCESS) {
- return rc;
- }
-
- struct pldm_bios_attribute_update_event_req *request =
- (struct pldm_bios_attribute_update_event_req *)msg->payload;
- request->format_version = format_version;
- request->tid = tid;
- request->event_class = PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE;
- request->num_handles = num_handles;
- memcpy(request->bios_attribute_handles, list_of_handles,
- num_handles * sizeof(uint16_t));
-
- return PLDM_SUCCESS;
+#include "platform_oem_ibm.h"
+#include "platform.h"
+#include <string.h>
+
+int encode_bios_attribute_update_event_req(uint8_t instance_id,
+ uint8_t format_version, uint8_t tid,
+ uint8_t num_handles,
+ const uint8_t *list_of_handles,
+ size_t payload_length,
+ struct pldm_msg *msg)
+{
+ if (format_version != 1) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (msg == NULL || list_of_handles == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (num_handles == 0) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length !=
+ (PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(num_handles) +
+ (num_handles * sizeof(uint16_t)))) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_REQUEST;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_PLATFORM;
+ header.command = PLDM_PLATFORM_EVENT_MESSAGE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
+ return rc;
+ }
+
+ struct pldm_bios_attribute_update_event_req *request =
+ (struct pldm_bios_attribute_update_event_req *)msg->payload;
+ request->format_version = format_version;
+ request->tid = tid;
+ request->event_class = PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE;
+ request->num_handles = num_handles;
+ memcpy(request->bios_attribute_handles, list_of_handles,
+ num_handles * sizeof(uint16_t));
+
+ return PLDM_SUCCESS;
}
\ No newline at end of file
diff --git a/oem/ibm/libpldm/platform_oem_ibm.h b/oem/ibm/libpldm/platform_oem_ibm.h
index 7d918e7..f0aafd3 100644
--- a/oem/ibm/libpldm/platform_oem_ibm.h
+++ b/oem/ibm/libpldm/platform_oem_ibm.h
@@ -1,56 +1,56 @@
-#ifndef PLATFORM_OEM_IBM_H
-#define PLATFORM_OEM_IBM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "base.h"
-#include <stddef.h>
-#include <stdint.h>
-
-enum pldm_event_types_ibm_oem {
- PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE = 0xF0,
-};
-
-/** @struct pldm_bios_attribute_update_event_req
- *
- * Structure representing PlatformEventMessage command request data for OEM
- * event type BIOS attribute update.
- */
-struct pldm_bios_attribute_update_event_req {
- uint8_t format_version;
- uint8_t tid;
- uint8_t event_class;
- uint8_t num_handles;
- uint8_t bios_attribute_handles[1];
-} __attribute__((packed));
-
-/** @brief Encode PlatformEventMessage request data for BIOS attribute update
- *
- * @param[in] instance_id - Message's instance id
- * @param[in] format_version - Version of the event format
- * @param[in] tid - Terminus ID for the terminus that originated the event
- * message
- * @param[in] num_handles - Number of BIOS handles with an update
- * @param[in] list_of_handles - Pointer to the list of BIOS attribute handles
- * @param[in] payload_length - Length of request message payload
- * @param[out] msg - Message will be written to this
- *
- * @return pldm_completion_codes
- *
- * @note Caller is responsible for memory alloc and dealloc of param
- * 'msg.payload'
- */
-int encode_bios_attribute_update_event_req(uint8_t instance_id,
- uint8_t format_version, uint8_t tid,
- uint8_t num_handles,
- const uint8_t *list_of_handles,
- size_t payload_length,
- struct pldm_msg *msg);
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifndef PLATFORM_OEM_IBM_H
+#define PLATFORM_OEM_IBM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "base.h"
+#include <stddef.h>
+#include <stdint.h>
+
+enum pldm_event_types_ibm_oem {
+ PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE = 0xF0,
+};
+
+/** @struct pldm_bios_attribute_update_event_req
+ *
+ * Structure representing PlatformEventMessage command request data for OEM
+ * event type BIOS attribute update.
+ */
+struct pldm_bios_attribute_update_event_req {
+ uint8_t format_version;
+ uint8_t tid;
+ uint8_t event_class;
+ uint8_t num_handles;
+ uint8_t bios_attribute_handles[1];
+} __attribute__((packed));
+
+/** @brief Encode PlatformEventMessage request data for BIOS attribute update
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] format_version - Version of the event format
+ * @param[in] tid - Terminus ID for the terminus that originated the event
+ * message
+ * @param[in] num_handles - Number of BIOS handles with an update
+ * @param[in] list_of_handles - Pointer to the list of BIOS attribute handles
+ * @param[in] payload_length - Length of request message payload
+ * @param[out] msg - Message will be written to this
+ *
+ * @return pldm_completion_codes
+ *
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_bios_attribute_update_event_req(uint8_t instance_id,
+ uint8_t format_version, uint8_t tid,
+ uint8_t num_handles,
+ const uint8_t *list_of_handles,
+ size_t payload_length,
+ struct pldm_msg *msg);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* PLATFORM_OEM_IBM_H */
\ No newline at end of file
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 0ae1adb..a8d070e 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -1,117 +1,117 @@
-#include "platform_oem_ibm.hpp"
-
-#include "libpldm/platform_oem_ibm.h"
-#include "libpldm/requester/pldm.h"
-
-#include "common/utils.hpp"
-#include "libpldmresponder/pdr.hpp"
-
-#include <iostream>
-
-namespace pldm
-{
-namespace responder
-{
-namespace platform
-{
-
-int sendBiosAttributeUpdateEvent(
- uint8_t eid, dbus_api::Requester* requester,
- const std::vector<uint16_t>& handles,
- pldm::requester::Handler<pldm::requester::Request>* handler)
-{
- constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
- constexpr auto hostStateInterface =
- "xyz.openbmc_project.State.Boot.Progress";
- constexpr auto hostStateProperty = "BootProgress";
-
- try
- {
- auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
- hostStatePath, hostStateProperty, hostStateInterface);
- const auto& currHostState = std::get<std::string>(propVal);
- if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
- "ProgressStages.SystemInitComplete") &&
- (currHostState != "xyz.openbmc_project.State.Boot.Progress."
- "ProgressStages.OSRunning") &&
- (currHostState != "xyz.openbmc_project.State.Boot.Progress."
- "ProgressStages.OSStart"))
- {
- return PLDM_SUCCESS;
- }
- }
- catch (const sdbusplus::exception::SdBusError& e)
- {
- std::cerr << "Error in getting current host state, continue ... \n";
- }
-
- auto instanceId = requester->getInstanceId(eid);
-
- std::vector<uint8_t> requestMsg(
- sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
- 1 + (handles.size() * sizeof(uint16_t)),
- 0);
-
- auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
-
- auto rc = encode_bios_attribute_update_event_req(
- instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION,
- pldm::responder::pdr::BmcMctpEid, handles.size(),
- reinterpret_cast<const uint8_t*>(handles.data()),
- requestMsg.size() - sizeof(pldm_msg_hdr), request);
- if (rc != PLDM_SUCCESS)
- {
- std::cerr << "Message encode failure 1. PLDM error code = " << std::hex
- << std::showbase << rc << "\n";
- requester->markFree(eid, instanceId);
- return rc;
- }
-
- if (requestMsg.size())
- {
- std::ostringstream tempStream;
- for (int byte : requestMsg)
- {
- tempStream << std::setfill('0') << std::setw(2) << std::hex << byte
- << " ";
- }
- std::cout << tempStream.str() << std::endl;
- }
-
- auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
- const pldm_msg* response,
- size_t respMsgLen) {
- if (response == nullptr || !respMsgLen)
- {
- std::cerr
- << "Failed to receive response for platform event message \n";
- return;
- }
- uint8_t completionCode{};
- uint8_t status{};
- auto rc = decode_platform_event_message_resp(response, respMsgLen,
- &completionCode, &status);
- if (rc || completionCode)
- {
- std::cerr << "Failed to decode_platform_event_message_resp: "
- << "rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
- }
- };
- rc = handler->registerRequest(
- eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
- std::move(requestMsg), std::move(platformEventMessageResponseHandler));
- if (rc)
- {
- std::cerr << "Failed to send the platform event message \n";
- }
-
- return rc;
-}
-
-} // namespace platform
-
-} // namespace responder
-
-} // namespace pldm
+#include "platform_oem_ibm.hpp"
+
+#include "libpldm/platform_oem_ibm.h"
+#include "libpldm/requester/pldm.h"
+
+#include "common/utils.hpp"
+#include "libpldmresponder/pdr.hpp"
+
+#include <iostream>
+
+namespace pldm
+{
+namespace responder
+{
+namespace platform
+{
+
+int sendBiosAttributeUpdateEvent(
+ uint8_t eid, dbus_api::Requester* requester,
+ const std::vector<uint16_t>& handles,
+ pldm::requester::Handler<pldm::requester::Request>* handler)
+{
+ constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
+ constexpr auto hostStateInterface =
+ "xyz.openbmc_project.State.Boot.Progress";
+ constexpr auto hostStateProperty = "BootProgress";
+
+ try
+ {
+ auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
+ hostStatePath, hostStateProperty, hostStateInterface);
+ const auto& currHostState = std::get<std::string>(propVal);
+ if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
+ "ProgressStages.SystemInitComplete") &&
+ (currHostState != "xyz.openbmc_project.State.Boot.Progress."
+ "ProgressStages.OSRunning") &&
+ (currHostState != "xyz.openbmc_project.State.Boot.Progress."
+ "ProgressStages.OSStart"))
+ {
+ return PLDM_SUCCESS;
+ }
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ std::cerr << "Error in getting current host state, continue ... \n";
+ }
+
+ auto instanceId = requester->getInstanceId(eid);
+
+ std::vector<uint8_t> requestMsg(
+ sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
+ 1 + (handles.size() * sizeof(uint16_t)),
+ 0);
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_bios_attribute_update_event_req(
+ instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION,
+ pldm::responder::pdr::BmcMctpEid, handles.size(),
+ reinterpret_cast<const uint8_t*>(handles.data()),
+ requestMsg.size() - sizeof(pldm_msg_hdr), request);
+ if (rc != PLDM_SUCCESS)
+ {
+ std::cerr << "Message encode failure 1. PLDM error code = " << std::hex
+ << std::showbase << rc << "\n";
+ requester->markFree(eid, instanceId);
+ return rc;
+ }
+
+ if (requestMsg.size())
+ {
+ std::ostringstream tempStream;
+ for (int byte : requestMsg)
+ {
+ tempStream << std::setfill('0') << std::setw(2) << std::hex << byte
+ << " ";
+ }
+ std::cout << tempStream.str() << std::endl;
+ }
+
+ auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
+ const pldm_msg* response,
+ size_t respMsgLen) {
+ if (response == nullptr || !respMsgLen)
+ {
+ std::cerr
+ << "Failed to receive response for platform event message \n";
+ return;
+ }
+ uint8_t completionCode{};
+ uint8_t status{};
+ auto rc = decode_platform_event_message_resp(response, respMsgLen,
+ &completionCode, &status);
+ if (rc || completionCode)
+ {
+ std::cerr << "Failed to decode_platform_event_message_resp: "
+ << "rc=" << rc
+ << ", cc=" << static_cast<unsigned>(completionCode)
+ << std::endl;
+ }
+ };
+ rc = handler->registerRequest(
+ eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
+ std::move(requestMsg), std::move(platformEventMessageResponseHandler));
+ if (rc)
+ {
+ std::cerr << "Failed to send the platform event message \n";
+ }
+
+ return rc;
+}
+
+} // namespace platform
+
+} // namespace responder
+
+} // namespace pldm
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.hpp b/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
index 6f3a320..94dc2dd 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
@@ -1,36 +1,36 @@
-#pragma once
-
-#include "pldmd/dbus_impl_requester.hpp"
-#include "requester/handler.hpp"
-
-#include <vector>
-
-namespace pldm
-{
-namespace responder
-{
-namespace platform
-{
-
-/** @brief To send BIOS attribute update event
- *
- * When the attribute value changes for any BIOS attribute, then
- * PlatformEventMessage command with OEM event type
- * PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE is send to host with the
- * list of BIOS attribute handles.
- *
- * @param[in] eid - MCTP EID of host firmware
- * @param[in] requester - pointer to Requester object
- * @param[in] handles - List of BIOS attribute handles
- * @param[in] handler - PLDM request handler
- */
-int sendBiosAttributeUpdateEvent(
- uint8_t eid, dbus_api::Requester* requester,
- const std::vector<uint16_t>& handles,
- pldm::requester::Handler<pldm::requester::Request>* handler);
-
-} // namespace platform
-
-} // namespace responder
-
-} // namespace pldm
+#pragma once
+
+#include "pldmd/dbus_impl_requester.hpp"
+#include "requester/handler.hpp"
+
+#include <vector>
+
+namespace pldm
+{
+namespace responder
+{
+namespace platform
+{
+
+/** @brief To send BIOS attribute update event
+ *
+ * When the attribute value changes for any BIOS attribute, then
+ * PlatformEventMessage command with OEM event type
+ * PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE is send to host with the
+ * list of BIOS attribute handles.
+ *
+ * @param[in] eid - MCTP EID of host firmware
+ * @param[in] requester - pointer to Requester object
+ * @param[in] handles - List of BIOS attribute handles
+ * @param[in] handler - PLDM request handler
+ */
+int sendBiosAttributeUpdateEvent(
+ uint8_t eid, dbus_api::Requester* requester,
+ const std::vector<uint16_t>& handles,
+ pldm::requester::Handler<pldm::requester::Request>* handler);
+
+} // namespace platform
+
+} // namespace responder
+
+} // namespace pldm