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 #if !defined(NXPLOG__H_INCLUDED)
18 #define NXPLOG__H_INCLUDED
19 
20 #include <cutils/log.h>
21 
22 typedef struct nci_log_level {
23   uint8_t global_log_level;
24   uint8_t extns_log_level;
25   uint8_t hal_log_level;
26   uint8_t dnld_log_level;
27   uint8_t tml_log_level;
28   uint8_t ncix_log_level;
29   uint8_t ncir_log_level;
30 } nci_log_level_t;
31 
32 /* global log level Ref */
33 extern nci_log_level_t gLog_level;
34 
35 /* define log module included when compile */
36 #define ENABLE_EXTNS_TRACES TRUE
37 #define ENABLE_HAL_TRACES TRUE
38 #define ENABLE_TML_TRACES TRUE
39 #define ENABLE_FWDNLD_TRACES TRUE
40 #define ENABLE_NCIX_TRACES TRUE
41 #define ENABLE_NCIR_TRACES TRUE
42 
43 #define ENABLE_HCPX_TRACES FALSE
44 #define ENABLE_HCPR_TRACES FALSE
45 
46 /* ####################### Set the log module name in .conf file
47  * ########################## */
48 #define NAME_NXPLOG_EXTNS_LOGLEVEL "NXPLOG_EXTNS_LOGLEVEL"
49 #define NAME_NXPLOG_HAL_LOGLEVEL "NXPLOG_NCIHAL_LOGLEVEL"
50 #define NAME_NXPLOG_NCIX_LOGLEVEL "NXPLOG_NCIX_LOGLEVEL"
51 #define NAME_NXPLOG_NCIR_LOGLEVEL "NXPLOG_NCIR_LOGLEVEL"
52 #define NAME_NXPLOG_FWDNLD_LOGLEVEL "NXPLOG_FWDNLD_LOGLEVEL"
53 #define NAME_NXPLOG_TML_LOGLEVEL "NXPLOG_TML_LOGLEVEL"
54 
55 /* ####################### Set the log module name by Android property
56  * ########################## */
57 #define PROP_NAME_NXPLOG_GLOBAL_LOGLEVEL "nfc.nxp_log_level_global"
58 #define PROP_NAME_NXPLOG_EXTNS_LOGLEVEL "nfc.nxp_log_level_extns"
59 #define PROP_NAME_NXPLOG_HAL_LOGLEVEL "nfc.nxp_log_level_hal"
60 #define PROP_NAME_NXPLOG_NCI_LOGLEVEL "nfc.nxp_log_level_nci"
61 #define PROP_NAME_NXPLOG_FWDNLD_LOGLEVEL "nfc.nxp_log_level_dnld"
62 #define PROP_NAME_NXPLOG_TML_LOGLEVEL "nfc.nxp_log_level_tml"
63 
64 /* ####################### Set the logging level for EVERY COMPONENT here
65  * ######################## :START: */
66 #define NXPLOG_LOG_SILENT_LOGLEVEL 0x00
67 #define NXPLOG_LOG_ERROR_LOGLEVEL 0x01
68 #define NXPLOG_LOG_WARN_LOGLEVEL 0x02
69 #define NXPLOG_LOG_DEBUG_LOGLEVEL 0x03
70 /* ####################### Set the default logging level for EVERY COMPONENT
71  * here ########################## :END: */
72 
73 /* The Default log level for all the modules. */
74 #define NXPLOG_DEFAULT_LOGLEVEL NXPLOG_LOG_ERROR_LOGLEVEL
75 
76 /* ################################################################################################################
77  */
78 /* ############################################### Component Names
79  * ################################################ */
80 /* ################################################################################################################
81  */
82 
83 extern const char* NXPLOG_ITEM_EXTNS;  /* Android logging tag for NxpExtns  */
84 extern const char* NXPLOG_ITEM_NCIHAL; /* Android logging tag for NxpNciHal */
85 extern const char* NXPLOG_ITEM_NCIX;   /* Android logging tag for NxpNciX   */
86 extern const char* NXPLOG_ITEM_NCIR;   /* Android logging tag for NxpNciR   */
87 extern const char* NXPLOG_ITEM_FWDNLD; /* Android logging tag for NxpFwDnld */
88 extern const char* NXPLOG_ITEM_TML;    /* Android logging tag for NxpTml    */
89 
90 #ifdef NXP_HCI_REQ
91 extern const char* NXPLOG_ITEM_HCPX; /* Android logging tag for NxpHcpX   */
92 extern const char* NXPLOG_ITEM_HCPR; /* Android logging tag for NxpHcpR   */
93 #endif                               /*NXP_HCI_REQ*/
94 
95 /* ######################################## Defines used for Logging data
96  * ######################################### */
97 #ifdef NXP_VRBS_REQ
98 #define NXPLOG_FUNC_ENTRY(COMP) \
99   LOG_PRI(ANDROID_LOG_VERBOSE, (COMP), "+:%s", (__func__))
100 #define NXPLOG_FUNC_EXIT(COMP) \
101   LOG_PRI(ANDROID_LOG_VERBOSE, (COMP), "-:%s", (__func__))
102 #endif /*NXP_VRBS_REQ*/
103 
104 /* ################################################################################################################
105  */
106 /* ######################################## Logging APIs of actual modules
107  * ######################################## */
108 /* ################################################################################################################
109  */
110 /* Logging APIs used by NxpExtns module */
111 #if (ENABLE_EXTNS_TRACES == TRUE)
112 #define NXPLOG_EXTNS_D(...)                                       \
113   {                                                               \
114     if (gLog_level.extns_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)  \
115       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \
116   }
117 #define NXPLOG_EXTNS_W(...)                                      \
118   {                                                              \
119     if (gLog_level.extns_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)  \
120       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \
121   }
122 #define NXPLOG_EXTNS_E(...)                                       \
123   {                                                               \
124     if (gLog_level.extns_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)  \
125       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \
126   }
127 #else
128 #define NXPLOG_EXTNS_D(...)
129 #define NXPLOG_EXTNS_W(...)
130 #define NXPLOG_EXTNS_E(...)
131 #endif /* Logging APIs used by NxpExtns module */
132 
133 /* Logging APIs used by NxpNciHal module */
134 #if (ENABLE_HAL_TRACES == TRUE)
135 #define NXPLOG_NCIHAL_D(...)                                       \
136   {                                                                \
137     if (gLog_level.hal_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)     \
138       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \
139   }
140 #define NXPLOG_NCIHAL_W(...)                                      \
141   {                                                               \
142     if (gLog_level.hal_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)     \
143       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \
144   }
145 #define NXPLOG_NCIHAL_E(...)                                       \
146   {                                                                \
147     if (gLog_level.hal_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)     \
148       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \
149   }
150 #else
151 #define NXPLOG_NCIHAL_D(...)
152 #define NXPLOG_NCIHAL_W(...)
153 #define NXPLOG_NCIHAL_E(...)
154 #endif /* Logging APIs used by HAL module */
155 
156 /* Logging APIs used by NxpNciX module */
157 #if (ENABLE_NCIX_TRACES == TRUE)
158 #define NXPLOG_NCIX_D(...)                                       \
159   {                                                              \
160     if (gLog_level.ncix_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)  \
161       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIX, __VA_ARGS__); \
162   }
163 #define NXPLOG_NCIX_W(...)                                      \
164   {                                                             \
165     if (gLog_level.ncix_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)  \
166       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIX, __VA_ARGS__); \
167   }
168 #define NXPLOG_NCIX_E(...)                                       \
169   {                                                              \
170     if (gLog_level.ncix_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)  \
171       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIX, __VA_ARGS__); \
172   }
173 #else
174 #define NXPLOG_NCIX_D(...)
175 #define NXPLOG_NCIX_W(...)
176 #define NXPLOG_NCIX_E(...)
177 #endif /* Logging APIs used by NCIx module */
178 
179 /* Logging APIs used by NxpNciR module */
180 #if (ENABLE_NCIR_TRACES == TRUE)
181 #define NXPLOG_NCIR_D(...)                                       \
182   {                                                              \
183     if (gLog_level.ncir_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)  \
184       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIR, __VA_ARGS__); \
185   }
186 #define NXPLOG_NCIR_W(...)                                      \
187   {                                                             \
188     if (gLog_level.ncir_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)  \
189       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIR, __VA_ARGS__); \
190   }
191 #define NXPLOG_NCIR_E(...)                                       \
192   {                                                              \
193     if (gLog_level.ncir_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)  \
194       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIR, __VA_ARGS__); \
195   }
196 #else
197 #define NXPLOG_NCIR_D(...)
198 #define NXPLOG_NCIR_W(...)
199 #define NXPLOG_NCIR_E(...)
200 #endif /* Logging APIs used by NCIR module */
201 
202 /* Logging APIs used by NxpFwDnld module */
203 #if (ENABLE_FWDNLD_TRACES == TRUE)
204 #define NXPLOG_FWDNLD_D(...)                                       \
205   {                                                                \
206     if (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)    \
207       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
208   }
209 #define NXPLOG_FWDNLD_W(...)                                      \
210   {                                                               \
211     if (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)    \
212       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
213   }
214 #define NXPLOG_FWDNLD_E(...)                                       \
215   {                                                                \
216     if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)    \
217       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
218   }
219 #else
220 #define NXPLOG_FWDNLD_D(...)
221 #define NXPLOG_FWDNLD_W(...)
222 #define NXPLOG_FWDNLD_E(...)
223 #endif /* Logging APIs used by NxpFwDnld module */
224 
225 /* Logging APIs used by NxpTml module */
226 #if (ENABLE_TML_TRACES == TRUE)
227 #define NXPLOG_TML_D(...)                                       \
228   {                                                             \
229     if (gLog_level.tml_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)  \
230       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_TML, __VA_ARGS__); \
231   }
232 #define NXPLOG_TML_W(...)                                      \
233   {                                                            \
234     if (gLog_level.tml_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)  \
235       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_TML, __VA_ARGS__); \
236   }
237 #define NXPLOG_TML_E(...)                                       \
238   {                                                             \
239     if (gLog_level.tml_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)  \
240       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_TML, __VA_ARGS__); \
241   }
242 #else
243 #define NXPLOG_TML_D(...)
244 #define NXPLOG_TML_W(...)
245 #define NXPLOG_TML_E(...)
246 #endif /* Logging APIs used by NxpTml module */
247 
248 #ifdef NXP_HCI_REQ
249 /* Logging APIs used by NxpHcpX module */
250 #if (ENABLE_HCPX_TRACES == TRUE)
251 #define NXPLOG_HCPX_D(...)                                         \
252   {                                                                \
253     if (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)    \
254       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
255   }
256 #define NXPLOG_HCPX_W(...)                                        \
257   {                                                               \
258     if (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)    \
259       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
260   }
261 #define NXPLOG_HCPX_E(...)                                         \
262   {                                                                \
263     if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)    \
264       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
265   }
266 #else
267 #define NXPLOG_HCPX_D(...)
268 #define NXPLOG_HCPX_W(...)
269 #define NXPLOG_HCPX_E(...)
270 #endif /* Logging APIs used by NxpHcpX module */
271 
272 /* Logging APIs used by NxpHcpR module */
273 #if (ENABLE_HCPR_TRACES == TRUE)
274 #define NXPLOG_HCPR_D(...)                                         \
275   {                                                                \
276     if (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)    \
277       LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
278   }
279 #define NXPLOG_HCPR_W(...)                                        \
280   {                                                               \
281     if (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)    \
282       LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
283   }
284 #define NXPLOG_HCPR_E(...)                                         \
285   {                                                                \
286     if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL)    \
287       LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \
288   }
289 #else
290 #define NXPLOG_HCPR_D(...)
291 #define NXPLOG_HCPR_W(...)
292 #define NXPLOG_HCPR_E(...)
293 #endif /* Logging APIs used by NxpHcpR module */
294 #endif /* NXP_HCI_REQ */
295 
296 #ifdef NXP_VRBS_REQ
297 #if (ENABLE_EXTNS_TRACES == TRUE)
298 #define NXPLOG_EXTNS_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_EXTNS)
299 #define NXPLOG_EXTNS_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_EXTNS)
300 #else
301 #define NXPLOG_EXTNS_ENTRY()
302 #define NXPLOG_EXTNS_EXIT()
303 #endif
304 
305 #if (ENABLE_HAL_TRACES == TRUE)
306 #define NXPLOG_NCIHAL_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIHAL)
307 #define NXPLOG_NCIHAL_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIHAL)
308 #else
309 #define NXPLOG_NCIHAL_ENTRY()
310 #define NXPLOG_NCIHAL_EXIT()
311 #endif
312 
313 #if (ENABLE_NCIX_TRACES == TRUE)
314 #define NXPLOG_NCIX_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIX)
315 #define NXPLOG_NCIX_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIX)
316 #else
317 #define NXPLOG_NCIX_ENTRY()
318 #define NXPLOG_NCIX_EXIT()
319 #endif
320 
321 #if (ENABLE_NCIR_TRACES == TRUE)
322 #define NXPLOG_NCIR_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIR)
323 #define NXPLOG_NCIR_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIR)
324 #else
325 #define NXPLOG_NCIR_ENTRY()
326 #define NXPLOG_NCIR_EXIT()
327 #endif
328 
329 #ifdef NXP_HCI_REQ
330 
331 #if (ENABLE_HCPX_TRACES == TRUE)
332 #define NXPLOG_HCPX_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_HCPX)
333 #define NXPLOG_HCPX_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_HCPX)
334 #else
335 #define NXPLOG_HCPX_ENTRY()
336 #define NXPLOG_HCPX_EXIT()
337 #endif
338 
339 #if (ENABLE_HCPR_TRACES == TRUE)
340 #define NXPLOG_HCPR_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_HCPR)
341 #define NXPLOG_HCPR_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_HCPR)
342 #else
343 #define NXPLOG_HCPR_ENTRY()
344 #define NXPLOG_HCPR_EXIT()
345 #endif
346 #endif /* NXP_HCI_REQ */
347 
348 #endif /* NXP_VRBS_REQ */
349 
350 void phNxpLog_InitializeLogLevel(void);
351 
352 #endif /* NXPLOG__H_INCLUDED */
353