rse_comms_protocol.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2022, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <assert.h>
  8. #include <common/debug.h>
  9. #include "rse_comms_protocol.h"
  10. psa_status_t rse_protocol_serialize_msg(psa_handle_t handle,
  11. int16_t type,
  12. const psa_invec *in_vec,
  13. uint8_t in_len,
  14. const psa_outvec *out_vec,
  15. uint8_t out_len,
  16. struct serialized_rse_comms_msg_t *msg,
  17. size_t *msg_len)
  18. {
  19. psa_status_t status;
  20. assert(msg != NULL);
  21. assert(msg_len != NULL);
  22. assert(in_vec != NULL);
  23. switch (msg->header.protocol_ver) {
  24. case RSE_COMMS_PROTOCOL_EMBED:
  25. status = rse_protocol_embed_serialize_msg(handle, type, in_vec, in_len, out_vec,
  26. out_len, &msg->msg.embed, msg_len);
  27. if (status != PSA_SUCCESS) {
  28. return status;
  29. }
  30. break;
  31. case RSE_COMMS_PROTOCOL_POINTER_ACCESS:
  32. status = rse_protocol_pointer_access_serialize_msg(handle, type, in_vec, in_len,
  33. out_vec, out_len,
  34. &msg->msg.pointer_access,
  35. msg_len);
  36. if (status != PSA_SUCCESS) {
  37. return status;
  38. }
  39. break;
  40. default:
  41. return PSA_ERROR_NOT_SUPPORTED;
  42. }
  43. *msg_len += sizeof(struct serialized_rse_comms_header_t);
  44. return PSA_SUCCESS;
  45. }
  46. psa_status_t rse_protocol_deserialize_reply(psa_outvec *out_vec,
  47. uint8_t out_len,
  48. psa_status_t *return_val,
  49. const struct serialized_rse_comms_reply_t *reply,
  50. size_t reply_size)
  51. {
  52. assert(reply != NULL);
  53. assert(return_val != NULL);
  54. switch (reply->header.protocol_ver) {
  55. case RSE_COMMS_PROTOCOL_EMBED:
  56. return rse_protocol_embed_deserialize_reply(out_vec, out_len, return_val,
  57. &reply->reply.embed, reply_size);
  58. case RSE_COMMS_PROTOCOL_POINTER_ACCESS:
  59. return rse_protocol_pointer_access_deserialize_reply(out_vec, out_len, return_val,
  60. &reply->reply.pointer_access,
  61. reply_size);
  62. default:
  63. return PSA_ERROR_NOT_SUPPORTED;
  64. }
  65. return PSA_SUCCESS;
  66. }