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.
Defines |
|
#define | WPA_TYPES_DEFINED |
|
#define | __LITTLE_ENDIAN 1234 |
|
#define | __BIG_ENDIAN 4321 |
|
#define | WPA_BYTE_SWAP_DEFINED |
|
#define | WPA_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1])) |
| #define | WPA_PUT_BE16(a, val) |
|
#define | WPA_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0])) |
| #define | WPA_PUT_LE16(a, val) |
| #define | WPA_GET_BE24(a) |
| #define | WPA_PUT_BE24(a, val) |
| #define | WPA_GET_BE32(a) |
| #define | WPA_PUT_BE32(a, val) |
| #define | WPA_GET_LE32(a) |
| #define | WPA_PUT_LE32(a, val) |
| #define | WPA_GET_BE64(a) |
| #define | WPA_PUT_BE64(a, val) |
| #define | WPA_GET_LE64(a) |
|
#define | ETH_ALEN 6 |
|
#define | IFNAMSIZ 16 |
|
#define | ETH_P_ALL 0x0003 |
|
#define | ETH_P_PAE 0x888E |
|
#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 |
| | WPA Pairwise Transient Key.
|
|
#define | MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] |
|
#define | MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" |
|
#define | BIT(x) (1 << (x)) |
|
#define | __force |
|
#define | __bitwise |
|
#define | wpa_unicode2ascii_inplace(s) do { } while (0) |
|
#define | wpa_strdup_tchar(s) strdup((s)) |
|
#define | aliasing_hide_typecast(a, t) (t *) __hide_aliasing_typecast((a)) |
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.
|
| int | hexstr2bin (const char *hex, u8 *buf, size_t len) |
| | Convert ASCII hex string into binary data.
|
| void | inc_byte_array (u8 *counter, size_t len) |
| | Increment arbitrary length byte array by one.
|
|
void | wpa_get_ntp_timestamp (u8 *buf) |
| 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.
|
| 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.
|
| const char * | wpa_ssid_txt (const u8 *ssid, size_t ssid_len) |
| | Convert SSID to a printable string.
|
|
void * | __hide_aliasing_typecast (void *foo) |
Detailed Description
wpa_supplicant/hostapd / common helper functions, etc.
- Copyright
- Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
Alternatively, this software may be distributed under the terms of BSD license.
See README and COPYING for more details.
Define Documentation
WPA Pairwise Transient Key.
IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
| #define WPA_GET_BE24 |
( |
a |
|
) |
|
Value:((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
((u32) (a)[2]))
| #define WPA_GET_BE32 |
( |
a |
|
) |
|
Value:((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
(((u32) (a)[2]) << 8) | ((u32) (a)[3]))
| #define WPA_GET_BE64 |
( |
a |
|
) |
|
Value:((((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]))
| #define WPA_GET_LE32 |
( |
a |
|
) |
|
Value:((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \
(((u32) (a)[1]) << 8) | ((u32) (a)[0]))
| #define WPA_GET_LE64 |
( |
a |
|
) |
|
Value:((((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]))
| #define WPA_PUT_BE16 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[0] = ((u16) (val)) >> 8; \
(a)[1] = ((u16) (val)) & 0xff; \
} while (0)
| #define WPA_PUT_BE24 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
(a)[2] = (u8) (((u32) (val)) & 0xff); \
} while (0)
| #define WPA_PUT_BE32 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
(a)[3] = (u8) (((u32) (val)) & 0xff); \
} while (0)
| #define WPA_PUT_BE64 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[0] = (u8) (((u64) (val)) >> 56); \
(a)[1] = (u8) (((u64) (val)) >> 48); \
(a)[2] = (u8) (((u64) (val)) >> 40); \
(a)[3] = (u8) (((u64) (val)) >> 32); \
(a)[4] = (u8) (((u64) (val)) >> 24); \
(a)[5] = (u8) (((u64) (val)) >> 16); \
(a)[6] = (u8) (((u64) (val)) >> 8); \
(a)[7] = (u8) (((u64) (val)) & 0xff); \
} while (0)
| #define WPA_PUT_LE16 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[1] = ((u16) (val)) >> 8; \
(a)[0] = ((u16) (val)) & 0xff; \
} while (0)
| #define WPA_PUT_LE32 |
( |
a, |
|
|
val |
|
) |
|
Value:do { \
(a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \
(a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
(a)[0] = (u8) (((u32) (val)) & 0xff); \
} while (0)
Function Documentation
| int hexstr2bin |
( |
const char * |
hex, |
|
|
u8 * |
buf, |
|
|
size_t |
len | |
|
) |
| | |
Convert ASCII hex string into binary data.
- Parameters:
-
| hex | ASCII hex string (e.g., "01ab") |
| buf | Buffer for the binary data |
| len | Length 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.
- Parameters:
-
| txt | MAC address as a string (e.g., "00:11:22:33:44:55") |
| addr | Buffer for the MAC address (ETH_ALEN = 6 bytes) |
- 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:
-
| counter | Pointer to byte array |
| len | Length 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.
| 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:
-
| buf | Memory area to use as the output buffer |
| buf_size | Maximum buffer size in bytes (should be at least 2 * len + 1) |
| data | Data to be printed |
| len | Length 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:
-
| buf | Memory area to use as the output buffer |
| buf_size | Maximum buffer size in bytes (should be at least 2 * len + 1) |
| data | Data to be printed |
| len | Length 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:
-
| ssid | SSID (32-octet string) |
| ssid_len | Length 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.