wpa_debug.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /**
  58. * wpa_hexdump - conditional hex dump
  59. * @level: priority level (MSG_*) of the message
  60. * @title: title of for the message
  61. * @buf: data buffer to be dumped
  62. * @len: length of the buf
  63. *
  64. * This function is used to print conditional debugging and error messages. The
  65. * output may be directed to stdout, stderr, and/or syslog based on
  66. * configuration. The contents of buf is printed out has hex dump.
  67. */
  68. void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
  69. static inline void wpa_hexdump_ascii(int level, const char *title, const void *buf, size_t len)
  70. {
  71. wpa_hexdump(level, title, buf, len);
  72. }
  73. static inline void wpa_hexdump_ascii_key(int level, const char *title, const void *buf, size_t len)
  74. {
  75. wpa_hexdump(level, title, buf, len);
  76. }
  77. static inline void wpa_hexdump_buf(int level, const char *title,
  78. const struct wpabuf *buf)
  79. {
  80. wpa_hexdump(level, title, wpabuf_head(buf), wpabuf_len(buf));
  81. }
  82. /**
  83. * wpa_hexdump_key - conditional hex dump, hide keys
  84. * @level: priority level (MSG_*) of the message
  85. * @title: title of for the message
  86. * @buf: data buffer to be dumped
  87. * @len: length of the buf
  88. *
  89. * This function is used to print conditional debugging and error messages. The
  90. * output may be directed to stdout, stderr, and/or syslog based on
  91. * configuration. The contents of buf is printed out has hex dump. This works
  92. * like wpa_hexdump(), but by default, does not include secret keys (passwords,
  93. * etc.) in debug output.
  94. */
  95. void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
  96. static inline void wpa_hexdump_buf_key(int level, const char *title,
  97. const struct wpabuf *buf)
  98. {
  99. wpa_hexdump_key(level, title, wpabuf_head(buf), wpabuf_len(buf));
  100. }
  101. /**
  102. * wpa_hexdump_ascii - conditional hex dump
  103. * @level: priority level (MSG_*) of the message
  104. * @title: title of for the message
  105. * @buf: data buffer to be dumped
  106. * @len: length of the buf
  107. *
  108. * This function is used to print conditional debugging and error messages. The
  109. * output may be directed to stdout, stderr, and/or syslog based on
  110. * configuration. The contents of buf is printed out has hex dump with both
  111. * the hex numbers and ASCII characters (for printable range) are shown. 16
  112. * bytes per line will be shown.
  113. */
  114. void wpa_hexdump_ascii(int level, const char *title, const void *buf,
  115. size_t len);
  116. /**
  117. * wpa_hexdump_ascii_key - conditional hex dump, hide keys
  118. * @level: priority level (MSG_*) of the message
  119. * @title: title of for the message
  120. * @buf: data buffer to be dumped
  121. * @len: length of the buf
  122. *
  123. * This function is used to print conditional debugging and error messages. The
  124. * output may be directed to stdout, stderr, and/or syslog based on
  125. * configuration. The contents of buf is printed out has hex dump with both
  126. * the hex numbers and ASCII characters (for printable range) are shown. 16
  127. * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
  128. * default, does not include secret keys (passwords, etc.) in debug output.
  129. */
  130. void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
  131. size_t len);
  132. #else
  133. #define wpa_printf(level,fmt, args...) do {} while(0)
  134. #define wpa_hexdump(...) do {} while(0)
  135. #define wpa_dump_mem(...) do {} while(0)
  136. #define wpa_hexdump_buf(...) do {} while(0)
  137. #define wpa_hexdump_key(...) do {} while(0)
  138. #define wpa_hexdump_buf_key(...) do {} while(0)
  139. #define wpa_hexdump_ascii(...) do {} while(0)
  140. #define wpa_hexdump_ascii_key(...) do {} while(0)
  141. #define wpa_dbg(...) do {} while(0)
  142. #endif
  143. #define wpa_auth_logger(...) do {} while(0)
  144. #define wpa_auth_vlogger(...) do {} while(0)
  145. /**
  146. * wpa_msg - Conditional printf for default target and ctrl_iface monitors
  147. * @ctx: Pointer to context data; this is the ctx variable registered
  148. * with struct wpa_driver_ops::init()
  149. * @level: priority level (MSG_*) of the message
  150. * @fmt: printf format string, followed by optional arguments
  151. *
  152. * This function is used to print conditional debugging and error messages. The
  153. * output may be directed to stdout, stderr, and/or syslog based on
  154. * configuration. This function is like wpa_printf(), but it also sends the
  155. * same message to all attached ctrl_iface monitors.
  156. *
  157. * Note: New line '\n' is added to the end of the text when printing to stdout.
  158. */
  159. #define wpa_msg(...) do {} while(0)
  160. /**
  161. * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
  162. * @ctx: Pointer to context data; this is the ctx variable registered
  163. * with struct wpa_driver_ops::init()
  164. * @level: priority level (MSG_*) of the message
  165. * @fmt: printf format string, followed by optional arguments
  166. *
  167. * This function is used to print conditional debugging and error messages.
  168. * This function is like wpa_msg(), but it sends the output only to the
  169. * attached ctrl_iface monitors. In other words, it can be used for frequent
  170. * events that do not need to be sent to syslog.
  171. */
  172. void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  173. PRINTF_FORMAT(3, 4);
  174. typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
  175. size_t len);
  176. #endif /* WPA_DEBUG_H */