summaryrefslogtreecommitdiff
authormax <max>2003-02-12 01:03:29 (UTC)
committer max <max>2003-02-12 01:03:29 (UTC)
commitc7fe028f53eb676c9ce619840c0d0a4603a9301f (patch) (side-by-side diff)
tree81c32bfe1445092f52ae8097418dbb2375a7342b
parentee67394120b5436d955d64a21b8ea707b57ac0c0 (diff)
downloadopie-c7fe028f53eb676c9ce619840c0d0a4603a9301f.zip
opie-c7fe028f53eb676c9ce619840c0d0a4603a9301f.tar.gz
opie-c7fe028f53eb676c9ce619840c0d0a4603a9301f.tar.bz2
All card monitor and switching
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc128
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh49
2 files changed, 164 insertions, 13 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index 8c94cb1..cf50d8c 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -10,3 +10,3 @@
/* main card into monitor function */
-int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
+int card_into_monitormode (pcap_t **orighandle, const char *device, int cardtype)
{
@@ -49,3 +49,2 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1);
- printf ("\n %s",wlanngcmd);
if (system(wlanngcmd) != 0)
@@ -58,12 +57,20 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
{
- wl_logerr("Got a host-ap card, nothing is implemented now");
- char hostapcmd[250];
- snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1);
- if (system(hostapcmd) !=0)
+ int skfd;
+ skfd = socket(AF_INET, SOCK_STREAM, 0);
+ struct iwreq wrq;
+ wrq.u.mode = IW_MODE_MONITOR;
+
+ if(iw_set_ext(skfd,device,SIOCSIWMODE,&wrq)<0)
{
- wl_logerr("Could not set %s in raw mode, check cardtype", device);
+ wl_logerr("Could not set hostap card %s to raw mode, check cardtype", device);
return 0;
}
+ else
+ {
+ wl_loginfo("Successfully set hostap card %s into raw mode",device);
+ return 1;
+ }
+ return 1;
}
- else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
+ else if (cardtype == CARD_TYPE_ORINOCCO )
{
@@ -94,3 +101,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
/* Check card is in the rfmon mode */
-int card_check_rfmon_datalink (char *device)
+int card_check_rfmon_datalink (const char *device)
{
@@ -140,3 +147,3 @@ int card_set_promisc_up (const char *device)
strncpy(ifr.ifr_name, device,10);
- ioctl(fd, SIOCGIFFLAGS, &ifr);
+ err = ioctl(fd, SIOCGIFFLAGS, &ifr);
if (err < 0)
@@ -170,3 +177,3 @@ int card_set_channel (const char *device, int channel, int cardtype)
/* If it is a lucent orinocco card */
- else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP)
+ else if (cardtype == CARD_TYPE_ORINOCCO)
{
@@ -182,2 +189,3 @@ int card_set_channel (const char *device, int channel, int cardtype)
}
+
ptr = (int *) ireq.u.name;
@@ -202,2 +210,21 @@ int card_set_channel (const char *device, int channel, int cardtype)
}
+ /* 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;
+ iw_float2freq((double) channel, &wrq.u.freq);
+
+ if(iw_set_ext(skfd,device,SIOCSIWFREQ,&wrq)<0)
+ {
+ wl_logerr("Could not set hostap card %s to channel %d", device, channel);
+ return 0;
+ }
+ else
+ {
+ wl_loginfo("Successfully set hostap card %s to channel %d", device, channel);
+ return 1;
+ }
+ }
/* For undefined situations */
@@ -206 +233,80 @@ int card_set_channel (const char *device, int channel, int cardtype)
+
+int card_detect_channels (char * device)
+{
+ int skfd;
+ skfd = socket(AF_INET, SOCK_STREAM, 0);
+ struct iw_range range;
+ /* Get list of frequencies / channels */
+ printf ("\n hostap card get the frequencies");
+ /* Get list of frequencies / channels */
+ if(iw_get_range_info(skfd, device, &range) < 0)
+ { /* We are failsave if something went wrong, asume only 11 channels */
+ return 11;
+ }
+ else
+ {
+ if(range.num_frequency > 0)
+ {
+ return range.num_frequency;
+ }
+ else
+ { /* We are failsave asume only 11 channels */
+ return 11;
+ }
+ }
+
+} /* End of card_detect_channels */
+
+int iw_get_range_info(int skfd, const char * ifname, iw_range * range)
+{
+ struct iwreq wrq2;
+ char buffer[sizeof(iw_range) * 2]; /* Large enough */
+
+ /* Cleanup */
+ memset(buffer, 0, sizeof(buffer));
+ wrq2.u.data.pointer = (caddr_t) buffer;
+ wrq2.u.data.length = sizeof(buffer);
+ wrq2.u.data.flags = 0;
+
+ if(iw_get_ext(skfd, ifname, SIOCGIWRANGE, &wrq2) < 0)
+ {
+ wl_logerr("Could not get the range from the interface");
+ return(-1);
+ }
+ else
+ {
+ /* Copy stuff at the right place, ignore extra */
+ memcpy((char *) range, buffer, sizeof(iw_range));
+ return 0;
+ }
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Convert our internal representation of frequencies to a floating point.
+ */
+double iw_freq2float(iw_freq * in)
+{
+ int i;
+ double res = (double) in->m;
+ for(i = 0; i < in->e; i++)
+ res *= 10;
+ return(res);
+}
+
+
+void iw_float2freq(double in, iw_freq * out)
+{
+ /* Version without libm : slower */
+ out->e = 0;
+ while(in > 1e9)
+ {
+ in /= 10;
+ out->e++;
+ }
+ out->m = (long) in;
+}
+
+
+
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index 4a95956..b35dddd 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -37,2 +37,8 @@ extern "C"
+/* Some usefull constants for frequencies */
+#define KILO 1e3
+#define MEGA 1e6
+#define GIGA 1e9
+
+
/* only for now, until we have the daemon running */
@@ -42,6 +48,45 @@ extern "C"
/* Prototypes */
-int card_check_rfmon_datalink (char *device);
-int card_into_monitormode (pcap_t **, char *, int);
+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_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));
+}
+
+