blob: 291aa07f5743b374a7114e080c59194bf0ff1d61 [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;
Paul Stewart092955c2017-02-06 09:13:09 -080017extern int wpa_debug_syslog;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019/* Debugging function - conditional printf and hex dump. Driver wrappers can
20 * use these for debugging purposes. */
21
22enum {
23 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
24};
25
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#ifdef CONFIG_NO_STDOUT_DEBUG
27
28#define wpa_debug_print_timestamp() do { } while (0)
29#define wpa_printf(args...) do { } while (0)
30#define wpa_hexdump(l,t,b,le) do { } while (0)
31#define wpa_hexdump_buf(l,t,b) do { } while (0)
32#define wpa_hexdump_key(l,t,b,le) do { } while (0)
33#define wpa_hexdump_buf_key(l,t,b) do { } while (0)
34#define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
35#define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
36#define wpa_debug_open_file(p) do { } while (0)
37#define wpa_debug_close_file() do { } while (0)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080038#define wpa_debug_setup_stdout() do { } while (0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#define wpa_dbg(args...) do { } while (0)
40
41static inline int wpa_debug_reopen_file(void)
42{
43 return 0;
44}
45
46#else /* CONFIG_NO_STDOUT_DEBUG */
47
48int wpa_debug_open_file(const char *path);
49int wpa_debug_reopen_file(void);
50void wpa_debug_close_file(void);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080051void wpa_debug_setup_stdout(void);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000052void wpa_debug_stop_log(void);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54/**
55 * wpa_debug_printf_timestamp - Print timestamp for debug output
56 *
57 * This function prints a timestamp in seconds_from_1970.microsoconds
58 * format if debug output has been configured to include timestamps in debug
59 * messages.
60 */
61void wpa_debug_print_timestamp(void);
62
63/**
64 * wpa_printf - conditional printf
65 * @level: priority level (MSG_*) of the message
66 * @fmt: printf format string, followed by optional arguments
67 *
68 * This function is used to print conditional debugging and error messages. The
69 * output may be directed to stdout, stderr, and/or syslog based on
70 * configuration.
71 *
72 * Note: New line '\n' is added to the end of the text when printing to stdout.
73 */
74void wpa_printf(int level, const char *fmt, ...)
75PRINTF_FORMAT(2, 3);
76
77/**
78 * wpa_hexdump - conditional hex dump
79 * @level: priority level (MSG_*) of the message
80 * @title: title of for the message
81 * @buf: data buffer to be dumped
82 * @len: length of the buf
83 *
84 * This function is used to print conditional debugging and error messages. The
85 * output may be directed to stdout, stderr, and/or syslog based on
86 * configuration. The contents of buf is printed out has hex dump.
87 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080088void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089
90static inline void wpa_hexdump_buf(int level, const char *title,
91 const struct wpabuf *buf)
92{
93 wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
94 buf ? wpabuf_len(buf) : 0);
95}
96
97/**
98 * wpa_hexdump_key - conditional hex dump, hide keys
99 * @level: priority level (MSG_*) of the message
100 * @title: title of for the message
101 * @buf: data buffer to be dumped
102 * @len: length of the buf
103 *
104 * This function is used to print conditional debugging and error messages. The
105 * output may be directed to stdout, stderr, and/or syslog based on
106 * configuration. The contents of buf is printed out has hex dump. This works
107 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
108 * etc.) in debug output.
109 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800110void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111
112static inline void wpa_hexdump_buf_key(int level, const char *title,
113 const struct wpabuf *buf)
114{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800115 wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700116 buf ? wpabuf_len(buf) : 0);
117}
118
119/**
120 * wpa_hexdump_ascii - conditional hex dump
121 * @level: priority level (MSG_*) of the message
122 * @title: title of for the message
123 * @buf: data buffer to be dumped
124 * @len: length of the buf
125 *
126 * This function is used to print conditional debugging and error messages. The
127 * output may be directed to stdout, stderr, and/or syslog based on
128 * configuration. The contents of buf is printed out has hex dump with both
129 * the hex numbers and ASCII characters (for printable range) are shown. 16
130 * bytes per line will be shown.
131 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800132void wpa_hexdump_ascii(int level, const char *title, const void *buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133 size_t len);
134
135/**
136 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
137 * @level: priority level (MSG_*) of the message
138 * @title: title of for the message
139 * @buf: data buffer to be dumped
140 * @len: length of the buf
141 *
142 * This function is used to print conditional debugging and error messages. The
143 * output may be directed to stdout, stderr, and/or syslog based on
144 * configuration. The contents of buf is printed out has hex dump with both
145 * the hex numbers and ASCII characters (for printable range) are shown. 16
146 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
147 * default, does not include secret keys (passwords, etc.) in debug output.
148 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800149void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150 size_t len);
151
152/*
153 * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
154 * binary size. As such, it should be used with debugging messages that are not
155 * needed in the control interface while wpa_msg() has to be used for anything
156 * that needs to shown to control interface monitors.
157 */
158#define wpa_dbg(args...) wpa_msg(args)
159
160#endif /* CONFIG_NO_STDOUT_DEBUG */
161
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162
163#ifdef CONFIG_NO_WPA_MSG
164#define wpa_msg(args...) do { } while (0)
165#define wpa_msg_ctrl(args...) do { } while (0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700166#define wpa_msg_global(args...) do { } while (0)
Dmitry Shmidt7f0b69e2014-07-28 10:35:20 -0700167#define wpa_msg_global_ctrl(args...) do { } while (0)
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700168#define wpa_msg_no_global(args...) do { } while (0)
Anton Nayshtutf715e8d2014-11-16 16:52:49 +0200169#define wpa_msg_global_only(args...) do { } while (0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170#define wpa_msg_register_cb(f) do { } while (0)
Hu Wang7c5a4322021-06-24 17:24:59 +0800171#define wpa_msg_register_aidl_cb(f) do { } while (0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172#define wpa_msg_register_ifname_cb(f) do { } while (0)
173#else /* CONFIG_NO_WPA_MSG */
174/**
175 * wpa_msg - Conditional printf for default target and ctrl_iface monitors
176 * @ctx: Pointer to context data; this is the ctx variable registered
177 * with struct wpa_driver_ops::init()
178 * @level: priority level (MSG_*) of the message
179 * @fmt: printf format string, followed by optional arguments
180 *
181 * This function is used to print conditional debugging and error messages. The
182 * output may be directed to stdout, stderr, and/or syslog based on
183 * configuration. This function is like wpa_printf(), but it also sends the
184 * same message to all attached ctrl_iface monitors.
185 *
186 * Note: New line '\n' is added to the end of the text when printing to stdout.
187 */
188void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
189
190/**
191 * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
192 * @ctx: Pointer to context data; this is the ctx variable registered
193 * with struct wpa_driver_ops::init()
194 * @level: priority level (MSG_*) of the message
195 * @fmt: printf format string, followed by optional arguments
196 *
197 * This function is used to print conditional debugging and error messages.
198 * This function is like wpa_msg(), but it sends the output only to the
199 * attached ctrl_iface monitors. In other words, it can be used for frequent
200 * events that do not need to be sent to syslog.
201 */
202void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
203PRINTF_FORMAT(3, 4);
204
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700205/**
206 * wpa_msg_global - Global printf for ctrl_iface monitors
207 * @ctx: Pointer to context data; this is the ctx variable registered
208 * with struct wpa_driver_ops::init()
209 * @level: priority level (MSG_*) of the message
210 * @fmt: printf format string, followed by optional arguments
211 *
212 * This function is used to print conditional debugging and error messages.
213 * This function is like wpa_msg(), but it sends the output as a global event,
214 * i.e., without being specific to an interface. For backwards compatibility,
215 * an old style event is also delivered on one of the interfaces (the one
216 * specified by the context data).
217 */
218void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
219PRINTF_FORMAT(3, 4);
220
221/**
Dmitry Shmidt7f0b69e2014-07-28 10:35:20 -0700222 * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
223 * @ctx: Pointer to context data; this is the ctx variable registered
224 * with struct wpa_driver_ops::init()
225 * @level: priority level (MSG_*) of the message
226 * @fmt: printf format string, followed by optional arguments
227 *
228 * This function is used to print conditional debugging and error messages.
229 * This function is like wpa_msg_global(), but it sends the output only to the
230 * attached global ctrl_iface monitors. In other words, it can be used for
231 * frequent events that do not need to be sent to syslog.
232 */
233void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
234PRINTF_FORMAT(3, 4);
235
236/**
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700237 * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
238 * @ctx: Pointer to context data; this is the ctx variable registered
239 * with struct wpa_driver_ops::init()
240 * @level: priority level (MSG_*) of the message
241 * @fmt: printf format string, followed by optional arguments
242 *
243 * This function is used to print conditional debugging and error messages.
244 * This function is like wpa_msg(), but it does not send the output as a global
245 * event.
246 */
247void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
248PRINTF_FORMAT(3, 4);
249
Anton Nayshtutf715e8d2014-11-16 16:52:49 +0200250/**
251 * wpa_msg_global_only - Conditional printf for ctrl_iface monitors
252 * @ctx: Pointer to context data; this is the ctx variable registered
253 * with struct wpa_driver_ops::init()
254 * @level: priority level (MSG_*) of the message
255 * @fmt: printf format string, followed by optional arguments
256 *
257 * This function is used to print conditional debugging and error messages.
258 * This function is like wpa_msg_global(), but it sends the output only as a
259 * global event.
260 */
261void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
262PRINTF_FORMAT(3, 4);
263
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700264enum wpa_msg_type {
265 WPA_MSG_PER_INTERFACE,
266 WPA_MSG_GLOBAL,
267 WPA_MSG_NO_GLOBAL,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +0200268 WPA_MSG_ONLY_GLOBAL,
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700269};
270
271typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700272 const char *txt, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273
274/**
275 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
276 * @func: Callback function (%NULL to unregister)
277 */
278void wpa_msg_register_cb(wpa_msg_cb_func func);
Hu Wang7c5a4322021-06-24 17:24:59 +0800279void wpa_msg_register_aidl_cb(wpa_msg_cb_func func);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
281void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
282
283#endif /* CONFIG_NO_WPA_MSG */
284
285#ifdef CONFIG_NO_HOSTAPD_LOGGER
286#define hostapd_logger(args...) do { } while (0)
287#define hostapd_logger_register_cb(f) do { } while (0)
288#else /* CONFIG_NO_HOSTAPD_LOGGER */
289void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
290 const char *fmt, ...) PRINTF_FORMAT(5, 6);
291
292typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
293 unsigned int module, int level,
294 const char *txt, size_t len);
295
296/**
297 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
298 * @func: Callback function (%NULL to unregister)
299 */
300void hostapd_logger_register_cb(hostapd_logger_cb_func func);
301#endif /* CONFIG_NO_HOSTAPD_LOGGER */
302
303#define HOSTAPD_MODULE_IEEE80211 0x00000001
304#define HOSTAPD_MODULE_IEEE8021X 0x00000002
305#define HOSTAPD_MODULE_RADIUS 0x00000004
306#define HOSTAPD_MODULE_WPA 0x00000008
307#define HOSTAPD_MODULE_DRIVER 0x00000010
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308#define HOSTAPD_MODULE_MLME 0x00000040
309
310enum hostapd_logger_level {
311 HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
312 HOSTAPD_LEVEL_DEBUG = 1,
313 HOSTAPD_LEVEL_INFO = 2,
314 HOSTAPD_LEVEL_NOTICE = 3,
315 HOSTAPD_LEVEL_WARNING = 4
316};
317
318
319#ifdef CONFIG_DEBUG_SYSLOG
320
321void wpa_debug_open_syslog(void);
322void wpa_debug_close_syslog(void);
323
324#else /* CONFIG_DEBUG_SYSLOG */
325
326static inline void wpa_debug_open_syslog(void)
327{
328}
329
330static inline void wpa_debug_close_syslog(void)
331{
332}
333
334#endif /* CONFIG_DEBUG_SYSLOG */
335
Dmitry Shmidt04949592012-07-19 12:16:46 -0700336#ifdef CONFIG_DEBUG_LINUX_TRACING
337
338int wpa_debug_open_linux_tracing(void);
339void wpa_debug_close_linux_tracing(void);
340
341#else /* CONFIG_DEBUG_LINUX_TRACING */
342
343static inline int wpa_debug_open_linux_tracing(void)
344{
345 return 0;
346}
347
348static inline void wpa_debug_close_linux_tracing(void)
349{
350}
351
352#endif /* CONFIG_DEBUG_LINUX_TRACING */
353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354
355#ifdef EAPOL_TEST
356#define WPA_ASSERT(a) \
357 do { \
358 if (!(a)) { \
359 printf("WPA_ASSERT FAILED '" #a "' " \
360 "%s %s:%d\n", \
361 __FUNCTION__, __FILE__, __LINE__); \
362 exit(1); \
363 } \
364 } while (0)
365#else
366#define WPA_ASSERT(a) do { } while (0)
367#endif
368
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800369const char * debug_level_str(int level);
370int str_to_debug_level(const char *s);
371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372#endif /* WPA_DEBUG_H */