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 <stdio.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
47 num = 1;
48 if (GetNumValue(NAME_STNFC_HAL_LOGLEVEL, &num, sizeof(num)))
49 hal_trace_level = (unsigned char)num;
50
51 STLOG_HAL_D("%s: level=%u", __func__, hal_trace_level);
52 return hal_trace_level;
53 }
54
DispHal(const char * title,const void * data,size_t length)55 void DispHal(const char* title, const void* data, size_t length) {
56 uint8_t* d = (uint8_t*)data;
57 char line[100];
58 size_t i, k;
59 bool first_line = true;
60 bool privacy = false;
61
62 if (hal_trace_level & STNFC_TRACE_FLAG_PRIVACY) {
63 if ((length > 3) &&
64 // DATA message
65 (((d[0] & 0xE0) == 0) ||
66 // routing table contains the AIDs
67 ((d[0] == 0x21) && (d[1] == 0x01)) ||
68 // NTF showing which AID was selected
69 ((d[0] == 0x61) && (d[1] == 0x09)))) {
70 // We hide the payload for GSMA TS27 15.9.3.2.*
71 privacy = true;
72 }
73 }
74
75 line[0] = 0;
76 if (length == 0) {
77 STLOG_HAL_D("%s", title);
78 return;
79 }
80 for (i = 0, k = 0; i < (privacy ? 3 : length); i++, k++) {
81 if (k > 31) {
82 k = 0;
83 if (first_line == true) {
84 first_line = false;
85 if (title[0] == 'R') {
86 STLOG_HAL_D("Rx %s\n", line);
87 } else if (title[0] == 'T') {
88 STLOG_HAL_D("Tx %s\n", line);
89 } else {
90 STLOG_HAL_D("%s\n", line);
91 }
92 } else {
93 STLOG_HAL_D("%s\n", line);
94 }
95 line[k] = 0;
96 }
97 sprintf(&line[k * 3], "%02x ", d[i]);
98 }
99
100 if (privacy) {
101 sprintf(&line[k * 3], "(hidden)");
102 }
103
104 if (first_line == true) {
105 if (title[0] == 'R') {
106 STLOG_HAL_D("Rx %s\n", line);
107 } else if (title[0] == 'T') {
108 STLOG_HAL_D("Tx %s\n", line);
109 } else {
110 STLOG_HAL_D("%s\n", line);
111 }
112 } else {
113 STLOG_HAL_D("%s\n", line);
114 }
115 }
116