blob: a501c93033838709d9efe6d9e0140e264dc971c2 [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 {
Jayashankar Padathdb124362021-01-28 21:12:34 -060049 PLDM_FILE_TYPE_PEL = 0x0,
50 PLDM_FILE_TYPE_LID_PERM = 0x1,
51 PLDM_FILE_TYPE_LID_TEMP = 0x2,
52 PLDM_FILE_TYPE_DUMP = 0x3,
53 PLDM_FILE_TYPE_CERT_SIGNING_REQUEST = 0x4,
54 PLDM_FILE_TYPE_SIGNED_CERT = 0x5,
55 PLDM_FILE_TYPE_ROOT_CERT = 0x6,
56 PLDM_FILE_TYPE_LID_MARKER = 0x7,
57 PLDM_FILE_TYPE_RESOURCE_DUMP_PARMS = 0x8,
58 PLDM_FILE_TYPE_RESOURCE_DUMP = 0x9,
Sampa Misra854e61f2019-08-22 04:36:47 -050059};
60
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053061#define PLDM_RW_FILE_MEM_REQ_BYTES 20
62#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph0c6d22c2019-06-26 09:58:41 +053063#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
64#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
vkaverap2ffe3292019-06-24 00:08:13 -050065#define PLDM_READ_FILE_REQ_BYTES 12
66#define PLDM_READ_FILE_RESP_BYTES 5
67#define PLDM_WRITE_FILE_REQ_BYTES 12
68#define PLDM_WRITE_FILE_RESP_BYTES 5
vkaverap07404562019-08-05 22:57:11 -050069#define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES 22
70#define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES 5
Deepak Kodihalli83388762020-01-28 04:09:58 -060071#define PLDM_NEW_FILE_REQ_BYTES 14
vkaverapa9aac722019-08-22 02:10:15 -050072#define PLDM_NEW_FILE_RESP_BYTES 1
Deepak Kodihallidce1c992019-11-19 07:06:53 -060073#define PLDM_RW_FILE_BY_TYPE_REQ_BYTES 14
74#define PLDM_RW_FILE_BY_TYPE_RESP_BYTES 5
vkaverapf4e0a492019-11-19 01:47:35 -060075#define PLDM_FILE_ACK_REQ_BYTES 7
76#define PLDM_FILE_ACK_RESP_BYTES 1
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053077
Priyanga8b976652019-06-27 11:30:33 -050078/** @struct pldm_read_write_file_memory_req
79 *
80 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
81 * request
82 */
83struct pldm_read_write_file_memory_req {
84 uint32_t file_handle; //!< A Handle to the file
85 uint32_t offset; //!< Offset to the file
86 uint32_t length; //!< Number of bytes to be read/write
87 uint64_t address; //!< Memory address of the file
88} __attribute__((packed));
89
90/** @struct pldm_read_write_file_memory_resp
91 *
92 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
93 * response
94 */
95struct pldm_read_write_file_memory_resp {
96 uint8_t completion_code; //!< completion code
97 uint32_t length; //!< Number of bytes read/written
98} __attribute__((packed));
99
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530100/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
101 * data
102 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500103 * @param[in] msg - Pointer to PLDM request message
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530104 * @param[in] payload_length - Length of request payload
105 * @param[out] file_handle - A handle to the file
106 * @param[out] offset - Offset to the file at which the read should begin
107 * @param[out] length - Number of bytes to be read
108 * @param[out] address - Memory address where the file content has to be
109 * written to
110 * @return pldm_completion_codes
111 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500112int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530113 uint32_t *file_handle, uint32_t *offset,
114 uint32_t *length, uint64_t *address);
115
116/** @brief Create a PLDM response for ReadFileIntoMemory and
117 * WriteFileFromMemory
118 *
119 * @param[in] instance_id - Message's instance id
120 * @param[in] command - PLDM command
121 * @param[in] completion_code - PLDM completion code
122 * @param[in] length - Number of bytes read. This could be less than what the
123 requester asked for.
124 * @param[in,out] msg - Message will be written to this
125 * @return pldm_completion_codes
126 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
127 */
128int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
129 uint8_t completion_code, uint32_t length,
130 struct pldm_msg *msg);
131
Priyanga8b976652019-06-27 11:30:33 -0500132/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
133 * commands request data
134 *
135 * @param[in] instance_id - Message's instance id
136 * @param[in] command - PLDM command
137 * @param[in] file_handle - A handle to the file
138 * @param[in] offset - Offset to the file at which the read should begin
139 * @param[in] length - Number of bytes to be read/written
140 * @param[in] address - Memory address where the file content has to be
141 * written to
142 * @param[out] msg - Message will be written to this
143 * @return pldm_completion_codes
144 */
145int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
146 uint32_t file_handle, uint32_t offset,
147 uint32_t length, uint64_t address,
148 struct pldm_msg *msg);
149
150/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
151 * commands response data
152 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500153 * @param[in] msg - pointer to PLDM response message
Priyanga8b976652019-06-27 11:30:33 -0500154 * @param[in] payload_length - Length of response payload
155 * @param[out] completion_code - PLDM completion code
156 * @param[out] length - Number of bytes to be read/written
157 * @return pldm_completion_codes
158 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500159int decode_rw_file_memory_resp(const struct pldm_msg *msg,
160 size_t payload_length, uint8_t *completion_code,
161 uint32_t *length);
Priyanga8b976652019-06-27 11:30:33 -0500162
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530163/** @struct pldm_get_file_table_req
164 *
165 * Structure representing GetFileTable request
166 */
167struct pldm_get_file_table_req {
168 uint32_t transfer_handle; //!< Data transfer handle
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500169 uint8_t operation_flag; //!< Transfer operation flag
170 uint8_t table_type; //!< Table type
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530171} __attribute__((packed));
172
173/** @struct pldm_get_file_table_resp
174 *
175 * Structure representing GetFileTable response fixed data
176 */
177struct pldm_get_file_table_resp {
178 uint8_t completion_code; //!< Completion code
179 uint32_t next_transfer_handle; //!< Next data transfer handle
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500180 uint8_t transfer_flag; //!< Transfer flag
181 uint8_t table_data[1]; //!< Table Data
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530182} __attribute__((packed));
183
Pavithra Barithayac4e80cc2020-05-26 07:00:26 -0500184/** @struct pldm_file_attr_table_entry
185 *
186 * Structure representing File attribute table entry
187 */
188struct pldm_file_attr_table_entry {
189 uint32_t file_handle; //!< File Handle
190 uint16_t file_name_length; //!< File name length
191 uint8_t file_attr_table_nst[1]; //!< File name size traits
192} __attribute__((packed));
193
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530194/** @brief Decode GetFileTable command request data
195 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500196 * @param[in] msg - Pointer to PLDM request message
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530197 * @param[in] payload_length - Length of request payload
198 * @param[out] trasnfer_handle - the handle of data
199 * @param[out] transfer_opflag - Transfer operation flag
200 * @param[out] table_type - the type of file table
201 * @return pldm_completion_codes
202 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500203int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530204 uint32_t *transfer_handle,
205 uint8_t *transfer_opflag, uint8_t *table_type);
206
207/** @brief Create a PLDM response for GetFileTable command
208 *
209 * @param[in] instance_id - Message's instance id
210 * @param[in] completion_code - PLDM completion code
211 * @param[in] next_transfer_handle - Handle to identify next portion of
212 * data transfer
213 * @param[in] transfer_flag - Represents the part of transfer
214 * @param[in] table_data - pointer to file table data
215 * @param[in] table_size - file table size
216 * @param[in,out] msg - Message will be written to this
217 * @return pldm_completion_codes
218 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
219 */
220int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
221 uint32_t next_transfer_handle,
222 uint8_t transfer_flag, const uint8_t *table_data,
223 size_t table_size, struct pldm_msg *msg);
224
Pavithra Barithayad15c8092020-05-12 02:26:26 -0500225/** @brief Encode GetFileTable command request data
226 *
227 * @param[in] instance_id - Message's instance id
228 * @param[in] transfer_handle - the handle of data
229 * @param[in] transfer_opflag - Transfer operation flag
230 * @param[in] table_type - the type of file table
231 * @param[out] msg - Message will be written to this
232 * @return pldm_completion_codes
233 */
234int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle,
235 uint8_t transfer_opflag, uint8_t table_type,
236 struct pldm_msg *msg);
237
238/** @brief Decode GetFileTable command response data
239 * @param[in] msg - Response message
240 * @param[in] payload_length - length of response message payload
241 * @param[out] completion_code - PLDM completion code
242 * @param[out] next_transfer_handle - Handle to identify next portion of data
243 * transfer
244 * @param[out] transfer_flag - Represents the part of transfer
245 * @param[out] file_table_data_start_offset - This data is a portion of the
246 * overall File Table
247 * @param[out] file_table_length - Length of the File table data
248 * @return pldm_completion_codes
249 */
250int decode_get_file_table_resp(const struct pldm_msg *msg,
251 size_t payload_length, uint8_t *completion_code,
252 uint32_t *next_transfer_handle,
253 uint8_t *transfer_flag,
254 uint8_t *file_table_data_start_offset,
255 size_t *file_table_length);
256
vkaverap2ffe3292019-06-24 00:08:13 -0500257/** @struct pldm_read_file_req
258 *
259 * Structure representing ReadFile request
260 */
261struct pldm_read_file_req {
262 uint32_t file_handle; //!< Handle to file
263 uint32_t offset; //!< Offset to file where read starts
264 uint32_t length; //!< Bytes to be read
265} __attribute__((packed));
266
267/** @struct pldm_read_file_resp
268 *
269 * Structure representing ReadFile response data
270 */
271struct pldm_read_file_resp {
272 uint8_t completion_code; //!< Completion code
273 uint32_t length; //!< Number of bytes read
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500274 uint8_t file_data[1]; //!< Address of this is where file data starts
vkaverap2ffe3292019-06-24 00:08:13 -0500275} __attribute__((packed));
276
277/** @struct pldm_write_file_req
278 *
279 * Structure representing WriteFile request
280 */
281struct pldm_write_file_req {
282 uint32_t file_handle; //!< Handle to file
283 uint32_t offset; //!< Offset to file where write starts
284 uint32_t length; //!< Bytes to be written
285 uint8_t file_data[1]; //!< Address of this is where file data starts
286} __attribute__((packed));
287
288/** @struct pldm_write_file_resp
289 *
290 * Structure representing WriteFile response data
291 */
292struct pldm_write_file_resp {
293 uint8_t completion_code; //!< Completion code
294 uint32_t length; //!< Bytes written
295} __attribute__((packed));
296
297/** @brief Decode Read File commands request
298 *
299 * @param[in] msg - PLDM request message payload
300 * @param[in] payload_length - Length of request payload
301 * @param[out] file_handle - A handle to the file
302 * @param[out] offset - Offset to the file at which the read should begin
303 * @param[out] length - Number of bytes read
304 * @return pldm_completion_codes
305 */
306int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
307 uint32_t *file_handle, uint32_t *offset,
308 uint32_t *length);
309
310/** @brief Encode Read File commands request
311 *
312 * @param[in] instance_id - Message's instance id
313 * @param[in] file_handle - A handle to the file
314 * @param[in] offset - Offset to the file at which the read should begin
315 * @param[in] length - Number of bytes read
316 * @param[in,out] msg - Message will be written to this
317 * @return pldm_completion_codes
318 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
319 */
320int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
321 uint32_t offset, uint32_t length,
322 struct pldm_msg *msg);
323
324/** @brief Decode Read File commands response
325 *
326 * @param[in] msg - PLDM response message payload
327 * @param[in] payload_length - Length of request payload
328 * @param[out] completion_code - PLDM completion code
329 * @param[out] length - Number of bytes read. This could be less than what the
330 * requester asked for.
331 * @param[out] file_data_offset - Offset where file data should be read in pldm
332 * msg.
333 * @return pldm_completion_codes
334 */
335int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
336 uint8_t *completion_code, uint32_t *length,
337 size_t *file_data_offset);
338
339/** @brief Create a PLDM response for Read File
340 *
341 * @param[in] instance_id - Message's instance id
342 * @param[in] completion_code - PLDM completion code
343 * @param[in] length - Number of bytes read. This could be less than what the
344 * requester asked for.
345 * @param[in,out] msg - Message will be written to this
346 * @return pldm_completion_codes
347 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
348 * Although read file command response includes file data, this function
349 * does not encode the file data to prevent additional copying of the data.
350 * The position of file data is calculated by caller from address and size
351 * of other input arguments.
352 */
353int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
354 uint32_t length, struct pldm_msg *msg);
355
356/** @brief Decode Write File commands request
357 *
358 * @param[in] msg - PLDM request message payload
359 * @param[in] payload_length - Length of request payload
360 * @param[out] file_handle - A handle to the file
361 * @param[out] offset - Offset to the file at which the write should begin
362 * @param[out] length - Number of bytes to write
363 * @param[out] file_data_offset - Offset where file data write begins in pldm
364 * msg.
365 * @return pldm_completion_codes
366 */
367int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
368 uint32_t *file_handle, uint32_t *offset,
369 uint32_t *length, size_t *file_data_offset);
370
371/** @brief Create a PLDM request for Write File
372 *
373 * @param[in] instance_id - Message's instance id
374 * @param[in] file_handle - A handle to the file
375 * @param[in] offset - Offset to the file at which the read should begin
376 * @param[in] length - Number of bytes written. This could be less than what
377 * the requester asked for.
378 * @param[in,out] msg - Message will be written to this
379 * @return pldm_completion_codes
380 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
381 * Although write file command request includes file data, this function
382 * does not encode the file data to prevent additional copying of the data.
383 * The position of file data is calculated by caller from address and size
384 * of other input arguments.
385 */
386int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
387 uint32_t offset, uint32_t length,
388 struct pldm_msg *msg);
389
390/** @brief Decode Write File commands response
391 *
392 * @param[in] msg - PLDM request message payload
393 * @param[in] payload_length - Length of request payload
394 * @param[out] completion_code - PLDM completion code
395 * @param[out] length - Number of bytes written
396 * @return pldm_completion_codes
397 */
398int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
399 uint8_t *completion_code, uint32_t *length);
400
401/** @brief Create a PLDM response for Write File
402 *
403 * @param[in] instance_id - Message's instance id
404 * @param[in] completion_code - PLDM completion code
405 * @param[in] length - Number of bytes written. This could be less than what
406 * the requester asked for.
407 * @param[in,out] msg - Message will be written to this
408 * @return pldm_completion_codes
409 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
410 */
411int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
412 uint32_t length, struct pldm_msg *msg);
413
vkaverap07404562019-08-05 22:57:11 -0500414/** @struct pldm_read_write_file_by_type_memory_req
415 *
416 * Structure representing ReadFileByTypeIntoMemory and
417 * WriteFileByTypeFromMemory request
418 */
419struct pldm_read_write_file_by_type_memory_req {
420 uint16_t file_type; //!< Type of file
421 uint32_t file_handle; //!< Handle to file
422 uint32_t offset; //!< Offset to file where read starts
423 uint32_t length; //!< Bytes to be read
424 uint64_t address; //!< Memory address of the file
425} __attribute__((packed));
426
427/** @struct pldm_read_write_file_by_type_memory_resp
428 *
429 * Structure representing ReadFileByTypeIntoMemory and
430 * WriteFileByTypeFromMemory response
431 */
432struct pldm_read_write_file_by_type_memory_resp {
433 uint8_t completion_code; //!< Completion code
434 uint32_t length; //!< Number of bytes read
435} __attribute__((packed));
436
437/** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
438 * commands request data
439 *
440 * @param[in] msg - Pointer to PLDM request message
441 * @param[in] payload_length - Length of request payload
442 * @param[in] file_type - Type of the file
443 * @param[out] file_handle - A handle to the file
444 * @param[out] offset - Offset to the file at which the read should begin
445 * @param[out] length - Number of bytes to be read
446 * @param[out] address - Memory address of the file content
447 * @return pldm_completion_codes
448 */
449int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
450 size_t payload_length,
451 uint16_t *file_type,
452 uint32_t *file_handle, uint32_t *offset,
453 uint32_t *length, uint64_t *address);
454
455/** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
456 * WriteFileByTypeFromMemory
457 *
458 * @param[in] instance_id - Message's instance id
459 * @param[in] command - PLDM command
460 * @param[in] completion_code - PLDM completion code
461 * @param[in] length - Number of bytes read. This could be less than what the
462 * requester asked for.
463 * @param[in,out] msg - Message will be written to this
464 * @return pldm_completion_codes
465 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
466 */
467int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
468 uint8_t completion_code, uint32_t length,
469 struct pldm_msg *msg);
470
471/** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
472 * commands request data
473 *
474 * @param[in] instance_id - Message's instance id
475 * @param[in] command - PLDM command
476 * @param[in] file_type - Type of the file
477 * @param[in] file_handle - A handle to the file
478 * @param[in] offset - Offset to the file at which the read should begin
479 * @param[in] length - Number of bytes to be read/written
480 * @param[in] address - Memory address where the file content has to be
481 * written to
482 * @param[out] msg - Message will be written to this
483 * @return pldm_completion_codes
484 */
485int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
486 uint16_t file_type, uint32_t file_handle,
487 uint32_t offset, uint32_t length,
488 uint64_t address, struct pldm_msg *msg);
489
490/** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
491 * commands response data
492 *
493 * @param[in] msg - pointer to PLDM response message
494 * @param[in] payload_length - Length of response payload
495 * @param[out] completion_code - PLDM completion code
496 * @param[out] length - Number of bytes to be read/written
497 * @return pldm_completion_codes
498 */
499int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
500 size_t payload_length,
501 uint8_t *completion_code,
502 uint32_t *length);
503
vkaverapa9aac722019-08-22 02:10:15 -0500504/** @struct pldm_new_file_req
505 *
506 * Structure representing NewFile request
507 */
508struct pldm_new_file_req {
509 uint16_t file_type; //!< Type of file
510 uint32_t file_handle; //!< Handle to file
Deepak Kodihalli83388762020-01-28 04:09:58 -0600511 uint64_t length; //!< Number of bytes in new file
vkaverapa9aac722019-08-22 02:10:15 -0500512} __attribute__((packed));
513
514/** @struct pldm_new_file_resp
515 *
516 * Structure representing NewFile response data
517 */
518struct pldm_new_file_resp {
519 uint8_t completion_code; //!< Completion code
520} __attribute__((packed));
521
522/** @brief Decode NewFileAvailable command request data
523 *
524 * @param[in] msg - Pointer to PLDM request message
525 * @param[in] payload_length - Length of request payload
526 * @param[in] file_type - Type of the file
527 * @param[out] file_handle - A handle to the file
528 * @param[out] length - Number of bytes in new file
529 * @return pldm_completion_codes
530 */
531int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
532 uint16_t *file_type, uint32_t *file_handle,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600533 uint64_t *length);
vkaverapa9aac722019-08-22 02:10:15 -0500534
535/** @brief Create a PLDM response for NewFileAvailable
536 *
537 * @param[in] instance_id - Message's instance id
538 * @param[in] completion_code - PLDM completion code
539 * @param[in,out] msg - Message will be written to this
540 * @return pldm_completion_codes
541 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
542 */
543int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
544 struct pldm_msg *msg);
545
546/** @brief Encode NewFileAvailable command request data
547 *
548 * @param[in] instance_id - Message's instance id
549 * @param[in] file_type - Type of the file
550 * @param[in] file_handle - A handle to the file
551 * @param[in] length - Number of bytes in new file
552 * @param[out] msg - Message will be written to this
553 * @return pldm_completion_codes
554 */
555int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
Deepak Kodihalli83388762020-01-28 04:09:58 -0600556 uint32_t file_handle, uint64_t length,
vkaverapa9aac722019-08-22 02:10:15 -0500557 struct pldm_msg *msg);
558
559/** @brief Decode NewFileAvailable command response data
560 *
561 * @param[in] msg - pointer to PLDM response message
562 * @param[in] payload_length - Length of response payload
563 * @param[out] completion_code - PLDM completion code
564 * @return pldm_completion_codes
565 */
566int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
567 uint8_t *completion_code);
568
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600569/** @struct pldm_read_write_file_by_type_req
570 *
571 * Structure representing ReadFileByType and
572 * WriteFileByType request
573 */
574struct pldm_read_write_file_by_type_req {
575 uint16_t file_type; //!< Type of file
576 uint32_t file_handle; //!< Handle to file
577 uint32_t offset; //!< Offset to file where read/write starts
578 uint32_t length; //!< Bytes to be read
579} __attribute__((packed));
580
581/** @struct pldm_read_write_file_by_type_resp
582 *
583 * Structure representing ReadFileByType and
584 * WriteFileByType response
585 */
586struct pldm_read_write_file_by_type_resp {
587 uint8_t completion_code; //!< Completion code
588 uint32_t length; //!< Number of bytes read
589} __attribute__((packed));
590
591/** @brief Decode ReadFileByType and WriteFileByType
592 * commands request data
593 *
594 * @param[in] msg - Pointer to PLDM request message
595 * @param[in] payload_length - Length of request payload
vkaverapf4e0a492019-11-19 01:47:35 -0600596 * @param[out] file_type - Type of the file
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600597 * @param[out] file_handle - A handle to the file
598 * @param[out] offset - Offset to the file at which the read/write should begin
599 * @param[out] length - Number of bytes to be read/written
600 * @return pldm_completion_codes
601 */
602int decode_rw_file_by_type_req(const struct pldm_msg *msg,
603 size_t payload_length, uint16_t *file_type,
604 uint32_t *file_handle, uint32_t *offset,
605 uint32_t *length);
606
607/** @brief Create a PLDM response for ReadFileByType and
608 * WriteFileByType
609 *
610 * @param[in] instance_id - Message's instance id
611 * @param[in] command - PLDM command
612 * @param[in] completion_code - PLDM completion code
613 * @param[in] length - Number of bytes read/written. This could be less than
vkaverapf4e0a492019-11-19 01:47:35 -0600614 * what the requester asked for.
Deepak Kodihallidce1c992019-11-19 07:06:53 -0600615 * @param[in,out] msg - Message will be written to this
616 * @return pldm_completion_codes
617 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
618 * @note File content has to be copied directly by the caller.
619 */
620int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
621 uint8_t completion_code, uint32_t length,
622 struct pldm_msg *msg);
623
624/** @brief Encode ReadFileByType and WriteFileByType
625 * commands request data
626 *
627 * @param[in] instance_id - Message's instance id
628 * @param[in] command - PLDM command
629 * @param[in] file_type - Type of the file
630 * @param[in] file_handle - A handle to the file
631 * @param[in] offset - Offset to the file at which the read should begin
632 * @param[in] length - Number of bytes to be read/written
633 * @param[out] msg - Message will be written to this
634 * @return pldm_completion_codes
635 * @note File content has to be read directly by the caller.
636 */
637int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
638 uint16_t file_type, uint32_t file_handle,
639 uint32_t offset, uint32_t length,
640 struct pldm_msg *msg);
641
642/** @brief Decode ReadFileByType and WriteFileByType
643 * commands response data
644 *
645 * @param[in] msg - pointer to PLDM response message
646 * @param[in] payload_length - Length of response payload
647 * @param[out] completion_code - PLDM completion code
648 * @param[out] length - Number of bytes to be read/written
649 * @return pldm_completion_codes
650 */
651int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
652 size_t payload_length, uint8_t *completion_code,
653 uint32_t *length);
654
vkaverapf4e0a492019-11-19 01:47:35 -0600655/** @struct pldm_file_ack_req
656 *
657 * Structure representing FileAck request
658 */
659struct pldm_file_ack_req {
660 uint16_t file_type; //!< Type of file
661 uint32_t file_handle; //!< Handle to file
662 uint8_t file_status; //!< Status of file processing
663} __attribute__((packed));
664
665/** @struct pldm_file_ack_resp
666 *
667 * Structure representing NewFile response data
668 */
669struct pldm_file_ack_resp {
670 uint8_t completion_code; //!< Completion code
671} __attribute__((packed));
672
673/** @brief Decode FileAck command request data
674 *
675 * @param[in] msg - Pointer to PLDM request message
676 * @param[in] payload_length - Length of request payload
677 * @param[out] file_type - Type of the file
678 * @param[out] file_handle - A handle to the file
679 * @param[out] file_status - Status of file processing
680 * @return pldm_completion_codes
681 */
682int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
683 uint16_t *file_type, uint32_t *file_handle,
684 uint8_t *file_status);
685
686/** @brief Create a PLDM response for FileAck
687 *
688 * @param[in] instance_id - Message's instance id
689 * @param[in] completion_code - PLDM completion code
690 * @param[in,out] msg - Message will be written to this
691 * @return pldm_completion_codes
692 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
693 */
694int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
695 struct pldm_msg *msg);
696
697/** @brief Encode FileAck command request data
698 *
699 * @param[in] instance_id - Message's instance id
700 * @param[in] file_type - Type of the file
701 * @param[in] file_handle - A handle to the file
702 * @param[in] file_status - Status of file processing
703 * @param[out] msg - Message will be written to this
704 * @return pldm_completion_codes
705 */
706int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
707 uint32_t file_handle, uint8_t file_status,
708 struct pldm_msg *msg);
709
710/** @brief Decode FileAck command response data
711 *
712 * @param[in] msg - pointer to PLDM response message
713 * @param[in] payload_length - Length of response payload
714 * @param[out] completion_code - PLDM completion code
715 * @return pldm_completion_codes
716 */
717int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
718 uint8_t *completion_code);
719
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530720#ifdef __cplusplus
721}
722#endif
723
724#endif /* FILEIO_H */