blob: 59366b84d112d755271d48cc16dc921cfd4ab7d5 [file] [log] [blame]
Janis Danisevskis7daa66a2019-06-06 22:05:41 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
David Drysdaled0149e82023-02-03 18:25:03 +000016#define LOG_TAG "android.hardware.gatekeeper-service.trusty"
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070017
18#include <android-base/logging.h>
David Drysdaled0149e82023-02-03 18:25:03 +000019#include <android/binder_manager.h>
20#include <android/binder_process.h>
Arve Hjønnevåg2fea1dd2023-09-13 17:51:20 -070021#include <getopt.h>
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070022
23#include "trusty_gatekeeper.h"
Arve Hjønnevåg2fea1dd2023-09-13 17:51:20 -070024#include "trusty_gatekeeper_ipc.h"
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070025
David Drysdaled0149e82023-02-03 18:25:03 +000026using aidl::android::hardware::gatekeeper::TrustyGateKeeperDevice;
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070027
Arve Hjønnevåg2fea1dd2023-09-13 17:51:20 -070028static const char* _sopts = "hD:";
29static const struct option _lopts[] = {
30 {"help", no_argument, 0, 'h'},
31 {"dev", required_argument, 0, 'D'},
32 {0, 0, 0, 0},
33};
34
35static const char* usage =
36 "Usage: %s [options]\n"
37 "\n"
38 "options:\n"
39 " -h, --help prints this message and exit\n"
40 " -D, --dev name Trusty device name\n"
41 "\n";
42
43static const char* usage_long = "\n";
44
45static void print_usage_and_exit(const char* prog, int code, bool verbose) {
46 fprintf(stderr, usage, prog);
47 if (verbose) {
48 fprintf(stderr, "%s", usage_long);
49 }
50 exit(code);
51}
52
53static void parse_options(int argc, char** argv) {
54 int c;
55 int oidx = 0;
56
57 while (1) {
58 c = getopt_long(argc, argv, _sopts, _lopts, &oidx);
59 if (c == -1) {
60 break; /* done */
61 }
62
63 switch (c) {
64 case 'D':
65 trusty_gatekeeper_set_dev_name(optarg);
66 break;
67
68 case 'h':
69 print_usage_and_exit(argv[0], EXIT_SUCCESS, true);
70 break;
71
72 default:
73 print_usage_and_exit(argv[0], EXIT_FAILURE, false);
74 }
75 }
76}
77
78int main(int argc, char** argv) {
79 parse_options(argc, argv);
80
David Drysdaled0149e82023-02-03 18:25:03 +000081 ABinderProcess_setThreadPoolMaxThreadCount(0);
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070082
David Drysdaled0149e82023-02-03 18:25:03 +000083 std::shared_ptr<TrustyGateKeeperDevice> gatekeeper =
84 ndk::SharedRefBase::make<TrustyGateKeeperDevice>();
85
86 const std::string instance = std::string() + TrustyGateKeeperDevice::descriptor + "/default";
87 binder_status_t status =
88 AServiceManager_addService(gatekeeper->asBinder().get(), instance.c_str());
89 CHECK_EQ(status, STATUS_OK);
90
91 ABinderProcess_joinThreadPool();
92
Janis Danisevskis7daa66a2019-06-06 22:05:41 -070093 return -1; // Should never get here.
94}