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/hermes.h>
00033 #include <src/crt_io.h>
00034 #include <src/functions.h>
00035
00036 static char *ID = "$Id: hermes.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 selectChannelHERMES(char *devname, int channel)
00048 {
00049 char str[80];
00050 int result = NO_ERROR;
00051
00052 #if 0
00053 sprintf(str, "iwpriv %s monitor 1 %d 2>/dev/null 1>/dev/null", devname,
00054 channel);
00055
00056 result += system(str);
00057 #endif
00058 Iwconfig_Set_IntPriv(devname, "monitor", 1, channel);
00059
00060
00061
00062
00063 return NO_ERROR;
00064 }
00065
00066 int shutCardHERMES(char *devname)
00067 {
00068 char str[80];
00069 int result = NO_ERROR;
00070
00071
00072 result = IwconfigSetMode(devname, IW_MODE_INFRA);
00073 warning_if_error(result);
00074
00075 result = IfconfigSetFlags(devname, 0);
00076 warning_if_error(result);
00077
00078 sprintf(str, "iwpriv %s monitor 0 1", devname);
00079 debug(3, "%s\n", str);
00080 result += system(str);
00081
00082 return result;
00083 }
00084
00085 int openCardHERMES(char *devname)
00086 {
00087 char str[80];
00088 int result = NO_ERROR;
00089
00090
00091 result = IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00092 warning_if_error(result);
00093
00094 IwconfigClearSSID(devname);
00095
00096 sprintf(str, "iwpriv %s monitor 1 1", devname);
00097 debug(3, "%s\n", str);
00098 result += system(str);
00099
00100 return result;
00101 }
00102
00103
00104
00105 int getPacketHERMES(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00106 {
00107 struct pcap_pkthdr pktHdr;
00108 u_char *ret;
00109 fd_set rs;
00110 p80211msg_lnxind_wlansniffrm_t *Sniff_Frame;
00111
00112 FD_ZERO(&rs);
00113 FD_SET(0, &rs);
00114
00115 ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00116
00117 if ((ret)
00118 && (pktHdr.len >= sizeof(p80211msg_lnxind_wlansniffrm_t))) {
00119 if (memcpy_buff(buf, ret, pktHdr.len) == NULL)
00120 return 0;
00121 Sniff_Frame = (p80211msg_lnxind_wlansniffrm_t *) buf;
00122
00123 wlan_header->version = 0;
00124 wlan_header->length = 0;
00125 wlan_header->mactime = Sniff_Frame->mactime.data;
00126 wlan_header->hosttime = Sniff_Frame->hosttime.data;
00127 wlan_header->phytype = phytype_dsss_dot11_b;
00128 wlan_header->channel = Sniff_Frame->channel.data;
00129 wlan_header->datarate = Sniff_Frame->rate.data * 5;
00130 wlan_header->antenna = 0;
00131 wlan_header->priority = 0;
00132 wlan_header->ssi_type = 0;
00133 wlan_header->ssi_signal = Sniff_Frame->signal.data;
00134 wlan_header->ssi_noise = Sniff_Frame->noise.data;
00135 wlan_header->preamble = 0;
00136 wlan_header->encoding = 0;
00137
00138 if (memcpy_buff(wlan_payload,
00139 &buf[sizeof(p80211msg_lnxind_wlansniffrm_t)],
00140 pktHdr.len - sizeof(p80211msg_lnxind_wlansniffrm_t)) ==
00141 NULL)
00142 return 0;
00143 if (memcpy_buff(buf, wlan_payload,
00144 maxlen - sizeof(p80211msg_lnxind_wlansniffrm_t)) ==
00145 NULL)
00146 return 0;
00147
00148 if (pktHdr.len <= sizeof(p80211msg_lnxind_wlansniffrm_t))
00149
00150 return 0;
00151 else
00152 return (pktHdr.len - sizeof(p80211msg_lnxind_wlansniffrm_t));
00153 } else {
00154 return (0);
00155 }
00156 }
00157
00158 int openPacketHERMES(char *devname)
00159 {
00160 ca.pcap = pcap_open_live(devname, 3000, 1, 0, errbuf);
00161 if (ca.pcap) {
00162 pcap_setnonblock(ca.pcap, 1, errbuf);
00163 ca.DataLink = pcap_datalink(ca.pcap);
00164 ca.offset = CalculateOffset(ca.DataLink);
00165 return NO_ERROR;
00166 }
00167 return ERROR_CANT_OPEN_PCAP;
00168 }
00169
00170 void closePacketHERMES(void)
00171 {
00172 pcap_close(ca.pcap);
00173 }