Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

include.h

Go to the documentation of this file.
00001 /* 
00002  * File : include.h
00003  * Project : WifiScanner (c) 2002-2004 Hervé Schauer Consultants
00004  * Usage : This utility is written for use with IEEE 802.11 adapters based
00005  * on Intersil's PRISM II chipset (PCMCIA).
00006  * 
00007  * Base code was from prismstumbler Jan Fernquist <Jan.B.Fernquist@telia.com>
00008  * and wlanctl from www.linux-wlan.org
00009  *
00010  * This program is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License
00012  * as published by the Free Software Foundation; either version 2
00013  * of the License, or (at your option) any later version.
00014  * 
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  *
00024  */
00025 
00026 /* $Id: include.h,v 1.51 2005/02/23 11:36:52 poggij Exp $ */
00027 
00028 #ifndef _WIFISCAN_INCLUDE_H_
00029 #define _WIFISCAN_INCLUDE_H_
00030 
00031 // A little ugly hack ...
00032 #ifdef LWNG_2_1
00033 #define LWNG_2_0
00034 #endif
00035 
00036 #ifdef LWNG_2_0
00037 #define LWNG_16
00038 #endif
00039 
00040 #ifdef LWNG_16
00041 #define LWNG_15
00042 #endif
00043 
00044 #ifdef LWNG_15
00045 #define LWNG_14
00046 #endif
00047 
00048 
00049 #define ABSTRACTION_LAYER
00050 
00051 #include <config.h>
00052 
00053 #include <stdio.h>
00054 #include <stdlib.h>
00055 #include <signal.h>
00056 #include <unistd.h>
00057 #include <limits.h>
00058 
00059 #ifdef STDC_HEADERS
00060 # include <string.h>
00061 #else
00062 # ifndef HAVE_MEMSET
00063 #  error "You didn't have memset function, try to create it or change your OS"
00064 # endif
00065 #endif
00066 
00067 #if TIME_WITH_SYS_TIME
00068 # include <sys/time.h>
00069 # include <time.h>
00070 #else
00071 # if HAVE_SYS_TIME_H
00072 #  include <sys/time.h>
00073 # else
00074 #  include <time.h>
00075 # endif
00076 #endif
00077 
00078 #include <sys/timeb.h>
00079 #include <sys/socket.h>
00080 #include <sys/resource.h>
00081 #include <sys/ioctl.h>
00082 #include <asm/types.h>
00083 #include <linux/netlink.h>
00084 #include <errno.h>
00085 #include <ctype.h>
00086 
00087 #ifdef NET_BPH_H_DEBIAN
00088 #  include <pcap-bpf.h>
00089 #else
00090 #  include <net/bpf.h>
00091 #endif
00092 
00093 #if defined(HAVE_LIBNCURSES) && defined(BUILD_CURSES)
00094 #ifdef HAVE_LIBCURSES
00095 #include <curses.h>
00096 #else
00097 #include <ncurses.h>
00098 #endif
00099 #endif
00100 
00101 #ifdef WITH_THREAD
00102 #include <pthread.h>
00103 #else
00104 #define WITHOUT_THREAD
00105 #endif
00106 
00107 #include <pcap.h>
00108 /* include from Linux-Wlan-NG */
00109 //#include <wlan/wlan_compat.h>
00110 /*
00111 #include <wlan/p80211types.h>
00112 #include <wlan/p80211msg.h>
00113 #include <wlan/p80211meta.h>
00114 #include <wlan/p80211metamsg.h>
00115 #include <wlan/p80211metastruct.h>
00116 #include <wlan/p80211metadef.h>
00117 #include <wlan/p80211ioctl.h>
00118 #include <wlan/p80211mgmt.h>
00119 #include <wlan/version.h>
00120 */
00121 #include <wlan/p80211hdr.h>
00122 #ifdef LWNG_16
00123 //#include <wlan/p80211conv.h>
00124 #endif
00125 
00126 #ifndef RETSIGTYPE
00127 #define RETSIGTYPE void
00128 #endif
00129 
00130 #ifndef FALSE
00131 #define FALSE (UINT8) 0
00132 #endif
00133 #ifndef TRUE
00134 #define TRUE (UINT8) 1
00135 #endif
00136 
00137 #define UINT8_MAX       (0xffUL)
00138 #define UINT16_MAX      (0xffffUL)
00139 #define UINT32_MAX      (0xffffffffUL)
00140 
00141 #define INT8_MAX        (0x7fL)
00142 #define INT16_MAX       (0x7fffL)
00143 #define INT32_MAX       (0x7fffffffL)
00144 
00145 #define __WLAN_ATTRIB_PACK__            __attribute__ ((packed))
00146 #define __WLAN_PRAGMA_PACK1__
00147 #define __WLAN_PRAGMA_PACKDFLT__
00148 #define __WLAN_INLINE__                 inline
00149 
00150 
00151 /* Version */
00152 // If the fourth number is <> 0 it's a CVS version only
00153 #ifdef LWNG_13
00154 #error "CODE for this driver version is DEAD and deprecated\nTry to update linux-wlan-ng code"
00155 #endif
00156 
00157 #define WIFISCANNER_VERSION WIFISCANNER_VERSION_NUM
00158 
00159 /* Different size or constant */
00160 #define MAX_BUFFER_SIZE 4096    /* Size of receive buffer */
00161 #define DEVNAME_LEN 16
00162 #define MCAST_GRP_SNIFF 0x00000002      /* Value used to notify netlink */
00163 #define WLAN_STR_ADDR_LEN 18
00164 #define MAXSIZE_OTHERINFORMATION 0x100
00165 #define HISTORY_SIZE 4
00166 #define MAX_NUMBER_OF_DETECTED_CLIENT 8192      /* Maximum of station */
00167 #define KEYBOARD_BUFFER 8
00168 
00169 #define MANUF_MAXSTRINGLENGTH 32
00170 
00171 /*
00172  * How many packet should we read if we have a signal on a channel????
00173  * After that we force a channel change anyway
00174  */
00175 //#define CHANNEL_READ_COUNT 1 
00176 
00177 /* We want to do only 7 channel scan per second 
00178    With this time, the capture was optimized
00179 */
00180 #define TIME_TO_SLEEP_BEFORE_CHANGE_CHANNEL (1000/(14*1))       /* in ms */
00181 #define TIMEOUT_TRY_TO_READ_PAQUET (1000000/(14/2))     /* µs */
00182 
00183 /*****************************/
00184 /* MACRO                     */
00185 /*****************************/
00186 
00187 #define SET_BIT(a,n)    (a|=(1<<n))
00188 #define CLR_BIT(a,n)    (a&=~(1<<n))
00189 #define IS_BIT_SET(a,n) (a & (1<<n))
00190 #define IS_BIT_CLR(a,n) (~(a & (1<<n)))
00191 #define SWITCH_BIT(a,n) (a^=(1<<n))
00192 #define GET_BIT(a,n)    ((a >> n) & 1)
00193 
00194 /*
00195 Structure of bit field description
00196 ---------------------------------
00197 |   |   |   |   |   |   |   |   |
00198 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
00199 |   |   |   |   |   |   |   |   |
00200 +---------------+---------------+
00201 | <- SUBTYPE -> | <-  TYPE   -> |
00202 
00203 bit set     : do    or is    capable
00204 bit not set : don't or isn't capable
00205 
00206 bit 0 = 1 && Dedicated Access point || classic client (CPU + Card)
00207 bit 1 = 1 && Emmit some Beacon || don't Emmit Beacon
00208 bit 2 = 1 && mode P2P (Ad-Hoc) || Not
00209 bit 3 = 1 && Data transmited || Not
00210 bit 4 = 1 && Data go to DS || Not
00211 bit 5 = 1 && Data go from DS || Not
00212 */
00213 
00214 #define TYPE_BIT_AP      0
00215 #define TYPE_BIT_BEACON  1
00216 #define TYPE_BIT_P2P     2
00217 #define TYPE_BIT_DATA    3
00218 #define TYPE_BIT_TODS    4
00219 #define TYPE_BIT_FROMDS  5
00220 
00221 #define SET_TYPE_BIT_AP(x)      SET_BIT(x, TYPE_BIT_AP)
00222 #define SET_TYPE_BIT_BEACON(x)  SET_BIT(x, TYPE_BIT_BEACON)
00223 #define SET_TYPE_BIT_P2P(x)     SET_BIT(x, TYPE_BIT_P2P)
00224 #define SET_TYPE_BIT_DATA(x)    SET_BIT(x, TYPE_BIT_DATA)
00225 #define SET_TYPE_BIT_TODS(x)    SET_BIT(x, TYPE_BIT_TODS)
00226 #define SET_TYPE_BIT_FROMDS(x)  SET_BIT(x, TYPE_BIT_FROMDS)
00227 
00228 #define CLEAR_TYPE_BIT_AP(x)      CLR_BIT(x, TYPE_BIT_AP)
00229 #define CLEAR_TYPE_BIT_BEACON(x)  CLR_BIT(x, TYPE_BIT_BEACON)
00230 #define CLEAR_TYPE_BIT_P2P(x)     CLR_BIT(x, TYPE_BIT_P2P)
00231 #define CLEAR_TYPE_BIT_DATA(x)    CLR_BIT(x, TYPE_BIT_DATA)
00232 #define CLEAR_TYPE_BIT_TODS(x)    CLR_BIT(x, TYPE_BIT_TODS)
00233 #define CLEAR_TYPE_BIT_FROMDS(x)  CLR_BIT(x, TYPE_BIT_FROMDS)
00234 
00235 #define GET_TYPE_BIT_AP(x)      GET_BIT(x, TYPE_BIT_AP)
00236 #define GET_TYPE_BIT_BEACON(x)  GET_BIT(x, TYPE_BIT_BEACON)
00237 #define GET_TYPE_BIT_P2P(x)     GET_BIT(x, TYPE_BIT_P2P)
00238 #define GET_TYPE_BIT_DATA(x)    GET_BIT(x, TYPE_BIT_DATA)
00239 #define GET_TYPE_BIT_TODS(x)    GET_BIT(x, TYPE_BIT_TODS)
00240 #define GET_TYPE_BIT_FROMDS(x)  GET_BIT(x, TYPE_BIT_FROMDS)
00241 
00242 #define TYPE_BIT_00 "Client"
00243 #define TYPE_BIT_01 "AP Base"
00244 #define TYPE_BIT_02 "AP Base (STA in master mode)"
00245 #define TYPE_BIT_03 "AP Base (dedicated)"
00246 #define TYPE_BIT_04 "Ad-Hoc STA"
00247 #define TYPE_BIT_05 "???5"
00248 #define TYPE_BIT_06 "Ad-Hoc STA (beacon)"
00249 #define TYPE_BIT_07 "Ad-Hoc STA"
00250 #define TYPE_BIT_08 "STA Activity"
00251 #define TYPE_BIT_09 "???9 Reserved"
00252 #define TYPE_BIT_0A "???A Reserved"
00253 #define TYPE_BIT_0B "???B Reserved"
00254 #define TYPE_BIT_0C "???C Reserved"
00255 #define TYPE_BIT_0D "???D Reserved"
00256 #define TYPE_BIT_0E "???E Reserved"
00257 #define TYPE_BIT_0F "???F Reserved"
00258 
00259 #define SUBTYPE_BIT_00 "Radio only"
00260 #define SUBTYPE_BIT_01 "Data To DS"
00261 #define SUBTYPE_BIT_02 "Data From DS"
00262 #define SUBTYPE_BIT_03 "Data AP to AP"
00263 #define SUBTYPE_BIT_04 "???4 Reserved"
00264 #define SUBTYPE_BIT_05 "???5 Reserved"
00265 #define SUBTYPE_BIT_06 "???6 Reserved"
00266 #define SUBTYPE_BIT_07 "???7 Reserved"
00267 #define SUBTYPE_BIT_08 "???8 Reserved"
00268 #define SUBTYPE_BIT_09 "???9 Reserved"
00269 #define SUBTYPE_BIT_0A "???A Reserved"
00270 #define SUBTYPE_BIT_0B "???B Reserved"
00271 #define SUBTYPE_BIT_0C "???C Reserved"
00272 #define SUBTYPE_BIT_0D "???D Reserved"
00273 #define SUBTYPE_BIT_0E "???E Reserved"
00274 #define SUBTYPE_BIT_0F "???F Reserved"
00275 
00276 #define WLAN_SIZEOF_TYPEOFPACKET 6      
00277 
00278 #define STR_YES "Yes"
00279 #define STR_NO  "No"
00280 
00281 #define STR_WEP    "Wep"
00282 #define STR_NOWEP  "---"
00283 
00284 #define STR_STA "STA"
00285 #define STR_AP  "AP"
00286 
00288 #define MAX_DEBUG_LEVEL 3
00289 #define DEBUG_POINT debug(3, "%s:%d\n", __FUNCTION__, __LINE__);
00290 
00294 #define HELPTEXT1 \
00295 "Call with no parameters or with the following options\n" \
00296 " --help          -h           - This help page\n" \
00297 " --version       -v           - Write Version and quit\n" \
00298 " --verbose       -V level     - For verbose, level 2 is for debugging\n" \
00299 " --card-driver   -C           - Wireless card driver :\n" \
00300 "                                'prism', 'cisco' 'cisco_wifi (eth+wifi)' 'orinoco' 'atheros', 'prism54g', or 'hostap'\n" \
00301 " --iface         -i device    - Name of the interface (default wlan0)\n" \
00302 "                              - for cisco_wifi driver, give the two interfaces like eth1,wifi0\n" \
00303 " --output-file   -F filename  - Save output to a file as well as stdout\n" \
00304 " --device-file   -D filename  - Create a file of detected devices, in a .dot format\n" \
00305 " --hop           -H number    - Number of hops do for rotating channel (default 5)\n" \
00306 " --channel       -S channel   - Only listen on a specific Channel (1-14)\n" \
00307 " --computer-date -d           - Write date in machine readable format\n" \
00308 " --ids           -I           - Activate the IDS functions\n" \
00309 " --max-packets   -M number    - Max packets to capture before exit\n" \
00310 "                                (0 = unlimited)\n" \
00311 " --hide-packets  -N abcd      - Do not display Ack, Beacon, Control, Data\n" \
00312 " --hop-delay     -t number    - Number of ms before channel change (default=200)\n" \
00313 " --disable-check -c           - Do not chek curses screen size\n" \
00314 
00315 
00316 #ifdef WITH_WIRETAP
00317 #define HELPTEXT HELPTEXT1 \
00318 " --pcap-file     -W filename  - Save sniffed data to a file in PCAP format\n"
00319 #else
00320 #define WITHOUT_WIRETAP
00321 #define HELPTEXT HELPTEXT1
00322 #endif
00323 // Option that was available but work is still in progress ;-)
00324 //"        -G ??? \n"
00325 //"        -w FileName  - Save weak IV packet to break WEP\n"
00326 //"        -k FileName  - Save KeyStream in hex format (IV, KeyStream)\n"
00327 
00328 
00330 #define IS_DISPLAY_ACK(x)     ( (x > 0) & 1)
00331 #define IS_DISPLAY_BEACON(x)  ( (x > 1) & 1)
00332 #define IS_DISPLAY_CONTROL(x) ( (x > 2) & 1)
00333 #define IS_DISPLAY_DATA(x)    ( (x > 3) & 1)
00334 
00336 #define WLAN_NG_CARD          1 
00337 #define CISCO_CARD            2 
00338 #define LUCENT_CARD           3 
00339 #define WLAN_NG_CARD_AVS_CFF2 4 
00340 #define PCAP_VIRTUAL_CARD     5 
00341 #define HOSTAP_CARD           6 
00342 #define CISCO_CVS_CARD        7 
00343 #define ATHEROS_CARD          8 
00344 #define PRISM54G_CARD         9 
00345 
00346 #ifndef phytype_fhss_dot11_97
00347 #define phytype_fhss_dot11_97   1
00348 #define phytype_dsss_dot11_97   2
00349 #define phytype_irbaseband      3
00350 #define phytype_dsss_dot11_b    4
00351 #define phytype_pbcc_dot11_b    5
00352 #define phytype_ofdm_dot11_g    6
00353 #define phytype_pbcc_dot11_g    7
00354 #define phytype_ofdm_dot11_a    8
00355 #endif
00356 
00357 // Code from of Linux-wlan-ng.0.2.0
00358 /*================================================================*/
00359 /* Constants */
00360 
00361 #define WLAN_ETHADDR_LEN        6
00362 #define WLAN_IEEE_OUI_LEN       3
00363 
00364 #define WLAN_ETHCONV_ENCAP      1
00365 #define WLAN_ETHCONV_RFC1042    2
00366 #define WLAN_ETHCONV_8021h      3
00367 
00368 #define WLAN_MIN_ETHFRM_LEN     60
00369 #define WLAN_MAX_ETHFRM_LEN     1514
00370 #define WLAN_ETHHDR_LEN         14
00371 
00372 #define WLAN_SSID_MAXLEN            32
00373 
00374 #ifndef P80211CAPTURE_VERSION
00375 
00376 #define P80211CAPTURE_VERSION   0x80211001
00377 
00378 /*================================================================*/
00379 /* Types */
00380 
00384 __WLAN_PRAGMA_PACK1__ typedef struct p80211_caphdr {
00385   UINT32 version __WLAN_ATTRIB_PACK__;
00386   UINT32 length __WLAN_ATTRIB_PACK__;
00387   UINT64 mactime __WLAN_ATTRIB_PACK__;
00388   UINT64 hosttime __WLAN_ATTRIB_PACK__;
00389   UINT32 phytype __WLAN_ATTRIB_PACK__;
00390   UINT32 channel __WLAN_ATTRIB_PACK__;
00391   UINT32 datarate __WLAN_ATTRIB_PACK__;
00392   UINT32 antenna __WLAN_ATTRIB_PACK__;
00393   UINT32 priority __WLAN_ATTRIB_PACK__;
00394   UINT32 ssi_type __WLAN_ATTRIB_PACK__;
00395   INT32 ssi_signal __WLAN_ATTRIB_PACK__;
00396   INT32 ssi_noise __WLAN_ATTRIB_PACK__;
00397   UINT32 preamble __WLAN_ATTRIB_PACK__;
00398   UINT32 encoding __WLAN_ATTRIB_PACK__;
00399 } p80211_caphdr_t;
00400 
00401 __WLAN_PRAGMA_PACKDFLT__
00402 #endif                          // ifndef P80211CAPTURE_VERSION
00403 
00407     typedef struct {
00408   UINT64 ts;                    
00409   UINT16 bcn_int;               
00410   UINT16 cap_info;              
00411 } FixedField_t;
00412 
00414 typedef struct {
00415   char DestMac[WLAN_STR_ADDR_LEN];
00416   char SrcMac[WLAN_STR_ADDR_LEN];
00417   char BssId[WLAN_STR_ADDR_LEN];
00418   char SSID[WLAN_SSID_MAXLEN + 1];
00419   UINT8 hasWep;
00420   //UINT8 isAp;
00421   UINT8 Channel;
00422   UINT8 SChannel;
00423   UINT8 Signal;
00424   UINT8 Noise;
00425   UINT8 Rate;
00426   UINT16 TypeOfClient;
00427   char OtherInformation[MAXSIZE_OTHERINFORMATION];
00428   char TypeOfPacket[WLAN_SIZEOF_TYPEOFPACKET + 1];
00429   UINT8 TypeSubtype;
00430   UINT8 IV[4];
00431 } ScanResult_t;
00432 
00434 typedef struct {
00435   UINT8 AddMac[WLAN_ADDR_LEN];
00436   UINT8 BSSID[WLAN_ADDR_LEN];
00437   char SSID[WLAN_SSID_MAXLEN + 1];
00438   UINT32 SNMax;                         
00439   UINT32 SNMin;                         
00440   UINT32 SNMed;                         
00441   UINT32 SN[HISTORY_SIZE];              
00442   UINT8 RateMax;
00443   UINT8 RateMin;
00444   UINT8 hasWep:1;
00445   UINT8 IsDS:1;                         
00446   UINT8 IsAP:1;                         
00447   UINT8 IsP2P:1;                        
00448   UINT8 Channel;
00449   UINT16 bcn_int[HISTORY_SIZE];         
00450   UINT64 TimeStamp[HISTORY_SIZE];       
00451   UINT16 SeqNum[HISTORY_SIZE];          
00452   UINT16 SeqNumWithAP[HISTORY_SIZE];            
00453   char OtherInformation[MAXSIZE_OTHERINFORMATION];
00454   UINT8 LastIV[4];
00455   float coef_a_TS;              
00456   float coef_b_TS;
00457   UINT8 MaxSpeed;
00458   char Manuf[MANUF_MAXSTRINGLENGTH];
00459   char Model[MANUF_MAXSTRINGLENGTH];
00460 } ClientInfo_t;
00461 
00463 typedef struct {
00464   UINT16 AP;                    // Nb of different AP
00465   UINT16 STA;                   // Nb of different STA
00466   UINT32 Beacon;                // Nb of beacon detected
00467   UINT16 SSID;                  // Nb of different SSID
00468   UINT16 Channel;               // Nb of channel who a signal has been detected
00469   UINT16 INVLD;                 // Nb of invalid packets
00470   UINT32 WeakIV;                // Nb of weak IV
00471   UINT32 CryptedPackets;        // Nb of Crypted Packets
00472   UINT32 Packets;               // Nb of packets
00473   UINT8 IV[4];                  // Las IV
00474   UINT8 MaxSignal[14];          // Max strength of signal on each channel
00475 } Statistics_t;
00476 
00478 typedef struct CaptureArg_t {
00479   pcap_t *pcap;
00480   pcap_dumper_t *dump;
00481   int offset;
00482 } CaptureArg;
00483 
00484 // Wifiscanner configuration
00485 typedef struct {
00486   UINT8 SingleChannel;
00487   char *OutFileName;            // Name of file .txt
00488   char *OutDumpFileName;        // Name of file .tcp
00489   char *OutDotFileName;         // Name of file .dot
00490   UINT8 DebugLevel;             // Debug Level
00491   unsigned int TimeToSleepBeforeChangeChannel;
00492   char devname[DEVNAME_LEN];    // Device name to work
00493   char devname2[DEVNAME_LEN];   // Second device name (for Cisco Wifi)
00494   UINT8 ChannelHop;             // Size of the Hop channel
00495   UINT64 MaxPacket;             // Number of packet to catch before stop automatically
00496   UINT8 DateFormat;             // Format of Date
00497   UINT8 DoNotDisplay;           // Do not display Ack, Beacon, Control and Data
00498   UINT8 IDS_is_ON;              // IDS state
00499   UINT8 SendAlert2Syslog;       // Send Alert to Syslog
00500   UINT8 CheckScreenSize;        // If we must check Screen Size
00501   UINT8 TypeOfCard;             // Driver name
00502   UINT16 FirstNIC;              // First NIC to display (used in NIC list) Scroll !
00503   UINT8 GPSDisWanted;           // True if we must use GPSD
00504   char *HostGPSD;               // Host to connect to GPSD (localhost)
00505   UINT16 PortOfGPSD;            // Port to connect to GPSD (2947)
00506 } ConfigStruct;
00507 
00508 // Manufacturer Data
00509 typedef struct {
00510   char Name[MANUF_MAXSTRINGLENGTH];
00511   char Model[MANUF_MAXSTRINGLENGTH];
00512 } ManufData_t;
00513 
00514 #endif                          /* _WIFI_INCLUDE_H_ */

Generated on Fri Feb 25 12:02:37 2005 for WifiScanner by  doxygen 1.4.1