blob: 4d003589f35b98a5079ab007dc4cf54a07f384d1 [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 {
49 PLDM_FILE_TYPE_PEL = 0,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060050 PLDM_FILE_TYPE_LID_PERM = 1,
51 PLDM_FILE_TYPE_LID_TEMP = 2,
Sampa Misra18967162020-01-14 02:31:41 -060052 PLDM_FILE_TYPE_DUMP = 3,
Sampa Misrad823cc02020-03-24 04:53:20 -050053 PLDM_FILE_TYPE_CERT_SIGNING_REQUEST = 4,
54 PLDM_FILE_TYPE_SIGNED_CERT = 5,
55 PLDM_FILE_TYPE_ROOT_CERT = 6,
Sampa Misra854e61f2019-08-22 04:36:47 -050056};
57
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053058#define PLDM_RW_FILE_MEM_REQ_BYTES 20
59#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph0c6d22c2019-06-26 09:58:41 +053060#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
61#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
vkaverap2ffe3292019-06-24 00:08:13 -050062#define PLDM_READ_FILE_REQ_BYTES 12
63#define PLDM_READ_FILE_RESP_BYTES 5
64#define PLDM_WRITE_FILE_REQ_BYTES 12
65#define PLDM_WRITE_FILE_RESP_BYTES 5
vkaverap07404562019-08-05 22:57:11 -050066#define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES 22
67#define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES 5
Deepak Kodihalli83388762020-01-28 04:09:58 -060068#define PLDM_NEW_FILE_REQ_BYTES 14
vkaverapa9aac722019-08-22 02:10:15 -050069#define PLDM_NEW_FILE_RESP_BYTES 1
Deepak Kodihallidce1c992019-11-19 07:06:53 -060070#define PLDM_RW_FILE_BY_TYPE_REQ_BYTES 14
71#define PLDM_RW_FILE_BY_TYPE_RESP_BYTES 5
vkaverapf4e0a492019-11-19 01:47:35 -060072#define PLDM_FILE_ACK_REQ_BYTES 7
73#define PLDM_FILE_ACK_RESP_BYTES 1
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053074
Priyanga8b976652019-06-27 11:30:33 -050075/** @struct pldm_read_write_file_memory_req
76 *
77 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
78 * request
79 */
80struct pldm_read_write_file_memory_req {
81 uint32_t file_handle; //!< A Handle to the file
82 uint32_t offset; //!< Offset to the file
83 uint32_t length; //!< Number of bytes to be read/write
84 uint64_t address; //!< Memory address of the file
85} __attribute__((packed));
86
87/** @struct pldm_read_write_file_memory_resp
88 *
89 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
90 * response
91 */
92struct pldm_read_write_file_memory_resp {
93 uint8_t completion_code; //!< completion code
94 uint32_t length; //!< Number of bytes read/written
95} __attribute__((packed));
96
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053097/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
98 * data
99 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500100 * @param[in] msg - Pointer to PLDM request message
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530101 * @param[in] payload_length - Length of request payload
102 * @param[out] file_handle - A handle to the file
103 * @param[out] offset - Offset to the file at which the read should begin
104 * @param[out] length - Number of bytes to be read
105 * @param[out] address - Memory address where the file content has to be
106 * written to
107 * @return pldm_completion_codes
108 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500109int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530110 uint32_t *file_handle, uint32_t *offset,
111 uint32_t *length, uint64_t *address);
112
113/** @brief Create a PLDM response for ReadFileIntoMemory and
114 * WriteFileFromMemory
115 *
116 * @param[in] instance_id - Message's instance id
117 * @param[in] command - PLDM command
118 * @param[in] completion_code - PLDM completion code
119 * @param[in] length - Number of bytes read. This could be less than what the
120 requester asked for.
121 * @param[in,out] msg - Message will be written to this
122 * @return pldm_completion_codes
123 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
124 */
125int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
126 uint8_t completion_code, uint32_t length,
127 struct pldm_msg *msg);
128
Priyanga8b976652019-06-27 11:30:33 -0500129/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
130 * commands request data
131 *
132 * @param[in] instance_id - Message's instance id
133 * @param[in] command - PLDM command
134 * @param[in] file_handle - A handle to the file
135 * @param[in] offset - Offset to the file at which the read should begin
136 * @param[in] length - Number of bytes to be read/written
137 * @param[in] address - Memory address where the file content has to be
138 * written to
139 * @param[out] msg - Message will be written to this
140 * @return pldm_completion_codes
141 */
142int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
143 uint32_t file_handle, uint32_t offset,
144 uint32_t length, uint64_t address,
145 struct pldm_msg *msg);
146
147/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
148 * commands response data
149 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500150 * @param[in] msg - pointer to PLDM response message
Priyanga8b976652019-06-27 11:30:33 -0500151 * @param[in] payload_length - Length of response payload
152 * @param[out] completion_code - PLDM completion code
153 * @param[out] length - Number of bytes to be read/written
154 * @return pldm_completion_codes
155 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500156int decode_rw_file_memory_resp(const struct pldm_msg *msg,
157 size_t payload_length, uint8_t *completion_code,
158 uint32_t *length);
Priyanga8b976652019-06-27 11:30:33 -0500159
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530160/** @struct pldm_get_file_table_req
161 *
162 * Structure representing GetFileTable request
163 */
164struct pldm_get_file_table_req {
165 uint32_t transfer_handle; //!< Data transfer handle
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500166 uint8_t operation_flag; //!< Transfer operation flag
167 uint8_t table_type; //!< Table type
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530168} __attribute__((packed));
169
170/** @struct pldm_get_file_table_resp
171 *
172 * Structure representing GetFileTable response fixed data
173 */
174struct pldm_get_file_table_resp {
175 uint8_t completion_code; //!< Completion code
176 uint32_t next_transfer_handle; //!< Next data transfer handle
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500177 uint8_t transfer_flag; //!< Transfer flag
178 uint8_t table_data[1]; //!< Table Data
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530179} __attribute__((packed));
180
181/** @brief Decode GetFileTable command request data
182 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500183 * @param[in] msg - Pointer to PLDM request message
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530184 * @param[in] payload_length - Length of request payload
185 * @param[out] trasnfer_handle - the handle of data
186 * @param[out] transfer_opflag - Transfer operation flag
187 * @param[out] table_type - the type of file table
188 * @return pldm_completion_codes
189 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500190int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530191 uint32_t *transfer_handle,
192 uint8_t *transfer_opflag, uint8_t *table_type);
193
194/** @brief Create a PLDM response for GetFileTable command
195 *
196 * @param[in] instance_id - Message's instance id
197 * @param[in] completion_code - PLDM completion code
198 * @param[in] next_transfer_handle - Handle to identify next portion of
199 * data transfer
200 * @param[in] transfer_flag - Represents the part of transfer
201 * @param[in] table_data - pointer to file table data
202 * @param[in] table_size - file table size
203 * @param[in,out] msg - Message will be written to this
204 * @return pldm_completion_codes
205 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
206 */
207int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
208 uint32_t next_transfer_handle,
209 uint8_t transfer_flag, const uint8_t *table_data,
210 size_t table_size, struct pldm_msg *msg);
211
vkaverap2ffe3292019-06-24 00:08:13 -0500212/** @struct pldm_read_file_req
213 *
214 * Structure representing ReadFile request
215 */
216struct pldm_read_file_req {
217 uint32_t file_handle; //!< Handle to file
218 uint32_t offset; //!< Offset to file where read starts
219 uint32_t length; //!< Bytes to be read
220} __attribute__((packed));
221
222/** @struct pldm_read_file_resp
223 *
224 * Structure representing ReadFile response data
225 */
226struct pldm_read_file_resp {
227 uint8_t completion_code; //!< Completion code
228 uint32_t length; //!< Number of bytes read
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500229 uint8_t file_data[1]; //!< Address of this is where file data starts
vkaverap2ffe3292019-06-24 00:08:13 -0500230} __attribute__((packed));
231
232/** @struct pldm_write_file_req
233 *
234 * Structure representing WriteFile request
235 */
236struct pldm_write_file_req {
237 uint32_t file_handle; //!< Handle to file
238 uint32_t offset; //!< Offset to file where write starts
239 uint32_t length; //!< Bytes to be written
240 uint8_t file_data[1]; //!< Address of this is where file data starts
241} __attribute__((packed));
242
243/** @struct pldm_write_file_resp
244 *
245 * Structure representing WriteFile response data
246 */
247struct pldm_write_file_resp {
248 uint8_t completion_code; //!< Completion code
249 uint32_t length; //!< Bytes written
250} __attribute__((packed));
251
252/** @brief Decode Read File commands request
253 *
254 * @param[in] msg - PLDM request message payload
255 * @param[in] payload_length - Length of request payload
256 * @param[out] file_handle - A handle to the file
257 * @param[out] offset - Offset to the file at which the read should begin
258 * @param[out] length - Number of bytes read
259 * @return pldm_completion_codes
260 */
261int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
262 uint32_t *file_handle, uint32_t *offset,
263 uint32_t *length);
264
265/** @brief Encode Read File commands request
266 *
267 * @param[in] instance_id - Message's instance id
268 * @param[in] file_handle - A handle to the file
269 * @param[in] offset - Offset to the file at which the read should begin
270 * @param[in] length - Number of bytes read
271 * @param[in,out] msg - Message will be written to this
272 * @return pldm_completion_codes
273 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
274 */
275int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
276 uint32_t offset, uint32_t length,
277 struct pldm_msg *msg);
278
279/** @brief Decode Read File commands response
280 *
281 * @param[in] msg - PLDM response message payload
282 * @param[in] payload_length - Length of request payload
283 * @param[out] completion_code - PLDM completion code
284 * @param[out] length - Number of bytes read. This could be less than what the
285 * requester asked for.
286 * @param[out] file_data_offset - Offset where file data should be read in pldm
287 * msg.
288 * @return pldm_completion_codes
289 */
290int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
291 uint8_t *completion_code, uint32_t *length,
292 size_t *file_data_offset);
293
294/** @brief Create a PLDM response for Read File
295 *
296 * @param[in] instance_id - Message's instance id
297 * @param[in] completion_code - PLDM completion code
298 * @param[in] length - Number of bytes read. This could be less than what the
299 * requester asked for.
300 * @param[in,out] msg - Message will be written to this
301 * @return pldm_completion_codes
302 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
303 * Although read file command response includes file data, this function
304 * does not encode the file data to prevent additional copying of the data.
305 * The position of file data is calculated by caller from address and size
306 * of other input arguments.
307 */
308int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
309 uint32_t length, struct pldm_msg *msg);
310
311/** @brief Decode Write File commands request
312 *
313 * @param[in] msg - PLDM request message payload
314 * @param[in] payload_length - Length of request payload
315 * @param[out] file_handle - A handle to the file
316 * @param[out] offset - Offset to the file at which the write should begin
317 * @param[out] length - Number of bytes to write
318 * @param[out] file_data_offset - Offset where file data write begins in pldm
319 * msg.
320 * @return pldm_completion_codes
321 */
322int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
323 uint32_t *file_handle, uint32_t *offset,
324 uint32_t *length, size_t *file_data_offset);
325
326/** @brief Create a PLDM request for Write File
327 *
328 * @param[in] instance_id - Message's instance id
329 * @param[in] file_handle - A handle to the file
330 * @param[in] offset - Offset to the file at which the read should begin
331 * @param[in] length - Number of bytes written. This could be less than what
332 * the requester asked for.
333 * @param[in,out] msg - Message will be written to this
334 * @return pldm_completion_codes
335 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
336 * Although write file command request includes file data, this function
337 * does not encode the file data to prevent additional copying of the data.
338 * The position of file data is calculated by caller from address and size
339 * of other input arguments.
340 */
341int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
342 uint32_t offset, uint32_t length,
343 struct pldm_msg *msg);
344
345/** @brief Decode Write File commands response
346 *
347 * @param[in] msg - PLDM request message payload
348 * @param[in] payload_length - Length of request payload
349 * @param[out] completion_code - PLDM completion code
350 * @param[out] length - Number of bytes written
351 * @return pldm_completion_codes
352 */
353int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
354 uint8_t *completion_code, uint32_t *length);
355
356/** @brief Create a PLDM response for Write File
357 *
358 * @param[in] instance_id - Message's instance id
359 * @param[in] completion_code - PLDM completion code
360 * @param[in] length - Number of bytes written. This could be less than what
361 * the requester asked for.
362 * @param[in,out] msg - Message will be written to this
363 * @return pldm_completion_codes
364 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
365 */
366int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
367 uint32_t length, struct pldm_msg *msg);
368
vkaverap07404562019-08-05 22:57:11 -0500369/** @struct pldm_read_write_file_by_type_memory_req
370 *
371 * Structure representing ReadFileByTypeIntoMemory and
372 * WriteFileByTypeFromMemory request
373 */
374struct pldm_read_write_file_by_type_memory_req {
375 uint16_t file_type; //!< Type of file
376 uint32_t file_handle; //!< Handle to file
377 uint32_t offset; //!< Offset to file where read starts
378 uint32_t length; //!< Bytes to be read
379 uint64_t address; //!< Memory address of the file
380} __attribute__((packed));
381
382/** @struct pldm_read_write_file_by_type_memory_resp
383 *
384 * Structure representing ReadFileByTypeIntoMemory and
385 * WriteFileByTypeFromMemory response
386 */
387struct pldm_read_write_file_by_type_memory_resp {
388 uint8_t completion_code; //!< Completion code
389 uint32_t length; //!< Number of bytes read
390} __attribute__((packed));
391
392/** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
393 * commands request data
394 *
395 * @param[in] msg - Pointer to PLDM request message
396 * @param[in] payload_length - Length of request payload
397 * @param[in] file_type - Type of the file
398 * @param[out] file_handle - A handle to the file
399 * @param[out] offset - Offset to the file at which the read should begin
400 * @param[out] length - Number of bytes to be read
401 * @param[out] address - Memory address of the file content
402 * @return pldm_completion_codes
403 */
404int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
405 size_t payload_length,
406 uint16_t *file_type,
407 uint32_t *file_handle, uint32_t *offset,
408 uint32_t *length, uint64_t *address);
409
410/** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
411 * WriteFileByTypeFromMemory
412 *
413 * @param[in] instance_id - Message's instance id
414 * @param[in] command - PLDM command
415 * @param[in] completion_code - PLDM completion code
416 * @param[in] length - Number of bytes read. This could be less than what the
417 * requester asked for.
418 * @param[in,out] msg - Message will be written to this
419 * @return pldm_completion_codes
420 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
421 */
422int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
423 uint8_t completion_code, uint32_t length,
424 struct pldm_msg *msg);
425
426/** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
427 * commands request data
428 *
429 * @param[in] instance_id - Message's instance id
430 * @param[in] command - PLDM command
431 * @param[in] file_type - Type of the file
432 * @param[in] file_handle - A handle to the file
433 * @param[in] offset - Offset to the file at which the read should begin
434 * @param[in] length - Number of bytes to be read/written
435 * @param[in] address - Memory address where the file content has to be
436 * written to
437 * @param[out] msg - Message will be written to this
438 * @return pldm_completion_codes
439 */
440int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
441 uint16_t file_type, uint32_t file_handle,
442 uint32_t offset, uint32_t length,
443 uint64_t address, struct pldm_msg *msg);
444
445/** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
446 * commands response data
447 *
448 * @param[in] msg - pointer to PLDM response message
449 * @param[in] payload_length - Length of response payload
450 * @param[out] completion_code - PLDM completion code
451 * @param[out] length - Number of bytes to be read/written
452 * @return pldm_completion_codes
453 */
454int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
455 size_t payload_length,
456 uint8_t *completion_code,
457 uint32_t *length);
458
vkaverapa9aac722019-08-22 02:10:15 -0500459/** @struct pldm_new_file_req
460 *
461 * Structure representing NewFile request
462 */
463struct pldm_new_file_req {
464 uint16_t file_type; //!< Type of file
465 uint32_t file_handle; //!< Handle to file
Deepak Kodihalli83388762020-01-28 04:09:58 -0600466 uint64_t length; //!< Number of bytes in new file
vkaverapa9aac722019-08-22 02:10:15 -0500467} __attribute__((packed));
468
469/** @struct pldm_new_file_resp
470 *
471 * Structure representing NewFile response data
472 */
473struct pldm_new_file_resp {
474 uint8_t completion_code; //!< Completion code
475} __attribute__((packed));
476
477/** @brief Decode NewFileAvailable command request data
478 *
479 * @param[in] msg - Pointer to PLDM request message
480 * @param[in] payload_length - Length of request payload
481 * @param[in] file_type - Type of the file
482 * @param[out] file_handle - A handle to the file
483 * @param[out] length - Number of bytes in new file
484 * @return pldm_completion_codes
485 */
486int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
487 uint16_t *file_type, uint32_t *file_handle,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600488 uint64_t *length);
vkaverapa9aac722019-08-22 02:10:15 -0500489
490/** @brief Create a PLDM response for NewFileAvailable
491 *
492 * @param[in] instance_id - Message's instance id
493 * @param[in] completion_code - PLDM completion code
494 * @param[in,out] msg - Message will be written to this
495 * @return pldm_completion_codes
496 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
497 */
498int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
499 struct pldm_msg *msg);
500
501/** @brief Encode NewFileAvailable command request data
502 *
503 * @param[in] instance_id - Message's instance id
504 * @param[in] file_type - Type of the file
505 * @param[in] file_handle - A handle to the file
506 * @param[in] length - Number of bytes in new file
507 * @param[out] msg - Message will be written to this
508 * @return pldm_completion_codes
509 */
510int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600511 uint32_t file_handle, uint64_t length,
vkaverapa9aac722019-08-22 02:10:15 -0500512 struct pldm_msg *msg);
513
514/** @brief Decode NewFileAvailable command response data
515 *
516 * @param[in] msg - pointer to PLDM response message
517 * @param[in] payload_length - Length of response payload
518 * @param[out] completion_code - PLDM completion code
519 * @return pldm_completion_codes
520 */
521int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
522 uint8_t *completion_code);
523
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600524/** @struct pldm_read_write_file_by_type_req
525 *
526 * Structure representing ReadFileByType and
527 * WriteFileByType request
528 */
529struct pldm_read_write_file_by_type_req {
530 uint16_t file_type; //!< Type of file
531 uint32_t file_handle; //!< Handle to file
532 uint32_t offset; //!< Offset to file where read/write starts
533 uint32_t length; //!< Bytes to be read
534} __attribute__((packed));
535
536/** @struct pldm_read_write_file_by_type_resp
537 *
538 * Structure representing ReadFileByType and
539 * WriteFileByType response
540 */
541struct pldm_read_write_file_by_type_resp {
542 uint8_t completion_code; //!< Completion code
543 uint32_t length; //!< Number of bytes read
544} __attribute__((packed));
545
546/** @brief Decode ReadFileByType and WriteFileByType
547 * commands request data
548 *
549 * @param[in] msg - Pointer to PLDM request message
550 * @param[in] payload_length - Length of request payload
vkaverapf4e0a492019-11-19 01:47:35 -0600551 * @param[out] file_type - Type of the file
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600552 * @param[out] file_handle - A handle to the file
553 * @param[out] offset - Offset to the file at which the read/write should begin
554 * @param[out] length - Number of bytes to be read/written
555 * @return pldm_completion_codes
556 */
557int decode_rw_file_by_type_req(const struct pldm_msg *msg,
558 size_t payload_length, uint16_t *file_type,
559 uint32_t *file_handle, uint32_t *offset,
560 uint32_t *length);
561
562/** @brief Create a PLDM response for ReadFileByType and
563 * WriteFileByType
564 *
565 * @param[in] instance_id - Message's instance id
566 * @param[in] command - PLDM command
567 * @param[in] completion_code - PLDM completion code
568 * @param[in] length - Number of bytes read/written. This could be less than
vkaverapf4e0a492019-11-19 01:47:35 -0600569 * what the requester asked for.
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600570 * @param[in,out] msg - Message will be written to this
571 * @return pldm_completion_codes
572 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
573 * @note File content has to be copied directly by the caller.
574 */
575int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
576 uint8_t completion_code, uint32_t length,
577 struct pldm_msg *msg);
578
579/** @brief Encode ReadFileByType and WriteFileByType
580 * commands request data
581 *
582 * @param[in] instance_id - Message's instance id
583 * @param[in] command - PLDM command
584 * @param[in] file_type - Type of the file
585 * @param[in] file_handle - A handle to the file
586 * @param[in] offset - Offset to the file at which the read should begin
587 * @param[in] length - Number of bytes to be read/written
588 * @param[out] msg - Message will be written to this
589 * @return pldm_completion_codes
590 * @note File content has to be read directly by the caller.
591 */
592int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
593 uint16_t file_type, uint32_t file_handle,
594 uint32_t offset, uint32_t length,
595 struct pldm_msg *msg);
596
597/** @brief Decode ReadFileByType and WriteFileByType
598 * commands response data
599 *
600 * @param[in] msg - pointer to PLDM response message
601 * @param[in] payload_length - Length of response payload
602 * @param[out] completion_code - PLDM completion code
603 * @param[out] length - Number of bytes to be read/written
604 * @return pldm_completion_codes
605 */
606int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
607 size_t payload_length, uint8_t *completion_code,
608 uint32_t *length);
609
vkaverapf4e0a492019-11-19 01:47:35 -0600610/** @struct pldm_file_ack_req
611 *
612 * Structure representing FileAck request
613 */
614struct pldm_file_ack_req {
615 uint16_t file_type; //!< Type of file
616 uint32_t file_handle; //!< Handle to file
617 uint8_t file_status; //!< Status of file processing
618} __attribute__((packed));
619
620/** @struct pldm_file_ack_resp
621 *
622 * Structure representing NewFile response data
623 */
624struct pldm_file_ack_resp {
625 uint8_t completion_code; //!< Completion code
626} __attribute__((packed));
627
628/** @brief Decode FileAck command request data
629 *
630 * @param[in] msg - Pointer to PLDM request message
631 * @param[in] payload_length - Length of request payload
632 * @param[out] file_type - Type of the file
633 * @param[out] file_handle - A handle to the file
634 * @param[out] file_status - Status of file processing
635 * @return pldm_completion_codes
636 */
637int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
638 uint16_t *file_type, uint32_t *file_handle,
639 uint8_t *file_status);
640
641/** @brief Create a PLDM response for FileAck
642 *
643 * @param[in] instance_id - Message's instance id
644 * @param[in] completion_code - PLDM completion code
645 * @param[in,out] msg - Message will be written to this
646 * @return pldm_completion_codes
647 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
648 */
649int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
650 struct pldm_msg *msg);
651
652/** @brief Encode FileAck command request data
653 *
654 * @param[in] instance_id - Message's instance id
655 * @param[in] file_type - Type of the file
656 * @param[in] file_handle - A handle to the file
657 * @param[in] file_status - Status of file processing
658 * @param[out] msg - Message will be written to this
659 * @return pldm_completion_codes
660 */
661int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
662 uint32_t file_handle, uint8_t file_status,
663 struct pldm_msg *msg);
664
665/** @brief Decode FileAck command response data
666 *
667 * @param[in] msg - pointer to PLDM response message
668 * @param[in] payload_length - Length of response payload
669 * @param[out] completion_code - PLDM completion code
670 * @return pldm_completion_codes
671 */
672int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
673 uint8_t *completion_code);
674
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530675#ifdef __cplusplus
676}
677#endif
678
679#endif /* FILEIO_H */