common.h File Reference

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

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

Include dependency graph for common.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __LITTLE_ENDIAN   1234
#define __BIG_ENDIAN   4321
#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_PUT_BE64(a, val)
#define ETH_ALEN   6
#define WPA_TYPES_DEFINED
#define hostapd_get_rand   os_get_random
#define PRINTF_FORMAT(a, b)
#define STRUCT_PACKED
#define WPA_ASSERT(a)   do { } while (0)
#define wpa_zalloc(s)   os_zalloc((s))
#define wpa_unicode2ascii_inplace(s)   do { } while (0)
#define wpa_strdup_tchar(s)   strdup((s))

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 u32 __be32
typedef u64 __be64

Enumerations

enum  {
  MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING,
  MSG_ERROR
}

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_debug_open_file (void)
void wpa_debug_close_file (void)
void wpa_debug_print_timestamp (void)
 Print timestamp for debug output.
void wpa_printf (int level, char *fmt,...) PRINTF_FORMAT(2
 conditional printf
void void wpa_hexdump (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump
void wpa_hexdump_key (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump, hide keys
void wpa_hexdump_ascii (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump
void wpa_hexdump_ascii_key (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump, hide keys
void wpa_msg (void *ctx, int level, char *fmt,...) PRINTF_FORMAT(3
 Conditional printf for default target and ctrl_iface monitors.
void wpa_msg_register_cb (wpa_msg_cb_func func)
 Register callback function for wpa_msg() messages.
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 (u8 *ssid, size_t ssid_len)
 Convert SSID to a printable string.

Variables

void typedef void(* wpa_msg_cb_func )(void *ctx, int level, const char *txt, size_t len)


Detailed Description

wpa_supplicant/hostapd / common helper functions, etc.

Copyright
Copyright (c) 2002-2006, Jouni Malinen <[email protected]>
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.

Definition in file common.h.


Define Documentation

#define WPA_GET_BE24  ) 
 

Value:

((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
                         ((u32) (a)[2]))

Definition at line 146 of file common.h.

#define WPA_GET_BE32  ) 
 

Value:

((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
                         (((u32) (a)[2]) << 8) | ((u32) (a)[3]))

Definition at line 155 of file common.h.

#define WPA_PUT_BE16 a,
val   ) 
 

Value:

do {                                    \
                (a)[0] = ((u16) (val)) >> 8;    \
                (a)[1] = ((u16) (val)) & 0xff;  \
        } while (0)

Definition at line 133 of file common.h.

#define WPA_PUT_BE24 a,
val   ) 
 

Value:

do {                                            \
                (a)[0] = (u8) (((u32) (val)) >> 16);    \
                (a)[1] = (u8) (((u32) (val)) >> 8);     \
                (a)[2] = (u8) (((u32) (val)) & 0xff);   \
        } while (0)

Definition at line 148 of file common.h.

#define WPA_PUT_BE32 a,
val   ) 
 

Value:

do {                                            \
                (a)[0] = (u8) (((u32) (val)) >> 24);    \
                (a)[1] = (u8) (((u32) (val)) >> 16);    \
                (a)[2] = (u8) (((u32) (val)) >> 8);     \
                (a)[3] = (u8) (((u32) (val)) & 0xff);   \
        } while (0)

Definition at line 157 of file common.h.

#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)

Definition at line 165 of file common.h.

#define WPA_PUT_LE16 a,
val   ) 
 

Value:

do {                                    \
                (a)[1] = ((u16) (val)) >> 8;    \
                (a)[0] = ((u16) (val)) & 0xff;  \
        } while (0)

Definition at line 140 of file common.h.


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)

Definition at line 93 of file common.c.

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)

Definition at line 62 of file common.c.

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.

Definition at line 121 of file common.c.

void wpa_debug_print_timestamp void   ) 
 

Print timestamp for debug output.

This function prints a timestamp in <seconds from 1970>.<microsoconds> format if debug output has been configured to include timestamps in debug messages.

Definition at line 152 of file common.c.

Here is the call graph for this function:

void void wpa_hexdump int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump.

Definition at line 242 of file common.c.

void wpa_hexdump_ascii int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump with both the hex numbers and ASCII characters (for printable range) are shown. 16 bytes per line will be shown.

Definition at line 339 of file common.c.

void wpa_hexdump_ascii_key int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump, hide keys

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump with both the hex numbers and ASCII characters (for printable range) are shown. 16 bytes per line will be shown. This works like wpa_hexdump_ascii(), but by default, does not include secret keys (passwords, etc.) in debug output.

Definition at line 345 of file common.c.

void wpa_hexdump_key int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump, hide keys

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump. This works like wpa_hexdump(), but by default, does not include secret keys (passwords, etc.) in debug output.

Definition at line 248 of file common.c.

void wpa_msg void *  ctx,
int  level,
char *  fmt,
  ...
 

Conditional printf for default target and ctrl_iface monitors.

Parameters:
ctx Pointer to context data; this is the ctx variable registered with struct wpa_driver_ops::init()
level priority level (MSG_*) of the message
fmt printf format string, followed by optional arguments
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. This function is like wpa_printf(), but it also sends the same message to all attached ctrl_iface monitors.

Note: New line '
' is added to the end of the text when printing to stdout.

void wpa_msg_register_cb wpa_msg_cb_func  func  ) 
 

Register callback function for wpa_msg() messages.

Parameters:
func Callback function (NULL to unregister)

Definition at line 390 of file common.c.

void wpa_printf int  level,
char *  fmt,
  ...
 

conditional printf

Parameters:
level priority level (MSG_*) of the message
fmt printf format string, followed by optional arguments
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration.

Note: New line '
' is added to the end of the text when printing to stdout.

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

Definition at line 450 of file common.c.

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

Definition at line 465 of file common.c.

const char* wpa_ssid_txt 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.

Definition at line 598 of file common.c.


Generated on Sun Dec 31 13:43:49 2006 for hostapd by  doxygen 1.4.2