- * @param numeric should (IP) addresses be displayed in numeric form?
- * @param timeout after how long should we give up?
- * @param asc function to call on each string
- * @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)
-{
- 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);
- return;
- }
- input = (const unsigned char*) addr;
- GNUNET_snprintf(ret, sizeof(ret),
- "%s Mac-Address %.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
- * address. If so, consider adding it to the list
- * of addresses.
- *
- * @param cls closure
- * @param addr pointer to the address
- * @param addrlen length of addr
- * @return GNUNET_OK if this is a plausible address for this peer
- * and transport
- */
-
-static int
-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! */
-
- GNUNET_assert(cls !=NULL);
- //FIXME mitm is not checked
- //Mac Address has 6 bytes
- if (addrlen == 6)
- {
- /* TODO check for bad addresses like multicast, broadcast, etc */
- return GNUNET_OK;
- }
-
- 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
- * address and that the next call to this function is allowed
- * to override the address again.
- *
- * @param cls closure
- * @param addr binary address
- * @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 char ret[40];
- const struct MacAddress *mac;
-
- if (addrlen != sizeof(struct MacAddress))
- {
- GNUNET_break (0);
- return NULL;
- }
- mac = addr;
- GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
- PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3],
- mac->mac[4], mac->mac[5]);
- return ret;
-}
-
-/**
- * function to check if bitfield is representation of fragments of the message
- * @param rec_message message to check
- */
-
-void
-check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message)
-{
- uint64_t checkfragments = 0;
- struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head;
-
- while (rec_queue != NULL)
- {
- setBit((char*) &checkfragments, rec_queue->num);
- rec_queue = rec_queue->next;
-
- }
- GNUNET_assert(checkfragments == rec_message->received_fragments);
-}
-
-/**
- * Function to test if fragment number already exists in the fragments received
- *
- * @param rec_message message this fragment belongs to
- * @param fh Fragmentheader of the fragment
- * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session
- */
-
-static const int
-is_double_msg(struct Receive_Message_Queue * rec_message,
- struct FragmentationHeader * fh)
-{
- //test if bitfield is okay
-#if DEBUG_wlan
- check_message_fragment_bitfield(rec_message);
-#endif
-
- return testBit((char *) &rec_message->received_fragments, ntohs(
- fh->fragment_off_or_num));
-
-}
-
-/**
- * Function to insert a fragment in a queue of a message
- * @param session session the fragment belongs to
- * @param rec_queue fragment to add
- */
-
-static void
-insert_fragment_in_queue(struct Receive_Message_Queue * rec_message,
- struct Receive_Fragment_Queue * rec_queue)
-{
- GNUNET_assert(rec_message != NULL);
- GNUNET_assert(rec_queue != NULL);
-
- struct Receive_Fragment_Queue * rec_queue2 = rec_message->frag_head;
- struct WlanHeader * wlanheader = NULL;
-
- //this is the first fragment of the message (fragment id 0)
- if (rec_queue->num == 0)
- {
- wlanheader = (struct WlanHeader *) rec_queue->msg;
- rec_message->rec_size = ntohs(wlanheader->header.size);
- }
-
- //sort into list
- while (rec_queue2 != NULL)
- {
- if (rec_queue2->num > rec_queue->num)
- {
- //next element number is grater than the current num
- GNUNET_CONTAINER_DLL_insert_before(rec_message->frag_head, rec_message->frag_tail, rec_queue2, rec_queue);
- setBit((char *) &rec_message->received_fragments, rec_queue->num);
- return;
- }
- rec_queue = rec_queue->next;
- }
- //no element has a grater number
- GNUNET_CONTAINER_DLL_insert_tail(rec_message->frag_head, rec_message->frag_tail, rec_queue);
-
- setBit((char *) &rec_message->received_fragments, rec_queue->num);
-}
-
-/**
- * Function to dispose the fragments received for a message and the message
- * @param plugin pointer to the plugin struct
- * @param rec_message pointer to the struct holding the message which should be freed
- */
-
-static void
-free_receive_message(struct Plugin* plugin,
- struct Receive_Message_Queue * rx_message)
-{
- GNUNET_assert(rx_message !=NULL);
- struct Receive_Fragment_Queue * rec_queue = rx_message->frag_head;
- struct Receive_Fragment_Queue * rec_queue2;
-
- while (rec_queue != NULL)
- {
- rec_queue2 = rec_queue;
- rec_queue = rec_queue->next;
- GNUNET_free(rec_queue2);
- }
-
- GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message);
-
- GNUNET_assert(plugin->pending_receive_messages > 0);
- GNUNET_assert(rx_message->session->fragment_messages_in_count > 0);
-
- plugin->pending_receive_messages--;
- rx_message->session->fragment_messages_in_count--;
- GNUNET_free(rx_message);
-}
-
-/**
- * Function to check if all fragments of a message have been received
- * @param plugin the plugin handle
- * @param session_light information of the message sender
- * @param session session the message belongs to
- * @param rec_message pointer to the message that should be checked
- */
-
-static void
-check_rec_finished_msg(struct Plugin* plugin,
- struct Session_light * session_light, struct Session * session,
- struct Receive_Message_Queue * rx_message)
-{
- GNUNET_assert(rx_message !=NULL);
-
- struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head;
- int packetsize = rx_message->rec_size;
- int sum = 0;
- int aktnum = 0;
- uint64_t bitfield = 0;
- char * msg;
-
- //check if first fragment is present
- if (packetsize == MESSAGE_LENGHT_UNKNOWN)
- {
- return;
- }
- // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader
- else if (packetsize < sizeof(struct WlanHeader)
- + sizeof(struct GNUNET_MessageHeader))
- {
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Message not big enough\n");
-#endif
- free_receive_message(plugin, rx_message);
- return;
- }
-
-#if DEBUG_wlan
- check_message_fragment_bitfield(rx_message);
-#endif
-
- if (rx_message->frag_tail->num == ffsl(rx_message->received_fragments))
- {
- bitfield = ~bitfield;
- bitfield = bitfield << (63 - ffsl(rx_message->received_fragments));
- if (rx_message->received_fragments == bitfield)
- {
-
- while (rx_frag != NULL)
- {
- sum += rx_frag->size;
- rx_frag = rx_frag->next;
- }
- //sum should always be smaller or equal of
- GNUNET_assert(sum <= packetsize);
- if (sum == packetsize)
- {
-
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "check_rec_finished_msg: A message for %p is complete\n",
- session);
-#endif
-
- //TODO use mst
- //copy fragments together
- msg = GNUNET_malloc(packetsize);
- rx_frag = rx_message->frag_head;
- aktnum = 0;
- while (rx_frag != NULL)
- {
- //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY
- memcpy(msg + aktnum, rx_frag->msg, rx_frag->size);
- aktnum += rx_frag->size;
- rx_frag = rx_frag->next;
- }
-
- free_receive_message(plugin, rx_message);
- //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);
- }
- }
- }
-}
-