OSDN Git Service

v21
[android-x86/external-wireless-tools.git] / wireless_tools / iwcommon.h
1 /*
2  *      Wireless Tools
3  *
4  *              Jean II - HPLB 97->99 - HPL 99->00
5  *
6  * Common header for the wireless tools...
7  *
8  * This file is released under the GPL license.
9  */
10
11 #ifndef IWCOMMON_H
12 #define IWCOMMON_H
13
14 /************************** DOCUMENTATION **************************/
15 /*
16  * None ? Todo...
17  */
18
19 /* --------------------------- HISTORY --------------------------- */
20 /*
21  * wireless 16 :                (Jean Tourrilhes)
22  * -----------
23  *      o iwconfig, iwpriv & iwspy
24  *
25  * wireless 17 :                (Justin Seger)
26  * -----------
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
31  *
32  * wireless 18 :
33  * -----------
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>)
50  *      o Minor fixes
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
59  *
60  * wireless 19 :
61  * -----------
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]
73  *
74  * wireless 20 :
75  * -----------
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 ;-)
94  *
95  * wireless 21 :
96  * -----------
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]
105  *      ---
106  *      o Common subroutines to display stats & power saving info [iwcommon]
107  *      o Display all power management info, capability and values [iwspy]
108  *      ---
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]
112  *      ---
113  *      o Transmit Power stuff (dBm + mW) [iwconfig/iwspy]
114  *      o Cleaner formatting algorithm when displaying params [iwconfig]
115  *      ---
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
129  *      ---
130  *      o Fix bug in display ints - "Allen Miu" <aklmiu@mit.edu> [iwpriv]
131  */
132
133 /* ----------------------------- TODO ----------------------------- */
134 /*
135  * One day, maybe...
136  *
137  * iwconfig :
138  * --------
139  *      Make disable a per encryption key modifier if some hardware
140  *      requires it.
141  *
142  * iwpriv :
143  * ------
144  *      Remove 'port' and 'roam' cruft now that we have mode in iwconfig
145  *
146  * iwspy :
147  * -----
148  *      -
149  *
150  * Doc & man pages :
151  * ---------------
152  *      Update main doc.
153  *
154  * Other :
155  * -----
156  *      What about some graphical tools ?
157  */
158
159 /***************************** INCLUDES *****************************/
160
161 /* Standard headers */
162 #include <sys/types.h>
163 #include <sys/ioctl.h>
164 #include <stdio.h>
165 #include <math.h>
166 #include <errno.h>
167 #include <fcntl.h>
168 #include <ctype.h>
169 #include <stdlib.h>
170 #include <string.h>
171 #include <unistd.h>
172 #include <netdb.h>              /* gethostbyname, getnetbyname */
173
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 ;-) */
177
178 #ifdef KLUDGE_HEADERS
179 #include <socketbits.h>
180 #endif  /* KLUDGE_HEADERS */
181
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 */
187
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 */    
194
195 #ifdef LIBC5_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 */
200
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 */
208
209 #if WIRELESS_EXT < 9
210 #error "Wireless Extension v9 or newer required :-(\
211 Use Wireless Tools v19 or update your kernel headers"
212 #endif
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..."
216 #endif
217
218 /****************************** DEBUG ******************************/
219
220
221 /************************ CONSTANTS & MACROS ************************/
222
223 /* Some usefull constants */
224 #define KILO    1e3
225 #define MEGA    1e6
226 #define GIGA    1e9
227
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
235
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
240
241 /****************************** TYPES ******************************/
242
243 /* Shortcuts */
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;
251
252 /* Structure for storing all wireless information for each device */
253 typedef struct wireless_info
254 {
255   char          name[IFNAMSIZ];         /* Wireless/protocol name */
256   int           has_nwid;
257   iwparam       nwid;                   /* Network ID */
258   int           has_freq;
259   float         freq;                   /* Frequency/channel */
260   int           has_sens;
261   iwparam       sens;                   /* sensitivity */
262   int           has_key;
263   unsigned char key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
264   int           key_size;               /* Number of bytes */
265   int           key_flags;              /* Various flags */
266   int           has_essid;
267   int           essid_on;
268   char          essid[IW_ESSID_MAX_SIZE + 1];   /* ESSID (extended network) */
269   int           has_nickname;
270   char          nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
271   int           has_ap_addr;
272   sockaddr      ap_addr;                /* Access point address */
273   int           has_bitrate;
274   iwparam       bitrate;                /* Bit rate in bps */
275   int           has_rts;
276   iwparam       rts;                    /* RTS threshold in bytes */
277   int           has_frag;
278   iwparam       frag;                   /* Fragmentation threshold in bytes */
279   int           has_mode;
280   int           mode;                   /* Operation mode */
281   int           has_power;
282   iwparam       power;                  /* Power management parameters */
283   int           has_txpower;
284   iwparam       txpower;                /* Transmit Power in dBm */
285   int           has_retry;
286   iwparam       retry;                  /* Retry limit or lifetime */
287
288   /* Stats */
289   iwstats       stats;
290   int           has_stats;
291   iwrange       range;
292   int           has_range;
293 } wireless_info;
294
295 /**************************** PROTOTYPES ****************************/
296 /*
297  * All the functions in iwcommon.c
298  */
299 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
300 int
301         sockets_open(void);
302 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
303 int
304         get_range_info(int              skfd,
305                        char *           ifname,
306                        iwrange *        range);
307 int
308         get_priv_info(int               skfd,
309                       char *            ifname,
310                       iwprivargs *      priv);
311 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
312 void
313         float2freq(double       in,
314                    iwfreq *     out);
315 double
316         freq2float(iwfreq *     in);
317 /* ---------------------- POWER SUBROUTINES ----------------------- */
318 int
319         dbm2mwatt(int   in);
320 int
321         mwatt2dbm(int   in);
322 /* -------------------- STATISTICS SUBROUTINES -------------------- */
323 void
324         print_stats(FILE *      stream,
325                     iwqual *    qual,
326                     iwrange *   range,
327                     int         has_range);
328 /* --------------------- ENCODING SUBROUTINES --------------------- */
329 void
330         print_key(FILE *                stream,
331                   unsigned char *       key,
332                   int                   key_size,
333                   int                   key_flags);
334 /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
335 void
336         print_pm_value(FILE *   stream,
337                        int      value,
338                        int      flags);
339 void
340         print_pm_mode(FILE *    stream,
341                       int       flags);
342 /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */
343 #if WIRELESS_EXT > 10
344 void
345         print_retry_value(FILE *        stream,
346                           int           value,
347                           int           flags);
348 #endif
349 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
350 int
351         check_addr_type(int     skfd,
352                         char *  ifname);
353 char *
354         pr_ether(unsigned char *ptr);
355 int
356         in_ether(char *bufp, struct sockaddr *sap);
357 int
358         in_inet(char *bufp, struct sockaddr *sap);
359 int
360         in_addr(int             skfd,
361                 char *          ifname,
362                 char *          bufp,
363                 struct sockaddr *sap);
364 /* ----------------------- MISC SUBROUTINES ------------------------ */
365 int
366         byte_size(int           args);
367
368 /**************************** VARIABLES ****************************/
369
370 #endif  /* IWCOMMON_H */