Remove unnecessary defines
[libeap.git] / src / utils / wpa_debug.h
1 /*
2  * wpa_supplicant/hostapd / Debug prints
3  * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef WPA_DEBUG_H
16 #define WPA_DEBUG_H
17
18 #include "wpabuf.h"
19
20 /* Debugging function - conditional printf and hex dump. Driver wrappers can
21  * use these for debugging purposes. */
22
23 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
24
25 #ifdef CONFIG_NO_STDOUT_DEBUG
26
27 #define wpa_debug_print_timestamp() do { } while (0)
28 #define wpa_printf(args...) do { } while (0)
29 #define wpa_hexdump(l,t,b,le) do { } while (0)
30 #define wpa_hexdump_buf(l,t,b) do { } while (0)
31 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
32 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
33 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
34 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
35 #define wpa_debug_open_file(p) do { } while (0)
36 #define wpa_debug_close_file() do { } while (0)
37
38 #else /* CONFIG_NO_STDOUT_DEBUG */
39
40 int wpa_debug_open_file(const char *path);
41 void wpa_debug_close_file(void);
42
43 /**
44  * wpa_debug_printf_timestamp - Print timestamp for debug output
45  *
46  * This function prints a timestamp in seconds_from_1970.microsoconds
47  * format if debug output has been configured to include timestamps in debug
48  * messages.
49  */
50 void wpa_debug_print_timestamp(void);
51
52 /**
53  * wpa_printf - conditional printf
54  * @level: priority level (MSG_*) of the message
55  * @fmt: printf format string, followed by optional arguments
56  *
57  * This function is used to print conditional debugging and error messages. The
58  * output may be directed to stdout, stderr, and/or syslog based on
59  * configuration.
60  *
61  * Note: New line '\n' is added to the end of the text when printing to stdout.
62  */
63 void wpa_printf(int level, char *fmt, ...)
64 PRINTF_FORMAT(2, 3);
65
66 /**
67  * wpa_hexdump - conditional hex dump
68  * @level: priority level (MSG_*) of the message
69  * @title: title of for the message
70  * @buf: data buffer to be dumped
71  * @len: length of the buf
72  *
73  * This function is used to print conditional debugging and error messages. The
74  * output may be directed to stdout, stderr, and/or syslog based on
75  * configuration. The contents of buf is printed out has hex dump.
76  */
77 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
78
79 static inline void wpa_hexdump_buf(int level, const char *title,
80                                    const struct wpabuf *buf)
81 {
82         wpa_hexdump(level, title, wpabuf_head(buf), wpabuf_len(buf));
83 }
84
85 /**
86  * wpa_hexdump_key - conditional hex dump, hide keys
87  * @level: priority level (MSG_*) of the message
88  * @title: title of for the message
89  * @buf: data buffer to be dumped
90  * @len: length of the buf
91  *
92  * This function is used to print conditional debugging and error messages. The
93  * output may be directed to stdout, stderr, and/or syslog based on
94  * configuration. The contents of buf is printed out has hex dump. This works
95  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
96  * etc.) in debug output.
97  */
98 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
99
100 static inline void wpa_hexdump_buf_key(int level, const char *title,
101                                        const struct wpabuf *buf)
102 {
103         wpa_hexdump_key(level, title, wpabuf_head(buf), wpabuf_len(buf));
104 }
105
106 /**
107  * wpa_hexdump_ascii - conditional hex dump
108  * @level: priority level (MSG_*) of the message
109  * @title: title of for the message
110  * @buf: data buffer to be dumped
111  * @len: length of the buf
112  *
113  * This function is used to print conditional debugging and error messages. The
114  * output may be directed to stdout, stderr, and/or syslog based on
115  * configuration. The contents of buf is printed out has hex dump with both
116  * the hex numbers and ASCII characters (for printable range) are shown. 16
117  * bytes per line will be shown.
118  */
119 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
120                        size_t len);
121
122 /**
123  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
124  * @level: priority level (MSG_*) of the message
125  * @title: title of for the message
126  * @buf: data buffer to be dumped
127  * @len: length of the buf
128  *
129  * This function is used to print conditional debugging and error messages. The
130  * output may be directed to stdout, stderr, and/or syslog based on
131  * configuration. The contents of buf is printed out has hex dump with both
132  * the hex numbers and ASCII characters (for printable range) are shown. 16
133  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
134  * default, does not include secret keys (passwords, etc.) in debug output.
135  */
136 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
137                            size_t len);
138
139 #endif /* CONFIG_NO_STDOUT_DEBUG */
140
141
142 #ifdef CONFIG_NO_WPA_MSG
143 #define wpa_msg(args...) do { } while (0)
144 #define wpa_msg_ctrl(args...) do { } while (0)
145 #define wpa_msg_register_cb(f) do { } while (0)
146 #else /* CONFIG_NO_WPA_MSG */
147 /**
148  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
149  * @ctx: Pointer to context data; this is the ctx variable registered
150  *      with struct wpa_driver_ops::init()
151  * @level: priority level (MSG_*) of the message
152  * @fmt: printf format string, followed by optional arguments
153  *
154  * This function is used to print conditional debugging and error messages. The
155  * output may be directed to stdout, stderr, and/or syslog based on
156  * configuration. This function is like wpa_printf(), but it also sends the
157  * same message to all attached ctrl_iface monitors.
158  *
159  * Note: New line '\n' is added to the end of the text when printing to stdout.
160  */
161 void wpa_msg(void *ctx, int level, char *fmt, ...) PRINTF_FORMAT(3, 4);
162
163 /**
164  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
165  * @ctx: Pointer to context data; this is the ctx variable registered
166  *      with struct wpa_driver_ops::init()
167  * @level: priority level (MSG_*) of the message
168  * @fmt: printf format string, followed by optional arguments
169  *
170  * This function is used to print conditional debugging and error messages.
171  * This function is like wpa_msg(), but it sends the output only to the
172  * attached ctrl_iface monitors. In other words, it can be used for frequent
173  * events that do not need to be sent to syslog.
174  */
175 void wpa_msg_ctrl(void *ctx, int level, char *fmt, ...) PRINTF_FORMAT(3, 4);
176
177 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
178                                 size_t len);
179
180 /**
181  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
182  * @func: Callback function (%NULL to unregister)
183  */
184 void wpa_msg_register_cb(wpa_msg_cb_func func);
185 #endif /* CONFIG_NO_WPA_MSG */
186
187
188 #ifdef CONFIG_NO_HOSTAPD_LOGGER
189 #define hostapd_logger(args...) do { } while (0)
190 #define hostapd_logger_register_cb(f) do { } while (0)
191 #else /* CONFIG_NO_HOSTAPD_LOGGER */
192 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
193                     const char *fmt, ...) PRINTF_FORMAT(5, 6);
194
195 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
196                                        unsigned int module, int level,
197                                        const char *txt, size_t len);
198
199 /**
200  * hostapd_logger_register_cb - Register callback function for hostapd_logger()
201  * @func: Callback function (%NULL to unregister)
202  */
203 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
204 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
205
206 #define HOSTAPD_MODULE_IEEE80211        0x00000001
207 #define HOSTAPD_MODULE_IEEE8021X        0x00000002
208 #define HOSTAPD_MODULE_RADIUS           0x00000004
209 #define HOSTAPD_MODULE_WPA              0x00000008
210 #define HOSTAPD_MODULE_DRIVER           0x00000010
211 #define HOSTAPD_MODULE_IAPP             0x00000020
212 #define HOSTAPD_MODULE_MLME             0x00000040
213
214 enum hostapd_logger_level {
215         HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
216         HOSTAPD_LEVEL_DEBUG = 1,
217         HOSTAPD_LEVEL_INFO = 2,
218         HOSTAPD_LEVEL_NOTICE = 3,
219         HOSTAPD_LEVEL_WARNING = 4
220 };
221
222
223 #ifdef CONFIG_DEBUG_SYSLOG
224
225 void wpa_debug_open_syslog(void);
226 void wpa_debug_close_syslog(void);
227
228 #else /* CONFIG_DEBUG_SYSLOG */
229
230 static inline void wpa_debug_open_syslog(void)
231 {
232 }
233
234 static inline void wpa_debug_close_syslog(void)
235 {
236 }
237
238 #endif /* CONFIG_DEBUG_SYSLOG */
239
240
241 #ifdef EAPOL_TEST
242 #define WPA_ASSERT(a)                                                  \
243         do {                                                           \
244                 if (!(a)) {                                            \
245                         printf("WPA_ASSERT FAILED '" #a "' "           \
246                                "%s %s:%d\n",                           \
247                                __FUNCTION__, __FILE__, __LINE__);      \
248                         exit(1);                                       \
249                 }                                                      \
250         } while (0)
251 #else
252 #define WPA_ASSERT(a) do { } while (0)
253 #endif
254
255 #endif /* WPA_DEBUG_H */