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.
pull/12955/head
Jaeden Amero 2020-05-06 11:12:30 +01:00
parent abccf97ebf
commit 908c33bac7
2 changed files with 149 additions and 0 deletions

View File

@ -25,6 +25,10 @@
#include <stddef.h>
#include "psa/error.h"
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(UINT32_MAX)
#define UINT32_MAX ((uint32_t)-1)
#endif
@ -53,5 +57,99 @@ typedef struct psa_outvec {
size_t len; /**< Length in bytes of the buffer.*/
} psa_outvec;
/**
* \brief Retrieve the version of the PSA Framework API that is implemented.
*
* \return version The version of the PSA Framework implementation
* that is providing the runtime services to the
* caller. The major and minor version are encoded
* as follows:
* \arg version[15:8] -- major version number.
* \arg version[7:0] -- minor version number.
*/
uint32_t psa_framework_version(void);
/**
* \brief Retrieve the version of an RoT Service or indicate that it is not
* present on this system.
*
* \param[in] sid ID of the RoT Service to query.
*
* \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
* caller is not permitted to access the service.
* \retval > 0 The version of the implemented RoT Service.
*/
uint32_t psa_version(uint32_t sid);
/**
* \brief Connect to an RoT Service by its SID.
*
* \param[in] sid ID of the RoT Service to connect to.
* \param[in] version Requested version of the RoT Service.
*
* \retval > 0 A handle for the connection.
* \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
* connection.
* \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
* connection at the moment.
* \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
* of the following are true:
* \arg The RoT Service ID is not present.
* \arg The RoT Service version is not supported.
* \arg The caller is not allowed to access the RoT
* service.
*/
psa_handle_t psa_connect(uint32_t sid, uint32_t version);
/**
* \brief Call an RoT Service on an established connection.
*
* \param[in] handle A handle to an established connection.
* \param[in] type The reuqest type.
* Must be zero( \ref PSA_IPC_CALL) or positive.
* \param[in] in_vec Array of input \ref psa_invec structures.
* \param[in] in_len Number of input \ref psa_invec structures.
* \param[in/out] out_vec Array of output \ref psa_outvec structures.
* \param[in] out_len Number of output \ref psa_outvec structures.
*
* \retval >=0 RoT Service-specific status value.
* \retval <0 RoT Service-specific error code.
* \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the
* RoT Service. The call is a PROGRAMMER ERROR if
* one or more of the following are true:
* \arg An invalid handle was passed.
* \arg The connection is already handling a request.
* \arg type < 0.
* \arg An invalid memory reference was provided.
* \arg in_len + out_len > PSA_MAX_IOVEC.
* \arg The message is unrecognized by the RoT
* Service or incorrectly formatted.
*/
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);
/**
* \brief Close a connection to an RoT Service.
*
* \param[in] handle A handle to an established connection, or the
* null handle.
*
* \retval void Success.
* \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
* of the following are true:
* \arg An invalid handle was provided that is not
* the null handle.
* \arg The connection is currently handling a
* request.
*/
void psa_close(psa_handle_t handle);
#ifdef __cplusplus
}
#endif
#endif // __MBED_OS_DEFAULT_PSA_CLIENT_API_H__
#endif

View File

@ -0,0 +1,51 @@
/* Copyright (c) 2017-2020 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* This implementation of the PSA Client API is provided for application
* compatibility on single v7-M targets. The client implementation is stubbed
* and non-functional, but present and returns sane errors. */
#include "psa/client.h"
uint32_t psa_framework_version(void)
{
return PSA_FRAMEWORK_VERSION;
}
uint32_t psa_version(uint32_t sid)
{
return PSA_VERSION_NONE;
}
psa_handle_t psa_connect(uint32_t sid, uint32_t version)
{
return PSA_ERROR_PROGRAMMER_ERROR;
}
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)
{
return PSA_ERROR_PROGRAMMER_ERROR;
}
void psa_close(psa_handle_t handle)
{
return;
}