nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * Compatibility header
3 *
4 * Copyright (C) 2009-2016 Thomas d'Otreppe <tdotreppe@aircrack-ng.org>
5 *
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.
10 *
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.
15 *
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
19 *
20 *
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of portions of this program with the
23 * OpenSSL library under certain conditions as described in each
24 * individual source file, and distribute linked combinations
25 * including the two.
26 * You must obey the GNU General Public License in all respects
27 * for all of the code used other than OpenSSL. * If you modify
28 * file(s) with this exception, you may extend this exception to your
29 * version of the file(s), but you are not obligated to do so. * If you
30 * do not wish to do so, delete this exception statement from your
31 * version. * If you delete this exception statement from all source
32 * files in the program, then also delete it here.
33 */
34  
35 #ifndef _AIRCRACK_NG_BYTEORDER_H_
36 #define _AIRCRACK_NG_BYTEORDER_H_
37  
38 #define ___my_swab16(x) \
39 ((u_int16_t)( \
40 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
41 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
42 #define ___my_swab32(x) \
43 ((u_int32_t)( \
44 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
45 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
46 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
47 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
48 #define ___my_swab64(x) \
49 ((u_int64_t)( \
50 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
51 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
52 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
53 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
54 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
55 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
56 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
57 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
58  
59  
60 /*
61 * Linux
62 */
63 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
64 #include <endian.h>
65 #include <unistd.h>
66 #include <stdint.h>
67  
68 #ifndef __int8_t_defined
69 typedef uint64_t u_int64_t;
70 typedef uint32_t u_int32_t;
71 typedef uint16_t u_int16_t;
72 typedef uint8_t u_int8_t;
73 #endif
74  
75 #endif
76  
77 /*
78 * Cygwin
79 */
80 #if defined(__CYGWIN32__)
81 #include <asm/byteorder.h>
82 #include <unistd.h>
83  
84 #define __be64_to_cpu(x) ___my_swab64(x)
85 #define __be32_to_cpu(x) ___my_swab32(x)
86 #define __be16_to_cpu(x) ___my_swab16(x)
87 #define __cpu_to_be64(x) ___my_swab64(x)
88 #define __cpu_to_be32(x) ___my_swab32(x)
89 #define __cpu_to_be16(x) ___my_swab16(x)
90 #define __le64_to_cpu(x) (x)
91 #define __le32_to_cpu(x) (x)
92 #define __le16_to_cpu(x) (x)
93 #define __cpu_to_le64(x) (x)
94 #define __cpu_to_le32(x) (x)
95 #define __cpu_to_le16(x) (x)
96  
97 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
98  
99 #endif
100  
101 /*
102 * Windows (DDK)
103 */
104 #if defined(__WIN__)
105  
106 #include <io.h>
107  
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)
120  
121 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
122  
123 #endif
124  
125 /*
126 * MAC (Darwin)
127 */
128 #if defined(__APPLE_CC__)
129 #if defined(__x86_64__) && defined(__APPLE__)
130  
131 #include <libkern/OSByteOrder.h>
132  
133 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
134 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
135 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
136 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
137 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
138 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
139 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
140 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
141 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
142 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
143 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
144 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
145 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
146 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
147 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
148  
149 #else
150  
151 #include <architecture/byte_order.h>
152  
153 #define __swab64(x) NXSwapLongLong(x)
154 #define __swab32(x) NXSwapLong(x)
155 #define __swab16(x) NXSwapShort(x)
156 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
157 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
158 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
159 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
160 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
161 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
162 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
163 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
164 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
165 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
166 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
167 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
168  
169 #endif
170  
171 #define __LITTLE_ENDIAN 1234
172 #define __BIG_ENDIAN 4321
173 #define __PDP_ENDIAN 3412
174 #define __BYTE_ORDER __BIG_ENDIAN
175  
176 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
177  
178 #endif
179  
180 /*
181 * Solaris
182 * -------
183 */
184 #if defined(__SVR4) && defined(__sun__)
185 #include <sys/byteorder.h>
186 #include <sys/types.h>
187 #include <unistd.h>
188  
189 typedef uint64_t u_int64_t;
190 typedef uint32_t u_int32_t;
191 typedef uint16_t u_int16_t;
192 typedef uint8_t u_int8_t;
193  
194 #if defined(__sparc__)
195 #define __be64_to_cpu(x) (x)
196 #define __be32_to_cpu(x) (x)
197 #define __be16_to_cpu(x) (x)
198 #define __cpu_to_be64(x) (x)
199 #define __cpu_to_be32(x) (x)
200 #define __cpu_to_be16(x) (x)
201 #define __le64_to_cpu(x) ___my_swab64(x)
202 #define __le32_to_cpu(x) ___my_swab32(x)
203 #define __le16_to_cpu(x) ___my_swab16(x)
204 #define __cpu_to_le64(x) ___my_swab64(x)
205 #define __cpu_to_le32(x) ___my_swab32(x)
206 #define __cpu_to_le16(x) ___my_swab16(x)
207  
208 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
209 #else
210 #define AIRCRACK_NG_BYTE_ORDER 1
211 #define LITTLE_ENDIAN 1
212 #endif
213 #endif
214  
215 /*
216 * Custom stuff
217 */
218 #if defined(__MACH__) && !defined(__APPLE_CC__) && !defined(__GNU__)
219 #include <libkern/OSByteOrder.h>
220 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
221 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
222  
223 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
224 #endif
225  
226 // FreeBSD
227 #ifdef __FreeBSD__
228 #undef ushort
229 #undef uint
230 #include <sys/types.h>
231 #endif
232  
233 /*
234 * Android
235 */
236 #if defined(__ANDROID__)
237 #undef __swab16
238 #undef __swab32
239 #undef __swab64
240 #define __swab16(x) ___my_swab16(x)
241 #define __swab32(x) ___my_swab32(x)
242 #define __swab64(x) ___my_swab64(x)
243 #include <linux/byteorder/little_endian.h>
244 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
245 #endif
246  
247 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
248  
249  
250 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
251 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
252 // Write to apple to ask what should be used.
253  
254 #if defined(LITTLE_ENDIAN)
255 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
256 #elif defined(__LITTLE_ENDIAN)
257 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
258 #elif defined(_LITTLE_ENDIAN)
259 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
260 #endif
261  
262 #if defined(BIG_ENDIAN)
263 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
264 #elif defined(__BIG_ENDIAN)
265 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
266 #elif defined(_BIG_ENDIAN)
267 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
268 #endif
269  
270 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
271 #error Impossible to determine endianness (Little or Big endian), please contact the author.
272 #endif
273  
274 #if defined(BYTE_ORDER)
275 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
276 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
277 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
278 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
279 #endif
280 #elif defined(__BYTE_ORDER)
281 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
282 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
283 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
284 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
285 #endif
286 #elif defined(_BYTE_ORDER)
287 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
288 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
289 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
290 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
291 #endif
292 #endif
293  
294 #ifndef AIRCRACK_NG_BYTE_ORDER
295 #error Impossible to determine endianness (Little or Big endian), please contact the author.
296 #endif
297  
298 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
299  
300 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
301 #define __be64_to_cpu(x) ___my_swab64(x)
302 #define __be32_to_cpu(x) ___my_swab32(x)
303 #define __be16_to_cpu(x) ___my_swab16(x)
304 #define __cpu_to_be64(x) ___my_swab64(x)
305 #define __cpu_to_be32(x) ___my_swab32(x)
306 #define __cpu_to_be16(x) ___my_swab16(x)
307 #define __le64_to_cpu(x) (x)
308 #define __le32_to_cpu(x) (x)
309 #define __le16_to_cpu(x) (x)
310 #define __cpu_to_le64(x) (x)
311 #define __cpu_to_le32(x) (x)
312 #define __cpu_to_le16(x) (x)
313 #endif
314  
315 #ifndef htobe16
316 #define htobe16 ___my_swab16
317 #endif
318 #ifndef htobe32
319 #define htobe32 ___my_swab32
320 #endif
321 #ifndef htobe64
322 #define htobe64 ___my_swab64
323 #endif
324 #ifndef betoh16
325 #define betoh16 ___my_swab16
326 #endif
327 #ifndef betoh32
328 #define betoh32 ___my_swab32
329 #endif
330 #ifndef betoh64
331 #define betoh64 ___my_swab64
332 #endif
333  
334 #ifndef htole16
335 #define htole16(x) (x)
336 #endif
337 #ifndef htole32
338 #define htole32(x) (x)
339 #endif
340 #ifndef htole64
341 #define htole64(x) (x)
342 #endif
343 #ifndef letoh16
344 #define letoh16(x) (x)
345 #endif
346 #ifndef letoh32
347 #define letoh32(x) (x)
348 #endif
349 #ifndef letoh64
350 #define letoh64(x) (x)
351 #endif
352  
353 #endif
354  
355 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
356  
357 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
358 #define __be64_to_cpu(x) (x)
359 #define __be32_to_cpu(x) (x)
360 #define __be16_to_cpu(x) (x)
361 #define __cpu_to_be64(x) (x)
362 #define __cpu_to_be32(x) (x)
363 #define __cpu_to_be16(x) (x)
364 #define __le64_to_cpu(x) ___my_swab64(x)
365 #define __le32_to_cpu(x) ___my_swab32(x)
366 #define __le16_to_cpu(x) ___my_swab16(x)
367 #define __cpu_to_le64(x) ___my_swab64(x)
368 #define __cpu_to_le32(x) ___my_swab32(x)
369 #define __cpu_to_le16(x) ___my_swab16(x)
370 #endif
371  
372 #ifndef htobe16
373 #define htobe16(x) (x)
374 #endif
375 #ifndef htobe32
376 #define htobe32(x) (x)
377 #endif
378 #ifndef htobe64
379 #define htobe64(x) (x)
380 #endif
381 #ifndef betoh16
382 #define betoh16(x) (x)
383 #endif
384 #ifndef betoh32
385 #define betoh32(x) (x)
386 #endif
387 #ifndef betoh64
388 #define betoh64(x) (x)
389 #endif
390  
391 #ifndef htole16
392 #define htole16 ___my_swab16
393 #endif
394 #ifndef htole32
395 #define htole32 ___my_swab32
396 #endif
397 #ifndef htole64
398 #define htole64 ___my_swab64
399 #endif
400 #ifndef letoh16
401 #define letoh16 ___my_swab16
402 #endif
403 #ifndef letoh32
404 #define letoh32 ___my_swab32
405 #endif
406 #ifndef letoh64
407 #define letoh64 ___my_swab64
408 #endif
409  
410 #endif
411  
412 // Common defines
413 #define cpu_to_le64 __cpu_to_le64
414 #define le64_to_cpu __le64_to_cpu
415 #define cpu_to_le32 __cpu_to_le32
416 #define le32_to_cpu __le32_to_cpu
417 #define cpu_to_le16 __cpu_to_le16
418 #define le16_to_cpu __le16_to_cpu
419 #define cpu_to_be64 __cpu_to_be64
420 #define be64_to_cpu __be64_to_cpu
421 #define cpu_to_be32 __cpu_to_be32
422 #define be32_to_cpu __be32_to_cpu
423 #define cpu_to_be16 __cpu_to_be16
424 #define be16_to_cpu __be16_to_cpu
425  
426 #ifndef le16toh
427 #define le16toh le16_to_cpu
428 #endif
429 #ifndef be16toh
430 #define be16toh be16_to_cpu
431 #endif
432 #ifndef le32toh
433 #define le32toh le32_to_cpu
434 #endif
435 #ifndef be32toh
436 #define be32toh be32_to_cpu
437 #endif
438  
439  
440 #ifndef htons
441 #define htons be16_to_cpu
442 #endif
443 #ifndef htonl
444 #define htonl cpu_to_be16
445 #endif
446 #ifndef ntohs
447 #define ntohs cpu_to_be16
448 #endif
449 #ifndef ntohl
450 #define ntohl cpu_to_be32
451 #endif
452  
453 #endif