Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame^] | 2 | #include <libpldm/base.h> |
| 3 | #include <libpldm/oem/ibm/libpldm/file_io.h> |
| 4 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <endian.h> |
| 6 | #include <string.h> |
| 7 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 8 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 9 | int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length, |
| 10 | uint32_t *file_handle, uint32_t *offset, |
| 11 | uint32_t *length, uint64_t *address) |
| 12 | { |
| 13 | if (msg == NULL || file_handle == NULL || offset == NULL || |
| 14 | length == NULL || address == NULL) { |
| 15 | return PLDM_ERROR_INVALID_DATA; |
| 16 | } |
| 17 | |
| 18 | if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) { |
| 19 | return PLDM_ERROR_INVALID_LENGTH; |
| 20 | } |
| 21 | |
| 22 | struct pldm_read_write_file_memory_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 23 | (struct pldm_read_write_file_memory_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 24 | |
| 25 | *file_handle = le32toh(request->file_handle); |
| 26 | *offset = le32toh(request->offset); |
| 27 | *length = le32toh(request->length); |
| 28 | *address = le64toh(request->address); |
| 29 | |
| 30 | return PLDM_SUCCESS; |
| 31 | } |
| 32 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 33 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 34 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 35 | uint8_t completion_code, uint32_t length, |
| 36 | struct pldm_msg *msg) |
| 37 | { |
| 38 | if (msg == NULL) { |
| 39 | return PLDM_ERROR_INVALID_LENGTH; |
| 40 | } |
| 41 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 42 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 43 | header.msg_type = PLDM_RESPONSE; |
| 44 | header.instance = instance_id; |
| 45 | header.pldm_type = PLDM_OEM; |
| 46 | header.command = command; |
| 47 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 48 | if (rc != PLDM_SUCCESS) { |
| 49 | return rc; |
| 50 | } |
| 51 | |
| 52 | struct pldm_read_write_file_memory_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 53 | (struct pldm_read_write_file_memory_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 54 | response->completion_code = completion_code; |
| 55 | if (response->completion_code == PLDM_SUCCESS) { |
| 56 | response->length = htole32(length); |
| 57 | } |
| 58 | |
| 59 | return PLDM_SUCCESS; |
| 60 | } |
| 61 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 62 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 63 | int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command, |
| 64 | uint32_t file_handle, uint32_t offset, |
| 65 | uint32_t length, uint64_t address, |
| 66 | struct pldm_msg *msg) |
| 67 | { |
| 68 | if (msg == NULL) { |
| 69 | return PLDM_ERROR_INVALID_DATA; |
| 70 | } |
| 71 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 72 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 73 | header.msg_type = PLDM_REQUEST; |
| 74 | header.instance = instance_id; |
| 75 | header.pldm_type = PLDM_OEM; |
| 76 | header.command = command; |
| 77 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 78 | if (rc != PLDM_SUCCESS) { |
| 79 | return rc; |
| 80 | } |
| 81 | |
| 82 | struct pldm_read_write_file_memory_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 83 | (struct pldm_read_write_file_memory_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 84 | req->file_handle = htole32(file_handle); |
| 85 | req->offset = htole32(offset); |
| 86 | req->length = htole32(length); |
| 87 | req->address = htole64(address); |
| 88 | return PLDM_SUCCESS; |
| 89 | } |
| 90 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 91 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 92 | int decode_rw_file_memory_resp(const struct pldm_msg *msg, |
| 93 | size_t payload_length, uint8_t *completion_code, |
| 94 | uint32_t *length) |
| 95 | { |
| 96 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 97 | return PLDM_ERROR_INVALID_DATA; |
| 98 | } |
| 99 | |
| 100 | if (payload_length != PLDM_RW_FILE_MEM_RESP_BYTES) { |
| 101 | return PLDM_ERROR_INVALID_LENGTH; |
| 102 | } |
| 103 | |
| 104 | struct pldm_read_write_file_memory_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 105 | (struct pldm_read_write_file_memory_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 106 | *completion_code = response->completion_code; |
| 107 | if (*completion_code == PLDM_SUCCESS) { |
| 108 | *length = le32toh(response->length); |
| 109 | } |
| 110 | |
| 111 | return PLDM_SUCCESS; |
| 112 | } |
| 113 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 114 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 115 | int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length, |
| 116 | uint32_t *transfer_handle, |
| 117 | uint8_t *transfer_opflag, uint8_t *table_type) |
| 118 | { |
| 119 | if (msg == NULL || transfer_handle == NULL || transfer_opflag == NULL || |
| 120 | table_type == NULL) { |
| 121 | return PLDM_ERROR_INVALID_DATA; |
| 122 | } |
| 123 | |
| 124 | if (payload_length != PLDM_GET_FILE_TABLE_REQ_BYTES) { |
| 125 | return PLDM_ERROR_INVALID_LENGTH; |
| 126 | } |
| 127 | |
| 128 | struct pldm_get_file_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 129 | (struct pldm_get_file_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 130 | |
| 131 | *transfer_handle = le32toh(request->transfer_handle); |
| 132 | *transfer_opflag = request->operation_flag; |
| 133 | *table_type = request->table_type; |
| 134 | |
| 135 | return PLDM_SUCCESS; |
| 136 | } |
| 137 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 138 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 139 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 140 | uint32_t next_transfer_handle, |
| 141 | uint8_t transfer_flag, const uint8_t *table_data, |
| 142 | size_t table_size, struct pldm_msg *msg) |
| 143 | { |
| 144 | if (msg == NULL) { |
| 145 | return PLDM_ERROR_INVALID_LENGTH; |
| 146 | } |
| 147 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 148 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 149 | header.msg_type = PLDM_RESPONSE; |
| 150 | header.instance = instance_id; |
| 151 | header.pldm_type = PLDM_OEM; |
| 152 | header.command = PLDM_GET_FILE_TABLE; |
| 153 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 154 | if (rc != PLDM_SUCCESS) { |
| 155 | return rc; |
| 156 | } |
| 157 | |
| 158 | struct pldm_get_file_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 159 | (struct pldm_get_file_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 160 | response->completion_code = completion_code; |
| 161 | |
| 162 | if (completion_code == PLDM_SUCCESS) { |
| 163 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 164 | response->transfer_flag = transfer_flag; |
| 165 | memcpy(response->table_data, table_data, table_size); |
| 166 | } |
| 167 | |
| 168 | return PLDM_SUCCESS; |
| 169 | } |
| 170 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 171 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 172 | int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle, |
| 173 | uint8_t transfer_opflag, uint8_t table_type, |
| 174 | struct pldm_msg *msg) |
| 175 | { |
| 176 | if (msg == NULL) { |
| 177 | return PLDM_ERROR_INVALID_DATA; |
| 178 | } |
| 179 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 180 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 181 | header.msg_type = PLDM_REQUEST; |
| 182 | header.instance = instance_id; |
| 183 | header.pldm_type = PLDM_OEM; |
| 184 | header.command = PLDM_GET_FILE_TABLE; |
| 185 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 186 | if (rc != PLDM_SUCCESS) { |
| 187 | return rc; |
| 188 | } |
| 189 | |
| 190 | struct pldm_get_file_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 191 | (struct pldm_get_file_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 192 | |
| 193 | request->transfer_handle = htole32(transfer_handle); |
| 194 | request->operation_flag = transfer_opflag; |
| 195 | request->table_type = table_type; |
| 196 | return PLDM_SUCCESS; |
| 197 | } |
| 198 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 199 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 200 | int decode_get_file_table_resp(const struct pldm_msg *msg, |
| 201 | size_t payload_length, uint8_t *completion_code, |
| 202 | uint32_t *next_transfer_handle, |
| 203 | uint8_t *transfer_flag, |
| 204 | uint8_t *file_table_data_start_offset, |
| 205 | size_t *file_table_length) |
| 206 | { |
| 207 | if (msg == NULL || transfer_flag == NULL || |
| 208 | next_transfer_handle == NULL || completion_code == NULL || |
| 209 | file_table_data_start_offset == NULL || file_table_length == NULL) { |
| 210 | return PLDM_ERROR_INVALID_DATA; |
| 211 | } |
| 212 | |
| 213 | if (payload_length <= PLDM_GET_FILE_TABLE_MIN_RESP_BYTES) { |
| 214 | return PLDM_ERROR_INVALID_LENGTH; |
| 215 | } |
| 216 | |
| 217 | *completion_code = msg->payload[0]; |
| 218 | |
| 219 | if (PLDM_SUCCESS != *completion_code) { |
| 220 | return PLDM_SUCCESS; |
| 221 | } |
| 222 | |
| 223 | struct pldm_get_file_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 224 | (struct pldm_get_file_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 225 | |
| 226 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 227 | *transfer_flag = response->transfer_flag; |
| 228 | *file_table_data_start_offset = sizeof(*completion_code) + |
| 229 | sizeof(*next_transfer_handle) + |
| 230 | sizeof(*transfer_flag); |
| 231 | *file_table_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 232 | payload_length - PLDM_GET_FILE_TABLE_MIN_RESP_BYTES; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 233 | |
| 234 | return PLDM_SUCCESS; |
| 235 | } |
| 236 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 237 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 238 | int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 239 | uint32_t *file_handle, uint32_t *offset, |
| 240 | uint32_t *length) |
| 241 | { |
| 242 | if (msg == NULL || file_handle == NULL || offset == NULL || |
| 243 | length == NULL) { |
| 244 | return PLDM_ERROR_INVALID_DATA; |
| 245 | } |
| 246 | |
| 247 | if (payload_length != PLDM_READ_FILE_REQ_BYTES) { |
| 248 | return PLDM_ERROR_INVALID_LENGTH; |
| 249 | } |
| 250 | |
| 251 | struct pldm_read_file_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 252 | (struct pldm_read_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 253 | |
| 254 | *file_handle = le32toh(request->file_handle); |
| 255 | *offset = le32toh(request->offset); |
| 256 | *length = le32toh(request->length); |
| 257 | |
| 258 | return PLDM_SUCCESS; |
| 259 | } |
| 260 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 261 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 262 | int encode_read_file_req(uint8_t instance_id, uint32_t file_handle, |
| 263 | uint32_t offset, uint32_t length, struct pldm_msg *msg) |
| 264 | { |
| 265 | if (msg == NULL) { |
| 266 | return PLDM_ERROR_INVALID_DATA; |
| 267 | } |
| 268 | |
| 269 | if (length == 0) { |
| 270 | return PLDM_ERROR_INVALID_LENGTH; |
| 271 | } |
| 272 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 273 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 274 | header.msg_type = PLDM_REQUEST; |
| 275 | header.instance = instance_id; |
| 276 | header.pldm_type = PLDM_OEM; |
| 277 | header.command = PLDM_READ_FILE; |
| 278 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 279 | if (rc != PLDM_SUCCESS) { |
| 280 | return rc; |
| 281 | } |
| 282 | |
| 283 | struct pldm_read_file_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 284 | (struct pldm_read_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 285 | |
| 286 | request->file_handle = htole32(file_handle); |
| 287 | request->offset = htole32(offset); |
| 288 | request->length = htole32(length); |
| 289 | |
| 290 | return PLDM_SUCCESS; |
| 291 | } |
| 292 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 293 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 294 | int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 295 | uint8_t *completion_code, uint32_t *length, |
| 296 | size_t *file_data_offset) |
| 297 | { |
| 298 | if (msg == NULL || completion_code == NULL || length == NULL) { |
| 299 | return PLDM_ERROR_INVALID_DATA; |
| 300 | } |
| 301 | |
| 302 | if (payload_length < PLDM_READ_FILE_RESP_BYTES) { |
| 303 | return PLDM_ERROR_INVALID_LENGTH; |
| 304 | } |
| 305 | |
| 306 | struct pldm_read_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 307 | (struct pldm_read_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 308 | |
| 309 | *completion_code = response->completion_code; |
| 310 | if (*completion_code == PLDM_SUCCESS) { |
| 311 | *length = le32toh(response->length); |
| 312 | if (payload_length != PLDM_READ_FILE_RESP_BYTES + *length) { |
| 313 | return PLDM_ERROR_INVALID_LENGTH; |
| 314 | } |
| 315 | *file_data_offset = sizeof(*completion_code) + sizeof(*length); |
| 316 | } |
| 317 | |
| 318 | return PLDM_SUCCESS; |
| 319 | } |
| 320 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 321 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 322 | int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 323 | uint32_t length, struct pldm_msg *msg) |
| 324 | { |
| 325 | if (msg == NULL) { |
| 326 | return PLDM_ERROR_INVALID_DATA; |
| 327 | } |
| 328 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 329 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 330 | header.msg_type = PLDM_RESPONSE; |
| 331 | header.instance = instance_id; |
| 332 | header.pldm_type = PLDM_OEM; |
| 333 | header.command = PLDM_READ_FILE; |
| 334 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 335 | if (rc != PLDM_SUCCESS) { |
| 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | struct pldm_read_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 340 | (struct pldm_read_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 341 | response->completion_code = completion_code; |
| 342 | |
| 343 | if (response->completion_code == PLDM_SUCCESS) { |
| 344 | response->length = htole32(length); |
| 345 | } |
| 346 | |
| 347 | return PLDM_SUCCESS; |
| 348 | } |
| 349 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 350 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 351 | int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 352 | uint32_t *file_handle, uint32_t *offset, |
| 353 | uint32_t *length, size_t *file_data_offset) |
| 354 | { |
| 355 | if (msg == NULL || file_handle == NULL || length == NULL) { |
| 356 | return PLDM_ERROR_INVALID_DATA; |
| 357 | } |
| 358 | |
| 359 | if (payload_length < PLDM_WRITE_FILE_REQ_BYTES) { |
| 360 | return PLDM_ERROR_INVALID_LENGTH; |
| 361 | } |
| 362 | |
| 363 | struct pldm_write_file_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 364 | (struct pldm_write_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 365 | |
| 366 | *file_handle = le32toh(request->file_handle); |
| 367 | *offset = le32toh(request->offset); |
| 368 | *length = le32toh(request->length); |
| 369 | if (payload_length != PLDM_WRITE_FILE_REQ_BYTES + *length) { |
| 370 | return PLDM_ERROR_INVALID_LENGTH; |
| 371 | } |
| 372 | *file_data_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 373 | sizeof(*file_handle) + sizeof(*offset) + sizeof(*length); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 374 | |
| 375 | return PLDM_SUCCESS; |
| 376 | } |
| 377 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 378 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 379 | int encode_write_file_req(uint8_t instance_id, uint32_t file_handle, |
| 380 | uint32_t offset, uint32_t length, |
| 381 | struct pldm_msg *msg) |
| 382 | { |
| 383 | if (msg == NULL) { |
| 384 | return PLDM_ERROR_INVALID_DATA; |
| 385 | } |
| 386 | |
| 387 | if (length == 0) { |
| 388 | return PLDM_ERROR_INVALID_LENGTH; |
| 389 | } |
| 390 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 391 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 392 | header.msg_type = PLDM_REQUEST; |
| 393 | header.instance = instance_id; |
| 394 | header.pldm_type = PLDM_OEM; |
| 395 | header.command = PLDM_WRITE_FILE; |
| 396 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 397 | if (rc != PLDM_SUCCESS) { |
| 398 | return rc; |
| 399 | } |
| 400 | |
| 401 | struct pldm_write_file_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 402 | (struct pldm_write_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 403 | |
| 404 | request->file_handle = htole32(file_handle); |
| 405 | request->offset = htole32(offset); |
| 406 | request->length = htole32(length); |
| 407 | |
| 408 | return PLDM_SUCCESS; |
| 409 | } |
| 410 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 411 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 412 | int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 413 | uint8_t *completion_code, uint32_t *length) |
| 414 | { |
| 415 | if (msg == NULL || completion_code == NULL || length == NULL) { |
| 416 | return PLDM_ERROR_INVALID_DATA; |
| 417 | } |
| 418 | |
| 419 | if (payload_length != PLDM_WRITE_FILE_RESP_BYTES) { |
| 420 | return PLDM_ERROR_INVALID_LENGTH; |
| 421 | } |
| 422 | |
| 423 | struct pldm_write_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 424 | (struct pldm_write_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 425 | |
| 426 | *completion_code = le32toh(response->completion_code); |
| 427 | if (response->completion_code == PLDM_SUCCESS) { |
| 428 | *length = le32toh(response->length); |
| 429 | } |
| 430 | |
| 431 | return PLDM_SUCCESS; |
| 432 | } |
| 433 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 434 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 435 | int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 436 | uint32_t length, struct pldm_msg *msg) |
| 437 | { |
| 438 | if (msg == NULL) { |
| 439 | return PLDM_ERROR_INVALID_DATA; |
| 440 | } |
| 441 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 442 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 443 | header.msg_type = PLDM_RESPONSE; |
| 444 | header.instance = instance_id; |
| 445 | header.pldm_type = PLDM_OEM; |
| 446 | header.command = PLDM_WRITE_FILE; |
| 447 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 448 | if (rc != PLDM_SUCCESS) { |
| 449 | return rc; |
| 450 | } |
| 451 | |
| 452 | struct pldm_write_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 453 | (struct pldm_write_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 454 | response->completion_code = completion_code; |
| 455 | |
| 456 | if (response->completion_code == PLDM_SUCCESS) { |
| 457 | response->length = htole32(length); |
| 458 | } |
| 459 | |
| 460 | return PLDM_SUCCESS; |
| 461 | } |
| 462 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 463 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 464 | int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg, |
| 465 | size_t payload_length, |
| 466 | uint16_t *file_type, |
| 467 | uint32_t *file_handle, uint32_t *offset, |
| 468 | uint32_t *length, uint64_t *address) |
| 469 | { |
| 470 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 471 | offset == NULL || length == NULL || address == NULL) { |
| 472 | return PLDM_ERROR_INVALID_DATA; |
| 473 | } |
| 474 | |
| 475 | if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES) { |
| 476 | return PLDM_ERROR_INVALID_LENGTH; |
| 477 | } |
| 478 | |
| 479 | struct pldm_read_write_file_by_type_memory_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 480 | (struct pldm_read_write_file_by_type_memory_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 481 | *file_type = le16toh(request->file_type); |
| 482 | *file_handle = le32toh(request->file_handle); |
| 483 | *offset = le32toh(request->offset); |
| 484 | *length = le32toh(request->length); |
| 485 | *address = le64toh(request->address); |
| 486 | |
| 487 | return PLDM_SUCCESS; |
| 488 | } |
| 489 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 490 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 491 | int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command, |
| 492 | uint8_t completion_code, uint32_t length, |
| 493 | struct pldm_msg *msg) |
| 494 | { |
| 495 | if (msg == NULL) { |
| 496 | return PLDM_ERROR_INVALID_DATA; |
| 497 | } |
| 498 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 499 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 500 | header.msg_type = PLDM_RESPONSE; |
| 501 | header.instance = instance_id; |
| 502 | header.pldm_type = PLDM_OEM; |
| 503 | header.command = command; |
| 504 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 505 | if (rc != PLDM_SUCCESS) { |
| 506 | return rc; |
| 507 | } |
| 508 | |
| 509 | struct pldm_read_write_file_by_type_memory_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 510 | (struct pldm_read_write_file_by_type_memory_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 511 | response->completion_code = completion_code; |
| 512 | if (response->completion_code == PLDM_SUCCESS) { |
| 513 | response->length = htole32(length); |
| 514 | } |
| 515 | |
| 516 | return PLDM_SUCCESS; |
| 517 | } |
| 518 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 519 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 520 | int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command, |
| 521 | uint16_t file_type, uint32_t file_handle, |
| 522 | uint32_t offset, uint32_t length, |
| 523 | uint64_t address, struct pldm_msg *msg) |
| 524 | { |
| 525 | if (msg == NULL) { |
| 526 | return PLDM_ERROR_INVALID_DATA; |
| 527 | } |
| 528 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 529 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 530 | header.msg_type = PLDM_REQUEST; |
| 531 | header.instance = instance_id; |
| 532 | header.pldm_type = PLDM_OEM; |
| 533 | header.command = command; |
| 534 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 535 | if (rc != PLDM_SUCCESS) { |
| 536 | return rc; |
| 537 | } |
| 538 | |
| 539 | struct pldm_read_write_file_by_type_memory_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 540 | (struct pldm_read_write_file_by_type_memory_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 541 | req->file_type = htole16(file_type); |
| 542 | req->file_handle = htole32(file_handle); |
| 543 | req->offset = htole32(offset); |
| 544 | req->length = htole32(length); |
| 545 | req->address = htole64(address); |
| 546 | |
| 547 | return PLDM_SUCCESS; |
| 548 | } |
| 549 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 550 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 551 | int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg, |
| 552 | size_t payload_length, |
| 553 | uint8_t *completion_code, |
| 554 | uint32_t *length) |
| 555 | { |
| 556 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 557 | return PLDM_ERROR_INVALID_DATA; |
| 558 | } |
| 559 | |
| 560 | if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES) { |
| 561 | return PLDM_ERROR_INVALID_LENGTH; |
| 562 | } |
| 563 | |
| 564 | struct pldm_read_write_file_by_type_memory_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 565 | (struct pldm_read_write_file_by_type_memory_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 566 | *completion_code = response->completion_code; |
| 567 | if (*completion_code == PLDM_SUCCESS) { |
| 568 | *length = le32toh(response->length); |
| 569 | } |
| 570 | |
| 571 | return PLDM_SUCCESS; |
| 572 | } |
| 573 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 574 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 575 | int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 576 | uint16_t *file_type, uint32_t *file_handle, |
| 577 | uint64_t *length) |
| 578 | { |
| 579 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 580 | length == NULL) { |
| 581 | return PLDM_ERROR_INVALID_DATA; |
| 582 | } |
| 583 | |
| 584 | if (payload_length != PLDM_NEW_FILE_REQ_BYTES) { |
| 585 | return PLDM_ERROR_INVALID_LENGTH; |
| 586 | } |
| 587 | |
| 588 | struct pldm_new_file_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 589 | (struct pldm_new_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 590 | *file_type = le16toh(request->file_type); |
| 591 | *file_handle = le32toh(request->file_handle); |
| 592 | *length = le64toh(request->length); |
| 593 | |
| 594 | return PLDM_SUCCESS; |
| 595 | } |
| 596 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 597 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 598 | int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 599 | struct pldm_msg *msg) |
| 600 | { |
| 601 | if (msg == NULL) { |
| 602 | return PLDM_ERROR_INVALID_DATA; |
| 603 | } |
| 604 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 605 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 606 | header.msg_type = PLDM_RESPONSE; |
| 607 | header.instance = instance_id; |
| 608 | header.pldm_type = PLDM_OEM; |
| 609 | header.command = PLDM_NEW_FILE_AVAILABLE; |
| 610 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 611 | if (rc != PLDM_SUCCESS) { |
| 612 | return rc; |
| 613 | } |
| 614 | |
| 615 | struct pldm_new_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 616 | (struct pldm_new_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 617 | response->completion_code = completion_code; |
| 618 | |
| 619 | return PLDM_SUCCESS; |
| 620 | } |
| 621 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 622 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 623 | int encode_new_file_req(uint8_t instance_id, uint16_t file_type, |
| 624 | uint32_t file_handle, uint64_t length, |
| 625 | struct pldm_msg *msg) |
| 626 | { |
| 627 | if (msg == NULL) { |
| 628 | return PLDM_ERROR_INVALID_DATA; |
| 629 | } |
| 630 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 631 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 632 | header.msg_type = PLDM_REQUEST; |
| 633 | header.instance = instance_id; |
| 634 | header.pldm_type = PLDM_OEM; |
| 635 | header.command = PLDM_NEW_FILE_AVAILABLE; |
| 636 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 637 | if (rc != PLDM_SUCCESS) { |
| 638 | return rc; |
| 639 | } |
| 640 | |
| 641 | struct pldm_new_file_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 642 | (struct pldm_new_file_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 643 | req->file_type = htole16(file_type); |
| 644 | req->file_handle = htole32(file_handle); |
| 645 | req->length = htole64(length); |
| 646 | |
| 647 | return PLDM_SUCCESS; |
| 648 | } |
| 649 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 650 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 651 | int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 652 | uint8_t *completion_code) |
| 653 | { |
| 654 | if (msg == NULL || completion_code == NULL) { |
| 655 | return PLDM_ERROR_INVALID_DATA; |
| 656 | } |
| 657 | |
| 658 | if (payload_length != PLDM_NEW_FILE_RESP_BYTES) { |
| 659 | return PLDM_ERROR_INVALID_LENGTH; |
| 660 | } |
| 661 | |
| 662 | struct pldm_new_file_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 663 | (struct pldm_new_file_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 664 | *completion_code = response->completion_code; |
| 665 | |
| 666 | return PLDM_SUCCESS; |
| 667 | } |
| 668 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 669 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 670 | int decode_rw_file_by_type_req(const struct pldm_msg *msg, |
| 671 | size_t payload_length, uint16_t *file_type, |
| 672 | uint32_t *file_handle, uint32_t *offset, |
| 673 | uint32_t *length) |
| 674 | { |
| 675 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 676 | offset == NULL || length == NULL) { |
| 677 | return PLDM_ERROR_INVALID_DATA; |
| 678 | } |
| 679 | |
| 680 | if (payload_length < PLDM_RW_FILE_BY_TYPE_REQ_BYTES) { |
| 681 | return PLDM_ERROR_INVALID_LENGTH; |
| 682 | } |
| 683 | |
| 684 | struct pldm_read_write_file_by_type_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 685 | (struct pldm_read_write_file_by_type_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 686 | *file_type = le16toh(request->file_type); |
| 687 | *file_handle = le32toh(request->file_handle); |
| 688 | *offset = le32toh(request->offset); |
| 689 | *length = le32toh(request->length); |
| 690 | |
| 691 | return PLDM_SUCCESS; |
| 692 | } |
| 693 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 694 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 695 | int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command, |
| 696 | uint8_t completion_code, uint32_t length, |
| 697 | struct pldm_msg *msg) |
| 698 | { |
| 699 | if (msg == NULL) { |
| 700 | return PLDM_ERROR_INVALID_DATA; |
| 701 | } |
| 702 | if (command != PLDM_READ_FILE_BY_TYPE && |
| 703 | command != PLDM_WRITE_FILE_BY_TYPE) { |
| 704 | return PLDM_ERROR_INVALID_DATA; |
| 705 | } |
| 706 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 707 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 708 | header.msg_type = PLDM_RESPONSE; |
| 709 | header.instance = instance_id; |
| 710 | header.pldm_type = PLDM_OEM; |
| 711 | header.command = command; |
| 712 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 713 | if (rc != PLDM_SUCCESS) { |
| 714 | return rc; |
| 715 | } |
| 716 | |
| 717 | struct pldm_read_write_file_by_type_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 718 | (struct pldm_read_write_file_by_type_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 719 | response->completion_code = completion_code; |
| 720 | if (response->completion_code == PLDM_SUCCESS) { |
| 721 | response->length = htole32(length); |
| 722 | } |
| 723 | |
| 724 | return PLDM_SUCCESS; |
| 725 | } |
| 726 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 727 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 728 | int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command, |
| 729 | uint16_t file_type, uint32_t file_handle, |
| 730 | uint32_t offset, uint32_t length, |
| 731 | struct pldm_msg *msg) |
| 732 | { |
| 733 | if (msg == NULL) { |
| 734 | return PLDM_ERROR_INVALID_DATA; |
| 735 | } |
| 736 | if (command != PLDM_READ_FILE_BY_TYPE && |
| 737 | command != PLDM_WRITE_FILE_BY_TYPE) { |
| 738 | return PLDM_ERROR_INVALID_DATA; |
| 739 | } |
| 740 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 741 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 742 | header.msg_type = PLDM_REQUEST; |
| 743 | header.instance = instance_id; |
| 744 | header.pldm_type = PLDM_OEM; |
| 745 | header.command = command; |
| 746 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 747 | if (rc != PLDM_SUCCESS) { |
| 748 | return rc; |
| 749 | } |
| 750 | |
| 751 | struct pldm_read_write_file_by_type_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 752 | (struct pldm_read_write_file_by_type_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 753 | req->file_type = htole16(file_type); |
| 754 | req->file_handle = htole32(file_handle); |
| 755 | req->offset = htole32(offset); |
| 756 | req->length = htole32(length); |
| 757 | |
| 758 | return PLDM_SUCCESS; |
| 759 | } |
| 760 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 761 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 762 | int decode_rw_file_by_type_resp(const struct pldm_msg *msg, |
| 763 | size_t payload_length, uint8_t *completion_code, |
| 764 | uint32_t *length) |
| 765 | { |
| 766 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 767 | return PLDM_ERROR_INVALID_DATA; |
| 768 | } |
| 769 | |
| 770 | if (payload_length != PLDM_RW_FILE_BY_TYPE_RESP_BYTES) { |
| 771 | return PLDM_ERROR_INVALID_LENGTH; |
| 772 | } |
| 773 | |
| 774 | struct pldm_read_write_file_by_type_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 775 | (struct pldm_read_write_file_by_type_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 776 | *completion_code = response->completion_code; |
| 777 | if (*completion_code == PLDM_SUCCESS) { |
| 778 | *length = le32toh(response->length); |
| 779 | } |
| 780 | |
| 781 | return PLDM_SUCCESS; |
| 782 | } |
| 783 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 784 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 785 | int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length, |
| 786 | uint16_t *file_type, uint32_t *file_handle, |
| 787 | uint8_t *file_status) |
| 788 | { |
| 789 | if (msg == NULL || file_type == NULL || file_handle == NULL) { |
| 790 | return PLDM_ERROR_INVALID_DATA; |
| 791 | } |
| 792 | |
| 793 | if (payload_length != PLDM_FILE_ACK_REQ_BYTES) { |
| 794 | return PLDM_ERROR_INVALID_LENGTH; |
| 795 | } |
| 796 | |
| 797 | struct pldm_file_ack_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 798 | (struct pldm_file_ack_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 799 | *file_type = le16toh(request->file_type); |
| 800 | *file_handle = le32toh(request->file_handle); |
| 801 | *file_status = request->file_status; |
| 802 | |
| 803 | return PLDM_SUCCESS; |
| 804 | } |
| 805 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 806 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 807 | int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code, |
| 808 | struct pldm_msg *msg) |
| 809 | { |
| 810 | if (msg == NULL) { |
| 811 | return PLDM_ERROR_INVALID_DATA; |
| 812 | } |
| 813 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 814 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 815 | header.msg_type = PLDM_RESPONSE; |
| 816 | header.instance = instance_id; |
| 817 | header.pldm_type = PLDM_OEM; |
| 818 | header.command = PLDM_FILE_ACK; |
| 819 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 820 | if (rc != PLDM_SUCCESS) { |
| 821 | return rc; |
| 822 | } |
| 823 | |
| 824 | struct pldm_file_ack_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 825 | (struct pldm_file_ack_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 826 | response->completion_code = completion_code; |
| 827 | |
| 828 | return PLDM_SUCCESS; |
| 829 | } |
| 830 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 831 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 832 | int encode_file_ack_req(uint8_t instance_id, uint16_t file_type, |
| 833 | uint32_t file_handle, uint8_t file_status, |
| 834 | struct pldm_msg *msg) |
| 835 | { |
| 836 | if (msg == NULL) { |
| 837 | return PLDM_ERROR_INVALID_DATA; |
| 838 | } |
| 839 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 840 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 841 | header.msg_type = PLDM_REQUEST; |
| 842 | header.instance = instance_id; |
| 843 | header.pldm_type = PLDM_OEM; |
| 844 | header.command = PLDM_FILE_ACK; |
| 845 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 846 | if (rc != PLDM_SUCCESS) { |
| 847 | return rc; |
| 848 | } |
| 849 | |
| 850 | struct pldm_file_ack_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 851 | (struct pldm_file_ack_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 852 | req->file_type = htole16(file_type); |
| 853 | req->file_handle = htole32(file_handle); |
| 854 | req->file_status = file_status; |
| 855 | |
| 856 | return PLDM_SUCCESS; |
| 857 | } |
| 858 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 859 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 860 | int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length, |
| 861 | uint8_t *completion_code) |
| 862 | { |
| 863 | if (msg == NULL || completion_code == NULL) { |
| 864 | return PLDM_ERROR_INVALID_DATA; |
| 865 | } |
| 866 | |
| 867 | if (payload_length != PLDM_FILE_ACK_RESP_BYTES) { |
| 868 | return PLDM_ERROR_INVALID_LENGTH; |
| 869 | } |
| 870 | |
| 871 | struct pldm_file_ack_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 872 | (struct pldm_file_ack_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 873 | *completion_code = response->completion_code; |
| 874 | |
| 875 | return PLDM_SUCCESS; |
| 876 | } |
| 877 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 878 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 879 | int encode_file_ack_with_meta_data_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 880 | uint8_t instance_id, uint16_t file_type, uint32_t file_handle, |
| 881 | uint8_t file_status, uint32_t file_meta_data_1, |
| 882 | uint32_t file_meta_data_2, uint32_t file_meta_data_3, |
| 883 | uint32_t file_meta_data_4, struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 884 | { |
| 885 | if (msg == NULL) { |
| 886 | return PLDM_ERROR_INVALID_DATA; |
| 887 | } |
| 888 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 889 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 890 | header.msg_type = PLDM_REQUEST; |
| 891 | header.instance = instance_id; |
| 892 | header.pldm_type = PLDM_OEM; |
| 893 | header.command = PLDM_FILE_ACK_WITH_META_DATA; |
| 894 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 895 | if (rc != PLDM_SUCCESS) { |
| 896 | return rc; |
| 897 | } |
| 898 | |
| 899 | struct pldm_file_ack_with_meta_data_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 900 | (struct pldm_file_ack_with_meta_data_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 901 | req->file_type = htole16(file_type); |
| 902 | req->file_handle = htole32(file_handle); |
| 903 | req->file_status = file_status; |
| 904 | req->file_meta_data_1 = htole32(file_meta_data_1); |
| 905 | req->file_meta_data_2 = htole32(file_meta_data_2); |
| 906 | req->file_meta_data_3 = htole32(file_meta_data_3); |
| 907 | req->file_meta_data_4 = htole32(file_meta_data_4); |
| 908 | |
| 909 | return PLDM_SUCCESS; |
| 910 | } |
| 911 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 912 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 913 | int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg, |
| 914 | size_t payload_length, |
| 915 | uint8_t *completion_code) |
| 916 | { |
| 917 | if (msg == NULL || completion_code == NULL) { |
| 918 | return PLDM_ERROR_INVALID_DATA; |
| 919 | } |
| 920 | |
| 921 | if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES) { |
| 922 | return PLDM_ERROR_INVALID_LENGTH; |
| 923 | } |
| 924 | |
| 925 | struct pldm_file_ack_with_meta_data_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 926 | (struct pldm_file_ack_with_meta_data_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 927 | *completion_code = response->completion_code; |
| 928 | |
| 929 | return PLDM_SUCCESS; |
| 930 | } |
| 931 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 932 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 933 | int decode_file_ack_with_meta_data_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 934 | const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type, |
| 935 | uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1, |
| 936 | uint32_t *file_meta_data_2, uint32_t *file_meta_data_3, |
| 937 | uint32_t *file_meta_data_4) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 938 | { |
| 939 | if (msg == NULL || file_type == NULL || file_handle == NULL) { |
| 940 | return PLDM_ERROR_INVALID_DATA; |
| 941 | } |
| 942 | |
| 943 | if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES) { |
| 944 | return PLDM_ERROR_INVALID_LENGTH; |
| 945 | } |
| 946 | |
| 947 | struct pldm_file_ack_with_meta_data_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 948 | (struct pldm_file_ack_with_meta_data_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 949 | *file_type = le16toh(request->file_type); |
| 950 | *file_handle = le32toh(request->file_handle); |
| 951 | *file_status = request->file_status; |
| 952 | *file_meta_data_1 = le32toh(request->file_meta_data_1); |
| 953 | *file_meta_data_2 = le32toh(request->file_meta_data_2); |
| 954 | *file_meta_data_3 = le32toh(request->file_meta_data_3); |
| 955 | *file_meta_data_4 = le32toh(request->file_meta_data_4); |
| 956 | |
| 957 | return PLDM_SUCCESS; |
| 958 | } |
| 959 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 960 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 961 | int encode_file_ack_with_meta_data_resp(uint8_t instance_id, |
| 962 | uint8_t completion_code, |
| 963 | struct pldm_msg *msg) |
| 964 | { |
| 965 | if (msg == NULL) { |
| 966 | return PLDM_ERROR_INVALID_DATA; |
| 967 | } |
| 968 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 969 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 970 | header.msg_type = PLDM_RESPONSE; |
| 971 | header.instance = instance_id; |
| 972 | header.pldm_type = PLDM_OEM; |
| 973 | header.command = PLDM_FILE_ACK_WITH_META_DATA; |
| 974 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 975 | if (rc != PLDM_SUCCESS) { |
| 976 | return rc; |
| 977 | } |
| 978 | |
| 979 | struct pldm_file_ack_with_meta_data_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 980 | (struct pldm_file_ack_with_meta_data_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 981 | response->completion_code = completion_code; |
| 982 | |
| 983 | return PLDM_SUCCESS; |
| 984 | } |
| 985 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 986 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 987 | int encode_new_file_with_metadata_req(uint8_t instance_id, uint16_t file_type, |
| 988 | uint32_t file_handle, uint64_t length, |
| 989 | uint32_t file_meta_data_1, |
| 990 | uint32_t file_meta_data_2, |
| 991 | uint32_t file_meta_data_3, |
| 992 | uint32_t file_meta_data_4, |
| 993 | struct pldm_msg *msg) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 994 | { |
| 995 | if (msg == NULL) { |
| 996 | return PLDM_ERROR_INVALID_DATA; |
| 997 | } |
| 998 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 999 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1000 | header.msg_type = PLDM_REQUEST; |
| 1001 | header.instance = instance_id; |
| 1002 | header.pldm_type = PLDM_OEM; |
| 1003 | header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA; |
| 1004 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1005 | if (rc != PLDM_SUCCESS) { |
| 1006 | return rc; |
| 1007 | } |
| 1008 | |
| 1009 | struct pldm_new_file_with_metadata_req *req = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1010 | (struct pldm_new_file_with_metadata_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1011 | req->file_type = htole16(file_type); |
| 1012 | req->file_handle = htole32(file_handle); |
| 1013 | req->length = htole64(length); |
| 1014 | req->file_meta_data_1 = htole32(file_meta_data_1); |
| 1015 | req->file_meta_data_2 = htole32(file_meta_data_2); |
| 1016 | req->file_meta_data_3 = htole32(file_meta_data_3); |
| 1017 | req->file_meta_data_4 = htole32(file_meta_data_4); |
| 1018 | |
| 1019 | return PLDM_SUCCESS; |
| 1020 | } |
| 1021 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1022 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1023 | int decode_new_file_with_metadata_resp(const struct pldm_msg *msg, |
| 1024 | size_t payload_length, |
| 1025 | uint8_t *completion_code) |
| 1026 | { |
| 1027 | if (msg == NULL || completion_code == NULL) { |
| 1028 | return PLDM_ERROR_INVALID_DATA; |
| 1029 | } |
| 1030 | |
| 1031 | if (payload_length != |
| 1032 | PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES) { |
| 1033 | return PLDM_ERROR_INVALID_LENGTH; |
| 1034 | } |
| 1035 | |
| 1036 | struct pldm_new_file_with_metadata_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1037 | (struct pldm_new_file_with_metadata_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1038 | |
| 1039 | *completion_code = msg->payload[0]; |
| 1040 | if (*completion_code == PLDM_SUCCESS) { |
| 1041 | *completion_code = response->completion_code; |
| 1042 | } |
| 1043 | return PLDM_SUCCESS; |
| 1044 | } |
| 1045 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1046 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1047 | int decode_new_file_with_metadata_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1048 | const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type, |
| 1049 | uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1, |
| 1050 | uint32_t *file_meta_data_2, uint32_t *file_meta_data_3, |
| 1051 | uint32_t *file_meta_data_4) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1052 | { |
| 1053 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 1054 | length == NULL) { |
| 1055 | return PLDM_ERROR_INVALID_DATA; |
| 1056 | } |
| 1057 | |
| 1058 | if (payload_length != |
| 1059 | PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES) { |
| 1060 | return PLDM_ERROR_INVALID_LENGTH; |
| 1061 | } |
| 1062 | |
| 1063 | struct pldm_new_file_with_metadata_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1064 | (struct pldm_new_file_with_metadata_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1065 | *file_type = le16toh(request->file_type); |
| 1066 | *file_handle = le32toh(request->file_handle); |
| 1067 | *length = le64toh(request->length); |
| 1068 | *file_meta_data_1 = le32toh(request->file_meta_data_1); |
| 1069 | *file_meta_data_2 = le32toh(request->file_meta_data_2); |
| 1070 | *file_meta_data_3 = le32toh(request->file_meta_data_3); |
| 1071 | *file_meta_data_4 = le32toh(request->file_meta_data_4); |
| 1072 | |
| 1073 | return PLDM_SUCCESS; |
| 1074 | } |
| 1075 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1076 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1077 | int encode_new_file_with_metadata_resp(uint8_t instance_id, |
| 1078 | uint8_t completion_code, |
| 1079 | struct pldm_msg *msg) |
| 1080 | { |
| 1081 | if (msg == NULL) { |
| 1082 | return PLDM_ERROR_INVALID_DATA; |
| 1083 | } |
| 1084 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1085 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1086 | header.msg_type = PLDM_RESPONSE; |
| 1087 | header.instance = instance_id; |
| 1088 | header.pldm_type = PLDM_OEM; |
| 1089 | header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA; |
| 1090 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1091 | if (rc != PLDM_SUCCESS) { |
| 1092 | return rc; |
| 1093 | } |
| 1094 | |
| 1095 | struct pldm_new_file_with_metadata_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1096 | (struct pldm_new_file_with_metadata_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1097 | |
| 1098 | if (response->completion_code == PLDM_SUCCESS) { |
| 1099 | response->completion_code = completion_code; |
| 1100 | } |
| 1101 | |
| 1102 | return PLDM_SUCCESS; |
| 1103 | } |