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