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