blob: 317032c01c00523001d8a819f409fc2f47515a12 [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Marc Moreno Berengue675b6e92018-06-14 17:31:01 +01002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Ashutosh Singhf4d88672017-11-29 13:35:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Mate Toth-Pal1379e152018-07-30 17:38:29 +02008#include "tfm_sst_veneers.h"
Ashutosh Singhf4d88672017-11-29 13:35:43 +00009#include "tfm_sst_defs.h"
10#include "tfm_ns_lock.h"
Mate Toth-Pal261df462018-08-07 12:02:42 +020011
12/* This define uses the TF-M invalid client ID to specify a direct client read,
13 * as that it can not be used to identify a client.
14 */
15#define SST_DIRECT_CLIENT_READ TFM_INVALID_CLIENT_ID
Ashutosh Singhf4d88672017-11-29 13:35:43 +000016
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010017enum psa_sst_err_t psa_sst_create(uint32_t asset_uuid, const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010018 uint32_t token_size)
Ashutosh Singhf4d88672017-11-29 13:35:43 +000019{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010020 struct tfm_sst_token_t s_token;
21
22 /* Pack the token information in the token structure */
23 s_token.token = token;
24 s_token.token_size = token_size;
25
Mate Toth-Pal1379e152018-07-30 17:38:29 +020026 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_create,
Mate Toth-Pal1379e152018-07-30 17:38:29 +020027 asset_uuid,
28 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +020029 0, 0);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000030}
31
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010032enum psa_sst_err_t psa_sst_get_info(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010033 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010034 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010035 struct psa_sst_asset_info_t *info)
Ashutosh Singhf4d88672017-11-29 13:35:43 +000036{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010037 struct tfm_sst_token_t s_token;
38
39 /* Pack the token information in the token structure */
40 s_token.token = token;
41 s_token.token_size = token_size;
42
Mate Toth-Pal1379e152018-07-30 17:38:29 +020043 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_get_info,
Mate Toth-Pal1379e152018-07-30 17:38:29 +020044 asset_uuid,
45 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +020046 (uint32_t)info,
47 0);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000048}
49
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010050enum psa_sst_err_t psa_sst_get_attributes(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010051 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010052 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010053 struct psa_sst_asset_attrs_t *attrs)
Marc Moreno Berengue51af9512018-06-14 18:28:14 +010054{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010055 struct tfm_sst_token_t s_token;
56
57 /* Pack the token information in the token structure */
58 s_token.token = token;
59 s_token.token_size = token_size;
60
Mate Toth-Pal1379e152018-07-30 17:38:29 +020061 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_get_attributes,
Mate Toth-Pal1379e152018-07-30 17:38:29 +020062 asset_uuid,
63 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +020064 (uint32_t)attrs,
65 0);
Marc Moreno Berengue51af9512018-06-14 18:28:14 +010066}
67
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010068enum psa_sst_err_t psa_sst_set_attributes(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010069 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010070 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010071 const struct psa_sst_asset_attrs_t *attrs)
Marc Moreno Berengue51af9512018-06-14 18:28:14 +010072{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010073 struct tfm_sst_token_t s_token;
74
75 /* Pack the token information in the token structure */
76 s_token.token = token;
77 s_token.token_size = token_size;
78
Mate Toth-Pal1379e152018-07-30 17:38:29 +020079 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_set_attributes,
Mate Toth-Pal1379e152018-07-30 17:38:29 +020080 asset_uuid,
81 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +020082 (uint32_t)attrs,
83 0);
Marc Moreno Berengue51af9512018-06-14 18:28:14 +010084}
85
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010086enum psa_sst_err_t psa_sst_read(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010087 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010088 uint32_t token_size,
Marc Moreno Berengue79032942018-06-26 15:34:05 +010089 uint32_t size,
90 uint32_t offset,
91 uint8_t *data)
Ashutosh Singhf4d88672017-11-29 13:35:43 +000092{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010093 struct tfm_sst_token_t s_token;
Marc Moreno Berengue79032942018-06-26 15:34:05 +010094 struct tfm_sst_buf_t s_data;
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010095
96 /* Pack the token information in the token structure */
97 s_token.token = token;
98 s_token.token_size = token_size;
99
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100100 /* Pack buffer information in the buffer structure */
101 s_data.size = size;
102 s_data.offset = offset;
103 s_data.data = data;
104
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200105 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_read,
Mate Toth-Pal261df462018-08-07 12:02:42 +0200106 SST_DIRECT_CLIENT_READ,
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200107 asset_uuid,
108 (uint32_t)&s_token,
109 (uint32_t)&s_data);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000110}
111
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100112enum psa_sst_err_t psa_sst_write(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100113 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100114 uint32_t token_size,
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100115 uint32_t size,
116 uint32_t offset,
117 const uint8_t *data)
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000118{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100119 struct tfm_sst_token_t s_token;
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100120 struct tfm_sst_buf_t s_data;
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100121
122 /* Pack the token information in the token structure */
123 s_token.token = token;
124 s_token.token_size = token_size;
125
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100126 /* Pack buffer information in the buffer structure */
127 s_data.size = size;
128 s_data.offset = offset;
129 s_data.data = (uint8_t *)data;
130
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200131 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_write,
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200132 asset_uuid,
133 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +0200134 (uint32_t)&s_data,
135 0);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000136}
137
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100138enum psa_sst_err_t psa_sst_delete(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100139 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100140 uint32_t token_size)
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000141{
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100142 struct tfm_sst_token_t s_token;
143
144 /* Pack the token information in the token structure */
145 s_token.token = token;
146 s_token.token_size = token_size;
147
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200148 return tfm_ns_lock_dispatch((veneer_fn)tfm_sst_veneer_delete,
Mate Toth-Pal1379e152018-07-30 17:38:29 +0200149 asset_uuid,
150 (uint32_t)&s_token,
Mate Toth-Pal261df462018-08-07 12:02:42 +0200151 0, 0);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000152}