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.
14 extern int wpa_debug_level;
15 extern int wpa_debug_show_keys;
16 extern int wpa_debug_timestamp;
18 /* Debugging function - conditional printf and hex dump. Driver wrappers can
19 * use these for debugging purposes. */
22 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
25 #ifdef CONFIG_NO_STDOUT_DEBUG
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 #define wpa_dbg(args...) do { } while (0)
39 static inline int wpa_debug_reopen_file(void)
44 #else /* CONFIG_NO_STDOUT_DEBUG */
46 int wpa_debug_open_file(const char *path);
47 int wpa_debug_reopen_file(void);
48 void wpa_debug_close_file(void);
51 * wpa_debug_printf_timestamp - Print timestamp for debug output
53 * This function prints a timestamp in seconds_from_1970.microsoconds
54 * format if debug output has been configured to include timestamps in debug
57 void wpa_debug_print_timestamp(void);
60 * wpa_printf - conditional printf
61 * @level: priority level (MSG_*) of the message
62 * @fmt: printf format string, followed by optional arguments
64 * This function is used to print conditional debugging and error messages. The
65 * output may be directed to stdout, stderr, and/or syslog based on
68 * Note: New line '\n' is added to the end of the text when printing to stdout.
70 void wpa_printf(int level, const char *fmt, ...)
74 * wpa_hexdump - conditional hex dump
75 * @level: priority level (MSG_*) of the message
76 * @title: title of for the message
77 * @buf: data buffer to be dumped
78 * @len: length of the buf
80 * This function is used to print conditional debugging and error messages. The
81 * output may be directed to stdout, stderr, and/or syslog based on
82 * configuration. The contents of buf is printed out has hex dump.
84 void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
86 static inline void wpa_hexdump_buf(int level, const char *title,
87 const struct wpabuf *buf)
89 wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
90 buf ? wpabuf_len(buf) : 0);
94 * wpa_hexdump_key - conditional hex dump, hide keys
95 * @level: priority level (MSG_*) of the message
96 * @title: title of for the message
97 * @buf: data buffer to be dumped
98 * @len: length of the buf
100 * This function is used to print conditional debugging and error messages. The
101 * output may be directed to stdout, stderr, and/or syslog based on
102 * configuration. The contents of buf is printed out has hex dump. This works
103 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
104 * etc.) in debug output.
106 void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
108 static inline void wpa_hexdump_buf_key(int level, const char *title,
109 const struct wpabuf *buf)
111 wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
112 buf ? wpabuf_len(buf) : 0);
116 * wpa_hexdump_ascii - conditional hex dump
117 * @level: priority level (MSG_*) of the message
118 * @title: title of for the message
119 * @buf: data buffer to be dumped
120 * @len: length of the buf
122 * This function is used to print conditional debugging and error messages. The
123 * output may be directed to stdout, stderr, and/or syslog based on
124 * configuration. The contents of buf is printed out has hex dump with both
125 * the hex numbers and ASCII characters (for printable range) are shown. 16
126 * bytes per line will be shown.
128 void wpa_hexdump_ascii(int level, const char *title, const void *buf,
132 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
133 * @level: priority level (MSG_*) of the message
134 * @title: title of for the message
135 * @buf: data buffer to be dumped
136 * @len: length of the buf
138 * This function is used to print conditional debugging and error messages. The
139 * output may be directed to stdout, stderr, and/or syslog based on
140 * configuration. The contents of buf is printed out has hex dump with both
141 * the hex numbers and ASCII characters (for printable range) are shown. 16
142 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
143 * default, does not include secret keys (passwords, etc.) in debug output.
145 void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
149 * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
150 * binary size. As such, it should be used with debugging messages that are not
151 * needed in the control interface while wpa_msg() has to be used for anything
152 * that needs to shown to control interface monitors.
154 #define wpa_dbg(args...) wpa_msg(args)
156 #endif /* CONFIG_NO_STDOUT_DEBUG */
159 #ifdef CONFIG_NO_WPA_MSG
160 #define wpa_msg(args...) do { } while (0)
161 #define wpa_msg_ctrl(args...) do { } while (0)
162 #define wpa_msg_global(args...) do { } while (0)
163 #define wpa_msg_global_ctrl(args...) do { } while (0)
164 #define wpa_msg_no_global(args...) do { } while (0)
165 #define wpa_msg_register_cb(f) do { } while (0)
166 #define wpa_msg_register_ifname_cb(f) do { } while (0)
167 #else /* CONFIG_NO_WPA_MSG */
169 * wpa_msg - Conditional printf for default target and ctrl_iface monitors
170 * @ctx: Pointer to context data; this is the ctx variable registered
171 * with struct wpa_driver_ops::init()
172 * @level: priority level (MSG_*) of the message
173 * @fmt: printf format string, followed by optional arguments
175 * This function is used to print conditional debugging and error messages. The
176 * output may be directed to stdout, stderr, and/or syslog based on
177 * configuration. This function is like wpa_printf(), but it also sends the
178 * same message to all attached ctrl_iface monitors.
180 * Note: New line '\n' is added to the end of the text when printing to stdout.
182 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
185 * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
186 * @ctx: Pointer to context data; this is the ctx variable registered
187 * with struct wpa_driver_ops::init()
188 * @level: priority level (MSG_*) of the message
189 * @fmt: printf format string, followed by optional arguments
191 * This function is used to print conditional debugging and error messages.
192 * This function is like wpa_msg(), but it sends the output only to the
193 * attached ctrl_iface monitors. In other words, it can be used for frequent
194 * events that do not need to be sent to syslog.
196 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
200 * wpa_msg_global - Global printf for ctrl_iface monitors
201 * @ctx: Pointer to context data; this is the ctx variable registered
202 * with struct wpa_driver_ops::init()
203 * @level: priority level (MSG_*) of the message
204 * @fmt: printf format string, followed by optional arguments
206 * This function is used to print conditional debugging and error messages.
207 * This function is like wpa_msg(), but it sends the output as a global event,
208 * i.e., without being specific to an interface. For backwards compatibility,
209 * an old style event is also delivered on one of the interfaces (the one
210 * specified by the context data).
212 void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
216 * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
217 * @ctx: Pointer to context data; this is the ctx variable registered
218 * with struct wpa_driver_ops::init()
219 * @level: priority level (MSG_*) of the message
220 * @fmt: printf format string, followed by optional arguments
222 * This function is used to print conditional debugging and error messages.
223 * This function is like wpa_msg_global(), but it sends the output only to the
224 * attached global ctrl_iface monitors. In other words, it can be used for
225 * frequent events that do not need to be sent to syslog.
227 void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
231 * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
232 * @ctx: Pointer to context data; this is the ctx variable registered
233 * with struct wpa_driver_ops::init()
234 * @level: priority level (MSG_*) of the message
235 * @fmt: printf format string, followed by optional arguments
237 * This function is used to print conditional debugging and error messages.
238 * This function is like wpa_msg(), but it does not send the output as a global
241 void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
244 typedef void (*wpa_msg_cb_func)(void *ctx, int level, int global,
245 const char *txt, size_t len);
248 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
249 * @func: Callback function (%NULL to unregister)
251 void wpa_msg_register_cb(wpa_msg_cb_func func);
253 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
254 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
256 #endif /* CONFIG_NO_WPA_MSG */
258 #ifdef CONFIG_NO_HOSTAPD_LOGGER
259 #define hostapd_logger(args...) do { } while (0)
260 #define hostapd_logger_register_cb(f) do { } while (0)
261 #else /* CONFIG_NO_HOSTAPD_LOGGER */
262 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
263 const char *fmt, ...) PRINTF_FORMAT(5, 6);
265 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
266 unsigned int module, int level,
267 const char *txt, size_t len);
270 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
271 * @func: Callback function (%NULL to unregister)
273 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
274 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
276 #define HOSTAPD_MODULE_IEEE80211 0x00000001
277 #define HOSTAPD_MODULE_IEEE8021X 0x00000002
278 #define HOSTAPD_MODULE_RADIUS 0x00000004
279 #define HOSTAPD_MODULE_WPA 0x00000008
280 #define HOSTAPD_MODULE_DRIVER 0x00000010
281 #define HOSTAPD_MODULE_IAPP 0x00000020
282 #define HOSTAPD_MODULE_MLME 0x00000040
284 enum hostapd_logger_level {
285 HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
286 HOSTAPD_LEVEL_DEBUG = 1,
287 HOSTAPD_LEVEL_INFO = 2,
288 HOSTAPD_LEVEL_NOTICE = 3,
289 HOSTAPD_LEVEL_WARNING = 4
293 #ifdef CONFIG_DEBUG_SYSLOG
295 void wpa_debug_open_syslog(void);
296 void wpa_debug_close_syslog(void);
298 #else /* CONFIG_DEBUG_SYSLOG */
300 static inline void wpa_debug_open_syslog(void)
304 static inline void wpa_debug_close_syslog(void)
308 #endif /* CONFIG_DEBUG_SYSLOG */
310 #ifdef CONFIG_DEBUG_LINUX_TRACING
312 int wpa_debug_open_linux_tracing(void);
313 void wpa_debug_close_linux_tracing(void);
315 #else /* CONFIG_DEBUG_LINUX_TRACING */
317 static inline int wpa_debug_open_linux_tracing(void)
322 static inline void wpa_debug_close_linux_tracing(void)
326 #endif /* CONFIG_DEBUG_LINUX_TRACING */
330 #define WPA_ASSERT(a) \
333 printf("WPA_ASSERT FAILED '" #a "' " \
335 __FUNCTION__, __FILE__, __LINE__); \
340 #define WPA_ASSERT(a) do { } while (0)
343 #endif /* WPA_DEBUG_H */