LCOV - code coverage report
Current view: top level - src/utils - wpa_debug.h (source / functions) Hit Total Coverage
Test: wpa_supplicant hwsim test run 1388240082 Lines: 8 10 80.0 %
Date: 2013-12-28 Functions: 3 4 75.0 %
Branches: 4 8 50.0 %

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

Generated by: LCOV version 1.9