OSDN Git Service

v20
[android-x86/external-wireless-tools.git] / wireless_tools / iwcommon.h
1 /*
2  *      Wireless Tools
3  *
4  *              Jean II - HPLB '99
5  *
6  * Common header for the wireless tools...
7  */
8
9 #ifndef IWCOMMON_H
10 #define IWCOMMON_H
11
12 /************************** DOCUMENTATION **************************/
13 /*
14  * None ? Todo...
15  */
16
17 /* --------------------------- HISTORY --------------------------- */
18 /*
19  * wireless 16 :                (Jean Tourrilhes)
20  * -----------
21  *      o iwconfig, iwpriv & iwspy
22  *
23  * wireless 17 :                (Justin Seger)
24  * -----------
25  *      o Compile under glibc fix
26  *      o merge iwpriv in iwconfig
27  *      o Add Wavelan roaming support
28  *      o Update man page of iwconfig
29  *
30  * wireless 18 :
31  * -----------
32  *              (From Andreas Neuhaus <andy@fasta.fh-dortmund.de>)
33  *      o Many fix to remove "core dumps" in iwconfig
34  *      o Remove useless headers in iwconfig
35  *      o CHAR wide private ioctl
36  *              (From Jean Tourrilhes)
37  *      o Create iwcommon.h and iwcommon.c
38  *      o Separate iwpriv again for user interface issues
39  *        The folllowing didn't make sense and crashed :
40  *              iwconfig eth0 priv sethisto 12 15 nwid 100
41  *      o iwspy no longer depend on net-tools-1.2.0
42  *      o Reorganisation of the code, cleanup
43  *      o Add ESSID stuff in iwconfig
44  *      o Add display of level & noise in dBm (stats in iwconfig)
45  *      o Update man page of iwconfig and iwpriv
46  *      o Add xwireless (didn't check if it compiles)
47  *              (From Dean W. Gehnert <deang@tpi.com>)
48  *      o Minor fixes
49  *              (Jan Rafaj <rafaj@cedric.vabo.cz>)
50  *      o Cosmetic changes (sensitivity relative, freq list)
51  *      o Frequency computation on double
52  *      o Compile clean on libc5
53  *              (From Jean Tourrilhes)
54  *      o Move listing of frequencies to iwspy
55  *      o Add AP address stuff in iwconfig
56  *      o Add AP list stuff in iwspy
57  *
58  * wireless 19 :
59  * -----------
60  *              (From Jean Tourrilhes)
61  *      o Allow for sensitivity in dBm (if < 0) [iwconfig]
62  *      o Formatting changes in displaying ap address in [iwconfig]
63  *      o Slightly improved man pages and usage display
64  *      o Add channel number for each frequency in list [iwspy]
65  *      o Add nickname... [iwconfig]
66  *      o Add "port" private ioctl shortcut [iwpriv]
67  *      o If signal level = 0, no range or dBms [iwconfig]
68  *      o I think I now got set/get char strings right in [iwpriv]
69  *              (From Thomas Ekstrom <tomeck@thelogic.com>)
70  *      o Fix a very obscure bug in [iwspy]
71  *
72  * wireless 20 :
73  * -----------
74  *              (From Jean Tourrilhes)
75  *      o Remove all #ifdef WIRELESS ugliness, but add a #error :
76  *              we require Wireless Extensions 9 or nothing !  [all]
77  *      o Switch to new 'nwid' definition (specific -> iw_param) [iwconfig]
78  *      o Rewriten totally the encryption support [iwconfig]
79  *              - Multiple keys, through key index
80  *              - Flexible/multiple key size, and remove 64bits upper limit
81  *              - Open/Restricted modes
82  *              - Enter keys as ASCII strings
83  *      o List key sizes supported and all keys in [iwspy]
84  *      o Mode of operation support (ad-hoc, managed...) [iwconfig]
85  *      o Use '=' to indicate fixed instead of ugly '(f)' [iwconfig]
86  *      o Ability to disable RTS & frag (off), now the right way [iwconfig]
87  *      o Auto as an input modifier for bitrate [iwconfig]
88  *      o Power Management support [iwconfig]
89  *              - set timeout or period and its value
90  *              - Reception mode (unicast/multicast/all)
91  *      o Updated man pages with all that ;-)
92  */
93
94 /* ----------------------------- TODO ----------------------------- */
95 /*
96  * One day, maybe...
97  *
98  * iwconfig :
99  * --------
100  *      Make disable a per encryption key modifier if some hardware
101  *      requires it.
102  *      Should not mention "Access Point" but something different when
103  *      in ad-hoc mode.
104  *
105  * iwpriv :
106  * ------
107  *      Remove 'port' and 'roam' cruft now that we have mode in iwconfig
108  *
109  * iwspy :
110  * -----
111  *      ?
112  *
113  * Doc & man pages :
114  * ---------------
115  *      Update main doc.
116  *
117  * Other :
118  * -----
119  *      What about some graphical tools ?
120  */
121
122 /***************************** INCLUDES *****************************/
123
124 /* Standard headers */
125 #include <sys/types.h>
126 #include <sys/ioctl.h>
127 #include <stdio.h>
128 #include <math.h>
129 #include <errno.h>
130 #include <fcntl.h>
131 #include <ctype.h>
132 #include <stdlib.h>
133 #include <string.h>
134 #include <unistd.h>
135 #include <netdb.h>              /* gethostbyname, getnetbyname */
136
137 /* This is our header selection. Try to hide the mess and the misery :-(
138  * Please choose only one of the define...
139  */
140 /* Kernel headers 2.0.X + Glibc 2.0 - Debian 2.0, RH5
141  * Kernel headers 2.2.X + Glibc 2.1 - Debian 2.2, RH6.1 */
142 #define GLIBC_HEADERS
143
144 /* Kernel headers 2.2.X + Glibc 2.0 - Debian 2.1 */
145 #undef KLUDGE_HEADERS
146
147 /* Kernel headers 2.0.X + libc5 - old systems */
148 #undef LIBC5_HEADERS
149
150 #ifdef KLUDGE_HEADERS
151 #include <socketbits.h>
152 #endif  /* KLUDGE_HEADERS */
153
154 #if defined(KLUDGE_HEADERS) || defined(GLIBC_HEADERS)
155 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
156 #include <linux/socket.h>       /* For AF_INET & struct sockaddr */
157 #include <linux/in.h>           /* For struct sockaddr_in */
158 #endif  /* KLUDGE_HEADERS || GLIBC_HEADERS */
159
160 #ifdef LIBC5_HEADERS
161 #include <sys/socket.h>         /* For AF_INET & struct sockaddr & socket() */
162 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
163 #include <linux/in.h>           /* For struct sockaddr_in */
164 #endif  /* LIBC5_HEADERS */
165
166 /* Wireless extensions */
167 #include <linux/wireless.h>
168
169 #if WIRELESS_EXT < 8
170 #error "Wireless Extension v9 or newer required :-(\n\
171 Use Wireless Tools v19 or update your kernel headers"
172 #endif
173
174 /****************************** DEBUG ******************************/
175
176
177 /************************ CONSTANTS & MACROS ************************/
178
179 /* Some usefull constants */
180 #define KILO    1e3
181 #define MEGA    1e6
182 #define GIGA    1e9
183
184 /****************************** TYPES ******************************/
185
186 /* Shortcuts */
187 typedef struct iw_statistics    iwstats;
188 typedef struct iw_range         iwrange;
189 typedef struct iw_param         iwparam;
190 typedef struct iw_freq          iwfreq;
191 typedef struct iw_priv_args     iwprivargs;
192 typedef struct sockaddr         sockaddr;
193
194 /* Structure for storing all wireless information for each device */
195 typedef struct wireless_info
196 {
197   char          name[IFNAMSIZ];         /* Wireless/protocol name */
198   int           has_nwid;
199   iwparam       nwid;                   /* Network ID */
200   int           has_freq;
201   float         freq;                   /* Frequency/channel */
202   int           has_sens;
203   iwparam       sens;                   /* sensitivity */
204   int           has_key;
205   unsigned char key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
206   int           key_size;               /* Number of bytes */
207   int           key_flags;              /* Various flags */
208   int           has_essid;
209   int           essid_on;
210   char          essid[IW_ESSID_MAX_SIZE + 1];   /* ESSID (extended network) */
211   int           has_nickname;
212   char          nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
213   int           has_ap_addr;
214   sockaddr      ap_addr;                /* Access point address */
215   int           has_bitrate;
216   iwparam       bitrate;                /* Bit rate in bps */
217   int           has_rts;
218   iwparam       rts;                    /* RTS threshold in bytes */
219   int           has_frag;
220   iwparam       frag;                   /* Fragmentation threshold in bytes */
221   int           has_mode;
222   int           mode;                   /* Operation mode */
223   int           has_power;
224   iwparam       power;                  /* Power management parameters */
225
226   /* Stats */
227   iwstats       stats;
228   int           has_stats;
229   iwrange       range;
230   int           has_range;
231 } wireless_info;
232
233 /**************************** PROTOTYPES ****************************/
234 /*
235  * All the functions in iwcommon.c
236  */
237 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
238 int
239         sockets_open(void);
240 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
241 int
242         get_range_info(int              skfd,
243                        char *           ifname,
244                        iwrange *        range);
245 int
246         get_priv_info(int               skfd,
247                       char *            ifname,
248                       iwprivargs *      priv);
249 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
250 void
251         float2freq(double       in,
252                    iwfreq *     out);
253 double
254         freq2float(iwfreq *     in);
255 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
256 int
257         check_addr_type(int     skfd,
258                         char *  ifname);
259 char *
260         pr_ether(unsigned char *ptr);
261 int
262         in_ether(char *bufp, struct sockaddr *sap);
263 int
264         in_inet(char *bufp, struct sockaddr *sap);
265 int
266         in_addr(int             skfd,
267                 char *          ifname,
268                 char *          bufp,
269                 struct sockaddr *sap);
270 /* ----------------------- MISC SUBROUTINES ------------------------ */
271 int
272         byte_size(int           args);
273
274 /**************************** VARIABLES ****************************/
275
276 #endif  /* IWCOMMON_H */