1 /*
2 * Copyright (C) 2010-2014 NXP Semiconductors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <string.h>
18 #if !defined(NXPLOG__H_INCLUDED)
19 #include "phNxpConfig.h"
20 #include "phNxpLog.h"
21 #endif
22 #include <cutils/properties.h>
23
24 const char* NXPLOG_ITEM_EXTNS = "NxpExtns";
25 const char* NXPLOG_ITEM_NCIHAL = "NxpHal";
26 const char* NXPLOG_ITEM_NCIX = "NxpNciX";
27 const char* NXPLOG_ITEM_NCIR = "NxpNciR";
28 const char* NXPLOG_ITEM_FWDNLD = "NxpFwDnld";
29 const char* NXPLOG_ITEM_TML = "NxpTml";
30
31 #ifdef NXP_HCI_REQ
32 const char* NXPLOG_ITEM_HCPX = "NxpHcpX";
33 const char* NXPLOG_ITEM_HCPR = "NxpHcpR";
34 #endif /*NXP_HCI_REQ*/
35
36 /* global log level structure */
37 nci_log_level_t gLog_level;
38
39 /*******************************************************************************
40 *
41 * Function phNxpLog_SetGlobalLogLevel
42 *
43 * Description Sets the global log level for all modules.
44 * This value is set by Android property
45 *nfc.nxp_log_level_global.
46 * If value can be overridden by module log level.
47 *
48 * Returns The value of global log level
49 *
50 ******************************************************************************/
phNxpLog_SetGlobalLogLevel(void)51 static uint8_t phNxpLog_SetGlobalLogLevel(void) {
52 uint8_t level = NXPLOG_DEFAULT_LOGLEVEL;
53 unsigned long num = 0;
54 char valueStr[PROPERTY_VALUE_MAX] = {0};
55
56 int len = property_get(PROP_NAME_NXPLOG_GLOBAL_LOGLEVEL, valueStr, "");
57 if (len > 0) {
58 /* let Android property override .conf variable */
59 sscanf(valueStr, "%lu", &num);
60 level = (unsigned char)num;
61 }
62 memset(&gLog_level, level, sizeof(nci_log_level_t));
63 return level;
64 }
65
66 /*******************************************************************************
67 *
68 * Function phNxpLog_SetHALLogLevel
69 *
70 * Description Sets the HAL layer log level.
71 *
72 * Returns void
73 *
74 ******************************************************************************/
phNxpLog_SetHALLogLevel(uint8_t level)75 static void phNxpLog_SetHALLogLevel(uint8_t level) {
76 unsigned long num = 0;
77 int len;
78 char valueStr[PROPERTY_VALUE_MAX] = {0};
79
80 if (GetNxpNumValue(NAME_NXPLOG_HAL_LOGLEVEL, &num, sizeof(num))) {
81 gLog_level.hal_log_level =
82 (level > (unsigned char)num) ? level : (unsigned char)num;
83 ;
84 }
85
86 len = property_get(PROP_NAME_NXPLOG_HAL_LOGLEVEL, valueStr, "");
87 if (len > 0) {
88 /* let Android property override .conf variable */
89 sscanf(valueStr, "%lu", &num);
90 gLog_level.hal_log_level = (unsigned char)num;
91 }
92 }
93
94 /*******************************************************************************
95 *
96 * Function phNxpLog_SetExtnsLogLevel
97 *
98 * Description Sets the Extensions layer log level.
99 *
100 * Returns void
101 *
102 ******************************************************************************/
phNxpLog_SetExtnsLogLevel(uint8_t level)103 static void phNxpLog_SetExtnsLogLevel(uint8_t level) {
104 unsigned long num = 0;
105 int len;
106 char valueStr[PROPERTY_VALUE_MAX] = {0};
107 if (GetNxpNumValue(NAME_NXPLOG_EXTNS_LOGLEVEL, &num, sizeof(num))) {
108 gLog_level.extns_log_level =
109 (level > (unsigned char)num) ? level : (unsigned char)num;
110 ;
111 }
112
113 len = property_get(PROP_NAME_NXPLOG_EXTNS_LOGLEVEL, valueStr, "");
114 if (len > 0) {
115 /* let Android property override .conf variable */
116 sscanf(valueStr, "%lu", &num);
117 gLog_level.extns_log_level = (unsigned char)num;
118 }
119 }
120
121 /*******************************************************************************
122 *
123 * Function phNxpLog_SetTmlLogLevel
124 *
125 * Description Sets the Tml layer log level.
126 *
127 * Returns void
128 *
129 ******************************************************************************/
phNxpLog_SetTmlLogLevel(uint8_t level)130 static void phNxpLog_SetTmlLogLevel(uint8_t level) {
131 unsigned long num = 0;
132 int len;
133 char valueStr[PROPERTY_VALUE_MAX] = {0};
134 if (GetNxpNumValue(NAME_NXPLOG_TML_LOGLEVEL, &num, sizeof(num))) {
135 gLog_level.tml_log_level =
136 (level > (unsigned char)num) ? level : (unsigned char)num;
137 ;
138 }
139
140 len = property_get(PROP_NAME_NXPLOG_TML_LOGLEVEL, valueStr, "");
141 if (len > 0) {
142 /* let Android property override .conf variable */
143 sscanf(valueStr, "%lu", &num);
144 gLog_level.tml_log_level = (unsigned char)num;
145 }
146 }
147
148 /*******************************************************************************
149 *
150 * Function phNxpLog_SetDnldLogLevel
151 *
152 * Description Sets the FW download layer log level.
153 *
154 * Returns void
155 *
156 ******************************************************************************/
phNxpLog_SetDnldLogLevel(uint8_t level)157 static void phNxpLog_SetDnldLogLevel(uint8_t level) {
158 unsigned long num = 0;
159 int len;
160 char valueStr[PROPERTY_VALUE_MAX] = {0};
161 if (GetNxpNumValue(NAME_NXPLOG_FWDNLD_LOGLEVEL, &num, sizeof(num))) {
162 gLog_level.dnld_log_level =
163 (level > (unsigned char)num) ? level : (unsigned char)num;
164 ;
165 }
166
167 len = property_get(PROP_NAME_NXPLOG_FWDNLD_LOGLEVEL, valueStr, "");
168 if (len > 0) {
169 /* let Android property override .conf variable */
170 sscanf(valueStr, "%lu", &num);
171 gLog_level.dnld_log_level = (unsigned char)num;
172 }
173 }
174
175 /*******************************************************************************
176 *
177 * Function phNxpLog_SetNciTxLogLevel
178 *
179 * Description Sets the NCI transaction layer log level.
180 *
181 * Returns void
182 *
183 ******************************************************************************/
phNxpLog_SetNciTxLogLevel(uint8_t level)184 static void phNxpLog_SetNciTxLogLevel(uint8_t level) {
185 unsigned long num = 0;
186 int len;
187 char valueStr[PROPERTY_VALUE_MAX] = {0};
188 if (GetNxpNumValue(NAME_NXPLOG_NCIX_LOGLEVEL, &num, sizeof(num))) {
189 gLog_level.ncix_log_level =
190 (level > (unsigned char)num) ? level : (unsigned char)num;
191 }
192 if (GetNxpNumValue(NAME_NXPLOG_NCIR_LOGLEVEL, &num, sizeof(num))) {
193 gLog_level.ncir_log_level =
194 (level > (unsigned char)num) ? level : (unsigned char)num;
195 ;
196 }
197
198 len = property_get(PROP_NAME_NXPLOG_NCI_LOGLEVEL, valueStr, "");
199 if (len > 0) {
200 /* let Android property override .conf variable */
201 sscanf(valueStr, "%lu", &num);
202 gLog_level.ncix_log_level = (unsigned char)num;
203 gLog_level.ncir_log_level = (unsigned char)num;
204 }
205 }
206
207 /******************************************************************************
208 * Function phNxpLog_InitializeLogLevel
209 *
210 * Description Initialize and get log level of module from libnfc-nxp.conf
211 *or
212 * Android runtime properties.
213 * The Android property nfc.nxp_global_log_level is to
214 * define log level for all modules. Modules log level will
215 *overwide global level.
216 * The Android property will overwide the level
217 * in libnfc-nxp.conf
218 *
219 * Android property names:
220 * nfc.nxp_log_level_global * defines log level for all
221 *modules
222 * nfc.nxp_log_level_extns * extensions module log
223 * nfc.nxp_log_level_hal * Hal module log
224 * nfc.nxp_log_level_dnld * firmware download module
225 *log
226 * nfc.nxp_log_level_tml * TML module log
227 * nfc.nxp_log_level_nci * NCI transaction log
228 *
229 * Log Level values:
230 * NXPLOG_LOG_SILENT_LOGLEVEL 0 * No trace to show
231 * NXPLOG_LOG_ERROR_LOGLEVEL 1 * Show Error trace
232 *only
233 * NXPLOG_LOG_WARN_LOGLEVEL 2 * Show Warning
234 *trace and Error trace
235 * NXPLOG_LOG_DEBUG_LOGLEVEL 3 * Show all traces
236 *
237 * Returns void
238 *
239 ******************************************************************************/
phNxpLog_InitializeLogLevel(void)240 void phNxpLog_InitializeLogLevel(void) {
241 uint8_t level = phNxpLog_SetGlobalLogLevel();
242 phNxpLog_SetHALLogLevel(level);
243 phNxpLog_SetExtnsLogLevel(level);
244 phNxpLog_SetTmlLogLevel(level);
245 phNxpLog_SetDnldLogLevel(level);
246 phNxpLog_SetNciTxLogLevel(level);
247
248 ALOGD(
249 "%s: global =%u, Fwdnld =%u, extns =%u, \
250 hal =%u, tml =%u, ncir =%u, \
251 ncix =%u",
252 __func__, gLog_level.global_log_level, gLog_level.dnld_log_level,
253 gLog_level.extns_log_level, gLog_level.hal_log_level,
254 gLog_level.tml_log_level, gLog_level.ncir_log_level,
255 gLog_level.ncix_log_level);
256 }
257