blob: 345b3632207d13372f27cdb07bf0ffbb570b4401 [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
13#define PLDM_IBM_OEM_TYPE 0x3F
14
15/** @brief PLDM Commands in IBM OEM type
16 */
17enum pldm_fileio_commands {
18 PLDM_READ_FILE_INTO_MEMORY = 0x6,
19 PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
20};
21
22/** @brief PLDM Command specific codes
23 */
24enum pldm_fileio_completion_codes {
25 PLDM_INVALID_FILE_HANDLE = 0x80,
26 PLDM_DATA_OUT_OF_RANGE = 0x81,
27 PLDM_INVALID_READ_LENGTH = 0x82,
28 PLDM_INVALID_WRITE_LENGTH = 0x83,
29};
30
31#define PLDM_RW_FILE_MEM_REQ_BYTES 20
32#define PLDM_RW_FILE_MEM_RESP_BYTES 5
33
34/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
35 * data
36 *
37 * @param[in] msg - Pointer to PLDM request message payload
38 * @param[in] payload_length - Length of request payload
39 * @param[out] file_handle - A handle to the file
40 * @param[out] offset - Offset to the file at which the read should begin
41 * @param[out] length - Number of bytes to be read
42 * @param[out] address - Memory address where the file content has to be
43 * written to
44 * @return pldm_completion_codes
45 */
46int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
47 uint32_t *file_handle, uint32_t *offset,
48 uint32_t *length, uint64_t *address);
49
50/** @brief Create a PLDM response for ReadFileIntoMemory and
51 * WriteFileFromMemory
52 *
53 * @param[in] instance_id - Message's instance id
54 * @param[in] command - PLDM command
55 * @param[in] completion_code - PLDM completion code
56 * @param[in] length - Number of bytes read. This could be less than what the
57 requester asked for.
58 * @param[in,out] msg - Message will be written to this
59 * @return pldm_completion_codes
60 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
61 */
62int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
63 uint8_t completion_code, uint32_t length,
64 struct pldm_msg *msg);
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif /* FILEIO_H */