• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * wpa_supplicant/hostapd / Debug prints
3  * Copyright (c) 2002-2007, 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 /* Debugging function - conditional printf and hex dump. Driver wrappers can
15  * use these for debugging purposes. */
16 
17 enum {
18 	MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
19 };
20 
21 #ifdef CONFIG_NO_STDOUT_DEBUG
22 
23 #define wpa_debug_print_timestamp() do { } while (0)
24 #define wpa_printf(args...) do { } while (0)
25 #define wpa_hexdump(l,t,b,le) do { } while (0)
26 #define wpa_hexdump_buf(l,t,b) do { } while (0)
27 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
28 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
29 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
30 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
31 #define wpa_debug_open_file(p) do { } while (0)
32 #define wpa_debug_close_file() do { } while (0)
33 #define wpa_dbg(args...) do { } while (0)
34 
wpa_debug_reopen_file(void)35 static inline int wpa_debug_reopen_file(void)
36 {
37 	return 0;
38 }
39 
40 #else /* CONFIG_NO_STDOUT_DEBUG */
41 
42 int wpa_debug_open_file(const char *path);
43 int wpa_debug_reopen_file(void);
44 void wpa_debug_close_file(void);
45 
46 /**
47  * wpa_debug_printf_timestamp - Print timestamp for debug output
48  *
49  * This function prints a timestamp in seconds_from_1970.microsoconds
50  * format if debug output has been configured to include timestamps in debug
51  * messages.
52  */
53 void wpa_debug_print_timestamp(void);
54 
55 /**
56  * wpa_printf - conditional printf
57  * @level: priority level (MSG_*) of the message
58  * @fmt: printf format string, followed by optional arguments
59  *
60  * This function is used to print conditional debugging and error messages. The
61  * output may be directed to stdout, stderr, and/or syslog based on
62  * configuration.
63  *
64  * Note: New line '\n' is added to the end of the text when printing to stdout.
65  */
66 void wpa_printf(int level, const char *fmt, ...)
67 PRINTF_FORMAT(2, 3);
68 
69 /**
70  * wpa_hexdump - conditional hex dump
71  * @level: priority level (MSG_*) of the message
72  * @title: title of for the message
73  * @buf: data buffer to be dumped
74  * @len: length of the buf
75  *
76  * This function is used to print conditional debugging and error messages. The
77  * output may be directed to stdout, stderr, and/or syslog based on
78  * configuration. The contents of buf is printed out has hex dump.
79  */
80 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
81 
wpa_hexdump_buf(int level,const char * title,const struct wpabuf * buf)82 static inline void wpa_hexdump_buf(int level, const char *title,
83 				   const struct wpabuf *buf)
84 {
85 	wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
86 		    buf ? wpabuf_len(buf) : 0);
87 }
88 
89 /**
90  * wpa_hexdump_key - conditional hex dump, hide keys
91  * @level: priority level (MSG_*) of the message
92  * @title: title of for the message
93  * @buf: data buffer to be dumped
94  * @len: length of the buf
95  *
96  * This function is used to print conditional debugging and error messages. The
97  * output may be directed to stdout, stderr, and/or syslog based on
98  * configuration. The contents of buf is printed out has hex dump. This works
99  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
100  * etc.) in debug output.
101  */
102 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
103 
wpa_hexdump_buf_key(int level,const char * title,const struct wpabuf * buf)104 static inline void wpa_hexdump_buf_key(int level, const char *title,
105 				       const struct wpabuf *buf)
106 {
107 	wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
108 			buf ? wpabuf_len(buf) : 0);
109 }
110 
111 /**
112  * wpa_hexdump_ascii - conditional hex dump
113  * @level: priority level (MSG_*) of the message
114  * @title: title of for the message
115  * @buf: data buffer to be dumped
116  * @len: length of the buf
117  *
118  * This function is used to print conditional debugging and error messages. The
119  * output may be directed to stdout, stderr, and/or syslog based on
120  * configuration. The contents of buf is printed out has hex dump with both
121  * the hex numbers and ASCII characters (for printable range) are shown. 16
122  * bytes per line will be shown.
123  */
124 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
125 		       size_t len);
126 
127 /**
128  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
129  * @level: priority level (MSG_*) of the message
130  * @title: title of for the message
131  * @buf: data buffer to be dumped
132  * @len: length of the buf
133  *
134  * This function is used to print conditional debugging and error messages. The
135  * output may be directed to stdout, stderr, and/or syslog based on
136  * configuration. The contents of buf is printed out has hex dump with both
137  * the hex numbers and ASCII characters (for printable range) are shown. 16
138  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
139  * default, does not include secret keys (passwords, etc.) in debug output.
140  */
141 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
142 			   size_t len);
143 
144 /*
145  * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
146  * binary size. As such, it should be used with debugging messages that are not
147  * needed in the control interface while wpa_msg() has to be used for anything
148  * that needs to shown to control interface monitors.
149  */
150 #define wpa_dbg(args...) wpa_msg(args)
151 
152 #endif /* CONFIG_NO_STDOUT_DEBUG */
153 
154 
155 #ifdef CONFIG_NO_WPA_MSG
156 #define wpa_msg(args...) do { } while (0)
157 #define wpa_msg_ctrl(args...) do { } while (0)
158 #define wpa_msg_register_cb(f) do { } while (0)
159 #define wpa_msg_register_ifname_cb(f) do { } while (0)
160 #else /* CONFIG_NO_WPA_MSG */
161 /**
162  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
163  * @ctx: Pointer to context data; this is the ctx variable registered
164  *	with struct wpa_driver_ops::init()
165  * @level: priority level (MSG_*) of the message
166  * @fmt: printf format string, followed by optional arguments
167  *
168  * This function is used to print conditional debugging and error messages. The
169  * output may be directed to stdout, stderr, and/or syslog based on
170  * configuration. This function is like wpa_printf(), but it also sends the
171  * same message to all attached ctrl_iface monitors.
172  *
173  * Note: New line '\n' is added to the end of the text when printing to stdout.
174  */
175 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
176 
177 /**
178  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
179  * @ctx: Pointer to context data; this is the ctx variable registered
180  *	with struct wpa_driver_ops::init()
181  * @level: priority level (MSG_*) of the message
182  * @fmt: printf format string, followed by optional arguments
183  *
184  * This function is used to print conditional debugging and error messages.
185  * This function is like wpa_msg(), but it sends the output only to the
186  * attached ctrl_iface monitors. In other words, it can be used for frequent
187  * events that do not need to be sent to syslog.
188  */
189 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
190 PRINTF_FORMAT(3, 4);
191 
192 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
193 				size_t len);
194 
195 /**
196  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
197  * @func: Callback function (%NULL to unregister)
198  */
199 void wpa_msg_register_cb(wpa_msg_cb_func func);
200 
201 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
202 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
203 
204 #endif /* CONFIG_NO_WPA_MSG */
205 
206 #ifdef CONFIG_NO_HOSTAPD_LOGGER
207 #define hostapd_logger(args...) do { } while (0)
208 #define hostapd_logger_register_cb(f) do { } while (0)
209 #else /* CONFIG_NO_HOSTAPD_LOGGER */
210 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
211 		    const char *fmt, ...) PRINTF_FORMAT(5, 6);
212 
213 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
214 				       unsigned int module, int level,
215 				       const char *txt, size_t len);
216 
217 /**
218  * hostapd_logger_register_cb - Register callback function for hostapd_logger()
219  * @func: Callback function (%NULL to unregister)
220  */
221 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
222 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
223 
224 #define HOSTAPD_MODULE_IEEE80211	0x00000001
225 #define HOSTAPD_MODULE_IEEE8021X	0x00000002
226 #define HOSTAPD_MODULE_RADIUS		0x00000004
227 #define HOSTAPD_MODULE_WPA		0x00000008
228 #define HOSTAPD_MODULE_DRIVER		0x00000010
229 #define HOSTAPD_MODULE_IAPP		0x00000020
230 #define HOSTAPD_MODULE_MLME		0x00000040
231 
232 enum hostapd_logger_level {
233 	HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
234 	HOSTAPD_LEVEL_DEBUG = 1,
235 	HOSTAPD_LEVEL_INFO = 2,
236 	HOSTAPD_LEVEL_NOTICE = 3,
237 	HOSTAPD_LEVEL_WARNING = 4
238 };
239 
240 
241 #ifdef CONFIG_DEBUG_SYSLOG
242 
243 void wpa_debug_open_syslog(void);
244 void wpa_debug_close_syslog(void);
245 
246 #else /* CONFIG_DEBUG_SYSLOG */
247 
wpa_debug_open_syslog(void)248 static inline void wpa_debug_open_syslog(void)
249 {
250 }
251 
wpa_debug_close_syslog(void)252 static inline void wpa_debug_close_syslog(void)
253 {
254 }
255 
256 #endif /* CONFIG_DEBUG_SYSLOG */
257 
258 #ifdef CONFIG_DEBUG_LINUX_TRACING
259 
260 int wpa_debug_open_linux_tracing(void);
261 void wpa_debug_close_linux_tracing(void);
262 
263 #else /* CONFIG_DEBUG_LINUX_TRACING */
264 
wpa_debug_open_linux_tracing(void)265 static inline int wpa_debug_open_linux_tracing(void)
266 {
267 	return 0;
268 }
269 
wpa_debug_close_linux_tracing(void)270 static inline void wpa_debug_close_linux_tracing(void)
271 {
272 }
273 
274 #endif /* CONFIG_DEBUG_LINUX_TRACING */
275 
276 
277 #ifdef EAPOL_TEST
278 #define WPA_ASSERT(a)						       \
279 	do {							       \
280 		if (!(a)) {					       \
281 			printf("WPA_ASSERT FAILED '" #a "' "	       \
282 			       "%s %s:%d\n",			       \
283 			       __FUNCTION__, __FILE__, __LINE__);      \
284 			exit(1);				       \
285 		}						       \
286 	} while (0)
287 #else
288 #define WPA_ASSERT(a) do { } while (0)
289 #endif
290 
291 #endif /* WPA_DEBUG_H */
292