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 "tfm_ns_interface.h" |
| 12 | #include "tfm_veneers.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 | |
| 23 | psa_invec in_vec[] = { |
| 24 | { .base = &uid, .len = sizeof(uid) }, |
| 25 | { .base = p_data, .len = data_length }, |
| 26 | { .base = &create_flags, .len = sizeof(create_flags) } |
| 27 | }; |
| 28 | |
| 29 | status = tfm_ns_interface_dispatch((veneer_fn)tfm_tfm_its_set_req_veneer, |
| 30 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 31 | (uint32_t)NULL, 0); |
| 32 | |
| 33 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 34 | return PSA_ERROR_INVALID_ARGUMENT; |
| 35 | } |
| 36 | |
| 37 | return status; |
| 38 | } |
| 39 | |
| 40 | psa_status_t psa_its_get(psa_storage_uid_t uid, |
| 41 | size_t data_offset, |
| 42 | size_t data_size, |
| 43 | void *p_data, |
| 44 | size_t *p_data_length) |
| 45 | { |
| 46 | psa_status_t status; |
| 47 | |
| 48 | psa_invec in_vec[] = { |
| 49 | { .base = &uid, .len = sizeof(uid) }, |
| 50 | { .base = &data_offset, .len = sizeof(data_offset) } |
| 51 | }; |
| 52 | |
| 53 | psa_outvec out_vec[] = { |
| 54 | { .base = p_data, .len = data_size } |
| 55 | }; |
| 56 | |
| 57 | if (p_data_length == NULL) { |
| 58 | return PSA_ERROR_INVALID_ARGUMENT; |
| 59 | } |
| 60 | |
| 61 | status = tfm_ns_interface_dispatch((veneer_fn)tfm_tfm_its_get_req_veneer, |
| 62 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 63 | (uint32_t)out_vec, IOVEC_LEN(out_vec)); |
| 64 | |
| 65 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 66 | return PSA_ERROR_INVALID_ARGUMENT; |
| 67 | } |
| 68 | |
| 69 | *p_data_length = out_vec[0].len; |
| 70 | |
| 71 | return status; |
| 72 | } |
| 73 | |
| 74 | psa_status_t psa_its_get_info(psa_storage_uid_t uid, |
| 75 | struct psa_storage_info_t *p_info) |
| 76 | { |
| 77 | psa_status_t status; |
| 78 | |
| 79 | psa_invec in_vec[] = { |
| 80 | { .base = &uid, .len = sizeof(uid) } |
| 81 | }; |
| 82 | |
| 83 | psa_outvec out_vec[] = { |
| 84 | { .base = p_info, .len = sizeof(*p_info) } |
| 85 | }; |
| 86 | |
| 87 | status = tfm_ns_interface_dispatch( |
| 88 | (veneer_fn)tfm_tfm_its_get_info_req_veneer, |
| 89 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 90 | (uint32_t)out_vec, IOVEC_LEN(out_vec)); |
| 91 | |
| 92 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 93 | return PSA_ERROR_INVALID_ARGUMENT; |
| 94 | } |
| 95 | |
| 96 | return status; |
| 97 | } |
| 98 | |
| 99 | psa_status_t psa_its_remove(psa_storage_uid_t uid) |
| 100 | { |
| 101 | psa_invec in_vec[] = { |
| 102 | { .base = &uid, .len = sizeof(uid) } |
| 103 | }; |
| 104 | |
| 105 | return tfm_ns_interface_dispatch((veneer_fn)tfm_tfm_its_remove_req_veneer, |
| 106 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 107 | (uint32_t)NULL, 0); |
| 108 | } |