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, |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 21 | PLDM_READ_FILE_BY_TYPE_INTO_MEMORY = 0x8, |
| 22 | PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY = 0x9, |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 23 | PLDM_NEW_FILE_AVAILABLE = 0xA, |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 24 | PLDM_READ_FILE_BY_TYPE = 0xB, |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 25 | PLDM_WRITE_FILE_BY_TYPE = 0xC, |
| 26 | PLDM_FILE_ACK = 0xD, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | /** @brief PLDM Command specific codes |
| 30 | */ |
| 31 | enum pldm_fileio_completion_codes { |
Deepak Kodihalli | 3bf5c55 | 2020-04-20 06:16:01 -0500 | [diff] [blame] | 32 | PLDM_FILE_TABLE_UNAVAILABLE = 0x83, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 33 | PLDM_INVALID_FILE_TABLE_TYPE = 0x85, |
Deepak Kodihalli | 3bf5c55 | 2020-04-20 06:16:01 -0500 | [diff] [blame] | 34 | PLDM_INVALID_FILE_HANDLE = 0x86, |
| 35 | PLDM_DATA_OUT_OF_RANGE = 0x87, |
| 36 | PLDM_INVALID_FILE_TYPE = 0x89, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | /** @brief PLDM File I/O table types |
| 40 | */ |
| 41 | enum pldm_fileio_table_type { |
| 42 | PLDM_FILE_ATTRIBUTE_TABLE = 0, |
| 43 | PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 44 | }; |
| 45 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 46 | /** @brief PLDM File I/O table types |
| 47 | */ |
| 48 | enum pldm_fileio_file_type { |
| 49 | PLDM_FILE_TYPE_PEL = 0, |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 50 | PLDM_FILE_TYPE_LID_PERM = 1, |
| 51 | PLDM_FILE_TYPE_LID_TEMP = 2, |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 52 | PLDM_FILE_TYPE_DUMP = 3, |
Sampa Misra | d823cc0 | 2020-03-24 04:53:20 -0500 | [diff] [blame] | 53 | PLDM_FILE_TYPE_CERT_SIGNING_REQUEST = 4, |
| 54 | PLDM_FILE_TYPE_SIGNED_CERT = 5, |
| 55 | PLDM_FILE_TYPE_ROOT_CERT = 6, |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 56 | PLDM_FILE_TYPE_LID_MARKER = 7, |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 57 | }; |
| 58 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 59 | #define PLDM_RW_FILE_MEM_REQ_BYTES 20 |
| 60 | #define PLDM_RW_FILE_MEM_RESP_BYTES 5 |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 61 | #define PLDM_GET_FILE_TABLE_REQ_BYTES 6 |
| 62 | #define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6 |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 63 | #define PLDM_READ_FILE_REQ_BYTES 12 |
| 64 | #define PLDM_READ_FILE_RESP_BYTES 5 |
| 65 | #define PLDM_WRITE_FILE_REQ_BYTES 12 |
| 66 | #define PLDM_WRITE_FILE_RESP_BYTES 5 |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 67 | #define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES 22 |
| 68 | #define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES 5 |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 69 | #define PLDM_NEW_FILE_REQ_BYTES 14 |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 70 | #define PLDM_NEW_FILE_RESP_BYTES 1 |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 71 | #define PLDM_RW_FILE_BY_TYPE_REQ_BYTES 14 |
| 72 | #define PLDM_RW_FILE_BY_TYPE_RESP_BYTES 5 |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 73 | #define PLDM_FILE_ACK_REQ_BYTES 7 |
| 74 | #define PLDM_FILE_ACK_RESP_BYTES 1 |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 75 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 76 | /** @struct pldm_read_write_file_memory_req |
| 77 | * |
| 78 | * Structure representing ReadFileIntoMemory request and WriteFileFromMemory |
| 79 | * request |
| 80 | */ |
| 81 | struct pldm_read_write_file_memory_req { |
| 82 | uint32_t file_handle; //!< A Handle to the file |
| 83 | uint32_t offset; //!< Offset to the file |
| 84 | uint32_t length; //!< Number of bytes to be read/write |
| 85 | uint64_t address; //!< Memory address of the file |
| 86 | } __attribute__((packed)); |
| 87 | |
| 88 | /** @struct pldm_read_write_file_memory_resp |
| 89 | * |
| 90 | * Structure representing ReadFileIntoMemory response and WriteFileFromMemory |
| 91 | * response |
| 92 | */ |
| 93 | struct pldm_read_write_file_memory_resp { |
| 94 | uint8_t completion_code; //!< completion code |
| 95 | uint32_t length; //!< Number of bytes read/written |
| 96 | } __attribute__((packed)); |
| 97 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 98 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request |
| 99 | * data |
| 100 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 101 | * @param[in] msg - Pointer to PLDM request message |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 102 | * @param[in] payload_length - Length of request payload |
| 103 | * @param[out] file_handle - A handle to the file |
| 104 | * @param[out] offset - Offset to the file at which the read should begin |
| 105 | * @param[out] length - Number of bytes to be read |
| 106 | * @param[out] address - Memory address where the file content has to be |
| 107 | * written to |
| 108 | * @return pldm_completion_codes |
| 109 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 110 | 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] | 111 | uint32_t *file_handle, uint32_t *offset, |
| 112 | uint32_t *length, uint64_t *address); |
| 113 | |
| 114 | /** @brief Create a PLDM response for ReadFileIntoMemory and |
| 115 | * WriteFileFromMemory |
| 116 | * |
| 117 | * @param[in] instance_id - Message's instance id |
| 118 | * @param[in] command - PLDM command |
| 119 | * @param[in] completion_code - PLDM completion code |
| 120 | * @param[in] length - Number of bytes read. This could be less than what the |
| 121 | requester asked for. |
| 122 | * @param[in,out] msg - Message will be written to this |
| 123 | * @return pldm_completion_codes |
| 124 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 125 | */ |
| 126 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 127 | uint8_t completion_code, uint32_t length, |
| 128 | struct pldm_msg *msg); |
| 129 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 130 | /** @brief Encode ReadFileIntoMemory and WriteFileFromMemory |
| 131 | * commands request data |
| 132 | * |
| 133 | * @param[in] instance_id - Message's instance id |
| 134 | * @param[in] command - PLDM command |
| 135 | * @param[in] file_handle - A handle to the file |
| 136 | * @param[in] offset - Offset to the file at which the read should begin |
| 137 | * @param[in] length - Number of bytes to be read/written |
| 138 | * @param[in] address - Memory address where the file content has to be |
| 139 | * written to |
| 140 | * @param[out] msg - Message will be written to this |
| 141 | * @return pldm_completion_codes |
| 142 | */ |
| 143 | int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command, |
| 144 | uint32_t file_handle, uint32_t offset, |
| 145 | uint32_t length, uint64_t address, |
| 146 | struct pldm_msg *msg); |
| 147 | |
| 148 | /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory |
| 149 | * commands response data |
| 150 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 151 | * @param[in] msg - pointer to PLDM response message |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 152 | * @param[in] payload_length - Length of response payload |
| 153 | * @param[out] completion_code - PLDM completion code |
| 154 | * @param[out] length - Number of bytes to be read/written |
| 155 | * @return pldm_completion_codes |
| 156 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 157 | int decode_rw_file_memory_resp(const struct pldm_msg *msg, |
| 158 | size_t payload_length, uint8_t *completion_code, |
| 159 | uint32_t *length); |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 160 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 161 | /** @struct pldm_get_file_table_req |
| 162 | * |
| 163 | * Structure representing GetFileTable request |
| 164 | */ |
| 165 | struct pldm_get_file_table_req { |
| 166 | uint32_t transfer_handle; //!< Data transfer handle |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 167 | uint8_t operation_flag; //!< Transfer operation flag |
| 168 | uint8_t table_type; //!< Table type |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 169 | } __attribute__((packed)); |
| 170 | |
| 171 | /** @struct pldm_get_file_table_resp |
| 172 | * |
| 173 | * Structure representing GetFileTable response fixed data |
| 174 | */ |
| 175 | struct pldm_get_file_table_resp { |
| 176 | uint8_t completion_code; //!< Completion code |
| 177 | uint32_t next_transfer_handle; //!< Next data transfer handle |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 178 | uint8_t transfer_flag; //!< Transfer flag |
| 179 | uint8_t table_data[1]; //!< Table Data |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 180 | } __attribute__((packed)); |
| 181 | |
Pavithra Barithaya | c4e80cc | 2020-05-26 07:00:26 -0500 | [diff] [blame] | 182 | /** @struct pldm_file_attr_table_entry |
| 183 | * |
| 184 | * Structure representing File attribute table entry |
| 185 | */ |
| 186 | struct pldm_file_attr_table_entry { |
| 187 | uint32_t file_handle; //!< File Handle |
| 188 | uint16_t file_name_length; //!< File name length |
| 189 | uint8_t file_attr_table_nst[1]; //!< File name size traits |
| 190 | } __attribute__((packed)); |
| 191 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 192 | /** @brief Decode GetFileTable command request data |
| 193 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 194 | * @param[in] msg - Pointer to PLDM request message |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 195 | * @param[in] payload_length - Length of request payload |
| 196 | * @param[out] trasnfer_handle - the handle of data |
| 197 | * @param[out] transfer_opflag - Transfer operation flag |
| 198 | * @param[out] table_type - the type of file table |
| 199 | * @return pldm_completion_codes |
| 200 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 201 | 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] | 202 | uint32_t *transfer_handle, |
| 203 | uint8_t *transfer_opflag, uint8_t *table_type); |
| 204 | |
| 205 | /** @brief Create a PLDM response for GetFileTable command |
| 206 | * |
| 207 | * @param[in] instance_id - Message's instance id |
| 208 | * @param[in] completion_code - PLDM completion code |
| 209 | * @param[in] next_transfer_handle - Handle to identify next portion of |
| 210 | * data transfer |
| 211 | * @param[in] transfer_flag - Represents the part of transfer |
| 212 | * @param[in] table_data - pointer to file table data |
| 213 | * @param[in] table_size - file table size |
| 214 | * @param[in,out] msg - Message will be written to this |
| 215 | * @return pldm_completion_codes |
| 216 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 217 | */ |
| 218 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 219 | uint32_t next_transfer_handle, |
| 220 | uint8_t transfer_flag, const uint8_t *table_data, |
| 221 | size_t table_size, struct pldm_msg *msg); |
| 222 | |
Pavithra Barithaya | d15c809 | 2020-05-12 02:26:26 -0500 | [diff] [blame] | 223 | /** @brief Encode GetFileTable command request data |
| 224 | * |
| 225 | * @param[in] instance_id - Message's instance id |
| 226 | * @param[in] transfer_handle - the handle of data |
| 227 | * @param[in] transfer_opflag - Transfer operation flag |
| 228 | * @param[in] table_type - the type of file table |
| 229 | * @param[out] msg - Message will be written to this |
| 230 | * @return pldm_completion_codes |
| 231 | */ |
| 232 | int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle, |
| 233 | uint8_t transfer_opflag, uint8_t table_type, |
| 234 | struct pldm_msg *msg); |
| 235 | |
| 236 | /** @brief Decode GetFileTable command response data |
| 237 | * @param[in] msg - Response message |
| 238 | * @param[in] payload_length - length of response message payload |
| 239 | * @param[out] completion_code - PLDM completion code |
| 240 | * @param[out] next_transfer_handle - Handle to identify next portion of data |
| 241 | * transfer |
| 242 | * @param[out] transfer_flag - Represents the part of transfer |
| 243 | * @param[out] file_table_data_start_offset - This data is a portion of the |
| 244 | * overall File Table |
| 245 | * @param[out] file_table_length - Length of the File table data |
| 246 | * @return pldm_completion_codes |
| 247 | */ |
| 248 | int decode_get_file_table_resp(const struct pldm_msg *msg, |
| 249 | size_t payload_length, uint8_t *completion_code, |
| 250 | uint32_t *next_transfer_handle, |
| 251 | uint8_t *transfer_flag, |
| 252 | uint8_t *file_table_data_start_offset, |
| 253 | size_t *file_table_length); |
| 254 | |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 255 | /** @struct pldm_read_file_req |
| 256 | * |
| 257 | * Structure representing ReadFile request |
| 258 | */ |
| 259 | struct pldm_read_file_req { |
| 260 | uint32_t file_handle; //!< Handle to file |
| 261 | uint32_t offset; //!< Offset to file where read starts |
| 262 | uint32_t length; //!< Bytes to be read |
| 263 | } __attribute__((packed)); |
| 264 | |
| 265 | /** @struct pldm_read_file_resp |
| 266 | * |
| 267 | * Structure representing ReadFile response data |
| 268 | */ |
| 269 | struct pldm_read_file_resp { |
| 270 | uint8_t completion_code; //!< Completion code |
| 271 | uint32_t length; //!< Number of bytes read |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 272 | uint8_t file_data[1]; //!< Address of this is where file data starts |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 273 | } __attribute__((packed)); |
| 274 | |
| 275 | /** @struct pldm_write_file_req |
| 276 | * |
| 277 | * Structure representing WriteFile request |
| 278 | */ |
| 279 | struct pldm_write_file_req { |
| 280 | uint32_t file_handle; //!< Handle to file |
| 281 | uint32_t offset; //!< Offset to file where write starts |
| 282 | uint32_t length; //!< Bytes to be written |
| 283 | uint8_t file_data[1]; //!< Address of this is where file data starts |
| 284 | } __attribute__((packed)); |
| 285 | |
| 286 | /** @struct pldm_write_file_resp |
| 287 | * |
| 288 | * Structure representing WriteFile response data |
| 289 | */ |
| 290 | struct pldm_write_file_resp { |
| 291 | uint8_t completion_code; //!< Completion code |
| 292 | uint32_t length; //!< Bytes written |
| 293 | } __attribute__((packed)); |
| 294 | |
| 295 | /** @brief Decode Read File commands request |
| 296 | * |
| 297 | * @param[in] msg - PLDM request message payload |
| 298 | * @param[in] payload_length - Length of request payload |
| 299 | * @param[out] file_handle - A handle to the file |
| 300 | * @param[out] offset - Offset to the file at which the read should begin |
| 301 | * @param[out] length - Number of bytes read |
| 302 | * @return pldm_completion_codes |
| 303 | */ |
| 304 | int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 305 | uint32_t *file_handle, uint32_t *offset, |
| 306 | uint32_t *length); |
| 307 | |
| 308 | /** @brief Encode Read File commands request |
| 309 | * |
| 310 | * @param[in] instance_id - Message's instance id |
| 311 | * @param[in] file_handle - A handle to the file |
| 312 | * @param[in] offset - Offset to the file at which the read should begin |
| 313 | * @param[in] length - Number of bytes read |
| 314 | * @param[in,out] msg - Message will be written to this |
| 315 | * @return pldm_completion_codes |
| 316 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 317 | */ |
| 318 | int encode_read_file_req(uint8_t instance_id, uint32_t file_handle, |
| 319 | uint32_t offset, uint32_t length, |
| 320 | struct pldm_msg *msg); |
| 321 | |
| 322 | /** @brief Decode Read File commands response |
| 323 | * |
| 324 | * @param[in] msg - PLDM response message payload |
| 325 | * @param[in] payload_length - Length of request payload |
| 326 | * @param[out] completion_code - PLDM completion code |
| 327 | * @param[out] length - Number of bytes read. This could be less than what the |
| 328 | * requester asked for. |
| 329 | * @param[out] file_data_offset - Offset where file data should be read in pldm |
| 330 | * msg. |
| 331 | * @return pldm_completion_codes |
| 332 | */ |
| 333 | int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 334 | uint8_t *completion_code, uint32_t *length, |
| 335 | size_t *file_data_offset); |
| 336 | |
| 337 | /** @brief Create a PLDM response for Read File |
| 338 | * |
| 339 | * @param[in] instance_id - Message's instance id |
| 340 | * @param[in] completion_code - PLDM completion code |
| 341 | * @param[in] length - Number of bytes read. This could be less than what the |
| 342 | * requester asked for. |
| 343 | * @param[in,out] msg - Message will be written to this |
| 344 | * @return pldm_completion_codes |
| 345 | * @note Caller is responsible for memory alloc and dealloc of param 'msg'. |
| 346 | * Although read file command response includes file data, this function |
| 347 | * does not encode the file data to prevent additional copying of the data. |
| 348 | * The position of file data is calculated by caller from address and size |
| 349 | * of other input arguments. |
| 350 | */ |
| 351 | int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 352 | uint32_t length, struct pldm_msg *msg); |
| 353 | |
| 354 | /** @brief Decode Write File commands request |
| 355 | * |
| 356 | * @param[in] msg - PLDM request message payload |
| 357 | * @param[in] payload_length - Length of request payload |
| 358 | * @param[out] file_handle - A handle to the file |
| 359 | * @param[out] offset - Offset to the file at which the write should begin |
| 360 | * @param[out] length - Number of bytes to write |
| 361 | * @param[out] file_data_offset - Offset where file data write begins in pldm |
| 362 | * msg. |
| 363 | * @return pldm_completion_codes |
| 364 | */ |
| 365 | int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 366 | uint32_t *file_handle, uint32_t *offset, |
| 367 | uint32_t *length, size_t *file_data_offset); |
| 368 | |
| 369 | /** @brief Create a PLDM request for Write File |
| 370 | * |
| 371 | * @param[in] instance_id - Message's instance id |
| 372 | * @param[in] file_handle - A handle to the file |
| 373 | * @param[in] offset - Offset to the file at which the read should begin |
| 374 | * @param[in] length - Number of bytes written. This could be less than what |
| 375 | * the requester asked for. |
| 376 | * @param[in,out] msg - Message will be written to this |
| 377 | * @return pldm_completion_codes |
| 378 | * @note Caller is responsible for memory alloc and dealloc of param 'msg'. |
| 379 | * Although write file command request includes file data, this function |
| 380 | * does not encode the file data to prevent additional copying of the data. |
| 381 | * The position of file data is calculated by caller from address and size |
| 382 | * of other input arguments. |
| 383 | */ |
| 384 | int encode_write_file_req(uint8_t instance_id, uint32_t file_handle, |
| 385 | uint32_t offset, uint32_t length, |
| 386 | struct pldm_msg *msg); |
| 387 | |
| 388 | /** @brief Decode Write File commands response |
| 389 | * |
| 390 | * @param[in] msg - PLDM request message payload |
| 391 | * @param[in] payload_length - Length of request payload |
| 392 | * @param[out] completion_code - PLDM completion code |
| 393 | * @param[out] length - Number of bytes written |
| 394 | * @return pldm_completion_codes |
| 395 | */ |
| 396 | int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 397 | uint8_t *completion_code, uint32_t *length); |
| 398 | |
| 399 | /** @brief Create a PLDM response for Write File |
| 400 | * |
| 401 | * @param[in] instance_id - Message's instance id |
| 402 | * @param[in] completion_code - PLDM completion code |
| 403 | * @param[in] length - Number of bytes written. This could be less than what |
| 404 | * the requester asked for. |
| 405 | * @param[in,out] msg - Message will be written to this |
| 406 | * @return pldm_completion_codes |
| 407 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 408 | */ |
| 409 | int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 410 | uint32_t length, struct pldm_msg *msg); |
| 411 | |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 412 | /** @struct pldm_read_write_file_by_type_memory_req |
| 413 | * |
| 414 | * Structure representing ReadFileByTypeIntoMemory and |
| 415 | * WriteFileByTypeFromMemory request |
| 416 | */ |
| 417 | struct pldm_read_write_file_by_type_memory_req { |
| 418 | uint16_t file_type; //!< Type of file |
| 419 | uint32_t file_handle; //!< Handle to file |
| 420 | uint32_t offset; //!< Offset to file where read starts |
| 421 | uint32_t length; //!< Bytes to be read |
| 422 | uint64_t address; //!< Memory address of the file |
| 423 | } __attribute__((packed)); |
| 424 | |
| 425 | /** @struct pldm_read_write_file_by_type_memory_resp |
| 426 | * |
| 427 | * Structure representing ReadFileByTypeIntoMemory and |
| 428 | * WriteFileByTypeFromMemory response |
| 429 | */ |
| 430 | struct pldm_read_write_file_by_type_memory_resp { |
| 431 | uint8_t completion_code; //!< Completion code |
| 432 | uint32_t length; //!< Number of bytes read |
| 433 | } __attribute__((packed)); |
| 434 | |
| 435 | /** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory |
| 436 | * commands request data |
| 437 | * |
| 438 | * @param[in] msg - Pointer to PLDM request message |
| 439 | * @param[in] payload_length - Length of request payload |
| 440 | * @param[in] file_type - Type of the file |
| 441 | * @param[out] file_handle - A handle to the file |
| 442 | * @param[out] offset - Offset to the file at which the read should begin |
| 443 | * @param[out] length - Number of bytes to be read |
| 444 | * @param[out] address - Memory address of the file content |
| 445 | * @return pldm_completion_codes |
| 446 | */ |
| 447 | int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg, |
| 448 | size_t payload_length, |
| 449 | uint16_t *file_type, |
| 450 | uint32_t *file_handle, uint32_t *offset, |
| 451 | uint32_t *length, uint64_t *address); |
| 452 | |
| 453 | /** @brief Create a PLDM response for ReadFileByTypeIntoMemory and |
| 454 | * WriteFileByTypeFromMemory |
| 455 | * |
| 456 | * @param[in] instance_id - Message's instance id |
| 457 | * @param[in] command - PLDM command |
| 458 | * @param[in] completion_code - PLDM completion code |
| 459 | * @param[in] length - Number of bytes read. This could be less than what the |
| 460 | * requester asked for. |
| 461 | * @param[in,out] msg - Message will be written to this |
| 462 | * @return pldm_completion_codes |
| 463 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 464 | */ |
| 465 | int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command, |
| 466 | uint8_t completion_code, uint32_t length, |
| 467 | struct pldm_msg *msg); |
| 468 | |
| 469 | /** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory |
| 470 | * commands request data |
| 471 | * |
| 472 | * @param[in] instance_id - Message's instance id |
| 473 | * @param[in] command - PLDM command |
| 474 | * @param[in] file_type - Type of the file |
| 475 | * @param[in] file_handle - A handle to the file |
| 476 | * @param[in] offset - Offset to the file at which the read should begin |
| 477 | * @param[in] length - Number of bytes to be read/written |
| 478 | * @param[in] address - Memory address where the file content has to be |
| 479 | * written to |
| 480 | * @param[out] msg - Message will be written to this |
| 481 | * @return pldm_completion_codes |
| 482 | */ |
| 483 | int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command, |
| 484 | uint16_t file_type, uint32_t file_handle, |
| 485 | uint32_t offset, uint32_t length, |
| 486 | uint64_t address, struct pldm_msg *msg); |
| 487 | |
| 488 | /** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory |
| 489 | * commands response data |
| 490 | * |
| 491 | * @param[in] msg - pointer to PLDM response message |
| 492 | * @param[in] payload_length - Length of response payload |
| 493 | * @param[out] completion_code - PLDM completion code |
| 494 | * @param[out] length - Number of bytes to be read/written |
| 495 | * @return pldm_completion_codes |
| 496 | */ |
| 497 | int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg, |
| 498 | size_t payload_length, |
| 499 | uint8_t *completion_code, |
| 500 | uint32_t *length); |
| 501 | |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 502 | /** @struct pldm_new_file_req |
| 503 | * |
| 504 | * Structure representing NewFile request |
| 505 | */ |
| 506 | struct pldm_new_file_req { |
| 507 | uint16_t file_type; //!< Type of file |
| 508 | uint32_t file_handle; //!< Handle to file |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 509 | uint64_t length; //!< Number of bytes in new file |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 510 | } __attribute__((packed)); |
| 511 | |
| 512 | /** @struct pldm_new_file_resp |
| 513 | * |
| 514 | * Structure representing NewFile response data |
| 515 | */ |
| 516 | struct pldm_new_file_resp { |
| 517 | uint8_t completion_code; //!< Completion code |
| 518 | } __attribute__((packed)); |
| 519 | |
| 520 | /** @brief Decode NewFileAvailable command request data |
| 521 | * |
| 522 | * @param[in] msg - Pointer to PLDM request message |
| 523 | * @param[in] payload_length - Length of request payload |
| 524 | * @param[in] file_type - Type of the file |
| 525 | * @param[out] file_handle - A handle to the file |
| 526 | * @param[out] length - Number of bytes in new file |
| 527 | * @return pldm_completion_codes |
| 528 | */ |
| 529 | int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 530 | uint16_t *file_type, uint32_t *file_handle, |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 531 | uint64_t *length); |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 532 | |
| 533 | /** @brief Create a PLDM response for NewFileAvailable |
| 534 | * |
| 535 | * @param[in] instance_id - Message's instance id |
| 536 | * @param[in] completion_code - PLDM completion code |
| 537 | * @param[in,out] msg - Message will be written to this |
| 538 | * @return pldm_completion_codes |
| 539 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 540 | */ |
| 541 | int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 542 | struct pldm_msg *msg); |
| 543 | |
| 544 | /** @brief Encode NewFileAvailable command request data |
| 545 | * |
| 546 | * @param[in] instance_id - Message's instance id |
| 547 | * @param[in] file_type - Type of the file |
| 548 | * @param[in] file_handle - A handle to the file |
| 549 | * @param[in] length - Number of bytes in new file |
| 550 | * @param[out] msg - Message will be written to this |
| 551 | * @return pldm_completion_codes |
| 552 | */ |
| 553 | int encode_new_file_req(uint8_t instance_id, uint16_t file_type, |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 554 | uint32_t file_handle, uint64_t length, |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 555 | struct pldm_msg *msg); |
| 556 | |
| 557 | /** @brief Decode NewFileAvailable command response data |
| 558 | * |
| 559 | * @param[in] msg - pointer to PLDM response message |
| 560 | * @param[in] payload_length - Length of response payload |
| 561 | * @param[out] completion_code - PLDM completion code |
| 562 | * @return pldm_completion_codes |
| 563 | */ |
| 564 | int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 565 | uint8_t *completion_code); |
| 566 | |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 567 | /** @struct pldm_read_write_file_by_type_req |
| 568 | * |
| 569 | * Structure representing ReadFileByType and |
| 570 | * WriteFileByType request |
| 571 | */ |
| 572 | struct pldm_read_write_file_by_type_req { |
| 573 | uint16_t file_type; //!< Type of file |
| 574 | uint32_t file_handle; //!< Handle to file |
| 575 | uint32_t offset; //!< Offset to file where read/write starts |
| 576 | uint32_t length; //!< Bytes to be read |
| 577 | } __attribute__((packed)); |
| 578 | |
| 579 | /** @struct pldm_read_write_file_by_type_resp |
| 580 | * |
| 581 | * Structure representing ReadFileByType and |
| 582 | * WriteFileByType response |
| 583 | */ |
| 584 | struct pldm_read_write_file_by_type_resp { |
| 585 | uint8_t completion_code; //!< Completion code |
| 586 | uint32_t length; //!< Number of bytes read |
| 587 | } __attribute__((packed)); |
| 588 | |
| 589 | /** @brief Decode ReadFileByType and WriteFileByType |
| 590 | * commands request data |
| 591 | * |
| 592 | * @param[in] msg - Pointer to PLDM request message |
| 593 | * @param[in] payload_length - Length of request payload |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 594 | * @param[out] file_type - Type of the file |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 595 | * @param[out] file_handle - A handle to the file |
| 596 | * @param[out] offset - Offset to the file at which the read/write should begin |
| 597 | * @param[out] length - Number of bytes to be read/written |
| 598 | * @return pldm_completion_codes |
| 599 | */ |
| 600 | int decode_rw_file_by_type_req(const struct pldm_msg *msg, |
| 601 | size_t payload_length, uint16_t *file_type, |
| 602 | uint32_t *file_handle, uint32_t *offset, |
| 603 | uint32_t *length); |
| 604 | |
| 605 | /** @brief Create a PLDM response for ReadFileByType and |
| 606 | * WriteFileByType |
| 607 | * |
| 608 | * @param[in] instance_id - Message's instance id |
| 609 | * @param[in] command - PLDM command |
| 610 | * @param[in] completion_code - PLDM completion code |
| 611 | * @param[in] length - Number of bytes read/written. This could be less than |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 612 | * what the requester asked for. |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 613 | * @param[in,out] msg - Message will be written to this |
| 614 | * @return pldm_completion_codes |
| 615 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 616 | * @note File content has to be copied directly by the caller. |
| 617 | */ |
| 618 | int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command, |
| 619 | uint8_t completion_code, uint32_t length, |
| 620 | struct pldm_msg *msg); |
| 621 | |
| 622 | /** @brief Encode ReadFileByType and WriteFileByType |
| 623 | * commands request data |
| 624 | * |
| 625 | * @param[in] instance_id - Message's instance id |
| 626 | * @param[in] command - PLDM command |
| 627 | * @param[in] file_type - Type of the file |
| 628 | * @param[in] file_handle - A handle to the file |
| 629 | * @param[in] offset - Offset to the file at which the read should begin |
| 630 | * @param[in] length - Number of bytes to be read/written |
| 631 | * @param[out] msg - Message will be written to this |
| 632 | * @return pldm_completion_codes |
| 633 | * @note File content has to be read directly by the caller. |
| 634 | */ |
| 635 | int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command, |
| 636 | uint16_t file_type, uint32_t file_handle, |
| 637 | uint32_t offset, uint32_t length, |
| 638 | struct pldm_msg *msg); |
| 639 | |
| 640 | /** @brief Decode ReadFileByType and WriteFileByType |
| 641 | * commands response data |
| 642 | * |
| 643 | * @param[in] msg - pointer to PLDM response message |
| 644 | * @param[in] payload_length - Length of response payload |
| 645 | * @param[out] completion_code - PLDM completion code |
| 646 | * @param[out] length - Number of bytes to be read/written |
| 647 | * @return pldm_completion_codes |
| 648 | */ |
| 649 | int decode_rw_file_by_type_resp(const struct pldm_msg *msg, |
| 650 | size_t payload_length, uint8_t *completion_code, |
| 651 | uint32_t *length); |
| 652 | |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 653 | /** @struct pldm_file_ack_req |
| 654 | * |
| 655 | * Structure representing FileAck request |
| 656 | */ |
| 657 | struct pldm_file_ack_req { |
| 658 | uint16_t file_type; //!< Type of file |
| 659 | uint32_t file_handle; //!< Handle to file |
| 660 | uint8_t file_status; //!< Status of file processing |
| 661 | } __attribute__((packed)); |
| 662 | |
| 663 | /** @struct pldm_file_ack_resp |
| 664 | * |
| 665 | * Structure representing NewFile response data |
| 666 | */ |
| 667 | struct pldm_file_ack_resp { |
| 668 | uint8_t completion_code; //!< Completion code |
| 669 | } __attribute__((packed)); |
| 670 | |
| 671 | /** @brief Decode FileAck command request data |
| 672 | * |
| 673 | * @param[in] msg - Pointer to PLDM request message |
| 674 | * @param[in] payload_length - Length of request payload |
| 675 | * @param[out] file_type - Type of the file |
| 676 | * @param[out] file_handle - A handle to the file |
| 677 | * @param[out] file_status - Status of file processing |
| 678 | * @return pldm_completion_codes |
| 679 | */ |
| 680 | int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length, |
| 681 | uint16_t *file_type, uint32_t *file_handle, |
| 682 | uint8_t *file_status); |
| 683 | |
| 684 | /** @brief Create a PLDM response for FileAck |
| 685 | * |
| 686 | * @param[in] instance_id - Message's instance id |
| 687 | * @param[in] completion_code - PLDM completion code |
| 688 | * @param[in,out] msg - Message will be written to this |
| 689 | * @return pldm_completion_codes |
| 690 | * @note Caller is responsible for memory alloc and dealloc of param 'msg' |
| 691 | */ |
| 692 | int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code, |
| 693 | struct pldm_msg *msg); |
| 694 | |
| 695 | /** @brief Encode FileAck command request data |
| 696 | * |
| 697 | * @param[in] instance_id - Message's instance id |
| 698 | * @param[in] file_type - Type of the file |
| 699 | * @param[in] file_handle - A handle to the file |
| 700 | * @param[in] file_status - Status of file processing |
| 701 | * @param[out] msg - Message will be written to this |
| 702 | * @return pldm_completion_codes |
| 703 | */ |
| 704 | int encode_file_ack_req(uint8_t instance_id, uint16_t file_type, |
| 705 | uint32_t file_handle, uint8_t file_status, |
| 706 | struct pldm_msg *msg); |
| 707 | |
| 708 | /** @brief Decode FileAck command response data |
| 709 | * |
| 710 | * @param[in] msg - pointer to PLDM response message |
| 711 | * @param[in] payload_length - Length of response payload |
| 712 | * @param[out] completion_code - PLDM completion code |
| 713 | * @return pldm_completion_codes |
| 714 | */ |
| 715 | int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length, |
| 716 | uint8_t *completion_code); |
| 717 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 718 | #ifdef __cplusplus |
| 719 | } |
| 720 | #endif |
| 721 | |
| 722 | #endif /* FILEIO_H */ |