2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* wpa_supplicant/hostapd / common helper functions, etc.
|
|
|
|
* Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
|
2010-03-06 09:16:47 +01:00
|
|
|
#if defined(__linux__) || defined(__GLIBC__)
|
2008-02-28 02:34:43 +01:00
|
|
|
#include <endian.h>
|
|
|
|
#include <byteswap.h>
|
|
|
|
#endif /* __linux__ */
|
|
|
|
|
2009-08-26 22:40:51 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
|
|
|
|
defined(__OpenBSD__)
|
2008-02-28 02:34:43 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#define __BYTE_ORDER _BYTE_ORDER
|
|
|
|
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
|
|
|
#define __BIG_ENDIAN _BIG_ENDIAN
|
2009-08-26 22:40:51 +02:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#define bswap_16 swap16
|
|
|
|
#define bswap_32 swap32
|
|
|
|
#define bswap_64 swap64
|
|
|
|
#else /* __OpenBSD__ */
|
2008-02-28 02:34:43 +01:00
|
|
|
#define bswap_16 bswap16
|
|
|
|
#define bswap_32 bswap32
|
|
|
|
#define bswap_64 bswap64
|
2009-08-26 22:40:51 +02:00
|
|
|
#endif /* __OpenBSD__ */
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif /* defined(__FreeBSD__) || defined(__NetBSD__) ||
|
2009-08-26 22:40:51 +02:00
|
|
|
* defined(__DragonFly__) || defined(__OpenBSD__) */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <machine/endian.h>
|
|
|
|
#define __BYTE_ORDER _BYTE_ORDER
|
|
|
|
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
|
|
|
#define __BIG_ENDIAN _BIG_ENDIAN
|
|
|
|
static inline unsigned short bswap_16(unsigned short v)
|
|
|
|
{
|
|
|
|
return ((v & 0xff) << 8) | (v >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int bswap_32(unsigned int v)
|
|
|
|
{
|
|
|
|
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
|
|
|
|
((v & 0xff0000) >> 8) | (v >> 24);
|
|
|
|
}
|
|
|
|
#endif /* __APPLE__ */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NATIVE_WINDOWS
|
|
|
|
#include <winsock.h>
|
|
|
|
|
|
|
|
typedef int socklen_t;
|
|
|
|
|
|
|
|
#ifndef MSG_DONTWAIT
|
|
|
|
#define MSG_DONTWAIT 0 /* not supported */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_NATIVE_WINDOWS */
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define inline __inline
|
|
|
|
|
|
|
|
#undef vsnprintf
|
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#undef close
|
|
|
|
#define close closesocket
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
|
|
|
|
|
|
|
/* Define platform specific integer types */
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
typedef UINT64 u64;
|
|
|
|
typedef UINT32 u32;
|
|
|
|
typedef UINT16 u16;
|
|
|
|
typedef UINT8 u8;
|
|
|
|
typedef INT64 s64;
|
|
|
|
typedef INT32 s32;
|
|
|
|
typedef INT16 s16;
|
|
|
|
typedef INT8 s8;
|
|
|
|
#define WPA_TYPES_DEFINED
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
|
|
|
#ifdef __vxworks
|
|
|
|
typedef unsigned long long u64;
|
|
|
|
typedef UINT32 u32;
|
|
|
|
typedef UINT16 u16;
|
|
|
|
typedef UINT8 u8;
|
|
|
|
typedef long long s64;
|
|
|
|
typedef INT32 s32;
|
|
|
|
typedef INT16 s16;
|
|
|
|
typedef INT8 s8;
|
|
|
|
#define WPA_TYPES_DEFINED
|
|
|
|
#endif /* __vxworks */
|
|
|
|
|
|
|
|
#ifndef WPA_TYPES_DEFINED
|
|
|
|
#ifdef CONFIG_USE_INTTYPES_H
|
|
|
|
#include <inttypes.h>
|
|
|
|
#else
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
typedef uint64_t u64;
|
|
|
|
typedef uint32_t u32;
|
|
|
|
typedef uint16_t u16;
|
|
|
|
typedef uint8_t u8;
|
|
|
|
typedef int64_t s64;
|
|
|
|
typedef int32_t s32;
|
|
|
|
typedef int16_t s16;
|
|
|
|
typedef int8_t s8;
|
|
|
|
#define WPA_TYPES_DEFINED
|
|
|
|
#endif /* !WPA_TYPES_DEFINED */
|
|
|
|
|
|
|
|
|
|
|
|
/* Define platform specific byte swapping macros */
|
|
|
|
|
|
|
|
#if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
|
|
|
|
|
|
|
|
static inline unsigned short wpa_swap_16(unsigned short v)
|
|
|
|
{
|
|
|
|
return ((v & 0xff) << 8) | (v >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int wpa_swap_32(unsigned int v)
|
|
|
|
{
|
|
|
|
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
|
|
|
|
((v & 0xff0000) >> 8) | (v >> 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define le_to_host16(n) (n)
|
|
|
|
#define host_to_le16(n) (n)
|
|
|
|
#define be_to_host16(n) wpa_swap_16(n)
|
|
|
|
#define host_to_be16(n) wpa_swap_16(n)
|
|
|
|
#define le_to_host32(n) (n)
|
2015-01-10 23:52:19 +01:00
|
|
|
#define host_to_le32(n) (n)
|
2008-02-28 02:34:43 +01:00
|
|
|
#define be_to_host32(n) wpa_swap_32(n)
|
|
|
|
#define host_to_be32(n) wpa_swap_32(n)
|
|
|
|
|
|
|
|
#define WPA_BYTE_SWAP_DEFINED
|
|
|
|
|
|
|
|
#endif /* __CYGWIN__ || CONFIG_NATIVE_WINDOWS */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WPA_BYTE_SWAP_DEFINED
|
|
|
|
|
|
|
|
#ifndef __BYTE_ORDER
|
|
|
|
#ifndef __LITTLE_ENDIAN
|
|
|
|
#ifndef __BIG_ENDIAN
|
|
|
|
#define __LITTLE_ENDIAN 1234
|
|
|
|
#define __BIG_ENDIAN 4321
|
|
|
|
#if defined(sparc)
|
|
|
|
#define __BYTE_ORDER __BIG_ENDIAN
|
|
|
|
#endif
|
|
|
|
#endif /* __BIG_ENDIAN */
|
|
|
|
#endif /* __LITTLE_ENDIAN */
|
|
|
|
#endif /* __BYTE_ORDER */
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#define le_to_host16(n) ((__force u16) (le16) (n))
|
|
|
|
#define host_to_le16(n) ((__force le16) (u16) (n))
|
|
|
|
#define be_to_host16(n) bswap_16((__force u16) (be16) (n))
|
|
|
|
#define host_to_be16(n) ((__force be16) bswap_16((n)))
|
|
|
|
#define le_to_host32(n) ((__force u32) (le32) (n))
|
|
|
|
#define host_to_le32(n) ((__force le32) (u32) (n))
|
|
|
|
#define be_to_host32(n) bswap_32((__force u32) (be32) (n))
|
|
|
|
#define host_to_be32(n) ((__force be32) bswap_32((n)))
|
|
|
|
#define le_to_host64(n) ((__force u64) (le64) (n))
|
|
|
|
#define host_to_le64(n) ((__force le64) (u64) (n))
|
|
|
|
#define be_to_host64(n) bswap_64((__force u64) (be64) (n))
|
|
|
|
#define host_to_be64(n) ((__force be64) bswap_64((n)))
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
#define le_to_host16(n) bswap_16(n)
|
|
|
|
#define host_to_le16(n) bswap_16(n)
|
|
|
|
#define be_to_host16(n) (n)
|
|
|
|
#define host_to_be16(n) (n)
|
|
|
|
#define le_to_host32(n) bswap_32(n)
|
2013-07-20 16:17:32 +02:00
|
|
|
#define host_to_le32(n) bswap_32(n)
|
2008-02-28 02:34:43 +01:00
|
|
|
#define be_to_host32(n) (n)
|
|
|
|
#define host_to_be32(n) (n)
|
|
|
|
#define le_to_host64(n) bswap_64(n)
|
|
|
|
#define host_to_le64(n) bswap_64(n)
|
|
|
|
#define be_to_host64(n) (n)
|
|
|
|
#define host_to_be64(n) (n)
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
|
|
|
#define WORDS_BIGENDIAN
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#error Could not determine CPU byte order
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WPA_BYTE_SWAP_DEFINED
|
|
|
|
#endif /* !WPA_BYTE_SWAP_DEFINED */
|
|
|
|
|
|
|
|
|
|
|
|
/* Macros for handling unaligned memory accesses */
|
|
|
|
|
2013-01-01 19:32:36 +01:00
|
|
|
static inline u16 WPA_GET_BE16(const u8 *a)
|
|
|
|
{
|
|
|
|
return (a[0] << 8) | a[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_BE16(u8 *a, u16 val)
|
|
|
|
{
|
|
|
|
a[0] = val >> 8;
|
|
|
|
a[1] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u16 WPA_GET_LE16(const u8 *a)
|
|
|
|
{
|
|
|
|
return (a[1] << 8) | a[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_LE16(u8 *a, u16 val)
|
|
|
|
{
|
|
|
|
a[1] = val >> 8;
|
|
|
|
a[0] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 WPA_GET_BE24(const u8 *a)
|
|
|
|
{
|
|
|
|
return (a[0] << 16) | (a[1] << 8) | a[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_BE24(u8 *a, u32 val)
|
|
|
|
{
|
|
|
|
a[0] = (val >> 16) & 0xff;
|
|
|
|
a[1] = (val >> 8) & 0xff;
|
|
|
|
a[2] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 WPA_GET_BE32(const u8 *a)
|
|
|
|
{
|
2015-07-07 14:54:31 +02:00
|
|
|
return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
|
2013-01-01 19:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_BE32(u8 *a, u32 val)
|
|
|
|
{
|
|
|
|
a[0] = (val >> 24) & 0xff;
|
|
|
|
a[1] = (val >> 16) & 0xff;
|
|
|
|
a[2] = (val >> 8) & 0xff;
|
|
|
|
a[3] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 WPA_GET_LE32(const u8 *a)
|
|
|
|
{
|
2015-07-07 14:54:31 +02:00
|
|
|
return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0];
|
2013-01-01 19:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_LE32(u8 *a, u32 val)
|
|
|
|
{
|
|
|
|
a[3] = (val >> 24) & 0xff;
|
|
|
|
a[2] = (val >> 16) & 0xff;
|
|
|
|
a[1] = (val >> 8) & 0xff;
|
|
|
|
a[0] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 WPA_GET_BE64(const u8 *a)
|
|
|
|
{
|
|
|
|
return (((u64) a[0]) << 56) | (((u64) a[1]) << 48) |
|
|
|
|
(((u64) a[2]) << 40) | (((u64) a[3]) << 32) |
|
|
|
|
(((u64) a[4]) << 24) | (((u64) a[5]) << 16) |
|
|
|
|
(((u64) a[6]) << 8) | ((u64) a[7]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_BE64(u8 *a, u64 val)
|
|
|
|
{
|
|
|
|
a[0] = val >> 56;
|
|
|
|
a[1] = val >> 48;
|
|
|
|
a[2] = val >> 40;
|
|
|
|
a[3] = val >> 32;
|
|
|
|
a[4] = val >> 24;
|
|
|
|
a[5] = val >> 16;
|
|
|
|
a[6] = val >> 8;
|
|
|
|
a[7] = val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 WPA_GET_LE64(const u8 *a)
|
|
|
|
{
|
|
|
|
return (((u64) a[7]) << 56) | (((u64) a[6]) << 48) |
|
|
|
|
(((u64) a[5]) << 40) | (((u64) a[4]) << 32) |
|
|
|
|
(((u64) a[3]) << 24) | (((u64) a[2]) << 16) |
|
|
|
|
(((u64) a[1]) << 8) | ((u64) a[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void WPA_PUT_LE64(u8 *a, u64 val)
|
|
|
|
{
|
|
|
|
a[7] = val >> 56;
|
|
|
|
a[6] = val >> 48;
|
|
|
|
a[5] = val >> 40;
|
|
|
|
a[4] = val >> 32;
|
|
|
|
a[3] = val >> 24;
|
|
|
|
a[2] = val >> 16;
|
|
|
|
a[1] = val >> 8;
|
|
|
|
a[0] = val & 0xff;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef ETH_ALEN
|
|
|
|
#define ETH_ALEN 6
|
|
|
|
#endif
|
2014-09-25 08:17:29 +02:00
|
|
|
#ifndef ETH_HLEN
|
|
|
|
#define ETH_HLEN 14
|
|
|
|
#endif
|
2009-11-23 15:14:39 +01:00
|
|
|
#ifndef IFNAMSIZ
|
|
|
|
#define IFNAMSIZ 16
|
|
|
|
#endif
|
|
|
|
#ifndef ETH_P_ALL
|
|
|
|
#define ETH_P_ALL 0x0003
|
|
|
|
#endif
|
2010-10-07 09:26:56 +02:00
|
|
|
#ifndef ETH_P_80211_ENCAP
|
|
|
|
#define ETH_P_80211_ENCAP 0x890d /* TDLS comes under this category */
|
|
|
|
#endif
|
2009-11-23 15:14:39 +01:00
|
|
|
#ifndef ETH_P_PAE
|
|
|
|
#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
|
|
|
|
#endif /* ETH_P_PAE */
|
|
|
|
#ifndef ETH_P_EAPOL
|
|
|
|
#define ETH_P_EAPOL ETH_P_PAE
|
|
|
|
#endif /* ETH_P_EAPOL */
|
|
|
|
#ifndef ETH_P_RSN_PREAUTH
|
|
|
|
#define ETH_P_RSN_PREAUTH 0x88c7
|
|
|
|
#endif /* ETH_P_RSN_PREAUTH */
|
|
|
|
#ifndef ETH_P_RRB
|
|
|
|
#define ETH_P_RRB 0x890D
|
|
|
|
#endif /* ETH_P_RRB */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
|
|
|
|
#define STRUCT_PACKED __attribute__ ((packed))
|
|
|
|
#else
|
|
|
|
#define PRINTF_FORMAT(a,b)
|
|
|
|
#define STRUCT_PACKED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_ANSI_C_EXTRA
|
|
|
|
|
|
|
|
#if !defined(_MSC_VER) || _MSC_VER < 1400
|
|
|
|
/* snprintf - used in number of places; sprintf() is _not_ a good replacement
|
|
|
|
* due to possible buffer overflow; see, e.g.,
|
|
|
|
* http://www.ijs.si/software/snprintf/ for portable implementation of
|
|
|
|
* snprintf. */
|
|
|
|
int snprintf(char *str, size_t size, const char *format, ...);
|
|
|
|
|
|
|
|
/* vsnprintf - only used for wpa_msg() in wpa_supplicant.c */
|
|
|
|
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
|
|
|
#endif /* !defined(_MSC_VER) || _MSC_VER < 1400 */
|
|
|
|
|
|
|
|
/* getopt - only used in main.c */
|
|
|
|
int getopt(int argc, char *const argv[], const char *optstring);
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
|
|
|
#ifndef CONFIG_NO_SOCKLEN_T_TYPEDEF
|
|
|
|
#ifndef __socklen_t_defined
|
|
|
|
typedef int socklen_t;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* inline - define as __inline or just define it to be empty, if needed */
|
|
|
|
#ifdef CONFIG_NO_INLINE
|
|
|
|
#define inline
|
|
|
|
#else
|
|
|
|
#define inline __inline
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __func__
|
|
|
|
#define __func__ "__func__ not defined"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef bswap_16
|
|
|
|
#define bswap_16(a) ((((u16) (a) << 8) & 0xff00) | (((u16) (a) >> 8) & 0xff))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef bswap_32
|
|
|
|
#define bswap_32(a) ((((u32) (a) << 24) & 0xff000000) | \
|
|
|
|
(((u32) (a) << 8) & 0xff0000) | \
|
|
|
|
(((u32) (a) >> 8) & 0xff00) | \
|
|
|
|
(((u32) (a) >> 24) & 0xff))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MSG_DONTWAIT
|
|
|
|
#define MSG_DONTWAIT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
void perror(const char *s);
|
|
|
|
#endif /* _WIN32_WCE */
|
|
|
|
|
|
|
|
#endif /* CONFIG_ANSI_C_EXTRA */
|
|
|
|
|
|
|
|
#ifndef MAC2STR
|
|
|
|
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
|
|
|
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
2011-02-02 16:11:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compact form for string representation of MAC address
|
|
|
|
* To be used, e.g., for constructing dbus paths for P2P Devices
|
|
|
|
*/
|
|
|
|
#define COMPACT_MACSTR "%02x%02x%02x%02x%02x%02x"
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef BIT
|
2015-07-07 11:33:03 +02:00
|
|
|
#define BIT(x) (1U << (x))
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Definitions for sparse validation
|
|
|
|
* (http://kernel.org/pub/linux/kernel/people/josh/sparse/)
|
|
|
|
*/
|
|
|
|
#ifdef __CHECKER__
|
|
|
|
#define __force __attribute__((force))
|
|
|
|
#define __bitwise __attribute__((bitwise))
|
|
|
|
#else
|
|
|
|
#define __force
|
|
|
|
#define __bitwise
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef u16 __bitwise be16;
|
|
|
|
typedef u16 __bitwise le16;
|
|
|
|
typedef u32 __bitwise be32;
|
|
|
|
typedef u32 __bitwise le32;
|
|
|
|
typedef u64 __bitwise be64;
|
|
|
|
typedef u64 __bitwise le64;
|
|
|
|
|
|
|
|
#ifndef __must_check
|
|
|
|
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
|
|
|
#define __must_check __attribute__((__warn_unused_result__))
|
|
|
|
#else
|
|
|
|
#define __must_check
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* __must_check */
|
2013-12-29 12:37:17 +01:00
|
|
|
|
|
|
|
#ifndef __maybe_unused
|
|
|
|
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
|
|
|
#define __maybe_unused __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#define __maybe_unused
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* __must_check */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
int hwaddr_aton(const char *txt, u8 *addr);
|
2015-01-05 21:10:16 +01:00
|
|
|
int hwaddr_masked_aton(const char *txt, u8 *addr, u8 *mask, u8 maskable);
|
2011-02-02 16:11:00 +01:00
|
|
|
int hwaddr_compact_aton(const char *txt, u8 *addr);
|
2010-04-06 09:37:13 +02:00
|
|
|
int hwaddr_aton2(const char *txt, u8 *addr);
|
2010-12-16 15:11:54 +01:00
|
|
|
int hex2byte(const char *hex);
|
2008-02-28 02:34:43 +01:00
|
|
|
int hexstr2bin(const char *hex, u8 *buf, size_t len);
|
|
|
|
void inc_byte_array(u8 *counter, size_t len);
|
|
|
|
void wpa_get_ntp_timestamp(u8 *buf);
|
2014-10-22 14:04:02 +02:00
|
|
|
int wpa_scnprintf(char *buf, size_t size, const char *fmt, ...);
|
2015-03-29 21:27:43 +02:00
|
|
|
int wpa_snprintf_hex_sep(char *buf, size_t buf_size, const u8 *data, size_t len,
|
|
|
|
char sep);
|
2008-02-28 02:34:43 +01:00
|
|
|
int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len);
|
|
|
|
int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data,
|
|
|
|
size_t len);
|
|
|
|
|
2015-01-05 21:10:16 +01:00
|
|
|
int hwaddr_mask_txt(char *buf, size_t len, const u8 *addr, const u8 *mask);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
#ifdef CONFIG_NATIVE_WINDOWS
|
|
|
|
void wpa_unicode2ascii_inplace(TCHAR *str);
|
|
|
|
TCHAR * wpa_strdup_tchar(const char *str);
|
|
|
|
#else /* CONFIG_NATIVE_WINDOWS */
|
|
|
|
#define wpa_unicode2ascii_inplace(s) do { } while (0)
|
|
|
|
#define wpa_strdup_tchar(s) strdup((s))
|
|
|
|
#endif /* CONFIG_NATIVE_WINDOWS */
|
|
|
|
|
2012-08-07 12:30:13 +02:00
|
|
|
void printf_encode(char *txt, size_t maxlen, const u8 *data, size_t len);
|
|
|
|
size_t printf_decode(u8 *buf, size_t maxlen, const char *str);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
|
|
|
|
|
2012-08-07 15:13:51 +02:00
|
|
|
char * wpa_config_parse_string(const char *value, size_t *len);
|
2012-08-07 15:27:40 +02:00
|
|
|
int is_hex(const u8 *data, size_t len);
|
2012-08-19 16:52:41 +02:00
|
|
|
size_t merge_byte_arrays(u8 *res, size_t res_len,
|
|
|
|
const u8 *src1, size_t src1_len,
|
|
|
|
const u8 *src2, size_t src2_len);
|
2013-04-27 22:44:59 +02:00
|
|
|
char * dup_binstr(const void *src, size_t len);
|
2012-08-07 15:13:51 +02:00
|
|
|
|
2008-06-03 17:08:48 +02:00
|
|
|
static inline int is_zero_ether_addr(const u8 *a)
|
|
|
|
{
|
|
|
|
return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2010-11-18 23:35:13 +01:00
|
|
|
static inline int is_broadcast_ether_addr(const u8 *a)
|
|
|
|
{
|
|
|
|
return (a[0] & a[1] & a[2] & a[3] & a[4] & a[5]) == 0xff;
|
|
|
|
}
|
|
|
|
|
2015-01-27 15:30:08 +01:00
|
|
|
static inline int is_multicast_ether_addr(const u8 *a)
|
|
|
|
{
|
|
|
|
return a[0] & 0x01;
|
|
|
|
}
|
|
|
|
|
2011-01-09 18:44:28 +01:00
|
|
|
#define broadcast_ether_addr (const u8 *) "\xff\xff\xff\xff\xff\xff"
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "wpa_debug.h"
|
|
|
|
|
2009-11-04 18:49:14 +01:00
|
|
|
|
2013-10-22 18:10:56 +02:00
|
|
|
struct wpa_freq_range_list {
|
|
|
|
struct wpa_freq_range {
|
|
|
|
unsigned int min;
|
|
|
|
unsigned int max;
|
|
|
|
} *range;
|
|
|
|
unsigned int num;
|
|
|
|
};
|
|
|
|
|
|
|
|
int freq_range_list_parse(struct wpa_freq_range_list *res, const char *value);
|
|
|
|
int freq_range_list_includes(const struct wpa_freq_range_list *list,
|
|
|
|
unsigned int freq);
|
|
|
|
char * freq_range_list_str(const struct wpa_freq_range_list *list);
|
|
|
|
|
2013-12-25 19:02:57 +01:00
|
|
|
int int_array_len(const int *a);
|
|
|
|
void int_array_concat(int **res, const int *a);
|
|
|
|
void int_array_sort_unique(int *a);
|
|
|
|
void int_array_add_unique(int **res, int a);
|
|
|
|
|
2013-10-26 16:00:01 +02:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
|
2014-06-30 00:32:07 +02:00
|
|
|
void str_clear_free(char *str);
|
|
|
|
void bin_clear_free(void *bin, size_t len);
|
|
|
|
|
2014-09-27 18:12:02 +02:00
|
|
|
int random_mac_addr(u8 *addr);
|
2014-09-29 22:23:11 +02:00
|
|
|
int random_mac_addr_keep_oui(u8 *addr);
|
2014-09-27 18:12:02 +02:00
|
|
|
|
2015-07-02 15:21:19 +02:00
|
|
|
const char * cstr_token(const char *str, const char *delim, const char **last);
|
2014-10-22 14:03:58 +02:00
|
|
|
char * str_token(char *str, const char *delim, char **context);
|
2014-09-05 15:43:57 +02:00
|
|
|
size_t utf8_escape(const char *inp, size_t in_size,
|
|
|
|
char *outp, size_t out_size);
|
|
|
|
size_t utf8_unescape(const char *inp, size_t in_size,
|
|
|
|
char *outp, size_t out_size);
|
2015-04-07 14:43:32 +02:00
|
|
|
int is_ctrl_char(char c);
|
2014-10-22 14:03:58 +02:00
|
|
|
|
2014-06-30 00:32:07 +02:00
|
|
|
|
2009-11-04 18:49:14 +01:00
|
|
|
/*
|
|
|
|
* gcc 4.4 ends up generating strict-aliasing warnings about some very common
|
|
|
|
* networking socket uses that do not really result in a real problem and
|
|
|
|
* cannot be easily avoided with union-based type-punning due to struct
|
|
|
|
* definitions including another struct in system header files. To avoid having
|
|
|
|
* to fully disable strict-aliasing warnings, provide a mechanism to hide the
|
|
|
|
* typecast from aliasing for now. A cleaner solution will hopefully be found
|
|
|
|
* in the future to handle these cases.
|
|
|
|
*/
|
|
|
|
void * __hide_aliasing_typecast(void *foo);
|
|
|
|
#define aliasing_hide_typecast(a,t) (t *) __hide_aliasing_typecast((a))
|
|
|
|
|
2011-01-27 12:59:00 +01:00
|
|
|
#ifdef CONFIG_VALGRIND
|
|
|
|
#include <valgrind/memcheck.h>
|
|
|
|
#define WPA_MEM_DEFINED(ptr, len) VALGRIND_MAKE_MEM_DEFINED((ptr), (len))
|
|
|
|
#else /* CONFIG_VALGRIND */
|
|
|
|
#define WPA_MEM_DEFINED(ptr, len) do { } while (0)
|
|
|
|
#endif /* CONFIG_VALGRIND */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif /* COMMON_H */
|