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 | |
Priyanga | f4736d4 | 2019-05-02 14:48:04 +0530 | [diff] [blame^] | 46 | /** @struct pldm_read_write_file_memory_req |
| 47 | * |
| 48 | * Structure representing ReadFileIntoMemory request and WriteFileFromMemory |
| 49 | * request |
| 50 | */ |
| 51 | struct pldm_read_write_file_memory_req { |
| 52 | uint32_t file_handle; //!< A Handle to the file |
| 53 | uint32_t offset; //!< Offset to the file |
| 54 | uint32_t length; //!< Number of bytes to be read/write |
| 55 | uint64_t address; //!< Memory address of the file |
| 56 | } __attribute__((packed)); |
| 57 | |
| 58 | /** @struct pldm_read_write_file_memory_resp |
| 59 | * |
| 60 | * Structure representing ReadFileIntoMemory response and WriteFileFromMemory |
| 61 | * response |
| 62 | */ |
| 63 | struct pldm_read_write_file_memory_resp { |
| 64 | uint8_t completion_code; //!< completion code |
| 65 | uint32_t length; //!< Number of bytes read/written |
| 66 | } __attribute__((packed)); |
| 67 | |
| 68 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory |
| 69 | * commands request data |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 70 | * |
| 71 | * @param[in] msg - Pointer to PLDM request message payload |
| 72 | * @param[in] payload_length - Length of request payload |
| 73 | * @param[out] file_handle - A handle to the file |
| 74 | * @param[out] offset - Offset to the file at which the read should begin |
| 75 | * @param[out] length - Number of bytes to be read |
| 76 | * @param[out] address - Memory address where the file content has to be |
| 77 | * written to |
| 78 | * @return pldm_completion_codes |
| 79 | */ |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 80 | int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length, |
| 81 | uint32_t *file_handle, uint32_t *offset, |
| 82 | uint32_t *length, uint64_t *address); |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 83 | |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 84 | /** @brief Create a PLDM response for ReadFileIntoMemory and |
| 85 | * WriteFileFromMemory |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 86 | * |
| 87 | * @param[in] instance_id - Message's instance id |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 88 | * @param[in] command - PLDM command |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 89 | * @param[in] completion_code - PLDM completion code |
Priyanga | f4736d4 | 2019-05-02 14:48:04 +0530 | [diff] [blame^] | 90 | * @param[in] length - Number of bytes read. This could be less than |
| 91 | * what the requester asked for. |
| 92 | * @param[out] msg - Message will be written to this |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 93 | * @return pldm_completion_codes |
| 94 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 95 | */ |
Eddie James | 3b02e27 | 2019-04-22 20:13:55 +0000 | [diff] [blame] | 96 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 97 | uint8_t completion_code, uint32_t length, |
| 98 | struct pldm_msg *msg); |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 99 | |
Priyanga | f4736d4 | 2019-05-02 14:48:04 +0530 | [diff] [blame^] | 100 | /** @brief Encode ReadFileIntoMemory and WriteFileFromMemory |
| 101 | * commands request data |
| 102 | * |
| 103 | * @param[in] instance_id - Message's instance id |
| 104 | * @param[in] command - PLDM command |
| 105 | * @param[in] file_handle - A handle to the file |
| 106 | * @param[in] offset - Offset to the file at which the read should begin |
| 107 | * @param[in] length - Number of bytes to be read/written |
| 108 | * @param[in] address - Memory address where the file content has to be |
| 109 | * written to |
| 110 | * @param[out] msg - Message will be written to this |
| 111 | * @return pldm_completion_codes |
| 112 | */ |
| 113 | int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command, |
| 114 | uint32_t file_handle, uint32_t offset, |
| 115 | uint32_t length, uint64_t address, |
| 116 | struct pldm_msg *msg); |
| 117 | |
| 118 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory |
| 119 | * commands response data |
| 120 | * |
| 121 | * @param[in] msg - pointer to PLDM response message payload |
| 122 | * @param[in] payload_length - Length of response payload |
| 123 | * @param[out] completion_code - PLDM completion code |
| 124 | * @param[out] length - Number of bytes to be read/written |
| 125 | * @return pldm_completion_codes |
| 126 | */ |
| 127 | int decode_rw_file_memory_resp(const uint8_t *msg, size_t payload_length, |
| 128 | uint8_t *completion_code, uint32_t *length); |
| 129 | |
Tom Joseph | 61325fa | 2019-06-04 15:22:22 +0530 | [diff] [blame] | 130 | /** @struct pldm_get_file_table_req |
| 131 | * |
| 132 | * Structure representing GetFileTable request |
| 133 | */ |
| 134 | struct pldm_get_file_table_req { |
| 135 | uint32_t transfer_handle; //!< Data transfer handle |
| 136 | uint8_t operation_flag; //!< Transfer operation flag |
| 137 | uint8_t table_type; //!< Table type |
| 138 | } __attribute__((packed)); |
| 139 | |
| 140 | /** @struct pldm_get_file_table_resp |
| 141 | * |
| 142 | * Structure representing GetFileTable response fixed data |
| 143 | */ |
| 144 | struct pldm_get_file_table_resp { |
| 145 | uint8_t completion_code; //!< Completion code |
| 146 | uint32_t next_transfer_handle; //!< Next data transfer handle |
| 147 | uint8_t transfer_flag; //!< Transfer flag |
| 148 | uint8_t table_data[1]; //!< Table Data |
| 149 | } __attribute__((packed)); |
| 150 | |
| 151 | /** @brief Decode GetFileTable command request data |
| 152 | * |
| 153 | * @param[in] msg - Pointer to PLDM request message payload |
| 154 | * @param[in] payload_length - Length of request payload |
| 155 | * @param[out] trasnfer_handle - the handle of data |
| 156 | * @param[out] transfer_opflag - Transfer operation flag |
| 157 | * @param[out] table_type - the type of file table |
| 158 | * @return pldm_completion_codes |
| 159 | */ |
| 160 | int decode_get_file_table_req(const uint8_t *msg, size_t payload_length, |
| 161 | uint32_t *transfer_handle, |
| 162 | uint8_t *transfer_opflag, uint8_t *table_type); |
| 163 | |
| 164 | /** @brief Create a PLDM response for GetFileTable command |
| 165 | * |
| 166 | * @param[in] instance_id - Message's instance id |
| 167 | * @param[in] completion_code - PLDM completion code |
| 168 | * @param[in] next_transfer_handle - Handle to identify next portion of |
| 169 | * data transfer |
| 170 | * @param[in] transfer_flag - Represents the part of transfer |
| 171 | * @param[in] table_data - pointer to file table data |
| 172 | * @param[in] table_size - file table size |
| 173 | * @param[in,out] msg - Message will be written to this |
| 174 | * @return pldm_completion_codes |
| 175 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 176 | */ |
| 177 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 178 | uint32_t next_transfer_handle, |
| 179 | uint8_t transfer_flag, const uint8_t *table_data, |
| 180 | size_t table_size, struct pldm_msg *msg); |
| 181 | |
Tom Joseph | 7dae777 | 2019-04-10 14:44:44 +0530 | [diff] [blame] | 182 | #ifdef __cplusplus |
| 183 | } |
| 184 | #endif |
| 185 | |
| 186 | #endif /* FILEIO_H */ |