Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 1 | #ifndef FILEIO_H |
| 2 | #define FILEIO_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | #include "base.h" |
| 12 | |
| 13 | #define PLDM_IBM_OEM_TYPE 0x3F |
| 14 | |
| 15 | /** @brief PLDM Commands in IBM OEM type |
| 16 | */ |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 17 | enum pldm_fileio_commands { |
Tom Joseph | 61325fa | 2019-06-04 15:22:22 +0530 | [diff] [blame] | 18 | PLDM_GET_FILE_TABLE = 0x1, |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 19 | PLDM_READ_FILE_INTO_MEMORY = 0x6, |
| 20 | PLDM_WRITE_FILE_FROM_MEMORY = 0x7, |
| 21 | }; |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 22 | |
| 23 | /** @brief PLDM Command specific codes |
| 24 | */ |
| 25 | enum pldm_fileio_completion_codes { |
| 26 | PLDM_INVALID_FILE_HANDLE = 0x80, |
| 27 | PLDM_DATA_OUT_OF_RANGE = 0x81, |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 28 | PLDM_INVALID_READ_LENGTH = 0x82, |
| 29 | PLDM_INVALID_WRITE_LENGTH = 0x83, |
Tom Joseph | 61325fa | 2019-06-04 15:22:22 +0530 | [diff] [blame] | 30 | PLDM_FILE_TABLE_UNAVAILABLE = 0x84, |
| 31 | PLDM_INVALID_FILE_TABLE_TYPE = 0x85, |
| 32 | }; |
| 33 | |
| 34 | /** @brief PLDM File I/O table types |
| 35 | */ |
| 36 | enum pldm_fileio_table_type { |
| 37 | PLDM_FILE_ATTRIBUTE_TABLE = 0, |
| 38 | PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1, |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 39 | }; |
| 40 | |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 41 | #define PLDM_RW_FILE_MEM_REQ_BYTES 20 |
| 42 | #define PLDM_RW_FILE_MEM_RESP_BYTES 5 |
Tom Joseph | 61325fa | 2019-06-04 15:22:22 +0530 | [diff] [blame] | 43 | #define PLDM_GET_FILE_TABLE_REQ_BYTES 6 |
| 44 | #define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6 |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 45 | |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 46 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request |
| 47 | * data |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 48 | * |
| 49 | * @param[in] msg - Pointer to PLDM request message payload |
| 50 | * @param[in] payload_length - Length of request payload |
| 51 | * @param[out] file_handle - A handle to the file |
| 52 | * @param[out] offset - Offset to the file at which the read should begin |
| 53 | * @param[out] length - Number of bytes to be read |
| 54 | * @param[out] address - Memory address where the file content has to be |
| 55 | * written to |
| 56 | * @return pldm_completion_codes |
| 57 | */ |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 58 | int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length, |
| 59 | uint32_t *file_handle, uint32_t *offset, |
| 60 | uint32_t *length, uint64_t *address); |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 61 | |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 62 | /** @brief Create a PLDM response for ReadFileIntoMemory and |
| 63 | * WriteFileFromMemory |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 64 | * |
| 65 | * @param[in] instance_id - Message's instance id |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 66 | * @param[in] command - PLDM command |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 67 | * @param[in] completion_code - PLDM completion code |
| 68 | * @param[in] length - Number of bytes read. This could be less than what the |
| 69 | requester asked for. |
| 70 | * @param[in,out] msg - Message will be written to this |
| 71 | * @return pldm_completion_codes |
| 72 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 73 | */ |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 74 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 75 | uint8_t completion_code, uint32_t length, |
| 76 | struct pldm_msg *msg); |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 77 | |
Tom Joseph | 61325fa | 2019-06-04 15:22:22 +0530 | [diff] [blame] | 78 | /** @struct pldm_get_file_table_req |
| 79 | * |
| 80 | * Structure representing GetFileTable request |
| 81 | */ |
| 82 | struct pldm_get_file_table_req { |
| 83 | uint32_t transfer_handle; //!< Data transfer handle |
| 84 | uint8_t operation_flag; //!< Transfer operation flag |
| 85 | uint8_t table_type; //!< Table type |
| 86 | } __attribute__((packed)); |
| 87 | |
| 88 | /** @struct pldm_get_file_table_resp |
| 89 | * |
| 90 | * Structure representing GetFileTable response fixed data |
| 91 | */ |
| 92 | struct pldm_get_file_table_resp { |
| 93 | uint8_t completion_code; //!< Completion code |
| 94 | uint32_t next_transfer_handle; //!< Next data transfer handle |
| 95 | uint8_t transfer_flag; //!< Transfer flag |
| 96 | uint8_t table_data[1]; //!< Table Data |
| 97 | } __attribute__((packed)); |
| 98 | |
| 99 | /** @brief Decode GetFileTable command request data |
| 100 | * |
| 101 | * @param[in] msg - Pointer to PLDM request message payload |
| 102 | * @param[in] payload_length - Length of request payload |
| 103 | * @param[out] trasnfer_handle - the handle of data |
| 104 | * @param[out] transfer_opflag - Transfer operation flag |
| 105 | * @param[out] table_type - the type of file table |
| 106 | * @return pldm_completion_codes |
| 107 | */ |
| 108 | int decode_get_file_table_req(const uint8_t *msg, size_t payload_length, |
| 109 | uint32_t *transfer_handle, |
| 110 | uint8_t *transfer_opflag, uint8_t *table_type); |
| 111 | |
| 112 | /** @brief Create a PLDM response for GetFileTable command |
| 113 | * |
| 114 | * @param[in] instance_id - Message's instance id |
| 115 | * @param[in] completion_code - PLDM completion code |
| 116 | * @param[in] next_transfer_handle - Handle to identify next portion of |
| 117 | * data transfer |
| 118 | * @param[in] transfer_flag - Represents the part of transfer |
| 119 | * @param[in] table_data - pointer to file table data |
| 120 | * @param[in] table_size - file table size |
| 121 | * @param[in,out] msg - Message will be written to this |
| 122 | * @return pldm_completion_codes |
| 123 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 124 | */ |
| 125 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 126 | uint32_t next_transfer_handle, |
| 127 | uint8_t transfer_flag, const uint8_t *table_data, |
| 128 | size_t table_size, struct pldm_msg *msg); |
| 129 | |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 130 | #ifdef __cplusplus |
| 131 | } |
| 132 | #endif |
| 133 | |
| 134 | #endif /* FILEIO_H */ |