00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef IWLIB_H
00013 #define IWLIB_H
00014
00015
00016
00017
00018
00019
00020 #include <sys/types.h>
00021 #include <sys/ioctl.h>
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include <errno.h>
00025 #include <fcntl.h>
00026 #include <ctype.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <unistd.h>
00030 #include <netdb.h>
00031 #include <net/ethernet.h>
00032 #include <sys/time.h>
00033 #include <unistd.h>
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <net/if_arp.h>
00044 #include <sys/socket.h>
00045 #include <netinet/in.h>
00046 #include <netinet/if_ether.h>
00047
00048
00049
00050 #ifndef __user
00051 #define __user
00052 #endif
00053
00054 #include <linux/types.h>
00055
00056
00057 #include <sys/socket.h>
00058 #include <net/if.h>
00059
00060
00061 #include "wireless.h"
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #undef IW_GCC_HAS_BROKEN_INLINE
00073 #if __GNUC__ == 3
00074 #if __GNUC_MINOR__ >= 1 && __GNUC_MINOR__ < 4
00075 #define IW_GCC_HAS_BROKEN_INLINE 1
00076 #endif
00077 #endif
00078
00079
00080
00081
00082 #if __GNUC__ == 4
00083 #define IW_GCC_HAS_BROKEN_INLINE 1
00084 #endif
00085
00086 #ifdef IW_GCC_HAS_BROKEN_INLINE
00087 #ifdef inline
00088 #undef inline
00089 #endif
00090 #define inline inline __attribute__((always_inline))
00091 #endif
00092
00093 #ifdef __cplusplus
00094 extern "C" {
00095 #endif
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #define WE_VERSION 21
00106
00107 #define WE_MAX_VERSION 22
00108
00109 #define WT_VERSION 29
00110
00111
00112 #define PROC_NET_WIRELESS "/proc/net/wireless"
00113 #define PROC_NET_DEV "/proc/net/dev"
00114
00115
00116 #define KILO 1e3
00117 #define MEGA 1e6
00118 #define GIGA 1e9
00119
00120 #define LOG10_MAGIC 1.25892541179
00121
00122
00123 #ifndef ARPHRD_IEEE80211
00124 #define ARPHRD_IEEE80211 801
00125 #endif
00126
00127 #ifndef IW_EV_LCP_PK_LEN
00128
00129 #define IW_EV_LCP_PK_LEN (4)
00130
00131 #define IW_EV_CHAR_PK_LEN (IW_EV_LCP_PK_LEN + IFNAMSIZ)
00132 #define IW_EV_UINT_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(__u32))
00133 #define IW_EV_FREQ_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq))
00134 #define IW_EV_PARAM_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_param))
00135 #define IW_EV_ADDR_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr))
00136 #define IW_EV_QUAL_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))
00137 #define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4)
00138
00139 struct iw_pk_event
00140 {
00141 __u16 len;
00142 __u16 cmd;
00143 union iwreq_data u;
00144 } __attribute__ ((packed));
00145 struct iw_pk_point
00146 {
00147 void __user *pointer;
00148 __u16 length;
00149 __u16 flags;
00150 } __attribute__ ((packed));
00151
00152 #define IW_EV_LCP_PK2_LEN (sizeof(struct iw_pk_event) - sizeof(union iwreq_data))
00153 #define IW_EV_POINT_PK2_LEN (IW_EV_LCP_PK2_LEN + sizeof(struct iw_pk_point) - IW_EV_POINT_OFF)
00154
00155 #endif
00156
00157
00158
00159
00160 typedef struct iw_statistics iwstats;
00161 typedef struct iw_range iwrange;
00162 typedef struct iw_param iwparam;
00163 typedef struct iw_freq iwfreq;
00164 typedef struct iw_quality iwqual;
00165 typedef struct iw_priv_args iwprivargs;
00166 typedef struct sockaddr sockaddr;
00167
00168
00169
00170
00171
00172 typedef struct wireless_config
00173 {
00174 char name[IFNAMSIZ + 1];
00175 int has_nwid;
00176 iwparam nwid;
00177 int has_freq;
00178 double freq;
00179 int freq_flags;
00180 int has_key;
00181 unsigned char key[IW_ENCODING_TOKEN_MAX];
00182 int key_size;
00183 int key_flags;
00184 int has_essid;
00185 int essid_on;
00186 char essid[IW_ESSID_MAX_SIZE + 1];
00187 int has_mode;
00188 int mode;
00189 } wireless_config;
00190
00191
00192
00193 typedef struct wireless_info
00194 {
00195 struct wireless_config b;
00196
00197 int has_sens;
00198 iwparam sens;
00199 int has_nickname;
00200 char nickname[IW_ESSID_MAX_SIZE + 1];
00201 int has_ap_addr;
00202 sockaddr ap_addr;
00203 int has_bitrate;
00204 iwparam bitrate;
00205 int has_rts;
00206 iwparam rts;
00207 int has_frag;
00208 iwparam frag;
00209 int has_power;
00210 iwparam power;
00211 int has_txpower;
00212 iwparam txpower;
00213 int has_retry;
00214 iwparam retry;
00215
00216
00217 iwstats stats;
00218 int has_stats;
00219 iwrange range;
00220 int has_range;
00221
00222
00223 int auth_key_mgmt;
00224 int has_auth_key_mgmt;
00225 int auth_cipher_pairwise;
00226 int has_auth_cipher_pairwise;
00227 int auth_cipher_group;
00228 int has_auth_cipher_group;
00229 } wireless_info;
00230
00231
00232
00233
00234
00235 typedef struct wireless_scan
00236 {
00237
00238 struct wireless_scan * next;
00239
00240
00241 int has_ap_addr;
00242 sockaddr ap_addr;
00243
00244
00245 struct wireless_config b;
00246 iwstats stats;
00247 int has_stats;
00248 iwparam maxbitrate;
00249 int has_maxbitrate;
00250 } wireless_scan;
00251
00252
00253
00254
00255 typedef struct wireless_scan_head
00256 {
00257 wireless_scan * result;
00258 int retry;
00259 } wireless_scan_head;
00260
00261
00262
00263 typedef struct stream_descr
00264 {
00265 char * end;
00266 char * current;
00267 char * value;
00268 } stream_descr;
00269
00270
00271
00272 typedef int (*iw_enum_handler)(int skfd,
00273 char * ifname,
00274 char * args[],
00275 int count);
00276
00277
00278 typedef struct iw_modul_descr
00279 {
00280 unsigned int mask;
00281 char cmd[8];
00282 char * verbose;
00283 } iw_modul_descr;
00284
00285
00286
00287
00288
00289
00290
00291 int
00292 iw_sockets_open(void);
00293 void
00294 iw_enum_devices(int skfd,
00295 iw_enum_handler fn,
00296 char * args[],
00297 int count);
00298
00299 int
00300 iw_get_kernel_we_version(void);
00301 int
00302 iw_print_version_info(const char * toolname);
00303 int
00304 iw_get_range_info(int skfd,
00305 const char * ifname,
00306 iwrange * range);
00307 int
00308 iw_get_priv_info(int skfd,
00309 const char * ifname,
00310 iwprivargs ** ppriv);
00311 int
00312 iw_get_basic_config(int skfd,
00313 const char * ifname,
00314 wireless_config * info);
00315 int
00316 iw_set_basic_config(int skfd,
00317 const char * ifname,
00318 wireless_config * info);
00319
00320 int
00321 iw_protocol_compare(const char * protocol1,
00322 const char * protocol2);
00323
00324 void
00325 iw_float2freq(double in,
00326 iwfreq * out);
00327 double
00328 iw_freq2float(const iwfreq * in);
00329 void
00330 iw_print_freq_value(char * buffer,
00331 int buflen,
00332 double freq);
00333 void
00334 iw_print_freq(char * buffer,
00335 int buflen,
00336 double freq,
00337 int channel,
00338 int freq_flags);
00339 int
00340 iw_freq_to_channel(double freq,
00341 const struct iw_range * range);
00342 int
00343 iw_channel_to_freq(int channel,
00344 double * pfreq,
00345 const struct iw_range * range);
00346 void
00347 iw_print_bitrate(char * buffer,
00348 int buflen,
00349 int bitrate);
00350
00351 int
00352 iw_dbm2mwatt(int in);
00353 int
00354 iw_mwatt2dbm(int in);
00355 void
00356 iw_print_txpower(char * buffer,
00357 int buflen,
00358 struct iw_param * txpower);
00359
00360 int
00361 iw_get_stats(int skfd,
00362 const char * ifname,
00363 iwstats * stats,
00364 const iwrange * range,
00365 int has_range);
00366 void
00367 iw_print_stats(char * buffer,
00368 int buflen,
00369 const iwqual * qual,
00370 const iwrange * range,
00371 int has_range);
00372
00373 void
00374 iw_print_key(char * buffer,
00375 int buflen,
00376 const unsigned char * key,
00377 int key_size,
00378 int key_flags);
00379 int
00380 iw_in_key(const char * input,
00381 unsigned char * key);
00382 int
00383 iw_in_key_full(int skfd,
00384 const char * ifname,
00385 const char * input,
00386 unsigned char * key,
00387 __u16 * flags);
00388
00389 void
00390 iw_print_pm_value(char * buffer,
00391 int buflen,
00392 int value,
00393 int flags,
00394 int we_version);
00395 void
00396 iw_print_pm_mode(char * buffer,
00397 int buflen,
00398 int flags);
00399
00400 void
00401 iw_print_retry_value(char * buffer,
00402 int buflen,
00403 int value,
00404 int flags,
00405 int we_version);
00406
00407 void
00408 iw_print_timeval(char * buffer,
00409 int buflen,
00410 const struct timeval * time,
00411 const struct timezone * tz);
00412
00413 int
00414 iw_check_mac_addr_type(int skfd,
00415 const char * ifname);
00416 int
00417 iw_check_if_addr_type(int skfd,
00418 const char * ifname);
00419 #if 0
00420 int
00421 iw_check_addr_type(int skfd,
00422 const char * ifname);
00423 #endif
00424 #if 0
00425 int
00426 iw_get_mac_addr(int skfd,
00427 const char * name,
00428 struct ether_addr * eth,
00429 unsigned short * ptype);
00430 #endif
00431 char *
00432 iw_mac_ntop(const unsigned char * mac,
00433 int maclen,
00434 char * buf,
00435 int buflen);
00436 void
00437 iw_ether_ntop(const struct ether_addr * eth,
00438 char * buf);
00439 char *
00440 iw_sawap_ntop(const struct sockaddr * sap,
00441 char * buf);
00442 int
00443 iw_mac_aton(const char * orig,
00444 unsigned char * mac,
00445 int macmax);
00446 int
00447 iw_ether_aton(const char* bufp, struct ether_addr* eth);
00448 int
00449 iw_in_inet(char *bufp, struct sockaddr *sap);
00450 int
00451 iw_in_addr(int skfd,
00452 const char * ifname,
00453 char * bufp,
00454 struct sockaddr * sap);
00455
00456 int
00457 iw_get_priv_size(int args);
00458
00459
00460 void
00461 iw_init_event_stream(struct stream_descr * stream,
00462 char * data,
00463 int len);
00464 int
00465 iw_extract_event_stream(struct stream_descr * stream,
00466 struct iw_event * iwe,
00467 int we_version);
00468
00469 int
00470 iw_process_scan(int skfd,
00471 char * ifname,
00472 int we_version,
00473 wireless_scan_head * context);
00474 int
00475 iw_scan(int skfd,
00476 char * ifname,
00477 int we_version,
00478 wireless_scan_head * context);
00479
00480
00481
00482
00483 extern const char * const iw_operation_mode[];
00484 #define IW_NUM_OPER_MODE 7
00485 #define IW_NUM_OPER_MODE_EXT 8
00486
00487
00488 extern const struct iw_modul_descr iw_modul_list[];
00489 #define IW_SIZE_MODUL_LIST 16
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 static inline int
00506 iw_set_ext(int skfd,
00507 const char * ifname,
00508 int request,
00509 struct iwreq * pwrq)
00510 {
00511
00512 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
00513
00514 return(ioctl(skfd, request, pwrq));
00515 }
00516
00517
00518
00519
00520
00521 static inline int
00522 iw_get_ext(int skfd,
00523 const char * ifname,
00524 int request,
00525 struct iwreq * pwrq)
00526 {
00527
00528 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
00529
00530 return(ioctl(skfd, request, pwrq));
00531 }
00532
00533
00534
00535
00536
00537 static inline void
00538 iw_sockets_close(int skfd)
00539 {
00540 close(skfd);
00541 }
00542
00543
00544
00545
00546
00547 static inline char *
00548 iw_saether_ntop(const struct sockaddr *sap, char* bufp)
00549 {
00550 iw_ether_ntop((const struct ether_addr *) sap->sa_data, bufp);
00551 return bufp;
00552 }
00553
00554
00555
00556
00557 static inline int
00558 iw_saether_aton(const char *bufp, struct sockaddr *sap)
00559 {
00560 sap->sa_family = ARPHRD_ETHER;
00561 return iw_ether_aton(bufp, (struct ether_addr *) sap->sa_data);
00562 }
00563
00564
00565
00566
00567
00568 static inline void
00569 iw_broad_ether(struct sockaddr *sap)
00570 {
00571 sap->sa_family = ARPHRD_ETHER;
00572 memset((char *) sap->sa_data, 0xFF, ETH_ALEN);
00573 }
00574
00575
00576
00577
00578
00579 static inline void
00580 iw_null_ether(struct sockaddr *sap)
00581 {
00582 sap->sa_family = ARPHRD_ETHER;
00583 memset((char *) sap->sa_data, 0x00, ETH_ALEN);
00584 }
00585
00586
00587
00588
00589
00590 static inline int
00591 iw_ether_cmp(const struct ether_addr* eth1, const struct ether_addr* eth2)
00592 {
00593 return memcmp(eth1, eth2, sizeof(*eth1));
00594 }
00595
00596 #ifdef __cplusplus
00597 }
00598 #endif
00599
00600 #endif