11 #include <sys/types.h>
12 #include <sys/endian.h>
13 #define __BYTE_ORDER _BYTE_ORDER
14 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
15 #define __BIG_ENDIAN _BIG_ENDIAN
16 #define bswap_16 bswap16
17 #define bswap_32 bswap32
18 #define bswap_64 bswap64
21 #ifdef CONFIG_NATIVE_WINDOWS
25 static inline int daemon(int nochdir, int noclose)
27 printf("Windows - daemon() not supported yet\n");
31 static inline void sleep(int seconds)
33 Sleep(seconds * 1000);
36 static inline void usleep(unsigned long usec)
42 #define timersub(a, b, res) do { \
43 (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
44 (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
45 if ((res)->tv_usec < 0) { \
47 (res)->tv_usec += 1000000; \
57 int gettimeofday(struct timeval *tv, struct timezone *tz);
59 #endif /* CONFIG_NATIVE_WINDOWS */
61 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
63 static inline unsigned short wpa_swap_16(unsigned short v)
65 return ((v & 0xff) << 8) | (v >> 8);
68 static inline unsigned int wpa_swap_32(unsigned int v)
70 return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
71 ((v & 0xff0000) >> 8) | (v >> 24);
74 #define le_to_host16(n) (n)
75 #define host_to_le16(n) (n)
76 #define be_to_host16(n) wpa_swap_16(n)
77 #define host_to_be16(n) wpa_swap_16(n)
78 #define le_to_host32(n) (n)
79 #define be_to_host32(n) wpa_swap_32(n)
80 #define host_to_be32(n) wpa_swap_32(n)
82 #else /* __CYGWIN__ */
84 #if __BYTE_ORDER == __LITTLE_ENDIAN
85 #define le_to_host16(n) (n)
86 #define host_to_le16(n) (n)
87 #define be_to_host16(n) bswap_16(n)
88 #define host_to_be16(n) bswap_16(n)
89 #define le_to_host32(n) (n)
90 #define be_to_host32(n) bswap_32(n)
91 #define host_to_be32(n) bswap_32(n)
92 #elif __BYTE_ORDER == __BIG_ENDIAN
93 #define le_to_host16(n) bswap_16(n)
94 #define host_to_le16(n) bswap_16(n)
95 #define be_to_host16(n) (n)
96 #define host_to_be16(n) (n)
97 #define le_to_host32(n) bswap_32(n)
98 #define be_to_host32(n) (n)
99 #define host_to_be32(n) (n)
100 #ifndef WORDS_BIGENDIAN
101 #define WORDS_BIGENDIAN
104 #error Could not determine CPU byte order
107 #endif /* __CYGWIN__ */
115 typedef uint64_t u64;
116 typedef uint32_t u32;
117 typedef uint16_t u16;
124 int hostapd_get_rand(u8 *buf, size_t len);
125 void hostapd_hexdump(const char *title, const u8 *buf, size_t len);
126 int hwaddr_aton(const char *txt, u8 *addr);
127 int hexstr2bin(const char *hex, u8 *buf, size_t len);
128 char * rel2abs_path(const char *rel_path);
129 void inc_byte_array(u8 *counter, size_t len);
130 void print_char(char c);
131 void fprint_char(FILE *f, char c);
134 /* Debugging function - conditional printf and hex dump. Driver wrappers can
135 * use these for debugging purposes. */
137 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
140 * wpa_printf - conditional printf
141 * @level: priority level (MSG_*) of the message
142 * @fmt: printf format string, followed by optional arguments
144 * This function is used to print conditional debugging and error messages. The
145 * output may be directed to stdout, stderr, and/or syslog based on
148 * Note: New line '\n' is added to the end of the text when printing to stdout.
150 void wpa_printf(int level, char *fmt, ...)
151 __attribute__ ((format (printf, 2, 3)));
154 * wpa_hexdump - conditional hex dump
155 * @level: priority level (MSG_*) of the message
156 * @title: title of for the message
157 * @buf: data buffer to be dumped
158 * @len: length of the @buf
160 * This function is used to print conditional debugging and error messages. The
161 * output may be directed to stdout, stderr, and/or syslog based on
162 * configuration. The contents of @buf is printed out has hex dump.
164 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
167 * wpa_hexdump_key - conditional hex dump, hide keys
168 * @level: priority level (MSG_*) of the message
169 * @title: title of for the message
170 * @buf: data buffer to be dumped
171 * @len: length of the @buf
173 * This function is used to print conditional debugging and error messages. The
174 * output may be directed to stdout, stderr, and/or syslog based on
175 * configuration. The contents of @buf is printed out has hex dump. This works
176 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
177 * etc.) in debug output.
179 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
182 * wpa_hexdump_ascii - conditional hex dump
183 * @level: priority level (MSG_*) of the message
184 * @title: title of for the message
185 * @buf: data buffer to be dumped
186 * @len: length of the @buf
188 * This function is used to print conditional debugging and error messages. The
189 * output may be directed to stdout, stderr, and/or syslog based on
190 * configuration. The contents of @buf is printed out has hex dump with both
191 * the hex numbers and ASCII characters (for printable range) are shown. 16
192 * bytes per line will be shown.
194 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
198 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
199 * @level: priority level (MSG_*) of the message
200 * @title: title of for the message
201 * @buf: data buffer to be dumped
202 * @len: length of the @buf
204 * This function is used to print conditional debugging and error messages. The
205 * output may be directed to stdout, stderr, and/or syslog based on
206 * configuration. The contents of @buf is printed out has hex dump with both
207 * the hex numbers and ASCII characters (for printable range) are shown. 16
208 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
209 * default, does not include secret keys (passwords, etc.) in debug output.
211 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
215 #define WPA_ASSERT(a) \
218 printf("WPA_ASSERT FAILED '" #a "' " \
220 __FUNCTION__, __FILE__, __LINE__); \
225 #define WPA_ASSERT(a) do { } while (0)
228 #endif /* COMMON_H */