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