blob: 6354f8154b7d53433ba57a6d7cdb11ded1926d0c [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
Eddie James3b02e272019-04-22 20:13:55 +000046/** @brief Decode ReadFileIntoMemory and WriteFileFromMemory commands request
47 * data
Tom Joseph7dae7772019-04-10 14:44:44 +053048 *
49 * @param[in] msg - Pointer to PLDM request message payload
50 * @param[in] payload_length - Length of request payload
51 * @param[out] file_handle - A handle to the file
52 * @param[out] offset - Offset to the file at which the read should begin
53 * @param[out] length - Number of bytes to be read
54 * @param[out] address - Memory address where the file content has to be
55 * written to
56 * @return pldm_completion_codes
57 */
Eddie James3b02e272019-04-22 20:13:55 +000058int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length,
59 uint32_t *file_handle, uint32_t *offset,
60 uint32_t *length, uint64_t *address);
Tom Joseph7dae7772019-04-10 14:44:44 +053061
Eddie James3b02e272019-04-22 20:13:55 +000062/** @brief Create a PLDM response for ReadFileIntoMemory and
63 * WriteFileFromMemory
Tom Joseph7dae7772019-04-10 14:44:44 +053064 *
65 * @param[in] instance_id - Message's instance id
Eddie James3b02e272019-04-22 20:13:55 +000066 * @param[in] command - PLDM command
Tom Joseph7dae7772019-04-10 14:44:44 +053067 * @param[in] completion_code - PLDM completion code
68 * @param[in] length - Number of bytes read. This could be less than what the
69 requester asked for.
70 * @param[in,out] msg - Message will be written to this
71 * @return pldm_completion_codes
72 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
73 */
Eddie James3b02e272019-04-22 20:13:55 +000074int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
75 uint8_t completion_code, uint32_t length,
76 struct pldm_msg *msg);
Tom Joseph7dae7772019-04-10 14:44:44 +053077
Tom Joseph61325fa2019-06-04 15:22:22 +053078/** @struct pldm_get_file_table_req
79 *
80 * Structure representing GetFileTable request
81 */
82struct pldm_get_file_table_req {
83 uint32_t transfer_handle; //!< Data transfer handle
84 uint8_t operation_flag; //!< Transfer operation flag
85 uint8_t table_type; //!< Table type
86} __attribute__((packed));
87
88/** @struct pldm_get_file_table_resp
89 *
90 * Structure representing GetFileTable response fixed data
91 */
92struct pldm_get_file_table_resp {
93 uint8_t completion_code; //!< Completion code
94 uint32_t next_transfer_handle; //!< Next data transfer handle
95 uint8_t transfer_flag; //!< Transfer flag
96 uint8_t table_data[1]; //!< Table Data
97} __attribute__((packed));
98
99/** @brief Decode GetFileTable command request data
100 *
101 * @param[in] msg - Pointer to PLDM request message payload
102 * @param[in] payload_length - Length of request payload
103 * @param[out] trasnfer_handle - the handle of data
104 * @param[out] transfer_opflag - Transfer operation flag
105 * @param[out] table_type - the type of file table
106 * @return pldm_completion_codes
107 */
108int decode_get_file_table_req(const uint8_t *msg, size_t payload_length,
109 uint32_t *transfer_handle,
110 uint8_t *transfer_opflag, uint8_t *table_type);
111
112/** @brief Create a PLDM response for GetFileTable command
113 *
114 * @param[in] instance_id - Message's instance id
115 * @param[in] completion_code - PLDM completion code
116 * @param[in] next_transfer_handle - Handle to identify next portion of
117 * data transfer
118 * @param[in] transfer_flag - Represents the part of transfer
119 * @param[in] table_data - pointer to file table data
120 * @param[in] table_size - file table size
121 * @param[in,out] msg - Message will be written to this
122 * @return pldm_completion_codes
123 * @note Caller is responsible for memory alloc and dealloc of param 'msg'
124 */
125int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
126 uint32_t next_transfer_handle,
127 uint8_t transfer_flag, const uint8_t *table_data,
128 size_t table_size, struct pldm_msg *msg);
129
Tom Joseph7dae7772019-04-10 14:44:44 +0530130#ifdef __cplusplus
131}
132#endif
133
134#endif /* FILEIO_H */