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