2 * wpa_supplicant/hostapd / Debug prints
3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
18 extern int wpa_debug_level;
19 extern int wpa_debug_show_keys;
20 extern int wpa_debug_timestamp;
23 /* Debugging function - conditional printf and hex dump. Driver wrappers can
24 * use these for debugging purposes. */
27 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
30 #ifdef CONFIG_NO_STDOUT_DEBUG
32 #define wpa_debug_print_timestamp() do { } while (0)
33 #define wpa_printf(args...) do { } while (0)
34 #define wpa_hexdump(l,t,b,le) do { } while (0)
35 #define wpa_hexdump_buf(l,t,b) do { } while (0)
36 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
37 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
38 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
39 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
40 #define wpa_debug_open_file(p) do { } while (0)
41 #define wpa_debug_close_file() do { } while (0)
42 #define wpa_debug_setup_stdout() do { } while (0)
43 #define wpa_dbg(args...) do { } while (0)
45 static inline int wpa_debug_reopen_file(void)
50 #else /* CONFIG_NO_STDOUT_DEBUG */
52 int wpa_debug_open_file(const char *path);
53 int wpa_debug_reopen_file(void);
54 void wpa_debug_close_file(void);
55 void wpa_debug_setup_stdout(void);
58 * wpa_debug_printf_timestamp - Print timestamp for debug output
60 * This function prints a timestamp in seconds_from_1970.microsoconds
61 * format if debug output has been configured to include timestamps in debug
64 void wpa_debug_print_timestamp(void);
67 * wpa_printf - conditional printf
68 * @level: priority level (MSG_*) of the message
69 * @fmt: printf format string, followed by optional arguments
71 * This function is used to print conditional debugging and error messages. The
72 * output may be directed to stdout, stderr, and/or syslog based on
75 * Note: New line '\n' is added to the end of the text when printing to stdout.
77 void wpa_printf(int level, const char *fmt, ...)
81 * wpa_hexdump - conditional hex dump
82 * @level: priority level (MSG_*) of the message
83 * @title: title of for the message
84 * @buf: data buffer to be dumped
85 * @len: length of the buf
87 * This function is used to print conditional debugging and error messages. The
88 * output may be directed to stdout, stderr, and/or syslog based on
89 * configuration. The contents of buf is printed out has hex dump.
91 void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
93 static inline void wpa_hexdump_buf(int level, const char *title,
94 const struct wpabuf *buf)
96 //!!LOCAL wpa_hexdump(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
98 wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
99 buf ? wpabuf_len(buf) : 0);
103 * wpa_hexdump_key - conditional hex dump, hide keys
104 * @level: priority level (MSG_*) of the message
105 * @title: title of for the message
106 * @buf: data buffer to be dumped
107 * @len: length of the buf
109 * This function is used to print conditional debugging and error messages. The
110 * output may be directed to stdout, stderr, and/or syslog based on
111 * configuration. The contents of buf is printed out has hex dump. This works
112 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
113 * etc.) in debug output.
115 void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
117 static inline void wpa_hexdump_buf_key(int level, const char *title,
118 const struct wpabuf *buf)
120 //!! LOCAL wpa_hexdump_key(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
122 wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
123 buf ? wpabuf_len(buf) : 0);
127 * wpa_hexdump_ascii - conditional hex dump
128 * @level: priority level (MSG_*) of the message
129 * @title: title of for the message
130 * @buf: data buffer to be dumped
131 * @len: length of the buf
133 * This function is used to print conditional debugging and error messages. The
134 * output may be directed to stdout, stderr, and/or syslog based on
135 * configuration. The contents of buf is printed out has hex dump with both
136 * the hex numbers and ASCII characters (for printable range) are shown. 16
137 * bytes per line will be shown.
139 void wpa_hexdump_ascii(int level, const char *title, const void *buf,
143 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
144 * @level: priority level (MSG_*) of the message
145 * @title: title of for the message
146 * @buf: data buffer to be dumped
147 * @len: length of the buf
149 * This function is used to print conditional debugging and error messages. The
150 * output may be directed to stdout, stderr, and/or syslog based on
151 * configuration. The contents of buf is printed out has hex dump with both
152 * the hex numbers and ASCII characters (for printable range) are shown. 16
153 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
154 * default, does not include secret keys (passwords, etc.) in debug output.
156 void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
160 * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
161 * binary size. As such, it should be used with debugging messages that are not
162 * needed in the control interface while wpa_msg() has to be used for anything
163 * that needs to shown to control interface monitors.
165 #define wpa_dbg(args...) wpa_msg(args)
167 #endif /* CONFIG_NO_STDOUT_DEBUG */
170 #ifdef CONFIG_NO_WPA_MSG
171 #define wpa_msg(args...) do { } while (0)
172 #define wpa_msg_ctrl(args...) do { } while (0)
173 #define wpa_msg_global(args...) do { } while (0)
174 #define wpa_msg_global_ctrl(args...) do { } while (0)
175 #define wpa_msg_no_global(args...) do { } while (0)
176 #define wpa_msg_global_only(args...) do { } while (0)
177 #define wpa_msg_register_cb(f) do { } while (0)
178 #define wpa_msg_register_ifname_cb(f) do { } while (0)
179 #else /* CONFIG_NO_WPA_MSG */
181 * wpa_msg - Conditional printf for default target and ctrl_iface monitors
182 * @ctx: Pointer to context data; this is the ctx variable registered
183 * with struct wpa_driver_ops::init()
184 * @level: priority level (MSG_*) of the message
185 * @fmt: printf format string, followed by optional arguments
187 * This function is used to print conditional debugging and error messages. The
188 * output may be directed to stdout, stderr, and/or syslog based on
189 * configuration. This function is like wpa_printf(), but it also sends the
190 * same message to all attached ctrl_iface monitors.
192 * Note: New line '\n' is added to the end of the text when printing to stdout.
194 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
197 * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
198 * @ctx: Pointer to context data; this is the ctx variable registered
199 * with struct wpa_driver_ops::init()
200 * @level: priority level (MSG_*) of the message
201 * @fmt: printf format string, followed by optional arguments
203 * This function is used to print conditional debugging and error messages.
204 * This function is like wpa_msg(), but it sends the output only to the
205 * attached ctrl_iface monitors. In other words, it can be used for frequent
206 * events that do not need to be sent to syslog.
208 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
212 * wpa_msg_global - Global printf for ctrl_iface monitors
213 * @ctx: Pointer to context data; this is the ctx variable registered
214 * with struct wpa_driver_ops::init()
215 * @level: priority level (MSG_*) of the message
216 * @fmt: printf format string, followed by optional arguments
218 * This function is used to print conditional debugging and error messages.
219 * This function is like wpa_msg(), but it sends the output as a global event,
220 * i.e., without being specific to an interface. For backwards compatibility,
221 * an old style event is also delivered on one of the interfaces (the one
222 * specified by the context data).
224 void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
228 * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
229 * @ctx: Pointer to context data; this is the ctx variable registered
230 * with struct wpa_driver_ops::init()
231 * @level: priority level (MSG_*) of the message
232 * @fmt: printf format string, followed by optional arguments
234 * This function is used to print conditional debugging and error messages.
235 * This function is like wpa_msg_global(), but it sends the output only to the
236 * attached global ctrl_iface monitors. In other words, it can be used for
237 * frequent events that do not need to be sent to syslog.
239 void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
243 * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
244 * @ctx: Pointer to context data; this is the ctx variable registered
245 * with struct wpa_driver_ops::init()
246 * @level: priority level (MSG_*) of the message
247 * @fmt: printf format string, followed by optional arguments
249 * This function is used to print conditional debugging and error messages.
250 * This function is like wpa_msg(), but it does not send the output as a global
253 void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
257 * wpa_msg_global_only - Conditional printf for ctrl_iface monitors
258 * @ctx: Pointer to context data; this is the ctx variable registered
259 * with struct wpa_driver_ops::init()
260 * @level: priority level (MSG_*) of the message
261 * @fmt: printf format string, followed by optional arguments
263 * This function is used to print conditional debugging and error messages.
264 * This function is like wpa_msg_global(), but it sends the output only as a
267 void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
271 WPA_MSG_PER_INTERFACE,
277 typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
278 const char *txt, size_t len);
281 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
282 * @func: Callback function (%NULL to unregister)
284 void wpa_msg_register_cb(wpa_msg_cb_func func);
286 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
287 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
289 #endif /* CONFIG_NO_WPA_MSG */
291 #ifdef CONFIG_NO_HOSTAPD_LOGGER
292 #define hostapd_logger(args...) do { } while (0)
293 #define hostapd_logger_register_cb(f) do { } while (0)
294 #else /* CONFIG_NO_HOSTAPD_LOGGER */
295 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
296 const char *fmt, ...) PRINTF_FORMAT(5, 6);
298 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
299 unsigned int module, int level,
300 const char *txt, size_t len);
303 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
304 * @func: Callback function (%NULL to unregister)
306 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
307 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
309 #define HOSTAPD_MODULE_IEEE80211 0x00000001
310 #define HOSTAPD_MODULE_IEEE8021X 0x00000002
311 #define HOSTAPD_MODULE_RADIUS 0x00000004
312 #define HOSTAPD_MODULE_WPA 0x00000008
313 #define HOSTAPD_MODULE_DRIVER 0x00000010
314 #define HOSTAPD_MODULE_IAPP 0x00000020
315 #define HOSTAPD_MODULE_MLME 0x00000040
317 enum hostapd_logger_level {
318 HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
319 HOSTAPD_LEVEL_DEBUG = 1,
320 HOSTAPD_LEVEL_INFO = 2,
321 HOSTAPD_LEVEL_NOTICE = 3,
322 HOSTAPD_LEVEL_WARNING = 4
326 #ifdef CONFIG_DEBUG_SYSLOG
328 void wpa_debug_open_syslog(void);
329 void wpa_debug_close_syslog(void);
331 #else /* CONFIG_DEBUG_SYSLOG */
333 static inline void wpa_debug_open_syslog(void)
337 static inline void wpa_debug_close_syslog(void)
341 #endif /* CONFIG_DEBUG_SYSLOG */
343 #ifdef CONFIG_DEBUG_LINUX_TRACING
345 int wpa_debug_open_linux_tracing(void);
346 void wpa_debug_close_linux_tracing(void);
348 #else /* CONFIG_DEBUG_LINUX_TRACING */
350 static inline int wpa_debug_open_linux_tracing(void)
355 static inline void wpa_debug_close_linux_tracing(void)
359 #endif /* CONFIG_DEBUG_LINUX_TRACING */
363 #define WPA_ASSERT(a) \
366 printf("WPA_ASSERT FAILED '" #a "' " \
368 __FUNCTION__, __FILE__, __LINE__); \
373 #define WPA_ASSERT(a) do { } while (0)
376 const char * debug_level_str(int level);
377 int str_to_debug_level(const char *s);
383 #endif /* WPA_DEBUG_H */