blob: 05dba3bede23e046a92388834f138f8d6770d7a2 [file] [log] [blame]
Chau Lycf26f2a2025-03-18 10:39:03 +00001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2#include "dsp/base.h"
3#include "msgbuf.h"
4
5#include <libpldm/base.h>
6#include <libpldm/file.h>
7#include <libpldm/utils.h>
8
9#include <assert.h>
10#include <errno.h>
11#include <stdbool.h>
12#include <stdint.h>
13#include <string.h>
14#include <stdlib.h>
15
16LIBPLDM_ABI_TESTING
17int encode_pldm_file_df_open_req(uint8_t instance_id,
18 const struct pldm_file_df_open_req *req,
19 struct pldm_msg *msg, size_t payload_length)
20{
21 PLDM_MSGBUF_DEFINE_P(buf);
22 int rc;
23
24 if (req == NULL || msg == NULL) {
25 return -EINVAL;
26 }
27
28 struct pldm_header_info header = { 0 };
29 header.instance = instance_id;
30 header.msg_type = PLDM_REQUEST;
31 header.pldm_type = PLDM_FILE;
32 header.command = PLDM_FILE_CMD_DF_OPEN;
33
34 rc = pack_pldm_header_errno(&header, &(msg->hdr));
35 if (rc) {
36 return rc;
37 }
38
39 rc = pldm_msgbuf_init_errno(buf, PLDM_DF_OPEN_REQ_BYTES, msg->payload,
40 payload_length);
41 if (rc) {
42 return rc;
43 }
44
45 pldm_msgbuf_insert(buf, req->file_identifier);
46 pldm_msgbuf_insert(buf, req->file_attribute.value);
47
48 return pldm_msgbuf_complete(buf);
49}
50
51LIBPLDM_ABI_TESTING
52int decode_pldm_file_df_open_resp(const struct pldm_msg *msg,
53 size_t payload_length,
54 struct pldm_file_df_open_resp *resp)
55{
56 PLDM_MSGBUF_DEFINE_P(buf);
57 int rc;
58
59 if (!msg || !resp) {
60 return -EINVAL;
61 }
62
63 rc = pldm_msg_has_error(msg, payload_length);
64 if (rc) {
65 resp->completion_code = rc;
66 return 0;
67 }
68
69 rc = pldm_msgbuf_init_errno(buf, PLDM_DF_OPEN_RESP_BYTES, msg->payload,
70 payload_length);
71 if (rc) {
72 return rc;
73 }
74
75 pldm_msgbuf_extract(buf, resp->completion_code);
76 pldm_msgbuf_extract(buf, resp->file_descriptor);
77
78 return pldm_msgbuf_complete_consumed(buf);
79}
Chau Ly7286ca62025-03-26 05:47:18 +000080
81LIBPLDM_ABI_TESTING
82int encode_pldm_file_df_close_req(uint8_t instance_id,
83 const struct pldm_file_df_close_req *req,
84 struct pldm_msg *msg, size_t payload_length)
85{
86 PLDM_MSGBUF_DEFINE_P(buf);
87 int rc;
88
89 if (!req || !msg) {
90 return -EINVAL;
91 }
92
93 struct pldm_header_info header = { 0 };
94 header.instance = instance_id;
95 header.msg_type = PLDM_REQUEST;
96 header.pldm_type = PLDM_FILE;
97 header.command = PLDM_FILE_CMD_DF_CLOSE;
98
99 rc = pack_pldm_header_errno(&header, &(msg->hdr));
100 if (rc) {
101 return rc;
102 }
103
104 rc = pldm_msgbuf_init_errno(buf, PLDM_DF_CLOSE_REQ_BYTES, msg->payload,
105 payload_length);
106 if (rc) {
107 return rc;
108 }
109
110 pldm_msgbuf_insert(buf, req->file_descriptor);
111 pldm_msgbuf_insert(buf, req->df_close_options.value);
112
113 return pldm_msgbuf_complete(buf);
114}
115
116LIBPLDM_ABI_TESTING
117int decode_pldm_file_df_close_resp(const struct pldm_msg *msg,
118 size_t payload_length,
119 struct pldm_file_df_close_resp *resp)
120{
121 if (!msg || !resp) {
122 return -EINVAL;
123 }
124
125 resp->completion_code = pldm_msg_has_error(msg, payload_length);
126
127 return 0;
128}