📄 iwlib.h
字号:
/* * Wireless Tools * * Jean II - HPLB 97->99 - HPL 99->07 * * Common header for the Wireless Extension library... * * This file is released under the GPL license. * Copyright (c) 1997-2007 Jean Tourrilhes <jt@hpl.hp.com> */#ifndef IWLIB_H#define IWLIB_H/*#include "CHANGELOG.h"*//***************************** INCLUDES *****************************//* Standard headers */#include <sys/types.h>#include <sys/ioctl.h>#include <stdio.h>#include <math.h>#include <errno.h>#include <fcntl.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <netdb.h> /* gethostbyname, getnetbyname */#include <net/ethernet.h> /* struct ether_addr */#include <sys/time.h> /* struct timeval */#include <unistd.h>/* This is our header selection. Try to hide the mess and the misery :-( * 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 <rietz@mail.amps.de>, 27.3.2 */#include <net/if_arp.h> /* For ARPHRD_ETHER */#include <sys/socket.h> /* For AF_INET & struct sockaddr */#include <netinet/in.h> /* For struct sockaddr_in */#include <netinet/if_ether.h>/* Fixup to be able to include kernel includes in userspace. * Basically, kill the sparse annotations... Jean II */#ifndef __user#define __user#endif#include <linux/types.h> /* for "caddr_t" et al *//* Glibc systems headers are supposedly less problematic than kernel ones */#include <sys/socket.h> /* for "struct sockaddr" et al */#include <net/if.h> /* for IFNAMSIZ and co... *//* Private copy of Wireless extensions (in this directoty) */#include "wireless.h"/* Make gcc understant that when we say inline, we mean it. * I really hate when the compiler is trying to be more clever than me, * because in this case gcc is not able to figure out functions with a * single call site, so not only I have to tag those functions inline * by hand, but then it refuse to inline them properly. * Total saving for iwevent : 150B = 0.7%. * Fortunately, in gcc 3.4, they now automatically inline static functions * with a single call site. Hurrah ! * Jean II */#undef IW_GCC_HAS_BROKEN_INLINE#if __GNUC__ == 3#if __GNUC_MINOR__ >= 1 && __GNUC_MINOR__ < 4#define IW_GCC_HAS_BROKEN_INLINE 1#endif /* __GNUC_MINOR__ */#endif /* __GNUC__ *//* However, gcc 4.0 has introduce a new "feature", when compiling with * '-Os', it does not want to inline iw_ether_cmp() and friends. * So, we need to fix inline again ! * Jean II */#if __GNUC__ == 4#define IW_GCC_HAS_BROKEN_INLINE 1#endif /* __GNUC__ *//* Now, really fix the inline */#ifdef IW_GCC_HAS_BROKEN_INLINE#ifdef inline#undef inline#endif /* inline */#define inline inline __attribute__((always_inline))#endif /* IW_GCC_HAS_BROKEN_INLINE */#ifdef __cplusplusextern "C" {#endif/****************************** DEBUG ******************************///#define DEBUG 1/************************ CONSTANTS & MACROS ************************//* Various versions information *//* Recommended Wireless Extension version */#define WE_VERSION 21/* Maximum forward compatibility built in this version of WT */#define WE_MAX_VERSION 22/* Version of Wireless Tools */#define WT_VERSION 29/* Paths */#define PROC_NET_WIRELESS "/proc/net/wireless"#define PROC_NET_DEV "/proc/net/dev"/* Some usefull constants */#define KILO 1e3#define MEGA 1e6#define GIGA 1e9/* For doing log10/exp10 without libm */#define LOG10_MAGIC 1.25892541179/* Backward compatibility for network headers */#ifndef ARPHRD_IEEE80211#define ARPHRD_IEEE80211 801 /* IEEE 802.11 */#endif /* ARPHRD_IEEE80211 */#ifndef IW_EV_LCP_PK_LEN/* Size of the Event prefix when packed in stream */#define IW_EV_LCP_PK_LEN (4)/* Size of the various events when packed in stream */#define IW_EV_CHAR_PK_LEN (IW_EV_LCP_PK_LEN + IFNAMSIZ)#define IW_EV_UINT_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(__u32))#define IW_EV_FREQ_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq))#define IW_EV_PARAM_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_param))#define IW_EV_ADDR_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr))#define IW_EV_QUAL_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))#define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4)struct iw_pk_event{ __u16 len; /* Real lenght of this stuff */ __u16 cmd; /* Wireless IOCTL */ union iwreq_data u; /* IOCTL fixed payload */} __attribute__ ((packed));struct iw_pk_point{ void __user *pointer; /* Pointer to the data (in user space) */ __u16 length; /* number of fields or size in bytes */ __u16 flags; /* Optional params */} __attribute__ ((packed));#define IW_EV_LCP_PK2_LEN (sizeof(struct iw_pk_event) - sizeof(union iwreq_data))#define IW_EV_POINT_PK2_LEN (IW_EV_LCP_PK2_LEN + sizeof(struct iw_pk_point) - IW_EV_POINT_OFF)#endif /* IW_EV_LCP_PK_LEN *//****************************** TYPES ******************************//* Shortcuts */typedef struct iw_statistics iwstats;typedef struct iw_range iwrange;typedef struct iw_param iwparam;typedef struct iw_freq iwfreq;typedef struct iw_quality iwqual;typedef struct iw_priv_args iwprivargs;typedef struct sockaddr sockaddr;/* 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{ char name[IFNAMSIZ + 1]; /* Wireless/protocol name */ int has_nwid; iwparam nwid; /* Network ID */ int has_freq; 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) */ 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 */ int has_ap_addr; sockaddr ap_addr; /* Access point address */ int has_bitrate; iwparam bitrate; /* Bit rate in bps */ int has_rts; iwparam rts; /* RTS threshold in bytes */ int has_frag; iwparam frag; /* Fragmentation threshold in bytes */ int has_power; iwparam power; /* Power management parameters */ int has_txpower; iwparam txpower; /* Transmit Power in dBm */ int has_retry; iwparam retry; /* Retry limit or lifetime */ /* Stats */ iwstats stats; 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 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{ /* 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 *//* ---------------------- 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -