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> |
| 10 | #include <protocols/rpc/common/packed-c/encoding.h> |
| 11 | #include "../service_under_test.h" |
| 12 | |
| 13 | /* RPC context */ |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 14 | static struct rpc_caller_session *session = NULL; |
| 15 | static struct service_context *attestation_service_context = NULL; |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 16 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 17 | int locate_service_under_test(void) |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 18 | { |
| 19 | int status = -1; |
| 20 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 21 | if (!session && !attestation_service_context) { |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 22 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 23 | service_locator_init(); |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 24 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 25 | attestation_service_context = |
| 26 | service_locator_query("sn:trustedfirmware.org:crypto:0"); |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 27 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 28 | if (attestation_service_context) { |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 29 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 30 | session = service_context_open(attestation_service_context); |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 31 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 32 | if (session) { |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 33 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 34 | psa_crypto_client_init(session); |
Julian Hall | 628be29 | 2021-08-04 16:57:40 +0100 | [diff] [blame] | 35 | |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 36 | status = 0; |
| 37 | } |
| 38 | else { |
| 39 | |
| 40 | status = -1; |
| 41 | relinquish_service_under_test(); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return status; |
| 47 | } |
| 48 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 49 | int relinquish_service_under_test(void) |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 50 | { |
| 51 | psa_crypto_client_deinit(); |
| 52 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 53 | if (attestation_service_context && session) { |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 54 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 55 | service_context_close(attestation_service_context, session); |
| 56 | session = NULL; |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 59 | if (attestation_service_context) { |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 60 | |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 61 | service_context_relinquish(attestation_service_context); |
| 62 | attestation_service_context = NULL; |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 63 | } |
Balint Dobszay | 3ddded3 | 2023-07-11 10:53:25 +0200 | [diff] [blame] | 64 | |
| 65 | return 0; |
Julian Hall | d407138 | 2021-07-07 16:45:53 +0100 | [diff] [blame] | 66 | } |