Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be8f723e authored by Arve Hjønnevåg's avatar Arve Hjønnevåg Committed by Gerrit Code Review
Browse files

Merge changes Ibaa89dd0,I7ca0a7e7,Ib2ef34df into main

* changes:
  trusty: keymint: Add commandline option to specify device name
  trusty: keymaster: Add commandline option to specify device name
  trusty: gatekeeper: Add device option
parents f8aaabec b4158e25
Loading
Loading
Loading
Loading
+55 −1
Original line number Diff line number Diff line
@@ -18,12 +18,66 @@
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <getopt.h>

#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<TrustyGateKeeperDevice> gatekeeper =
+6 −3
Original line number Diff line number Diff line
@@ -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;
    }
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ const uint32_t TRUSTY_KEYMASTER_RECV_BUF_SIZE = 2 * 4096;
const uint32_t TRUSTY_KEYMASTER_SEND_BUF_SIZE =
        (4096 - sizeof(struct keymaster_message) - 16 /* tipc header */);

void trusty_keymaster_set_dev_name(const char* device_name);
int trusty_keymaster_connect(void);
int trusty_keymaster_call(uint32_t cmd, void* in, uint32_t in_size, uint8_t* out,
                          uint32_t* out_size);
+5 −2
Original line number Diff line number Diff line
@@ -36,15 +36,18 @@
#include <trusty_keymaster/ipc/trusty_keymaster_ipc.h>
#include <utils/Timers.h>

#define TRUSTY_DEVICE_NAME "/dev/trusty-ipc-dev0"
static const char* trusty_device_name = "/dev/trusty-ipc-dev0";

static int handle_ = -1;

static const int timeout_ms = 10 * 1000;
static const int max_timeout_ms = 60 * 1000;

void trusty_keymaster_set_dev_name(const char* device_name) {
    trusty_device_name = device_name;
}
int trusty_keymaster_connect() {
    int rc = tipc_connect(TRUSTY_DEVICE_NAME, KEYMASTER_PORT);
    int rc = tipc_connect(trusty_device_name, KEYMASTER_PORT);
    if (rc < 0) {
        return rc;
    }
Loading