17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci#ifndef __TEE_LOG_H 177777dab0Sopenharmony_ci#define __TEE_LOG_H 187777dab0Sopenharmony_ci 197777dab0Sopenharmony_ci/** 207777dab0Sopenharmony_ci * @addtogroup TeeTrusted 217777dab0Sopenharmony_ci * @{ 227777dab0Sopenharmony_ci * 237777dab0Sopenharmony_ci * @brief TEE(Trusted Excution Environment) API. 247777dab0Sopenharmony_ci * Provides security capability APIs such as trusted storage, encryption and decryption, 257777dab0Sopenharmony_ci * and trusted time for trusted application development. 267777dab0Sopenharmony_ci * 277777dab0Sopenharmony_ci * @since 12 287777dab0Sopenharmony_ci */ 297777dab0Sopenharmony_ci 307777dab0Sopenharmony_ci/** 317777dab0Sopenharmony_ci * @file tee_log.h 327777dab0Sopenharmony_ci * 337777dab0Sopenharmony_ci * @brief Provides TEE log APIs. 347777dab0Sopenharmony_ci * 357777dab0Sopenharmony_ci * Reference of TEE log APIs and internal definitions. 367777dab0Sopenharmony_ci * 377777dab0Sopenharmony_ci * @library NA 387777dab0Sopenharmony_ci * @kit TEEKit 397777dab0Sopenharmony_ci * @syscap SystemCapability.Tee.TeeClient 407777dab0Sopenharmony_ci * @since 12 417777dab0Sopenharmony_ci * @version 1.0 427777dab0Sopenharmony_ci */ 437777dab0Sopenharmony_ci 447777dab0Sopenharmony_ci#include "tee_defines.h" 457777dab0Sopenharmony_ci 467777dab0Sopenharmony_ci#ifdef __cplusplus 477777dab0Sopenharmony_ciextern "C" { 487777dab0Sopenharmony_ci#endif 497777dab0Sopenharmony_ci 507777dab0Sopenharmony_ci/** 517777dab0Sopenharmony_ci * @brief Defines the ERROR level of the TA log. 527777dab0Sopenharmony_ci * 537777dab0Sopenharmony_ci * @since 12 547777dab0Sopenharmony_ci */ 557777dab0Sopenharmony_ci#define TA_LOG_LEVEL_ERROR 0 567777dab0Sopenharmony_ci 577777dab0Sopenharmony_ci/** 587777dab0Sopenharmony_ci * @brief Defines the WARNING level of the TA log. 597777dab0Sopenharmony_ci * 607777dab0Sopenharmony_ci * @since 12 617777dab0Sopenharmony_ci */ 627777dab0Sopenharmony_ci#define TA_LOG_LEVEL_WARNING 1 637777dab0Sopenharmony_ci 647777dab0Sopenharmony_ci/** 657777dab0Sopenharmony_ci * @brief Defines the INFO level of the TA log. 667777dab0Sopenharmony_ci * 677777dab0Sopenharmony_ci * @since 12 687777dab0Sopenharmony_ci */ 697777dab0Sopenharmony_ci#define TA_LOG_LEVEL_INFO 2 707777dab0Sopenharmony_ci 717777dab0Sopenharmony_ci/** 727777dab0Sopenharmony_ci * @brief Defines the DEBUG level of the TA log. 737777dab0Sopenharmony_ci * 747777dab0Sopenharmony_ci * @since 12 757777dab0Sopenharmony_ci */ 767777dab0Sopenharmony_ci#define TA_LOG_LEVEL_DEBUG 3 777777dab0Sopenharmony_ci 787777dab0Sopenharmony_ci/** 797777dab0Sopenharmony_ci * @brief Defines the VERBO level of the TA log. 807777dab0Sopenharmony_ci * 817777dab0Sopenharmony_ci * @since 12 827777dab0Sopenharmony_ci */ 837777dab0Sopenharmony_ci#define TA_LOG_LEVEL_VERBO 4 847777dab0Sopenharmony_ci 857777dab0Sopenharmony_ci/** 867777dab0Sopenharmony_ci * @brief Defines the default level of the TA log. 877777dab0Sopenharmony_ci * 887777dab0Sopenharmony_ci * @since 12 897777dab0Sopenharmony_ci */ 907777dab0Sopenharmony_ci#define TA_LOG_LEVEL_DEFAULT TA_LOG_LEVEL_INFO 917777dab0Sopenharmony_ci 927777dab0Sopenharmony_ci/** 937777dab0Sopenharmony_ci * @brief Defines the default level of the TA log. 947777dab0Sopenharmony_ci * {@code TA_LOG_LEVEL} can be redefined by TA developers 957777dab0Sopenharmony_ci * 967777dab0Sopenharmony_ci * @since 12 977777dab0Sopenharmony_ci */ 987777dab0Sopenharmony_ci#ifndef TA_LOG_LEVEL 997777dab0Sopenharmony_ci#define TA_LOG_LEVEL TA_LOG_LEVEL_DEFAULT 1007777dab0Sopenharmony_ci#endif 1017777dab0Sopenharmony_ci 1027777dab0Sopenharmony_ci/** 1037777dab0Sopenharmony_ci * @brief Defines the tag of the VERBO level TA log. 1047777dab0Sopenharmony_ci * 1057777dab0Sopenharmony_ci * @since 12 1067777dab0Sopenharmony_ci */ 1077777dab0Sopenharmony_ci#define TAG_VERB "[verb]" 1087777dab0Sopenharmony_ci 1097777dab0Sopenharmony_ci/** 1107777dab0Sopenharmony_ci * @brief Defines the tag of the DEBUG level TA log. 1117777dab0Sopenharmony_ci * 1127777dab0Sopenharmony_ci * @since 12 1137777dab0Sopenharmony_ci */ 1147777dab0Sopenharmony_ci#define TAG_DEBUG "[debug]" 1157777dab0Sopenharmony_ci 1167777dab0Sopenharmony_ci/** 1177777dab0Sopenharmony_ci * @brief Defines the tag of the INFO level TA log. 1187777dab0Sopenharmony_ci * 1197777dab0Sopenharmony_ci * @since 12 1207777dab0Sopenharmony_ci */ 1217777dab0Sopenharmony_ci#define TAG_INFO "[info]" 1227777dab0Sopenharmony_ci 1237777dab0Sopenharmony_ci/** 1247777dab0Sopenharmony_ci * @brief Defines the tag of the WARNING level TA log. 1257777dab0Sopenharmony_ci * 1267777dab0Sopenharmony_ci * @since 12 1277777dab0Sopenharmony_ci */ 1287777dab0Sopenharmony_ci#define TAG_WARN "[warn]" 1297777dab0Sopenharmony_ci 1307777dab0Sopenharmony_ci/** 1317777dab0Sopenharmony_ci * @brief Defines the tag of the ERROR level TA log. 1327777dab0Sopenharmony_ci * 1337777dab0Sopenharmony_ci * @since 12 1347777dab0Sopenharmony_ci */ 1357777dab0Sopenharmony_ci#define TAG_ERROR "[error]" 1367777dab0Sopenharmony_ci 1377777dab0Sopenharmony_ci/** 1387777dab0Sopenharmony_ci * @brief Enumerates the levels of the log. 1397777dab0Sopenharmony_ci * 1407777dab0Sopenharmony_ci * @since 12 1417777dab0Sopenharmony_ci */ 1427777dab0Sopenharmony_citypedef enum { 1437777dab0Sopenharmony_ci LOG_LEVEL_ERROR = 0, 1447777dab0Sopenharmony_ci LOG_LEVEL_WARN = 1, 1457777dab0Sopenharmony_ci LOG_LEVEL_INFO = 2, 1467777dab0Sopenharmony_ci LOG_LEVEL_DEBUG = 3, 1477777dab0Sopenharmony_ci LOG_LEVEL_VERBO = 4, 1487777dab0Sopenharmony_ci LOG_LEVEL_ON = 5, 1497777dab0Sopenharmony_ci} LOG_LEVEL; 1507777dab0Sopenharmony_ci 1517777dab0Sopenharmony_ci/** 1527777dab0Sopenharmony_ci * @brief Provides to print UART logs. 1537777dab0Sopenharmony_ci * 1547777dab0Sopenharmony_ci * @param fmt [IN] The log information. 1557777dab0Sopenharmony_ci * 1567777dab0Sopenharmony_ci * @since 12 1577777dab0Sopenharmony_ci */ 1587777dab0Sopenharmony_civoid uart_cprintf(const char *fmt, ...); 1597777dab0Sopenharmony_ci 1607777dab0Sopenharmony_ci/** 1617777dab0Sopenharmony_ci * @brief Provides to print UART logs. 1627777dab0Sopenharmony_ci * 1637777dab0Sopenharmony_ci * @param fmt [IN] The log information. 1647777dab0Sopenharmony_ci * 1657777dab0Sopenharmony_ci * @since 12 1667777dab0Sopenharmony_ci */ 1677777dab0Sopenharmony_civoid uart_printf_func(const char *fmt, ...); 1687777dab0Sopenharmony_ci 1697777dab0Sopenharmony_ci/** 1707777dab0Sopenharmony_ci * @brief Provides to print TEE logs. 1717777dab0Sopenharmony_ci * 1727777dab0Sopenharmony_ci * @param log_level [IN] The level of the log. 1737777dab0Sopenharmony_ci * @param fmt [IN] The log information. 1747777dab0Sopenharmony_ci * 1757777dab0Sopenharmony_ci * @since 12 1767777dab0Sopenharmony_ci */ 1777777dab0Sopenharmony_civoid tee_print(LOG_LEVEL log_level, const char *fmt, ...); 1787777dab0Sopenharmony_ci 1797777dab0Sopenharmony_ci/** 1807777dab0Sopenharmony_ci * @brief Provides to print TEE driver logs. 1817777dab0Sopenharmony_ci * 1827777dab0Sopenharmony_ci * @param log_level [IN] The level of the log. 1837777dab0Sopenharmony_ci * @param log_tag [IN] The tag of the log. 1847777dab0Sopenharmony_ci * @param fmt [IN] The log information. 1857777dab0Sopenharmony_ci * 1867777dab0Sopenharmony_ci * @since 12 1877777dab0Sopenharmony_ci */ 1887777dab0Sopenharmony_civoid tee_print_driver(LOG_LEVEL log_level, const char *log_tag, const char *fmt, ...); 1897777dab0Sopenharmony_ci 1907777dab0Sopenharmony_ciextern const char *g_debug_prefix; 1917777dab0Sopenharmony_ci 1927777dab0Sopenharmony_ci/** 1937777dab0Sopenharmony_ci * @brief Defines the API to print TEE log at the VERBO level. 1947777dab0Sopenharmony_ci * 1957777dab0Sopenharmony_ci * @since 12 1967777dab0Sopenharmony_ci */ 1977777dab0Sopenharmony_ci#if (TA_LOG_LEVEL >= TA_LOG_LEVEL_VERBO) 1987777dab0Sopenharmony_ci#ifdef DRIVER_LOG_TAG 1997777dab0Sopenharmony_ci#define tlogv(fmt, args...) \ 2007777dab0Sopenharmony_ci tee_print_driver(LOG_LEVEL_VERBO, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_VERB, __LINE__, ##args) 2017777dab0Sopenharmony_ci#else 2027777dab0Sopenharmony_ci#define tlogv(fmt, args...) tee_print(LOG_LEVEL_VERBO, "%s %d:" fmt "", TAG_VERB, __LINE__, ##args) 2037777dab0Sopenharmony_ci#endif /* DRIVER_LOG_TAG */ 2047777dab0Sopenharmony_ci#else 2057777dab0Sopenharmony_ci#define tlogv(fmt, args...) \ 2067777dab0Sopenharmony_ci do { \ 2077777dab0Sopenharmony_ci } while (0) 2087777dab0Sopenharmony_ci#endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_VERBO */ 2097777dab0Sopenharmony_ci 2107777dab0Sopenharmony_ci/** 2117777dab0Sopenharmony_ci * @brief Defines the API to print TEE log at the DEBUG level. 2127777dab0Sopenharmony_ci * 2137777dab0Sopenharmony_ci * @since 12 2147777dab0Sopenharmony_ci */ 2157777dab0Sopenharmony_ci#if (TA_LOG_LEVEL >= TA_LOG_LEVEL_DEBUG) 2167777dab0Sopenharmony_ci#ifdef DRIVER_LOG_TAG 2177777dab0Sopenharmony_ci#define tlogd(fmt, args...) \ 2187777dab0Sopenharmony_ci tee_print_driver(LOG_LEVEL_DEBUG, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_DEBUG, __LINE__, ##args) 2197777dab0Sopenharmony_ci#else 2207777dab0Sopenharmony_ci#define tlogd(fmt, args...) tee_print(LOG_LEVEL_DEBUG, "%s %d:" fmt "", TAG_DEBUG, __LINE__, ##args) 2217777dab0Sopenharmony_ci#endif /* DRIVER_LOG_TAG */ 2227777dab0Sopenharmony_ci#else 2237777dab0Sopenharmony_ci#define tlogd(fmt, args...) \ 2247777dab0Sopenharmony_ci do { \ 2257777dab0Sopenharmony_ci } while (0) 2267777dab0Sopenharmony_ci#endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_DEBUG */ 2277777dab0Sopenharmony_ci 2287777dab0Sopenharmony_ci/** 2297777dab0Sopenharmony_ci * @brief Defines the API to print TEE log at the INFO level. 2307777dab0Sopenharmony_ci * 2317777dab0Sopenharmony_ci * @since 12 2327777dab0Sopenharmony_ci */ 2337777dab0Sopenharmony_ci#if (TA_LOG_LEVEL >= TA_LOG_LEVEL_INFO) 2347777dab0Sopenharmony_ci#ifdef DRIVER_LOG_TAG 2357777dab0Sopenharmony_ci#define tlogi(fmt, args...) \ 2367777dab0Sopenharmony_ci tee_print_driver(LOG_LEVEL_INFO, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_INFO, __LINE__, ##args) 2377777dab0Sopenharmony_ci#else 2387777dab0Sopenharmony_ci#define tlogi(fmt, args...) tee_print(LOG_LEVEL_INFO, "%s %d:" fmt "", TAG_INFO, __LINE__, ##args) 2397777dab0Sopenharmony_ci#endif /* DRIVER_LOG_TAG */ 2407777dab0Sopenharmony_ci#else 2417777dab0Sopenharmony_ci#define tlogi(fmt, args...) \ 2427777dab0Sopenharmony_ci do { \ 2437777dab0Sopenharmony_ci } while (0) 2447777dab0Sopenharmony_ci#endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_INFO */ 2457777dab0Sopenharmony_ci 2467777dab0Sopenharmony_ci/** 2477777dab0Sopenharmony_ci * @brief Defines the API to print TEE log at the WARNING level. 2487777dab0Sopenharmony_ci * 2497777dab0Sopenharmony_ci * @since 12 2507777dab0Sopenharmony_ci */ 2517777dab0Sopenharmony_ci#if (TA_LOG_LEVEL >= TA_LOG_LEVEL_WARNING) 2527777dab0Sopenharmony_ci#ifdef DRIVER_LOG_TAG 2537777dab0Sopenharmony_ci#define tlogw(fmt, args...) \ 2547777dab0Sopenharmony_ci tee_print_driver(LOG_LEVEL_WARN, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_WARN, __LINE__, ##args) 2557777dab0Sopenharmony_ci#else 2567777dab0Sopenharmony_ci#define tlogw(fmt, args...) tee_print(LOG_LEVEL_WARN, "%s %d:" fmt "", TAG_WARN, __LINE__, ##args) 2577777dab0Sopenharmony_ci#endif /* DRIVER_LOG_TAG */ 2587777dab0Sopenharmony_ci#else 2597777dab0Sopenharmony_ci#define tlogw(fmt, args...) \ 2607777dab0Sopenharmony_ci do { \ 2617777dab0Sopenharmony_ci } while (0) 2627777dab0Sopenharmony_ci#endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_WARNING */ 2637777dab0Sopenharmony_ci 2647777dab0Sopenharmony_ci/** 2657777dab0Sopenharmony_ci * @brief Defines the API to print TEE log at the ERROR level. 2667777dab0Sopenharmony_ci * 2677777dab0Sopenharmony_ci * @since 12 2687777dab0Sopenharmony_ci */ 2697777dab0Sopenharmony_ci#if (TA_LOG_LEVEL >= TA_LOG_LEVEL_ERROR) /* Always meet this condition. */ 2707777dab0Sopenharmony_ci#ifndef TLOGE_NO_TIMESTAMP 2717777dab0Sopenharmony_ci#ifdef DRIVER_LOG_TAG 2727777dab0Sopenharmony_ci#define tloge(fmt, args...) \ 2737777dab0Sopenharmony_ci tee_print_driver(LOG_LEVEL_ERROR, DRIVER_LOG_TAG, "%s %d:" fmt " ", TAG_ERROR, __LINE__, ##args) 2747777dab0Sopenharmony_ci#else 2757777dab0Sopenharmony_ci#define tloge(fmt, args...) tee_print(LOG_LEVEL_ERROR, "%s %d:" fmt " ", TAG_ERROR, __LINE__, ##args) 2767777dab0Sopenharmony_ci#endif /* DRIVER_LOG_TAG */ 2777777dab0Sopenharmony_ci#else 2787777dab0Sopenharmony_ci#define tloge(fmt, args...) printf("[%s] %s %d:" fmt " ", g_debug_prefix, TAG_ERROR, __LINE__, ##args) 2797777dab0Sopenharmony_ci#endif /* TLOGE_NO_TIMESTAMP */ 2807777dab0Sopenharmony_ci#else 2817777dab0Sopenharmony_ci#define tloge(fmt, args...) \ 2827777dab0Sopenharmony_ci do { \ 2837777dab0Sopenharmony_ci } while (0) 2847777dab0Sopenharmony_ci#endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_ERROR */ 2857777dab0Sopenharmony_ci 2867777dab0Sopenharmony_ci#ifdef __cplusplus 2877777dab0Sopenharmony_ci} 2887777dab0Sopenharmony_ci#endif 2897777dab0Sopenharmony_ci/** @} */ 2907777dab0Sopenharmony_ci#endif /* __TEE_LOG_H */ 291