blob: e1382757d84e969d6776e1158197f246139eefee [file] [log] [blame]
Tom Joseph7dae7772019-04-10 14:44:44 +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 */
Eddie James3b02e272019-04-22 20:13:55 +000017enum pldm_fileio_commands {
Tom Joseph61325fa2019-06-04 15:22:22 +053018 PLDM_GET_FILE_TABLE = 0x1,
Eddie James3b02e272019-04-22 20:13:55 +000019 PLDM_READ_FILE_INTO_MEMORY = 0x6,
20 PLDM_WRITE_FILE_FROM_MEMORY = 0x7,
21};
Tom Joseph7dae7772019-04-10 14:44:44 +053022
23/** @brief PLDM Command specific codes
24 */
25enum pldm_fileio_completion_codes {
26 PLDM_INVALID_FILE_HANDLE = 0x80,
27 PLDM_DATA_OUT_OF_RANGE = 0x81,
Eddie James3b02e272019-04-22 20:13:55 +000028 PLDM_INVALID_READ_LENGTH = 0x82,
29 PLDM_INVALID_WRITE_LENGTH = 0x83,
Tom Joseph61325fa2019-06-04 15:22:22 +053030 PLDM_FILE_TABLE_UNAVAILABLE = 0x84,
31 PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
32};
33
34/** @brief PLDM File I/O table types
35 */
36enum pldm_fileio_table_type {
37 PLDM_FILE_ATTRIBUTE_TABLE = 0,
38 PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
Tom Joseph7dae7772019-04-10 14:44:44 +053039};
40
Eddie James3b02e272019-04-22 20:13:55 +000041#define PLDM_RW_FILE_MEM_REQ_BYTES 20
42#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph61325fa2019-06-04 15:22:22 +053043#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
44#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
Tom Joseph7dae7772019-04-10 14:44:44 +053045
Priyangaf4736d42019-05-02 14:48:04 +053046/** @struct pldm_read_write_file_memory_req
47 *
48 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
49 * request
50 */
51struct pldm_read_write_file_memory_req {
52 uint32_t file_handle; //!< A Handle to the file
53 uint32_t offset; //!< Offset to the file
54 uint32_t length; //!< Number of bytes to be read/write
55 uint64_t address; //!< Memory address of the file
56} __attribute__((packed));
57
58/** @struct pldm_read_write_file_memory_resp
59 *
60 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
61 * response
62 */
63struct pldm_read_write_file_memory_resp {
64 uint8_t completion_code; //!< completion code
65 uint32_t length; //!< Number of bytes read/written
66} __attribute__((packed));
67
68/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
69 * commands request data
Tom Joseph7dae7772019-04-10 14:44:44 +053070 *
71 * @param[in] msg - Pointer to PLDM request message payload
72 * @param[in] payload_length - Length of request payload
73 * @param[out] file_handle - A handle to the file
74 * @param[out] offset - Offset to the file at which the read should begin
75 * @param[out] length - Number of bytes to be read
76 * @param[out] address - Memory address where the file content has to be
77 * written to
78 * @return pldm_completion_codes
79 */
Eddie James3b02e272019-04-22 20:13:55 +000080int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
81 uint32_t *file_handle, uint32_t *offset,
82 uint32_t *length, uint64_t *address);
Tom Joseph7dae7772019-04-10 14:44:44 +053083
Eddie James3b02e272019-04-22 20:13:55 +000084/** @brief Create a PLDM response for ReadFileIntoMemory and
85 * WriteFileFromMemory
Tom Joseph7dae7772019-04-10 14:44:44 +053086 *
87 * @param[in] instance_id - Message's instance id
Eddie James3b02e272019-04-22 20:13:55 +000088 * @param[in] command - PLDM command
Tom Joseph7dae7772019-04-10 14:44:44 +053089 * @param[in] completion_code - PLDM completion code
Priyangaf4736d42019-05-02 14:48:04 +053090 * @param[in] length - Number of bytes read. This could be less than
91 * what the requester asked for.
92 * @param[out] msg - Message will be written to this
Tom Joseph7dae7772019-04-10 14:44:44 +053093 * @return pldm_completion_codes
94 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
95 */
Eddie James3b02e272019-04-22 20:13:55 +000096int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
97 uint8_t completion_code, uint32_t length,
98 struct pldm_msg *msg);
Tom Joseph7dae7772019-04-10 14:44:44 +053099
Priyangaf4736d42019-05-02 14:48:04 +0530100/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
101 * commands request data
102 *
103 * @param[in] instance_id - Message's instance id
104 * @param[in] command - PLDM command
105 * @param[in] file_handle - A handle to the file
106 * @param[in] offset - Offset to the file at which the read should begin
107 * @param[in] length - Number of bytes to be read/written
108 * @param[in] address - Memory address where the file content has to be
109 * written to
110 * @param[out] msg - Message will be written to this
111 * @return pldm_completion_codes
112 */
113int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
114 uint32_t file_handle, uint32_t offset,
115 uint32_t length, uint64_t address,
116 struct pldm_msg *msg);
117
118/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
119 * commands response data
120 *
121 * @param[in] msg - pointer to PLDM response message payload
122 * @param[in] payload_length - Length of response payload
123 * @param[out] completion_code - PLDM completion code
124 * @param[out] length - Number of bytes to be read/written
125 * @return pldm_completion_codes
126 */
127int decode_rw_file_memory_resp(const uint8_t *msg, size_t payload_length,
128 uint8_t *completion_code, uint32_t *length);
129
Tom Joseph61325fa2019-06-04 15:22:22 +0530130/** @struct pldm_get_file_table_req
131 *
132 * Structure representing GetFileTable request
133 */
134struct pldm_get_file_table_req {
135 uint32_t transfer_handle; //!< Data transfer handle
136 uint8_t operation_flag; //!< Transfer operation flag
137 uint8_t table_type; //!< Table type
138} __attribute__((packed));
139
140/** @struct pldm_get_file_table_resp
141 *
142 * Structure representing GetFileTable response fixed data
143 */
144struct pldm_get_file_table_resp {
145 uint8_t completion_code; //!< Completion code
146 uint32_t next_transfer_handle; //!< Next data transfer handle
147 uint8_t transfer_flag; //!< Transfer flag
148 uint8_t table_data[1]; //!< Table Data
149} __attribute__((packed));
150
151/** @brief Decode GetFileTable command request data
152 *
153 * @param[in] msg - Pointer to PLDM request message payload
154 * @param[in] payload_length - Length of request payload
155 * @param[out] trasnfer_handle - the handle of data
156 * @param[out] transfer_opflag - Transfer operation flag
157 * @param[out] table_type - the type of file table
158 * @return pldm_completion_codes
159 */
160int decode_get_file_table_req(const uint8_t *msg, size_t payload_length,
161 uint32_t *transfer_handle,
162 uint8_t *transfer_opflag, uint8_t *table_type);
163
164/** @brief Create a PLDM response for GetFileTable command
165 *
166 * @param[in] instance_id - Message's instance id
167 * @param[in] completion_code - PLDM completion code
168 * @param[in] next_transfer_handle - Handle to identify next portion of
169 * data transfer
170 * @param[in] transfer_flag - Represents the part of transfer
171 * @param[in] table_data - pointer to file table data
172 * @param[in] table_size - file table size
173 * @param[in,out] msg - Message will be written to this
174 * @return pldm_completion_codes
175 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
176 */
177int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
178 uint32_t next_transfer_handle,
179 uint8_t transfer_flag, const uint8_t *table_data,
180 size_t table_size, struct pldm_msg *msg);
181
Tom Joseph7dae7772019-04-10 14:44:44 +0530182#ifdef __cplusplus
183}
184#endif
185
186#endif /* FILEIO_H */