Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
debug_lib.h
Go to the documentation of this file.
1/*
2 * Copyright 2015-2018 Yubico AB
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#ifndef DEBUG_LIB_H
18#define DEBUG_LIB_H
19
20#include <stdint.h>
21#include <stdio.h>
22#include <sys/time.h>
23#include <time.h>
24
25#include "yubihsm.h"
26
27#include "../common/debug.h"
28
30extern FILE *_yh_output;
31
32#define DUMPIF(var, len, lev) \
33 do { \
34 if (_yh_verbosity & lev) { \
35 dump_hex(_yh_output, var, len); \
36 fprintf(_yh_output, "\n"); \
37 } \
38 } while (0)
39
40#define DBG_INT(var, len, ...) \
41 do { \
42 D(_yh_verbosity &YH_VERB_INTERMEDIATE, _yh_output, ANSI_YELLOW, "LIB", \
43 "INT", __VA_ARGS__); \
44 DUMPIF(var, len, YH_VERB_INTERMEDIATE); \
45 } while (0)
46
47#define DBG_CRYPTO(var, len, ...) \
48 do { \
49 D(_yh_verbosity &YH_VERB_CRYPTO, _yh_output, ANSI_GREEN, "LIB", "CRY", \
50 __VA_ARGS__); \
51 DUMPIF(var, len, YH_VERB_CRYPTO); \
52 } while (0)
53
54#define DBG_NET(var, dump) \
55 do { \
56 D(_yh_verbosity &YH_VERB_RAW, _yh_output, ANSI_MAGENTA, "LIB", "NET", \
57 " "); \
58 if (_yh_verbosity & YH_VERB_RAW) { \
59 dump(_yh_output, (var)); \
60 } \
61 } while (0)
62
63#define DBG_INFO(...) \
64 do { \
65 DLN(_yh_verbosity &YH_VERB_INFO, _yh_output, ANSI_BLUE, "LIB", "INF", \
66 __VA_ARGS__); \
67 } while (0)
68
69#define DBG_DUMPINFO(var, len, ...) \
70 do { \
71 D(_yh_verbosity &YH_VERB_INFO, _yh_output, ANSI_BLUE, "LIB", "INF", \
72 __VA_ARGS__); \
73 DUMPIF(var, len, YH_VERB_INFO); \
74 } while (0)
75
76#define DBG_ERR(...) \
77 do { \
78 DLN(_yh_verbosity &YH_VERB_ERR, _yh_output, ANSI_RED, "LIB", "ERR", \
79 __VA_ARGS__); \
80 } while (0)
81#endif
82
83#define DBG_DUMPERR(var, len, ...) \
84 do { \
85 D(_yh_verbosity &YH_VERB_ERR, _yh_output, ANSI_RED, "LIB", "ERR", \
86 __VA_ARGS__); \
87 DUMPIF(var, len, YH_VERB_ERR); \
88 } while (0)
uint8_t _yh_verbosity
FILE * _yh_output
unsigned char uint8_t
Definition stdint.h:124