gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r14553 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r14553 - gnunet/src/transport
Date: Mon, 28 Feb 2011 20:09:42 +0100

Author: brodski
Date: 2011-02-28 20:09:42 +0100 (Mon, 28 Feb 2011)
New Revision: 14553

Modified:
   gnunet/src/transport/plugin_transport_wlan.c
Log:
Fixed many errors, send and receive with acks works now

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2011-02-28 19:05:01 UTC 
(rev 14552)
+++ gnunet/src/transport/plugin_transport_wlan.c        2011-02-28 19:09:42 UTC 
(rev 14553)
@@ -1,22 +1,22 @@
 /*
-     This file is part of GNUnet
-     (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff 
(and other contributing authors)
+ This file is part of GNUnet
+ (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 transport/plugin_transport_wlan.c
@@ -45,16 +45,17 @@
 /**
  * Time until retransmission of a fragment in ms
  */
-#define FRAGMENT_TIMEOUT GNUNET_TIME_UNIT_SECONDS 
+#define FRAGMENT_TIMEOUT GNUNET_TIME_UNIT_SECONDS
 
 #define FRAGMENT_QUEUE_SIZE 10
 
+#define HALLO_BEACON_SCALING_FACTOR 900
+
 #define DEBUG_wlan GNUNET_YES
 
 #define MESSAGE_LENGHT_UNKNOWN -1
 #define NO_MESSAGE_OR_MESSAGE_FINISHED -2
 
-
 /**
  * After how long do we expire an address that we
  * learned from another peer if it is not reconfirmed
@@ -79,7 +80,6 @@
 
 };
 
-
 /**
  * Encapsulation of all of the state of the plugin.
  */
@@ -112,7 +112,6 @@
 
   struct GNUNET_SERVER_MessageStreamTokenizer * consoltoken;
 
-
   /**
    * stdout pipe handle for the gnunet-wlan-helper process
    */
@@ -170,9 +169,9 @@
   struct Sessionqueue * pending_Sessions;
 
   /**
-    * Sessions currently pending for transmission
-    * to this peer (tail), if any.
-    */
+   * Sessions currently pending for transmission
+   * to this peer (tail), if any.
+   */
   struct Sessionqueue * pending_Sessions_tail;
 
   /**
@@ -193,8 +192,8 @@
   struct FragmentMessage * pending_Fragment_Messages_tail;
 
   /**
-     * number of pending fragment message
-     */
+   * number of pending fragment message
+   */
 
   unsigned int pending_fragment_messages;
 
@@ -204,6 +203,14 @@
 
   struct GNUNET_TIME_Absolute beacon_time;
 
+  /**
+   * queue to send acks for received fragments
+   */
+
+  struct AckSendQueue * ack_send_queue_head;
+
+  struct AckSendQueue * ack_send_queue_tail;
+
 };
 
 struct Finish_send
@@ -220,9 +227,9 @@
 
 struct Sessionqueue
 {
-       struct Sessionqueue * next;
-       struct Sessionqueue * prev;
-       struct Session * content;
+  struct Sessionqueue * next;
+  struct Sessionqueue * prev;
+  struct Session * content;
 };
 
 /**
@@ -231,24 +238,22 @@
 
 struct AckQueue
 {
-       struct AckQueue * next;
-       struct AckQueue * prev;
-       int fragment_num; //TODO change it to offset if better
+  struct AckQueue * next;
+  struct AckQueue * prev;
+  int fragment_num; //TODO change it to offset if better
 };
 
-
-
 /**
  * Queue for the fragments received
  */
 
 struct RecQueue
 {
-        struct RecQueue * next;
-        struct RecQueue * prev;
-        uint16_t num;
-        const char * msg;
-        uint16_t size;
+  struct RecQueue * next;
+  struct RecQueue * prev;
+  uint16_t num;
+  const char * msg;
+  uint16_t size;
 };
 
 /**
@@ -264,6 +269,11 @@
   char *msg;
 
   /**
+   * Size of the message
+   */
+  size_t message_size;
+
+  /**
    * Continuation function to call once the message
    * has been sent.  Can be NULL if there is no
    * continuation to call.
@@ -280,11 +290,29 @@
    */
   struct GNUNET_TIME_Absolute timeout;
 
+};
+
+/**
+ * Queue for acks to send for fragments recived
+ */
+//TODO comments
+struct AckSendQueue
+{
+
+  struct AckSendQueue * next;
+  struct AckSendQueue * prev;
+
+  struct Session * session;
   /**
-   * Size of the message
+   * ID of message, to distinguish between the messages, picked randomly.
    */
-  size_t message_size;
+  uint32_t message_id GNUNET_PACKED;
 
+  /**
+   * Offset or number of this fragment, for fragmentation/segmentation (design 
choice, TBD)
+   */
+  uint16_t fragment_off_or_num GNUNET_PACKED;
+
 };
 
 /**
@@ -397,65 +425,66 @@
 
 };
 
+/**
+ * Struct for Messages in the fragment queue
+ */
 
-
-
 struct FragmentMessage
 {
-       /**
-        * Session this message belongs to
-        */
+  /**
+   * Session this message belongs to
+   */
 
-       struct Session *session;
+  struct Session *session;
 
-       /**
-       * This is a doubly-linked list.
-       */
-       struct FragmentMessage *next;
+  /**
+   * This is a doubly-linked list.
+   */
+  struct FragmentMessage *next;
 
-       /**
-       * This is a doubly-linked list.
-       */
-       struct FragmentMessage *prev;
+  /**
+   * This is a doubly-linked list.
+   */
+  struct FragmentMessage *prev;
 
-       /**
-       * The pending message
-       */
-       char *msg;
+  /**
+   * The pending message
+   */
+  char *msg;
 
-       /**
-       * Timeout value for the pending message.
-       */
-       struct GNUNET_TIME_Absolute timeout;
+  /**
+   * Timeout value for the pending message.
+   */
+  struct GNUNET_TIME_Absolute timeout;
 
-       /**
-       * Timeout value for the pending fragments.
-       * Stores the time when the next msg fragment ack has to be received
-       */
-       struct GNUNET_TIME_Absolute next_ack;
+  /**
+   * Timeout value for the pending fragments.
+   * Stores the time when the next msg fragment ack has to be received
+   */
+  struct GNUNET_TIME_Absolute next_ack;
 
-       /**
-       * Sorted queue with the acks received for fragments; head
-       */
+  /**
+   * Sorted queue with the acks received for fragments; head
+   */
 
-       struct AckQueue * head;
+  struct AckQueue * head;
 
-       /**
-       * Sorted queue with the acks received for fragments; tail
-       */
+  /**
+   * Sorted queue with the acks received for fragments; tail
+   */
 
-       struct AckQueue * tail;
+  struct AckQueue * tail;
 
-       /**
-       * Size of the message
-       */
-       size_t message_size;
+  /**
+   * Size of the message
+   */
+  size_t message_size;
 
-       /**
-       * pos / next fragment number in the message, for 
fragmentation/segmentation,
-       * some acks can be missing but there is still time
-       */
-       uint32_t message_pos;
+  /**
+   * pos / next fragment number in the message, for fragmentation/segmentation,
+   * some acks can be missing but there is still time
+   */
+  uint32_t message_pos;
 
 };
 
@@ -478,7 +507,7 @@
    */
   struct GNUNET_PeerIdentity target;
 
-  // followed by payload
+// followed by payload
 
 };
 
@@ -511,31 +540,30 @@
    */
   uint16_t message_crc GNUNET_PACKED;
 
-  /**
-   * Flags
-   * // 0x1 ack => Use two different message types in header.type! 
(FRAG_MESSAGE; FRAG_ACK)
-   * // 0x2 has data (not only ack)
-   * // 0x4 last fragment of message
-   * // 0x8 new message
-   */
-  //  uint32_t flags GNUNET_PACKED;
+/**
+ * Flags
+ * // 0x1 ack => Use two different message types in header.type! 
(FRAG_MESSAGE; FRAG_ACK)
+ * // 0x2 has data (not only ack)
+ * // 0x4 last fragment of message
+ * // 0x8 new message
+ */
+//  uint32_t flags GNUNET_PACKED;
 
-  /**
-   * checksum/error correction
-   */
-  // uint32_t crc GNUNET_PACKED;
+/**
+ * checksum/error correction
+ */
+// uint32_t crc GNUNET_PACKED;
 
-  // followed by payload unless ACK
+// followed by payload unless ACK
 
 };
 
-//enum { ACK_FRAGMENT = 1, DATA_FRAGMENT = 2, LAST_FRAGMENT = 4, NEW_MESSAGE = 
8 };
-
 int
 getRadiotapHeader(struct RadiotapHeader * Header);
 
 int
-getWlanHeader(struct IeeeHeader * Header);
+getWlanHeader(struct IeeeHeader * Header,const char * to_mac_addr,
+    struct Plugin * plugin);
 
 static int
 wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen);
@@ -556,16 +584,21 @@
 free_rec_frag_queue(struct Session * session);
 
 static void
-wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * 
hdr);
+wlan_data_helper(void *cls, struct Session_light * session_light,
+    const struct GNUNET_MessageHeader * hdr);
 
 static void
-wlan_process_helper (void *cls,
-                      void *client,
-                      const struct GNUNET_MessageHeader *hdr);
+wlan_process_helper(void *cls, void *client,
+    const struct GNUNET_MessageHeader *hdr);
 
 static void
 finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+static void
+wlan_data_massage_handler(struct Plugin * plugin,
+    struct Session_light * session_light,
+    const struct GNUNET_MessageHeader * hdr);
+
 /**
  * get the next message number, at the moment just a random one
  * @return returns the next valid message-number for sending packets
@@ -627,7 +660,7 @@
  */
 
 static struct Session *
-create_session(struct Plugin *plugin,const uint8_t * addr)
+create_session(struct Plugin *plugin, const uint8_t * addr)
 {
   struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue));
 
@@ -688,49 +721,52 @@
  */
 //TODO doxigen
 static void
-queue_Session (struct Plugin *plugin,
-               struct Session * session)
+queue_Session(struct Plugin *plugin, struct Session * session)
 {
-       struct Sessionqueue * queue = plugin->pending_Sessions;
-       struct Sessionqueue * lastitem = NULL;
+  struct Sessionqueue * queue = plugin->pending_Sessions;
+  struct Sessionqueue * lastitem = NULL;
 
-       while (queue != NULL){
-               // content is never NULL
-               GNUNET_assert (queue->content != NULL);
-               // is session already in queue?
-               if (session == queue->content){
-                       return;
-               }
-               // try next
-               lastitem = queue;
-               queue = queue->next;
-       }
+  while (queue != NULL)
+    {
+      // content is never NULL
+      GNUNET_assert (queue->content != NULL);
+      // is session already in queue?
+      if (session == queue->content)
+        {
+          return;
+        }
+      // try next
+      lastitem = queue;
+      queue = queue->next;
+    }
 
-       // Session is not in the queue
+  // Session is not in the queue
 
-       queue = GNUNET_malloc (sizeof (struct Sessionqueue));
-       queue->content = session;
+  queue = GNUNET_malloc (sizeof (struct Sessionqueue));
+  queue->content = session;
 
-       //insert at the tail
-       GNUNET_CONTAINER_DLL_insert_after (plugin->pending_Sessions,
-                       plugin->pending_Sessions_tail,
-                       plugin->pending_Sessions_tail, queue);
-       plugin->pendingsessions ++;
+  //insert at the tail
+  GNUNET_CONTAINER_DLL_insert_after (plugin->pending_Sessions,
+      plugin->pending_Sessions_tail,
+      plugin->pending_Sessions_tail, queue);
+  plugin->pendingsessions++;
 
 }
 
 //TODO doxigen
 static void
-free_acks (struct FragmentMessage * fm){
-       struct AckQueue * fq;
-       while (fm->head != NULL){
-               fq = fm->head;
-               GNUNET_CONTAINER_DLL_remove(fm->head, fm->tail, fq);
-               GNUNET_free(fq);
-       }
-       //needed?
-       fm->head = NULL;
-       fm->tail = NULL;
+free_acks(struct FragmentMessage * fm)
+{
+  struct AckQueue * fq;
+  while (fm->head != NULL)
+    {
+      fq = fm->head;
+      GNUNET_CONTAINER_DLL_remove(fm->head, fm->tail, fq);
+      GNUNET_free(fq);
+    }
+  //needed?
+  fm->head = NULL;
+  fm->tail = NULL;
 }
 
 //TODO doxigen
@@ -766,24 +802,25 @@
   if (plugin->session_count < 10)
     {
       plugin->beacon_time = GNUNET_TIME_absolute_add(
-          GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_SECONDS);
+          GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
+              GNUNET_TIME_UNIT_SECONDS, HALLO_BEACON_SCALING_FACTOR));
     }
   //under 30 known peers: every 10 seconds
   else if (plugin->session_count < 30)
     {
       plugin->beacon_time = GNUNET_TIME_absolute_add(
           GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
-              GNUNET_TIME_UNIT_SECONDS, 10));
+              GNUNET_TIME_UNIT_SECONDS, 10 * HALLO_BEACON_SCALING_FACTOR));
     }
   //over 30 known peers: once a minute
   else
     {
       plugin->beacon_time = GNUNET_TIME_absolute_add(
-          GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_MINUTES);
+          GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
+              GNUNET_TIME_UNIT_MINUTES, HALLO_BEACON_SCALING_FACTOR));
     }
 }
 
-
 //TODO doxigen
 struct GNUNET_TIME_Relative
 get_next_frag_timeout(struct FragmentMessage * fm)
@@ -798,11 +835,11 @@
  */
 
 struct GNUNET_TIME_Relative
-get_ack_timeout (struct FragmentMessage * fm){
-       return FRAGMENT_TIMEOUT;
+get_ack_timeout(struct FragmentMessage * fm)
+{
+  return FRAGMENT_TIMEOUT;
 }
 
-
 /**
  * Function to set the timer for the next timeout of the fragment queue
  * @param plugin the handle to the plugin struct
@@ -825,8 +862,13 @@
 
   GNUNET_assert(plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK);
 
+  //check if some acks are in the queue
+  if (plugin->ack_send_queue_head != NULL)
+    {
+      next_send = GNUNET_TIME_relative_get_zero();
+    }
   //check if there are some fragments in the queue
-  if (fm != NULL)
+  else if (fm != NULL)
     {
       next_send
           = GNUNET_TIME_relative_min(next_send, get_next_frag_timeout(fm));
@@ -835,85 +877,95 @@
       &delay_fragment_task, plugin);
 }
 
-
-
 //TODO doxigen
 /**
  * Function to get the next queued Session, removes the session from the queue
  */
 
 static struct Session *
-get_next_queue_Session (struct Plugin * plugin){
-       struct Session * session;
-       struct Sessionqueue * sessionqueue;
-       struct Sessionqueue * sessionqueue_alt;
-       struct PendingMessage * pm;
-       sessionqueue = plugin->pending_Sessions;
-       while (sessionqueue != NULL){
-               session = sessionqueue->content;
-               pm = session->pending_message;
+get_next_queue_Session(struct Plugin * plugin)
+{
+  struct Session * session;
+  struct Sessionqueue * sessionqueue;
+  struct Sessionqueue * sessionqueue_alt;
+  struct PendingMessage * pm;
+  sessionqueue = plugin->pending_Sessions;
+  while (sessionqueue != NULL)
+    {
+      session = sessionqueue->content;
+      pm = session->pending_message;
 
-               //check for message timeout
-               if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 
0){
-                       //check if session has no message in the fragment queue
-                       if (! session->has_fragment){
-                               plugin->pendingsessions --;
-                               GNUNET_CONTAINER_DLL_remove 
(plugin->pending_Sessions,
-                                               plugin->pending_Sessions_tail, 
sessionqueue);
-                               GNUNET_free(sessionqueue);
+      //check for message timeout
+      if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0)
+        {
+          //check if session has no message in the fragment queue
+          if (!session->has_fragment)
+            {
+              plugin->pendingsessions--;
+              GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
+                  plugin->pending_Sessions_tail, sessionqueue);
+              GNUNET_free(sessionqueue);
 
-                               return session;
-                       } else {
-                               sessionqueue = sessionqueue->next;
-                       }
-               } else {
+              return session;
+            }
+          else
+            {
+              sessionqueue = sessionqueue->next;
+            }
+        }
+      else
+        {
 
-                       session->pending_message = NULL;
-                       //call the cont func that it did not work
-                       if (pm->transmit_cont != NULL)
-                         pm->transmit_cont (pm->transmit_cont_cls,
-                                               &(session->target), 
GNUNET_SYSERR);
-                       GNUNET_free(pm->msg);
-                       GNUNET_free(pm);
+          session->pending_message = NULL;
+          //call the cont func that it did not work
+          if (pm->transmit_cont != NULL)
+            pm->transmit_cont(pm->transmit_cont_cls, &(session->target),
+                GNUNET_SYSERR);
+          GNUNET_free(pm->msg);
+          GNUNET_free(pm);
 
-                       sessionqueue_alt = sessionqueue;
-                       sessionqueue = sessionqueue->next;
-                       plugin->pendingsessions --;
-                       GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
-                                       plugin->pending_Sessions_tail, 
sessionqueue_alt);
+          sessionqueue_alt = sessionqueue;
+          sessionqueue = sessionqueue->next;
+          plugin->pendingsessions--;
+          GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
+              plugin->pending_Sessions_tail, sessionqueue_alt);
 
-                       GNUNET_free(sessionqueue_alt);
+          GNUNET_free(sessionqueue_alt);
 
-               }
+        }
 
-
-       }
-       return NULL;
+    }
+  return NULL;
 }
 
-
 /**
  * Function to sort the message into the message fragment queue
  * @param plugin the plugin struct
  * @param fm message to sort into the queue
  */
 static void
-sort_fragment_into_queue (struct Plugin * plugin, struct FragmentMessage * fm){
-       struct FragmentMessage * fm2;
-       //sort into the list at the right position
+sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm)
+{
+  struct FragmentMessage * fm2;
+  //sort into the list at the right position
 
-       fm2 = plugin->pending_Fragment_Messages_head;
+  fm2 = plugin->pending_Fragment_Messages_head;
 
-       while (fm2 != NULL){
-               if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, 
fm->next_ack).rel_value == 0){
-                       break;
-               } else {
-                       fm2 = fm2->next;
-               }
-       }
+  while (fm2 != NULL)
+    {
+      if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, 
fm->next_ack).rel_value
+          == 0)
+        {
+          break;
+        }
+      else
+        {
+          fm2 = fm2->next;
+        }
+    }
 
-       
GNUNET_CONTAINER_DLL_insert_after(plugin->pending_Fragment_Messages_head,
-                       plugin->pending_Fragment_Messages_tail,fm2,fm);
+  GNUNET_CONTAINER_DLL_insert_after(plugin->pending_Fragment_Messages_head,
+      plugin->pending_Fragment_Messages_tail,fm2,fm);
 }
 
 /**
@@ -922,7 +974,7 @@
  * @param fm message to free
  */
 static void
-free_fragment_message(struct Plugin * plugin,struct FragmentMessage * fm)
+free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
 {
   if (fm != NULL)
     {
@@ -931,8 +983,12 @@
       GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head,
           plugin->pending_Fragment_Messages_tail, fm);
       GNUNET_free(fm);
-      plugin->pending_fragment_messages --;
+      plugin->pending_fragment_messages--;
       check_fragment_queue(plugin);
+
+#if DEBUG_wlan
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Pending fragment messages: 
%u\n", plugin->pending_fragment_messages);
+#endif
     }
 }
 
@@ -943,43 +999,58 @@
  */
 
 static void
-check_fragment_queue (struct Plugin * plugin){
-       struct Session * session;
-       struct FragmentMessage * fm;
+check_fragment_queue(struct Plugin * plugin)
+{
+  struct Session * session;
+  struct FragmentMessage * fm;
+  struct GNUNET_PeerIdentity pid;
 
-       struct PendingMessage * pm;
+  struct PendingMessage * pm;
 
-       if (plugin->pending_fragment_messages < FRAGMENT_QUEUE_SIZE){
-               session = get_next_queue_Session(plugin);
-               if (session != NULL){
-                       pm = session->pending_message;
-                       session->pending_message = NULL;
-                       session->has_fragment = 1;
-                       GNUNET_assert(pm != NULL);
+  if (plugin->pending_fragment_messages < FRAGMENT_QUEUE_SIZE)
+    {
+      session = get_next_queue_Session(plugin);
+      if (session != NULL)
+        {
+          pm = session->pending_message;
+          session->pending_message = NULL;
+          session->has_fragment = 1;
+          GNUNET_assert(pm != NULL);
 
-                       fm = GNUNET_malloc(sizeof(struct FragmentMessage));
-                       fm->message_size = pm->message_size;
-                       fm->msg = pm->msg;
-                       fm->session = session;
-                       fm->timeout.abs_value = pm->timeout.abs_value;
-                       fm->message_pos = 0;
-                       fm->next_ack = GNUNET_TIME_absolute_get();
+          fm = GNUNET_malloc(sizeof(struct FragmentMessage));
+          fm->message_size = pm->message_size;
+          fm->msg = pm->msg;
+          fm->session = session;
+          fm->timeout.abs_value = pm->timeout.abs_value;
+          fm->message_pos = 0;
+          fm->next_ack = GNUNET_TIME_absolute_get();
 
-                       if (pm->transmit_cont != NULL)
-                                 pm->transmit_cont (pm->transmit_cont_cls,
-                                                       &(session->target), 
GNUNET_OK);
-                       GNUNET_free(pm);
+          if (pm->transmit_cont != NULL) {
+            pid = session->target;
+            pm->transmit_cont(pm->transmit_cont_cls, &pid,
+                GNUNET_OK);
+#if DEBUG_wlan
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "called 
pm->transmit_cont\n");
+#endif
+            }
+          else
+            {
+#if DEBUG_wlan
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "no pm->transmit_cont\n");
+#endif
+            }
+          GNUNET_free(pm);
 
-                       sort_fragment_into_queue(plugin,fm);
-                       plugin->pending_fragment_messages ++;
+          sort_fragment_into_queue(plugin, fm);
+          plugin->pending_fragment_messages++;
 
-                       //generate new message id
-                       session->message_id_out = get_next_message_id();
+          //generate new message id
+          session->message_id_out = get_next_message_id();
 
-                       //check if timeout changed
-                       check_next_fragment_timeout(plugin);
-               }
-       }
+          //check if timeout changed
+          check_next_fragment_timeout(plugin);
+        }
+    }
 }
 
 /**
@@ -989,7 +1060,8 @@
  * @param fm the message to check
  */
 static void
-check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm){
+check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
+{
   struct AckQueue * ack;
   int counter = 0;
 
@@ -1003,9 +1075,11 @@
         {
           if (counter == ack->fragment_num)
             {
-              counter ++;
+              counter++;
               ack = ack->next;
-            } else {
+            }
+          else
+            {
               //ack is missing
               return;
             }
@@ -1013,11 +1087,165 @@
       fm->session->has_fragment = 0;
       free_fragment_message(plugin, fm);
 
+#if DEBUG_wlan
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished a fragmented message\n");
+#endif
 
+
+      check_next_fragment_timeout(plugin);
+
     }
 }
 
 /**
+ * Function to set the next fragment number
+ * @param fm use this FragmentMessage
+ */
+
+void
+set_next_message_fragment_pos(struct FragmentMessage * fm)
+{
+  struct AckQueue * akt = NULL;
+  //check if retransmit is needed
+  if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0)
+    {
+
+      // be positive and try again later :-D
+      fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(fm));
+      // find first missing fragment
+
+      fm->message_pos = 0;
+    }
+
+  akt = fm->head;
+  //test if ack 0 (or X) was already received
+  while (akt != NULL)
+    {
+      //if fragment is present, take next
+      if (akt->fragment_num == fm->message_pos)
+        {
+          fm->message_pos++;
+        }
+      //next ack is bigger then the fragment number
+      //in case there is something like this: (acks) 1, 2, 5, 6, ...
+      //and we send 3 again, the next number should be 4
+      else if (akt->fragment_num > fm->message_pos)
+        {
+          break;
+        }
+
+      akt = akt->next;
+
+    }
+
+}
+
+void
+send_hello_beacon(struct Plugin * plugin)
+{
+
+#if DEBUG_wlan
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello beacon\n");
+#endif
+
+   uint16_t size = 0;
+   ssize_t bytes;
+   struct GNUNET_MessageHeader * msgheader = NULL;
+   struct IeeeHeader * ieeewlanheader = NULL;
+   struct RadiotapHeader * 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)
+   + 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];
+   getWlanHeader(ieeewlanheader, bc_all_mac, plugin);
+
+   msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
+   msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello))
+   + sizeof(struct GNUNET_MessageHeader));
+
+   msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
+   memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size(
+   *(plugin->env->our_hello)));
+
+   bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, 
size);
+
+   if (bytes == GNUNET_SYSERR)
+   {
+   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+   _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+   errno, strerror(errno));
+
+   }
+   GNUNET_assert(bytes != GNUNET_SYSERR);
+   GNUNET_assert(bytes == size);
+   GNUNET_free(msgheader);
+
+  set_next_beacon_time(plugin);
+  check_next_fragment_timeout(plugin);
+}
+
+static void
+send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
+{
+
+  uint16_t size = 0;
+  ssize_t bytes;
+  struct GNUNET_MessageHeader * msgheader = NULL;
+  struct IeeeHeader * ieeewlanheader = NULL;
+  struct RadiotapHeader * radioHeader = NULL;
+  struct FragmentationHeader * msgheader2 = NULL;
+
+  GNUNET_assert(sizeof(struct FragmentationHeader) <= WLAN_MTU);
+
+#if DEBUG_wlan
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+      "Sending ack for message_id %u with fragment number %u\n",
+      ack->message_id, ack->fragment_off_or_num);
+#endif
+
+  size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader)
+      + sizeof(struct IeeeHeader) + sizeof(struct FragmentationHeader);
+  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];
+  getWlanHeader(ieeewlanheader, ack->session->addr, plugin);
+
+  msgheader2 = (struct FragmentationHeader*) &ieeewlanheader[1];
+  msgheader2->header.size = htons(sizeof(struct FragmentationHeader));
+  msgheader2->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK);
+  msgheader2->message_id = htonl(ack->message_id);
+  msgheader2->fragment_off_or_num = htons(ack->fragment_off_or_num);
+
+  bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
+  if (bytes == GNUNET_SYSERR)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+          _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+          errno, strerror(errno));
+
+    }
+  GNUNET_assert(bytes != GNUNET_SYSERR);
+  GNUNET_assert(bytes == size);
+  GNUNET_free(msgheader);
+  check_next_fragment_timeout(plugin);
+}
+
+/**
  * Function called when wlan helper is ready to get some data
  *
  * @param cls closure
@@ -1031,8 +1259,6 @@
   struct Plugin * plugin = cls;
   plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
 
-  ssize_t bytes;
-
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
     return;
 
@@ -1045,251 +1271,178 @@
   struct FragmentationHeader fragheader;
   struct FragmentationHeader * fragheaderptr = NULL;
   struct Finish_send * finish = NULL;
+  struct AckSendQueue * ack;
   uint16_t size = 0;
+  ssize_t bytes;
   const char * copystart = NULL;
   uint16_t copysize = 0;
   uint copyoffset = 0;
-  struct AckQueue * akt = NULL;
 
+  if (plugin->ack_send_queue_head != NULL)
+    {
+      ack = plugin->ack_send_queue_head;
+      GNUNET_CONTAINER_DLL_remove(plugin->ack_send_queue_head,
+          plugin->ack_send_queue_tail, ack);
+      send_ack(plugin, ack);
+      GNUNET_free(ack);
+      return;
+    }
 
-  struct GNUNET_MessageHeader * msgheader2 = NULL;
-
   //test if a "hello-beacon" has to be send
-  if (0==1)
-  //if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0)
+  if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0)
     {
-      //check if the message is not to big
-      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) + GNUNET_HELLO_size(
-          *(plugin->env->our_hello));
+      send_hello_beacon(plugin);
 
-      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];
-      getWlanHeader(ieeewlanheader);
-
-      msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
-      msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello))
-          + sizeof(struct GNUNET_MessageHeader));
-      msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
-
-      memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size(
-          *(plugin->env->our_hello)));
-
-      bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader,
-          size);
-      if (bytes == GNUNET_SYSERR)
-        {
-          GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-              _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
-              errno, strerror(errno));
-
-        }
-      GNUNET_assert(bytes != GNUNET_SYSERR);
-      GNUNET_assert(bytes == size);
-
-      GNUNET_free(msgheader);
-
-      set_next_beacon_time(plugin);
-      check_next_fragment_timeout(plugin);
-
       return;
 
     }
 
-
-
   fm = plugin->pending_Fragment_Messages_head;
-  GNUNET_assert(fm != NULL);
-  session = fm->session;
-  GNUNET_assert(session != NULL);
-
-  // test if message timed out
-  if (GNUNET_TIME_absolute_get_remaining(fm->timeout).rel_value == 0)
+  if (fm != NULL)
     {
-      free_acks(fm);
-      GNUNET_assert(plugin->pending_fragment_messages > 0);
-      plugin->pending_fragment_messages--;
-      GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head,
-          plugin->pending_Fragment_Messages_tail, fm);
+      session = fm->session;
+      GNUNET_assert(session != NULL);
 
-      GNUNET_free(fm->msg);
+      // test if message timed out
+      if (GNUNET_TIME_absolute_get_remaining(fm->timeout).rel_value == 0)
+        {
+#if DEBUG_wlan
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n");
+#endif
+          free_acks(fm);
+          GNUNET_assert(plugin->pending_fragment_messages > 0);
+          plugin->pending_fragment_messages--;
+          GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head,
+              plugin->pending_Fragment_Messages_tail, fm);
 
-      GNUNET_free(fm);
-      check_fragment_queue(plugin);
-    }
-  else
-    {
+          GNUNET_free(fm->msg);
 
-      if (fm->message_size > WLAN_MTU)
+          GNUNET_free(fm);
+          check_fragment_queue(plugin);
+        }
+      else
         {
+
+          //if (fm->message_size > WLAN_MTU)
+          // {
           size += sizeof(struct FragmentationHeader);
-          // check/set for retransmission
-          if (GNUNET_TIME_absolute_get_duration(fm->next_ack).rel_value == 0)
-            {
 
-              // be positive and try again later :-D
-              fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(
-                  fm));
-              // find first missing fragment
-              akt = fm->head;
-              fm->message_pos = 0;
+          set_next_message_fragment_pos(fm);
 
-              //test if ack 0 was already received
-              while (akt != NULL)
-                {
-                  //if fragment is present, take next
-                  if (akt->fragment_num == fm->message_pos)
-                    {
-                      fm->message_pos++;
-                    }
-                  //next ack is bigger then the fragment number
-                  //in case there is something like this: (acks) 1, 2, 5, 6, 
...
-                  //and we send 3 again, the next number should be 4
-                  else if (akt->fragment_num > fm->message_pos)
-                    {
-                      break;
-                    }
-
-                  akt = akt->next;
-
-                }
-
-            }
-
           copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader))
               * fm->message_pos;
           fragheader.fragment_off_or_num = htons(fm->message_pos);
           fragheader.message_id = htonl(session->message_id_out);
-
-          // start should be smaller then the packet size
           GNUNET_assert(copyoffset < fm->message_size);
           copystart = fm->msg + copyoffset;
-
-          //size of the fragment is either the MTU - overhead
-          //or the missing part of the message in case this is the last 
fragment
           copysize = GNUNET_MIN(fm->message_size - copyoffset,
               WLAN_MTU - sizeof(struct FragmentationHeader));
           fragheader.header.size = htons(copysize
               + sizeof(struct FragmentationHeader));
           fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
 
-          //get the next missing fragment
-          akt = fm->head;
-          fm->message_pos++;
+          /* }
+           else
+           {
+           // there is no need to split
+           copystart = fm->msg;
+           copysize = fm->message_size;
+           }*/
 
-          //test if ack was already received
-          while (akt != NULL)
-            {
-              //if fragment is present, take next
-              if (akt->fragment_num == fm->message_pos)
-                {
-                  fm->message_pos++;
-                }
-              //next ack is bigger then the fragment number
-              //in case there is something like this: (acks) 1, 2, 5, 6, ...
-              //and we send 3 again, the next number should be 4
-              else if (akt->fragment_num > fm->message_pos)
-                {
-                  break;
-                }
+#if DEBUG_wlan
+          GNUNET_log(
+              GNUNET_ERROR_TYPE_DEBUG,
+              "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u 
with fragment number %i, size: %u, time until timeout %u\n",
+              session->message_id_out, fm->message_pos, copysize
+                  + sizeof(struct FragmentationHeader),
+              GNUNET_TIME_absolute_get_remaining(fm->timeout));
+#endif
 
-              akt = akt->next;
-            }
-        }
-      else
-        {
-          // there is no need to split
-          copystart = fm->msg;
-          copysize = fm->message_size;
-        }
+          size += copysize;
+          size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader)
+              + sizeof(struct GNUNET_MessageHeader);
+          msgheader = GNUNET_malloc(size);
+          msgheader->size = htons(size);
+          msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
 
-      size += copysize;
-      size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader)
-          + 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 RadiotapHeader*) &msgheader[1];
-      getRadiotapHeader(radioHeader);
+          ieeewlanheader = (struct IeeeHeader *) &radioHeader[1];
+          getWlanHeader(ieeewlanheader, fm->session->addr, plugin);
 
-      ieeewlanheader = (struct IeeeHeader *) &radioHeader[1];
-      getWlanHeader(ieeewlanheader);
-
-      //could be faster if content is just send and not copyed before
-      //fragmentheader is needed
-      if (fm->message_size > WLAN_MTU)
-        {
+          //could be faster if content is just send and not copyed before
+          //fragmentheader is needed
+          //if (fm->message_size > WLAN_MTU)
+          // {
           fragheader.message_crc = htons(getcrc16(copystart, copysize));
           memcpy(&ieeewlanheader[1], &fragheader,
               sizeof(struct FragmentationHeader));
           fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1];
           memcpy(&fragheaderptr[1], copystart, copysize);
-        }
-      else
-        {
-          memcpy(&ieeewlanheader[1], copystart, copysize);
-        }
+          /* }
+           else
+           {
+           memcpy(&ieeewlanheader[1], copystart, copysize);
+           }*/
 
-      bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, 
size);
-      if (bytes == GNUNET_SYSERR){
-        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-            _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 
errno, strerror(errno) );
+          bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
+              msgheader, size);
+          if (bytes == GNUNET_SYSERR)
+            {
+              GNUNET_log(
+                  GNUNET_ERROR_TYPE_ERROR,
+                  _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+                  errno, strerror(errno));
 
-      }
-      GNUNET_assert(bytes != GNUNET_SYSERR);
+            }
+          GNUNET_assert(bytes != GNUNET_SYSERR);
 
-      if (bytes != size)
-        {
-          finish = GNUNET_malloc(sizeof( struct Finish_send));
-          finish->plugin = plugin;
-          finish->msgheader = (char * ) msgheader + bytes;
-          finish->size = size - bytes;
-          finish->msgstart = msgheader;
+          if (bytes != size)
+            {
+              finish = GNUNET_malloc(sizeof( struct Finish_send));
+              finish->plugin = plugin;
+              finish->msgheader = (char *) msgheader + bytes;
+              finish->size = size - bytes;
+              finish->msgstart = msgheader;
 
-          GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
+              GNUNET_assert(plugin->server_write_task == 
GNUNET_SCHEDULER_NO_TASK);
 
-          plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
-              GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
-              &finish_sending, finish);
+              plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
+                  GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
+                  &finish_sending, finish);
 
-        }
-      else
-        {
-          GNUNET_assert(bytes == size);
+            }
+          else
+            {
+              GNUNET_assert(bytes == size);
 
-          GNUNET_free(msgheader);
-          check_next_fragment_timeout(plugin);
-        }
+              GNUNET_free(msgheader);
+              check_next_fragment_timeout(plugin);
+            }
 
-      //check if this was the last fragment of this message, if true then 
queue at the end of the list
-      if (copysize + copyoffset >= fm->message_size)
-        {
-          GNUNET_assert(copysize + copyoffset == fm->message_size);
+          //check if this was the last fragment of this message, if true then 
queue at the end of the list
+          if (copysize + copyoffset >= fm->message_size)
+            {
+              GNUNET_assert(copysize + copyoffset == fm->message_size);
 
-          GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head,
-              plugin->pending_Fragment_Messages_tail, fm);
+              GNUNET_CONTAINER_DLL_remove 
(plugin->pending_Fragment_Messages_head,
+                  plugin->pending_Fragment_Messages_tail, fm);
 
-          
GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head,
-              plugin->pending_Fragment_Messages_tail, fm);
-          // if fragments have opimized timeouts
-          //sort_fragment_into_queue(plugin,fm);
+              
GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head,
+                  plugin->pending_Fragment_Messages_tail, fm);
+              // if fragments have opimized timeouts
+              //sort_fragment_into_queue(plugin,fm);
 
+            }
+
         }
-
+      return;
     }
+  GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+      "do_transmit did nothing, should not happen!\n");
 }
 
-
 static void
 finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -1302,7 +1455,8 @@
 
   plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
 
-  bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, 
finish->msgheader, finish->size);
+  bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
+      finish->msgheader, finish->size);
   GNUNET_assert(bytes != GNUNET_SYSERR);
 
   GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
@@ -1326,17 +1480,30 @@
 }
 
 int
-getRadiotapHeader(struct RadiotapHeader * Header){
+getRadiotapHeader(struct RadiotapHeader * Header)
+{
   return GNUNET_YES;
-};
+}
+;
 
+/**
+ * function to generate the wlan hardware header for one packet
+ * @param Header address to write the header to
+ * @param to_mac_addr address of the recipient
+ * @param plugin pointer to the plugin struct
+ * @return GNUNET_YES if there was no error
+ */
+
 int
-getWlanHeader(struct IeeeHeader * Header){
-
+getWlanHeader(struct IeeeHeader * Header,const char * const to_mac_addr,
+    struct Plugin * plugin)
+{
+  memcpy(&Header->mac2, macbc, sizeof(macbc));
+  memcpy(&Header->mac3, plugin->mac_address.mac, sizeof(plugin->mac_address));
+  memcpy(&Header->mac1, to_mac_addr, sizeof(plugin->mac_address));
   return GNUNET_YES;
 }
 
-
 /**
  * 32bit CRC
  *
@@ -1347,10 +1514,10 @@
  */
 
 uint32_t
-getcrc32 (const char *msgbuf,
-                 size_t msgbuf_size){
-       //TODO calc some crc
-       return 0;
+getcrc32(const char *msgbuf, size_t msgbuf_size)
+{
+  //TODO calc some crc
+  return 0;
 }
 
 /**
@@ -1363,10 +1530,10 @@
  */
 
 uint16_t
-getcrc16 (const char *msgbuf,
-                 size_t msgbuf_size){
-       //TODO calc some crc
-       return 0;
+getcrc16(const char *msgbuf, size_t msgbuf_size)
+{
+  //TODO calc some crc
+  return 0;
 }
 
 /**
@@ -1396,22 +1563,18 @@
  *         and does NOT mean that the message was not transmitted (DV)
  */
 static ssize_t
-wlan_plugin_send (void *cls,
-                 const struct GNUNET_PeerIdentity * target,
-                 const char *msgbuf,
-                 size_t msgbuf_size,
-                 unsigned int priority,
-                 struct GNUNET_TIME_Relative timeout,
-                 struct Session *session,
-                 const void *addr,
-                 size_t addrlen,
-                 int force_address,
-                 GNUNET_TRANSPORT_TransmitContinuation cont,
-                 void *cont_cls)
+wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
+    const char *msgbuf, size_t msgbuf_size, unsigned int priority,
+    struct GNUNET_TIME_Relative timeout, struct Session *session,
+    const void *addr, size_t addrlen, int force_address,
+    GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 {
   struct Plugin * plugin = cls;
   struct PendingMessage * newmsg = NULL;
   struct WlanHeader * wlanheader = NULL;
+  struct GNUNET_MessageHeader * innermsg =
+      (struct GNUNET_MessageHeader *) msgbuf;
+
   //check if msglen > 0
   GNUNET_assert(msgbuf_size > 0);
 
@@ -1430,6 +1593,14 @@
         }
     }
 
+#if DEBUG_wlan
+  GNUNET_log(
+      GNUNET_ERROR_TYPE_DEBUG,
+      "wlan_plugin_send got %u bytes data, packet says it has %u bytes for 
%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
+      msgbuf_size, ntohs(innermsg->size), session->addr[0], session->addr[1],
+      session->addr[2], session->addr[3], session->addr[4], session->addr[5]);
+#endif
+
   //TODO target "problem" not solved
   session->target = *target;
 
@@ -1439,7 +1610,17 @@
 
   //queue message in session
   //test if there is no other message in the "queue"
-  GNUNET_assert (session->pending_message == NULL);
+  //FIXME: to many send requests
+  //GNUNET_assert (session->pending_message == NULL);
+  if (session->pending_message != NULL)
+    {
+      newmsg = session->pending_message;
+      GNUNET_log(
+          GNUNET_ERROR_TYPE_ERROR,
+          "wlan_plugin_send: a pending message is already in the queue for 
this client\n remaining time to send this message is %u\n",
+          GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value);
+      return -1;
+    }
 
   newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
   (newmsg->msg) = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader));
@@ -1453,6 +1634,9 @@
   newmsg->transmit_cont = cont;
   newmsg->transmit_cont_cls = cont_cls;
   newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+
+  newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
+
   newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader);
 
   session->pending_message = newmsg;
@@ -1510,7 +1694,7 @@
             {
               if (pendingsession->content == queue->content)
                 {
-                  plugin->pendingsessions --;
+                  plugin->pendingsessions--;
                   GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
                       plugin->pending_Sessions_tail, pendingsession);
                   GNUNET_free(pendingsession);
@@ -1521,20 +1705,23 @@
 
           //is something of this session in the fragment queue?
           fm = get_fragment_message_from_session(queue->content);
-          free_fragment_message(plugin,fm);
+          free_fragment_message(plugin, fm);
 
           //dispose all received fragments
           free_rec_frag_queue(queue->content);
 
           // remove PendingMessage
           pm = queue->content->pending_message;
-          GNUNET_free(pm->msg);
-          GNUNET_free(pm);
+          if (pm != NULL)
+            {
+              GNUNET_free_non_null(pm->msg);
+              GNUNET_free(pm);
+            }
 
           GNUNET_free(queue->content);
           GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, 
queue);
           GNUNET_free(queue);
-          plugin->session_count --;
+          plugin->session_count--;
 
           return;
         }
@@ -1543,7 +1730,6 @@
     }
 }
 
-
 /**
  * Convert the transports address to a nice, human-readable
  * format.
@@ -1559,37 +1745,29 @@
  * @param asc_cls closure for asc
  */
 static void
-wlan_plugin_address_pretty_printer (void *cls,
-                                   const char *type,
-                                   const void *addr,
-                                   size_t addrlen,
-                                   int numeric,
-                                   struct GNUNET_TIME_Relative timeout,
-                                   GNUNET_TRANSPORT_AddressStringCallback
-                                   asc, void *asc_cls)
+wlan_plugin_address_pretty_printer(void *cls, const char *type,
+    const void *addr, size_t addrlen, int numeric,
+    struct GNUNET_TIME_Relative timeout,
+    GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
 {
   char ret[92];
   const unsigned char * input;
-  
+
   GNUNET_assert(cls !=NULL);
   if (addrlen != 6)
     {
       /* invalid address (MAC addresses have 6 bytes) */
       GNUNET_break (0);
-      asc (asc_cls, NULL);
+      asc(asc_cls, NULL);
       return;
     }
   input = (const unsigned char*) addr;
-  GNUNET_snprintf (ret, 
-                  sizeof (ret),
-                  "%s Mac-Adress %X:%X:%X:%X:%X:%X",
-                  PROTOCOL_PREFIX, 
-                  input[0], input[1], input[2], input[3], input[4], input[5]); 
 
-  asc (asc_cls, ret);
+  GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Adress 
%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+      PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4],
+      input[5]);
+  asc(asc_cls, ret);
 }
 
-
-
 /**
  * Another peer has suggested an address for this
  * peer and transport plugin.  Check that this could be a valid
@@ -1603,31 +1781,30 @@
  *         and transport
  */
 
-
 static int
-wlan_plugin_address_suggested (void *cls,
-                                  const void *addr,
-                                  size_t addrlen)
+wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
 {
   //struct Plugin *plugin = cls;
 
   /* check if the address is plausible; if so,
-     add it to our list! */
+   add it to our list! */
 
   GNUNET_assert(cls !=NULL);
   //FIXME mitm is not checked
   //Mac Adress has 6 bytes
-  if (addrlen == 6){
-    /* TODO check for bad addresses like milticast, broadcast, etc */
-    return GNUNET_OK;
-  } else {
-    return GNUNET_SYSERR;
-  }
+  if (addrlen == 6)
+    {
+      /* TODO check for bad addresses like multicast, broadcast, etc */
+      return GNUNET_OK;
+    }
+  else
+    {
+      return GNUNET_SYSERR;
+    }
 
   return GNUNET_SYSERR;
 }
 
-
 /**
  * Function called for a quick conversion of the binary address to
  * a numeric address.  Note that the caller must not free the 
@@ -1639,14 +1816,12 @@
  * @param addrlen length of the address
  * @return string representing the same address 
  */
-static const char* 
-wlan_plugin_address_to_string (void *cls,
-                              const void *addr,
-                              size_t addrlen)
+static const char*
+wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
 {
   static char ret[40];
   const unsigned char * input;
-  
+
   GNUNET_assert(cls !=NULL);
   if (addrlen != 6)
     {
@@ -1655,11 +1830,9 @@
       return NULL;
     }
   input = (const unsigned char*) addr;
-  GNUNET_snprintf (ret, 
-                  sizeof (ret),
-                  "%s Mac-Adress %X:%X:%X:%X:%X:%X",
-                  PROTOCOL_PREFIX, 
-                  input[0], input[1], input[2], input[3], input[4], input[5]); 
 
+  GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Adress 
%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+      PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4],
+      input[5]);
   return ret;
 }
 
@@ -1707,7 +1880,7 @@
   if (rec_queue->num == 0)
     {
       wlanheader = (struct WlanHeader *) rec_queue->msg;
-      session->rec_size = wlanheader->header.size;
+      session->rec_size = ntohs(wlanheader->header.size);
     }
 
   //sort into list
@@ -1754,7 +1927,9 @@
  */
 
 static void
-check_rec_finished_msg (struct Plugin* plugin, struct Session_light * 
session_light, struct Session * session){
+check_rec_finished_msg(struct Plugin* plugin,
+    struct Session_light * session_light, struct Session * session)
+{
   struct RecQueue * rec_queue = session->frag_head;
   int packetsize = session->rec_size;
   int sum = 0;
@@ -1763,107 +1938,75 @@
   //some fragment should be received
   GNUNET_assert(session->rec_size != NO_MESSAGE_OR_MESSAGE_FINISHED);
   //check if first fragment is present
-  if (session->rec_size == MESSAGE_LENGHT_UNKNOWN){
-    return;
-  }
-  while (rec_queue != NULL){
-    sum += rec_queue->size;
-    //check if all fragment numbers are present
-    if (rec_queue->num != aktnum){
+  if (session->rec_size == MESSAGE_LENGHT_UNKNOWN)
+    {
       return;
     }
-    aktnum ++;
-    rec_queue = rec_queue->next;
-  }
+  while (rec_queue != NULL)
+    {
+      sum += rec_queue->size;
+      //check if all fragment numbers are present
+      if (rec_queue->num != aktnum)
+        {
+          return;
+        }
+      aktnum++;
+      rec_queue = rec_queue->next;
+    }
   //sum should always be smaller or equal of
   GNUNET_assert(sum <= packetsize);
-  if(sum == packetsize){
+  if (sum == packetsize)
+    {
 
 #if DEBUG_wlan
       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
           "check_rec_finished_msg: A message with fragments is complete\n");
 #endif
 
-    //copy fragments together
-    msg = GNUNET_malloc(packetsize);
-    rec_queue = session->frag_head;
-    aktnum = 0;
-    while (rec_queue != NULL){
-      memcpy(msg + aktnum, rec_queue->msg, rec_queue->size);
-      aktnum += rec_queue->size;
-      rec_queue = rec_queue->next;
+      //copy fragments together
+      msg = GNUNET_malloc(packetsize);
+      rec_queue = session->frag_head;
+      aktnum = 0;
+      while (rec_queue != NULL)
+        {
+          memcpy(msg + aktnum, rec_queue->msg, rec_queue->size);
+          aktnum += rec_queue->size;
+          rec_queue = rec_queue->next;
+        }
+      free_rec_frag_queue(session);
+      //call wlan_process_helper to process the message
+      wlan_data_massage_handler(plugin, session_light,
+          (struct GNUNET_MessageHeader*) msg);
+      //wlan_data_helper (plugin, session_light, (struct 
GNUNET_MessageHeader*) msg);
+
+      GNUNET_free(msg);
     }
-    free_rec_frag_queue(session);
-    //call wlan_process_helper to process the message
-    wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) 
msg);
-
-    GNUNET_free(msg);
-  }
 }
 
-/**
- * Function used for to process the data received from the wlan interface
- *
- * @param cls the plugin handle
- * @param client client which send the data (not used)
- * @param hdr hdr of the GNUNET_MessageHeader
- */
 static void
-wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * 
hdr)
+wlan_data_massage_handler(struct Plugin * plugin,
+    struct Session_light * session_light,
+    const struct GNUNET_MessageHeader * hdr)
 {
-  struct Plugin *plugin = cls;
+  struct WlanHeader * wlanheader = NULL;
   struct Session * session = NULL;
-  struct Session_light * session_light = NULL;
-
-  struct WlanHeader * wlanheader = NULL;
-  struct FragmentationHeader * fh = NULL;
-  struct FragmentMessage * fm = NULL;
-
   const char * tempmsg = NULL;
-
-  struct AckQueue * ack = NULL;
-  struct AckQueue * ack2 = NULL;
-
-  struct RecQueue * rec_queue = NULL;
   const struct GNUNET_MessageHeader * temp_hdr = NULL;
+  struct GNUNET_PeerIdentity tmptarget;
 
-  if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
+  if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
     {
 
 #if DEBUG_wlan
       GNUNET_log(
           GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT 
size: %i\n",
+          "Func wlan_data_massage_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA 
size: %u\n",
           ntohs(hdr->size));
 #endif
 
-      //TODO better DOS protection, error handling
-      GNUNET_assert(client != NULL);
-      session_light = (struct Session_light *) client;
+      GNUNET_assert(session_light != NULL);
       if (session_light->session == NULL)
         {
-          session_light->session = get_Session(plugin, session_light->addr);
-        }
-      GNUNET_assert(GNUNET_HELLO_get_id(
-              (const struct GNUNET_HELLO_Message *) &hdr[1],
-              &(session_light->session->target) ) != GNUNET_SYSERR);
-
-    }
-
-
-    else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
-    {
-
-#if DEBUG_wlan
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %i\n",
-          ntohs(hdr->size));
-#endif
-
-      GNUNET_assert(client != NULL);
-      session_light = (struct Session_light *) client;
-      if (session_light->session == NULL)
-        {
           session_light->session = search_session(plugin, session_light->addr);
         }
       session = session_light->session;
@@ -1871,31 +2014,62 @@
       tempmsg = (char*) &wlanheader[1];
       temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
 
-      if (getcrc32(tempmsg, wlanheader->header.size) != wlanheader->crc)
+      if (getcrc32(tempmsg, ntohs(wlanheader->header.size)) != ntohl(
+          wlanheader->crc))
         {
           //wrong crc, dispose message
-          GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN message crc was wrong\n");
+          GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+              "Wlan message Header crc was wrong\n");
           return;
         }
 
       //if not in session list
       if (session == NULL)
         {
-
+#if DEBUG_wlan
+          GNUNET_log(
+              GNUNET_ERROR_TYPE_DEBUG,
+              "WLAN client not in session list: packet size = %u, inner size = 
%u, header size = %u\n",
+              ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
+              sizeof(struct WlanHeader));
+#endif
           //try if it is a hello message
-          if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
+          if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size)
+              + sizeof(struct WlanHeader))
             {
-              session = create_session(plugin, session_light->addr);
-              session_light->session = session;
-              GNUNET_assert(GNUNET_HELLO_get_id(
+              if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
+                {
+                  if (GNUNET_HELLO_get_id(
                       (const struct GNUNET_HELLO_Message *) temp_hdr,
-                      &session->target ) != GNUNET_SYSERR);
+                      &tmptarget) == GNUNET_OK)
+                    {
+                      session = create_session(plugin, session_light->addr);
+                      session_light->session = session;
+                      memcpy(&session->target, &tmptarget,
+                          sizeof(struct GNUNET_PeerIdentity));
+                    }
+                  else
+                    {
+                      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                          "WLAN client not in session list and hello message 
not okay\n");
+                      return;
+                    }
 
+                }
+              else
+                {
+                  GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                      "WLAN client not in session list and not a hello 
message\n");
+                  return;
+                }
             }
           else
             {
-              GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
-                  "WLAN client not in session list and not a hello message\n");
+              GNUNET_log(
+                  GNUNET_ERROR_TYPE_WARNING,
+                  "WLAN client not in session list and message size in does 
not fit\npacket size = %u, inner size = %u, header size = %u\n",
+                  ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
+                  sizeof(struct WlanHeader));
               return;
             }
         }
@@ -1906,26 +2080,104 @@
       distance[0].value = htonl(1);
       distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
       distance[1].value = htonl(0);
+
+#if DEBUG_wlan
+          GNUNET_log(
+              GNUNET_ERROR_TYPE_DEBUG,
+              "Calling plugin->env->receive\n");
+#endif
       plugin->env->receive(plugin->env->cls, &(session->target), temp_hdr,
           (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
           session, session->addr, sizeof(session->addr));
-
+      return;
     }
+  else
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+          "wlan_data_massage_handler got wrong message type\n");
+      return;
+    }
+}
 
-  else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
+/**
+ * function to add an ack to send it for a received fragment
+ * @param plugin pointer to the global plugin structure
+ * @param session pointer to the session this ack belongs to
+ * @param fh pointer to the fragmentation header which we would like to 
acknolage
+ */
+
+void
+add_ack_for_send(struct Plugin * plugin, struct Session * session,
+    struct FragmentationHeader * fh)
+{
+  struct AckSendQueue * ack;
+
+  GNUNET_assert(plugin != NULL);
+  GNUNET_assert(session != NULL);
+  GNUNET_assert(fh != NULL);
+
+  ack = GNUNET_malloc(sizeof(struct AckSendQueue));
+  ack->fragment_off_or_num = ntohs(fh->fragment_off_or_num);
+  ack->message_id = ntohl(fh->message_id);
+  ack->session = session;
+
+  GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head,
+      plugin->ack_send_queue_tail, ack);
+
+}
+
+/**
+ * Function used for to process the data received from the wlan interface
+ *
+ * @param cls the plugin handle
+ * @param client client which send the data (not used)
+ * @param hdr hdr of the GNUNET_MessageHeader
+ */
+static void
+wlan_data_helper(void *cls, struct Session_light * session_light,
+    const struct GNUNET_MessageHeader * hdr)
+{
+  struct Plugin *plugin = cls;
+  struct Session * session = NULL;
+
+  struct FragmentationHeader * fh = NULL;
+  struct FragmentMessage * fm = NULL;
+
+  const char * tempmsg = NULL;
+
+  struct AckQueue * ack = NULL;
+  struct AckQueue * ack2 = NULL;
+
+  struct RecQueue * rec_queue = NULL;
+  //ADVERTISEMENT
+  if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
     {
-
 #if DEBUG_wlan
       GNUNET_log(
           GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT size: 
%i\n",
+          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT 
size: %u\n",
           ntohs(hdr->size));
 #endif
 
-      GNUNET_assert(client != NULL);
-      session_light = (struct Session_light *) client;
+      //TODO better DOS protection, error handling
+      GNUNET_assert(session_light != NULL);
       if (session_light->session == NULL)
         {
+          session_light->session = get_Session(plugin, session_light->addr);
+        }
+      GNUNET_assert(GNUNET_HELLO_get_id(
+              (const struct GNUNET_HELLO_Message *) &hdr[1],
+              &(session_light->session->target) ) != GNUNET_SYSERR);
+
+    }
+
+  //FRAGMENT
+  else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
+    {
+
+      GNUNET_assert(session_light != NULL);
+      if (session_light->session == NULL)
+        {
           session_light->session = search_session(plugin, session_light->addr);
         }
       session = session_light->session;
@@ -1933,83 +2185,106 @@
       fh = (struct FragmentationHeader *) hdr;
       tempmsg = (char*) &fh[1];
 
-      //if not in session list
+#if DEBUG_wlan
+      GNUNET_log(
+          GNUNET_ERROR_TYPE_DEBUG,
+          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with 
message_id %u with fragment number %i, size: %u\n",
+          ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs(
+              hdr->size));
+#endif
+
+      if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc))
+        {
+          //wrong crc, dispose message
+          GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN fragment crc was wrong\n");
+          return;
+        }
+
+      //if in the session list
       if (session != NULL)
         {
-          if (getcrc16(tempmsg, fh->header.size) != fh->message_crc)
+          //TODO fragments do not timeout
+          //check if message_id is right or it is a new msg
+          if ((session->message_id_in == ntohs(fh->message_id))
+              || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
             {
-              //wrong crc, dispose message
-              GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-                  "WLAN fragment crc was wrong\n");
-              return;
-            }
-          else
-            {
-              //todo fragments do not timeout
-              //check if message_id is rigth or it is a new msg
-              if ((session->message_id_in == ntohs(fh->message_id))
-                  || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
+              session->message_id_in = ntohs(fh->message_id);
+              if (is_double_msg(session, fh) != GNUNET_YES)
                 {
-                  session->message_id_in = ntohs(fh->message_id);
-                  if (is_double_msg(session, fh) != GNUNET_YES)
+                  //report size
+                  //TODO ask if it is right like this
+                  if (plugin->env->traffic_report != NULL)
                     {
-                      rec_queue
-                          = GNUNET_malloc(sizeof (struct RecQueue) +
-                              ntohs(fh->header.size) - sizeof(struct 
FragmentationHeader));
-                      rec_queue->size = ntohs(fh->header.size
-                          - sizeof(struct FragmentationHeader));
-                      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);
-                      insert_fragment_in_queue(session, rec_queue);
-                      check_rec_finished_msg(plugin, session_light, session);
+                      plugin->env->traffic_report(plugin->env->cls,
+                          &session->target, ntohs(fh->header.size));
                     }
-                  else
-                    {
-                      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-                          "WLAN fragment is a clone\n");
-                      return;
-                    }
+                  rec_queue
+                      = GNUNET_malloc(sizeof (struct RecQueue) +
+                          ntohs(fh->header.size) - sizeof(struct 
FragmentationHeader));
+                  rec_queue->size = ntohs(fh->header.size)
+                      - sizeof(struct FragmentationHeader);
+                  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);
+                  insert_fragment_in_queue(session, rec_queue);
+                  check_rec_finished_msg(plugin, session_light, session);
                 }
               else
                 {
-                  GNUNET_log(
-                      GNUNET_ERROR_TYPE_INFO,
-                      "WLAN fragment message_id and session message_id are not 
the same and a message is already (partly) received\n");
-                  return;
+                  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                      "WLAN fragment is a clone\n");
+
                 }
             }
+          else
+            {
+              GNUNET_log(
+                  GNUNET_ERROR_TYPE_INFO,
+                  "WLAN fragment message_id and session message_id are not the 
same and a message is already (partly) received\n");
+
+            }
         }
       else
         {
-          GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+          GNUNET_log(GNUNET_ERROR_TYPE_INFO,
               "WLAN client not in session list and it is a fragment 
message\n");
-          return;
+          wlan_data_massage_handler(plugin, session_light,
+              (struct GNUNET_MessageHeader *) tempmsg);
+          session = session_light->session;
+          //test if a session was created
+          if (session == NULL)
+            {
+              return;
+            }
         }
 
+      //TODO make and send ack
+      add_ack_for_send(plugin, session, fh);
+      check_next_fragment_timeout(plugin);
+
     }
 
+  //ACK
   else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
     {
 
 #if DEBUG_wlan
       GNUNET_log(
           GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK 
size: %i\n",
+          "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK 
size: %u\n",
           ntohs(hdr->size));
 #endif
 
-      GNUNET_assert(client != NULL);
-      session_light = (struct Session_light *) client;
+      GNUNET_assert(session_light != NULL);
       if (session_light->session == NULL)
         {
           session_light->session = search_session(plugin, session_light->addr);
           GNUNET_assert(session_light->session != NULL);
         }
       session = session_light->session;
-      fh = (struct FragmentationHeader *) &hdr[1];
-      if (fh->message_id == session->message_id_out)
+      fh = (struct FragmentationHeader *) hdr;
+      if (session->message_id_out == ntohl(fh->message_id))
         {
           fm = get_fragment_message_from_session(session);
           if (fm != NULL)
@@ -2019,13 +2294,13 @@
               while (ack2 != NULL)
                 {
                   // check for double
-                  if (ack2->fragment_num != fh->fragment_off_or_num)
+                  if (ack2->fragment_num != ntohs(fh->fragment_off_or_num))
                     {
                       // check if next ack has bigger number
-                      if (ack2->fragment_num > fh->fragment_off_or_num)
+                      if (ack2->fragment_num > ntohs(fh->fragment_off_or_num))
                         {
                           ack = GNUNET_malloc(sizeof(struct AckQueue));
-                          ack->fragment_num = fh->fragment_off_or_num;
+                          ack->fragment_num = ntohs(fh->fragment_off_or_num);
                           
GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack);
                           //check if finished
                           check_finished_fragment(plugin, fm);
@@ -2035,22 +2310,42 @@
                   else
                     {
                       //double ack
+#if DEBUG_wlan
+                      GNUNET_log(
+                          GNUNET_ERROR_TYPE_DEBUG,
+                          "WLAN got double ack for message id %u and fragment 
num %u\n",
+                          session->message_id_out, ack2->fragment_num);
+#endif
                       return;
                     }
                   ack2 = ack2->next;
                 }
-              //GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
-              //should never happen but...
-              //check_finished_fragment(plugin, fm);
+
+              //all acks are have smaller numbers
+              ack = GNUNET_malloc(sizeof(struct AckQueue));
+              ack->fragment_num = ntohs(fh->fragment_off_or_num);
+              GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
+              check_finished_fragment(plugin, fm);
             }
           else
             {
-              GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
-                  "WLAN fragment not in fragment list but id is right\n");
+              GNUNET_log(
+                  GNUNET_ERROR_TYPE_WARNING,
+                  "WLAN fragment not in fragment list but id %u of ack is 
right\n",
+                  ntohl(fh->message_id));
               return;
             }
 
         }
+      else
+        {
+#if DEBUG_wlan
+          GNUNET_log(
+              GNUNET_ERROR_TYPE_DEBUG,
+              _("WLAN got ack but session->message_id_out %u and fragment id 
%u mismatch\n"),
+              session->message_id_out, ntohl(fh->message_id));
+#endif
+        }
 
     }
   else
@@ -2062,8 +2357,8 @@
     }
 
 #if 0
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-          "Helper finished\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+      "Helper finished\n");
 #endif
 
 }
@@ -2077,83 +2372,105 @@
  */
 
 static void
-wlan_process_helper (void *cls,
-                      void *client,
-                      const struct GNUNET_MessageHeader *hdr)
+wlan_process_helper(void *cls, void *client,
+    const struct GNUNET_MessageHeader *hdr)
 {
   struct Plugin *plugin = cls;
   struct IeeeHeader * wlanIeeeHeader = NULL;
   struct Session_light * session_light = NULL;
   const struct GNUNET_MessageHeader * temp_hdr = NULL;
 
+  int datasize = 0;
   int pos = 0;
 
-
   if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA)
     {
 #if DEBUG_wlan
       GNUNET_log(
           GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_process_helper got  GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 
size: %i\n",
+          "Func wlan_process_helper got  GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 
size: %u\n",
           ntohs(hdr->size));
 #endif
 
       //call wlan_process_helper with the message inside, later with wlan: 
analyze signal
-      GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader));
+      GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader) + 
sizeof(struct GNUNET_MessageHeader));
       wlanIeeeHeader = (struct IeeeHeader *) &hdr[1];
+      datasize = ntohs(hdr->size) - sizeof(struct IeeeHeader)
+          - sizeof(struct GNUNET_MessageHeader);
 
       session_light = GNUNET_malloc(sizeof(struct Session_light));
-      memcpy(session_light->addr, &(wlanIeeeHeader->mac3), sizeof(struct 
MacAddress));
+      memcpy(session_light->addr, &(wlanIeeeHeader->mac3),
+          sizeof(struct MacAddress));
       session_light->session = search_session(plugin, session_light->addr);
 
       //process only if it is an broadcast or for this computer both with the 
gnunet bssid
+
       //check for bssid
-      if (memcmp(&(wlanIeeeHeader->mac2), macbc, sizeof(struct MacAddress)))
+      if (memcmp(&(wlanIeeeHeader->mac2), macbc, sizeof(struct MacAddress))
+          == 0)
         {
           //check for broadcast or mac
-          if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac, sizeof(struct 
MacAddress))
-              || memcmp(&(wlanIeeeHeader->mac1), &(plugin->mac_address),
-                  sizeof(struct MacAddress)))
+          if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac,
+              sizeof(struct MacAddress) == 0) || memcmp(
+              &(wlanIeeeHeader->mac1), &(plugin->mac_address),
+              sizeof(struct MacAddress)) == 0)
             {
               // process the inner data
-            pos = 0;
-            temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1];
-              while (pos < hdr->size)
+              pos = 0;
+              temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1];
+              while (pos < datasize)
                 {
+                  temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]
+                      + pos;
+
                   wlan_data_helper(plugin, session_light, temp_hdr);
-                  pos += temp_hdr->size + sizeof(struct GNUNET_MessageHeader);
+                  pos += ntohs(temp_hdr->size);
+
                 }
             }
+          else
+            {
+#if DEBUG_wlan
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                  "Func wlan_process_helper got wrong MAC: %s\n",
+                  wlanIeeeHeader->mac1);
+#endif
+            }
         }
+      else
+        {
+#if DEBUG_wlan
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+              "Func wlan_process_helper got wrong BSSID: %s\n",
+              wlanIeeeHeader->mac2);
+#endif
+        }
 
       //clean up
       GNUNET_free(session_light);
 
     }
 
-
-
   else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL)
     {
 
-
 #if DEBUG_wlan
       GNUNET_log(
           GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_process_helper got  
GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL size: %i\n",
+          "Func wlan_process_helper got  
GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL size: %u\n",
           ntohs(hdr->size));
 #endif
 
-      //TODO more control
+      //TODO more control messages
       //TODO use struct wlan_helper_control
       if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message))
         {
           //plugin->mac_address = GNUNET_malloc(sizeof(struct MacAddress));
           memcpy(&(plugin->mac_address), &hdr[1], sizeof(struct MacAddress));
-          GNUNET_log(
-              GNUNET_ERROR_TYPE_DEBUG,
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
               "Notifying transport of address %s\n",
-              wlan_plugin_address_to_string(cls, &(plugin->mac_address), 
ntohs(hdr->size) - sizeof(struct GNUNET_MessageHeader)));
+              wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs(
+                  hdr->size) - sizeof(struct GNUNET_MessageHeader)));
           plugin->env->notify_address(plugin->env->cls, "wlan",
               &plugin->mac_address, sizeof(struct MacAddress),
               GNUNET_TIME_UNIT_FOREVER_REL);
@@ -2166,11 +2483,11 @@
 
     }
 
-
   else
     {
       // TODO Wrong data?
-      GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN helper packet has not the right 
type\n");
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+          "WLAN helper packet has not the right type\n");
       return;
     }
 }
@@ -2185,43 +2502,44 @@
  */
 
 static void
-wlan_plugin_helper_read (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+wlan_plugin_helper_read(void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct Plugin *plugin = cls;
   plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
 
-#if DEBUG_wlan
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      "Start reading from STDIN\n");
-#endif
-
+  /*
+   #if DEBUG_wlan
+   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+   "Start reading from STDIN\n");
+   #endif
+   */
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
     return;
 
   char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)];
   ssize_t bytes;
 
-  bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, 
-                                mybuf, sizeof(mybuf));
+  bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, mybuf,
+      sizeof(mybuf));
   if (bytes <= 0)
     {
 #if DEBUG_wlan
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      _("Finished reading from wlan-helper stdout with code: 
%d\n"), bytes);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+          _("Finished reading from wlan-helper stdout with code: %d\n"),
+          bytes);
 #endif
       return;
     }
-  GNUNET_SERVER_mst_receive(plugin->consoltoken, NULL,
-                           mybuf, bytes, GNUNET_NO, GNUNET_NO);
+  GNUNET_SERVER_mst_receive(plugin->consoltoken, NULL, mybuf, bytes, GNUNET_NO,
+      GNUNET_NO);
 
   GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
-  plugin->server_read_task =
-  GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                  plugin->server_stdout_handle, 
&wlan_plugin_helper_read, plugin);
+  plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
+      GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
+      &wlan_plugin_helper_read, plugin);
 }
 
-
 /**
  * Start the gnunet-wlan-helper process.
  *
@@ -2242,18 +2560,19 @@
     return GNUNET_SYSERR;
 
 #if DEBUG_wlan
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filename, 
plugin->interface, testmode);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+      "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filename,
+      plugin->interface, testmode);
 #endif
   /* Start the server process */
 
-
   plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
-                 plugin->server_stdout, filename,filename, plugin->interface, 
((testmode==1)?"1":(testmode==2)?"2":"0"), NULL);
+      plugin->server_stdout, filename, filename, plugin->interface, ((testmode
+          == 1) ? "1" : (testmode == 2) ? "2" : "0"), NULL);
   if (plugin->server_proc == NULL)
     {
 #if DEBUG_wlan
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
           "Failed to start gnunet-wlan-helper process\n");
 #endif
       return GNUNET_SYSERR;
@@ -2273,7 +2592,7 @@
   GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
 
 #if DEBUG_wlan
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
       "Adding server_read_task for the wlan-helper\n");
 #endif
 
@@ -2286,27 +2605,27 @@
   return GNUNET_YES;
 }
 
-
 /**
  * Exit point from the plugin.
+ * @param cls pointer to the api struct
  */
-//TODO doxigen
+
 //FIXME cleanup
 void *
-libgnunet_plugin_transport_wlan_done (void *cls)
+libgnunet_plugin_transport_wlan_done(void *cls)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
 
 #if DEBUG_wlan
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
       "libgnunet_plugin_transport_wlan_done started\n");
 #endif
 
   GNUNET_assert(cls !=NULL);
 
   if (plugin->consoltoken != NULL)
-  GNUNET_SERVER_mst_destroy(plugin->consoltoken);
+    GNUNET_SERVER_mst_destroy(plugin->consoltoken);
 
   GNUNET_free_non_null(plugin->interface);
   GNUNET_free (plugin);
@@ -2321,13 +2640,13 @@
  * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
  */
 void *
-libgnunet_plugin_transport_wlan_init (void *cls)
+libgnunet_plugin_transport_wlan_init(void *cls)
 {
   //struct GNUNET_SERVICE_Context *service;
   struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
   struct GNUNET_TRANSPORT_PluginFunctions *api;
   struct Plugin *plugin;
-  static unsigned long long testmode =0;
+  static unsigned long long testmode = 0;
 
   GNUNET_assert(cls !=NULL);
 
@@ -2339,26 +2658,27 @@
   plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
   plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
 
+  set_next_beacon_time(plugin);
 
   if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE"))
     {
-      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, 
"transport-wlan",
-          "TESTMODE", &testmode))
+      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg,
+          "transport-wlan", "TESTMODE", &testmode))
         return NULL;
     }
 
-  if (GNUNET_CONFIGURATION_have_value(env->cfg,
-                 "transport-wlan", "INTERFACE"))
-       {
-          if (GNUNET_CONFIGURATION_get_value_string (env->cfg,
-                         "transport-wlan","INTERFACE", &(plugin->interface)) 
!= GNUNET_YES){
-                  libgnunet_plugin_transport_wlan_done(plugin);
-                  return NULL;
-          }
-       }
+  if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE"))
+    {
+      if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan",
+          "INTERFACE", &(plugin->interface)) != GNUNET_YES)
+        {
+          libgnunet_plugin_transport_wlan_done(plugin);
+          return NULL;
+        }
+    }
 
   wlan_transport_start_wlan_helper(plugin, testmode);
-  plugin->consoltoken = GNUNET_SERVER_mst_create(&wlan_process_helper,plugin);
+  plugin->consoltoken = GNUNET_SERVER_mst_create(&wlan_process_helper, plugin);
 
   //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
   //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
@@ -2371,12 +2691,10 @@
   api->check_address = &wlan_plugin_address_suggested;
   api->address_to_string = &wlan_plugin_address_to_string;
 
-
   start_next_message_id();
 
 #if DEBUG_wlan
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "wlan init finished\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "wlan init finished\n");
 #endif
 
   return api;




reply via email to

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