Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 1 | #include "file_io.h" |
| 2 | #include <endian.h> |
| 3 | #include <string.h> |
| 4 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 5 | int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 6 | uint32_t *file_handle, uint32_t *offset, |
| 7 | uint32_t *length, uint64_t *address) |
| 8 | { |
| 9 | if (msg == NULL || file_handle == NULL || offset == NULL || |
| 10 | length == NULL || address == NULL) { |
| 11 | return PLDM_ERROR_INVALID_DATA; |
| 12 | } |
| 13 | |
| 14 | if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) { |
| 15 | return PLDM_ERROR_INVALID_LENGTH; |
| 16 | } |
| 17 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 18 | struct pldm_read_write_file_memory_req *request = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 19 | (struct pldm_read_write_file_memory_req *)msg->payload; |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 20 | |
| 21 | *file_handle = le32toh(request->file_handle); |
| 22 | *offset = le32toh(request->offset); |
| 23 | *length = le32toh(request->length); |
| 24 | *address = le64toh(request->address); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 25 | |
| 26 | return PLDM_SUCCESS; |
| 27 | } |
| 28 | |
| 29 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 30 | uint8_t completion_code, uint32_t length, |
| 31 | struct pldm_msg *msg) |
| 32 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 33 | if (msg == NULL) { |
| 34 | return PLDM_ERROR_INVALID_LENGTH; |
| 35 | } |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 36 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 37 | struct pldm_header_info header = {0}; |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 38 | header.msg_type = PLDM_RESPONSE; |
| 39 | header.instance = instance_id; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 40 | header.pldm_type = PLDM_OEM; |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 41 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 42 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 43 | if (rc != PLDM_SUCCESS) { |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 44 | return rc; |
| 45 | } |
| 46 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 47 | struct pldm_read_write_file_memory_resp *response = |
| 48 | (struct pldm_read_write_file_memory_resp *)msg->payload; |
| 49 | response->completion_code = completion_code; |
| 50 | if (response->completion_code == PLDM_SUCCESS) { |
| 51 | response->length = htole32(length); |
| 52 | } |
| 53 | |
| 54 | return PLDM_SUCCESS; |
| 55 | } |
| 56 | |
| 57 | int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command, |
| 58 | uint32_t file_handle, uint32_t offset, |
| 59 | uint32_t length, uint64_t address, |
| 60 | struct pldm_msg *msg) |
| 61 | { |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 62 | if (msg == NULL) { |
| 63 | return PLDM_ERROR_INVALID_DATA; |
| 64 | } |
| 65 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 66 | struct pldm_header_info header = {0}; |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 67 | header.msg_type = PLDM_REQUEST; |
| 68 | header.instance = instance_id; |
| 69 | header.pldm_type = PLDM_OEM; |
| 70 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 71 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 72 | if (rc != PLDM_SUCCESS) { |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 73 | return rc; |
| 74 | } |
| 75 | |
| 76 | struct pldm_read_write_file_memory_req *req = |
| 77 | (struct pldm_read_write_file_memory_req *)msg->payload; |
| 78 | req->file_handle = htole32(file_handle); |
| 79 | req->offset = htole32(offset); |
| 80 | req->length = htole32(length); |
| 81 | req->address = htole64(address); |
| 82 | return PLDM_SUCCESS; |
| 83 | } |
| 84 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 85 | int decode_rw_file_memory_resp(const struct pldm_msg *msg, |
| 86 | size_t payload_length, uint8_t *completion_code, |
| 87 | uint32_t *length) |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 88 | { |
| 89 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 90 | return PLDM_ERROR_INVALID_DATA; |
| 91 | } |
| 92 | |
| 93 | if (payload_length != PLDM_RW_FILE_MEM_RESP_BYTES) { |
| 94 | return PLDM_ERROR_INVALID_LENGTH; |
| 95 | } |
| 96 | |
| 97 | struct pldm_read_write_file_memory_resp *response = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 98 | (struct pldm_read_write_file_memory_resp *)msg->payload; |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 99 | *completion_code = response->completion_code; |
| 100 | if (*completion_code == PLDM_SUCCESS) { |
| 101 | *length = le32toh(response->length); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | return PLDM_SUCCESS; |
| 105 | } |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 106 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 107 | int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 108 | uint32_t *transfer_handle, |
| 109 | uint8_t *transfer_opflag, uint8_t *table_type) |
| 110 | { |
| 111 | if (msg == NULL || transfer_handle == NULL || transfer_opflag == NULL || |
| 112 | table_type == NULL) { |
| 113 | return PLDM_ERROR_INVALID_DATA; |
| 114 | } |
| 115 | |
| 116 | if (payload_length != PLDM_GET_FILE_TABLE_REQ_BYTES) { |
| 117 | return PLDM_ERROR_INVALID_LENGTH; |
| 118 | } |
| 119 | |
| 120 | struct pldm_get_file_table_req *request = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 121 | (struct pldm_get_file_table_req *)msg->payload; |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 122 | |
| 123 | *transfer_handle = le32toh(request->transfer_handle); |
| 124 | *transfer_opflag = request->operation_flag; |
| 125 | *table_type = request->table_type; |
| 126 | |
| 127 | return PLDM_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code, |
| 131 | uint32_t next_transfer_handle, |
| 132 | uint8_t transfer_flag, const uint8_t *table_data, |
| 133 | size_t table_size, struct pldm_msg *msg) |
| 134 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 135 | if (msg == NULL) { |
| 136 | return PLDM_ERROR_INVALID_LENGTH; |
| 137 | } |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 138 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 139 | struct pldm_header_info header = {0}; |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 140 | header.msg_type = PLDM_RESPONSE; |
| 141 | header.instance = instance_id; |
| 142 | header.pldm_type = PLDM_OEM; |
| 143 | header.command = PLDM_GET_FILE_TABLE; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 144 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 145 | if (rc != PLDM_SUCCESS) { |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 146 | return rc; |
| 147 | } |
| 148 | |
| 149 | struct pldm_get_file_table_resp *response = |
| 150 | (struct pldm_get_file_table_resp *)msg->payload; |
| 151 | response->completion_code = completion_code; |
| 152 | |
| 153 | if (completion_code == PLDM_SUCCESS) { |
| 154 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 155 | response->transfer_flag = transfer_flag; |
| 156 | memcpy(response->table_data, table_data, table_size); |
| 157 | } |
| 158 | |
| 159 | return PLDM_SUCCESS; |
| 160 | } |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 161 | |
Pavithra Barithaya | d15c809 | 2020-05-12 02:26:26 -0500 | [diff] [blame] | 162 | int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle, |
| 163 | uint8_t transfer_opflag, uint8_t table_type, |
| 164 | struct pldm_msg *msg) |
| 165 | { |
Pavithra Barithaya | d15c809 | 2020-05-12 02:26:26 -0500 | [diff] [blame] | 166 | if (msg == NULL) { |
| 167 | return PLDM_ERROR_INVALID_DATA; |
| 168 | } |
| 169 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 170 | struct pldm_header_info header = {0}; |
Pavithra Barithaya | d15c809 | 2020-05-12 02:26:26 -0500 | [diff] [blame] | 171 | header.msg_type = PLDM_REQUEST; |
| 172 | header.instance = instance_id; |
| 173 | header.pldm_type = PLDM_OEM; |
| 174 | header.command = PLDM_GET_FILE_TABLE; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 175 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 176 | if (rc != PLDM_SUCCESS) { |
Pavithra Barithaya | d15c809 | 2020-05-12 02:26:26 -0500 | [diff] [blame] | 177 | return rc; |
| 178 | } |
| 179 | |
| 180 | struct pldm_get_file_table_req *request = |
| 181 | (struct pldm_get_file_table_req *)msg->payload; |
| 182 | |
| 183 | request->transfer_handle = htole32(transfer_handle); |
| 184 | request->operation_flag = transfer_opflag; |
| 185 | request->table_type = table_type; |
| 186 | return PLDM_SUCCESS; |
| 187 | } |
| 188 | |
| 189 | int decode_get_file_table_resp(const struct pldm_msg *msg, |
| 190 | size_t payload_length, uint8_t *completion_code, |
| 191 | uint32_t *next_transfer_handle, |
| 192 | uint8_t *transfer_flag, |
| 193 | uint8_t *file_table_data_start_offset, |
| 194 | size_t *file_table_length) |
| 195 | { |
| 196 | if (msg == NULL || transfer_flag == NULL || |
| 197 | next_transfer_handle == NULL || completion_code == NULL || |
| 198 | file_table_data_start_offset == NULL || file_table_length == NULL) { |
| 199 | return PLDM_ERROR_INVALID_DATA; |
| 200 | } |
| 201 | |
| 202 | if (payload_length <= PLDM_GET_FILE_TABLE_MIN_RESP_BYTES) { |
| 203 | return PLDM_ERROR_INVALID_LENGTH; |
| 204 | } |
| 205 | |
| 206 | *completion_code = msg->payload[0]; |
| 207 | |
| 208 | if (PLDM_SUCCESS != *completion_code) { |
| 209 | return PLDM_SUCCESS; |
| 210 | } |
| 211 | |
| 212 | struct pldm_get_file_table_resp *response = |
| 213 | (struct pldm_get_file_table_resp *)msg->payload; |
| 214 | |
| 215 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 216 | *transfer_flag = response->transfer_flag; |
| 217 | *file_table_data_start_offset = sizeof(*completion_code) + |
| 218 | sizeof(*next_transfer_handle) + |
| 219 | sizeof(*transfer_flag); |
| 220 | *file_table_length = |
| 221 | payload_length - PLDM_GET_FILE_TABLE_MIN_RESP_BYTES; |
| 222 | |
| 223 | return PLDM_SUCCESS; |
| 224 | } |
| 225 | |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 226 | int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 227 | uint32_t *file_handle, uint32_t *offset, |
| 228 | uint32_t *length) |
| 229 | { |
| 230 | if (msg == NULL || file_handle == NULL || offset == NULL || |
| 231 | length == NULL) { |
| 232 | return PLDM_ERROR_INVALID_DATA; |
| 233 | } |
| 234 | |
| 235 | if (payload_length != PLDM_READ_FILE_REQ_BYTES) { |
| 236 | return PLDM_ERROR_INVALID_LENGTH; |
| 237 | } |
| 238 | |
| 239 | struct pldm_read_file_req *request = |
| 240 | (struct pldm_read_file_req *)msg->payload; |
| 241 | |
| 242 | *file_handle = le32toh(request->file_handle); |
| 243 | *offset = le32toh(request->offset); |
| 244 | *length = le32toh(request->length); |
| 245 | |
| 246 | return PLDM_SUCCESS; |
| 247 | } |
| 248 | |
| 249 | int encode_read_file_req(uint8_t instance_id, uint32_t file_handle, |
| 250 | uint32_t offset, uint32_t length, struct pldm_msg *msg) |
| 251 | { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 252 | if (msg == NULL) { |
| 253 | return PLDM_ERROR_INVALID_DATA; |
| 254 | } |
| 255 | |
| 256 | if (length == 0) { |
Deepak Kodihalli | 3bf5c55 | 2020-04-20 06:16:01 -0500 | [diff] [blame] | 257 | return PLDM_ERROR_INVALID_LENGTH; |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 258 | } |
| 259 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 260 | struct pldm_header_info header = {0}; |
| 261 | header.msg_type = PLDM_REQUEST; |
| 262 | header.instance = instance_id; |
| 263 | header.pldm_type = PLDM_OEM; |
| 264 | header.command = PLDM_READ_FILE; |
| 265 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 266 | if (rc != PLDM_SUCCESS) { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 267 | return rc; |
| 268 | } |
| 269 | |
| 270 | struct pldm_read_file_req *request = |
| 271 | (struct pldm_read_file_req *)msg->payload; |
| 272 | |
| 273 | request->file_handle = htole32(file_handle); |
| 274 | request->offset = htole32(offset); |
| 275 | request->length = htole32(length); |
| 276 | |
| 277 | return PLDM_SUCCESS; |
| 278 | } |
| 279 | |
| 280 | int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 281 | uint8_t *completion_code, uint32_t *length, |
| 282 | size_t *file_data_offset) |
| 283 | { |
| 284 | if (msg == NULL || completion_code == NULL || length == NULL) { |
| 285 | return PLDM_ERROR_INVALID_DATA; |
| 286 | } |
| 287 | |
| 288 | if (payload_length < PLDM_READ_FILE_RESP_BYTES) { |
| 289 | return PLDM_ERROR_INVALID_LENGTH; |
| 290 | } |
| 291 | |
| 292 | struct pldm_read_file_resp *response = |
| 293 | (struct pldm_read_file_resp *)msg->payload; |
| 294 | |
| 295 | *completion_code = response->completion_code; |
| 296 | if (*completion_code == PLDM_SUCCESS) { |
| 297 | *length = le32toh(response->length); |
| 298 | if (payload_length != PLDM_READ_FILE_RESP_BYTES + *length) { |
| 299 | return PLDM_ERROR_INVALID_LENGTH; |
| 300 | } |
| 301 | *file_data_offset = sizeof(*completion_code) + sizeof(*length); |
| 302 | } |
| 303 | |
| 304 | return PLDM_SUCCESS; |
| 305 | } |
| 306 | |
| 307 | int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 308 | uint32_t length, struct pldm_msg *msg) |
| 309 | { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 310 | if (msg == NULL) { |
| 311 | return PLDM_ERROR_INVALID_DATA; |
| 312 | } |
| 313 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 314 | struct pldm_header_info header = {0}; |
| 315 | header.msg_type = PLDM_RESPONSE; |
| 316 | header.instance = instance_id; |
| 317 | header.pldm_type = PLDM_OEM; |
| 318 | header.command = PLDM_READ_FILE; |
| 319 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 320 | if (rc != PLDM_SUCCESS) { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 321 | return rc; |
| 322 | } |
| 323 | |
| 324 | struct pldm_read_file_resp *response = |
| 325 | (struct pldm_read_file_resp *)msg->payload; |
| 326 | response->completion_code = completion_code; |
| 327 | |
| 328 | if (response->completion_code == PLDM_SUCCESS) { |
| 329 | response->length = htole32(length); |
| 330 | } |
| 331 | |
| 332 | return PLDM_SUCCESS; |
| 333 | } |
| 334 | |
| 335 | int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 336 | uint32_t *file_handle, uint32_t *offset, |
| 337 | uint32_t *length, size_t *file_data_offset) |
| 338 | { |
| 339 | if (msg == NULL || file_handle == NULL || length == NULL) { |
| 340 | return PLDM_ERROR_INVALID_DATA; |
| 341 | } |
| 342 | |
| 343 | if (payload_length < PLDM_WRITE_FILE_REQ_BYTES) { |
| 344 | return PLDM_ERROR_INVALID_LENGTH; |
| 345 | } |
| 346 | |
| 347 | struct pldm_write_file_req *request = |
| 348 | (struct pldm_write_file_req *)msg->payload; |
| 349 | |
| 350 | *file_handle = le32toh(request->file_handle); |
| 351 | *offset = le32toh(request->offset); |
| 352 | *length = le32toh(request->length); |
| 353 | if (payload_length != PLDM_WRITE_FILE_REQ_BYTES + *length) { |
| 354 | return PLDM_ERROR_INVALID_LENGTH; |
| 355 | } |
| 356 | *file_data_offset = |
| 357 | sizeof(*file_handle) + sizeof(*offset) + sizeof(*length); |
| 358 | |
| 359 | return PLDM_SUCCESS; |
| 360 | } |
| 361 | |
| 362 | int encode_write_file_req(uint8_t instance_id, uint32_t file_handle, |
| 363 | uint32_t offset, uint32_t length, |
| 364 | struct pldm_msg *msg) |
| 365 | { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 366 | if (msg == NULL) { |
| 367 | return PLDM_ERROR_INVALID_DATA; |
| 368 | } |
| 369 | |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 370 | if (length == 0) { |
Deepak Kodihalli | 3bf5c55 | 2020-04-20 06:16:01 -0500 | [diff] [blame] | 371 | return PLDM_ERROR_INVALID_LENGTH; |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 372 | } |
| 373 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 374 | struct pldm_header_info header = {0}; |
| 375 | header.msg_type = PLDM_REQUEST; |
| 376 | header.instance = instance_id; |
| 377 | header.pldm_type = PLDM_OEM; |
| 378 | header.command = PLDM_WRITE_FILE; |
| 379 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 380 | if (rc != PLDM_SUCCESS) { |
| 381 | return rc; |
| 382 | } |
| 383 | |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 384 | struct pldm_write_file_req *request = |
| 385 | (struct pldm_write_file_req *)msg->payload; |
| 386 | |
| 387 | request->file_handle = htole32(file_handle); |
| 388 | request->offset = htole32(offset); |
| 389 | request->length = htole32(length); |
| 390 | |
| 391 | return PLDM_SUCCESS; |
| 392 | } |
| 393 | |
| 394 | int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 395 | uint8_t *completion_code, uint32_t *length) |
| 396 | { |
| 397 | if (msg == NULL || completion_code == NULL || length == NULL) { |
| 398 | return PLDM_ERROR_INVALID_DATA; |
| 399 | } |
| 400 | |
| 401 | if (payload_length != PLDM_WRITE_FILE_RESP_BYTES) { |
| 402 | return PLDM_ERROR_INVALID_LENGTH; |
| 403 | } |
| 404 | |
| 405 | struct pldm_write_file_resp *response = |
| 406 | (struct pldm_write_file_resp *)msg->payload; |
| 407 | |
| 408 | *completion_code = le32toh(response->completion_code); |
| 409 | if (response->completion_code == PLDM_SUCCESS) { |
| 410 | *length = le32toh(response->length); |
| 411 | } |
| 412 | |
| 413 | return PLDM_SUCCESS; |
| 414 | } |
| 415 | |
| 416 | int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 417 | uint32_t length, struct pldm_msg *msg) |
| 418 | { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 419 | if (msg == NULL) { |
| 420 | return PLDM_ERROR_INVALID_DATA; |
| 421 | } |
| 422 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 423 | struct pldm_header_info header = {0}; |
| 424 | header.msg_type = PLDM_RESPONSE; |
| 425 | header.instance = instance_id; |
| 426 | header.pldm_type = PLDM_OEM; |
| 427 | header.command = PLDM_WRITE_FILE; |
| 428 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 429 | if (rc != PLDM_SUCCESS) { |
vkaverap | 2ffe329 | 2019-06-24 00:08:13 -0500 | [diff] [blame] | 430 | return rc; |
| 431 | } |
| 432 | |
| 433 | struct pldm_write_file_resp *response = |
| 434 | (struct pldm_write_file_resp *)msg->payload; |
| 435 | response->completion_code = completion_code; |
| 436 | |
| 437 | if (response->completion_code == PLDM_SUCCESS) { |
| 438 | response->length = htole32(length); |
| 439 | } |
| 440 | |
| 441 | return PLDM_SUCCESS; |
| 442 | } |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 443 | |
| 444 | int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg, |
| 445 | size_t payload_length, |
| 446 | uint16_t *file_type, |
| 447 | uint32_t *file_handle, uint32_t *offset, |
| 448 | uint32_t *length, uint64_t *address) |
| 449 | { |
| 450 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 451 | offset == NULL || length == NULL || address == NULL) { |
| 452 | return PLDM_ERROR_INVALID_DATA; |
| 453 | } |
| 454 | |
| 455 | if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES) { |
| 456 | return PLDM_ERROR_INVALID_LENGTH; |
| 457 | } |
| 458 | |
| 459 | struct pldm_read_write_file_by_type_memory_req *request = |
| 460 | (struct pldm_read_write_file_by_type_memory_req *)msg->payload; |
| 461 | *file_type = le16toh(request->file_type); |
| 462 | *file_handle = le32toh(request->file_handle); |
| 463 | *offset = le32toh(request->offset); |
| 464 | *length = le32toh(request->length); |
| 465 | *address = le64toh(request->address); |
| 466 | |
| 467 | return PLDM_SUCCESS; |
| 468 | } |
| 469 | |
| 470 | int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command, |
| 471 | uint8_t completion_code, uint32_t length, |
| 472 | struct pldm_msg *msg) |
| 473 | { |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 474 | if (msg == NULL) { |
| 475 | return PLDM_ERROR_INVALID_DATA; |
| 476 | } |
| 477 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 478 | struct pldm_header_info header = {0}; |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 479 | header.msg_type = PLDM_RESPONSE; |
| 480 | header.instance = instance_id; |
| 481 | header.pldm_type = PLDM_OEM; |
| 482 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 483 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 484 | if (rc != PLDM_SUCCESS) { |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 485 | return rc; |
| 486 | } |
| 487 | |
| 488 | struct pldm_read_write_file_by_type_memory_resp *response = |
| 489 | (struct pldm_read_write_file_by_type_memory_resp *)msg->payload; |
| 490 | response->completion_code = completion_code; |
| 491 | if (response->completion_code == PLDM_SUCCESS) { |
| 492 | response->length = htole32(length); |
| 493 | } |
| 494 | |
| 495 | return PLDM_SUCCESS; |
| 496 | } |
| 497 | |
| 498 | int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command, |
| 499 | uint16_t file_type, uint32_t file_handle, |
| 500 | uint32_t offset, uint32_t length, |
| 501 | uint64_t address, struct pldm_msg *msg) |
| 502 | { |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 503 | if (msg == NULL) { |
| 504 | return PLDM_ERROR_INVALID_DATA; |
| 505 | } |
| 506 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 507 | struct pldm_header_info header = {0}; |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 508 | header.msg_type = PLDM_REQUEST; |
| 509 | header.instance = instance_id; |
| 510 | header.pldm_type = PLDM_OEM; |
| 511 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 512 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 513 | if (rc != PLDM_SUCCESS) { |
vkaverap | 0740456 | 2019-08-05 22:57:11 -0500 | [diff] [blame] | 514 | return rc; |
| 515 | } |
| 516 | |
| 517 | struct pldm_read_write_file_by_type_memory_req *req = |
| 518 | (struct pldm_read_write_file_by_type_memory_req *)msg->payload; |
| 519 | req->file_type = htole16(file_type); |
| 520 | req->file_handle = htole32(file_handle); |
| 521 | req->offset = htole32(offset); |
| 522 | req->length = htole32(length); |
| 523 | req->address = htole64(address); |
| 524 | |
| 525 | return PLDM_SUCCESS; |
| 526 | } |
| 527 | |
| 528 | int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg, |
| 529 | size_t payload_length, |
| 530 | uint8_t *completion_code, |
| 531 | uint32_t *length) |
| 532 | { |
| 533 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 534 | return PLDM_ERROR_INVALID_DATA; |
| 535 | } |
| 536 | |
| 537 | if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES) { |
| 538 | return PLDM_ERROR_INVALID_LENGTH; |
| 539 | } |
| 540 | |
| 541 | struct pldm_read_write_file_by_type_memory_resp *response = |
| 542 | (struct pldm_read_write_file_by_type_memory_resp *)msg->payload; |
| 543 | *completion_code = response->completion_code; |
| 544 | if (*completion_code == PLDM_SUCCESS) { |
| 545 | *length = le32toh(response->length); |
| 546 | } |
| 547 | |
| 548 | return PLDM_SUCCESS; |
| 549 | } |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 550 | |
| 551 | int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length, |
| 552 | uint16_t *file_type, uint32_t *file_handle, |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 553 | uint64_t *length) |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 554 | { |
| 555 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 556 | length == NULL) { |
| 557 | return PLDM_ERROR_INVALID_DATA; |
| 558 | } |
| 559 | |
| 560 | if (payload_length != PLDM_NEW_FILE_REQ_BYTES) { |
| 561 | return PLDM_ERROR_INVALID_LENGTH; |
| 562 | } |
| 563 | |
| 564 | struct pldm_new_file_req *request = |
| 565 | (struct pldm_new_file_req *)msg->payload; |
| 566 | *file_type = le16toh(request->file_type); |
| 567 | *file_handle = le32toh(request->file_handle); |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 568 | *length = le64toh(request->length); |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 569 | |
| 570 | return PLDM_SUCCESS; |
| 571 | } |
| 572 | |
| 573 | int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code, |
| 574 | struct pldm_msg *msg) |
| 575 | { |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 576 | if (msg == NULL) { |
| 577 | return PLDM_ERROR_INVALID_DATA; |
| 578 | } |
| 579 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 580 | struct pldm_header_info header = {0}; |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 581 | header.msg_type = PLDM_RESPONSE; |
| 582 | header.instance = instance_id; |
| 583 | header.pldm_type = PLDM_OEM; |
| 584 | header.command = PLDM_NEW_FILE_AVAILABLE; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 585 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 586 | if (rc != PLDM_SUCCESS) { |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 587 | return rc; |
| 588 | } |
| 589 | |
| 590 | struct pldm_new_file_resp *response = |
| 591 | (struct pldm_new_file_resp *)msg->payload; |
| 592 | response->completion_code = completion_code; |
| 593 | |
| 594 | return PLDM_SUCCESS; |
| 595 | } |
| 596 | |
| 597 | int encode_new_file_req(uint8_t instance_id, uint16_t file_type, |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 598 | uint32_t file_handle, uint64_t length, |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 599 | struct pldm_msg *msg) |
| 600 | { |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 601 | if (msg == NULL) { |
| 602 | return PLDM_ERROR_INVALID_DATA; |
| 603 | } |
| 604 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 605 | struct pldm_header_info header = {0}; |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 606 | header.msg_type = PLDM_REQUEST; |
| 607 | header.instance = instance_id; |
| 608 | header.pldm_type = PLDM_OEM; |
| 609 | header.command = PLDM_NEW_FILE_AVAILABLE; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 610 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 611 | if (rc != PLDM_SUCCESS) { |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 612 | return rc; |
| 613 | } |
| 614 | |
| 615 | struct pldm_new_file_req *req = |
| 616 | (struct pldm_new_file_req *)msg->payload; |
| 617 | req->file_type = htole16(file_type); |
| 618 | req->file_handle = htole32(file_handle); |
Deepak Kodihalli | 8338876 | 2020-01-28 04:09:58 -0600 | [diff] [blame] | 619 | req->length = htole64(length); |
vkaverap | a9aac72 | 2019-08-22 02:10:15 -0500 | [diff] [blame] | 620 | |
| 621 | return PLDM_SUCCESS; |
| 622 | } |
| 623 | |
| 624 | int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length, |
| 625 | uint8_t *completion_code) |
| 626 | { |
| 627 | if (msg == NULL || completion_code == NULL) { |
| 628 | return PLDM_ERROR_INVALID_DATA; |
| 629 | } |
| 630 | |
| 631 | if (payload_length != PLDM_NEW_FILE_RESP_BYTES) { |
| 632 | return PLDM_ERROR_INVALID_LENGTH; |
| 633 | } |
| 634 | |
| 635 | struct pldm_new_file_resp *response = |
| 636 | (struct pldm_new_file_resp *)msg->payload; |
| 637 | *completion_code = response->completion_code; |
| 638 | |
| 639 | return PLDM_SUCCESS; |
| 640 | } |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 641 | |
| 642 | int decode_rw_file_by_type_req(const struct pldm_msg *msg, |
| 643 | size_t payload_length, uint16_t *file_type, |
| 644 | uint32_t *file_handle, uint32_t *offset, |
| 645 | uint32_t *length) |
| 646 | { |
| 647 | if (msg == NULL || file_type == NULL || file_handle == NULL || |
| 648 | offset == NULL || length == NULL) { |
| 649 | return PLDM_ERROR_INVALID_DATA; |
| 650 | } |
| 651 | |
Sampa Misra | d823cc0 | 2020-03-24 04:53:20 -0500 | [diff] [blame] | 652 | if (payload_length < PLDM_RW_FILE_BY_TYPE_REQ_BYTES) { |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 653 | return PLDM_ERROR_INVALID_LENGTH; |
| 654 | } |
| 655 | |
| 656 | struct pldm_read_write_file_by_type_req *request = |
| 657 | (struct pldm_read_write_file_by_type_req *)msg->payload; |
| 658 | *file_type = le16toh(request->file_type); |
| 659 | *file_handle = le32toh(request->file_handle); |
| 660 | *offset = le32toh(request->offset); |
| 661 | *length = le32toh(request->length); |
| 662 | |
| 663 | return PLDM_SUCCESS; |
| 664 | } |
| 665 | |
| 666 | int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command, |
| 667 | uint8_t completion_code, uint32_t length, |
| 668 | struct pldm_msg *msg) |
| 669 | { |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 670 | if (msg == NULL) { |
| 671 | return PLDM_ERROR_INVALID_DATA; |
| 672 | } |
| 673 | if (command != PLDM_READ_FILE_BY_TYPE && |
| 674 | command != PLDM_WRITE_FILE_BY_TYPE) { |
| 675 | return PLDM_ERROR_INVALID_DATA; |
| 676 | } |
| 677 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 678 | struct pldm_header_info header = {0}; |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 679 | header.msg_type = PLDM_RESPONSE; |
| 680 | header.instance = instance_id; |
| 681 | header.pldm_type = PLDM_OEM; |
| 682 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 683 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 684 | if (rc != PLDM_SUCCESS) { |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 685 | return rc; |
| 686 | } |
| 687 | |
| 688 | struct pldm_read_write_file_by_type_resp *response = |
| 689 | (struct pldm_read_write_file_by_type_resp *)msg->payload; |
| 690 | response->completion_code = completion_code; |
| 691 | if (response->completion_code == PLDM_SUCCESS) { |
| 692 | response->length = htole32(length); |
| 693 | } |
| 694 | |
| 695 | return PLDM_SUCCESS; |
| 696 | } |
| 697 | |
| 698 | int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command, |
| 699 | uint16_t file_type, uint32_t file_handle, |
| 700 | uint32_t offset, uint32_t length, |
| 701 | struct pldm_msg *msg) |
| 702 | { |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 703 | if (msg == NULL) { |
| 704 | return PLDM_ERROR_INVALID_DATA; |
| 705 | } |
| 706 | if (command != PLDM_READ_FILE_BY_TYPE && |
| 707 | command != PLDM_WRITE_FILE_BY_TYPE) { |
| 708 | return PLDM_ERROR_INVALID_DATA; |
| 709 | } |
| 710 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 711 | struct pldm_header_info header = {0}; |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 712 | header.msg_type = PLDM_REQUEST; |
| 713 | header.instance = instance_id; |
| 714 | header.pldm_type = PLDM_OEM; |
| 715 | header.command = command; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 716 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 717 | if (rc != PLDM_SUCCESS) { |
Deepak Kodihalli | dce1c99 | 2019-11-19 07:06:53 -0600 | [diff] [blame] | 718 | return rc; |
| 719 | } |
| 720 | |
| 721 | struct pldm_read_write_file_by_type_req *req = |
| 722 | (struct pldm_read_write_file_by_type_req *)msg->payload; |
| 723 | req->file_type = htole16(file_type); |
| 724 | req->file_handle = htole32(file_handle); |
| 725 | req->offset = htole32(offset); |
| 726 | req->length = htole32(length); |
| 727 | |
| 728 | return PLDM_SUCCESS; |
| 729 | } |
| 730 | |
| 731 | int decode_rw_file_by_type_resp(const struct pldm_msg *msg, |
| 732 | size_t payload_length, uint8_t *completion_code, |
| 733 | uint32_t *length) |
| 734 | { |
| 735 | if (msg == NULL || length == NULL || completion_code == NULL) { |
| 736 | return PLDM_ERROR_INVALID_DATA; |
| 737 | } |
| 738 | |
| 739 | if (payload_length != PLDM_RW_FILE_BY_TYPE_RESP_BYTES) { |
| 740 | return PLDM_ERROR_INVALID_LENGTH; |
| 741 | } |
| 742 | |
| 743 | struct pldm_read_write_file_by_type_resp *response = |
| 744 | (struct pldm_read_write_file_by_type_resp *)msg->payload; |
| 745 | *completion_code = response->completion_code; |
| 746 | if (*completion_code == PLDM_SUCCESS) { |
| 747 | *length = le32toh(response->length); |
| 748 | } |
| 749 | |
| 750 | return PLDM_SUCCESS; |
| 751 | } |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 752 | |
| 753 | int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length, |
| 754 | uint16_t *file_type, uint32_t *file_handle, |
| 755 | uint8_t *file_status) |
| 756 | { |
| 757 | if (msg == NULL || file_type == NULL || file_handle == NULL) { |
| 758 | return PLDM_ERROR_INVALID_DATA; |
| 759 | } |
| 760 | |
| 761 | if (payload_length != PLDM_FILE_ACK_REQ_BYTES) { |
| 762 | return PLDM_ERROR_INVALID_LENGTH; |
| 763 | } |
| 764 | |
| 765 | struct pldm_file_ack_req *request = |
| 766 | (struct pldm_file_ack_req *)msg->payload; |
| 767 | *file_type = le16toh(request->file_type); |
| 768 | *file_handle = le32toh(request->file_handle); |
| 769 | *file_status = request->file_status; |
| 770 | |
| 771 | return PLDM_SUCCESS; |
| 772 | } |
| 773 | |
| 774 | int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code, |
| 775 | struct pldm_msg *msg) |
| 776 | { |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 777 | if (msg == NULL) { |
| 778 | return PLDM_ERROR_INVALID_DATA; |
| 779 | } |
| 780 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 781 | struct pldm_header_info header = {0}; |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 782 | header.msg_type = PLDM_RESPONSE; |
| 783 | header.instance = instance_id; |
| 784 | header.pldm_type = PLDM_OEM; |
| 785 | header.command = PLDM_FILE_ACK; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 786 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 787 | if (rc != PLDM_SUCCESS) { |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 788 | return rc; |
| 789 | } |
| 790 | |
| 791 | struct pldm_file_ack_resp *response = |
| 792 | (struct pldm_file_ack_resp *)msg->payload; |
| 793 | response->completion_code = completion_code; |
| 794 | |
| 795 | return PLDM_SUCCESS; |
| 796 | } |
| 797 | |
| 798 | int encode_file_ack_req(uint8_t instance_id, uint16_t file_type, |
| 799 | uint32_t file_handle, uint8_t file_status, |
| 800 | struct pldm_msg *msg) |
| 801 | { |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 802 | if (msg == NULL) { |
| 803 | return PLDM_ERROR_INVALID_DATA; |
| 804 | } |
| 805 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 806 | struct pldm_header_info header = {0}; |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 807 | header.msg_type = PLDM_REQUEST; |
| 808 | header.instance = instance_id; |
| 809 | header.pldm_type = PLDM_OEM; |
| 810 | header.command = PLDM_FILE_ACK; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 811 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 812 | if (rc != PLDM_SUCCESS) { |
vkaverap | f4e0a49 | 2019-11-19 01:47:35 -0600 | [diff] [blame] | 813 | return rc; |
| 814 | } |
| 815 | |
| 816 | struct pldm_file_ack_req *req = |
| 817 | (struct pldm_file_ack_req *)msg->payload; |
| 818 | req->file_type = htole16(file_type); |
| 819 | req->file_handle = htole32(file_handle); |
| 820 | req->file_status = file_status; |
| 821 | |
| 822 | return PLDM_SUCCESS; |
| 823 | } |
| 824 | |
| 825 | int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length, |
| 826 | uint8_t *completion_code) |
| 827 | { |
| 828 | if (msg == NULL || completion_code == NULL) { |
| 829 | return PLDM_ERROR_INVALID_DATA; |
| 830 | } |
| 831 | |
| 832 | if (payload_length != PLDM_FILE_ACK_RESP_BYTES) { |
| 833 | return PLDM_ERROR_INVALID_LENGTH; |
| 834 | } |
| 835 | |
| 836 | struct pldm_file_ack_resp *response = |
| 837 | (struct pldm_file_ack_resp *)msg->payload; |
| 838 | *completion_code = response->completion_code; |
| 839 | |
| 840 | return PLDM_SUCCESS; |
| 841 | } |