4 * Copyright (C) 2009 Thomas d'Otreppe
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _AIRCRACK_NG_BYTEORDER_H_
22 #define _AIRCRACK_NG_BYTEORDER_H_
24 #define ___my_swab16(x) \
26 (\
\r(((u_int16_t) (x) & (u_int16_t) 0x00ffU) << 8) |
27 \
\r(((u_int16_t) (x) & (u_int16_t) 0xff00U) >> 8)))
28 #define ___my_swab32(x) \
30 (\
\r(((u_int32_t) (x) & (u_int32_t) 0x000000ffUL) << 24) |
31 \
\r(((u_int32_t) (x) & (u_int32_t) 0x0000ff00UL) << 8) |
32 \
\r(((u_int32_t) (x) & (u_int32_t) 0x00ff0000UL) >> 8) |
33 \
\r(((u_int32_t) (x) & (u_int32_t) 0xff000000UL) >> 24)))
34 #define ___my_swab64(x) \
37 (((u_int64_t) (x) & (u_int64_t) 0x00000000000000ffULL) << 56) |
38 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t) 0x000000000000ff00ULL) <<
39 40) | \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
40 0x0000000000ff0000ULL) << 24) |
41 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t) 0x00000000ff000000ULL) << 8)
42 | \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t) 0x000000ff00000000ULL) >>
43 8) | \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
44 0x0000ff0000000000ULL) >> 24) |
45 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t) 0x00ff000000000000ULL) >>
46 40) | \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
47 0xff00000000000000ULL) >> 56)))
\r \r
51 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
56 #ifndef __int8_t_defined
57 typedef uint64_t u_int64_t;
58 \rtypedef uint32_t u_int32_t;
59 \rtypedef uint16_t u_int16_t;
60 \rtypedef uint8_t u_int8_t;
66 #if __BYTE_ORDER == __LITTLE_ENDIAN
67 #define htobe16(x) ___my_swab16 (x)
68 #define htole16(x) (x)
69 #define be16toh(x) ___my_swab16 (x)
70 #define le16toh(x) (x)
72 #define htobe32(x) ___my_swab32 (x)
73 #define htole32(x) (x)
74 #define be32toh(x) ___my_swab32 (x)
75 #define le32toh(x) (x)
77 #define htobe64(x) ___my_swab64 (x)
78 #define htole64(x) (x)
79 #define be64toh(x) ___my_swab64 (x)
80 #define le64toh(x) (x)
82 #define htobe16(x) (x)
83 #define htole16(x) ___my_swab16 (x)
84 #define be16toh(x) (x)
85 #define le16toh(x) ___my_swab16 (x)
87 #define htobe32(x) (x)
88 #define htole32(x) ___my_swab32 (x)
89 #define be32toh(x) (x)
90 #define le32toh(x) ___my_swab32 (x)
92 #define htobe64(x) (x)
93 #define htole64(x) ___my_swab64 (x)
94 #define be64toh(x) (x)
95 #define le64toh(x) ___my_swab64 (x)
104 #if defined(__CYGWIN32__)
105 #include <asm/byteorder.h>
108 #define __be64_to_cpu(x) ___my_swab64(x)
109 #define __be32_to_cpu(x) ___my_swab32(x)
110 #define __be16_to_cpu(x) ___my_swab16(x)
111 #define __cpu_to_be64(x) ___my_swab64(x)
112 #define __cpu_to_be32(x) ___my_swab32(x)
113 #define __cpu_to_be16(x) ___my_swab16(x)
114 #define __le64_to_cpu(x) (x)
115 #define __le32_to_cpu(x) (x)
116 #define __le16_to_cpu(x) (x)
117 #define __cpu_to_le64(x) (x)
118 #define __cpu_to_le32(x) (x)
119 #define __cpu_to_le16(x) (x)
121 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
132 #define __be64_to_cpu(x) ___my_swab64(x)
133 #define __be32_to_cpu(x) ___my_swab32(x)
134 #define __be16_to_cpu(x) ___my_swab16(x)
135 #define __cpu_to_be64(x) ___my_swab64(x)
136 #define __cpu_to_be32(x) ___my_swab32(x)
137 #define __cpu_to_be16(x) ___my_swab16(x)
138 #define __le64_to_cpu(x) (x)
139 #define __le32_to_cpu(x) (x)
140 #define __le16_to_cpu(x) (x)
141 #define __cpu_to_le64(x) (x)
142 #define __cpu_to_le32(x) (x)
143 #define __cpu_to_le16(x) (x)
145 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
152 #if defined(__APPLE_CC__)
153 #if defined(__x86_64__) && defined(__APPLE__)
155 #include <libkern/OSByteOrder.h>
157 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
158 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
159 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
160 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
161 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
162 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
163 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
164 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
165 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
166 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
167 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
168 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
169 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
170 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
171 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
175 #include <architecture/byte_order.h>
177 #define __swab64(x) NXSwapLongLong(x)
178 #define __swab32(x) NXSwapLong(x)
179 #define __swab16(x) NXSwapShort(x)
180 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
181 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
182 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
183 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
184 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
185 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
186 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
187 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
188 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
189 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
190 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
191 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
195 #define __LITTLE_ENDIAN 1234
196 #define __BIG_ENDIAN 4321
197 #define __PDP_ENDIAN 3412
198 #define __BYTE_ORDER __BIG_ENDIAN
200 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
208 #if defined(__sparc__) && defined(__sun__)
209 #include <sys/byteorder.h>
210 #include <sys/types.h>
213 #define __be64_to_cpu(x) (x)
214 #define __be32_to_cpu(x) (x)
215 #define __be16_to_cpu(x) (x)
216 #define __cpu_to_be64(x) (x)
217 #define __cpu_to_be32(x) (x)
218 #define __cpu_to_be16(x) (x)
219 #define __le64_to_cpu(x) ___my_swab64(x)
220 #define __le32_to_cpu(x) ___my_swab32(x)
221 #define __le16_to_cpu(x) ___my_swab16(x)
222 #define __cpu_to_le64(x) ___my_swab64(x)
223 #define __cpu_to_le32(x) ___my_swab32(x)
224 #define __cpu_to_le16(x) ___my_swab16(x)
225 \rtypedef uint64_t u_int64_t;
226 \rtypedef uint32_t u_int32_t;
227 \rtypedef uint16_t u_int16_t;
228 \rtypedef uint8_t u_int8_t;
231 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
238 #if defined(__MACH__) && !defined(__APPLE_CC__)
239 #include <libkern/OSByteOrder.h>
240 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
241 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
243 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
249 #include <machine/endian.h>
252 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
254 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
255 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
256 // Write to apple to ask what should be used.
258 #if defined(LITTLE_ENDIAN)
259 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
260 #elif defined(__LITTLE_ENDIAN)
261 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
262 #elif defined(_LITTLE_ENDIAN)
263 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
266 #if defined(BIG_ENDIAN)
267 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
268 #elif defined(__BIG_ENDIAN)
269 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
270 #elif defined(_BIG_ENDIAN)
271 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
274 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
275 #error Impossible to determine endianness (Little or Big endian), please contact the author.
278 #if defined(BYTE_ORDER)
279 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
280 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
281 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
282 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
284 #elif defined(__BYTE_ORDER)
285 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
286 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
287 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
288 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
290 #elif defined(_BYTE_ORDER)
291 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
292 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
293 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
294 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
298 #ifndef AIRCRACK_NG_BYTE_ORDER
299 #error Impossible to determine endianness (Little or Big endian), please contact the author.
302 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
304 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
305 #define __be64_to_cpu(x) ___my_swab64(x)
306 #define __be32_to_cpu(x) ___my_swab32(x)
307 #define __be16_to_cpu(x) ___my_swab16(x)
308 #define __cpu_to_be64(x) ___my_swab64(x)
309 #define __cpu_to_be32(x) ___my_swab32(x)
310 #define __cpu_to_be16(x) ___my_swab16(x)
311 #define __le64_to_cpu(x) (x)
312 #define __le32_to_cpu(x) (x)
313 #define __le16_to_cpu(x) (x)
314 #define __cpu_to_le64(x) (x)
315 #define __cpu_to_le32(x) (x)
316 #define __cpu_to_le16(x) (x)
320 #define htobe16 ___my_swab16
323 #define htobe32 ___my_swab32
326 #define betoh16 ___my_swab16
329 #define betoh32 ___my_swab32
333 #define htole16(x) (x)
336 #define htole32(x) (x)
339 #define letoh16(x) (x)
342 #define letoh32(x) (x)
347 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
349 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
350 #define __be64_to_cpu(x) (x)
351 #define __be32_to_cpu(x) (x)
352 #define __be16_to_cpu(x) (x)
353 #define __cpu_to_be64(x) (x)
354 #define __cpu_to_be32(x) (x)
355 #define __cpu_to_be16(x) (x)
356 #define __le64_to_cpu(x) ___my_swab64(x)
357 #define __le32_to_cpu(x) ___my_swab32(x)
358 #define __le16_to_cpu(x) ___my_swab16(x)
359 #define __cpu_to_le64(x) ___my_swab64(x)
360 #define __cpu_to_le32(x) ___my_swab32(x)
361 #define __cpu_to_le16(x) ___my_swab16(x)
365 #define htobe16(x) (x)
368 #define htobe32(x) (x)
371 #define betoh16(x) (x)
374 #define betoh32(x) (x)
378 #define htole16 ___my_swab16
381 #define htole32 ___my_swab32
384 #define letoh16 ___my_swab16
387 #define letoh32 ___my_swab32
393 #define cpu_to_le64 __cpu_to_le64
394 #define le64_to_cpu __le64_to_cpu
395 #define cpu_to_le32 __cpu_to_le32
396 #define le32_to_cpu __le32_to_cpu
397 #define cpu_to_le16 __cpu_to_le16
398 #define le16_to_cpu __le16_to_cpu
399 #define cpu_to_be64 __cpu_to_be64
400 #define be64_to_cpu __be64_to_cpu
401 #define cpu_to_be32 __cpu_to_be32
402 #define be32_to_cpu __be32_to_cpu
403 #define cpu_to_be16 __cpu_to_be16
404 #define be16_to_cpu __be16_to_cpu
407 #define le16toh le16_to_cpu
410 #define be16toh be16_to_cpu
413 #define le32toh le32_to_cpu
416 #define be32toh be32_to_cpu
420 #define htons be16_to_cpu
423 #define htonl cpu_to_be16
426 #define ntohs cpu_to_be16
429 #define ntohl cpu_to_be32