carl9170 firmware: check virtual interface no. range
[carl9170fw.git] / tools / carlu / src / debug.h
1 /*
2  * carl9170user - userspace testing utility for ar9170 devices
3  *
4  * Debug API definition
5  *
6  * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __CARL9170USER_DEBUG_H
24 #define __CARL9170USER_DEBUG_H
25
26 #include <stdio.h>
27 #include "compiler.h"
28
29 enum debug_level_t {
30         SILENT,
31         ERROR,
32         WARNING,
33         INFO,
34         VERBOSE,
35
36         /* KEEP LAST */
37         ALL,
38 };
39
40 extern bool print_message_debug_level;
41 extern enum debug_level_t debug_level;
42
43 #define __fprintf(lvl, fmt, args...)            do {                                            \
44                 if (lvl <= debug_level) {                                                       \
45                         if (print_message_debug_level)                                          \
46                                 fprintf(dbg_lvl_to_fh(lvl), "<%d>:" fmt, lvl, ##args);          \
47                         else                                                                    \
48                                 fprintf(dbg_lvl_to_fh(lvl), fmt, ##args);                       \
49                 }                                                                               \
50         } while (0);
51
52 #define dbg(fmt, args...) __fprintf(VERBOSE, fmt, ##args)
53 #define info(fmt, args...) __fprintf(INFO, fmt, ##args)
54 #define warn(fmt, args...) __fprintf(WARNING, fmt, ##args)
55 #define err(fmt, args...) __fprintf(ERROR, fmt, ##args)
56
57 #define BUG_ON(a)                                                                               \
58         do {                                                                                    \
59                 if (a) {                                                                        \
60                         __fprintf(ERROR, "!!!=>BUG IN function \"%s\" at line %d<=!!! %s\n",    \
61                                  __func__, __LINE__, #a);                                       \
62                         fflush(stderr);                                                         \
63                         abort();                                                                \
64                 }                                                                               \
65         } while (0)
66
67 FILE *dbg_lvl_to_fh(const enum debug_level_t lvl);
68 void init_debug(void);
69 void print_hex_dump_bytes(const enum debug_level_t lvl, const char *prefix,
70                           const void *buf, size_t len);
71
72 #endif /* __CARL9170USER_DEBUG_H */