4 * Jean II - HPLB 97->99 - HPL 99->02
6 * Common header for the Wireless Extension library...
8 * This file is released under the GPL license.
9 * Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com>
15 /*#include "CHANGELOG.h"*/
17 /***************************** INCLUDES *****************************/
19 /* Standard headers */
20 #include <sys/types.h>
21 #include <sys/ioctl.h>
30 #include <netdb.h> /* gethostbyname, getnetbyname */
32 /* This is our header selection. Try to hide the mess and the misery :-(
33 * Don't look, you would go blind ;-) */
35 #ifndef LINUX_VERSION_CODE
36 #include <linux/version.h>
39 /* Kernel headers 2.4.X + Glibc 2.2 - Mandrake 8.0, Debian 2.3, RH 7.1 */
40 #if defined(__GLIBC__) \
42 && __GLIBC_MINOR__ >= 2 \
43 && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
44 #define GLIBC22_HEADERS
46 /* Kernel headers 2.4.X + Glibc 2.1 - Debian 2.2 upgraded, RH 7.0
47 * Kernel headers 2.2.X + Glibc 2.1 - Debian 2.2, RH 6.1 */
48 #elif defined(__GLIBC__) \
50 && __GLIBC_MINOR__ == 1 \
51 && LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
54 /* Kernel headers 2.2.X + Glibc 2.0 - Debian 2.1 */
55 #elif defined(__GLIBC__) \
57 && __GLIBC_MINOR__ == 0 \
58 && LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,0) \
59 && LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
61 #define KLUDGE_HEADERS
63 /* Note : is it really worth supporting kernel 2.0.X, knowing that
64 * we require WE v9, which is only available in 2.2.X and higher ?
65 * I guess one could use 2.0.x with an upgraded wireless.h... */
67 /* Kernel headers 2.0.X + Glibc 2.0 - Debian 2.0, RH 5 */
68 #elif defined(__GLIBC__) \
70 && __GLIBC_MINOR__ == 0 \
71 && LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) \
72 && LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,0)
75 /* Kernel headers 2.0.X + libc5 - old systems */
76 #elif defined(_LINUX_C_LIB_VERSION_MAJOR) \
77 && _LINUX_C_LIB_VERSION_MAJOR == 5 \
78 && LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,0) \
79 && LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
82 /* Unsupported combination */
84 #error "Your kernel/libc combination is not supported"
87 #ifdef GLIBC22_HEADERS
88 /* Added by Ross G. Miller <Ross_Miller@baylor.edu>, 3/28/01 */
89 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
90 #include <linux/socket.h> /* For AF_INET & struct sockaddr */
91 #include <sys/socket.h>
92 #endif /* GLIBC22_HEADERS */
95 #include <socketbits.h>
96 #endif /* KLUDGE_HEADERS */
99 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
100 #include <linux/socket.h> /* For AF_INET & struct sockaddr */
101 #include <linux/in.h> /* For struct sockaddr_in */
102 #endif /* KLUDGE_HEADERS || GLIBC_HEADERS */
105 #include <sys/socket.h> /* For AF_INET & struct sockaddr & socket() */
106 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
107 #include <linux/in.h> /* For struct sockaddr_in */
108 #endif /* LIBC5_HEADERS */
110 #ifdef PRIVATE_WE_HEADER
111 /* Private copy of Wireless extensions */
112 #include "wireless.h"
113 #else /* PRIVATE_WE_HEADER */
114 /* System wide Wireless extensions */
115 #include <linux/wireless.h>
116 #endif /* PRIVATE_WE_HEADER */
119 #error "Wireless Extension v9 or newer required :-(\
120 Use Wireless Tools v19 or update your kernel headers"
122 #if WIRELESS_EXT < 12
123 #warning "Wireless Extension v12 recommended...\
124 You may update your kernel and/or system headers to get the new features..."
127 /****************************** DEBUG ******************************/
130 /************************ CONSTANTS & MACROS ************************/
132 /* Some usefull constants */
137 /* Backward compatibility for Wireless Extension 9 */
138 #ifndef IW_POWER_MODIFIER
139 #define IW_POWER_MODIFIER 0x000F /* Modify a parameter */
140 #define IW_POWER_MIN 0x0001 /* Value is a minimum */
141 #define IW_POWER_MAX 0x0002 /* Value is a maximum */
142 #define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */
143 #endif /* IW_POWER_MODIFIER */
145 #ifndef IW_ENCODE_NOKEY
146 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not here */
147 #define IW_ENCODE_MODE 0xF000 /* Modes defined below */
148 #endif /* IW_ENCODE_NOKEY */
150 /* More backward compatibility */
151 #ifndef SIOCSIWCOMMIT
152 #define SIOCSIWCOMMIT SIOCSIWNAME
153 #endif /* SIOCSIWCOMMIT */
155 /****************************** TYPES ******************************/
158 typedef struct iw_statistics iwstats;
159 typedef struct iw_range iwrange;
160 typedef struct iw_param iwparam;
161 typedef struct iw_freq iwfreq;
162 typedef struct iw_quality iwqual;
163 typedef struct iw_priv_args iwprivargs;
164 typedef struct sockaddr sockaddr;
166 /* Structure for storing all wireless information for each device
167 * This is pretty exhaustive... */
168 typedef struct wireless_info
170 char name[IFNAMSIZ]; /* Wireless/protocol name */
172 iwparam nwid; /* Network ID */
174 float freq; /* Frequency/channel */
176 iwparam sens; /* sensitivity */
178 unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */
179 int key_size; /* Number of bytes */
180 int key_flags; /* Various flags */
183 char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */
185 char nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
187 sockaddr ap_addr; /* Access point address */
189 iwparam bitrate; /* Bit rate in bps */
191 iwparam rts; /* RTS threshold in bytes */
193 iwparam frag; /* Fragmentation threshold in bytes */
195 int mode; /* Operation mode */
197 iwparam power; /* Power management parameters */
199 iwparam txpower; /* Transmit Power in dBm */
201 iwparam retry; /* Retry limit or lifetime */
210 /* Structure for storing all wireless information for each device
211 * This is a cut down version of the one above, containing only
212 * the things *truly* needed to configure a card.
213 * Don't add other junk, I'll remove it... */
214 typedef struct wireless_config
216 char name[IFNAMSIZ]; /* Wireless/protocol name */
218 iwparam nwid; /* Network ID */
220 float freq; /* Frequency/channel */
222 unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */
223 int key_size; /* Number of bytes */
224 int key_flags; /* Various flags */
227 char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */
229 int mode; /* Operation mode */
232 /**************************** PROTOTYPES ****************************/
234 * All the functions in iwcommon.c
236 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
238 iw_sockets_open(void);
239 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
241 iw_get_range_info(int skfd,
245 iw_get_priv_info(int skfd,
249 iw_get_basic_config(int skfd,
251 wireless_config * info);
253 iw_set_basic_config(int skfd,
255 wireless_config * info);
256 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
258 iw_float2freq(double in,
261 iw_freq2float(iwfreq * in);
262 /* ---------------------- POWER SUBROUTINES ----------------------- */
264 iw_dbm2mwatt(int in);
266 iw_mwatt2dbm(int in);
267 /* -------------------- STATISTICS SUBROUTINES -------------------- */
269 iw_get_stats(int skfd,
273 iw_print_stats(char * buffer,
277 /* --------------------- ENCODING SUBROUTINES --------------------- */
279 iw_print_key(char * buffer,
283 /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
285 iw_print_pm_value(char * buffer,
289 iw_print_pm_mode(char * buffer,
291 /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */
292 #if WIRELESS_EXT > 10
294 iw_print_retry_value(char * buffer,
298 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
300 iw_check_mac_addr_type(int skfd,
303 iw_check_if_addr_type(int skfd,
307 iw_check_addr_type(int skfd,
311 iw_pr_ether(char *buffer, unsigned char *ptr);
313 iw_in_ether(char *bufp, struct sockaddr *sap);
315 iw_in_inet(char *bufp, struct sockaddr *sap);
320 struct sockaddr * sap);
321 /* ----------------------- MISC SUBROUTINES ------------------------ */
323 iw_byte_size(int args);
325 /**************************** VARIABLES ****************************/
327 extern const char * iw_operation_mode[];
328 #define IW_NUM_OPER_MODE 6
330 /************************* INLINE FUNTIONS *************************/
332 * Function that are so simple that it's more efficient inlining them
336 * Note : I've defined wrapper for the ioctl request so that
337 * it will be easier to migrate to other kernel API if needed
340 /*------------------------------------------------------------------*/
342 * Wrapper to push some Wireless Parameter in the driver
345 iw_set_ext(int skfd, /* Socket to the kernel */
346 char * ifname, /* Device name */
347 int request, /* WE ID */
348 struct iwreq * pwrq) /* Fixed part of the request */
350 /* Set device name */
351 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
353 return(ioctl(skfd, request, pwrq));
356 /*------------------------------------------------------------------*/
358 * Wrapper to extract some Wireless Parameter out of the driver
361 iw_get_ext(int skfd, /* Socket to the kernel */
362 char * ifname, /* Device name */
363 int request, /* WE ID */
364 struct iwreq * pwrq) /* Fixed part of the request */
366 /* Set device name */
367 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
369 return(ioctl(skfd, request, pwrq));