libpldm : Add encode API for QueryDeviceIdentifiers cmd
QueryDeviceIdentifiers command is used by update agent to obtain the
firmware identifiers for the fimrware device and its defined in DSP0267
Version 1.1.0 sec:10.1.
Tested: Unit tests passed
Signed-off-by: gokulsanker <gokul.sanker.v.g@intel.com>
Change-Id: I472e85414b1a04b550b88c3e6058b86efb9b89b1
diff --git a/libpldm/base.c b/libpldm/base.c
index 79f5ba5..c8369f8 100644
--- a/libpldm/base.c
+++ b/libpldm/base.c
@@ -408,3 +408,18 @@
return PLDM_SUCCESS;
}
+
+int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
+ uint8_t pldm_type, uint8_t command,
+ struct pldm_msg *msg)
+{
+ struct pldm_header_info header = {0};
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+ header.msg_type = msg_type;
+ header.instance = instance_id;
+ header.pldm_type = pldm_type;
+ header.command = command;
+ return (pack_pldm_header(&header, &(msg->hdr)));
+}
diff --git a/libpldm/base.h b/libpldm/base.h
index 4813ee6..36b9d8f 100644
--- a/libpldm/base.h
+++ b/libpldm/base.h
@@ -18,6 +18,7 @@
PLDM_PLATFORM = 0x02,
PLDM_BIOS = 0x03,
PLDM_FRU = 0x04,
+ PLDM_FWUP = 0x05,
PLDM_OEM = 0x3F,
};
@@ -480,6 +481,19 @@
int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
uint8_t cc, struct pldm_msg *msg);
+/** @brief Create a PLDM message only with the header
+ *
+ * @param[in] msg_type - PLDM message type
+ * @param[in] instance_id - Message's instance id
+ * @param[in] pldm_type - PLDM Type
+ * @param[in] command - PLDM Command
+ * @param[out] msg - Message will be written to this
+ *
+ * @return pldm_completion_codes
+ */
+int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
+ uint8_t pldm_type, uint8_t command,
+ struct pldm_msg *msg);
#ifdef __cplusplus
}
#endif
diff --git a/libpldm/firmware_update.c b/libpldm/firmware_update.c
new file mode 100644
index 0000000..25b2997
--- /dev/null
+++ b/libpldm/firmware_update.c
@@ -0,0 +1,17 @@
+#include "firmware_update.h"
+
+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);
+}
diff --git a/libpldm/firmware_update.h b/libpldm/firmware_update.h
new file mode 100644
index 0000000..dbff92d
--- /dev/null
+++ b/libpldm/firmware_update.h
@@ -0,0 +1,33 @@
+#ifndef FW_UPDATE_H
+#define FW_UPDATE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "base.h"
+
+#define PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES 0
+
+/** @brief PLDM Firmware update commands
+ */
+enum pldm_firmware_update_commands { PLDM_QUERY_DEVICE_IDENTIFIERS = 0x01 };
+
+/** @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);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // End of FW_UPDATE_H
diff --git a/libpldm/meson.build b/libpldm/meson.build
index e884f66..0d868f9 100644
--- a/libpldm/meson.build
+++ b/libpldm/meson.build
@@ -9,7 +9,8 @@
'state_set.h',
'fru.h',
'utils.h',
- 'pdr.h'
+ 'pdr.h',
+ 'firmware_update.h'
]
sources = [
@@ -19,7 +20,8 @@
'bios_table.c',
'fru.c',
'utils.c',
- 'pdr.c'
+ 'pdr.c',
+ 'firmware_update.c'
]
libpldm_headers = ['.', '..']
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/libpldm/tests/libpldm_firmware_update_test.cpp
new file mode 100644
index 0000000..8387b77
--- /dev/null
+++ b/libpldm/tests/libpldm_firmware_update_test.cpp
@@ -0,0 +1,22 @@
+#include "libpldm/base.h"
+#include "libpldm/firmware_update.h"
+
+#include <gtest/gtest.h>
+
+constexpr auto hdrSize = sizeof(pldm_msg_hdr);
+
+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);
+}
diff --git a/libpldm/tests/meson.build b/libpldm/tests/meson.build
index 607dd7d..b94959a 100644
--- a/libpldm/tests/meson.build
+++ b/libpldm/tests/meson.build
@@ -5,7 +5,8 @@
'libpldm_bios_table_test',
'libpldm_fru_test',
'libpldm_utils_test',
- 'libpldm_pdr_test'
+ 'libpldm_pdr_test',
+ 'libpldm_firmware_update_test'
]
if get_option('oem-ibm').enabled()