• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * wpa_supplicant/hostapd / Debug prints
3  * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef WPA_DEBUG_H
10 #define WPA_DEBUG_H
11 
12 #include "wpabuf.h"
13 
14 extern int wpa_debug_level;
15 extern int wpa_debug_show_keys;
16 extern int wpa_debug_timestamp;
17 extern int wpa_debug_syslog;
18 
19 /* Debugging function - conditional printf and hex dump. Driver wrappers can
20  * use these for debugging purposes. */
21 
22 enum {
23 	MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
24 };
25 
26 #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)
38 #define wpa_debug_setup_stdout() do { } while (0)
39 #define wpa_dbg(args...) do { } while (0)
40 
wpa_debug_reopen_file(void)41 static inline int wpa_debug_reopen_file(void)
42 {
43 	return 0;
44 }
45 
46 #else /* CONFIG_NO_STDOUT_DEBUG */
47 
48 int wpa_debug_open_file(const char *path);
49 int wpa_debug_reopen_file(void);
50 void wpa_debug_close_file(void);
51 void wpa_debug_setup_stdout(void);
52 void wpa_debug_stop_log(void);
53 
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  */
61 void 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  */
74 void wpa_printf(int level, const char *fmt, ...)
75 PRINTF_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  */
88 void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
89 
wpa_hexdump_buf(int level,const char * title,const struct wpabuf * buf)90 static 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  */
110 void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
111 
wpa_hexdump_buf_key(int level,const char * title,const struct wpabuf * buf)112 static inline void wpa_hexdump_buf_key(int level, const char *title,
113 				       const struct wpabuf *buf)
114 {
115 	wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
116 			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  */
132 void wpa_hexdump_ascii(int level, const char *title, const void *buf,
133 		       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  */
149 void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
150 			   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 
162 
163 #ifdef CONFIG_NO_WPA_MSG
164 #define wpa_msg(args...) do { } while (0)
165 #define wpa_msg_ctrl(args...) do { } while (0)
166 #define wpa_msg_global(args...) do { } while (0)
167 #define wpa_msg_global_ctrl(args...) do { } while (0)
168 #define wpa_msg_no_global(args...) do { } while (0)
169 #define wpa_msg_global_only(args...) do { } while (0)
170 #define wpa_msg_register_cb(f) do { } while (0)
171 #define wpa_msg_register_ifname_cb(f) do { } while (0)
172 #else /* CONFIG_NO_WPA_MSG */
173 /**
174  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
175  * @ctx: Pointer to context data; this is the ctx variable registered
176  *	with struct wpa_driver_ops::init()
177  * @level: priority level (MSG_*) of the message
178  * @fmt: printf format string, followed by optional arguments
179  *
180  * This function is used to print conditional debugging and error messages. The
181  * output may be directed to stdout, stderr, and/or syslog based on
182  * configuration. This function is like wpa_printf(), but it also sends the
183  * same message to all attached ctrl_iface monitors.
184  *
185  * Note: New line '\n' is added to the end of the text when printing to stdout.
186  */
187 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
188 
189 void wpa_msg_only_for_cb(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
190 
191 /**
192  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
193  * @ctx: Pointer to context data; this is the ctx variable registered
194  *	with struct wpa_driver_ops::init()
195  * @level: priority level (MSG_*) of the message
196  * @fmt: printf format string, followed by optional arguments
197  *
198  * This function is used to print conditional debugging and error messages.
199  * This function is like wpa_msg(), but it sends the output only to the
200  * attached ctrl_iface monitors. In other words, it can be used for frequent
201  * events that do not need to be sent to syslog.
202  */
203 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
204 PRINTF_FORMAT(3, 4);
205 
206 /**
207  * wpa_msg_global - Global printf for ctrl_iface monitors
208  * @ctx: Pointer to context data; this is the ctx variable registered
209  *	with struct wpa_driver_ops::init()
210  * @level: priority level (MSG_*) of the message
211  * @fmt: printf format string, followed by optional arguments
212  *
213  * This function is used to print conditional debugging and error messages.
214  * This function is like wpa_msg(), but it sends the output as a global event,
215  * i.e., without being specific to an interface. For backwards compatibility,
216  * an old style event is also delivered on one of the interfaces (the one
217  * specified by the context data).
218  */
219 void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
220 PRINTF_FORMAT(3, 4);
221 
222 /**
223  * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
224  * @ctx: Pointer to context data; this is the ctx variable registered
225  *	with struct wpa_driver_ops::init()
226  * @level: priority level (MSG_*) of the message
227  * @fmt: printf format string, followed by optional arguments
228  *
229  * This function is used to print conditional debugging and error messages.
230  * This function is like wpa_msg_global(), but it sends the output only to the
231  * attached global ctrl_iface monitors. In other words, it can be used for
232  * frequent events that do not need to be sent to syslog.
233  */
234 void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
235 PRINTF_FORMAT(3, 4);
236 
237 /**
238  * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
239  * @ctx: Pointer to context data; this is the ctx variable registered
240  *	with struct wpa_driver_ops::init()
241  * @level: priority level (MSG_*) of the message
242  * @fmt: printf format string, followed by optional arguments
243  *
244  * This function is used to print conditional debugging and error messages.
245  * This function is like wpa_msg(), but it does not send the output as a global
246  * event.
247  */
248 void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
249 PRINTF_FORMAT(3, 4);
250 
251 /**
252  * wpa_msg_global_only - Conditional printf for ctrl_iface monitors
253  * @ctx: Pointer to context data; this is the ctx variable registered
254  *	with struct wpa_driver_ops::init()
255  * @level: priority level (MSG_*) of the message
256  * @fmt: printf format string, followed by optional arguments
257  *
258  * This function is used to print conditional debugging and error messages.
259  * This function is like wpa_msg_global(), but it sends the output only as a
260  * global event.
261  */
262 void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
263 PRINTF_FORMAT(3, 4);
264 
265 const char *anonymize_ip(const char *str);
266 
267 const char *anonymize_ssid(const char *str);
268 
269 const char *anonymize_common(const char *str);
270 
271 const char *anonymize_token(const u8 num);
272 
273 const char *get_anonymized_result_setnetwork(const char *str);
274 
275 const char *get_anonymized_result_setnetwork_for_bssid(const char *str);
276 
277 int disable_anonymized_print();
278 
279 long get_realtime_microsecond();
280 
281 const char *get_anonymized_result_for_set(const char *str);
282 
283 enum wpa_msg_type {
284 	WPA_MSG_PER_INTERFACE,
285 	WPA_MSG_GLOBAL,
286 	WPA_MSG_NO_GLOBAL,
287 	WPA_MSG_ONLY_GLOBAL,
288 };
289 
290 typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
291 				const char *txt, size_t len);
292 
293 /**
294  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
295  * @func: Callback function (%NULL to unregister)
296  */
297 void wpa_msg_register_cb(wpa_msg_cb_func func);
298 
299 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
300 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
301 
302 #endif /* CONFIG_NO_WPA_MSG */
303 
304 #ifdef CONFIG_NO_HOSTAPD_LOGGER
305 #define hostapd_logger(args...) do { } while (0)
306 #define hostapd_logger_register_cb(f) do { } while (0)
307 #else /* CONFIG_NO_HOSTAPD_LOGGER */
308 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
309 		    const char *fmt, ...) PRINTF_FORMAT(5, 6);
310 void hostapd_logger_only_for_cb(void *ctx, const u8 *addr, unsigned int module, int level,
311 	const char *fmt, ...) PRINTF_FORMAT(5, 6);
312 
313 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
314 				       unsigned int module, int level,
315 				       const char *txt, size_t len);
316 
317 /**
318  * hostapd_logger_register_cb - Register callback function for hostapd_logger()
319  * @func: Callback function (%NULL to unregister)
320  */
321 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
322 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
323 
324 #define HOSTAPD_MODULE_IEEE80211	0x00000001
325 #define HOSTAPD_MODULE_IEEE8021X	0x00000002
326 #define HOSTAPD_MODULE_RADIUS		0x00000004
327 #define HOSTAPD_MODULE_WPA		0x00000008
328 #define HOSTAPD_MODULE_DRIVER		0x00000010
329 #define HOSTAPD_MODULE_MLME		0x00000040
330 
331 enum hostapd_logger_level {
332 	HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
333 	HOSTAPD_LEVEL_DEBUG = 1,
334 	HOSTAPD_LEVEL_INFO = 2,
335 	HOSTAPD_LEVEL_NOTICE = 3,
336 	HOSTAPD_LEVEL_WARNING = 4
337 };
338 
339 
340 #ifdef CONFIG_DEBUG_SYSLOG
341 
342 void wpa_debug_open_syslog(void);
343 void wpa_debug_close_syslog(void);
344 
345 #else /* CONFIG_DEBUG_SYSLOG */
346 
wpa_debug_open_syslog(void)347 static inline void wpa_debug_open_syslog(void)
348 {
349 }
350 
wpa_debug_close_syslog(void)351 static inline void wpa_debug_close_syslog(void)
352 {
353 }
354 
355 #endif /* CONFIG_DEBUG_SYSLOG */
356 
357 #ifdef CONFIG_DEBUG_LINUX_TRACING
358 
359 int wpa_debug_open_linux_tracing(void);
360 void wpa_debug_close_linux_tracing(void);
361 
362 #else /* CONFIG_DEBUG_LINUX_TRACING */
363 
wpa_debug_open_linux_tracing(void)364 static inline int wpa_debug_open_linux_tracing(void)
365 {
366 	return 0;
367 }
368 
wpa_debug_close_linux_tracing(void)369 static inline void wpa_debug_close_linux_tracing(void)
370 {
371 }
372 
373 #endif /* CONFIG_DEBUG_LINUX_TRACING */
374 
375 
376 #ifdef EAPOL_TEST
377 #define WPA_ASSERT(a)						       \
378 	do {							       \
379 		if (!(a)) {					       \
380 			printf("WPA_ASSERT FAILED '" #a "' "	       \
381 			       "%s %s:%d\n",			       \
382 			       __FUNCTION__, __FILE__, __LINE__);      \
383 			exit(1);				       \
384 		}						       \
385 	} while (0)
386 #else
387 #define WPA_ASSERT(a) do { } while (0)
388 #endif
389 
390 const char * debug_level_str(int level);
391 int str_to_debug_level(const char *s);
392 
393 #endif /* WPA_DEBUG_H */
394