00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _WIFISCAN_INCLUDE_H_
00029 #define _WIFISCAN_INCLUDE_H_
00030
00031
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
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 #include <wlan/p80211hdr.h>
00122 #ifdef LWNG_16
00123
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
00152
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
00160 #define MAX_BUFFER_SIZE 4096
00161 #define DEVNAME_LEN 16
00162 #define MCAST_GRP_SNIFF 0x00000002
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
00167 #define KEYBOARD_BUFFER 8
00168
00169 #define MANUF_MAXSTRINGLENGTH 32
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 #define TIME_TO_SLEEP_BEFORE_CHANGE_CHANNEL (1000/(14*1))
00181 #define TIMEOUT_TRY_TO_READ_PAQUET (1000000/(14/2))
00182
00183
00184
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
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
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
00324
00325
00326
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
00358
00359
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
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
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;
00465 UINT16 STA;
00466 UINT32 Beacon;
00467 UINT16 SSID;
00468 UINT16 Channel;
00469 UINT16 INVLD;
00470 UINT32 WeakIV;
00471 UINT32 CryptedPackets;
00472 UINT32 Packets;
00473 UINT8 IV[4];
00474 UINT8 MaxSignal[14];
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
00485 typedef struct {
00486 UINT8 SingleChannel;
00487 char *OutFileName;
00488 char *OutDumpFileName;
00489 char *OutDotFileName;
00490 UINT8 DebugLevel;
00491 unsigned int TimeToSleepBeforeChangeChannel;
00492 char devname[DEVNAME_LEN];
00493 char devname2[DEVNAME_LEN];
00494 UINT8 ChannelHop;
00495 UINT64 MaxPacket;
00496 UINT8 DateFormat;
00497 UINT8 DoNotDisplay;
00498 UINT8 IDS_is_ON;
00499 UINT8 SendAlert2Syslog;
00500 UINT8 CheckScreenSize;
00501 UINT8 TypeOfCard;
00502 UINT16 FirstNIC;
00503 UINT8 GPSDisWanted;
00504 char *HostGPSD;
00505 UINT16 PortOfGPSD;
00506 } ConfigStruct;
00507
00508
00509 typedef struct {
00510 char Name[MANUF_MAXSTRINGLENGTH];
00511 char Model[MANUF_MAXSTRINGLENGTH];
00512 } ManufData_t;
00513
00514 #endif