1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 2 #ifndef LIBPLDM_FILE_H 3 #define LIBPLDM_FILE_H 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 #include <libpldm/pldm_types.h> 10 11 #include <asm/byteorder.h> 12 #include <stddef.h> 13 #include <stdint.h> 14 15 #define PLDM_DF_OPEN_REQ_BYTES 4ul 16 #define PLDM_DF_OPEN_RESP_BYTES 3ul 17 #define PLDM_DF_CLOSE_REQ_BYTES 4ul 18 #define PLDM_DF_CLOSE_RESP_BYTES 1ul 19 #define PLDM_DF_HEARTBEAT_REQ_BYTES 6ul 20 #define PLDM_DF_HEARTBEAT_RESP_BYTES 5ul 21 22 /** @brief PLDM File Transfer Completion Code */ 23 enum pldm_file_cc { 24 PLDM_FILE_CC_INVALID_FILE_DESCRIPTOR = 0x80, 25 PLDM_FILE_CC_INVALID_DF_ATTRIBUTE = 0x81, 26 PLDM_FILE_CC_ZEROLENGTH_NOT_ALLOWED = 0x82, 27 PLDM_FILE_CC_EXCLUSIVE_OWNERSHIP_NOT_ESTABLISHED = 0x83, 28 PLDM_FILE_CC_EXCLUSIVE_OWNERSHIP_NOT_ALLOWED = 0x84, 29 PLDM_FILE_CC_EXCLUSIVE_OWNERSHIP_NOT_AVAILABLE = 0x85, 30 PLDM_FILE_CC_INVALID_FILE_IDENTIFIER = 0x86, 31 PLDM_FILE_CC_DFOPEN_DIR_NOT_ALLOWED = 0x87, 32 PLDM_FILE_CC_MAX_NUM_FDS_EXCEEDED = 0x88, 33 PLDM_FILE_CC_FILE_OPEN = 0x89, 34 PLDM_FILE_CC_UNABLE_TO_OPEN_FILE = 0x8A, 35 }; 36 37 /** @brief PLDM File Transfer Command */ 38 enum pldm_file_cmd { 39 PLDM_FILE_CMD_DF_OPEN = 0x01, 40 PLDM_FILE_CMD_DF_CLOSE = 0x02, 41 PLDM_FILE_CMD_DF_HEARTBEAT = 0x03, 42 PLDM_FILE_CMD_DF_PROPERTIES = 0x10, 43 PLDM_FILE_CMD_DF_GET_FILE_ATTRIBUTE = 0x11, 44 PLDM_FILE_CMD_DF_SET_FILE_ATTRIBUTE = 0x12, 45 PLDM_FILE_CMD_DF_READ = 0x20, 46 PLDM_FILE_CMD_DF_FIFO_SEND = 0x21, 47 }; 48 49 /** @struct pldm_file_df_open_req 50 * 51 * Structure representing PLDM File DfOpen request. 52 */ 53 struct pldm_file_df_open_req { 54 uint16_t file_identifier; 55 bitfield16_t file_attribute; 56 }; 57 58 /** @struct pldm_file_df_open_resp 59 * 60 * Structure representing PLDM File DfOpen response. 61 */ 62 struct pldm_file_df_open_resp { 63 uint8_t completion_code; 64 uint16_t file_descriptor; 65 }; 66 67 /** @struct pldm_file_df_close_req 68 * 69 * Structure representing PLDM File DfClose request. 70 */ 71 struct pldm_file_df_close_req { 72 uint16_t file_descriptor; 73 bitfield16_t df_close_options; 74 }; 75 76 /** @struct pldm_file_df_close_resp 77 * 78 * Structure representing PLDM File DfClose response. 79 */ 80 struct pldm_file_df_close_resp { 81 uint8_t completion_code; 82 }; 83 84 /** @struct pldm_file_df_heartbeat_req 85 * 86 * Structure representing PLDM File DfHeartbeat request. 87 */ 88 struct pldm_file_df_heartbeat_req { 89 uint16_t file_descriptor; 90 uint32_t requester_max_interval; 91 }; 92 93 /** @struct pldm_file_df_heartbeat_resp 94 * 95 * Structure representing PLDM File DfHearbeat response. 96 */ 97 struct pldm_file_df_heartbeat_resp { 98 uint8_t completion_code; 99 uint32_t responder_max_interval; 100 }; 101 102 /** @brief Create a PLDM request message for DFOpen 103 * 104 * @param[in] instance_id - Message's instance id 105 * @param[in] req - The pointer to the request message to be encoded 106 * @param[in,out] msg - Message will be written to this 107 * @param[in, out] payload_length - Length of the request message payload 108 * @return 0 on success 109 * -EINVAL if the input parameters' memory are not allocated, 110 * or message type or instance in request header is invalid 111 * -ENOMSG if the PLDM type in the request header is invalid 112 * -EOVERFLOW if the input message length is invalid 113 * @note Caller is responsible for memory alloc and dealloc of param 114 * 'msg.payload' 115 */ 116 int encode_pldm_file_df_open_req(uint8_t instance_id, 117 const struct pldm_file_df_open_req *req, 118 struct pldm_msg *msg, size_t *payload_length); 119 120 /** @brief Decode DFOpen request data 121 * 122 * @param[in] msg - Response message 123 * @param[in] payload_length - Length of response message payload 124 * @param[out] req - Pointer to the decoded request message 125 * @return 0 on success 126 * -EINVAL if argument values are invalid for the invocation 127 * -EOVERFLOW if the input message buffer is too short for the output 128 * response struct 129 * -EBADMSG if the input message buffer is too large for the output 130 * response struct. 131 */ 132 int decode_pldm_file_df_open_req(const struct pldm_msg *msg, 133 size_t payload_length, 134 struct pldm_file_df_open_req *req); 135 136 /** @brief Create a PLDM response message for DFOpen 137 * 138 * @param[in] instance_id - Message's instance id 139 * @param[in] resp - The pointer to the response message to be encoded 140 * @param[in,out] msg - Message will be written to this 141 * @param[in, out] payload_length - Length of the request message payload 142 * @return 0 on success 143 * -EINVAL if argument values are invalid for the invocation 144 * -ENOMSG if the PLDM type in the request header is invalid 145 * -EOVERFLOW if the input message length is invalid 146 * @note Caller is responsible for memory alloc and dealloc of param 147 * 'msg.payload' 148 */ 149 int encode_pldm_file_df_open_resp(uint8_t instance_id, 150 const struct pldm_file_df_open_resp *resp, 151 struct pldm_msg *msg, size_t *payload_length); 152 153 /** @brief Decode DFOpen response data 154 * 155 * @param[in] msg - Response message 156 * @param[in] payload_length - Length of response message payload 157 * @param[out] resp - pointer to the decoded response message 158 * @return 0 on success 159 * -EINVAL if the input parameters' memory are not allocated 160 * -EOVERFLOW if the input message buffer is too short for the output 161 * response struct 162 * -EBADMSG if the input message buffer is too large for the output 163 * response struct. 164 */ 165 int decode_pldm_file_df_open_resp(const struct pldm_msg *msg, 166 size_t payload_length, 167 struct pldm_file_df_open_resp *resp); 168 169 /** @brief Create a PLDM request message for DFClose 170 * 171 * @param[in] instance_id - Message's instance id 172 * @param[in] req - The pointer to the request message to be encoded 173 * @param[in,out] msg - Message will be written to this 174 * @param[in, out] payload_length - Length of the request message payload 175 * @return 0 on success 176 * -EINVAL if the input parameters' memory are not allocated, 177 * or message type or instance in request header is invalid 178 * -ENOMSG if the PLDM type in the request header is invalid 179 * -EOVERFLOW if the input message length is invalid 180 * @note Caller is responsible for memory alloc and dealloc of param 181 * 'msg.payload' 182 */ 183 int encode_pldm_file_df_close_req(uint8_t instance_id, 184 const struct pldm_file_df_close_req *req, 185 struct pldm_msg *msg, size_t *payload_length); 186 187 /** @brief Decode DFClose request data 188 * 189 * @param[in] msg - Response message 190 * @param[in] payload_length - Length of response message payload 191 * @param[out] req - pointer to the decoded request message 192 * @return 0 on success 193 * -EINVAL if argument values are invalid for the invocation 194 * -EOVERFLOW if the input message buffer is too short for the output 195 * response struct 196 * -EBADMSG if the input message buffer is too large for the output 197 * response struct. 198 */ 199 int decode_pldm_file_df_close_req(const struct pldm_msg *msg, 200 size_t payload_length, 201 struct pldm_file_df_close_req *req); 202 203 /** @brief Create a PLDM response message for DFClose 204 * 205 * @param[in] instance_id - Message's instance id 206 * @param[in] resp - The pointer to the response message to be encoded 207 * @param[in,out] msg - Message will be written to this 208 * @param[in,out] payload_length - Length of the request message payload 209 * @return 0 on success 210 * -EINVAL if argument values are invalid for the invocation 211 * -ENOMSG if the PLDM type in the request header is invalid 212 * -EOVERFLOW if the input message length is invalid 213 * @note Caller is responsible for memory alloc and dealloc of param 214 * 'msg.payload' 215 */ 216 int encode_pldm_file_df_close_resp(uint8_t instance_id, 217 const struct pldm_file_df_close_resp *resp, 218 struct pldm_msg *msg, 219 size_t *payload_length); 220 221 /** @brief Decode DFClose response data 222 * 223 * @param[in] msg - Response message 224 * @param[in] payload_length - Length of response message payload 225 * @param[out] resp - pointer to the decoded response message 226 * @return 0 on success 227 * -EINVAL if the input parameters' memory are not allocated 228 */ 229 int decode_pldm_file_df_close_resp(const struct pldm_msg *msg, 230 size_t payload_length, 231 struct pldm_file_df_close_resp *resp); 232 233 /** @brief Create a PLDM request message for DFHeartbeat 234 * 235 * @param[in] instance_id - Message's instance id 236 * @param[in] req - The pointer to the request message to be encoded 237 * @param[in,out] msg - Message will be written to this 238 * @param[in, out] payload_length - Length of the request message payload 239 * @return 0 on success 240 * -EINVAL if the input parameters' memory are not allocated, 241 * or message type or instance in request header is invalid 242 * -ENOMSG if the PLDM type in the request header is invalid 243 * -EOVERFLOW if the input message length is invalid 244 * @note Caller is responsible for memory alloc and dealloc of param 245 * 'msg.payload' 246 */ 247 int encode_pldm_file_df_heartbeat_req( 248 uint8_t instance_id, const struct pldm_file_df_heartbeat_req *req, 249 struct pldm_msg *msg, size_t *payload_length); 250 251 /** @brief Decode DFHeartbeat response data 252 * 253 * @param[in] msg - Response message 254 * @param[in] payload_length - Length of response message payload 255 * @param[out] resp - pointer to the decoded response message 256 * @return 0 on success 257 * -EINVAL if the input parameters' memory are not allocated 258 * -EOVERFLOW if the input message buffer is too short for the output 259 * response struct 260 * -EBADMSG if the input message buffer is too large for the output 261 * response struct 262 */ 263 int decode_pldm_file_df_heartbeat_resp(const struct pldm_msg *msg, 264 size_t payload_length, 265 struct pldm_file_df_heartbeat_resp *resp); 266 267 #ifdef __cplusplus 268 } 269 #endif 270 271 #endif 272