1 /*
2  * wpa_supplicant/hostapd / Debug prints
3  * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14 
15 #ifndef WPA_DEBUG_H
16 #define WPA_DEBUG_H
17 
18 #include "wpabuf.h"
19 #include "esp_log.h"
20 #include "supplicant_opt.h"
21 #define TAG "wpa"
22 
23 #ifdef ESPRESSIF_USE
24 
25 
26 #define MSG_ERROR ESP_LOG_ERROR
27 #define MSG_WARNING ESP_LOG_WARN
28 #define MSG_INFO ESP_LOG_INFO
29 #define MSG_DEBUG ESP_LOG_DEBUG
30 #define MSG_MSGDUMP ESP_LOG_VERBOSE
31 #define MSG_EXCESSIVE ESP_LOG_VERBOSE
32 
33 #else
34 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
35 #define MSG_EXCESSIVE MSG_DEBUG
36 #endif
37 
38 /** EAP authentication completed successfully */
39 #define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
40 
41 int wpa_debug_open_file(const char *path);
42 void wpa_debug_close_file(void);
43 
44 /**
45  * wpa_debug_printf_timestamp - Print timestamp for debug output
46  *
47  * This function prints a timestamp in seconds_from_1970.microsoconds
48  * format if debug output has been configured to include timestamps in debug
49  * messages.
50  */
51 void wpa_debug_print_timestamp(void);
52 
53 #ifdef DEBUG_PRINT
54 /**
55  * wpa_printf - conditional printf
56  * @level: priority level (MSG_*) of the message
57  * @fmt: printf format string, followed by optional arguments
58  *
59  * This function is used to print conditional debugging and error messages. The
60  * output may be directed to stdout, stderr, and/or syslog based on
61  * configuration.
62  *
63  * Note: New line '\n' is added to the end of the text when printing to stdout.
64  */
65 #define wpa_printf(level,fmt, args...) ESP_LOG_LEVEL_LOCAL(level, TAG, fmt, ##args)
66 #define wpa_dbg(ctx, level, fmt, args...) wpa_printf(level, fmt, ##args)
67 
68 void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len);
69 
70 /**
71  * wpa_hexdump - conditional hex dump
72  * @level: priority level (MSG_*) of the message
73  * @title: title of for the message
74  * @buf: data buffer to be dumped
75  * @len: length of the buf
76  *
77  * This function is used to print conditional debugging and error messages. The
78  * output may be directed to stdout, stderr, and/or syslog based on
79  * configuration. The contents of buf is printed out has hex dump.
80  */
81 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
82 
wpa_hexdump_ascii(int level,const char * title,const void * buf,size_t len)83 static inline void wpa_hexdump_ascii(int level, const char *title, const void *buf, size_t len)
84 {
85 	wpa_hexdump(level, title, buf, len);
86 }
87 
wpa_hexdump_ascii_key(int level,const char * title,const void * buf,size_t len)88 static inline void wpa_hexdump_ascii_key(int level, const char *title, const void *buf, size_t len)
89 {
90 	wpa_hexdump(level, title, buf, len);
91 }
92 
wpa_hexdump_buf(int level,const char * title,const struct wpabuf * buf)93 static inline void wpa_hexdump_buf(int level, const char *title,
94 				   const struct wpabuf *buf)
95 {
96 	wpa_hexdump(level, title, wpabuf_head(buf), wpabuf_len(buf));
97 }
98 
99 /**
100  * wpa_hexdump_key - conditional hex dump, hide keys
101  * @level: priority level (MSG_*) of the message
102  * @title: title of for the message
103  * @buf: data buffer to be dumped
104  * @len: length of the buf
105  *
106  * This function is used to print conditional debugging and error messages. The
107  * output may be directed to stdout, stderr, and/or syslog based on
108  * configuration. The contents of buf is printed out has hex dump. This works
109  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
110  * etc.) in debug output.
111  */
112 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
113 
wpa_hexdump_buf_key(int level,const char * title,const struct wpabuf * buf)114 static inline void wpa_hexdump_buf_key(int level, const char *title,
115 				       const struct wpabuf *buf)
116 {
117 	wpa_hexdump_key(level, title, wpabuf_head(buf), wpabuf_len(buf));
118 }
119 
120 /**
121  * wpa_hexdump_ascii - conditional hex dump
122  * @level: priority level (MSG_*) of the message
123  * @title: title of for the message
124  * @buf: data buffer to be dumped
125  * @len: length of the buf
126  *
127  * This function is used to print conditional debugging and error messages. The
128  * output may be directed to stdout, stderr, and/or syslog based on
129  * configuration. The contents of buf is printed out has hex dump with both
130  * the hex numbers and ASCII characters (for printable range) are shown. 16
131  * bytes per line will be shown.
132  */
133 void wpa_hexdump_ascii(int level, const char *title, const void *buf,
134 		       size_t len);
135 
136 /**
137  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
138  * @level: priority level (MSG_*) of the message
139  * @title: title of for the message
140  * @buf: data buffer to be dumped
141  * @len: length of the buf
142  *
143  * This function is used to print conditional debugging and error messages. The
144  * output may be directed to stdout, stderr, and/or syslog based on
145  * configuration. The contents of buf is printed out has hex dump with both
146  * the hex numbers and ASCII characters (for printable range) are shown. 16
147  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
148  * default, does not include secret keys (passwords, etc.) in debug output.
149  */
150 void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
151 			   size_t len);
152 #else
153 #define wpa_printf(level,fmt, args...) do {} while(0)
154 #define wpa_hexdump(...) do {} while(0)
155 #define wpa_dump_mem(...) do {} while(0)
156 #define wpa_hexdump_buf(...) do {} while(0)
157 #define wpa_hexdump_key(...) do {} while(0)
158 #define wpa_hexdump_buf_key(...) do {} while(0)
159 #define wpa_hexdump_ascii(...) do {} while(0)
160 #define wpa_hexdump_ascii_key(...) do {} while(0)
161 #define wpa_dbg(...) do {} while(0)
162 #endif
163 
164 #define wpa_auth_logger(...) do {} while(0)
165 #define wpa_auth_vlogger(...) do {} while(0)
166 
167 /**
168  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
169  * @ctx: Pointer to context data; this is the ctx variable registered
170  *	with struct wpa_driver_ops::init()
171  * @level: priority level (MSG_*) of the message
172  * @fmt: printf format string, followed by optional arguments
173  *
174  * This function is used to print conditional debugging and error messages. The
175  * output may be directed to stdout, stderr, and/or syslog based on
176  * configuration. This function is like wpa_printf(), but it also sends the
177  * same message to all attached ctrl_iface monitors.
178  *
179  * Note: New line '\n' is added to the end of the text when printing to stdout.
180  */
181 #define wpa_msg(...) do {} while(0)
182 
183 /**
184  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
185  * @ctx: Pointer to context data; this is the ctx variable registered
186  *	with struct wpa_driver_ops::init()
187  * @level: priority level (MSG_*) of the message
188  * @fmt: printf format string, followed by optional arguments
189  *
190  * This function is used to print conditional debugging and error messages.
191  * This function is like wpa_msg(), but it sends the output only to the
192  * attached ctrl_iface monitors. In other words, it can be used for frequent
193  * events that do not need to be sent to syslog.
194  */
195 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
196 PRINTF_FORMAT(3, 4);
197 
198 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
199 				size_t len);
200 
201 #endif /* WPA_DEBUG_H */
202