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