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