dsp: file: Add decode req & encode resp for DfOpen & DfClose command
Add encode/decode APIs for DfOpen & DfClose command
which are defined in DSP0242 Version 1.0.0 Section 9.2 & 9.3
Change-Id: I249b3c915b3d0a2c35be31c808a84d0800637b68
Signed-off-by: John Chung <john.chung@arm.com>
diff --git a/src/dsp/file.c b/src/dsp/file.c
index fb3d1de..988d284 100644
--- a/src/dsp/file.c
+++ b/src/dsp/file.c
@@ -49,6 +49,67 @@
}
LIBPLDM_ABI_TESTING
+int decode_pldm_file_df_open_req(const struct pldm_msg *msg,
+ size_t payload_length,
+ struct pldm_file_df_open_req *req)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ int rc;
+
+ if (!msg || !req) {
+ return -EINVAL;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_DF_OPEN_REQ_BYTES, msg->payload,
+ payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_extract(buf, req->file_identifier);
+ pldm_msgbuf_extract(buf, req->file_attribute.value);
+
+ return pldm_msgbuf_complete_consumed(buf);
+}
+
+LIBPLDM_ABI_TESTING
+int encode_pldm_file_df_open_resp(uint8_t instance_id,
+ const struct pldm_file_df_open_resp *resp,
+ struct pldm_msg *msg, size_t *payload_length)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ int rc;
+
+ if (!msg || !resp) {
+ return -EINVAL;
+ }
+
+ struct pldm_header_info header = { 0 };
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FILE;
+ header.command = PLDM_FILE_CMD_DF_OPEN;
+
+ rc = pack_pldm_header_errno(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_DF_OPEN_RESP_BYTES, msg->payload,
+ *payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_insert(buf, resp->completion_code);
+ if (resp->completion_code == PLDM_SUCCESS) {
+ pldm_msgbuf_insert(buf, resp->file_descriptor);
+ }
+
+ return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
+}
+
+LIBPLDM_ABI_TESTING
int decode_pldm_file_df_open_resp(const struct pldm_msg *msg,
size_t payload_length,
struct pldm_file_df_open_resp *resp)
@@ -73,6 +134,11 @@
}
pldm_msgbuf_extract(buf, resp->completion_code);
+ if (resp->completion_code != PLDM_SUCCESS) {
+ // Return the CC directly without decoding the rest of the payload
+ return pldm_msgbuf_complete(buf);
+ }
+
pldm_msgbuf_extract(buf, resp->file_descriptor);
return pldm_msgbuf_complete_consumed(buf);
@@ -114,6 +180,64 @@
}
LIBPLDM_ABI_TESTING
+int decode_pldm_file_df_close_req(const struct pldm_msg *msg,
+ size_t payload_length,
+ struct pldm_file_df_close_req *req)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ int rc;
+
+ if (!msg || !req) {
+ return -EINVAL;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_DF_CLOSE_REQ_BYTES, msg->payload,
+ payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_extract(buf, req->file_descriptor);
+ pldm_msgbuf_extract(buf, req->df_close_options.value);
+
+ return pldm_msgbuf_complete_consumed(buf);
+}
+
+LIBPLDM_ABI_TESTING
+int encode_pldm_file_df_close_resp(uint8_t instance_id,
+ const struct pldm_file_df_close_resp *resp,
+ struct pldm_msg *msg, size_t *payload_length)
+{
+ PLDM_MSGBUF_DEFINE_P(buf);
+ int rc;
+
+ if (!msg || !resp) {
+ return -EINVAL;
+ }
+
+ struct pldm_header_info header = { 0 };
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.pldm_type = PLDM_FILE;
+ header.command = PLDM_FILE_CMD_DF_CLOSE;
+
+ rc = pack_pldm_header_errno(&header, &(msg->hdr));
+ if (rc) {
+ return rc;
+ }
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_DF_CLOSE_RESP_BYTES, msg->payload,
+ *payload_length);
+ if (rc) {
+ return rc;
+ }
+
+ pldm_msgbuf_insert(buf, resp->completion_code);
+
+ return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
+}
+
+LIBPLDM_ABI_TESTING
int decode_pldm_file_df_close_resp(const struct pldm_msg *msg,
size_t payload_length,
struct pldm_file_df_close_resp *resp)