10 #include <sys/endian.h>
11 #define bswap_16 bswap16
12 #define bswap_32 bswap32
15 #ifdef CONFIG_NATIVE_WINDOWS
19 static inline int daemon(int nochdir, int noclose)
21 printf("Windows - daemon() not supported yet\n");
25 static inline void sleep(int seconds)
27 Sleep(seconds * 1000);
30 static inline void usleep(unsigned long usec)
36 #define timersub(a, b, res) do { \
37 (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
38 (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
39 if ((res)->tv_usec < 0) { \
41 (res)->tv_usec += 1000000; \
51 int gettimeofday(struct timeval *tv, struct timezone *tz);
53 #endif /* CONFIG_NATIVE_WINDOWS */
55 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
57 static inline unsigned short wpa_swap_16(unsigned short v)
59 return ((v & 0xff) << 8) | (v >> 8);
62 static inline unsigned int wpa_swap_32(unsigned int v)
64 return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
65 ((v & 0xff0000) >> 8) | (v >> 24);
68 #define le_to_host16(n) (n)
69 #define host_to_le16(n) (n)
70 #define be_to_host16(n) wpa_swap_16(n)
71 #define host_to_be16(n) wpa_swap_16(n)
72 #define le_to_host32(n) (n)
73 #define be_to_host32(n) wpa_swap_32(n)
74 #define host_to_be32(n) wpa_swap_32(n)
76 #else /* __CYGWIN__ */
78 #if __BYTE_ORDER == __LITTLE_ENDIAN
79 #define le_to_host16(n) (n)
80 #define host_to_le16(n) (n)
81 #define be_to_host16(n) bswap_16(n)
82 #define host_to_be16(n) bswap_16(n)
83 #define le_to_host32(n) (n)
84 #define be_to_host32(n) bswap_32(n)
85 #define host_to_be32(n) bswap_32(n)
86 #elif __BYTE_ORDER == __BIG_ENDIAN
87 #define le_to_host16(n) bswap_16(n)
88 #define host_to_le16(n) bswap_16(n)
89 #define be_to_host16(n) (n)
90 #define host_to_be16(n) (n)
91 #define le_to_host32(n) bswap_32(n)
92 #define be_to_host32(n) (n)
93 #define host_to_be32(n) (n)
94 #ifndef WORDS_BIGENDIAN
95 #define WORDS_BIGENDIAN
98 #error Could not determine CPU byte order
101 #endif /* __CYGWIN__ */
109 typedef uint64_t u64;
110 typedef uint32_t u32;
111 typedef uint16_t u16;
118 int hostapd_get_rand(u8 *buf, size_t len);
119 void hostapd_hexdump(const char *title, const u8 *buf, size_t len);
120 int hwaddr_aton(const char *txt, u8 *addr);
121 int hexstr2bin(const char *hex, u8 *buf, size_t len);
122 char * rel2abs_path(const char *rel_path);
123 void inc_byte_array(u8 *counter, size_t len);
124 void print_char(char c);
125 void fprint_char(FILE *f, char c);
128 /* Debugging function - conditional printf and hex dump. Driver wrappers can
129 * use these for debugging purposes. */
131 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
134 * wpa_printf - conditional printf
135 * @level: priority level (MSG_*) of the message
136 * @fmt: printf format string, followed by optional arguments
138 * This function is used to print conditional debugging and error messages. The
139 * output may be directed to stdout, stderr, and/or syslog based on
142 * Note: New line '\n' is added to the end of the text when printing to stdout.
144 void wpa_printf(int level, char *fmt, ...)
145 __attribute__ ((format (printf, 2, 3)));
148 * wpa_hexdump - conditional hex dump
149 * @level: priority level (MSG_*) of the message
150 * @title: title of for the message
151 * @buf: data buffer to be dumped
152 * @len: length of the @buf
154 * This function is used to print conditional debugging and error messages. The
155 * output may be directed to stdout, stderr, and/or syslog based on
156 * configuration. The contents of @buf is printed out has hex dump.
158 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
161 * wpa_hexdump_key - conditional hex dump, hide keys
162 * @level: priority level (MSG_*) of the message
163 * @title: title of for the message
164 * @buf: data buffer to be dumped
165 * @len: length of the @buf
167 * This function is used to print conditional debugging and error messages. The
168 * output may be directed to stdout, stderr, and/or syslog based on
169 * configuration. The contents of @buf is printed out has hex dump. This works
170 * like wpa_hexdump(), but by default, does not include secret keys (passwords,
171 * etc.) in debug output.
173 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
176 * wpa_hexdump_ascii - conditional hex dump
177 * @level: priority level (MSG_*) of the message
178 * @title: title of for the message
179 * @buf: data buffer to be dumped
180 * @len: length of the @buf
182 * This function is used to print conditional debugging and error messages. The
183 * output may be directed to stdout, stderr, and/or syslog based on
184 * configuration. The contents of @buf is printed out has hex dump with both
185 * the hex numbers and ASCII characters (for printable range) are shown. 16
186 * bytes per line will be shown.
188 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
192 * wpa_hexdump_ascii_key - conditional hex dump, hide keys
193 * @level: priority level (MSG_*) of the message
194 * @title: title of for the message
195 * @buf: data buffer to be dumped
196 * @len: length of the @buf
198 * This function is used to print conditional debugging and error messages. The
199 * output may be directed to stdout, stderr, and/or syslog based on
200 * configuration. The contents of @buf is printed out has hex dump with both
201 * the hex numbers and ASCII characters (for printable range) are shown. 16
202 * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
203 * default, does not include secret keys (passwords, etc.) in debug output.
205 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
209 #define WPA_ASSERT(a) \
212 printf("WPA_ASSERT FAILED '" #a "' " \
214 __FUNCTION__, __FILE__, __LINE__); \
219 #define WPA_ASSERT(a) do { } while (0)
222 #endif /* COMMON_H */