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 174 2007-07-25 13:20:29Z poggij $
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/functions.h>
00036 #include <src/crt_io.h>
00037 
00038 static char *ID = "$Id: prism54g.c 174 2007-07-25 13:20:29Z poggij $";
00039 
00040 // All extern value you want
00041 //extern unsigned int DebugLevel;
00042 //extern UINT8 SingleChannel;
00043 //extern UINT8 TypeOfCard;
00044 extern ConfigStruct config;
00045 
00046 static CaptureArg ca;
00047 static char errbuf[PCAP_ERRBUF_SIZE];
00048 
00049 //-------------
00050 int selectChannelPRISM54g(char *devname, int channel)
00051 {
00052   int result = NO_ERROR;
00053 
00054   result = IwconfigSetChannel(devname, channel);
00055   return NO_ERROR;
00056   //return result;
00057 }
00058 
00059 int shutCardPRISM54g(char *devname)
00060 {
00061   int result = NO_ERROR;
00062 
00063   // Turn off monitor mode
00064   result = IwconfigSetMode(devname, IW_MODE_INFRA);
00065   warning_if_error(result);
00066   result = IfconfigSetFlags(devname, 0);
00067   warning_if_error(result);
00068   return result;
00069 }
00070 
00071 int openCardPRISM54g(char *devname)
00072 {
00073   int result = NO_ERROR;
00074 
00075   // Turn on monitor mode
00076   result = IwconfigSetMode(devname, IW_MODE_MONITOR);
00077   warning_if_error(result);
00078   result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00079   warning_if_error(result);
00080   return result;
00081 }
00082 
00083 
00084 // Get packet from card
00085 int getPacketPRISM54g(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00086 {
00087   struct pcap_pkthdr pktHdr;
00088   u_char *ret;
00089   fd_set rs;
00090 
00091   FD_ZERO(&rs);
00092   FD_SET(0, &rs);
00093 
00094   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00095   // If no problem and packet is enought big (with data)
00096   if ((ret) && (pktHdr.len >= 1)) {
00097     if (memcpy_buff(buf, ret, pktHdr.len) == NULL)
00098       return 0;
00099     // Fill Header
00100     // TODO : find this information in any maner ?!
00101     wlan_header->version = 0;    // It's a reduced capture frame format
00102     wlan_header->length = 0;     // Not used for now
00103     wlan_header->mactime = 0;
00104     wlan_header->hosttime = 0;
00105     wlan_header->phytype = 0;    // Not used for now
00106     wlan_header->channel = 0;
00107     wlan_header->datarate = 0;   // datarate is in units of 100kbps.
00108     wlan_header->antenna = 0;    // Not used for now
00109     wlan_header->priority = 0;   // Not used for now
00110     wlan_header->ssi_type = 0;   // Not used for now
00111     wlan_header->ssi_signal = 0;
00112     wlan_header->ssi_noise = 0;
00113     wlan_header->preamble = 0;   // Not used for now
00114     wlan_header->encoding = 0;   // Not used for now
00115 
00116     return pktHdr.len;
00117   } else {
00118     return (0);                 // Noting to read
00119   }
00120 }
00121 
00122 int openPacketPRISM54g(char *devname)
00123 {
00124   ca.pcap = pcap_open_live(devname, 3000, 1, 0, errbuf);
00125   if (ca.pcap) {
00126     pcap_setnonblock(ca.pcap, 1, errbuf);
00127     ca.DataLink = pcap_datalink(ca.pcap);
00128     ca.offset = CalculateOffset(ca.DataLink);
00129     return NO_ERROR;
00130   }
00131   return ERROR_CANT_OPEN_PCAP;
00132 }
00133 
00134 void closePacketPRISM54g(void)
00135 {
00136   pcap_close(ca.pcap);
00137 }

Generated on Fri Jul 25 17:10:36 2008 for WifiScanner by  doxygen 1.5.5