Enable IBM PLDM OEM commands support
Create folder structure (oem/ibm) for ibm pldm oem commands. Move the
files from the ibm-pldm-oem repo [https://github.com/openbmc/ibm-pldm-oem]
to the folder oem/ibm/ under the pldm repo and enable conditional
compilation for it. The test files are also conditionally compiled.
You would need to provide --enable-oem-ibm to configure.
This is done to simplify the build time and runtime dependencies between the
standard and oem implementations.
Signed-off-by: Jinu Joy Thomas <jinu.joy.thomas@in.ibm.com>
Change-Id: Iaa93c73faff87290e3d3d5d155d9ecae6e7ee6f9
diff --git a/oem/ibm/libpldm/.clang-format b/oem/ibm/libpldm/.clang-format
new file mode 100644
index 0000000..a3ef233
--- /dev/null
+++ b/oem/ibm/libpldm/.clang-format
@@ -0,0 +1,6 @@
+BasedOnStyle: LLVM
+IndentWidth: 8
+UseTab: Always
+BreakBeforeBraces: Linux
+AllowShortIfStatementsOnASingleLine: false
+IndentCaseLabels: false
diff --git a/oem/ibm/libpldm/file_io.c b/oem/ibm/libpldm/file_io.c
new file mode 100644
index 0000000..ca33cef
--- /dev/null
+++ b/oem/ibm/libpldm/file_io.c
@@ -0,0 +1,54 @@
+#include "file_io.h"
+#include <endian.h>
+#include <string.h>
+
+int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
+ uint32_t *file_handle, uint32_t *offset,
+ uint32_t *length, uint64_t *address)
+{
+ if (msg == NULL || file_handle == NULL || offset == NULL ||
+ length == NULL || address == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ *file_handle = le32toh(*((uint32_t *)msg));
+ *offset = le32toh(*((uint32_t *)(msg + sizeof(*file_handle))));
+ *length = le32toh(
+ *((uint32_t *)(msg + sizeof(*file_handle) + sizeof(*offset))));
+ *address = le64toh(*((uint64_t *)(msg + sizeof(*file_handle) +
+ sizeof(*offset) + sizeof(*length))));
+
+ return PLDM_SUCCESS;
+}
+
+int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
+ uint8_t completion_code, uint32_t length,
+ struct pldm_msg *msg)
+{
+ struct pldm_header_info header = {0};
+ int rc = PLDM_SUCCESS;
+
+ uint8_t *payload = msg->payload;
+ *payload = completion_code;
+
+ header.msg_type = PLDM_RESPONSE;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_IBM_OEM_TYPE;
+ header.command = command;
+
+ if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ return rc;
+ }
+
+ if (msg->payload[0] == PLDM_SUCCESS) {
+ uint8_t *dst = msg->payload + sizeof(completion_code);
+ length = htole32(length);
+ memcpy(dst, &length, sizeof(length));
+ }
+
+ return PLDM_SUCCESS;
+}
diff --git a/oem/ibm/libpldm/file_io.h b/oem/ibm/libpldm/file_io.h
new file mode 100644
index 0000000..345b363
--- /dev/null
+++ b/oem/ibm/libpldm/file_io.h
@@ -0,0 +1,70 @@
+#ifndef FILEIO_H
+#define FILEIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base.h"
+
+#define PLDM_IBM_OEM_TYPE 0x3F
+
+/** @brief PLDM Commands in IBM OEM type
+ */
+enum pldm_fileio_commands {
+ PLDM_READ_FILE_INTO_MEMORY = 0x6,
+ PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
+};
+
+/** @brief PLDM Command specific codes
+ */
+enum pldm_fileio_completion_codes {
+ PLDM_INVALID_FILE_HANDLE = 0x80,
+ PLDM_DATA_OUT_OF_RANGE = 0x81,
+ PLDM_INVALID_READ_LENGTH = 0x82,
+ PLDM_INVALID_WRITE_LENGTH = 0x83,
+};
+
+#define PLDM_RW_FILE_MEM_REQ_BYTES 20
+#define PLDM_RW_FILE_MEM_RESP_BYTES 5
+
+/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
+ * data
+ *
+ * @param[in] msg - Pointer to PLDM request message payload
+ * @param[in] payload_length - Length of request payload
+ * @param[out] file_handle - A handle to the file
+ * @param[out] offset - Offset to the file at which the read should begin
+ * @param[out] length - Number of bytes to be read
+ * @param[out] address - Memory address where the file content has to be
+ * written to
+ * @return pldm_completion_codes
+ */
+int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
+ uint32_t *file_handle, uint32_t *offset,
+ uint32_t *length, uint64_t *address);
+
+/** @brief Create a PLDM response for ReadFileIntoMemory and
+ * WriteFileFromMemory
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] command - PLDM command
+ * @param[in] completion_code - PLDM completion code
+ * @param[in] length - Number of bytes read. This could be less than what the
+ requester asked for.
+ * @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'
+ */
+int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
+ uint8_t completion_code, uint32_t length,
+ struct pldm_msg *msg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FILEIO_H */