blob: 7f58d4ab3da0574c3e86bd5734ce033b8e1137ff [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>
Julian Hall628be292021-08-04 16:57:40 +010010#include <service/discovery/client/discovery_client.h>
Julian Halld4071382021-07-07 16:45:53 +010011#include <protocols/rpc/common/packed-c/encoding.h>
12#include "../service_under_test.h"
13
14/* RPC context */
15static rpc_session_handle session_handle = NULL;
16static struct service_context *crypto_service_context = NULL;
17
Julian Hall04460402021-07-08 17:40:57 +010018int locate_service_under_test(struct logging_caller *call_logger)
Julian Halld4071382021-07-07 16:45:53 +010019{
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
Julian Hall04460402021-07-08 17:40:57 +010036 if (call_logger) {
37
38 psa_crypto_client_init(logging_caller_attach(call_logger, caller));
39 }
40 else {
41
42 psa_crypto_client_init(caller);
43 }
44
Julian Hall628be292021-08-04 16:57:40 +010045 discovery_client_get_service_info(psa_crypto_client_base());
46
Julian Halld4071382021-07-07 16:45:53 +010047 status = 0;
48 }
49 else {
50
51 status = -1;
52 relinquish_service_under_test();
53 }
54 }
55 }
56
57 return status;
58}
59
60void relinquish_service_under_test(void)
61{
62 psa_crypto_client_deinit();
63
64 if (crypto_service_context && session_handle) {
65
66 service_context_close(crypto_service_context, session_handle);
67 session_handle = NULL;
68 }
69
70 if (crypto_service_context) {
71
72 service_context_relinquish(crypto_service_context);
73 crypto_service_context = NULL;
74 }
75}