OEM-IBM: Implement encode & decode APIs for NewFileAvailableWithMetaData.
This commit implements requester and responder flow for
NewFileAvailableWithMetaData.
Tested: Unit tests passed.
Change-Id: I3dbcdd354a9e89529125125333aa413c733daf3c
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/oem/ibm/libpldm/file_io.c b/oem/ibm/libpldm/file_io.c
index 6c045a9..fae3a9c 100644
--- a/oem/ibm/libpldm/file_io.c
+++ b/oem/ibm/libpldm/file_io.c
@@ -942,3 +942,115 @@
return PLDM_SUCCESS;
}
+
+int encode_new_file_with_metadata_req(
+ uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
+ uint64_t length, uint32_t file_meta_data_1, uint32_t file_meta_data_2,
+ uint32_t file_meta_data_3, uint32_t file_meta_data_4, struct pldm_msg *msg)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_REQUEST;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
+ return rc;
+ }
+
+ struct pldm_new_file_with_metadata_req *req =
+ (struct pldm_new_file_with_metadata_req *)msg->payload;
+ req->file_type = htole16(file_type);
+ req->file_handle = htole32(file_handle);
+ req->length = htole64(length);
+ req->file_meta_data_1 = htole32(file_meta_data_1);
+ req->file_meta_data_2 = htole32(file_meta_data_2);
+ req->file_meta_data_3 = htole32(file_meta_data_3);
+ req->file_meta_data_4 = htole32(file_meta_data_4);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_new_file_with_metadata_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 !=
+ PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_new_file_with_metadata_resp *response =
+ (struct pldm_new_file_with_metadata_resp *)msg->payload;
+
+ *completion_code = msg->payload[0];
+ if (*completion_code == PLDM_SUCCESS) {
+ *completion_code = response->completion_code;
+ }
+ return PLDM_SUCCESS;
+}
+
+int decode_new_file_with_metadata_req(
+ const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
+ uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1,
+ uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
+ uint32_t *file_meta_data_4)
+{
+ if (msg == NULL || file_type == NULL || file_handle == NULL ||
+ length == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length !=
+ PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_new_file_with_metadata_req *request =
+ (struct pldm_new_file_with_metadata_req *)msg->payload;
+ *file_type = le16toh(request->file_type);
+ *file_handle = le32toh(request->file_handle);
+ *length = le64toh(request->length);
+ *file_meta_data_1 = le32toh(request->file_meta_data_1);
+ *file_meta_data_2 = le32toh(request->file_meta_data_2);
+ *file_meta_data_3 = le32toh(request->file_meta_data_3);
+ *file_meta_data_4 = le32toh(request->file_meta_data_4);
+
+ return PLDM_SUCCESS;
+}
+
+int encode_new_file_with_metadata_resp(uint8_t instance_id,
+ uint8_t completion_code,
+ struct pldm_msg *msg)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_RESPONSE;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
+ return rc;
+ }
+
+ struct pldm_new_file_with_metadata_resp *response =
+ (struct pldm_new_file_with_metadata_resp *)msg->payload;
+
+ if (response->completion_code == PLDM_SUCCESS) {
+ response->completion_code = completion_code;
+ }
+
+ return PLDM_SUCCESS;
+}
diff --git a/oem/ibm/libpldm/file_io.h b/oem/ibm/libpldm/file_io.h
index 72892da..e5765a6 100644
--- a/oem/ibm/libpldm/file_io.h
+++ b/oem/ibm/libpldm/file_io.h
@@ -79,6 +79,8 @@
#define PLDM_FILE_ACK_RESP_BYTES 1
#define PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES 23
#define PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES 1
+#define PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES 30
+#define PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES 1
/** @struct pldm_read_write_file_memory_req
*
@@ -805,6 +807,91 @@
uint8_t completion_code,
struct pldm_msg *msg);
+/* NewFileAvailableWithMetaData */
+
+/** @struct pldm_new_file_with_metadata_req
+ *
+ * Structure representing NewFileAvailableWithMetaData request
+ */
+
+struct pldm_new_file_with_metadata_req {
+ uint16_t file_type; //!< Type of file
+ uint32_t file_handle; //!< Handle to file
+ uint64_t length; //!< Number of bytes in new file
+ uint32_t file_meta_data_1; //!< Meta data specific to file type 1
+ uint32_t file_meta_data_2; //!< Meta data specific to file type 2
+ uint32_t file_meta_data_3; //!< Meta data specific to file type 3
+ uint32_t file_meta_data_4; //!< Meta data specific to file type 4
+} __attribute__((packed));
+
+/** @struct pldm_new_file_with_metadata_resp
+ *
+ * Structure representing NewFileAvailableWithMetaData response data
+ */
+struct pldm_new_file_with_metadata_resp {
+ uint8_t completion_code; //!< Completion code
+} __attribute__((packed));
+
+/** @brief Encode NewFileAvailableWithMetaData request data
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] file_type - Type of the file
+ * @param[in] file_handle - A handle to the file
+ * @param[in] length - Number of bytes in new file
+ * @param[in] file_meta_data_1 - Meta data specific to file type 1
+ * @param[in] file_meta_data_2 - Meta data specific to file type 2
+ * @param[in] file_meta_data_3 - Meta data specific to file type 3
+ * @param[in] file_meta_data_4 - Meta data specific to file type 4
+ * @param[out] msg - Message will be written to this
+ * @return pldm_completion_codes
+ */
+int encode_new_file_with_metadata_req(
+ uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
+ uint64_t length, uint32_t file_meta_data_1, uint32_t file_meta_data_2,
+ uint32_t file_meta_data_3, uint32_t file_meta_data_4, struct pldm_msg *msg);
+
+/** @brief Decode NewFileAvailableWithMetaData response data
+ *
+ * @param[in] msg - pointer to PLDM response message
+ * @param[in] payload_length - Length of response payload
+ * @param[out] completion_code - PLDM completion code
+ * @return pldm_completion_codes
+ */
+int decode_new_file_with_metadata_resp(const struct pldm_msg *msg,
+ size_t payload_length,
+ uint8_t *completion_code);
+
+/** @brief Decode NewFileAvailableWithMetaData request data
+ *
+ * @param[in] msg - Pointer to PLDM request message
+ * @param[in] payload_length - Length of request payload
+ * @param[out] file_type - Type of the file
+ * @param[out] file_handle - A handle to the file
+ * @param[out] length - Number of bytes in new file
+ * @param[out] file_meta_data_1 - Meta data specific to file type 1
+ * @param[out] file_meta_data_2 - Meta data specific to file type 2
+ * @param[out] file_meta_data_3 - Meta data specific to file type 3
+ * @param[out] file_meta_data_4 - Meta data specific to file type 4
+ * @return pldm_completion_codes
+ */
+int decode_new_file_with_metadata_req(
+ const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
+ uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1,
+ uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
+ uint32_t *file_meta_data_4);
+
+/** @brief Create a PLDM response for NewFileAvailableWithMetaData
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - PLDM completion code
+ * @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_new_file_with_metadata_resp(uint8_t instance_id,
+ uint8_t completion_code,
+ struct pldm_msg *msg);
+
#ifdef __cplusplus
}
#endif