2019-02-12 22:18:17 +00:00
|
|
|
|
// Copyright 2019 SoloKeys Developers
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
|
|
|
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
|
|
|
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
|
|
|
// copied, modified, or distributed except according to those terms.
|
2018-05-15 02:55:47 +00:00
|
|
|
|
#include <stdio.h>
|
2018-05-18 15:47:17 +00:00
|
|
|
|
#include <stdlib.h>
|
2018-05-15 02:55:47 +00:00
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include "log.h"
|
2018-05-18 15:40:17 +00:00
|
|
|
|
#include "util.h"
|
2019-02-13 01:28:48 +00:00
|
|
|
|
#include "device.h"
|
2018-05-15 02:55:47 +00:00
|
|
|
|
|
2018-12-03 05:14:26 +00:00
|
|
|
|
#if DEBUG_LEVEL > 0
|
|
|
|
|
|
2018-05-18 15:40:17 +00:00
|
|
|
|
static uint32_t LOGMASK = TAG_FILENO;
|
|
|
|
|
|
2018-12-03 05:14:26 +00:00
|
|
|
|
|
2018-05-18 15:40:17 +00:00
|
|
|
|
void set_logging_mask(uint32_t mask)
|
|
|
|
|
{
|
|
|
|
|
LOGMASK = mask;
|
|
|
|
|
}
|
2018-12-03 05:14:26 +00:00
|
|
|
|
|
|
|
|
|
|
2018-05-18 15:40:17 +00:00
|
|
|
|
struct logtag
|
|
|
|
|
{
|
|
|
|
|
uint32_t tagn;
|
|
|
|
|
const char * tag;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct logtag tagtable[] = {
|
2018-06-04 23:35:34 +00:00
|
|
|
|
{TAG_GEN,""},
|
2018-05-18 15:40:17 +00:00
|
|
|
|
{TAG_MC,"MC"},
|
|
|
|
|
{TAG_GA,"GA"},
|
|
|
|
|
{TAG_CP,"CP"},
|
|
|
|
|
{TAG_ERR,"ERR"},
|
|
|
|
|
{TAG_PARSE,"PARSE"},
|
|
|
|
|
{TAG_CTAP,"CTAP"},
|
2018-05-26 19:29:37 +00:00
|
|
|
|
{TAG_U2F,"U2F"},
|
2018-05-18 15:40:17 +00:00
|
|
|
|
{TAG_DUMP,"DUMP"},
|
2018-11-12 16:51:43 +00:00
|
|
|
|
{TAG_DUMP2,"DUMP2"},
|
2018-06-03 04:50:46 +00:00
|
|
|
|
{TAG_HID,"HID"},
|
2018-06-04 23:35:34 +00:00
|
|
|
|
{TAG_USB,"USB"},
|
|
|
|
|
{TAG_GREEN,"[1;32mDEBUG[0m"},
|
|
|
|
|
{TAG_RED,"[1;31mDEBUG[0m"},
|
|
|
|
|
{TAG_TIME,"[1;33mTIME[0m"},
|
2018-07-08 02:43:06 +00:00
|
|
|
|
{TAG_WALLET,"[1;34mWALLET[0m"},
|
2018-07-12 01:55:20 +00:00
|
|
|
|
{TAG_STOR,"[1;35mSTOR[0m"},
|
2018-12-03 04:31:34 +00:00
|
|
|
|
{TAG_BOOT,"[1;36mBOOT[0m"},
|
2019-01-07 23:29:38 +00:00
|
|
|
|
{TAG_EXT,"[1;37mEXT[0m"},
|
|
|
|
|
{TAG_NFC,"[1;38mNFC[0m"},
|
2019-02-06 17:21:06 +00:00
|
|
|
|
{TAG_NFC_APDU, "NAPDU"},
|
2018-05-18 15:40:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-06-02 18:44:12 +00:00
|
|
|
|
|
|
|
|
|
__attribute__((weak)) void set_logging_tag(uint32_t tag)
|
|
|
|
|
{
|
|
|
|
|
// nothing
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-18 15:40:17 +00:00
|
|
|
|
void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...)
|
2018-05-15 02:55:47 +00:00
|
|
|
|
{
|
2019-01-06 16:41:56 +00:00
|
|
|
|
unsigned int i;
|
2018-05-18 15:40:17 +00:00
|
|
|
|
|
|
|
|
|
if (((tag & 0x7fffffff) & LOGMASK) == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < sizeof(tagtable)/sizeof(struct logtag); i++)
|
|
|
|
|
{
|
|
|
|
|
if (tag & tagtable[i].tagn)
|
|
|
|
|
{
|
2019-01-08 02:19:45 +00:00
|
|
|
|
if (tagtable[i].tag[0] && !(tag & TAG_NO_TAG)) printf("[%s] ", tagtable[i].tag);
|
2018-05-18 15:47:17 +00:00
|
|
|
|
i = 0;
|
2018-05-18 15:40:17 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-18 15:47:17 +00:00
|
|
|
|
if (i != 0)
|
|
|
|
|
{
|
2018-06-04 23:35:34 +00:00
|
|
|
|
printf2(TAG_ERR,"INVALID LOG TAG\n");
|
2018-05-18 15:47:17 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2018-06-02 18:44:12 +00:00
|
|
|
|
set_logging_tag(tag);
|
2018-05-15 02:55:47 +00:00
|
|
|
|
#ifdef ENABLE_FILE_LOGGING
|
2018-05-18 15:40:17 +00:00
|
|
|
|
if (tag & TAG_FILENO)
|
|
|
|
|
{
|
|
|
|
|
printf("%s:%d: ", filename, num);
|
|
|
|
|
}
|
2018-05-15 02:55:47 +00:00
|
|
|
|
#endif
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
vprintf(fmt, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
2018-05-18 15:40:17 +00:00
|
|
|
|
|
|
|
|
|
void LOG_HEX(uint32_t tag, uint8_t * data, int length)
|
|
|
|
|
{
|
|
|
|
|
if (((tag & 0x7fffffff) & LOGMASK) == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-04 23:35:34 +00:00
|
|
|
|
set_logging_tag(tag);
|
2018-05-18 15:40:17 +00:00
|
|
|
|
dump_hex(data,length);
|
|
|
|
|
}
|
2019-02-13 01:28:48 +00:00
|
|
|
|
|
|
|
|
|
uint32_t timestamp()
|
|
|
|
|
{
|
|
|
|
|
static uint32_t t1 = 0;
|
|
|
|
|
uint32_t t2 = millis();
|
|
|
|
|
uint32_t diff = t2 - t1;
|
|
|
|
|
t1 = t2;
|
2019-02-13 01:52:03 +00:00
|
|
|
|
return diff;
|
2019-02-13 01:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 05:14:26 +00:00
|
|
|
|
#endif
|