airjack.c File Reference

#include <include.h>
#include <src/airjack.h>
#include <src/wlan-ng.h>
#include <src/functions.h>
#include <src/crt_io.h>
#include <net/if.h>
#include <sys/socket.h>
#include <features.h>
#include <netinet/in.h>
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>

Include dependency graph for airjack.c:

Go to the source code of this file.

Defines

#define STR_MAX   80

Functions

int selectChannelAIRJACK (char *devname, int channel)
int shutCardAIRJACK (char *devname)
int openCardAIRJACK (char *devname)
int getPacketAIRJACK (p80211_caphdr_t *wlan_header, UINT8 *buf, int maxlen)
int openPacketAIRJACK (char *devname)
void closePacketAIRJACK (void)
void sendDeauth (UINT8 dest[WLAN_ADDR_LEN], UINT8 bssid[WLAN_ADDR_LEN], UINT8 channel)

Variables

static char * ID = "$Id: airjack.c 174 2007-07-25 13:20:29Z poggij $"
ConfigStruct config
UINT16 NumberOfDetectedClient
ClientInfo_tClientInfo
ScanResult_t Res
static CaptureArg ca
static char errbuf [PCAP_ERRBUF_SIZE]
static int sockfd
static struct ifreq req
static struct aj_config aj_conf
static const UINT8 BroadcastMAC [WLAN_ADDR_LEN]


Define Documentation

#define STR_MAX   80


Function Documentation

int selectChannelAIRJACK ( char *  devname,
int  channel 
)

Definition at line 71 of file airjack.c.

References aj_conf, aj_config::channel, debug, aj_config::monitor, req, SIOCAJGMODE, SIOCAJSMODE, sockfd, and STR_MAX.

Referenced by selectChannel(), and sendDeauth().

00072 {
00073 #define STR_MAX 80
00074   int result = 0;
00075 #if 0
00076   char str[STR_MAX];
00077   snprintf(str, STR_MAX, "set_channel -c %d -i %s 2>/dev/null",
00078            channel, devname);
00079   debug(3, "%s\n", str);
00080   result += system(str);
00081 #else
00082   req.ifr_data = (char *) &aj_conf;
00083 
00084   /* populate the structure */
00085   if (ioctl(sockfd, SIOCAJGMODE, &req) < 0) {
00086     return (-4);
00087   }
00088 
00089   aj_conf.channel = channel;
00090   aj_conf.monitor = 1;
00091 
00092   if (ioctl(sockfd, SIOCAJSMODE, &req) < 0) {
00093     return (-4);
00094   }
00095 #endif
00096   return result;
00097 }

int shutCardAIRJACK ( char *  devname  ) 

Definition at line 99 of file airjack.c.

References IfconfigSetFlags().

Referenced by shutCard().

00100 {
00101   return IfconfigSetFlags(devname, IFF_UP);
00102 }

int openCardAIRJACK ( char *  devname  ) 

Definition at line 104 of file airjack.c.

References aj_conf, IfconfigSetFlags(), req, and sockfd.

Referenced by openCard().

00105 {
00106   int result = 0;
00107   struct sockaddr_ll addr;
00108 
00109   // Turn on monitor mode
00110   result += IfconfigSetFlags(devname, IFF_UP + IFF_PROMISC);
00111 
00112   /* open the link layer socket */
00113   if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
00114     return (-1);
00115   }
00116 
00117   /* get the interface index */
00118   memset(&req, 0, sizeof(struct ifreq));
00119   memset(&aj_conf, 0, sizeof(struct aj_config));
00120   strncpy(req.ifr_name, devname, IFNAMSIZ);
00121 
00122   if (ioctl(sockfd, SIOCGIFINDEX, &req) < 0) {
00123     return (-2);
00124   }
00125 
00126   /* bind the socket to the interface */
00127   memset(&addr, 0, sizeof(struct sockaddr_ll));
00128   addr.sll_ifindex = req.ifr_ifindex;
00129   addr.sll_protocol = htons(ETH_P_ALL);
00130   addr.sll_family = AF_PACKET;
00131   if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_ll)) <
00132       0) {
00133     return (-3);
00134   }
00135 
00136 
00137   return result;
00138 }

int getPacketAIRJACK ( p80211_caphdr_t wlan_header,
UINT8 buf,
int  maxlen 
)

Definition at line 142 of file airjack.c.

References p80211_caphdr::antenna, p80211_caphdr::channel, p80211_caphdr::datarate, p80211_caphdr::encoding, p80211_caphdr::hosttime, p80211_caphdr::length, p80211_caphdr::mactime, memcpy_buff(), CaptureArg_t::pcap, p80211_caphdr::phytype, p80211_caphdr::preamble, p80211_caphdr::priority, p80211_caphdr::ssi_noise, p80211_caphdr::ssi_signal, p80211_caphdr::ssi_type, and p80211_caphdr::version.

Referenced by getPacket().

00143 {
00144   struct pcap_pkthdr pktHdr;
00145   u_char *ret;
00146   fd_set rs;
00147 
00148   FD_ZERO(&rs);
00149   FD_SET(0, &rs);
00150 
00151   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00152   // If no problem and packet is enought big (with data)
00153   if ((ret) && (pktHdr.len >= 1)) {
00154     if (memcpy_buff(buf, ret, pktHdr.len) == NULL)
00155       return 0;
00156     // Fill Header
00157     // TODO : find this information in any maner ?!
00158     wlan_header->version = 0;    // It's a reduced capture frame format
00159     wlan_header->length = 0;     // Not used for now
00160     wlan_header->mactime = 0;
00161     wlan_header->hosttime = 0;
00162     wlan_header->phytype = 0;    // Not used for now
00163     wlan_header->channel = 0;
00164     wlan_header->datarate = 0;   // datarate is in units of 100kbps.
00165     wlan_header->antenna = 0;    // Not used for now
00166     wlan_header->priority = 0;   // Not used for now
00167     wlan_header->ssi_type = 0;   // Not used for now
00168     wlan_header->ssi_signal = 0;
00169     wlan_header->ssi_noise = 0;
00170     wlan_header->preamble = 0;   // Not used for now
00171     wlan_header->encoding = 0;   // Not used for now
00172 
00173     return pktHdr.len;
00174   } else {
00175     return (0);                 // Noting to read
00176   }
00177 }

int openPacketAIRJACK ( char *  devname  ) 

Definition at line 179 of file airjack.c.

References debug, DLT_PRISM_HEADER, errbuf, CaptureArg_t::offset, and CaptureArg_t::pcap.

Referenced by openPacket().

00180 {
00181   int DataLink;
00182 
00183   ca.pcap = pcap_open_live(devname, 3000, 1, 0, errbuf);
00184   if (ca.pcap) {
00185     pcap_setnonblock(ca.pcap, 1, errbuf);
00186     DataLink = pcap_datalink(ca.pcap);
00187     switch (DataLink) {
00188     case DLT_PRISM_HEADER:
00189       debug(2,
00190             "pcap_datalink(ca.pcap) = %d = DLT_PRISM_HEADER\n", DataLink);
00191       ca.offset = 0x90;
00192       break;
00193     case DLT_IEEE802_11:
00194       debug(2, "pcap_datalink(ca.pcap) = %d = DLT_IEEE802_11\n", DataLink);
00195       ca.offset = 0;
00196       break;
00197     case DLT_AIRONET_HEADER:
00198       debug(2,
00199             "pcap_datalink(ca.pcap) = %d = DLT_AIRONET_HEADER:\n",
00200             DataLink);
00201       ca.offset = 0;
00202       break;
00203     default:                   //COOKED
00204       debug(2, "pcap_datalink(ca.pcap) = %d = COOKED:\n", DataLink);
00205       ca.offset = 160;
00206     }
00207     return 1;
00208   }
00209   return -1;
00210 }

void closePacketAIRJACK ( void   ) 

Definition at line 212 of file airjack.c.

References CaptureArg_t::pcap.

Referenced by closePacket().

00213 {
00214   pcap_close(ca.pcap);
00215 }

void sendDeauth ( UINT8  dest[WLAN_ADDR_LEN],
UINT8  bssid[WLAN_ADDR_LEN],
UINT8  channel 
)

Definition at line 217 of file airjack.c.

References debug, ConfigStruct::devname, FC_TYPE_MGT, MGT_DEAUTH, ScanResult_t::SChannel, selectChannelAIRJACK(), sockfd, and warning().

Referenced by LogPutIsAP(), and Send_To_All_BSSID_A_Deauth().

00219 {
00220   struct {
00221     struct a3_80211 hdr;
00222     unsigned short int reason;
00223   } __attribute__ ((packed)) frame;
00224   UINT8 OldChannel = 0;
00225 
00226   /* setup the frame */
00227   memset(&frame, 0, sizeof(frame));
00228   memcpy(frame.hdr.mh_mac1, dest, sizeof(frame.hdr.mh_mac1));
00229   memcpy(frame.hdr.mh_mac2, bssid, sizeof(frame.hdr.mh_mac2));
00230   memcpy(frame.hdr.mh_mac3, bssid, sizeof(frame.hdr.mh_mac3));
00231 
00232   frame.hdr.mh_type = FC_TYPE_MGT;
00233   frame.hdr.mh_subtype = MGT_DEAUTH;
00234   frame.hdr.mh_from_ds = 1;
00235   frame.reason = 2;             /* previous authentication is no longer valid */
00236 
00237   if (channel != 0) {           // Backup channel and change to the channel of the AP
00238     OldChannel = Res.SChannel;
00239     selectChannelAIRJACK(config.devname, channel);
00240   }
00241 
00242   if (write(sockfd, &frame, sizeof(frame)) < 0) {
00243     warning("AIRJACK error : write\n");
00244   }
00245 
00246   debug(2, "Send De-auth -- BSSID: %02X:%02X:%02X:%02X:%02X:%02X --"
00247         " DEST: %02X:%02X:%02X:%02X:%02X:%02X -- Channel: %d\n",
00248         bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
00249         dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], channel);
00250 
00251   if (channel != 0) {           // restore channel
00252     Res.SChannel = OldChannel;
00253     selectChannelAIRJACK(config.devname, OldChannel);
00254   }
00255 }


Variable Documentation

char* ID = "$Id: airjack.c 174 2007-07-25 13:20:29Z poggij $" [static]

Definition at line 49 of file airjack.c.

Definition at line 58 of file scanner.c.

Definition at line 48 of file analyse.c.

CaptureArg ca [static]

Definition at line 61 of file airjack.c.

char errbuf[PCAP_ERRBUF_SIZE] [static]

int sockfd [static]

Definition at line 63 of file airjack.c.

Referenced by openCardAIRJACK(), selectChannelAIRJACK(), and sendDeauth().

struct ifreq req [static]

Definition at line 64 of file airjack.c.

Referenced by do_ioctl(), openCardAIRJACK(), and selectChannelAIRJACK().

struct aj_config aj_conf [static]

Definition at line 65 of file airjack.c.

Referenced by openCardAIRJACK(), and selectChannelAIRJACK().

const UINT8 BroadcastMAC[WLAN_ADDR_LEN] [static]

Initial value:

    { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }

Definition at line 67 of file airjack.c.

Referenced by LogPutIsAP(), and Send_To_All_BSSID_A_Deauth().


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