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