blob: 558f5b316038542d90e4065bec53d0b51316f72c [file] [log] [blame]
Balint Dobszay72c3f042020-11-23 18:23:57 +01001/*
Imre Kisd0ed5c22021-12-15 17:05:47 +01002 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Balint Dobszay72c3f042020-11-23 18:23:57 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Balint Dobszay72c3f042020-11-23 18:23:57 +01007#include <ffa_api.h>
8#include <components/rpc/ffarpc/caller/sp/ffarpc_caller.h>
julhal011260f102021-02-15 17:34:08 +00009#include <components/service/secure_storage/frontend/psa/its/its_frontend.h>
10#include <service/secure_storage/backend/secure_storage_client/secure_storage_client.h>
Balint Dobszay72c3f042020-11-23 18:23:57 +010011#include <psa/internal_trusted_storage.h>
12#include <sp_api.h>
Imre Kis76e8a3c2021-04-16 16:54:17 +020013#include "sp_messaging.h"
Balint Dobszay72c3f042020-11-23 18:23:57 +010014#include <sp_rxtx.h>
15#include <trace.h>
16#include <string.h>
17
18// #define SP_ITS_UUID_BYTES \
19// { 0xdc, 0x1e, 0xef, 0x48, 0xb1, 0x7a, 0x4c, 0xcf, \
20// 0xac, 0x8b, 0xdf, 0xcf, 0xf7, 0x71, 0x1b, 0x14, }
21
22#define SP_ITS_UUID_BYTES \
23 { 0x48, 0xef, 0x1e, 0xdc, 0x7a, 0xb1, 0xcf, 0x4c, \
24 0xac, 0x8b, 0xdf, 0xcf, 0xf7, 0x71, 0x1b, 0x14, }
25
Balint Dobszay72c3f042020-11-23 18:23:57 +010026static uint8_t tx_buffer[4096] __aligned(4096);
27static uint8_t rx_buffer[4096] __aligned(4096);
28static const uint8_t its_uuid[] = SP_ITS_UUID_BYTES;
29
30static const psa_storage_uid_t test_data_uid = 0x12345678;
31static const uint8_t test_data[] = {
32 0xc3, 0xe2, 0xf8, 0x1c, 0xe0, 0x87, 0x8a, 0x14, 0xbf, 0x59, 0xa3, 0xff,
33 0x96, 0x50, 0x25, 0x95, 0x76, 0xdc, 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0xf6, 0x65, 0x28, 0x7f, 0x56, 0x7a,
49 0xe2, 0xb3, 0xd2, 0xbf, 0xc3, 0x0c, 0x06, 0x8e, 0x5f, 0xdc, 0xd3, 0x1f,
50 0x85, 0x74, 0x38, 0x96, 0x5e, 0x1b, 0xe5, 0xa0, 0xc0, 0xfb, 0x90, 0xb7,
51 0x14, 0x16, 0x1b, 0xbe, 0xd8, 0x5c, 0x8e, 0xcc, 0x74, 0x71, 0x8c, 0x34,
52 0xc0, 0xbc, 0x24, 0xf5, 0xb9, 0x9b, 0xa1, 0x59, 0xe8, 0x54, 0xd0, 0xe9,
53 0x01, 0xa9, 0x6e, 0x27,
54};
55static const size_t test_data_size = sizeof(test_data);
56static uint8_t check_data[256] = { 0 };
57static size_t check_data_size = 0;
58
59static void run_its_test(void)
60{
61 psa_status_t its_status;
62 struct psa_storage_info_t info;
63
64 /* Write data */
65 its_status = psa_its_set(test_data_uid, test_data_size, test_data,
66 PSA_STORAGE_FLAG_NONE);
67
68 if (its_status != PSA_SUCCESS) {
69 EMSG("Error: %d", its_status);
70 }
71
72 /* Read back and compare */
73 its_status = psa_its_get(test_data_uid, 0, test_data_size,
74 check_data, &check_data_size);
75
76 if (its_status != PSA_SUCCESS || check_data_size != test_data_size) {
77 EMSG("Error: %d", its_status);
78 }
79
80 if(memcmp(test_data, check_data, test_data_size)) {
81 EMSG("Data check failed");
82 }
83
84 memset(check_data, 0, test_data_size);
85
86 /* Get info of entry */
87 psa_its_get_info(test_data_uid, &info);
88 if (its_status != PSA_SUCCESS) {
89 EMSG("Error: %d", its_status);
90 }
91
92 /* Write data with new uid */
93 its_status = psa_its_set(test_data_uid + 1, test_data_size, test_data,
94 PSA_STORAGE_FLAG_NONE);
95
96 if (its_status != PSA_SUCCESS) {
97 EMSG("Error: %d", its_status);
98 }
99
100 /* Read back and compare */
101 its_status = psa_its_get(test_data_uid + 1, 0, test_data_size,
102 check_data, &check_data_size);
103
104 if (its_status != PSA_SUCCESS || check_data_size != test_data_size) {
105 EMSG("Error: %d", its_status);
106 }
107
108 if(memcmp(test_data, check_data, test_data_size)) {
109 EMSG("Data check failed");
110 }
111
112 /* Delete entry */
113 its_status = psa_its_remove(test_data_uid + 1);
114 if (its_status != PSA_SUCCESS) {
115 EMSG("Error: %d", its_status);
116 }
117
118 /* Check if really deleted */
119 its_status = psa_its_get(test_data_uid + 1, 0, test_data_size,
120 check_data, &check_data_size);
121
122 if (its_status != PSA_ERROR_DOES_NOT_EXIST) {
123 EMSG("Error: %d", its_status);
124 }
125
126 IMSG("ITS test done");
127}
128
129void __noreturn sp_main(struct ffa_init_info *init_info) {
130
131 ffa_result ffa_res;
132 sp_result sp_res;
Imre Kis76e8a3c2021-04-16 16:54:17 +0200133 struct sp_msg req_msg = { 0 };
Balint Dobszay72c3f042020-11-23 18:23:57 +0100134 struct rpc_caller *caller;
135 struct ffarpc_caller ffa_caller;
julhal011260f102021-02-15 17:34:08 +0000136 struct secure_storage_client secure_storage_client;
137 struct storage_backend *storage_backend;
Balint Dobszay72c3f042020-11-23 18:23:57 +0100138 uint16_t sp_ids[3];
139 uint32_t sp_id_cnt = 0;
Imre Kisf6562652022-07-04 15:33:13 +0200140 uint16_t own_id = 0;
Balint Dobszay72c3f042020-11-23 18:23:57 +0100141
142 /* Boot */
143 (void) init_info;
144 IMSG("Test SP started");
145
146 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
147 if (sp_res != SP_RESULT_OK) {
148 goto err;
149 }
150
151 ffa_res = ffa_id_get(&own_id);
152 if (ffa_res != FFA_OK) {
153 goto err;
154 }
155 IMSG("Test SP ID: 0x%x", own_id);
156
Imre Kis0181ebd2022-07-04 13:09:25 +0200157 caller = ffarpc_caller_init(&ffa_caller, own_id);
Balint Dobszay72c3f042020-11-23 18:23:57 +0100158 sp_id_cnt = ffarpc_caller_discover(its_uuid, sp_ids, 3);
159
160 if (sp_id_cnt == 0) {
161 EMSG("Error: %d", sp_id_cnt);
162 goto err;
163 }
164 IMSG("ITS SP ID: 0x%x", sp_ids[0]);
165
julhal01c3f4e9a2020-12-15 13:39:01 +0000166 if (ffarpc_caller_open(&ffa_caller, sp_ids[0], 0)) {
Balint Dobszay72c3f042020-11-23 18:23:57 +0100167 goto err;
168 }
169
julhal011260f102021-02-15 17:34:08 +0000170 storage_backend = secure_storage_client_init(&secure_storage_client, caller);
171 psa_its_frontend_init(storage_backend);
Balint Dobszay72c3f042020-11-23 18:23:57 +0100172
173 /*
174 * This is not thorough testing of the ITS SP!
175 * Only some basic functionality checks.
176 */
177 run_its_test();
178
179 if (ffarpc_caller_close(&ffa_caller)) {
180 goto err;
181 }
182
183 /* End of boot phase */
Imre Kis76e8a3c2021-04-16 16:54:17 +0200184 sp_msg_wait(&req_msg);
Balint Dobszay72c3f042020-11-23 18:23:57 +0100185
186err:
187 EMSG("Test SP error");
188 while (1) {}
189}
190
191void sp_interrupt_handler(uint32_t interrupt_id) {
192 (void)interrupt_id;
193}