X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;ds=sidebyside;f=wireless_tools%2Fiwlib.h;h=6082ac590645108e868b3037d785608b81d0c864;hb=41b8e9b1157054ddcb90e68f1b12707811c90361;hp=723475b9e94294952b679fb1abdef8a6ba805224;hpb=fb1188c580d9ff90cc4d80d2bedb03e86b463057;p=android-x86%2Fexternal-wireless-tools.git diff --git a/wireless_tools/iwlib.h b/wireless_tools/iwlib.h index 723475b..6082ac5 100644 --- a/wireless_tools/iwlib.h +++ b/wireless_tools/iwlib.h @@ -1,18 +1,17 @@ /* * Wireless Tools * - * Jean II - HPLB 97->99 - HPL 99->01 + * Jean II - HPLB 97->99 - HPL 99->09 * * Common header for the Wireless Extension library... * * This file is released under the GPL license. + * Copyright (c) 1997-2009 Jean Tourrilhes */ #ifndef IWLIB_H #define IWLIB_H -/*#include "CHANGELOG.h"*/ - /***************************** INCLUDES *****************************/ /* Standard headers */ @@ -27,73 +26,51 @@ #include #include #include /* gethostbyname, getnetbyname */ +#include /* struct ether_addr */ +#include /* struct timeval */ +#include /* This is our header selection. Try to hide the mess and the misery :-( - * The selection has been moved in the Makefile, here we have only - * the ugly part. Don't look, you would go blind ;-) */ - -#ifdef KLUDGE_HEADERS -#include -#endif /* KLUDGE_HEADERS */ - -#if defined(KLUDGE_HEADERS) || defined(GLIBC_HEADERS) -#include /* For ARPHRD_ETHER */ -#include /* For AF_INET & struct sockaddr */ -#include /* For struct sockaddr_in */ -#endif /* KLUDGE_HEADERS || GLIBC_HEADERS */ - -#ifdef GLIBC22_HEADERS -/* Added by Ross G. Miller , 3/28/01 */ -#include /* For ARPHRD_ETHER */ -#include /* For AF_INET & struct sockaddr */ -#include -#endif /* GLIBC22_HEADERS */ - -#ifdef LIBC5_HEADERS -#include /* For AF_INET & struct sockaddr & socket() */ -#include /* For ARPHRD_ETHER */ -#include /* For struct sockaddr_in */ -#endif /* LIBC5_HEADERS */ - -#ifdef PRIVATE_WE_HEADER -/* Private copy of Wireless extensions */ -#include "wireless.h" -#else /* PRIVATE_WE_HEADER */ -/* System wide Wireless extensions */ -#include -#endif /* PRIVATE_WE_HEADER */ - -#if WIRELESS_EXT < 9 -#error "Wireless Extension v9 or newer required :-(\ -Use Wireless Tools v19 or update your kernel headers" -#endif -#if WIRELESS_EXT < 11 -#warning "Wireless Extension v11 recommended...\ -You may update your kernel and/or system headers to get the new features..." + * Don't look, you would go blind ;-) + * Note : compatibility with *old* distributions has been removed, + * you will need Glibc 2.2 and older to compile (which means + * Mandrake 8.0, Debian 2.3, RH 7.1 or older). + */ + +/* Set of headers proposed by Dr. Michael Rietz , 27.3.2 */ +#include /* For ARPHRD_ETHER */ +#include /* For AF_INET & struct sockaddr */ +#include /* For struct sockaddr_in */ +#include + +/* Fixup to be able to include kernel includes in userspace. + * Basically, kill the sparse annotations... Jean II */ +#ifndef __user +#define __user #endif -/****************************** DEBUG ******************************/ +#include /* for "caddr_t" et al */ +/* Glibc systems headers are supposedly less problematic than kernel ones */ +#include /* for "struct sockaddr" et al */ +#include /* for IFNAMSIZ and co... */ -/************************ CONSTANTS & MACROS ************************/ +/* Private copy of Wireless extensions (in this directoty) */ +#include "wireless.h" -/* Some usefull constants */ -#define KILO 1e3 -#define MEGA 1e6 -#define GIGA 1e9 +#ifdef __cplusplus +extern "C" { +#endif -/* Backward compatibility for Wireless Extension 9 */ -#ifndef IW_POWER_MODIFIER -#define IW_POWER_MODIFIER 0x000F /* Modify a parameter */ -#define IW_POWER_MIN 0x0001 /* Value is a minimum */ -#define IW_POWER_MAX 0x0002 /* Value is a maximum */ -#define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ -#endif IW_POWER_MODIFIER +/************************ CONSTANTS & MACROS ************************/ -#ifndef IW_ENCODE_NOKEY -#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not here */ -#define IW_ENCODE_MODE 0xF000 /* Modes defined below */ -#endif IW_ENCODE_NOKEY +/* Various versions information */ +/* Recommended Wireless Extension version */ +#define WE_VERSION 22 +/* Maximum forward compatibility built in this version of WT */ +#define WE_MAX_VERSION 22 +/* Version of Wireless Tools */ +#define WT_VERSION 30 /****************************** TYPES ******************************/ @@ -107,25 +84,39 @@ typedef struct iw_priv_args iwprivargs; typedef struct sockaddr sockaddr; /* Structure for storing all wireless information for each device - * This is pretty exhaustive... */ -typedef struct wireless_info + * This is a cut down version of the one above, containing only + * the things *truly* needed to configure a card. + * Don't add other junk, I'll remove it... */ +typedef struct wireless_config { - char name[IFNAMSIZ]; /* Wireless/protocol name */ + char name[IFNAMSIZ + 1]; /* Wireless/protocol name */ int has_nwid; iwparam nwid; /* Network ID */ int has_freq; - float freq; /* Frequency/channel */ - int has_sens; - iwparam sens; /* sensitivity */ + double freq; /* Frequency/channel */ + int freq_flags; int has_key; unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */ int key_size; /* Number of bytes */ int key_flags; /* Various flags */ int has_essid; int essid_on; - char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */ + char essid[IW_ESSID_MAX_SIZE + 2]; /* ESSID (extended network) */ + int essid_len; + int has_mode; + int mode; /* Operation mode */ +} wireless_config; + +/* Structure for storing all wireless information for each device + * This is pretty exhaustive... */ +typedef struct wireless_info +{ + struct wireless_config b; /* Basic information */ + + int has_sens; + iwparam sens; /* sensitivity */ int has_nickname; - char nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */ + char nickname[IW_ESSID_MAX_SIZE + 2]; /* NickName */ int has_ap_addr; sockaddr ap_addr; /* Access point address */ int has_bitrate; @@ -134,8 +125,6 @@ typedef struct wireless_info iwparam rts; /* RTS threshold in bytes */ int has_frag; iwparam frag; /* Fragmentation threshold in bytes */ - int has_mode; - int mode; /* Operation mode */ int has_power; iwparam power; /* Power management parameters */ int has_txpower; @@ -148,118 +137,327 @@ typedef struct wireless_info int has_stats; iwrange range; int has_range; + + /* Auth params for WPA/802.1x/802.11i */ + int auth_key_mgmt; + int has_auth_key_mgmt; + int auth_cipher_pairwise; + int has_auth_cipher_pairwise; + int auth_cipher_group; + int has_auth_cipher_group; } wireless_info; -/* Structure for storing all wireless information for each device - * This is a cut down version of the one above, containing only - * the things *truly* needed to configure a card. - * Don't add other junk, I'll remove it... */ -typedef struct wireless_config +/* Structure for storing an entry of a wireless scan. + * This is only a subset of all possible information, the flexible + * structure of scan results make it impossible to capture all + * information in such a static structure. */ +typedef struct wireless_scan { - char name[IFNAMSIZ]; /* Wireless/protocol name */ - int has_nwid; - iwparam nwid; /* Network ID */ - int has_freq; - float freq; /* Frequency/channel */ - int has_key; - unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */ - int key_size; /* Number of bytes */ - int key_flags; /* Various flags */ - int has_essid; - int essid_on; - char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */ - int has_mode; - int mode; /* Operation mode */ -} wireless_config; + /* Linked list */ + struct wireless_scan * next; + + /* Cell identifiaction */ + int has_ap_addr; + sockaddr ap_addr; /* Access point address */ + + /* Other information */ + struct wireless_config b; /* Basic information */ + iwstats stats; /* Signal strength */ + int has_stats; + iwparam maxbitrate; /* Max bit rate in bps */ + int has_maxbitrate; +} wireless_scan; + +/* + * Context used for non-blocking scan. + */ +typedef struct wireless_scan_head +{ + wireless_scan * result; /* Result of the scan */ + int retry; /* Retry level */ +} wireless_scan_head; + +/* Structure used for parsing event streams, such as Wireless Events + * and scan results */ +typedef struct stream_descr +{ + char * end; /* End of the stream */ + char * current; /* Current event in stream of events */ + char * value; /* Current value in event */ +} stream_descr; + +/* Prototype for handling display of each single interface on the + * system - see iw_enum_devices() */ +typedef int (*iw_enum_handler)(int skfd, + char * ifname, + char * args[], + int count); + +/* Describe a modulation */ +typedef struct iw_modul_descr +{ + unsigned int mask; /* Modulation bitmask */ + char cmd[8]; /* Short name */ + char * verbose; /* Verbose description */ +} iw_modul_descr; /**************************** PROTOTYPES ****************************/ /* - * All the functions in iwcommon.c + * All the functions in iwlib.c */ + /* ---------------------- SOCKET SUBROUTINES -----------------------*/ int iw_sockets_open(void); +void + iw_enum_devices(int skfd, + iw_enum_handler fn, + char * args[], + int count); /* --------------------- WIRELESS SUBROUTINES ----------------------*/ int + iw_get_kernel_we_version(void); +int + iw_print_version_info(const char * toolname); +int iw_get_range_info(int skfd, - char * ifname, + const char * ifname, iwrange * range); int iw_get_priv_info(int skfd, - char * ifname, - iwprivargs * priv); + const char * ifname, + iwprivargs ** ppriv); int iw_get_basic_config(int skfd, - char * ifname, + const char * ifname, wireless_config * info); int iw_set_basic_config(int skfd, - char * ifname, + const char * ifname, wireless_config * info); +/* --------------------- PROTOCOL SUBROUTINES --------------------- */ +int + iw_protocol_compare(const char * protocol1, + const char * protocol2); +/* ---------------------- ESSID SUBROUTINES ---------------------- */ +void + iw_essid_escape(char * dest, + const char * src, + const int slen); +int + iw_essid_unescape(char * dest, + const char * src); /* -------------------- FREQUENCY SUBROUTINES --------------------- */ void iw_float2freq(double in, - iwfreq * out); + iwfreq * out); double - iw_freq2float(iwfreq * in); + iw_freq2float(const iwfreq * in); +void + iw_print_freq_value(char * buffer, + int buflen, + double freq); +void + iw_print_freq(char * buffer, + int buflen, + double freq, + int channel, + int freq_flags); +int + iw_freq_to_channel(double freq, + const struct iw_range * range); +int + iw_channel_to_freq(int channel, + double * pfreq, + const struct iw_range * range); +void + iw_print_bitrate(char * buffer, + int buflen, + int bitrate); /* ---------------------- POWER SUBROUTINES ----------------------- */ int iw_dbm2mwatt(int in); int iw_mwatt2dbm(int in); +void + iw_print_txpower(char * buffer, + int buflen, + struct iw_param * txpower); /* -------------------- STATISTICS SUBROUTINES -------------------- */ int - iw_get_stats(int skfd, - char * ifname, - iwstats * stats); + iw_get_stats(int skfd, + const char * ifname, + iwstats * stats, + const iwrange * range, + int has_range); void iw_print_stats(char * buffer, - iwqual * qual, - iwrange * range, + int buflen, + const iwqual * qual, + const iwrange * range, int has_range); /* --------------------- ENCODING SUBROUTINES --------------------- */ void - iw_print_key(char * buffer, - unsigned char * key, - int key_size, - int key_flags); + iw_print_key(char * buffer, + int buflen, + const unsigned char * key, + int key_size, + int key_flags); +int + iw_in_key(const char * input, + unsigned char * key); +int + iw_in_key_full(int skfd, + const char * ifname, + const char * input, + unsigned char * key, + __u16 * flags); /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */ void iw_print_pm_value(char * buffer, + int buflen, int value, - int flags); + int flags, + int we_version); void iw_print_pm_mode(char * buffer, + int buflen, int flags); /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */ -#if WIRELESS_EXT > 10 void iw_print_retry_value(char * buffer, + int buflen, int value, - int flags); -#endif + int flags, + int we_version); +/* ----------------------- TIME SUBROUTINES ----------------------- */ +void + iw_print_timeval(char * buffer, + int buflen, + const struct timeval * time, + const struct timezone * tz); /* --------------------- ADDRESS SUBROUTINES ---------------------- */ int - iw_check_addr_type(int skfd, - char * ifname); + iw_check_mac_addr_type(int skfd, + const char * ifname); +int + iw_check_if_addr_type(int skfd, + const char * ifname); +char * + iw_mac_ntop(const unsigned char * mac, + int maclen, + char * buf, + int buflen); +void + iw_ether_ntop(const struct ether_addr * eth, + char * buf); char * - iw_pr_ether(char *buffer, unsigned char *ptr); + iw_sawap_ntop(const struct sockaddr * sap, + char * buf); int - iw_in_ether(char *bufp, struct sockaddr *sap); + iw_mac_aton(const char * orig, + unsigned char * mac, + int macmax); +int + iw_ether_aton(const char* bufp, struct ether_addr* eth); int iw_in_inet(char *bufp, struct sockaddr *sap); int iw_in_addr(int skfd, - char * ifname, + const char * ifname, char * bufp, struct sockaddr * sap); /* ----------------------- MISC SUBROUTINES ------------------------ */ int - iw_byte_size(int args); + iw_get_priv_size(int args); + +/* ---------------------- EVENT SUBROUTINES ---------------------- */ +void + iw_init_event_stream(struct stream_descr * stream, + char * data, + int len); +int + iw_extract_event_stream(struct stream_descr * stream, + struct iw_event * iwe, + int we_version); +/* --------------------- SCANNING SUBROUTINES --------------------- */ +int + iw_process_scan(int skfd, + char * ifname, + int we_version, + wireless_scan_head * context); +int + iw_scan(int skfd, + char * ifname, + int we_version, + wireless_scan_head * context); /**************************** VARIABLES ****************************/ -extern const char * iw_operation_mode[]; -#define IW_NUM_OPER_MODE 6 +/* Modes as human readable strings */ +extern const char * const iw_operation_mode[]; +#define IW_NUM_OPER_MODE 7 +#define IW_NUM_OPER_MODE_EXT 8 + +/* Modulations as human readable strings */ +extern const struct iw_modul_descr iw_modul_list[]; +#define IW_SIZE_MODUL_LIST 16 + +/************************* INLINE FUNTIONS *************************/ +/* + * Functions that are so simple that it's more efficient inlining them + * Most inline are private because gcc is fussy about inline... + */ + +/* + * Note : I've defined wrapper for the ioctl request so that + * it will be easier to migrate to other kernel API if needed + */ + +/*------------------------------------------------------------------*/ +/* + * Wrapper to push some Wireless Parameter in the driver + */ +static inline __attribute__((always_inline)) int +iw_set_ext(int skfd, /* Socket to the kernel */ + const char * ifname, /* Device name */ + int request, /* WE ID */ + struct iwreq * pwrq) /* Fixed part of the request */ +{ + /* Set device name */ + strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); + /* Do the request */ + return(ioctl(skfd, request, pwrq)); +} + +/*------------------------------------------------------------------*/ +/* + * Wrapper to extract some Wireless Parameter out of the driver + */ +static inline __attribute__((always_inline)) int +iw_get_ext(int skfd, /* Socket to the kernel */ + const char * ifname, /* Device name */ + int request, /* WE ID */ + struct iwreq * pwrq) /* Fixed part of the request */ +{ + /* Set device name */ + strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); + /* Do the request */ + return(ioctl(skfd, request, pwrq)); +} + +/*------------------------------------------------------------------*/ +/* + * Close the socket used for ioctl. + */ +static inline void +iw_sockets_close(int skfd) +{ + close(skfd); +} + +#ifdef __cplusplus +} +#endif #endif /* IWLIB_H */