TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_platform_secure_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "tfm_platform_api.h"
9 #include "tfm_veneers.h"
10 #ifdef TFM_PSA_API
11 #include "psa_manifest/sid.h"
12 #endif
13 
14 __attribute__((section("SFN")))
16 {
17 #ifdef TFM_PSA_API
20 
23  if (handle <= 0) {
25  }
26 
27  status = psa_call(handle, PSA_IPC_CALL,
28  NULL, 0, NULL, 0);
29  psa_close(handle);
30 
31  if (status < PSA_SUCCESS) {
33  } else {
34  return (enum tfm_platform_err_t) status;
35  }
36 #else /* TFM_PSA_API */
37  return (enum tfm_platform_err_t) tfm_platform_sp_system_reset_veneer(
38  NULL, 0, NULL, 0);
39 #endif /* TFM_PSA_API */
40 }
41 
42 __attribute__((section("SFN")))
45  psa_invec *input, psa_outvec *output)
46 {
47  tfm_platform_ioctl_req_t req = request;
48  struct psa_invec in_vec[2];
49  size_t inlen, outlen;
50 #ifdef TFM_PSA_API
53 #endif /* TFM_PSA_API */
54 
55  in_vec[0].base = &req;
56  in_vec[0].len = sizeof(req);
57  if (input != NULL) {
58  in_vec[1].base = input->base;
59  in_vec[1].len = input->len;
60  inlen = 2;
61  } else {
62  inlen = 1;
63  }
64 
65  if (output != NULL) {
66  outlen = 1;
67  } else {
68  outlen = 0;
69  }
70 #ifdef TFM_PSA_API
73  if (handle <= 0) {
75  }
76 
77  status = psa_call(handle, PSA_IPC_CALL,
78  in_vec, inlen,
79  output, outlen);
80  psa_close(handle);
81 
82  if (status < PSA_SUCCESS) {
84  } else {
85  return (enum tfm_platform_err_t) status;
86  }
87 #else /* TFM_PSA_API */
88  return (enum tfm_platform_err_t) tfm_platform_sp_ioctl_veneer(
89  in_vec, inlen, output, outlen);
90 #endif /* TFM_PSA_API */
91 }
92 
93 __attribute__((section("SFN")))
96 {
97 #ifdef TFM_PSA_API
100 #endif
101  struct psa_invec in_vec[1];
102 
103  in_vec[0].base = &counter_id;
104  in_vec[0].len = sizeof(counter_id);
105 
106 #ifdef TFM_PSA_API
109  if (handle <= 0) {
111  }
112 
114  in_vec, 1, (psa_outvec *)NULL, 0);
115 
116  psa_close(handle);
117 
118  if (status < PSA_SUCCESS) {
120  } else {
121  return (enum tfm_platform_err_t) status;
122  }
123 #else /* TFM_PSA_API */
124  return
125  (enum tfm_platform_err_t) tfm_platform_sp_nv_counter_increment_veneer(
126  in_vec, 1, (psa_outvec *)NULL, 0);
127 #endif /* TFM_PSA_API */
128 }
129 
130 __attribute__((section("SFN")))
132 tfm_platform_nv_counter_read(uint32_t counter_id,
133  uint32_t size, uint8_t *val)
134 {
135 #ifdef TFM_PSA_API
137  psa_handle_t handle = PSA_NULL_HANDLE;
138 #endif
139  struct psa_invec in_vec[1];
140  struct psa_outvec out_vec[1];
141 
142  in_vec[0].base = &counter_id;
143  in_vec[0].len = sizeof(counter_id);
144 
145  out_vec[0].base = val;
146  out_vec[0].len = size;
147 
148 #ifdef TFM_PSA_API
151  if (handle <= 0) {
153  }
154 
155  status = psa_call(handle, TFM_PLATFORM_API_ID_NV_READ,
156  in_vec, 1, out_vec, 1);
157 
158  psa_close(handle);
159 
160  if (status < PSA_SUCCESS) {
162  } else {
163  return (enum tfm_platform_err_t) status;
164  }
165 #else /* TFM_PSA_API */
166  return (enum tfm_platform_err_t) tfm_platform_sp_nv_counter_read_veneer(
167  in_vec, 1, out_vec, 1);
168 #endif /* TFM_PSA_API */
169 }
#define TFM_SP_PLATFORM_IOCTL_SID
Definition: sid.h:46
void * base
Definition: client.h:75
#define PSA_SUCCESS
Definition: crypto_values.h:35
#define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION
Definition: sid.h:45
enum tfm_platform_err_t tfm_platform_system_reset(void)
Resets the system.
int32_t tfm_platform_ioctl_req_t
size_t len
Definition: client.h:68
#define TFM_PLATFORM_API_ID_NV_INCREMENT
void psa_close(psa_handle_t handle)
Close a connection to an RoT Service.
Definition: psa_client.c:63
#define TFM_PLATFORM_API_ID_NV_READ
enum tfm_platform_err_t tfm_platform_nv_counter_read(uint32_t counter_id, uint32_t size, uint8_t *val)
Reads the given non-volatile (NV) counter.
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_NULL_HANDLE
Definition: client.h:38
#define PSA_ERROR_CONNECTION_REFUSED
Definition: error.h:33
size_t len
Definition: client.h:76
int32_t psa_handle_t
Definition: client.h:61
#define TFM_SP_PLATFORM_NV_COUNTER_VERSION
Definition: sid.h:49
enum tfm_platform_err_t tfm_platform_nv_counter_increment(uint32_t counter_id)
Increments the given non-volatile (NV) counter by one.
#define PSA_IPC_CALL
Definition: client.h:59
#define TFM_SP_PLATFORM_SYSTEM_RESET_SID
Definition: sid.h:44
tfm_platform_err_t
Platform service error types.
const void * base
Definition: client.h:67
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
enum tfm_platform_err_t tfm_platform_ioctl(tfm_platform_ioctl_req_t request, psa_invec *input, psa_outvec *output)
Performs a platform-specific service.
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
#define TFM_SP_PLATFORM_IOCTL_VERSION
Definition: sid.h:47
#define TFM_SP_PLATFORM_NV_COUNTER_SID
Definition: sid.h:48