OSDN Git Service

v19
[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
73 /* ----------------------------- TODO ----------------------------- */
74 /*
75  * One day, maybe...
76  *
77  * iwconfig :
78  * --------
79  *      Use new 802.11 parameters (rate, rts, frag)...
80  *
81  * iwpriv :
82  * ------
83  *      ?
84  *
85  * iwspy :
86  * -----
87  *      ?
88  *
89  * Doc & man pages :
90  * ---------------
91  *      ?
92  */
93
94 /***************************** INCLUDES *****************************/
95
96 /* Standard headers */
97 #include <sys/types.h>
98 #include <sys/ioctl.h>
99 #include <stdio.h>
100 #include <math.h>
101 #include <errno.h>
102 #include <fcntl.h>
103 #include <ctype.h>
104 #include <stdlib.h>
105 #include <string.h>
106 #include <unistd.h>
107 #include <netdb.h>              /* gethostbyname, getnetbyname */
108
109 /* This is our header selection. Try to hide the mess and the misery :-(
110  * Please choose only one of the define...
111  */
112 #define KER2_2_HEADERS          /* Kernel 2.2.X + Glibc - ok for most people */
113 #undef LINUX_HEADERS            /* Kernel 2.0.X + Glibc - Debian 2.0, RH5 */
114 #undef LIBC5_HEADERS            /* Kernel 2.0.X + libc5 - old systems */
115 #undef PRIVATE_HEADERS          /* Ugly last resort case */
116
117 #ifdef KER2_2_HEADERS
118 #include <socketbits.h>
119 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
120 #include <linux/socket.h>       /* For AF_INET & struct sockaddr */
121 #include <linux/in.h>           /* For struct sockaddr_in */
122
123 /* Wireless extensions */
124 #include <linux/wireless.h>
125
126 #endif  /* KER2_2_HEADERS */
127
128 #ifdef LINUX_HEADERS
129 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
130 #include <linux/socket.h>       /* For AF_INET & struct sockaddr */
131 #include <linux/in.h>           /* For struct sockaddr_in */
132
133 /* Wireless extensions */
134 #include <linux/wireless.h>
135
136 #endif  /* LINUX_HEADERS */
137
138 #ifdef LIBC5_HEADERS
139 #include <sys/socket.h>         /* For AF_INET & struct sockaddr & socket() */
140 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
141 #include <linux/in.h>           /* For struct sockaddr_in */
142
143 /* Wireless extensions */
144 #include <linux/wireless.h>
145
146 #endif  /* LIBC5_HEADERS */
147
148 #ifdef PRIVATE_HEADERS
149 #include <sys/types.h>
150 #include <sys/socket.h>
151 #include <socketbits.h>
152 #include "compat.h"             /* Don't ask ! */
153
154 /* Wireless extensions */
155 #include "wireless.h"
156
157 #endif  /* PRIVATE_HEADERS */
158
159
160 /****************************** DEBUG ******************************/
161
162
163 /************************ CONSTANTS & MACROS ************************/
164
165 /* Some usefull constants */
166 #define KILO    1e3
167 #define MEGA    1e6
168 #define GIGA    1e9
169
170 /* Some hack */
171 #ifndef IW_ESSID_MAX_SIZE
172 #define IW_ESSID_MAX_SIZE       32      /* Should be in wireless.h */
173 #endif
174 #ifndef IW_MAX_AP
175 #define IW_MAX_AP               8       /* Should be in wireless.h */
176 #endif
177
178 /****************************** TYPES ******************************/
179
180 /* Shortcuts */
181 typedef struct iw_statistics    iwstats;
182 typedef struct iw_range         iwrange;
183 typedef struct iw_freq          iwfreq;
184 typedef struct iw_priv_args     iwprivargs;
185 typedef struct sockaddr         sockaddr;
186
187 /* Structure for storing all wireless information for each device */
188 typedef struct wireless_info
189 {
190   char          name[IFNAMSIZ];         /* Wireless/protocol name */
191   int           has_nwid;
192   int           nwid_on;
193   u_long        nwid;                   /* Network ID */
194   int           has_freq;
195   float         freq;                   /* Frequency/channel */
196   int           has_sens;
197   int           sens;                   /* sensitivity */
198   int           has_enc;
199   int           enc_method;             /* encoding method or off */
200   long long     enc_key;                /* key used */
201   int           has_essid;
202   int           essid_on;
203   char          essid[IW_ESSID_MAX_SIZE + 1];   /* ESSID (extended network) */
204   int           has_nickname;
205   char          nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
206   int           has_ap_addr;
207   sockaddr      ap_addr;                /* Access point address */
208   int           has_bitrate;
209   long          bitrate;                /* Bit rate in bps */
210   int           bitrate_fixed;          /* Fixed or auto */
211   int           has_rts;
212   long          rts;                    /* RTS threshold in bytes */
213   int           rts_fixed;              /* Fixed or auto */
214   int           has_frag;
215   long          frag;                   /* Fragmentation threshold in bytes */
216   int           frag_fixed;             /* Fixed or auto */
217
218   /* Stats */
219   iwstats       stats;
220   int           has_stats;
221   iwrange       range;
222   int           has_range;
223 } wireless_info;
224
225 /**************************** PROTOTYPES ****************************/
226 /*
227  * All the functions in iwcommon.c
228  */
229 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
230 int
231         sockets_open(void);
232 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
233 int
234         get_range_info(int              skfd,
235                        char *           ifname,
236                        iwrange *        range);
237 int
238         get_priv_info(int               skfd,
239                       char *            ifname,
240                       iwprivargs *      priv);
241 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
242 void
243         float2freq(double       in,
244                    iwfreq *     out);
245 double
246         freq2float(iwfreq *     in);
247 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
248 int
249         check_addr_type(int     skfd,
250                         char *  ifname);
251 char *
252         pr_ether(unsigned char *ptr);
253 int
254         in_ether(char *bufp, struct sockaddr *sap);
255 int
256         in_inet(char *bufp, struct sockaddr *sap);
257 int
258         in_addr(int             skfd,
259                 char *          ifname,
260                 char *          bufp,
261                 struct sockaddr *sap);
262 /* ----------------------- MISC SUBROUTINES ------------------------ */
263 int
264         byte_size(int           args);
265
266 /**************************** VARIABLES ****************************/
267
268 #endif  /* IWCOMMON_H */