From 2fea1dd4abdb2250a94fe4a048b8d09a08a82f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= Date: Wed, 13 Sep 2023 17:51:20 -0700 Subject: [PATCH] trusty: gatekeeper: Add device option Add commandline option to specify the trusty device to use. Bug: 300338484 Test: VtsHalGatekeeperTargetTest Change-Id: Ib2ef34dfc104c65119a98937280ae9db74417766 --- trusty/gatekeeper/service.cpp | 56 ++++++++++++++++++++++- trusty/gatekeeper/trusty_gatekeeper_ipc.c | 9 ++-- trusty/gatekeeper/trusty_gatekeeper_ipc.h | 1 + 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/trusty/gatekeeper/service.cpp b/trusty/gatekeeper/service.cpp index d09804f9a..59366b84d 100644 --- a/trusty/gatekeeper/service.cpp +++ b/trusty/gatekeeper/service.cpp @@ -18,12 +18,66 @@ #include #include #include +#include #include "trusty_gatekeeper.h" +#include "trusty_gatekeeper_ipc.h" using aidl::android::hardware::gatekeeper::TrustyGateKeeperDevice; -int main() { +static const char* _sopts = "hD:"; +static const struct option _lopts[] = { + {"help", no_argument, 0, 'h'}, + {"dev", required_argument, 0, 'D'}, + {0, 0, 0, 0}, +}; + +static const char* usage = + "Usage: %s [options]\n" + "\n" + "options:\n" + " -h, --help prints this message and exit\n" + " -D, --dev name Trusty device name\n" + "\n"; + +static const char* usage_long = "\n"; + +static void print_usage_and_exit(const char* prog, int code, bool verbose) { + fprintf(stderr, usage, prog); + if (verbose) { + fprintf(stderr, "%s", usage_long); + } + exit(code); +} + +static void parse_options(int argc, char** argv) { + int c; + int oidx = 0; + + while (1) { + c = getopt_long(argc, argv, _sopts, _lopts, &oidx); + if (c == -1) { + break; /* done */ + } + + switch (c) { + case 'D': + trusty_gatekeeper_set_dev_name(optarg); + break; + + case 'h': + print_usage_and_exit(argv[0], EXIT_SUCCESS, true); + break; + + default: + print_usage_and_exit(argv[0], EXIT_FAILURE, false); + } + } +} + +int main(int argc, char** argv) { + parse_options(argc, argv); + ABinderProcess_setThreadPoolMaxThreadCount(0); std::shared_ptr gatekeeper = diff --git a/trusty/gatekeeper/trusty_gatekeeper_ipc.c b/trusty/gatekeeper/trusty_gatekeeper_ipc.c index f67944b35..5ca951cd5 100644 --- a/trusty/gatekeeper/trusty_gatekeeper_ipc.c +++ b/trusty/gatekeeper/trusty_gatekeeper_ipc.c @@ -28,12 +28,15 @@ #include "trusty_gatekeeper_ipc.h" #include "gatekeeper_ipc.h" -#define TRUSTY_DEVICE_NAME "/dev/trusty-ipc-dev0" - +static const char* trusty_device_name = "/dev/trusty-ipc-dev0"; static int handle_ = 0; +void trusty_gatekeeper_set_dev_name(const char* device_name) { + trusty_device_name = device_name; +} + int trusty_gatekeeper_connect() { - int rc = tipc_connect(TRUSTY_DEVICE_NAME, GATEKEEPER_PORT); + int rc = tipc_connect(trusty_device_name, GATEKEEPER_PORT); if (rc < 0) { return rc; } diff --git a/trusty/gatekeeper/trusty_gatekeeper_ipc.h b/trusty/gatekeeper/trusty_gatekeeper_ipc.h index f8de7f873..47ba33b38 100644 --- a/trusty/gatekeeper/trusty_gatekeeper_ipc.h +++ b/trusty/gatekeeper/trusty_gatekeeper_ipc.h @@ -16,6 +16,7 @@ __BEGIN_DECLS +void trusty_gatekeeper_set_dev_name(const char* device_name); int trusty_gatekeeper_connect(); int trusty_gatekeeper_call(uint32_t cmd, void *in, uint32_t in_size, uint8_t *out, uint32_t *out_size);