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