summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc43
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh8
2 files changed, 48 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index d868438..697d182 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -1,144 +1,187 @@
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#include "wl_log.hh" 8#include "wl_log.hh"
9 9
10/* main card into monitor function */ 10/* main card into monitor function */
11int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) 11int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
12{ 12{
13 char CiscoRFMON[35] = "/proc/driver/aironet/"; 13 char CiscoRFMON[35] = "/proc/driver/aironet/";
14 FILE *CISCO_CONFIG_FILE; 14 FILE *CISCO_CONFIG_FILE;
15 15
16 /* Checks if we have a device to sniff on */ 16 /* Checks if we have a device to sniff on */
17 if(device == NULL) 17 if(device == NULL)
18 { 18 {
19 wl_logerr("No device given"); 19 wl_logerr("No device given");
20 return 0; 20 return 0;
21 } 21 }
22 22
23 /* Setting the promiscous and up flag to the interface */ 23 /* Setting the promiscous and up flag to the interface */
24 if (!card_set_promisc_up(device)) 24 if (!card_set_promisc_up(device))
25 { 25 {
26 wl_logerr("Cannot set interface to promisc mode"); 26 wl_logerr("Cannot set interface to promisc mode");
27 return 0; 27 return 0;
28 } 28 }
29 wl_loginfo("Interface set to promisc mode"); 29 wl_loginfo("Interface set to promisc mode");
30 30
31 /* 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 */
32 if (cardtype == CARD_TYPE_CISCO) 32 if (cardtype == CARD_TYPE_CISCO)
33 { 33 {
34 /* bring the sniffer into rfmon mode */ 34 /* bring the sniffer into rfmon mode */
35 snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); 35 snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device);
36 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) 36 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
37 { 37 {
38 wl_logerr("Cannot open config file: %s", strerror(errno)); 38 wl_logerr("Cannot open config file: %s", strerror(errno));
39 return 0; 39 return 0;
40 } 40 }
41 fputs ("Mode: r",CISCO_CONFIG_FILE); 41 fputs ("Mode: r",CISCO_CONFIG_FILE);
42 fputs ("Mode: y",CISCO_CONFIG_FILE); 42 fputs ("Mode: y",CISCO_CONFIG_FILE);
43 fputs ("XmitPower: 1",CISCO_CONFIG_FILE); 43 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
44 fclose(CISCO_CONFIG_FILE); 44 fclose(CISCO_CONFIG_FILE);
45 } 45 }
46 else if (cardtype == CARD_TYPE_NG) 46 else if (cardtype == CARD_TYPE_NG)
47 { 47 {
48 char wlanngcmd[62]; 48 char wlanngcmd[62];
49 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); 49 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
50 if (system(wlanngcmd) != 0) 50 if (system(wlanngcmd) != 0)
51 { 51 {
52 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);
53 return 0; 53 return 0;
54 } 54 }
55 } 55 }
56 else if (cardtype == CARD_TYPE_HOSTAP) 56 else if (cardtype == CARD_TYPE_HOSTAP)
57 { 57 {
58 wl_logerr("Got a host-ap card, nothing is implemented now"); 58 wl_logerr("Got a host-ap card, nothing is implemented now");
59 char hostapcmd[250]; 59 char hostapcmd[250];
60 snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device); 60 snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device);
61 if (system(hostapcmd) !=0) 61 if (system(hostapcmd) !=0)
62 { 62 {
63 wl_logerr("Could not set %s in raw mode, check cardtype", device); 63 wl_logerr("Could not set %s in raw mode, check cardtype", device);
64 return 0; 64 return 0;
65 } 65 }
66 } 66 }
67 else if (cardtype == CARD_TYPE_ORINOCCO)
68 {
69 char lucentcmd[62];
70 snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, 1);
71 if (system(lucentcmd) != 0)
72 {
73 wl_logerr("Could not set %s in raw mode, check cardtype", device);
74 return 0;
75 }
76 }
67 77
68 /* Setting the promiscous and up flag to the interface */ 78 /* Setting the promiscous and up flag to the interface */
69 if (!card_check_rfmon_datalink(device)) 79 if (!card_check_rfmon_datalink(device))
70 { 80 {
71 wl_logerr("Cannot set interface to rfmon mode"); 81 wl_logerr("Cannot set interface to rfmon mode");
72 return 0; 82 return 0;
73 } 83 }
74 else 84 else
75 { 85 {
76 wl_loginfo("Interface set to rfmon mode"); 86 wl_loginfo("Interface set to rfmon mode");
77 } 87 }
78 return 1; 88 return 1;
79} 89}
80 90
81/* Check card is in the rfmon mode */ 91/* Check card is in the rfmon mode */
82int card_check_rfmon_datalink (char *device) 92int card_check_rfmon_datalink (char *device)
83{ 93{
84 int datalinktype=0; 94 int datalinktype=0;
85 pcap_t *phandle; 95 pcap_t *phandle;
86 phandle = pcap_open_live(device, 65,0,0,NULL); 96 phandle = pcap_open_live(device, 65,0,0,NULL);
87 datalinktype = pcap_datalink (phandle); 97 datalinktype = pcap_datalink (phandle);
88 pcap_close(phandle); 98 pcap_close(phandle);
89 99
90 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ 100 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
91 { 101 {
92 return 0; 102 return 0;
93 } 103 }
94 else 104 else
95 { 105 {
96 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); 106 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
97 return 1; 107 return 1;
98 } 108 }
99} 109}
100 110
101/* Set card into promisc mode */ 111/* Set card into promisc mode */
102int card_set_promisc_up (const char *device) 112int card_set_promisc_up (const char *device)
103{ 113{
104 int err; 114 int err;
105 /* First generate a socket to use with iocalls */ 115 /* First generate a socket to use with iocalls */
106 int fd = socket(AF_INET, SOCK_DGRAM, 0); 116 int fd = socket(AF_INET, SOCK_DGRAM, 0);
107 if (fd < 0) 117 if (fd < 0)
108 { 118 {
109 /* In case of an error */ 119 /* In case of an error */
110 perror("socket"); 120 perror("socket");
111 return 0; 121 return 0;
112 } 122 }
113 123
114 /* Fill an empty an interface structure with the right flags (UP and Promsic) */ 124 /* Fill an empty an interface structure with the right flags (UP and Promsic) */
115 struct ifreq ifr; 125 struct ifreq ifr;
116 strncpy(ifr.ifr_name, device,10); 126 strncpy(ifr.ifr_name, device,10);
117 ifr.ifr_flags = IFF_UP + IFF_PROMISC; 127 ifr.ifr_flags = IFF_UP + IFF_PROMISC;
118 err = ioctl(fd, SIOCSIFFLAGS, &ifr); 128 err = ioctl(fd, SIOCSIFFLAGS, &ifr);
119 if (err < 0) 129 if (err < 0)
120 { 130 {
121 perror("Could not access the interface, "); 131 perror("Could not access the interface, ");
122 return 0; 132 return 0;
123 } 133 }
124 134
125 /* Get the informations back from the interface to check if the flags are correct */ 135 /* Get the informations back from the interface to check if the flags are correct */
126 strncpy(ifr.ifr_name, device,10); 136 strncpy(ifr.ifr_name, device,10);
127 ioctl(fd, SIOCGIFFLAGS, &ifr); 137 ioctl(fd, SIOCGIFFLAGS, &ifr);
128 if (err < 0) 138 if (err < 0)
129 { 139 {
130 perror("Could not access the interface, "); 140 perror("Could not access the interface, ");
131 return 0; 141 return 0;
132 } 142 }
133 143
134 if(ifr.ifr_flags && IFF_UP) 144 if(ifr.ifr_flags && IFF_UP)
135 { 145 {
136 printf("%s is ok\n", device); 146 printf("%s is ok\n", device);
137 return 1; 147 return 1;
138 } 148 }
139 else 149 else
140 { 150 {
141 printf("%s flags could not be set", device); 151 printf("%s flags could not be set", device);
142 return 0; 152 return 0;
143 } 153 }
144} 154}
155
156/* Set channel (Wireless frequency) of the device */
157int card_set_channel (const char *device, int channel, int cardtype)
158{
159
160 if (cardtype == CARD_TYPE_CISCO)
161 {
162 /* Cisco cards don't need channelswitching */
163 return 1;
164 }
165 /* If it is a lucent orinocco card */
166 else if (cardtype == CARD_TYPE_ORINOCCO)
167 {
168 char lucentreset[63];
169 char lucentcmd[62];
170 snprintf(lucentreset, sizeof(lucentreset) -1,"$(which iwpriv) %s card_reset", device);
171 if (system(lucentreset) != 0)
172 {
173 wl_logerr("Could not reset the card %s",device);
174 return 0;
175 }
176 snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, channel);
177 if (system(lucentcmd) != 0)
178 {
179 wl_logerr("Could not set %s in raw mode, check cardtype", device);
180 return 0;
181 }
182 }
183
184 /* For undefined situations */
185 return 0;
186}
187
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index 4eec122..3a1991b 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -1,42 +1,44 @@
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 <errno.h> 8#include <errno.h>
9#include <sys/types.h> 9#include <sys/types.h>
10#include <sys/time.h> 10#include <sys/time.h>
11#include <sys/socket.h> 11#include <sys/socket.h>
12#include <netinet/in.h> 12#include <netinet/in.h>
13#include <arpa/inet.h> 13#include <arpa/inet.h>
14#include <sys/ioctl.h> 14#include <sys/ioctl.h>
15#include <linux/if.h> 15#include <linux/if.h>
16 16
17extern "C" 17extern "C"
18{ 18{
19#include <net/bpf.h> 19#include <net/bpf.h>
20#include <pcap.h> 20#include <pcap.h>
21} 21}
22 22
23/* Defines, used for the card setup */ 23/* Defines, used for the card setup */
24#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 24#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
25 #define CISCO_STATUS "/proc/driver/aironet/%s/Status" 25#define CISCO_STATUS "/proc/driver/aironet/%s/Status"
26 #define CARD_TYPE_CISCO1 26 #define CARD_TYPE_CISCO 1
27 #define CARD_TYPE_NG 2 27 #define CARD_TYPE_NG 2
28 #define CARD_TYPE_HOSTAP3 28 #define CARD_TYPE_HOSTAP3
29#define CARD_TYPE_ORINOCCO 4
29 30
30/* only for now, until we have the daemon running */ 31/* only for now, until we have the daemon running */
31/*the config file should provide these information */ 32/*the config file should provide these information */
32#define CARD_TYPE CARD_TYPE_HOSTAP 33#define CARD_TYPE CARD_TYPE_HOSTAP
33 #define SBIN_PATH "/sbin/ifconfig %s promisc up" 34 #define SBIN_PATH "/sbin/ifconfig %s promisc up"
34#define WLANCTL_PATH "/sbin/wlanctl-ng" 35#define WLANCTL_PATH "/sbin/wlanctl-ng"
35 #define IWPRIV_PATH "/sbin/iwpriv" 36 #define IWPRIV_PATH "/sbin/iwpriv"
36 37
37/* Prototypes */ 38/* Prototypes */
38int card_check_rfmon_datalink (char *device); 39int card_check_rfmon_datalink (char *device);
39int card_into_monitormode (pcap_t **, char *, int); 40int card_into_monitormode (pcap_t **, char *, int);
40int card_set_promisc_up (const char *); 41int card_set_promisc_up (const char *);
42int card_set_channel (const char *device, int channel,int cardtype);
41 43
42#endif /* CARDMODE_HH */ 44#endif /* CARDMODE_HH */