2018-11-18 18:14:05 +00:00
|
|
|
/* Copyright (c) 2017-2018 ARM Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-11-13 18:33:05 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "string.h"
|
2019-02-24 08:50:24 +00:00
|
|
|
#include "psa/client.h"
|
2019-01-24 10:36:33 +00:00
|
|
|
#include "psa/service.h"
|
2019-04-18 13:52:24 +00:00
|
|
|
#include "mbed_spm_partitions.h"
|
2018-11-13 18:33:05 +00:00
|
|
|
#include "server_tests.h"
|
|
|
|
|
|
|
|
extern psa_test_server_side_func test_list[];
|
|
|
|
static size_t num_of_tests = 0;
|
|
|
|
static void init_num_of_tests()
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2018-11-18 09:04:51 +00:00
|
|
|
while (test_list[i] != NULL) {
|
2018-11-13 18:33:05 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_of_tests = i;
|
|
|
|
}
|
|
|
|
|
2019-02-24 08:50:24 +00:00
|
|
|
void server_part1_main(void *ptr)
|
2018-11-13 18:33:05 +00:00
|
|
|
{
|
2019-02-22 18:31:48 +00:00
|
|
|
psa_signal_t signals = 0;
|
2019-02-27 12:03:25 +00:00
|
|
|
psa_msg_t msg = {0};
|
2019-01-24 10:36:33 +00:00
|
|
|
psa_status_t test_status = PSA_SUCCESS; // status of the api calls during the test
|
|
|
|
psa_status_t test_result = PSA_SUCCESS; // result of the critical section of the test
|
2018-11-13 18:33:05 +00:00
|
|
|
test_action_t action;
|
|
|
|
uint32_t test_idx = 0;
|
|
|
|
|
2019-02-27 12:03:25 +00:00
|
|
|
|
2018-11-13 18:33:05 +00:00
|
|
|
init_num_of_tests();
|
|
|
|
while (1) {
|
2019-02-22 18:31:48 +00:00
|
|
|
signals = psa_wait(CONTROL_MSK, PSA_BLOCK);
|
2018-11-13 18:33:05 +00:00
|
|
|
if (0 == (signals & CONTROL_MSK)) {
|
2019-02-22 18:31:48 +00:00
|
|
|
SPM_PANIC("returned from psa_wait without CONTROL_ROT_SRV bit on signals=(0x%08x)\n", signals);
|
2018-11-13 18:33:05 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 12:01:22 +00:00
|
|
|
if (PSA_SUCCESS != psa_get(CONTROL_MSK, &msg)) {
|
|
|
|
SPM_PANIC("psa_get() failed\n");
|
|
|
|
}
|
2018-11-13 18:33:05 +00:00
|
|
|
switch (msg.type) {
|
2018-11-18 09:04:51 +00:00
|
|
|
case PSA_IPC_CALL:
|
|
|
|
if (msg.in_size[0] == 0) {
|
2019-02-28 08:37:53 +00:00
|
|
|
SPM_PANIC("got a zero message size to SERVER_TESTS_PART1_CONTROL ROT_SRV\n");
|
2018-11-18 09:04:51 +00:00
|
|
|
}
|
2018-11-13 18:33:05 +00:00
|
|
|
|
2018-11-18 09:04:51 +00:00
|
|
|
if (psa_read(msg.handle, 0, &action, sizeof(action)) != sizeof(action)) {
|
|
|
|
SPM_PANIC("could not read the entire test payload structure\n");
|
|
|
|
}
|
2018-11-13 18:33:05 +00:00
|
|
|
|
2018-11-18 09:04:51 +00:00
|
|
|
switch (action) {
|
|
|
|
case START_TEST:
|
|
|
|
if ((test_idx >= num_of_tests) || (test_list[test_idx] == NULL)) {
|
|
|
|
SPM_PANIC("Invalid test ID was sent!\n");
|
|
|
|
}
|
2018-11-13 18:33:05 +00:00
|
|
|
|
2018-11-18 09:04:51 +00:00
|
|
|
psa_reply(msg.handle, PSA_SUCCESS);
|
|
|
|
test_status = test_list[test_idx](&test_result);
|
|
|
|
break;
|
|
|
|
case GET_TEST_RESULT:
|
|
|
|
test_idx++;
|
|
|
|
psa_write(msg.handle, 0, &test_result, sizeof(test_result));
|
|
|
|
psa_reply(msg.handle, test_status);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPM_PANIC("Got illegal Value in test action");
|
|
|
|
}
|
2018-11-13 18:33:05 +00:00
|
|
|
|
2018-11-18 09:04:51 +00:00
|
|
|
break;
|
|
|
|
case PSA_IPC_CONNECT:
|
|
|
|
case PSA_IPC_DISCONNECT:
|
|
|
|
psa_reply(msg.handle, PSA_SUCCESS);
|
|
|
|
break;
|
|
|
|
default:
|
2019-02-24 10:31:04 +00:00
|
|
|
SPM_PANIC("Unexpected message type %lu!", msg.type);
|
2018-11-13 18:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|