]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/wpa_supplicant/common.h
This commit was generated by cvs2svn to compensate for changes in r149749,
[FreeBSD/FreeBSD.git] / contrib / wpa_supplicant / common.h
1 /* $FreeBSD$ */
2
3 #ifndef COMMON_H
4 #define COMMON_H
5
6 #ifdef __linux__
7 #include <endian.h>
8 #include <byteswap.h>
9 #endif
10 #ifdef __FreeBSD__
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
19 #endif
20
21 #ifdef CONFIG_NATIVE_WINDOWS
22 #include <winsock.h>
23 #include <winsock2.h>
24
25 static inline int daemon(int nochdir, int noclose)
26 {
27         printf("Windows - daemon() not supported yet\n");
28         return -1;
29 }
30
31 static inline void sleep(int seconds)
32 {
33         Sleep(seconds * 1000);
34 }
35
36 static inline void usleep(unsigned long usec)
37 {
38         Sleep(usec / 1000);
39 }
40
41 #ifndef timersub
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) { \
46                 (res)->tv_sec--; \
47                 (res)->tv_usec += 1000000; \
48         } \
49 } while (0)
50 #endif
51
52 struct timezone {
53         int  tz_minuteswest;
54         int  tz_dsttime;
55 };
56
57 int gettimeofday(struct timeval *tv, struct timezone *tz);
58
59 #endif /* CONFIG_NATIVE_WINDOWS */
60
61 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
62
63 static inline unsigned short wpa_swap_16(unsigned short v)
64 {
65         return ((v & 0xff) << 8) | (v >> 8);
66 }
67
68 static inline unsigned int wpa_swap_32(unsigned int v)
69 {
70         return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
71                 ((v & 0xff0000) >> 8) | (v >> 24);
72 }
73
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)
81
82 #else /* __CYGWIN__ */
83
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
102 #endif
103 #else
104 #error Could not determine CPU byte order
105 #endif
106
107 #endif /* __CYGWIN__ */
108
109
110 #ifndef ETH_ALEN
111 #define ETH_ALEN 6
112 #endif
113
114 #include <stdint.h>
115 typedef uint64_t u64;
116 typedef uint32_t u32;
117 typedef uint16_t u16;
118 typedef uint8_t u8;
119 typedef int64_t s64;
120 typedef int32_t s32;
121 typedef int16_t s16;
122 typedef int8_t s8;
123
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);
132
133
134 /* Debugging function - conditional printf and hex dump. Driver wrappers can
135  *  use these for debugging purposes. */
136
137 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
138
139 /**
140  * wpa_printf - conditional printf
141  * @level: priority level (MSG_*) of the message
142  * @fmt: printf format string, followed by optional arguments
143  *
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
146  * configuration.
147  *
148  * Note: New line '\n' is added to the end of the text when printing to stdout.
149  */
150 void wpa_printf(int level, char *fmt, ...)
151 __attribute__ ((format (printf, 2, 3)));
152
153 /**
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
159  *
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.
163  */
164 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
165
166 /**
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
172  *
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.
178  */
179 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
180
181 /**
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
187  *
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.
193  */
194 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
195                        size_t len);
196
197 /**
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
203  *
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.
210  */
211 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
212                            size_t len);
213
214 #ifdef EAPOL_TEST
215 #define WPA_ASSERT(a)                                                  \
216         do {                                                           \
217                 if (!(a)) {                                            \
218                         printf("WPA_ASSERT FAILED '" #a "' "           \
219                                "%s %s:%d\n",                           \
220                                __FUNCTION__, __FILE__, __LINE__);      \
221                         exit(1);                                       \
222                 }                                                      \
223         } while (0)
224 #else
225 #define WPA_ASSERT(a) do { } while (0)
226 #endif
227
228 #endif /* COMMON_H */