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

cisco.c

Go to the documentation of this file.
00001 /* Linux Prism II Stumbler - Utility Scan for 802_11 networks under Linux
00002  * 
00003  * File : cisco.c
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: cisco.c,v 1.9 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/cisco.h>
00034 #include <src/crt_io.h>
00035 
00036 static char *ID = "$Id: cisco.c,v 1.9 2005/02/23 11:36:53 poggij Exp $";
00037 
00038 // All extern value you want
00039 //extern unsigned int DebugLevel;
00040 //extern UINT8 SingleChannel;
00041 //extern UINT8 TypeOfCard;
00042 extern ConfigStruct config;
00043 extern p80211_caphdr_t wlan_header;
00044 
00045 static CaptureArg ca;
00046 static char errbuf[PCAP_ERRBUF_SIZE];
00047 static char devname1[DEVNAME_LEN];      // for cisco_cvs driver, it's eth??
00048 static char devname2[DEVNAME_LEN];      // for cisco_cvs driver, it's wifi??
00049 
00050 //-------------
00051 int selectChannelCISCO(char *devname, int channel)
00052 {
00053   if (config.SingleChannel) {
00054     // CISCO card use an hardware scan
00055     return 1;
00056   } else {
00057     // CISCO card use an hardware scan
00058     return 1;
00059   }
00060 }
00061 
00062 int shutCardCISCO(char *devname)
00063 {
00064 #define STR_MAX 80
00065   char str[STR_MAX];
00066   int result = 0;
00067 
00068   // Turn off monitor mode
00069   snprintf(str, STR_MAX,
00070            "echo \"Mode: i\" > /proc/driver/aironet/%s/Config", devname1);
00071   debug(3, str);
00072   debug(3, "\n");
00073   result += system(str);
00074 
00075   snprintf(str, STR_MAX,
00076            "echo \"XmitPower: 100\" > /proc/driver/aironet/%s/Config",
00077            devname1);
00078   debug(3, str);
00079   debug(3, "\n");
00080   result += system(str);
00081 
00082   snprintf(str, STR_MAX, "ifconfig %s -promisc down", devname);
00083   debug(3, str);
00084   debug(3, "\n");
00085   result += system(str);
00086   if (config.TypeOfCard == CISCO_CVS_CARD) {
00087     snprintf(str, STR_MAX, "ifconfig %s -promisc down", devname2);
00088     debug(3, str);
00089     debug(3, "\n");
00090     result += system(str);
00091   }
00092 
00093   return result;
00094 }
00095 
00096 int openCardCISCO(char *devname)
00097 {
00098   char str[STR_MAX];
00099   int result = 0;
00100 
00101   strncpy(devname1, config.devname, DEVNAME_LEN);
00102   if (config.TypeOfCard == CISCO_CVS_CARD) {
00103     strncpy(devname2, config.devname2, DEVNAME_LEN);
00104   }
00105   // Turn off monitor mode
00106   snprintf(str, STR_MAX,
00107            "echo \"Mode: r\" > /proc/driver/aironet/%s/Config", devname1);
00108   debug(3, str);
00109   debug(3, "\n");
00110   result += system(str);
00111 
00112   snprintf(str, STR_MAX,
00113            "echo \"Mode: y\" > /proc/driver/aironet/%s/Config", devname1);
00114   debug(3, str);
00115   debug(3, "\n");
00116   result += system(str);
00117 
00118   snprintf(str, STR_MAX,
00119            "echo \"XmitPower: 1\" > /proc/driver/aironet/%s/Config",
00120            devname1);
00121   debug(3, str);
00122   debug(3, "\n");
00123   result += system(str);
00124 
00125   snprintf(str, STR_MAX, "ifconfig %s promisc up 0", devname1);
00126   debug(3, str);
00127   debug(3, "\n");
00128   result += system(str);
00129   if (config.TypeOfCard == CISCO_CVS_CARD) {
00130     snprintf(str, STR_MAX, "ifconfig %s promisc up 0", devname2);
00131     debug(3, str);
00132     debug(3, "\n");
00133     result += system(str);
00134   }
00135 
00136   return result;
00137 }
00138 
00139 
00140 // Get packet from card
00141 int getPacketCISCO(unsigned char *buf, int maxlen)
00142 {
00143   struct pcap_pkthdr pktHdr;
00144   u_char *ret;
00145   fd_set rs;
00146 
00147   FD_ZERO(&rs);
00148   FD_SET(0, &rs);
00149 
00150   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00151   // If no problem and packet is enought big (with data)
00152   if ((ret) && (pktHdr.len >= 1)) {
00153     memcpy_buff(buf, ret, pktHdr.len);
00154     // Fill Header
00155     // TODO : find this information in any maner ?!
00156     wlan_header.version = 0;    // It's a reduced capture frame format
00157     wlan_header.length = 0;     // Not used for now
00158     wlan_header.mactime = 0;
00159     wlan_header.hosttime = 0;
00160     wlan_header.phytype = 0;    // Not used for now
00161     wlan_header.channel = 0;
00162     wlan_header.datarate = 0;   // datarate is in units of 100kbps.
00163     wlan_header.antenna = 0;    // Not used for now
00164     wlan_header.priority = 0;   // Not used for now
00165     wlan_header.ssi_type = 0;   // Not used for now
00166     wlan_header.ssi_signal = 0;
00167     wlan_header.ssi_noise = 0;
00168     wlan_header.preamble = 0;   // Not used for now
00169     wlan_header.encoding = 0;   // Not used for now
00170 
00171     return pktHdr.len;
00172   } else {
00173     return (0);                 /* Noting to read */
00174   }
00175 }
00176 
00177 int openPacketCISCO(char *devname)
00178 {
00179   int DataLink;
00180 
00181   ca.pcap = pcap_open_live(devname2, 3000, 1, 0, errbuf);
00182   if (ca.pcap) {
00183     pcap_setnonblock(ca.pcap, 1, errbuf);
00184     DataLink = pcap_datalink(ca.pcap);
00185     switch (DataLink) {
00186     case DLT_PRISM_HEADER:
00187       fatal("pcap_datalink(ca.pcap) = %d = DLT_PRISM_HEADER\n", DataLink);
00188       ca.offset = 144;
00189       break;
00190     case DLT_IEEE802_11:
00191       debug(2, "pcap_datalink(ca.pcap) = %d = DLT_IEEE802_11\n", DataLink);
00192       ca.offset = 0;
00193       break;
00194     case DLT_AIRONET_HEADER:
00195       debug(2,
00196             "pcap_datalink(ca.pcap) = %d = DLT_AIRONET_HEADER:\n",
00197             DataLink);
00198       ca.offset = 0;
00199       break;
00200     default:                   //COOKED
00201       debug(2, "pcap_datalink(ca.pcap) = %d = COOKED:\n", DataLink);
00202       ca.offset = 160;
00203     }
00204     return 1;
00205   }
00206   return -1;
00207 }
00208 
00209 void closePacketCISCO(void)
00210 {
00211   pcap_close(ca.pcap);
00212 }

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