blob: 4b3de54e83f626aaad3edd874010ae6f4e5c30d0 [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 */
7
8#include <common/debug.h>
9#include "rss_comms_protocol.h"
10
11psa_status_t rss_protocol_serialize_msg(psa_handle_t handle,
12 int16_t type,
13 const psa_invec *in_vec,
14 uint8_t in_len,
15 const psa_outvec *out_vec,
16 uint8_t out_len,
17 struct serialized_rss_comms_msg_t *msg,
18 size_t *msg_len)
19{
20 psa_status_t status;
21
22 assert(msg != NULL);
23 assert(msg_len != NULL);
24 assert(in_vec != NULL);
25 assert(out_vec != NULL);
26
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);
60 assert(out_vec != NULL);
61 assert(return_val != NULL);
62
63 switch (reply->header.protocol_ver) {
64 case RSS_COMMS_PROTOCOL_EMBED:
65 return rss_protocol_embed_deserialize_reply(out_vec, out_len, return_val,
66 &reply->reply.embed, reply_size);
67 case RSS_COMMS_PROTOCOL_POINTER_ACCESS:
68 return rss_protocol_pointer_access_deserialize_reply(out_vec, out_len, return_val,
69 &reply->reply.pointer_access,
70 reply_size);
71 default:
72 return PSA_ERROR_NOT_SUPPORTED;
73 }
74
75 return PSA_SUCCESS;
76}