summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc18
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh1
2 files changed, 13 insertions, 6 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index 9e0a772..29dcc75 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -86,125 +86,131 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
else
{
wl_loginfo("Interface set to rfmon mode");
}
return 1;
}
/* Check card is in the rfmon mode */
int card_check_rfmon_datalink (char *device)
{
int datalinktype=0;
pcap_t *phandle;
phandle = pcap_open_live(device, 65,0,0,NULL);
datalinktype = pcap_datalink (phandle);
pcap_close(phandle);
if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
{
return 0;
}
else
{
wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device);
return 1;
}
}
/* 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);
ioctl(fd, SIOCGIFFLAGS, &ifr);
if (err < 0)
{
perror("Could not access the interface, ");
+ close(fd);
return 0;
}
if(ifr.ifr_flags && IFF_UP)
{
- printf("%s is ok\n", device);
- return 1;
+ close(fd);
+ return 1;
}
else
{
- printf("%s flags could not be set", device);
- return 0;
+ wl_logerr("Could not set promisc flag on %d", device);
+ close(fd);
+ return 0;
}
}
/* Set channel (Wireless frequency) of the device */
int card_set_channel (const char *device, int channel, int cardtype)
{
if (cardtype == CARD_TYPE_CISCO)
{
/* Cisco cards don't need channelswitching */
return 1;
}
/* If it is a lucent orinocco card */
else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
{
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);
+ close(fd);
wl_loginfo("Set channel %d on interface %s",channel, device);
return 1;
}
else
- { /* iocall does not work */
+ {
+ /* iocall does not work */
+ close(fd);
wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
return 0;
}
}
else if (cardtype == CARD_TYPE_NG)
{
char wlanngcmd[62];
snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel);
if (system(wlanngcmd) != 0)
{
wl_logerr("Could not set channel %d on %s, check cardtype",channel, device);
return 0;
}
}
/* For undefined situations */
return 0;
}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index 242d8c5..4a95956 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -1,47 +1,48 @@
/* $Id$ */
#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
/* 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 (char *device);
int card_into_monitormode (pcap_t **, char *, int);
int card_set_promisc_up (const char *);
int card_set_channel (const char *device, int channel,int cardtype);
#endif /* CARDMODE_HH */