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

prism54g.c

Go to the documentation of this file.
00001 /* Linux Prism II Stumbler - Utility Scan for 802_11 networks under Linux
00002  * 
00003  * File : $Name:  $
00004  * Project : WifiScanner (c) 2002 Hervé Schauer Consultants
00005  * Usage : This utility is written for use with IEEE 802.11 adapters based
00006  * on Intersil's PRISM II chipset (PCMCIA).
00007  * 
00008  * Base code was from prismstumbler Jan Fernquist <Jan.B.Fernquist@telia.com>
00009  * and wlanctl from www.linux-wlan.com
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  * 
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  * 
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00024  *
00025  * $Id: prism54g.c,v 1.2 2005/02/23 11:36:53 poggij Exp $
00026  */
00027 
00028 
00029 // A lot of think is get from kismet
00030 //  http://www.kismetwireless.net/
00031 
00032 #include <include.h>
00033 #include <src/prism54g.h>
00034 #include <src/wlan-ng.h>
00035 #include <src/crt_io.h>
00036 
00037 static char *ID = "$Id: prism54g.c,v 1.2 2005/02/23 11:36:53 poggij Exp $";
00038 
00039 // All extern value you want
00040 //extern unsigned int DebugLevel;
00041 //extern UINT8 SingleChannel;
00042 //extern UINT8 TypeOfCard;
00043 extern ConfigStruct config;
00044 extern p80211_caphdr_t wlan_header;
00045 
00046 static CaptureArg ca;
00047 static char errbuf[PCAP_ERRBUF_SIZE];
00048 
00049 //-------------
00050 int selectChannelPRISM54g(char *devname, int channel)
00051 {
00052 #define STR_MAX 80
00053   char str[STR_MAX];
00054   int result = 0;
00055 
00056 /*
00057   if (config.SingleChannel) {
00058     // ???
00059     return 1;
00060   } else {
00061     // ???
00062     return 1;
00063   }
00064 */
00065   snprintf(str, STR_MAX, "iwconfig %s channel %d 2>/dev/null",
00066            devname, channel);
00067   debug(3, "%s\n", str);
00068   result += system(str);
00069   return 0;
00070   return result;
00071 }
00072 
00073 int shutCardPRISM54g(char *devname)
00074 {
00075 #define STR_MAX 80
00076   char str[STR_MAX];
00077   int result = 0;
00078 
00079   // Turn off monitor mode
00080   snprintf(str, STR_MAX, "iwconfig %s mode managed", devname);
00081   debug(3, "%s\n", str);
00082   result += system(str);
00083 
00084   snprintf(str, STR_MAX, "ifconfig %s -promisc up", devname);
00085   debug(3, "%s\n", str);
00086   result += system(str);
00087 
00088   return result;
00089 }
00090 
00091 int openCardPRISM54g(char *devname)
00092 {
00093   char str[STR_MAX];
00094   int result = 0;
00095 
00096   // Turn on monitor mode
00097   snprintf(str, STR_MAX, "iwconfig %s mode monitor", devname);
00098   debug(3, "%s\n", str);
00099   result += system(str);
00100   snprintf(str, STR_MAX, "ifconfig %s promisc up", devname);
00101   debug(3, "%s\n", str);
00102   result += system(str);
00103 
00104   return result;
00105 }
00106 
00107 
00108 // Get packet from card
00109 int getPacketPRISM54g(unsigned char *buf, int maxlen)
00110 {
00111   struct pcap_pkthdr pktHdr;
00112   u_char *ret;
00113   fd_set rs;
00114 
00115   FD_ZERO(&rs);
00116   FD_SET(0, &rs);
00117 
00118   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00119   // If no problem and packet is enought big (with data)
00120   if ((ret) && (pktHdr.len >= 1)) {
00121     if (memcpy_buff(buf, ret, pktHdr.len) == NULL)
00122       return 0;
00123     // Fill Header
00124     // TODO : find this information in any maner ?!
00125     wlan_header.version = 0;    // It's a reduced capture frame format
00126     wlan_header.length = 0;     // Not used for now
00127     wlan_header.mactime = 0;
00128     wlan_header.hosttime = 0;
00129     wlan_header.phytype = 0;    // Not used for now
00130     wlan_header.channel = 0;
00131     wlan_header.datarate = 0;   // datarate is in units of 100kbps.
00132     wlan_header.antenna = 0;    // Not used for now
00133     wlan_header.priority = 0;   // Not used for now
00134     wlan_header.ssi_type = 0;   // Not used for now
00135     wlan_header.ssi_signal = 0;
00136     wlan_header.ssi_noise = 0;
00137     wlan_header.preamble = 0;   // Not used for now
00138     wlan_header.encoding = 0;   // Not used for now
00139 
00140     return pktHdr.len;
00141   } else {
00142     return (0);                 // Noting to read
00143   }
00144 }
00145 
00146 int openPacketPRISM54g(char *devname)
00147 {
00148   int DataLink;
00149 
00150   ca.pcap = pcap_open_live(devname, 3000, 1, 0, errbuf);
00151   if (ca.pcap) {
00152     pcap_setnonblock(ca.pcap, 1, errbuf);
00153     DataLink = pcap_datalink(ca.pcap);
00154     switch (DataLink) {
00155     case DLT_PRISM_HEADER:
00156       debug(2,
00157             "pcap_datalink(ca.pcap) = %d = DLT_PRISM_HEADER\n", DataLink);
00158       ca.offset = 0x90;
00159       break;
00160     case DLT_IEEE802_11:
00161       debug(2, "pcap_datalink(ca.pcap) = %d = DLT_IEEE802_11\n", DataLink);
00162       ca.offset = 0;
00163       break;
00164     case DLT_AIRONET_HEADER:
00165       debug(2,
00166             "pcap_datalink(ca.pcap) = %d = DLT_AIRONET_HEADER:\n",
00167             DataLink);
00168       ca.offset = 0;
00169       break;
00170     default:                   //COOKED
00171       debug(2, "pcap_datalink(ca.pcap) = %d = COOKED:\n", DataLink);
00172       ca.offset = 160;
00173     }
00174     return 1;
00175   }
00176   return -1;
00177 }
00178 
00179 void closePacketPRISM54g(void)
00180 {
00181   pcap_close(ca.pcap);
00182 }

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