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