#
-# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
#
# Contact: Krzysztof Dynowski <k.dynowski@samsung.com>
#
SET(CMAKE_C_FLAGS -m32)
ENDIF()
-INCLUDE_DIRECTORIES(
- ${TEF_API_PATH}
-)
-
FILE(GLOB TEF_API_HEADERS api/tef/*.h)
FILE(GLOB TEF_API_SOURCES src/*.c src/simulator/*.c src/optee/*.c)
ADD_LIBRARY(${TEF_TARGET} SHARED ${TEF_API_SOURCES})
+PKG_CHECK_MODULES(LIBTEEC_DEPS
+ capi-system-info
+)
+
+INCLUDE_DIRECTORIES(
+ ${TEF_API_PATH}
+ ${LIBTEEC_DEPS_INCLUDE_DIRS}
+)
+
+TARGET_LINK_LIBRARIES(${TEF_TARGET}
+ ${LIBTEEC_DEPS_LIBRARIES}
+)
+
SET(_LIB_VERSION_ "${VERSION}")
SET(_LIB_SOVERSION_ "0")
SET_TARGET_PROPERTIES(${TEF_TARGET} PROPERTIES
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Krzysztof Dynowski <k.dynowski@samsung.com>
*
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <stdbool.h>
+#include <system_info.h>
#include "simulator/creators.h"
#include "optee/creators.h"
#define TEF_LIB_PATH LIB_INSTALL_DIR "/tef"
#define TEF_IMPLEMENTATION_SONAME "libteec.so"
#define TEEC_SYMBOL(lib, name) *((void**)&lib.w##name) = dlsym(lib.handle, "TEEC_" #name)
+#define TEE_FEATURE "http://tizen.org/feature/security.tee"
typedef struct {
const char *name;
void *lastOperation;
} TEF_SessionImpl;
+static TEEC_Result tee_enabled_check()
+{
+ bool enabled;
+ int sys_ret = system_info_get_platform_bool(TEE_FEATURE, &enabled);
+ if (sys_ret == SYSTEM_INFO_ERROR_NONE) {
+ if (enabled)
+ return TEEC_SUCCESS;
+ else
+ return TEEC_ERROR_NOT_SUPPORTED;
+ }
+
+ const char *error_str;
+ char error_str_buf[256];
+ int ret = TEEC_ERROR_GENERIC, err;
+
+ switch (sys_ret) {
+ case SYSTEM_INFO_ERROR_INVALID_PARAMETER:
+ error_str = "Feature key not present";
+ break;
+ case SYSTEM_INFO_ERROR_IO_ERROR:
+ error_str = "Input/output error";
+ break;
+ case SYSTEM_INFO_ERROR_PERMISSION_DENIED:
+ error_str = "Permission denied";
+ break;
+ default:
+ err = snprintf(error_str_buf, sizeof(error_str_buf), "Unknown error %d", ret);
+ if (err < 0 || (unsigned int) err >= sizeof(error_str_buf))
+ return TEEC_ERROR_GENERIC;
+ error_str = error_str_buf;
+ }
+ fprintf(stderr, "tef-libteec: Failed to query feature %s: %s",
+ TEE_FEATURE, error_str);
+ return ret;
+}
+
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context)
{
if (lib.handle == NULL) {
if (context == NULL) {
return TEEC_ERROR_BAD_PARAMETERS;
}
+ TEEC_Result result;
+ result = tee_enabled_check();
+ if (result != TEEC_SUCCESS)
+ return result;
+
context->imp = lib.createContext();
- TEEC_Result result = lib.wInitializeContext(name, (TEEC_Context *)context->imp);
+ result = lib.wInitializeContext(name, (TEEC_Context *)context->imp);
if (result != TEEC_SUCCESS) {
free(context->imp);
context->imp = NULL;