wpa_debug.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * wpa_supplicant/hostapd / Debug prints
  3. * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef WPA_DEBUG_H
  9. #define WPA_DEBUG_H
  10. #include "wpabuf.h"
  11. extern int wpa_debug_level;
  12. extern int wpa_debug_show_keys;
  13. extern int wpa_debug_timestamp;
  14. /* Debugging function - conditional printf and hex dump. Driver wrappers can
  15. * use these for debugging purposes. */
  16. enum {
  17. MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
  18. };
  19. #ifdef CONFIG_NO_STDOUT_DEBUG
  20. #define wpa_debug_print_timestamp() do { } while (0)
  21. #define wpa_printf(args...) do { } while (0)
  22. #define wpa_hexdump(l,t,b,le) do { } while (0)
  23. #define wpa_hexdump_buf(l,t,b) do { } while (0)
  24. #define wpa_hexdump_key(l,t,b,le) do { } while (0)
  25. #define wpa_hexdump_buf_key(l,t,b) do { } while (0)
  26. #define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
  27. #define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
  28. #define wpa_debug_open_file(p) do { } while (0)
  29. #define wpa_debug_close_file() do { } while (0)
  30. #define wpa_debug_setup_stdout() do { } while (0)
  31. #define wpa_dbg(args...) do { } while (0)
  32. static inline int wpa_debug_reopen_file(void)
  33. {
  34. return 0;
  35. }
  36. #else /* CONFIG_NO_STDOUT_DEBUG */
  37. int wpa_debug_open_file(const char *path);
  38. int wpa_debug_reopen_file(void);
  39. void wpa_debug_close_file(void);
  40. void wpa_debug_setup_stdout(void);
  41. /**
  42. * wpa_debug_printf_timestamp - Print timestamp for debug output
  43. *
  44. * This function prints a timestamp in seconds_from_1970.microsoconds
  45. * format if debug output has been configured to include timestamps in debug
  46. * messages.
  47. */
  48. void wpa_debug_print_timestamp(void);
  49. /**
  50. * wpa_printf - conditional printf
  51. * @level: priority level (MSG_*) of the message
  52. * @fmt: printf format string, followed by optional arguments
  53. *
  54. * This function is used to print conditional debugging and error messages. The
  55. * output may be directed to stdout, stderr, and/or syslog based on
  56. * configuration.
  57. *
  58. * Note: New line '\n' is added to the end of the text when printing to stdout.
  59. */
  60. void wpa_printf(int level, const char *fmt, ...)
  61. PRINTF_FORMAT(2, 3);
  62. /**
  63. * wpa_hexdump - conditional hex dump
  64. * @level: priority level (MSG_*) of the message
  65. * @title: title of for the message
  66. * @buf: data buffer to be dumped
  67. * @len: length of the buf
  68. *
  69. * This function is used to print conditional debugging and error messages. The
  70. * output may be directed to stdout, stderr, and/or syslog based on
  71. * configuration. The contents of buf is printed out has hex dump.
  72. */
  73. void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
  74. static inline void wpa_hexdump_buf(int level, const char *title,
  75. const struct wpabuf *buf)
  76. {
  77. wpa_hexdump(level, title, buf ? wpabuf_head(buf) : NULL,
  78. buf ? wpabuf_len(buf) : 0);
  79. }
  80. /**
  81. * wpa_hexdump_key - conditional hex dump, hide keys
  82. * @level: priority level (MSG_*) of the message
  83. * @title: title of for the message
  84. * @buf: data buffer to be dumped
  85. * @len: length of the buf
  86. *
  87. * This function is used to print conditional debugging and error messages. The
  88. * output may be directed to stdout, stderr, and/or syslog based on
  89. * configuration. The contents of buf is printed out has hex dump. This works
  90. * like wpa_hexdump(), but by default, does not include secret keys (passwords,
  91. * etc.) in debug output.
  92. */
  93. void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
  94. static inline void wpa_hexdump_buf_key(int level, const char *title,
  95. const struct wpabuf *buf)
  96. {
  97. wpa_hexdump_key(level, title, buf ? wpabuf_head(buf) : NULL,
  98. buf ? wpabuf_len(buf) : 0);
  99. }
  100. /**
  101. * wpa_hexdump_ascii - conditional hex dump
  102. * @level: priority level (MSG_*) of the message
  103. * @title: title of for the message
  104. * @buf: data buffer to be dumped
  105. * @len: length of the buf
  106. *
  107. * This function is used to print conditional debugging and error messages. The
  108. * output may be directed to stdout, stderr, and/or syslog based on
  109. * configuration. The contents of buf is printed out has hex dump with both
  110. * the hex numbers and ASCII characters (for printable range) are shown. 16
  111. * bytes per line will be shown.
  112. */
  113. void wpa_hexdump_ascii(int level, const char *title, const void *buf,
  114. size_t len);
  115. /**
  116. * wpa_hexdump_ascii_key - conditional hex dump, hide keys
  117. * @level: priority level (MSG_*) of the message
  118. * @title: title of for the message
  119. * @buf: data buffer to be dumped
  120. * @len: length of the buf
  121. *
  122. * This function is used to print conditional debugging and error messages. The
  123. * output may be directed to stdout, stderr, and/or syslog based on
  124. * configuration. The contents of buf is printed out has hex dump with both
  125. * the hex numbers and ASCII characters (for printable range) are shown. 16
  126. * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
  127. * default, does not include secret keys (passwords, etc.) in debug output.
  128. */
  129. void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
  130. size_t len);
  131. /*
  132. * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
  133. * binary size. As such, it should be used with debugging messages that are not
  134. * needed in the control interface while wpa_msg() has to be used for anything
  135. * that needs to shown to control interface monitors.
  136. */
  137. #define wpa_dbg(args...) wpa_msg(args)
  138. #endif /* CONFIG_NO_STDOUT_DEBUG */
  139. #ifdef CONFIG_NO_WPA_MSG
  140. #define wpa_msg(args...) do { } while (0)
  141. #define wpa_msg_ctrl(args...) do { } while (0)
  142. #define wpa_msg_global(args...) do { } while (0)
  143. #define wpa_msg_global_ctrl(args...) do { } while (0)
  144. #define wpa_msg_no_global(args...) do { } while (0)
  145. #define wpa_msg_global_only(args...) do { } while (0)
  146. #define wpa_msg_register_cb(f) do { } while (0)
  147. #define wpa_msg_register_ifname_cb(f) do { } while (0)
  148. #else /* CONFIG_NO_WPA_MSG */
  149. /**
  150. * wpa_msg - Conditional printf for default target and ctrl_iface monitors
  151. * @ctx: Pointer to context data; this is the ctx variable registered
  152. * with struct wpa_driver_ops::init()
  153. * @level: priority level (MSG_*) of the message
  154. * @fmt: printf format string, followed by optional arguments
  155. *
  156. * This function is used to print conditional debugging and error messages. The
  157. * output may be directed to stdout, stderr, and/or syslog based on
  158. * configuration. This function is like wpa_printf(), but it also sends the
  159. * same message to all attached ctrl_iface monitors.
  160. *
  161. * Note: New line '\n' is added to the end of the text when printing to stdout.
  162. */
  163. void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
  164. /**
  165. * wpa_msg_ctrl - Conditional printf for 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.
  172. * This function is like wpa_msg(), but it sends the output only to the
  173. * attached ctrl_iface monitors. In other words, it can be used for frequent
  174. * events that do not need to be sent to syslog.
  175. */
  176. void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  177. PRINTF_FORMAT(3, 4);
  178. /**
  179. * wpa_msg_global - Global printf for ctrl_iface monitors
  180. * @ctx: Pointer to context data; this is the ctx variable registered
  181. * with struct wpa_driver_ops::init()
  182. * @level: priority level (MSG_*) of the message
  183. * @fmt: printf format string, followed by optional arguments
  184. *
  185. * This function is used to print conditional debugging and error messages.
  186. * This function is like wpa_msg(), but it sends the output as a global event,
  187. * i.e., without being specific to an interface. For backwards compatibility,
  188. * an old style event is also delivered on one of the interfaces (the one
  189. * specified by the context data).
  190. */
  191. void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
  192. PRINTF_FORMAT(3, 4);
  193. /**
  194. * wpa_msg_global_ctrl - Conditional global printf for ctrl_iface monitors
  195. * @ctx: Pointer to context data; this is the ctx variable registered
  196. * with struct wpa_driver_ops::init()
  197. * @level: priority level (MSG_*) of the message
  198. * @fmt: printf format string, followed by optional arguments
  199. *
  200. * This function is used to print conditional debugging and error messages.
  201. * This function is like wpa_msg_global(), but it sends the output only to the
  202. * attached global ctrl_iface monitors. In other words, it can be used for
  203. * frequent events that do not need to be sent to syslog.
  204. */
  205. void wpa_msg_global_ctrl(void *ctx, int level, const char *fmt, ...)
  206. PRINTF_FORMAT(3, 4);
  207. /**
  208. * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
  209. * @ctx: Pointer to context data; this is the ctx variable registered
  210. * with struct wpa_driver_ops::init()
  211. * @level: priority level (MSG_*) of the message
  212. * @fmt: printf format string, followed by optional arguments
  213. *
  214. * This function is used to print conditional debugging and error messages.
  215. * This function is like wpa_msg(), but it does not send the output as a global
  216. * event.
  217. */
  218. void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
  219. PRINTF_FORMAT(3, 4);
  220. /**
  221. * wpa_msg_global_only - Conditional printf for ctrl_iface monitors
  222. * @ctx: Pointer to context data; this is the ctx variable registered
  223. * with struct wpa_driver_ops::init()
  224. * @level: priority level (MSG_*) of the message
  225. * @fmt: printf format string, followed by optional arguments
  226. *
  227. * This function is used to print conditional debugging and error messages.
  228. * This function is like wpa_msg_global(), but it sends the output only as a
  229. * global event.
  230. */
  231. void wpa_msg_global_only(void *ctx, int level, const char *fmt, ...)
  232. PRINTF_FORMAT(3, 4);
  233. enum wpa_msg_type {
  234. WPA_MSG_PER_INTERFACE,
  235. WPA_MSG_GLOBAL,
  236. WPA_MSG_NO_GLOBAL,
  237. WPA_MSG_ONLY_GLOBAL,
  238. };
  239. typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
  240. const char *txt, size_t len);
  241. /**
  242. * wpa_msg_register_cb - Register callback function for wpa_msg() messages
  243. * @func: Callback function (%NULL to unregister)
  244. */
  245. void wpa_msg_register_cb(wpa_msg_cb_func func);
  246. typedef const char * (*wpa_msg_get_ifname_func)(void *ctx);
  247. void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
  248. #endif /* CONFIG_NO_WPA_MSG */
  249. #ifdef CONFIG_NO_HOSTAPD_LOGGER
  250. #define hostapd_logger(args...) do { } while (0)
  251. #define hostapd_logger_register_cb(f) do { } while (0)
  252. #else /* CONFIG_NO_HOSTAPD_LOGGER */
  253. void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
  254. const char *fmt, ...) PRINTF_FORMAT(5, 6);
  255. typedef void (*hostapd_logger_cb_func)(void *ctx, const u8 *addr,
  256. unsigned int module, int level,
  257. const char *txt, size_t len);
  258. /**
  259. * hostapd_logger_register_cb - Register callback function for hostapd_logger()
  260. * @func: Callback function (%NULL to unregister)
  261. */
  262. void hostapd_logger_register_cb(hostapd_logger_cb_func func);
  263. #endif /* CONFIG_NO_HOSTAPD_LOGGER */
  264. #define HOSTAPD_MODULE_IEEE80211 0x00000001
  265. #define HOSTAPD_MODULE_IEEE8021X 0x00000002
  266. #define HOSTAPD_MODULE_RADIUS 0x00000004
  267. #define HOSTAPD_MODULE_WPA 0x00000008
  268. #define HOSTAPD_MODULE_DRIVER 0x00000010
  269. #define HOSTAPD_MODULE_IAPP 0x00000020
  270. #define HOSTAPD_MODULE_MLME 0x00000040
  271. enum hostapd_logger_level {
  272. HOSTAPD_LEVEL_DEBUG_VERBOSE = 0,
  273. HOSTAPD_LEVEL_DEBUG = 1,
  274. HOSTAPD_LEVEL_INFO = 2,
  275. HOSTAPD_LEVEL_NOTICE = 3,
  276. HOSTAPD_LEVEL_WARNING = 4
  277. };
  278. #ifdef CONFIG_DEBUG_SYSLOG
  279. void wpa_debug_open_syslog(void);
  280. void wpa_debug_close_syslog(void);
  281. #else /* CONFIG_DEBUG_SYSLOG */
  282. static inline void wpa_debug_open_syslog(void)
  283. {
  284. }
  285. static inline void wpa_debug_close_syslog(void)
  286. {
  287. }
  288. #endif /* CONFIG_DEBUG_SYSLOG */
  289. #ifdef CONFIG_DEBUG_LINUX_TRACING
  290. int wpa_debug_open_linux_tracing(void);
  291. void wpa_debug_close_linux_tracing(void);
  292. #else /* CONFIG_DEBUG_LINUX_TRACING */
  293. static inline int wpa_debug_open_linux_tracing(void)
  294. {
  295. return 0;
  296. }
  297. static inline void wpa_debug_close_linux_tracing(void)
  298. {
  299. }
  300. #endif /* CONFIG_DEBUG_LINUX_TRACING */
  301. #ifdef EAPOL_TEST
  302. #define WPA_ASSERT(a) \
  303. do { \
  304. if (!(a)) { \
  305. printf("WPA_ASSERT FAILED '" #a "' " \
  306. "%s %s:%d\n", \
  307. __FUNCTION__, __FILE__, __LINE__); \
  308. exit(1); \
  309. } \
  310. } while (0)
  311. #else
  312. #define WPA_ASSERT(a) do { } while (0)
  313. #endif
  314. const char * debug_level_str(int level);
  315. int str_to_debug_level(const char *s);
  316. #endif /* WPA_DEBUG_H */