gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r14758 - in gnunet/src/transport: . wlan


From: gnunet
Subject: [GNUnet-SVN] r14758 - in gnunet/src/transport: . wlan
Date: Mon, 28 Mar 2011 23:52:47 +0200

Author: brodski
Date: 2011-03-28 23:52:47 +0200 (Mon, 28 Mar 2011)
New Revision: 14758

Added:
   gnunet/src/transport/wlan/
   gnunet/src/transport/wlan/byteorder.h
   gnunet/src/transport/wlan/crctable_osdep.h
   gnunet/src/transport/wlan/helper_common.c
   gnunet/src/transport/wlan/helper_common.h
   gnunet/src/transport/wlan/ieee80211.h
   gnunet/src/transport/wlan/ieee80211_radiotap.h
   gnunet/src/transport/wlan/loopback_helper.c
   gnunet/src/transport/wlan/loopback_helper.h
   gnunet/src/transport/wlan/radiotap-parser.c
   gnunet/src/transport/wlan/radiotap-parser.h
Modified:
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/gnunet-transport-wlan-helper.c
   gnunet/src/transport/gnunet-transport-wlan-helper.h
   gnunet/src/transport/plugin_transport_wlan.c
   gnunet/src/transport/plugin_transport_wlan.h
Log:
First test of wlan driver, sends beacon every 2 seconds

Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2011-03-28 16:41:58 UTC (rev 14757)
+++ gnunet/src/transport/Makefile.am    2011-03-28 21:52:47 UTC (rev 14758)
@@ -88,7 +88,11 @@
 
     
 gnunet_transport_wlan_helper_SOURCES = \
+ wlan/radiotap-parser.c \
+ wlan/helper_common.c \
+ wlan/loopback_helper.c \
  gnunet-transport-wlan-helper.c
+
 gnunet_transport_wlan_helper_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
  -lpcap

Modified: gnunet/src/transport/gnunet-transport-wlan-helper.c
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-03-28 16:41:58 UTC 
(rev 14757)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-03-28 21:52:47 UTC 
(rev 14758)
@@ -1,22 +1,22 @@
 /*
-     This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+ This file is part of GNUnet.
+ (C) 2010 Christian Grothoff (and other contributing authors)
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
 
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING.  If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
 
 /**
  * @file src/transport/gnunet-transport-wlan-helper.c
@@ -28,8 +28,36 @@
  * gnunet
  */
 
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <netpacket/packet.h>
+#include <linux/if_ether.h>
+#include <linux/if.h>
+#include <linux/wireless.h>
+#include <netinet/in.h>
+#include <linux/if_tun.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <dirent.h>
+//#include <sys/utsname.h>
+#include <sys/param.h>
 
-#include "platform.h"
+/*
+ //#include <resolv.h>
+ #include <string.h>
+ #include <utime.h>
+ //#include <unistd.h>
+ #include <getopt.h>
+ */
+//#include "platform.h"
 #include "gnunet_constants.h"
 #include "gnunet_os_lib.h"
 #include "gnunet_transport_plugin.h"
@@ -39,16 +67,92 @@
 #include "gnunet_common.h"
 #include "gnunet-transport-wlan-helper.h"
 #include "gnunet_crypto_lib.h"
-#include "ieee80211_radiotap.h"
+
 #include <pcap.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 
+#include "wlan/radiotap-parser.h"
+/* radiotap-parser defines types like u8 that
+ * ieee80211_radiotap.h needs
+ *
+ * we use our local copy of ieee80211_radiotap.h
+ *
+ * - since we can't support extensions we don't understand
+ * - since linux does not include it in userspace headers
+ */
+#include "wlan/ieee80211_radiotap.h"
+#include "wlan/crctable_osdep.h"
+#include "wlan/loopback_helper.h"
 
+#define ARPHRD_IEEE80211        801
+#define ARPHRD_IEEE80211_PRISM  802
+#define ARPHRD_IEEE80211_FULL   803
 
+int first;
+int closeprog;
 
+#include "wlan/helper_common.h"
+#include "wlan/loopback_helper.h"
 
+#define DEBUG 1
+
+typedef enum
+{
+  DT_NULL = 0,
+  DT_WLANNG,
+  DT_HOSTAP,
+  DT_MADWIFI,
+  DT_MADWIFING,
+  DT_BCM43XX,
+  DT_ORINOCO,
+  DT_ZD1211RW,
+  DT_ACX,
+  DT_MAC80211_RT,
+  DT_AT76USB,
+  DT_IPW2200
+
+} DRIVER_TYPE;
+
+static const char * szaDriverTypes[] =
+  { [DT_NULL] = "Unknown", [DT_WLANNG] = "Wlan-NG", [DT_HOSTAP] = "HostAP",
+      [DT_MADWIFI] = "Madwifi", [DT_MADWIFING] = "Madwifi-NG",
+      [DT_BCM43XX] = "BCM43xx", [DT_ORINOCO] = "Orinoco",
+      [DT_ZD1211RW] = "ZD1211RW", [DT_ACX] = "ACX",
+      [DT_MAC80211_RT] = "Mac80211-Radiotap", [DT_AT76USB] = "Atmel 76_usb",
+      [DT_IPW2200] = "ipw2200" };
+
+struct Hardware_Infos
+{
+
+  struct sendbuf *write_pout;
+  int fd_in, arptype_in;
+  int fd_out, arptype_out;
+  int fd_main;
+  int fd_rtc;
+
+  DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */
+
+  FILE *f_cap_in;
+
+  struct pcap_file_header pfh_in;
+
+  int sysfs_inject;
+  int channel;
+  int freq;
+  int rate;
+  int tx_power;
+  char *wlanctlng; /* XXX never set */
+  char *iwpriv;
+  char *iwconfig;
+  char *ifconfig;
+  char *iface;
+  char *main_if;
+  unsigned char pl_mac[6];
+  int inject_wlanng;
+};
+
 //#include "radiotap.h"
 
 // mac of this node
@@ -57,20 +161,11 @@
 
 /* wifi bitrate to use in 500kHz units */
 
-static const u8 u8aRatesToUse[] = {
+static const u8 u8aRatesToUse[] =
+  {
 
-       54*2,
-       48*2,
-       36*2,
-       24*2,
-       18*2,
-       12*2,
-       9*2,
-       11*2,
-       11, // 5.5
-       2*2,
-       1*2
-};
+  54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5
+      2 * 2, 1 * 2 };
 
 #define        OFFSET_FLAGS 0x10
 #define        OFFSET_RATE 0x11
@@ -78,809 +173,813 @@
 // this is where we store a summary of the
 // information from the radiotap header
 
-typedef struct  {
-       int m_nChannel;
-       int m_nChannelFlags;
-       int m_nRate;
-       int m_nAntenna;
-       int m_nRadiotapFlags;
-} __attribute__((packed)) PENUMBRA_RADIOTAP_DATA;
+typedef struct
+{
+  int m_nChannel;
+  int m_nChannelFlags;
+  int m_nRate;
+  int m_nAntenna;
+  int m_nRadiotapFlags;
+}__attribute__((packed)) PENUMBRA_RADIOTAP_DATA;
 
+static void
+sigfunc_hw(int sig)
+{
+  closeprog = 1;
+}
+
 void
 Dump(u8 * pu8, int nLength)
 {
-       char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1;
-       unsigned char baaLast[2][16];
-       uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0;
+  char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1;
+  unsigned char baaLast[2][16];
+  uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0;
 
-       buf = szBuf;
-       szChar[0] = '\0';
+  buf = szBuf;
+  szChar[0] = '\0';
 
-       for (n = 0; n < nLength; n++) {
-               baaLast[(nLine&1)^1][n&0xf] = pu8[n];
-               if ((pu8[n] < 32) || (pu8[n] >= 0x7f))
-                       szChar[n&0xf] = '.';
-               else
-                       szChar[n&0xf] = pu8[n];
-               szChar[(n&0xf)+1] = '\0';
-               nPos += sprintf(&sz[nPos], "%02X ",
-                       baaLast[(nLine&1)^1][n&0xf]);
-               if ((n&15) != 15)
-                       continue;
-               if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) {
-                       nSameCount++;
-               } else {
-                       if (nSameCount)
-                               buf += sprintf(buf, "(repeated %d times)\n",
-                                       nSameCount);
-                       buf += sprintf(buf, "%04x: %s %s\n",
-                               nStart, sz, szChar);
-                       nSameCount = 0;
-                       printf("%s", szBuf);
-                       buf = szBuf;
-               }
-               nPos = 0; nStart = n+1; nLine++;
-               fFirst = 0; sz[0] = '\0'; szChar[0] = '\0';
-       }
-       if (nSameCount)
-               buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
+  for (n = 0; n < nLength; n++)
+    {
+      baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n];
+      if ((pu8[n] < 32) || (pu8[n] >= 0x7f))
+        szChar[n & 0xf] = '.';
+      else
+        szChar[n & 0xf] = pu8[n];
+      szChar[(n & 0xf) + 1] = '\0';
+      nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]);
+      if ((n & 15) != 15)
+        continue;
+      if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst))
+        {
+          nSameCount++;
+        }
+      else
+        {
+          if (nSameCount)
+            buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
+          buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar);
+          nSameCount = 0;
+          printf("%s", szBuf);
+          buf = szBuf;
+        }
+      nPos = 0;
+      nStart = n + 1;
+      nLine++;
+      fFirst = 0;
+      sz[0] = '\0';
+      szChar[0] = '\0';
+    }
+  if (nSameCount)
+    buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
 
-       buf += sprintf(buf, "%04x: %s", nStart, sz);
-       if (n & 0xf) {
-               *buf++ = ' ';
-               while (n & 0xf) {
-                       buf += sprintf(buf, "   ");
-                       n++;
-               }
-       }
-       buf += sprintf(buf, "%s\n", szChar);
-       printf("%s", szBuf);
+  buf += sprintf(buf, "%04x: %s", nStart, sz);
+  if (n & 0xf)
+    {
+      *buf++ = ' ';
+      while (n & 0xf)
+        {
+          buf += sprintf(buf, "   ");
+          n++;
+        }
+    }
+  buf += sprintf(buf, "%s\n", szChar);
+  printf("%s", szBuf);
 }
 
-
 void
 usage()
 {
-       printf(
-           "Usage: wlan-hwd [options] <interface>\n\nOptions\n"
-           "-f/--fcs           Mark as having FCS (CRC) already\n"
-           "                   (pkt ends with 4 x sacrificial - chars)\n"
-           "Example:\n"
-           "  echo -n mon0 > /sys/class/ieee80211/phy0/add_iface\n"
-           "  iwconfig mon0 mode monitor\n"
-           "  ifconfig mon0 up\n"
-           "  wlan-hwd mon0        Spam down mon0 with\n"
-           "                       radiotap header first\n"
-           "\n");
-       exit(1);
+  printf("Usage: wlan-hwd [options] <interface>\n\nOptions\n"
+    "-f/--fcs           Mark as having FCS (CRC) already\n"
+    "                   (pkt ends with 4 x sacrificial - chars)\n"
+    "Example:\n"
+    "  echo -n mon0 > /sys/class/ieee80211/phy0/add_iface\n"
+    "  iwconfig mon0 mode monitor\n"
+    "  ifconfig mon0 up\n"
+    "  wlan-hwd mon0        Spam down mon0 with\n"
+    "                       radiotap header first\n"
+    "\n");
+  exit(1);
 }
 
-int flagHelp = 0, flagMarkWithFCS = 0;
-int flagVerbose = 0;
+void
+packet_callback(unsigned char *Args, const struct pcap_pkthdr* Pkthdr,
+    unsigned char *Packet)
+{
+  fprintf(stderr, "+");
+  fflush(stderr);
+}
 
+unsigned long
+calc_crc_osdep(unsigned char * buf, int len)
+{
+  unsigned long crc = 0xFFFFFFFF;
 
-/*
- * Radiotap parser
- *
- * Copyright 2007              Andy Green <address@hidden>
- */
+  for (; len > 0; len--, buf++)
+    crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
 
-/**
- * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization
- * @param iterator: radiotap_iterator to initialize
- * @param radiotap_header: radiotap header to parse
- * @param max_length: total length we can parse into (eg, whole packet length)
- *
- * @return 0 or a negative error code if there is a problem.
- *
- * This function initializes an opaque iterator struct which can then
- * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap
- * argument which is present in the header.  It knows about extended
- * present headers and handles them.
- *
- * How to use:
- * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
- * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
- * checking for a good 0 return code.  Then loop calling
- * __ieee80211_radiotap_iterator_next()... it returns either 0,
- * -ENOENT if there are no more args to parse, or -EINVAL if there is a 
problem.
- * The iterator's this_arg member points to the start of the argument
- * associated with the current argument index that is present, which can be
- * found in the iterator's this_arg_index member.  This arg index corresponds
- * to the IEEE80211_RADIOTAP_... defines.
- *
- * Radiotap header length:
- * You can find the CPU-endian total radiotap header length in
- * iterator->max_length after executing ieee80211_radiotap_iterator_init()
- * successfully.
- *
- * Example code:
- * See Documentation/networking/radiotap-headers.txt
- */
+  return (~crc);
+}
 
-int ieee80211_radiotap_iterator_init(
-    struct ieee80211_radiotap_iterator *iterator,
-    struct ieee80211_radiotap_header *radiotap_header,
-    int max_length)
+/* CRC checksum verification routine */
+
+int
+check_crc_buf_osdep(unsigned char *buf, int len)
 {
-       /* Linux only supports version 0 radiotap format */
-       if (radiotap_header->it_version)
-               return -EINVAL;
+  unsigned long crc;
 
-       /* sanity check for allowed length and radiotap length field */
-       if (max_length < le16_to_cpu(radiotap_header->it_len))
-               return -EINVAL;
+  if (len < 0)
+    return 0;
 
-       iterator->rtheader = radiotap_header;
-       iterator->max_length = le16_to_cpu(radiotap_header->it_len);
-       iterator->arg_index = 0;
-       iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
-       iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header);
-       iterator->this_arg = 0;
+  crc = calc_crc_osdep(buf, len);
+  buf += len;
+  return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc
+      >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
+}
 
-       /* find payload start allowing for extended bitmap(s) */
+/* Search a file recursively */
+static char *
+searchInside(const char * dir, const char * filename)
+{
+  char * ret;
+  char * curfile;
+  struct stat sb;
+  int len, lentot;
+  DIR *dp;
+  struct dirent *ep;
 
-       if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) {
-               while (le32_to_cpu(*((u32 *)iterator->arg)) &
-                                  (1<<IEEE80211_RADIOTAP_EXT)) {
-                       iterator->arg += sizeof(u32);
+  dp = opendir(dir);
+  if (dp == NULL)
+    {
+      return NULL;
+    }
 
-                       /*
-                        * check for insanity where the present bitmaps
-                        * keep claiming to extend up to or even beyond the
-                        * stated radiotap header length
-                        */
+  len = strlen(filename);
+  lentot = strlen(dir) + 256 + 2;
+  curfile = (char *) calloc(1, lentot);
 
-                       if (((ulong)iterator->arg -
-                            (ulong)iterator->rtheader) > iterator->max_length)
-                               return -EINVAL;
-               }
+  while ((ep = readdir(dp)) != NULL)
+    {
 
-               iterator->arg += sizeof(u32);
+      memset(curfile, 0, lentot);
+      sprintf(curfile, "%s/%s", dir, ep->d_name);
 
-               /*
-                * no need to check again for blowing past stated radiotap
-                * header length, because ieee80211_radiotap_iterator_next
-                * checks it before it is dereferenced
-                */
-       }
+      //Checking if it's the good file
+      if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename))
+        {
+          (void) closedir(dp);
+          return curfile;
+        }
+      lstat(curfile, &sb);
 
-       /* we are all initialized happily */
-
-       return 0;
+      //If it's a directory and not a link, try to go inside to search
+      if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode))
+        {
+          //Check if the directory isn't "." or ".."
+          if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name))
+            {
+              //Recursive call
+              ret = searchInside(curfile, filename);
+              if (ret != NULL)
+                {
+                  (void) closedir(dp);
+                  free(curfile);
+                  return ret;
+                }
+            }
+        }
+    }
+  (void) closedir(dp);
+  free(curfile);
+  return NULL;
 }
 
+/* Search a wireless tool and return its path */
+static char *
+wiToolsPath(const char * tool)
+{
+  char * path;
+  int i, nbelems;
+  static const char * paths[] =
+    { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin",
+        "/usr/local/bin", "/tmp" };
 
-/**
- * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
- * @param iterator: radiotap_iterator to move to next arg (if any)
- *
- * @return 0 if there is an argument to handle,
- * -ENOENT if there are no more args or -EINVAL
- * if there is something else wrong.
- *
- * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*)
- * in this_arg_index and sets this_arg to point to the
- * payload for the field.  It takes care of alignment handling and extended
- * present fields.  this_arg can be changed by the caller (eg,
- * incremented to move inside a compound argument like
- * IEEE80211_RADIOTAP_CHANNEL).  The args pointed to are in
- * little-endian format whatever the endianess of your CPU.
- */
+  nbelems = sizeof(paths) / sizeof(char *);
 
-int ieee80211_radiotap_iterator_next(
-    struct ieee80211_radiotap_iterator *iterator)
+  for (i = 0; i < nbelems; i++)
+    {
+      path = searchInside(paths[i], tool);
+      if (path != NULL)
+        return path;
+    }
+
+  return NULL;
+}
+
+static int
+linux_get_channel(struct Hardware_Infos *dev)
 {
+  struct iwreq wrq;
+  int fd, frequency;
+  int chan = 0;
 
-       /*
-        * small length lookup table for all radiotap types we heard of
-        * starting from b0 in the bitmap, so we can walk the payload
-        * area of the radiotap header
-        *
-        * There is a requirement to pad args, so that args
-        * of a given length must begin at a boundary of that length
-        * -- but note that compound args are allowed (eg, 2 x u16
-        * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
-        * a reliable indicator of alignment requirement.
-        *
-        * upper nybble: content alignment for arg
-        * lower nybble: content length for arg
-        */
+  memset(&wrq, 0, sizeof(struct iwreq));
 
-       static const u8 rt_sizes[] = {
-               [IEEE80211_RADIOTAP_TSFT] = 0x88,
-               [IEEE80211_RADIOTAP_FLAGS] = 0x11,
-               [IEEE80211_RADIOTAP_RATE] = 0x11,
-               [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
-               [IEEE80211_RADIOTAP_FHSS] = 0x22,
-               [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
-               [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
-               [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
-               [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
-               [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
-               [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
-               [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
-               [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
-               [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
-               [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
-               [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
-               [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
-               [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
-               /*
-                * add more here as they are defined in
-                * include/net/ieee80211_radiotap.h
-                */
-       };
+  if (dev->main_if)
+    strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ );
+  else
+    strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ );
 
-       /*
-        * for every radiotap entry we can at
-        * least skip (by knowing the length)...
-        */
+  fd = dev->fd_in;
+  if (dev->drivertype == DT_IPW2200)
+    fd = dev->fd_main;
 
-       while (iterator->arg_index < sizeof(rt_sizes)) {
-               int hit = 0;
-               int pad;
+  if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0)
+    return (-1);
 
-               if (!(iterator->bitmap_shifter & 1))
-                       goto next_entry; /* arg not present */
+  frequency = wrq.u.freq.m;
+  if (frequency > 100000000)
+    frequency /= 100000;
+  else if (frequency > 1000000)
+    frequency /= 1000;
 
-               /*
-                * arg is present, account for alignment padding
-                *  8-bit args can be at any alignment
-                * 16-bit args must start on 16-bit boundary
-                * 32-bit args must start on 32-bit boundary
-                * 64-bit args must start on 64-bit boundary
-                *
-                * note that total arg size can differ from alignment of
-                * elements inside arg, so we use upper nybble of length
-                * table to base alignment on
-                *
-                * also note: these alignments are ** relative to the
-                * start of the radiotap header **.  There is no guarantee
-                * that the radiotap header itself is aligned on any
-                * kind of boundary.
-                */
+  if (frequency > 1000)
+    chan = getChannelFromFrequency(frequency);
+  else
+    chan = frequency;
 
-               pad = (((ulong)iterator->arg) -
-                       ((ulong)iterator->rtheader)) &
-                       ((rt_sizes[iterator->arg_index] >> 4) - 1);
+  return chan;
+}
 
-               if (pad)
-                       iterator->arg_index +=
-                               (rt_sizes[iterator->arg_index] >> 4) - pad;
+static int
+linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count,
+    struct rx_info * ri)
+{
+  unsigned char tmpbuf[4096];
 
-               /*
-                * this is what we will return to user, but we need to
-                * move on first so next call has something fresh to test
-                */
-               iterator->this_arg_index = iterator->arg_index;
-               iterator->this_arg = iterator->arg;
-               hit = 1;
+  int caplen, n, got_signal, got_noise, got_channel, fcs_removed;
 
-               /* internally move on the size of this arg */
-               iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
+  caplen = n = got_signal = got_noise = got_channel = fcs_removed = 0;
 
-               /*
-                * check for insanity where we are given a bitmap that
-                * claims to have more arg content than the length of the
-                * radiotap section.  We will normally end up equalling this
-                * max_length on the last arg, never exceeding it.
-                */
+  if ((unsigned) count > sizeof(tmpbuf))
+    return (-1);
+  caplen = read(dev->fd_in, tmpbuf, count);
+  if (0 > caplen)
+    {
+      if (errno == EAGAIN)
+        return (0);
 
-               if (((ulong)iterator->arg - (ulong)iterator->rtheader) >
-                   iterator->max_length)
-                       return -EINVAL;
+      perror("read failed");
+      return (-1);
+    }
 
-       next_entry:
-               iterator->arg_index++;
-               if (unlikely((iterator->arg_index & 31) == 0)) {
-                       /* completed current u32 bitmap */
-                       if (iterator->bitmap_shifter & 1) {
-                               /* b31 was set, there is more */
-                               /* move to next u32 bitmap */
-                               iterator->bitmap_shifter =
-                                   le32_to_cpu(*iterator->next_bitmap);
-                               iterator->next_bitmap++;
-                       } else {
-                               /* no more bitmaps: end */
-                               iterator->arg_index = sizeof(rt_sizes);
-                       }
-               } else { /* just try the next bit */
-                       iterator->bitmap_shifter >>= 1;
-               }
+  memset(buf, 0, sizeof(buf));
 
-               /* if we found a valid arg earlier, return it now */
-               if (hit)
-                       return 0;
-       }
+  /* XXX */
+  if (ri)
+    memset(ri, 0, sizeof(*ri));
 
-       /* we don't know how to handle any more args, we're done */
-       return -ENOENT;
-}
+  if (dev->arptype_in == ARPHRD_IEEE80211_PRISM)
+    {
+      /* skip the prism header */
+      if (tmpbuf[7] == 0x40)
+        {
+          /* prism54 uses a different format */
+          if (ri)
+            {
+              ri->ri_power = tmpbuf[0x33];
+              ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
+              ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
 
-#define FIFO_FILE1       "/tmp/MYFIFOin"
-#define FIFO_FILE2       "/tmp/MYFIFOout"
-#define MAXLINE         4096
+              got_signal = 1;
+              got_noise = 1;
+            }
 
-static int first;
-static int closeprog;
+          n = 0x40;
+        }
+      else
+        {
+          if (ri)
+            {
+              ri->ri_mactime = *(u_int64_t*) (tmpbuf + 0x5C - 48);
+              ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
+              ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
+              ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
+              ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
 
-static void 
-sigfunc(int sig)
-{
-  closeprog = 1;  
-  unlink(FIFO_FILE1);
-  unlink(FIFO_FILE2);
-}
+              got_channel = 1;
+              got_signal = 1;
+              got_noise = 1;
+            }
 
-struct sendbuf {
-  int pos;
-  int size;
-  char buf[MAXLINE * 2];
-};
+          n = *(int *) (tmpbuf + 4);
+        }
 
-static void
-stdin_send (void *cls,
-                      void *client,
-                      const struct GNUNET_MessageHeader *hdr)
-{
-  struct sendbuf *write_pout = cls;
-  int sendsize;
-  struct GNUNET_MessageHeader newheader;
-  char * from;
-  char * to;
+      if (n < 8 || n >= caplen)
+        return (0);
+    }
 
-  sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ;
+  if (dev->arptype_in == ARPHRD_IEEE80211_FULL)
+    {
+      struct ieee80211_radiotap_iterator iterator;
+      struct ieee80211_radiotap_header *rthdr;
 
+      rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
 
-  if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){
-    fprintf(stderr, "Function stdin_send: wrong packet type\n");
-    exit(1);
-  }
-  if((sendsize + write_pout->size) > MAXLINE * 2){
-    fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
-    exit(1);
-  }
+      if (ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen) < 0)
+        return (0);
 
+      /* go through the radiotap arguments we have been given
+       * by the driver
+       */
 
-  newheader.size = htons(sendsize);
-  newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+      while (ri && (ieee80211_radiotap_iterator_next(&iterator) >= 0))
+        {
 
+          switch (iterator.this_arg_index)
+            {
 
-  to = write_pout->buf + write_pout->size;
-  memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader));
-  write_pout->size += sizeof(struct GNUNET_MessageHeader);
+          case IEEE80211_RADIOTAP_TSFT:
+            ri->ri_mactime = le64_to_cpu(*((uint64_t*) iterator.this_arg));
+            break;
 
-  from = ((char *) hdr) + sizeof(struct RadiotapHeader) + sizeof(struct 
GNUNET_MessageHeader);
-  to = write_pout->buf + write_pout->size;
-  memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader));
-  write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader);
-}
+          case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
+            if (!got_signal)
+              {
+                if (*iterator.this_arg < 127)
+                  ri->ri_power = *iterator.this_arg;
+                else
+                  ri->ri_power = *iterator.this_arg - 255;
 
-static void
-file_in_send (void *cls,
-             void *client,
-             const struct GNUNET_MessageHeader *hdr)
-{
-  struct sendbuf * write_std = cls;
-  uint16_t sendsize;
+                got_signal = 1;
+              }
+            break;
 
-  sendsize = ntohs(hdr->size);
+          case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
+            if (!got_signal)
+              {
+                if (*iterator.this_arg < 127)
+                  ri->ri_power = *iterator.this_arg;
+                else
+                  ri->ri_power = *iterator.this_arg - 255;
 
-  if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
-    {
-      fprintf (stderr, 
-              "Function file_in_send: wrong packet type\n");
-      exit(1);
-    }
-  if((sendsize + write_std->size) > MAXLINE * 2){
-    fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
-    exit(1);
-  }
+                got_signal = 1;
+              }
+            break;
 
-  memcpy(write_std->buf + write_std->size, hdr, sendsize);
-  write_std->size += sendsize;
-}
+          case IEEE80211_RADIOTAP_DBM_ANTNOISE:
+            if (!got_noise)
+              {
+                if (*iterator.this_arg < 127)
+                  ri->ri_noise = *iterator.this_arg;
+                else
+                  ri->ri_noise = *iterator.this_arg - 255;
 
-/**
- * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for 
plugin
- * @param buffer pointer to buffer for the message
- * @param mac pointer to the mac address
- * @return number of bytes written
- */
+                got_noise = 1;
+              }
+            break;
 
-int
-send_mac_to_plugin(char* buffer, char * mac){
+          case IEEE80211_RADIOTAP_DB_ANTNOISE:
+            if (!got_noise)
+              {
+                if (*iterator.this_arg < 127)
+                  ri->ri_noise = *iterator.this_arg;
+                else
+                  ri->ri_noise = *iterator.this_arg - 255;
 
-  struct Wlan_Helper_Control_Message macmsg;
+                got_noise = 1;
+              }
+            break;
 
+          case IEEE80211_RADIOTAP_ANTENNA:
+            ri->ri_antenna = *iterator.this_arg;
+            break;
 
+          case IEEE80211_RADIOTAP_CHANNEL:
+            ri->ri_channel = *iterator.this_arg;
+            got_channel = 1;
+            break;
 
-  memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
-  macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
-  macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+          case IEEE80211_RADIOTAP_RATE:
+            ri->ri_rate = (*iterator.this_arg) * 500000;
+            break;
 
-  memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
-  return sizeof(struct Wlan_Helper_Control_Message);
-}
+          case IEEE80211_RADIOTAP_FLAGS:
+            /* is the CRC visible at the end?
+             * remove
+             */
+            if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
+              {
+                fcs_removed = 1;
+                caplen -= 4;
+              }
 
-int
-testmode(int argc, char *argv[])
-{
-  struct stat st;
-  int erg;
+            if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
+              return (0);
 
-  FILE *fpin;
-  FILE *fpout;
+            break;
 
-  int fdpin;
-  int fdpout;
-
-  //make the fifos if needed
-  if (0 != stat(FIFO_FILE1, &st))
-    {
-      if (0 == stat(FIFO_FILE2, &st))
-        {
-        fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
-          exit(1);
+            }
         }
 
-      umask(0);
-      erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
-      erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
+      n = le16_to_cpu(rthdr->it_len);
 
+      if (n <= 0 || n >= caplen)
+        return (0);
     }
-  else
-    {
 
-      if (0 != stat(FIFO_FILE2, &st))
-        {
-        fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
-          exit(1);
-        }
+  caplen -= n;
 
+  //detect fcs at the end, even if the flag wasn't set and remove it
+  if (fcs_removed == 0 && check_crc_buf_osdep(tmpbuf + n, caplen - 4) == 1)
+    {
+      caplen -= 4;
     }
 
-  if (strstr(argv[2], "1"))
+  memcpy(buf, tmpbuf + n, caplen);
+
+  if (ri && !got_channel)
+    ri->ri_channel = linux_get_channel(dev);
+
+  return (caplen);
+}
+
+static int
+linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int 
count)
+{
+  int ret, usedrtap = 0;
+  unsigned short int *p_rtlen;
+
+  unsigned char * u8aRadiotap = buf;
+
+  /* Pointer to the radiotap header length field for later use. */
+  p_rtlen = (unsigned short int*) (u8aRadiotap + 2);
+  usedrtap = 0;
+  ret = write(dev->fd_out, buf, count);
+
+  if (ret < 0)
     {
-      //fprintf(stderr, "First\n");
-      first = 1;
-      fpin = fopen(FIFO_FILE1, "r");
-      if (NULL == fpin)
+      if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno
+          == ENOMEM)
         {
-        fprintf(stderr, "fopen of read FIFO_FILE1\n");
-          exit(1);
+          usleep(10000);
+          return (0);
         }
-      if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
-        {
-        fprintf(stderr, "fopen of write FIFO_FILE2\n");
-          exit(1);
-        }
 
+      perror("write failed");
+      return (-1);
     }
-  else
+
+  /* radiotap header length is stored little endian on all systems */
+  if (usedrtap)
+    ret -= letoh16(*p_rtlen);
+
+  if (ret < 0)
     {
-      first = 0;
-      //fprintf(stderr, "Second\n");
-      if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
+      if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno
+          == ENOMEM)
         {
-        fprintf(stderr, "fopen of write FIFO_FILE1\n");
-          exit(1);
+          usleep(10000);
+          return (0);
         }
-      if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
-        {
-        fprintf(stderr, "fopen of read FIFO_FILE2\n");
-          exit(1);
-        }
 
+      perror("write failed");
+      return (-1);
     }
 
-  fdpin = fileno(fpin);
-  if (fdpin >= FD_SETSIZE)
+  return (ret);
+}
+
+static int
+openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype,
+    uint8_t *mac)
+{
+  struct ifreq ifr;
+  struct iwreq wrq;
+  struct packet_mreq mr;
+  struct sockaddr_ll sll;
+
+  /* find the interface index */
+
+  memset(&ifr, 0, sizeof(ifr));
+  strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1);
+
+  if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
     {
-      fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
-          (unsigned int) FD_SETSIZE);
-      close(fdpin);
-      return -1;
+      printf("Interface %s: \n", iface);
+      perror("ioctl(SIOCGIFINDEX) failed");
+      return (1);
     }
 
-  fdpout = fileno(fpout);
-  if (fdpout >= FD_SETSIZE)
+  memset(&sll, 0, sizeof(sll));
+  sll.sll_family = AF_PACKET;
+  sll.sll_ifindex = ifr.ifr_ifindex;
+
+  switch (dev->drivertype)
     {
-      fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
-          (unsigned int) FD_SETSIZE);
-      close(fdpout);
-      return -1;
+  default:
+    sll.sll_protocol = htons(ETH_P_ALL);
+    break;
+    }
 
+  /* lookup the hardware type */
+
+  if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
+    {
+      printf("Interface %s: \n", iface);
+      perror("ioctl(SIOCGIFHWADDR) failed");
+      return (1);
     }
 
-  signal(SIGINT, &sigfunc);
-  signal(SIGTERM, &sigfunc);
+  /* lookup iw mode */
+  memset(&wrq, 0, sizeof(struct iwreq));
+  strncpy(wrq.ifr_name, iface, IFNAMSIZ);
 
-  char readbuf[MAXLINE];
-  int readsize = 0;
-  struct sendbuf write_std;
-  write_std.size = 0;
-  write_std.pos = 0;
+  if (ioctl(fd, SIOCGIWMODE, &wrq) < 0)
+    {
+      /* most probably not supported (ie for rtap ipw interface) *
+       * so just assume its correctly set...                     */
+      wrq.u.mode = IW_MODE_MONITOR;
+    }
 
-  struct sendbuf write_pout;
-  write_pout.size = 0;
-  write_pout.pos = 0;
+  if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family
+      != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family
+      != ARPHRD_IEEE80211_FULL) || (wrq.u.mode != IW_MODE_MONITOR))
+    {
+      printf("Error: %s not in monitor mode\n", iface);
+      return (1);
+    }
 
-  int ret = 0;
-  int maxfd = 0;
+  /* Is interface st to up, broadcast & running ? */
+  if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
+    {
+      /* Bring interface up*/
+      ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
 
-  fd_set rfds;
-  fd_set wfds;
-  struct timeval tv;
-  int retval;
+      if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
+        {
+          perror("ioctl(SIOCSIFFLAGS) failed");
+          return (1);
+        }
+    }
+  /* bind the raw socket to the interface */
 
+  if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0)
+    {
+      printf("Interface %s: \n", iface);
+      perror("bind(ETH_P_ALL) failed");
+      return (1);
+    }
 
+  /* lookup the hardware type */
 
-  struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
-  struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
+  if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
+    {
+      printf("Interface %s: \n", iface);
+      perror("ioctl(SIOCGIFHWADDR) failed");
+      return (1);
+    }
 
-  stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
-  file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
+  memcpy(mac, (unsigned char*) ifr.ifr_hwaddr.sa_data, 6);
 
-  //send mac first
+  *arptype = ifr.ifr_hwaddr.sa_family;
 
-  struct MacAddress macaddr;
+  if (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family
+      != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family
+      != ARPHRD_IEEE80211_FULL)
+    {
+      if (ifr.ifr_hwaddr.sa_family == 1)
+        fprintf(stderr, "\nARP linktype is set to 1 (Ethernet) ");
+      else
+        fprintf(stderr, "\nUnsupported hardware link type %4d ",
+            ifr.ifr_hwaddr.sa_family);
 
-  //Send random mac address
-  macaddr.mac[0] = 0x13;
-  macaddr.mac[1] = 0x22;
-  macaddr.mac[2] = 0x33;
-  macaddr.mac[3] = 0x44;
-  macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
-  macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
+      fprintf(stderr, "- expected ARPHRD_IEEE80211,\nARPHRD_IEEE80211_"
+        "FULL or ARPHRD_IEEE80211_PRISM instead.  Make\n"
+        "sure RFMON is enabled: run 'airmon-ng start %s"
+        " <#>'\nSysfs injection support was not found "
+        "either.\n\n", iface);
+      return (1);
+    }
 
-  write_std.size = send_mac_to_plugin((char *) &write_std.buf, macaddr.mac);
+  /* enable promiscuous mode */
 
-  /*
-  //wait
-  tv.tv_sec = 2;
-  tv.tv_usec = 0;
-  retval = select(0, NULL, NULL, NULL, &tv);
+  memset(&mr, 0, sizeof(mr));
+  mr.mr_ifindex = sll.sll_ifindex;
+  mr.mr_type = PACKET_MR_PROMISC;
 
+  if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0)
+    {
+      perror("setsockopt(PACKET_MR_PROMISC) failed");
+      return (1);
+    }
 
-  tv.tv_sec = 3;
-  tv.tv_usec = 0;
-  // if there is something to write
-  FD_ZERO(&wfds);
-  FD_SET(STDOUT_FILENO, &wfds);
+  return (0);
+}
 
-  retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv);
+int
+wlaninit(struct Hardware_Infos * dev, char *iface)
+{
 
-  if (FD_ISSET(STDOUT_FILENO, &wfds))
+  char *iwpriv;
+  char strbuf[512];
+  dev->inject_wlanng = 1;
+  dev->rate = 2; /* default to 1Mbps if nothing is set */
+
+  /* open raw socks */
+  dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+  if (0 > dev->fd_in)
     {
-      ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size
-          - write_std.pos);
+      perror("socket(PF_PACKET) failed at fd_in");
+      if (getuid() != 0)
+        fprintf(stderr, "This program requires root privileges.\n");
+      return (1);
+    }
 
-      if (0 > ret)
-        {
-          closeprog = 1;
-          fprintf(stderr, "Write ERROR to STDOUT");
-          exit(1);
-        }
-      else
-        {
-          write_std.pos += ret;
-          // check if finished
-          if (write_std.pos == write_std.size)
-            {
-              write_std.pos = 0;
-              write_std.size = 0;
-            }
-        }
+  dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) );
+  if (0 > dev->fd_main)
+    {
+      perror("socket(PF_PACKET) failed at fd_main");
+      if (getuid() != 0)
+        fprintf(stderr, "This program requires root privileges.\n");
+      return (1);
     }
 
-  memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
-  write_std.size = sizeof(struct Wlan_Helper_Control_Message);
-  */
+  /* Check iwpriv existence */
 
-  //wait
-  tv.tv_sec = 2;
-  tv.tv_usec = 0;
-  retval = select(0, NULL, NULL, NULL, &tv);
+  iwpriv = wiToolsPath("iwpriv");
+  dev->iwpriv = iwpriv;
+  dev->iwconfig = wiToolsPath("iwconfig");
+  dev->ifconfig = wiToolsPath("ifconfig");
 
-  while (0 == closeprog)
+  if (!iwpriv)
     {
+      fprintf(stderr, "Can't find wireless tools, exiting.\n");
+      goto close_in;
+    }
 
-      maxfd = 0;
+  dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+  if (0 > dev->fd_out)
+    {
+      perror("socket(PF_PACKET) failed at fd_out");
+      goto close_in;
+    }
 
-      //set timeout
-      tv.tv_sec = 5;
-      tv.tv_usec = 0;
+  /* figure out device type */
 
-      FD_ZERO(&rfds);
-      // if output queue is empty
-      if (0 == write_pout.size)
-        {
-          FD_SET(STDIN_FILENO, &rfds);
+  /* mac80211 radiotap injection
+   * detected based on interface called mon...
+   * since mac80211 allows multiple virtual interfaces
+   *
+   * note though that the virtual interfaces are ultimately using a
+   * single physical radio: that means for example they must all
+   * operate on the same channel
+   */
 
-        }
-      if (0 == write_std.size)
-        {
-          FD_SET(fdpin, &rfds);
-          maxfd = fdpin;
-        }
-      FD_ZERO(&wfds);
-      // if there is something to write
-      if (0 < write_std.size){
-        FD_SET(STDOUT_FILENO, &wfds);
-        maxfd = MAX(maxfd, STDOUT_FILENO);
-      }
+  /* mac80211 stack detection */
+  memset(strbuf, 0, sizeof(strbuf));
+  snprintf(strbuf, sizeof(strbuf) - 1,
+      "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface);
 
-      if (0 < write_pout.size){
-        FD_SET(fdpout, &wfds);
-        maxfd = MAX(maxfd, fdpout);
-      }
+  if (system(strbuf) == 0)
+    dev->drivertype = DT_MAC80211_RT;
 
+  else
+    {
+      // At the moment only mac80211 tested
+      return 1;
+    }
 
-      retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
+#ifdef DEBUG
+  fprintf(stderr, "Interface %s -> driver: %s\n", iface,
+      szaDriverTypes[dev->drivertype]);
+#endif
 
-      if (-1 == retval && EINTR == errno)
-        {
-          continue;
-        }
-      if (0 > retval)
-        {
-          fprintf(stderr, "select failed: %s\n", strerror(errno));
-          exit(1);
-        }
+  if (openraw(dev, iface, dev->fd_out, &dev->arptype_out, dev->pl_mac) != 0)
+    {
+      goto close_out;
+    }
 
-      if (FD_ISSET(STDOUT_FILENO, &wfds))
-        {
-          ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
-              write_std.size - write_std.pos);
+  dev->fd_in = dev->fd_out;
 
-          if (0 > ret)
-            {
-              closeprog = 1;
-              fprintf(stderr, "Write ERROR to STDOUT\n");
-              exit(1);
-            }
-          else
-            {
-              write_std.pos += ret;
-              // check if finished
-              if (write_std.pos == write_std.size)
-                {
-                  write_std.pos = 0;
-                  write_std.size = 0;
-                }
-            }
-        }
+  dev->arptype_in = dev->arptype_out;
 
-      if (FD_ISSET(fdpout, &wfds))
-        {
-          ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
-              - write_pout.pos);
+  return 0;
+  close_out: close(dev->fd_out);
+  close_in: close(dev->fd_in);
+  return 1;
+}
 
-          if (0 > ret)
-            {
-              closeprog = 1;
-              fprintf(stderr, "Write ERROR to fdpout\n");
-            }
-          else
-            {
-              write_pout.pos += ret;
-              // check if finished
-              if (write_pout.pos == write_pout.size)
-                {
-                  write_pout.pos = 0;
-                  write_pout.size = 0;
-                }
-            }
-        }
+static void
+stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+{
+  struct Hardware_Infos * dev = cls;
+  struct sendbuf *write_pout = dev->write_pout;
+  struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1];
+  int sendsize;
 
-      if (FD_ISSET(STDIN_FILENO, &rfds))
-        {
-          readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
+  unsigned char u8aRadiotap[] =
+    { 0x00, 0x00, // <-- radiotap version
+        0x0c, 0x00, // <- radiotap header length
+        0x04, 0x80, 0x00, 0x00, // <-- bitmap
+        0x00, // <-- rate
+        0x00, // <-- padding for natural alignment
+        0x18, 0x00, // <-- TX flags
+      };
 
-          if (0 > readsize)
-            {
-              closeprog = 1;
-              fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
-            }
-          else if (0 < readsize)
-            {
-              GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
-                  GNUNET_NO, GNUNET_NO);
+  sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send)
+      - sizeof(struct GNUNET_MessageHeader);
 
-            }
-          else
-            {
-              //eof
-              closeprog = 1;
-            }
-        }
+  if ((sendsize) > MAXLINE * 2)
+    {
+      fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
+      exit(1);
+    }
 
-      if (FD_ISSET(fdpin, &rfds))
-        {
-          readsize = read(fdpin, readbuf, sizeof(readbuf));
+  if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
+    {
+      fprintf(stderr, "Function stdin_send: wrong packet type\n");
+      exit(1);
+    }
 
-          if (0 > readsize)
-            {
-              closeprog = 1;
-              fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
-              closeprog = 1;
-            }
-          else if (0 < readsize)
-            {
-              GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
-                  GNUNET_NO, GNUNET_NO);
+  u8aRadiotap[8] = header->rate;
 
-            }
-          else
-            {
-              //eof
-              closeprog = 1;
-            }
-        }
+  switch (dev->drivertype)
+    {
 
-    }
+  case DT_MAC80211_RT:
+    memcpy(write_pout->buf, u8aRadiotap, sizeof(u8aRadiotap));
+    memcpy(write_pout->buf + sizeof(u8aRadiotap), write_pout->buf
+        + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader),
+        sendsize);
+    sendsize += sizeof(u8aRadiotap);
 
-  //clean up
-  fclose(fpout);
-  fclose(fpin);
-
-  if (1 == first)
-    {
-      unlink(FIFO_FILE1);
-      unlink(FIFO_FILE2);
+    //usedrtap = 1;
+    break;
+  default:
+    break;
     }
 
-  return (0);
+  write_pout->size = sendsize;
 }
 
-void packet_callback(unsigned char *Args,
-                      const struct pcap_pkthdr* Pkthdr,
-                      unsigned char *Packet)
+int
+maketest(unsigned char * buf)
 {
-fprintf(stderr, "+"); fflush(stderr);
+  unsigned char u8aRadiotap[] =
+    { 0x00, 0x00, // <-- radiotap version
+        0x0c, 0x00, // <- radiotap header length
+        0x04, 0x80, 0x00, 0x00, // <-- bitmap
+        0x00, // <-- rate
+        0x00, // <-- padding for natural alignment
+        0x18, 0x00, // <-- TX flags
+      };
+
+  static const uint8_t u8aIeeeHeader[] =
+    { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
+        //      b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
+        //      0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
+        0x00, 0x00, // Duration/ID
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
+        0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
+        0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
+        0x10, 0x86, //Sequence Control
+      };
+
+  static const char txt[] = "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
+
+  u8aRadiotap[8] = 8;
+  memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap));
+  struct ieee80211_frame * ieee = (struct ieee80211_frame *) u8aIeeeHeader;
+  memcpy(buf + sizeof(u8aRadiotap), ieee, sizeof(u8aIeeeHeader));
+  memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt));
+  return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt);
+
 }
 
-
 int
 hardwaremode(int argc, char *argv[])
 {
 
+  struct Hardware_Infos dev;
   struct ifreq ifreq;
-  char mac[6];
-  int SockFD;
+  struct rx_info * rxinfo;
+  uint8_t * mac = dev.pl_mac;
+  int fdpin, fdpout;
 
-  int fdpin;
-  int fdpout;
+  signal(SIGINT, &sigfunc_hw);
+  signal(SIGTERM, &sigfunc_hw);
 
-  pcap_t *ppcap = NULL;
-  char szErrbuf[PCAP_ERRBUF_SIZE];
-
-  SockFD = socket(AF_INET, SOCK_DGRAM, 0);
-
-  strcpy(ifreq.ifr_name, argv[1]);
-  if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0)
+  if (wlaninit(&dev, argv[1]))
     {
-      printf("SIOCGIFHWADDR(%s): %m\n", ifreq.ifr_name);
-      return 0;
+      return 1;
     }
 
-  //copy mac to mac array
-  memcpy(mac, ifreq.ifr_hwaddr.sa_data, sizeof(struct MacAddress));
-
   printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n",
       ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3],
       (int) mac[4], (int) mac[5]);
 
-  return 0;
-  // open the interface in pcap
-  ppcap = pcap_open_live(argv[1], 800, 1, 20, szErrbuf);
-  if (ppcap == NULL)
-    {
-      printf("Unable to open interface %s in pcap: %s\n", argv[1], szErrbuf);
-      return (1);
-    }
+  //return 0;
 
   char readbuf[MAXLINE];
   int readsize = 0;
@@ -892,6 +991,8 @@
   write_pout.size = 0;
   write_pout.pos = 0;
 
+  dev.write_pout = &write_pout;
+
   int ret = 0;
   int maxfd = 0;
 
@@ -901,13 +1002,11 @@
   int retval;
 
   struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
-  struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
 
-  fdpin = pcap_fileno(ppcap);
-  fdpout = pcap_fileno(ppcap);
+  fdpin = dev.fd_in;
+  fdpout = dev.fd_out;
 
-  stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
-  file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
+  stdin_mst = GNUNET_SERVER_mst_create(&stdin_send_hw, &dev);
 
   //send mac first
 
@@ -921,6 +1020,11 @@
   while (0 == closeprog)
     {
 
+      write_pout.size = maketest(write_pout.buf);
+      tv.tv_sec = 2;
+      tv.tv_usec = 0;
+      retval = select(0, NULL, NULL, NULL, &tv);
+
       maxfd = 0;
 
       //set timeout
@@ -936,8 +1040,8 @@
         }
       if (0 == write_std.size)
         {
-          FD_SET(fdpin, &rfds);
-          maxfd = fdpin;
+          //FD_SET(fdpin, &rfds);
+          //maxfd = fdpin;
         }
       FD_ZERO(&wfds);
       // if there is something to write
@@ -990,9 +1094,11 @@
 
       if (FD_ISSET(fdpout, &wfds))
         {
-          ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
-              - write_pout.pos);
 
+          ret = linux_write(&dev, write_pout.buf, write_pout.size);
+          //ret = write(fdpout, write_pout.buf + write_pout.pos, 
write_pout.size
+          //    - write_pout.pos);
+
           if (0 > ret)
             {
               closeprog = 1;
@@ -1002,11 +1108,17 @@
             {
               write_pout.pos += ret;
               // check if finished
-              if (write_pout.pos == write_pout.size)
+              if (write_pout.pos != write_pout.size && ret != 0)
                 {
+                  closeprog = 1;
+                  fprintf(stderr, "Write ERROR packet not in one piece send: 
%u, %u\n", write_pout.pos, write_pout.size);
+                }
+              else if (write_pout.pos == write_pout.size)
+                {
                   write_pout.pos = 0;
                   write_pout.size = 0;
                 }
+
             }
         }
 
@@ -1034,7 +1146,13 @@
 
       if (FD_ISSET(fdpin, &rfds))
         {
-          readsize = read(fdpin, readbuf, sizeof(readbuf));
+          rxinfo = (struct rx_info *) (write_pout.buf
+              + sizeof(struct GNUNET_MessageHeader));
+          readsize = linux_read(&dev, (unsigned char *) readbuf
+              + sizeof(struct rx_info) + sizeof(struct GNUNET_MessageHeader),
+              sizeof(readbuf) - sizeof(struct rx_info)
+                  - sizeof(struct GNUNET_MessageHeader), rxinfo);
+          //readsize = read(fdpin, readbuf, sizeof(readbuf));
 
           if (0 > readsize)
             {
@@ -1044,19 +1162,19 @@
             }
           else if (0 < readsize)
             {
-              GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
-                  GNUNET_NO, GNUNET_NO);
 
             }
           else
             {
               //eof
-              closeprog = 1;
+              //closeprog = 1;
             }
         }
 
     }
 
+  return 0;
+
 }
 
 int
@@ -1074,269 +1192,274 @@
     {
 
       return testmode(argc, argv);
-    } else {
+    }
+  else
+    {
       hardwaremode(argc, argv);
     }
 
 #if 0
-       u8 u8aSendBuffer[500];
-       char szErrbuf[PCAP_ERRBUF_SIZE];
-       int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0;
-       int nOrdinal = 0, r, nDelay = 100000;
-       int nRateIndex = 0, retval, bytes;
-       pcap_t *ppcap = NULL;
-       struct bpf_program bpfprogram;
-       char * szProgram = "", fBrokenSocket = 0;
-       u16 u16HeaderLen;
-       char szHostname[PATH_MAX];
+  u8 u8aSendBuffer[500];
+  char szErrbuf[PCAP_ERRBUF_SIZE];
+  int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0;
+  int nOrdinal = 0, r, nDelay = 100000;
+  int nRateIndex = 0, retval, bytes;
+  pcap_t *ppcap = NULL;
+  struct bpf_program bpfprogram;
+  char * szProgram = "", fBrokenSocket = 0;
+  u16 u16HeaderLen;
+  char szHostname[PATH_MAX];
 
-       if (gethostname(szHostname, sizeof (szHostname) - 1)) {
-               perror("unable to get hostname");
-       }
-       szHostname[sizeof (szHostname) - 1] = '\0';
+  if (gethostname(szHostname, sizeof (szHostname) - 1))
+    {
+      perror("unable to get hostname");
+    }
+  szHostname[sizeof (szHostname) - 1] = '\0';
 
+  printf("Packetspammer (c)2007 Andy Green <address@hidden>  GPL2\n");
 
-       printf("Packetspammer (c)2007 Andy Green <address@hidden>  GPL2\n");
+  while (1)
+    {
+      int nOptionIndex;
+      static const struct option optiona[] =
+        {
+            { "delay", required_argument, NULL, 'd'},
+            { "fcs", no_argument, &flagMarkWithFCS, 1},
+            { "help", no_argument, &flagHelp, 1},
+            { "verbose", no_argument, &flagVerbose, 1},
+            { 0, 0, 0, 0}
+        };
+      int c = getopt_long(argc, argv, "d:hf",
+          optiona, &nOptionIndex);
 
-       while (1) {
-               int nOptionIndex;
-               static const struct option optiona[] = {
-                       { "delay", required_argument, NULL, 'd' },
-                       { "fcs", no_argument, &flagMarkWithFCS, 1 },
-                       { "help", no_argument, &flagHelp, 1 },
-                       { "verbose", no_argument, &flagVerbose, 1},
-                       { 0, 0, 0, 0 }
-               };
-               int c = getopt_long(argc, argv, "d:hf",
-                       optiona, &nOptionIndex);
+      if (c == -1)
+      break;
+      switch (c)
+        {
+          case 0: // long option
+          break;
 
-               if (c == -1)
-                       break;
-               switch (c) {
-               case 0: // long option
-                       break;
+          case 'h': // help
+          usage();
 
-               case 'h': // help
-                       usage();
+          case 'd': // delay
+          nDelay = atoi(optarg);
+          break;
 
-               case 'd': // delay
-                       nDelay = atoi(optarg);
-                       break;
+          case 'f': // mark as FCS attached
+          flagMarkWithFCS = 1;
+          break;
 
-               case 'f': // mark as FCS attached
-                       flagMarkWithFCS = 1;
-                       break;
+          case 'v': //Verbose / readable output to cout
+          flagVerbose = 1;
+          break;
 
-               case 'v': //Verbose / readable output to cout
-                       flagVerbose = 1;
-                       break;
+          default:
+          printf("unknown switch %c\n", c);
+          usage();
+          break;
+        }
+    }
 
-               default:
-                       printf("unknown switch %c\n", c);
-                       usage();
-                       break;
-               }
-       }
+  if (optind >= argc)
+  usage();
 
-       if (optind >= argc)
-               usage();
+  // open the interface in pcap
 
+  szErrbuf[0] = '\0';
+  ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf);
+  if (ppcap == NULL)
+    {
+      printf("Unable to open interface %s in pcap: %s\n",
+          argv[optind], szErrbuf);
+      return (1);
+    }
 
-               // open the interface in pcap
+  //get mac from interface
 
-       szErrbuf[0] = '\0';
-       ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf);
-       if (ppcap == NULL) {
-               printf("Unable to open interface %s in pcap: %s\n",
-                   argv[optind], szErrbuf);
-               return (1);
-       }
+  /*int sock, j, k;
+   char mac[32];
 
-       //get mac from interface
+   sock=socket(PF_INET, SOCK_STREAM, 0);
+   if (-1==sock) {
+   perror("can not open socket\n");
+   return 1;
+   }
 
-       /*int sock, j, k;
-       char mac[32];
+   if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
+   perror("ioctl(SIOCGIFHWADDR) ");
+   return 1;
+   }
+   for (j=0, k=0; j<6; j++) {
+   k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
+   (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
+   }
+   mac[sizeof(mac)-1]='\0';
+   */
 
-       sock=socket(PF_INET, SOCK_STREAM, 0);
-       if (-1==sock) {
-               perror("can not open socket\n");
-               return 1;
-       }
+  //get header type
+  nLinkEncap = pcap_datalink(ppcap);
+  nCaptureHeaderLength = 0;
 
-       if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
-               perror("ioctl(SIOCGIFHWADDR) ");
-               return 1;
-       }
-       for (j=0, k=0; j<6; j++) {
-               k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
-                       (int)(unsigned int)(unsigned 
char)ifr.ifr_hwaddr.sa_data[j]);
-       }
-       mac[sizeof(mac)-1]='\0';
-       */
+  switch (nLinkEncap)
+    {
 
-       //get header type
-       nLinkEncap = pcap_datalink(ppcap);
-       nCaptureHeaderLength = 0;
+      case DLT_PRISM_HEADER:
+      printf("DLT_PRISM_HEADER Encap\n");
+      nCaptureHeaderLength = 0x40;
+      n80211HeaderLength = 0x20; // ieee80211 comes after this
+      szProgram = "radio[0x4a:4]==0x13223344";
+      break;
 
-       switch (nLinkEncap) {
+      case DLT_IEEE802_11_RADIO:
+      printf("DLT_IEEE802_11_RADIO Encap\n");
+      nCaptureHeaderLength = 0x40;
+      n80211HeaderLength = 0x18; // ieee80211 comes after this
+      szProgram = "ether[0x0a:4]==0x13223344";
+      break;
 
-               case DLT_PRISM_HEADER:
-                       printf("DLT_PRISM_HEADER Encap\n");
-                       nCaptureHeaderLength = 0x40;
-                       n80211HeaderLength = 0x20; // ieee80211 comes after this
-                       szProgram = "radio[0x4a:4]==0x13223344";
-                       break;
+      default:
+      printf("!!! unknown encapsulation on %s !\n", argv[1]);
+      return (1);
 
-               case DLT_IEEE802_11_RADIO:
-                       printf("DLT_IEEE802_11_RADIO Encap\n");
-                       nCaptureHeaderLength = 0x40;
-                       n80211HeaderLength = 0x18; // ieee80211 comes after this
-                       szProgram = "ether[0x0a:4]==0x13223344";
-                       break;
+    }
 
-               default:
-                       printf("!!! unknown encapsulation on %s !\n", argv[1]);
-                       return (1);
+  if (pcap_compile(ppcap, &bpfprogram, szProgram, 1, 0) == -1)
+    {
+      puts(szProgram);
+      puts(pcap_geterr(ppcap));
+      return (1);
+    }
+  else
+    {
+      if (pcap_setfilter(ppcap, &bpfprogram) == -1)
+        {
+          puts(szProgram);
+          puts(pcap_geterr(ppcap));
+        }
+      else
+        {
+          printf("RX Filter applied\n");
+        }
+      pcap_freecode(&bpfprogram);
+    }
 
-       }
+  pcap_setnonblock(ppcap, 1, szErrbuf);
 
-       if (pcap_compile(ppcap, &bpfprogram, szProgram, 1, 0) == -1) {
-               puts(szProgram);
-               puts(pcap_geterr(ppcap));
-               return (1);
-       } else {
-               if (pcap_setfilter(ppcap, &bpfprogram) == -1) {
-                       puts(szProgram);
-                       puts(pcap_geterr(ppcap));
-               } else {
-                       printf("RX Filter applied\n");
-               }
-               pcap_freecode(&bpfprogram);
-       }
+  printf("   (delay between packets %dus)\n", nDelay);
 
-       pcap_setnonblock(ppcap, 1, szErrbuf);
+  memset(u8aSendBuffer, 0, sizeof(u8aSendBuffer));
 
-       printf("   (delay between packets %dus)\n", nDelay);
+  while (!fBrokenSocket)
+    {
+      u8 * pu8 = u8aSendBuffer;
+      struct pcap_pkthdr * ppcapPacketHeader = NULL;
+      struct ieee80211_radiotap_iterator rti;
+      PENUMBRA_RADIOTAP_DATA prd;
+      //init of the values
+      prd.m_nRate = 255;
+      prd.m_nChannel = 255;
+      prd.m_nAntenna = 255;
+      prd.m_nRadiotapFlags = 255;
+      u8 * pu8Payload = u8aSendBuffer;
+      int n, nRate;
 
-       memset(u8aSendBuffer, 0, sizeof (u8aSendBuffer));
+      // receive
 
-       while (!fBrokenSocket) {
-               u8 * pu8 = u8aSendBuffer;
-               struct pcap_pkthdr * ppcapPacketHeader = NULL;
-               struct ieee80211_radiotap_iterator rti;
-               PENUMBRA_RADIOTAP_DATA prd;
-               //init of the values
-               prd.m_nRate = 255;
-               prd.m_nChannel = 255;
-               prd.m_nAntenna = 255;
-               prd.m_nRadiotapFlags = 255;
-               u8 * pu8Payload = u8aSendBuffer;
-               int n, nRate;
+      retval = pcap_next_ex(ppcap, &ppcapPacketHeader,
+          (const u_char**) &pu8Payload);
 
-               // receive
+      if (retval < 0)
+        {
+          fBrokenSocket = 1;
+          continue;
+        }
 
-               retval = pcap_next_ex(ppcap, &ppcapPacketHeader,
-                   (const u_char**)&pu8Payload);
+      if (retval != 1)
+      goto do_tx;
 
-               if (retval < 0) {
-                       fBrokenSocket = 1;
-                       continue;
-               }
+      u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8));
 
-               if (retval != 1)
-                       goto do_tx;
+      printf("rtap: ");
+      Dump(pu8Payload, u16HeaderLen);
 
-               u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8));
+      if (ppcapPacketHeader->len < (u16HeaderLen + n80211HeaderLength))
+      continue;
 
-               printf("rtap: ");
-               Dump(pu8Payload, u16HeaderLen);
+      bytes = ppcapPacketHeader->len - (u16HeaderLen + n80211HeaderLength);
+      if (bytes < 0)
+      continue;
 
-               if (ppcapPacketHeader->len <
-                   (u16HeaderLen + n80211HeaderLength))
-                       continue;
+      if (ieee80211_radiotap_iterator_init(&rti,
+              (struct ieee80211_radiotap_header *) pu8Payload, bytes) < 0)
+      continue;
 
-               bytes = ppcapPacketHeader->len -
-                       (u16HeaderLen + n80211HeaderLength);
-               if (bytes < 0)
-                       continue;
+      while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0)
+        {
 
-               if (ieee80211_radiotap_iterator_init(&rti,
-                   (struct ieee80211_radiotap_header *)pu8Payload,
-                   bytes) < 0)
-                       continue;
+          switch (rti.this_arg_index)
+            {
+              case IEEE80211_RADIOTAP_RATE:
+              prd.m_nRate = (*rti.this_arg);
+              break;
 
-               while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0) {
+              case IEEE80211_RADIOTAP_CHANNEL:
+              prd.m_nChannel = le16_to_cpu(*((u16 *)rti.this_arg));
+              prd.m_nChannelFlags = le16_to_cpu(*((u16 *)(rti.this_arg + 2)));
+              break;
 
-                       switch (rti.this_arg_index) {
-                       case IEEE80211_RADIOTAP_RATE:
-                               prd.m_nRate = (*rti.this_arg);
-                               break;
+              case IEEE80211_RADIOTAP_ANTENNA:
+              prd.m_nAntenna = (*rti.this_arg) + 1;
+              break;
 
-                       case IEEE80211_RADIOTAP_CHANNEL:
-                               prd.m_nChannel =
-                                   le16_to_cpu(*((u16 *)rti.this_arg));
-                               prd.m_nChannelFlags =
-                                   le16_to_cpu(*((u16 *)(rti.this_arg + 2)));
-                               break;
+              case IEEE80211_RADIOTAP_FLAGS:
+              prd.m_nRadiotapFlags = *rti.this_arg;
+              break;
 
-                       case IEEE80211_RADIOTAP_ANTENNA:
-                               prd.m_nAntenna = (*rti.this_arg) + 1;
-                               break;
+            }
+        }
 
-                       case IEEE80211_RADIOTAP_FLAGS:
-                               prd.m_nRadiotapFlags = *rti.this_arg;
-                               break;
+      pu8Payload += u16HeaderLen + n80211HeaderLength;
 
-                       }
-               }
+      if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS)
+      bytes -= 4;
 
-               pu8Payload += u16HeaderLen + n80211HeaderLength;
+      printf("RX: Rate: %2d.%dMbps, Freq: %d.%dGHz, "
+          "Ant: %d, Flags: 0x%X\n", prd.m_nRate / 2, 5 * (prd.m_nRate & 1),
+          prd.m_nChannel / 1000, prd.m_nChannel - ((prd.m_nChannel / 1000)
+              * 1000), prd.m_nAntenna, prd.m_nRadiotapFlags);
 
-               if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS)
-                       bytes -= 4;
+      Dump(pu8Payload, bytes);
 
-               printf("RX: Rate: %2d.%dMbps, Freq: %d.%dGHz, "
-                   "Ant: %d, Flags: 0x%X\n",
-                   prd.m_nRate / 2, 5 * (prd.m_nRate & 1),
-                   prd.m_nChannel / 1000,
-                   prd.m_nChannel - ((prd.m_nChannel / 1000) * 1000),
-                   prd.m_nAntenna,
-                   prd.m_nRadiotapFlags);
+      do_tx:
 
-               Dump(pu8Payload, bytes);
+      // transmit
 
-       do_tx:
+      memcpy(u8aSendBuffer, u8aRadiotapHeader, sizeof(u8aRadiotapHeader));
+      if (flagMarkWithFCS)
+      pu8[OFFSET_FLAGS] |= IEEE80211_RADIOTAP_F_FCS;
+      nRate = pu8[OFFSET_RATE] = u8aRatesToUse[nRateIndex++];
+      if (nRateIndex >= sizeof(u8aRatesToUse))
+      nRateIndex = 0;
+      pu8 += sizeof(u8aRadiotapHeader);
 
-               // transmit
+      memcpy(pu8, u8aIeeeHeader, sizeof(u8aIeeeHeader));
+      pu8 += sizeof(u8aIeeeHeader);
 
-               memcpy(u8aSendBuffer, u8aRadiotapHeader,
-                       sizeof (u8aRadiotapHeader));
-               if (flagMarkWithFCS)
-                       pu8[OFFSET_FLAGS] |= IEEE80211_RADIOTAP_F_FCS;
-               nRate = pu8[OFFSET_RATE] = u8aRatesToUse[nRateIndex++];
-               if (nRateIndex >= sizeof (u8aRatesToUse))
-                       nRateIndex = 0;
-               pu8 += sizeof (u8aRadiotapHeader);
+      pu8 += sprintf((char *) u8aSendBuffer, "Packetspammer %02d"
+          "broadcast packet"
+          "#%05d -- :-D --%s ----", nRate / 2, nOrdinal++, szHostname);
+      r = pcap_inject(ppcap, u8aSendBuffer, pu8 - u8aSendBuffer);
+      if (r != (pu8 - u8aSendBuffer))
+        {
+          perror("Trouble injecting packet");
+          return (1);
+        }
+      if (nDelay)
+      usleep(nDelay);
+    }
 
-               memcpy(pu8, u8aIeeeHeader, sizeof (u8aIeeeHeader));
-               pu8 += sizeof (u8aIeeeHeader);
-
-               pu8 += sprintf((char *)u8aSendBuffer,
-                   "Packetspammer %02d"
-                   "broadcast packet"
-                   "#%05d -- :-D --%s ----",
-                   nRate/2, nOrdinal++, szHostname);
-               r = pcap_inject(ppcap, u8aSendBuffer, pu8 - u8aSendBuffer);
-               if (r != (pu8-u8aSendBuffer)) {
-                       perror("Trouble injecting packet");
-                       return (1);
-               }
-               if (nDelay)
-                       usleep(nDelay);
-       }
-
-
 #endif
-       return (0);
+  return (0);
 }
 

Modified: gnunet/src/transport/gnunet-transport-wlan-helper.h
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.h 2011-03-28 16:41:58 UTC 
(rev 14757)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.h 2011-03-28 21:52:47 UTC 
(rev 14758)
@@ -27,6 +27,7 @@
 #ifndef gnunet_wlan_H
 #define gnunet_wlan_H
 
+/*
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -35,16 +36,16 @@
 #include <utime.h>
 #include <unistd.h>
 #include <getopt.h>
-#include <pcap.h>
+#include <pcap.h>*/
 //#include <endian.h>
-#include <pcap.h>
 
-
+/*
 typedef unsigned int u32;
 typedef unsigned short u16;
 typedef unsigned char u8;
 typedef u32 __le32;
-
+*/
+/*
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define        le16_to_cpu(x) (x)
 #define        le32_to_cpu(x) (x)
@@ -53,44 +54,22 @@
 #define        le32_to_cpu(x) \
 ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)&0xff0000)>>8)|(((x)&0xff000000)>>24))
 #endif
+*/
 #define        unlikely(x) (x)
 
+#define FIFO_FILE1       "/tmp/MYFIFOin"
+#define FIFO_FILE2       "/tmp/MYFIFOout"
+#define MAXLINE         4096
 
-#endif /* gnunet_wlan_H */
+extern int closeprog;
 
-
-/* Radiotap header iteration
- *   implemented in net/wireless/radiotap.c
- *   docs in Documentation/networking/radiotap-headers.txt
- */
-/**
- * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
- * rtheader: pointer to the radiotap header we are walking through
- * max_length: length of radiotap header in cpu byte ordering
- * this_arg_index: IEEE80211_RADIOTAP_... index of current arg
- * this_arg: pointer to current radiotap arg
- * arg_index: internal next argument index
- * arg: internal next argument pointer
- * next_bitmap: internal pointer to next present u32
- * bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
- */
-
-struct ieee80211_radiotap_iterator {
-       struct ieee80211_radiotap_header *rtheader;
-       int max_length;
-       int this_arg_index;
-       u8 *this_arg;
-
-       int arg_index;
-       u8 *arg;
-       __le32 *next_bitmap;
-       u32 bitmap_shifter;
+struct sendbuf
+{
+  unsigned int pos;
+  unsigned int size;
+  unsigned char buf[MAXLINE * 2];
 };
 
-extern int ieee80211_radiotap_iterator_init(
-   struct ieee80211_radiotap_iterator *iterator,
-   struct ieee80211_radiotap_header *radiotap_header,
-   int max_length);
 
-extern int ieee80211_radiotap_iterator_next(
-   struct ieee80211_radiotap_iterator *iterator);
+#endif /* gnunet_wlan_H */
+

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2011-03-28 16:41:58 UTC 
(rev 14757)
+++ gnunet/src/transport/plugin_transport_wlan.c        2011-03-28 21:52:47 UTC 
(rev 14758)
@@ -34,6 +34,7 @@
 #include "plugin_transport_wlan.h"
 #include "gnunet_common.h"
 #include "gnunet_crypto_lib.h"
+#include "wlan/ieee80211.h"
 
 #define PROTOCOL_PREFIX "wlan"
 
@@ -473,6 +474,11 @@
 
   int fragment_messages_in_count;
 
+  //TODO DOXIGEN
+  uint8_t rate;
+  uint16_t tx_power;
+  uint8_t antenna;
+
 };
 
 /**
@@ -606,10 +612,11 @@
 };
 
 int
-getRadiotapHeader(struct RadiotapHeader * Header);
+getRadiotapHeader(struct Plugin * plugin, struct Session * session,
+    struct Radiotap_Send * Header);
 
 int
-getWlanHeader(struct IeeeHeader * Header, const char * to_mac_addr,
+getWlanHeader(struct ieee80211_frame * Header, const char * to_mac_addr,
     struct Plugin * plugin);
 
 static int
@@ -696,15 +703,15 @@
  * @param bitIdx which bit to unset
  */
 /*static void
-clearBit(char *bitArray, unsigned int bitIdx)
-{
-  size_t slot;
-  unsigned int targetBit;
+ clearBit(char *bitArray, unsigned int bitIdx)
+ {
+ size_t slot;
+ unsigned int targetBit;
 
-  slot = bitIdx / 8;
-  targetBit = (1L << (bitIdx % 8));
-  bitArray[slot] = bitArray[slot] & (~targetBit);
-}*/
+ slot = bitIdx / 8;
+ targetBit = (1L << (bitIdx % 8));
+ bitArray[slot] = bitArray[slot] & (~targetBit);
+ }*/
 
 /**
  * Checks if a bit is active in the bitArray
@@ -1012,12 +1019,14 @@
       session = sessionqueue->content;
 
       pm = session->pending_message;
-      if (pm == NULL){
+      if (pm == NULL)
+        {
 #if DEBUG_wlan
-      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-          "pending message is empty, should not happen. session %p\n", 
session);
+          GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+              "pending message is empty, should not happen. session %p\n",
+              session);
 #endif
-      }
+        }
       GNUNET_assert(pm != NULL);
 
       //check for message timeout
@@ -1180,12 +1189,13 @@
             }
           GNUNET_free(pm);
 
-          if (session->pending_message2 != NULL){
-            session->pending_message = session->pending_message2;
-            session->pending_message2 = NULL;
-            //requeue session
-            queue_Session(plugin, session);
-          }
+          if (session->pending_message2 != NULL)
+            {
+              session->pending_message = session->pending_message2;
+              session->pending_message2 = NULL;
+              //requeue session
+              queue_Session(plugin, session);
+            }
 
           //check if timeout changed
           check_next_fragment_timeout(plugin);
@@ -1270,23 +1280,23 @@
   uint16_t size = 0;
   ssize_t bytes;
   struct GNUNET_MessageHeader * msgheader = NULL;
-  struct IeeeHeader * ieeewlanheader = NULL;
-  struct RadiotapHeader * radioHeader = NULL;
+  struct ieee80211_frame * ieeewlanheader = NULL;
+  struct Radiotap_Send * radioHeader = NULL;
   struct GNUNET_MessageHeader * msgheader2 = NULL;
 
   GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size(
           *(plugin->env->our_hello)) <= WLAN_MTU);
-  size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader)
-      + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader)
+  size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
+      + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)
       + GNUNET_HELLO_size(*(plugin->env->our_hello));
 
   msgheader = GNUNET_malloc(size);
   msgheader->size = htons(size);
   msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
 
-  radioHeader = (struct RadiotapHeader*) &msgheader[1];
-  getRadiotapHeader(radioHeader);
-  ieeewlanheader = (struct IeeeHeader*) &radioHeader[1];
+  radioHeader = (struct Radiotap_Send*) &msgheader[1];
+  getRadiotapHeader(plugin, NULL, radioHeader);
+  ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
   getWlanHeader(ieeewlanheader, bc_all_mac, plugin);
 
   msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
@@ -1321,8 +1331,8 @@
   uint16_t size = 0;
   ssize_t bytes;
   struct GNUNET_MessageHeader * msgheader = NULL;
-  struct IeeeHeader * ieeewlanheader = NULL;
-  struct RadiotapHeader * radioHeader = NULL;
+  struct ieee80211_frame * ieeewlanheader = NULL;
+  struct Radiotap_Send * radioHeader = NULL;
   struct FragmentationAckHeader * msgheader2 = NULL;
 
   GNUNET_assert(sizeof(struct FragmentationAckHeader) <= WLAN_MTU);
@@ -1333,15 +1343,15 @@
       ack->message_id, ack->fragments_field);
 #endif
 
-  size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader)
-      + sizeof(struct IeeeHeader) + sizeof(struct FragmentationAckHeader);
+  size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
+      + sizeof(struct ieee80211_frame) + sizeof(struct FragmentationAckHeader);
   msgheader = GNUNET_malloc(size);
   msgheader->size = htons(size);
   msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
 
-  radioHeader = (struct RadiotapHeader*) &msgheader[1];
-  getRadiotapHeader(radioHeader);
-  ieeewlanheader = (struct IeeeHeader*) &radioHeader[1];
+  radioHeader = (struct Radiotap_Send*) &msgheader[1];
+  getRadiotapHeader(plugin, ack->session, radioHeader);
+  ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
   getWlanHeader(ieeewlanheader, ack->session->addr, plugin);
 
   msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1];
@@ -1383,8 +1393,8 @@
 
   struct Session * session = NULL;
   struct FragmentMessage * fm = NULL;
-  struct IeeeHeader * ieeewlanheader = NULL;
-  struct RadiotapHeader * radioHeader = NULL;
+  struct ieee80211_frame * ieeewlanheader = NULL;
+  struct Radiotap_Send * radioHeader = NULL;
   struct GNUNET_MessageHeader * msgheader = NULL;
 
   struct FragmentationHeader fragheader;
@@ -1486,16 +1496,16 @@
            }*/
 
           size += copysize;
-          size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader)
+          size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame)
               + sizeof(struct GNUNET_MessageHeader);
           msgheader = GNUNET_malloc(size);
           msgheader->size = htons(size);
           msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
 
-          radioHeader = (struct RadiotapHeader*) &msgheader[1];
-          getRadiotapHeader(radioHeader);
+          radioHeader = (struct Radiotap_Send*) &msgheader[1];
+          getRadiotapHeader(plugin, session, radioHeader);
 
-          ieeewlanheader = (struct IeeeHeader *) &radioHeader[1];
+          ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
           getWlanHeader(ieeewlanheader, fm->session->addr, plugin);
 
           //could be faster if content is just send and not copyed before
@@ -1607,8 +1617,13 @@
 }
 
 int
-getRadiotapHeader(struct RadiotapHeader * Header)
+getRadiotapHeader(struct Plugin * plugin, struct Session * session,
+    struct Radiotap_Send * header)
 {
+
+  header->rate = session->rate;
+  header->tx_power = session->tx_power;
+  header->antenna = session->antenna;
   return GNUNET_YES;
 }
 ;
@@ -1622,12 +1637,12 @@
  */
 
 int
-getWlanHeader(struct IeeeHeader * Header, const char * const to_mac_addr,
+getWlanHeader(struct ieee80211_frame * Header, const char * const to_mac_addr,
     struct Plugin * plugin)
 {
-  memcpy(&Header->mac3, mac_bssid, sizeof(mac_bssid));
-  memcpy(&Header->mac2, plugin->mac_address.mac, sizeof(plugin->mac_address));
-  memcpy(&Header->mac1, to_mac_addr, sizeof(plugin->mac_address));
+  memcpy(&Header->i_addr3, mac_bssid, sizeof(mac_bssid));
+  memcpy(&Header->i_addr2, plugin->mac_address.mac, 
sizeof(plugin->mac_address));
+  memcpy(&Header->i_addr1, to_mac_addr, sizeof(plugin->mac_address));
   return GNUNET_YES;
 }
 
@@ -1722,7 +1737,7 @@
   //if (session->target != NULL){
   //  GNUNET_assert(session->target == *target);
   //} else {
-    session->target = *target;
+  session->target = *target;
   //}
 
 
@@ -1781,7 +1796,6 @@
       newmsg->message_size);
 #endif
 
-
   //queue session
   queue_Session(plugin, session);
 
@@ -2494,7 +2508,7 @@
       rec_queue->num = ntohs(fh->fragment_off_or_num);
       rec_queue->msg = (char*) &(rec_queue[1]);
       //copy msg to buffer
-      memcpy((char *)rec_queue->msg, tempmsg, rec_queue->size);
+      memcpy((char *) rec_queue->msg, tempmsg, rec_queue->size);
       insert_fragment_in_queue(rec_message, rec_queue);
       //save bitfield
       retval = rec_message->received_fragments;
@@ -2679,10 +2693,9 @@
 }
 
 char *
-macprinter(struct MacAddress macx)
+macprinter(u_int8_t * mac)
 {
   static char macstr[20];
-  char * mac = macx.mac;
   sprintf(macstr, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2],
       mac[3], mac[4], mac[5]);
   return macstr;
@@ -2701,7 +2714,7 @@
     const struct GNUNET_MessageHeader *hdr)
 {
   struct Plugin *plugin = cls;
-  struct IeeeHeader * wlanIeeeHeader = NULL;
+  struct ieee80211_frame * wlanIeeeHeader = NULL;
   struct Session_light * session_light = NULL;
   const struct GNUNET_MessageHeader * temp_hdr = NULL;
 
@@ -2718,30 +2731,30 @@
 #endif
 
       //call wlan_process_helper with the message inside, later with wlan: 
analyze signal
-      GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader) + 
sizeof(struct GNUNET_MessageHeader));
-      wlanIeeeHeader = (struct IeeeHeader *) &hdr[1];
+      GNUNET_assert(ntohs(hdr->size) >= sizeof(struct ieee80211_frame) + 
sizeof(struct GNUNET_MessageHeader));
+      wlanIeeeHeader = (struct ieee80211_frame *) &hdr[1];
 
       //process only if it is an broadcast or for this computer both with the 
gnunet bssid
 
       //check for bssid
-      if (memcmp(&(wlanIeeeHeader->mac3), mac_bssid, sizeof(struct MacAddress))
-          == 0)
+      if (memcmp(&(wlanIeeeHeader->i_addr3), mac_bssid,
+          sizeof(struct MacAddress)) == 0)
         {
           //check for broadcast or mac
-          if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac,
+          if (memcmp(&(wlanIeeeHeader->i_addr1), bc_all_mac,
               sizeof(struct MacAddress) == 0) || memcmp(
-              &(wlanIeeeHeader->mac1), &(plugin->mac_address),
+              &(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
               sizeof(struct MacAddress)) == 0)
             {
 
               // process the inner data
 
 
-              datasize = ntohs(hdr->size) - sizeof(struct IeeeHeader)
+              datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame)
                   - sizeof(struct GNUNET_MessageHeader);
 
               session_light = GNUNET_malloc(sizeof(struct Session_light));
-              memcpy(session_light->addr, &(wlanIeeeHeader->mac2),
+              memcpy(session_light->addr, &(wlanIeeeHeader->i_addr2),
                   sizeof(struct MacAddress));
               //session_light->session = 
search_session(plugin,session_light->addr);
 
@@ -2765,7 +2778,7 @@
 #if DEBUG_wlan
               GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                   "Func wlan_process_helper got wrong MAC: %s\n", macprinter(
-                      wlanIeeeHeader->mac1));
+                       wlanIeeeHeader->i_addr1));
 #endif
             }
         }
@@ -2774,7 +2787,7 @@
 #if DEBUG_wlan
           GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
               "Func wlan_process_helper got wrong BSSID: %s\n", macprinter(
-                  wlanIeeeHeader->mac2));
+                  wlanIeeeHeader->i_addr2));
 #endif
         }
 
@@ -2807,7 +2820,7 @@
       else
         {
           GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n",
-              macprinter(plugin->mac_address));
+              macprinter(plugin->mac_address.mac));
         }
 
     }

Modified: gnunet/src/transport/plugin_transport_wlan.h
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.h        2011-03-28 16:41:58 UTC 
(rev 14757)
+++ gnunet/src/transport/plugin_transport_wlan.h        2011-03-28 21:52:47 UTC 
(rev 14758)
@@ -34,7 +34,7 @@
 
 struct MacAddress
 {
-  char mac[6];
+  u_int8_t mac[6];
 };
 
 struct Wlan_Helper_Control_Message
@@ -67,44 +67,7 @@
 static const char bc_all_mac[] =
    { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 
-/**
- * Wlan header
- */
 
-struct IeeeHeader
-{
-  /**
-   * Wlan flags
-   */
-  uint16_t frame_control GNUNET_PACKED;
-
-  /**
-   * Duration / ID
-   */
-  uint16_t duration_id GNUNET_PACKED;
-  
-  /**
-   * first mac byte 1
-   */
-  struct MacAddress mac1;
-
-  
-  /**
-   * second mac
-   */
-  struct MacAddress mac2;
-  
-  /**
-   * third mac
-   */
-  struct MacAddress mac3;
-  
-  /**
-   * Wlan Sequence Control
-   */
-  uint16_t sequence_control GNUNET_PACKED;
-};
-
 /* this is the template radiotap header we send packets out with */
 
 static const uint8_t u8aRadiotapHeader[] = 
@@ -121,6 +84,36 @@
     0x01, // <-- antenna
 };
 
+struct Radiotap_Send
+{
+  /**
+     * wlan send rate
+     */
+    uint8_t rate;
+
+    /**
+     * antenna
+     */
+    uint8_t antenna;
+
+    /**
+     * Transmit power expressed as unitless distance from max power set at 
factory calibration.
+     * 0 is max power. Monotonically nondecreasing with lower power levels.
+     */
+
+    uint16_t tx_power;
+};
+
+struct rx_info {
+        uint64_t ri_mactime;
+        int32_t ri_power;
+        int32_t ri_noise;
+        uint32_t ri_channel;
+        uint32_t ri_freq;
+        uint32_t ri_rate;
+        uint32_t ri_antenna;
+};
+
 /**
  * Radiotap Header
  */

Added: gnunet/src/transport/wlan/byteorder.h
===================================================================
--- gnunet/src/transport/wlan/byteorder.h                               (rev 0)
+++ gnunet/src/transport/wlan/byteorder.h       2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,397 @@
+/*
+ *  Compatibility header
+ *
+ *  Copyright (C) 2009 Thomas d'Otreppe
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _AIRCRACK_NG_BYTEORDER_H_
+#define _AIRCRACK_NG_BYTEORDER_H_
+
+       #define ___my_swab16(x) \
+       ((u_int16_t)( \
+                       (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
+                       (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
+       #define ___my_swab32(x) \
+       ((u_int32_t)( \
+                       (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
+                       (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) <<  8) | \
+                       (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >>  8) | \
+                       (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
+       #define ___my_swab64(x) \
+       ((u_int64_t)( \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x00000000000000ffULL) << 56) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x000000000000ff00ULL) << 40) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x0000000000ff0000ULL) << 24) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x00000000ff000000ULL) <<  8) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x000000ff00000000ULL) >>  8) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x0000ff0000000000ULL) >> 24) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0x00ff000000000000ULL) >> 40) | \
+                       (u_int64_t)(((u_int64_t)(x) & 
(u_int64_t)0xff00000000000000ULL) >> 56) ))
+
+
+       /*
+        * Linux
+        */
+       #if defined(linux) || defined(Linux) || defined(__linux__) || 
defined(__linux) || defined(__gnu_linux__)
+               #include <endian.h>
+               #include <unistd.h>
+               #include <stdint.h>
+
+               #ifndef __int8_t_defined
+                       typedef uint64_t u_int64_t;
+                       typedef uint32_t u_int32_t;
+                       typedef uint16_t u_int16_t;
+                       typedef uint8_t  u_int8_t;
+               #endif
+
+       #endif
+
+       /*
+        * Cygwin
+        */
+       #if defined(__CYGWIN32__)
+               #include <asm/byteorder.h>
+               #include <unistd.h>
+
+               #define __be64_to_cpu(x) ___my_swab64(x)
+               #define __be32_to_cpu(x) ___my_swab32(x)
+               #define __be16_to_cpu(x) ___my_swab16(x)
+               #define __cpu_to_be64(x) ___my_swab64(x)
+               #define __cpu_to_be32(x) ___my_swab32(x)
+               #define __cpu_to_be16(x) ___my_swab16(x)
+               #define __le64_to_cpu(x) (x)
+               #define __le32_to_cpu(x) (x)
+               #define __le16_to_cpu(x) (x)
+               #define __cpu_to_le64(x) (x)
+               #define __cpu_to_le32(x) (x)
+               #define __cpu_to_le16(x) (x)
+
+               #define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+       #endif
+
+       /*
+        * Windows (DDK)
+        */
+       #if defined(__WIN__)
+
+               #include <io.h>
+
+               #define __be64_to_cpu(x) ___my_swab64(x)
+               #define __be32_to_cpu(x) ___my_swab32(x)
+               #define __be16_to_cpu(x) ___my_swab16(x)
+               #define __cpu_to_be64(x) ___my_swab64(x)
+               #define __cpu_to_be32(x) ___my_swab32(x)
+               #define __cpu_to_be16(x) ___my_swab16(x)
+               #define __le64_to_cpu(x) (x)
+               #define __le32_to_cpu(x) (x)
+               #define __le16_to_cpu(x) (x)
+               #define __cpu_to_le64(x) (x)
+               #define __cpu_to_le32(x) (x)
+               #define __cpu_to_le16(x) (x)
+
+               #define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+       #endif
+
+       /*
+        * MAC (Darwin)
+        */
+       #if defined(__APPLE_CC__)
+               #if defined(__x86_64__) && defined(__APPLE__)
+
+                       #include <libkern/OSByteOrder.h>
+
+                       #define __swab64(x)      (unsigned long long) 
OSSwapInt64((uint64_t)x)
+                       #define __swab32(x)      (unsigned long) 
OSSwapInt32((uint32_t)x)
+                       #define __swab16(x)      (unsigned short) 
OSSwapInt16((uint16_t)x)
+                       #define __be64_to_cpu(x) (unsigned long long) 
OSSwapBigToHostInt64((uint64_t)x)
+                       #define __be32_to_cpu(x) (unsigned long) 
OSSwapBigToHostInt32((uint32_t)x)
+                       #define __be16_to_cpu(x) (unsigned short) 
OSSwapBigToHostInt16((uint16_t)x)
+                       #define __le64_to_cpu(x) (unsigned long long) 
OSSwapLittleToHostInt64((uint64_t)x)
+                       #define __le32_to_cpu(x) (unsigned long) 
OSSwapLittleToHostInt32((uint32_t)x)
+                       #define __le16_to_cpu(x) (unsigned short) 
OSSwapLittleToHostInt16((uint16_t)x)
+                       #define __cpu_to_be64(x) (unsigned long long) 
OSSwapHostToBigInt64((uint64_t)x)
+                       #define __cpu_to_be32(x) (unsigned long) 
OSSwapHostToBigInt32((uint32_t)x)
+                       #define __cpu_to_be16(x) (unsigned short) 
OSSwapHostToBigInt16((uint16_t)x)
+                       #define __cpu_to_le64(x) (unsigned long long) 
OSSwapHostToLittleInt64((uint64_t)x)
+                       #define __cpu_to_le32(x) (unsigned long) 
OSSwapHostToLittleInt32((uint32_t)x)
+                       #define __cpu_to_le16(x) (unsigned short) 
OSSwapHostToLittleInt16((uint16_t)x)
+
+               #else
+
+                       #include <architecture/byte_order.h>
+
+                       #define __swab64(x)      NXSwapLongLong(x)
+                       #define __swab32(x)      NXSwapLong(x)
+                       #define __swab16(x)      NXSwapShort(x)
+                       #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
+                       #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
+                       #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
+                       #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
+                       #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
+                       #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
+                       #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
+                       #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
+                       #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
+                       #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
+                       #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
+                       #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
+
+               #endif
+
+               #define __LITTLE_ENDIAN 1234
+               #define __BIG_ENDIAN    4321
+               #define __PDP_ENDIAN    3412
+               #define __BYTE_ORDER    __BIG_ENDIAN
+
+               #define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+       #endif
+
+       /*
+        * Solaris
+        * -------
+        */
+       #if defined(__sparc__)
+       #include <sys/byteorder.h>
+       #include <sys/types.h>
+       #include <unistd.h>
+
+               #define __be64_to_cpu(x) (x)
+               #define __be32_to_cpu(x) (x)
+               #define __be16_to_cpu(x) (x)
+               #define __cpu_to_be64(x) (x)
+               #define __cpu_to_be32(x) (x)
+               #define __cpu_to_be16(x) (x)
+               #define __le64_to_cpu(x) ___my_swab64(x)
+               #define __le32_to_cpu(x) ___my_swab32(x)
+               #define __le16_to_cpu(x) ___my_swab16(x)
+               #define __cpu_to_le64(x) ___my_swab64(x)
+               #define __cpu_to_le32(x) ___my_swab32(x)
+               #define __cpu_to_le16(x) ___my_swab16(x)
+
+               typedef uint64_t u_int64_t;
+               typedef uint32_t u_int32_t;
+               typedef uint16_t u_int16_t;
+               typedef uint8_t  u_int8_t;
+
+               #define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+       #endif
+
+       /*
+        * Custom stuff
+        */
+       #if  defined(__MACH__) && !defined(__APPLE_CC__)
+               #include <libkern/OSByteOrder.h>
+               #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
+               #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
+
+               #define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+       #endif
+
+
+       // FreeBSD
+       #ifdef __FreeBSD__
+               #include <machine/endian.h>
+       #endif
+
+       // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
+
+
+       // XXX: Mac: Check 
http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
+       //           
http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
+       //           Write to apple to ask what should be used.
+
+       #if defined(LITTLE_ENDIAN)
+               #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
+       #elif defined(__LITTLE_ENDIAN)
+               #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
+       #elif defined(_LITTLE_ENDIAN)
+               #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
+       #endif
+
+       #if defined(BIG_ENDIAN)
+               #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
+       #elif defined(__BIG_ENDIAN)
+               #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
+       #elif defined(_BIG_ENDIAN)
+               #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
+       #endif
+
+       #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && 
!defined(AIRCRACK_NG_BIG_ENDIAN)
+               #error Impossible to determine endianness (Little or Big 
endian), please contact the author.
+       #endif
+
+       #if defined(BYTE_ORDER)
+               #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+               #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+               #endif
+       #elif defined(__BYTE_ORDER)
+               #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+               #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+               #endif
+       #elif defined(_BYTE_ORDER)
+               #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+               #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+                       #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+               #endif
+       #endif
+
+       #ifndef AIRCRACK_NG_BYTE_ORDER
+               #error Impossible to determine endianness (Little or Big 
endian), please contact the author.
+       #endif
+
+       #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+
+               #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
+                       #define __be64_to_cpu(x) ___my_swab64(x)
+                       #define __be32_to_cpu(x) ___my_swab32(x)
+                       #define __be16_to_cpu(x) ___my_swab16(x)
+                       #define __cpu_to_be64(x) ___my_swab64(x)
+                       #define __cpu_to_be32(x) ___my_swab32(x)
+                       #define __cpu_to_be16(x) ___my_swab16(x)
+                       #define __le64_to_cpu(x) (x)
+                       #define __le32_to_cpu(x) (x)
+                       #define __le16_to_cpu(x) (x)
+                       #define __cpu_to_le64(x) (x)
+                       #define __cpu_to_le32(x) (x)
+                       #define __cpu_to_le16(x) (x)
+               #endif
+
+               #ifndef htobe16
+                       #define htobe16 ___my_swab16
+               #endif
+               #ifndef htobe32
+                       #define htobe32 ___my_swab32
+               #endif
+               #ifndef betoh16
+                       #define betoh16 ___my_swab16
+               #endif
+               #ifndef betoh32
+                       #define betoh32 ___my_swab32
+               #endif
+
+               #ifndef htole16
+                       #define htole16(x) (x)
+               #endif
+               #ifndef htole32
+                       #define htole32(x) (x)
+               #endif
+               #ifndef letoh16
+                       #define letoh16(x) (x)
+               #endif
+               #ifndef letoh32
+                       #define letoh32(x) (x)
+               #endif
+
+       #endif
+
+       #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+
+               #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
+                       #define __be64_to_cpu(x) (x)
+                       #define __be32_to_cpu(x) (x)
+                       #define __be16_to_cpu(x) (x)
+                       #define __cpu_to_be64(x) (x)
+                       #define __cpu_to_be32(x) (x)
+                       #define __cpu_to_be16(x) (x)
+                       #define __le64_to_cpu(x) ___my_swab64(x)
+                       #define __le32_to_cpu(x) ___my_swab32(x)
+                       #define __le16_to_cpu(x) ___my_swab16(x)
+                       #define __cpu_to_le64(x) ___my_swab64(x)
+                       #define __cpu_to_le32(x) ___my_swab32(x)
+                       #define __cpu_to_le16(x) ___my_swab16(x)
+               #endif
+
+               #ifndef htobe16
+                       #define htobe16(x) (x)
+               #endif
+               #ifndef htobe32
+                       #define htobe32(x) (x)
+               #endif
+               #ifndef betoh16
+                       #define betoh16(x) (x)
+               #endif
+               #ifndef betoh32
+                       #define betoh32(x) (x)
+               #endif
+
+               #ifndef htole16
+                       #define htole16 ___my_swab16
+               #endif
+               #ifndef htole32
+                       #define htole32 ___my_swab32
+               #endif
+               #ifndef letoh16
+                       #define letoh16 ___my_swab16
+               #endif
+               #ifndef letoh32
+                       #define letoh32 ___my_swab32
+               #endif
+
+       #endif
+
+       // Common defines
+       #define cpu_to_le64 __cpu_to_le64
+       #define le64_to_cpu __le64_to_cpu
+       #define cpu_to_le32 __cpu_to_le32
+       #define le32_to_cpu __le32_to_cpu
+       #define cpu_to_le16 __cpu_to_le16
+       #define le16_to_cpu __le16_to_cpu
+       #define cpu_to_be64 __cpu_to_be64
+       #define be64_to_cpu __be64_to_cpu
+       #define cpu_to_be32 __cpu_to_be32
+       #define be32_to_cpu __be32_to_cpu
+       #define cpu_to_be16 __cpu_to_be16
+       #define be16_to_cpu __be16_to_cpu
+
+       #ifndef le16toh
+               #define le16toh le16_to_cpu
+       #endif
+       #ifndef be16toh
+               #define be16toh be16_to_cpu
+       #endif
+       #ifndef le32toh
+               #define le32toh le32_to_cpu
+       #endif
+       #ifndef be32toh
+               #define be32toh be32_to_cpu
+       #endif
+
+
+       #ifndef htons
+               #define htons be16_to_cpu
+       #endif
+       #ifndef htonl
+               #define htonl cpu_to_be16
+       #endif
+       #ifndef ntohs
+               #define ntohs cpu_to_be16
+       #endif
+       #ifndef ntohl
+               #define ntohl cpu_to_be32
+       #endif
+
+#endif

Added: gnunet/src/transport/wlan/crctable_osdep.h
===================================================================
--- gnunet/src/transport/wlan/crctable_osdep.h                          (rev 0)
+++ gnunet/src/transport/wlan/crctable_osdep.h  2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,40 @@
+#ifndef _CRCTABLE_OSDEP_H
+#define _CRCTABLE_OSDEP_H
+
+const unsigned long int crc_tbl_osdep[256] =
+{
+    0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 
0xE963A535, 0x9E6495A3,
+    0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 
0xE7B82D07, 0x90BF1D91,
+    0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 
0xF4D4B551, 0x83D385C7,
+    0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 
0xFA0F3D63, 0x8D080DF5,
+    0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 
0xD20D85FD, 0xA50AB56B,
+    0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 
0xDCD60DCF, 0xABD13D59,
+    0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 
0xCFBA9599, 0xB8BDA50F,
+    0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 
0xC1611DAB, 0xB6662D3D,
+    0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 
0x9FBFE4A5, 0xE8B8D433,
+    0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 
0x91646C97, 0xE6635C01,
+    0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 
0x8208F4C1, 0xF50FC457,
+    0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 
0x8CD37CF3, 0xFBD44C65,
+    0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 
0xA4D1C46D, 0xD3D6F4FB,
+    0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 
0xAA0A4C5F, 0xDD0D7CC9,
+    0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 
0xB966D409, 0xCE61E49F,
+    0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 
0xB7BD5C3B, 0xC0BA6CAD,
+    0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 
0x04DB2615, 0x73DC1683,
+    0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 
0x0A00AE27, 0x7D079EB1,
+    0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 
0x196C3671, 0x6E6B06E7,
+    0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 
0x17B7BE43, 0x60B08ED5,
+    0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 
0x3FB506DD, 0x48B2364B,
+    0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 
0x316E8EEF, 0x4669BE79,
+    0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 
0x220216B9, 0x5505262F,
+    0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 
0x2CD99E8B, 0x5BDEAE1D,
+    0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 
0x72076785, 0x05005713,
+    0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 
0x7CDCEFB7, 0x0BDBDF21,
+    0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 
0x6FB077E1, 0x18B74777,
+    0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 
0x616BFFD3, 0x166CCF45,
+    0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 
0x4969474D, 0x3E6E77DB,
+    0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 
0x47B2CF7F, 0x30B5FFE9,
+    0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 
0x54DE5729, 0x23D967BF,
+    0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 
0x5A05DF1B, 0x2D02EF8D
+};
+
+#endif /* crctable_osdep.h */

Added: gnunet/src/transport/wlan/helper_common.c
===================================================================
--- gnunet/src/transport/wlan/helper_common.c                           (rev 0)
+++ gnunet/src/transport/wlan/helper_common.c   2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,110 @@
+/*
+ * helper_common.c
+ *
+ *  Created on: 28.03.2011
+ *      Author: David Brodski
+ */
+
+#include <sys/socket.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+#include <utime.h>
+#include <unistd.h>
+#include <getopt.h>
+
+//#include "platform.h"
+#include "gnunet_constants.h"
+#include "gnunet_os_lib.h"
+#include "gnunet_transport_plugin.h"
+#include "transport.h"
+#include "gnunet_util_lib.h"
+#include "plugin_transport_wlan.h"
+#include "gnunet_common.h"
+#include "gnunet_transport_plugin.h"
+//#include "gnunet_util_lib.h"
+
+/**
+ * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for 
plugin
+ * @param buffer pointer to buffer for the message
+ * @param mac pointer to the mac address
+ * @return number of bytes written
+ */
+
+int
+send_mac_to_plugin(char * buffer, uint8_t * mac)
+{
+
+  struct Wlan_Helper_Control_Message macmsg;
+
+  memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
+  macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
+  macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+
+  memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
+  return sizeof(struct Wlan_Helper_Control_Message);
+}
+
+/*
+   *  Copyright (c) 2008, Thomas d'Otreppe
+   *
+   *  Common OSdep stuff
+   *
+   *  This program is free software; you can redistribute it and/or modify
+   *  it under the terms of the GNU General Public License as published by
+   *  the Free Software Foundation; either version 2 of the License, or
+   *  (at your option) any later version.
+   *
+   *  This program is distributed in the hope that it will be useful,
+   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   *  GNU General Public License for more details.
+   *
+   *  You should have received a copy of the GNU General Public License
+   *  along with this program; if not, write to the Free Software
+   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+   */
+
+/**
+ * Return the frequency in Mhz from a channel number
+ */
+int getFrequencyFromChannel(int channel)
+{
+        static int frequencies[] = {
+                -1, // No channel 0
+                2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 
2462, 2467, 2472, 2484,
+                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive)
+                5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 
5220, 5225, 5230, 5235, 5240, 5245,
+                5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 
5300, 5305, 5310, 5315, 5320, 5325,
+                5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 
5380, 5385, 5390, 5395, 5400, 5405,
+                5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 
5460, 5465, 5470, 5475, 5480, 5485,
+                5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 
5540, 5545, 5550, 5555, 5560, 5565,
+                5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 
5620, 5625, 5630, 5635, 5640, 5645,
+                5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 
5700, 5705, 5710, 5715, 5720, 5725,
+                5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 
5780, 5785, 5790, 5795, 5800, 5805,
+                5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 
5860, 5865, 5870, 5875, 5880, 5885,
+                5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 
5940, 5945, 5950, 5955, 5960, 5965,
+                5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 
6020, 6025, 6030, 6035, 6040, 6045,
+                6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 
6100
+        };
+
+        return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
+}
+
+/**
+ * Return the channel from the frequency (in Mhz)
+ */
+int getChannelFromFrequency(int frequency)
+{
+        if (frequency >= 2412 && frequency <= 2472)
+                return (frequency - 2407) / 5;
+        else if (frequency == 2484)
+                return 14;
+        else if (frequency >= 5000 && frequency <= 6100)
+                return (frequency - 5000) / 5;
+        else
+                return -1;
+}

Added: gnunet/src/transport/wlan/helper_common.h
===================================================================
--- gnunet/src/transport/wlan/helper_common.h                           (rev 0)
+++ gnunet/src/transport/wlan/helper_common.h   2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,15 @@
+/*
+ * helper_common.h
+ *
+ *  Created on: 28.03.2011
+ *      Author: david
+ */
+
+#ifndef HELPER_COMMON_H_
+#define HELPER_COMMON_H_
+
+int getFrequencyFromChannel(int channel);
+int getChannelFromFrequency(int frequency);
+int send_mac_to_plugin(char * buffer, uint8_t * mac);
+
+#endif /* HELPER_COMMON_H_ */

Added: gnunet/src/transport/wlan/ieee80211.h
===================================================================
--- gnunet/src/transport/wlan/ieee80211.h                               (rev 0)
+++ gnunet/src/transport/wlan/ieee80211.h       2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,663 @@
+/*-
+ * Copyright (c) 2001 Atsushi Onoe
+ * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.12 2006/12/01 18:40:51 imp Exp $
+ */
+#ifndef _NET80211_IEEE80211_H_
+#define _NET80211_IEEE80211_H_
+
+/*
+ * 802.11 protocol definitions.
+ */
+
+#define        IEEE80211_ADDR_LEN      6               /* size of 802.11 
address */
+/* is 802.11 address multicast/broadcast? */
+#define        IEEE80211_IS_MULTICAST(_a)      (*(_a) & 0x01)
+
+/* IEEE 802.11 PLCP header */
+struct ieee80211_plcp_hdr {
+       u_int16_t       i_sfd;
+       u_int8_t        i_signal;
+       u_int8_t        i_service;
+       u_int16_t       i_length;
+       u_int16_t       i_crc;
+} GNUNET_PACKED;
+
+#define IEEE80211_PLCP_SFD      0xF3A0 
+#define IEEE80211_PLCP_SERVICE  0x00
+
+/*
+ * generic definitions for IEEE 802.11 frames
+ */
+struct ieee80211_frame {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_addr1[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr2[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr3[IEEE80211_ADDR_LEN];
+       u_int8_t        i_seq[2];
+       /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
+       /* see below */
+} GNUNET_PACKED;
+
+struct ieee80211_qosframe {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_addr1[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr2[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr3[IEEE80211_ADDR_LEN];
+       u_int8_t        i_seq[2];
+       u_int8_t        i_qos[2];
+       /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
+       /* see below */
+} GNUNET_PACKED;
+
+struct ieee80211_qoscntl {
+       u_int8_t        i_qos[2];
+};
+
+struct ieee80211_frame_addr4 {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_addr1[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr2[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr3[IEEE80211_ADDR_LEN];
+       u_int8_t        i_seq[2];
+       u_int8_t        i_addr4[IEEE80211_ADDR_LEN];
+} GNUNET_PACKED;
+
+
+struct ieee80211_qosframe_addr4 {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_addr1[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr2[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr3[IEEE80211_ADDR_LEN];
+       u_int8_t        i_seq[2];
+       u_int8_t        i_addr4[IEEE80211_ADDR_LEN];
+       u_int8_t        i_qos[2];
+} GNUNET_PACKED;
+
+#define        IEEE80211_FC0_VERSION_MASK              0x03
+#define        IEEE80211_FC0_VERSION_SHIFT             0
+#define        IEEE80211_FC0_VERSION_0                 0x00
+#define        IEEE80211_FC0_TYPE_MASK                 0x0c
+#define        IEEE80211_FC0_TYPE_SHIFT                2
+#define        IEEE80211_FC0_TYPE_MGT                  0x00
+#define        IEEE80211_FC0_TYPE_CTL                  0x04
+#define        IEEE80211_FC0_TYPE_DATA                 0x08
+
+#define        IEEE80211_FC0_SUBTYPE_MASK              0xf0
+#define        IEEE80211_FC0_SUBTYPE_SHIFT             4
+/* for TYPE_MGT */
+#define        IEEE80211_FC0_SUBTYPE_ASSOC_REQ         0x00
+#define        IEEE80211_FC0_SUBTYPE_ASSOC_RESP        0x10
+#define        IEEE80211_FC0_SUBTYPE_REASSOC_REQ       0x20
+#define        IEEE80211_FC0_SUBTYPE_REASSOC_RESP      0x30
+#define        IEEE80211_FC0_SUBTYPE_PROBE_REQ         0x40
+#define        IEEE80211_FC0_SUBTYPE_PROBE_RESP        0x50
+#define        IEEE80211_FC0_SUBTYPE_BEACON            0x80
+#define        IEEE80211_FC0_SUBTYPE_ATIM              0x90
+#define        IEEE80211_FC0_SUBTYPE_DISASSOC          0xa0
+#define        IEEE80211_FC0_SUBTYPE_AUTH              0xb0
+#define        IEEE80211_FC0_SUBTYPE_DEAUTH            0xc0
+/* for TYPE_CTL */
+#define        IEEE80211_FC0_SUBTYPE_PS_POLL           0xa0
+#define        IEEE80211_FC0_SUBTYPE_RTS               0xb0
+#define        IEEE80211_FC0_SUBTYPE_CTS               0xc0
+#define        IEEE80211_FC0_SUBTYPE_ACK               0xd0
+#define        IEEE80211_FC0_SUBTYPE_CF_END            0xe0
+#define        IEEE80211_FC0_SUBTYPE_CF_END_ACK        0xf0
+/* for TYPE_DATA (bit combination) */
+#define        IEEE80211_FC0_SUBTYPE_DATA              0x00
+#define        IEEE80211_FC0_SUBTYPE_CF_ACK            0x10
+#define        IEEE80211_FC0_SUBTYPE_CF_POLL           0x20
+#define        IEEE80211_FC0_SUBTYPE_CF_ACPL           0x30
+#define        IEEE80211_FC0_SUBTYPE_NODATA            0x40
+#define        IEEE80211_FC0_SUBTYPE_CFACK             0x50
+#define        IEEE80211_FC0_SUBTYPE_CFPOLL            0x60
+#define        IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK     0x70
+#define        IEEE80211_FC0_SUBTYPE_QOS               0x80
+#define        IEEE80211_FC0_SUBTYPE_QOS_NULL          0xc0
+
+#define        IEEE80211_FC1_DIR_MASK                  0x03
+#define        IEEE80211_FC1_DIR_NODS                  0x00    /* STA->STA */
+#define        IEEE80211_FC1_DIR_TODS                  0x01    /* STA->AP  */
+#define        IEEE80211_FC1_DIR_FROMDS                0x02    /* AP ->STA */
+#define        IEEE80211_FC1_DIR_DSTODS                0x03    /* AP ->AP  */
+
+#define        IEEE80211_FC1_MORE_FRAG                 0x04
+#define        IEEE80211_FC1_RETRY                     0x08
+#define        IEEE80211_FC1_PWR_MGT                   0x10
+#define        IEEE80211_FC1_MORE_DATA                 0x20
+#define        IEEE80211_FC1_WEP                       0x40
+#define        IEEE80211_FC1_ORDER                     0x80
+
+#define        IEEE80211_SEQ_FRAG_MASK                 0x000f
+#define        IEEE80211_SEQ_FRAG_SHIFT                0
+#define        IEEE80211_SEQ_SEQ_MASK                  0xfff0
+#define        IEEE80211_SEQ_SEQ_SHIFT                 4
+
+#define        IEEE80211_NWID_LEN                      32
+
+#define        IEEE80211_QOS_TXOP                      0x00ff
+/* bit 8 is reserved */
+#define        IEEE80211_QOS_ACKPOLICY                 0x60
+#define        IEEE80211_QOS_ACKPOLICY_S               5
+#define        IEEE80211_QOS_ESOP                      0x10
+#define        IEEE80211_QOS_ESOP_S                    4
+#define        IEEE80211_QOS_TID                       0x0f
+
+/* does frame have QoS sequence control data */
+#define        IEEE80211_QOS_HAS_SEQ(wh) \
+       (((wh)->i_fc[0] & \
+         (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
+         (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
+
+/*
+ * WME/802.11e information element.
+ */
+struct ieee80211_wme_info {
+       u_int8_t        wme_id;         /* IEEE80211_ELEMID_VENDOR */
+       u_int8_t        wme_len;        /* length in bytes */
+       u_int8_t        wme_oui[3];     /* 0x00, 0x50, 0xf2 */
+       u_int8_t        wme_type;       /* OUI type */
+       u_int8_t        wme_subtype;    /* OUI subtype */
+       u_int8_t        wme_version;    /* spec revision */
+       u_int8_t        wme_info;       /* QoS info */
+} GNUNET_PACKED;
+
+/*
+ * WME/802.11e Tspec Element
+ */
+struct ieee80211_wme_tspec {
+       u_int8_t        ts_id;
+       u_int8_t        ts_len;
+       u_int8_t        ts_oui[3];
+       u_int8_t        ts_oui_type;
+       u_int8_t        ts_oui_subtype;
+       u_int8_t        ts_version;
+       u_int8_t        ts_tsinfo[3];
+       u_int8_t        ts_nom_msdu[2];
+       u_int8_t        ts_max_msdu[2];
+       u_int8_t        ts_min_svc[4];
+       u_int8_t        ts_max_svc[4];
+       u_int8_t        ts_inactv_intv[4];
+       u_int8_t        ts_susp_intv[4];
+       u_int8_t        ts_start_svc[4];
+       u_int8_t        ts_min_rate[4];
+       u_int8_t        ts_mean_rate[4];
+       u_int8_t        ts_max_burst[4];
+       u_int8_t        ts_min_phy[4];
+       u_int8_t        ts_peak_rate[4];
+       u_int8_t        ts_delay[4];
+       u_int8_t        ts_surplus[2];
+       u_int8_t        ts_medium_time[2];
+} GNUNET_PACKED;
+
+/*
+ * WME AC parameter field
+ */
+struct ieee80211_wme_acparams {
+       u_int8_t        acp_aci_aifsn;
+       u_int8_t        acp_logcwminmax;
+       u_int16_t       acp_txop;
+} GNUNET_PACKED;
+
+#define WME_NUM_AC             4       /* 4 AC categories */
+
+#define WME_PARAM_ACI          0x60    /* Mask for ACI field */
+#define WME_PARAM_ACI_S                5       /* Shift for ACI field */
+#define WME_PARAM_ACM          0x10    /* Mask for ACM bit */
+#define WME_PARAM_ACM_S                4       /* Shift for ACM bit */
+#define WME_PARAM_AIFSN                0x0f    /* Mask for aifsn field */
+#define WME_PARAM_AIFSN_S      0       /* Shift for aifsn field */
+#define WME_PARAM_LOGCWMIN     0x0f    /* Mask for CwMin field (in log) */
+#define WME_PARAM_LOGCWMIN_S   0       /* Shift for CwMin field */
+#define WME_PARAM_LOGCWMAX     0xf0    /* Mask for CwMax field (in log) */
+#define WME_PARAM_LOGCWMAX_S   4       /* Shift for CwMax field */
+
+#define WME_AC_TO_TID(_ac) (       \
+       ((_ac) == WME_AC_VO) ? 6 : \
+       ((_ac) == WME_AC_VI) ? 5 : \
+       ((_ac) == WME_AC_BK) ? 1 : \
+       0)
+
+#define TID_TO_WME_AC(_tid) (      \
+       ((_tid) < 1) ? WME_AC_BE : \
+       ((_tid) < 3) ? WME_AC_BK : \
+       ((_tid) < 6) ? WME_AC_VI : \
+       WME_AC_VO)
+
+/*
+ * WME Parameter Element
+ */
+struct ieee80211_wme_param {
+       u_int8_t        param_id;
+       u_int8_t        param_len;
+       u_int8_t        param_oui[3];
+       u_int8_t        param_oui_type;
+       u_int8_t        param_oui_sybtype;
+       u_int8_t        param_version;
+       u_int8_t        param_qosInfo;
+#define        WME_QOSINFO_COUNT       0x0f    /* Mask for param count field */
+       u_int8_t        param_reserved;
+       struct ieee80211_wme_acparams   params_acParams[WME_NUM_AC];
+} GNUNET_PACKED;
+
+/*
+ * Management Notification Frame
+ */
+struct ieee80211_mnf {
+       u_int8_t        mnf_category;
+       u_int8_t        mnf_action;
+       u_int8_t        mnf_dialog;
+       u_int8_t        mnf_status;
+} GNUNET_PACKED;
+#define        MNF_SETUP_REQ   0
+#define        MNF_SETUP_RESP  1
+#define        MNF_TEARDOWN    2
+
+/*
+ * Control frames.
+ */
+struct ieee80211_frame_min {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_addr1[IEEE80211_ADDR_LEN];
+       u_int8_t        i_addr2[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+struct ieee80211_frame_rts {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_ra[IEEE80211_ADDR_LEN];
+       u_int8_t        i_ta[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+struct ieee80211_frame_cts {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_ra[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+struct ieee80211_frame_ack {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];
+       u_int8_t        i_ra[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+struct ieee80211_frame_pspoll {
+       u_int8_t        i_fc[2];
+       u_int8_t        i_aid[2];
+       u_int8_t        i_bssid[IEEE80211_ADDR_LEN];
+       u_int8_t        i_ta[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+struct ieee80211_frame_cfend {         /* NB: also CF-End+CF-Ack */
+       u_int8_t        i_fc[2];
+       u_int8_t        i_dur[2];       /* should be zero */
+       u_int8_t        i_ra[IEEE80211_ADDR_LEN];
+       u_int8_t        i_bssid[IEEE80211_ADDR_LEN];
+       /* FCS */
+} GNUNET_PACKED;
+
+/*
+ * BEACON management packets
+ *
+ *     octet timestamp[8]
+ *     octet beacon interval[2]
+ *     octet capability information[2]
+ *     information element
+ *             octet elemid
+ *             octet length
+ *             octet information[length]
+ */
+
+typedef u_int8_t *ieee80211_mgt_beacon_t;
+
+#define        IEEE80211_BEACON_INTERVAL(beacon) \
+       ((beacon)[8] | ((beacon)[9] << 8))
+#define        IEEE80211_BEACON_CAPABILITY(beacon) \
+       ((beacon)[10] | ((beacon)[11] << 8))
+
+#define        IEEE80211_CAPINFO_ESS                   0x0001
+#define        IEEE80211_CAPINFO_IBSS                  0x0002
+#define        IEEE80211_CAPINFO_CF_POLLABLE           0x0004
+#define        IEEE80211_CAPINFO_CF_POLLREQ            0x0008
+#define        IEEE80211_CAPINFO_PRIVACY               0x0010
+#define        IEEE80211_CAPINFO_SHORT_PREAMBLE        0x0020
+#define        IEEE80211_CAPINFO_PBCC                  0x0040
+#define        IEEE80211_CAPINFO_CHNL_AGILITY          0x0080
+/* bits 8-9 are reserved */
+#define        IEEE80211_CAPINFO_SHORT_SLOTTIME        0x0400
+#define        IEEE80211_CAPINFO_RSN                   0x0800
+/* bit 12 is reserved */
+#define        IEEE80211_CAPINFO_DSSSOFDM              0x2000
+/* bits 14-15 are reserved */
+
+/*
+ * 802.11i/WPA information element (maximally sized).
+ */
+struct ieee80211_ie_wpa {
+       u_int8_t        wpa_id;         /* IEEE80211_ELEMID_VENDOR */
+       u_int8_t        wpa_len;        /* length in bytes */
+       u_int8_t        wpa_oui[3];     /* 0x00, 0x50, 0xf2 */
+       u_int8_t        wpa_type;       /* OUI type */
+       u_int16_t       wpa_version;    /* spec revision */
+       u_int32_t       wpa_mcipher[1]; /* multicast/group key cipher */
+       u_int16_t       wpa_uciphercnt; /* # pairwise key ciphers */
+       u_int32_t       wpa_uciphers[8];/* ciphers */
+       u_int16_t       wpa_authselcnt; /* authentication selector cnt*/
+       u_int32_t       wpa_authsels[8];/* selectors */
+       u_int16_t       wpa_caps;       /* 802.11i capabilities */
+       u_int16_t       wpa_pmkidcnt;   /* 802.11i pmkid count */
+       u_int16_t       wpa_pmkids[8];  /* 802.11i pmkids */
+} GNUNET_PACKED;
+
+/*
+ * Management information element payloads.
+ */
+
+enum {
+       IEEE80211_ELEMID_SSID           = 0,
+       IEEE80211_ELEMID_RATES          = 1,
+       IEEE80211_ELEMID_FHPARMS        = 2,
+       IEEE80211_ELEMID_DSPARMS        = 3,
+       IEEE80211_ELEMID_CFPARMS        = 4,
+       IEEE80211_ELEMID_TIM            = 5,
+       IEEE80211_ELEMID_IBSSPARMS      = 6,
+       IEEE80211_ELEMID_COUNTRY        = 7,
+       IEEE80211_ELEMID_CHALLENGE      = 16,
+       /* 17-31 reserved for challenge text extension */
+       IEEE80211_ELEMID_ERP            = 42,
+       IEEE80211_ELEMID_RSN            = 48,
+       IEEE80211_ELEMID_XRATES         = 50,
+       IEEE80211_ELEMID_TPC            = 150,
+       IEEE80211_ELEMID_CCKM           = 156,
+       IEEE80211_ELEMID_VENDOR         = 221,  /* vendor private */
+};
+
+struct ieee80211_tim_ie {
+       u_int8_t        tim_ie;                 /* IEEE80211_ELEMID_TIM */
+       u_int8_t        tim_len;
+       u_int8_t        tim_count;              /* DTIM count */
+       u_int8_t        tim_period;             /* DTIM period */
+       u_int8_t        tim_bitctl;             /* bitmap control */
+       u_int8_t        tim_bitmap[1];          /* variable-length bitmap */
+} GNUNET_PACKED;
+
+struct ieee80211_country_ie {
+       u_int8_t        ie;                     /* IEEE80211_ELEMID_COUNTRY */
+       u_int8_t        len;
+       u_int8_t        cc[3];                  /* ISO CC+(I)ndoor/(O)utdoor */
+       struct {
+               u_int8_t schan;                 /* starting channel */
+               u_int8_t nchan;                 /* number channels */
+               u_int8_t maxtxpwr;              /* tx power cap */
+       } GNUNET_PACKED band[4];                        /* up to 4 sub bands */
+} GNUNET_PACKED;
+
+#define IEEE80211_CHALLENGE_LEN                128
+
+#define        IEEE80211_RATE_BASIC            0x80
+#define        IEEE80211_RATE_VAL              0x7f
+
+/* EPR information element flags */
+#define        IEEE80211_ERP_NON_ERP_PRESENT   0x01
+#define        IEEE80211_ERP_USE_PROTECTION    0x02
+#define        IEEE80211_ERP_LONG_PREAMBLE     0x04
+
+/* Atheros private advanced capabilities info */
+#define        ATHEROS_CAP_TURBO_PRIME         0x01
+#define        ATHEROS_CAP_COMPRESSION         0x02
+#define        ATHEROS_CAP_FAST_FRAME          0x04
+/* bits 3-6 reserved */
+#define        ATHEROS_CAP_BOOST               0x80
+
+#define        ATH_OUI                 0x7f0300                /* Atheros OUI 
*/
+#define        ATH_OUI_TYPE            0x01
+#define        ATH_OUI_VERSION         0x01
+
+#define        WPA_OUI                 0xf25000
+#define        WPA_OUI_TYPE            0x01
+#define        WPA_VERSION             1               /* current supported 
version */
+
+#define        WPA_CSE_NULL            0x00
+#define        WPA_CSE_WEP40           0x01
+#define        WPA_CSE_TKIP            0x02
+#define        WPA_CSE_CCMP            0x04
+#define        WPA_CSE_WEP104          0x05
+
+#define        WPA_ASE_NONE            0x00
+#define        WPA_ASE_8021X_UNSPEC    0x01
+#define        WPA_ASE_8021X_PSK       0x02
+
+#define        RSN_OUI                 0xac0f00
+#define        RSN_VERSION             1               /* current supported 
version */
+
+#define        RSN_CSE_NULL            0x00
+#define        RSN_CSE_WEP40           0x01
+#define        RSN_CSE_TKIP            0x02
+#define        RSN_CSE_WRAP            0x03
+#define        RSN_CSE_CCMP            0x04
+#define        RSN_CSE_WEP104          0x05
+
+#define        RSN_ASE_NONE            0x00
+#define        RSN_ASE_8021X_UNSPEC    0x01
+#define        RSN_ASE_8021X_PSK       0x02
+
+#define        RSN_CAP_PREAUTH         0x01
+
+#define        WME_OUI                 0xf25000
+#define        WME_OUI_TYPE            0x02
+#define        WME_INFO_OUI_SUBTYPE    0x00
+#define        WME_PARAM_OUI_SUBTYPE   0x01
+#define        WME_VERSION             1
+
+/* WME stream classes */
+#define        WME_AC_BE       0               /* best effort */
+#define        WME_AC_BK       1               /* background */
+#define        WME_AC_VI       2               /* video */
+#define        WME_AC_VO       3               /* voice */
+
+/*
+ * AUTH management packets
+ *
+ *     octet algo[2]
+ *     octet seq[2]
+ *     octet status[2]
+ *     octet chal.id
+ *     octet chal.length
+ *     octet chal.text[253]
+ */
+
+typedef u_int8_t *ieee80211_mgt_auth_t;
+
+#define        IEEE80211_AUTH_ALGORITHM(auth) \
+       ((auth)[0] | ((auth)[1] << 8))
+#define        IEEE80211_AUTH_TRANSACTION(auth) \
+       ((auth)[2] | ((auth)[3] << 8))
+#define        IEEE80211_AUTH_STATUS(auth) \
+       ((auth)[4] | ((auth)[5] << 8))
+
+#define        IEEE80211_AUTH_ALG_OPEN         0x0000
+#define        IEEE80211_AUTH_ALG_SHARED       0x0001
+#define        IEEE80211_AUTH_ALG_LEAP         0x0080
+
+enum {
+       IEEE80211_AUTH_OPEN_REQUEST             = 1,
+       IEEE80211_AUTH_OPEN_RESPONSE            = 2,
+};
+
+enum {
+       IEEE80211_AUTH_SHARED_REQUEST           = 1,
+       IEEE80211_AUTH_SHARED_CHALLENGE         = 2,
+       IEEE80211_AUTH_SHARED_RESPONSE          = 3,
+       IEEE80211_AUTH_SHARED_PASS              = 4,
+};
+
+/*
+ * Reason codes
+ *
+ * Unlisted codes are reserved
+ */
+
+enum {
+       IEEE80211_REASON_UNSPECIFIED            = 1,
+       IEEE80211_REASON_AUTH_EXPIRE            = 2,
+       IEEE80211_REASON_AUTH_LEAVE             = 3,
+       IEEE80211_REASON_ASSOC_EXPIRE           = 4,
+       IEEE80211_REASON_ASSOC_TOOMANY          = 5,
+       IEEE80211_REASON_NOT_AUTHED             = 6,
+       IEEE80211_REASON_NOT_ASSOCED            = 7,
+       IEEE80211_REASON_ASSOC_LEAVE            = 8,
+       IEEE80211_REASON_ASSOC_NOT_AUTHED       = 9,
+
+       IEEE80211_REASON_RSN_REQUIRED           = 11,
+       IEEE80211_REASON_RSN_INCONSISTENT       = 12,
+       IEEE80211_REASON_IE_INVALID             = 13,
+       IEEE80211_REASON_MIC_FAILURE            = 14,
+
+       IEEE80211_STATUS_SUCCESS                = 0,
+       IEEE80211_STATUS_UNSPECIFIED            = 1,
+       IEEE80211_STATUS_CAPINFO                = 10,
+       IEEE80211_STATUS_NOT_ASSOCED            = 11,
+       IEEE80211_STATUS_OTHER                  = 12,
+       IEEE80211_STATUS_ALG                    = 13,
+       IEEE80211_STATUS_SEQUENCE               = 14,
+       IEEE80211_STATUS_CHALLENGE              = 15,
+       IEEE80211_STATUS_TIMEOUT                = 16,
+       IEEE80211_STATUS_TOOMANY                = 17,
+       IEEE80211_STATUS_BASIC_RATE             = 18,
+       IEEE80211_STATUS_SP_REQUIRED            = 19,
+       IEEE80211_STATUS_PBCC_REQUIRED          = 20,
+       IEEE80211_STATUS_CA_REQUIRED            = 21,
+       IEEE80211_STATUS_TOO_MANY_STATIONS      = 22,
+       IEEE80211_STATUS_RATES                  = 23,
+       IEEE80211_STATUS_SHORTSLOT_REQUIRED     = 25,
+       IEEE80211_STATUS_DSSSOFDM_REQUIRED      = 26,
+};
+
+#define        IEEE80211_WEP_KEYLEN            5       /* 40bit */
+#define        IEEE80211_WEP_IVLEN             3       /* 24bit */
+#define        IEEE80211_WEP_KIDLEN            1       /* 1 octet */
+#define        IEEE80211_WEP_CRCLEN            4       /* CRC-32 */
+#define        IEEE80211_WEP_NKID              4       /* number of key ids */
+
+/*
+ * 802.11i defines an extended IV for use with non-WEP ciphers.
+ * When the EXTIV bit is set in the key id byte an additional
+ * 4 bytes immediately follow the IV for TKIP.  For CCMP the
+ * EXTIV bit is likewise set but the 8 bytes represent the
+ * CCMP header rather than IV+extended-IV.
+ */
+#define        IEEE80211_WEP_EXTIV             0x20
+#define        IEEE80211_WEP_EXTIVLEN          4       /* extended IV length */
+#define        IEEE80211_WEP_MICLEN            8       /* trailing MIC */
+
+#define        IEEE80211_CRC_LEN               4
+
+/*
+ * Maximum acceptable MTU is:
+ *     IEEE80211_MAX_LEN - WEP overhead - CRC -
+ *             QoS overhead - RSN/WPA overhead
+ * Min is arbitrarily chosen > IEEE80211_MIN_LEN.  The default
+ * mtu is Ethernet-compatible; it's set by ether_ifattach.
+ */
+#define        IEEE80211_MTU_MAX               2290
+#define        IEEE80211_MTU_MIN               32
+
+#define        IEEE80211_MAX_LEN               (2300 + IEEE80211_CRC_LEN + \
+    (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
+#define        IEEE80211_ACK_LEN \
+       (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
+#define        IEEE80211_MIN_LEN \
+       (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
+
+/*
+ * The 802.11 spec says at most 2007 stations may be
+ * associated at once.  For most AP's this is way more
+ * than is feasible so we use a default of 128.  This
+ * number may be overridden by the driver and/or by
+ * user configuration.
+ */
+#define        IEEE80211_AID_MAX               2007
+#define        IEEE80211_AID_DEF               128
+
+#define        IEEE80211_AID(b)        ((b) &~ 0xc000)
+
+/* 
+ * RTS frame length parameters.  The default is specified in
+ * the 802.11 spec as 512; we treat it as implementation-dependent
+ * so it's defined in ieee80211_var.h.  The max may be wrong
+ * for jumbo frames.
+ */
+#define        IEEE80211_RTS_MIN               1
+#define        IEEE80211_RTS_MAX               2346
+
+/* 
+ * TX fragmentation parameters.  As above for RTS, we treat
+ * default as implementation-dependent so define it elsewhere.
+ */
+#define        IEEE80211_FRAG_MIN              256
+#define        IEEE80211_FRAG_MAX              2346
+
+/*
+ * Beacon interval (TU's).  Min+max come from WiFi requirements.
+ * As above, we treat default as implementation-dependent so
+ * define it elsewhere.
+ */
+#define        IEEE80211_BINTVAL_MAX   1000    /* max beacon interval (TU's) */
+#define        IEEE80211_BINTVAL_MIN   25      /* min beacon interval (TU's) */
+
+/*
+ * DTIM period (beacons).  Min+max are not really defined
+ * by the protocol but we want them publicly visible so
+ * define them here.
+ */
+#define        IEEE80211_DTIM_MAX      15      /* max DTIM period */
+#define        IEEE80211_DTIM_MIN      1       /* min DTIM period */
+
+/*
+ * Beacon miss threshold (beacons).  As for DTIM, we define
+ * them here to be publicly visible.  Note the max may be
+ * clamped depending on device capabilities.
+ */
+#define        IEEE80211_HWBMISS_MIN   1
+#define        IEEE80211_HWBMISS_MAX   255
+
+#endif /* _NET80211_IEEE80211_H_ */

Added: gnunet/src/transport/wlan/ieee80211_radiotap.h
===================================================================
--- gnunet/src/transport/wlan/ieee80211_radiotap.h                              
(rev 0)
+++ gnunet/src/transport/wlan/ieee80211_radiotap.h      2011-03-28 21:52:47 UTC 
(rev 14758)
@@ -0,0 +1,260 @@
+/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 
sam Exp $ */
+/* $NetBSD: ieee80211_radiotap.h,v 1.11 2005/06/22 06:16:02 dyoung Exp $ */
+
+/*-
+ * Copyright (c) 2003, 2004 David Young.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of David Young may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DAVID
+ * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+/*
+ * Modifications to fit into the linux IEEE 802.11 stack,
+ * Mike Kershaw (address@hidden)
+ */
+
+#ifndef IEEE80211RADIOTAP_H
+#define IEEE80211RADIOTAP_H
+
+/* Radiotap header version (from official NetBSD feed) */
+#define IEEE80211RADIOTAP_VERSION      "1.5"
+/* Base version of the radiotap packet header data */
+#define PKTHDR_RADIOTAP_VERSION                0
+
+/* A generic radio capture format is desirable. There is one for
+ * Linux, but it is neither rigidly defined (there were not even
+ * units given for some fields) nor easily extensible.
+ *
+ * I suggest the following extensible radio capture format. It is
+ * based on a bitmap indicating which fields are present.
+ *
+ * I am trying to describe precisely what the application programmer
+ * should expect in the following, and for that reason I tell the
+ * units and origin of each measurement (where it applies), or else I
+ * use sufficiently weaselly language ("is a monotonically nondecreasing
+ * function of...") that I cannot set false expectations for lawyerly
+ * readers.
+ */
+
+/* XXX tcpdump/libpcap do not tolerate variable-length headers,
+ * yet, so we pad every radiotap header to 64 bytes. Ugh.
+ */
+#define IEEE80211_RADIOTAP_HDRLEN      64
+
+/* The radio capture header precedes the 802.11 header.
+ * All data in the header is little endian on all platforms.
+ */
+struct ieee80211_radiotap_header {
+       u8 it_version;          /* Version 0. Only increases
+                                * for drastic changes,
+                                * introduction of compatible
+                                * new fields does not count.
+                                */
+       u8 it_pad;
+       u16 it_len;             /* length of the whole
+                                * header in bytes, including
+                                * it_version, it_pad,
+                                * it_len, and data fields.
+                                */
+       u32 it_present;         /* A bitmap telling which
+                                * fields are present. Set bit 31
+                                * (0x80000000) to extend the
+                                * bitmap by another 32 bits.
+                                * Additional extensions are made
+                                * by setting bit 31.
+                                */
+};
+
+#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
+
+/* Name                                 Data type    Units
+ * ----                                 ---------    -----
+ *
+ * IEEE80211_RADIOTAP_TSFT              __le64       microseconds
+ *
+ *      Value in microseconds of the MAC's 64-bit 802.11 Time
+ *      Synchronization Function timer when the first bit of the
+ *      MPDU arrived at the MAC. For received frames, only.
+ *
+ * IEEE80211_RADIOTAP_CHANNEL           2 x __le16   MHz, bitmap
+ *
+ *      Tx/Rx frequency in MHz, followed by flags (see below).
+ *
+ * IEEE80211_RADIOTAP_FHSS              __le16       see below
+ *
+ *      For frequency-hopping radios, the hop set (first byte)
+ *      and pattern (second byte).
+ *
+ * IEEE80211_RADIOTAP_RATE              u8           500kb/s
+ *
+ *      Tx/Rx data rate
+ *
+ * IEEE80211_RADIOTAP_DBM_ANTSIGNAL     s8           decibels from
+ *                                                   one milliwatt (dBm)
+ *
+ *      RF signal power at the antenna, decibel difference from
+ *      one milliwatt.
+ *
+ * IEEE80211_RADIOTAP_DBM_ANTNOISE      s8           decibels from
+ *                                                   one milliwatt (dBm)
+ *
+ *      RF noise power at the antenna, decibel difference from one
+ *      milliwatt.
+ *
+ * IEEE80211_RADIOTAP_DB_ANTSIGNAL      u8           decibel (dB)
+ *
+ *      RF signal power at the antenna, decibel difference from an
+ *      arbitrary, fixed reference.
+ *
+ * IEEE80211_RADIOTAP_DB_ANTNOISE       u8           decibel (dB)
+ *
+ *      RF noise power at the antenna, decibel difference from an
+ *      arbitrary, fixed reference point.
+ *
+ * IEEE80211_RADIOTAP_LOCK_QUALITY      __le16       unitless
+ *
+ *      Quality of Barker code lock. Unitless. Monotonically
+ *      nondecreasing with "better" lock strength. Called "Signal
+ *      Quality" in datasheets.  (Is there a standard way to measure
+ *      this?)
+ *
+ * IEEE80211_RADIOTAP_TX_ATTENUATION    __le16       unitless
+ *
+ *      Transmit power expressed as unitless distance from max
+ *      power set at factory calibration.  0 is max power.
+ *      Monotonically nondecreasing with lower power levels.
+ *
+ * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16       decibels (dB)
+ *
+ *      Transmit power expressed as decibel distance from max power
+ *      set at factory calibration.  0 is max power.  Monotonically
+ *      nondecreasing with lower power levels.
+ *
+ * IEEE80211_RADIOTAP_DBM_TX_POWER      s8           decibels from
+ *                                                   one milliwatt (dBm)
+ *
+ *      Transmit power expressed as dBm (decibels from a 1 milliwatt
+ *      reference). This is the absolute power level measured at
+ *      the antenna port.
+ *
+ * IEEE80211_RADIOTAP_FLAGS             u8           bitmap
+ *
+ *      Properties of transmitted and received frames. See flags
+ *      defined below.
+ *
+ * IEEE80211_RADIOTAP_ANTENNA           u8           antenna index
+ *
+ *      Unitless indication of the Rx/Tx antenna for this packet.
+ *      The first antenna is antenna 0.
+ *
+ * IEEE80211_RADIOTAP_RX_FLAGS          __le16       bitmap
+ *
+ *     Properties of received frames. See flags defined below.
+ *
+ * IEEE80211_RADIOTAP_TX_FLAGS          __le16       bitmap
+ *
+ *     Properties of transmitted frames. See flags defined below.
+ *
+ * IEEE80211_RADIOTAP_RTS_RETRIES       u8           data
+ *
+ *     Number of rts retries a transmitted frame used.
+ *
+ * IEEE80211_RADIOTAP_DATA_RETRIES      u8           data
+ *
+ *     Number of unicast retries a transmitted frame used.
+ *
+ */
+enum ieee80211_radiotap_type {
+       IEEE80211_RADIOTAP_TSFT = 0,
+       IEEE80211_RADIOTAP_FLAGS = 1,
+       IEEE80211_RADIOTAP_RATE = 2,
+       IEEE80211_RADIOTAP_CHANNEL = 3,
+       IEEE80211_RADIOTAP_FHSS = 4,
+       IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
+       IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
+       IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
+       IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
+       IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
+       IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
+       IEEE80211_RADIOTAP_ANTENNA = 11,
+       IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
+       IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
+       IEEE80211_RADIOTAP_RX_FLAGS = 14,
+       IEEE80211_RADIOTAP_TX_FLAGS = 15,
+       IEEE80211_RADIOTAP_RTS_RETRIES = 16,
+       IEEE80211_RADIOTAP_DATA_RETRIES = 17,
+       IEEE80211_RADIOTAP_EXT = 31
+};
+
+/* Channel flags. */
+#define        IEEE80211_CHAN_TURBO    0x0010  /* Turbo channel */
+#define        IEEE80211_CHAN_CCK      0x0020  /* CCK channel */
+#define        IEEE80211_CHAN_OFDM     0x0040  /* OFDM channel */
+#define        IEEE80211_CHAN_2GHZ     0x0080  /* 2 GHz spectrum channel. */
+#define        IEEE80211_CHAN_5GHZ     0x0100  /* 5 GHz spectrum channel */
+#define        IEEE80211_CHAN_PASSIVE  0x0200  /* Only passive scan allowed */
+#define        IEEE80211_CHAN_DYN      0x0400  /* Dynamic CCK-OFDM channel */
+#define        IEEE80211_CHAN_GFSK     0x0800  /* GFSK channel (FHSS PHY) */
+
+/* For IEEE80211_RADIOTAP_FLAGS */
+#define        IEEE80211_RADIOTAP_F_CFP        0x01    /* sent/received
+                                                * during CFP
+                                                */
+#define        IEEE80211_RADIOTAP_F_SHORTPRE   0x02    /* sent/received
+                                                * with short
+                                                * preamble
+                                                */
+#define        IEEE80211_RADIOTAP_F_WEP        0x04    /* sent/received
+                                                * with WEP encryption
+                                                */
+#define        IEEE80211_RADIOTAP_F_FRAG       0x08    /* sent/received
+                                                * with fragmentation
+                                                */
+#define        IEEE80211_RADIOTAP_F_FCS        0x10    /* frame includes FCS */
+#define        IEEE80211_RADIOTAP_F_DATAPAD    0x20    /* frame has padding 
between
+                                                * 802.11 header and payload
+                                                * (to 32-bit boundary)
+                                                */
+/* For IEEE80211_RADIOTAP_RX_FLAGS */
+#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001  /* frame failed crc check */
+
+/* For IEEE80211_RADIOTAP_TX_FLAGS */
+#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001  /* failed due to excessive
+                                                * retries */
+#define IEEE80211_RADIOTAP_F_TX_CTS    0x0002  /* used cts 'protection' */
+#define IEEE80211_RADIOTAP_F_TX_RTS    0x0004  /* used rts/cts handshake */
+#define IEEE80211_RADIOTAP_F_TX_NOACK  0x0008  /* frame should not be ACKed */
+#define IEEE80211_RADIOTAP_F_TX_NOSEQ  0x0010  /* sequence number handled
+                                                * by userspace */
+
+/* Ugly macro to convert literal channel numbers into their mhz equivalents
+ * There are certianly some conditions that will break this (like feeding it 
'30')
+ * but they shouldn't arise since nothing talks on channel 30. */
+#define ieee80211chan2mhz(x) \
+       (((x) <= 14) ? \
+       (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
+       ((x) + 1000) * 5)
+
+#endif                         /* IEEE80211_RADIOTAP_H */

Added: gnunet/src/transport/wlan/loopback_helper.c
===================================================================
--- gnunet/src/transport/wlan/loopback_helper.c                         (rev 0)
+++ gnunet/src/transport/wlan/loopback_helper.c 2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,428 @@
+
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+#include <utime.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "gnunet_constants.h"
+#include "gnunet_os_lib.h"
+#include "gnunet_transport_plugin.h"
+#include "transport.h"
+#include "gnunet_util_lib.h"
+#include "plugin_transport_wlan.h"
+#include "gnunet_common.h"
+#include "gnunet-transport-wlan-helper.h"
+#include "gnunet_crypto_lib.h"
+#include "loopback_helper.h"
+#include "helper_common.h"
+
+extern int first;
+
+static void
+sigfunc(int sig)
+{
+  closeprog = 1;
+  unlink(FIFO_FILE1);
+  unlink(FIFO_FILE2);
+}
+
+static void
+stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+{
+  struct sendbuf *write_pout = cls;
+  int sendsize;
+  struct GNUNET_MessageHeader newheader;
+  unsigned char * from;
+  unsigned char * to;
+
+  sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send);
+
+  if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
+    {
+      fprintf(stderr, "Function stdin_send: wrong packet type\n");
+      exit(1);
+    }
+  if ((sendsize + write_pout->size) > MAXLINE * 2)
+    {
+      fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
+      exit(1);
+    }
+
+  newheader.size = htons(sendsize);
+  newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+
+  to = write_pout->buf + write_pout->size;
+  memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader));
+  write_pout->size += sizeof(struct GNUNET_MessageHeader);
+
+  from = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send)
+      + sizeof(struct GNUNET_MessageHeader);
+  to = write_pout->buf + write_pout->size;
+  memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader));
+  write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader);
+}
+
+static void
+file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+{
+  struct sendbuf * write_std = cls;
+  uint16_t sendsize;
+
+  sendsize = ntohs(hdr->size);
+
+  if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
+    {
+      fprintf(stderr, "Function file_in_send: wrong packet type\n");
+      exit(1);
+    }
+  if ((sendsize + write_std->size) > MAXLINE * 2)
+    {
+      fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
+      exit(1);
+    }
+
+  memcpy(write_std->buf + write_std->size, hdr, sendsize);
+  write_std->size += sendsize;
+}
+
+int
+testmode(int argc, char *argv[])
+{
+  struct stat st;
+  int erg;
+
+  FILE *fpin;
+  FILE *fpout;
+
+  int fdpin;
+  int fdpout;
+
+  //make the fifos if needed
+  if (0 != stat(FIFO_FILE1, &st))
+    {
+      if (0 == stat(FIFO_FILE2, &st))
+        {
+          fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
+          exit(1);
+        }
+
+      umask(0);
+      erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
+      erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
+
+    }
+  else
+    {
+
+      if (0 != stat(FIFO_FILE2, &st))
+        {
+          fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
+          exit(1);
+        }
+
+    }
+
+  if (strstr(argv[2], "1"))
+    {
+      //fprintf(stderr, "First\n");
+      first = 1;
+      fpin = fopen(FIFO_FILE1, "r");
+      if (NULL == fpin)
+        {
+          fprintf(stderr, "fopen of read FIFO_FILE1\n");
+          exit(1);
+        }
+      if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
+        {
+          fprintf(stderr, "fopen of write FIFO_FILE2\n");
+          exit(1);
+        }
+
+    }
+  else
+    {
+      first = 0;
+      //fprintf(stderr, "Second\n");
+      if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
+        {
+          fprintf(stderr, "fopen of write FIFO_FILE1\n");
+          exit(1);
+        }
+      if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
+        {
+          fprintf(stderr, "fopen of read FIFO_FILE2\n");
+          exit(1);
+        }
+
+    }
+
+  fdpin = fileno(fpin);
+  if (fdpin >= FD_SETSIZE)
+    {
+      fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
+          (unsigned int) FD_SETSIZE);
+      close(fdpin);
+      return -1;
+    }
+
+  fdpout = fileno(fpout);
+  if (fdpout >= FD_SETSIZE)
+    {
+      fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
+          (unsigned int) FD_SETSIZE);
+      close(fdpout);
+      return -1;
+
+    }
+
+  signal(SIGINT, &sigfunc);
+  signal(SIGTERM, &sigfunc);
+
+  char readbuf[MAXLINE];
+  int readsize = 0;
+  struct sendbuf write_std;
+  write_std.size = 0;
+  write_std.pos = 0;
+
+  struct sendbuf write_pout;
+  write_pout.size = 0;
+  write_pout.pos = 0;
+
+  int ret = 0;
+  int maxfd = 0;
+
+  fd_set rfds;
+  fd_set wfds;
+  struct timeval tv;
+  int retval;
+
+  struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
+  struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
+
+  stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
+  file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
+
+  //send mac first
+
+  struct MacAddress macaddr;
+
+  //Send random mac address
+  macaddr.mac[0] = 0x13;
+  macaddr.mac[1] = 0x22;
+  macaddr.mac[2] = 0x33;
+  macaddr.mac[3] = 0x44;
+  macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
+  macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
+
+  write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac);
+
+  /*
+   //wait
+   tv.tv_sec = 2;
+   tv.tv_usec = 0;
+   retval = select(0, NULL, NULL, NULL, &tv);
+
+
+   tv.tv_sec = 3;
+   tv.tv_usec = 0;
+   // if there is something to write
+   FD_ZERO(&wfds);
+   FD_SET(STDOUT_FILENO, &wfds);
+
+   retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv);
+
+   if (FD_ISSET(STDOUT_FILENO, &wfds))
+   {
+   ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size
+   - write_std.pos);
+
+   if (0 > ret)
+   {
+   closeprog = 1;
+   fprintf(stderr, "Write ERROR to STDOUT");
+   exit(1);
+   }
+   else
+   {
+   write_std.pos += ret;
+   // check if finished
+   if (write_std.pos == write_std.size)
+   {
+   write_std.pos = 0;
+   write_std.size = 0;
+   }
+   }
+   }
+
+   memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
+   write_std.size = sizeof(struct Wlan_Helper_Control_Message);
+   */
+
+  //wait
+  tv.tv_sec = 2;
+  tv.tv_usec = 0;
+  retval = select(0, NULL, NULL, NULL, &tv);
+
+  while (0 == closeprog)
+    {
+
+      maxfd = 0;
+
+      //set timeout
+      tv.tv_sec = 5;
+      tv.tv_usec = 0;
+
+      FD_ZERO(&rfds);
+      // if output queue is empty
+      if (0 == write_pout.size)
+        {
+          FD_SET(STDIN_FILENO, &rfds);
+
+        }
+      if (0 == write_std.size)
+        {
+          FD_SET(fdpin, &rfds);
+          maxfd = fdpin;
+        }
+      FD_ZERO(&wfds);
+      // if there is something to write
+      if (0 < write_std.size)
+        {
+          FD_SET(STDOUT_FILENO, &wfds);
+          maxfd = MAX(maxfd, STDOUT_FILENO);
+        }
+
+      if (0 < write_pout.size)
+        {
+          FD_SET(fdpout, &wfds);
+          maxfd = MAX(maxfd, fdpout);
+        }
+
+      retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
+
+      if (-1 == retval && EINTR == errno)
+        {
+          continue;
+        }
+      if (0 > retval)
+        {
+          fprintf(stderr, "select failed: %s\n", strerror(errno));
+          exit(1);
+        }
+
+      if (FD_ISSET(STDOUT_FILENO, &wfds))
+        {
+          ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
+              write_std.size - write_std.pos);
+
+          if (0 > ret)
+            {
+              closeprog = 1;
+              fprintf(stderr, "Write ERROR to STDOUT\n");
+              exit(1);
+            }
+          else
+            {
+              write_std.pos += ret;
+              // check if finished
+              if (write_std.pos == write_std.size)
+                {
+                  write_std.pos = 0;
+                  write_std.size = 0;
+                }
+            }
+        }
+
+      if (FD_ISSET(fdpout, &wfds))
+        {
+          ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
+              - write_pout.pos);
+
+          if (0 > ret)
+            {
+              closeprog = 1;
+              fprintf(stderr, "Write ERROR to fdpout\n");
+            }
+          else
+            {
+              write_pout.pos += ret;
+              // check if finished
+              if (write_pout.pos == write_pout.size)
+                {
+                  write_pout.pos = 0;
+                  write_pout.size = 0;
+                }
+            }
+        }
+
+      if (FD_ISSET(STDIN_FILENO, &rfds))
+        {
+          readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
+
+          if (0 > readsize)
+            {
+              closeprog = 1;
+              fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
+            }
+          else if (0 < readsize)
+            {
+              GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
+                  GNUNET_NO, GNUNET_NO);
+
+            }
+          else
+            {
+              //eof
+              closeprog = 1;
+            }
+        }
+
+      if (FD_ISSET(fdpin, &rfds))
+        {
+          readsize = read(fdpin, readbuf, sizeof(readbuf));
+
+          if (0 > readsize)
+            {
+              closeprog = 1;
+              fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
+              closeprog = 1;
+            }
+          else if (0 < readsize)
+            {
+              GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
+                  GNUNET_NO, GNUNET_NO);
+
+            }
+          else
+            {
+              //eof
+              closeprog = 1;
+            }
+        }
+
+    }
+
+  //clean up
+  fclose(fpout);
+  fclose(fpin);
+
+  if (1 == first)
+    {
+      unlink(FIFO_FILE1);
+      unlink(FIFO_FILE2);
+    }
+
+  return (0);
+}

Added: gnunet/src/transport/wlan/loopback_helper.h
===================================================================
--- gnunet/src/transport/wlan/loopback_helper.h                         (rev 0)
+++ gnunet/src/transport/wlan/loopback_helper.h 2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,20 @@
+/*
+ * loopback_helper.h
+ *
+ *  Created on: 28.03.2011
+ *      Author: David Brodski
+ */
+
+#ifndef LOOPBACK_HELPER_H_
+#define LOOPBACK_HELPER_H_
+
+//static void sigfunc(int sig);
+
+//static void stdin_send(void *cls, void *client, const struct 
GNUNET_MessageHeader *hdr);
+
+//static void file_in_send(void *cls, void *client, const struct 
GNUNET_MessageHeader *hdr);
+
+int
+testmode(int argc, char *argv[]);
+
+#endif /* LOOPBACK_HELPER_H_ */

Added: gnunet/src/transport/wlan/radiotap-parser.c
===================================================================
--- gnunet/src/transport/wlan/radiotap-parser.c                         (rev 0)
+++ gnunet/src/transport/wlan/radiotap-parser.c 2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,251 @@
+ /*
+  *  Copyright (c) 2007, 2008, Andy Green <address@hidden>
+  *
+  *  This program is free software; you can redistribute it and/or modify
+  *  it under the terms of the GNU General Public License as published by
+  *  the Free Software Foundation; either version 2 of the License, or
+  *  (at your option) any later version.
+  *
+  *  This program is distributed in the hope that it will be useful,
+  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  *  GNU General Public License for more details.
+  *
+  *  You should have received a copy of the GNU General Public License
+  *  along with this program; if not, write to the Free Software
+  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "radiotap-parser.h"
+
+
+/*
+ * Radiotap header iteration
+ *   implemented in src/radiotap-parser.c
+ *
+ * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
+ * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
+ * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
+ * if there are no more args in the header, or the next argument type index
+ * that is present.  The iterator's this_arg member points to the start of the
+ * argument associated with the current argument index that is present,
+ * which can be found in the iterator's this_arg_index member.  This arg
+ * index corresponds to the IEEE80211_RADIOTAP_... defines.
+ */
+
+
+int ieee80211_radiotap_iterator_init(
+       struct ieee80211_radiotap_iterator * iterator,
+       struct ieee80211_radiotap_header * radiotap_header,
+       int max_length)
+{
+       if(iterator == NULL)
+               return (-EINVAL);
+
+       if(radiotap_header == NULL)
+               return (-EINVAL);
+       /* Linux only supports version 0 radiotap format */
+
+       if (radiotap_header->it_version)
+               return (-EINVAL);
+
+       /* sanity check for allowed length and radiotap length field */
+
+       if (max_length < (le16_to_cpu(radiotap_header->it_len)))
+               return (-EINVAL);
+
+       iterator->rtheader = radiotap_header;
+       iterator->max_length = le16_to_cpu(radiotap_header->it_len);
+       iterator->arg_index = 0;
+       iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
+       iterator->arg = ((u8 *)radiotap_header) +
+                       sizeof (struct ieee80211_radiotap_header);
+       iterator->this_arg = 0;
+
+       /* find payload start allowing for extended bitmap(s) */
+
+       if (unlikely(iterator->bitmap_shifter &
+           IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
+               while (le32_to_cpu(*((u32 *)iterator->arg)) &
+                   IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
+                       iterator->arg += sizeof (u32);
+
+                       /*
+                        * check for insanity where the present bitmaps
+                        * keep claiming to extend up to or even beyond the
+                        * stated radiotap header length
+                        */
+
+                       if ((((void*)iterator->arg) - 
((void*)iterator->rtheader)) >
+                           iterator->max_length)
+                               return (-EINVAL);
+
+               }
+
+               iterator->arg += sizeof (u32);
+
+               /*
+                * no need to check again for blowing past stated radiotap
+                * header length, becuase ieee80211_radiotap_iterator_next
+                * checks it before it is dereferenced
+                */
+
+       }
+
+       /* we are all initialized happily */
+
+       return (0);
+}
+
+
+/**
+ * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
+ * @iterator: radiotap_iterator to move to next arg (if any)
+ *
+ * Returns: next present arg index on success or negative if no more or error
+ *
+ * This function returns the next radiotap arg index (IEEE80211_RADIOTAP_...)
+ * and sets iterator->this_arg to point to the payload for the arg.  It takes
+ * care of alignment handling and extended present fields.  interator->this_arg
+ * can be changed by the caller.  The args pointed to are in little-endian
+ * format.
+ */
+
+int ieee80211_radiotap_iterator_next(
+       struct ieee80211_radiotap_iterator * iterator)
+{
+
+       /*
+        * small length lookup table for all radiotap types we heard of
+        * starting from b0 in the bitmap, so we can walk the payload
+        * area of the radiotap header
+        *
+        * There is a requirement to pad args, so that args
+        * of a given length must begin at a boundary of that length
+        * -- but note that compound args are allowed (eg, 2 x u16
+        * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
+        * a reliable indicator of alignment requirement.
+        *
+        * upper nybble: content alignment for arg
+        * lower nybble: content length for arg
+        */
+
+       static const u8 rt_sizes[] = {
+               [IEEE80211_RADIOTAP_TSFT] = 0x88,
+               [IEEE80211_RADIOTAP_FLAGS] = 0x11,
+               [IEEE80211_RADIOTAP_RATE] = 0x11,
+               [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
+               [IEEE80211_RADIOTAP_FHSS] = 0x22,
+               [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
+               [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
+               [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
+               [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
+               [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
+               [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
+               [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
+               [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
+               [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
+               [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
+               [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
+               [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
+               [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
+               /*
+                * add more here as they are defined in
+                * include/net/ieee80211_radiotap.h
+                */
+       };
+
+       /*
+        * for every radiotap entry we can at
+        * least skip (by knowing the length)...
+        */
+
+       while (iterator->arg_index < (int)sizeof (rt_sizes)) {
+               int hit = 0;
+
+               if (!(iterator->bitmap_shifter & 1))
+                       goto next_entry; /* arg not present */
+
+               /*
+                * arg is present, account for alignment padding
+                *  8-bit args can be at any alignment
+                * 16-bit args must start on 16-bit boundary
+                * 32-bit args must start on 32-bit boundary
+                * 64-bit args must start on 64-bit boundary
+                *
+                * note that total arg size can differ from alignment of
+                * elements inside arg, so we use upper nybble of length
+                * table to base alignment on
+                *
+                * also note: these alignments are ** relative to the
+                * start of the radiotap header **.  There is no guarantee
+                * that the radiotap header itself is aligned on any
+                * kind of boundary.
+                */
+
+               if ((((void*)iterator->arg)-((void*)iterator->rtheader)) &
+                   ((rt_sizes[iterator->arg_index] >> 4) - 1))
+                       iterator->arg_index +=
+                               (rt_sizes[iterator->arg_index] >> 4) -
+                               ((((void*)iterator->arg) -
+                               ((void*)iterator->rtheader)) &
+                               ((rt_sizes[iterator->arg_index] >> 4) - 1));
+
+               /*
+                * this is what we will return to user, but we need to
+                * move on first so next call has something fresh to test
+                */
+
+               iterator->this_arg_index = iterator->arg_index;
+               iterator->this_arg = iterator->arg;
+               hit = 1;
+
+               /* internally move on the size of this arg */
+
+               iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
+
+               /*
+                * check for insanity where we are given a bitmap that
+                * claims to have more arg content than the length of the
+                * radiotap section.  We will normally end up equalling this
+                * max_length on the last arg, never exceeding it.
+                */
+
+               if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
+                   iterator->max_length)
+                       return (-EINVAL);
+
+       next_entry:
+
+               iterator->arg_index++;
+               if (unlikely((iterator->arg_index & 31) == 0)) {
+                       /* completed current u32 bitmap */
+                       if (iterator->bitmap_shifter & 1) {
+                               /* b31 was set, there is more */
+                               /* move to next u32 bitmap */
+                               iterator->bitmap_shifter = le32_to_cpu(
+                                       *iterator->next_bitmap);
+                               iterator->next_bitmap++;
+                       } else {
+                               /* no more bitmaps: end */
+                               iterator->arg_index = sizeof (rt_sizes);
+                       }
+               } else { /* just try the next bit */
+                       iterator->bitmap_shifter >>= 1;
+               }
+
+               /* if we found a valid arg earlier, return it now */
+
+               if (hit)
+                       return (iterator->this_arg_index);
+
+       }
+
+       /* we don't know how to handle any more args, we're done */
+
+       return (-1);
+}

Added: gnunet/src/transport/wlan/radiotap-parser.h
===================================================================
--- gnunet/src/transport/wlan/radiotap-parser.h                         (rev 0)
+++ gnunet/src/transport/wlan/radiotap-parser.h 2011-03-28 21:52:47 UTC (rev 
14758)
@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2007, 2008, Andy Green <address@hidden>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License along
+ *   with this program; if not, write to the Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#define        __user
+#include "byteorder.h"
+#include <stdint.h>
+
+typedef uint64_t u64;
+typedef uint32_t u32;
+typedef uint16_t u16;
+typedef uint8_t u8;
+
+#ifndef unlikely
+#define        unlikely(x) (x)
+#endif
+
+#include "ieee80211_radiotap.h"
+
+
+/*
+ * Radiotap header iteration
+ *   implemented in src/radiotap-parser.c
+ *
+ * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
+ * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
+ * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
+ * if there are no more args in the header, or the next argument type index
+ * that is present.  The iterator's this_arg member points to the start of the
+ * argument associated with the current argument index that is present,
+ * which can be found in the iterator's this_arg_index member.  This arg
+ * index corresponds to the IEEE80211_RADIOTAP_... defines.
+ */
+/**
+ * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
+ * @rtheader: pointer to the radiotap header we are walking through
+ * @max_length: length of radiotap header in cpu byte ordering
+ * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
+ * @this_arg: pointer to current radiotap arg
+ * @arg_index: internal next argument index
+ * @arg: internal next argument pointer
+ * @next_bitmap: internal pointer to next present u32
+ * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
+ */
+
+struct ieee80211_radiotap_iterator {
+       struct ieee80211_radiotap_header *rtheader;
+       int max_length;
+       int this_arg_index;
+       u8 * this_arg;
+
+       int arg_index;
+       u8 * arg;
+       u32 *next_bitmap;
+       u32 bitmap_shifter;
+};
+
+int ieee80211_radiotap_iterator_init(
+       struct ieee80211_radiotap_iterator * iterator,
+       struct ieee80211_radiotap_header * radiotap_header,
+       int max_length);
+
+int ieee80211_radiotap_iterator_next(
+       struct ieee80211_radiotap_iterator * iterator);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]