blob: 0495ac50571de588ab38919146297f35004077e6 [file] [log] [blame]
Delphine CC Chiu22fad392023-10-27 11:05:01 +08001/* 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 Jefferya98814f2023-11-30 12:30:34 +10309LIBPLDM_ABI_STABLE
Delphine CC Chiu22fad392023-10-27 11:05:01 +080010int 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;
16
17 if (msg == NULL || file_handle == NULL || length == NULL ||
18 data == NULL) {
19 return PLDM_ERROR_INVALID_DATA;
20 }
21
22 int rc = pldm_msgbuf_init(buf,
23 PLDM_OEM_META_DECODE_WRITE_FILE_IO_MIN_SIZE,
24 msg->payload, payload_length);
25 if (rc) {
26 return rc;
27 }
28
Andrew Jeffery66c77232024-04-24 11:42:02 +093029 pldm_msgbuf_extract_p(buf, file_handle);
30 pldm_msgbuf_extract_p(buf, length);
Delphine CC Chiu22fad392023-10-27 11:05:01 +080031 pldm_msgbuf_extract_array_uint8(buf, data, *length);
32
33 return pldm_msgbuf_destroy_consumed(buf);
34}