blob: 5fdc50ef55400a405721268717a09247ddaad6c5 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * wpa_supplicant/hostapd / Debug prints
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#ifndef WPA_DEBUG_H
10#define WPA_DEBUG_H
11
12#include "wpabuf.h"
13
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080014extern int wpa_debug_level;
15extern int wpa_debug_show_keys;
16extern int wpa_debug_timestamp;
17
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018/* Debugging function - conditional printf and hex dump. Driver wrappers can
19 * use these for debugging purposes. */
20
21enum {
22 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
23};
24
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#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)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080037#define wpa_debug_setup_stdout() do { } while (0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#define wpa_dbg(args...) do { } while (0)
39
40static inline int wpa_debug_reopen_file(void)
41{
42 return 0;
43}
44
45#else /* CONFIG_NO_STDOUT_DEBUG */
46
47int wpa_debug_open_file(const char *path);
48int wpa_debug_reopen_file(void);
49void wpa_debug_close_file(void);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080050void wpa_debug_setup_stdout(void);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070051
52/**
53 * wpa_debug_printf_timestamp - Print timestamp for debug output
54 *
55 * This function prints a timestamp in seconds_from_1970.microsoconds
56 * format if debug output has been configured to include timestamps in debug
57 * messages.
58 */
59void wpa_debug_print_timestamp(void);
60
61/**
62 * wpa_printf - conditional printf
63 * @level: priority level (MSG_*) of the message
64 * @fmt: printf format string, followed by optional arguments
65 *
66 * This function is used to print conditional debugging and error messages. The
67 * output may be directed to stdout, stderr, and/or syslog based on
68 * configuration.
69 *
70 * Note: New line '\n' is added to the end of the text when printing to stdout.
71 */
72void wpa_printf(int level, const char *fmt, ...)
73PRINTF_FORMAT(2, 3);
74
75/**
76 * wpa_hexdump - conditional hex dump
77 * @level: priority level (MSG_*) of the message
78 * @title: title of for the message
79 * @buf: data buffer to be dumped
80 * @len: length of the buf
81 *
82 * This function is used to print conditional debugging and error messages. The
83 * output may be directed to stdout, stderr, and/or syslog based on
84 * configuration. The contents of buf is printed out has hex dump.
85 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080086void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087
88static inline void wpa_hexdump_buf(int level, const char *title,
89 const struct wpabuf *buf)
90{
91 wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
92 buf ? wpabuf_len(buf) : 0);
93}
94
95/**
96 * wpa_hexdump_key - conditional hex dump, hide keys
97 * @level: priority level (MSG_*) of the message
98 * @title: title of for the message
99 * @buf: data buffer to be dumped
100 * @len: length of the buf
101 *
102 * This function is used to print conditional debugging and error messages. The
103 * output may be directed to stdout, stderr, and/or syslog based on
104 * configuration. The contents of buf is printed out has hex dump. This works
105 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
106 * etc.) in debug output.
107 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800108void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109
110static inline void wpa_hexdump_buf_key(int level, const char *title,
111 const struct wpabuf *buf)
112{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800113 wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 buf ? wpabuf_len(buf) : 0);
115}
116
117/**
118 * wpa_hexdump_ascii - conditional hex dump
119 * @level: priority level (MSG_*) of the message
120 * @title: title of for the message
121 * @buf: data buffer to be dumped
122 * @len: length of the buf
123 *
124 * This function is used to print conditional debugging and error messages. The
125 * output may be directed to stdout, stderr, and/or syslog based on
126 * configuration. The contents of buf is printed out has hex dump with both
127 * the hex numbers and ASCII characters (for printable range) are shown. 16
128 * bytes per line will be shown.
129 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800130void wpa_hexdump_ascii(int level, const char *title, const void *buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 size_t len);
132
133/**
134 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
135 * @level: priority level (MSG_*) of the message
136 * @title: title of for the message
137 * @buf: data buffer to be dumped
138 * @len: length of the buf
139 *
140 * This function is used to print conditional debugging and error messages. The
141 * output may be directed to stdout, stderr, and/or syslog based on
142 * configuration. The contents of buf is printed out has hex dump with both
143 * the hex numbers and ASCII characters (for printable range) are shown. 16
144 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
145 * default, does not include secret keys (passwords, etc.) in debug output.
146 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800147void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148 size_t len);
149
150/*
151 * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
152 * binary size. As such, it should be used with debugging messages that are not
153 * needed in the control interface while wpa_msg() has to be used for anything
154 * that needs to shown to control interface monitors.
155 */
156#define wpa_dbg(args...) wpa_msg(args)
157
158#endif /* CONFIG_NO_STDOUT_DEBUG */
159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160
161#ifdef CONFIG_NO_WPA_MSG
162#define wpa_msg(args...) do { } while (0)
163#define wpa_msg_ctrl(args...) do { } while (0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700164#define wpa_msg_global(args...) do { } while (0)
Dmitry Shmidt7f0b69e2014-07-28 10:35:20 -0700165#define wpa_msg_global_ctrl(args...) do { } while (0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700166#define wpa_msg_no_global(args...) do { } while (0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167#define wpa_msg_register_cb(f) do { } while (0)
168#define wpa_msg_register_ifname_cb(f) do { } while (0)
169#else /* CONFIG_NO_WPA_MSG */
170/**
171 * wpa_msg - Conditional printf for default target and ctrl_iface monitors
172 * @ctx: Pointer to context data; this is the ctx variable registered
173 * with struct wpa_driver_ops::init()
174 * @level: priority level (MSG_*) of the message
175 * @fmt: printf format string, followed by optional arguments
176 *
177 * This function is used to print conditional debugging and error messages. The
178 * output may be directed to stdout, stderr, and/or syslog based on
179 * configuration. This function is like wpa_printf(), but it also sends the
180 * same message to all attached ctrl_iface monitors.
181 *
182 * Note: New line '\n' is added to the end of the text when printing to stdout.
183 */
184void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
185
186/**
187 * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
188 * @ctx: Pointer to context data; this is the ctx variable registered
189 * with struct wpa_driver_ops::init()
190 * @level: priority level (MSG_*) of the message
191 * @fmt: printf format string, followed by optional arguments
192 *
193 * This function is used to print conditional debugging and error messages.
194 * This function is like wpa_msg(), but it sends the output only to the
195 * attached ctrl_iface monitors. In other words, it can be used for frequent
196 * events that do not need to be sent to syslog.
197 */
198void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
199PRINTF_FORMAT(3, 4);
200
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700201/**
202 * wpa_msg_global - Global printf for ctrl_iface monitors
203 * @ctx: Pointer to context data; this is the ctx variable registered
204 * with struct wpa_driver_ops::init()
205 * @level: priority level (MSG_*) of the message
206 * @fmt: printf format string, followed by optional arguments
207 *
208 * This function is used to print conditional debugging and error messages.
209 * This function is like wpa_msg(), but it sends the output as a global event,
210 * i.e., without being specific to an interface. For backwards compatibility,
211 * an old style event is also delivered on one of the interfaces (the one
212 * specified by the context data).
213 */
214void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
215PRINTF_FORMAT(3, 4);
216
217/**
Dmitry Shmidt7f0b69e2014-07-28 10:35:20 -0700218 * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
219 * @ctx: Pointer to context data; this is the ctx variable registered
220 * with struct wpa_driver_ops::init()
221 * @level: priority level (MSG_*) of the message
222 * @fmt: printf format string, followed by optional arguments
223 *
224 * This function is used to print conditional debugging and error messages.
225 * This function is like wpa_msg_global(), but it sends the output only to the
226 * attached global ctrl_iface monitors. In other words, it can be used for
227 * frequent events that do not need to be sent to syslog.
228 */
229void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
230PRINTF_FORMAT(3, 4);
231
232/**
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700233 * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
234 * @ctx: Pointer to context data; this is the ctx variable registered
235 * with struct wpa_driver_ops::init()
236 * @level: priority level (MSG_*) of the message
237 * @fmt: printf format string, followed by optional arguments
238 *
239 * This function is used to print conditional debugging and error messages.
240 * This function is like wpa_msg(), but it does not send the output as a global
241 * event.
242 */
243void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
244PRINTF_FORMAT(3, 4);
245
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700246enum wpa_msg_type {
247 WPA_MSG_PER_INTERFACE,
248 WPA_MSG_GLOBAL,
249 WPA_MSG_NO_GLOBAL,
250};
251
252typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700253 const char *txt, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254
255/**
256 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
257 * @func: Callback function (%NULL to unregister)
258 */
259void wpa_msg_register_cb(wpa_msg_cb_func func);
260
261typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
262void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
263
264#endif /* CONFIG_NO_WPA_MSG */
265
266#ifdef CONFIG_NO_HOSTAPD_LOGGER
267#define hostapd_logger(args...) do { } while (0)
268#define hostapd_logger_register_cb(f) do { } while (0)
269#else /* CONFIG_NO_HOSTAPD_LOGGER */
270void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
271 const char *fmt, ...) PRINTF_FORMAT(5, 6);
272
273typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
274 unsigned int module, int level,
275 const char *txt, size_t len);
276
277/**
278 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
279 * @func: Callback function (%NULL to unregister)
280 */
281void hostapd_logger_register_cb(hostapd_logger_cb_func func);
282#endif /* CONFIG_NO_HOSTAPD_LOGGER */
283
284#define HOSTAPD_MODULE_IEEE80211 0x00000001
285#define HOSTAPD_MODULE_IEEE8021X 0x00000002
286#define HOSTAPD_MODULE_RADIUS 0x00000004
287#define HOSTAPD_MODULE_WPA 0x00000008
288#define HOSTAPD_MODULE_DRIVER 0x00000010
289#define HOSTAPD_MODULE_IAPP 0x00000020
290#define HOSTAPD_MODULE_MLME 0x00000040
291
292enum hostapd_logger_level {
293 HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
294 HOSTAPD_LEVEL_DEBUG = 1,
295 HOSTAPD_LEVEL_INFO = 2,
296 HOSTAPD_LEVEL_NOTICE = 3,
297 HOSTAPD_LEVEL_WARNING = 4
298};
299
300
301#ifdef CONFIG_DEBUG_SYSLOG
302
303void wpa_debug_open_syslog(void);
304void wpa_debug_close_syslog(void);
305
306#else /* CONFIG_DEBUG_SYSLOG */
307
308static inline void wpa_debug_open_syslog(void)
309{
310}
311
312static inline void wpa_debug_close_syslog(void)
313{
314}
315
316#endif /* CONFIG_DEBUG_SYSLOG */
317
Dmitry Shmidt04949592012-07-19 12:16:46 -0700318#ifdef CONFIG_DEBUG_LINUX_TRACING
319
320int wpa_debug_open_linux_tracing(void);
321void wpa_debug_close_linux_tracing(void);
322
323#else /* CONFIG_DEBUG_LINUX_TRACING */
324
325static inline int wpa_debug_open_linux_tracing(void)
326{
327 return 0;
328}
329
330static inline void wpa_debug_close_linux_tracing(void)
331{
332}
333
334#endif /* CONFIG_DEBUG_LINUX_TRACING */
335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336
337#ifdef EAPOL_TEST
338#define WPA_ASSERT(a) \
339 do { \
340 if (!(a)) { \
341 printf("WPA_ASSERT FAILED '" #a "' " \
342 "%s %s:%d\n", \
343 __FUNCTION__, __FILE__, __LINE__); \
344 exit(1); \
345 } \
346 } while (0)
347#else
348#define WPA_ASSERT(a) do { } while (0)
349#endif
350
351#endif /* WPA_DEBUG_H */