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