wpa_debug.h 7.1 KB

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