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