4 * Jean II - HPLB 97->99 - HPL 99->00
6 * Common header for the wireless tools...
8 * This file is released under the GPL license.
14 /************************** DOCUMENTATION **************************/
19 /* --------------------------- HISTORY --------------------------- */
21 * wireless 16 : (Jean Tourrilhes)
23 * o iwconfig, iwpriv & iwspy
25 * wireless 17 : (Justin Seger)
27 * o Compile under glibc fix
28 * o merge iwpriv in iwconfig
29 * o Add Wavelan roaming support
30 * o Update man page of iwconfig
34 * (From Andreas Neuhaus <andy@fasta.fh-dortmund.de>)
35 * o Many fix to remove "core dumps" in iwconfig
36 * o Remove useless headers in iwconfig
37 * o CHAR wide private ioctl
38 * (From Jean Tourrilhes)
39 * o Create iwcommon.h and iwcommon.c
40 * o Separate iwpriv again for user interface issues
41 * The folllowing didn't make sense and crashed :
42 * iwconfig eth0 priv sethisto 12 15 nwid 100
43 * o iwspy no longer depend on net-tools-1.2.0
44 * o Reorganisation of the code, cleanup
45 * o Add ESSID stuff in iwconfig
46 * o Add display of level & noise in dBm (stats in iwconfig)
47 * o Update man page of iwconfig and iwpriv
48 * o Add xwireless (didn't check if it compiles)
49 * (From Dean W. Gehnert <deang@tpi.com>)
51 * (Jan Rafaj <rafaj@cedric.vabo.cz>)
52 * o Cosmetic changes (sensitivity relative, freq list)
53 * o Frequency computation on double
54 * o Compile clean on libc5
55 * (From Jean Tourrilhes)
56 * o Move listing of frequencies to iwspy
57 * o Add AP address stuff in iwconfig
58 * o Add AP list stuff in iwspy
62 * (From Jean Tourrilhes)
63 * o Allow for sensitivity in dBm (if < 0) [iwconfig]
64 * o Formatting changes in displaying ap address in [iwconfig]
65 * o Slightly improved man pages and usage display
66 * o Add channel number for each frequency in list [iwspy]
67 * o Add nickname... [iwconfig]
68 * o Add "port" private ioctl shortcut [iwpriv]
69 * o If signal level = 0, no range or dBms [iwconfig]
70 * o I think I now got set/get char strings right in [iwpriv]
71 * (From Thomas Ekstrom <tomeck@thelogic.com>)
72 * o Fix a very obscure bug in [iwspy]
76 * (From Jean Tourrilhes)
77 * o Remove all #ifdef WIRELESS ugliness, but add a #error :
78 * we require Wireless Extensions 9 or nothing ! [all]
79 * o Switch to new 'nwid' definition (specific -> iw_param) [iwconfig]
80 * o Rewriten totally the encryption support [iwconfig]
81 * - Multiple keys, through key index
82 * - Flexible/multiple key size, and remove 64bits upper limit
83 * - Open/Restricted modes
84 * - Enter keys as ASCII strings
85 * o List key sizes supported and all keys in [iwspy]
86 * o Mode of operation support (ad-hoc, managed...) [iwconfig]
87 * o Use '=' to indicate fixed instead of ugly '(f)' [iwconfig]
88 * o Ability to disable RTS & frag (off), now the right way [iwconfig]
89 * o Auto as an input modifier for bitrate [iwconfig]
90 * o Power Management support [iwconfig]
91 * - set timeout or period and its value
92 * - Reception mode (unicast/multicast/all)
93 * o Updated man pages with all that ;-)
97 * (from Alan McReynolds <alan_mcreynolds@hpl.hp.com>)
98 * o Use proper macros for compilation directives [Makefile]
99 * (From Jean Tourrilhes)
100 * o Put licensing info everywhere (almost). Yes, it's GPL !
101 * o Document the use of /etc/pcmcia/wireless.opts
102 * o Add min/max modifiers to power management parameters [iwconfig]
103 * -> requested by Lee Keyser-Allen for the Spectrum24 driver
104 * o Optionally output a second power management parameter [iwconfig]
106 * o Common subroutines to display stats & power saving info [iwcommon]
107 * o Display all power management info, capability and values [iwspy]
109 * o Optional index for ESSID (for Aironet driver) [iwcommon]
110 * o IW_ENCODE_NOKEY for write only keys [iwconfig/iwspy]
111 * o Common subrouting to print encoding keys [iwspy]
113 * o Transmit Power stuff (dBm + mW) [iwconfig/iwspy]
114 * o Cleaner formatting algorithm when displaying params [iwconfig]
116 * o Fix get_range_info() and use it everywhere - Should fix core dumps.
117 * o Catch WE version differences between tools and driver and
118 * warn user. Thanks to Tobias Ringstrom for the tip... [iwcommon]
119 * o Add Retry limit and lifetime support. [iwconfig/iwlist]
120 * o Display "Cell:" instead of "Access Point:" in ad-hoc mode [iwconfig]
121 * o Header fix for glibc2.2 by Ross G. Miller <Ross_Miller@baylor.edu>
122 * o Move header selection flags in Makefile [iwcommon/Makefile]
123 * o Spin-off iwlist.c from iwspy.c. iwspy is now much smaller
124 * After moving this bit of code all over the place, from iwpriv
125 * to iwconfig to iwspy, it now has a home of its own... [iwspy/iwlist]
126 * o Wrote quick'n'dirty iwgetid.
127 * o Remove output of second power management parameter [iwconfig]
128 * Please use iwlist, I don't want to bloat iwconfig
130 * o Fix bug in display ints - "Allen Miu" <aklmiu@mit.edu> [iwpriv]
133 /* ----------------------------- TODO ----------------------------- */
139 * Make disable a per encryption key modifier if some hardware
144 * Remove 'port' and 'roam' cruft now that we have mode in iwconfig
156 * What about some graphical tools ?
159 /***************************** INCLUDES *****************************/
161 /* Standard headers */
162 #include <sys/types.h>
163 #include <sys/ioctl.h>
172 #include <netdb.h> /* gethostbyname, getnetbyname */
174 /* This is our header selection. Try to hide the mess and the misery :-(
175 * The selection has been moved in the Makefile, here we have only
176 * the ugly part. Don't look, you would go blind ;-) */
178 #ifdef KLUDGE_HEADERS
179 #include <socketbits.h>
180 #endif /* KLUDGE_HEADERS */
182 #if defined(KLUDGE_HEADERS) || defined(GLIBC_HEADERS)
183 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
184 #include <linux/socket.h> /* For AF_INET & struct sockaddr */
185 #include <linux/in.h> /* For struct sockaddr_in */
186 #endif /* KLUDGE_HEADERS || GLIBC_HEADERS */
188 #ifdef GLIBC22_HEADERS
189 /* Added by Ross G. Miller <Ross_Miller@baylor.edu>, 3/28/01 */
190 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
191 #include <linux/socket.h> /* For AF_INET & struct sockaddr */
192 #include <sys/socket.h>
193 #endif /* GLIBC22_HEADERS */
196 #include <sys/socket.h> /* For AF_INET & struct sockaddr & socket() */
197 #include <linux/if_arp.h> /* For ARPHRD_ETHER */
198 #include <linux/in.h> /* For struct sockaddr_in */
199 #endif /* LIBC5_HEADERS */
201 #ifdef PRIVATE_WE_HEADER
202 /* Private copy of Wireless extensions */
203 #include "wireless.h"
204 #else /* PRIVATE_WE_HEADER */
205 /* System wide Wireless extensions */
206 #include <linux/wireless.h>
207 #endif /* PRIVATE_WE_HEADER */
210 #error "Wireless Extension v9 or newer required :-(\
211 Use Wireless Tools v19 or update your kernel headers"
213 #if WIRELESS_EXT < 11
214 #warning "Wireless Extension v11 recommended...\
215 You may update your kernel and/or system headers to get the new features..."
218 /****************************** DEBUG ******************************/
221 /************************ CONSTANTS & MACROS ************************/
223 /* Some usefull constants */
228 /* Backward compatibility for Wireless Extension 9 */
229 #ifndef IW_POWER_MODIFIER
230 #define IW_POWER_MODIFIER 0x000F /* Modify a parameter */
231 #define IW_POWER_MIN 0x0001 /* Value is a minimum */
232 #define IW_POWER_MAX 0x0002 /* Value is a maximum */
233 #define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */
234 #endif IW_POWER_MODIFIER
236 #ifndef IW_ENCODE_NOKEY
237 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not here */
238 #define IW_ENCODE_MODE 0xF000 /* Modes defined below */
239 #endif IW_ENCODE_NOKEY
241 /****************************** TYPES ******************************/
244 typedef struct iw_statistics iwstats;
245 typedef struct iw_range iwrange;
246 typedef struct iw_param iwparam;
247 typedef struct iw_freq iwfreq;
248 typedef struct iw_quality iwqual;
249 typedef struct iw_priv_args iwprivargs;
250 typedef struct sockaddr sockaddr;
252 /* Structure for storing all wireless information for each device */
253 typedef struct wireless_info
255 char name[IFNAMSIZ]; /* Wireless/protocol name */
257 iwparam nwid; /* Network ID */
259 float freq; /* Frequency/channel */
261 iwparam sens; /* sensitivity */
263 unsigned char key[IW_ENCODING_TOKEN_MAX]; /* Encoding key used */
264 int key_size; /* Number of bytes */
265 int key_flags; /* Various flags */
268 char essid[IW_ESSID_MAX_SIZE + 1]; /* ESSID (extended network) */
270 char nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
272 sockaddr ap_addr; /* Access point address */
274 iwparam bitrate; /* Bit rate in bps */
276 iwparam rts; /* RTS threshold in bytes */
278 iwparam frag; /* Fragmentation threshold in bytes */
280 int mode; /* Operation mode */
282 iwparam power; /* Power management parameters */
284 iwparam txpower; /* Transmit Power in dBm */
286 iwparam retry; /* Retry limit or lifetime */
295 /**************************** PROTOTYPES ****************************/
297 * All the functions in iwcommon.c
299 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
302 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
304 get_range_info(int skfd,
308 get_priv_info(int skfd,
311 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
313 float2freq(double in,
316 freq2float(iwfreq * in);
317 /* ---------------------- POWER SUBROUTINES ----------------------- */
322 /* -------------------- STATISTICS SUBROUTINES -------------------- */
324 print_stats(FILE * stream,
328 /* --------------------- ENCODING SUBROUTINES --------------------- */
330 print_key(FILE * stream,
334 /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
336 print_pm_value(FILE * stream,
340 print_pm_mode(FILE * stream,
342 /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */
343 #if WIRELESS_EXT > 10
345 print_retry_value(FILE * stream,
349 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
351 check_addr_type(int skfd,
354 pr_ether(unsigned char *ptr);
356 in_ether(char *bufp, struct sockaddr *sap);
358 in_inet(char *bufp, struct sockaddr *sap);
363 struct sockaddr *sap);
364 /* ----------------------- MISC SUBROUTINES ------------------------ */
368 /**************************** VARIABLES ****************************/
370 #endif /* IWCOMMON_H */