00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00040
00041
00042
00043 extern ConfigStruct config;
00044
00045 static CaptureArg ca;
00046 static char errbuf[PCAP_ERRBUF_SIZE];
00047 static char devname1[DEVNAME_LEN];
00048 static char devname2[DEVNAME_LEN];
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
00064 result = IwconfigClearSSID(devname);
00065
00066
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
00095 result = IwconfigClearSSID(devname);
00096
00097
00098
00099
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
00112 result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00113 warning_if_error(result);
00114
00115 if (config.TypeOfCard == CISCO_CVS_CARD) {
00116
00117 result = IfconfigSetFlags(devname2, IFF_UP + IFF_PROMISC);
00118 warning_if_error(result);
00119 }
00120
00121 return result;
00122 }
00123
00124
00125
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
00137 if ((ret) && (pktHdr.len >= 1)) {
00138 memcpy_buff(buf, ret, pktHdr.len);
00139
00140
00141 wlan_header->version = 0;
00142 wlan_header->length = 0;
00143 wlan_header->mactime = 0;
00144 wlan_header->hosttime = 0;
00145 wlan_header->phytype = 0;
00146 wlan_header->channel = 0;
00147 wlan_header->datarate = 0;
00148 wlan_header->antenna = 0;
00149 wlan_header->priority = 0;
00150 wlan_header->ssi_type = 0;
00151 wlan_header->ssi_signal = 0;
00152 wlan_header->ssi_noise = 0;
00153 wlan_header->preamble = 0;
00154 wlan_header->encoding = 0;
00155
00156 return pktHdr.len;
00157 } else {
00158 return (0);
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:
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 }