blob: 64f203c5924597ca5a2c0d8440c802c54214db74 [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,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053017 PLDM_READ_FILE_INTO_MEMORY = 0x6,
18 PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
19};
20
21/** @brief PLDM Command specific codes
22 */
23enum pldm_fileio_completion_codes {
24 PLDM_INVALID_FILE_HANDLE = 0x80,
25 PLDM_DATA_OUT_OF_RANGE = 0x81,
26 PLDM_INVALID_READ_LENGTH = 0x82,
27 PLDM_INVALID_WRITE_LENGTH = 0x83,
Tom Joseph0c6d22c2019-06-26 09:58:41 +053028 PLDM_FILE_TABLE_UNAVAILABLE = 0x84,
29 PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
30};
31
32/** @brief PLDM File I/O table types
33 */
34enum pldm_fileio_table_type {
35 PLDM_FILE_ATTRIBUTE_TABLE = 0,
36 PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053037};
38
39#define PLDM_RW_FILE_MEM_REQ_BYTES 20
40#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph0c6d22c2019-06-26 09:58:41 +053041#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
42#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053043
Priyanga8b976652019-06-27 11:30:33 -050044/** @struct pldm_read_write_file_memory_req
45 *
46 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
47 * request
48 */
49struct pldm_read_write_file_memory_req {
50 uint32_t file_handle; //!< A Handle to the file
51 uint32_t offset; //!< Offset to the file
52 uint32_t length; //!< Number of bytes to be read/write
53 uint64_t address; //!< Memory address of the file
54} __attribute__((packed));
55
56/** @struct pldm_read_write_file_memory_resp
57 *
58 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
59 * response
60 */
61struct pldm_read_write_file_memory_resp {
62 uint8_t completion_code; //!< completion code
63 uint32_t length; //!< Number of bytes read/written
64} __attribute__((packed));
65
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053066/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
67 * data
68 *
69 * @param[in] msg - Pointer to PLDM request message payload
70 * @param[in] payload_length - Length of request payload
71 * @param[out] file_handle - A handle to the file
72 * @param[out] offset - Offset to the file at which the read should begin
73 * @param[out] length - Number of bytes to be read
74 * @param[out] address - Memory address where the file content has to be
75 * written to
76 * @return pldm_completion_codes
77 */
78int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
79 uint32_t *file_handle, uint32_t *offset,
80 uint32_t *length, uint64_t *address);
81
82/** @brief Create a PLDM response for ReadFileIntoMemory and
83 * WriteFileFromMemory
84 *
85 * @param[in] instance_id - Message's instance id
86 * @param[in] command - PLDM command
87 * @param[in] completion_code - PLDM completion code
88 * @param[in] length - Number of bytes read. This could be less than what the
89 requester asked for.
90 * @param[in,out] msg - Message will be written to this
91 * @return pldm_completion_codes
92 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
93 */
94int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
95 uint8_t completion_code, uint32_t length,
96 struct pldm_msg *msg);
97
Priyanga8b976652019-06-27 11:30:33 -050098/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
99 * commands request data
100 *
101 * @param[in] instance_id - Message's instance id
102 * @param[in] command - PLDM command
103 * @param[in] file_handle - A handle to the file
104 * @param[in] offset - Offset to the file at which the read should begin
105 * @param[in] length - Number of bytes to be read/written
106 * @param[in] address - Memory address where the file content has to be
107 * written to
108 * @param[out] msg - Message will be written to this
109 * @return pldm_completion_codes
110 */
111int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
112 uint32_t file_handle, uint32_t offset,
113 uint32_t length, uint64_t address,
114 struct pldm_msg *msg);
115
116/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
117 * commands response data
118 *
119 * @param[in] msg - pointer to PLDM response message payload
120 * @param[in] payload_length - Length of response payload
121 * @param[out] completion_code - PLDM completion code
122 * @param[out] length - Number of bytes to be read/written
123 * @return pldm_completion_codes
124 */
125int decode_rw_file_memory_resp(const uint8_t *msg, size_t payload_length,
126 uint8_t *completion_code, uint32_t *length);
127
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530128/** @struct pldm_get_file_table_req
129 *
130 * Structure representing GetFileTable request
131 */
132struct pldm_get_file_table_req {
133 uint32_t transfer_handle; //!< Data transfer handle
134 uint8_t operation_flag; //!< Transfer operation flag
135 uint8_t table_type; //!< Table type
136} __attribute__((packed));
137
138/** @struct pldm_get_file_table_resp
139 *
140 * Structure representing GetFileTable response fixed data
141 */
142struct pldm_get_file_table_resp {
143 uint8_t completion_code; //!< Completion code
144 uint32_t next_transfer_handle; //!< Next data transfer handle
145 uint8_t transfer_flag; //!< Transfer flag
146 uint8_t table_data[1]; //!< Table Data
147} __attribute__((packed));
148
149/** @brief Decode GetFileTable command request data
150 *
151 * @param[in] msg - Pointer to PLDM request message payload
152 * @param[in] payload_length - Length of request payload
153 * @param[out] trasnfer_handle - the handle of data
154 * @param[out] transfer_opflag - Transfer operation flag
155 * @param[out] table_type - the type of file table
156 * @return pldm_completion_codes
157 */
158int decode_get_file_table_req(const uint8_t *msg, size_t payload_length,
159 uint32_t *transfer_handle,
160 uint8_t *transfer_opflag, uint8_t *table_type);
161
162/** @brief Create a PLDM response for GetFileTable command
163 *
164 * @param[in] instance_id - Message's instance id
165 * @param[in] completion_code - PLDM completion code
166 * @param[in] next_transfer_handle - Handle to identify next portion of
167 * data transfer
168 * @param[in] transfer_flag - Represents the part of transfer
169 * @param[in] table_data - pointer to file table data
170 * @param[in] table_size - file table size
171 * @param[in,out] msg - Message will be written to this
172 * @return pldm_completion_codes
173 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
174 */
175int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
176 uint32_t next_transfer_handle,
177 uint8_t transfer_flag, const uint8_t *table_data,
178 size_t table_size, struct pldm_msg *msg);
179
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530180#ifdef __cplusplus
181}
182#endif
183
184#endif /* FILEIO_H */