wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Macros | Typedefs | Functions
common.h File Reference

wpa_supplicant/hostapd / common helper functions, etc. More...

#include "os.h"
#include <stdint.h>
#include "wpa_debug.h"

Go to the source code of this file.

Data Structures

struct  wpa_freq_range_list
 
struct  wpa_freq_range_list::wpa_freq_range
 

Macros

#define WPA_TYPES_DEFINED
 
#define __LITTLE_ENDIAN   1234
 
#define __BIG_ENDIAN   4321
 
#define WPA_BYTE_SWAP_DEFINED
 
#define ETH_ALEN   6
 
#define ETH_HLEN   14
 
#define IFNAMSIZ   16
 
#define ETH_P_ALL   0x0003
 
#define ETH_P_80211_ENCAP   0x890d /* TDLS comes under this category */
 
#define ETH_P_PAE   0x888E /* Port Access Entity (IEEE 802.1X) */
 
#define ETH_P_EAPOL   ETH_P_PAE
 
#define ETH_P_RSN_PREAUTH   0x88c7
 
#define ETH_P_RRB   0x890D
 
#define PRINTF_FORMAT(a, b)
 
#define STRUCT_PACKED
 
#define MAC2STR(a)   (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
 
#define MACSTR   "%02x:%02x:%02x:%02x:%02x:%02x"
 
#define COMPACT_MACSTR   "%02x%02x%02x%02x%02x%02x"
 
#define BIT(x)   (1U << (x))
 
#define __force
 
#define __bitwise
 
#define __must_check
 
#define __maybe_unused
 
#define wpa_unicode2ascii_inplace(s)   do { } while (0)
 
#define wpa_strdup_tchar(s)   strdup((s))
 
#define broadcast_ether_addr   (const u8 *) "\xff\xff\xff\xff\xff\xff"
 
#define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
 
#define aliasing_hide_typecast(a, t)   (t *) __hide_aliasing_typecast((a))
 
#define WPA_MEM_DEFINED(ptr, len)   do { } while (0)
 

Typedefs

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
 
typedef u16 __bitwise be16
 
typedef u16 __bitwise le16
 
typedef u32 __bitwise be32
 
typedef u32 __bitwise le32
 
typedef u64 __bitwise be64
 
typedef u64 __bitwise le64
 

Functions

int hwaddr_aton (const char *txt, u8 *addr)
 Convert ASCII string to MAC address (colon-delimited format) More...
 
int hwaddr_masked_aton (const char *txt, u8 *addr, u8 *mask, u8 maskable)
 Convert ASCII string with optional mask to MAC address (colon-delimited format) More...
 
int hwaddr_compact_aton (const char *txt, u8 *addr)
 Convert ASCII string to MAC address (no colon delimitors format) More...
 
int hwaddr_aton2 (const char *txt, u8 *addr)
 Convert ASCII string to MAC address (in any known format) More...
 
int hex2byte (const char *hex)
 
int hexstr2bin (const char *hex, u8 *buf, size_t len)
 Convert ASCII hex string into binary data. More...
 
void inc_byte_array (u8 *counter, size_t len)
 Increment arbitrary length byte array by one. More...
 
void wpa_get_ntp_timestamp (u8 *buf)
 
int wpa_scnprintf (char *buf, size_t size, const char *fmt,...)
 Simpler-to-use snprintf function. More...
 
int wpa_snprintf_hex_sep (char *buf, size_t buf_size, const u8 *data, size_t len, char sep)
 
int wpa_snprintf_hex (char *buf, size_t buf_size, const u8 *data, size_t len)
 Print data as a hex string into a buffer. More...
 
int wpa_snprintf_hex_uppercase (char *buf, size_t buf_size, const u8 *data, size_t len)
 Print data as a upper case hex string into buf. More...
 
int hwaddr_mask_txt (char *buf, size_t len, const u8 *addr, const u8 *mask)
 
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)
 
const char * wpa_ssid_txt (const u8 *ssid, size_t ssid_len)
 Convert SSID to a printable string. More...
 
char * wpa_config_parse_string (const char *value, size_t *len)
 
int is_hex (const u8 *data, size_t len)
 
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)
 
char * dup_binstr (const void *src, size_t len)
 
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)
 
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)
 
void str_clear_free (char *str)
 
void bin_clear_free (void *bin, size_t len)
 
int random_mac_addr (u8 *addr)
 
int random_mac_addr_keep_oui (u8 *addr)
 
const char * cstr_token (const char *str, const char *delim, const char **last)
 Get next token from const char string. More...
 
char * str_token (char *str, const char *delim, char **context)
 Get next token from a string. More...
 
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)
 
int is_ctrl_char (char c)
 
void * __hide_aliasing_typecast (void *foo)
 

Detailed Description

wpa_supplicant/hostapd / common helper functions, etc.

Function Documentation

const char* cstr_token ( const char *  str,
const char *  delim,
const char **  last 
)

Get next token from const char string.

Parameters
stra constant string to tokenize
delima string of delimiters
lasta pointer to a character following the returned token It has to be set to NULL for the first call and passed for any futher call.
Returns
a pointer to token position in str or NULL

This function is similar to str_token, but it can be used with both char and const char strings. Differences:

  • The str buffer remains unmodified
  • The returned token is not a NULL terminated string, but a token position in str buffer. If a return value is not NULL a size of the returned token could be calculated as (last - token).
int hexstr2bin ( const char *  hex,
u8 *  buf,
size_t  len 
)

Convert ASCII hex string into binary data.

Parameters
hexASCII hex string (e.g., "01ab")
bufBuffer for the binary data
lenLength of the text to convert in bytes (of buf); hex will be double this size
Returns
0 on success, -1 on failure (invalid hex string)
int hwaddr_aton ( const char *  txt,
u8 *  addr 
)

Convert ASCII string to MAC address (colon-delimited format)

Parameters
txtMAC address as a string (e.g., "00:11:22:33:44:55")
addrBuffer for the MAC address (ETH_ALEN = 6 bytes)
Returns
0 on success, -1 on failure (e.g., string not a MAC address)
int hwaddr_aton2 ( const char *  txt,
u8 *  addr 
)

Convert ASCII string to MAC address (in any known format)

Parameters
txtMAC address as a string (e.g., 00:11:22:33:44:55 or 0011.2233.4455)
addrBuffer for the MAC address (ETH_ALEN = 6 bytes)
Returns
Characters used (> 0) on success, -1 on failure
int hwaddr_compact_aton ( const char *  txt,
u8 *  addr 
)

Convert ASCII string to MAC address (no colon delimitors format)

Parameters
txtMAC address as a string (e.g., "001122334455")
addrBuffer for the MAC address (ETH_ALEN = 6 bytes)
Returns
0 on success, -1 on failure (e.g., string not a MAC address)
int hwaddr_masked_aton ( const char *  txt,
u8 *  addr,
u8 *  mask,
u8  maskable 
)

Convert ASCII string with optional mask to MAC address (colon-delimited format)

Parameters
txtMAC address with optional mask as a string (e.g., "00:11:22:33:44:55/ff:ff:ff:ff:00:00")
addrBuffer for the MAC address (ETH_ALEN = 6 bytes)
maskBuffer for the MAC address mask (ETH_ALEN = 6 bytes)
maskableFlag to indicate whether a mask is allowed
Returns
0 on success, -1 on failure (e.g., string not a MAC address)
void inc_byte_array ( u8 *  counter,
size_t  len 
)

Increment arbitrary length byte array by one.

Parameters
counterPointer to byte array
lenLength of the counter in bytes

This function increments the last byte of the counter by one and continues rolling over to more significant bytes if the byte was incremented from 0xff to 0x00.

char* str_token ( char *  str,
const char *  delim,
char **  context 
)

Get next token from a string.

Parameters
bufString to tokenize. Note that the string might be modified.
delimString of delimiters
contextPointer to save our context. Should be initialized with NULL on the first call, and passed for any further call.
Returns
The next token, NULL if there are no more valid tokens.
int wpa_scnprintf ( char *  buf,
size_t  size,
const char *  fmt,
  ... 
)

Simpler-to-use snprintf function.

Parameters
bufOutput buffer
sizeBuffer size
fmtformat

Simpler snprintf version that doesn't require further error checks - the return value only indicates how many bytes were actually written, excluding the NULL byte (i.e., 0 on error, size-1 if buffer is not big enough).

int wpa_snprintf_hex ( char *  buf,
size_t  buf_size,
const u8 *  data,
size_t  len 
)

Print data as a hex string into a buffer.

Parameters
bufMemory area to use as the output buffer
buf_sizeMaximum buffer size in bytes (should be at least 2 * len + 1)
dataData to be printed
lenLength of data in bytes
Returns
Number of bytes written
int wpa_snprintf_hex_uppercase ( char *  buf,
size_t  buf_size,
const u8 *  data,
size_t  len 
)

Print data as a upper case hex string into buf.

Parameters
bufMemory area to use as the output buffer
buf_sizeMaximum buffer size in bytes (should be at least 2 * len + 1)
dataData to be printed
lenLength of data in bytes
Returns
Number of bytes written
const char* wpa_ssid_txt ( const u8 *  ssid,
size_t  ssid_len 
)

Convert SSID to a printable string.

Parameters
ssidSSID (32-octet string)
ssid_lenLength of ssid in octets
Returns
Pointer to a printable string

This function can be used to convert SSIDs into printable form. In most cases, SSIDs do not use unprintable characters, but IEEE 802.11 standard does not limit the used character set, so anything could be used in an SSID.

This function uses a static buffer, so only one call can be used at the time, i.e., this is not re-entrant and the returned buffer must be used before calling this again.