blob: 38e50cab5b3c7cf2b7922e326a4ad1f6bf6b4b76 [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
Pavithra Barithayad15c8092020-05-12 02:26:26 -0500212/** @brief Encode GetFileTable command request data
213 *
214 * @param[in] instance_id - Message's instance id
215 * @param[in] transfer_handle - the handle of data
216 * @param[in] transfer_opflag - Transfer operation flag
217 * @param[in] table_type - the type of file table
218 * @param[out] msg - Message will be written to this
219 * @return pldm_completion_codes
220 */
221int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle,
222 uint8_t transfer_opflag, uint8_t table_type,
223 struct pldm_msg *msg);
224
225/** @brief Decode GetFileTable command response data
226 * @param[in] msg - Response message
227 * @param[in] payload_length - length of response message payload
228 * @param[out] completion_code - PLDM completion code
229 * @param[out] next_transfer_handle - Handle to identify next portion of data
230 * transfer
231 * @param[out] transfer_flag - Represents the part of transfer
232 * @param[out] file_table_data_start_offset - This data is a portion of the
233 * overall File Table
234 * @param[out] file_table_length - Length of the File table data
235 * @return pldm_completion_codes
236 */
237int decode_get_file_table_resp(const struct pldm_msg *msg,
238 size_t payload_length, uint8_t *completion_code,
239 uint32_t *next_transfer_handle,
240 uint8_t *transfer_flag,
241 uint8_t *file_table_data_start_offset,
242 size_t *file_table_length);
243
vkaverap2ffe3292019-06-24 00:08:13 -0500244/** @struct pldm_read_file_req
245 *
246 * Structure representing ReadFile request
247 */
248struct pldm_read_file_req {
249 uint32_t file_handle; //!< Handle to file
250 uint32_t offset; //!< Offset to file where read starts
251 uint32_t length; //!< Bytes to be read
252} __attribute__((packed));
253
254/** @struct pldm_read_file_resp
255 *
256 * Structure representing ReadFile response data
257 */
258struct pldm_read_file_resp {
259 uint8_t completion_code; //!< Completion code
260 uint32_t length; //!< Number of bytes read
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500261 uint8_t file_data[1]; //!< Address of this is where file data starts
vkaverap2ffe3292019-06-24 00:08:13 -0500262} __attribute__((packed));
263
264/** @struct pldm_write_file_req
265 *
266 * Structure representing WriteFile request
267 */
268struct pldm_write_file_req {
269 uint32_t file_handle; //!< Handle to file
270 uint32_t offset; //!< Offset to file where write starts
271 uint32_t length; //!< Bytes to be written
272 uint8_t file_data[1]; //!< Address of this is where file data starts
273} __attribute__((packed));
274
275/** @struct pldm_write_file_resp
276 *
277 * Structure representing WriteFile response data
278 */
279struct pldm_write_file_resp {
280 uint8_t completion_code; //!< Completion code
281 uint32_t length; //!< Bytes written
282} __attribute__((packed));
283
284/** @brief Decode Read File commands request
285 *
286 * @param[in] msg - PLDM request message payload
287 * @param[in] payload_length - Length of request payload
288 * @param[out] file_handle - A handle to the file
289 * @param[out] offset - Offset to the file at which the read should begin
290 * @param[out] length - Number of bytes read
291 * @return pldm_completion_codes
292 */
293int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
294 uint32_t *file_handle, uint32_t *offset,
295 uint32_t *length);
296
297/** @brief Encode Read File commands request
298 *
299 * @param[in] instance_id - Message's instance id
300 * @param[in] file_handle - A handle to the file
301 * @param[in] offset - Offset to the file at which the read should begin
302 * @param[in] length - Number of bytes read
303 * @param[in,out] msg - Message will be written to this
304 * @return pldm_completion_codes
305 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
306 */
307int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
308 uint32_t offset, uint32_t length,
309 struct pldm_msg *msg);
310
311/** @brief Decode Read File commands response
312 *
313 * @param[in] msg - PLDM response message payload
314 * @param[in] payload_length - Length of request payload
315 * @param[out] completion_code - PLDM completion code
316 * @param[out] length - Number of bytes read. This could be less than what the
317 * requester asked for.
318 * @param[out] file_data_offset - Offset where file data should be read in pldm
319 * msg.
320 * @return pldm_completion_codes
321 */
322int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
323 uint8_t *completion_code, uint32_t *length,
324 size_t *file_data_offset);
325
326/** @brief Create a PLDM response for Read File
327 *
328 * @param[in] instance_id - Message's instance id
329 * @param[in] completion_code - PLDM completion code
330 * @param[in] length - Number of bytes read. This could be less than what the
331 * 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 read file command response 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_read_file_resp(uint8_t instance_id, uint8_t completion_code,
341 uint32_t length, struct pldm_msg *msg);
342
343/** @brief Decode Write File commands request
344 *
345 * @param[in] msg - PLDM request message payload
346 * @param[in] payload_length - Length of request payload
347 * @param[out] file_handle - A handle to the file
348 * @param[out] offset - Offset to the file at which the write should begin
349 * @param[out] length - Number of bytes to write
350 * @param[out] file_data_offset - Offset where file data write begins in pldm
351 * msg.
352 * @return pldm_completion_codes
353 */
354int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
355 uint32_t *file_handle, uint32_t *offset,
356 uint32_t *length, size_t *file_data_offset);
357
358/** @brief Create a PLDM request for Write File
359 *
360 * @param[in] instance_id - Message's instance id
361 * @param[in] file_handle - A handle to the file
362 * @param[in] offset - Offset to the file at which the read should begin
363 * @param[in] length - Number of bytes written. This could be less than what
364 * the requester asked for.
365 * @param[in,out] msg - Message will be written to this
366 * @return pldm_completion_codes
367 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
368 * Although write file command request includes file data, this function
369 * does not encode the file data to prevent additional copying of the data.
370 * The position of file data is calculated by caller from address and size
371 * of other input arguments.
372 */
373int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
374 uint32_t offset, uint32_t length,
375 struct pldm_msg *msg);
376
377/** @brief Decode Write File commands response
378 *
379 * @param[in] msg - PLDM request message payload
380 * @param[in] payload_length - Length of request payload
381 * @param[out] completion_code - PLDM completion code
382 * @param[out] length - Number of bytes written
383 * @return pldm_completion_codes
384 */
385int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
386 uint8_t *completion_code, uint32_t *length);
387
388/** @brief Create a PLDM response for Write File
389 *
390 * @param[in] instance_id - Message's instance id
391 * @param[in] completion_code - PLDM completion code
392 * @param[in] length - Number of bytes written. This could be less than what
393 * the requester asked for.
394 * @param[in,out] msg - Message will be written to this
395 * @return pldm_completion_codes
396 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
397 */
398int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
399 uint32_t length, struct pldm_msg *msg);
400
vkaverap07404562019-08-05 22:57:11 -0500401/** @struct pldm_read_write_file_by_type_memory_req
402 *
403 * Structure representing ReadFileByTypeIntoMemory and
404 * WriteFileByTypeFromMemory request
405 */
406struct pldm_read_write_file_by_type_memory_req {
407 uint16_t file_type; //!< Type of file
408 uint32_t file_handle; //!< Handle to file
409 uint32_t offset; //!< Offset to file where read starts
410 uint32_t length; //!< Bytes to be read
411 uint64_t address; //!< Memory address of the file
412} __attribute__((packed));
413
414/** @struct pldm_read_write_file_by_type_memory_resp
415 *
416 * Structure representing ReadFileByTypeIntoMemory and
417 * WriteFileByTypeFromMemory response
418 */
419struct pldm_read_write_file_by_type_memory_resp {
420 uint8_t completion_code; //!< Completion code
421 uint32_t length; //!< Number of bytes read
422} __attribute__((packed));
423
424/** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
425 * commands request data
426 *
427 * @param[in] msg - Pointer to PLDM request message
428 * @param[in] payload_length - Length of request payload
429 * @param[in] file_type - Type of the file
430 * @param[out] file_handle - A handle to the file
431 * @param[out] offset - Offset to the file at which the read should begin
432 * @param[out] length - Number of bytes to be read
433 * @param[out] address - Memory address of the file content
434 * @return pldm_completion_codes
435 */
436int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
437 size_t payload_length,
438 uint16_t *file_type,
439 uint32_t *file_handle, uint32_t *offset,
440 uint32_t *length, uint64_t *address);
441
442/** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
443 * WriteFileByTypeFromMemory
444 *
445 * @param[in] instance_id - Message's instance id
446 * @param[in] command - PLDM command
447 * @param[in] completion_code - PLDM completion code
448 * @param[in] length - Number of bytes read. This could be less than what the
449 * requester asked for.
450 * @param[in,out] msg - Message will be written to this
451 * @return pldm_completion_codes
452 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
453 */
454int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
455 uint8_t completion_code, uint32_t length,
456 struct pldm_msg *msg);
457
458/** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
459 * commands request data
460 *
461 * @param[in] instance_id - Message's instance id
462 * @param[in] command - PLDM command
463 * @param[in] file_type - Type of the file
464 * @param[in] file_handle - A handle to the file
465 * @param[in] offset - Offset to the file at which the read should begin
466 * @param[in] length - Number of bytes to be read/written
467 * @param[in] address - Memory address where the file content has to be
468 * written to
469 * @param[out] msg - Message will be written to this
470 * @return pldm_completion_codes
471 */
472int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
473 uint16_t file_type, uint32_t file_handle,
474 uint32_t offset, uint32_t length,
475 uint64_t address, struct pldm_msg *msg);
476
477/** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
478 * commands response data
479 *
480 * @param[in] msg - pointer to PLDM response message
481 * @param[in] payload_length - Length of response payload
482 * @param[out] completion_code - PLDM completion code
483 * @param[out] length - Number of bytes to be read/written
484 * @return pldm_completion_codes
485 */
486int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
487 size_t payload_length,
488 uint8_t *completion_code,
489 uint32_t *length);
490
vkaverapa9aac722019-08-22 02:10:15 -0500491/** @struct pldm_new_file_req
492 *
493 * Structure representing NewFile request
494 */
495struct pldm_new_file_req {
496 uint16_t file_type; //!< Type of file
497 uint32_t file_handle; //!< Handle to file
Deepak Kodihalli83388762020-01-28 04:09:58 -0600498 uint64_t length; //!< Number of bytes in new file
vkaverapa9aac722019-08-22 02:10:15 -0500499} __attribute__((packed));
500
501/** @struct pldm_new_file_resp
502 *
503 * Structure representing NewFile response data
504 */
505struct pldm_new_file_resp {
506 uint8_t completion_code; //!< Completion code
507} __attribute__((packed));
508
509/** @brief Decode NewFileAvailable command request data
510 *
511 * @param[in] msg - Pointer to PLDM request message
512 * @param[in] payload_length - Length of request payload
513 * @param[in] file_type - Type of the file
514 * @param[out] file_handle - A handle to the file
515 * @param[out] length - Number of bytes in new file
516 * @return pldm_completion_codes
517 */
518int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
519 uint16_t *file_type, uint32_t *file_handle,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600520 uint64_t *length);
vkaverapa9aac722019-08-22 02:10:15 -0500521
522/** @brief Create a PLDM response for NewFileAvailable
523 *
524 * @param[in] instance_id - Message's instance id
525 * @param[in] completion_code - PLDM completion code
526 * @param[in,out] msg - Message will be written to this
527 * @return pldm_completion_codes
528 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
529 */
530int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
531 struct pldm_msg *msg);
532
533/** @brief Encode NewFileAvailable command request data
534 *
535 * @param[in] instance_id - Message's instance id
536 * @param[in] file_type - Type of the file
537 * @param[in] file_handle - A handle to the file
538 * @param[in] length - Number of bytes in new file
539 * @param[out] msg - Message will be written to this
540 * @return pldm_completion_codes
541 */
542int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600543 uint32_t file_handle, uint64_t length,
vkaverapa9aac722019-08-22 02:10:15 -0500544 struct pldm_msg *msg);
545
546/** @brief Decode NewFileAvailable command response data
547 *
548 * @param[in] msg - pointer to PLDM response message
549 * @param[in] payload_length - Length of response payload
550 * @param[out] completion_code - PLDM completion code
551 * @return pldm_completion_codes
552 */
553int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
554 uint8_t *completion_code);
555
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600556/** @struct pldm_read_write_file_by_type_req
557 *
558 * Structure representing ReadFileByType and
559 * WriteFileByType request
560 */
561struct pldm_read_write_file_by_type_req {
562 uint16_t file_type; //!< Type of file
563 uint32_t file_handle; //!< Handle to file
564 uint32_t offset; //!< Offset to file where read/write starts
565 uint32_t length; //!< Bytes to be read
566} __attribute__((packed));
567
568/** @struct pldm_read_write_file_by_type_resp
569 *
570 * Structure representing ReadFileByType and
571 * WriteFileByType response
572 */
573struct pldm_read_write_file_by_type_resp {
574 uint8_t completion_code; //!< Completion code
575 uint32_t length; //!< Number of bytes read
576} __attribute__((packed));
577
578/** @brief Decode ReadFileByType and WriteFileByType
579 * commands request data
580 *
581 * @param[in] msg - Pointer to PLDM request message
582 * @param[in] payload_length - Length of request payload
vkaverapf4e0a492019-11-19 01:47:35 -0600583 * @param[out] file_type - Type of the file
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600584 * @param[out] file_handle - A handle to the file
585 * @param[out] offset - Offset to the file at which the read/write should begin
586 * @param[out] length - Number of bytes to be read/written
587 * @return pldm_completion_codes
588 */
589int decode_rw_file_by_type_req(const struct pldm_msg *msg,
590 size_t payload_length, uint16_t *file_type,
591 uint32_t *file_handle, uint32_t *offset,
592 uint32_t *length);
593
594/** @brief Create a PLDM response for ReadFileByType and
595 * WriteFileByType
596 *
597 * @param[in] instance_id - Message's instance id
598 * @param[in] command - PLDM command
599 * @param[in] completion_code - PLDM completion code
600 * @param[in] length - Number of bytes read/written. This could be less than
vkaverapf4e0a492019-11-19 01:47:35 -0600601 * what the requester asked for.
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600602 * @param[in,out] msg - Message will be written to this
603 * @return pldm_completion_codes
604 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
605 * @note File content has to be copied directly by the caller.
606 */
607int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
608 uint8_t completion_code, uint32_t length,
609 struct pldm_msg *msg);
610
611/** @brief Encode ReadFileByType and WriteFileByType
612 * commands request data
613 *
614 * @param[in] instance_id - Message's instance id
615 * @param[in] command - PLDM command
616 * @param[in] file_type - Type of the file
617 * @param[in] file_handle - A handle to the file
618 * @param[in] offset - Offset to the file at which the read should begin
619 * @param[in] length - Number of bytes to be read/written
620 * @param[out] msg - Message will be written to this
621 * @return pldm_completion_codes
622 * @note File content has to be read directly by the caller.
623 */
624int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
625 uint16_t file_type, uint32_t file_handle,
626 uint32_t offset, uint32_t length,
627 struct pldm_msg *msg);
628
629/** @brief Decode ReadFileByType and WriteFileByType
630 * commands response data
631 *
632 * @param[in] msg - pointer to PLDM response message
633 * @param[in] payload_length - Length of response payload
634 * @param[out] completion_code - PLDM completion code
635 * @param[out] length - Number of bytes to be read/written
636 * @return pldm_completion_codes
637 */
638int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
639 size_t payload_length, uint8_t *completion_code,
640 uint32_t *length);
641
vkaverapf4e0a492019-11-19 01:47:35 -0600642/** @struct pldm_file_ack_req
643 *
644 * Structure representing FileAck request
645 */
646struct pldm_file_ack_req {
647 uint16_t file_type; //!< Type of file
648 uint32_t file_handle; //!< Handle to file
649 uint8_t file_status; //!< Status of file processing
650} __attribute__((packed));
651
652/** @struct pldm_file_ack_resp
653 *
654 * Structure representing NewFile response data
655 */
656struct pldm_file_ack_resp {
657 uint8_t completion_code; //!< Completion code
658} __attribute__((packed));
659
660/** @brief Decode FileAck command request data
661 *
662 * @param[in] msg - Pointer to PLDM request message
663 * @param[in] payload_length - Length of request payload
664 * @param[out] file_type - Type of the file
665 * @param[out] file_handle - A handle to the file
666 * @param[out] file_status - Status of file processing
667 * @return pldm_completion_codes
668 */
669int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
670 uint16_t *file_type, uint32_t *file_handle,
671 uint8_t *file_status);
672
673/** @brief Create a PLDM response for FileAck
674 *
675 * @param[in] instance_id - Message's instance id
676 * @param[in] completion_code - PLDM completion code
677 * @param[in,out] msg - Message will be written to this
678 * @return pldm_completion_codes
679 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
680 */
681int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
682 struct pldm_msg *msg);
683
684/** @brief Encode FileAck command request data
685 *
686 * @param[in] instance_id - Message's instance id
687 * @param[in] file_type - Type of the file
688 * @param[in] file_handle - A handle to the file
689 * @param[in] file_status - Status of file processing
690 * @param[out] msg - Message will be written to this
691 * @return pldm_completion_codes
692 */
693int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
694 uint32_t file_handle, uint8_t file_status,
695 struct pldm_msg *msg);
696
697/** @brief Decode FileAck command response data
698 *
699 * @param[in] msg - pointer to PLDM response message
700 * @param[in] payload_length - Length of response payload
701 * @param[out] completion_code - PLDM completion code
702 * @return pldm_completion_codes
703 */
704int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
705 uint8_t *completion_code);
706
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530707#ifdef __cplusplus
708}
709#endif
710
711#endif /* FILEIO_H */