1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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 <android-base/logging.h>
#include <errno.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <cutils/android_filesystem_config.h>
#include "DPUHandler.h"
static void show_usage_and_exit(int code) {
LOG(ERROR) << "usage: securedpud -d <trusty_dev>";
exit(code);
}
static void parse_device_name(int argc, char* argv[], char*& device_name) {
static const char* _sopts = "h:d:";
static const struct option _lopts[] = {{"help", no_argument, NULL, 'h'},
{"trusty_dev", required_argument, NULL, 'd'},
{0, 0, 0, 0}};
int opt;
int oidx = 0;
while ((opt = getopt_long(argc, argv, _sopts, _lopts, &oidx)) != -1) {
switch (opt) {
case 'd':
device_name = strdup(optarg);
break;
default:
LOG(ERROR) << "unrecognized option: " << opt;
show_usage_and_exit(EXIT_FAILURE);
}
}
if (device_name == nullptr) {
LOG(ERROR) << "missing required argument(s)";
show_usage_and_exit(EXIT_FAILURE);
}
LOG(INFO) << "starting securedpud";
LOG(INFO) << "trusty dev: " << device_name;
}
int main(int argc, char* argv[])
{
char* device_name;
/* parse arguments */
parse_device_name(argc, argv, device_name);
android::trusty::secure_dpu::DPUHandler dpu_handler;
auto rc = dpu_handler.Init(std::string(device_name));
if (!rc.ok()) {
LOG(ERROR) << rc.error();
return EXIT_FAILURE;
}
/* main loop */
while (1) {
auto result = dpu_handler.Handle();
if (!result.ok()) {
LOG(ERROR) << result.error();
}
}
LOG(ERROR) << "exiting securedpud loop";
return EXIT_FAILURE;
}
|