blob: d6c9b6ab3a57e455d490c070b2999ec99c251ccd [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,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053024};
25
26/** @brief PLDM Command specific codes
27 */
28enum pldm_fileio_completion_codes {
29 PLDM_INVALID_FILE_HANDLE = 0x80,
30 PLDM_DATA_OUT_OF_RANGE = 0x81,
31 PLDM_INVALID_READ_LENGTH = 0x82,
32 PLDM_INVALID_WRITE_LENGTH = 0x83,
Tom Joseph0c6d22c2019-06-26 09:58:41 +053033 PLDM_FILE_TABLE_UNAVAILABLE = 0x84,
34 PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
Sampa Misra854e61f2019-08-22 04:36:47 -050035 PLDM_INVALID_FILE_TYPE = 0x86,
Tom Joseph0c6d22c2019-06-26 09:58:41 +053036};
37
38/** @brief PLDM File I/O table types
39 */
40enum pldm_fileio_table_type {
41 PLDM_FILE_ATTRIBUTE_TABLE = 0,
42 PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053043};
44
Sampa Misra854e61f2019-08-22 04:36:47 -050045/** @brief PLDM File I/O table types
46 */
47enum pldm_fileio_file_type {
48 PLDM_FILE_TYPE_PEL = 0,
49};
50
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053051#define PLDM_RW_FILE_MEM_REQ_BYTES 20
52#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph0c6d22c2019-06-26 09:58:41 +053053#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
54#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
vkaverap2ffe3292019-06-24 00:08:13 -050055#define PLDM_READ_FILE_REQ_BYTES 12
56#define PLDM_READ_FILE_RESP_BYTES 5
57#define PLDM_WRITE_FILE_REQ_BYTES 12
58#define PLDM_WRITE_FILE_RESP_BYTES 5
vkaverap07404562019-08-05 22:57:11 -050059#define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES 22
60#define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES 5
vkaverapa9aac722019-08-22 02:10:15 -050061#define PLDM_NEW_FILE_REQ_BYTES 10
62#define PLDM_NEW_FILE_RESP_BYTES 1
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053063
Priyanga8b976652019-06-27 11:30:33 -050064/** @struct pldm_read_write_file_memory_req
65 *
66 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
67 * request
68 */
69struct pldm_read_write_file_memory_req {
70 uint32_t file_handle; //!< A Handle to the file
71 uint32_t offset; //!< Offset to the file
72 uint32_t length; //!< Number of bytes to be read/write
73 uint64_t address; //!< Memory address of the file
74} __attribute__((packed));
75
76/** @struct pldm_read_write_file_memory_resp
77 *
78 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
79 * response
80 */
81struct pldm_read_write_file_memory_resp {
82 uint8_t completion_code; //!< completion code
83 uint32_t length; //!< Number of bytes read/written
84} __attribute__((packed));
85
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053086/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
87 * data
88 *
Zahed Hossain223a73d2019-07-04 12:46:18 -050089 * @param[in] msg - Pointer to PLDM request message
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053090 * @param[in] payload_length - Length of request payload
91 * @param[out] file_handle - A handle to the file
92 * @param[out] offset - Offset to the file at which the read should begin
93 * @param[out] length - Number of bytes to be read
94 * @param[out] address - Memory address where the file content has to be
95 * written to
96 * @return pldm_completion_codes
97 */
Zahed Hossain223a73d2019-07-04 12:46:18 -050098int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053099 uint32_t *file_handle, uint32_t *offset,
100 uint32_t *length, uint64_t *address);
101
102/** @brief Create a PLDM response for ReadFileIntoMemory and
103 * WriteFileFromMemory
104 *
105 * @param[in] instance_id - Message's instance id
106 * @param[in] command - PLDM command
107 * @param[in] completion_code - PLDM completion code
108 * @param[in] length - Number of bytes read. This could be less than what the
109 requester asked for.
110 * @param[in,out] msg - Message will be written to this
111 * @return pldm_completion_codes
112 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
113 */
114int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
115 uint8_t completion_code, uint32_t length,
116 struct pldm_msg *msg);
117
Priyanga8b976652019-06-27 11:30:33 -0500118/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
119 * commands request data
120 *
121 * @param[in] instance_id - Message's instance id
122 * @param[in] command - PLDM command
123 * @param[in] file_handle - A handle to the file
124 * @param[in] offset - Offset to the file at which the read should begin
125 * @param[in] length - Number of bytes to be read/written
126 * @param[in] address - Memory address where the file content has to be
127 * written to
128 * @param[out] msg - Message will be written to this
129 * @return pldm_completion_codes
130 */
131int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
132 uint32_t file_handle, uint32_t offset,
133 uint32_t length, uint64_t address,
134 struct pldm_msg *msg);
135
136/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
137 * commands response data
138 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500139 * @param[in] msg - pointer to PLDM response message
Priyanga8b976652019-06-27 11:30:33 -0500140 * @param[in] payload_length - Length of response payload
141 * @param[out] completion_code - PLDM completion code
142 * @param[out] length - Number of bytes to be read/written
143 * @return pldm_completion_codes
144 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500145int decode_rw_file_memory_resp(const struct pldm_msg *msg,
146 size_t payload_length, uint8_t *completion_code,
147 uint32_t *length);
Priyanga8b976652019-06-27 11:30:33 -0500148
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530149/** @struct pldm_get_file_table_req
150 *
151 * Structure representing GetFileTable request
152 */
153struct pldm_get_file_table_req {
154 uint32_t transfer_handle; //!< Data transfer handle
155 uint8_t operation_flag; //!< Transfer operation flag
156 uint8_t table_type; //!< Table type
157} __attribute__((packed));
158
159/** @struct pldm_get_file_table_resp
160 *
161 * Structure representing GetFileTable response fixed data
162 */
163struct pldm_get_file_table_resp {
164 uint8_t completion_code; //!< Completion code
165 uint32_t next_transfer_handle; //!< Next data transfer handle
166 uint8_t transfer_flag; //!< Transfer flag
167 uint8_t table_data[1]; //!< Table Data
168} __attribute__((packed));
169
170/** @brief Decode GetFileTable command request data
171 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500172 * @param[in] msg - Pointer to PLDM request message
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530173 * @param[in] payload_length - Length of request payload
174 * @param[out] trasnfer_handle - the handle of data
175 * @param[out] transfer_opflag - Transfer operation flag
176 * @param[out] table_type - the type of file table
177 * @return pldm_completion_codes
178 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500179int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530180 uint32_t *transfer_handle,
181 uint8_t *transfer_opflag, uint8_t *table_type);
182
183/** @brief Create a PLDM response for GetFileTable command
184 *
185 * @param[in] instance_id - Message's instance id
186 * @param[in] completion_code - PLDM completion code
187 * @param[in] next_transfer_handle - Handle to identify next portion of
188 * data transfer
189 * @param[in] transfer_flag - Represents the part of transfer
190 * @param[in] table_data - pointer to file table data
191 * @param[in] table_size - file table size
192 * @param[in,out] msg - Message will be written to this
193 * @return pldm_completion_codes
194 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
195 */
196int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
197 uint32_t next_transfer_handle,
198 uint8_t transfer_flag, const uint8_t *table_data,
199 size_t table_size, struct pldm_msg *msg);
200
vkaverap2ffe3292019-06-24 00:08:13 -0500201/** @struct pldm_read_file_req
202 *
203 * Structure representing ReadFile request
204 */
205struct pldm_read_file_req {
206 uint32_t file_handle; //!< Handle to file
207 uint32_t offset; //!< Offset to file where read starts
208 uint32_t length; //!< Bytes to be read
209} __attribute__((packed));
210
211/** @struct pldm_read_file_resp
212 *
213 * Structure representing ReadFile response data
214 */
215struct pldm_read_file_resp {
216 uint8_t completion_code; //!< Completion code
217 uint32_t length; //!< Number of bytes read
218 uint8_t file_data[1]; //!< Address of this is where file data starts
219} __attribute__((packed));
220
221/** @struct pldm_write_file_req
222 *
223 * Structure representing WriteFile request
224 */
225struct pldm_write_file_req {
226 uint32_t file_handle; //!< Handle to file
227 uint32_t offset; //!< Offset to file where write starts
228 uint32_t length; //!< Bytes to be written
229 uint8_t file_data[1]; //!< Address of this is where file data starts
230} __attribute__((packed));
231
232/** @struct pldm_write_file_resp
233 *
234 * Structure representing WriteFile response data
235 */
236struct pldm_write_file_resp {
237 uint8_t completion_code; //!< Completion code
238 uint32_t length; //!< Bytes written
239} __attribute__((packed));
240
241/** @brief Decode Read File commands request
242 *
243 * @param[in] msg - PLDM request message payload
244 * @param[in] payload_length - Length of request payload
245 * @param[out] file_handle - A handle to the file
246 * @param[out] offset - Offset to the file at which the read should begin
247 * @param[out] length - Number of bytes read
248 * @return pldm_completion_codes
249 */
250int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
251 uint32_t *file_handle, uint32_t *offset,
252 uint32_t *length);
253
254/** @brief Encode Read File commands request
255 *
256 * @param[in] instance_id - Message's instance id
257 * @param[in] file_handle - A handle to the file
258 * @param[in] offset - Offset to the file at which the read should begin
259 * @param[in] length - Number of bytes read
260 * @param[in,out] msg - Message will be written to this
261 * @return pldm_completion_codes
262 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
263 */
264int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
265 uint32_t offset, uint32_t length,
266 struct pldm_msg *msg);
267
268/** @brief Decode Read File commands response
269 *
270 * @param[in] msg - PLDM response message payload
271 * @param[in] payload_length - Length of request payload
272 * @param[out] completion_code - PLDM completion code
273 * @param[out] length - Number of bytes read. This could be less than what the
274 * requester asked for.
275 * @param[out] file_data_offset - Offset where file data should be read in pldm
276 * msg.
277 * @return pldm_completion_codes
278 */
279int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
280 uint8_t *completion_code, uint32_t *length,
281 size_t *file_data_offset);
282
283/** @brief Create a PLDM response for Read File
284 *
285 * @param[in] instance_id - Message's instance id
286 * @param[in] completion_code - PLDM completion code
287 * @param[in] length - Number of bytes read. This could be less than what the
288 * requester asked for.
289 * @param[in,out] msg - Message will be written to this
290 * @return pldm_completion_codes
291 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
292 * Although read file command response includes file data, this function
293 * does not encode the file data to prevent additional copying of the data.
294 * The position of file data is calculated by caller from address and size
295 * of other input arguments.
296 */
297int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
298 uint32_t length, struct pldm_msg *msg);
299
300/** @brief Decode Write File commands request
301 *
302 * @param[in] msg - PLDM request message payload
303 * @param[in] payload_length - Length of request payload
304 * @param[out] file_handle - A handle to the file
305 * @param[out] offset - Offset to the file at which the write should begin
306 * @param[out] length - Number of bytes to write
307 * @param[out] file_data_offset - Offset where file data write begins in pldm
308 * msg.
309 * @return pldm_completion_codes
310 */
311int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
312 uint32_t *file_handle, uint32_t *offset,
313 uint32_t *length, size_t *file_data_offset);
314
315/** @brief Create a PLDM request for Write File
316 *
317 * @param[in] instance_id - Message's instance id
318 * @param[in] file_handle - A handle to the file
319 * @param[in] offset - Offset to the file at which the read should begin
320 * @param[in] length - Number of bytes written. This could be less than what
321 * the requester asked for.
322 * @param[in,out] msg - Message will be written to this
323 * @return pldm_completion_codes
324 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
325 * Although write file command request includes file data, this function
326 * does not encode the file data to prevent additional copying of the data.
327 * The position of file data is calculated by caller from address and size
328 * of other input arguments.
329 */
330int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
331 uint32_t offset, uint32_t length,
332 struct pldm_msg *msg);
333
334/** @brief Decode Write File commands response
335 *
336 * @param[in] msg - PLDM request message payload
337 * @param[in] payload_length - Length of request payload
338 * @param[out] completion_code - PLDM completion code
339 * @param[out] length - Number of bytes written
340 * @return pldm_completion_codes
341 */
342int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
343 uint8_t *completion_code, uint32_t *length);
344
345/** @brief Create a PLDM response for Write File
346 *
347 * @param[in] instance_id - Message's instance id
348 * @param[in] completion_code - PLDM completion code
349 * @param[in] length - Number of bytes written. This could be less than what
350 * the requester asked for.
351 * @param[in,out] msg - Message will be written to this
352 * @return pldm_completion_codes
353 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
354 */
355int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
356 uint32_t length, struct pldm_msg *msg);
357
vkaverap07404562019-08-05 22:57:11 -0500358/** @struct pldm_read_write_file_by_type_memory_req
359 *
360 * Structure representing ReadFileByTypeIntoMemory and
361 * WriteFileByTypeFromMemory request
362 */
363struct pldm_read_write_file_by_type_memory_req {
364 uint16_t file_type; //!< Type of file
365 uint32_t file_handle; //!< Handle to file
366 uint32_t offset; //!< Offset to file where read starts
367 uint32_t length; //!< Bytes to be read
368 uint64_t address; //!< Memory address of the file
369} __attribute__((packed));
370
371/** @struct pldm_read_write_file_by_type_memory_resp
372 *
373 * Structure representing ReadFileByTypeIntoMemory and
374 * WriteFileByTypeFromMemory response
375 */
376struct pldm_read_write_file_by_type_memory_resp {
377 uint8_t completion_code; //!< Completion code
378 uint32_t length; //!< Number of bytes read
379} __attribute__((packed));
380
381/** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
382 * commands request data
383 *
384 * @param[in] msg - Pointer to PLDM request message
385 * @param[in] payload_length - Length of request payload
386 * @param[in] file_type - Type of the file
387 * @param[out] file_handle - A handle to the file
388 * @param[out] offset - Offset to the file at which the read should begin
389 * @param[out] length - Number of bytes to be read
390 * @param[out] address - Memory address of the file content
391 * @return pldm_completion_codes
392 */
393int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
394 size_t payload_length,
395 uint16_t *file_type,
396 uint32_t *file_handle, uint32_t *offset,
397 uint32_t *length, uint64_t *address);
398
399/** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
400 * WriteFileByTypeFromMemory
401 *
402 * @param[in] instance_id - Message's instance id
403 * @param[in] command - PLDM command
404 * @param[in] completion_code - PLDM completion code
405 * @param[in] length - Number of bytes read. This could be less than what the
406 * 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_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
412 uint8_t completion_code, uint32_t length,
413 struct pldm_msg *msg);
414
415/** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
416 * commands request data
417 *
418 * @param[in] instance_id - Message's instance id
419 * @param[in] command - PLDM command
420 * @param[in] file_type - Type of the file
421 * @param[in] file_handle - A handle to the file
422 * @param[in] offset - Offset to the file at which the read should begin
423 * @param[in] length - Number of bytes to be read/written
424 * @param[in] address - Memory address where the file content has to be
425 * written to
426 * @param[out] msg - Message will be written to this
427 * @return pldm_completion_codes
428 */
429int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
430 uint16_t file_type, uint32_t file_handle,
431 uint32_t offset, uint32_t length,
432 uint64_t address, struct pldm_msg *msg);
433
434/** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
435 * commands response data
436 *
437 * @param[in] msg - pointer to PLDM response message
438 * @param[in] payload_length - Length of response payload
439 * @param[out] completion_code - PLDM completion code
440 * @param[out] length - Number of bytes to be read/written
441 * @return pldm_completion_codes
442 */
443int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
444 size_t payload_length,
445 uint8_t *completion_code,
446 uint32_t *length);
447
vkaverapa9aac722019-08-22 02:10:15 -0500448/** @struct pldm_new_file_req
449 *
450 * Structure representing NewFile request
451 */
452struct pldm_new_file_req {
453 uint16_t file_type; //!< Type of file
454 uint32_t file_handle; //!< Handle to file
455 uint32_t length; //!< Number of bytes in new file
456} __attribute__((packed));
457
458/** @struct pldm_new_file_resp
459 *
460 * Structure representing NewFile response data
461 */
462struct pldm_new_file_resp {
463 uint8_t completion_code; //!< Completion code
464} __attribute__((packed));
465
466/** @brief Decode NewFileAvailable command request data
467 *
468 * @param[in] msg - Pointer to PLDM request message
469 * @param[in] payload_length - Length of request payload
470 * @param[in] file_type - Type of the file
471 * @param[out] file_handle - A handle to the file
472 * @param[out] length - Number of bytes in new file
473 * @return pldm_completion_codes
474 */
475int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
476 uint16_t *file_type, uint32_t *file_handle,
477 uint32_t *length);
478
479/** @brief Create a PLDM response for NewFileAvailable
480 *
481 * @param[in] instance_id - Message's instance id
482 * @param[in] completion_code - PLDM completion code
483 * @param[in,out] msg - Message will be written to this
484 * @return pldm_completion_codes
485 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
486 */
487int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
488 struct pldm_msg *msg);
489
490/** @brief Encode NewFileAvailable command request data
491 *
492 * @param[in] instance_id - Message's instance id
493 * @param[in] file_type - Type of the file
494 * @param[in] file_handle - A handle to the file
495 * @param[in] length - Number of bytes in new file
496 * @param[out] msg - Message will be written to this
497 * @return pldm_completion_codes
498 */
499int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
500 uint32_t file_handle, uint32_t length,
501 struct pldm_msg *msg);
502
503/** @brief Decode NewFileAvailable command response data
504 *
505 * @param[in] msg - pointer to PLDM response message
506 * @param[in] payload_length - Length of response payload
507 * @param[out] completion_code - PLDM completion code
508 * @return pldm_completion_codes
509 */
510int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
511 uint8_t *completion_code);
512
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530513#ifdef __cplusplus
514}
515#endif
516
517#endif /* FILEIO_H */