Delphine CC Chiu | 22fad39 | 2023-10-27 11:05:01 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
| 2 | #include <libpldm/oem/meta/file_io.h> |
| 3 | #include <endian.h> |
| 4 | #include <string.h> |
| 5 | #include <stdio.h> |
| 6 | #include "msgbuf.h" |
| 7 | |
| 8 | #define PLDM_OEM_META_DECODE_WRITE_FILE_IO_MIN_SIZE 6 |
Andrew Jeffery | a98814f | 2023-11-30 12:30:34 +1030 | [diff] [blame] | 9 | LIBPLDM_ABI_STABLE |
Delphine CC Chiu | 22fad39 | 2023-10-27 11:05:01 +0800 | [diff] [blame] | 10 | int decode_oem_meta_file_io_req(const struct pldm_msg *msg, |
| 11 | size_t payload_length, uint8_t *file_handle, |
| 12 | uint32_t *length, uint8_t *data) |
| 13 | { |
| 14 | struct pldm_msgbuf _buf; |
| 15 | struct pldm_msgbuf *buf = &_buf; |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 16 | int rc; |
Delphine CC Chiu | 22fad39 | 2023-10-27 11:05:01 +0800 | [diff] [blame] | 17 | |
| 18 | if (msg == NULL || file_handle == NULL || length == NULL || |
| 19 | data == NULL) { |
| 20 | return PLDM_ERROR_INVALID_DATA; |
| 21 | } |
| 22 | |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 23 | rc = pldm_msgbuf_init_cc(buf, |
| 24 | PLDM_OEM_META_DECODE_WRITE_FILE_IO_MIN_SIZE, |
| 25 | msg->payload, payload_length); |
Delphine CC Chiu | 22fad39 | 2023-10-27 11:05:01 +0800 | [diff] [blame] | 26 | if (rc) { |
| 27 | return rc; |
| 28 | } |
| 29 | |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 30 | pldm_msgbuf_extract_p(buf, file_handle); |
| 31 | pldm_msgbuf_extract_p(buf, length); |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame] | 32 | |
| 33 | /* NOTE: Memory safety failure */ |
| 34 | rc = pldm_msgbuf_extract_array_uint8(buf, (size_t)(*length), data, |
| 35 | UINT32_MAX); |
| 36 | if (rc) { |
| 37 | return rc; |
| 38 | } |
Delphine CC Chiu | 22fad39 | 2023-10-27 11:05:01 +0800 | [diff] [blame] | 39 | |
| 40 | return pldm_msgbuf_destroy_consumed(buf); |
| 41 | } |