summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc32
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh3
2 files changed, 4 insertions, 31 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index a9b3276..a1c3945 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -1,103 +1,77 @@
1/* 1/*
2 * Set card modes for sniffing 2 * Set card modes for sniffing
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "cardmode.hh" 7#include "cardmode.hh"
8 8
9/* main card into monitor function */ 9/* main card into monitor function */
10int card_into_monitormode (void *orighandle, char *device, int cardtype) 10int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
11{ 11{
12 int datalink; /* used for getting the pcap datalink type */
13 char CiscoRFMON[35] = "/proc/driver/aironet/"; 12 char CiscoRFMON[35] = "/proc/driver/aironet/";
14 FILE *CISCO_CONFIG_FILE; 13 FILE *CISCO_CONFIG_FILE;
15 char errbuf[PCAP_ERRBUF_SIZE]; 14 pcap_t *handle = (pcap_t*)orighandle;
16 pcap_t *handle;
17
18 handle = (pcap_t *)orighandle;
19 15
20 /* Checks if we have a device to sniff on */ 16 /* Checks if we have a device to sniff on */
21 if(device == NULL) 17 if(device == NULL)
22 { 18 {
23 wl_logerr("No device given"); 19 wl_logerr("No device given");
24 return 0; 20 return 0;
25 } 21 }
26 22
27 /* Setting the prmiscous and up flag to the interface */ 23 /* Setting the prmiscous and up flag to the interface */
28 if (!card_set_promisc_up(device)) 24 if (!card_set_promisc_up(device))
29 { 25 {
30 wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); 26 wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno));
31 return 0; 27 return 0;
32 } 28 }
33 wl_loginfo("Interface set to promisc mode"); 29 wl_loginfo("Interface set to promisc mode");
34 30
35 /* Check the cardtype and executes the commands to go into monitor mode */ 31 /* Check the cardtype and executes the commands to go into monitor mode */
36 if (cardtype == CARD_TYPE_CISCO) 32 if (cardtype == CARD_TYPE_CISCO)
37 { 33 {
38 /* bring the sniffer into rfmon mode */ 34 /* bring the sniffer into rfmon mode */
39 snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); 35 snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device);
40 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) 36 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
41 { 37 {
42 wl_logerr("Cannot open config file: %s", strerror(errno)); 38 wl_logerr("Cannot open config file: %s", strerror(errno));
43 return 0; 39 return 0;
44 } 40 }
45 fputs ("Mode: r",CISCO_CONFIG_FILE); 41 fputs ("Mode: r",CISCO_CONFIG_FILE);
46 fputs ("Mode: y",CISCO_CONFIG_FILE); 42 fputs ("Mode: y",CISCO_CONFIG_FILE);
47 fputs ("XmitPower: 1",CISCO_CONFIG_FILE); 43 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
48 fclose(CISCO_CONFIG_FILE); 44 fclose(CISCO_CONFIG_FILE);
49 } 45 }
50 else if (cardtype == CARD_TYPE_NG) 46 else if (cardtype == CARD_TYPE_NG)
51 { 47 {
52 char wlanngcmd[62]; 48 char wlanngcmd[62];
53 snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); 49 snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
54 if (system(wlanngcmd) != 0) 50 if (system(wlanngcmd) != 0)
55 { 51 {
56 wl_logerr("Could not set %s in raw mode, check cardtype", device); 52 wl_logerr("Could not set %s in raw mode, check cardtype", device);
57 return 0; 53 return 0;
58 } 54 }
59 } 55 }
60 else if (cardtype == CARD_TYPE_HOSTAP) 56 else if (cardtype == CARD_TYPE_HOSTAP)
61 { 57 {
62 wl_logerr("Got a host-ap card, nothing is implemented now"); 58 wl_logerr("Got a host-ap card, nothing is implemented now");
63 } 59 }
64 60
65 /* Check the interface if it is in the correct raw mode */
66 if((handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf)) == NULL)
67 {
68 wl_logerr("pcap_open_live() failed: %s", strerror(errno));
69 return 0;
70 }
71
72#ifdef HAVE_PCAP_NONBLOCK
73 pcap_setnonblock(handle, 1, errstr);
74#endif
75
76 /* getting the datalink type */
77 datalink = pcap_datalink(handle);
78
79 if (datalink != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
80 {
81 wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", device);
82 pcap_close(handle);
83 return 0;
84 }
85 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
86
87 return 1; 61 return 1;
88} 62}
89 63
90/* Set card into promisc mode */ 64/* Set card into promisc mode */
91int card_set_promisc_up (const char *device) 65int card_set_promisc_up (const char *device)
92{ 66{
93 char ifconfigcmd[32]; 67 char ifconfigcmd[32];
94 int retval=0; 68 int retval=0;
95 69
96 snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); 70 snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device);
97 retval = system(ifconfigcmd); 71 retval = system(ifconfigcmd);
98 72
99 if(retval < 0 || retval == 1) 73 if(retval != 0)
100 return 0; 74 return 0;
101 75
102return 1; 76return 1;
103} 77}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index d80b24b..976ceeb 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -1,34 +1,33 @@
1/* $Id$ */ 1/* $Id$ */
2 2
3#ifndef CARDMODE_HH 3#ifndef CARDMODE_HH
4#define CARDMODE_HH 4#define CARDMODE_HH
5 5
6#include <string.h> 6#include <string.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <pcap.h> 8#include <pcap.h>
9#include <errno.h> 9#include <errno.h>
10#include <sys/socket.h> 10#include <sys/socket.h>
11#include <netinet/in.h> 11#include <netinet/in.h>
12#include <arpa/inet.h> 12#include <arpa/inet.h>
13#include <net/bpf.h> 13#include <net/bpf.h>
14 14
15#include "../../libwellenreiter/source/log.hh" 15#include "../../libwellenreiter/source/log.hh"
16 16
17/* Defines, used for the card setup */ 17/* Defines, used for the card setup */
18#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 18#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
19 #define CARD_TYPE_CISCO1 19 #define CARD_TYPE_CISCO1
20 #define CARD_TYPE_NG 2 20 #define CARD_TYPE_NG 2
21 #define CARD_TYPE_HOSTAP3 21 #define CARD_TYPE_HOSTAP3
22 22
23/* only for now, until we have the daemon running */ 23/* only for now, until we have the daemon running */
24/*the config file should provide these information */ 24/*the config file should provide these information */
25#define CARD_TYPE CARD_TYPE_CISCO 25#define CARD_TYPE CARD_TYPE_CISCO
26 #define SBIN_PATH "/sbin/ifconfig %s promisc up" 26 #define SBIN_PATH "/sbin/ifconfig %s promisc up"
27#define WLANCTL_PATH "/sbin/wlanctl-ng" 27#define WLANCTL_PATH "/sbin/wlanctl-ng"
28 28
29/* Prototypes */ 29/* Prototypes */
30 30int card_into_monitormode (pcap_t **, char *, int);
31int card_into_monitormode (void *, char *, int);
32int card_set_promisc_up (const char *); 31int card_set_promisc_up (const char *);
33 32
34#endif /* CARDMODE_HH */ 33#endif /* CARDMODE_HH */