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