summaryrefslogtreecommitdiff
authormax <max>2003-02-11 00:29:37 (UTC)
committer max <max>2003-02-11 00:29:37 (UTC)
commitd426759d470699bd4320b23660f19dae639293d6 (patch) (unidiff)
treee9a0ff886e1b241d920e87ae3115594412a427e3
parent0af800b30845a0d3df8be9db5c11c06fd81386e7 (diff)
downloadopie-d426759d470699bd4320b23660f19dae639293d6.zip
opie-d426759d470699bd4320b23660f19dae639293d6.tar.gz
opie-d426759d470699bd4320b23660f19dae639293d6.tar.bz2
Wlan-ng chanswitch
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc18
1 files changed, 4 insertions, 14 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index 29dcc75..8c94cb1 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -1,216 +1,206 @@
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[80];
49 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1); 49 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1);
50 printf ("\n %s",wlanngcmd);
50 if (system(wlanngcmd) != 0) 51 if (system(wlanngcmd) != 0)
51 { 52 {
52 wl_logerr("Could not set %s in raw mode, check cardtype", device); 53 wl_logerr("Could not set %s in raw mode, check cardtype", device);
53 return 0; 54 return 0;
54 } 55 }
55 } 56 }
56 else if (cardtype == CARD_TYPE_HOSTAP) 57 else if (cardtype == CARD_TYPE_HOSTAP)
57 { 58 {
58 wl_logerr("Got a host-ap card, nothing is implemented now"); 59 wl_logerr("Got a host-ap card, nothing is implemented now");
59 char hostapcmd[250]; 60 char hostapcmd[250];
60 snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1); 61 snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1);
61 if (system(hostapcmd) !=0) 62 if (system(hostapcmd) !=0)
62 { 63 {
63 wl_logerr("Could not set %s in raw mode, check cardtype", device); 64 wl_logerr("Could not set %s in raw mode, check cardtype", device);
64 return 0; 65 return 0;
65 } 66 }
66 } 67 }
67 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) 68 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
68 { 69 {
69 if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) 70 if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO))
70 { 71 {
71 wl_logerr("Could not set %s in raw mode, check cardtype", device); 72 wl_logerr("Could not set %s in raw mode, check cardtype", device);
72 return 0; 73 return 0;
73 } 74 }
74 else 75 else
75 { 76 {
76 wl_loginfo("Successfully set %s into raw mode",device); 77 wl_loginfo("Successfully set %s into raw mode",device);
77 } 78 }
78 } 79 }
79 80
80 /* Setting the promiscous and up flag to the interface */ 81 /* Setting the promiscous and up flag to the interface */
81 if (!card_check_rfmon_datalink(device)) 82 if (!card_check_rfmon_datalink(device))
82 { 83 {
83 wl_logerr("Cannot set interface to rfmon mode"); 84 wl_logerr("Cannot set interface to rfmon mode");
84 return 0; 85 return 0;
85 } 86 }
86 else 87 else
87 { 88 {
88 wl_loginfo("Interface set to rfmon mode"); 89 wl_loginfo("Interface set to rfmon mode");
89 } 90 }
90 return 1; 91 return 1;
91} 92}
92 93
93/* Check card is in the rfmon mode */ 94/* Check card is in the rfmon mode */
94int card_check_rfmon_datalink (char *device) 95int card_check_rfmon_datalink (char *device)
95{ 96{
96 int datalinktype=0; 97 int datalinktype=0;
97 pcap_t *phandle; 98 pcap_t *phandle;
98 phandle = pcap_open_live(device, 65,0,0,NULL); 99 phandle = pcap_open_live(device, 65,0,0,NULL);
99 datalinktype = pcap_datalink (phandle); 100 datalinktype = pcap_datalink (phandle);
100 pcap_close(phandle); 101 pcap_close(phandle);
101 102
102 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ 103 if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
103 { 104 {
104 return 0; 105 return 0;
105 } 106 }
106 else 107 else
107 { 108 {
108 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); 109 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
109 return 1; 110 return 1;
110 } 111 }
111} 112}
112 113
113/* Set card into promisc mode */ 114/* Set card into promisc mode */
114int card_set_promisc_up (const char *device) 115int card_set_promisc_up (const char *device)
115{ 116{
116 int err; 117 int err;
117 /* First generate a socket to use with iocalls */ 118 /* First generate a socket to use with iocalls */
118 int fd = socket(AF_INET, SOCK_DGRAM, 0); 119 int fd = socket(AF_INET, SOCK_DGRAM, 0);
119 if (fd < 0) 120 if (fd < 0)
120 { 121 {
121 /* In case of an error */ 122 /* In case of an error */
122 perror("socket"); 123 perror("socket");
123 return 0; 124 return 0;
124 } 125 }
125 126
126 /* Fill an empty an interface structure with the right flags (UP and Promsic) */ 127 /* Fill an empty an interface structure with the right flags (UP and Promsic) */
127 struct ifreq ifr; 128 struct ifreq ifr;
128 strncpy(ifr.ifr_name, device,10); 129 strncpy(ifr.ifr_name, device,10);
129 ifr.ifr_flags = IFF_UP + IFF_PROMISC; 130 ifr.ifr_flags = IFF_UP + IFF_PROMISC;
130 err = ioctl(fd, SIOCSIFFLAGS, &ifr); 131 err = ioctl(fd, SIOCSIFFLAGS, &ifr);
131 if (err < 0) 132 if (err < 0)
132 { 133 {
133 perror("Could not access the interface, "); 134 perror("Could not access the interface, ");
134 close(fd); 135 close(fd);
135 return 0; 136 return 0;
136 } 137 }
137 138
138 /* Get the informations back from the interface to check if the flags are correct */ 139 /* Get the informations back from the interface to check if the flags are correct */
139 strncpy(ifr.ifr_name, device,10); 140 strncpy(ifr.ifr_name, device,10);
140 ioctl(fd, SIOCGIFFLAGS, &ifr); 141 ioctl(fd, SIOCGIFFLAGS, &ifr);
141 if (err < 0) 142 if (err < 0)
142 { 143 {
143 perror("Could not access the interface, "); 144 perror("Could not access the interface, ");
144 close(fd); 145 close(fd);
145 return 0; 146 return 0;
146 } 147 }
147 148
148 if(ifr.ifr_flags && IFF_UP) 149 if(ifr.ifr_flags && IFF_UP)
149 { 150 {
150 close(fd); 151 close(fd);
151 return 1; 152 return 1;
152 } 153 }
153 else 154 else
154 { 155 {
155 wl_logerr("Could not set promisc flag on %d", device); 156 wl_logerr("Could not set promisc flag on %d", device);
156 close(fd); 157 close(fd);
157 return 0; 158 return 0;
158 } 159 }
159} 160}
160 161
161/* Set channel (Wireless frequency) of the device */ 162/* Set channel (Wireless frequency) of the device */
162int card_set_channel (const char *device, int channel, int cardtype) 163int card_set_channel (const char *device, int channel, int cardtype)
163{ 164{
164 if (cardtype == CARD_TYPE_CISCO) 165 if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG)
165 { 166 {
166 /* Cisco cards don't need channelswitching */ 167 /* Cisco and wlan-ng drivers don't need channelswitching */
167 return 1; 168 return 1;
168 } 169 }
169 /* If it is a lucent orinocco card */ 170 /* If it is a lucent orinocco card */
170 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) 171 else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
171 { 172 {
172 int fd; 173 int fd;
173 //Wireless tools structure for the iocalls 174 //Wireless tools structure for the iocalls
174 struct iwreq ireq; 175 struct iwreq ireq;
175 int *ptr; 176 int *ptr;
176 /* Socket needed to use the iocall to */ 177 /* Socket needed to use the iocall to */
177 fd = socket(AF_INET, SOCK_STREAM, 0); 178 fd = socket(AF_INET, SOCK_STREAM, 0);
178 179
179 if ( fd == -1 ) { 180 if ( fd == -1 ) {
180 return -1; 181 return -1;
181 } 182 }
182 ptr = (int *) ireq.u.name; 183 ptr = (int *) ireq.u.name;
183 // This is the monitor mode for 802.11 non-prism header 184 // This is the monitor mode for 802.11 non-prism header
184 ptr[0] = 2; 185 ptr[0] = 2;
185 ptr[1] = channel; 186 ptr[1] = channel;
186 strcpy(ireq.ifr_ifrn.ifrn_name, device); 187 strcpy(ireq.ifr_ifrn.ifrn_name, device);
187 if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) 188 if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0)
188 { 189 {
189 /* All was fine... */ 190 /* All was fine... */
190 close(fd); 191 close(fd);
191 wl_loginfo("Set channel %d on interface %s",channel, device); 192 wl_loginfo("Set channel %d on interface %s",channel, device);
192 return 1; 193 return 1;
193 } 194 }
194 else 195 else
195 { 196 {
196 /* iocall does not work */ 197 /* iocall does not work */
197 close(fd); 198 close(fd);
198 wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); 199 wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
199 return 0; 200 return 0;
200 } 201 }
201 } 202 }
202 else if (cardtype == CARD_TYPE_NG)
203 {
204 char wlanngcmd[62];
205 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel);
206 if (system(wlanngcmd) != 0)
207 {
208 wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
209 return 0;
210 }
211
212 }
213 /* For undefined situations */ 203 /* For undefined situations */
214 return 0; 204 return 0;
215} 205}
216 206