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