iwlib.h   iwlib.h 
/* /*
* Wireless Tools * Wireless Tools
* *
* Jean II - HPLB 97->99 - HPL 99->02 * Jean II - HPLB 97->99 - HPL 99->04
* *
* Common header for the Wireless Extension library... * Common header for the Wireless Extension library...
* *
* This file is released under the GPL license. * This file is released under the GPL license.
* Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> * Copyright (c) 1997-2004 Jean Tourrilhes <jt@hpl.hp.com>
*/ */
#ifndef IWLIB_H #ifndef IWLIB_H
#define IWLIB_H #define IWLIB_H
/*#include "CHANGELOG.h"*/ /*#include "CHANGELOG.h"*/
/***************************** INCLUDES *****************************/ /***************************** INCLUDES *****************************/
/* Standard headers */ /* Standard headers */
skipping to change at line 130 skipping to change at line 130
#include <sys/socket.h> /* For AF_INET & struct sockaddr & s ocket() */ #include <sys/socket.h> /* For AF_INET & struct sockaddr & s ocket() */
#include <linux/if_arp.h> /* For ARPHRD_ETHER */ #include <linux/if_arp.h> /* For ARPHRD_ETHER */
#include <linux/in.h> /* For struct sockaddr_in */ #include <linux/in.h> /* For struct sockaddr_in */
#endif /* LIBC5_HEADERS */ #endif /* LIBC5_HEADERS */
/* Those 3 headers were previously included in wireless.h */ /* Those 3 headers were previously included in wireless.h */
#include <linux/types.h> /* for "caddr_t" et al */ #include <linux/types.h> /* for "caddr_t" et al */
#include <linux/socket.h> /* for "struct sockaddr" et al */ #include <linux/socket.h> /* for "struct sockaddr" et al */
#include <linux/if.h> /* for IFNAMSIZ and co... */ #include <linux/if.h> /* for IFNAMSIZ and co... */
#ifdef WEXT_HEADER
/* Private copy of Wireless extensions */ /* Private copy of Wireless extensions */
#include WEXT_HEADER #include <wireless.h>
#else /* !WEXT_HEADER */
/* System wide Wireless extensions */ /* Make gcc understant that when we say inline, we mean it.
#include <linux/wireless.h> * I really hate when the compiler is trying to be more clever than me,
#endif /* !WEXT_HEADER */ * 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 */
#if __GNUC__ == 3
#if __GNUC_MINOR__ >= 1 && __GNUC_MINOR__ < 4
#define inline inline __attribute__((always_inline))
#endif
#endif /* __GNUC__ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/****************************** DEBUG ******************************/ /****************************** DEBUG ******************************/
/************************ CONSTANTS & MACROS ************************/ /************************ CONSTANTS & MACROS ************************/
/* Various versions information */
/* Recommended Wireless Extension version */
#define WE_VERSION 17
/* Version of Wireless Tools */
#define WT_VERSION 27
/* Paths */ /* Paths */
#define PROC_NET_WIRELESS "/proc/net/wireless" #define PROC_NET_WIRELESS "/proc/net/wireless"
#define PROC_NET_DEV "/proc/net/dev" #define PROC_NET_DEV "/proc/net/dev"
/* Some usefull constants */ /* Some usefull constants */
#define KILO 1e3 #define KILO 1e3
#define MEGA 1e6 #define MEGA 1e6
#define GIGA 1e9 #define GIGA 1e9
/* For doing log10/exp10 without libm */ /* For doing log10/exp10 without libm */
#define LOG10_MAGIC 1.25892541179 #define LOG10_MAGIC 1.25892541179
skipping to change at line 178 skipping to change at line 194
#endif /* IW_ENCODE_NOKEY */ #endif /* IW_ENCODE_NOKEY */
#ifndef IW_ENCODE_TEMP #ifndef IW_ENCODE_TEMP
#define IW_ENCODE_TEMP 0x0400 /* Temporary key */ #define IW_ENCODE_TEMP 0x0400 /* Temporary key */
#endif /* IW_ENCODE_TEMP */ #endif /* IW_ENCODE_TEMP */
/* More backward compatibility */ /* More backward compatibility */
#ifndef SIOCSIWCOMMIT #ifndef SIOCSIWCOMMIT
#define SIOCSIWCOMMIT SIOCSIWNAME #define SIOCSIWCOMMIT SIOCSIWNAME
#endif /* SIOCSIWCOMMIT */ #endif /* SIOCSIWCOMMIT */
/* Still more backward compatibility */
#ifndef IW_FREQ_FIXED
#define IW_FREQ_FIXED 0x01
#endif /* IW_FREQ_FIXED */
/****************************** TYPES ******************************/ /****************************** TYPES ******************************/
/* Shortcuts */ /* Shortcuts */
typedef struct iw_statistics iwstats; typedef struct iw_statistics iwstats;
typedef struct iw_range iwrange; typedef struct iw_range iwrange;
typedef struct iw_param iwparam; typedef struct iw_param iwparam;
typedef struct iw_freq iwfreq; typedef struct iw_freq iwfreq;
typedef struct iw_quality iwqual; typedef struct iw_quality iwqual;
typedef struct iw_priv_args iwprivargs; typedef struct iw_priv_args iwprivargs;
typedef struct sockaddr sockaddr; typedef struct sockaddr sockaddr;
/* Structure for storing all wireless information for each device /* Structure for storing all wireless information for each device
* This is pretty exhaustive... */ * This is a cut down version of the one above, containing only
typedef struct wireless_info * 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 */ char name[IFNAMSIZ + 1]; /* Wireless/protocol name */
int has_nwid; int has_nwid;
iwparam nwid; /* Network ID */ iwparam nwid; /* Network ID */
int has_freq; int has_freq;
double freq; /* Frequency/channel */ double freq; /* Frequency/channel */
int has_sens; int freq_flags;
iwparam sens; /* sensitivity */
int has_key; int has_key;
unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */ unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */
int key_size; /* Number of bytes */ int key_size; /* Number of bytes */
int key_flags; /* Various flags */ int key_flags; /* Various flags */
int has_essid; int has_essid;
int essid_on; int essid_on;
char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */ 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; int has_nickname;
char nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */ char nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
int has_ap_addr; int has_ap_addr;
sockaddr ap_addr; /* Access point address */ sockaddr ap_addr; /* Access point address */
int has_bitrate; int has_bitrate;
iwparam bitrate; /* Bit rate in bps */ iwparam bitrate; /* Bit rate in bps */
int has_rts; int has_rts;
iwparam rts; /* RTS threshold in bytes */ iwparam rts; /* RTS threshold in bytes */
int has_frag; int has_frag;
iwparam frag; /* Fragmentation threshold in bytes */ iwparam frag; /* Fragmentation threshold in bytes */
int has_mode;
int mode; /* Operation mode */
int has_power; int has_power;
iwparam power; /* Power management parameters */ iwparam power; /* Power management parameters */
int has_txpower; int has_txpower;
iwparam txpower; /* Transmit Power in dBm */ iwparam txpower; /* Transmit Power in dBm */
int has_retry; int has_retry;
iwparam retry; /* Retry limit or lifetime */ iwparam retry; /* Retry limit or lifetime */
/* Stats */ /* Stats */
iwstats stats; iwstats stats;
int has_stats; int has_stats;
iwrange range; iwrange range;
int has_range; int has_range;
} wireless_info; } wireless_info;
/* Structure for storing all wireless information for each device /* Structure for storing an entry of a wireless scan.
* This is a cut down version of the one above, containing only * This is only a subset of all possible information, the flexible
* the things *truly* needed to configure a card. * structure of scan results make it impossible to capture all
* Don't add other junk, I'll remove it... */ * information in such a static structure. */
typedef struct wireless_config typedef struct wireless_scan
{ {
char name[IFNAMSIZ + 1]; /* Wireless/protocol name */ /* Linked list */
int has_nwid; struct wireless_scan * next;
iwparam nwid; /* Network ID */
int has_freq; /* Cell identifiaction */
double freq; /* Frequency/channel */ int has_ap_addr;
int has_key; sockaddr ap_addr; /* Access point address */
unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used
*/ /* Other information */
int key_size; /* Number of bytes */ struct wireless_config b; /* Basic information */
int key_flags; /* Various flags */ iwstats stats; /* Signal strength */
int has_essid; int has_stats;
int essid_on; } wireless_scan;
char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network)
*/ /*
int has_mode; * Context used for non-blocking scan.
int mode; /* Operation mode */ */
} wireless_config; 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 typedef struct stream_descr
{ {
char * end; /* End of the stream */ char * end; /* End of the stream */
char * current; /* Current event in stream of events */ char * current; /* Current event in stream of events */
char * value; /* Current value in event */ char * value; /* Current value in event */
} stream_descr; } stream_descr;
/* Prototype for handling display of each single interface on the /* Prototype for handling display of each single interface on the
* system - see iw_enum_devices() */ * system - see iw_enum_devices() */
typedef int (*iw_enum_handler)(int skfd, typedef int (*iw_enum_handler)(int skfd,
skipping to change at line 284 skipping to change at line 324
/* ---------------------- SOCKET SUBROUTINES -----------------------*/ /* ---------------------- SOCKET SUBROUTINES -----------------------*/
int int
iw_sockets_open(void); iw_sockets_open(void);
void void
iw_enum_devices(int skfd, iw_enum_devices(int skfd,
iw_enum_handler fn, iw_enum_handler fn,
char * args[], char * args[],
int count); int count);
/* --------------------- WIRELESS SUBROUTINES ----------------------*/ /* --------------------- WIRELESS SUBROUTINES ----------------------*/
int int
iw_get_kernel_we_version(void);
int
iw_print_version_info(const char * toolname);
int
iw_get_range_info(int skfd, iw_get_range_info(int skfd,
char * ifname, const char * ifname,
iwrange * range); iwrange * range);
int int
iw_print_version_info(char * toolname);
int
iw_get_priv_info(int skfd, iw_get_priv_info(int skfd,
char * ifname, const char * ifname,
iwprivargs * priv, iwprivargs ** ppriv);
int maxpriv);
int int
iw_get_basic_config(int skfd, iw_get_basic_config(int skfd,
char * ifname, const char * ifname,
wireless_config * info); wireless_config * info);
int int
iw_set_basic_config(int skfd, iw_set_basic_config(int skfd,
char * ifname, const char * ifname,
wireless_config * info); wireless_config * info);
/* --------------------- PROTOCOL SUBROUTINES --------------------- */ /* --------------------- PROTOCOL SUBROUTINES --------------------- */
int int
iw_protocol_compare(char * protocol1, iw_protocol_compare(const char * protocol1,
char * protocol2); const char * protocol2);
/* -------------------- FREQUENCY SUBROUTINES --------------------- */ /* -------------------- FREQUENCY SUBROUTINES --------------------- */
void void
iw_float2freq(double in, iw_float2freq(double in,
iwfreq * out); iwfreq * out);
double double
iw_freq2float(iwfreq * in); iw_freq2float(const iwfreq * in);
void
iw_print_freq_value(char * buffer,
int buflen,
double freq);
void void
iw_print_freq(char * buffer, iw_print_freq(char * buffer,
double freq); int buflen,
double freq,
int channel,
int freq_flags);
int int
iw_freq_to_channel(double freq, iw_freq_to_channel(double freq,
struct iw_range * range); const struct iw_range * range);
int
iw_channel_to_freq(int channel,
double * pfreq,
const struct iw_range * range);
void void
iw_print_bitrate(char * buffer, iw_print_bitrate(char * buffer,
int buflen,
int bitrate); int bitrate);
/* ---------------------- POWER SUBROUTINES ----------------------- */ /* ---------------------- POWER SUBROUTINES ----------------------- */
int int
iw_dbm2mwatt(int in); iw_dbm2mwatt(int in);
int int
iw_mwatt2dbm(int in); iw_mwatt2dbm(int in);
void
iw_print_txpower(char * buffer,
int buflen,
struct iw_param * txpower);
/* -------------------- STATISTICS SUBROUTINES -------------------- */ /* -------------------- STATISTICS SUBROUTINES -------------------- */
int int
iw_get_stats(int skfd, iw_get_stats(int skfd,
char * ifname, const char * ifname,
iwstats * stats); iwstats * stats,
const iwrange * range,
int has_range);
void void
iw_print_stats(char * buffer, iw_print_stats(char * buffer,
iwqual * qual, int buflen,
iwrange * range, const iwqual * qual,
const iwrange * range,
int has_range); int has_range);
/* --------------------- ENCODING SUBROUTINES --------------------- */ /* --------------------- ENCODING SUBROUTINES --------------------- */
void void
iw_print_key(char * buffer, iw_print_key(char * buffer,
unsigned char * key, int buflen,
int key_size, const unsigned char * key,
int key_flags); int key_size,
int key_flags);
int int
iw_in_key(char * input, iw_in_key(const char * input,
unsigned char * key); unsigned char * key);
int int
iw_in_key_full(int skfd, iw_in_key_full(int skfd,
char * ifname, const char * ifname,
char * input, const char * input,
unsigned char * key, unsigned char * key,
__u16 * flags); __u16 * flags);
/* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */ /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
void void
iw_print_pm_value(char * buffer, iw_print_pm_value(char * buffer,
int buflen,
int value, int value,
int flags); int flags);
void void
iw_print_pm_mode(char * buffer, iw_print_pm_mode(char * buffer,
int buflen,
int flags); int flags);
/* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */ /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */
#if WIRELESS_EXT > 10
void void
iw_print_retry_value(char * buffer, iw_print_retry_value(char * buffer,
int buflen,
int value, int value,
int flags); int flags);
#endif
/* ----------------------- TIME SUBROUTINES ----------------------- */ /* ----------------------- TIME SUBROUTINES ----------------------- */
void void
iw_print_timeval(char * buffer, iw_print_timeval(char * buffer,
int buflen,
const struct timeval * time); const struct timeval * time);
/* --------------------- ADDRESS SUBROUTINES ---------------------- */ /* --------------------- ADDRESS SUBROUTINES ---------------------- */
int int
iw_check_mac_addr_type(int skfd, iw_check_mac_addr_type(int skfd,
char * ifname); char * ifname);
int int
iw_check_if_addr_type(int skfd, iw_check_if_addr_type(int skfd,
char * ifname); char * ifname);
#if 0 #if 0
int int
iw_check_addr_type(int skfd, iw_check_addr_type(int skfd,
char * ifname); char * ifname);
#endif #endif
int
iw_get_mac_addr(int skfd,
const char * name,
struct ether_addr * eth,
unsigned short * ptype);
void void
iw_ether_ntop(const struct ether_addr* eth, char* buf); iw_ether_ntop(const struct ether_addr* eth, char* buf);
char* char*
iw_ether_ntoa(const struct ether_addr* eth); iw_ether_ntoa(const struct ether_addr* eth);
int int
iw_ether_aton(const char* bufp, struct ether_addr* eth); iw_ether_aton(const char* bufp, struct ether_addr* eth);
int int
iw_in_inet(char *bufp, struct sockaddr *sap); iw_in_inet(char *bufp, struct sockaddr *sap);
int int
iw_in_addr(int skfd, iw_in_addr(int skfd,
char * ifname, char * ifname,
char * bufp, char * bufp,
struct sockaddr * sap); struct sockaddr * sap);
/* ----------------------- MISC SUBROUTINES ------------------------ */ /* ----------------------- MISC SUBROUTINES ------------------------ */
int int
iw_get_priv_size(int args); iw_get_priv_size(int args);
#if WIRELESS_EXT > 13
/* ---------------------- EVENT SUBROUTINES ---------------------- */ /* ---------------------- EVENT SUBROUTINES ---------------------- */
void void
iw_init_event_stream(struct stream_descr * stream, iw_init_event_stream(struct stream_descr * stream,
char * data, char * data,
int len); int len);
int int
iw_extract_event_stream(struct stream_descr * stream, iw_extract_event_stream(struct stream_descr * stream,
struct iw_event * iwe); struct iw_event * iwe,
#endif /* WIRELESS_EXT > 13 */ 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 ****************************/ /**************************** VARIABLES ****************************/
/* Modes as human readable strings */
extern const char * const iw_operation_mode[]; extern const char * const iw_operation_mode[];
#define IW_NUM_OPER_MODE 7 #define IW_NUM_OPER_MODE 7
/************************* INLINE FUNTIONS *************************/ /************************* INLINE FUNTIONS *************************/
/* /*
* Functions that are so simple that it's more efficient inlining them * Functions that are so simple that it's more efficient inlining them
*/ */
/* /*
* Note : I've defined wrapper for the ioctl request so that * Note : I've defined wrapper for the ioctl request so that
* it will be easier to migrate to other kernel API if needed * it will be easier to migrate to other kernel API if needed
*/ */
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* /*
* Wrapper to push some Wireless Parameter in the driver * Wrapper to push some Wireless Parameter in the driver
*/ */
static inline int static inline int
iw_set_ext(int skfd, /* Socket to the kernel */ iw_set_ext(int skfd, /* Socket to the kernel */
char * ifname, /* Device name */ const char * ifname, /* Device name */
int request, /* WE ID */ int request, /* WE ID */
struct iwreq * pwrq) /* Fixed part of the request */ struct iwreq * pwrq) /* Fixed part of the request */
{ {
/* Set device name */ /* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */ /* Do the request */
return(ioctl(skfd, request, pwrq)); return(ioctl(skfd, request, pwrq));
} }
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* /*
* Wrapper to extract some Wireless Parameter out of the driver * Wrapper to extract some Wireless Parameter out of the driver
*/ */
static inline int static inline int
iw_get_ext(int skfd, /* Socket to the kernel */ iw_get_ext(int skfd, /* Socket to the kernel */
char * ifname, /* Device name */ const char * ifname, /* Device name */
int request, /* WE ID */ int request, /* WE ID */
struct iwreq * pwrq) /* Fixed part of the request */ struct iwreq * pwrq) /* Fixed part of the request */
{ {
/* Set device name */ /* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */ /* Do the request */
return(ioctl(skfd, request, pwrq)); return(ioctl(skfd, request, pwrq));
} }
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/*
* Close the socket used for ioctl.
*/
static inline void
iw_sockets_close(int skfd)
{
close(skfd);
}
/*------------------------------------------------------------------*/
/* Backwards compatability /* Backwards compatability
* Actually, those form are much easier to use when dealing with * Actually, those form are much easier to use when dealing with
* struct sockaddr... */ * struct sockaddr... */
static inline char* static inline char*
iw_pr_ether(char* bufp, const unsigned char* addr) iw_pr_ether(char* bufp, const unsigned char* addr)
{ {
iw_ether_ntop((const struct ether_addr *) addr, bufp); iw_ether_ntop((const struct ether_addr *) addr, bufp);
return bufp; return bufp;
} }
/* Backwards compatability */ /* Backwards compatability */
 End of changes. 44 change blocks. 
70 lines changed or deleted 157 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/