2008-02-27 20:34:43 -05:00
|
|
|
/*
|
|
|
|
* wpa_supplicant/hostapd / Debug prints
|
2013-05-18 07:19:24 -04:00
|
|
|
* Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
|
2008-02-27 20:34:43 -05:00
|
|
|
*
|
2012-02-11 09:46:35 -05:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-27 20:34:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WPA_DEBUG_H
|
|
|
|
#define WPA_DEBUG_H
|
|
|
|
|
|
|
|
#include "wpabuf.h"
|
|
|
|
|
2013-12-31 12:29:52 -05:00
|
|
|
extern int wpa_debug_level;
|
|
|
|
extern int wpa_debug_show_keys;
|
|
|
|
extern int wpa_debug_timestamp;
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
/* Debugging function - conditional printf and hex dump. Driver wrappers can
|
|
|
|
* use these for debugging purposes. */
|
|
|
|
|
2010-07-05 15:21:48 -04:00
|
|
|
enum {
|
|
|
|
MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
|
|
|
|
};
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_NO_STDOUT_DEBUG
|
|
|
|
|
|
|
|
#define wpa_debug_print_timestamp() do { } while (0)
|
|
|
|
#define wpa_printf(args...) do { } while (0)
|
|
|
|
#define wpa_hexdump(l,t,b,le) do { } while (0)
|
|
|
|
#define wpa_hexdump_buf(l,t,b) do { } while (0)
|
|
|
|
#define wpa_hexdump_key(l,t,b,le) do { } while (0)
|
|
|
|
#define wpa_hexdump_buf_key(l,t,b) do { } while (0)
|
|
|
|
#define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
|
|
|
|
#define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
|
|
|
|
#define wpa_debug_open_file(p) do { } while (0)
|
|
|
|
#define wpa_debug_close_file() do { } while (0)
|
2014-12-04 17:23:35 -05:00
|
|
|
#define wpa_debug_setup_stdout() do { } while (0)
|
2011-02-10 13:14:46 -05:00
|
|
|
#define wpa_dbg(args...) do { } while (0)
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2011-02-10 13:24:06 -05:00
|
|
|
static inline int wpa_debug_reopen_file(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
#else /* CONFIG_NO_STDOUT_DEBUG */
|
|
|
|
|
|
|
|
int wpa_debug_open_file(const char *path);
|
2011-02-06 13:15:19 -05:00
|
|
|
int wpa_debug_reopen_file(void);
|
2008-02-27 20:34:43 -05:00
|
|
|
void wpa_debug_close_file(void);
|
2014-12-04 17:23:35 -05:00
|
|
|
void wpa_debug_setup_stdout(void);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_debug_printf_timestamp - Print timestamp for debug output
|
|
|
|
*
|
2009-01-04 08:07:54 -05:00
|
|
|
* This function prints a timestamp in seconds_from_1970.microsoconds
|
2008-02-27 20:34:43 -05:00
|
|
|
* format if debug output has been configured to include timestamps in debug
|
|
|
|
* messages.
|
|
|
|
*/
|
|
|
|
void wpa_debug_print_timestamp(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_printf - conditional printf
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration.
|
|
|
|
*
|
|
|
|
* Note: New line '\n' is added to the end of the text when printing to stdout.
|
|
|
|
*/
|
2010-01-04 12:16:19 -05:00
|
|
|
void wpa_printf(int level, const char *fmt, ...)
|
2008-02-27 20:34:43 -05:00
|
|
|
PRINTF_FORMAT(2, 3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_hexdump - conditional hex dump
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @title: title of for the message
|
|
|
|
* @buf: data buffer to be dumped
|
|
|
|
* @len: length of the buf
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration. The contents of buf is printed out has hex dump.
|
|
|
|
*/
|
2013-12-24 16:12:37 -05:00
|
|
|
void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
static inline void wpa_hexdump_buf(int level, const char *title,
|
|
|
|
const struct wpabuf *buf)
|
|
|
|
{
|
2010-10-31 06:09:18 -04:00
|
|
|
wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
|
|
|
|
buf ? wpabuf_len(buf) : 0);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_hexdump_key - conditional hex dump, hide keys
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @title: title of for the message
|
|
|
|
* @buf: data buffer to be dumped
|
|
|
|
* @len: length of the buf
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration. The contents of buf is printed out has hex dump. This works
|
|
|
|
* like wpa_hexdump(), but by default, does not include secret keys (passwords,
|
|
|
|
* etc.) in debug output.
|
|
|
|
*/
|
2013-12-24 16:12:37 -05:00
|
|
|
void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
static inline void wpa_hexdump_buf_key(int level, const char *title,
|
|
|
|
const struct wpabuf *buf)
|
|
|
|
{
|
2011-11-18 15:07:30 -05:00
|
|
|
wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
|
2010-10-31 06:09:18 -04:00
|
|
|
buf ? wpabuf_len(buf) : 0);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_hexdump_ascii - conditional hex dump
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @title: title of for the message
|
|
|
|
* @buf: data buffer to be dumped
|
|
|
|
* @len: length of the buf
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration. The contents of buf is printed out has hex dump with both
|
|
|
|
* the hex numbers and ASCII characters (for printable range) are shown. 16
|
|
|
|
* bytes per line will be shown.
|
|
|
|
*/
|
2013-12-24 16:12:37 -05:00
|
|
|
void wpa_hexdump_ascii(int level, const char *title, const void *buf,
|
2008-02-27 20:34:43 -05:00
|
|
|
size_t len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_hexdump_ascii_key - conditional hex dump, hide keys
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @title: title of for the message
|
|
|
|
* @buf: data buffer to be dumped
|
|
|
|
* @len: length of the buf
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration. The contents of buf is printed out has hex dump with both
|
|
|
|
* the hex numbers and ASCII characters (for printable range) are shown. 16
|
|
|
|
* bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
|
|
|
|
* default, does not include secret keys (passwords, etc.) in debug output.
|
|
|
|
*/
|
2013-12-24 16:12:37 -05:00
|
|
|
void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
|
2008-02-27 20:34:43 -05:00
|
|
|
size_t len);
|
|
|
|
|
2011-02-10 13:14:46 -05:00
|
|
|
/*
|
|
|
|
* wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
|
|
|
|
* binary size. As such, it should be used with debugging messages that are not
|
|
|
|
* needed in the control interface while wpa_msg() has to be used for anything
|
|
|
|
* that needs to shown to control interface monitors.
|
|
|
|
*/
|
|
|
|
#define wpa_dbg(args...) wpa_msg(args)
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
#endif /* CONFIG_NO_STDOUT_DEBUG */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_NO_WPA_MSG
|
|
|
|
#define wpa_msg(args...) do { } while (0)
|
2009-11-10 08:59:41 -05:00
|
|
|
#define wpa_msg_ctrl(args...) do { } while (0)
|
2013-05-18 07:19:24 -04:00
|
|
|
#define wpa_msg_global(args...) do { } while (0)
|
2014-07-26 06:04:03 -04:00
|
|
|
#define wpa_msg_global_ctrl(args...) do { } while (0)
|
2013-05-18 12:18:31 -04:00
|
|
|
#define wpa_msg_no_global(args...) do { } while (0)
|
2014-11-16 09:52:49 -05:00
|
|
|
#define wpa_msg_global_only(args...) do { } while (0)
|
2008-02-27 20:34:43 -05:00
|
|
|
#define wpa_msg_register_cb(f) do { } while (0)
|
2011-02-10 13:24:06 -05:00
|
|
|
#define wpa_msg_register_ifname_cb(f) do { } while (0)
|
2008-02-27 20:34:43 -05:00
|
|
|
#else /* CONFIG_NO_WPA_MSG */
|
|
|
|
/**
|
|
|
|
* wpa_msg - Conditional printf for default target and ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages. The
|
|
|
|
* output may be directed to stdout, stderr, and/or syslog based on
|
|
|
|
* configuration. This function is like wpa_printf(), but it also sends the
|
|
|
|
* same message to all attached ctrl_iface monitors.
|
|
|
|
*
|
|
|
|
* Note: New line '\n' is added to the end of the text when printing to stdout.
|
|
|
|
*/
|
2010-01-04 12:16:19 -05:00
|
|
|
void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2009-11-10 08:59:41 -05:00
|
|
|
/**
|
|
|
|
* wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages.
|
|
|
|
* This function is like wpa_msg(), but it sends the output only to the
|
|
|
|
* attached ctrl_iface monitors. In other words, it can be used for frequent
|
|
|
|
* events that do not need to be sent to syslog.
|
|
|
|
*/
|
2010-01-04 12:16:19 -05:00
|
|
|
void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
2009-11-10 08:59:41 -05:00
|
|
|
|
2013-05-18 07:19:24 -04:00
|
|
|
/**
|
|
|
|
* wpa_msg_global - Global printf for ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages.
|
|
|
|
* This function is like wpa_msg(), but it sends the output as a global event,
|
|
|
|
* i.e., without being specific to an interface. For backwards compatibility,
|
|
|
|
* an old style event is also delivered on one of the interfaces (the one
|
|
|
|
* specified by the context data).
|
|
|
|
*/
|
|
|
|
void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
|
|
|
|
2014-07-26 06:04:03 -04:00
|
|
|
/**
|
|
|
|
* wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages.
|
|
|
|
* This function is like wpa_msg_global(), but it sends the output only to the
|
|
|
|
* attached global ctrl_iface monitors. In other words, it can be used for
|
|
|
|
* frequent events that do not need to be sent to syslog.
|
|
|
|
*/
|
|
|
|
void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
|
|
|
|
2013-05-18 12:18:31 -04:00
|
|
|
/**
|
|
|
|
* wpa_msg_no_global - Conditional printf for ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages.
|
|
|
|
* This function is like wpa_msg(), but it does not send the output as a global
|
|
|
|
* event.
|
|
|
|
*/
|
|
|
|
void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
|
|
|
|
2014-11-16 09:52:49 -05:00
|
|
|
/**
|
|
|
|
* wpa_msg_global_only - Conditional printf for ctrl_iface monitors
|
|
|
|
* @ctx: Pointer to context data; this is the ctx variable registered
|
|
|
|
* with struct wpa_driver_ops::init()
|
|
|
|
* @level: priority level (MSG_*) of the message
|
|
|
|
* @fmt: printf format string, followed by optional arguments
|
|
|
|
*
|
|
|
|
* This function is used to print conditional debugging and error messages.
|
|
|
|
* This function is like wpa_msg_global(), but it sends the output only as a
|
|
|
|
* global event.
|
|
|
|
*/
|
|
|
|
void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
|
|
|
|
2015-02-06 05:08:28 -05:00
|
|
|
enum wpa_msg_type {
|
|
|
|
WPA_MSG_PER_INTERFACE,
|
|
|
|
WPA_MSG_GLOBAL,
|
|
|
|
WPA_MSG_NO_GLOBAL,
|
2014-11-16 09:52:49 -05:00
|
|
|
WPA_MSG_ONLY_GLOBAL,
|
2015-02-06 05:08:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
|
2013-05-18 07:19:24 -04:00
|
|
|
const char *txt, size_t len);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_msg_register_cb - Register callback function for wpa_msg() messages
|
|
|
|
* @func: Callback function (%NULL to unregister)
|
|
|
|
*/
|
|
|
|
void wpa_msg_register_cb(wpa_msg_cb_func func);
|
|
|
|
|
2011-02-06 13:39:34 -05:00
|
|
|
typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
|
|
|
|
void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
|
|
|
|
|
|
|
|
#endif /* CONFIG_NO_WPA_MSG */
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_NO_HOSTAPD_LOGGER
|
|
|
|
#define hostapd_logger(args...) do { } while (0)
|
|
|
|
#define hostapd_logger_register_cb(f) do { } while (0)
|
|
|
|
#else /* CONFIG_NO_HOSTAPD_LOGGER */
|
|
|
|
void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
|
|
|
|
const char *fmt, ...) PRINTF_FORMAT(5, 6);
|
|
|
|
|
|
|
|
typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
|
|
|
|
unsigned int module, int level,
|
|
|
|
const char *txt, size_t len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hostapd_logger_register_cb - Register callback function for hostapd_logger()
|
|
|
|
* @func: Callback function (%NULL to unregister)
|
|
|
|
*/
|
|
|
|
void hostapd_logger_register_cb(hostapd_logger_cb_func func);
|
|
|
|
#endif /* CONFIG_NO_HOSTAPD_LOGGER */
|
|
|
|
|
|
|
|
#define HOSTAPD_MODULE_IEEE80211 0x00000001
|
|
|
|
#define HOSTAPD_MODULE_IEEE8021X 0x00000002
|
|
|
|
#define HOSTAPD_MODULE_RADIUS 0x00000004
|
|
|
|
#define HOSTAPD_MODULE_WPA 0x00000008
|
|
|
|
#define HOSTAPD_MODULE_DRIVER 0x00000010
|
|
|
|
#define HOSTAPD_MODULE_IAPP 0x00000020
|
|
|
|
#define HOSTAPD_MODULE_MLME 0x00000040
|
|
|
|
|
|
|
|
enum hostapd_logger_level {
|
|
|
|
HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
|
|
|
|
HOSTAPD_LEVEL_DEBUG = 1,
|
|
|
|
HOSTAPD_LEVEL_INFO = 2,
|
|
|
|
HOSTAPD_LEVEL_NOTICE = 3,
|
|
|
|
HOSTAPD_LEVEL_WARNING = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-02 14:40:44 -05:00
|
|
|
#ifdef CONFIG_DEBUG_SYSLOG
|
|
|
|
|
|
|
|
void wpa_debug_open_syslog(void);
|
|
|
|
void wpa_debug_close_syslog(void);
|
|
|
|
|
|
|
|
#else /* CONFIG_DEBUG_SYSLOG */
|
|
|
|
|
|
|
|
static inline void wpa_debug_open_syslog(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wpa_debug_close_syslog(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG_SYSLOG */
|
|
|
|
|
2012-03-31 06:55:33 -04:00
|
|
|
#ifdef CONFIG_DEBUG_LINUX_TRACING
|
|
|
|
|
|
|
|
int wpa_debug_open_linux_tracing(void);
|
|
|
|
void wpa_debug_close_linux_tracing(void);
|
|
|
|
|
|
|
|
#else /* CONFIG_DEBUG_LINUX_TRACING */
|
|
|
|
|
|
|
|
static inline int wpa_debug_open_linux_tracing(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wpa_debug_close_linux_tracing(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG_LINUX_TRACING */
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
#ifdef EAPOL_TEST
|
|
|
|
#define WPA_ASSERT(a) \
|
|
|
|
do { \
|
|
|
|
if (!(a)) { \
|
|
|
|
printf("WPA_ASSERT FAILED '" #a "' " \
|
|
|
|
"%s %s:%d\n", \
|
|
|
|
__FUNCTION__, __FILE__, __LINE__); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define WPA_ASSERT(a) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2015-08-03 10:44:55 -04:00
|
|
|
const char * debug_level_str(int level);
|
|
|
|
int str_to_debug_level(const char *s);
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
#endif /* WPA_DEBUG_H */
|