Sync ibm-pldm-oem repository changes to pldm repository

Change-Id: I6f30b39f483647ad84fe2fbe1c24298841040801
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/oem/ibm/libpldm/file_io.c b/oem/ibm/libpldm/file_io.c
index 2fa3034..a415414 100644
--- a/oem/ibm/libpldm/file_io.c
+++ b/oem/ibm/libpldm/file_io.c
@@ -52,3 +52,56 @@
 
 	return PLDM_SUCCESS;
 }
+
+int decode_get_file_table_req(const uint8_t *msg, size_t payload_length,
+			      uint32_t *transfer_handle,
+			      uint8_t *transfer_opflag, uint8_t *table_type)
+{
+	if (msg == NULL || transfer_handle == NULL || transfer_opflag == NULL ||
+	    table_type == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	if (payload_length != PLDM_GET_FILE_TABLE_REQ_BYTES) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
+
+	struct pldm_get_file_table_req *request =
+	    (struct pldm_get_file_table_req *)msg;
+
+	*transfer_handle = le32toh(request->transfer_handle);
+	*transfer_opflag = request->operation_flag;
+	*table_type = request->table_type;
+
+	return PLDM_SUCCESS;
+}
+
+int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
+			       uint32_t next_transfer_handle,
+			       uint8_t transfer_flag, const uint8_t *table_data,
+			       size_t table_size, struct pldm_msg *msg)
+{
+	struct pldm_header_info header = {0};
+	int rc = PLDM_SUCCESS;
+
+	header.msg_type = PLDM_RESPONSE;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_OEM;
+	header.command = PLDM_GET_FILE_TABLE;
+
+	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+		return rc;
+	}
+
+	struct pldm_get_file_table_resp *response =
+	    (struct pldm_get_file_table_resp *)msg->payload;
+	response->completion_code = completion_code;
+
+	if (completion_code == PLDM_SUCCESS) {
+		response->next_transfer_handle = htole32(next_transfer_handle);
+		response->transfer_flag = transfer_flag;
+		memcpy(response->table_data, table_data, table_size);
+	}
+
+	return PLDM_SUCCESS;
+}
diff --git a/oem/ibm/libpldm/file_io.h b/oem/ibm/libpldm/file_io.h
index 79a8035..eb23332 100644
--- a/oem/ibm/libpldm/file_io.h
+++ b/oem/ibm/libpldm/file_io.h
@@ -13,6 +13,7 @@
 /** @brief PLDM Commands in IBM OEM type
  */
 enum pldm_fileio_commands {
+	PLDM_GET_FILE_TABLE = 0x1,
 	PLDM_READ_FILE_INTO_MEMORY = 0x6,
 	PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
 };
@@ -24,10 +25,21 @@
 	PLDM_DATA_OUT_OF_RANGE = 0x81,
 	PLDM_INVALID_READ_LENGTH = 0x82,
 	PLDM_INVALID_WRITE_LENGTH = 0x83,
+	PLDM_FILE_TABLE_UNAVAILABLE = 0x84,
+	PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
+};
+
+/** @brief PLDM File I/O table types
+ */
+enum pldm_fileio_table_type {
+	PLDM_FILE_ATTRIBUTE_TABLE = 0,
+	PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
 };
 
 #define PLDM_RW_FILE_MEM_REQ_BYTES 20
 #define PLDM_RW_FILE_MEM_RESP_BYTES 5
+#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
+#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
 
 /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
  *         data
@@ -61,6 +73,58 @@
 			       uint8_t completion_code, uint32_t length,
 			       struct pldm_msg *msg);
 
+/** @struct pldm_get_file_table_req
+ *
+ *  Structure representing GetFileTable request
+ */
+struct pldm_get_file_table_req {
+	uint32_t transfer_handle; //!< Data transfer handle
+	uint8_t operation_flag;   //!< Transfer operation flag
+	uint8_t table_type;       //!< Table type
+} __attribute__((packed));
+
+/** @struct pldm_get_file_table_resp
+ *
+ *  Structure representing GetFileTable response fixed data
+ */
+struct pldm_get_file_table_resp {
+	uint8_t completion_code;       //!< Completion code
+	uint32_t next_transfer_handle; //!< Next data transfer handle
+	uint8_t transfer_flag;	 //!< Transfer flag
+	uint8_t table_data[1];	 //!< Table Data
+} __attribute__((packed));
+
+/** @brief Decode GetFileTable command request data
+ *
+ *  @param[in] msg - Pointer to PLDM request message payload
+ *  @param[in] payload_length - Length of request payload
+ *  @param[out] trasnfer_handle - the handle of data
+ *  @param[out] transfer_opflag - Transfer operation flag
+ *  @param[out] table_type - the type of file table
+ *  @return pldm_completion_codes
+ */
+int decode_get_file_table_req(const uint8_t *msg, size_t payload_length,
+			      uint32_t *transfer_handle,
+			      uint8_t *transfer_opflag, uint8_t *table_type);
+
+/** @brief Create a PLDM response for GetFileTable command
+ *
+ *  @param[in] instance_id - Message's instance id
+ *  @param[in] completion_code - PLDM completion code
+ *  @param[in] next_transfer_handle - Handle to identify next portion of
+ *              data transfer
+ *  @param[in] transfer_flag - Represents the part of transfer
+ *  @param[in] table_data - pointer to file table data
+ *  @param[in] table_size - file table size
+ *  @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_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
+			       uint32_t next_transfer_handle,
+			       uint8_t transfer_flag, const uint8_t *table_data,
+			       size_t table_size, struct pldm_msg *msg);
+
 #ifdef __cplusplus
 }
 #endif