REST/NAMESTORE: rework API
[oweals/gnunet.git] / src / transport / plugin_transport_wlan.c
index b0be343463d39d4bb8c847ab04352b9790aa0dfb..e1a93bf884d6843ea2137a3f0da3becca8a7e8f8 100644 (file)
@@ -1,21 +1,21 @@
 /*
   This file is part of GNUnet
-  (C) 2010-2014 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2010-2014 GNUnet e.V.
 
-  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 Affero General Public License as published
+  by the Free Software Foundation, either version 3 of the License,
+  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.
+  Affero General Public License for more details.
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-  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.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -38,6 +38,7 @@
 #include "gnunet_fragmentation_lib.h"
 #include "gnunet_constants.h"
 
+
 #if BUILD_WLAN
 /* begin case wlan */
 #define PLUGIN_NAME "wlan"
@@ -48,6 +49,7 @@
 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done
 #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__)
 
+
 /**
  * time out of a mac endpoint
  */
 #error need to build wlan or bluetooth
 #endif
 
+
+
+/**
+ * Functions with this signature are called whenever a
+ * complete message is received by the tokenizer.
+ *
+ * Do not call #GNUNET_SERVER_mst_destroy from within
+ * the scope of this callback.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
+ */
+typedef int
+(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
+                                           void *client,
+                                           const struct GNUNET_MessageHeader *message);
+
+
+/* Include legacy message stream tokenizer that was removed from util (for now) */
+#include "tcp_server_mst_legacy.c"
+
+
 /**
  * Max size of packet (that we give to the WLAN driver for transmission)
  */
 #define WLAN_MTU 1430
 
 
+/**
+ * Which network scope do we belong to?
+ */
+#if BUILD_WLAN
+static const enum GNUNET_NetworkType scope = GNUNET_NT_WLAN;
+#else
+static const enum GNUNET_NetworkType scope = GNUNET_NT_BT;
+#endif
+
 
 /**
  * Maximum number of messages in defragmentation queue per MAC
@@ -212,7 +247,7 @@ struct PendingMessage
 /**
  * Session handle for connections with other peers.
  */
-struct Session
+struct GNUNET_ATS_Session
 {
   /**
    * To whom are we talking to (set to our identity
@@ -224,13 +259,13 @@ struct Session
    * We keep all sessions in a DLL at their respective
    * `struct MACEndpoint *`.
    */
-  struct Session *next;
+  struct GNUNET_ATS_Session *next;
 
   /**
    * We keep all sessions in a DLL at their respective
    * `struct MACEndpoint *`.
    */
-  struct Session *prev;
+  struct GNUNET_ATS_Session *prev;
 
   /**
    * MAC endpoint with the address of this peer.
@@ -307,6 +342,12 @@ struct FragmentMessage
    */
   GNUNET_TRANSPORT_TransmitContinuation cont;
 
+  /**
+   * Message we need to fragment and transmit, NULL after the
+   * @e fragmentcontext has been created.
+   */
+  struct GNUNET_MessageHeader *msg;
+
   /**
    * Closure for @e cont
    */
@@ -349,12 +390,12 @@ struct MacEndpoint
   /**
    * Head of sessions that use this MAC.
    */
-  struct Session *sessions_head;
+  struct GNUNET_ATS_Session *sessions_head;
 
   /**
    * Tail of sessions that use this MAC.
    */
-  struct Session *sessions_tail;
+  struct GNUNET_ATS_Session *sessions_tail;
 
   /**
    * Head of messages we are currently sending to this MAC.
@@ -484,7 +525,7 @@ struct Plugin
   /**
    * Task that periodically sends a HELLO beacon via the helper.
    */
-  struct GNUNET_SCHEDULER_Task * beacon_task;
+  struct GNUNET_SCHEDULER_Task *beacon_task;
 
   /**
    * Tracker for bandwidth limit
@@ -524,7 +565,7 @@ struct MacAndSession
   /**
    * NULL if the identity of the other peer is not known.
    */
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   /**
    * MAC address of the other peer, NULL if not known.
@@ -601,7 +642,7 @@ wlan_plugin_address_to_string (void *cls,
  */
 static void
 notify_session_monitor (struct Plugin *plugin,
-                        struct Session *session,
+                        struct GNUNET_ATS_Session *session,
                         enum GNUNET_TRANSPORT_SessionState state)
 {
   struct GNUNET_TRANSPORT_SessionInfo info;
@@ -688,7 +729,8 @@ get_wlan_header (struct Plugin *plugin,
  * @param hdr pointer to the hdr where the ack is stored
  */
 static void
-send_ack (void *cls, uint32_t msg_id,
+send_ack (void *cls,
+          uint32_t msg_id,
          const struct GNUNET_MessageHeader *hdr)
 {
   struct MacEndpoint *endpoint = cls;
@@ -702,20 +744,21 @@ send_ack (void *cls, uint32_t msg_id,
     GNUNET_break (0);
     return;
   }
-  if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (size >= GNUNET_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Sending ACK to helper\n");
+       "Sending ACK to %s\n",
+       mac_to_string (&endpoint->wlan_addr.mac));
   radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
   get_radiotap_header (endpoint, radio_header, size);
   get_wlan_header (endpoint->plugin,
                   &radio_header->frame,
                   &endpoint->wlan_addr.mac,
                   sizeof (endpoint->wlan_addr.mac));
-  memcpy (&radio_header[1], hdr, msize);
+  GNUNET_memcpy (&radio_header[1], hdr, msize);
   if (NULL !=
       GNUNET_HELPER_send (endpoint->plugin->suid_helper,
                          &radio_header->header,
@@ -763,7 +806,7 @@ wlan_data_message_handler (void *cls,
  */
 static int
 wlan_plugin_disconnect_session (void *cls,
-                                struct Session *session)
+                                struct GNUNET_ATS_Session *session)
 {
   struct MacEndpoint *endpoint = session->mac;
   struct Plugin *plugin = endpoint->plugin;
@@ -811,13 +854,11 @@ wlan_plugin_query_keepalive_factor (void *cls)
  * A session is timing out.  Clean up.
  *
  * @param cls pointer to the Session
- * @param tc unused
  */
 static void
-session_timeout (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+session_timeout (void *cls)
 {
-  struct Session *session = cls;
+  struct GNUNET_ATS_Session *session = cls;
   struct GNUNET_TIME_Relative left;
 
   session->timeout_task = NULL;
@@ -843,11 +884,11 @@ session_timeout (void *cls,
  * @param peer peer identity to use for this session
  * @return returns the session or NULL
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 lookup_session (struct MacEndpoint *endpoint,
                 const struct GNUNET_PeerIdentity *peer)
 {
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   for (session = endpoint->sessions_head; NULL != session; session = session->next)
     if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity)))
@@ -863,17 +904,17 @@ lookup_session (struct MacEndpoint *endpoint,
  * @param peer peer identity to use for this session
  * @return returns the session or NULL
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 create_session (struct MacEndpoint *endpoint,
                 const struct GNUNET_PeerIdentity *peer)
 {
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
                             _("# Sessions allocated"),
                             1,
                             GNUNET_NO);
-  session = GNUNET_new (struct Session);
+  session = GNUNET_new (struct GNUNET_ATS_Session);
   GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
                                     endpoint->sessions_tail,
                                    session);
@@ -911,11 +952,11 @@ create_session (struct MacEndpoint *endpoint,
  * @param peer peer identity to use for this session
  * @return returns the session
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 get_session (struct MacEndpoint *endpoint,
              const struct GNUNET_PeerIdentity *peer)
 {
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   if (NULL != (session = lookup_session (endpoint, peer)))
     return session;
@@ -939,7 +980,6 @@ fragment_transmission_done (void *cls,
 {
   struct FragmentMessage *fm = cls;
 
-
   fm->sh = NULL;
   GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
 }
@@ -973,11 +1013,16 @@ transmit_fragment (void *cls,
 
     radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
     get_radiotap_header (endpoint, radio_header, size);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Sending %u bytes of data to MAC `%s'\n",
+        (unsigned int) msize,
+        mac_to_string (&endpoint->wlan_addr.mac));
+
     get_wlan_header (endpoint->plugin,
                     &radio_header->frame,
                     &endpoint->wlan_addr.mac,
                     sizeof (endpoint->wlan_addr.mac));
-    memcpy (&radio_header[1], hdr, msize);
+    GNUNET_memcpy (&radio_header[1], hdr, msize);
     GNUNET_assert (NULL == fm->sh);
     fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
                                 &radio_header->header,
@@ -985,12 +1030,16 @@ transmit_fragment (void *cls,
                                 &fragment_transmission_done, fm);
     fm->size_on_wire += size;
     if (NULL != fm->sh)
+    {
       GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
                                 _("# message fragments sent"),
                                1,
                                 GNUNET_NO);
+    }
     else
+    {
       GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
+    }
     GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
                               "# bytes currently in buffers",
                               -msize, GNUNET_NO);
@@ -1022,10 +1071,19 @@ free_fragment_message (struct FragmentMessage *fm)
     GNUNET_HELPER_send_cancel (fm->sh);
     fm->sh = NULL;
   }
-  GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
-                                   &endpoint->msg_delay,
-                                   &endpoint->ack_delay);
-  if (fm->timeout_task != NULL)
+  if (NULL != fm->msg)
+  {
+    GNUNET_free (fm->msg);
+    fm->msg = NULL;
+  }
+  if (NULL != fm->fragcontext)
+  {
+    GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
+                                     &endpoint->msg_delay,
+                                     &endpoint->ack_delay);
+    fm->fragcontext = NULL;
+  }
+  if (NULL != fm->timeout_task)
   {
     GNUNET_SCHEDULER_cancel (fm->timeout_task);
     fm->timeout_task = NULL;
@@ -1038,11 +1096,9 @@ free_fragment_message (struct FragmentMessage *fm)
  * A FragmentMessage has timed out.  Remove it.
  *
  * @param cls pointer to the 'struct FragmentMessage'
- * @param tc unused
  */
 static void
-fragmentmessage_timeout (void *cls,
-                         const struct GNUNET_SCHEDULER_TaskContext *tc)
+fragmentmessage_timeout (void *cls)
 {
   struct FragmentMessage *fm = cls;
 
@@ -1096,17 +1152,25 @@ send_with_fragmentation (struct MacEndpoint *endpoint,
   fm->cont = cont;
   fm->cont_cls = cont_cls;
   /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */
-  fm->fragcontext =
-    GNUNET_FRAGMENT_context_create (plugin->env->stats,
-                                    WLAN_MTU,
-                                   &plugin->tracker,
-                                   endpoint->msg_delay,
-                                   endpoint->ack_delay,
-                                   msg,
-                                   &transmit_fragment, fm);
   fm->timeout_task =
     GNUNET_SCHEDULER_add_delayed (timeout,
-                                 &fragmentmessage_timeout, fm);
+                                  &fragmentmessage_timeout,
+                                  fm);
+  if (GNUNET_YES == plugin->have_mac)
+  {
+    fm->fragcontext =
+      GNUNET_FRAGMENT_context_create (plugin->env->stats,
+                                      WLAN_MTU,
+                                      &plugin->tracker,
+                                      fm->macendpoint->msg_delay,
+                                      fm->macendpoint->ack_delay,
+                                      msg,
+                                      &transmit_fragment, fm);
+  }
+  else
+  {
+    fm->msg = GNUNET_copy_message (msg);
+  }
   GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
                                    endpoint->sending_messages_tail,
                                    fm);
@@ -1123,7 +1187,7 @@ free_macendpoint (struct MacEndpoint *endpoint)
 {
   struct Plugin *plugin = endpoint->plugin;
   struct FragmentMessage *fm;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   GNUNET_STATISTICS_update (plugin->env->stats,
                            _("# MAC endpoints allocated"),
@@ -1158,11 +1222,9 @@ free_macendpoint (struct MacEndpoint *endpoint)
  * A MAC endpoint is timing out.  Clean up.
  *
  * @param cls pointer to the `struct MacEndpoint *`
- * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
  */
 static void
-macendpoint_timeout (void *cls,
-                     const struct GNUNET_SCHEDULER_TaskContext *tc)
+macendpoint_timeout (void *cls)
 {
   struct MacEndpoint *endpoint = cls;
   struct GNUNET_TIME_Relative timeout;
@@ -1237,14 +1299,33 @@ create_macendpoint (struct Plugin *plugin,
  * @param session the session
  * @return the network type in HBO or #GNUNET_SYSERR
  */
-static enum GNUNET_ATS_Network_Type
+static enum GNUNET_NetworkType
 wlan_plugin_get_network (void *cls,
-                         struct Session *session)
+                         struct GNUNET_ATS_Session *session)
 {
 #if BUILD_WLAN
-  return GNUNET_ATS_NET_WLAN;
+  return GNUNET_NT_WLAN;
 #else
-  return GNUNET_ATS_NET_BT;
+  return GNUNET_NT_BT;
+#endif
+}
+
+
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_NetworkType
+wlan_plugin_get_network_for_address (void *cls,
+                                    const struct GNUNET_HELLO_Address *address)
+{
+#if BUILD_WLAN
+  return GNUNET_NT_WLAN;
+#else
+  return GNUNET_NT_BT;
 #endif
 }
 
@@ -1257,7 +1338,7 @@ wlan_plugin_get_network (void *cls,
  * @param address the address
  * @return the session or NULL of max connections exceeded
  */
-static struct Session *
+static struct GNUNET_ATS_Session *
 wlan_plugin_get_session (void *cls,
                         const struct GNUNET_HELLO_Address *address)
 {
@@ -1296,7 +1377,7 @@ wlan_plugin_disconnect_peer (void *cls,
                              const struct GNUNET_PeerIdentity *target)
 {
   struct Plugin *plugin = cls;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
   struct MacEndpoint *endpoint;
 
   for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
@@ -1339,7 +1420,7 @@ wlan_plugin_disconnect_peer (void *cls,
  */
 static ssize_t
 wlan_plugin_send (void *cls,
-                  struct Session *session,
+                  struct GNUNET_ATS_Session *session,
                   const char *msgbuf, size_t msgbuf_size,
                   unsigned int priority,
                   struct GNUNET_TIME_Relative to,
@@ -1362,13 +1443,13 @@ wlan_plugin_send (void *cls,
   wlanheader->sender = *plugin->env->my_identity;
   wlanheader->target = session->target;
   wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
-  memcpy (&wlanheader[1], msgbuf, msgbuf_size);
-
+  GNUNET_memcpy (&wlanheader[1],
+          msgbuf,
+          msgbuf_size);
   GNUNET_STATISTICS_update (plugin->env->stats,
                             "# bytes currently in buffers",
                             msgbuf_size,
                             GNUNET_NO);
-
   send_with_fragmentation (session->mac,
                           to,
                           &session->target,
@@ -1395,20 +1476,12 @@ process_data (void *cls,
   struct Plugin *plugin = cls;
   struct GNUNET_HELLO_Address *address;
   struct MacAndSession *mas = client;
-  struct MacAndSession xmas;
-  struct GNUNET_ATS_Information ats;
   struct FragmentMessage *fm;
   struct GNUNET_PeerIdentity tmpsource;
   const struct WlanHeader *wlanheader;
   int ret;
   uint16_t msize;
 
-  ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
-#if BUILD_WLAN
-  ats.value = htonl (GNUNET_ATS_NET_WLAN);
-#else
-  ats.value = htonl (GNUNET_ATS_NET_BT);
-#endif
   msize = ntohs (hdr->size);
 
   GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1447,15 +1520,22 @@ process_data (void *cls,
                                              PLUGIN_NAME,
                                              &mas->endpoint->wlan_addr,
                                              sizeof (mas->endpoint->wlan_addr),
-                                             GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+                                             GNUNET_HELLO_ADDRESS_INFO_NONE);
+    mas->session = lookup_session (mas->endpoint,
+                                   &tmpsource);
+    if (NULL == mas->session)
+    {
+      mas->session = create_session (mas->endpoint,
+                                     &tmpsource);
+      plugin->env->session_start (plugin->env->cls,
+                                  address,
+                                  mas->session,
+                                  scope);
+    }
     plugin->env->receive (plugin->env->cls,
                           address,
                           mas->session,
                           hdr);
-    plugin->env->update_address_metrics (plugin->env->cls,
-                                         address,
-                                         mas->session,
-                                         &ats, 1);
     GNUNET_HELLO_address_free (address);
     break;
   case GNUNET_MESSAGE_TYPE_FRAGMENT:
@@ -1520,11 +1600,12 @@ process_data (void *cls,
         break;
       }
     }
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-        "ACK not matched against any active fragmentation with MAC `%s'\n",
-         wlan_plugin_address_to_string (NULL,
-                                        &mas->endpoint->wlan_addr,
-                                        sizeof (mas->endpoint->wlan_addr)));
+    if (NULL == fm)
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "ACK not matched against any active fragmentation with MAC `%s'\n",
+           wlan_plugin_address_to_string (NULL,
+                                          &mas->endpoint->wlan_addr,
+                                          sizeof (mas->endpoint->wlan_addr)));
     break;
   case GNUNET_MESSAGE_TYPE_WLAN_DATA:
     if (NULL == mas->endpoint)
@@ -1557,34 +1638,34 @@ process_data (void *cls,
                                GNUNET_NO);
       break;
     }
-    xmas.endpoint = mas->endpoint;
-    if (NULL == (xmas.session = lookup_session (mas->endpoint,
-                                                &wlanheader->sender)))
+    mas->session = lookup_session (mas->endpoint,
+                                   &wlanheader->sender);
+    if (NULL == mas->session)
     {
-      xmas.session = create_session (mas->endpoint,
+      mas->session = create_session (mas->endpoint,
                                      &wlanheader->sender);
       address = GNUNET_HELLO_address_allocate (&wlanheader->sender,
                                                PLUGIN_NAME,
                                                &mas->endpoint->wlan_addr,
                                                sizeof (struct WlanAddress),
                                                GNUNET_HELLO_ADDRESS_INFO_NONE);
-      plugin->env->session_start (NULL,
+      plugin->env->session_start (plugin->env->cls,
                                   address,
-                                  xmas.session,
-                                  NULL, 0);
+                                  mas->session,
+                                  scope);
       LOG (GNUNET_ERROR_TYPE_DEBUG,
-          "Notifying transport about peer `%s''s new session %p \n",
+           "Notifying transport about peer `%s''s new session %p \n",
            GNUNET_i2s (&wlanheader->sender),
-           xmas.session);
+           mas->session);
       GNUNET_HELLO_address_free (address);
     }
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Processing %u bytes of DATA from peer `%s'\n",
         (unsigned int) msize,
         GNUNET_i2s (&wlanheader->sender));
-    xmas.session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+    mas->session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
     (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
-                                     &xmas,
+                                     mas,
                                      (const char *) &wlanheader[1],
                                      msize - sizeof (struct WlanHeader),
                                      GNUNET_YES,
@@ -1610,25 +1691,73 @@ process_data (void *cls,
                           mas->session->address,
                           mas->session,
                           hdr);
-    plugin->env->update_address_metrics (plugin->env->cls,
-                                         mas->session->address,
-                                         mas->session,
-                                         &ats, 1);
     break;
   }
   return GNUNET_OK;
 }
 
 
+/**
+ * Task to (periodically) send a HELLO beacon
+ *
+ * @param cls pointer to the plugin struct
+ */
+static void
+send_hello_beacon (void *cls)
+{
+  struct Plugin *plugin = cls;
+  uint16_t size;
+  uint16_t hello_size;
+  struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
+  const struct GNUNET_MessageHeader *hello;
+
+  hello = plugin->env->get_our_hello ();
+  if (NULL != hello)
+  {
+    hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
+    GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
+    size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
+  {
+    char buf[size] GNUNET_ALIGN;
+
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Sending %u byte HELLO beacon\n",
+        (unsigned int) size);
+    radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
+    get_radiotap_header (NULL, radioHeader, size);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Broadcasting %u bytes of data to MAC `%s'\n",
+        (unsigned int) size,
+        mac_to_string (&bc_all_mac));
+    get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
+    GNUNET_memcpy (&radioHeader[1], hello, hello_size);
+    if (NULL !=
+       GNUNET_HELPER_send (plugin->suid_helper,
+                           &radioHeader->header,
+                           GNUNET_YES /* can drop */,
+                           NULL, NULL))
+      GNUNET_STATISTICS_update (plugin->env->stats,
+                                _("# HELLO beacons sent"),
+                               1, GNUNET_NO);
+  } }
+  plugin->beacon_task =
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                 (HELLO_BEACON_SCALING_FACTOR,
+                                  plugin->mac_count + 1),
+                                 &send_hello_beacon,
+                                 plugin);
+
+}
+
+
 /**
  * Function used for to process the data from the suid process
  *
  * @param cls the plugin handle
- * @param client client that send the data (not used)
  * @param hdr header of the GNUNET_MessageHeader
  */
 static int
-handle_helper_message (void *cls, void *client,
+handle_helper_message (void *cls,
                       const struct GNUNET_MessageHeader *hdr)
 {
   struct Plugin *plugin = cls;
@@ -1638,6 +1767,8 @@ handle_helper_message (void *cls, void *client,
   struct WlanAddress wa;
   struct MacAndSession mas;
   uint16_t msize;
+  struct FragmentMessage *fm;
+  struct MacEndpoint *endpoint;
 
   msize = ntohs (hdr->size);
   switch (ntohs (hdr->type))
@@ -1667,9 +1798,38 @@ handle_helper_message (void *cls, void *client,
                                    GNUNET_NO,
                                    my_address);
       GNUNET_HELLO_address_free (my_address);
+      plugin->mac_address = cm->mac;
+    }
+    else
+    {
+      plugin->mac_address = cm->mac;
+      plugin->have_mac = GNUNET_YES;
+      for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
+      {
+        for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next)
+        {
+          if (NULL != fm->fragcontext)
+          {
+            GNUNET_break (0); /* should not happen */
+            continue;
+          }
+          fm->fragcontext =
+            GNUNET_FRAGMENT_context_create (plugin->env->stats,
+                                            WLAN_MTU,
+                                            &plugin->tracker,
+                                            fm->macendpoint->msg_delay,
+                                            fm->macendpoint->ack_delay,
+                                            fm->msg,
+                                            &transmit_fragment, fm);
+          GNUNET_free (fm->msg);
+          fm->msg = NULL;
+        }
+      }
+      GNUNET_break (NULL == plugin->beacon_task);
+      plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
+                                                      plugin);
+
     }
-    plugin->mac_address = cm->mac;
-    plugin->have_mac = GNUNET_YES;
 
     memset (&wa, 0, sizeof (struct WlanAddress));
     wa.mac = plugin->mac_address;
@@ -1733,6 +1893,14 @@ handle_helper_message (void *cls, void *client,
         "Receiving %u bytes of data from MAC `%s'\n",
         (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
         mac_to_string (&rxinfo->frame.addr2));
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Receiving %u bytes of data to MAC `%s'\n",
+        (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
+        mac_to_string (&rxinfo->frame.addr1));
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Receiving %u bytes of data with BSSID MAC `%s'\n",
+        (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
+        mac_to_string (&rxinfo->frame.addr3));
     wa.mac = rxinfo->frame.addr2;
     wa.options = htonl (0);
     mas.endpoint = create_macendpoint (plugin, &wa);
@@ -1745,64 +1913,16 @@ handle_helper_message (void *cls, void *client,
     break;
   default:
     GNUNET_break (0);
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
+    LOG (GNUNET_ERROR_TYPE_ERROR,
         "Unexpected message of type %u (%u bytes)",
-        ntohs (hdr->type), ntohs (hdr->size));
+        ntohs (hdr->type),
+        ntohs (hdr->size));
     break;
   }
   return GNUNET_OK;
 }
 
 
-/**
- * Task to (periodically) send a HELLO beacon
- *
- * @param cls pointer to the plugin struct
- * @param tc scheduler context
- */
-static void
-send_hello_beacon (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct Plugin *plugin = cls;
-  uint16_t size;
-  uint16_t hello_size;
-  struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
-  const struct GNUNET_MessageHeader *hello;
-
-  hello = plugin->env->get_our_hello ();
-  hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
-  GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
-  size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
-  {
-    char buf[size] GNUNET_ALIGN;
-
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-        "Sending %u byte HELLO beacon\n",
-        (unsigned int) size);
-    radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
-    get_radiotap_header (NULL, radioHeader, size);
-    get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
-    memcpy (&radioHeader[1], hello, hello_size);
-    if (NULL !=
-       GNUNET_HELPER_send (plugin->suid_helper,
-                           &radioHeader->header,
-                           GNUNET_YES /* can drop */,
-                           NULL, NULL))
-      GNUNET_STATISTICS_update (plugin->env->stats,
-                                _("# HELLO beacons sent"),
-                               1, GNUNET_NO);
-  }
-  plugin->beacon_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                 (HELLO_BEACON_SCALING_FACTOR,
-                                  plugin->mac_count + 1),
-                                 &send_hello_beacon,
-                                 plugin);
-
-}
-
-
 /**
  * Another peer has suggested an address for this
  * peer and transport plugin.  Check that this could be a valid
@@ -2041,7 +2161,7 @@ wlan_plugin_setup_monitor (void *cls,
 {
   struct Plugin *plugin = cls;
   struct MacEndpoint *mac;
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   plugin->sic = sic;
   plugin->sic_cls = sic_cls;
@@ -2075,7 +2195,7 @@ wlan_plugin_setup_monitor (void *cls,
 static void
 wlan_plugin_update_session_timeout (void *cls,
                                     const struct GNUNET_PeerIdentity *peer,
-                                    struct Session *session)
+                                    struct GNUNET_ATS_Session *session)
 {
   GNUNET_assert (NULL != session->timeout_task);
   session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
@@ -2095,7 +2215,7 @@ wlan_plugin_update_session_timeout (void *cls,
 static void
 wlan_plugin_update_inbound_delay (void *cls,
                                   const struct GNUNET_PeerIdentity *peer,
-                                  struct Session *session,
+                                  struct GNUNET_ATS_Session *session,
                                   struct GNUNET_TIME_Relative delay)
 {
   /* does nothing, as inbound delay is not supported by WLAN */
@@ -2188,11 +2308,12 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
                                  GNUNET_BANDWIDTH_value_init (100 * 1024 *
                                                               1024 / 8),
                                  100);
-  plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
-  plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
-  plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
-  plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
-                                                 plugin);
+  plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+                                                              plugin);
+  plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+                                                                    plugin);
+  plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+                                                               plugin);
 
   plugin->options = 0;
 
@@ -2248,6 +2369,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   api->address_to_string = &wlan_plugin_address_to_string;
   api->string_to_address = &wlan_plugin_string_to_address;
   api->get_network = &wlan_plugin_get_network;
+  api->get_network_for_address = &wlan_plugin_get_network_for_address;
   api->update_session_timeout = &wlan_plugin_update_session_timeout;
   api->update_inbound_delay = &wlan_plugin_update_inbound_delay;
   api->setup_monitor = &wlan_plugin_setup_monitor;