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 #define LOG_TAG "StEse-logmsg"
20 #include "android_logmsg.h"
21 #include <ese_config.h>
22 #include <stdio.h>
23
24 void DispHal(const char* title, const void* data, size_t length);
25 unsigned char hal_trace_level = STESE_TRACE_LEVEL_DEBUG;
26
27 /*******************************************************************************
28 **
29 ** Function: InitializeGlobalAppLogLevel
30 **
31 ** Description: Initialize and get global logging level from
32 ** Android property nfc.app_log_level.
33 **
34 ** Returns: Global log level:
35 ** STESE_TRACE_LEVEL_NONE 0 * No trace messages to be
36 * generated
37 ** STESE_TRACE_LEVEL_ERROR 1 * Error condition trace
38 * messages
39 ** STESE_TRACE_LEVEL_WARNING 2 * Warning condition trace
40 * messages
41 ** STESE_TRACE_LEVEL_DEBUG 3 * Debug messages (general)
42 **
43 ** STESE_TRACE_LEVEL_VERBOSE 4 * Verbose messages
44 **
45 *******************************************************************************/
InitializeSTLogLevel()46 unsigned char InitializeSTLogLevel() {
47 unsigned long num = 0;
48
49 num = 1;
50 num = EseConfig::getUnsigned(NAME_STESE_HAL_LOGLEVEL, 0);
51 if (num >= 0) hal_trace_level = (unsigned char)num;
52
53 STLOG_HAL_D("%s: level=%u", __func__, hal_trace_level);
54 return hal_trace_level;
55 }
56
DispHal(const char * title,const void * data,size_t length)57 void DispHal(const char* title, const void* data, size_t length) {
58 uint8_t* d = (uint8_t*)data;
59 char line[100];
60 size_t i, k;
61 bool first_line = true;
62
63 line[0] = 0;
64 if (length == 0) {
65 STLOG_HAL_D("%s", title);
66 return;
67 }
68 for (i = 0, k = 0; i < length; i++, k++) {
69 if (k > 31) {
70 k = 0;
71 if (first_line == true) {
72 first_line = false;
73 if (title[0] == 'R') {
74 STLOG_HAL_D("spiRx %s\n", line);
75 } else if (title[0] == 'T') {
76 STLOG_HAL_D("spiTx %s\n", line);
77 } else {
78 STLOG_HAL_D("%s\n", line);
79 }
80 } else {
81 STLOG_HAL_D("%s\n", line);
82 }
83 line[k] = 0;
84 }
85 sprintf(&line[k * 3], "%02x ", d[i]);
86 }
87
88 if (first_line == true) {
89 if (title[0] == 'R') {
90 STLOG_HAL_D("spiRx %s\n", line);
91 } else if (title[0] == 'T') {
92 STLOG_HAL_D("spiTx %s\n", line);
93 } else {
94 STLOG_HAL_D("%s\n", line);
95 }
96 } else {
97 STLOG_HAL_D("%s\n", line);
98 }
99 }
100