]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/wpa_supplicant/common.h
This commit was generated by cvs2svn to compensate for changes in r147072,
[FreeBSD/FreeBSD.git] / contrib / wpa_supplicant / common.h
1 #ifndef COMMON_H
2 #define COMMON_H
3
4 #ifdef __linux__
5 #include <endian.h>
6 #include <byteswap.h>
7 #endif
8 #ifdef __FreeBSD__
9 #include <sys/types.h>
10 #include <sys/endian.h>
11 #define bswap_16 bswap16
12 #define bswap_32 bswap32
13 #endif
14
15 #ifdef CONFIG_NATIVE_WINDOWS
16 #include <winsock.h>
17 #include <winsock2.h>
18
19 static inline int daemon(int nochdir, int noclose)
20 {
21         printf("Windows - daemon() not supported yet\n");
22         return -1;
23 }
24
25 static inline void sleep(int seconds)
26 {
27         Sleep(seconds * 1000);
28 }
29
30 static inline void usleep(unsigned long usec)
31 {
32         Sleep(usec / 1000);
33 }
34
35 #ifndef timersub
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) { \
40                 (res)->tv_sec--; \
41                 (res)->tv_usec += 1000000; \
42         } \
43 } while (0)
44 #endif
45
46 struct timezone {
47         int  tz_minuteswest;
48         int  tz_dsttime;
49 };
50
51 int gettimeofday(struct timeval *tv, struct timezone *tz);
52
53 #endif /* CONFIG_NATIVE_WINDOWS */
54
55 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
56
57 static inline unsigned short wpa_swap_16(unsigned short v)
58 {
59         return ((v & 0xff) << 8) | (v >> 8);
60 }
61
62 static inline unsigned int wpa_swap_32(unsigned int v)
63 {
64         return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
65                 ((v & 0xff0000) >> 8) | (v >> 24);
66 }
67
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)
75
76 #else /* __CYGWIN__ */
77
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
96 #endif
97 #else
98 #error Could not determine CPU byte order
99 #endif
100
101 #endif /* __CYGWIN__ */
102
103
104 #ifndef ETH_ALEN
105 #define ETH_ALEN 6
106 #endif
107
108 #include <stdint.h>
109 typedef uint64_t u64;
110 typedef uint32_t u32;
111 typedef uint16_t u16;
112 typedef uint8_t u8;
113 typedef int64_t s64;
114 typedef int32_t s32;
115 typedef int16_t s16;
116 typedef int8_t s8;
117
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);
126
127
128 /* Debugging function - conditional printf and hex dump. Driver wrappers can
129  *  use these for debugging purposes. */
130
131 enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
132
133 /**
134  * wpa_printf - conditional printf
135  * @level: priority level (MSG_*) of the message
136  * @fmt: printf format string, followed by optional arguments
137  *
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
140  * configuration.
141  *
142  * Note: New line '\n' is added to the end of the text when printing to stdout.
143  */
144 void wpa_printf(int level, char *fmt, ...)
145 __attribute__ ((format (printf, 2, 3)));
146
147 /**
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
153  *
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.
157  */
158 void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len);
159
160 /**
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
166  *
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.
172  */
173 void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len);
174
175 /**
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
181  *
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.
187  */
188 void wpa_hexdump_ascii(int level, const char *title, const u8 *buf,
189                        size_t len);
190
191 /**
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
197  *
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.
204  */
205 void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
206                            size_t len);
207
208 #ifdef EAPOL_TEST
209 #define WPA_ASSERT(a)                                                  \
210         do {                                                           \
211                 if (!(a)) {                                            \
212                         printf("WPA_ASSERT FAILED '" #a "' "           \
213                                "%s %s:%d\n",                           \
214                                __FUNCTION__, __FILE__, __LINE__);      \
215                         exit(1);                                       \
216                 }                                                      \
217         } while (0)
218 #else
219 #define WPA_ASSERT(a) do { } while (0)
220 #endif
221
222 #endif /* COMMON_H */