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 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/cisco.h>
00034 #include <src/crt_io.h>
00035 #include <src/functions.h>
00036 
00037 static char *ID = "$Id: cisco.c 174 2007-07-25 13:20:29Z poggij $";
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 
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   return 0;
00054 }
00055 
00056 int shutCardCISCO(char *devname)
00057 {
00058 #define STR_MAX 80
00059   int result = 0;
00060   FILE *cisco_config;
00061   char cisco_path[128];
00062 
00063   // Clear the SSID
00064   result = IwconfigClearSSID(devname);
00065 
00066   // Define the /proc file path
00067   snprintf(cisco_path, 128, "/proc/driver/aironet/%s/Config", devname1);
00068 
00069   if ((cisco_config = fopen(cisco_path, "w")) == NULL) {
00070     warning("Unable to open cisco control file '%s' %d:%s",cisco_path, errno, strerror(errno));
00071     return CISCO_PROC_FILE_ERROR;
00072   }
00073   fprintf(cisco_config, "Mode: i\n");
00074   fprintf(cisco_config, "XmitPower: 100\n");
00075   fclose(cisco_config);
00076 
00077   result = IfconfigSetFlags(devname, 0);
00078   warning_if_error(result);
00079 
00080   if (config.TypeOfCard == CISCO_CVS_CARD) {
00081     result = IfconfigSetFlags(devname2, 0);
00082     warning_if_error(result);
00083   }
00084 
00085   return result;
00086 }
00087 
00088 int openCardCISCO(char *devname)
00089 {
00090   int result = 0;
00091   FILE *cisco_config;
00092   char cisco_path[128];
00093 
00094   // Clear the SSID
00095   result = IwconfigClearSSID(devname);
00096 
00097   // TODO try the iwpriv before write to /proc file
00098 
00099   // Define the /proc file path
00100   snprintf(cisco_path, 128, "/proc/driver/aironet/%s/Config", devname);
00101 
00102   if ((cisco_config = fopen(cisco_path, "w")) == NULL) {
00103     warning("Unable to open cisco control file '%s' %d:%s",cisco_path, errno, strerror(errno));
00104     return CISCO_PROC_FILE_ERROR;
00105   }
00106   fprintf(cisco_config, "Mode: r\n");
00107   fprintf(cisco_config, "Mode: y\n");
00108   fprintf(cisco_config, "XmitPower: 1\n");
00109   fclose(cisco_config);
00110 
00111   // TODO : Need to put the addr to 0
00112   result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00113     warning_if_error(result);
00114 
00115   if (config.TypeOfCard == CISCO_CVS_CARD) {
00116     // TODO : Need to put the addr to 0
00117     result = IfconfigSetFlags(devname2, IFF_UP + IFF_PROMISC);
00118     warning_if_error(result);
00119   }
00120 
00121   return result;
00122 }
00123 
00124 
00125 // Get packet from card
00126 int getPacketCISCO(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00127 {
00128   struct pcap_pkthdr pktHdr;
00129   u_char *ret;
00130   fd_set rs;
00131 
00132   FD_ZERO(&rs);
00133   FD_SET(0, &rs);
00134 
00135   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00136   // If no problem and packet is enought big (with data)
00137   if ((ret) && (pktHdr.len >= 1)) {
00138     memcpy_buff(buf, ret, pktHdr.len);
00139     // Fill Header
00140     // TODO : find this information in any maner ?!
00141     wlan_header->version = 0;    // It's a reduced capture frame format
00142     wlan_header->length = 0;     // Not used for now
00143     wlan_header->mactime = 0;
00144     wlan_header->hosttime = 0;
00145     wlan_header->phytype = 0;    // Not used for now
00146     wlan_header->channel = 0;
00147     wlan_header->datarate = 0;   // datarate is in units of 100kbps.
00148     wlan_header->antenna = 0;    // Not used for now
00149     wlan_header->priority = 0;   // Not used for now
00150     wlan_header->ssi_type = 0;   // Not used for now
00151     wlan_header->ssi_signal = 0;
00152     wlan_header->ssi_noise = 0;
00153     wlan_header->preamble = 0;   // Not used for now
00154     wlan_header->encoding = 0;   // Not used for now
00155 
00156     return pktHdr.len;
00157   } else {
00158     return (0);                 /* Noting to read */
00159   }
00160 }
00161 
00162 int openPacketCISCO(char *devname)
00163 {
00164   int DataLink;
00165 
00166   ca.pcap = pcap_open_live(devname2, 3000, 1, 0, errbuf);
00167   if (ca.pcap) {
00168     pcap_setnonblock(ca.pcap, 1, errbuf);
00169     DataLink = pcap_datalink(ca.pcap);
00170     switch (DataLink) {
00171     case DLT_PRISM_HEADER:
00172       fatal("pcap_datalink(ca.pcap) = %d = DLT_PRISM_HEADER\n", DataLink);
00173       ca.offset = 144;
00174       break;
00175     case DLT_IEEE802_11:
00176       debug(2, "pcap_datalink(ca.pcap) = %d = DLT_IEEE802_11\n", DataLink);
00177       ca.offset = 0;
00178       break;
00179     case DLT_AIRONET_HEADER:
00180       debug(2,
00181             "pcap_datalink(ca.pcap) = %d = DLT_AIRONET_HEADER:\n",
00182             DataLink);
00183       ca.offset = 0;
00184       break;
00185     default:                   //COOKED
00186       debug(2, "pcap_datalink(ca.pcap) = %d = COOKED:\n", DataLink);
00187       ca.offset = 160;
00188     }
00189     return 1;
00190   }
00191   return -1;
00192 }
00193 
00194 void closePacketCISCO(void)
00195 {
00196   pcap_close(ca.pcap);
00197 }

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