blob: b3a0f739727689aade80f44311b85659b4e48d96 [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 *
Zahed Hossain223a73d2019-07-04 12:46:18 -050069 * @param[in] msg - Pointer to PLDM request message
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053070 * @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 */
Zahed Hossain223a73d2019-07-04 12:46:18 -050078int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053079 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 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500119 * @param[in] msg - pointer to PLDM response message
Priyanga8b976652019-06-27 11:30:33 -0500120 * @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 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500125int decode_rw_file_memory_resp(const struct pldm_msg *msg,
126 size_t payload_length, uint8_t *completion_code,
127 uint32_t *length);
Priyanga8b976652019-06-27 11:30:33 -0500128
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530129/** @struct pldm_get_file_table_req
130 *
131 * Structure representing GetFileTable request
132 */
133struct pldm_get_file_table_req {
134 uint32_t transfer_handle; //!< Data transfer handle
135 uint8_t operation_flag; //!< Transfer operation flag
136 uint8_t table_type; //!< Table type
137} __attribute__((packed));
138
139/** @struct pldm_get_file_table_resp
140 *
141 * Structure representing GetFileTable response fixed data
142 */
143struct pldm_get_file_table_resp {
144 uint8_t completion_code; //!< Completion code
145 uint32_t next_transfer_handle; //!< Next data transfer handle
146 uint8_t transfer_flag; //!< Transfer flag
147 uint8_t table_data[1]; //!< Table Data
148} __attribute__((packed));
149
150/** @brief Decode GetFileTable command request data
151 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500152 * @param[in] msg - Pointer to PLDM request message
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530153 * @param[in] payload_length - Length of request payload
154 * @param[out] trasnfer_handle - the handle of data
155 * @param[out] transfer_opflag - Transfer operation flag
156 * @param[out] table_type - the type of file table
157 * @return pldm_completion_codes
158 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500159int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530160 uint32_t *transfer_handle,
161 uint8_t *transfer_opflag, uint8_t *table_type);
162
163/** @brief Create a PLDM response for GetFileTable command
164 *
165 * @param[in] instance_id - Message's instance id
166 * @param[in] completion_code - PLDM completion code
167 * @param[in] next_transfer_handle - Handle to identify next portion of
168 * data transfer
169 * @param[in] transfer_flag - Represents the part of transfer
170 * @param[in] table_data - pointer to file table data
171 * @param[in] table_size - file table size
172 * @param[in,out] msg - Message will be written to this
173 * @return pldm_completion_codes
174 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
175 */
176int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
177 uint32_t next_transfer_handle,
178 uint8_t transfer_flag, const uint8_t *table_data,
179 size_t table_size, struct pldm_msg *msg);
180
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530181#ifdef __cplusplus
182}
183#endif
184
185#endif /* FILEIO_H */