diff options
author | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2018-07-05 11:56:41 +0300 |
---|---|---|
committer | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2018-07-05 11:56:41 +0300 |
commit | 34996aa48bb9979010b84f39858df4774d970e4f (patch) | |
tree | a6e49c43d48d47c9fe40962ce205dfb3c7fbd717 | |
parent | 0cab84de69641cdde1f7842006365de41280c17e (diff) |
First working release
-rw-r--r-- | host/main.c | 36 | ||||
-rw-r--r-- | ta/Makefile | 2 | ||||
-rw-r--r-- | ta/include/logger_ta.h | 8 | ||||
-rw-r--r-- | ta/logger_ta.c | 64 |
4 files changed, 47 insertions, 63 deletions
diff --git a/host/main.c b/host/main.c index d433e4a..8ea7be0 100644 --- a/host/main.c +++ b/host/main.c @@ -43,57 +43,57 @@ int main(int argc, char *argv[]) TEEC_Operation op; TEEC_UUID uuid = TA_LOGGER_UUID; uint32_t err_origin; + TEEC_SharedMemory buf_shm = { + .flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT, + .buffer = NULL, + }; /* Initialize a context connecting us to the TEE */ res = TEEC_InitializeContext(NULL, &ctx); if (res != TEEC_SUCCESS) errx(1, "TEEC_InitializeContext failed with code 0x%x", res); - /* - * Open a session to the "hello world" TA, the TA will print "hello - * world!" in the log when the session is created. - */ res = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin); if (res != TEEC_SUCCESS) errx(1, "TEEC_Opensession failed with code 0x%x origin 0x%x", - res, err_origin); + res, err_origin); /* - * Execute a function in the TA by invoking it, in this case - * we're incrementing a number. + * Execute a function in the TA by invoking it * * The value of command ID part and how the parameters are * interpreted is part of the interface provided by the TA. */ - - /* Clear the TEEC_Operation struct */ memset(&op, 0, sizeof(op)); /* * Prepare the argument. Pass a value in the first parameter, * the remaining three parameters are unused. */ - op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, + op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); - op.params[0].value.a = 42; - printf("Invoking TA to increment %d\n", op.params[0].value.a); - res = TEEC_InvokeCommand(&sess, 1, &op, + res = TEEC_AllocateSharedMemory(&ctx, &buf_shm); + if (res != TEEC_SUCCESS) { + errx(1, "TEEC_AllocateSharedMemory failed"); + return -1; + } + buf_shm.size = strlen(argv[1]) + 1; + memcpy(buf_shm.buffer, argv[1], buf_shm.size); + + op.params[0].memref.parent = &buf_shm; + res = TEEC_InvokeCommand(&sess, TA_LOGGER_WRITE, &op, &err_origin); if (res != TEEC_SUCCESS) errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x", res, err_origin); - printf("TA incremented value to %d\n", op.params[0].value.a); + TEEC_ReleaseSharedMemory(&buf_shm); /* * We're done with the TA, close the session and * destroy the context. - * - * The TA will print "Goodbye!" in the log when the - * session is closed. */ - TEEC_CloseSession(&sess); TEEC_FinalizeContext(&ctx); diff --git a/ta/Makefile b/ta/Makefile index 3d2e6fc..6c79496 100644 --- a/ta/Makefile +++ b/ta/Makefile @@ -2,7 +2,7 @@ CFG_TEE_TA_LOG_LEVEL ?= 4 CPPFLAGS += -DCFG_TEE_TA_LOG_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) # The UUID for the Trusted Application -BINARY=8aaaf200-2450-11e4-abe2-0002a5d5c51b +BINARY=34e65a4c-b04a-4c42-b98f-df901a800dcc -include $(TA_DEV_KIT_DIR)/mk/ta_dev_kit.mk diff --git a/ta/include/logger_ta.h b/ta/include/logger_ta.h index 4dd9d83..a469d35 100644 --- a/ta/include/logger_ta.h +++ b/ta/include/logger_ta.h @@ -36,4 +36,12 @@ { 0x34e65a4c, 0xb04a, 0x4c42, \ { 0xb9, 0x8f, 0xdf, 0x90, 0x1a, 0x80, 0x0d, 0xcc} } +#define TA_LOGGER_READ 0 +#define TA_LOGGER_WRITE 1 + +struct record_t { + uint64_t secure_user_id; + uint64_t last_checked_timestamp; +}; + #endif /*TA_LOGGER_H*/ diff --git a/ta/logger_ta.c b/ta/logger_ta.c index 6913f96..6c869ab 100644 --- a/ta/logger_ta.c +++ b/ta/logger_ta.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Linaro Limited + * Copyright (c) 2018, Linaro Limited * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,8 +65,6 @@ TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); - DMSG("has been called"); - if (param_types != exp_param_types) return TEE_ERROR_BAD_PARAMETERS; @@ -74,13 +72,6 @@ TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types, (void)¶ms; (void)&sess_ctx; - /* - * The DMSG() macro is non-standard, TEE Internal API doesn't - * specify any means to logging from a TA. - */ - IMSG("Entry log World!\n"); - - /* If return value != TEE_SUCCESS the session will not be created. */ return TEE_SUCCESS; } @@ -91,48 +82,26 @@ TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types, void TA_CloseSessionEntryPoint(void __maybe_unused *sess_ctx) { (void)&sess_ctx; /* Unused parameter */ - IMSG("Goodbye!\n"); -} - -static TEE_Result inc_value(uint32_t param_types, - TEE_Param params[4]) -{ - uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, - TEE_PARAM_TYPE_NONE, - TEE_PARAM_TYPE_NONE, - TEE_PARAM_TYPE_NONE); - - DMSG("has been called"); - - if (param_types != exp_param_types) - return TEE_ERROR_BAD_PARAMETERS; - - IMSG("Got value: %u from NW", params[0].value.a); - params[0].value.a++; - IMSG("Increase value to: %u", params[0].value.a); - - return TEE_SUCCESS; } static TEE_Result dec_value(uint32_t param_types, - TEE_Param params[4]) + TEE_Param params[4]) { - uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, - TEE_PARAM_TYPE_NONE, - TEE_PARAM_TYPE_NONE, - TEE_PARAM_TYPE_NONE); + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INOUT, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE); + char *iv; - DMSG("has been called"); + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; - if (param_types != exp_param_types) - return TEE_ERROR_BAD_PARAMETERS; - - IMSG("Got value: %u from NW", params[0].value.a); - params[0].value.a--; - IMSG("Decrease value to: %u", params[0].value.a); + iv = params[0].memref.buffer; + IMSG("Got value: %s from NW", iv); - return TEE_SUCCESS; + return TEE_SUCCESS; } + /* * Called when a TA is invoked. sess_ctx hold that value that was * assigned by TA_OpenSessionEntryPoint(). The rest of the paramters @@ -144,5 +113,12 @@ TEE_Result TA_InvokeCommandEntryPoint(void __maybe_unused *sess_ctx, { (void)&sess_ctx; /* Unused parameter */ + switch (cmd_id) { + case TA_LOGGER_WRITE: + return dec_value(param_types, params); + default: + return TEE_ERROR_BAD_PARAMETERS; + } + return TEE_ERROR_BAD_PARAMETERS; } |