summaryrefslogtreecommitdiff
authormax <max>2003-02-18 09:31:47 (UTC)
committer max <max>2003-02-18 09:31:47 (UTC)
commit065f26b161f6df269cfbf9c75751c09453350995 (patch) (side-by-side diff)
tree0d242028eadc37ecc9afa38af676906998d92329
parent3d8495ee454395e95190693af9baa9420f90431f (diff)
downloadopie-065f26b161f6df269cfbf9c75751c09453350995.zip
opie-065f26b161f6df269cfbf9c75751c09453350995.tar.gz
opie-065f26b161f6df269cfbf9c75751c09453350995.tar.bz2
Remove-promisc-flag
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
@@ -155,96 +155,166 @@ int card_check_rfmon_datalink (const char *device)
/* Set card into promisc mode */
int card_set_promisc_up (const char *device)
{
int err;
/* First generate a socket to use with iocalls */
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
/* In case of an error */
perror("socket");
return 0;
}
/* Fill an empty an interface structure with the right flags (UP and Promsic) */
struct ifreq ifr;
strncpy(ifr.ifr_name, device,10);
ifr.ifr_flags = IFF_UP + IFF_PROMISC;
err = ioctl(fd, SIOCSIFFLAGS, &ifr);
if (err < 0)
{
perror("Could not access the interface, ");
close(fd);
return 0;
}
/* Get the informations back from the interface to check if the flags are correct */
strncpy(ifr.ifr_name, device,10);
err = ioctl(fd, SIOCGIFFLAGS, &ifr);
if (err < 0)
{
perror("Could not access the interface, ");
close(fd);
return 0;
}
if(ifr.ifr_flags && IFF_UP)
{
close(fd);
return 1;
}
else
{
wl_logerr("Could not set promisc flag on %d", device);
close(fd);
return 0;
}
}
+/* Remove card from promisc mode */
+int card_remove_promisc (const char *device)
+{
+ int err;
+ /* First generate a socket to use with iocalls */
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ {
+ /* In case of an error */
+ perror("socket");
+ return 0;
+ }
+
+ /* Fill an empty an interface structure with the right flags (UP and Promsic) */
+ struct ifreq ifr;
+/* strncpy(ifr.ifr_name, device,10);
+ ifr.ifr_flags = IFF_UP + IFF_PROMISC;
+ err = ioctl(fd, SIOCSIFFLAGS, &ifr);
+ if (err < 0)
+ {
+ perror("Could not access the interface, ");
+ close(fd);
+ return 0;
+ }
+ */
+ /* Get the flags from the interface*/
+ strncpy(ifr.ifr_name, device,10);
+ err = ioctl(fd, SIOCGIFFLAGS, &ifr);
+ if (err < 0)
+ {
+ perror("Could not access the interface, ");
+ close(fd);
+ return 0;
+ }
+ /* Remove the IFF_PROMISC flag */
+ ifr.ifr_flags = ifr.ifr_flags - IFF_PROMISC;
+ /*Set the new flags to the interface*/
+ err = ioctl(fd, SIOCSIFFLAGS, &ifr);
+ if (err < 0)
+ {
+ perror("Could not access the interface, ");
+ close(fd);
+ return 0;
+ }
+
+ /* Get the flags again to check if IFF_PROMISC is removed */
+ err = ioctl(fd, SIOCGIFFLAGS, &ifr);
+ if (err < 0)
+ {
+ perror("Could not access the interface, ");
+ close(fd);
+ return 0;
+ }
+ if(ifr.ifr_flags && IFF_PROMISC)
+ {
+ wl_logerr("Could not remove the promisc flag on %d", device);
+ close(fd);
+ return 0;
+ }
+ else
+ {
+ /* Successfully removed the promisc flags */
+ close(fd);
+ return 1;
+ }
+}
+
+
+
+
/* Set channel (Wireless frequency) of the device */
int card_set_channel (const char *device, int channel, int cardtype)
{
if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG)
{
/* Cisco and wlan-ng drivers don't need channelswitching */
return 1;
}
/* If it is a lucent orinocco card */
else if (cardtype == CARD_TYPE_ORINOCCO)
{
int fd;
//Wireless tools structure for the iocalls
struct iwreq ireq;
int *ptr;
/* Socket needed to use the iocall to */
fd = socket(AF_INET, SOCK_STREAM, 0);
if ( fd == -1 ) {
return -1;
}
ptr = (int *) ireq.u.name;
// This is the monitor mode for 802.11 non-prism header
ptr[0] = 2;
ptr[1] = channel;
strcpy(ireq.ifr_ifrn.ifrn_name, device);
if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0)
{
/* All was fine... */
close(fd);
wl_loginfo("Set channel %d on interface %s",channel, device);
return 1;
}
else
{
/* iocall does not work */
close(fd);
wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
return 0;
}
}
/* when it is an hostap card you need another iocall for channel switching */
else if (cardtype == CARD_TYPE_HOSTAP)
{
int skfd;
skfd = socket(AF_INET, SOCK_STREAM, 0);
struct iwreq wrq;
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
@@ -3,91 +3,92 @@
#ifndef CARDMODE_HH
#define CARDMODE_HH
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/if.h>
#include <linux/wireless.h>
#ifndef SIOCIWFIRSTPRIV
#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
#endif
extern "C"
{
#include <net/bpf.h>
#include <pcap.h>
}
/* Defines, used for the card setup */
#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
#define CISCO_STATUS "/proc/driver/aironet/%s/Status"
#define CARD_TYPE_CISCO 1
#define CARD_TYPE_NG 2
#define CARD_TYPE_HOSTAP 3
#define CARD_TYPE_ORINOCCO 4
/* Some usefull constants for frequencies */
#define KILO 1e3
#define MEGA 1e6
#define GIGA 1e9
/* only for now, until we have the daemon running */
/*the config file should provide these information */
#define CARD_TYPE CARD_TYPE_HOSTAP
/* Prototypes */
int card_check_rfmon_datalink (const char *device);
int card_into_monitormode (pcap_t **, const char *, int);
-int card_set_promisc_up (const char *);
+int card_set_promisc_up (const char *device);
+int card_remove_promisc (const char *device);
int card_set_channel (const char *device, int channel,int cardtype);
int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range);
double iw_freq2float(iw_freq * in);
void iw_float2freq(double in, iw_freq * out);
int card_detect_channels (char * device);
/*------------------------------------------------------------------*/
/*
* Wrapper to push some Wireless Parameter in the driver
*/
static inline int
iw_set_ext(int skfd, /* Socket to the kernel */
char * ifname, /* Device name */
int request, /* WE ID */
struct iwreq * pwrq) /* Fixed part of the request */
{
/* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */
return(ioctl(skfd, request, pwrq));
}
/*------------------------------------------------------------------*/
/*
* Wrapper to extract some Wireless Parameter out of the driver
*/
static inline int
iw_get_ext(int skfd, /* Socket to the kernel */
char * ifname, /* Device name */
int request, /* WE ID */
struct iwreq * pwrq) /* Fixed part of the request */
{
/* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */
return(ioctl(skfd, request, pwrq));
}
#endif /* CARDMODE_HH */