1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #ifndef FILEIO_H
3 #define FILEIO_H
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 
12 struct pldm_msg;
13 /** @brief PLDM Commands in IBM OEM type
14  */
15 enum pldm_fileio_commands {
16 	PLDM_GET_FILE_TABLE = 0x1,
17 	PLDM_READ_FILE = 0x4,
18 	PLDM_WRITE_FILE = 0x5,
19 	PLDM_READ_FILE_INTO_MEMORY = 0x6,
20 	PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
21 	PLDM_READ_FILE_BY_TYPE_INTO_MEMORY = 0x8,
22 	PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY = 0x9,
23 	PLDM_NEW_FILE_AVAILABLE = 0xa,
24 	PLDM_READ_FILE_BY_TYPE = 0xb,
25 	PLDM_WRITE_FILE_BY_TYPE = 0xc,
26 	PLDM_FILE_ACK = 0xd,
27 	PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA = 0xe,
28 	PLDM_FILE_ACK_WITH_META_DATA = 0xf,
29 };
30 
31 /** @brief PLDM Command specific codes
32  */
33 enum pldm_fileio_completion_codes {
34 	PLDM_FILE_TABLE_UNAVAILABLE = 0x83,
35 	PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
36 	PLDM_INVALID_FILE_HANDLE = 0x86,
37 	PLDM_DATA_OUT_OF_RANGE = 0x87,
38 	PLDM_INVALID_FILE_TYPE = 0x89,
39 	PLDM_ERROR_FILE_DISCARDED = 0x8a,
40 	PLDM_FULL_FILE_DISCARDED = 0x8b,
41 };
42 
43 /** @brief PLDM File I/O table types
44  */
45 enum pldm_fileio_table_type {
46 	PLDM_FILE_ATTRIBUTE_TABLE = 0,
47 	PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
48 };
49 
50 /** @brief PLDM File I/O table types
51  */
52 enum pldm_fileio_file_type {
53 	PLDM_FILE_TYPE_PEL = 0x0,
54 	PLDM_FILE_TYPE_LID_PERM = 0x1,
55 	PLDM_FILE_TYPE_LID_TEMP = 0x2,
56 	PLDM_FILE_TYPE_DUMP = 0x3,
57 	PLDM_FILE_TYPE_CERT_SIGNING_REQUEST = 0x4,
58 	PLDM_FILE_TYPE_SIGNED_CERT = 0x5,
59 	PLDM_FILE_TYPE_ROOT_CERT = 0x6,
60 	PLDM_FILE_TYPE_LID_MARKER = 0x7,
61 	PLDM_FILE_TYPE_RESOURCE_DUMP_PARMS = 0x8,
62 	PLDM_FILE_TYPE_RESOURCE_DUMP = 0x9,
63 	PLDM_FILE_TYPE_PROGRESS_SRC = 0xa,
64 	PLDM_FILE_TYPE_ADJUNCT_DUMP = 0xb,
65 	PLDM_FILE_TYPE_DEVICE_DUMP = 0xc,
66 	PLDM_FILE_TYPE_COD_LICENSE_KEY = 0xd,
67 	PLDM_FILE_TYPE_COD_LICENSED_RESOURCES = 0xe,
68 	PLDM_FILE_TYPE_BMC_DUMP = 0xf,
69 	PLDM_FILE_TYPE_SBE_DUMP = 0x10,
70 	PLDM_FILE_TYPE_HOSTBOOT_DUMP = 0x11,
71 	PLDM_FILE_TYPE_HARDWARE_DUMP = 0x12,
72 	PLDM_FILE_TYPE_LID_RUNNING = 0x13,
73 	PLDM_FILE_TYPE_PCIE_TOPOLOGY = 0x14,
74 	PLDM_FILE_TYPE_CABLE_INFO = 0x15,
75 	PLDM_FILE_TYPE_PSPD_VPD_PDD_KEYWORD = 0x16,
76 	PLDM_FILE_TYPE_CHAP_DATA = 0x17,
77 	PLDM_FILE_TYPE_USER_PASSWORD_AUTHENTICATION = 0x18,
78 	PLDM_FILE_TYPE_USER_PASSWORD_CHANGE = 0x19,
79 };
80 
81 #define PLDM_RW_FILE_MEM_REQ_BYTES			  20
82 #define PLDM_RW_FILE_MEM_RESP_BYTES			  5
83 #define PLDM_GET_FILE_TABLE_REQ_BYTES			  6
84 #define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES		  6
85 #define PLDM_READ_FILE_REQ_BYTES			  12
86 #define PLDM_READ_FILE_RESP_BYTES			  5
87 #define PLDM_WRITE_FILE_REQ_BYTES			  12
88 #define PLDM_WRITE_FILE_RESP_BYTES			  5
89 #define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES		  22
90 #define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES		  5
91 #define PLDM_NEW_FILE_REQ_BYTES				  14
92 #define PLDM_NEW_FILE_RESP_BYTES			  1
93 #define PLDM_RW_FILE_BY_TYPE_REQ_BYTES			  14
94 #define PLDM_RW_FILE_BY_TYPE_RESP_BYTES			  5
95 #define PLDM_FILE_ACK_REQ_BYTES				  7
96 #define PLDM_FILE_ACK_RESP_BYTES			  1
97 #define PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES		  23
98 #define PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES		  1
99 #define PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES  30
100 #define PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES 1
101 
102 /** @struct pldm_read_write_file_memory_req
103  *
104  *  Structure representing ReadFileIntoMemory request and WriteFileFromMemory
105  *  request
106  */
107 struct pldm_read_write_file_memory_req {
108 	uint32_t file_handle; //!< A Handle to the file
109 	uint32_t offset;      //!< Offset to the file
110 	uint32_t length;      //!< Number of bytes to be read/write
111 	uint64_t address;     //!< Memory address of the file
112 } __attribute__((packed));
113 
114 /** @struct pldm_read_write_file_memory_resp
115  *
116  *  Structure representing ReadFileIntoMemory response and WriteFileFromMemory
117  *  response
118  */
119 struct pldm_read_write_file_memory_resp {
120 	uint8_t completion_code; //!< completion code
121 	uint32_t length;	 //!< Number of bytes read/written
122 } __attribute__((packed));
123 
124 /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
125  *         data
126  *
127  *  @param[in] msg - Pointer to PLDM request message
128  *  @param[in] payload_length - Length of request payload
129  *  @param[out] file_handle - A handle to the file
130  *  @param[out] offset - Offset to the file at which the read should begin
131  *  @param[out] length - Number of bytes to be read
132  *  @param[out] address - Memory address where the file content has to be
133  *                        written to
134  *  @return pldm_completion_codes
135  */
136 int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
137 			      uint32_t *file_handle, uint32_t *offset,
138 			      uint32_t *length, uint64_t *address);
139 
140 /** @brief Create a PLDM response for ReadFileIntoMemory and
141  *         WriteFileFromMemory
142  *
143  *  @param[in] instance_id - Message's instance id
144  *  @param[in] command - PLDM command
145  *  @param[in] completion_code - PLDM completion code
146  *  @param[in] length - Number of bytes read. This could be less than what the
147 			 requester asked for.
148  *  @param[in,out] msg - Message will be written to this
149  *  @return pldm_completion_codes
150  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
151  */
152 int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
153 			       uint8_t completion_code, uint32_t length,
154 			       struct pldm_msg *msg);
155 
156 /** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
157  *         commands request data
158  *
159  *  @param[in] instance_id - Message's instance id
160  *  @param[in] command - PLDM command
161  *  @param[in] file_handle - A handle to the file
162  *  @param[in] offset -  Offset to the file at which the read should begin
163  *  @param[in] length -  Number of bytes to be read/written
164  *  @param[in] address - Memory address where the file content has to be
165  *                       written to
166  *  @param[out] msg - Message will be written to this
167  *  @return pldm_completion_codes
168  */
169 int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
170 			      uint32_t file_handle, uint32_t offset,
171 			      uint32_t length, uint64_t address,
172 			      struct pldm_msg *msg);
173 
174 /** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
175  *         commands response data
176  *
177  *  @param[in] msg - pointer to PLDM response message
178  *  @param[in] payload_length - Length of response payload
179  *  @param[out] completion_code - PLDM completion code
180  *  @param[out] length - Number of bytes to be read/written
181  *  @return pldm_completion_codes
182  */
183 int decode_rw_file_memory_resp(const struct pldm_msg *msg,
184 			       size_t payload_length, uint8_t *completion_code,
185 			       uint32_t *length);
186 
187 /** @struct pldm_get_file_table_req
188  *
189  *  Structure representing GetFileTable request
190  */
191 struct pldm_get_file_table_req {
192 	uint32_t transfer_handle; //!< Data transfer handle
193 	uint8_t operation_flag;	  //!< Transfer operation flag
194 	uint8_t table_type;	  //!< Table type
195 } __attribute__((packed));
196 
197 /** @struct pldm_get_file_table_resp
198  *
199  *  Structure representing GetFileTable response fixed data
200  */
201 struct pldm_get_file_table_resp {
202 	uint8_t completion_code;       //!< Completion code
203 	uint32_t next_transfer_handle; //!< Next data transfer handle
204 	uint8_t transfer_flag;	       //!< Transfer flag
205 	uint8_t table_data[1];	       //!< Table Data
206 } __attribute__((packed));
207 
208 /** @struct pldm_file_attr_table_entry
209  *
210  * Structure representing File attribute table entry
211  */
212 struct pldm_file_attr_table_entry {
213 	uint32_t file_handle;		//!< File Handle
214 	uint16_t file_name_length;	//!< File name length
215 	uint8_t file_attr_table_nst[1]; //!< File name size traits
216 } __attribute__((packed));
217 
218 /** @brief Decode GetFileTable command request data
219  *
220  *  @param[in] msg - Pointer to PLDM request message
221  *  @param[in] payload_length - Length of request payload
222  *  @param[out] trasnfer_handle - the handle of data
223  *  @param[out] transfer_opflag - Transfer operation flag
224  *  @param[out] table_type - the type of file table
225  *  @return pldm_completion_codes
226  */
227 int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
228 			      uint32_t *transfer_handle,
229 			      uint8_t *transfer_opflag, uint8_t *table_type);
230 
231 /** @brief Create a PLDM response for GetFileTable command
232  *
233  *  @param[in] instance_id - Message's instance id
234  *  @param[in] completion_code - PLDM completion code
235  *  @param[in] next_transfer_handle - Handle to identify next portion of
236  *              data transfer
237  *  @param[in] transfer_flag - Represents the part of transfer
238  *  @param[in] table_data - pointer to file table data
239  *  @param[in] table_size - file table size
240  *  @param[in,out] msg - Message will be written to this
241  *  @return pldm_completion_codes
242  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
243  */
244 int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
245 			       uint32_t next_transfer_handle,
246 			       uint8_t transfer_flag, const uint8_t *table_data,
247 			       size_t table_size, struct pldm_msg *msg);
248 
249 /** @brief Encode GetFileTable command request data
250  *
251  * @param[in] instance_id - Message's instance id
252  * @param[in] transfer_handle - the handle of data
253  * @param[in] transfer_opflag - Transfer operation flag
254  * @param[in] table_type - the type of file table
255  * @param[out] msg - Message will be written to this
256  * @return pldm_completion_codes
257  */
258 int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle,
259 			      uint8_t transfer_opflag, uint8_t table_type,
260 			      struct pldm_msg *msg);
261 
262 /** @brief Decode GetFileTable command response data
263  * @param[in] msg - Response message
264  * @param[in] payload_length - length of response message payload
265  * @param[out] completion_code - PLDM completion code
266  * @param[out] next_transfer_handle -  Handle to identify next portion of data
267  * transfer
268  * @param[out] transfer_flag - Represents the part of transfer
269  * @param[out] file_table_data_start_offset - This data is a portion of the
270  * overall File Table
271  * @param[out] file_table_length - Length of the File table data
272  * @return pldm_completion_codes
273  */
274 int decode_get_file_table_resp(const struct pldm_msg *msg,
275 			       size_t payload_length, uint8_t *completion_code,
276 			       uint32_t *next_transfer_handle,
277 			       uint8_t *transfer_flag,
278 			       uint8_t *file_table_data_start_offset,
279 			       size_t *file_table_length);
280 
281 /** @struct pldm_read_file_req
282  *
283  *  Structure representing ReadFile request
284  */
285 struct pldm_read_file_req {
286 	uint32_t file_handle; //!< Handle to file
287 	uint32_t offset;      //!< Offset to file where read starts
288 	uint32_t length;      //!< Bytes to be read
289 } __attribute__((packed));
290 
291 /** @struct pldm_read_file_resp
292  *
293  *  Structure representing ReadFile response data
294  */
295 struct pldm_read_file_resp {
296 	uint8_t completion_code; //!< Completion code
297 	uint32_t length;	 //!< Number of bytes read
298 	uint8_t file_data[1];	 //!< Address of this is where file data starts
299 } __attribute__((packed));
300 
301 /** @struct pldm_write_file_req
302  *
303  *  Structure representing WriteFile request
304  */
305 struct pldm_write_file_req {
306 	uint32_t file_handle; //!< Handle to file
307 	uint32_t offset;      //!< Offset to file where write starts
308 	uint32_t length;      //!< Bytes to be written
309 	uint8_t file_data[1]; //!< Address of this is where file data starts
310 } __attribute__((packed));
311 
312 /** @struct pldm_write_file_resp
313  *
314  *  Structure representing WriteFile response data
315  */
316 struct pldm_write_file_resp {
317 	uint8_t completion_code; //!< Completion code
318 	uint32_t length;	 //!< Bytes written
319 } __attribute__((packed));
320 
321 /** @brief Decode Read File commands request
322  *
323  *  @param[in] msg - PLDM request message payload
324  *  @param[in] payload_length - Length of request payload
325  *  @param[out] file_handle - A handle to the file
326  *  @param[out] offset - Offset to the file at which the read should begin
327  *  @param[out] length - Number of bytes read
328  *  @return pldm_completion_codes
329  */
330 int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
331 			 uint32_t *file_handle, uint32_t *offset,
332 			 uint32_t *length);
333 
334 /** @brief Encode Read File commands request
335  *
336  *  @param[in] instance_id - Message's instance id
337  *  @param[in] file_handle - A handle to the file
338  *  @param[in] offset - Offset to the file at which the read should begin
339  *  @param[in] length - Number of bytes read
340  *  @param[in,out] msg - Message will be written to this
341  *  @return pldm_completion_codes
342  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
343  */
344 int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
345 			 uint32_t offset, uint32_t length,
346 			 struct pldm_msg *msg);
347 
348 /** @brief Decode Read File commands response
349  *
350  *  @param[in] msg - PLDM response message payload
351  *  @param[in] payload_length - Length of request payload
352  *  @param[out] completion_code - PLDM completion code
353  *  @param[out] length - Number of bytes read. This could be less than what the
354  *                       requester asked for.
355  *  @param[out] file_data_offset - Offset where file data should be read in pldm
356  * msg.
357  *  @return pldm_completion_codes
358  */
359 int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
360 			  uint8_t *completion_code, uint32_t *length,
361 			  size_t *file_data_offset);
362 
363 /** @brief Create a PLDM response for Read File
364  *
365  *  @param[in] instance_id - Message's instance id
366  *  @param[in] completion_code - PLDM completion code
367  *  @param[in] length - Number of bytes read. This could be less than what the
368  *                      requester asked for.
369  *  @param[in,out] msg - Message will be written to this
370  *  @return pldm_completion_codes
371  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'.
372  *  Although read file command response includes file data, this function
373  *  does not encode the file data to prevent additional copying of the data.
374  *  The position of file data is calculated by caller from address and size
375  *  of other input arguments.
376  */
377 int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
378 			  uint32_t length, struct pldm_msg *msg);
379 
380 /** @brief Decode Write File commands request
381  *
382  *  @param[in] msg - PLDM request message payload
383  *  @param[in] payload_length - Length of request payload
384  *  @param[out] file_handle - A handle to the file
385  *  @param[out] offset - Offset to the file at which the write should begin
386  *  @param[out] length - Number of bytes to write
387  *  @param[out] file_data_offset - Offset where file data write begins in pldm
388  * msg.
389  *  @return pldm_completion_codes
390  */
391 int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
392 			  uint32_t *file_handle, uint32_t *offset,
393 			  uint32_t *length, size_t *file_data_offset);
394 
395 /** @brief Create a PLDM request for Write File
396  *
397  *  @param[in] instance_id - Message's instance id
398  *  @param[in] file_handle - A handle to the file
399  *  @param[in] offset - Offset to the file at which the read should begin
400  *  @param[in] length - Number of bytes written. This could be less than what
401  *                      the requester asked for.
402  *  @param[in,out] msg - Message will be written to this
403  *  @return pldm_completion_codes
404  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'.
405  *  Although write file command request includes file data, this function
406  *  does not encode the file data to prevent additional copying of the data.
407  *  The position of file data is calculated by caller from address and size
408  *  of other input arguments.
409  */
410 int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
411 			  uint32_t offset, uint32_t length,
412 			  struct pldm_msg *msg);
413 
414 /** @brief Decode Write File commands response
415  *
416  *  @param[in] msg - PLDM request message payload
417  *  @param[in] payload_length - Length of request payload
418  *  @param[out] completion_code - PLDM completion code
419  *  @param[out] length - Number of bytes written
420  *  @return pldm_completion_codes
421  */
422 int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
423 			   uint8_t *completion_code, uint32_t *length);
424 
425 /** @brief Create a PLDM response for Write File
426  *
427  *  @param[in] instance_id - Message's instance id
428  *  @param[in] completion_code - PLDM completion code
429  *  @param[in] length - Number of bytes written. This could be less than what
430  *                      the requester asked for.
431  *  @param[in,out] msg - Message will be written to this
432  *  @return pldm_completion_codes
433  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
434  */
435 int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
436 			   uint32_t length, struct pldm_msg *msg);
437 
438 /** @struct pldm_read_write_file_by_type_memory_req
439  *
440  *  Structure representing ReadFileByTypeIntoMemory and
441  * WriteFileByTypeFromMemory request
442  */
443 struct pldm_read_write_file_by_type_memory_req {
444 	uint16_t file_type;   //!< Type of file
445 	uint32_t file_handle; //!< Handle to file
446 	uint32_t offset;      //!< Offset to file where read starts
447 	uint32_t length;      //!< Bytes to be read
448 	uint64_t address;     //!< Memory address of the file
449 } __attribute__((packed));
450 
451 /** @struct pldm_read_write_file_by_type_memory_resp
452  *
453  *  Structure representing ReadFileByTypeIntoMemory and
454  * WriteFileByTypeFromMemory response
455  */
456 struct pldm_read_write_file_by_type_memory_resp {
457 	uint8_t completion_code; //!< Completion code
458 	uint32_t length;	 //!< Number of bytes read
459 } __attribute__((packed));
460 
461 /** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
462  * commands request data
463  *
464  *  @param[in] msg - Pointer to PLDM request message
465  *  @param[in] payload_length - Length of request payload
466  *  @param[in] file_type - Type of the file
467  *  @param[out] file_handle - A handle to the file
468  *  @param[out] offset - Offset to the file at which the read should begin
469  *  @param[out] length - Number of bytes to be read
470  *  @param[out] address - Memory address of the file content
471  *  @return pldm_completion_codes
472  */
473 int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
474 				      size_t payload_length,
475 				      uint16_t *file_type,
476 				      uint32_t *file_handle, uint32_t *offset,
477 				      uint32_t *length, uint64_t *address);
478 
479 /** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
480  * WriteFileByTypeFromMemory
481  *
482  *  @param[in] instance_id - Message's instance id
483  *  @param[in] command - PLDM command
484  *  @param[in] completion_code - PLDM completion code
485  *  @param[in] length - Number of bytes read. This could be less than what the
486  *                      requester asked for.
487  *  @param[in,out] msg - Message will be written to this
488  *  @return pldm_completion_codes
489  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
490  */
491 int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
492 				       uint8_t completion_code, uint32_t length,
493 				       struct pldm_msg *msg);
494 
495 /** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
496  *         commands request data
497  *
498  *  @param[in] instance_id - Message's instance id
499  *  @param[in] command - PLDM command
500  *  @param[in] file_type - Type of the file
501  *  @param[in] file_handle - A handle to the file
502  *  @param[in] offset -  Offset to the file at which the read should begin
503  *  @param[in] length -  Number of bytes to be read/written
504  *  @param[in] address - Memory address where the file content has to be
505  *                       written to
506  *  @param[out] msg - Message will be written to this
507  *  @return pldm_completion_codes
508  */
509 int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
510 				      uint16_t file_type, uint32_t file_handle,
511 				      uint32_t offset, uint32_t length,
512 				      uint64_t address, struct pldm_msg *msg);
513 
514 /** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
515  *         commands response data
516  *
517  *  @param[in] msg - pointer to PLDM response message
518  *  @param[in] payload_length - Length of response payload
519  *  @param[out] completion_code - PLDM completion code
520  *  @param[out] length - Number of bytes to be read/written
521  *  @return pldm_completion_codes
522  */
523 int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
524 				       size_t payload_length,
525 				       uint8_t *completion_code,
526 				       uint32_t *length);
527 
528 /** @struct pldm_new_file_req
529  *
530  *  Structure representing NewFile request
531  */
532 struct pldm_new_file_req {
533 	uint16_t file_type;   //!< Type of file
534 	uint32_t file_handle; //!< Handle to file
535 	uint64_t length;      //!< Number of bytes in new file
536 } __attribute__((packed));
537 
538 /** @struct pldm_new_file_resp
539  *
540  *  Structure representing NewFile response data
541  */
542 struct pldm_new_file_resp {
543 	uint8_t completion_code; //!< Completion code
544 } __attribute__((packed));
545 
546 /** @brief Decode NewFileAvailable command request data
547  *
548  *  @param[in] msg - Pointer to PLDM request message
549  *  @param[in] payload_length - Length of request payload
550  *  @param[in] file_type - Type of the file
551  *  @param[out] file_handle - A handle to the file
552  *  @param[out] length - Number of bytes in new file
553  *  @return pldm_completion_codes
554  */
555 int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
556 			uint16_t *file_type, uint32_t *file_handle,
557 			uint64_t *length);
558 
559 /** @brief Create a PLDM response for NewFileAvailable
560  *
561  *  @param[in] instance_id - Message's instance id
562  *  @param[in] completion_code - PLDM completion code
563  *  @param[in,out] msg - Message will be written to this
564  *  @return pldm_completion_codes
565  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
566  */
567 int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
568 			 struct pldm_msg *msg);
569 
570 /** @brief Encode NewFileAvailable command request data
571  *
572  *  @param[in] instance_id - Message's instance id
573  *  @param[in] file_type - Type of the file
574  *  @param[in] file_handle - A handle to the file
575  *  @param[in] length -  Number of bytes in new file
576  *  @param[out] msg - Message will be written to this
577  *  @return pldm_completion_codes
578  */
579 int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
580 			uint32_t file_handle, uint64_t length,
581 			struct pldm_msg *msg);
582 
583 /** @brief Decode NewFileAvailable command response data
584  *
585  *  @param[in] msg - pointer to PLDM response message
586  *  @param[in] payload_length - Length of response payload
587  *  @param[out] completion_code - PLDM completion code
588  *  @return pldm_completion_codes
589  */
590 int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
591 			 uint8_t *completion_code);
592 
593 /** @struct pldm_read_write_file_by_type_req
594  *
595  *  Structure representing ReadFileByType and
596  *  WriteFileByType request
597  */
598 struct pldm_read_write_file_by_type_req {
599 	uint16_t file_type;   //!< Type of file
600 	uint32_t file_handle; //!< Handle to file
601 	uint32_t offset;      //!< Offset to file where read/write starts
602 	uint32_t length;      //!< Bytes to be read
603 } __attribute__((packed));
604 
605 /** @struct pldm_read_write_file_by_type_resp
606  *
607  *  Structure representing ReadFileByType and
608  *  WriteFileByType response
609  */
610 struct pldm_read_write_file_by_type_resp {
611 	uint8_t completion_code; //!< Completion code
612 	uint32_t length;	 //!< Number of bytes read
613 } __attribute__((packed));
614 
615 /** @brief Decode ReadFileByType and WriteFileByType
616  *  commands request data
617  *
618  *  @param[in] msg - Pointer to PLDM request message
619  *  @param[in] payload_length - Length of request payload
620  *  @param[out] file_type - Type of the file
621  *  @param[out] file_handle - A handle to the file
622  *  @param[out] offset - Offset to the file at which the read/write should begin
623  *  @param[out] length - Number of bytes to be read/written
624  *  @return pldm_completion_codes
625  */
626 int decode_rw_file_by_type_req(const struct pldm_msg *msg,
627 			       size_t payload_length, uint16_t *file_type,
628 			       uint32_t *file_handle, uint32_t *offset,
629 			       uint32_t *length);
630 
631 /** @brief Create a PLDM response for ReadFileByType and
632  *  WriteFileByType
633  *
634  *  @param[in] instance_id - Message's instance id
635  *  @param[in] command - PLDM command
636  *  @param[in] completion_code - PLDM completion code
637  *  @param[in] length - Number of bytes read/written. This could be less than
638  *                      what the requester asked for.
639  *  @param[in,out] msg - Message will be written to this
640  *  @return pldm_completion_codes
641  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
642  *  @note File content has to be copied directly by the caller.
643  */
644 int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
645 				uint8_t completion_code, uint32_t length,
646 				struct pldm_msg *msg);
647 
648 /** @brief Encode ReadFileByType and WriteFileByType
649  *         commands request data
650  *
651  *  @param[in] instance_id - Message's instance id
652  *  @param[in] command - PLDM command
653  *  @param[in] file_type - Type of the file
654  *  @param[in] file_handle - A handle to the file
655  *  @param[in] offset -  Offset to the file at which the read should begin
656  *  @param[in] length -  Number of bytes to be read/written
657  *  @param[out] msg - Message will be written to this
658  *  @return pldm_completion_codes
659  *  @note File content has to be read directly by the caller.
660  */
661 int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
662 			       uint16_t file_type, uint32_t file_handle,
663 			       uint32_t offset, uint32_t length,
664 			       struct pldm_msg *msg);
665 
666 /** @brief Decode ReadFileByType and WriteFileByType
667  *         commands response data
668  *
669  *  @param[in] msg - pointer to PLDM response message
670  *  @param[in] payload_length - Length of response payload
671  *  @param[out] completion_code - PLDM completion code
672  *  @param[out] length - Number of bytes to be read/written
673  *  @return pldm_completion_codes
674  */
675 int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
676 				size_t payload_length, uint8_t *completion_code,
677 				uint32_t *length);
678 
679 /** @struct pldm_file_ack_req
680  *
681  *  Structure representing FileAck request
682  */
683 struct pldm_file_ack_req {
684 	uint16_t file_type;   //!< Type of file
685 	uint32_t file_handle; //!< Handle to file
686 	uint8_t file_status;  //!< Status of file processing
687 } __attribute__((packed));
688 
689 /** @struct pldm_file_ack_resp
690  *
691  *  Structure representing NewFile response data
692  */
693 struct pldm_file_ack_resp {
694 	uint8_t completion_code; //!< Completion code
695 } __attribute__((packed));
696 
697 /** @brief Decode FileAck command request data
698  *
699  *  @param[in] msg - Pointer to PLDM request message
700  *  @param[in] payload_length - Length of request payload
701  *  @param[out] file_type - Type of the file
702  *  @param[out] file_handle - A handle to the file
703  *  @param[out] file_status - Status of file processing
704  *  @return pldm_completion_codes
705  */
706 int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
707 			uint16_t *file_type, uint32_t *file_handle,
708 			uint8_t *file_status);
709 
710 /** @brief Create a PLDM response for FileAck
711  *
712  *  @param[in] instance_id - Message's instance id
713  *  @param[in] completion_code - PLDM completion code
714  *  @param[in,out] msg - Message will be written to this
715  *  @return pldm_completion_codes
716  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
717  */
718 int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
719 			 struct pldm_msg *msg);
720 
721 /** @brief Encode FileAck command request data
722  *
723  *  @param[in] instance_id - Message's instance id
724  *  @param[in] file_type - Type of the file
725  *  @param[in] file_handle - A handle to the file
726  *  @param[in] file_status - Status of file processing
727  *  @param[out] msg - Message will be written to this
728  *  @return pldm_completion_codes
729  */
730 int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
731 			uint32_t file_handle, uint8_t file_status,
732 			struct pldm_msg *msg);
733 
734 /** @brief Decode FileAck command response data
735  *
736  *  @param[in] msg - pointer to PLDM response message
737  *  @param[in] payload_length - Length of response payload
738  *  @param[out] completion_code - PLDM completion code
739  *  @return pldm_completion_codes
740  */
741 int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
742 			 uint8_t *completion_code);
743 
744 /* FileAckWithMetadata */
745 
746 /** @struct pldm_file_ack_with_meta_data_req
747  *
748  *  Structure representing FileAckWithMetadata request
749  */
750 struct pldm_file_ack_with_meta_data_req {
751 	uint16_t file_type;	   //!< Type of file
752 	uint32_t file_handle;	   //!< Handle to file
753 	uint8_t file_status;	   //!< Status of file processing
754 	uint32_t file_meta_data_1; //!< Meta data specific to file type 1
755 	uint32_t file_meta_data_2; //!< Meta data specific to file type 2
756 	uint32_t file_meta_data_3; //!< Meta data specific to file type 3
757 	uint32_t file_meta_data_4; //!< meta data specific to file type 4
758 } __attribute__((packed));
759 
760 /** @struct pldm_file_ack_with_meta_data_resp
761  *
762  *  Structure representing FileAckWithMetadata response
763  */
764 struct pldm_file_ack_with_meta_data_resp {
765 	uint8_t completion_code; //!< Completion code
766 } __attribute__((packed));
767 
768 /** @brief Encode FileAckWithMetadata request data
769  *
770  *  @param[in] instance_id - Message's instance id
771  *  @param[in] file_type - Type of the file
772  *  @param[in] file_handle - A handle to the file
773  *  @param[in] file_status - Status of file processing
774  *  @param[in] file_meta_data_1 - meta data specific to file type 1
775  *  @param[in] file_meta_data_2 - meta data specific to file type 2
776  *  @param[in] file_meta_data_3 - meta data specific to file type 3
777  *  @param[in] file_meta_data_4 - Meta data specific to file type 4
778  *  @param[out] msg - Message will be written to this
779  *  @return pldm_completion_codes
780  */
781 int encode_file_ack_with_meta_data_req(
782 	uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
783 	uint8_t file_status, uint32_t file_meta_data_1,
784 	uint32_t file_meta_data_2, uint32_t file_meta_data_3,
785 	uint32_t file_meta_data_4, struct pldm_msg *msg);
786 
787 /** @brief Decode FileAckWithMetadata command response data
788  *
789  * @param[in] msg - pointer to PLDM response message
790  * @param[in] payload_length - Length of response payload
791  * @param[out] completion_code - PLDM completion code
792  * @return pldm_completion_codes
793  */
794 int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg,
795 					size_t payload_length,
796 					uint8_t *completion_code);
797 
798 /** @brief Decode FileAckWithMetadata request data
799  *
800  * @param[in] msg - Pointer to PLDM request message
801  * @param[in] payload_length - Length of request payload
802  * @param[out] file_type - Type of the file
803  * @param[out] file_handle - A handle to the file
804  * @param[out] file_status - Status of file processing
805  * @param[out] file_meta_data_1 - meta data specific to file type 1
806  * @param[out] file_meta_data_2 - meta data specific to file type 2
807  * @param[out] file_meta_data_3 - meta data specific to file type 3
808  * @param[out] file_meta_data_4 - Meta data specific to file type 4
809  * @return pldm_completion_codes
810  */
811 int decode_file_ack_with_meta_data_req(
812 	const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
813 	uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1,
814 	uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
815 	uint32_t *file_meta_data_4);
816 
817 /** @brief Create a PLDM response message for FileAckWithMetadata
818  *
819  * @param[in] instance_id - Message's instance id
820  * @param[in] completion_code - PLDM completion code
821  * @param[in,out] msg - Message will be written to this
822  * @return pldm_completion_codes
823  */
824 int encode_file_ack_with_meta_data_resp(uint8_t instance_id,
825 					uint8_t completion_code,
826 					struct pldm_msg *msg);
827 
828 /* NewFileAvailableWithMetaData */
829 
830 /** @struct pldm_new_file_with_metadata_req
831  *
832  *  Structure representing NewFileAvailableWithMetaData request
833  */
834 
835 struct pldm_new_file_with_metadata_req {
836 	uint16_t file_type;	   //!< Type of file
837 	uint32_t file_handle;	   //!< Handle to file
838 	uint64_t length;	   //!< Number of bytes in new file
839 	uint32_t file_meta_data_1; //!< Meta data specific to file type 1
840 	uint32_t file_meta_data_2; //!< Meta data specific to file type 2
841 	uint32_t file_meta_data_3; //!< Meta data specific to file type 3
842 	uint32_t file_meta_data_4; //!< Meta data specific to file type 4
843 } __attribute__((packed));
844 
845 /** @struct pldm_new_file_with_metadata_resp
846  *
847  *  Structure representing NewFileAvailableWithMetaData response data
848  */
849 struct pldm_new_file_with_metadata_resp {
850 	uint8_t completion_code; //!< Completion code
851 } __attribute__((packed));
852 
853 /** @brief Encode NewFileAvailableWithMetaData request data
854  *
855  *  @param[in] instance_id - Message's instance id
856  *  @param[in] file_type - Type of the file
857  *  @param[in] file_handle - A handle to the file
858  *  @param[in] length -  Number of bytes in new file
859  *  @param[in] file_meta_data_1 - Meta data specific to file type 1
860  *  @param[in] file_meta_data_2 - Meta data specific to file type 2
861  *  @param[in] file_meta_data_3 - Meta data specific to file type 3
862  *  @param[in] file_meta_data_4 - Meta data specific to file type 4
863  *  @param[out] msg - Message will be written to this
864  *  @return pldm_completion_codes
865  */
866 int encode_new_file_with_metadata_req(uint8_t instance_id, uint16_t file_type,
867 				      uint32_t file_handle, uint64_t length,
868 				      uint32_t file_meta_data_1,
869 				      uint32_t file_meta_data_2,
870 				      uint32_t file_meta_data_3,
871 				      uint32_t file_meta_data_4,
872 				      struct pldm_msg *msg);
873 
874 /** @brief Decode NewFileAvailableWithMetaData response data
875  *
876  *  @param[in] msg - pointer to PLDM response message
877  *  @param[in] payload_length - Length of response payload
878  *  @param[out] completion_code - PLDM completion code
879  *  @return pldm_completion_codes
880  */
881 int decode_new_file_with_metadata_resp(const struct pldm_msg *msg,
882 				       size_t payload_length,
883 				       uint8_t *completion_code);
884 
885 /** @brief Decode NewFileAvailableWithMetaData request data
886  *
887  *  @param[in] msg - Pointer to PLDM request message
888  *  @param[in] payload_length - Length of request payload
889  *  @param[out] file_type - Type of the file
890  *  @param[out] file_handle - A handle to the file
891  *  @param[out] length - Number of bytes in new file
892  *  @param[out] file_meta_data_1 - Meta data specific to file type 1
893  *  @param[out] file_meta_data_2 - Meta data specific to file type 2
894  *  @param[out] file_meta_data_3 - Meta data specific to file type 3
895  *  @param[out] file_meta_data_4 - Meta data specific to file type 4
896  *  @return pldm_completion_codes
897  */
898 int decode_new_file_with_metadata_req(
899 	const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
900 	uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1,
901 	uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
902 	uint32_t *file_meta_data_4);
903 
904 /** @brief Create a PLDM response for NewFileAvailableWithMetaData
905  *
906  *  @param[in] instance_id - Message's instance id
907  *  @param[in] completion_code - PLDM completion code
908  *  @param[in,out] msg - Message will be written to this
909  *  @return pldm_completion_codes
910  *  @note  Caller is responsible for memory alloc and dealloc of param 'msg'
911  */
912 int encode_new_file_with_metadata_resp(uint8_t instance_id,
913 				       uint8_t completion_code,
914 				       struct pldm_msg *msg);
915 
916 #ifdef __cplusplus
917 }
918 #endif
919 
920 #endif /* FILEIO_H */
921