wpa_debug.h 8.5 KB

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