Skip to content

Commit 476d60c

Browse files
committed
psa: Add stubbed PSA client implementation
Add a stubbed PSA Client API implementation for application compatibility. The interface is non-functional, but provides sane error codes.
1 parent 1e013bc commit 476d60c

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

features/FEATURE_PSA/TARGET_MBED_PSA_SRV/inc/psa/client.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <stddef.h>
2626
#include "psa/error.h"
2727

28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
2832
#if !defined(UINT32_MAX)
2933
#define UINT32_MAX ((uint32_t)-1)
3034
#endif
@@ -53,5 +57,99 @@ typedef struct psa_outvec {
5357
size_t len; /**< Length in bytes of the buffer.*/
5458
} psa_outvec;
5559

60+
/**
61+
* \brief Retrieve the version of the PSA Framework API that is implemented.
62+
*
63+
* \return version The version of the PSA Framework implementation
64+
* that is providing the runtime services to the
65+
* caller. The major and minor version are encoded
66+
* as follows:
67+
* \arg version[15:8] -- major version number.
68+
* \arg version[7:0] -- minor version number.
69+
*/
70+
uint32_t psa_framework_version(void);
71+
72+
/**
73+
* \brief Retrieve the version of an RoT Service or indicate that it is not
74+
* present on this system.
75+
*
76+
* \param[in] sid ID of the RoT Service to query.
77+
*
78+
* \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
79+
* caller is not permitted to access the service.
80+
* \retval > 0 The version of the implemented RoT Service.
81+
*/
82+
uint32_t psa_version(uint32_t sid);
83+
84+
/**
85+
* \brief Connect to an RoT Service by its SID.
86+
*
87+
* \param[in] sid ID of the RoT Service to connect to.
88+
* \param[in] version Requested version of the RoT Service.
89+
*
90+
* \retval > 0 A handle for the connection.
91+
* \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
92+
* connection.
93+
* \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
94+
* connection at the moment.
95+
* \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
96+
* of the following are true:
97+
* \arg The RoT Service ID is not present.
98+
* \arg The RoT Service version is not supported.
99+
* \arg The caller is not allowed to access the RoT
100+
* service.
101+
*/
102+
psa_handle_t psa_connect(uint32_t sid, uint32_t version);
103+
104+
/**
105+
* \brief Call an RoT Service on an established connection.
106+
*
107+
* \param[in] handle A handle to an established connection.
108+
* \param[in] type The reuqest type.
109+
* Must be zero( \ref PSA_IPC_CALL) or positive.
110+
* \param[in] in_vec Array of input \ref psa_invec structures.
111+
* \param[in] in_len Number of input \ref psa_invec structures.
112+
* \param[in/out] out_vec Array of output \ref psa_outvec structures.
113+
* \param[in] out_len Number of output \ref psa_outvec structures.
114+
*
115+
* \retval >=0 RoT Service-specific status value.
116+
* \retval <0 RoT Service-specific error code.
117+
* \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the
118+
* RoT Service. The call is a PROGRAMMER ERROR if
119+
* one or more of the following are true:
120+
* \arg An invalid handle was passed.
121+
* \arg The connection is already handling a request.
122+
* \arg type < 0.
123+
* \arg An invalid memory reference was provided.
124+
* \arg in_len + out_len > PSA_MAX_IOVEC.
125+
* \arg The message is unrecognized by the RoT
126+
* Service or incorrectly formatted.
127+
*/
128+
psa_status_t psa_call(psa_handle_t handle, int32_t type,
129+
const psa_invec *in_vec,
130+
size_t in_len,
131+
psa_outvec *out_vec,
132+
size_t out_len);
133+
134+
/**
135+
* \brief Close a connection to an RoT Service.
136+
*
137+
* \param[in] handle A handle to an established connection, or the
138+
* null handle.
139+
*
140+
* \retval void Success.
141+
* \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
142+
* of the following are true:
143+
* \arg An invalid handle was provided that is not
144+
* the null handle.
145+
* \arg The connection is currently handling a
146+
* request.
147+
*/
148+
void psa_close(psa_handle_t handle);
149+
150+
#ifdef __cplusplus
151+
}
152+
#endif
153+
56154
#endif // __MBED_OS_DEFAULT_PSA_CLIENT_API_H__
57155
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (c) 2017-2020 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/* This implementation of the PSA Client API is provided for application
19+
* compatibility on single v7-M targets. The client implementation is stubbed
20+
* and non-functional, but present and returns sane errors. */
21+
22+
#include "psa/client.h"
23+
24+
uint32_t psa_framework_version(void)
25+
{
26+
return PSA_FRAMEWORK_VERSION;
27+
}
28+
29+
uint32_t psa_version(uint32_t sid)
30+
{
31+
return PSA_VERSION_NONE;
32+
}
33+
34+
psa_handle_t psa_connect(uint32_t sid, uint32_t version)
35+
{
36+
return PSA_ERROR_PROGRAMMER_ERROR;
37+
}
38+
39+
psa_status_t psa_call(psa_handle_t handle, int32_t type,
40+
const psa_invec *in_vec,
41+
size_t in_len,
42+
psa_outvec *out_vec,
43+
size_t out_len)
44+
{
45+
return PSA_ERROR_PROGRAMMER_ERROR;
46+
}
47+
48+
void psa_close(psa_handle_t handle)
49+
{
50+
return;
51+
}

0 commit comments

Comments
 (0)