Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +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 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 13 | /** @brief PLDM Commands in IBM OEM type |
| 14 | */ |
| 15 | enum pldm_fileio_commands { |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 16 | PLDM_GET_FILE_TABLE = 0x1, |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 17 | PLDM_READ_FILE = 0x4, |
| 18 | PLDM_WRITE_FILE = 0x5, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 19 | PLDM_READ_FILE_INTO_MEMORY = 0x6, |
| 20 | PLDM_WRITE_FILE_FROM_MEMORY = 0x7, |
| 21 | }; |
| 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, |
| 28 | PLDM_INVALID_READ_LENGTH = 0x82, |
| 29 | PLDM_INVALID_WRITE_LENGTH = 0x83, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +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, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | #define PLDM_RW_FILE_MEM_REQ_BYTES 20 |
| 42 | #define PLDM_RW_FILE_MEM_RESP_BYTES 5 |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 43 | #define PLDM_GET_FILE_TABLE_REQ_BYTES 6 |
| 44 | #define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6 |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 45 | #define PLDM_READ_FILE_REQ_BYTES 12 |
| 46 | #define PLDM_READ_FILE_RESP_BYTES 5 |
| 47 | #define PLDM_WRITE_FILE_REQ_BYTES 12 |
| 48 | #define PLDM_WRITE_FILE_RESP_BYTES 5 |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 49 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 50 | /** @struct pldm_read_write_file_memory_req |
| 51 | * |
| 52 | * Structure representing ReadFileIntoMemory request and WriteFileFromMemory |
| 53 | * request |
| 54 | */ |
| 55 | struct pldm_read_write_file_memory_req { |
| 56 | uint32_t file_handle; //!< A Handle to the file |
| 57 | uint32_t offset; //!< Offset to the file |
| 58 | uint32_t length; //!< Number of bytes to be read/write |
| 59 | uint64_t address; //!< Memory address of the file |
| 60 | } __attribute__((packed)); |
| 61 | |
| 62 | /** @struct pldm_read_write_file_memory_resp |
| 63 | * |
| 64 | * Structure representing ReadFileIntoMemory response and WriteFileFromMemory |
| 65 | * response |
| 66 | */ |
| 67 | struct pldm_read_write_file_memory_resp { |
| 68 | uint8_t completion_code; //!< completion code |
| 69 | uint32_t length; //!< Number of bytes read/written |
| 70 | } __attribute__((packed)); |
| 71 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 72 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request |
| 73 | * data |
| 74 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 75 | * @param[in] msg - Pointer to PLDM request message |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 76 | * @param[in] payload_length - Length of request payload |
| 77 | * @param[out] file_handle - A handle to the file |
| 78 | * @param[out] offset - Offset to the file at which the read should begin |
| 79 | * @param[out] length - Number of bytes to be read |
| 80 | * @param[out] address - Memory address where the file content has to be |
| 81 | * written to |
| 82 | * @return pldm_completion_codes |
| 83 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 84 | int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 85 | uint32_t *file_handle, uint32_t *offset, |
| 86 | uint32_t *length, uint64_t *address); |
| 87 | |
| 88 | /** @brief Create a PLDM response for ReadFileIntoMemory and |
| 89 | * WriteFileFromMemory |
| 90 | * |
| 91 | * @param[in] instance_id - Message's instance id |
| 92 | * @param[in] command - PLDM command |
| 93 | * @param[in] completion_code - PLDM completion code |
| 94 | * @param[in] length - Number of bytes read. This could be less than what the |
| 95 | requester asked for. |
| 96 | * @param[in,out] msg - Message will be written to this |
| 97 | * @return pldm_completion_codes |
| 98 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 99 | */ |
| 100 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 101 | uint8_t completion_code, uint32_t length, |
| 102 | struct pldm_msg *msg); |
| 103 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 104 | /** @brief Encode ReadFileIntoMemory and WriteFileFromMemory |
| 105 | * commands request data |
| 106 | * |
| 107 | * @param[in] instance_id - Message's instance id |
| 108 | * @param[in] command - PLDM command |
| 109 | * @param[in] file_handle - A handle to the file |
| 110 | * @param[in] offset - Offset to the file at which the read should begin |
| 111 | * @param[in] length - Number of bytes to be read/written |
| 112 | * @param[in] address - Memory address where the file content has to be |
| 113 | * written to |
| 114 | * @param[out] msg - Message will be written to this |
| 115 | * @return pldm_completion_codes |
| 116 | */ |
| 117 | int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command, |
| 118 | uint32_t file_handle, uint32_t offset, |
| 119 | uint32_t length, uint64_t address, |
| 120 | struct pldm_msg *msg); |
| 121 | |
| 122 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory |
| 123 | * commands response data |
| 124 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 125 | * @param[in] msg - pointer to PLDM response message |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 126 | * @param[in] payload_length - Length of response payload |
| 127 | * @param[out] completion_code - PLDM completion code |
| 128 | * @param[out] length - Number of bytes to be read/written |
| 129 | * @return pldm_completion_codes |
| 130 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 131 | int decode_rw_file_memory_resp(const struct pldm_msg *msg, |
| 132 | size_t payload_length, uint8_t *completion_code, |
| 133 | uint32_t *length); |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 134 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 135 | /** @struct pldm_get_file_table_req |
| 136 | * |
| 137 | * Structure representing GetFileTable request |
| 138 | */ |
| 139 | struct pldm_get_file_table_req { |
| 140 | uint32_t transfer_handle; //!< Data transfer handle |
| 141 | uint8_t operation_flag; //!< Transfer operation flag |
| 142 | uint8_t table_type; //!< Table type |
| 143 | } __attribute__((packed)); |
| 144 | |
| 145 | /** @struct pldm_get_file_table_resp |
| 146 | * |
| 147 | * Structure representing GetFileTable response fixed data |
| 148 | */ |
| 149 | struct pldm_get_file_table_resp { |
| 150 | uint8_t completion_code; //!< Completion code |
| 151 | uint32_t next_transfer_handle; //!< Next data transfer handle |
| 152 | uint8_t transfer_flag; //!< Transfer flag |
| 153 | uint8_t table_data[1]; //!< Table Data |
| 154 | } __attribute__((packed)); |
| 155 | |
| 156 | /** @brief Decode GetFileTable command request data |
| 157 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 158 | * @param[in] msg - Pointer to PLDM request message |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 159 | * @param[in] payload_length - Length of request payload |
| 160 | * @param[out] trasnfer_handle - the handle of data |
| 161 | * @param[out] transfer_opflag - Transfer operation flag |
| 162 | * @param[out] table_type - the type of file table |
| 163 | * @return pldm_completion_codes |
| 164 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 165 | int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 166 | uint32_t *transfer_handle, |
| 167 | uint8_t *transfer_opflag, uint8_t *table_type); |
| 168 | |
| 169 | /** @brief Create a PLDM response for GetFileTable command |
| 170 | * |
| 171 | * @param[in] instance_id - Message's instance id |
| 172 | * @param[in] completion_code - PLDM completion code |
| 173 | * @param[in] next_transfer_handle - Handle to identify next portion of |
| 174 | * data transfer |
| 175 | * @param[in] transfer_flag - Represents the part of transfer |
| 176 | * @param[in] table_data - pointer to file table data |
| 177 | * @param[in] table_size - file table size |
| 178 | * @param[in,out] msg - Message will be written to this |
| 179 | * @return pldm_completion_codes |
| 180 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 181 | */ |
| 182 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 183 | uint32_t next_transfer_handle, |
| 184 | uint8_t transfer_flag, const uint8_t *table_data, |
| 185 | size_t table_size, struct pldm_msg *msg); |
| 186 | |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 187 | /** @struct pldm_read_file_req |
| 188 | * |
| 189 | * Structure representing ReadFile request |
| 190 | */ |
| 191 | struct pldm_read_file_req { |
| 192 | uint32_t file_handle; //!< Handle to file |
| 193 | uint32_t offset; //!< Offset to file where read starts |
| 194 | uint32_t length; //!< Bytes to be read |
| 195 | } __attribute__((packed)); |
| 196 | |
| 197 | /** @struct pldm_read_file_resp |
| 198 | * |
| 199 | * Structure representing ReadFile response data |
| 200 | */ |
| 201 | struct pldm_read_file_resp { |
| 202 | uint8_t completion_code; //!< Completion code |
| 203 | uint32_t length; //!< Number of bytes read |
| 204 | uint8_t file_data[1]; //!< Address of this is where file data starts |
| 205 | } __attribute__((packed)); |
| 206 | |
| 207 | /** @struct pldm_write_file_req |
| 208 | * |
| 209 | * Structure representing WriteFile request |
| 210 | */ |
| 211 | struct pldm_write_file_req { |
| 212 | uint32_t file_handle; //!< Handle to file |
| 213 | uint32_t offset; //!< Offset to file where write starts |
| 214 | uint32_t length; //!< Bytes to be written |
| 215 | uint8_t file_data[1]; //!< Address of this is where file data starts |
| 216 | } __attribute__((packed)); |
| 217 | |
| 218 | /** @struct pldm_write_file_resp |
| 219 | * |
| 220 | * Structure representing WriteFile response data |
| 221 | */ |
| 222 | struct pldm_write_file_resp { |
| 223 | uint8_t completion_code; //!< Completion code |
| 224 | uint32_t length; //!< Bytes written |
| 225 | } __attribute__((packed)); |
| 226 | |
| 227 | /** @brief Decode Read File commands request |
| 228 | * |
| 229 | * @param[in] msg - PLDM request message payload |
| 230 | * @param[in] payload_length - Length of request payload |
| 231 | * @param[out] file_handle - A handle to the file |
| 232 | * @param[out] offset - Offset to the file at which the read should begin |
| 233 | * @param[out] length - Number of bytes read |
| 234 | * @return pldm_completion_codes |
| 235 | */ |
| 236 | int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 237 | uint32_t *file_handle, uint32_t *offset, |
| 238 | uint32_t *length); |
| 239 | |
| 240 | /** @brief Encode Read File commands request |
| 241 | * |
| 242 | * @param[in] instance_id - Message's instance id |
| 243 | * @param[in] file_handle - A handle to the file |
| 244 | * @param[in] offset - Offset to the file at which the read should begin |
| 245 | * @param[in] length - Number of bytes read |
| 246 | * @param[in,out] msg - Message will be written to this |
| 247 | * @return pldm_completion_codes |
| 248 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 249 | */ |
| 250 | int encode_read_file_req(uint8_t instance_id, uint32_t file_handle, |
| 251 | uint32_t offset, uint32_t length, |
| 252 | struct pldm_msg *msg); |
| 253 | |
| 254 | /** @brief Decode Read File commands response |
| 255 | * |
| 256 | * @param[in] msg - PLDM response message payload |
| 257 | * @param[in] payload_length - Length of request payload |
| 258 | * @param[out] completion_code - PLDM completion code |
| 259 | * @param[out] length - Number of bytes read. This could be less than what the |
| 260 | * requester asked for. |
| 261 | * @param[out] file_data_offset - Offset where file data should be read in pldm |
| 262 | * msg. |
| 263 | * @return pldm_completion_codes |
| 264 | */ |
| 265 | int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 266 | uint8_t *completion_code, uint32_t *length, |
| 267 | size_t *file_data_offset); |
| 268 | |
| 269 | /** @brief Create a PLDM response for Read File |
| 270 | * |
| 271 | * @param[in] instance_id - Message's instance id |
| 272 | * @param[in] completion_code - PLDM completion code |
| 273 | * @param[in] length - Number of bytes read. This could be less than what the |
| 274 | * requester asked for. |
| 275 | * @param[in,out] msg - Message will be written to this |
| 276 | * @return pldm_completion_codes |
| 277 | * @note Caller is responsible for memory alloc and dealloc of param 'msg'. |
| 278 | * Although read file command response includes file data, this function |
| 279 | * does not encode the file data to prevent additional copying of the data. |
| 280 | * The position of file data is calculated by caller from address and size |
| 281 | * of other input arguments. |
| 282 | */ |
| 283 | int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 284 | uint32_t length, struct pldm_msg *msg); |
| 285 | |
| 286 | /** @brief Decode Write File commands request |
| 287 | * |
| 288 | * @param[in] msg - PLDM request message payload |
| 289 | * @param[in] payload_length - Length of request payload |
| 290 | * @param[out] file_handle - A handle to the file |
| 291 | * @param[out] offset - Offset to the file at which the write should begin |
| 292 | * @param[out] length - Number of bytes to write |
| 293 | * @param[out] file_data_offset - Offset where file data write begins in pldm |
| 294 | * msg. |
| 295 | * @return pldm_completion_codes |
| 296 | */ |
| 297 | int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 298 | uint32_t *file_handle, uint32_t *offset, |
| 299 | uint32_t *length, size_t *file_data_offset); |
| 300 | |
| 301 | /** @brief Create a PLDM request for Write File |
| 302 | * |
| 303 | * @param[in] instance_id - Message's instance id |
| 304 | * @param[in] file_handle - A handle to the file |
| 305 | * @param[in] offset - Offset to the file at which the read should begin |
| 306 | * @param[in] length - Number of bytes written. This could be less than what |
| 307 | * the requester asked for. |
| 308 | * @param[in,out] msg - Message will be written to this |
| 309 | * @return pldm_completion_codes |
| 310 | * @note Caller is responsible for memory alloc and dealloc of param 'msg'. |
| 311 | * Although write file command request includes file data, this function |
| 312 | * does not encode the file data to prevent additional copying of the data. |
| 313 | * The position of file data is calculated by caller from address and size |
| 314 | * of other input arguments. |
| 315 | */ |
| 316 | int encode_write_file_req(uint8_t instance_id, uint32_t file_handle, |
| 317 | uint32_t offset, uint32_t length, |
| 318 | struct pldm_msg *msg); |
| 319 | |
| 320 | /** @brief Decode Write File commands response |
| 321 | * |
| 322 | * @param[in] msg - PLDM request message payload |
| 323 | * @param[in] payload_length - Length of request payload |
| 324 | * @param[out] completion_code - PLDM completion code |
| 325 | * @param[out] length - Number of bytes written |
| 326 | * @return pldm_completion_codes |
| 327 | */ |
| 328 | int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 329 | uint8_t *completion_code, uint32_t *length); |
| 330 | |
| 331 | /** @brief Create a PLDM response for Write File |
| 332 | * |
| 333 | * @param[in] instance_id - Message's instance id |
| 334 | * @param[in] completion_code - PLDM completion code |
| 335 | * @param[in] length - Number of bytes written. This could be less than what |
| 336 | * the requester asked for. |
| 337 | * @param[in,out] msg - Message will be written to this |
| 338 | * @return pldm_completion_codes |
| 339 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 340 | */ |
| 341 | int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 342 | uint32_t length, struct pldm_msg *msg); |
| 343 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 344 | #ifdef __cplusplus |
| 345 | } |
| 346 | #endif |
| 347 | |
| 348 | #endif /* FILEIO_H */ |