summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc70
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh3
2 files changed, 72 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index d385df4..7c9fbc4 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -179,48 +179,118 @@ int card_set_promisc_up (const char *device)
179 179
180 /* Get the informations back from the interface to check if the flags are correct */ 180 /* Get the informations back from the interface to check if the flags are correct */
181 strncpy(ifr.ifr_name, device,10); 181 strncpy(ifr.ifr_name, device,10);
182 err = ioctl(fd, SIOCGIFFLAGS, &ifr); 182 err = ioctl(fd, SIOCGIFFLAGS, &ifr);
183 if (err < 0) 183 if (err < 0)
184 { 184 {
185 perror("Could not access the interface, "); 185 perror("Could not access the interface, ");
186 close(fd); 186 close(fd);
187 return 0; 187 return 0;
188 } 188 }
189 189
190 if(ifr.ifr_flags && IFF_UP) 190 if(ifr.ifr_flags && IFF_UP)
191 { 191 {
192 close(fd); 192 close(fd);
193 return 1; 193 return 1;
194 } 194 }
195 else 195 else
196 { 196 {
197 wl_logerr("Could not set promisc flag on %d", device); 197 wl_logerr("Could not set promisc flag on %d", device);
198 close(fd); 198 close(fd);
199 return 0; 199 return 0;
200 } 200 }
201} 201}
202 202
203/* Remove card from promisc mode */
204int card_remove_promisc (const char *device)
205{
206 int err;
207 /* First generate a socket to use with iocalls */
208 int fd = socket(AF_INET, SOCK_DGRAM, 0);
209 if (fd < 0)
210 {
211 /* In case of an error */
212 perror("socket");
213 return 0;
214 }
215
216 /* Fill an empty an interface structure with the right flags (UP and Promsic) */
217 struct ifreq ifr;
218/* strncpy(ifr.ifr_name, device,10);
219 ifr.ifr_flags = IFF_UP + IFF_PROMISC;
220 err = ioctl(fd, SIOCSIFFLAGS, &ifr);
221 if (err < 0)
222 {
223 perror("Could not access the interface, ");
224 close(fd);
225 return 0;
226 }
227 */
228 /* Get the flags from the interface*/
229 strncpy(ifr.ifr_name, device,10);
230 err = ioctl(fd, SIOCGIFFLAGS, &ifr);
231 if (err < 0)
232 {
233 perror("Could not access the interface, ");
234 close(fd);
235 return 0;
236 }
237 /* Remove the IFF_PROMISC flag */
238 ifr.ifr_flags = ifr.ifr_flags - IFF_PROMISC;
239 /*Set the new flags to the interface*/
240 err = ioctl(fd, SIOCSIFFLAGS, &ifr);
241 if (err < 0)
242 {
243 perror("Could not access the interface, ");
244 close(fd);
245 return 0;
246 }
247
248 /* Get the flags again to check if IFF_PROMISC is removed */
249 err = ioctl(fd, SIOCGIFFLAGS, &ifr);
250 if (err < 0)
251 {
252 perror("Could not access the interface, ");
253 close(fd);
254 return 0;
255 }
256 if(ifr.ifr_flags && IFF_PROMISC)
257 {
258 wl_logerr("Could not remove the promisc flag on %d", device);
259 close(fd);
260 return 0;
261 }
262 else
263 {
264 /* Successfully removed the promisc flags */
265 close(fd);
266 return 1;
267 }
268}
269
270
271
272
203/* Set channel (Wireless frequency) of the device */ 273/* Set channel (Wireless frequency) of the device */
204int card_set_channel (const char *device, int channel, int cardtype) 274int card_set_channel (const char *device, int channel, int cardtype)
205{ 275{
206 if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG) 276 if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG)
207 { 277 {
208 /* Cisco and wlan-ng drivers don't need channelswitching */ 278 /* Cisco and wlan-ng drivers don't need channelswitching */
209 return 1; 279 return 1;
210 } 280 }
211 /* If it is a lucent orinocco card */ 281 /* If it is a lucent orinocco card */
212 else if (cardtype == CARD_TYPE_ORINOCCO) 282 else if (cardtype == CARD_TYPE_ORINOCCO)
213 { 283 {
214 int fd; 284 int fd;
215 //Wireless tools structure for the iocalls 285 //Wireless tools structure for the iocalls
216 struct iwreq ireq; 286 struct iwreq ireq;
217 int *ptr; 287 int *ptr;
218 /* Socket needed to use the iocall to */ 288 /* Socket needed to use the iocall to */
219 fd = socket(AF_INET, SOCK_STREAM, 0); 289 fd = socket(AF_INET, SOCK_STREAM, 0);
220 290
221 if ( fd == -1 ) { 291 if ( fd == -1 ) {
222 return -1; 292 return -1;
223 } 293 }
224 294
225 ptr = (int *) ireq.u.name; 295 ptr = (int *) ireq.u.name;
226 // This is the monitor mode for 802.11 non-prism header 296 // This is the monitor mode for 802.11 non-prism header
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index b35dddd..652b3ed 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -27,49 +27,50 @@ extern "C"
27#include <pcap.h> 27#include <pcap.h>
28} 28}
29 29
30/* Defines, used for the card setup */ 30/* Defines, used for the card setup */
31#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 31#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
32#define CISCO_STATUS "/proc/driver/aironet/%s/Status" 32#define CISCO_STATUS "/proc/driver/aironet/%s/Status"
33 #define CARD_TYPE_CISCO 1 33 #define CARD_TYPE_CISCO 1
34 #define CARD_TYPE_NG 2 34 #define CARD_TYPE_NG 2
35 #define CARD_TYPE_HOSTAP3 35 #define CARD_TYPE_HOSTAP3
36#define CARD_TYPE_ORINOCCO 4 36#define CARD_TYPE_ORINOCCO 4
37 37
38/* Some usefull constants for frequencies */ 38/* Some usefull constants for frequencies */
39#define KILO 1e3 39#define KILO 1e3
40#define MEGA 1e6 40#define MEGA 1e6
41#define GIGA 1e9 41#define GIGA 1e9
42 42
43 43
44/* only for now, until we have the daemon running */ 44/* only for now, until we have the daemon running */
45/*the config file should provide these information */ 45/*the config file should provide these information */
46#define CARD_TYPE CARD_TYPE_HOSTAP 46#define CARD_TYPE CARD_TYPE_HOSTAP
47 47
48/* Prototypes */ 48/* Prototypes */
49int card_check_rfmon_datalink (const char *device); 49int card_check_rfmon_datalink (const char *device);
50int card_into_monitormode (pcap_t **, const char *, int); 50int card_into_monitormode (pcap_t **, const char *, int);
51int card_set_promisc_up (const char *); 51int card_set_promisc_up (const char *device);
52int card_remove_promisc (const char *device);
52int card_set_channel (const char *device, int channel,int cardtype); 53int card_set_channel (const char *device, int channel,int cardtype);
53int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range); 54int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range);
54double iw_freq2float(iw_freq * in); 55double iw_freq2float(iw_freq * in);
55 void iw_float2freq(double in, iw_freq *out); 56 void iw_float2freq(double in, iw_freq *out);
56int card_detect_channels (char * device); 57int card_detect_channels (char * device);
57 58
58 59
59/*------------------------------------------------------------------*/ 60/*------------------------------------------------------------------*/
60/* 61/*
61 * Wrapper to push some Wireless Parameter in the driver 62 * Wrapper to push some Wireless Parameter in the driver
62 */ 63 */
63static inline int 64static inline int
64 iw_set_ext(int skfd, /* Socket to the kernel */ 65 iw_set_ext(int skfd, /* Socket to the kernel */
65 char * ifname, /* Device name */ 66 char * ifname, /* Device name */
66 int request,/* WE ID */ 67 int request,/* WE ID */
67 struct iwreq * pwrq) /* Fixed part of the request */ 68 struct iwreq * pwrq) /* Fixed part of the request */
68{ 69{
69 /* Set device name */ 70 /* Set device name */
70 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); 71 strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
71 /* Do the request */ 72 /* Do the request */
72 return(ioctl(skfd, request, pwrq)); 73 return(ioctl(skfd, request, pwrq));
73} 74}
74 75
75/*------------------------------------------------------------------*/ 76/*------------------------------------------------------------------*/