Home | History | Annotate | Download | only in adaptation
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 1999-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 #include "OverrideLog.h"
     19 extern "C"
     20 {
     21     #include "nfc_hal_target.h"
     22 }
     23 #include <cutils/log.h>
     24 
     25 
     26 #ifndef BTE_LOG_BUF_SIZE
     27     #define BTE_LOG_BUF_SIZE  1024
     28 #endif
     29 #define BTE_LOG_MAX_SIZE  (BTE_LOG_BUF_SIZE - 12)
     30 #define MAX_NCI_PACKET_SIZE  259
     31 #define MAX_LOGCAT_LINE     4096
     32 static char log_line[MAX_LOGCAT_LINE];
     33 static const char* sTable = "0123456789abcdef";
     34 
     35 extern UINT32 ScrProtocolTraceFlag;         // = SCR_PROTO_TRACE_ALL; // 0x017F;
     36 extern "C"
     37 {
     38     void DispNci (UINT8 *p, UINT16 len, BOOLEAN is_recv);
     39     void DispHciCmd (BT_HDR *p_buf);
     40     void DispHciEvt (BT_HDR *p_buf);
     41 }
     42 
     43 
     44 void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...)
     45 {
     46     static char buffer [BTE_LOG_BUF_SIZE];
     47     va_list ap;
     48     UINT32 trace_type = trace_set_mask & 0x07; //lower 3 bits contain trace type
     49     int android_log_type = ANDROID_LOG_INFO;
     50 
     51     va_start (ap, fmt_str);
     52     vsnprintf (buffer, BTE_LOG_MAX_SIZE, fmt_str, ap);
     53     va_end (ap);
     54     if (trace_type == TRACE_TYPE_ERROR)
     55         android_log_type = ANDROID_LOG_ERROR;
     56     __android_log_write (android_log_type, "NfcNciHal", buffer);
     57 }
     58 
     59 
     60 void DispNci (UINT8 *data, UINT16 len, BOOLEAN is_recv)
     61 {
     62     if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_NCI))
     63         return;
     64 
     65     char line_buf[(MAX_NCI_PACKET_SIZE*2)+1];
     66     int i,j;
     67 
     68     for(i = 0, j = 0; i < len && j < sizeof(line_buf)-3; i++)
     69     {
     70         line_buf[j++] = sTable[(*data >> 4) & 0xf];
     71         line_buf[j++] = sTable[*data & 0xf];
     72         data++;
     73     }
     74     line_buf[j] = '\0';
     75 
     76     __android_log_write(ANDROID_LOG_DEBUG, (is_recv) ? "BrcmNciR": "BrcmNciX", line_buf);
     77 }
     78 
     79 
     80 void DispHciCmd (BT_HDR *p_buf)
     81 {
     82     int i,j;
     83     int nBytes = ((BT_HDR_SIZE + p_buf->offset + p_buf->len)*2)+1;
     84     UINT8 * data = (UINT8*) p_buf;
     85     int data_len = BT_HDR_SIZE + p_buf->offset + p_buf->len;
     86 
     87     if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
     88         return;
     89 
     90     if (nBytes > sizeof(log_line))
     91         return;
     92 
     93     for(i = 0, j = 0; i < data_len && j < sizeof(log_line)-3; i++)
     94     {
     95         log_line[j++] = sTable[(*data >> 4) & 0xf];
     96         log_line[j++] = sTable[*data & 0xf];
     97         data++;
     98     }
     99     log_line[j] = '\0';
    100 
    101     __android_log_write(ANDROID_LOG_DEBUG, "BrcmHciX", log_line);
    102 }
    103 
    104 
    105 void DispHciEvt (BT_HDR *p_buf)
    106 {
    107     int i,j;
    108     int nBytes = ((BT_HDR_SIZE + p_buf->offset + p_buf->len)*2)+1;
    109     UINT8 * data = (UINT8*) p_buf;
    110     int data_len = BT_HDR_SIZE + p_buf->offset + p_buf->len;
    111 
    112     if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
    113         return;
    114 
    115     if (nBytes > sizeof(log_line))
    116         return;
    117 
    118     for(i = 0, j = 0; i < data_len && j < sizeof(log_line)-3; i++)
    119     {
    120         log_line[j++] = sTable[(*data >> 4) & 0xf];
    121         log_line[j++] = sTable[*data & 0xf];
    122         data++;
    123     }
    124     log_line[j] = '\0';
    125 
    126     __android_log_write(ANDROID_LOG_DEBUG, "BrcmHciR", log_line);
    127 }
    128