blob: a1b1b58cb051ef5828b55975f278ef70637fd4d6 [file] [log] [blame]
Raef Coles734aaac2022-06-15 14:37:22 +01001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Tamas Band1bbcbe2022-10-03 15:34:02 +02007#include <assert.h>
Raef Coles734aaac2022-06-15 14:37:22 +01008
9#include <common/debug.h>
10#include "rss_comms_protocol.h"
11
12psa_status_t rss_protocol_serialize_msg(psa_handle_t handle,
13 int16_t type,
14 const psa_invec *in_vec,
15 uint8_t in_len,
16 const psa_outvec *out_vec,
17 uint8_t out_len,
18 struct serialized_rss_comms_msg_t *msg,
19 size_t *msg_len)
20{
21 psa_status_t status;
22
23 assert(msg != NULL);
24 assert(msg_len != NULL);
25 assert(in_vec != NULL);
Raef Coles734aaac2022-06-15 14:37:22 +010026
27 switch (msg->header.protocol_ver) {
28 case RSS_COMMS_PROTOCOL_EMBED:
29 status = rss_protocol_embed_serialize_msg(handle, type, in_vec, in_len, out_vec,
30 out_len, &msg->msg.embed, msg_len);
31 if (status != PSA_SUCCESS) {
32 return status;
33 }
34 break;
35 case RSS_COMMS_PROTOCOL_POINTER_ACCESS:
36 status = rss_protocol_pointer_access_serialize_msg(handle, type, in_vec, in_len,
37 out_vec, out_len,
38 &msg->msg.pointer_access,
39 msg_len);
40 if (status != PSA_SUCCESS) {
41 return status;
42 }
43 break;
44 default:
45 return PSA_ERROR_NOT_SUPPORTED;
46 }
47
48 *msg_len += sizeof(struct serialized_rss_comms_header_t);
49
50 return PSA_SUCCESS;
51}
52
53psa_status_t rss_protocol_deserialize_reply(psa_outvec *out_vec,
54 uint8_t out_len,
55 psa_status_t *return_val,
56 const struct serialized_rss_comms_reply_t *reply,
57 size_t reply_size)
58{
59 assert(reply != NULL);
Raef Coles734aaac2022-06-15 14:37:22 +010060 assert(return_val != NULL);
61
62 switch (reply->header.protocol_ver) {
63 case RSS_COMMS_PROTOCOL_EMBED:
64 return rss_protocol_embed_deserialize_reply(out_vec, out_len, return_val,
65 &reply->reply.embed, reply_size);
66 case RSS_COMMS_PROTOCOL_POINTER_ACCESS:
67 return rss_protocol_pointer_access_deserialize_reply(out_vec, out_len, return_val,
68 &reply->reply.pointer_access,
69 reply_size);
70 default:
71 return PSA_ERROR_NOT_SUPPORTED;
72 }
73
74 return PSA_SUCCESS;
75}