blob: c2d13578c810562d6f9d2039c5221db78c855638 [file] [log] [blame]
Summer Qin153f3df2022-11-17 15:51:02 +08001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Summer Qin46f1c982022-12-14 15:24:50 +08008#include <stdint.h>
Summer Qin153f3df2022-11-17 15:51:02 +08009#include <stdio.h>
Summer Qin46f1c982022-12-14 15:24:50 +080010#include <string.h>
Summer Qin153f3df2022-11-17 15:51:02 +080011#include "erpc_port.h"
12#include "erpc_client_start.h"
Kevin Peng0eca5ea2023-07-21 17:32:31 +080013#include "tfm_erpc.h"
Summer Qin46f1c982022-12-14 15:24:50 +080014#include "tfm_crypto_defs.h"
15#include "psa/client.h"
16#include "psa/crypto.h"
17
Jason Guo4625c232023-07-11 10:21:49 +080018#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
19#include <stdlib.h>
20#include <getopt.h>
21#define ARGC_UART 3
22#define ARGC_TCP 4
23#endif
24
Summer Qin46f1c982022-12-14 15:24:50 +080025static void test_call(void)
26{
27 psa_status_t status;
28 uint8_t hash[PSA_HASH_LENGTH(PSA_ALG_SHA_256)] = {0};
29 size_t hash_size = sizeof(hash);
30 const uint8_t *msg = "test";
31
32 status = psa_hash_compute(PSA_ALG_SHA_256, msg, strlen(msg), hash, hash_size, &hash_size);
33
34 printf("psa_hash_compute: %d\r\n", status);
35 printf("> hash_size = %zu\r\n", hash_size);
36 printf("> hash = ");
37 for (size_t i = 0; i < sizeof(hash); ++i) {
38 printf("%02hhX", hash[i]);
39 }
40 printf("\r\n");
41}
Summer Qin153f3df2022-11-17 15:51:02 +080042
43int main(int argc, char *argv[])
44{
45 erpc_transport_t transport;
46
Jason Guo4625c232023-07-11 10:21:49 +080047#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
48 int erpc_uart_flag = 0, erpc_tcp_flag = 0;
49 char *uart_dev = NULL, *tcp_host = NULL, *tcp_port = NULL;
50 struct option erpc_transport_options[] =
51 {
52 {"UART", no_argument, &erpc_uart_flag, 1},
53 {"TCP", no_argument, &erpc_tcp_flag, 1},
54 {0, 0, 0, 0}
55 };
56#endif
57
Summer Qin153f3df2022-11-17 15:51:02 +080058#ifdef ERPC_TRANSPORT_UART
59 transport = erpc_transport_serial_init(PORT_NAME, 115200);
60#elif defined(ERPC_TRANSPORT_TCP)
61 transport = erpc_transport_tcp_init(ERPC_HOST, ERPC_PORT, false);
62#else
Jason Guo4625c232023-07-11 10:21:49 +080063 /* Check if argc is correct */
64 if (argc != ARGC_UART && argc != ARGC_TCP) {
65 printf("Incorrect argument numbers.\r\n");
66 printf("Please input --UART PORT or --TCP HOST PORT\r\n");
67 return 1;
68 }
69
70 /* Loop check to set _flag and parse arguments */
71 while (getopt_long(argc, argv, "", erpc_transport_options, NULL) != -1);
72 if (!erpc_uart_flag && !erpc_tcp_flag) {
73 printf("No valid transportation layer selected.\r\n");
74 return 1;
75 } else if(erpc_uart_flag && erpc_tcp_flag) {
76 printf("UART and TCP cannot be set at the same time.\r\n");
77 return 1;
78 } else if (erpc_uart_flag) {
79 if (argc - optind != 1) {
80 printf("Incorrect argument numbers for --UART.\r\n");
81 return 1;
82 }
83 uart_dev = argv[optind];
84 } else if (erpc_tcp_flag) {
85 if (argc - optind != 2) {
86 printf("Incorrect argument numbers for --TCP.\r\n");
87 return 1;
88 }
89 tcp_host = argv[optind];
90 tcp_port = argv[optind + 1];
91 }
92
93 /* eRPC transport initialization */
94 if (erpc_uart_flag) {
95 printf("UART device is setting to %s\r\n",uart_dev);
96 transport = erpc_transport_serial_init(uart_dev, 115200);
97 } else if (erpc_tcp_flag) {
98 printf("TCP host is setting to %s\t",tcp_host);
99 printf("TCP port is setting to %s\r\n",tcp_port);
100 transport = erpc_transport_tcp_init(tcp_host, atoi(tcp_port), false);
101 }
Summer Qin153f3df2022-11-17 15:51:02 +0800102#endif
103
104 if (!transport) {
105 printf("eRPC transport init failed!\r\n");
106 return 1;
107 }
108
109 erpc_client_start(transport);
110
111 printf("psa_framework_version: %d\r\n", psa_framework_version());
112
Summer Qin46f1c982022-12-14 15:24:50 +0800113 test_call();
114
Summer Qin153f3df2022-11-17 15:51:02 +0800115 return 0;
116}