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