summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc97
1 files changed, 97 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
new file mode 100644
index 0000000..62c2940
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -0,0 +1,97 @@
1/*
2 * Set card modes for sniffing
3 *
4 * $Id$
5 */
6
7#include "cardmode.hh"
8
9/* main card into monitor function */
10int card_into_monitormode (void *orighandle, char *device, int cardtype)
11{
12 int datalink; /* used for getting the pcap datalink type */
13 char CiscoRFMON[35] = "/proc/driver/aironet/";
14 FILE *CISCO_CONFIG_FILE;
15 char errbuf[PCAP_ERRBUF_SIZE];
16 pcap_t *handle;
17
18 handle = (pcap_t *)orighandle;
19
20 /* Checks if we have a device to sniff on */
21 if(device == NULL)
22 {
23 wl_logerr("No device given");
24 return 0;
25 }
26
27 /* Setting the prmiscous and up flag to the interface */
28 if (!card_set_promisc_up(device))
29 {
30 wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno));
31 return 0;
32 }
33 wl_loginfo("Interface set to promisc mode");
34
35 /* Check the cardtype and executes the commands to go into monitor mode */
36 if (cardtype == CARD_TYPE_CISCO)
37 {
38 /* bring the sniffer into rfmon mode */
39 snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device);
40 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
41 {
42 wl_logerr("Cannot open config file: %s", strerror(errno));
43 return 0;
44 }
45 fputs ("Mode: r",CISCO_CONFIG_FILE);
46 fputs ("Mode: y",CISCO_CONFIG_FILE);
47 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
48 fclose(CISCO_CONFIG_FILE);
49 }
50 else if (cardtype == CARD_TYPE_NG)
51 {
52 char wlanngcmd[62];
53 snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
54 if (system(wlanngcmd) != 0)
55 {
56 wl_logerr("Could not set %s in raw mode, check cardtype", device);
57 return 0;
58 }
59 }
60 else if (cardtype == CARD_TYPE_HOSTAP)
61 {
62 wl_logerr("Got a host-ap card, nothing is implemented now");
63 }
64
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;
88}
89
90/* Set card into promisc mode */
91int card_set_promisc_up (const char *device)
92{
93 char ifconfigcmd[32];
94 snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device);
95
96 return (system(ifconfigcmd) ? 1 : 0);
97}