wpa_debug.h 7.0 KB

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