1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __TEE_LOG_H 17 #define __TEE_LOG_H 18 19 /** 20 * @addtogroup TeeTrusted 21 * @{ 22 * 23 * @brief TEE(Trusted Excution Environment) API. 24 * Provides security capability APIs such as trusted storage, encryption and decryption, 25 * and trusted time for trusted application development. 26 * 27 * @since 12 28 */ 29 30 /** 31 * @file tee_log.h 32 * 33 * @brief Provides TEE log APIs. 34 * 35 * Reference of TEE log APIs and internal definitions. 36 * 37 * @library NA 38 * @kit TEE Kit 39 * @syscap SystemCapability.Tee.TeeClient 40 * @since 12 41 * @version 1.0 42 */ 43 44 #include "tee_defines.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Defines the ERROR level of the TA log. 52 * 53 * @since 12 54 */ 55 #define TA_LOG_LEVEL_ERROR 0 56 57 /** 58 * @brief Defines the WARNING level of the TA log. 59 * 60 * @since 12 61 */ 62 #define TA_LOG_LEVEL_WARNING 1 63 64 /** 65 * @brief Defines the INFO level of the TA log. 66 * 67 * @since 12 68 */ 69 #define TA_LOG_LEVEL_INFO 2 70 71 /** 72 * @brief Defines the DEBUG level of the TA log. 73 * 74 * @since 12 75 */ 76 #define TA_LOG_LEVEL_DEBUG 3 77 78 /** 79 * @brief Defines the VERBO level of the TA log. 80 * 81 * @since 12 82 */ 83 #define TA_LOG_LEVEL_VERBO 4 84 85 /** 86 * @brief Defines the default level of the TA log. 87 * 88 * @since 12 89 */ 90 #define TA_LOG_LEVEL_DEFAULT TA_LOG_LEVEL_INFO 91 92 /** 93 * @brief Defines the default level of the TA log. 94 * {@code TA_LOG_LEVEL} can be redefined by TA developers 95 * 96 * @since 12 97 */ 98 #ifndef TA_LOG_LEVEL 99 #define TA_LOG_LEVEL TA_LOG_LEVEL_DEFAULT 100 #endif 101 102 /** 103 * @brief Defines the tag of the VERBO level TA log. 104 * 105 * @since 12 106 */ 107 #define TAG_VERB "[verb]" 108 109 /** 110 * @brief Defines the tag of the DEBUG level TA log. 111 * 112 * @since 12 113 */ 114 #define TAG_DEBUG "[debug]" 115 116 /** 117 * @brief Defines the tag of the INFO level TA log. 118 * 119 * @since 12 120 */ 121 #define TAG_INFO "[info]" 122 123 /** 124 * @brief Defines the tag of the WARNING level TA log. 125 * 126 * @since 12 127 */ 128 #define TAG_WARN "[warn]" 129 130 /** 131 * @brief Defines the tag of the ERROR level TA log. 132 * 133 * @since 12 134 */ 135 #define TAG_ERROR "[error]" 136 137 /** 138 * @brief Enumerates the levels of the log. 139 * 140 * @since 12 141 */ 142 typedef enum { 143 LOG_LEVEL_ERROR = 0, 144 LOG_LEVEL_WARN = 1, 145 LOG_LEVEL_INFO = 2, 146 LOG_LEVEL_DEBUG = 3, 147 LOG_LEVEL_VERBO = 4, 148 LOG_LEVEL_ON = 5, 149 } LOG_LEVEL; 150 151 /** 152 * @brief Provides to print UART logs. 153 * 154 * @param fmt [IN] The log information. 155 * 156 * @since 12 157 */ 158 void uart_cprintf(const char *fmt, ...); 159 160 /** 161 * @brief Provides to print UART logs. 162 * 163 * @param fmt [IN] The log information. 164 * 165 * @since 12 166 */ 167 void uart_printf_func(const char *fmt, ...); 168 169 /** 170 * @brief Provides to print TEE logs. 171 * 172 * @param log_level [IN] The level of the log. 173 * @param fmt [IN] The log information. 174 * 175 * @since 12 176 */ 177 void tee_print(LOG_LEVEL log_level, const char *fmt, ...); 178 179 /** 180 * @brief Provides to print TEE driver logs. 181 * 182 * @param log_level [IN] The level of the log. 183 * @param log_tag [IN] The tag of the log. 184 * @param fmt [IN] The log information. 185 * 186 * @since 12 187 */ 188 void tee_print_driver(LOG_LEVEL log_level, const char *log_tag, const char *fmt, ...); 189 190 extern const char *g_debug_prefix; 191 192 /** 193 * @brief Defines the API to print TEE log at the VERBO level. 194 * 195 * @since 12 196 */ 197 #if (TA_LOG_LEVEL >= TA_LOG_LEVEL_VERBO) 198 #ifdef DRIVER_LOG_TAG 199 #define tlogv(fmt, args...) \ 200 tee_print_driver(LOG_LEVEL_VERBO, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_VERB, __LINE__, ##args) 201 #else 202 #define tlogv(fmt, args...) tee_print(LOG_LEVEL_VERBO, "%s %d:" fmt "", TAG_VERB, __LINE__, ##args) 203 #endif /* DRIVER_LOG_TAG */ 204 #else 205 #define tlogv(fmt, args...) \ 206 do { \ 207 } while (0) 208 #endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_VERBO */ 209 210 /** 211 * @brief Defines the API to print TEE log at the DEBUG level. 212 * 213 * @since 12 214 */ 215 #if (TA_LOG_LEVEL >= TA_LOG_LEVEL_DEBUG) 216 #ifdef DRIVER_LOG_TAG 217 #define tlogd(fmt, args...) \ 218 tee_print_driver(LOG_LEVEL_DEBUG, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_DEBUG, __LINE__, ##args) 219 #else 220 #define tlogd(fmt, args...) tee_print(LOG_LEVEL_DEBUG, "%s %d:" fmt "", TAG_DEBUG, __LINE__, ##args) 221 #endif /* DRIVER_LOG_TAG */ 222 #else 223 #define tlogd(fmt, args...) \ 224 do { \ 225 } while (0) 226 #endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_DEBUG */ 227 228 /** 229 * @brief Defines the API to print TEE log at the INFO level. 230 * 231 * @since 12 232 */ 233 #if (TA_LOG_LEVEL >= TA_LOG_LEVEL_INFO) 234 #ifdef DRIVER_LOG_TAG 235 #define tlogi(fmt, args...) \ 236 tee_print_driver(LOG_LEVEL_INFO, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_INFO, __LINE__, ##args) 237 #else 238 #define tlogi(fmt, args...) tee_print(LOG_LEVEL_INFO, "%s %d:" fmt "", TAG_INFO, __LINE__, ##args) 239 #endif /* DRIVER_LOG_TAG */ 240 #else 241 #define tlogi(fmt, args...) \ 242 do { \ 243 } while (0) 244 #endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_INFO */ 245 246 /** 247 * @brief Defines the API to print TEE log at the WARNING level. 248 * 249 * @since 12 250 */ 251 #if (TA_LOG_LEVEL >= TA_LOG_LEVEL_WARNING) 252 #ifdef DRIVER_LOG_TAG 253 #define tlogw(fmt, args...) \ 254 tee_print_driver(LOG_LEVEL_WARN, DRIVER_LOG_TAG, "%s %d:" fmt "", TAG_WARN, __LINE__, ##args) 255 #else 256 #define tlogw(fmt, args...) tee_print(LOG_LEVEL_WARN, "%s %d:" fmt "", TAG_WARN, __LINE__, ##args) 257 #endif /* DRIVER_LOG_TAG */ 258 #else 259 #define tlogw(fmt, args...) \ 260 do { \ 261 } while (0) 262 #endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_WARNING */ 263 264 /** 265 * @brief Defines the API to print TEE log at the ERROR level. 266 * 267 * @since 12 268 */ 269 #if (TA_LOG_LEVEL >= TA_LOG_LEVEL_ERROR) /* Always meet this condition. */ 270 #ifndef TLOGE_NO_TIMESTAMP 271 #ifdef DRIVER_LOG_TAG 272 #define tloge(fmt, args...) \ 273 tee_print_driver(LOG_LEVEL_ERROR, DRIVER_LOG_TAG, "%s %d:" fmt " ", TAG_ERROR, __LINE__, ##args) 274 #else 275 #define tloge(fmt, args...) tee_print(LOG_LEVEL_ERROR, "%s %d:" fmt " ", TAG_ERROR, __LINE__, ##args) 276 #endif /* DRIVER_LOG_TAG */ 277 #else 278 #define tloge(fmt, args...) printf("[%s] %s %d:" fmt " ", g_debug_prefix, TAG_ERROR, __LINE__, ##args) 279 #endif /* TLOGE_NO_TIMESTAMP */ 280 #else 281 #define tloge(fmt, args...) \ 282 do { \ 283 } while (0) 284 #endif /* TA_LOG_LEVEL >= TA_LOG_LEVEL_ERROR */ 285 286 #ifdef __cplusplus 287 } 288 #endif 289 /** @} */ 290 #endif /* __TEE_LOG_H */ 291