TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "psa/internal_trusted_storage.h" |
| 9 | #include "tfm_api.h" |
| 10 | |
| 11 | #include "psa/client.h" |
| 12 | #include "psa_manifest/sid.h" |
| 13 | |
| 14 | #define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) |
| 15 | |
| 16 | psa_status_t psa_its_set(psa_storage_uid_t uid, |
| 17 | size_t data_length, |
| 18 | const void *p_data, |
| 19 | psa_storage_create_flags_t create_flags) |
| 20 | { |
| 21 | psa_status_t status; |
| 22 | psa_handle_t handle; |
| 23 | |
| 24 | psa_invec in_vec[] = { |
| 25 | { .base = &uid, .len = sizeof(uid) }, |
| 26 | { .base = p_data, .len = data_length }, |
| 27 | { .base = &create_flags, .len = sizeof(create_flags) } |
| 28 | }; |
| 29 | |
| 30 | handle = psa_connect(TFM_ITS_SET_SID, TFM_ITS_SET_VERSION); |
| 31 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 32 | return PSA_ERROR_GENERIC_ERROR; |
| 33 | } |
| 34 | |
| 35 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, 0); |
| 36 | |
| 37 | psa_close(handle); |
| 38 | |
TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 39 | return status; |
| 40 | } |
| 41 | |
| 42 | psa_status_t psa_its_get(psa_storage_uid_t uid, |
| 43 | size_t data_offset, |
| 44 | size_t data_size, |
| 45 | void *p_data, |
| 46 | size_t *p_data_length) |
| 47 | { |
| 48 | psa_status_t status; |
| 49 | psa_handle_t handle; |
| 50 | |
| 51 | psa_invec in_vec[] = { |
| 52 | { .base = &uid, .len = sizeof(uid) }, |
| 53 | { .base = &data_offset, .len = sizeof(data_offset) } |
| 54 | }; |
| 55 | |
| 56 | psa_outvec out_vec[] = { |
| 57 | { .base = p_data, .len = data_size } |
| 58 | }; |
| 59 | |
| 60 | if (p_data_length == NULL) { |
| 61 | return PSA_ERROR_INVALID_ARGUMENT; |
| 62 | } |
| 63 | |
| 64 | handle = psa_connect(TFM_ITS_GET_SID, TFM_ITS_GET_VERSION); |
| 65 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 66 | return PSA_ERROR_GENERIC_ERROR; |
| 67 | } |
| 68 | |
| 69 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec, |
| 70 | IOVEC_LEN(out_vec)); |
| 71 | |
| 72 | psa_close(handle); |
| 73 | |
TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 74 | *p_data_length = out_vec[0].len; |
| 75 | |
| 76 | return status; |
| 77 | } |
| 78 | |
| 79 | psa_status_t psa_its_get_info(psa_storage_uid_t uid, |
| 80 | struct psa_storage_info_t *p_info) |
| 81 | { |
| 82 | psa_status_t status; |
| 83 | psa_handle_t handle; |
| 84 | |
| 85 | psa_invec in_vec[] = { |
| 86 | { .base = &uid, .len = sizeof(uid) } |
| 87 | }; |
| 88 | |
| 89 | psa_outvec out_vec[] = { |
| 90 | { .base = p_info, .len = sizeof(*p_info) } |
| 91 | }; |
| 92 | |
| 93 | handle = psa_connect(TFM_ITS_GET_INFO_SID, TFM_ITS_GET_INFO_VERSION); |
| 94 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 95 | return PSA_ERROR_GENERIC_ERROR; |
| 96 | } |
| 97 | |
| 98 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec, |
| 99 | IOVEC_LEN(out_vec)); |
| 100 | |
| 101 | psa_close(handle); |
| 102 | |
TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 103 | return status; |
| 104 | } |
| 105 | |
| 106 | psa_status_t psa_its_remove(psa_storage_uid_t uid) |
| 107 | { |
| 108 | psa_status_t status; |
| 109 | psa_handle_t handle; |
| 110 | |
| 111 | psa_invec in_vec[] = { |
| 112 | { .base = &uid, .len = sizeof(uid) } |
| 113 | }; |
| 114 | |
| 115 | handle = psa_connect(TFM_ITS_REMOVE_SID, TFM_ITS_REMOVE_VERSION); |
| 116 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 117 | return PSA_ERROR_GENERIC_ERROR; |
| 118 | } |
| 119 | |
| 120 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, 0); |
| 121 | |
| 122 | psa_close(handle); |
| 123 | |
| 124 | return status; |
| 125 | } |