Android: Extend debug logging to include wpa_dbg and hexdump
This makes the Android debug logs from logcat quite a bit more helpful in debugging wpa_supplicant. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
6d441b0da2
commit
4a0d25f08a
2 changed files with 59 additions and 45 deletions
|
@ -30,25 +30,18 @@ int wpa_debug_timestamp = 0;
|
|||
#define ANDROID_LOG_NAME "wpa_supplicant"
|
||||
#endif /* ANDROID_LOG_NAME */
|
||||
|
||||
void android_printf(int level, char *format, ...)
|
||||
static int wpa_to_android_level(int level)
|
||||
{
|
||||
if (level >= wpa_debug_level) {
|
||||
va_list ap;
|
||||
if (level == MSG_ERROR)
|
||||
level = ANDROID_LOG_ERROR;
|
||||
else if (level == MSG_WARNING)
|
||||
level = ANDROID_LOG_WARN;
|
||||
else if (level == MSG_INFO)
|
||||
level = ANDROID_LOG_INFO;
|
||||
else
|
||||
level = ANDROID_LOG_DEBUG;
|
||||
va_start(ap, format);
|
||||
__android_log_vprint(level, ANDROID_LOG_NAME, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
if (level == MSG_ERROR)
|
||||
return ANDROID_LOG_ERROR;
|
||||
if (level == MSG_WARNING)
|
||||
return ANDROID_LOG_WARN;
|
||||
if (level == MSG_INFO)
|
||||
return ANDROID_LOG_INFO;
|
||||
return ANDROID_LOG_DEBUG;
|
||||
}
|
||||
|
||||
#else /* CONFIG_ANDROID_LOG */
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
|
||||
#ifndef CONFIG_NO_STDOUT_DEBUG
|
||||
|
||||
|
@ -59,6 +52,7 @@ static FILE *out_file = NULL;
|
|||
|
||||
void wpa_debug_print_timestamp(void)
|
||||
{
|
||||
#ifndef CONFIG_ANDROID_LOG
|
||||
struct os_time tv;
|
||||
|
||||
if (!wpa_debug_timestamp)
|
||||
|
@ -72,6 +66,7 @@ void wpa_debug_print_timestamp(void)
|
|||
} else
|
||||
#endif /* CONFIG_DEBUG_FILE */
|
||||
printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec);
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,6 +124,10 @@ void wpa_printf(int level, const char *fmt, ...)
|
|||
|
||||
va_start(ap, fmt);
|
||||
if (level >= wpa_debug_level) {
|
||||
#ifdef CONFIG_ANDROID_LOG
|
||||
__android_log_vprint(wpa_to_android_level(level),
|
||||
ANDROID_LOG_NAME, fmt, ap);
|
||||
#else /* CONFIG_ANDROID_LOG */
|
||||
#ifdef CONFIG_DEBUG_SYSLOG
|
||||
if (wpa_debug_syslog) {
|
||||
vsyslog(syslog_priority(level), fmt, ap);
|
||||
|
@ -149,6 +148,7 @@ void wpa_printf(int level, const char *fmt, ...)
|
|||
#ifdef CONFIG_DEBUG_SYSLOG
|
||||
}
|
||||
#endif /* CONFIG_DEBUG_SYSLOG */
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
@ -160,6 +160,44 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
|
|||
size_t i;
|
||||
if (level < wpa_debug_level)
|
||||
return;
|
||||
#ifdef CONFIG_ANDROID_LOG
|
||||
{
|
||||
const char *display;
|
||||
char *strbuf = NULL;
|
||||
size_t slen = len;
|
||||
if (buf == NULL) {
|
||||
display = " [NULL]";
|
||||
} else if (len == 0) {
|
||||
display = "";
|
||||
} else if (show && len) {
|
||||
/* Limit debug message length for Android log */
|
||||
if (slen > 32)
|
||||
slen = 32;
|
||||
strbuf = os_malloc(1 + 3 * slen);
|
||||
if (strbuf == NULL) {
|
||||
wpa_printf(MSG_ERROR, "wpa_hexdump: Failed to "
|
||||
"allocate message buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < slen; i++)
|
||||
os_snprintf(&strbuf[i * 3], 4, " %02x",
|
||||
buf[i]);
|
||||
|
||||
display = strbuf;
|
||||
} else {
|
||||
display = " [REMOVED]";
|
||||
}
|
||||
|
||||
__android_log_print(wpa_to_android_level(level),
|
||||
ANDROID_LOG_NAME,
|
||||
"%s - hexdump(len=%lu):%s%s",
|
||||
title, (long unsigned int) len, display,
|
||||
len > slen ? " ..." : "");
|
||||
os_free(strbuf);
|
||||
return;
|
||||
}
|
||||
#else /* CONFIG_ANDROID_LOG */
|
||||
#ifdef CONFIG_DEBUG_SYSLOG
|
||||
if (wpa_debug_syslog) {
|
||||
const char *display;
|
||||
|
@ -221,6 +259,7 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
|
|||
#ifdef CONFIG_DEBUG_FILE
|
||||
}
|
||||
#endif /* CONFIG_DEBUG_FILE */
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
}
|
||||
|
||||
void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len)
|
||||
|
@ -244,6 +283,9 @@ static void _wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
|
|||
|
||||
if (level < wpa_debug_level)
|
||||
return;
|
||||
#ifdef CONFIG_ANDROID_LOG
|
||||
_wpa_hexdump(level, title, buf, len, show);
|
||||
#else /* CONFIG_ANDROID_LOG */
|
||||
wpa_debug_print_timestamp();
|
||||
#ifdef CONFIG_DEBUG_FILE
|
||||
if (out_file) {
|
||||
|
@ -317,6 +359,7 @@ static void _wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
|
|||
#ifdef CONFIG_DEBUG_FILE
|
||||
}
|
||||
#endif /* CONFIG_DEBUG_FILE */
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
}
|
||||
|
||||
|
||||
|
@ -398,7 +441,6 @@ void wpa_debug_close_file(void)
|
|||
|
||||
#endif /* CONFIG_NO_STDOUT_DEBUG */
|
||||
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
|
||||
#ifndef CONFIG_NO_WPA_MSG
|
||||
static wpa_msg_cb_func wpa_msg_cb = NULL;
|
||||
|
|
|
@ -18,32 +18,6 @@ enum {
|
|||
MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
|
||||
};
|
||||
|
||||
#ifdef CONFIG_ANDROID_LOG
|
||||
|
||||
#define wpa_debug_print_timestamp() do {} while (0)
|
||||
#define wpa_hexdump(...) do {} while (0)
|
||||
#define wpa_hexdump_key(...) do {} while (0)
|
||||
#define wpa_hexdump_buf(l,t,b) do {} while (0)
|
||||
#define wpa_hexdump_buf_key(l,t,b) do {} while (0)
|
||||
#define wpa_hexdump_ascii(...) do {} while (0)
|
||||
#define wpa_hexdump_ascii_key(...) do {} while (0)
|
||||
#define wpa_debug_open_file(...) do {} while (0)
|
||||
#define wpa_debug_close_file() do {} while (0)
|
||||
#define wpa_dbg(...) do {} while (0)
|
||||
|
||||
static inline int wpa_debug_reopen_file(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void android_printf(int level, char *format, ...)
|
||||
PRINTF_FORMAT(2, 3);
|
||||
|
||||
#define wpa_printf android_printf
|
||||
|
||||
#else /* CONFIG_ANDROID_LOG */
|
||||
|
||||
#ifdef CONFIG_NO_STDOUT_DEBUG
|
||||
|
||||
#define wpa_debug_print_timestamp() do { } while (0)
|
||||
|
@ -177,8 +151,6 @@ void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
|
|||
|
||||
#endif /* CONFIG_NO_STDOUT_DEBUG */
|
||||
|
||||
#endif /* CONFIG_ANDROID_LOG */
|
||||
|
||||
|
||||
#ifdef CONFIG_NO_WPA_MSG
|
||||
#define wpa_msg(args...) do { } while (0)
|
||||
|
|
Loading…
Reference in a new issue