First test of wlan driver, sends beacon every 2 seconds
[oweals/gnunet.git] / src / transport / wlan / byteorder.h
1 /*\r
2  *  Compatibility header\r
3  *\r
4  *  Copyright (C) 2009 Thomas d'Otreppe\r
5  *\r
6  *  This program is free software; you can redistribute it and/or modify\r
7  *  it under the terms of the GNU General Public License as published by\r
8  *  the Free Software Foundation; either version 2 of the License, or\r
9  *  (at your option) any later version.\r
10  *\r
11  *  This program is distributed in the hope that it will be useful,\r
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  *  GNU General Public License for more details.\r
15  *\r
16  *  You should have received a copy of the GNU General Public License\r
17  *  along with this program; if not, write to the Free Software\r
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  */\r
20 \r
21 #ifndef _AIRCRACK_NG_BYTEORDER_H_\r
22 #define _AIRCRACK_NG_BYTEORDER_H_\r
23 \r
24         #define ___my_swab16(x) \\r
25         ((u_int16_t)( \\r
26                         (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \\r
27                         (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))\r
28         #define ___my_swab32(x) \\r
29         ((u_int32_t)( \\r
30                         (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \\r
31                         (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) <<  8) | \\r
32                         (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >>  8) | \\r
33                         (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))\r
34         #define ___my_swab64(x) \\r
35         ((u_int64_t)( \\r
36                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \\r
37                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \\r
38                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \\r
39                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) <<  8) | \\r
40                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >>  8) | \\r
41                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \\r
42                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \\r
43                         (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))\r
44 \r
45 \r
46         /*\r
47          * Linux\r
48          */\r
49         #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)\r
50                 #include <endian.h>\r
51                 #include <unistd.h>\r
52                 #include <stdint.h>\r
53 \r
54                 #ifndef __int8_t_defined\r
55                         typedef uint64_t u_int64_t;\r
56                         typedef uint32_t u_int32_t;\r
57                         typedef uint16_t u_int16_t;\r
58                         typedef uint8_t  u_int8_t;\r
59                 #endif\r
60 \r
61         #endif\r
62 \r
63         /*\r
64          * Cygwin\r
65          */\r
66         #if defined(__CYGWIN32__)\r
67                 #include <asm/byteorder.h>\r
68                 #include <unistd.h>\r
69 \r
70                 #define __be64_to_cpu(x) ___my_swab64(x)\r
71                 #define __be32_to_cpu(x) ___my_swab32(x)\r
72                 #define __be16_to_cpu(x) ___my_swab16(x)\r
73                 #define __cpu_to_be64(x) ___my_swab64(x)\r
74                 #define __cpu_to_be32(x) ___my_swab32(x)\r
75                 #define __cpu_to_be16(x) ___my_swab16(x)\r
76                 #define __le64_to_cpu(x) (x)\r
77                 #define __le32_to_cpu(x) (x)\r
78                 #define __le16_to_cpu(x) (x)\r
79                 #define __cpu_to_le64(x) (x)\r
80                 #define __cpu_to_le32(x) (x)\r
81                 #define __cpu_to_le16(x) (x)\r
82 \r
83                 #define AIRCRACK_NG_BYTE_ORDER_DEFINED\r
84 \r
85         #endif\r
86 \r
87         /*\r
88          * Windows (DDK)\r
89          */\r
90         #if defined(__WIN__)\r
91 \r
92                 #include <io.h>\r
93 \r
94                 #define __be64_to_cpu(x) ___my_swab64(x)\r
95                 #define __be32_to_cpu(x) ___my_swab32(x)\r
96                 #define __be16_to_cpu(x) ___my_swab16(x)\r
97                 #define __cpu_to_be64(x) ___my_swab64(x)\r
98                 #define __cpu_to_be32(x) ___my_swab32(x)\r
99                 #define __cpu_to_be16(x) ___my_swab16(x)\r
100                 #define __le64_to_cpu(x) (x)\r
101                 #define __le32_to_cpu(x) (x)\r
102                 #define __le16_to_cpu(x) (x)\r
103                 #define __cpu_to_le64(x) (x)\r
104                 #define __cpu_to_le32(x) (x)\r
105                 #define __cpu_to_le16(x) (x)\r
106 \r
107                 #define AIRCRACK_NG_BYTE_ORDER_DEFINED\r
108 \r
109         #endif\r
110 \r
111         /*\r
112          * MAC (Darwin)\r
113          */\r
114         #if defined(__APPLE_CC__)\r
115                 #if defined(__x86_64__) && defined(__APPLE__)\r
116 \r
117                         #include <libkern/OSByteOrder.h>\r
118 \r
119                         #define __swab64(x)      (unsigned long long) OSSwapInt64((uint64_t)x)\r
120                         #define __swab32(x)      (unsigned long) OSSwapInt32((uint32_t)x)\r
121                         #define __swab16(x)      (unsigned short) OSSwapInt16((uint16_t)x)\r
122                         #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)\r
123                         #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)\r
124                         #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)\r
125                         #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)\r
126                         #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)\r
127                         #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)\r
128                         #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)\r
129                         #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)\r
130                         #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)\r
131                         #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)\r
132                         #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)\r
133                         #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)\r
134 \r
135                 #else\r
136 \r
137                         #include <architecture/byte_order.h>\r
138 \r
139                         #define __swab64(x)      NXSwapLongLong(x)\r
140                         #define __swab32(x)      NXSwapLong(x)\r
141                         #define __swab16(x)      NXSwapShort(x)\r
142                         #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)\r
143                         #define __be32_to_cpu(x) NXSwapBigLongToHost(x)\r
144                         #define __be16_to_cpu(x) NXSwapBigShortToHost(x)\r
145                         #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)\r
146                         #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)\r
147                         #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)\r
148                         #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)\r
149                         #define __cpu_to_be32(x) NXSwapHostLongToBig(x)\r
150                         #define __cpu_to_be16(x) NXSwapHostShortToBig(x)\r
151                         #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)\r
152                         #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)\r
153                         #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)\r
154 \r
155                 #endif\r
156 \r
157                 #define __LITTLE_ENDIAN 1234\r
158                 #define __BIG_ENDIAN    4321\r
159                 #define __PDP_ENDIAN    3412\r
160                 #define __BYTE_ORDER    __BIG_ENDIAN\r
161 \r
162                 #define AIRCRACK_NG_BYTE_ORDER_DEFINED\r
163 \r
164         #endif\r
165 \r
166         /*\r
167          * Solaris\r
168          * -------\r
169          */\r
170         #if defined(__sparc__)\r
171         #include <sys/byteorder.h>\r
172         #include <sys/types.h>\r
173         #include <unistd.h>\r
174 \r
175                 #define __be64_to_cpu(x) (x)\r
176                 #define __be32_to_cpu(x) (x)\r
177                 #define __be16_to_cpu(x) (x)\r
178                 #define __cpu_to_be64(x) (x)\r
179                 #define __cpu_to_be32(x) (x)\r
180                 #define __cpu_to_be16(x) (x)\r
181                 #define __le64_to_cpu(x) ___my_swab64(x)\r
182                 #define __le32_to_cpu(x) ___my_swab32(x)\r
183                 #define __le16_to_cpu(x) ___my_swab16(x)\r
184                 #define __cpu_to_le64(x) ___my_swab64(x)\r
185                 #define __cpu_to_le32(x) ___my_swab32(x)\r
186                 #define __cpu_to_le16(x) ___my_swab16(x)\r
187 \r
188                 typedef uint64_t u_int64_t;\r
189                 typedef uint32_t u_int32_t;\r
190                 typedef uint16_t u_int16_t;\r
191                 typedef uint8_t  u_int8_t;\r
192 \r
193                 #define AIRCRACK_NG_BYTE_ORDER_DEFINED\r
194 \r
195         #endif\r
196 \r
197         /*\r
198          * Custom stuff\r
199          */\r
200         #if  defined(__MACH__) && !defined(__APPLE_CC__)\r
201                 #include <libkern/OSByteOrder.h>\r
202                 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)\r
203                 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)\r
204 \r
205                 #define AIRCRACK_NG_BYTE_ORDER_DEFINED\r
206 \r
207         #endif\r
208 \r
209 \r
210         // FreeBSD\r
211         #ifdef __FreeBSD__\r
212                 #include <machine/endian.h>\r
213         #endif\r
214 \r
215         // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?\r
216 \r
217 \r
218         // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h\r
219         //           http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html\r
220         //           Write to apple to ask what should be used.\r
221 \r
222         #if defined(LITTLE_ENDIAN)\r
223                 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN\r
224         #elif defined(__LITTLE_ENDIAN)\r
225                 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN\r
226         #elif defined(_LITTLE_ENDIAN)\r
227                 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN\r
228         #endif\r
229 \r
230         #if defined(BIG_ENDIAN)\r
231                 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN\r
232         #elif defined(__BIG_ENDIAN)\r
233                 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN\r
234         #elif defined(_BIG_ENDIAN)\r
235                 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN\r
236         #endif\r
237 \r
238         #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)\r
239                 #error Impossible to determine endianness (Little or Big endian), please contact the author.\r
240         #endif\r
241 \r
242         #if defined(BYTE_ORDER)\r
243                 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)\r
244                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN\r
245                 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)\r
246                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN\r
247                 #endif\r
248         #elif defined(__BYTE_ORDER)\r
249                 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)\r
250                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN\r
251                 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)\r
252                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN\r
253                 #endif\r
254         #elif defined(_BYTE_ORDER)\r
255                 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)\r
256                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN\r
257                 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)\r
258                         #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN\r
259                 #endif\r
260         #endif\r
261 \r
262         #ifndef AIRCRACK_NG_BYTE_ORDER\r
263                 #error Impossible to determine endianness (Little or Big endian), please contact the author.\r
264         #endif\r
265 \r
266         #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)\r
267 \r
268                 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED\r
269                         #define __be64_to_cpu(x) ___my_swab64(x)\r
270                         #define __be32_to_cpu(x) ___my_swab32(x)\r
271                         #define __be16_to_cpu(x) ___my_swab16(x)\r
272                         #define __cpu_to_be64(x) ___my_swab64(x)\r
273                         #define __cpu_to_be32(x) ___my_swab32(x)\r
274                         #define __cpu_to_be16(x) ___my_swab16(x)\r
275                         #define __le64_to_cpu(x) (x)\r
276                         #define __le32_to_cpu(x) (x)\r
277                         #define __le16_to_cpu(x) (x)\r
278                         #define __cpu_to_le64(x) (x)\r
279                         #define __cpu_to_le32(x) (x)\r
280                         #define __cpu_to_le16(x) (x)\r
281                 #endif\r
282 \r
283                 #ifndef htobe16\r
284                         #define htobe16 ___my_swab16\r
285                 #endif\r
286                 #ifndef htobe32\r
287                         #define htobe32 ___my_swab32\r
288                 #endif\r
289                 #ifndef betoh16\r
290                         #define betoh16 ___my_swab16\r
291                 #endif\r
292                 #ifndef betoh32\r
293                         #define betoh32 ___my_swab32\r
294                 #endif\r
295 \r
296                 #ifndef htole16\r
297                         #define htole16(x) (x)\r
298                 #endif\r
299                 #ifndef htole32\r
300                         #define htole32(x) (x)\r
301                 #endif\r
302                 #ifndef letoh16\r
303                         #define letoh16(x) (x)\r
304                 #endif\r
305                 #ifndef letoh32\r
306                         #define letoh32(x) (x)\r
307                 #endif\r
308 \r
309         #endif\r
310 \r
311         #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)\r
312 \r
313                 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED\r
314                         #define __be64_to_cpu(x) (x)\r
315                         #define __be32_to_cpu(x) (x)\r
316                         #define __be16_to_cpu(x) (x)\r
317                         #define __cpu_to_be64(x) (x)\r
318                         #define __cpu_to_be32(x) (x)\r
319                         #define __cpu_to_be16(x) (x)\r
320                         #define __le64_to_cpu(x) ___my_swab64(x)\r
321                         #define __le32_to_cpu(x) ___my_swab32(x)\r
322                         #define __le16_to_cpu(x) ___my_swab16(x)\r
323                         #define __cpu_to_le64(x) ___my_swab64(x)\r
324                         #define __cpu_to_le32(x) ___my_swab32(x)\r
325                         #define __cpu_to_le16(x) ___my_swab16(x)\r
326                 #endif\r
327 \r
328                 #ifndef htobe16\r
329                         #define htobe16(x) (x)\r
330                 #endif\r
331                 #ifndef htobe32\r
332                         #define htobe32(x) (x)\r
333                 #endif\r
334                 #ifndef betoh16\r
335                         #define betoh16(x) (x)\r
336                 #endif\r
337                 #ifndef betoh32\r
338                         #define betoh32(x) (x)\r
339                 #endif\r
340 \r
341                 #ifndef htole16\r
342                         #define htole16 ___my_swab16\r
343                 #endif\r
344                 #ifndef htole32\r
345                         #define htole32 ___my_swab32\r
346                 #endif\r
347                 #ifndef letoh16\r
348                         #define letoh16 ___my_swab16\r
349                 #endif\r
350                 #ifndef letoh32\r
351                         #define letoh32 ___my_swab32\r
352                 #endif\r
353 \r
354         #endif\r
355 \r
356         // Common defines\r
357         #define cpu_to_le64 __cpu_to_le64\r
358         #define le64_to_cpu __le64_to_cpu\r
359         #define cpu_to_le32 __cpu_to_le32\r
360         #define le32_to_cpu __le32_to_cpu\r
361         #define cpu_to_le16 __cpu_to_le16\r
362         #define le16_to_cpu __le16_to_cpu\r
363         #define cpu_to_be64 __cpu_to_be64\r
364         #define be64_to_cpu __be64_to_cpu\r
365         #define cpu_to_be32 __cpu_to_be32\r
366         #define be32_to_cpu __be32_to_cpu\r
367         #define cpu_to_be16 __cpu_to_be16\r
368         #define be16_to_cpu __be16_to_cpu\r
369 \r
370         #ifndef le16toh\r
371                 #define le16toh le16_to_cpu\r
372         #endif\r
373         #ifndef be16toh\r
374                 #define be16toh be16_to_cpu\r
375         #endif\r
376         #ifndef le32toh\r
377                 #define le32toh le32_to_cpu\r
378         #endif\r
379         #ifndef be32toh\r
380                 #define be32toh be32_to_cpu\r
381         #endif\r
382 \r
383 \r
384         #ifndef htons\r
385                 #define htons be16_to_cpu\r
386         #endif\r
387         #ifndef htonl\r
388                 #define htonl cpu_to_be16\r
389         #endif\r
390         #ifndef ntohs\r
391                 #define ntohs cpu_to_be16\r
392         #endif\r
393         #ifndef ntohl\r
394                 #define ntohl cpu_to_be32\r
395         #endif\r
396 \r
397 #endif\r