1 /******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 * Copyright (C) 2016 ST Microelectronics S.A.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ******************************************************************************/
19 #include "android_logmsg.h"
20 #include "halcore.h"
21
22 void DispHal(const char* title, const void* data, size_t length);
23 unsigned char hal_trace_level = STNFC_TRACE_LEVEL_DEBUG;
24
25 /*******************************************************************************
26 **
27 ** Function: InitializeGlobalAppLogLevel
28 **
29 ** Description: Initialize and get global logging level from
30 ** Android property nfc.app_log_level.
31 **
32 ** Returns: Global log level:
33 ** STNFC_TRACE_LEVEL_NONE 0 * No trace messages to be
34 * generated
35 ** STNFC_TRACE_LEVEL_ERROR 1 * Error condition trace
36 * messages
37 ** STNFC_TRACE_LEVEL_WARNING 2 * Warning condition trace
38 * messages
39 ** STNFC_TRACE_LEVEL_DEBUG 3 * Debug messages (general)
40 **
41 ** STNFC_TRACE_LEVEL_VERBOSE 4 * Verbose messages
42 **
43 *******************************************************************************/
InitializeSTLogLevel()44 unsigned char InitializeSTLogLevel() {
45 unsigned long num = 0;
46 char valueStr[PROPERTY_VALUE_MAX] = {0};
47
48 num = 1;
49 if (GetNumValue(NAME_STNFC_HAL_LOGLEVEL, &num, sizeof(num)))
50 hal_trace_level = (unsigned char)num;
51
52 int len = property_get("nfc.st_hal_log_level", valueStr, "");
53 if (len > 0) {
54 // let Android property override default value
55 sscanf(valueStr, "%lu", &num);
56 hal_trace_level = (unsigned char)num;
57 }
58 STLOG_HAL_D("%s: level=%u", __func__, hal_trace_level);
59 return hal_trace_level;
60 }
61
DispHal(const char * title,const void * data,size_t length)62 void DispHal(const char* title, const void* data, size_t length) {
63 uint8_t* d = (uint8_t*)data;
64 char line[100];
65 size_t i, k;
66 bool first_line = true;
67
68 line[0] = 0;
69 if (length == 0) {
70 STLOG_HAL_D("%s", title);
71 return;
72 } else {
73 STLOG_HAL_D("%s: ", title);
74 }
75 for (i = 0, k = 0; i < length; i++, k++) {
76 if (k > 31) {
77 k = 0;
78 if (first_line == true) {
79 first_line = false;
80 if (title[0] == 'R') {
81 STLOG_HAL_D("Rx %s\n", line);
82 } else if (title[0] == 'T') {
83 STLOG_HAL_D("Tx %s\n", line);
84 } else {
85 STLOG_HAL_D("%s\n", line);
86 }
87 } else {
88 STLOG_HAL_D("%s\n", line);
89 }
90 line[k] = 0;
91 }
92 sprintf(&line[k * 3], "%02x ", d[i]);
93 }
94
95 if (first_line == true) {
96 if (title[0] == 'R') {
97 STLOG_HAL_D("Rx %s\n", line);
98 } else if (title[0] == 'T') {
99 STLOG_HAL_D("Tx %s\n", line);
100 } else {
101 STLOG_HAL_D("%s\n", line);
102 }
103 } else {
104 STLOG_HAL_D("%s\n", line);
105 }
106 }
107