TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_ps_ipc_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
9 
10 #include "tfm_ns_interface.h"
11 #include "psa_manifest/sid.h"
12 
13 #define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0]))
14 
16  size_t data_length,
17  const void *p_data,
18  psa_storage_create_flags_t create_flags)
19 {
20  psa_status_t status;
21  psa_handle_t handle;
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 
30  if (!PSA_HANDLE_IS_VALID(handle)) {
32  }
33 
34  status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec),
35  NULL, 0);
36 
37  psa_close(handle);
38 
39  /* A parameter with a buffer pointer pointer that has data length longer
40  * than maximum permitted is treated as a secure violation.
41  * TF-M framework rejects the request with TFM_ERROR_INVALID_PARAMETER.
42  */
45  }
46 
47  return status;
48 }
49 
51  size_t data_offset,
52  size_t data_size,
53  void *p_data,
54  size_t *p_data_length)
55 {
56  psa_status_t status;
57  psa_handle_t handle;
58 
59  psa_invec in_vec[] = {
60  { .base = &uid, .len = sizeof(uid) },
61  { .base = &data_offset, .len = sizeof(data_offset) }
62  };
63 
64  psa_outvec out_vec[] = {
65  { .base = p_data, .len = data_size }
66  };
67 
68  if (p_data_length == NULL) {
70  }
71 
73  if (!PSA_HANDLE_IS_VALID(handle)) {
75  }
76 
77  status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec,
78  IOVEC_LEN(out_vec));
79 
80  psa_close(handle);
81 
82  *p_data_length = out_vec[0].len;
83 
84  return status;
85 }
86 
88  struct psa_storage_info_t *p_info)
89 {
90  psa_status_t status;
91  psa_handle_t handle;
92 
93  psa_invec in_vec[] = {
94  { .base = &uid, .len = sizeof(uid) }
95  };
96 
97  psa_outvec out_vec[] = {
98  { .base = p_info, .len = sizeof(*p_info) }
99  };
100 
102  if (!PSA_HANDLE_IS_VALID(handle)) {
104  }
105 
106  status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec,
107  IOVEC_LEN(out_vec));
108 
109  psa_close(handle);
110 
111  return status;
112 }
113 
115 {
116  psa_status_t status;
117  psa_handle_t handle;
118 
119  psa_invec in_vec[] = {
120  { .base = &uid, .len = sizeof(uid) }
121  };
122 
123 
125  if (!PSA_HANDLE_IS_VALID(handle)) {
127  }
128 
129  status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec),
130  NULL, 0);
131 
132  psa_close(handle);
133 
134  return status;
135 }
136 
138  psa_storage_create_flags_t create_flags)
139 {
140  (void)uid;
141  (void)size;
142  (void)create_flags;
143 
145 }
146 
148  size_t data_length, const void *p_data)
149 {
150  (void)uid;
151  (void)data_offset;
152  (void)data_length;
153  (void)p_data;
154 
156 }
157 
158 uint32_t psa_ps_get_support(void)
159 {
160  /* Initialise support_flags to a sensible default, to avoid returning an
161  * uninitialised value in case the secure function fails.
162  */
163  uint32_t support_flags = 0;
164  psa_handle_t handle;
165 
166  psa_outvec out_vec[] = {
167  { .base = &support_flags, .len = sizeof(support_flags) }
168  };
169 
170  /* The PSA API does not return an error, so any error from TF-M is
171  * ignored.
172  */
174  if (!PSA_HANDLE_IS_VALID(handle)) {
175  return support_flags;
176  }
177 
178  (void)psa_call(handle, PSA_IPC_CALL, NULL, 0, out_vec, IOVEC_LEN(out_vec));
179 
180  psa_close(handle);
181 
182  return support_flags;
183 }
#define TFM_PS_GET_INFO_VERSION
Definition: sid.h:23
#define TFM_PS_REMOVE_SID
Definition: sid.h:24
void * base
Definition: client.h:75
#define TFM_PS_SET_SID
Definition: sid.h:18
#define TFM_PS_REMOVE_VERSION
Definition: sid.h:25
#define TFM_PS_GET_VERSION
Definition: sid.h:21
psa_status_t psa_ps_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length)
Retrieve data associated with a provided uid.
#define IOVEC_LEN(x)
void psa_close(psa_handle_t handle)
Close a connection to an RoT Service.
Definition: psa_client.c:63
#define TFM_PS_GET_SUPPORT_SID
Definition: sid.h:26
#define PSA_ERROR_GENERIC_ERROR
Definition: crypto_values.h:43
#define PSA_ERROR_INVALID_ARGUMENT
psa_handle_t psa_connect(uint32_t sid, uint32_t version)
Connect to an RoT Service by its SID.
Definition: psa_client.c:30
#define PSA_HANDLE_IS_VALID(handle)
Definition: client.h:43
psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, psa_storage_create_flags_t create_flags)
Create a new, or modify an existing, uid/value pair.
#define TFM_PS_SET_VERSION
Definition: sid.h:19
#define TFM_PS_GET_SID
Definition: sid.h:20
#define PSA_ERROR_NOT_SUPPORTED
Definition: crypto_values.h:52
#define TFM_PS_GET_SUPPORT_VERSION
Definition: sid.h:27
#define TFM_PS_GET_INFO_SID
Definition: sid.h:22
size_t len
Definition: client.h:76
psa_status_t psa_ps_create(psa_storage_uid_t uid, size_t size, psa_storage_create_flags_t create_flags)
Reserves storage for the specified uid.
int32_t psa_handle_t
Definition: client.h:61
uint64_t psa_storage_uid_t
psa_status_t psa_ps_remove(psa_storage_uid_t uid)
Remove the provided uid and its associated data from the storage.
uint32_t psa_ps_get_support(void)
Lists optional features.
#define PSA_IPC_CALL
Definition: client.h:59
const void * base
Definition: client.h:67
uint32_t psa_storage_create_flags_t
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
psa_status_t psa_ps_set_extended(psa_storage_uid_t uid, size_t data_offset, size_t data_length, const void *p_data)
Sets partial data into an asset.
psa_status_t psa_ps_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
psa_status_t psa_call(psa_handle_t handle, int32_t type, const psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len)
Call an RoT Service on an established connection.
Definition: psa_client.c:47