blob: 9a72951af3f459dad301a9d0ee1645eb54d14eca [file] [log] [blame]
Tamas Banafc4f3c2024-08-13 11:46:58 +02001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10
11#include "dice_protection_environment.h"
12#include "tfm_sp_log.h"
13
14#include "cmd.h"
15
16static int read_cmd(const char path[], char *cmd_buf, size_t *cmd_buf_size)
17{
18 FILE *fd;
19 size_t cmd_size;
20
21 if ((fd = fopen(path, "r")) == NULL) {
22 printf("ERROR: File (%s) cannot be opened.\n", path);
23 return -1;
24 }
25
26 fseek(fd, 0, SEEK_END);
27 cmd_size = ftell(fd);
28 rewind(fd);
29
30 if (*cmd_buf_size < cmd_size) {
31 printf("ERROR: cmd_buf is too small\n");
32 return -1;
33 }
34
35 for (size_t i = 0; i < cmd_size; ++i) {
36 cmd_buf[i] = fgetc(fd);
37 }
38 *cmd_buf_size = cmd_size;
39
40 fclose(fd);
41
42 return 0;
43}
44
45int main(int argc, char **argv)
46{
47 int context_handle;
48 int ret;
49 char cmd_in_buf[4096] = {0};
50 size_t cmd_in_size = sizeof(cmd_in_buf);
51 dpe_error_t err;
52
53 dpe_lib_init(&context_handle);
54
55 if (argc == 2) {
56 ret = read_cmd(argv[1], cmd_in_buf, &cmd_in_size);
57 if (ret < 0) {
58 exit(1);
59 }
60
61 err = exec_dpe_cmd(CBOR, cmd_in_buf, cmd_in_size, &context_handle);
62 if (err != DPE_NO_ERROR) {
63 printf("DPE command decode/execution failed (%d)\n", ret);
64 exit(1);
65 }
66 } else {
67 printf("Wrong number of input params! It must be 1!\n");
68 exit(1);
69 }
70
71 exit(0);
72}