remove @EAP_LDFLAGS@, no longer exists
[mech_eap.orig] / libeap / src / utils / wpa_debug.h
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
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /* Debugging function - conditional printf and hex dump. Driver wrappers can
25  * use these for debugging purposes. */
26
27 enum {
28         MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
29 };
30
31 #ifdef CONFIG_NO_STDOUT_DEBUG
32
33 #define wpa_debug_print_timestamp() do { } while (0)
34 #define wpa_printf(args...) do { } while (0)
35 #define wpa_hexdump(l,t,b,le) do { } while (0)
36 #define wpa_hexdump_buf(l,t,b) do { } while (0)
37 #define wpa_hexdump_key(l,t,b,le) do { } while (0)
38 #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
39 #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
40 #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
41 #define wpa_debug_open_file(p) do { } while (0)
42 #define wpa_debug_close_file() do { } while (0)
43
44 #else /* CONFIG_NO_STDOUT_DEBUG */
45
46 int wpa_debug_open_file(const char *path);
47 void wpa_debug_close_file(void);
48
49 /**
50  * wpa_debug_printf_timestamp - Print timestamp for debug output
51  *
52  * This function prints a timestamp in seconds_from_1970.microsoconds
53  * format if debug output has been configured to include timestamps in debug
54  * messages.
55  */
56 void wpa_debug_print_timestamp(void);
57
58 /**
59  * wpa_printf - conditional printf
60  * @level: priority level (MSG_*) of the message
61  * @fmt: printf format string, followed by optional arguments
62  *
63  * This function is used to print conditional debugging and error messages. The
64  * output may be directed to stdout, stderr, and/or syslog based on
65  * configuration.
66  *
67  * Note: New line '\n' is added to the end of the text when printing to stdout.
68  */
69 void wpa_printf(int level, const char *fmt, ...)
70 PRINTF_FORMAT(2, 3);
71
72 /**
73  * wpa_hexdump - conditional hex dump
74  * @level: priority level (MSG_*) of the message
75  * @title: title of for the message
76  * @buf: data buffer to be dumped
77  * @len: length of the buf
78  *
79  * This function is used to print conditional debugging and error messages. The
80  * output may be directed to stdout, stderr, and/or syslog based on
81  * configuration. The contents of buf is printed out has hex dump.
82  */
83 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
84
85 static inline void wpa_hexdump_buf(int level, const char *title,
86                                    const struct wpabuf *buf)
87 {
88         wpa_hexdump(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
89 }
90
91 /**
92  * wpa_hexdump_key - conditional hex dump, hide keys
93  * @level: priority level (MSG_*) of the message
94  * @title: title of for the message
95  * @buf: data buffer to be dumped
96  * @len: length of the buf
97  *
98  * This function is used to print conditional debugging and error messages. The
99  * output may be directed to stdout, stderr, and/or syslog based on
100  * configuration. The contents of buf is printed out has hex dump. This works
101  * like wpa_hexdump(), but by default, does not include secret keys (passwords,
102  * etc.) in debug output.
103  */
104 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
105
106 static inline void wpa_hexdump_buf_key(int level, const char *title,
107                                        const struct wpabuf *buf)
108 {
109         wpa_hexdump_key(level, title, (const u8 *)wpabuf_head(buf), wpabuf_len(buf));
110 }
111
112 /**
113  * wpa_hexdump_ascii - conditional hex dump
114  * @level: priority level (MSG_*) of the message
115  * @title: title of for the message
116  * @buf: data buffer to be dumped
117  * @len: length of the buf
118  *
119  * This function is used to print conditional debugging and error messages. The
120  * output may be directed to stdout, stderr, and/or syslog based on
121  * configuration. The contents of buf is printed out has hex dump with both
122  * the hex numbers and ASCII characters (for printable range) are shown. 16
123  * bytes per line will be shown.
124  */
125 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
126                        size_t len);
127
128 /**
129  * wpa_hexdump_ascii_key - conditional hex dump, hide keys
130  * @level: priority level (MSG_*) of the message
131  * @title: title of for the message
132  * @buf: data buffer to be dumped
133  * @len: length of the buf
134  *
135  * This function is used to print conditional debugging and error messages. The
136  * output may be directed to stdout, stderr, and/or syslog based on
137  * configuration. The contents of buf is printed out has hex dump with both
138  * the hex numbers and ASCII characters (for printable range) are shown. 16
139  * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
140  * default, does not include secret keys (passwords, etc.) in debug output.
141  */
142 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
143                            size_t len);
144
145 #endif /* CONFIG_NO_STDOUT_DEBUG */
146
147
148 #ifdef CONFIG_NO_WPA_MSG
149 #define wpa_msg(args...) do { } while (0)
150 #define wpa_msg_ctrl(args...) do { } while (0)
151 #define wpa_msg_register_cb(f) do { } while (0)
152 #else /* CONFIG_NO_WPA_MSG */
153 /**
154  * wpa_msg - Conditional printf for default target and ctrl_iface monitors
155  * @ctx: Pointer to context data; this is the ctx variable registered
156  *      with struct wpa_driver_ops::init()
157  * @level: priority level (MSG_*) of the message
158  * @fmt: printf format string, followed by optional arguments
159  *
160  * This function is used to print conditional debugging and error messages. The
161  * output may be directed to stdout, stderr, and/or syslog based on
162  * configuration. This function is like wpa_printf(), but it also sends the
163  * same message to all attached ctrl_iface monitors.
164  *
165  * Note: New line '\n' is added to the end of the text when printing to stdout.
166  */
167 void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
168
169 /**
170  * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
171  * @ctx: Pointer to context data; this is the ctx variable registered
172  *      with struct wpa_driver_ops::init()
173  * @level: priority level (MSG_*) of the message
174  * @fmt: printf format string, followed by optional arguments
175  *
176  * This function is used to print conditional debugging and error messages.
177  * This function is like wpa_msg(), but it sends the output only to the
178  * attached ctrl_iface monitors. In other words, it can be used for frequent
179  * events that do not need to be sent to syslog.
180  */
181 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
182 PRINTF_FORMAT(3, 4);
183
184 typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
185                                 size_t len);
186
187 /**
188  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
189  * @func: Callback function (%NULL to unregister)
190  */
191 void wpa_msg_register_cb(wpa_msg_cb_func func);
192 #endif /* CONFIG_NO_WPA_MSG */
193
194
195 #ifdef CONFIG_NO_HOSTAPD_LOGGER
196 #define hostapd_logger(args...) do { } while (0)
197 #define hostapd_logger_register_cb(f) do { } while (0)
198 #else /* CONFIG_NO_HOSTAPD_LOGGER */
199 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
200                     const char *fmt, ...) PRINTF_FORMAT(5, 6);
201
202 typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
203                                        unsigned int module, int level,
204                                        const char *txt, size_t len);
205
206 /**
207  * hostapd_logger_register_cb - Register callback function for hostapd_logger()
208  * @func: Callback function (%NULL to unregister)
209  */
210 void hostapd_logger_register_cb(hostapd_logger_cb_func func);
211 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
212
213 #define HOSTAPD_MODULE_IEEE80211        0x00000001
214 #define HOSTAPD_MODULE_IEEE8021X        0x00000002
215 #define HOSTAPD_MODULE_RADIUS           0x00000004
216 #define HOSTAPD_MODULE_WPA              0x00000008
217 #define HOSTAPD_MODULE_DRIVER           0x00000010
218 #define HOSTAPD_MODULE_IAPP             0x00000020
219 #define HOSTAPD_MODULE_MLME             0x00000040
220
221 enum hostapd_logger_level {
222         HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
223         HOSTAPD_LEVEL_DEBUG = 1,
224         HOSTAPD_LEVEL_INFO = 2,
225         HOSTAPD_LEVEL_NOTICE = 3,
226         HOSTAPD_LEVEL_WARNING = 4
227 };
228
229
230 #ifdef CONFIG_DEBUG_SYSLOG
231
232 void wpa_debug_open_syslog(void);
233 void wpa_debug_close_syslog(void);
234
235 #else /* CONFIG_DEBUG_SYSLOG */
236
237 static inline void wpa_debug_open_syslog(void)
238 {
239 }
240
241 static inline void wpa_debug_close_syslog(void)
242 {
243 }
244
245 #endif /* CONFIG_DEBUG_SYSLOG */
246
247
248 #ifdef EAPOL_TEST
249 #define WPA_ASSERT(a)                                                  \
250         do {                                                           \
251                 if (!(a)) {                                            \
252                         printf("WPA_ASSERT FAILED '" #a "' "           \
253                                "%s %s:%d\n",                           \
254                                __FUNCTION__, __FILE__, __LINE__);      \
255                         exit(1);                                       \
256                 }                                                      \
257         } while (0)
258 #else
259 #define WPA_ASSERT(a) do { } while (0)
260 #endif
261
262 #ifdef __cplusplus
263 }
264 #endif
265
266 #endif /* WPA_DEBUG_H */