| 1 | --- a/src/utils/wpa_debug.c |
| 2 | +++ b/src/utils/wpa_debug.c |
| 3 | @@ -129,7 +129,7 @@ static int syslog_priority(int level) |
| 4 | * |
| 5 | * Note: New line '\n' is added to the end of the text when printing to stdout. |
| 6 | */ |
| 7 | -void wpa_printf(int level, const char *fmt, ...) |
| 8 | +void _wpa_printf(int level, const char *fmt, ...) |
| 9 | { |
| 10 | va_list ap; |
| 11 | |
| 12 | @@ -160,8 +160,8 @@ void wpa_printf(int level, const char *f |
| 13 | } |
| 14 | |
| 15 | |
| 16 | -static void _wpa_hexdump(int level, const char *title, const u8 *buf, |
| 17 | - size_t len, int show) |
| 18 | +void _wpa_hexdump(int level, const char *title, const u8 *buf, |
| 19 | + size_t len, int show) |
| 20 | { |
| 21 | size_t i; |
| 22 | if (level < wpa_debug_level) |
| 23 | @@ -197,20 +197,9 @@ static void _wpa_hexdump(int level, cons |
| 24 | #endif /* CONFIG_DEBUG_FILE */ |
| 25 | } |
| 26 | |
| 27 | -void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len) |
| 28 | -{ |
| 29 | - _wpa_hexdump(level, title, buf, len, 1); |
| 30 | -} |
| 31 | - |
| 32 | - |
| 33 | -void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len) |
| 34 | -{ |
| 35 | - _wpa_hexdump(level, title, buf, len, wpa_debug_show_keys); |
| 36 | -} |
| 37 | |
| 38 | - |
| 39 | -static void _wpa_hexdump_ascii(int level, const char *title, const u8 *buf, |
| 40 | - size_t len, int show) |
| 41 | +void _wpa_hexdump_ascii(int level, const char *title, const u8 *buf, |
| 42 | + size_t len, int show) |
| 43 | { |
| 44 | size_t i, llen; |
| 45 | const u8 *pos = buf; |
| 46 | @@ -294,19 +283,6 @@ static void _wpa_hexdump_ascii(int level |
| 47 | } |
| 48 | |
| 49 | |
| 50 | -void wpa_hexdump_ascii(int level, const char *title, const u8 *buf, size_t len) |
| 51 | -{ |
| 52 | - _wpa_hexdump_ascii(level, title, buf, len, 1); |
| 53 | -} |
| 54 | - |
| 55 | - |
| 56 | -void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf, |
| 57 | - size_t len) |
| 58 | -{ |
| 59 | - _wpa_hexdump_ascii(level, title, buf, len, wpa_debug_show_keys); |
| 60 | -} |
| 61 | - |
| 62 | - |
| 63 | #ifdef CONFIG_DEBUG_FILE |
| 64 | static char *last_path = NULL; |
| 65 | #endif /* CONFIG_DEBUG_FILE */ |
| 66 | @@ -391,7 +367,7 @@ void wpa_msg_register_ifname_cb(wpa_msg_ |
| 67 | } |
| 68 | |
| 69 | |
| 70 | -void wpa_msg(void *ctx, int level, const char *fmt, ...) |
| 71 | +void _wpa_msg(void *ctx, int level, const char *fmt, ...) |
| 72 | { |
| 73 | va_list ap; |
| 74 | char *buf; |
| 75 | @@ -425,7 +401,7 @@ void wpa_msg(void *ctx, int level, const |
| 76 | } |
| 77 | |
| 78 | |
| 79 | -void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...) |
| 80 | +void _wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...) |
| 81 | { |
| 82 | va_list ap; |
| 83 | char *buf; |
| 84 | --- a/src/utils/wpa_debug.h |
| 85 | +++ b/src/utils/wpa_debug.h |
| 86 | @@ -75,6 +75,17 @@ int wpa_debug_open_file(const char *path |
| 87 | int wpa_debug_reopen_file(void); |
| 88 | void wpa_debug_close_file(void); |
| 89 | |
| 90 | +/* internal */ |
| 91 | +void _wpa_hexdump(int level, const char *title, const u8 *buf, |
| 92 | + size_t len, int show); |
| 93 | +void _wpa_hexdump_ascii(int level, const char *title, const u8 *buf, |
| 94 | + size_t len, int show); |
| 95 | +extern int wpa_debug_show_keys; |
| 96 | + |
| 97 | +#ifndef CONFIG_MSG_MIN_PRIORITY |
| 98 | +#define CONFIG_MSG_MIN_PRIORITY 0 |
| 99 | +#endif |
| 100 | + |
| 101 | /** |
| 102 | * wpa_debug_printf_timestamp - Print timestamp for debug output |
| 103 | * |
| 104 | @@ -95,9 +106,15 @@ void wpa_debug_print_timestamp(void); |
| 105 | * |
| 106 | * Note: New line '\n' is added to the end of the text when printing to stdout. |
| 107 | */ |
| 108 | -void wpa_printf(int level, const char *fmt, ...) |
| 109 | +void _wpa_printf(int level, const char *fmt, ...) |
| 110 | PRINTF_FORMAT(2, 3); |
| 111 | |
| 112 | +#define wpa_printf(level, ...) \ |
| 113 | + do { \ |
| 114 | + if (level >= CONFIG_MSG_MIN_PRIORITY) \ |
| 115 | + _wpa_printf(level, __VA_ARGS__); \ |
| 116 | + } while(0) |
| 117 | + |
| 118 | /** |
| 119 | * wpa_hexdump - conditional hex dump |
| 120 | * @level: priority level (MSG_*) of the message |
| 121 | @@ -109,7 +126,13 @@ PRINTF_FORMAT(2, 3); |
| 122 | * output may be directed to stdout, stderr, and/or syslog based on |
| 123 | * configuration. The contents of buf is printed out has hex dump. |
| 124 | */ |
| 125 | -void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len); |
| 126 | +static inline void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len) |
| 127 | +{ |
| 128 | + if (level < CONFIG_MSG_MIN_PRIORITY) |
| 129 | + return; |
| 130 | + |
| 131 | + _wpa_hexdump(level, title, buf, len, 1); |
| 132 | +} |
| 133 | |
| 134 | static inline void wpa_hexdump_buf(int level, const char *title, |
| 135 | const struct wpabuf *buf) |
| 136 | @@ -131,7 +154,13 @@ static inline void wpa_hexdump_buf(int l |
| 137 | * like wpa_hexdump(), but by default, does not include secret keys (passwords, |
| 138 | * etc.) in debug output. |
| 139 | */ |
| 140 | -void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len); |
| 141 | +static inline void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len) |
| 142 | +{ |
| 143 | + if (level < CONFIG_MSG_MIN_PRIORITY) |
| 144 | + return; |
| 145 | + |
| 146 | + _wpa_hexdump(level, title, buf, len, wpa_debug_show_keys); |
| 147 | +} |
| 148 | |
| 149 | static inline void wpa_hexdump_buf_key(int level, const char *title, |
| 150 | const struct wpabuf *buf) |
| 151 | @@ -153,8 +182,14 @@ static inline void wpa_hexdump_buf_key(i |
| 152 | * the hex numbers and ASCII characters (for printable range) are shown. 16 |
| 153 | * bytes per line will be shown. |
| 154 | */ |
| 155 | -void wpa_hexdump_ascii(int level, const char *title, const u8 *buf, |
| 156 | - size_t len); |
| 157 | +static inline void wpa_hexdump_ascii(int level, const char *title, |
| 158 | + const u8 *buf, size_t len) |
| 159 | +{ |
| 160 | + if (level < CONFIG_MSG_MIN_PRIORITY) |
| 161 | + return; |
| 162 | + |
| 163 | + _wpa_hexdump_ascii(level, title, buf, len, 1); |
| 164 | +} |
| 165 | |
| 166 | /** |
| 167 | * wpa_hexdump_ascii_key - conditional hex dump, hide keys |
| 168 | @@ -170,8 +205,14 @@ void wpa_hexdump_ascii(int level, const |
| 169 | * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by |
| 170 | * default, does not include secret keys (passwords, etc.) in debug output. |
| 171 | */ |
| 172 | -void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf, |
| 173 | - size_t len); |
| 174 | +static inline void wpa_hexdump_ascii_key(int level, const char *title, |
| 175 | + const u8 *buf, size_t len) |
| 176 | +{ |
| 177 | + if (level < CONFIG_MSG_MIN_PRIORITY) |
| 178 | + return; |
| 179 | + |
| 180 | + _wpa_hexdump_ascii(level, title, buf, len, wpa_debug_show_keys); |
| 181 | +} |
| 182 | |
| 183 | /* |
| 184 | * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce |
| 185 | @@ -206,7 +247,12 @@ void wpa_hexdump_ascii_key(int level, co |
| 186 | * |
| 187 | * Note: New line '\n' is added to the end of the text when printing to stdout. |
| 188 | */ |
| 189 | -void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4); |
| 190 | +void _wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4); |
| 191 | +#define wpa_msg(ctx, level, ...) \ |
| 192 | + do { \ |
| 193 | + if (level >= CONFIG_MSG_MIN_PRIORITY) \ |
| 194 | + _wpa_msg(ctx, level, __VA_ARGS__); \ |
| 195 | + } while(0) |
| 196 | |
| 197 | /** |
| 198 | * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors |
| 199 | @@ -220,8 +266,13 @@ void wpa_msg(void *ctx, int level, const |
| 200 | * attached ctrl_iface monitors. In other words, it can be used for frequent |
| 201 | * events that do not need to be sent to syslog. |
| 202 | */ |
| 203 | -void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...) |
| 204 | +void _wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...) |
| 205 | PRINTF_FORMAT(3, 4); |
| 206 | +#define wpa_msg_ctrl(ctx, level, ...) \ |
| 207 | + do { \ |
| 208 | + if (level >= CONFIG_MSG_MIN_PRIORITY) \ |
| 209 | + _wpa_msg_ctrl(ctx, level, __VA_ARGS__); \ |
| 210 | + } while(0) |
| 211 | |
| 212 | typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt, |
| 213 | size_t len); |
| 214 | |