2 * wpa_supplicant/hostapd / Debug prints
3 * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
14 /* Debugging function - conditional printf and hex dump. Driver wrappers can
15 * use these for debugging purposes. */
18 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
21 #ifdef CONFIG_NO_STDOUT_DEBUG
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)
35 static inline int wpa_debug_reopen_file(void)
40 #else /* CONFIG_NO_STDOUT_DEBUG */
42 int wpa_debug_open_file(const char *path);
43 int wpa_debug_reopen_file(void);
44 void wpa_debug_close_file(void);
47 * wpa_debug_printf_timestamp - Print timestamp for debug output
49 * This function prints a timestamp in seconds_from_1970.microsoconds
50 * format if debug output has been configured to include timestamps in debug
53 void wpa_debug_print_timestamp(void);
56 * wpa_printf - conditional printf
57 * @level: priority level (MSG_*) of the message
58 * @fmt: printf format string, followed by optional arguments
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
64 * Note: New line '\n' is added to the end of the text when printing to stdout.
66 void wpa_printf(int level, const char *fmt, ...)
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
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.
80 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
82 static inline void wpa_hexdump_buf(int level, const char *title,
83 const struct wpabuf *buf)
85 wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
86 buf ? wpabuf_len(buf) : 0);
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
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.
102 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
104 static inline void wpa_hexdump_buf_key(int level, const char *title,
105 const struct wpabuf *buf)
107 wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
108 buf ? wpabuf_len(buf) : 0);
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
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.
124 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
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
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.
141 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
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.
150 #define wpa_dbg(args...) wpa_msg(args)
152 #endif /* CONFIG_NO_STDOUT_DEBUG */
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 */
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
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.
173 * Note: New line '\n' is added to the end of the text when printing to stdout.
175 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
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
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.
189 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
192 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
196 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
197 * @func: Callback function (%NULL to unregister)
199 void wpa_msg_register_cb(wpa_msg_cb_func func);
201 typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
202 void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
204 #endif /* CONFIG_NO_WPA_MSG */
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);
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);
218 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
219 * @func: Callback function (%NULL to unregister)
221 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
222 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
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
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
241 #ifdef CONFIG_DEBUG_SYSLOG
243 void wpa_debug_open_syslog(void);
244 void wpa_debug_close_syslog(void);
246 #else /* CONFIG_DEBUG_SYSLOG */
248 static inline void wpa_debug_open_syslog(void)
252 static inline void wpa_debug_close_syslog(void)
256 #endif /* CONFIG_DEBUG_SYSLOG */
258 #ifdef CONFIG_DEBUG_LINUX_TRACING
260 int wpa_debug_open_linux_tracing(void);
261 void wpa_debug_close_linux_tracing(void);
263 #else /* CONFIG_DEBUG_LINUX_TRACING */
265 static inline int wpa_debug_open_linux_tracing(void)
270 static inline void wpa_debug_close_linux_tracing(void)
274 #endif /* CONFIG_DEBUG_LINUX_TRACING */
278 #define WPA_ASSERT(a) \
281 printf("WPA_ASSERT FAILED '" #a "' " \
283 __FUNCTION__, __FILE__, __LINE__); \
288 #define WPA_ASSERT(a) do { } while (0)
291 #endif /* WPA_DEBUG_H */