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