OSDN Git Service

v22
[android-x86/external-wireless-tools.git] / wireless_tools / iwlib.h
1 /*
2  *      Wireless Tools
3  *
4  *              Jean II - HPLB 97->99 - HPL 99->01
5  *
6  * Common header for the Wireless Extension library...
7  *
8  * This file is released under the GPL license.
9  */
10
11 #ifndef IWLIB_H
12 #define IWLIB_H
13
14 /*#include "CHANGELOG.h"*/
15
16 /***************************** INCLUDES *****************************/
17
18 /* Standard headers */
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
21 #include <stdio.h>
22 #include <math.h>
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <ctype.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <netdb.h>              /* gethostbyname, getnetbyname */
30
31 /* This is our header selection. Try to hide the mess and the misery :-(
32  * The selection has been moved in the Makefile, here we have only
33  * the ugly part. Don't look, you would go blind ;-) */
34
35 #ifdef KLUDGE_HEADERS
36 #include <socketbits.h>
37 #endif  /* KLUDGE_HEADERS */
38
39 #if defined(KLUDGE_HEADERS) || defined(GLIBC_HEADERS)
40 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
41 #include <linux/socket.h>       /* For AF_INET & struct sockaddr */
42 #include <linux/in.h>           /* For struct sockaddr_in */
43 #endif  /* KLUDGE_HEADERS || GLIBC_HEADERS */
44
45 #ifdef GLIBC22_HEADERS 
46 /* Added by Ross G. Miller <Ross_Miller@baylor.edu>, 3/28/01 */
47 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
48 #include <linux/socket.h>       /* For AF_INET & struct sockaddr */
49 #include <sys/socket.h>
50 #endif /* GLIBC22_HEADERS */    
51
52 #ifdef LIBC5_HEADERS
53 #include <sys/socket.h>         /* For AF_INET & struct sockaddr & socket() */
54 #include <linux/if_arp.h>       /* For ARPHRD_ETHER */
55 #include <linux/in.h>           /* For struct sockaddr_in */
56 #endif  /* LIBC5_HEADERS */
57
58 #ifdef PRIVATE_WE_HEADER
59 /* Private copy of Wireless extensions */
60 #include "wireless.h"
61 #else   /* PRIVATE_WE_HEADER */
62 /* System wide Wireless extensions */
63 #include <linux/wireless.h>
64 #endif  /* PRIVATE_WE_HEADER */
65
66 #if WIRELESS_EXT < 9
67 #error "Wireless Extension v9 or newer required :-(\
68 Use Wireless Tools v19 or update your kernel headers"
69 #endif
70 #if WIRELESS_EXT < 11
71 #warning "Wireless Extension v11 recommended...\
72 You may update your kernel and/or system headers to get the new features..."
73 #endif
74
75 /****************************** DEBUG ******************************/
76
77
78 /************************ CONSTANTS & MACROS ************************/
79
80 /* Some usefull constants */
81 #define KILO    1e3
82 #define MEGA    1e6
83 #define GIGA    1e9
84
85 /* Backward compatibility for Wireless Extension 9 */
86 #ifndef IW_POWER_MODIFIER
87 #define IW_POWER_MODIFIER       0x000F  /* Modify a parameter */
88 #define IW_POWER_MIN            0x0001  /* Value is a minimum  */
89 #define IW_POWER_MAX            0x0002  /* Value is a maximum */
90 #define IW_POWER_RELATIVE       0x0004  /* Value is not in seconds/ms/us */
91 #endif IW_POWER_MODIFIER
92
93 #ifndef IW_ENCODE_NOKEY
94 #define IW_ENCODE_NOKEY         0x0800  /* Key is write only, so not here */
95 #define IW_ENCODE_MODE          0xF000  /* Modes defined below */
96 #endif IW_ENCODE_NOKEY
97
98 /****************************** TYPES ******************************/
99
100 /* Shortcuts */
101 typedef struct iw_statistics    iwstats;
102 typedef struct iw_range         iwrange;
103 typedef struct iw_param         iwparam;
104 typedef struct iw_freq          iwfreq;
105 typedef struct iw_quality       iwqual;
106 typedef struct iw_priv_args     iwprivargs;
107 typedef struct sockaddr         sockaddr;
108
109 /* Structure for storing all wireless information for each device
110  * This is pretty exhaustive... */
111 typedef struct wireless_info
112 {
113   char          name[IFNAMSIZ];         /* Wireless/protocol name */
114   int           has_nwid;
115   iwparam       nwid;                   /* Network ID */
116   int           has_freq;
117   float         freq;                   /* Frequency/channel */
118   int           has_sens;
119   iwparam       sens;                   /* sensitivity */
120   int           has_key;
121   unsigned char key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
122   int           key_size;               /* Number of bytes */
123   int           key_flags;              /* Various flags */
124   int           has_essid;
125   int           essid_on;
126   char          essid[IW_ESSID_MAX_SIZE + 1];   /* ESSID (extended network) */
127   int           has_nickname;
128   char          nickname[IW_ESSID_MAX_SIZE + 1]; /* NickName */
129   int           has_ap_addr;
130   sockaddr      ap_addr;                /* Access point address */
131   int           has_bitrate;
132   iwparam       bitrate;                /* Bit rate in bps */
133   int           has_rts;
134   iwparam       rts;                    /* RTS threshold in bytes */
135   int           has_frag;
136   iwparam       frag;                   /* Fragmentation threshold in bytes */
137   int           has_mode;
138   int           mode;                   /* Operation mode */
139   int           has_power;
140   iwparam       power;                  /* Power management parameters */
141   int           has_txpower;
142   iwparam       txpower;                /* Transmit Power in dBm */
143   int           has_retry;
144   iwparam       retry;                  /* Retry limit or lifetime */
145
146   /* Stats */
147   iwstats       stats;
148   int           has_stats;
149   iwrange       range;
150   int           has_range;
151 } wireless_info;
152
153 /* Structure for storing all wireless information for each device
154  * This is a cut down version of the one above, containing only
155  * the things *truly* needed to configure a card.
156  * Don't add other junk, I'll remove it... */
157 typedef struct wireless_config
158 {
159   char          name[IFNAMSIZ];         /* Wireless/protocol name */
160   int           has_nwid;
161   iwparam       nwid;                   /* Network ID */
162   int           has_freq;
163   float         freq;                   /* Frequency/channel */
164   int           has_key;
165   unsigned char key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
166   int           key_size;               /* Number of bytes */
167   int           key_flags;              /* Various flags */
168   int           has_essid;
169   int           essid_on;
170   char          essid[IW_ESSID_MAX_SIZE + 1];   /* ESSID (extended network) */
171   int           has_mode;
172   int           mode;                   /* Operation mode */
173 } wireless_config;
174
175 /**************************** PROTOTYPES ****************************/
176 /*
177  * All the functions in iwcommon.c
178  */
179 /* ---------------------- SOCKET SUBROUTINES -----------------------*/
180 int
181         iw_sockets_open(void);
182 /* --------------------- WIRELESS SUBROUTINES ----------------------*/
183 int
184         iw_get_range_info(int           skfd,
185                           char *        ifname,
186                           iwrange *     range);
187 int
188         iw_get_priv_info(int            skfd,
189                          char *         ifname,
190                          iwprivargs *   priv);
191 int
192         iw_get_basic_config(int                 skfd,
193                             char *              ifname,
194                             wireless_config *   info);
195 int
196         iw_set_basic_config(int                 skfd,
197                             char *              ifname,
198                             wireless_config *   info);
199 /* -------------------- FREQUENCY SUBROUTINES --------------------- */
200 void
201         iw_float2freq(double    in,
202                    iwfreq *     out);
203 double
204         iw_freq2float(iwfreq *  in);
205 /* ---------------------- POWER SUBROUTINES ----------------------- */
206 int
207         iw_dbm2mwatt(int        in);
208 int
209         iw_mwatt2dbm(int        in);
210 /* -------------------- STATISTICS SUBROUTINES -------------------- */
211 int
212         iw_get_stats(int        skfd,
213                      char *     ifname,
214                      iwstats *  stats);
215 void
216         iw_print_stats(char *           buffer,
217                        iwqual *         qual,
218                        iwrange *        range,
219                        int              has_range);
220 /* --------------------- ENCODING SUBROUTINES --------------------- */
221 void
222         iw_print_key(char *             buffer,
223                      unsigned char *    key,
224                      int                key_size,
225                      int                key_flags);
226 /* ----------------- POWER MANAGEMENT SUBROUTINES ----------------- */
227 void
228         iw_print_pm_value(char *        buffer,
229                           int           value,
230                           int           flags);
231 void
232         iw_print_pm_mode(char *         buffer,
233                          int            flags);
234 /* --------------- RETRY LIMIT/LIFETIME SUBROUTINES --------------- */
235 #if WIRELESS_EXT > 10
236 void
237         iw_print_retry_value(char *     buffer,
238                              int        value,
239                              int        flags);
240 #endif
241 /* --------------------- ADDRESS SUBROUTINES ---------------------- */
242 int
243         iw_check_addr_type(int  skfd,
244                         char *  ifname);
245 char *
246         iw_pr_ether(char *buffer, unsigned char *ptr);
247 int
248         iw_in_ether(char *bufp, struct sockaddr *sap);
249 int
250         iw_in_inet(char *bufp, struct sockaddr *sap);
251 int
252         iw_in_addr(int                  skfd,
253                    char *               ifname,
254                    char *               bufp,
255                    struct sockaddr *    sap);
256 /* ----------------------- MISC SUBROUTINES ------------------------ */
257 int
258         iw_byte_size(int                args);
259
260 /**************************** VARIABLES ****************************/
261
262 extern const char *     iw_operation_mode[];
263 #define IW_NUM_OPER_MODE        6
264
265 #endif  /* IWLIB_H */