blob: 15b568b97fd7759f4e045b5eec9896d0317482de [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,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053023};
24
25/** @brief PLDM Command specific codes
26 */
27enum pldm_fileio_completion_codes {
28 PLDM_INVALID_FILE_HANDLE = 0x80,
29 PLDM_DATA_OUT_OF_RANGE = 0x81,
30 PLDM_INVALID_READ_LENGTH = 0x82,
31 PLDM_INVALID_WRITE_LENGTH = 0x83,
Tom Joseph0c6d22c2019-06-26 09:58:41 +053032 PLDM_FILE_TABLE_UNAVAILABLE = 0x84,
33 PLDM_INVALID_FILE_TABLE_TYPE = 0x85,
34};
35
36/** @brief PLDM File I/O table types
37 */
38enum pldm_fileio_table_type {
39 PLDM_FILE_ATTRIBUTE_TABLE = 0,
40 PLDM_OEM_FILE_ATTRIBUTE_TABLE = 1,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053041};
42
43#define PLDM_RW_FILE_MEM_REQ_BYTES 20
44#define PLDM_RW_FILE_MEM_RESP_BYTES 5
Tom Joseph0c6d22c2019-06-26 09:58:41 +053045#define PLDM_GET_FILE_TABLE_REQ_BYTES 6
46#define PLDM_GET_FILE_TABLE_MIN_RESP_BYTES 6
vkaverap2ffe3292019-06-24 00:08:13 -050047#define PLDM_READ_FILE_REQ_BYTES 12
48#define PLDM_READ_FILE_RESP_BYTES 5
49#define PLDM_WRITE_FILE_REQ_BYTES 12
50#define PLDM_WRITE_FILE_RESP_BYTES 5
vkaverap07404562019-08-05 22:57:11 -050051#define PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES 22
52#define PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES 5
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053053
Priyanga8b976652019-06-27 11:30:33 -050054/** @struct pldm_read_write_file_memory_req
55 *
56 * Structure representing ReadFileIntoMemory request and WriteFileFromMemory
57 * request
58 */
59struct pldm_read_write_file_memory_req {
60 uint32_t file_handle; //!< A Handle to the file
61 uint32_t offset; //!< Offset to the file
62 uint32_t length; //!< Number of bytes to be read/write
63 uint64_t address; //!< Memory address of the file
64} __attribute__((packed));
65
66/** @struct pldm_read_write_file_memory_resp
67 *
68 * Structure representing ReadFileIntoMemory response and WriteFileFromMemory
69 * response
70 */
71struct pldm_read_write_file_memory_resp {
72 uint8_t completion_code; //!< completion code
73 uint32_t length; //!< Number of bytes read/written
74} __attribute__((packed));
75
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053076/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
77 * data
78 *
Zahed Hossain223a73d2019-07-04 12:46:18 -050079 * @param[in] msg - Pointer to PLDM request message
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053080 * @param[in] payload_length - Length of request payload
81 * @param[out] file_handle - A handle to the file
82 * @param[out] offset - Offset to the file at which the read should begin
83 * @param[out] length - Number of bytes to be read
84 * @param[out] address - Memory address where the file content has to be
85 * written to
86 * @return pldm_completion_codes
87 */
Zahed Hossain223a73d2019-07-04 12:46:18 -050088int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053089 uint32_t *file_handle, uint32_t *offset,
90 uint32_t *length, uint64_t *address);
91
92/** @brief Create a PLDM response for ReadFileIntoMemory and
93 * WriteFileFromMemory
94 *
95 * @param[in] instance_id - Message's instance id
96 * @param[in] command - PLDM command
97 * @param[in] completion_code - PLDM completion code
98 * @param[in] length - Number of bytes read. This could be less than what the
99 requester asked for.
100 * @param[in,out] msg - Message will be written to this
101 * @return pldm_completion_codes
102 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
103 */
104int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
105 uint8_t completion_code, uint32_t length,
106 struct pldm_msg *msg);
107
Priyanga8b976652019-06-27 11:30:33 -0500108/** @brief Encode ReadFileIntoMemory and WriteFileFromMemory
109 * commands request data
110 *
111 * @param[in] instance_id - Message's instance id
112 * @param[in] command - PLDM command
113 * @param[in] file_handle - A handle to the file
114 * @param[in] offset - Offset to the file at which the read should begin
115 * @param[in] length - Number of bytes to be read/written
116 * @param[in] address - Memory address where the file content has to be
117 * written to
118 * @param[out] msg - Message will be written to this
119 * @return pldm_completion_codes
120 */
121int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
122 uint32_t file_handle, uint32_t offset,
123 uint32_t length, uint64_t address,
124 struct pldm_msg *msg);
125
126/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory
127 * commands response data
128 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500129 * @param[in] msg - pointer to PLDM response message
Priyanga8b976652019-06-27 11:30:33 -0500130 * @param[in] payload_length - Length of response payload
131 * @param[out] completion_code - PLDM completion code
132 * @param[out] length - Number of bytes to be read/written
133 * @return pldm_completion_codes
134 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500135int decode_rw_file_memory_resp(const struct pldm_msg *msg,
136 size_t payload_length, uint8_t *completion_code,
137 uint32_t *length);
Priyanga8b976652019-06-27 11:30:33 -0500138
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530139/** @struct pldm_get_file_table_req
140 *
141 * Structure representing GetFileTable request
142 */
143struct pldm_get_file_table_req {
144 uint32_t transfer_handle; //!< Data transfer handle
145 uint8_t operation_flag; //!< Transfer operation flag
146 uint8_t table_type; //!< Table type
147} __attribute__((packed));
148
149/** @struct pldm_get_file_table_resp
150 *
151 * Structure representing GetFileTable response fixed data
152 */
153struct pldm_get_file_table_resp {
154 uint8_t completion_code; //!< Completion code
155 uint32_t next_transfer_handle; //!< Next data transfer handle
156 uint8_t transfer_flag; //!< Transfer flag
157 uint8_t table_data[1]; //!< Table Data
158} __attribute__((packed));
159
160/** @brief Decode GetFileTable command request data
161 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500162 * @param[in] msg - Pointer to PLDM request message
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530163 * @param[in] payload_length - Length of request payload
164 * @param[out] trasnfer_handle - the handle of data
165 * @param[out] transfer_opflag - Transfer operation flag
166 * @param[out] table_type - the type of file table
167 * @return pldm_completion_codes
168 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500169int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530170 uint32_t *transfer_handle,
171 uint8_t *transfer_opflag, uint8_t *table_type);
172
173/** @brief Create a PLDM response for GetFileTable command
174 *
175 * @param[in] instance_id - Message's instance id
176 * @param[in] completion_code - PLDM completion code
177 * @param[in] next_transfer_handle - Handle to identify next portion of
178 * data transfer
179 * @param[in] transfer_flag - Represents the part of transfer
180 * @param[in] table_data - pointer to file table data
181 * @param[in] table_size - file table size
182 * @param[in,out] msg - Message will be written to this
183 * @return pldm_completion_codes
184 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
185 */
186int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
187 uint32_t next_transfer_handle,
188 uint8_t transfer_flag, const uint8_t *table_data,
189 size_t table_size, struct pldm_msg *msg);
190
vkaverap2ffe3292019-06-24 00:08:13 -0500191/** @struct pldm_read_file_req
192 *
193 * Structure representing ReadFile request
194 */
195struct pldm_read_file_req {
196 uint32_t file_handle; //!< Handle to file
197 uint32_t offset; //!< Offset to file where read starts
198 uint32_t length; //!< Bytes to be read
199} __attribute__((packed));
200
201/** @struct pldm_read_file_resp
202 *
203 * Structure representing ReadFile response data
204 */
205struct pldm_read_file_resp {
206 uint8_t completion_code; //!< Completion code
207 uint32_t length; //!< Number of bytes read
208 uint8_t file_data[1]; //!< Address of this is where file data starts
209} __attribute__((packed));
210
211/** @struct pldm_write_file_req
212 *
213 * Structure representing WriteFile request
214 */
215struct pldm_write_file_req {
216 uint32_t file_handle; //!< Handle to file
217 uint32_t offset; //!< Offset to file where write starts
218 uint32_t length; //!< Bytes to be written
219 uint8_t file_data[1]; //!< Address of this is where file data starts
220} __attribute__((packed));
221
222/** @struct pldm_write_file_resp
223 *
224 * Structure representing WriteFile response data
225 */
226struct pldm_write_file_resp {
227 uint8_t completion_code; //!< Completion code
228 uint32_t length; //!< Bytes written
229} __attribute__((packed));
230
231/** @brief Decode Read File commands request
232 *
233 * @param[in] msg - PLDM request message payload
234 * @param[in] payload_length - Length of request payload
235 * @param[out] file_handle - A handle to the file
236 * @param[out] offset - Offset to the file at which the read should begin
237 * @param[out] length - Number of bytes read
238 * @return pldm_completion_codes
239 */
240int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
241 uint32_t *file_handle, uint32_t *offset,
242 uint32_t *length);
243
244/** @brief Encode Read File commands request
245 *
246 * @param[in] instance_id - Message's instance id
247 * @param[in] file_handle - A handle to the file
248 * @param[in] offset - Offset to the file at which the read should begin
249 * @param[in] length - Number of bytes read
250 * @param[in,out] msg - Message will be written to this
251 * @return pldm_completion_codes
252 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
253 */
254int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
255 uint32_t offset, uint32_t length,
256 struct pldm_msg *msg);
257
258/** @brief Decode Read File commands response
259 *
260 * @param[in] msg - PLDM response message payload
261 * @param[in] payload_length - Length of request payload
262 * @param[out] completion_code - PLDM completion code
263 * @param[out] length - Number of bytes read. This could be less than what the
264 * requester asked for.
265 * @param[out] file_data_offset - Offset where file data should be read in pldm
266 * msg.
267 * @return pldm_completion_codes
268 */
269int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
270 uint8_t *completion_code, uint32_t *length,
271 size_t *file_data_offset);
272
273/** @brief Create a PLDM response for Read File
274 *
275 * @param[in] instance_id - Message's instance id
276 * @param[in] completion_code - PLDM completion code
277 * @param[in] length - Number of bytes read. This could be less than what the
278 * requester asked for.
279 * @param[in,out] msg - Message will be written to this
280 * @return pldm_completion_codes
281 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
282 * Although read file command response includes file data, this function
283 * does not encode the file data to prevent additional copying of the data.
284 * The position of file data is calculated by caller from address and size
285 * of other input arguments.
286 */
287int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
288 uint32_t length, struct pldm_msg *msg);
289
290/** @brief Decode Write File commands request
291 *
292 * @param[in] msg - PLDM request message payload
293 * @param[in] payload_length - Length of request payload
294 * @param[out] file_handle - A handle to the file
295 * @param[out] offset - Offset to the file at which the write should begin
296 * @param[out] length - Number of bytes to write
297 * @param[out] file_data_offset - Offset where file data write begins in pldm
298 * msg.
299 * @return pldm_completion_codes
300 */
301int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
302 uint32_t *file_handle, uint32_t *offset,
303 uint32_t *length, size_t *file_data_offset);
304
305/** @brief Create a PLDM request for Write File
306 *
307 * @param[in] instance_id - Message's instance id
308 * @param[in] file_handle - A handle to the file
309 * @param[in] offset - Offset to the file at which the read should begin
310 * @param[in] length - Number of bytes written. This could be less than what
311 * the requester asked for.
312 * @param[in,out] msg - Message will be written to this
313 * @return pldm_completion_codes
314 * @note Caller is responsible for memory alloc and dealloc of param 'msg'.
315 * Although write file command request includes file data, this function
316 * does not encode the file data to prevent additional copying of the data.
317 * The position of file data is calculated by caller from address and size
318 * of other input arguments.
319 */
320int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
321 uint32_t offset, uint32_t length,
322 struct pldm_msg *msg);
323
324/** @brief Decode Write File commands response
325 *
326 * @param[in] msg - PLDM request message payload
327 * @param[in] payload_length - Length of request payload
328 * @param[out] completion_code - PLDM completion code
329 * @param[out] length - Number of bytes written
330 * @return pldm_completion_codes
331 */
332int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
333 uint8_t *completion_code, uint32_t *length);
334
335/** @brief Create a PLDM response for Write File
336 *
337 * @param[in] instance_id - Message's instance id
338 * @param[in] completion_code - PLDM completion code
339 * @param[in] length - Number of bytes written. This could be less than what
340 * the requester asked for.
341 * @param[in,out] msg - Message will be written to this
342 * @return pldm_completion_codes
343 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
344 */
345int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
346 uint32_t length, struct pldm_msg *msg);
347
vkaverap07404562019-08-05 22:57:11 -0500348/** @struct pldm_read_write_file_by_type_memory_req
349 *
350 * Structure representing ReadFileByTypeIntoMemory and
351 * WriteFileByTypeFromMemory request
352 */
353struct pldm_read_write_file_by_type_memory_req {
354 uint16_t file_type; //!< Type of file
355 uint32_t file_handle; //!< Handle to file
356 uint32_t offset; //!< Offset to file where read starts
357 uint32_t length; //!< Bytes to be read
358 uint64_t address; //!< Memory address of the file
359} __attribute__((packed));
360
361/** @struct pldm_read_write_file_by_type_memory_resp
362 *
363 * Structure representing ReadFileByTypeIntoMemory and
364 * WriteFileByTypeFromMemory response
365 */
366struct pldm_read_write_file_by_type_memory_resp {
367 uint8_t completion_code; //!< Completion code
368 uint32_t length; //!< Number of bytes read
369} __attribute__((packed));
370
371/** @brief Decode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
372 * commands request data
373 *
374 * @param[in] msg - Pointer to PLDM request message
375 * @param[in] payload_length - Length of request payload
376 * @param[in] file_type - Type of the file
377 * @param[out] file_handle - A handle to the file
378 * @param[out] offset - Offset to the file at which the read should begin
379 * @param[out] length - Number of bytes to be read
380 * @param[out] address - Memory address of the file content
381 * @return pldm_completion_codes
382 */
383int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
384 size_t payload_length,
385 uint16_t *file_type,
386 uint32_t *file_handle, uint32_t *offset,
387 uint32_t *length, uint64_t *address);
388
389/** @brief Create a PLDM response for ReadFileByTypeIntoMemory and
390 * WriteFileByTypeFromMemory
391 *
392 * @param[in] instance_id - Message's instance id
393 * @param[in] command - PLDM command
394 * @param[in] completion_code - PLDM completion code
395 * @param[in] length - Number of bytes read. This could be less than what the
396 * requester asked for.
397 * @param[in,out] msg - Message will be written to this
398 * @return pldm_completion_codes
399 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
400 */
401int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
402 uint8_t completion_code, uint32_t length,
403 struct pldm_msg *msg);
404
405/** @brief Encode ReadFileByTypeIntoMemory and WriteFileByTypeFromMemory
406 * commands request data
407 *
408 * @param[in] instance_id - Message's instance id
409 * @param[in] command - PLDM command
410 * @param[in] file_type - Type of the file
411 * @param[in] file_handle - A handle to the file
412 * @param[in] offset - Offset to the file at which the read should begin
413 * @param[in] length - Number of bytes to be read/written
414 * @param[in] address - Memory address where the file content has to be
415 * written to
416 * @param[out] msg - Message will be written to this
417 * @return pldm_completion_codes
418 */
419int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
420 uint16_t file_type, uint32_t file_handle,
421 uint32_t offset, uint32_t length,
422 uint64_t address, struct pldm_msg *msg);
423
424/** @brief Decode ReadFileTypeIntoMemory and WriteFileTypeFromMemory
425 * commands response data
426 *
427 * @param[in] msg - pointer to PLDM response message
428 * @param[in] payload_length - Length of response payload
429 * @param[out] completion_code - PLDM completion code
430 * @param[out] length - Number of bytes to be read/written
431 * @return pldm_completion_codes
432 */
433int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
434 size_t payload_length,
435 uint8_t *completion_code,
436 uint32_t *length);
437
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530438#ifdef __cplusplus
439}
440#endif
441
442#endif /* FILEIO_H */