1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #ifndef LIBPLDM_OEM_META_FILE_IO_H
3 #define LIBPLDM_OEM_META_FILE_IO_H
4 
5 #include <libpldm/compiler.h>
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 struct pldm_msg;
15 /** @brief PLDM Commands in OEM META type
16  */
17 
18 enum pldm_oem_meta_file_io_commands {
19 	PLDM_OEM_META_FILE_IO_CMD_WRITE_FILE = 0x2,
20 	PLDM_OEM_META_FILE_IO_CMD_READ_FILE = 0x3,
21 };
22 
23 /** @brief read options in read file io command
24  */
25 enum pldm_oem_meta_file_io_read_option {
26 	// Read file attribute
27 	PLDM_OEM_META_FILE_IO_READ_ATTR = 0x00,
28 	// Read file data
29 	PLDM_OEM_META_FILE_IO_READ_DATA = 0x01,
30 };
31 
32 struct pldm_oem_meta_file_io_write_req {
33 	uint8_t handle;
34 	uint32_t length;
35 #ifndef __cplusplus
36 	uint8_t data[] LIBPLDM_CC_COUNTED_BY(length);
37 #endif
38 };
39 #define PLDM_OEM_META_FILE_IO_WRITE_REQ_MIN_LENGTH 5u
40 
41 /** @struct pldm_oem_meta_file_io_read_data_info
42  *
43  *  Structure representing PLDM read file data info
44  */
45 struct pldm_oem_meta_file_io_read_data_info {
46 	uint8_t transferFlag;
47 	uint16_t offset;
48 };
49 #define PLDM_OEM_META_FILE_IO_READ_DATA_INFO_LENGTH 3u
50 
51 /** @struct pldm_oem_meta_file_io_read_attr_info
52  *
53  *  Structure representing PLDM read file attribute info
54  */
55 struct pldm_oem_meta_file_io_read_attr_info {
56 	uint16_t size;
57 	uint32_t crc32;
58 };
59 #define PLDM_OEM_META_FILE_IO_READ_ATTR_INFO_LENGTH 6u
60 
61 /** @struct pldm_oem_meta_file_io_read_req
62  *
63  *  Structure representing PLDM read file request
64  */
65 struct pldm_oem_meta_file_io_read_req {
66 	size_t version;
67 	uint8_t handle;
68 	uint8_t option;
69 	uint8_t length;
70 	union {
71 		struct pldm_oem_meta_file_io_read_data_info data;
72 	} info;
73 };
74 #define PLDM_OEM_META_FILE_IO_READ_REQ_MIN_LENGTH 3u
75 
76 /** @struct pldm_oem_meta_file_io_read_resp
77  *
78  *  Structure representing PLDM read file response
79  */
80 struct pldm_oem_meta_file_io_read_resp {
81 	size_t version;
82 	uint8_t completion_code;
83 	uint8_t handle;
84 	uint8_t option;
85 	uint8_t length;
86 	union {
87 		struct pldm_oem_meta_file_io_read_attr_info attr;
88 		struct pldm_oem_meta_file_io_read_data_info data;
89 	} info;
90 #ifndef __cplusplus
91 	uint8_t data[] LIBPLDM_CC_COUNTED_BY(length);
92 #endif
93 };
94 #define PLDM_OEM_META_FILE_IO_READ_RESP_MIN_SIZE 4u
95 
96 /** @brief Obtain the pointer to the data array of a write request
97  *
98  * @param[in] req - The pointer to the write request struct
99  *
100  * @return The write request data pointer.
101  */
102 void *pldm_oem_meta_file_io_write_req_data(
103 	struct pldm_oem_meta_file_io_write_req *req);
104 
105 /** @brief Decode OEM meta write file io req
106  *
107  *  @param[in] msg - Pointer to PLDM request message
108  *  @param[in] payload_length - Length of request payload
109  *  @param[out] req - Pointer to the structure to store the decoded response data
110  *  @param[in] req_length - Length of request structure
111  *  @return 0 on success, negative errno value on failure
112  */
113 int decode_oem_meta_file_io_write_req(
114 	const struct pldm_msg *msg, size_t payload_length,
115 	struct pldm_oem_meta_file_io_write_req *req, size_t req_length);
116 
117 /** @brief Deprecated decoder for OEM meta write file io req
118  *
119  *  @param[in] msg - Pointer to PLDM request message
120  *  @param[in] payload_length - Length of request payload
121  *  @param[out] file_handle - The handle of data
122  *  @param[out] length - Total size of data
123  *  @param[out] data - Message will be written to this
124  *  @return pldm_completion_codes
125  */
126 int decode_oem_meta_file_io_req(const struct pldm_msg *msg,
127 				size_t payload_length, uint8_t *file_handle,
128 				uint32_t *length, uint8_t *data);
129 
130 /** @brief Decode OEM meta read file io req
131  *
132  *  @param[in] msg - Pointer to PLDM request message
133  *  @param[in] payload_length - Length of request payload
134  *  @param[out] req - Pointer to the structure to store the decoded response data
135  *  @return 0 on success, negative errno value on failure
136  */
137 int decode_oem_meta_file_io_read_req(const struct pldm_msg *msg,
138 				     size_t payload_length,
139 				     struct pldm_oem_meta_file_io_read_req *req);
140 
141 /** @brief Obtain the pointer to the data array of a read response
142  *
143  * @param[in] resp - The pointer to the read response struct
144  *
145  * @return The read response data pointer.
146  */
147 void *pldm_oem_meta_file_io_read_resp_data(
148 	struct pldm_oem_meta_file_io_read_resp *resp);
149 
150 /**
151  * @brief Encode OEM meta read file io resp
152  *
153  * @param[in] instance_id - The instance ID of the PLDM entity
154  * @param[out] resp - Pointer to the reqponse message
155  * @param[in] resp_len - Length of response message
156  * @param[out] responseMsg - Pointer to the buffer to store the response data
157  * @param[in] payload_length - Length of response payload
158  * @return 0 on success, negative errno value on failure
159  */
160 int encode_oem_meta_file_io_read_resp(
161 	uint8_t instance_id, struct pldm_oem_meta_file_io_read_resp *resp,
162 	size_t resp_len, struct pldm_msg *responseMsg, size_t payload_length);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif /*LIBPLDM_OEM_META_FILE_IO_H*/
169