From 851658109c6d792deece46138333dcad54c77801 Mon Sep 17 00:00:00 2001 From: "GOPTIONS\\pfrost" Date: Fri, 26 Jul 2019 15:56:40 +0100 Subject: [PATCH 1/2] Reduce log level of hexdumps to verbose Revert "Reduce log level of hexdumps to verbose" Add a menuconfig option to enable or disable the logging in wpa_supplicant Clarify help message --- components/wpa_supplicant/Kconfig | 11 +++++++ .../wpa_supplicant/include/utils/wpa_debug.h | 29 +++++++++---------- .../port/include/supplicant_opt.h | 4 +++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/components/wpa_supplicant/Kconfig b/components/wpa_supplicant/Kconfig index 927dc0165a..ccde605688 100644 --- a/components/wpa_supplicant/Kconfig +++ b/components/wpa_supplicant/Kconfig @@ -6,4 +6,15 @@ menu "Supplicant" help Select this option to use MbedTLS crypto API's which utilize hardware acceleration. + config WPA_DEBUG_PRINT + bool "Print debug messages from WPA Supplicant" + default n + help + Select this option to print logging information from WPA supplicant, + this includes handshake information and key hex dumps depending + on the project logging level. + + Enabling this could increase the build size ~60kb + depending on the project logging level. + endmenu diff --git a/components/wpa_supplicant/include/utils/wpa_debug.h b/components/wpa_supplicant/include/utils/wpa_debug.h index b204ec7d87..8f5cc8b914 100644 --- a/components/wpa_supplicant/include/utils/wpa_debug.h +++ b/components/wpa_supplicant/include/utils/wpa_debug.h @@ -47,6 +47,7 @@ void wpa_debug_close_file(void); */ void wpa_debug_print_timestamp(void); +#ifdef DEBUG_PRINT /** * wpa_printf - conditional printf * @level: priority level (MSG_*) of the message @@ -58,21 +59,6 @@ void wpa_debug_print_timestamp(void); * * Note: New line '\n' is added to the end of the text when printing to stdout. */ -#define DEBUG_PRINT -#define MSG_PRINT - -/** - * 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. - */ -#ifdef DEBUG_PRINT #define wpa_printf(level,fmt, args...) ESP_LOG_LEVEL_LOCAL(level, TAG, fmt, ##args) void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len); @@ -85,7 +71,17 @@ static inline void wpa_hexdump_ascii_key(int level, const char *title, const u8 { } - +/** + * 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. + */ void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len); static inline void wpa_hexdump_buf(int level, const char *title, @@ -151,6 +147,7 @@ void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf, #else #define wpa_printf(level,fmt, args...) #define wpa_hexdump(...) +#define wpa_dump_mem(...) #define wpa_hexdump_buf(...) #define wpa_hexdump_key(...) #define wpa_hexdump_buf_key(...) diff --git a/components/wpa_supplicant/port/include/supplicant_opt.h b/components/wpa_supplicant/port/include/supplicant_opt.h index 12d607add3..8ebb1e339b 100644 --- a/components/wpa_supplicant/port/include/supplicant_opt.h +++ b/components/wpa_supplicant/port/include/supplicant_opt.h @@ -21,4 +21,8 @@ #define USE_MBEDTLS_CRYPTO 1 #endif +#if CONFIG_WPA_DEBUG_PRINT +#define DEBUG_PRINT +#endif + #endif /* _SUPPLICANT_OPT_H */ From ec50c5344b9c311b9f7cc3cab5abb4ee3e59c918 Mon Sep 17 00:00:00 2001 From: Hrudaynath Dhabe Date: Thu, 30 Jan 2020 19:25:45 +0530 Subject: [PATCH 2/2] wpa_supplicant: Fix configurable debug log feature's warning issue --- .../wpa_supplicant/include/utils/wpa_debug.h | 16 ++++++++-------- .../wpa_supplicant/src/eap_peer/eap_tls_common.c | 2 ++ .../wpa_supplicant/src/esp_supplicant/esp_wpa2.c | 4 +++- .../wpa_supplicant/src/wps/wps_registrar.c | 12 ++++++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/components/wpa_supplicant/include/utils/wpa_debug.h b/components/wpa_supplicant/include/utils/wpa_debug.h index 8f5cc8b914..e32c697fe9 100644 --- a/components/wpa_supplicant/include/utils/wpa_debug.h +++ b/components/wpa_supplicant/include/utils/wpa_debug.h @@ -145,14 +145,14 @@ void wpa_hexdump_ascii(int level, const char *title, const u8 *buf, void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf, size_t len); #else -#define wpa_printf(level,fmt, args...) -#define wpa_hexdump(...) -#define wpa_dump_mem(...) -#define wpa_hexdump_buf(...) -#define wpa_hexdump_key(...) -#define wpa_hexdump_buf_key(...) -#define wpa_hexdump_ascii(...) -#define wpa_hexdump_ascii_key(...) +#define wpa_printf(level,fmt, args...) do {} while(0) +#define wpa_hexdump(...) do {} while(0) +#define wpa_dump_mem(...) do {} while(0) +#define wpa_hexdump_buf(...) do {} while(0) +#define wpa_hexdump_key(...) do {} while(0) +#define wpa_hexdump_buf_key(...) do {} while(0) +#define wpa_hexdump_ascii(...) do {} while(0) +#define wpa_hexdump_ascii_key(...) do {} while(0) #endif #define wpa_auth_logger diff --git a/components/wpa_supplicant/src/eap_peer/eap_tls_common.c b/components/wpa_supplicant/src/eap_peer/eap_tls_common.c index 7e032685ee..7d2c925caa 100644 --- a/components/wpa_supplicant/src/eap_peer/eap_tls_common.c +++ b/components/wpa_supplicant/src/eap_peer/eap_tls_common.c @@ -1038,7 +1038,9 @@ get_defaults: int eap_peer_tls_phase2_nak(struct eap_method_type *types, size_t num_types, struct eap_hdr *hdr, struct wpabuf **resp) { +#ifdef DEBUG_PRINT u8 *pos = (u8 *) (hdr + 1); +#endif size_t i; /* TODO: add support for expanded Nak */ diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_wpa2.c b/components/wpa_supplicant/src/esp_supplicant/esp_wpa2.c index 3033d2ad54..cb11426210 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_wpa2.c +++ b/components/wpa_supplicant/src/esp_supplicant/esp_wpa2.c @@ -187,7 +187,6 @@ void wpa2_task(void *pvParameters ) ETSEvent *e; struct eap_sm *sm = gEapSm; bool task_del = false; - uint32_t sig = 0; if (!sm) { return; @@ -195,7 +194,10 @@ void wpa2_task(void *pvParameters ) for (;;) { if ( pdPASS == xQueueReceive(s_wpa2_queue, &e, portMAX_DELAY) ) { +#ifdef DEBUG_PRINT + uint32_t sig = 0; sig = e->sig; +#endif if (e->sig < SIG_WPA2_MAX) { DATA_MUTEX_TAKE(); if(sm->wpa2_sig_cnt[e->sig]) { diff --git a/components/wpa_supplicant/src/wps/wps_registrar.c b/components/wpa_supplicant/src/wps/wps_registrar.c index e197dfdc06..33f0859b20 100644 --- a/components/wpa_supplicant/src/wps/wps_registrar.c +++ b/components/wpa_supplicant/src/wps/wps_registrar.c @@ -2422,14 +2422,18 @@ static int wps_process_wps_state(struct wps_data *wps, const u8 *state) static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc) { - u16 a; +#ifdef DEBUG_PRINT + u16 a; +#endif if (assoc == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Association State received"); return -1; } +#ifdef DEBUG_PRINT a = WPA_GET_BE16(assoc); +#endif wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a); return 0; @@ -2438,14 +2442,18 @@ static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc) static int wps_process_config_error(struct wps_data *wps, const u8 *err) { - u16 e; +#ifdef DEBUG_PRINT + u16 e; +#endif if (err == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received"); return -1; } +#ifdef DEBUG_PRINT e = WPA_GET_BE16(err); +#endif wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e); return 0;