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 
22 #ifdef ESPRESSIF_USE
23 
24 #define TAG "wpa"
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 #endif
36 
37 /** EAP authentication completed successfully */
38 #define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
39 
40 int wpa_debug_open_file(const char *path);
41 void wpa_debug_close_file(void);
42 
43 /**
44  * wpa_debug_printf_timestamp - Print timestamp for debug output
45  *
46  * This function prints a timestamp in seconds_from_1970.microsoconds
47  * format if debug output has been configured to include timestamps in debug
48  * messages.
49  */
50 void wpa_debug_print_timestamp(void);
51 
52 #ifdef DEBUG_PRINT
53 /**
54  * wpa_printf - conditional printf
55  * @level: priority level (MSG_*) of the message
56  * @fmt: printf format string, followed by optional arguments
57  *
58  * This function is used to print conditional debugging and error messages. The
59  * output may be directed to stdout, stderr, and/or syslog based on
60  * configuration.
61  *
62  * Note: New line '\n' is added to the end of the text when printing to stdout.
63  */
64 #define wpa_printf(level,fmt, args...) ESP_LOG_LEVEL_LOCAL(level, TAG, fmt, ##args)
65 #define wpa_dbg(ctx, level, fmt, args...) wpa_printf(level, fmt, ##args)
66 
67 void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len);
wpa_hexdump_ascii(int level,const char * title,const u8 * buf,size_t len)68 static inline void wpa_hexdump_ascii(int level, const char *title, const u8 *buf, size_t len)
69 {
70 
71 }
72 
wpa_hexdump_ascii_key(int level,const char * title,const u8 * buf,size_t len)73 static inline void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf, size_t len)
74 {
75 }
76 
77 /**
78  * wpa_hexdump - conditional hex dump
79  * @level: priority level (MSG_*) of the message
80  * @title: title of for the message
81  * @buf: data buffer to be dumped
82  * @len: length of the buf
83  *
84  * This function is used to print conditional debugging and error messages. The
85  * output may be directed to stdout, stderr, and/or syslog based on
86  * configuration. The contents of buf is printed out has hex dump.
87  */
88 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
89 
wpa_hexdump_buf(int level,const char * title,const struct wpabuf * buf)90 static inline void wpa_hexdump_buf(int level, const char *title,
91 				   const struct wpabuf *buf)
92 {
93 	wpa_hexdump(level, title, wpabuf_head(buf), wpabuf_len(buf));
94 }
95 
96 /**
97  * wpa_hexdump_key - conditional hex dump, hide keys
98  * @level: priority level (MSG_*) of the message
99  * @title: title of for the message
100  * @buf: data buffer to be dumped
101  * @len: length of the buf
102  *
103  * This function is used to print conditional debugging and error messages. The
104  * output may be directed to stdout, stderr, and/or syslog based on
105  * configuration. The contents of buf is printed out has hex dump. This works
106  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
107  * etc.) in debug output.
108  */
109 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
110 
111 
wpa_hexdump_buf_key(int level,const char * title,const struct wpabuf * buf)112 static inline void wpa_hexdump_buf_key(int level, const char *title,
113 				       const struct wpabuf *buf)
114 {
115 	wpa_hexdump_key(level, title, wpabuf_head(buf), wpabuf_len(buf));
116 }
117 
118 /**
119  * wpa_hexdump_ascii - conditional hex dump
120  * @level: priority level (MSG_*) of the message
121  * @title: title of for the message
122  * @buf: data buffer to be dumped
123  * @len: length of the buf
124  *
125  * This function is used to print conditional debugging and error messages. The
126  * output may be directed to stdout, stderr, and/or syslog based on
127  * configuration. The contents of buf is printed out has hex dump with both
128  * the hex numbers and ASCII characters (for printable range) are shown. 16
129  * bytes per line will be shown.
130  */
131 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
132 		       size_t len);
133 
134 /**
135  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
136  * @level: priority level (MSG_*) of the message
137  * @title: title of for the message
138  * @buf: data buffer to be dumped
139  * @len: length of the buf
140  *
141  * This function is used to print conditional debugging and error messages. The
142  * output may be directed to stdout, stderr, and/or syslog based on
143  * configuration. The contents of buf is printed out has hex dump with both
144  * the hex numbers and ASCII characters (for printable range) are shown. 16
145  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
146  * default, does not include secret keys (passwords, etc.) in debug output.
147  */
148 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
149 			   size_t len);
150 #else
151 #define wpa_printf(level,fmt, args...) do {} while(0)
152 #define wpa_hexdump(...) do {} while(0)
153 #define wpa_dump_mem(...) do {} while(0)
154 #define wpa_hexdump_buf(...) do {} while(0)
155 #define wpa_hexdump_key(...) do {} while(0)
156 #define wpa_hexdump_buf_key(...) do {} while(0)
157 #define wpa_hexdump_ascii(...) do {} while(0)
158 #define wpa_hexdump_ascii_key(...) do {} while(0)
159 #define wpa_dbg(...) do {} while(0)
160 #endif
161 
162 #define wpa_auth_logger
163 #define wpa_auth_vlogger
164 
165 /**
166  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
167  * @ctx: Pointer to context data; this is the ctx variable registered
168  *	with struct wpa_driver_ops::init()
169  * @level: priority level (MSG_*) of the message
170  * @fmt: printf format string, followed by optional arguments
171  *
172  * This function is used to print conditional debugging and error messages. The
173  * output may be directed to stdout, stderr, and/or syslog based on
174  * configuration. This function is like wpa_printf(), but it also sends the
175  * same message to all attached ctrl_iface monitors.
176  *
177  * Note: New line '\n' is added to the end of the text when printing to stdout.
178  */
179 #define wpa_msg(...) do {} while(0)
180 
181 /**
182  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
183  * @ctx: Pointer to context data; this is the ctx variable registered
184  *	with struct wpa_driver_ops::init()
185  * @level: priority level (MSG_*) of the message
186  * @fmt: printf format string, followed by optional arguments
187  *
188  * This function is used to print conditional debugging and error messages.
189  * This function is like wpa_msg(), but it sends the output only to the
190  * attached ctrl_iface monitors. In other words, it can be used for frequent
191  * events that do not need to be sent to syslog.
192  */
193 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
194 PRINTF_FORMAT(3, 4);
195 
196 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
197 				size_t len);
198 
199 typedef void (*eloop_timeout_handler)(void *eloop_data, void *user_ctx);
200 
201 int eloop_cancel_timeout(eloop_timeout_handler handler,
202 			 void *eloop_data, void *user_data);
203 
204 int eloop_register_timeout(unsigned int secs, unsigned int usecs,
205 			   eloop_timeout_handler handler,
206 			   void *eloop_data, void *user_data);
207 
208 
209 #endif /* WPA_DEBUG_H */
210