aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulhal01 <julian.hall@arm.com>2020-12-15 13:39:01 +0000
committerGyorgy Szing <Gyorgy.Szing@arm.com>2021-04-14 16:59:03 +0200
commitc3f4e9a7550ee4fddf2d24127ef33ca514351806 (patch)
treee61b25f7a93ea4ed2f26363186cc236aba06dd24
parent35c6d643b5f0c0387702e22bf742dd4878ca5ddd (diff)
downloadtrusted-services-c3f4e9a7550ee4fddf2d24127ef33ca514351806.tar.gz
Extend RPC parameters
The RPC model is extended to include parameters for identifying an RPC interface instance at an endpoint and another for identifying the parameter encoding. The interface ID parameter allows multiple service interfaces to be co-located. The encoding parameter allows clients to use different parameter serialization schemes and to specify the format in each RPC request. Signed-off-by: julhal01 <julian.hall@arm.com> Change-Id: I201b3417dc0e9f655113b9931db3494e41f1d74b
-rw-r--r--components/app/ts-demo/test/ts-demo_tests.cpp36
-rw-r--r--components/rpc/common/caller/rpc_caller.c16
-rw-r--r--components/rpc/common/endpoint/rpc_interface.h (renamed from components/rpc/common/endpoint/call_ep.h)48
-rw-r--r--components/rpc/common/interface/rpc_caller.h16
-rw-r--r--components/rpc/direct/direct_caller.c18
-rw-r--r--components/rpc/direct/direct_caller.h10
-rw-r--r--components/rpc/dummy/dummy_caller.c4
-rw-r--r--components/rpc/dummy/dummy_caller.h2
-rw-r--r--components/rpc/ffarpc/caller/linux/ffarpc_caller.c272
-rw-r--r--components/rpc/ffarpc/caller/linux/ffarpc_caller.h5
-rw-r--r--components/rpc/ffarpc/caller/sp/ffarpc_caller.c69
-rw-r--r--components/rpc/ffarpc/caller/sp/ffarpc_caller.h7
-rw-r--r--components/rpc/ffarpc/endpoint/ffarpc_call_args.h14
-rw-r--r--components/rpc/ffarpc/endpoint/ffarpc_call_ep.c39
-rw-r--r--components/rpc/ffarpc/endpoint/ffarpc_call_ep.h8
-rw-r--r--components/rpc/ffarpc/endpoint/ffarpc_call_ops.h16
-rw-r--r--components/service/common/provider/service_provider.c35
-rw-r--r--components/service/common/provider/service_provider.h29
-rw-r--r--components/service/common/provider/test/service_framework_tests.cpp14
-rw-r--r--components/service/crypto/client/cpp/crypto_client.cpp7
-rw-r--r--components/service/crypto/client/cpp/crypto_client.h4
-rw-r--r--components/service/crypto/client/test/mock/mock_crypto_client.cpp19
-rw-r--r--components/service/crypto/client/test/standalone/standalone_crypto_client.cpp16
-rw-r--r--components/service/crypto/provider/mbedcrypto/crypto_provider.c366
-rw-r--r--components/service/crypto/provider/mbedcrypto/crypto_provider.h20
-rw-r--r--components/service/crypto/provider/serializer/crypto_provider_serializer.h4
-rw-r--r--components/service/crypto/test/service/crypto_service_limit_tests.cpp10
-rw-r--r--components/service/crypto/test/service/crypto_service_op_tests.cpp10
-rw-r--r--components/service/locator/interface/service_locator.h7
-rw-r--r--components/service/locator/linux/ffa/linuxffa_service_context.c7
-rw-r--r--components/service/locator/service_locator.c9
-rw-r--r--components/service/locator/standalone/services/crypto/crypto_service_context.cpp12
-rw-r--r--components/service/locator/standalone/services/crypto/crypto_service_context.h2
-rw-r--r--components/service/locator/standalone/standalone_service_context.cpp14
-rw-r--r--components/service/locator/standalone/standalone_service_context.h10
-rw-r--r--components/service/secure_storage/provider/mock_store/mock_store_provider.c98
-rw-r--r--components/service/secure_storage/provider/mock_store/mock_store_provider.h4
-rw-r--r--components/service/secure_storage/provider/secure_flash_store/sfs_provider.c12
-rw-r--r--components/service/secure_storage/provider/secure_flash_store/sfs_provider.h4
-rw-r--r--components/service/secure_storage/test/its_tests.cpp4
-rw-r--r--deployments/crypto/opteesp/crypto_sp.c12
-rw-r--r--deployments/secure-storage/opteesp/sp.c10
-rw-r--r--deployments/sfs-demo/opteesp/sp.c4
-rw-r--r--deployments/ts-demo/ts-demo.cpp5
-rw-r--r--protocols/rpc/common/packed-c/encoding.h37
-rw-r--r--protocols/rpc/common/packed-c/header.h82
-rw-r--r--protocols/rpc/common/packed-c/status.h27
47 files changed, 884 insertions, 590 deletions
diff --git a/components/app/ts-demo/test/ts-demo_tests.cpp b/components/app/ts-demo/test/ts-demo_tests.cpp
index 98ca5a0..6629557 100644
--- a/components/app/ts-demo/test/ts-demo_tests.cpp
+++ b/components/app/ts-demo/test/ts-demo_tests.cpp
@@ -1,29 +1,53 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <app/ts-demo/ts-demo.h>
-#include <service/crypto/client/test/test_crypto_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
#include <CppUTest/TestHarness.h>
+#include <service_locator.h>
+#include <service/crypto/client/cpp/crypto_client.h>
+
TEST_GROUP(TsDemoTests) {
void setup()
{
- m_crypto_client = test_crypto_client::create_default();
- m_crypto_client->init();
+ struct rpc_caller *caller;
+ int status;
+
+ m_rpc_session_handle = NULL;
+ m_crypto_service_context = NULL;
+ m_crypto_client = NULL;
+
+ service_locator_init();
+
+ m_crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
+ CHECK(m_crypto_service_context);
+
+ m_rpc_session_handle = service_context_open(m_crypto_service_context, TS_RPC_ENCODING_PROTOBUF, &caller);
+ CHECK(m_rpc_session_handle);
+
+ m_crypto_client = new crypto_client(caller);
}
void teardown()
{
- m_crypto_client->deinit();
delete m_crypto_client;
m_crypto_client = NULL;
+
+ service_context_close(m_crypto_service_context, m_rpc_session_handle);
+ m_rpc_session_handle = NULL;
+
+ service_context_relinquish(m_crypto_service_context);
+ m_crypto_service_context = NULL;
}
- test_crypto_client *m_crypto_client;
+ rpc_session_handle m_rpc_session_handle;
+ struct service_context *m_crypto_service_context;
+ crypto_client *m_crypto_client;
};
TEST(TsDemoTests, runTsDemo)
diff --git a/components/rpc/common/caller/rpc_caller.c b/components/rpc/common/caller/rpc_caller.c
index 4fd1e5a..00b559c 100644
--- a/components/rpc/common/caller/rpc_caller.c
+++ b/components/rpc/common/caller/rpc_caller.c
@@ -1,11 +1,25 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <rpc_caller.h>
#include <stdint.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
+
+void rpc_caller_init(struct rpc_caller *s, void *context)
+{
+ s->context = context;
+
+ /* The default encoding scheme - may be overridden by a client */
+ s->encoding = TS_RPC_ENCODING_PACKED_C;
+}
+
+void rpc_caller_set_encoding_scheme(struct rpc_caller *s, uint32_t encoding)
+{
+ s->encoding = encoding;
+}
rpc_call_handle rpc_caller_begin(struct rpc_caller *s,
uint8_t **req_buf, size_t req_len)
diff --git a/components/rpc/common/endpoint/call_ep.h b/components/rpc/common/endpoint/rpc_interface.h
index 1b5d03d..44e5783 100644
--- a/components/rpc/common/endpoint/call_ep.h
+++ b/components/rpc/common/endpoint/rpc_interface.h
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#ifndef CALL_EP_H
-#define CALL_EP_H
+#ifndef RPC_INTERFACE_H
+#define RPC_INTERFACE_H
#include <stddef.h>
#include <stdint.h>
@@ -51,16 +51,6 @@ static inline struct call_param_buf call_param_buf_init_full(void *data,
return v;
}
-/** \brief Serializer for handling call parameters
- *
- * An abstract serializer pointer, used for attaching a concrete
- * serializer to a call request for serializing/deserializing call
- * parameters. The strategy for selecting an appropriate serializer
- * could be hard-coded or dynamic, based on a content type identifier
- * carried by a concrete rpc.
- */
-typedef const void* call_param_serializer_ptr;
-
/** \brief Call request
*
* A call request object represents a request from a client that will
@@ -68,9 +58,10 @@ typedef const void* call_param_serializer_ptr;
*/
struct call_req {
uint32_t caller_id;
+ uint32_t interface_id;
uint32_t opcode;
+ uint32_t encoding;
int opstatus;
- call_param_serializer_ptr serializer;
struct call_param_buf req_buf;
struct call_param_buf resp_buf;
};
@@ -80,11 +71,21 @@ static inline uint32_t call_req_get_caller_id(const struct call_req *req)
return req->caller_id;
}
+static inline uint32_t call_req_get_interface_id(const struct call_req *req)
+{
+ return req->interface_id;
+}
+
static inline uint32_t call_req_get_opcode(const struct call_req *req)
{
return req->opcode;
}
+static inline uint32_t call_req_get_encoding(const struct call_req *req)
+{
+ return req->encoding;
+}
+
static inline int call_req_get_opstatus(const struct call_req *req)
{
return req->opstatus;
@@ -95,11 +96,6 @@ static inline void call_req_set_opstatus(struct call_req *req, int opstatus)
req->opstatus = opstatus;
}
-static inline call_param_serializer_ptr call_req_get_serializer(const struct call_req *req)
-{
- return req->serializer;
-}
-
static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req)
{
return &req->req_buf;
@@ -110,25 +106,25 @@ static inline struct call_param_buf *call_req_get_resp_buf(struct call_req *req)
return &req->resp_buf;
}
-/** \brief Call endpoint
+/** \brief RPC interface
*
- * A generalized call endpoint. Provides a standard interface for a
+ * A generalized RPC interface. Provides a standard interface for a
* call endpoint that handles incoming call requests.
*/
-struct call_ep
+struct rpc_interface
{
void *context;
- rpc_status_t (*receive)(struct call_ep *ep, struct call_req *req);
+ rpc_status_t (*receive)(struct rpc_interface *iface, struct call_req *req);
};
-static inline rpc_status_t call_ep_receive(struct call_ep *ep,
+static inline rpc_status_t rpc_interface_receive(struct rpc_interface *iface,
struct call_req *req)
{
- return ep->receive(ep, req);
+ return iface->receive(iface, req);
}
#ifdef __cplusplus
}
#endif
-#endif /* CALL_EP_H */
+#endif /* RPC_INTERFACE_H */
diff --git a/components/rpc/common/interface/rpc_caller.h b/components/rpc/common/interface/rpc_caller.h
index a75bdd9..879d2cb 100644
--- a/components/rpc/common/interface/rpc_caller.h
+++ b/components/rpc/common/interface/rpc_caller.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -36,6 +36,7 @@ typedef void *rpc_call_handle;
struct rpc_caller
{
void *context;
+ uint32_t encoding;
/* A concrete rpc_caller implements these methods */
rpc_call_handle (*call_begin)(void *context, uint8_t **req_buf, size_t req_len);
@@ -47,6 +48,19 @@ struct rpc_caller
};
/*
+ * Called by a concrete rpc_caller to initialise the base rpc_caller.
+ */
+void rpc_caller_init(struct rpc_caller *s, void *context);
+
+/*
+ * Allows a client to specify the parameter encoding scheme that the client
+ * intends to use during an RPC session. It is the client's responsiblity
+ * to choose an encoding scheme that is supported by the remote interface.
+ */
+RPC_CALLER_EXPORTED void rpc_caller_set_encoding_scheme(struct rpc_caller *s,
+ uint32_t encoding);
+
+/*
* Starts a call transaction. The returned handle is an identifier for the
* transaction and must be passed as a parameter to call_invoke() and
* call_end(). A concrete rpc_caller may perform resource allocation during
diff --git a/components/rpc/direct/direct_caller.c b/components/rpc/direct/direct_caller.c
index 001ee7c..14f1a91 100644
--- a/components/rpc/direct/direct_caller.c
+++ b/components/rpc/direct/direct_caller.c
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "direct_caller.h"
-#include <rpc/common/endpoint/call_ep.h>
+#include <rpc/common/endpoint/rpc_interface.h>
#include <protocols/rpc/common/packed-c/status.h>
#include <stdlib.h>
@@ -18,17 +18,17 @@ static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t
static void call_end(void *context, rpc_call_handle handle);
-struct rpc_caller *direct_caller_init(struct direct_caller *s, struct call_ep *ep,
+struct rpc_caller *direct_caller_init(struct direct_caller *s, struct rpc_interface *iface,
size_t req_buf_size, size_t resp_buf_size)
{
struct rpc_caller *base = &s->rpc_caller;
- base->context = s;
+ rpc_caller_init(base, s);
base->call_begin = call_begin;
base->call_invoke = call_invoke;
base->call_end = call_end;
- s->call_ep = ep;
+ s->rpc_interface = iface;
s->caller_id = 0;
s->is_call_transaction_in_progess = false;
s->req_len = 0;
@@ -47,10 +47,10 @@ struct rpc_caller *direct_caller_init(struct direct_caller *s, struct call_ep *e
return base;
}
-struct rpc_caller *direct_caller_init_default(struct direct_caller *s, struct call_ep *ep)
+struct rpc_caller *direct_caller_init_default(struct direct_caller *s, struct rpc_interface *iface)
{
/* Initialise with default buffer sizes */
- return direct_caller_init(s, ep,
+ return direct_caller_init(s, iface,
DIRECT_CALLER_DEFAULT_REQ_BUF_SIZE,
DIRECT_CALLER_DEFAULT_RESP_BUF_SIZE);
}
@@ -94,7 +94,9 @@ static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t
struct call_req req;
+ req.interface_id = 0;
req.opcode = opcode;
+ req.encoding = this_context->rpc_caller.encoding;
req.caller_id = this_context->caller_id;
req.opstatus = 0;
req.req_buf = call_param_buf_init_full(this_context->req_buf,
@@ -102,7 +104,7 @@ static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t
req.resp_buf = call_param_buf_init_empty(this_context->resp_buf,
this_context->resp_buf_size);
- status = call_ep_receive(this_context->call_ep, &req);
+ status = rpc_interface_receive(this_context->rpc_interface, &req);
*resp_buf = this_context->resp_buf;
*resp_len = call_req_get_resp_buf(&req)->data_len;
diff --git a/components/rpc/direct/direct_caller.h b/components/rpc/direct/direct_caller.h
index 0f51845..fe5ac08 100644
--- a/components/rpc/direct/direct_caller.h
+++ b/components/rpc/direct/direct_caller.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -16,7 +16,7 @@
extern "C" {
#endif
-struct call_ep;
+struct rpc_interface;
/** An rpc_caller that calls methods associated with a specific endpoint
* directly. Used when the caller and endpoint are running in the same
@@ -25,7 +25,7 @@ struct call_ep;
struct direct_caller
{
struct rpc_caller rpc_caller;
- struct call_ep *call_ep;
+ struct rpc_interface *rpc_interface;
uint32_t caller_id;
bool is_call_transaction_in_progess;
size_t req_len;
@@ -35,10 +35,10 @@ struct direct_caller
uint8_t *resp_buf;
};
-struct rpc_caller *direct_caller_init(struct direct_caller *s, struct call_ep *ep,
+struct rpc_caller *direct_caller_init(struct direct_caller *s, struct rpc_interface *iface,
size_t req_buf_size, size_t resp_buf_size);
-struct rpc_caller *direct_caller_init_default(struct direct_caller *s, struct call_ep *ep);
+struct rpc_caller *direct_caller_init_default(struct direct_caller *s, struct rpc_interface *iface);
void direct_caller_deinit(struct direct_caller *s);
diff --git a/components/rpc/dummy/dummy_caller.c b/components/rpc/dummy/dummy_caller.c
index 6d40b80..f55b418 100644
--- a/components/rpc/dummy/dummy_caller.c
+++ b/components/rpc/dummy/dummy_caller.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -18,7 +18,7 @@ struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
{
struct rpc_caller *base = &s->rpc_caller;
- base->context = s;
+ rpc_caller_init(base, s);
base->call_begin = call_begin;
base->call_invoke = call_invoke;
base->call_end = call_end;
diff --git a/components/rpc/dummy/dummy_caller.h b/components/rpc/dummy/dummy_caller.h
index 215d293..27fe68a 100644
--- a/components/rpc/dummy/dummy_caller.h
+++ b/components/rpc/dummy/dummy_caller.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
diff --git a/components/rpc/ffarpc/caller/linux/ffarpc_caller.c b/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
index 70d6ca3..ac628a9 100644
--- a/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
+++ b/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
@@ -21,7 +21,7 @@
static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
- int *opstatus, uint8_t **resp_buf, size_t *resp_len);
+ int *opstatus, uint8_t **resp_buf, size_t *resp_len);
static void call_end(void *context, rpc_call_handle handle);
static int kernel_write_req_buf(struct ffarpc_caller *s);
@@ -35,14 +35,15 @@ struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s, const char *devic
{
struct rpc_caller *base = &s->rpc_caller;
- base->context = s;
+ rpc_caller_init(base, s);
base->call_begin = call_begin;
base->call_invoke = call_invoke;
base->call_end = call_end;
s->device_path = device_path;
s->fd = -1;
- s->call_ep_id = 0;
+ s->dest_partition_id = 0;
+ s->dest_iface_id = 0;
s->shared_mem_handle = 0;
s->shared_mem_required_size = DEFAULT_SHMEM_BUF_SIZE;
s->req_buf = NULL;
@@ -93,12 +94,12 @@ size_t ffarpc_caller_discover(const struct ffarpc_caller *s, const struct uuid_c
}
}
- return discover_count;
+ return discover_count;
}
-int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
+int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t dest_partition_id, uint16_t dest_iface_id)
{
- int ioctl_status = -1;
+ int ioctl_status = -1;
if (s->device_path) {
@@ -110,7 +111,8 @@ int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
if (ioctl_status == 0) {
/* Session successfully opened */
- s->call_ep_id = call_ep_id;
+ s->dest_partition_id = dest_partition_id;
+ s->dest_iface_id = dest_iface_id;
ioctl_status = share_mem_with_partition(s);
}
@@ -122,23 +124,23 @@ int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
}
}
- return ioctl_status;
+ return ioctl_status;
}
int ffarpc_caller_close(struct ffarpc_caller *s)
{
- int ioctl_status = -1;
+ int ioctl_status = -1;
- if (s->fd >= 0) {
+ if (s->fd >= 0) {
- unshare_mem_with_partition(s);
- ioctl_status = ioctl(s->fd, FFA_IOC_SHM_DEINIT);
- close(s->fd);
- s->fd = -1;
- s->call_ep_id = 0;
- }
+ unshare_mem_with_partition(s);
+ ioctl_status = ioctl(s->fd, FFA_IOC_SHM_DEINIT);
+ close(s->fd);
+ s->fd = -1;
+ s->dest_partition_id = 0;
+ }
- return ioctl_status;
+ return ioctl_status;
}
static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len)
@@ -146,96 +148,104 @@ static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_l
rpc_call_handle handle = NULL;
struct ffarpc_caller *s = (struct ffarpc_caller*)context;
- if (!s->is_call_transaction_in_progess) {
+ if (!s->is_call_transaction_in_progess) {
- s->is_call_transaction_in_progess = true;
- handle = s;
+ s->is_call_transaction_in_progess = true;
+ handle = s;
- if (req_len > 0) {
+ if (req_len > 0) {
- s->req_buf = malloc(req_len);
+ s->req_buf = malloc(req_len);
- if (s->req_buf) {
+ if (s->req_buf) {
- *req_buf = s->req_buf;
- s->req_len = req_len;
- }
- else {
- /* Failed to allocate req buffer */
- handle = NULL;
- s->is_call_transaction_in_progess = false;
- }
- }
- else {
+ *req_buf = s->req_buf;
+ s->req_len = req_len;
+ }
+ else {
+ /* Failed to allocate req buffer */
+ handle = NULL;
+ s->is_call_transaction_in_progess = false;
+ }
+ }
+ else {
- *req_buf = NULL;
- s->req_buf = NULL;
- s->req_len = req_len;
- }
- }
+ *req_buf = NULL;
+ s->req_buf = NULL;
+ s->req_len = req_len;
+ }
+ }
- return handle;
+ return handle;
}
static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
- int *opstatus, uint8_t **resp_buf, size_t *resp_len)
+ int *opstatus, uint8_t **resp_buf, size_t *resp_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
struct ffarpc_caller *s = (struct ffarpc_caller*)context;
- if ((handle == s) && s->is_call_transaction_in_progess) {
- int kernel_op_status = 0;
-
- if (s->req_len > 0) {
- kernel_op_status = kernel_write_req_buf(s);
- }
-
- if (kernel_op_status == 0) {
- /* Make direct call to send the request */
- struct ffa_ioctl_msg_args direct_msg;
- memset(&direct_msg, 0, sizeof(direct_msg));
-
- direct_msg.dst_id = s->call_ep_id;
- direct_msg.args[FFA_CALL_ARGS_OPCODE] = (uint64_t)opcode;
- direct_msg.args[FFA_CALL_ARGS_REQ_DATA_LEN] = (uint64_t)s->req_len;
-
- kernel_op_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
-
- if (kernel_op_status == 0) {
- /* Send completed normally - ffa return args in msg_args struct */
- s->resp_len = (size_t)direct_msg.args[FFA_CALL_ARGS_RESP_DATA_LEN];
- rpc_status = (int)direct_msg.args[FFA_CALL_ARGS_RESP_RPC_STATUS];
- *opstatus = (int)direct_msg.args[FFA_CALL_ARGS_RESP_OP_STATUS];
-
- if (s->resp_len > 0) {
- s->resp_buf = malloc(s->resp_len);
-
- if (s->resp_buf) {
- kernel_op_status = kernel_read_resp_buf(s);
-
- if (kernel_op_status != 0) {
- /* Failed to read response buffer */
- rpc_status = TS_RPC_ERROR_INTERNAL;
- }
- }
- else {
- /* Failed to allocate response buffer */
- s->resp_len = 0;
- rpc_status = TS_RPC_ERROR_INTERNAL;
- }
- }
- else {
+ if ((handle == s) && s->is_call_transaction_in_progess) {
+ int kernel_op_status = 0;
+
+ if (s->req_len > 0) {
+ kernel_op_status = kernel_write_req_buf(s);
+ }
+
+ if (kernel_op_status == 0) {
+ /* Make direct call to send the request */
+ struct ffa_ioctl_msg_args direct_msg;
+ memset(&direct_msg, 0, sizeof(direct_msg));
+
+ direct_msg.dst_id = s->dest_partition_id;
+ direct_msg.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(s->dest_partition_id, opcode);
+ direct_msg.args[FFA_CALL_ARGS_REQ_DATA_LEN] = (uint64_t)s->req_len;
+ direct_msg.args[FFA_CALL_ARGS_ENCODING] = s->rpc_caller.encoding;
+
+ /* Initialise the caller ID. Depending on the call path, this may
+ * be overridden by a higher privilege execution level, based on its
+ * perspective of the caller identity.
+ */
+ direct_msg.args[FFA_CALL_ARGS_CALLER_ID] = 0;
+
+ kernel_op_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
+
+ if (kernel_op_status == 0) {
+ /* Send completed normally - ffa return args in msg_args struct */
+ s->resp_len = (size_t)direct_msg.args[FFA_CALL_ARGS_RESP_DATA_LEN];
+ rpc_status = (int)direct_msg.args[FFA_CALL_ARGS_RESP_RPC_STATUS];
+ *opstatus = (int)direct_msg.args[FFA_CALL_ARGS_RESP_OP_STATUS];
+
+ if (s->resp_len > 0) {
+ s->resp_buf = malloc(s->resp_len);
+
+ if (s->resp_buf) {
+ kernel_op_status = kernel_read_resp_buf(s);
+
+ if (kernel_op_status != 0) {
+ /* Failed to read response buffer */
+ rpc_status = TS_RPC_ERROR_INTERNAL;
+ }
+ }
+ else {
+ /* Failed to allocate response buffer */
+ s->resp_len = 0;
+ rpc_status = TS_RPC_ERROR_INTERNAL;
+ }
+ }
+ else {
/* No response parameters */
- s->resp_buf = NULL;
- }
+ s->resp_buf = NULL;
+ }
- *resp_len = s->resp_len;
- *resp_buf = s->resp_buf;
- }
- }
+ *resp_len = s->resp_len;
+ *resp_buf = s->resp_buf;
+ }
+ }
}
- return rpc_status;
+ return rpc_status;
}
static void call_end(void *context, rpc_call_handle handle)
@@ -244,73 +254,75 @@ static void call_end(void *context, rpc_call_handle handle)
if ((handle == s) && s->is_call_transaction_in_progess) {
- /* Call transaction complete so free resource */
- free(s->req_buf);
- s->req_buf = NULL;
- s->req_len = 0;
+ /* Call transaction complete so free resource */
+ free(s->req_buf);
+ s->req_buf = NULL;
+ s->req_len = 0;
- free(s->resp_buf);
- s->resp_buf = NULL;
- s->resp_len = 0;
+ free(s->resp_buf);
+ s->resp_buf = NULL;
+ s->resp_len = 0;
- s->is_call_transaction_in_progess = false;
- }
+ s->is_call_transaction_in_progess = false;
+ }
}
static int kernel_write_req_buf(struct ffarpc_caller *s) {
- int ioctl_status;
- struct ffa_ioctl_buf_desc req_descr;
+ int ioctl_status;
+ struct ffa_ioctl_buf_desc req_descr;
- req_descr.buf_ptr = (uintptr_t)s->req_buf;
- req_descr.buf_len = s->req_len;
- ioctl_status = ioctl(s->fd, FFA_IOC_SHM_WRITE, &req_descr);
+ req_descr.buf_ptr = (uintptr_t)s->req_buf;
+ req_descr.buf_len = s->req_len;
+ ioctl_status = ioctl(s->fd, FFA_IOC_SHM_WRITE, &req_descr);
- return ioctl_status;
+ return ioctl_status;
}
static int kernel_read_resp_buf(struct ffarpc_caller *s) {
- int ioctl_status;
- struct ffa_ioctl_buf_desc resp_descr;
+ int ioctl_status;
+ struct ffa_ioctl_buf_desc resp_descr;
- resp_descr.buf_ptr = (uintptr_t)s->resp_buf;
- resp_descr.buf_len = s->resp_len;
- ioctl_status = ioctl(s->fd, FFA_IOC_SHM_READ, &resp_descr);
+ resp_descr.buf_ptr = (uintptr_t)s->resp_buf;
+ resp_descr.buf_len = s->resp_len;
+ ioctl_status = ioctl(s->fd, FFA_IOC_SHM_READ, &resp_descr);
- return ioctl_status;
+ return ioctl_status;
}
static int share_mem_with_partition(struct ffarpc_caller *s) {
- int ioctl_status;
- struct ffa_ioctl_msg_args direct_msg;
- memset(&direct_msg, 0, sizeof(direct_msg));
+ int ioctl_status;
+ struct ffa_ioctl_msg_args direct_msg;
+ memset(&direct_msg, 0, sizeof(direct_msg));
- direct_msg.dst_id = s->call_ep_id;
- direct_msg.args[FFA_CALL_ARGS_OPCODE] = (uint64_t)FFA_CALL_OPCODE_SHARE_BUF;
- direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)s->shared_mem_handle;
- direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = (uint32_t)(s->shared_mem_handle >> 32);
- direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_SIZE] = (uint64_t)s->shared_mem_required_size;
+ direct_msg.dst_id = s->dest_partition_id;
+ direct_msg.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(FFA_CALL_MGMT_IFACE_ID, FFA_CALL_OPCODE_SHARE_BUF);
+ direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)s->shared_mem_handle;
+ direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = (uint32_t)(s->shared_mem_handle >> 32);
+ direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_SIZE] = (uint64_t)s->shared_mem_required_size;
- ioctl_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
+ ioctl_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
- return ioctl_status;
+ return ioctl_status;
}
static int unshare_mem_with_partition(struct ffarpc_caller *s) {
- int ioctl_status;
- struct ffa_ioctl_msg_args direct_msg;
- memset(&direct_msg, 0, sizeof(direct_msg));
+ int ioctl_status;
+ struct ffa_ioctl_msg_args direct_msg;
+ memset(&direct_msg, 0, sizeof(direct_msg));
- direct_msg.dst_id = s->call_ep_id;
- direct_msg.args[FFA_CALL_ARGS_OPCODE] = (uint64_t)FFA_CALL_OPCODE_UNSHARE_BUF;
- direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)s->shared_mem_handle;
- direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = (uint32_t)(s->shared_mem_handle >> 32);
+ direct_msg.dst_id = s->dest_partition_id;
+ direct_msg.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(FFA_CALL_MGMT_IFACE_ID, FFA_CALL_OPCODE_UNSHARE_BUF);
+ direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)s->shared_mem_handle;
+ direct_msg.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = (uint32_t)(s->shared_mem_handle >> 32);
- ioctl_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
+ ioctl_status = ioctl(s->fd, FFA_IOC_MSG_SEND, &direct_msg);
- return ioctl_status;
+ return ioctl_status;
}
diff --git a/components/rpc/ffarpc/caller/linux/ffarpc_caller.h b/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
index 7e846ba..c81382e 100644
--- a/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
+++ b/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
@@ -24,7 +24,8 @@ struct ffarpc_caller {
struct rpc_caller rpc_caller;
int fd;
const char *device_path;
- uint16_t call_ep_id;
+ uint16_t dest_partition_id;
+ uint16_t dest_iface_id;
uint64_t shared_mem_handle;
size_t shared_mem_required_size;
uint8_t *req_buf;
@@ -38,7 +39,7 @@ struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s, const char *devic
void ffarpc_caller_deinit(struct ffarpc_caller *s);
size_t ffarpc_caller_discover(const struct ffarpc_caller *s, const struct uuid_canonical *uuid,
uint16_t *partition_ids, size_t discover_limit);
-int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id);
+int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t dest_partition_id, uint16_t dest_iface_id);
int ffarpc_caller_close(struct ffarpc_caller *s);
#ifdef __cplusplus
diff --git a/components/rpc/ffarpc/caller/sp/ffarpc_caller.c b/components/rpc/ffarpc/caller/sp/ffarpc_caller.c
index 9d98512..07a2dca 100644
--- a/components/rpc/ffarpc/caller/sp/ffarpc_caller.c
+++ b/components/rpc/ffarpc/caller/sp/ffarpc_caller.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -13,6 +13,7 @@
#include <sp_rxtx.h>
#include <trace.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
uint8_t shared_buffer[4096] __aligned(4096);
@@ -33,6 +34,11 @@ static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_l
goto out;
}
+ if (req_len > UINT32_MAX) {
+ EMSG("call_begin(): req_len too big");
+ goto out;
+ }
+
this_context->is_call_transaction_in_progess = true;
handle = this_context;
@@ -50,7 +56,7 @@ out:
}
static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
- int *opstatus, uint8_t **resp_buf, size_t *resp_len)
+ int *opstatus, uint8_t **resp_buf, size_t *resp_len)
{
struct ffarpc_caller *this_context = (struct ffarpc_caller *)context;
ffa_result res = FFA_OK;
@@ -59,7 +65,7 @@ static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t
rpc_status_t status = TS_RPC_ERROR_INTERNAL;
if (handle != this_context || opstatus == NULL ||
- resp_buf == NULL || resp_len == NULL) {
+ resp_buf == NULL || resp_len == NULL) {
EMSG("call_invoke(): invalid arguments");
status = TS_RPC_ERROR_INVALID_PARAMETER;
goto out;
@@ -71,16 +77,24 @@ static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t
goto out;
}
- req.destination_id = this_context->call_ep_id;
+ req.destination_id = this_context->dest_partition_id;
req.source_id = own_id;
- req.args[FFA_CALL_ARGS_OPCODE] = opcode;
+ req.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(this_context->dest_partition_id, opcode);
//TODO: downcast problem?
req.args[FFA_CALL_ARGS_REQ_DATA_LEN] = (uint32_t)this_context->req_len;
+ req.args[FFA_CALL_ARGS_ENCODING] = this_context->rpc_caller.encoding;
+
+ /* Initialise the caller ID. Depending on the call path, this may
+ * be overridden by a higher privilege execution level, based on its
+ * perspective of the caller identity.
+ */
+ req.args[FFA_CALL_ARGS_CALLER_ID] = 0;
res = ffa_msg_send_direct_req(req.source_id, req.destination_id,
- req.args[0], req.args[1],
- req.args[2], req.args[3],
- req.args[4], &resp);
+ req.args[0], req.args[1],
+ req.args[2], req.args[3],
+ req.args[4], &resp);
if (res != FFA_OK) {
EMSG("ffa_msg_send_direct_req(): error %"PRId32, res);
@@ -123,12 +137,13 @@ struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s)
{
struct rpc_caller *base = &s->rpc_caller;
- base->context = s;
+ rpc_caller_init(base, s);
base->call_begin = call_begin;
base->call_invoke = call_invoke;
base->call_end = call_end;
- s->call_ep_id = 0;
+ s->dest_partition_id = 0;
+ s->dest_iface_id = 0;
s->shared_mem_handle = 0;
s->shared_mem_required_size = sizeof(shared_buffer);
s->req_buf = NULL;
@@ -191,7 +206,7 @@ out:
return sp_cnt;
}
-int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
+int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t dest_partition_id, uint16_t dest_iface_id)
{
//TODO: revise return type, error handling
ffa_result ffa_res;
@@ -212,7 +227,7 @@ int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
acc_desc.data_access = sp_data_access_read_write;
acc_desc.instruction_access = sp_instruction_access_not_executable;
- acc_desc.receiver_id = call_ep_id;
+ acc_desc.receiver_id = dest_partition_id;
region.address = shared_buffer;
region.page_count = 1;
@@ -224,23 +239,25 @@ int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id)
}
req.source_id = own_id;
- req.destination_id = call_ep_id;
- req.args[FFA_CALL_ARGS_OPCODE] = FFA_CALL_OPCODE_SHARE_BUF;
- req.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)(handle & 0xffff);
+ req.destination_id = dest_partition_id;
+ req.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(FFA_CALL_MGMT_IFACE_ID, FFA_CALL_OPCODE_SHARE_BUF);
+ req.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = (uint32_t)(handle & UINT32_MAX);
req.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = (uint32_t)(handle >> 32);
//TODO: downcast
req.args[FFA_CALL_ARGS_SHARE_MEM_SIZE] = (uint32_t)(s->shared_mem_required_size);
ffa_res = ffa_msg_send_direct_req(req.source_id, req.destination_id,
- req.args[0], req.args[1],
- req.args[2], req.args[3],
- req.args[4], &resp);
+ req.args[0], req.args[1],
+ req.args[2], req.args[3],
+ req.args[4], &resp);
if (ffa_res != FFA_OK) {
EMSG("ffa_msg_send_direct_req(): error %"PRId32, ffa_res);
return -1;
}
- s->call_ep_id = call_ep_id;
+ s->dest_partition_id = dest_partition_id;
+ s->dest_iface_id = dest_iface_id;
s->shared_mem_handle = handle;
return 0;
@@ -260,15 +277,16 @@ int ffarpc_caller_close(struct ffarpc_caller *s)
handle_hi = (uint32_t)(s->shared_mem_handle >> 32);
req.source_id = own_id;
- req.destination_id = s->call_ep_id;
- req.args[FFA_CALL_ARGS_OPCODE] = FFA_CALL_OPCODE_UNSHARE_BUF;
+ req.destination_id = s->dest_partition_id;
+ req.args[FFA_CALL_ARGS_IFACE_ID_OPCODE] =
+ FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(FFA_CALL_MGMT_IFACE_ID, FFA_CALL_OPCODE_UNSHARE_BUF);
req.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_LSW] = handle_lo;
req.args[FFA_CALL_ARGS_SHARE_MEM_HANDLE_MSW] = handle_hi;
ffa_res = ffa_msg_send_direct_req(req.source_id, req.destination_id,
- req.args[0], req.args[1],
- req.args[2], req.args[3],
- req.args[4], &resp);
+ req.args[0], req.args[1],
+ req.args[2], req.args[3],
+ req.args[4], &resp);
if (ffa_res != FFA_OK) {
EMSG("ffa_msg_send_direct_req(): error %"PRId32, ffa_res);
return -1;
@@ -280,7 +298,8 @@ int ffarpc_caller_close(struct ffarpc_caller *s)
return -1;
}
- s->call_ep_id = 0;
+ s->dest_partition_id = 0;
+ s->dest_iface_id = 0;
s->shared_mem_handle = 0;
return 0;
diff --git a/components/rpc/ffarpc/caller/sp/ffarpc_caller.h b/components/rpc/ffarpc/caller/sp/ffarpc_caller.h
index ba810e9..a6c2fba 100644
--- a/components/rpc/ffarpc/caller/sp/ffarpc_caller.h
+++ b/components/rpc/ffarpc/caller/sp/ffarpc_caller.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -16,7 +16,8 @@ extern "C" {
struct ffarpc_caller {
struct rpc_caller rpc_caller;
- uint16_t call_ep_id;
+ uint16_t dest_partition_id;
+ uint16_t dest_iface_id;
uint64_t shared_mem_handle;
size_t shared_mem_required_size;
uint8_t *req_buf;
@@ -29,7 +30,7 @@ struct ffarpc_caller {
struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s);
void ffarpc_caller_deinit(struct ffarpc_caller *s);
uint32_t ffarpc_caller_discover(const uint8_t *uuid, uint16_t *sp_ids, uint32_t sp_max_cnt);
-int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t call_ep_id);
+int ffarpc_caller_open(struct ffarpc_caller *s, uint16_t dest_partition_id, uint16_t dest_iface_id);
int ffarpc_caller_close(struct ffarpc_caller *s);
#ifdef __cplusplus
diff --git a/components/rpc/ffarpc/endpoint/ffarpc_call_args.h b/components/rpc/ffarpc/endpoint/ffarpc_call_args.h
index 402e4f5..fbe7320 100644
--- a/components/rpc/ffarpc/endpoint/ffarpc_call_args.h
+++ b/components/rpc/ffarpc/endpoint/ffarpc_call_args.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -17,11 +17,21 @@ extern "C" {
* normal world RPC caller and the RPC listener in the SP.
*/
+/* Macros for parameters carried in a single register */
+#define FFA_CALL_ARGS_COMBINE_IFACE_ID_OPCODE(i, o) \
+ (((i) << 16) | ((o) & 0xffff))
+#define FFA_CALL_ARGS_EXTRACT_IFACE(reg) \
+ ((reg) >> 16)
+#define FFA_CALL_ARGS_EXTRACT_OPCODE(reg) \
+ ((reg) & 0xffff)
+
/* Common req & resp arg offests into msg_args structure */
-#define FFA_CALL_ARGS_OPCODE (0)
+#define FFA_CALL_ARGS_IFACE_ID_OPCODE (0)
/* Req arg offsets */
#define FFA_CALL_ARGS_REQ_DATA_LEN (1)
+#define FFA_CALL_ARGS_CALLER_ID (2)
+#define FFA_CALL_ARGS_ENCODING (3)
/* Resp arg offsets */
#define FFA_CALL_ARGS_RESP_DATA_LEN (1)
diff --git a/components/rpc/ffarpc/endpoint/ffarpc_call_ep.c b/components/rpc/ffarpc/endpoint/ffarpc_call_ep.c
index bb40cf3..1139e73 100644
--- a/components/rpc/ffarpc/endpoint/ffarpc_call_ep.c
+++ b/components/rpc/ffarpc/endpoint/ffarpc_call_ep.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -16,16 +16,16 @@
/* TODO: remove this when own ID will be available in libsp */
extern uint16_t own_id;
-static void set_resp_args(uint32_t *resp_args, uint32_t opcode, uint32_t data_len,
+static void set_resp_args(uint32_t *resp_args, uint32_t ifaceid_opcode, uint32_t data_len,
rpc_status_t rpc_status, uint32_t opstatus)
{
- resp_args[FFA_CALL_ARGS_OPCODE] = opcode;
+ resp_args[FFA_CALL_ARGS_IFACE_ID_OPCODE] = ifaceid_opcode;
resp_args[FFA_CALL_ARGS_RESP_DATA_LEN] = data_len;
resp_args[FFA_CALL_ARGS_RESP_RPC_STATUS] = rpc_status;
resp_args[FFA_CALL_ARGS_RESP_OP_STATUS] = opstatus;
}
-static void set_mgmt_resp_args(uint32_t *resp_args, uint32_t opcode,
+static void set_mgmt_resp_args(uint32_t *resp_args, uint32_t ifaceid_opcode,
rpc_status_t rpc_status)
{
/*
@@ -33,7 +33,7 @@ static void set_mgmt_resp_args(uint32_t *resp_args, uint32_t opcode,
* rather than from a higher layer service. These responses are not
* associated with a shared buffer for any additional message payload.
*/
- set_resp_args(resp_args, opcode, 0, rpc_status, 0);
+ set_resp_args(resp_args, ifaceid_opcode, 0, rpc_status, 0);
}
static void init_shmem_buf(struct ffa_call_ep *call_ep, uint16_t source_id,
@@ -68,7 +68,7 @@ static void init_shmem_buf(struct ffa_call_ep *call_ep, uint16_t source_id,
EMSG("memory retrieve error: %d", sp_res);
}
- set_mgmt_resp_args(resp_args, req_args[FFA_CALL_ARGS_OPCODE], rpc_status);
+ set_mgmt_resp_args(resp_args, req_args[FFA_CALL_ARGS_IFACE_ID_OPCODE], rpc_status);
}
static void deinit_shmem_buf(struct ffa_call_ep *call_ep, const uint32_t *req_args,
@@ -94,7 +94,7 @@ static void deinit_shmem_buf(struct ffa_call_ep *call_ep, const uint32_t *req_ar
EMSG("memory relinquish error: %d", sp_res);
}
- set_mgmt_resp_args(resp_args, req_args[FFA_CALL_ARGS_OPCODE], rpc_status);
+ set_mgmt_resp_args(resp_args, req_args[FFA_CALL_ARGS_IFACE_ID_OPCODE], rpc_status);
}
static void handle_service_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
@@ -103,8 +103,12 @@ static void handle_service_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
rpc_status_t rpc_status;
struct call_req call_req;
+ uint32_t ifaceid_opcode = req_args[FFA_CALL_ARGS_IFACE_ID_OPCODE];
+
call_req.caller_id = source_id;
- call_req.opcode = req_args[FFA_CALL_ARGS_OPCODE];
+ call_req.interface_id = FFA_CALL_ARGS_EXTRACT_IFACE(ifaceid_opcode);
+ call_req.opcode = FFA_CALL_ARGS_EXTRACT_OPCODE(ifaceid_opcode);
+ call_req.encoding = req_args[FFA_CALL_ARGS_ENCODING];
call_req.req_buf.data = call_ep->shmem_buf;
call_req.req_buf.data_len = req_args[FFA_CALL_ARGS_REQ_DATA_LEN];
@@ -114,10 +118,10 @@ static void handle_service_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
call_req.resp_buf.data_len = 0;
call_req.resp_buf.size = call_ep->shmem_buf_size;
- rpc_status = call_ep_receive(call_ep->call_ep, &call_req);
+ rpc_status = rpc_interface_receive(call_ep->iface, &call_req);
set_resp_args(resp_args,
- call_req.opcode,
+ ifaceid_opcode,
call_req.resp_buf.data_len,
rpc_status,
call_req.opstatus);
@@ -126,7 +130,8 @@ static void handle_service_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
static void handle_mgmt_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
const uint32_t *req_args, uint32_t *resp_args)
{
- uint32_t opcode = req_args[FFA_CALL_ARGS_OPCODE];
+ uint32_t ifaceid_opcode = req_args[FFA_CALL_ARGS_IFACE_ID_OPCODE];
+ uint32_t opcode = FFA_CALL_ARGS_EXTRACT_OPCODE(ifaceid_opcode);
/*
* TODO: shouldn't this be used to keep track of multiple
@@ -142,14 +147,14 @@ static void handle_mgmt_msg(struct ffa_call_ep *call_ep, uint16_t source_id,
deinit_shmem_buf(call_ep, req_args, resp_args);
break;
default:
- set_mgmt_resp_args(resp_args, opcode, TS_RPC_ERROR_INVALID_OPCODE);
+ set_mgmt_resp_args(resp_args, ifaceid_opcode, TS_RPC_ERROR_INVALID_OPCODE);
break;
}
}
-void ffa_call_ep_init(struct ffa_call_ep *ffa_call_ep, struct call_ep *call_ep)
+void ffa_call_ep_init(struct ffa_call_ep *ffa_call_ep, struct rpc_interface *iface)
{
- ffa_call_ep->call_ep = call_ep;
+ ffa_call_ep->iface = iface;
ffa_call_ep->shmem_buf_handle = 0;
ffa_call_ep->shmem_buf_size = 0;
ffa_call_ep->shmem_buf = NULL;
@@ -163,9 +168,9 @@ void ffa_call_ep_receive(struct ffa_call_ep *call_ep,
uint32_t *resp_args = resp_msg->args;
uint16_t source_id = req_msg->source_id;
- uint32_t opcode = req_args[FFA_CALL_ARGS_OPCODE];
+ uint32_t ifaceid_opcode = req_args[FFA_CALL_ARGS_IFACE_ID_OPCODE];
- if (FFA_CALL_OPCODE_IS_MGMT(opcode)) {
+ if (FFA_CALL_ARGS_EXTRACT_IFACE(ifaceid_opcode) == FFA_CALL_MGMT_IFACE_ID) {
/* It's an RPC layer management request */
handle_mgmt_msg(call_ep, source_id, req_args, resp_args);
} else {
@@ -177,6 +182,6 @@ void ffa_call_ep_receive(struct ffa_call_ep *call_ep,
if (call_ep->shmem_buf)
handle_service_msg(call_ep, source_id, req_args, resp_args);
else
- set_mgmt_resp_args(resp_args, opcode, TS_RPC_ERROR_NOT_READY);
+ set_mgmt_resp_args(resp_args, ifaceid_opcode, TS_RPC_ERROR_NOT_READY);
}
}
diff --git a/components/rpc/ffarpc/endpoint/ffarpc_call_ep.h b/components/rpc/ffarpc/endpoint/ffarpc_call_ep.h
index b4bcdd6..cc67f6e 100644
--- a/components/rpc/ffarpc/endpoint/ffarpc_call_ep.h
+++ b/components/rpc/ffarpc/endpoint/ffarpc_call_ep.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,7 +8,7 @@
#define FFA_CALL_EP_H
#include <ffa_api.h>
-#include <components/rpc/common/endpoint/call_ep.h>
+#include <components/rpc/common/endpoint/rpc_interface.h>
#include <stddef.h>
#include <stdint.h>
@@ -17,13 +17,13 @@ extern "C" {
#endif
struct ffa_call_ep {
- struct call_ep *call_ep;
+ struct rpc_interface *iface;
unsigned long shmem_buf_handle;
volatile uint8_t *shmem_buf;
size_t shmem_buf_size;
};
-void ffa_call_ep_init(struct ffa_call_ep *ffa_call_ep, struct call_ep *call_ep);
+void ffa_call_ep_init(struct ffa_call_ep *ffa_call_ep, struct rpc_interface *iface);
void ffa_call_ep_receive(struct ffa_call_ep *call_ep,
const struct ffa_direct_msg *req_msg,
struct ffa_direct_msg *resp_msg);
diff --git a/components/rpc/ffarpc/endpoint/ffarpc_call_ops.h b/components/rpc/ffarpc/endpoint/ffarpc_call_ops.h
index 3f14fc7..de22678 100644
--- a/components/rpc/ffarpc/endpoint/ffarpc_call_ops.h
+++ b/components/rpc/ffarpc/endpoint/ffarpc_call_ops.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -12,13 +12,15 @@ extern "C" {
#endif
/* Common opcodes used by the FFA based RPC layer for management operations */
-#define FFA_CALL_OPCODE_BASE (0x10)
-#define FFA_CALL_OPCODE_SHARE_BUF (FFA_CALL_OPCODE_BASE + 0)
-#define FFA_CALL_OPCODE_UNSHARE_BUF (FFA_CALL_OPCODE_BASE + 1)
-#define FFA_CALL_OPCODE_LIMIT (FFA_CALL_OPCODE_BASE + 2)
+enum
+{
+ FFA_CALL_OPCODE_SHARE_BUF = 0,
+ FFA_CALL_OPCODE_UNSHARE_BUF = 1,
+ FFA_CALL_OPCODE_LIMIT
+};
-#define FFA_CALL_OPCODE_IS_MGMT(opcode) \
- ((opcode >= FFA_CALL_OPCODE_BASE) && (opcode < FFA_CALL_OPCODE_LIMIT))
+/* Interface ID for FFA management interface */
+#define FFA_CALL_MGMT_IFACE_ID (0x1000)
#ifdef __cplusplus
}
diff --git a/components/service/common/provider/service_provider.c b/components/service/common/provider/service_provider.c
index 17f742f..f11c303 100644
--- a/components/service/common/provider/service_provider.c
+++ b/components/service/common/provider/service_provider.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -9,7 +9,7 @@
#include <stddef.h>
static const struct service_handler *find_handler(const struct service_provider *sp,
- uint32_t opcode)
+ uint32_t opcode)
{
const struct service_handler *handler = NULL;
size_t index = 0;
@@ -27,37 +27,40 @@ static const struct service_handler *find_handler(const struct service_provider
return handler;
}
-static rpc_status_t receive(struct call_ep *base_ep, struct call_req *req)
+static rpc_status_t receive(struct rpc_interface *rpc_iface, struct call_req *req)
{
rpc_status_t rpc_status;
struct service_provider *sp = NULL;
const struct service_handler *handler = NULL;
- sp = (struct service_provider*)((char*)base_ep - offsetof(struct service_provider, base));
+ sp = (struct service_provider*)((char*)rpc_iface - offsetof(struct service_provider, iface));
handler = find_handler(sp, call_req_get_opcode(req));
- if (handler) {
+ if (handler) {
- req->serializer = sp->default_serializer;
- rpc_status = service_handler_invoke(handler, base_ep->context, req);
- }
- else {
+ rpc_status = service_handler_invoke(handler, rpc_iface->context, req);
+ }
+ else if (sp->successor) {
+
+ rpc_status = rpc_interface_receive(sp->successor, req);
+ }
+ else {
- rpc_status = TS_RPC_ERROR_INVALID_OPCODE;
- }
+ rpc_status = TS_RPC_ERROR_INVALID_OPCODE;
+ }
return rpc_status;
}
void service_provider_init(struct service_provider *sp, void *context,
- const struct service_handler *handlers,
- size_t num_handlers)
+ const struct service_handler *handlers,
+ size_t num_handlers)
{
- sp->base.receive = receive;
- sp->base.context = context;
+ sp->iface.receive = receive;
+ sp->iface.context = context;
sp->handlers = handlers;
sp->num_handlers = num_handlers;
- sp->default_serializer = NULL;
+ sp->successor = NULL;
}
diff --git a/components/service/common/provider/service_provider.h b/components/service/common/provider/service_provider.h
index 6f86073..508a93f 100644
--- a/components/service/common/provider/service_provider.h
+++ b/components/service/common/provider/service_provider.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -7,7 +7,7 @@
#ifndef SERVICE_PROVIDER_H
#define SERVICE_PROVIDER_H
-#include <rpc/common/endpoint/call_ep.h>
+#include <rpc/common/endpoint/rpc_interface.h>
#include <stddef.h>
#include <stdint.h>
@@ -40,28 +40,29 @@ static inline uint32_t service_handler_get_opcode(const struct service_handler *
*
* A generalised service provider that acts as an rpc call endpoint. It receives call
* requests and delegates them to the approprate handle provided by a concrete service
- * provider.
+ * provider. To support service specialization and proxying, unhandled requests may
+ * optionally be passed to a delegate rpc_interface to form a chain of responsibility.
*/
struct service_provider {
- struct call_ep base;
- const struct service_handler *handlers;
- size_t num_handlers;
- call_param_serializer_ptr default_serializer;
+ struct rpc_interface iface;
+ const struct service_handler *handlers;
+ size_t num_handlers;
+ struct rpc_interface *successor;
};
-static inline struct call_ep *service_provider_get_call_ep(struct service_provider *sp)
+static inline struct rpc_interface *service_provider_get_rpc_interface(struct service_provider *sp)
{
- return &sp->base;
+ return &sp->iface;
}
void service_provider_init(struct service_provider *sp, void *context,
- const struct service_handler *handlers,
- size_t num_handlers);
+ const struct service_handler *handlers,
+ size_t num_handlers);
-static inline void service_set_default_serializer(struct service_provider *sp,
- call_param_serializer_ptr serializer)
+static inline void service_provider_link_successor(struct service_provider *sp,
+ struct rpc_interface *successor)
{
- sp->default_serializer = serializer;
+ sp->successor = successor;
}
#ifdef __cplusplus
diff --git a/components/service/common/provider/test/service_framework_tests.cpp b/components/service/common/provider/test/service_framework_tests.cpp
index 4aa3fdc..6483c4b 100644
--- a/components/service/common/provider/test/service_framework_tests.cpp
+++ b/components/service/common/provider/test/service_framework_tests.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -64,11 +64,11 @@ TEST_GROUP(ServiceFrameworkTests)
TEST(ServiceFrameworkTests, serviceWithNoOps)
{
/* Constructs a service endpoint with no handlers */
- struct service_provider ep;
+ struct service_provider service_provider;
- service_provider_init(&ep, &ep, NULL, 0);
+ service_provider_init(&service_provider, &service_provider, NULL, 0);
struct rpc_caller *caller = direct_caller_init_default(&m_direct_caller,
- service_provider_get_call_ep(&ep));
+ service_provider_get_rpc_interface(&service_provider));
rpc_call_handle handle;
uint8_t *req_buf;
@@ -97,11 +97,11 @@ TEST(ServiceFrameworkTests, serviceWithOps)
handlers[1].opcode = ANOTHER_ARBITRARY_OPCODE;
handlers[1].invoke = handlerThatFails;
- struct service_provider ep;
+ struct service_provider service_provider;
- service_provider_init(&ep, &ep, handlers, 2);
+ service_provider_init(&service_provider, &service_provider, handlers, 2);
struct rpc_caller *caller = direct_caller_init_default(&m_direct_caller,
- service_provider_get_call_ep(&ep));
+ service_provider_get_rpc_interface(&service_provider));
rpc_call_handle handle;
rpc_status_t rpc_status;
diff --git a/components/service/crypto/client/cpp/crypto_client.cpp b/components/service/crypto/client/cpp/crypto_client.cpp
index a374954..b27a585 100644
--- a/components/service/crypto/client/cpp/crypto_client.cpp
+++ b/components/service/crypto/client/cpp/crypto_client.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -45,6 +45,11 @@ crypto_client::~crypto_client()
}
+void crypto_client::set_caller(struct rpc_caller *caller)
+{
+ m_caller = caller;
+}
+
int crypto_client::err_rpc_status() const
{
return m_err_rpc_status;
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index 391f521..3d0366f 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -62,7 +62,7 @@ public:
protected:
crypto_client();
- void set_caller(struct rpc_caller *caller) {m_caller = caller;}
+ void set_caller(struct rpc_caller *caller);
private:
diff --git a/components/service/crypto/client/test/mock/mock_crypto_client.cpp b/components/service/crypto/client/test/mock/mock_crypto_client.cpp
index 8e55d34..a654ed1 100644
--- a/components/service/crypto/client/test/mock/mock_crypto_client.cpp
+++ b/components/service/crypto/client/test/mock/mock_crypto_client.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "mock_crypto_client.h"
+#include <service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.h>
mock_crypto_client::mock_crypto_client() :
test_crypto_client(),
@@ -27,11 +28,19 @@ bool mock_crypto_client::init()
if (should_do) {
- struct call_ep *storage_ep = mock_store_provider_init(&m_storage_provider);
- struct rpc_caller *storage_caller = direct_caller_init_default(&m_storage_caller, storage_ep);
+ struct rpc_interface *storage_ep = mock_store_provider_init(&m_storage_provider);
+ struct rpc_caller *storage_caller = direct_caller_init_default(&m_storage_caller,
+ storage_ep);
- struct call_ep *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider, storage_caller);
- struct rpc_caller *crypto_caller = direct_caller_init_default(&m_crypto_caller, crypto_ep);
+ struct rpc_interface *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider,
+ storage_caller);
+ struct rpc_caller *crypto_caller = direct_caller_init_default(&m_crypto_caller,
+ crypto_ep);
+
+ mbed_crypto_provider_register_serializer(&m_crypto_provider,
+ TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
+
+ rpc_caller_set_encoding_scheme(crypto_caller, TS_RPC_ENCODING_PROTOBUF);
crypto_client::set_caller(crypto_caller);
}
diff --git a/components/service/crypto/client/test/standalone/standalone_crypto_client.cpp b/components/service/crypto/client/test/standalone/standalone_crypto_client.cpp
index da3224d..459e42d 100644
--- a/components/service/crypto/client/test/standalone/standalone_crypto_client.cpp
+++ b/components/service/crypto/client/test/standalone/standalone_crypto_client.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -7,6 +7,7 @@
#include "standalone_crypto_client.h"
#include <protocols/rpc/common/packed-c/status.h>
#include <protocols/service/psa/packed-c/status.h>
+#include <service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.h>
standalone_crypto_client::standalone_crypto_client() :
test_crypto_client(),
@@ -35,7 +36,7 @@ bool standalone_crypto_client::init()
if (!is_fault_injected(FAILED_TO_DISCOVER_SECURE_STORAGE)) {
/* Establish rpc session with storage provider */
- struct call_ep *storage_ep = sfs_provider_init(&m_storage_provider);
+ struct rpc_interface *storage_ep = sfs_provider_init(&m_storage_provider);
storage_caller = direct_caller_init_default(&m_storage_caller, storage_ep);
}
else {
@@ -49,8 +50,15 @@ bool standalone_crypto_client::init()
TS_RPC_CALL_ACCEPTED, PSA_ERROR_STORAGE_FAILURE);
}
- struct call_ep *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider, storage_caller);
- struct rpc_caller *crypto_caller = direct_caller_init_default(&m_crypto_caller, crypto_ep);
+ struct rpc_interface *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider,
+ storage_caller);
+ struct rpc_caller *crypto_caller = direct_caller_init_default(&m_crypto_caller,
+ crypto_ep);
+
+ mbed_crypto_provider_register_serializer(&m_crypto_provider,
+ TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
+
+ rpc_caller_set_encoding_scheme(crypto_caller, TS_RPC_ENCODING_PROTOBUF);
crypto_client::set_caller(crypto_caller);
}
diff --git a/components/service/crypto/provider/mbedcrypto/crypto_provider.c b/components/service/crypto/provider/mbedcrypto/crypto_provider.c
index e8c77e9..bbbf169 100644
--- a/components/service/crypto/provider/mbedcrypto/crypto_provider.c
+++ b/components/service/crypto/provider/mbedcrypto/crypto_provider.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -7,8 +7,6 @@
#include <stdlib.h>
#include <protocols/service/crypto/packed-c/opcodes.h>
#include <service/crypto/provider/mbedcrypto/crypto_provider.h>
-#include <service/crypto/provider/serializer/crypto_provider_serializer.h>
-#include <service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.h>
#include <service/secure_storage/client/psa/its/its_client.h>
#include <protocols/rpc/common/packed-c/status.h>
#include <psa/crypto.h>
@@ -45,10 +43,10 @@ static const struct service_handler handler_table[] = {
{TS_CRYPTO_OPCODE_GENERATE_RANDOM, generate_random_handler}
};
-struct call_ep *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
+struct rpc_interface *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
struct rpc_caller *storage_provider)
{
- struct call_ep *call_ep = NULL;
+ struct rpc_interface *rpc_interface = NULL;
/*
* A storage provider is required for persistent key storage. As this
@@ -57,18 +55,18 @@ struct call_ep *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
*/
if (context && storage_provider) {
+ for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
+ context->serializers[encoding] = NULL;
+
service_provider_init(&context->base_provider, context,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
- service_set_default_serializer(&context->base_provider,
- pb_crypto_provider_serializer_instance());
-
if ((psa_its_client_init(storage_provider) == PSA_SUCCESS) &&
(psa_crypto_init() == PSA_SUCCESS))
- call_ep = service_provider_get_call_ep(&context->base_provider);
+ rpc_interface = service_provider_get_rpc_interface(&context->base_provider);
}
- return call_ep;
+ return rpc_interface;
}
void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context)
@@ -76,9 +74,23 @@ void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context)
(void)context;
}
-static inline const struct crypto_provider_serializer* get_crypto_serializer(const struct call_req *req)
+void mbed_crypto_provider_register_serializer(struct mbed_crypto_provider *context,
+ unsigned int encoding, const struct crypto_provider_serializer *serializer)
+{
+ if (encoding < TS_RPC_ENCODING_LIMIT)
+ context->serializers[encoding] = serializer;
+}
+
+static const struct crypto_provider_serializer* get_crypto_serializer(void *context,
+ const struct call_req *req)
{
- return (const struct crypto_provider_serializer*)call_req_get_serializer(req);
+ struct mbed_crypto_provider *this_instance = (struct mbed_crypto_provider*)context;
+ const struct crypto_provider_serializer* serializer = NULL;
+ unsigned int encoding = call_req_get_encoding(req);
+
+ if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
+
+ return serializer;
}
static rpc_status_t nop_handler(void *context, struct call_req* req)
@@ -95,14 +107,14 @@ static rpc_status_t nop_handler(void *context, struct call_req* req)
static rpc_status_t generate_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- rpc_status = serializer->deserialize_generate_key_req(req_buf, &attributes);
+ if (serializer)
+ rpc_status = serializer->deserialize_generate_key_req(req_buf, &attributes);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -127,14 +139,14 @@ static rpc_status_t generate_key_handler(void *context, struct call_req* req)
static rpc_status_t destroy_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
- rpc_status = serializer->deserialize_destroy_key_req(req_buf, &handle);
+ if (serializer)
+ rpc_status = serializer->deserialize_destroy_key_req(req_buf, &handle);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -149,14 +161,14 @@ static rpc_status_t destroy_key_handler(void *context, struct call_req* req)
static rpc_status_t open_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
- rpc_status = serializer->deserialize_open_key_req(req_buf, &id);
+ if (serializer)
+ rpc_status = serializer->deserialize_open_key_req(req_buf, &id);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -179,14 +191,14 @@ static rpc_status_t open_key_handler(void *context, struct call_req* req)
static rpc_status_t close_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
- rpc_status = serializer->deserialize_close_key_req(req_buf, &handle);
+ if (serializer)
+ rpc_status = serializer->deserialize_close_key_req(req_buf, &handle);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -201,14 +213,14 @@ static rpc_status_t close_key_handler(void *context, struct call_req* req)
static rpc_status_t export_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
- rpc_status = serializer->deserialize_export_key_req(req_buf, &handle);
+ if (serializer)
+ rpc_status = serializer->deserialize_export_key_req(req_buf, &handle);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -253,14 +265,14 @@ static rpc_status_t export_key_handler(void *context, struct call_req* req)
static rpc_status_t export_public_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
- rpc_status = serializer->deserialize_export_public_key_req(req_buf, &handle);
+ if (serializer)
+ rpc_status = serializer->deserialize_export_public_key_req(req_buf, &handle);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -305,41 +317,43 @@ static rpc_status_t export_public_key_handler(void *context, struct call_req* re
static rpc_status_t import_key_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
- size_t key_data_len = serializer->max_deserialised_parameter_size(req_buf);
- uint8_t *key_buffer = malloc(key_data_len);
+ if (serializer) {
- if (key_buffer) {
+ size_t key_data_len = serializer->max_deserialised_parameter_size(req_buf);
+ uint8_t *key_buffer = malloc(key_data_len);
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- rpc_status = serializer->deserialize_import_key_req(req_buf, &attributes, key_buffer, &key_data_len);
+ if (key_buffer) {
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ rpc_status = serializer->deserialize_import_key_req(req_buf, &attributes, key_buffer, &key_data_len);
- psa_status_t psa_status;
- psa_key_handle_t handle;
+ if (rpc_status == TS_RPC_CALL_ACCEPTED) {
- psa_status = psa_import_key(&attributes, key_buffer, key_data_len, &handle);
+ psa_status_t psa_status;
+ psa_key_handle_t handle;
- if (psa_status == PSA_SUCCESS) {
+ psa_status = psa_import_key(&attributes, key_buffer, key_data_len, &handle);
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_import_key_resp(resp_buf, handle);
+ if (psa_status == PSA_SUCCESS) {
+
+ struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ rpc_status = serializer->serialize_import_key_resp(resp_buf, handle);
+ }
+
+ call_req_set_opstatus(req, psa_status);
}
- call_req_set_opstatus(req, psa_status);
+ psa_reset_key_attributes(&attributes);
+ free(key_buffer);
}
+ else {
- psa_reset_key_attributes(&attributes);
- free(key_buffer);
- }
- else {
-
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ }
}
return rpc_status;
@@ -347,17 +361,17 @@ static rpc_status_t import_key_handler(void *context, struct call_req* req)
static rpc_status_t sign_hash_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
psa_algorithm_t alg;
size_t hash_len = PSA_HASH_MAX_SIZE;
uint8_t hash_buffer[PSA_HASH_MAX_SIZE];
- rpc_status = serializer->deserialize_sign_hash_req(req_buf, &handle, &alg, hash_buffer, &hash_len);
+ if (serializer)
+ rpc_status = serializer->deserialize_sign_hash_req(req_buf, &handle, &alg, hash_buffer, &hash_len);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -383,10 +397,9 @@ static rpc_status_t sign_hash_handler(void *context, struct call_req* req)
static rpc_status_t verify_hash_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_handle_t handle;
psa_algorithm_t alg;
@@ -395,7 +408,8 @@ static rpc_status_t verify_hash_handler(void *context, struct call_req* req)
size_t sig_len = PSA_SIGNATURE_MAX_SIZE;
uint8_t sig_buffer[PSA_SIGNATURE_MAX_SIZE];
- rpc_status = serializer->deserialize_verify_hash_req(req_buf, &handle, &alg,
+ if (serializer)
+ rpc_status = serializer->deserialize_verify_hash_req(req_buf, &handle, &alg,
hash_buffer, &hash_len,
sig_buffer, &sig_len);
@@ -415,166 +429,172 @@ static rpc_status_t verify_hash_handler(void *context, struct call_req* req)
static rpc_status_t asymmetric_decrypt_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
- psa_key_handle_t handle;
- psa_algorithm_t alg;
- size_t ciphertext_len = max_param_size;
- uint8_t *ciphertext_buffer = malloc(ciphertext_len);
- size_t salt_len = max_param_size;
- uint8_t *salt_buffer = malloc(salt_len);
+ if (serializer) {
- if (ciphertext_buffer && salt_buffer) {
+ size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
- rpc_status = serializer->deserialize_asymmetric_decrypt_req(req_buf,
- &handle, &alg,
- ciphertext_buffer, &ciphertext_len,
- salt_buffer, &salt_len);
+ psa_key_handle_t handle;
+ psa_algorithm_t alg;
+ size_t ciphertext_len = max_param_size;
+ uint8_t *ciphertext_buffer = malloc(ciphertext_len);
+ size_t salt_len = max_param_size;
+ uint8_t *salt_buffer = malloc(salt_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (ciphertext_buffer && salt_buffer) {
- psa_status_t psa_status;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ rpc_status = serializer->deserialize_asymmetric_decrypt_req(req_buf,
+ &handle, &alg,
+ ciphertext_buffer, &ciphertext_len,
+ salt_buffer, &salt_len);
- psa_status = psa_get_key_attributes(handle, &attributes);
+ if (rpc_status == TS_RPC_CALL_ACCEPTED) {
- if (psa_status == PSA_SUCCESS) {
+ psa_status_t psa_status;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- size_t max_decrypt_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(
- psa_get_key_type(&attributes),
- psa_get_key_bits(&attributes),
- alg);
+ psa_status = psa_get_key_attributes(handle, &attributes);
- size_t plaintext_len;
- uint8_t *plaintext_buffer = malloc(max_decrypt_size);
+ if (psa_status == PSA_SUCCESS) {
- if (plaintext_buffer) {
+ size_t max_decrypt_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes),
+ alg);
- psa_status = psa_asymmetric_decrypt(handle, alg,
- ciphertext_buffer, ciphertext_len,
- salt_buffer, salt_len,
- plaintext_buffer, max_decrypt_size, &plaintext_len);
+ size_t plaintext_len;
+ uint8_t *plaintext_buffer = malloc(max_decrypt_size);
- if (psa_status == PSA_SUCCESS) {
+ if (plaintext_buffer) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_asymmetric_decrypt_resp(resp_buf,
- plaintext_buffer, plaintext_len);
- }
+ psa_status = psa_asymmetric_decrypt(handle, alg,
+ ciphertext_buffer, ciphertext_len,
+ salt_buffer, salt_len,
+ plaintext_buffer, max_decrypt_size, &plaintext_len);
- free(plaintext_buffer);
- }
- else {
- /* Failed to allocate ouptput buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ if (psa_status == PSA_SUCCESS) {
+
+ struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ rpc_status = serializer->serialize_asymmetric_decrypt_resp(resp_buf,
+ plaintext_buffer, plaintext_len);
+ }
+
+ free(plaintext_buffer);
+ }
+ else {
+ /* Failed to allocate ouptput buffer */
+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ }
}
- }
- call_req_set_opstatus(req, psa_status);
- psa_reset_key_attributes(&attributes);
+ call_req_set_opstatus(req, psa_status);
+ psa_reset_key_attributes(&attributes);
+ }
+ }
+ else {
+ /* Failed to allocate buffers */
+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
}
- }
- else {
- /* Failed to allocate buffers */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
- }
- free(ciphertext_buffer);
- free(salt_buffer);
+ free(ciphertext_buffer);
+ free(salt_buffer);
+ }
return rpc_status;
}
static rpc_status_t asymmetric_encrypt_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
- psa_key_handle_t handle;
- psa_algorithm_t alg;
- size_t plaintext_len = max_param_size;
- uint8_t *plaintext_buffer = malloc(plaintext_len);
- size_t salt_len = max_param_size;
- uint8_t *salt_buffer = malloc(salt_len);
+ if (serializer) {
- if (plaintext_buffer && salt_buffer) {
+ size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
- rpc_status = serializer->deserialize_asymmetric_encrypt_req(req_buf,
- &handle, &alg,
- plaintext_buffer, &plaintext_len,
- salt_buffer, &salt_len);
+ psa_key_handle_t handle;
+ psa_algorithm_t alg;
+ size_t plaintext_len = max_param_size;
+ uint8_t *plaintext_buffer = malloc(plaintext_len);
+ size_t salt_len = max_param_size;
+ uint8_t *salt_buffer = malloc(salt_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (plaintext_buffer && salt_buffer) {
- psa_status_t psa_status;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ rpc_status = serializer->deserialize_asymmetric_encrypt_req(req_buf,
+ &handle, &alg,
+ plaintext_buffer, &plaintext_len,
+ salt_buffer, &salt_len);
- psa_status = psa_get_key_attributes(handle, &attributes);
+ if (rpc_status == TS_RPC_CALL_ACCEPTED) {
- if (psa_status == PSA_SUCCESS) {
+ psa_status_t psa_status;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- size_t max_encrypt_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(
- psa_get_key_type(&attributes),
- psa_get_key_bits(&attributes),
- alg);
+ psa_status = psa_get_key_attributes(handle, &attributes);
- size_t ciphertext_len;
- uint8_t *ciphertext_buffer = malloc(max_encrypt_size);
+ if (psa_status == PSA_SUCCESS) {
- if (ciphertext_buffer) {
+ size_t max_encrypt_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes),
+ alg);
- psa_status = psa_asymmetric_encrypt(handle, alg,
- plaintext_buffer, plaintext_len,
- salt_buffer, salt_len,
- ciphertext_buffer, max_encrypt_size, &ciphertext_len);
+ size_t ciphertext_len;
+ uint8_t *ciphertext_buffer = malloc(max_encrypt_size);
- if (psa_status == PSA_SUCCESS) {
+ if (ciphertext_buffer) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_asymmetric_encrypt_resp(resp_buf,
- ciphertext_buffer, ciphertext_len);
- }
+ psa_status = psa_asymmetric_encrypt(handle, alg,
+ plaintext_buffer, plaintext_len,
+ salt_buffer, salt_len,
+ ciphertext_buffer, max_encrypt_size, &ciphertext_len);
- free(ciphertext_buffer);
- }
- else {
- /* Failed to allocate ouptput buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ if (psa_status == PSA_SUCCESS) {
+
+ struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ rpc_status = serializer->serialize_asymmetric_encrypt_resp(resp_buf,
+ ciphertext_buffer, ciphertext_len);
+ }
+
+ free(ciphertext_buffer);
+ }
+ else {
+ /* Failed to allocate ouptput buffer */
+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ }
}
- }
- call_req_set_opstatus(req, psa_status);
- psa_reset_key_attributes(&attributes);
+ call_req_set_opstatus(req, psa_status);
+ psa_reset_key_attributes(&attributes);
+ }
+ }
+ else {
+ /* Failed to allocate buffers */
+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
}
- }
- else {
- /* Failed to allocate buffers */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
- }
- free(plaintext_buffer);
- free(salt_buffer);
+ free(plaintext_buffer);
+ free(salt_buffer);
+ }
return rpc_status;
}
static rpc_status_t generate_random_handler(void *context, struct call_req* req)
{
- rpc_status_t rpc_status;
+ rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
struct call_param_buf *req_buf = call_req_get_req_buf(req);
- const struct crypto_provider_serializer *serializer = get_crypto_serializer(req);
- (void)context;
+ const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
size_t output_size;
- rpc_status = serializer->deserialize_generate_random_req(req_buf, &output_size);
+ if (serializer)
+ rpc_status = serializer->deserialize_generate_random_req(req_buf, &output_size);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
@@ -602,4 +622,4 @@ static rpc_status_t generate_random_handler(void *context, struct call_req* req)
}
return rpc_status;
-} \ No newline at end of file
+}
diff --git a/components/service/crypto/provider/mbedcrypto/crypto_provider.h b/components/service/crypto/provider/mbedcrypto/crypto_provider.h
index 856867d..4a94be7 100644
--- a/components/service/crypto/provider/mbedcrypto/crypto_provider.h
+++ b/components/service/crypto/provider/mbedcrypto/crypto_provider.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -7,9 +7,11 @@
#ifndef MBED_CRYPTO_PROVIDER_H
#define MBED_CRYPTO_PROVIDER_H
-#include <rpc/common/endpoint/call_ep.h>
+#include <rpc/common/endpoint/rpc_interface.h>
#include <rpc_caller.h>
#include <service/common/provider/service_provider.h>
+#include <service/crypto/provider/serializer/crypto_provider_serializer.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
#ifdef __cplusplus
extern "C" {
@@ -18,6 +20,7 @@ extern "C" {
struct mbed_crypto_provider
{
struct service_provider base_provider;
+ const struct crypto_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT];
};
/*
@@ -28,9 +31,9 @@ struct mbed_crypto_provider
* using the provided rpc_caller. Any rpc endpoint discovery and
* session establishment should have been performed prior to initializing
* the mbed_crypto_provider. On successfully initializing the provider,
- * a pointer to the call_ep for the service is returned.
+ * a pointer to the rpc_interface for the service is returned.
*/
-struct call_ep *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
+struct rpc_interface *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
struct rpc_caller *storage_provider);
/*
@@ -39,6 +42,15 @@ struct call_ep *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
*/
void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context);
+/*
+ * Register a serializer for supportng a particular parameter encoding. At
+ * least one serializer must be registered but additional ones may be registered
+ * to allow alternative parameter serialization schemes to be used to allow
+ * for compatibility with different types of client.
+ */
+void mbed_crypto_provider_register_serializer(struct mbed_crypto_provider *context,
+ unsigned int encoding, const struct crypto_provider_serializer *serializer);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/components/service/crypto/provider/serializer/crypto_provider_serializer.h b/components/service/crypto/provider/serializer/crypto_provider_serializer.h
index de7a873..989db1a 100644
--- a/components/service/crypto/provider/serializer/crypto_provider_serializer.h
+++ b/components/service/crypto/provider/serializer/crypto_provider_serializer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/call_ep.h>
+#include <rpc/common/endpoint/rpc_interface.h>
/* Provides a common interface for parameter serialization operations
* for the crypto service provider. Allows alternative serialization
diff --git a/components/service/crypto/test/service/crypto_service_limit_tests.cpp b/components/service/crypto/test/service/crypto_service_limit_tests.cpp
index 53c8560..392391a 100644
--- a/components/service/crypto/test/service/crypto_service_limit_tests.cpp
+++ b/components/service/crypto/test/service/crypto_service_limit_tests.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,8 +8,8 @@
#include <vector>
#include <cstring>
#include <cstdint>
-#include <cassert>
#include <service/crypto/client/cpp/crypto_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
#include <service_locator.h>
#include <CppUTest/TestHarness.h>
@@ -31,10 +31,10 @@ TEST_GROUP(CryptoServiceLimitTests)
service_locator_init();
m_crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
- assert(m_crypto_service_context);
+ CHECK(m_crypto_service_context);
- m_rpc_session_handle = service_context_open(m_crypto_service_context, &caller);
- assert(m_rpc_session_handle);
+ m_rpc_session_handle = service_context_open(m_crypto_service_context, TS_RPC_ENCODING_PROTOBUF, &caller);
+ CHECK(m_rpc_session_handle);
m_crypto_client = new crypto_client(caller);
}
diff --git a/components/service/crypto/test/service/crypto_service_op_tests.cpp b/components/service/crypto/test/service/crypto_service_op_tests.cpp
index cd4bd04..569a196 100644
--- a/components/service/crypto/test/service/crypto_service_op_tests.cpp
+++ b/components/service/crypto/test/service/crypto_service_op_tests.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -7,8 +7,8 @@
#include <string>
#include <cstring>
#include <cstdint>
-#include <cassert>
#include <service/crypto/client/cpp/crypto_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
#include <service_locator.h>
#include <CppUTest/TestHarness.h>
@@ -31,10 +31,10 @@ TEST_GROUP(CryptoServiceOpTests)
service_locator_init();
m_crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
- assert(m_crypto_service_context);
+ CHECK_TRUE(m_crypto_service_context);
- m_rpc_session_handle = service_context_open(m_crypto_service_context, &caller);
- assert(m_rpc_session_handle);
+ m_rpc_session_handle = service_context_open(m_crypto_service_context, TS_RPC_ENCODING_PROTOBUF, &caller);
+ CHECK_TRUE(m_rpc_session_handle);
m_crypto_client = new crypto_client(caller);
}
diff --git a/components/service/locator/interface/service_locator.h b/components/service/locator/interface/service_locator.h
index 3e1404b..1fba453 100644
--- a/components/service/locator/interface/service_locator.h
+++ b/components/service/locator/interface/service_locator.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -93,9 +93,10 @@ struct service_location_strategy
/*
* Open an RPC session in order to use the service associated with this
- * service_context.
+ * service_context. The parameter encoding scheme that the client
+ * intends to use for serializing RPC parameters must be specified.
*/
-SERVICE_LOCATOR_EXPORTED rpc_session_handle service_context_open(struct service_context *s, struct rpc_caller **caller);
+SERVICE_LOCATOR_EXPORTED rpc_session_handle service_context_open(struct service_context *s, uint32_t encoding, struct rpc_caller **caller);
/*
* Close an RPC session.
diff --git a/components/service/locator/linux/ffa/linuxffa_service_context.c b/components/service/locator/linux/ffa/linuxffa_service_context.c
index 2af7c60..5242593 100644
--- a/components/service/locator/linux/ffa/linuxffa_service_context.c
+++ b/components/service/locator/linux/ffa/linuxffa_service_context.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -14,7 +14,8 @@ static void linuxffa_service_context_close(void *context, rpc_session_handle ses
static void linuxffa_service_context_relinquish(void *context);
-struct linuxffa_service_context *linuxffa_service_context_create(const char *dev_path, uint16_t partition_id)
+struct linuxffa_service_context *linuxffa_service_context_create(const char *dev_path,
+ uint16_t partition_id)
{
struct linuxffa_service_context *new_context =
(struct linuxffa_service_context*)malloc(sizeof(struct linuxffa_service_context));
@@ -42,7 +43,7 @@ static rpc_session_handle linuxffa_service_context_open(void *context, struct rp
int status;
*caller = ffarpc_caller_init(ffarpc_caller, this_context->ffa_dev_path);
- status = ffarpc_caller_open(ffarpc_caller, this_context->partition_id);
+ status = ffarpc_caller_open(ffarpc_caller, this_context->partition_id, 0);
if (status == 0) {
/* Successfully opened session */
diff --git a/components/service/locator/service_locator.c b/components/service/locator/service_locator.c
index 90cb457..6f1f218 100644
--- a/components/service/locator/service_locator.c
+++ b/components/service/locator/service_locator.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -55,9 +55,12 @@ struct service_context *service_locator_query(const char *sn, int *status)
return located_context;
}
-rpc_session_handle service_context_open(struct service_context *s, struct rpc_caller **caller)
+rpc_session_handle service_context_open(struct service_context *s, uint32_t encoding, struct rpc_caller **caller)
{
- return s->open(s->context, caller);
+ rpc_session_handle handle = s->open(s->context, caller);
+ if (handle) rpc_caller_set_encoding_scheme(*caller, encoding);
+
+ return handle;
}
void service_context_close(struct service_context *s, rpc_session_handle session_handle)
diff --git a/components/service/locator/standalone/services/crypto/crypto_service_context.cpp b/components/service/locator/standalone/services/crypto/crypto_service_context.cpp
index e3bc2e8..0545817 100644
--- a/components/service/locator/standalone/services/crypto/crypto_service_context.cpp
+++ b/components/service/locator/standalone/services/crypto/crypto_service_context.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "crypto_service_context.h"
+#include <service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.h>
crypto_service_context::crypto_service_context(const char *sn) :
standalone_service_context(sn),
@@ -22,11 +23,14 @@ crypto_service_context::~crypto_service_context()
void crypto_service_context::do_init()
{
- struct call_ep *storage_ep = sfs_provider_init(&m_storage_provider);
+ struct rpc_interface *storage_ep = sfs_provider_init(&m_storage_provider);
struct rpc_caller *storage_caller = direct_caller_init_default(&m_storage_caller, storage_ep);
- struct call_ep *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider, storage_caller);
+ struct rpc_interface *crypto_ep = mbed_crypto_provider_init(&m_crypto_provider, storage_caller);
- standalone_service_context::set_call_ep(crypto_ep);
+ mbed_crypto_provider_register_serializer(&m_crypto_provider,
+ TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
+
+ standalone_service_context::set_rpc_interface(crypto_ep);
}
void crypto_service_context::do_deinit()
diff --git a/components/service/locator/standalone/services/crypto/crypto_service_context.h b/components/service/locator/standalone/services/crypto/crypto_service_context.h
index 6e79163..44d5f99 100644
--- a/components/service/locator/standalone/services/crypto/crypto_service_context.h
+++ b/components/service/locator/standalone/services/crypto/crypto_service_context.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
diff --git a/components/service/locator/standalone/standalone_service_context.cpp b/components/service/locator/standalone/standalone_service_context.cpp
index 5e53ebe..13b8b1d 100644
--- a/components/service/locator/standalone/standalone_service_context.cpp
+++ b/components/service/locator/standalone/standalone_service_context.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -17,7 +17,7 @@ standalone_service_context::standalone_service_context(const char *sn) :
m_sn(sn),
m_ref_count(0),
m_service_context(),
- m_call_ep(NULL)
+ m_rpc_interface(NULL)
{
m_service_context.context = this;
m_service_context.open = standalone_service_context_open;
@@ -48,7 +48,7 @@ void standalone_service_context::deinit()
rpc_session_handle standalone_service_context::open(struct rpc_caller **caller)
{
- struct rpc_session *session = new rpc_session(m_call_ep);
+ struct rpc_session *session = new rpc_session(m_rpc_interface);
*caller = session->m_rpc_caller;
return static_cast<rpc_session_handle>(session);
}
@@ -69,16 +69,16 @@ struct service_context *standalone_service_context::get_service_context()
return &m_service_context;
}
-void standalone_service_context::set_call_ep(call_ep *ep)
+void standalone_service_context::set_rpc_interface(rpc_interface *iface)
{
- m_call_ep = ep;
+ m_rpc_interface = iface;
}
-standalone_service_context::rpc_session::rpc_session(struct call_ep *call_ep) :
+standalone_service_context::rpc_session::rpc_session(struct rpc_interface *rpc_interface) :
m_direct_caller(),
m_rpc_caller()
{
- m_rpc_caller = direct_caller_init_default(&m_direct_caller, call_ep);
+ m_rpc_caller = direct_caller_init_default(&m_direct_caller, rpc_interface);
}
standalone_service_context::rpc_session::~rpc_session()
diff --git a/components/service/locator/standalone/standalone_service_context.h b/components/service/locator/standalone/standalone_service_context.h
index d8ebb1f..2b5de68 100644
--- a/components/service/locator/standalone/standalone_service_context.h
+++ b/components/service/locator/standalone/standalone_service_context.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,7 +8,7 @@
#define STANDALONE_SERVICE_CONTEXT_H
#include <service_locator.h>
-#include <rpc/common/endpoint/call_ep.h>
+#include <rpc/common/endpoint/rpc_interface.h>
#include <rpc/direct/direct_caller.h>
#include <string>
@@ -28,7 +28,7 @@ public:
struct service_context *get_service_context();
protected:
- void set_call_ep(call_ep *ep);
+ void set_rpc_interface(rpc_interface *iface);
virtual void do_init() {}
virtual void do_deinit() {}
@@ -37,7 +37,7 @@ private:
struct rpc_session
{
- rpc_session(struct call_ep *call_ep);
+ rpc_session(struct rpc_interface *rpc_interface);
~rpc_session();
struct direct_caller m_direct_caller;
@@ -47,7 +47,7 @@ private:
std::string m_sn;
int m_ref_count;
struct service_context m_service_context;
- struct call_ep *m_call_ep;
+ struct rpc_interface *m_rpc_interface;
};
#endif /* STANDALONE_SERVICE_CONTEXT_H */
diff --git a/components/service/secure_storage/provider/mock_store/mock_store_provider.c b/components/service/secure_storage/provider/mock_store/mock_store_provider.c
index 9f1ce2e..b5eda2c 100644
--- a/components/service/secure_storage/provider/mock_store/mock_store_provider.c
+++ b/components/service/secure_storage/provider/mock_store/mock_store_provider.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -21,13 +21,13 @@ static rpc_status_t remove_handler(void *context, struct call_req* req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
- {TS_SECURE_STORAGE_OPCODE_SET, set_handler},
- {TS_SECURE_STORAGE_OPCODE_GET, get_handler},
- {TS_SECURE_STORAGE_OPCODE_GET_INFO, get_info_handler},
- {TS_SECURE_STORAGE_OPCODE_REMOVE, remove_handler}
+ {TS_SECURE_STORAGE_OPCODE_SET, set_handler},
+ {TS_SECURE_STORAGE_OPCODE_GET, get_handler},
+ {TS_SECURE_STORAGE_OPCODE_GET_INFO, get_info_handler},
+ {TS_SECURE_STORAGE_OPCODE_REMOVE, remove_handler}
};
-struct call_ep *mock_store_provider_init(struct mock_store_provider *context)
+struct rpc_interface *mock_store_provider_init(struct mock_store_provider *context)
{
for (int i = 0; i < MOCK_STORE_NUM_SLOTS; ++i) {
@@ -40,7 +40,7 @@ struct call_ep *mock_store_provider_init(struct mock_store_provider *context)
service_provider_init(&context->base_provider, context,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
- return service_provider_get_call_ep(&context->base_provider);
+ return service_provider_get_rpc_interface(&context->base_provider);
}
void mock_store_provider_deinit(struct mock_store_provider *context)
@@ -120,21 +120,21 @@ static rpc_status_t set_handler(void *context, struct call_req *req)
psa_status_t psa_status = PSA_ERROR_INSUFFICIENT_MEMORY;
struct mock_store_provider *this_context = (struct mock_store_provider*)context;
struct mock_store_slot *slot;
- struct secure_storage_request_set *request_desc;
+ struct secure_storage_request_set *request_desc;
- /* Checking if the descriptor fits into the request buffer */
- if (req->req_buf.data_len < sizeof(struct secure_storage_request_set))
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking if the descriptor fits into the request buffer */
+ if (req->req_buf.data_len < sizeof(struct secure_storage_request_set))
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
- request_desc = (struct secure_storage_request_set *)(req->req_buf.data);
+ request_desc = (struct secure_storage_request_set *)(req->req_buf.data);
- /* Checking for overflow */
- if (sizeof(struct secure_storage_request_set) + request_desc->data_length < request_desc->data_length)
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking for overflow */
+ if (sizeof(struct secure_storage_request_set) + request_desc->data_length < request_desc->data_length)
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
- /* Checking if descriptor and data fits into the request buffer */
- if (req->req_buf.data_len < sizeof(struct secure_storage_request_set) + request_desc->data_length)
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking if descriptor and data fits into the request buffer */
+ if (req->req_buf.data_len < sizeof(struct secure_storage_request_set) + request_desc->data_length)
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
/* Replace existing or add new item */
slot = find_slot(this_context, request_desc->uid);
@@ -152,27 +152,27 @@ static rpc_status_t set_handler(void *context, struct call_req *req)
}
}
- call_req_set_opstatus(req, psa_status);
+ call_req_set_opstatus(req, psa_status);
- return TS_RPC_CALL_ACCEPTED;
+ return TS_RPC_CALL_ACCEPTED;
}
static rpc_status_t get_handler(void *context, struct call_req *req)
{
- struct mock_store_provider *this_context = (struct mock_store_provider*)context;
+ struct mock_store_provider *this_context = (struct mock_store_provider*)context;
struct secure_storage_request_get *request_desc;
- psa_status_t psa_status = PSA_ERROR_DOES_NOT_EXIST;
+ psa_status_t psa_status = PSA_ERROR_DOES_NOT_EXIST;
struct mock_store_slot *slot;
- /* Checking if the descriptor fits into the request buffer */
- if (req->req_buf.data_len < sizeof(struct secure_storage_request_get))
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking if the descriptor fits into the request buffer */
+ if (req->req_buf.data_len < sizeof(struct secure_storage_request_get))
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
- request_desc = (struct secure_storage_request_get *)(req->req_buf.data);
+ request_desc = (struct secure_storage_request_get *)(req->req_buf.data);
- /* Check if the requested data would fit into the response buffer. */
- if (req->resp_buf.size < request_desc->data_size)
- return TS_RPC_ERROR_INVALID_RESP_BODY;
+ /* Check if the requested data would fit into the response buffer. */
+ if (req->resp_buf.size < request_desc->data_size)
+ return TS_RPC_ERROR_INVALID_RESP_BODY;
/* Find the item */
slot = find_slot(this_context, request_desc->uid);
@@ -183,28 +183,28 @@ static rpc_status_t get_handler(void *context, struct call_req *req)
psa_status = PSA_SUCCESS;
}
- call_req_set_opstatus(req, psa_status);
+ call_req_set_opstatus(req, psa_status);
- return TS_RPC_CALL_ACCEPTED;
+ return TS_RPC_CALL_ACCEPTED;
}
static rpc_status_t get_info_handler(void *context, struct call_req *req)
{
- struct mock_store_provider *this_context = (struct mock_store_provider*)context;
+ struct mock_store_provider *this_context = (struct mock_store_provider*)context;
struct secure_storage_request_get_info *request_desc;
- struct secure_storage_response_get_info *response_desc;
- psa_status_t psa_status;
+ struct secure_storage_response_get_info *response_desc;
+ psa_status_t psa_status;
struct mock_store_slot *slot;
- /* Checking if the descriptor fits into the request buffer */
- if (req->req_buf.data_len < sizeof(struct secure_storage_request_get_info))
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking if the descriptor fits into the request buffer */
+ if (req->req_buf.data_len < sizeof(struct secure_storage_request_get_info))
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
- request_desc = (struct secure_storage_request_get_info *)(req->req_buf.data);
+ request_desc = (struct secure_storage_request_get_info *)(req->req_buf.data);
- /* Checking if the response structure would fit the response buffer */
- if (req->resp_buf.size < sizeof(struct secure_storage_response_get_info))
- return TS_RPC_ERROR_INVALID_RESP_BODY;
+ /* Checking if the response structure would fit the response buffer */
+ if (req->resp_buf.size < sizeof(struct secure_storage_response_get_info))
+ return TS_RPC_ERROR_INVALID_RESP_BODY;
response_desc = (struct secure_storage_response_get_info *)(req->resp_buf.data);
req->resp_buf.data_len = sizeof(struct secure_storage_response_get_info);
@@ -227,21 +227,21 @@ static rpc_status_t get_info_handler(void *context, struct call_req *req)
call_req_set_opstatus(req, psa_status);
- return TS_RPC_CALL_ACCEPTED;
+ return TS_RPC_CALL_ACCEPTED;
}
static rpc_status_t remove_handler(void *context, struct call_req *req)
{
- struct mock_store_provider *this_context = (struct mock_store_provider*)context;
+ struct mock_store_provider *this_context = (struct mock_store_provider*)context;
struct secure_storage_request_remove *request_desc;
- psa_status_t psa_status = PSA_ERROR_DOES_NOT_EXIST;
+ psa_status_t psa_status = PSA_ERROR_DOES_NOT_EXIST;
struct mock_store_slot *slot;
- /* Checking if the descriptor fits into the request buffer */
- if (req->req_buf.data_len < sizeof(struct secure_storage_request_remove))
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ /* Checking if the descriptor fits into the request buffer */
+ if (req->req_buf.data_len < sizeof(struct secure_storage_request_remove))
+ return TS_RPC_ERROR_INVALID_REQ_BODY;
- request_desc = (struct secure_storage_request_remove *)(req->req_buf.data);
+ request_desc = (struct secure_storage_request_remove *)(req->req_buf.data);
/* Find and remove the item */
slot = find_slot(this_context, request_desc->uid);
@@ -253,5 +253,5 @@ static rpc_status_t remove_handler(void *context, struct call_req *req)
call_req_set_opstatus(req, psa_status);
- return TS_RPC_CALL_ACCEPTED;
+ return TS_RPC_CALL_ACCEPTED;
} \ No newline at end of file
diff --git a/components/service/secure_storage/provider/mock_store/mock_store_provider.h b/components/service/secure_storage/provider/mock_store/mock_store_provider.h
index ecb457a..9d2c136 100644
--- a/components/service/secure_storage/provider/mock_store/mock_store_provider.h
+++ b/components/service/secure_storage/provider/mock_store/mock_store_provider.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -31,7 +31,7 @@ struct mock_store_provider
struct mock_store_slot slots[MOCK_STORE_NUM_SLOTS];
};
-struct call_ep *mock_store_provider_init(struct mock_store_provider *context);
+struct rpc_interface *mock_store_provider_init(struct mock_store_provider *context);
void mock_store_provider_deinit(struct mock_store_provider *context);
/* Test support methods */
diff --git a/components/service/secure_storage/provider/secure_flash_store/sfs_provider.c b/components/service/secure_storage/provider/secure_flash_store/sfs_provider.c
index 5c801ed..76b6cba 100644
--- a/components/service/secure_storage/provider/secure_flash_store/sfs_provider.c
+++ b/components/service/secure_storage/provider/secure_flash_store/sfs_provider.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -9,7 +9,7 @@
#include <protocols/service/secure_storage/packed-c/secure_storage_proto.h>
#include <protocols/service/psa/packed-c/status.h>
#include <protocols/rpc/common/packed-c/status.h>
-#include <components/rpc/common/endpoint/call_ep.h>
+#include <components/rpc/common/endpoint/rpc_interface.h>
#include <stdio.h>
@@ -21,9 +21,9 @@ static const struct service_handler handler_table[] = {
{TS_SECURE_STORAGE_OPCODE_REMOVE, sfs_remove_handler}
};
-struct call_ep *sfs_provider_init(struct sfs_provider *context)
+struct rpc_interface *sfs_provider_init(struct sfs_provider *context)
{
- struct call_ep *call_ep = NULL;
+ struct rpc_interface *rpc_interface = NULL;
if (context == NULL)
goto out;
@@ -34,10 +34,10 @@ struct call_ep *sfs_provider_init(struct sfs_provider *context)
service_provider_init(&context->base_provider, context, handler_table,
sizeof(handler_table) / sizeof(handler_table[0]));
- call_ep = service_provider_get_call_ep(&context->base_provider);
+ rpc_interface = service_provider_get_rpc_interface(&context->base_provider);
out:
- return call_ep;
+ return rpc_interface;
}
rpc_status_t sfs_set_handler(void *context, struct call_req *req)
diff --git a/components/service/secure_storage/provider/secure_flash_store/sfs_provider.h b/components/service/secure_storage/provider/secure_flash_store/sfs_provider.h
index 82887de..a1d4c9c 100644
--- a/components/service/secure_storage/provider/secure_flash_store/sfs_provider.h
+++ b/components/service/secure_storage/provider/secure_flash_store/sfs_provider.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -17,7 +17,7 @@ struct sfs_provider {
struct service_provider base_provider;
};
-struct call_ep *sfs_provider_init(struct sfs_provider *context);
+struct rpc_interface *sfs_provider_init(struct sfs_provider *context);
rpc_status_t sfs_set_handler(void *context, struct call_req *req);
rpc_status_t sfs_get_handler(void *context, struct call_req *req);
rpc_status_t sfs_get_info_handler(void *context, struct call_req *req);
diff --git a/components/service/secure_storage/test/its_tests.cpp b/components/service/secure_storage/test/its_tests.cpp
index fbd432d..9ec24e4 100644
--- a/components/service/secure_storage/test/its_tests.cpp
+++ b/components/service/secure_storage/test/its_tests.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -17,7 +17,7 @@ TEST_GROUP(InternalTrustedStorageTests)
{
void setup()
{
- struct call_ep *storage_ep = sfs_provider_init(&m_storage_provider);
+ struct rpc_interface *storage_ep = sfs_provider_init(&m_storage_provider);
struct rpc_caller *storage_caller = direct_caller_init_default(&m_storage_caller, storage_ep);
psa_its_client_init(storage_caller);
}
diff --git a/deployments/crypto/opteesp/crypto_sp.c b/deployments/crypto/opteesp/crypto_sp.c
index 17e9cf4..5756d1b 100644
--- a/deployments/crypto/opteesp/crypto_sp.c
+++ b/deployments/crypto/opteesp/crypto_sp.c
@@ -8,6 +8,7 @@
#include <rpc/dummy/dummy_caller.h>
#include <service/secure_storage/client/psa/its/its_client.h>
#include <service/crypto/provider/mbedcrypto/crypto_provider.h>
+#include <service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.h>
#include <protocols/rpc/common/packed-c/status.h>
#include <ffa_api.h>
#include <sp_api.h>
@@ -29,7 +30,7 @@ void __noreturn sp_main(struct ffa_init_info *init_info)
{
struct mbed_crypto_provider crypto_provider;
struct ffa_call_ep ffarpc_call_ep;
- struct call_ep *crypto_ep;
+ struct rpc_interface *crypto_iface;
struct ffarpc_caller ffarpc_caller;
struct dummy_caller dummy_caller;
struct rpc_caller *storage_caller;
@@ -45,7 +46,7 @@ void __noreturn sp_main(struct ffa_init_info *init_info)
storage_caller = ffarpc_caller_init(&ffarpc_caller);
if (!ffarpc_caller_discover(storage_uuid, storage_sp_ids, sizeof(storage_sp_ids)/sizeof(uint16_t)) ||
- ffarpc_caller_open(&ffarpc_caller, storage_sp_ids[0])) {
+ ffarpc_caller_open(&ffarpc_caller, storage_sp_ids[0], 0)) {
/*
* Failed to establish session. To allow the crypto service
* to still be initialized, albeit with no persistent storage,
@@ -57,8 +58,11 @@ void __noreturn sp_main(struct ffa_init_info *init_info)
}
/* Initialize the crypto service */
- crypto_ep = mbed_crypto_provider_init(&crypto_provider, storage_caller);
- ffa_call_ep_init(&ffarpc_call_ep, crypto_ep);
+ crypto_iface = mbed_crypto_provider_init(&crypto_provider, storage_caller);
+ mbed_crypto_provider_register_serializer(&crypto_provider,
+ TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
+
+ ffa_call_ep_init(&ffarpc_call_ep, crypto_iface);
/* End of boot phase */
ffa_msg_wait(&req_msg);
diff --git a/deployments/secure-storage/opteesp/sp.c b/deployments/secure-storage/opteesp/sp.c
index d04dbb2..c24423c 100644
--- a/deployments/secure-storage/opteesp/sp.c
+++ b/deployments/secure-storage/opteesp/sp.c
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "sp.h"
#include <ffa_api.h>
-#include <components/rpc/common/endpoint/call_ep.h>
+#include <components/rpc/common/endpoint/rpc_interface.h>
#include <components/rpc/ffarpc/endpoint/ffarpc_call_ep.h>
#include <components/service/secure_storage/provider/secure_flash_store/sfs_provider.h>
#include <components/service/common/provider/service_provider.h>
@@ -22,7 +22,7 @@ void sp_main(struct ffa_init_info *init_info)
{
ffa_result ffa_res;
sp_result sp_res;
- struct call_ep *sfs_ep;
+ struct rpc_interface *sfs_iface;
struct ffa_call_ep ffa_call_ep;
struct ffa_direct_msg req_msg;
struct ffa_direct_msg resp_msg;
@@ -41,8 +41,8 @@ void sp_main(struct ffa_init_info *init_info)
EMSG("rxtx map error: %d", sp_res);
}
- sfs_ep = sfs_provider_init(&sfs_provider);
- ffa_call_ep_init(&ffa_call_ep, sfs_ep);
+ sfs_iface = sfs_provider_init(&sfs_provider);
+ ffa_call_ep_init(&ffa_call_ep, sfs_iface);
/* End of boot phase */
ffa_msg_wait(&req_msg);
diff --git a/deployments/sfs-demo/opteesp/sp.c b/deployments/sfs-demo/opteesp/sp.c
index eec703f..5bda8e9 100644
--- a/deployments/sfs-demo/opteesp/sp.c
+++ b/deployments/sfs-demo/opteesp/sp.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -160,7 +160,7 @@ void __noreturn sp_main(struct ffa_init_info *init_info) {
}
IMSG("ITS SP ID: 0x%x", sp_ids[0]);
- if (ffarpc_caller_open(&ffa_caller, sp_ids[0])) {
+ if (ffarpc_caller_open(&ffa_caller, sp_ids[0], 0)) {
goto err;
}
diff --git a/deployments/ts-demo/ts-demo.cpp b/deployments/ts-demo/ts-demo.cpp
index e055bad..eaa8b52 100644
--- a/deployments/ts-demo/ts-demo.cpp
+++ b/deployments/ts-demo/ts-demo.cpp
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*/
#include <service/crypto/client/cpp/crypto_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
#include <app/ts-demo/ts-demo.h>
#include <service_locator.h>
#include <rpc_caller.h>
@@ -24,7 +25,7 @@ int main(int argc, char *argv[]) {
struct rpc_caller *caller;
rpc_session_handle rpc_session_handle;
- rpc_session_handle = service_context_open(crypto_service_context, &caller);
+ rpc_session_handle = service_context_open(crypto_service_context, TS_RPC_ENCODING_PROTOBUF, &caller);
if (rpc_session_handle) {
diff --git a/protocols/rpc/common/packed-c/encoding.h b/protocols/rpc/common/packed-c/encoding.h
new file mode 100644
index 0000000..cd7093c
--- /dev/null
+++ b/protocols/rpc/common/packed-c/encoding.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOCOLS_RPC_COMMON_ENCODING_H
+#define PROTOCOLS_RPC_COMMON_ENCODING_H
+
+/*
+ * Encodings used for parameter serialization.
+ */
+enum
+{
+ /*
+ * Packed-c encoding. A lightweight serialization scheme with
+ * C language definition files.
+ */
+ TS_RPC_ENCODING_PACKED_C = 0,
+
+ /*
+ * Protocol Buffers serialization scheme with language independent
+ * definition files. Supports client code generation using definition
+ * files.
+ */
+ TS_RPC_ENCODING_PROTOBUF = 1,
+
+ /*
+ * The limit of known encodings. As new encodings are added,
+ * the limit value should be allowed to increase. An RPC interface
+ * that was built before a new encoding was added should safely
+ * reject an unsupported encoding.
+ */
+ TS_RPC_ENCODING_LIMIT
+};
+
+#endif /* PROTOCOLS_RPC_COMMON_ENCODING_H */
diff --git a/protocols/rpc/common/packed-c/header.h b/protocols/rpc/common/packed-c/header.h
new file mode 100644
index 0000000..2542dbd
--- /dev/null
+++ b/protocols/rpc/common/packed-c/header.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOCOLS_RPC_COMMON_HEADER_H
+#define PROTOCOLS_RPC_COMMON_HEADER_H
+
+#include <stdint.h>
+
+/*
+ * Defines an RPC request header that may be used for a packed-c serialization
+ * of common RPC fields. Different RPC protocols my carry some or all of these
+ * fields in a protocol specific way. If a particular protocol does't, this
+ * structure provides a common definition that may be used.
+ */
+struct __attribute__ ((__packed__)) ts_rpc_req_hdr
+{
+ /*
+ * A trustworthy identifier for the call originator. Used for access control, applied
+ * at the remote RPC interface. This ID will have been added by an intermediary running
+ * at a higher privilege level than the caller. Example caller_ids could be the UID
+ * or SELinux label associated with a calling process. The caller_id may be supplemented
+ * by a source identity from the messaging layer (e.g. the source partition ID).
+ */
+ uint32_t caller_id;
+
+ /*
+ * Identifies a particular RPC interface instance that is reachable at a messaging
+ * endpoint. Allows multiple services to be co-located at a single messaging endpoint.
+ */
+ uint16_t interface_id;
+
+ /*
+ * Identifies the requested operation to call.
+ */
+ uint16_t opcode;
+
+ /*
+ * Identifies the encoding scheme used to serialize request and response parameters.
+ * It is the responsibility of the caller to specify an encoding that the destination
+ * RPC interface can handle. Must be set to a meaningful value, even if there are
+ * no request parameters. This is because response parameters will beb serialized
+ * using the same encoding.
+ */
+ uint16_t encoding;
+
+ /*
+ * Specifies the length in bytes of the serialized parameters.
+ */
+ uint16_t param_len;
+};
+
+/*
+ * Defines the coresponding response header, used for returning status and
+ * any output parameters, serialized using the same encoding as specified in
+ * the request header.
+ */
+struct __attribute__ ((__packed__)) ts_rpc_resp_hdr
+{
+ /*
+ * Returns the RPC layer status. Only if a value of TS_RPC_CALL_ACCEPTED
+ * is returned should the opstatus value be consider. The RPC status is
+ * kept separate from the opstatus to allow a service specific status coding
+ * namespace to coexist with the RPC status namespace.
+ */
+ int16_t rpc_status;
+
+ /*
+ * Returns the status of the requested operation. The meaning of this status
+ * code will be service specific.
+ */
+ int16_t op_status;
+
+ /*
+ * Specifies the length in bytes of the serialized parameters.
+ */
+ uint16_t param_len;
+};
+
+#endif /* PROTOCOLS_RPC_COMMON_HEADER_H */
diff --git a/protocols/rpc/common/packed-c/status.h b/protocols/rpc/common/packed-c/status.h
index 7f78429..3838240 100644
--- a/protocols/rpc/common/packed-c/status.h
+++ b/protocols/rpc/common/packed-c/status.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -13,16 +13,19 @@
* alternative languages is checked through a set of test cases.
* These status values are aligned to PSA definitions.
*/
-#define TS_RPC_CALL_ACCEPTED (0)
-#define TS_RPC_ERROR_EP_DOES_NOT_EXIT (-1)
-#define TS_RPC_ERROR_INVALID_OPCODE (-2)
-#define TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED (-3)
-#define TS_RPC_ERROR_INVALID_REQ_BODY (-4)
-#define TS_RPC_ERROR_INVALID_RESP_BODY (-5)
-#define TS_RPC_ERROR_RESOURCE_FAILURE (-6)
-#define TS_RPC_ERROR_NOT_READY (-7)
-#define TS_RPC_ERROR_INVALID_TRANSACTION (-8)
-#define TS_RPC_ERROR_INTERNAL (-9)
-#define TS_RPC_ERROR_INVALID_PARAMETER (-10)
+enum
+{
+ TS_RPC_CALL_ACCEPTED = 0,
+ TS_RPC_ERROR_EP_DOES_NOT_EXIT = -1,
+ TS_RPC_ERROR_INVALID_OPCODE = -2,
+ TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED = -3,
+ TS_RPC_ERROR_INVALID_REQ_BODY = -4,
+ TS_RPC_ERROR_INVALID_RESP_BODY = -5,
+ TS_RPC_ERROR_RESOURCE_FAILURE = -6,
+ TS_RPC_ERROR_NOT_READY = -7,
+ TS_RPC_ERROR_INVALID_TRANSACTION = -8,
+ TS_RPC_ERROR_INTERNAL = -9,
+ TS_RPC_ERROR_INVALID_PARAMETER = -10
+};
#endif /* PROTOCOLS_RPC_COMMON_STATUS_H */