• 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 #ifdef CONFIG_DEBUG_SYSLOG
18 extern int wpa_debug_syslog;
19 #endif /* CONFIG_DEBUG_SYSLOG */
20 
21 /* Debugging function - conditional printf and hex dump. Driver wrappers can
22  * use these for debugging purposes. */
23 
24 enum {
25 	MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
26 };
27 
28 #ifdef CONFIG_NO_STDOUT_DEBUG
29 
30 #define wpa_debug_print_timestamp() do { } while (0)
31 #define wpa_printf(args...) do { } while (0)
32 #define wpa_hexdump(l,t,b,le) do { } while (0)
33 #define wpa_hexdump_buf(l,t,b) do { } while (0)
34 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
35 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
36 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
37 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
38 #define wpa_debug_open_file(p) do { } while (0)
39 #define wpa_debug_close_file() do { } while (0)
40 #define wpa_debug_setup_stdout() do { } while (0)
41 #define wpa_dbg(args...) do { } while (0)
42 
wpa_debug_reopen_file(void)43 static inline int wpa_debug_reopen_file(void)
44 {
45 	return 0;
46 }
47 
48 #else /* CONFIG_NO_STDOUT_DEBUG */
49 
50 int wpa_debug_open_file(const char *path);
51 int wpa_debug_reopen_file(void);
52 void wpa_debug_close_file(void);
53 void wpa_debug_setup_stdout(void);
54 
55 /**
56  * wpa_debug_printf_timestamp - Print timestamp for debug output
57  *
58  * This function prints a timestamp in seconds_from_1970.microsoconds
59  * format if debug output has been configured to include timestamps in debug
60  * messages.
61  */
62 void wpa_debug_print_timestamp(void);
63 
64 /**
65  * wpa_printf - conditional printf
66  * @level: priority level (MSG_*) of the message
67  * @fmt: printf format string, followed by optional arguments
68  *
69  * This function is used to print conditional debugging and error messages. The
70  * output may be directed to stdout, stderr, and/or syslog based on
71  * configuration.
72  *
73  * Note: New line '\n' is added to the end of the text when printing to stdout.
74  */
75 void wpa_printf(int level, const char *fmt, ...)
76 PRINTF_FORMAT(2, 3);
77 
78 /**
79  * wpa_hexdump - conditional hex dump
80  * @level: priority level (MSG_*) of the message
81  * @title: title of for the message
82  * @buf: data buffer to be dumped
83  * @len: length of the buf
84  *
85  * This function is used to print conditional debugging and error messages. The
86  * output may be directed to stdout, stderr, and/or syslog based on
87  * configuration. The contents of buf is printed out has hex dump.
88  */
89 void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
90 
wpa_hexdump_buf(int level,const char * title,const struct wpabuf * buf)91 static inline void wpa_hexdump_buf(int level, const char *title,
92 				   const struct wpabuf *buf)
93 {
94 	wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
95 		    buf ? wpabuf_len(buf) : 0);
96 }
97 
98 /**
99  * wpa_hexdump_key - conditional hex dump, hide keys
100  * @level: priority level (MSG_*) of the message
101  * @title: title of for the message
102  * @buf: data buffer to be dumped
103  * @len: length of the buf
104  *
105  * This function is used to print conditional debugging and error messages. The
106  * output may be directed to stdout, stderr, and/or syslog based on
107  * configuration. The contents of buf is printed out has hex dump. This works
108  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
109  * etc.) in debug output.
110  */
111 void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
112 
wpa_hexdump_buf_key(int level,const char * title,const struct wpabuf * buf)113 static inline void wpa_hexdump_buf_key(int level, const char *title,
114 				       const struct wpabuf *buf)
115 {
116 	wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
117 			buf ? wpabuf_len(buf) : 0);
118 }
119 
120 /**
121  * wpa_hexdump_ascii - conditional hex dump
122  * @level: priority level (MSG_*) of the message
123  * @title: title of for the message
124  * @buf: data buffer to be dumped
125  * @len: length of the buf
126  *
127  * This function is used to print conditional debugging and error messages. The
128  * output may be directed to stdout, stderr, and/or syslog based on
129  * configuration. The contents of buf is printed out has hex dump with both
130  * the hex numbers and ASCII characters (for printable range) are shown. 16
131  * bytes per line will be shown.
132  */
133 void wpa_hexdump_ascii(int level, const char *title, const void *buf,
134 		       size_t len);
135 
136 /**
137  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
138  * @level: priority level (MSG_*) of the message
139  * @title: title of for the message
140  * @buf: data buffer to be dumped
141  * @len: length of the buf
142  *
143  * This function is used to print conditional debugging and error messages. The
144  * output may be directed to stdout, stderr, and/or syslog based on
145  * configuration. The contents of buf is printed out has hex dump with both
146  * the hex numbers and ASCII characters (for printable range) are shown. 16
147  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
148  * default, does not include secret keys (passwords, etc.) in debug output.
149  */
150 void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
151 			   size_t len);
152 
153 /*
154  * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
155  * binary size. As such, it should be used with debugging messages that are not
156  * needed in the control interface while wpa_msg() has to be used for anything
157  * that needs to shown to control interface monitors.
158  */
159 #define wpa_dbg(args...) wpa_msg(args)
160 
161 #endif /* CONFIG_NO_STDOUT_DEBUG */
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 /**
190  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
191  * @ctx: Pointer to context data; this is the ctx variable registered
192  *	with struct wpa_driver_ops::init()
193  * @level: priority level (MSG_*) of the message
194  * @fmt: printf format string, followed by optional arguments
195  *
196  * This function is used to print conditional debugging and error messages.
197  * This function is like wpa_msg(), but it sends the output only to the
198  * attached ctrl_iface monitors. In other words, it can be used for frequent
199  * events that do not need to be sent to syslog.
200  */
201 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
202 PRINTF_FORMAT(3, 4);
203 
204 /**
205  * wpa_msg_global - Global printf for ctrl_iface monitors
206  * @ctx: Pointer to context data; this is the ctx variable registered
207  *	with struct wpa_driver_ops::init()
208  * @level: priority level (MSG_*) of the message
209  * @fmt: printf format string, followed by optional arguments
210  *
211  * This function is used to print conditional debugging and error messages.
212  * This function is like wpa_msg(), but it sends the output as a global event,
213  * i.e., without being specific to an interface. For backwards compatibility,
214  * an old style event is also delivered on one of the interfaces (the one
215  * specified by the context data).
216  */
217 void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
218 PRINTF_FORMAT(3, 4);
219 
220 /**
221  * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
222  * @ctx: Pointer to context data; this is the ctx variable registered
223  *	with struct wpa_driver_ops::init()
224  * @level: priority level (MSG_*) of the message
225  * @fmt: printf format string, followed by optional arguments
226  *
227  * This function is used to print conditional debugging and error messages.
228  * This function is like wpa_msg_global(), but it sends the output only to the
229  * attached global ctrl_iface monitors. In other words, it can be used for
230  * frequent events that do not need to be sent to syslog.
231  */
232 void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
233 PRINTF_FORMAT(3, 4);
234 
235 /**
236  * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
237  * @ctx: Pointer to context data; this is the ctx variable registered
238  *	with struct wpa_driver_ops::init()
239  * @level: priority level (MSG_*) of the message
240  * @fmt: printf format string, followed by optional arguments
241  *
242  * This function is used to print conditional debugging and error messages.
243  * This function is like wpa_msg(), but it does not send the output as a global
244  * event.
245  */
246 void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
247 PRINTF_FORMAT(3, 4);
248 
249 /**
250  * wpa_msg_global_only - Conditional printf for ctrl_iface monitors
251  * @ctx: Pointer to context data; this is the ctx variable registered
252  *	with struct wpa_driver_ops::init()
253  * @level: priority level (MSG_*) of the message
254  * @fmt: printf format string, followed by optional arguments
255  *
256  * This function is used to print conditional debugging and error messages.
257  * This function is like wpa_msg_global(), but it sends the output only as a
258  * global event.
259  */
260 void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
261 PRINTF_FORMAT(3, 4);
262 
263 enum wpa_msg_type {
264 	WPA_MSG_PER_INTERFACE,
265 	WPA_MSG_GLOBAL,
266 	WPA_MSG_NO_GLOBAL,
267 	WPA_MSG_ONLY_GLOBAL,
268 };
269 
270 typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
271 				const char *txt, size_t len);
272 
273 /**
274  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
275  * @func: Callback function (%NULL to unregister)
276  */
277 void wpa_msg_register_cb(wpa_msg_cb_func func);
278 
279 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
280 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
281 
282 #endif /* CONFIG_NO_WPA_MSG */
283 
284 #ifdef CONFIG_NO_HOSTAPD_LOGGER
285 #define hostapd_logger(args...) do { } while (0)
286 #define hostapd_logger_register_cb(f) do { } while (0)
287 #else /* CONFIG_NO_HOSTAPD_LOGGER */
288 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
289 		    const char *fmt, ...) PRINTF_FORMAT(5, 6);
290 
291 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
292 				       unsigned int module, int level,
293 				       const char *txt, size_t len);
294 
295 /**
296  * hostapd_logger_register_cb - Register callback function for hostapd_logger()
297  * @func: Callback function (%NULL to unregister)
298  */
299 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
300 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
301 
302 #define HOSTAPD_MODULE_IEEE80211	0x00000001
303 #define HOSTAPD_MODULE_IEEE8021X	0x00000002
304 #define HOSTAPD_MODULE_RADIUS		0x00000004
305 #define HOSTAPD_MODULE_WPA		0x00000008
306 #define HOSTAPD_MODULE_DRIVER		0x00000010
307 #define HOSTAPD_MODULE_IAPP		0x00000020
308 #define HOSTAPD_MODULE_MLME		0x00000040
309 
310 enum 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 
321 void wpa_debug_open_syslog(void);
322 void wpa_debug_close_syslog(void);
323 
324 #else /* CONFIG_DEBUG_SYSLOG */
325 
wpa_debug_open_syslog(void)326 static inline void wpa_debug_open_syslog(void)
327 {
328 }
329 
wpa_debug_close_syslog(void)330 static inline void wpa_debug_close_syslog(void)
331 {
332 }
333 
334 #endif /* CONFIG_DEBUG_SYSLOG */
335 
336 #ifdef CONFIG_DEBUG_LINUX_TRACING
337 
338 int wpa_debug_open_linux_tracing(void);
339 void wpa_debug_close_linux_tracing(void);
340 
341 #else /* CONFIG_DEBUG_LINUX_TRACING */
342 
wpa_debug_open_linux_tracing(void)343 static inline int wpa_debug_open_linux_tracing(void)
344 {
345 	return 0;
346 }
347 
wpa_debug_close_linux_tracing(void)348 static inline void wpa_debug_close_linux_tracing(void)
349 {
350 }
351 
352 #endif /* CONFIG_DEBUG_LINUX_TRACING */
353 
354 
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 
369 const char * debug_level_str(int level);
370 int str_to_debug_level(const char *s);
371 
372 #endif /* WPA_DEBUG_H */
373