atheros.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: atheros.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/atheros.h>
00034 #include <src/wlan-ng.h>
00035 #include <src/crt_io.h>
00036 #include <src/functions.h>
00037 
00038 static char *ID = "$Id: atheros.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 selectChannelATHEROS(char *devname, int channel)
00051 {
00052   int result = NO_ERROR;
00053 
00054   result = IwconfigSetChannel(devname, channel);
00055   return NO_ERROR;  // disintegrate error ...
00056   // return result; // XXX
00057 }
00058 
00059 int shutCardATHEROS(char *devname)
00060 {
00061 #define STR_MAX 80
00062   int result = NO_ERROR;
00063 
00064   // Turn off monitor mode, and promisc mode
00065   result = IwconfigSetMode(devname, IW_MODE_INFRA);
00066   warning_if_error(result);
00067   result = IfconfigSetFlags(devname, IFF_UP);
00068   warning_if_error(result);
00069 
00070   return result;
00071 }
00072 
00073 int openCardATHEROS(char *devname)
00074 {
00075   int result = NO_ERROR;
00076 
00077   // Turn on monitor mode and promisc mode
00078   result = IwconfigSetMode(devname, IW_MODE_MONITOR);
00079   warning_if_error(result);
00080   result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00081   warning_if_error(result);
00082 
00083   return result;
00084 }
00085 
00086 
00087 // Get packet from card
00088 int getPacketATHEROS(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00089 {
00090   struct pcap_pkthdr pktHdr;
00091   u_char *ret;
00092   fd_set rs;
00093   p80211msg_lnxind_wlansniffrm_t *Sniff_Frame;
00094   static UINT8 wlan_payload[MAX_BUFFER_SIZE];
00095 
00096   FD_ZERO(&rs);
00097   FD_SET(0, &rs);
00098 
00099   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00100 
00101   // If no problem and packet is enought big (with data)
00102   if ((ret)
00103       && (pktHdr.len >= sizeof(p80211msg_lnxind_wlansniffrm_t))) {
00104     if (memcpy_buff(buf, ret, pktHdr.len) == NULL)
00105       return 0;
00106     Sniff_Frame = (p80211msg_lnxind_wlansniffrm_t *) buf;
00107     // Fill Header
00108     wlan_header->version = 0;    // It's a reduced capture frame format
00109     wlan_header->length = 0;     // Not used for now
00110     wlan_header->mactime = Sniff_Frame->mactime.data;
00111     wlan_header->hosttime = Sniff_Frame->hosttime.data;
00112     wlan_header->phytype = phytype_dsss_dot11_b; // Not used for now
00113     wlan_header->channel = Sniff_Frame->channel.data;
00114     wlan_header->datarate = Sniff_Frame->rate.data * 5;  // datarate is in units of 100kbps.
00115     wlan_header->antenna = 0;    // Not used for now
00116     wlan_header->priority = 0;   // Not used for now
00117     wlan_header->ssi_type = 0;   // Not used for now
00118     wlan_header->ssi_signal = Sniff_Frame->signal.data;
00119     wlan_header->ssi_noise = Sniff_Frame->noise.data;
00120     wlan_header->preamble = 0;   // Not used for now
00121     wlan_header->encoding = 0;   // Not used for now
00122     // Fill data frame
00123     if (memcpy_buff(wlan_payload,
00124                     &buf[sizeof(p80211msg_lnxind_wlansniffrm_t)],
00125                     pktHdr.len - sizeof(p80211msg_lnxind_wlansniffrm_t)) ==
00126         NULL)
00127       return 0;
00128     if (memcpy_buff(buf, wlan_payload,
00129                     maxlen - sizeof(p80211msg_lnxind_wlansniffrm_t)) ==
00130         NULL)
00131       return 0;
00132 
00133     if (pktHdr.len <= sizeof(p80211msg_lnxind_wlansniffrm_t))
00134       // Don't return negative value
00135       return 0;
00136     else
00137       return (pktHdr.len - sizeof(p80211msg_lnxind_wlansniffrm_t));
00138   } else {
00139     return (0);                 // Noting to read
00140   }
00141 }
00142 
00143 int openPacketATHEROS(char *devname)
00144 {
00145   ca.pcap = pcap_open_live(devname, 3000, 1, 0, errbuf);
00146   if (ca.pcap) {
00147     pcap_setnonblock(ca.pcap, 1, errbuf);
00148     ca.DataLink = pcap_datalink(ca.pcap);
00149     ca.offset = CalculateOffset(ca.DataLink);
00150     return NO_ERROR;
00151   }
00152   return ERROR_CANT_OPEN_PCAP;
00153 }
00154 
00155 void closePacketATHEROS(void)
00156 {
00157   pcap_close(ca.pcap);
00158 }

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