2 * Compatibility header
\r
4 * Copyright (C) 2009 Thomas d'Otreppe
\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
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
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
21 #ifndef _AIRCRACK_NG_BYTEORDER_H_
\r
22 #define _AIRCRACK_NG_BYTEORDER_H_
\r
24 #define ___my_swab16(x) \
\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
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
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
49 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
\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
62 # if __BYTE_ORDER == __LITTLE_ENDIAN
\r
63 # define htobe16(x) ___my_swab16 (x)
\r
64 # define htole16(x) (x)
\r
65 # define be16toh(x) ___my_swab16 (x)
\r
66 # define le16toh(x) (x)
\r
68 # define htobe32(x) ___my_swab32 (x)
\r
69 # define htole32(x) (x)
\r
70 # define be32toh(x) ___my_swab32 (x)
\r
71 # define le32toh(x) (x)
\r
73 # define htobe64(x) ___my_swab64 (x)
\r
74 # define htole64(x) (x)
\r
75 # define be64toh(x) ___my_swab64 (x)
\r
76 # define le64toh(x) (x)
\r
78 # define htobe16(x) (x)
\r
79 # define htole16(x) ___my_swab16 (x)
\r
80 # define be16toh(x) (x)
\r
81 # define le16toh(x) ___my_swab16 (x)
\r
83 # define htobe32(x) (x)
\r
84 # define htole32(x) ___my_swab32 (x)
\r
85 # define be32toh(x) (x)
\r
86 # define le32toh(x) ___my_swab32 (x)
\r
88 # define htobe64(x) (x)
\r
89 # define htole64(x) ___my_swab64 (x)
\r
90 # define be64toh(x) (x)
\r
91 # define le64toh(x) ___my_swab64 (x)
\r
102 #if defined(__CYGWIN32__)
\r
103 #include <asm/byteorder.h>
\r
104 #include <unistd.h>
\r
106 #define __be64_to_cpu(x) ___my_swab64(x)
\r
107 #define __be32_to_cpu(x) ___my_swab32(x)
\r
108 #define __be16_to_cpu(x) ___my_swab16(x)
\r
109 #define __cpu_to_be64(x) ___my_swab64(x)
\r
110 #define __cpu_to_be32(x) ___my_swab32(x)
\r
111 #define __cpu_to_be16(x) ___my_swab16(x)
\r
112 #define __le64_to_cpu(x) (x)
\r
113 #define __le32_to_cpu(x) (x)
\r
114 #define __le16_to_cpu(x) (x)
\r
115 #define __cpu_to_le64(x) (x)
\r
116 #define __cpu_to_le32(x) (x)
\r
117 #define __cpu_to_le16(x) (x)
\r
119 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
126 #if defined(__WIN__)
\r
130 #define __be64_to_cpu(x) ___my_swab64(x)
\r
131 #define __be32_to_cpu(x) ___my_swab32(x)
\r
132 #define __be16_to_cpu(x) ___my_swab16(x)
\r
133 #define __cpu_to_be64(x) ___my_swab64(x)
\r
134 #define __cpu_to_be32(x) ___my_swab32(x)
\r
135 #define __cpu_to_be16(x) ___my_swab16(x)
\r
136 #define __le64_to_cpu(x) (x)
\r
137 #define __le32_to_cpu(x) (x)
\r
138 #define __le16_to_cpu(x) (x)
\r
139 #define __cpu_to_le64(x) (x)
\r
140 #define __cpu_to_le32(x) (x)
\r
141 #define __cpu_to_le16(x) (x)
\r
143 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
150 #if defined(__APPLE_CC__)
\r
151 #if defined(__x86_64__) && defined(__APPLE__)
\r
153 #include <libkern/OSByteOrder.h>
\r
155 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
\r
156 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
\r
157 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
\r
158 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
\r
159 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
\r
160 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
\r
161 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
\r
162 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
\r
163 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
\r
164 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
\r
165 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
\r
166 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
\r
167 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
\r
168 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
\r
169 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
\r
173 #include <architecture/byte_order.h>
\r
175 #define __swab64(x) NXSwapLongLong(x)
\r
176 #define __swab32(x) NXSwapLong(x)
\r
177 #define __swab16(x) NXSwapShort(x)
\r
178 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
\r
179 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
\r
180 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
\r
181 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
\r
182 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
\r
183 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
\r
184 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
\r
185 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
\r
186 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
\r
187 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
\r
188 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
\r
189 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
\r
193 #define __LITTLE_ENDIAN 1234
\r
194 #define __BIG_ENDIAN 4321
\r
195 #define __PDP_ENDIAN 3412
\r
196 #define __BYTE_ORDER __BIG_ENDIAN
\r
198 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
206 #if defined(__sparc__) && defined(__sun__)
\r
207 #include <sys/byteorder.h>
\r
208 #include <sys/types.h>
\r
209 #include <unistd.h>
\r
211 #define __be64_to_cpu(x) (x)
\r
212 #define __be32_to_cpu(x) (x)
\r
213 #define __be16_to_cpu(x) (x)
\r
214 #define __cpu_to_be64(x) (x)
\r
215 #define __cpu_to_be32(x) (x)
\r
216 #define __cpu_to_be16(x) (x)
\r
217 #define __le64_to_cpu(x) ___my_swab64(x)
\r
218 #define __le32_to_cpu(x) ___my_swab32(x)
\r
219 #define __le16_to_cpu(x) ___my_swab16(x)
\r
220 #define __cpu_to_le64(x) ___my_swab64(x)
\r
221 #define __cpu_to_le32(x) ___my_swab32(x)
\r
222 #define __cpu_to_le16(x) ___my_swab16(x)
\r
224 typedef uint64_t u_int64_t;
\r
225 typedef uint32_t u_int32_t;
\r
226 typedef uint16_t u_int16_t;
\r
227 typedef uint8_t u_int8_t;
\r
229 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
236 #if defined(__MACH__) && !defined(__APPLE_CC__)
\r
237 #include <libkern/OSByteOrder.h>
\r
238 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
\r
239 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
\r
241 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
248 #include <machine/endian.h>
\r
251 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
\r
254 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
\r
255 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
\r
256 // Write to apple to ask what should be used.
\r
258 #if defined(LITTLE_ENDIAN)
\r
259 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
\r
260 #elif defined(__LITTLE_ENDIAN)
\r
261 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
\r
262 #elif defined(_LITTLE_ENDIAN)
\r
263 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
\r
266 #if defined(BIG_ENDIAN)
\r
267 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
\r
268 #elif defined(__BIG_ENDIAN)
\r
269 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
\r
270 #elif defined(_BIG_ENDIAN)
\r
271 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
\r
274 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
\r
275 #error Impossible to determine endianness (Little or Big endian), please contact the author.
\r
278 #if defined(BYTE_ORDER)
\r
279 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
280 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
281 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
282 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
284 #elif defined(__BYTE_ORDER)
\r
285 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
286 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
287 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
288 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
290 #elif defined(_BYTE_ORDER)
\r
291 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
292 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
293 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
294 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
298 #ifndef AIRCRACK_NG_BYTE_ORDER
\r
299 #error Impossible to determine endianness (Little or Big endian), please contact the author.
\r
302 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
304 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
305 #define __be64_to_cpu(x) ___my_swab64(x)
\r
306 #define __be32_to_cpu(x) ___my_swab32(x)
\r
307 #define __be16_to_cpu(x) ___my_swab16(x)
\r
308 #define __cpu_to_be64(x) ___my_swab64(x)
\r
309 #define __cpu_to_be32(x) ___my_swab32(x)
\r
310 #define __cpu_to_be16(x) ___my_swab16(x)
\r
311 #define __le64_to_cpu(x) (x)
\r
312 #define __le32_to_cpu(x) (x)
\r
313 #define __le16_to_cpu(x) (x)
\r
314 #define __cpu_to_le64(x) (x)
\r
315 #define __cpu_to_le32(x) (x)
\r
316 #define __cpu_to_le16(x) (x)
\r
320 #define htobe16 ___my_swab16
\r
323 #define htobe32 ___my_swab32
\r
326 #define betoh16 ___my_swab16
\r
329 #define betoh32 ___my_swab32
\r
333 #define htole16(x) (x)
\r
336 #define htole32(x) (x)
\r
339 #define letoh16(x) (x)
\r
342 #define letoh32(x) (x)
\r
347 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
349 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
350 #define __be64_to_cpu(x) (x)
\r
351 #define __be32_to_cpu(x) (x)
\r
352 #define __be16_to_cpu(x) (x)
\r
353 #define __cpu_to_be64(x) (x)
\r
354 #define __cpu_to_be32(x) (x)
\r
355 #define __cpu_to_be16(x) (x)
\r
356 #define __le64_to_cpu(x) ___my_swab64(x)
\r
357 #define __le32_to_cpu(x) ___my_swab32(x)
\r
358 #define __le16_to_cpu(x) ___my_swab16(x)
\r
359 #define __cpu_to_le64(x) ___my_swab64(x)
\r
360 #define __cpu_to_le32(x) ___my_swab32(x)
\r
361 #define __cpu_to_le16(x) ___my_swab16(x)
\r
365 #define htobe16(x) (x)
\r
368 #define htobe32(x) (x)
\r
371 #define betoh16(x) (x)
\r
374 #define betoh32(x) (x)
\r
378 #define htole16 ___my_swab16
\r
381 #define htole32 ___my_swab32
\r
384 #define letoh16 ___my_swab16
\r
387 #define letoh32 ___my_swab32
\r
393 #define cpu_to_le64 __cpu_to_le64
\r
394 #define le64_to_cpu __le64_to_cpu
\r
395 #define cpu_to_le32 __cpu_to_le32
\r
396 #define le32_to_cpu __le32_to_cpu
\r
397 #define cpu_to_le16 __cpu_to_le16
\r
398 #define le16_to_cpu __le16_to_cpu
\r
399 #define cpu_to_be64 __cpu_to_be64
\r
400 #define be64_to_cpu __be64_to_cpu
\r
401 #define cpu_to_be32 __cpu_to_be32
\r
402 #define be32_to_cpu __be32_to_cpu
\r
403 #define cpu_to_be16 __cpu_to_be16
\r
404 #define be16_to_cpu __be16_to_cpu
\r
407 #define le16toh le16_to_cpu
\r
410 #define be16toh be16_to_cpu
\r
413 #define le32toh le32_to_cpu
\r
416 #define be32toh be32_to_cpu
\r
421 #define htons be16_to_cpu
\r
424 #define htonl cpu_to_be16
\r
427 #define ntohs cpu_to_be16
\r
430 #define ntohl cpu_to_be32
\r