Restore support for TA logging and debug.h header 05/179605/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 8 May 2018 12:01:43 +0000 (14:01 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Mon, 4 Jun 2018 10:14:02 +0000 (12:14 +0200)
Change-Id: I796839c17203b4898a9f82595d656b573916b715
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
TEEStub/CMakeLists.txt
include/include/debug.h [new file with mode: 0644]
log/CMakeLists.txt
log/log.c
log/log.h
log/ta_log.c [new file with mode: 0644]
packaging/tef-simulator.spec

index d1b97ad..8827c55 100644 (file)
@@ -46,6 +46,8 @@ SET(TEE_STUB_SOURCES
 
 SET(TEE_STUB_HEADERS
     ${TEF_SIMULATOR_INCLUDE_PATH}/include/tee_internal_api.h
+    ${TEF_SIMULATOR_INCLUDE_PATH}/include/log_level.h
+    ${TEF_SIMULATOR_INCLUDE_PATH}/include/debug.h
     )
 
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_TEE_STUB} STATIC
diff --git a/include/include/debug.h b/include/include/debug.h
new file mode 100644 (file)
index 0000000..42bf9c3
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * debug.h
+ *
+ * This source file is proprietary property of Samsung Electronics Co., Ltd.
+ *
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jaemin Ryu <jm77.ryu@samsung.com>
+ *
+ */
+
+#ifndef __ALLOC_DEBUG_H__
+#define __ALLOC_DEBUG_H__
+
+#include <log_level.h>
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#define TEE_STUB  "TEE_STUB"
+#define LOG_LABEL_SIZE 64
+
+int __logger_log(const char* tag, const usr_log_level lv, const char* fmt, const char* function, const int line, ...);
+
+#define LOGD(Tag, Fmt, ...) __logger_log(Tag, LOG_DEBUG, Fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define LOGI(Tag, Fmt, ...) __logger_log(Tag, LOG_INFO, Fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define LOGW(Tag, Fmt, ...) __logger_log(Tag, LOG_WARNING, Fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define LOGE(Tag, Fmt, ...) __logger_log(Tag, LOG_ERR, Fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define LOGC(Tag, Fmt, ...) __logger_log(Tag, LOG_CRIT, Fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
+void setDebugLogLevelNum(const usr_log_level __level);
+int getDebugLogLevelNum(void);
+void setDebugLogLevel(const char* __level);
+void setDebugLogName(const char* __name); /* buffer(__name) size should be LOG_LABEL_SIZE(64)  */
+void getDebugLogName(char* __name);       /* buffer(__name) size should be LOG_LABEL_SIZE(64)  */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ALLOC_DEBUG_H */
index 81382ec..8e07e04 100644 (file)
 
 SET(LOG_SOURCES
     ${LOG_PATH}/log.c
+    ${LOG_PATH}/ta_log.c
     )
 
+INCLUDE_DIRECTORIES(
+    ${TEF_SIMULATOR_INCLUDE_PATH}/include
+)
+
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_LOG} ${LOG_SOURCES})
 
 INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_LOG} DESTINATION ${LIB_DIR})
index 574a303..acd3f14 100644 (file)
--- a/log/log.c
+++ b/log/log.c
@@ -110,22 +110,18 @@ const char *getModuleLevelString(IN int32_t module_level)
        switch (module_level) {
        case MODULE_UTILS:
                return "UTILS";
-
        case MODULE_SIM_DAEMON:
                return "SIM_DAEMON";
-
        case MODULE_TEEC_LIB:
                return "TEEC_LIB";
-
        case MODULE_TEE_STUB:
                return "TEE_STUB";
-
        case MODULE_SSF_LIB:
                return "SSF_LIB";
-
        case MODULE_OSA_LIB:
                return "OSA_LIB";
-
+       case MODULE_CLIENT_TA:
+               return "CLIENT_TA";
        default:
                return "TA_SDK";
        }
@@ -200,10 +196,10 @@ static android_LogPriority logLevelToAndroidLogLevel(LogLevel log_level)
 }
 #endif
 
-static void PrintLog(IN const char *tag, IN const char *function_name,
-                    IN const int32_t line_no, IN int32_t module_level,
-                    IN LogLevel log_level, IN const char *message,
-                    va_list variable_list)
+void PrintLog(IN const char *tag, IN const char *function_name,
+             IN const int32_t line_no, IN int32_t module_level,
+             IN LogLevel log_level, IN const char *message,
+             va_list variable_list)
 {
        if (!(module_level & gmodule_level)
            || log_level > glog_level)
index e56c588..93c4d33 100644 (file)
--- a/log/log.h
+++ b/log/log.h
@@ -65,6 +65,7 @@ typedef enum {
        MODULE_TEST = 0x10,
        MODULE_SSF_LIB = 0x20,
        MODULE_OSA_LIB = 0x40,
+       MODULE_CLIENT_TA = 0x80,
        MODULE_ALL = 0xFFFFFFF,
 } ModuleLevel;
 
@@ -164,6 +165,11 @@ void setDebugAndModuleLevel(IN const int32_t module_level,
 void PrintSimulatorLog(IN const char* function_name, IN const int32_t line_no,
                        IN int32_t module_level, IN int32_t log_level,
                        IN const char* message, ...);
+
+void PrintLog(IN const char *tag, IN const char *function_name,
+              IN const int32_t line_no, IN int32_t module_level,
+              IN LogLevel log_level, IN const char *message,
+              va_list variable_list);
 #if defined(__cplusplus)
 } // extern "C"
 #endif
diff --git a/log/ta_log.c b/log/ta_log.c
new file mode 100644 (file)
index 0000000..291c3e2
--- /dev/null
@@ -0,0 +1,135 @@
+/**
+ * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ * @file
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.som)
+ * @brief  Logging interface for TAs
+ */
+
+
+/*-----------------------------------------------------------------------------
+ *  Include files
+ *-----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "log_level.h"
+#include "log.h"
+
+/* Do not include debug.h, its LOG* definitions conflict with dlog */
+
+#define LOG_LABEL_SIZE 64
+#define LOG_BUFFER_SIZE 4096
+
+static int level = TA_LOG_LEVEL;
+static char log_label[LOG_LABEL_SIZE];
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/* The LOG_* names in log_level.h conflict with syslog names, so we can't use
+ * them directly. At the same time usr_log_level is part of public API, so we
+ * can't change it.
+ */
+static LogLevel taLogLevelToLogLevel(usr_log_level log_level) {
+       switch(log_level) {
+       case LOG_EMERG:
+               return SIMU_LOG_EMERG;
+       case LOG_ALERT:
+               return SIMU_LOG_ALERT;
+       case LOG_CRIT:
+               return SIMU_LOG_CRIT;
+       case LOG_ERR:
+               return SIMU_LOG_ERR;
+       case LOG_WARNING:
+               return SIMU_LOG_WARNING;
+       case LOG_NOTICE:
+               return SIMU_LOG_NOTICE;
+       case LOG_INFO:
+               return SIMU_LOG_INFO;
+       case LOG_DEBUG:
+               return SIMU_LOG_DEBUG;
+       case LOG_SILENT:
+       default:
+               return SIMU_LOG_SILENT;
+       }
+}
+
+int getDebugLogLevelNum(void)
+{
+       return level;
+}
+
+void setDebugLogLevel(const char* __level)
+{
+       if(__level != NULL)
+               level = atoi(__level);
+}
+
+void setDebugLogLevelNum(const usr_log_level __level)
+{
+       level = __level;
+}
+
+void getDebugLogName(char* __name)
+{
+       if(__name != NULL) {
+               int length = strlen(log_label);
+               strncpy(__name, log_label, length);
+               __name[length] = '\0';
+       }
+}
+
+void setDebugLogName(const char* __name)
+{
+       if(__name == NULL)
+               return;
+
+       strncpy(log_label, __name, sizeof(log_label)-1);
+       log_label[sizeof(log_label)-1] = 0;
+}
+
+int __logger_log(const char* tag, const usr_log_level lv,
+               const char* fmt, const char* function,
+               const int line,  ...)
+{
+       LogLevel ta_log_level = taLogLevelToLogLevel(lv);
+
+       if (fmt == NULL || function == NULL)
+               return 0;
+       if (tag != NULL && strlen(log_label) == 0)
+               setDebugLogName(tag);
+       if (level < lv || level == LOG_SILENT)
+               return 0;
+
+       va_list args;
+       va_start(args, line);
+       PrintLog(log_label, function, line, MODULE_CLIENT_TA, ta_log_level, fmt, args);
+       va_end(args);
+       return 0;       // TODO
+}
+
+void initDebugLogLevel(const char* fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       __logger_log("Level", LOG_DEBUG, fmt, __FILE__, __LINE__, args);
+       va_end(args);
+}
+
+#ifdef  __cplusplus
+}
+#endif
index ba0b11a..855665d 100644 (file)
@@ -161,6 +161,8 @@ fi
 %{lib_dir}/libtef-simulator-log.a
 %{lib_dir}/libtef-simulator-osal.a
 %{include_dir}/tee_internal_api.h
+%{include_dir}/debug.h
+%{include_dir}/log_level.h
 %{lib_dir}/pkgconfig/tef-simulator-devkit.pc
 %{data_dir}/cmake/Modules/TEFSimulatorDevkit.cmake
 %{data_dir}/GPD_TEE_PROP