14 #if defined(__linux__) || defined(__GLIBC__) 19 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \ 21 #include <sys/types.h> 22 #include <sys/endian.h> 23 #define __BYTE_ORDER _BYTE_ORDER 24 #define __LITTLE_ENDIAN _LITTLE_ENDIAN 25 #define __BIG_ENDIAN _BIG_ENDIAN 27 #define bswap_16 swap16 28 #define bswap_32 swap32 29 #define bswap_64 swap64 31 #define bswap_16 bswap16 32 #define bswap_32 bswap32 33 #define bswap_64 bswap64 39 #include <sys/types.h> 40 #include <machine/endian.h> 41 #define __BYTE_ORDER _BYTE_ORDER 42 #define __LITTLE_ENDIAN _LITTLE_ENDIAN 43 #define __BIG_ENDIAN _BIG_ENDIAN 44 static inline unsigned short bswap_16(
unsigned short v)
46 return ((v & 0xff) << 8) | (v >> 8);
49 static inline unsigned int bswap_32(
unsigned int v)
51 return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
52 ((v & 0xff0000) >> 8) | (v >> 24);
56 #ifdef CONFIG_NATIVE_WINDOWS 59 typedef int socklen_t;
62 #define MSG_DONTWAIT 0 68 #define inline __inline 71 #define vsnprintf _vsnprintf 73 #define close closesocket 88 #define WPA_TYPES_DEFINED 92 typedef unsigned long long u64;
96 typedef long long s64;
100 #define WPA_TYPES_DEFINED 103 #ifndef WPA_TYPES_DEFINED 104 #ifdef CONFIG_USE_INTTYPES_H 105 #include <inttypes.h> 109 typedef uint64_t u64;
110 typedef uint32_t u32;
111 typedef uint16_t u16;
117 #define WPA_TYPES_DEFINED 123 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS) 125 static inline unsigned short wpa_swap_16(
unsigned short v)
127 return ((v & 0xff) << 8) | (v >> 8);
130 static inline unsigned int wpa_swap_32(
unsigned int v)
132 return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
133 ((v & 0xff0000) >> 8) | (v >> 24);
136 #define le_to_host16(n) (n) 137 #define host_to_le16(n) (n) 138 #define be_to_host16(n) wpa_swap_16(n) 139 #define host_to_be16(n) wpa_swap_16(n) 140 #define le_to_host32(n) (n) 141 #define host_to_le32(n) (n) 142 #define be_to_host32(n) wpa_swap_32(n) 143 #define host_to_be32(n) wpa_swap_32(n) 145 #define WPA_BYTE_SWAP_DEFINED 150 #ifndef WPA_BYTE_SWAP_DEFINED 153 #ifndef __LITTLE_ENDIAN 155 #define __LITTLE_ENDIAN 1234 156 #define __BIG_ENDIAN 4321 158 #define __BYTE_ORDER __BIG_ENDIAN 164 #if __BYTE_ORDER == __LITTLE_ENDIAN 165 #define le_to_host16(n) ((__force u16) (le16) (n)) 166 #define host_to_le16(n) ((__force le16) (u16) (n)) 167 #define be_to_host16(n) bswap_16((__force u16) (be16) (n)) 168 #define host_to_be16(n) ((__force be16) bswap_16((n))) 169 #define le_to_host32(n) ((__force u32) (le32) (n)) 170 #define host_to_le32(n) ((__force le32) (u32) (n)) 171 #define be_to_host32(n) bswap_32((__force u32) (be32) (n)) 172 #define host_to_be32(n) ((__force be32) bswap_32((n))) 173 #define le_to_host64(n) ((__force u64) (le64) (n)) 174 #define host_to_le64(n) ((__force le64) (u64) (n)) 175 #define be_to_host64(n) bswap_64((__force u64) (be64) (n)) 176 #define host_to_be64(n) ((__force be64) bswap_64((n))) 177 #elif __BYTE_ORDER == __BIG_ENDIAN 178 #define le_to_host16(n) bswap_16(n) 179 #define host_to_le16(n) bswap_16(n) 180 #define be_to_host16(n) (n) 181 #define host_to_be16(n) (n) 182 #define le_to_host32(n) bswap_32(n) 183 #define host_to_le32(n) bswap_32(n) 184 #define be_to_host32(n) (n) 185 #define host_to_be32(n) (n) 186 #define le_to_host64(n) bswap_64(n) 187 #define host_to_le64(n) bswap_64(n) 188 #define be_to_host64(n) (n) 189 #define host_to_be64(n) (n) 190 #ifndef WORDS_BIGENDIAN 191 #define WORDS_BIGENDIAN 194 #error Could not determine CPU byte order 197 #define WPA_BYTE_SWAP_DEFINED 203 static inline u16 WPA_GET_BE16(
const u8 *a)
205 return (a[0] << 8) | a[1];
208 static inline void WPA_PUT_BE16(u8 *a, u16 val)
214 static inline u16 WPA_GET_LE16(
const u8 *a)
216 return (a[1] << 8) | a[0];
219 static inline void WPA_PUT_LE16(u8 *a, u16 val)
225 static inline u32 WPA_GET_BE24(
const u8 *a)
227 return (a[0] << 16) | (a[1] << 8) | a[2];
230 static inline void WPA_PUT_BE24(u8 *a, u32 val)
232 a[0] = (val >> 16) & 0xff;
233 a[1] = (val >> 8) & 0xff;
237 static inline u32 WPA_GET_BE32(
const u8 *a)
239 return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
242 static inline void WPA_PUT_BE32(u8 *a, u32 val)
244 a[0] = (val >> 24) & 0xff;
245 a[1] = (val >> 16) & 0xff;
246 a[2] = (val >> 8) & 0xff;
250 static inline u32 WPA_GET_LE32(
const u8 *a)
252 return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0];
255 static inline void WPA_PUT_LE32(u8 *a, u32 val)
257 a[3] = (val >> 24) & 0xff;
258 a[2] = (val >> 16) & 0xff;
259 a[1] = (val >> 8) & 0xff;
263 static inline u64 WPA_GET_BE64(
const u8 *a)
265 return (((u64) a[0]) << 56) | (((u64) a[1]) << 48) |
266 (((u64) a[2]) << 40) | (((u64) a[3]) << 32) |
267 (((u64) a[4]) << 24) | (((u64) a[5]) << 16) |
268 (((u64) a[6]) << 8) | ((u64) a[7]);
271 static inline void WPA_PUT_BE64(u8 *a, u64 val)
283 static inline u64 WPA_GET_LE64(
const u8 *a)
285 return (((u64) a[7]) << 56) | (((u64) a[6]) << 48) |
286 (((u64) a[5]) << 40) | (((u64) a[4]) << 32) |
287 (((u64) a[3]) << 24) | (((u64) a[2]) << 16) |
288 (((u64) a[1]) << 8) | ((u64) a[0]);
291 static inline void WPA_PUT_LE64(u8 *a, u64 val)
314 #define ETH_P_ALL 0x0003 317 #define ETH_P_IP 0x0800 319 #ifndef ETH_P_80211_ENCAP 320 #define ETH_P_80211_ENCAP 0x890d 323 #define ETH_P_PAE 0x888E 326 #define ETH_P_EAPOL ETH_P_PAE 328 #ifndef ETH_P_RSN_PREAUTH 329 #define ETH_P_RSN_PREAUTH 0x88c7 332 #define ETH_P_RRB 0x890D 337 #define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b)))) 338 #define STRUCT_PACKED __attribute__ ((packed)) 340 #define PRINTF_FORMAT(a,b) 341 #define STRUCT_PACKED 345 #ifdef CONFIG_ANSI_C_EXTRA 347 #if !defined(_MSC_VER) || _MSC_VER < 1400 352 int snprintf(
char *str,
size_t size,
const char *format, ...);
355 int vsnprintf(
char *str,
size_t size,
const char *format, va_list ap);
359 int getopt(
int argc,
char *
const argv[],
const char *optstring);
363 #ifndef CONFIG_NO_SOCKLEN_T_TYPEDEF 364 #ifndef __socklen_t_defined 365 typedef int socklen_t;
370 #ifdef CONFIG_NO_INLINE 373 #define inline __inline 377 #define __func__ "__func__ not defined" 381 #define bswap_16(a) ((((u16) (a) << 8) & 0xff00) | (((u16) (a) >> 8) & 0xff)) 385 #define bswap_32(a) ((((u32) (a) << 24) & 0xff000000) | \ 386 (((u32) (a) << 8) & 0xff0000) | \ 387 (((u32) (a) >> 8) & 0xff00) | \ 388 (((u32) (a) >> 24) & 0xff)) 392 #define MSG_DONTWAIT 0 396 void perror(
const char *s);
402 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] 403 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" 409 #define COMPACT_MACSTR "%02x%02x%02x%02x%02x%02x" 413 #define BIT(x) (1U << (x)) 421 #define __force __attribute__((force)) 423 #define __bitwise __attribute__((bitwise)) 429 typedef u16 __bitwise be16;
430 typedef u16 __bitwise le16;
431 typedef u32 __bitwise be32;
432 typedef u32 __bitwise le32;
433 typedef u64 __bitwise be64;
434 typedef u64 __bitwise le64;
437 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 438 #define __must_check __attribute__((__warn_unused_result__)) 444 #ifndef __maybe_unused 445 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 446 #define __maybe_unused __attribute__((unused)) 448 #define __maybe_unused 452 #define SSID_MAX_LEN 32 455 u8 ssid[SSID_MAX_LEN];
459 int hwaddr_aton(
const char *txt, u8 *addr);
460 int hwaddr_masked_aton(
const char *txt, u8 *addr, u8 *mask, u8 maskable);
461 int hwaddr_compact_aton(
const char *txt, u8 *addr);
462 int hwaddr_aton2(
const char *txt, u8 *addr);
463 int hex2byte(
const char *hex);
464 int hexstr2bin(
const char *hex, u8 *buf,
size_t len);
465 void inc_byte_array(u8 *counter,
size_t len);
466 void wpa_get_ntp_timestamp(u8 *buf);
467 int wpa_scnprintf(
char *buf,
size_t size,
const char *fmt, ...);
468 int wpa_snprintf_hex_sep(
char *buf,
size_t buf_size,
const u8 *data,
size_t len,
470 int wpa_snprintf_hex(
char *buf,
size_t buf_size,
const u8 *data,
size_t len);
471 int wpa_snprintf_hex_uppercase(
char *buf,
size_t buf_size,
const u8 *data,
474 int hwaddr_mask_txt(
char *buf,
size_t len,
const u8 *addr,
const u8 *mask);
477 #ifdef CONFIG_NATIVE_WINDOWS 478 void wpa_unicode2ascii_inplace(TCHAR *str);
479 TCHAR * wpa_strdup_tchar(
const char *str);
481 #define wpa_unicode2ascii_inplace(s) do { } while (0) 482 #define wpa_strdup_tchar(s) strdup((s)) 485 void printf_encode(
char *txt,
size_t maxlen,
const u8 *data,
size_t len);
486 size_t printf_decode(u8 *buf,
size_t maxlen,
const char *str);
488 const char * wpa_ssid_txt(
const u8 *ssid,
size_t ssid_len);
490 char * wpa_config_parse_string(
const char *value,
size_t *len);
491 int is_hex(
const u8 *data,
size_t len);
492 int has_ctrl_char(
const u8 *data,
size_t len);
493 int has_newline(
const char *str);
494 size_t merge_byte_arrays(u8 *res,
size_t res_len,
495 const u8 *src1,
size_t src1_len,
496 const u8 *src2,
size_t src2_len);
497 char * dup_binstr(
const void *src,
size_t len);
499 static inline int is_zero_ether_addr(
const u8 *a)
501 return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
504 static inline int is_broadcast_ether_addr(
const u8 *a)
506 return (a[0] & a[1] & a[2] & a[3] & a[4] & a[5]) == 0xff;
509 static inline int is_multicast_ether_addr(
const u8 *a)
514 #define broadcast_ether_addr (const u8 *) "\xff\xff\xff\xff\xff\xff" 516 #include "wpa_debug.h" 532 int int_array_len(
const int *a);
533 void int_array_concat(
int **res,
const int *a);
534 void int_array_sort_unique(
int *a);
535 void int_array_add_unique(
int **res,
int a);
537 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 539 void str_clear_free(
char *str);
540 void bin_clear_free(
void *bin,
size_t len);
542 int random_mac_addr(u8 *addr);
543 int random_mac_addr_keep_oui(u8 *addr);
545 const char * cstr_token(
const char *str,
const char *delim,
const char **last);
546 char * str_token(
char *str,
const char *delim,
char **context);
547 size_t utf8_escape(
const char *inp,
size_t in_size,
548 char *outp,
size_t out_size);
549 size_t utf8_unescape(
const char *inp,
size_t in_size,
550 char *outp,
size_t out_size);
551 int is_ctrl_char(
char c);
553 int str_starts(
const char *str,
const char *start);
555 u8 rssi_to_rcpi(
int rssi);
566 void * __hide_aliasing_typecast(
void *foo);
567 #define aliasing_hide_typecast(a,t) (t *) __hide_aliasing_typecast((a)) 569 #ifdef CONFIG_VALGRIND 570 #include <valgrind/memcheck.h> 571 #define WPA_MEM_DEFINED(ptr, len) VALGRIND_MAKE_MEM_DEFINED((ptr), (len)) 573 #define WPA_MEM_DEFINED(ptr, len) do { } while (0)