blob: 8571b23e6e0f66ce541ea96ddb0f421ac83e98b6 [file] [log] [blame]
Julian Halld4071382021-07-07 16:45:53 +01001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stddef.h>
8#include <service_locator.h>
9#include <service/crypto/client/psa/psa_crypto_client.h>
10#include <protocols/rpc/common/packed-c/encoding.h>
11#include "../service_under_test.h"
12
13/* RPC context */
14static rpc_session_handle session_handle = NULL;
15static struct service_context *crypto_service_context = NULL;
16
17
18int locate_service_under_test(void)
19{
20 int status = -1;
21
22 if (!session_handle && !crypto_service_context) {
23
24 struct rpc_caller *caller;
25
26 crypto_service_context =
27 service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
28
29 if (crypto_service_context) {
30
31 session_handle =
32 service_context_open(crypto_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
33
34 if (session_handle) {
35
36 psa_crypto_client_init(caller);
37 status = 0;
38 }
39 else {
40
41 status = -1;
42 relinquish_service_under_test();
43 }
44 }
45 }
46
47 return status;
48}
49
50void relinquish_service_under_test(void)
51{
52 psa_crypto_client_deinit();
53
54 if (crypto_service_context && session_handle) {
55
56 service_context_close(crypto_service_context, session_handle);
57 session_handle = NULL;
58 }
59
60 if (crypto_service_context) {
61
62 service_context_relinquish(crypto_service_context);
63 crypto_service_context = NULL;
64 }
65}