2 * wpa_supplicant/hostapd / Debug prints
3 * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
24 /* Debugging function - conditional printf and hex dump. Driver wrappers can
25 * use these for debugging purposes. */
28 MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
31 #ifdef CONFIG_NO_STDOUT_DEBUG
33 #define wpa_debug_print_timestamp() do { } while (0)
34 #define wpa_printf(args...) do { } while (0)
35 #define wpa_hexdump(l,t,b,le) do { } while (0)
36 #define wpa_hexdump_buf(l,t,b) do { } while (0)
37 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
38 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
39 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
40 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
41 #define wpa_debug_open_file(p) do { } while (0)
42 #define wpa_debug_close_file() do { } while (0)
44 #else /* CONFIG_NO_STDOUT_DEBUG */
46 int wpa_debug_open_file(const char *path);
47 void wpa_debug_close_file(void);
50 * wpa_debug_printf_timestamp - Print timestamp for debug output
52 * This function prints a timestamp in seconds_from_1970.microsoconds
53 * format if debug output has been configured to include timestamps in debug
56 void wpa_debug_print_timestamp(void);
59 * wpa_printf - conditional printf
60 * @level: priority level (MSG_*) of the message
61 * @fmt: printf format string, followed by optional arguments
63 * This function is used to print conditional debugging and error messages. The
64 * output may be directed to stdout, stderr, and/or syslog based on
67 * Note: New line '\n' is added to the end of the text when printing to stdout.
69 void wpa_printf(int level, const char *fmt, ...)
73 * wpa_hexdump - conditional hex dump
74 * @level: priority level (MSG_*) of the message
75 * @title: title of for the message
76 * @buf: data buffer to be dumped
77 * @len: length of the buf
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. The contents of buf is printed out has hex dump.
83 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
85 static inline void wpa_hexdump_buf(int level, const char *title,
86 const struct wpabuf *buf)
88 wpa_hexdump(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
92 * wpa_hexdump_key - conditional hex dump, hide keys
93 * @level: priority level (MSG_*) of the message
94 * @title: title of for the message
95 * @buf: data buffer to be dumped
96 * @len: length of the buf
98 * This function is used to print conditional debugging and error messages. The
99 * output may be directed to stdout, stderr, and/or syslog based on
100 * configuration. The contents of buf is printed out has hex dump. This works
101 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
102 * etc.) in debug output.
104 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
106 static inline void wpa_hexdump_buf_key(int level, const char *title,
107 const struct wpabuf *buf)
109 wpa_hexdump_key(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
113 * wpa_hexdump_ascii - conditional hex dump
114 * @level: priority level (MSG_*) of the message
115 * @title: title of for the message
116 * @buf: data buffer to be dumped
117 * @len: length of the buf
119 * This function is used to print conditional debugging and error messages. The
120 * output may be directed to stdout, stderr, and/or syslog based on
121 * configuration. The contents of buf is printed out has hex dump with both
122 * the hex numbers and ASCII characters (for printable range) are shown. 16
123 * bytes per line will be shown.
125 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
129 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
130 * @level: priority level (MSG_*) of the message
131 * @title: title of for the message
132 * @buf: data buffer to be dumped
133 * @len: length of the buf
135 * This function is used to print conditional debugging and error messages. The
136 * output may be directed to stdout, stderr, and/or syslog based on
137 * configuration. The contents of buf is printed out has hex dump with both
138 * the hex numbers and ASCII characters (for printable range) are shown. 16
139 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
140 * default, does not include secret keys (passwords, etc.) in debug output.
142 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
145 #endif /* CONFIG_NO_STDOUT_DEBUG */
148 #ifdef CONFIG_NO_WPA_MSG
149 #define wpa_msg(args...) do { } while (0)
150 #define wpa_msg_ctrl(args...) do { } while (0)
151 #define wpa_msg_register_cb(f) do { } while (0)
152 #else /* CONFIG_NO_WPA_MSG */
154 * wpa_msg - Conditional printf for default target and ctrl_iface monitors
155 * @ctx: Pointer to context data; this is the ctx variable registered
156 * with struct wpa_driver_ops::init()
157 * @level: priority level (MSG_*) of the message
158 * @fmt: printf format string, followed by optional arguments
160 * This function is used to print conditional debugging and error messages. The
161 * output may be directed to stdout, stderr, and/or syslog based on
162 * configuration. This function is like wpa_printf(), but it also sends the
163 * same message to all attached ctrl_iface monitors.
165 * Note: New line '\n' is added to the end of the text when printing to stdout.
167 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
170 * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
171 * @ctx: Pointer to context data; this is the ctx variable registered
172 * with struct wpa_driver_ops::init()
173 * @level: priority level (MSG_*) of the message
174 * @fmt: printf format string, followed by optional arguments
176 * This function is used to print conditional debugging and error messages.
177 * This function is like wpa_msg(), but it sends the output only to the
178 * attached ctrl_iface monitors. In other words, it can be used for frequent
179 * events that do not need to be sent to syslog.
181 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
184 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
188 * wpa_msg_register_cb - Register callback function for wpa_msg() messages
189 * @func: Callback function (%NULL to unregister)
191 void wpa_msg_register_cb(wpa_msg_cb_func func);
192 #endif /* CONFIG_NO_WPA_MSG */
195 #ifdef CONFIG_NO_HOSTAPD_LOGGER
196 #define hostapd_logger(args...) do { } while (0)
197 #define hostapd_logger_register_cb(f) do { } while (0)
198 #else /* CONFIG_NO_HOSTAPD_LOGGER */
199 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
200 const char *fmt, ...) PRINTF_FORMAT(5, 6);
202 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
203 unsigned int module, int level,
204 const char *txt, size_t len);
207 * hostapd_logger_register_cb - Register callback function for hostapd_logger()
208 * @func: Callback function (%NULL to unregister)
210 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
211 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
213 #define HOSTAPD_MODULE_IEEE80211 0x00000001
214 #define HOSTAPD_MODULE_IEEE8021X 0x00000002
215 #define HOSTAPD_MODULE_RADIUS 0x00000004
216 #define HOSTAPD_MODULE_WPA 0x00000008
217 #define HOSTAPD_MODULE_DRIVER 0x00000010
218 #define HOSTAPD_MODULE_IAPP 0x00000020
219 #define HOSTAPD_MODULE_MLME 0x00000040
221 enum hostapd_logger_level {
222 HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
223 HOSTAPD_LEVEL_DEBUG = 1,
224 HOSTAPD_LEVEL_INFO = 2,
225 HOSTAPD_LEVEL_NOTICE = 3,
226 HOSTAPD_LEVEL_WARNING = 4
230 #ifdef CONFIG_DEBUG_SYSLOG
232 void wpa_debug_open_syslog(void);
233 void wpa_debug_close_syslog(void);
235 #else /* CONFIG_DEBUG_SYSLOG */
237 static inline void wpa_debug_open_syslog(void)
241 static inline void wpa_debug_close_syslog(void)
245 #endif /* CONFIG_DEBUG_SYSLOG */
249 #define WPA_ASSERT(a) \
252 printf("WPA_ASSERT FAILED '" #a "' " \
254 __FUNCTION__, __FILE__, __LINE__); \
259 #define WPA_ASSERT(a) do { } while (0)
266 #endif /* WPA_DEBUG_H */