Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 1 | /* |
| 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 Hall | 628be29 | 2021-08-04 16:57:40 +0100 | [diff] [blame] | 10 | #include <service/discovery/client/discovery_client.h> |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 11 | #include <protocols/rpc/common/packed-c/encoding.h> |
| 12 | #include "../service_under_test.h" |
| 13 | |
| 14 | /* RPC context */ |
| 15 | static rpc_session_handle session_handle = NULL; |
| 16 | static struct service_context *crypto_service_context = NULL; |
| 17 | |
Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 18 | int locate_service_under_test(struct logging_caller *call_logger) |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 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 | |
Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 36 | 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 Hall | 628be29 | 2021-08-04 16:57:40 +0100 | [diff] [blame] | 45 | discovery_client_get_service_info(psa_crypto_client_base()); |
| 46 | |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 47 | status = 0; |
| 48 | } |
| 49 | else { |
| 50 | |
| 51 | status = -1; |
| 52 | relinquish_service_under_test(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return status; |
| 58 | } |
| 59 | |
| 60 | void 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 | } |