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 #include <include.h>
00032 #include <src/hostap.h>
00033 #include <src/crt_io.h>
00034 #include <src/functions.h>
00035
00036 static char *ID = "$Id: hostap.c 174 2007-07-25 13:20:29Z poggij $";
00037
00038
00039 extern UINT8 SingleChannel;
00040 extern UINT8 TypeOfCard;
00041
00042 static CaptureArg ca;
00043 static char errbuf[PCAP_ERRBUF_SIZE];
00044 static UINT8 wlan_payload[MAX_BUFFER_SIZE];
00045
00046
00047 int selectChannelHOSTAP(char *devname, int channel)
00048 {
00049 int result = NO_ERROR;
00050
00051 result = IwconfigSetChannel(devname, channel);
00052
00053
00054
00055
00056 return NO_ERROR;
00057 }
00058
00059 int shutCardHOSTAP(char *devname)
00060 {
00061 int result = NO_ERROR;
00062
00063
00064 result = IwconfigSetMode(devname, IW_MODE_INFRA);
00065 warning_if_error(result);
00066 result = IwconfigSetChannel(devname, 11);
00067 warning_if_error(result);
00068 result = IfconfigSetFlags(devname, IFF_UP);
00069 warning_if_error(result);
00070
00071 return result;
00072 }
00073
00074 int openCardHOSTAP(char *devname)
00075 {
00076 char str[80];
00077 int result = NO_ERROR;
00078
00079
00080 sprintf(str, "prism2_param %s monitor_type 1", devname);
00081 debug(3, "%s\n", str);
00082 result += system(str);
00083
00084 result = IwconfigSetMode(devname, IW_MODE_MONITOR);
00085 warning_if_error(result);
00086 result = IwconfigSetChannel(devname, 1);
00087 warning_if_error(result);
00088 result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00089 warning_if_error(result);
00090
00091 return result;
00092 }
00093
00094
00095
00096
00097 int getPacketHOSTAP(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00098 {
00099 struct pcap_pkthdr pktHdr;
00100 u_char *RadioPacket;
00101 fd_set rs;
00102
00103 FD_ZERO(&rs);
00104 FD_SET(0, &rs);
00105
00106 RadioPacket = (u_char *) pcap_next(ca.pcap, &pktHdr);
00107
00108 if (RadioPacket != NULL) {
00109
00110 if (pktHdr.len >= sizeof(p80211msg_lnxind_wlansniffrm_t)) {
00111 if (pktHdr.len > MAX_BUFFER_SIZE) {
00112 debug(1, "ERROR : Packet is TOOO BIG size=%d\n", pktHdr.len);
00113
00114
00115 return 0;
00116 } else {
00117 FillRadioData(wlan_header, ca.DataLink, RadioPacket, pktHdr.len);
00118 memcpy_buff(buf, (RadioPacket + ca.offset),
00119 MIN_OF((pktHdr.len - ca.offset), maxlen));
00120 return MAX_OF(0,
00121 (pktHdr.len -
00122 sizeof(p80211msg_lnxind_wlansniffrm_t)));
00123 }
00124 }
00125 }
00126 return (0);
00127 }
00128
00129 int openPacketHOSTAP(char *devname)
00130 {
00131 ca.pcap = pcap_open_live(devname, 3000, TRUE, 1000, errbuf);
00132 if (ca.pcap) {
00133 pcap_setnonblock(ca.pcap, 1, errbuf);
00134 ca.DataLink = pcap_datalink(ca.pcap);
00135 ca.offset = CalculateOffset(ca.DataLink);
00136 return NO_ERROR;
00137 } else {
00138 warning("ERROR when pcap_open_live : %s\n", errbuf);
00139 }
00140 return ERROR_CANT_OPEN_PCAP;
00141 }
00142
00143 void closePacketHOSTAP(void)
00144 {
00145 pcap_close(ca.pcap);
00146 }