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