1 /*
2 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include "psa/client.h"
9 #include "psa/internal_trusted_storage.h"
10 #include "psa_manifest/sid.h"
11 #include "tfm_api.h"
12 #include "tfm_its_defs.h"
13
psa_its_set(psa_storage_uid_t uid,size_t data_length,const void * p_data,psa_storage_create_flags_t create_flags)14 psa_status_t psa_its_set(psa_storage_uid_t uid,
15 size_t data_length,
16 const void *p_data,
17 psa_storage_create_flags_t create_flags)
18 {
19 psa_status_t status;
20
21 psa_invec in_vec[] = {
22 { .base = &uid, .len = sizeof(uid) },
23 { .base = p_data, .len = data_length },
24 { .base = &create_flags, .len = sizeof(create_flags) }
25 };
26
27 status = psa_call(TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE, TFM_ITS_SET,
28 in_vec, IOVEC_LEN(in_vec), NULL, 0);
29
30 return status;
31 }
32
psa_its_get(psa_storage_uid_t uid,size_t data_offset,size_t data_size,void * p_data,size_t * p_data_length)33 psa_status_t psa_its_get(psa_storage_uid_t uid,
34 size_t data_offset,
35 size_t data_size,
36 void *p_data,
37 size_t *p_data_length)
38 {
39 psa_status_t status;
40
41 psa_invec in_vec[] = {
42 { .base = &uid, .len = sizeof(uid) },
43 { .base = &data_offset, .len = sizeof(data_offset) }
44 };
45
46 psa_outvec out_vec[] = {
47 { .base = p_data, .len = data_size }
48 };
49
50 if (p_data_length == NULL) {
51 return PSA_ERROR_INVALID_ARGUMENT;
52 }
53
54 status = psa_call(TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE, TFM_ITS_GET,
55 in_vec, IOVEC_LEN(in_vec), out_vec, IOVEC_LEN(out_vec));
56
57 *p_data_length = out_vec[0].len;
58
59 return status;
60 }
61
psa_its_get_info(psa_storage_uid_t uid,struct psa_storage_info_t * p_info)62 psa_status_t psa_its_get_info(psa_storage_uid_t uid,
63 struct psa_storage_info_t *p_info)
64 {
65 psa_status_t status;
66
67 psa_invec in_vec[] = {
68 { .base = &uid, .len = sizeof(uid) }
69 };
70
71 psa_outvec out_vec[] = {
72 { .base = p_info, .len = sizeof(*p_info) }
73 };
74
75 status = psa_call(TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE,
76 TFM_ITS_GET_INFO, in_vec, IOVEC_LEN(in_vec), out_vec,
77 IOVEC_LEN(out_vec));
78
79 return status;
80 }
81
psa_its_remove(psa_storage_uid_t uid)82 psa_status_t psa_its_remove(psa_storage_uid_t uid)
83 {
84 psa_status_t status;
85
86 psa_invec in_vec[] = {
87 { .base = &uid, .len = sizeof(uid) }
88 };
89
90 status = psa_call(TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE,
91 TFM_ITS_REMOVE, in_vec, IOVEC_LEN(in_vec), NULL, 0);
92
93 return status;
94 }
95