#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 ;-) */
#include <linux/version.h>
#endif
-/* Kernel headers 2.4.X + Glibc 2.2 - Mandrake 8.0, Debian 2.3, RH 7.1 */
+/* Kernel headers 2.4.X + Glibc 2.2 - Mandrake 8.0, Debian 2.3, RH 7.1
+ * Kernel headers 2.2.X + Glibc 2.2 - Slackware 8.0 */
#if defined(__GLIBC__) \
&& __GLIBC__ == 2 \
&& __GLIBC_MINOR__ >= 2 \
- && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-#define GLIBC22_HEADERS
+ && LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
+//#define GLIBC22_HEADERS
+#define GENERIC_HEADERS
/* Kernel headers 2.4.X + Glibc 2.1 - Debian 2.2 upgraded, RH 7.0
* Kernel headers 2.2.X + Glibc 2.1 - Debian 2.2, RH 6.1 */
&& __GLIBC__ == 2 \
&& __GLIBC_MINOR__ == 1 \
&& LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
-#define GLIBC_HEADERS
+//#define GLIBC_HEADERS
+#define GENERIC_HEADERS
/* Kernel headers 2.2.X + Glibc 2.0 - Debian 2.1 */
#elif defined(__GLIBC__) \
#error "Your kernel/libc combination is not supported"
#endif
+#ifdef GENERIC_HEADERS
+/* Proposed by Dr. Michael Rietz <rietz@mail.amps.de>, 27.3.2 */
+/* If this works for all, it might be more stable on the long term - Jean II */
+#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>
+#endif /* GENERIC_HEADERS */
+
#ifdef GLIBC22_HEADERS
/* Added by Ross G. Miller <Ross_Miller@baylor.edu>, 3/28/01 */
#include <linux/if_arp.h> /* For ARPHRD_ETHER */
#include <linux/in.h> /* For struct sockaddr_in */
#endif /* LIBC5_HEADERS */
-#ifdef PRIVATE_WE_HEADER
+/* Those 3 headers were previously included in wireless.h */
+#include <linux/types.h> /* for "caddr_t" et al */
+#include <linux/socket.h> /* for "struct sockaddr" et al */
+#include <linux/if.h> /* for IFNAMSIZ and co... */
+
+#ifdef WEXT_HEADER
/* Private copy of Wireless extensions */
-#include "wireless.h"
-#else /* PRIVATE_WE_HEADER */
+#include WEXT_HEADER
+#else /* !WEXT_HEADER */
/* System wide Wireless extensions */
#include <linux/wireless.h>
-#endif /* PRIVATE_WE_HEADER */
+#endif /* !WEXT_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 < 12
-#warning "Wireless Extension v12 recommended...\
-You may update your kernel and/or system headers to get the new features..."
+#ifdef __cplusplus
+extern "C" {
#endif
/****************************** DEBUG ******************************/
/************************ CONSTANTS & MACROS ************************/
+/* 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 Wireless Extension 9 */
#ifndef IW_POWER_MODIFIER
#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not here */
#define IW_ENCODE_MODE 0xF000 /* Modes defined below */
#endif /* IW_ENCODE_NOKEY */
+#ifndef IW_ENCODE_TEMP
+#define IW_ENCODE_TEMP 0x0400 /* Temporary key */
+#endif /* IW_ENCODE_TEMP */
/* More backward compatibility */
#ifndef SIOCSIWCOMMIT
* This is pretty exhaustive... */
typedef struct wireless_info
{
- 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 */
+ double freq; /* Frequency/channel */
int has_sens;
iwparam sens; /* sensitivity */
int has_key;
* 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 */
+ double freq; /* Frequency/channel */
int has_key;
unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */
int key_size; /* Number of bytes */
int mode; /* Operation mode */
} wireless_config;
+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);
+
/**************************** 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_range_info(int skfd,
char * ifname,
iwrange * range);
int
+ iw_print_version_info(char * toolname);
+int
iw_get_priv_info(int skfd,
char * ifname,
- iwprivargs * priv);
+ iwprivargs * priv,
+ int maxpriv);
int
iw_get_basic_config(int skfd,
char * ifname,
iw_set_basic_config(int skfd,
char * ifname,
wireless_config * info);
+/* --------------------- PROTOCOL SUBROUTINES --------------------- */
+int
+ iw_protocol_compare(char * protocol1,
+ char * protocol2);
/* -------------------- FREQUENCY SUBROUTINES --------------------- */
void
iw_float2freq(double in,
iwfreq * out);
double
iw_freq2float(iwfreq * in);
+void
+ iw_print_freq(char * buffer,
+ double freq);
+int
+ iw_freq_to_channel(double freq,
+ struct iw_range * range);
+void
+ iw_print_bitrate(char * buffer,
+ int bitrate);
/* ---------------------- POWER SUBROUTINES ----------------------- */
int
iw_dbm2mwatt(int in);
unsigned char * key,
int key_size,
int key_flags);
+int
+ iw_in_key(char * input,
+ unsigned char * key);
+int
+ iw_in_key_full(int skfd,
+ char * ifname,
+ char * input,
+ unsigned char * key,
+ __u16 * flags);
/* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
void
iw_print_pm_value(char * buffer,
int value,
int flags);
#endif
+/* ----------------------- TIME SUBROUTINES ----------------------- */
+void
+ iw_print_timeval(char * buffer,
+ const struct timeval * time);
/* --------------------- ADDRESS SUBROUTINES ---------------------- */
int
iw_check_mac_addr_type(int skfd,
char * ifname);
#if 0
int
- iw_check_addr_type(int skfd,
- char * ifname);
+ iw_check_addr_type(int skfd,
+ char * ifname);
#endif
-char *
- iw_pr_ether(char *buffer, unsigned char *ptr);
+void
+ iw_ether_ntop(const struct ether_addr* eth, char* buf);
+char*
+ iw_ether_ntoa(const struct ether_addr* eth);
int
- iw_in_ether(char *bufp, struct sockaddr *sap);
+ iw_ether_aton(const char* bufp, struct ether_addr* eth);
int
iw_in_inet(char *bufp, struct sockaddr *sap);
int
struct sockaddr * sap);
/* ----------------------- MISC SUBROUTINES ------------------------ */
int
- iw_byte_size(int args);
+ iw_get_priv_size(int args);
+
+#if WIRELESS_EXT > 13
+/* ---------------------- 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);
+#endif /* WIRELESS_EXT > 13 */
/**************************** VARIABLES ****************************/
-extern const char * iw_operation_mode[];
-#define IW_NUM_OPER_MODE 6
+extern const char * const iw_operation_mode[];
+#define IW_NUM_OPER_MODE 7
/************************* INLINE FUNTIONS *************************/
/*
- * Function that are so simple that it's more efficient inlining them
+ * Functions that are so simple that it's more efficient inlining them
*/
/*
return(ioctl(skfd, request, pwrq));
}
+/*------------------------------------------------------------------*/
+/* Backwards compatability
+ * Actually, those form are much easier to use when dealing with
+ * struct sockaddr... */
+static inline char*
+iw_pr_ether(char* bufp, const unsigned char* addr)
+{
+ iw_ether_ntop((const struct ether_addr *) addr, bufp);
+ return bufp;
+}
+/* Backwards compatability */
+static inline int
+iw_in_ether(const char *bufp, struct sockaddr *sap)
+{
+ sap->sa_family = ARPHRD_ETHER;
+ return iw_ether_aton(bufp, (struct ether_addr *) sap->sa_data) ? 0 : -1;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Create an Ethernet broadcast address
+ */
+static inline void
+iw_broad_ether(struct sockaddr *sap)
+{
+ sap->sa_family = ARPHRD_ETHER;
+ memset((char *) sap->sa_data, 0xFF, ETH_ALEN);
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Create an Ethernet NULL address
+ */
+static inline void
+iw_null_ether(struct sockaddr *sap)
+{
+ sap->sa_family = ARPHRD_ETHER;
+ memset((char *) sap->sa_data, 0x00, ETH_ALEN);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* IWLIB_H */