From ac0b4c184d3660b18e8e7d631e3476889e6ff6bd Mon Sep 17 00:00:00 2001 From: Hrudaynath Dhabe Date: Mon, 14 Oct 2019 23:37:51 +0800 Subject: [PATCH] wpa_supplicant: Make hexdump logs more compact When running with wpa debug prints enabled data/key hexdumps are printed to the log in a really verbose format (one byte per line). Make these printouts more compact. 16 bytes per line. --- .../wpa_supplicant/src/utils/wpa_debug.c | 52 +++++++++++++------ .../wpa2_enterprise/main/Kconfig.projbuild | 28 ++++++++-- .../main/wpa2_enterprise_main.c | 31 +++++++---- 3 files changed, 81 insertions(+), 30 deletions(-) diff --git a/components/wpa_supplicant/src/utils/wpa_debug.c b/components/wpa_supplicant/src/utils/wpa_debug.c index aed26664e..20a0ae444 100644 --- a/components/wpa_supplicant/src/utils/wpa_debug.c +++ b/components/wpa_supplicant/src/utils/wpa_debug.c @@ -16,17 +16,26 @@ #include "utils/common.h" #include "utils/wpa_debug.h" -static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len, int uppercase) +static inline int +_wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len, + int uppercase, int whitespace) { size_t i; char *pos = buf, *end = buf + buf_size; int ret; + static const char *fmt_upper = "%02X"; + static const char *fmt_lower = "%02x"; + static const char *fmt_upper_ws = "%02X "; + static const char *fmt_lower_ws = "%02x "; + const char *fmt = uppercase ? (whitespace ? fmt_upper_ws : fmt_upper) : + (whitespace ? fmt_lower_ws : fmt_lower); + if (buf_size == 0) return 0; for (i = 0; i < len; i++) { - ret = snprintf(pos, end - pos, uppercase? "%02X":"%02x", data[i]); + ret = snprintf(pos, end - pos, fmt, data[i]); if (ret < 0 || ret >= end - pos) { end[-1] = '\0'; return pos - buf; @@ -39,25 +48,31 @@ static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data, size_t len) { - return _wpa_snprintf_hex(buf, buf_size, data, len, 1); + return _wpa_snprintf_hex(buf, buf_size, data, len, 1, 0); } int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len) { - return _wpa_snprintf_hex(buf, buf_size, data, len, 0); + return _wpa_snprintf_hex(buf, buf_size, data, len, 0, 0); } #ifdef DEBUG_PRINT void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len) { + char output[50]; wpa_printf(MSG_DEBUG, "%s\n", desc); if (addr){ uint16_t i=0; - for (i=0; i