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/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
00041
00042
00043
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;
00056
00057 }
00058
00059 int shutCardATHEROS(char *devname)
00060 {
00061 #define STR_MAX 80
00062 int result = NO_ERROR;
00063
00064
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
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
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
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
00108 wlan_header->version = 0;
00109 wlan_header->length = 0;
00110 wlan_header->mactime = Sniff_Frame->mactime.data;
00111 wlan_header->hosttime = Sniff_Frame->hosttime.data;
00112 wlan_header->phytype = phytype_dsss_dot11_b;
00113 wlan_header->channel = Sniff_Frame->channel.data;
00114 wlan_header->datarate = Sniff_Frame->rate.data * 5;
00115 wlan_header->antenna = 0;
00116 wlan_header->priority = 0;
00117 wlan_header->ssi_type = 0;
00118 wlan_header->ssi_signal = Sniff_Frame->signal.data;
00119 wlan_header->ssi_noise = Sniff_Frame->noise.data;
00120 wlan_header->preamble = 0;
00121 wlan_header->encoding = 0;
00122
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
00135 return 0;
00136 else
00137 return (pktHdr.len - sizeof(p80211msg_lnxind_wlansniffrm_t));
00138 } else {
00139 return (0);
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 }