-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);
-}
-
-/**
- * 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 int
-is_double_msg(struct Receive_Message_Queue * rx_msg,
- struct FragmentationHeader * fh)
-{
-
- return testBit((char *) &rx_msg->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 * rx_message,
- struct Receive_Fragment_Queue * rx_frag)
-{
- GNUNET_assert(rx_message != NULL);
- GNUNET_assert(rx_frag != NULL);
-
- struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head;
- struct WlanHeader * wlanheader;
-
- //this is the first fragment of the message (fragment id 0)
- if (rx_frag->num == 0)
- {
- wlanheader = (struct WlanHeader *) rx_frag->msg;
- rx_message->rec_size = ntohs(wlanheader->header.size);
- }
-
- //sort into list
- while (rx_frag2 != NULL)
- {
- if (rx_frag2->num > rx_frag->num)
- {
- //next element number is grater than the current num
- GNUNET_CONTAINER_DLL_insert_before(rx_message->frag_head, rx_message->frag_tail, rx_frag2, rx_frag);
- setBit((char *) &rx_message->received_fragments, rx_frag->num);
- return;
- }
- rx_frag2 = rx_frag2->next;
- }
-
- //no element has a grater number
- GNUNET_CONTAINER_DLL_insert_tail(rx_message->frag_head, rx_message->frag_tail, rx_frag);
-
- setBit((char *) &rx_message->received_fragments, rx_frag->num);
-}
-
-/**
- * handels the data after all fragments are put together
- * @param plugin
- * @param session_light
- * @param hdr pointer to the data
- */
-static void
-wlan_data_message_handler(void *cls, void *client,
- const struct GNUNET_MessageHeader *hdr)
-{
- struct Plugin * plugin = (struct Plugin*) cls;
- struct Session_light * session_light = (struct Session_light *) client;
- struct WlanHeader * wlanheader;
- struct Session * session;
- //const char * tempmsg;
- const struct GNUNET_MessageHeader * temp_hdr;
- struct GNUNET_PeerIdentity tmptarget;
- int crc;
-
- if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
- {
-
-#if DEBUG_wlan
- GNUNET_log(
- GNUNET_ERROR_TYPE_DEBUG,
- "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
- ntohs(hdr->size));
-#endif
-
- if (ntohs(hdr->size) < sizeof(struct WlanHeader)
- + sizeof(struct GNUNET_MessageHeader))
- {
- //packet not big enought
- return;
- }
-
- GNUNET_assert(session_light != NULL);
- if (session_light->session == NULL)
- {
- session_light->session = search_session(plugin, &session_light->addr);
- }
- session = session_light->session;
- wlanheader = (struct WlanHeader *) hdr;
-
- //tempmsg = (char*) &wlanheader[1];
- temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
- crc = ntohl(wlanheader->crc);
- wlanheader->crc = 0;
- if (getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)) != crc)
- {
- //wrong crc, dispose message
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Wlan message Header crc was wrong: %u != %u\n",getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)), crc);
- hexdump((void *)hdr, ntohs(hdr->size));
- 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(wlanheader->header.size) >= ntohs(temp_hdr->size)
- + sizeof(struct WlanHeader))
- {
- if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
- {
- if (GNUNET_HELLO_get_id(
- (const struct GNUNET_HELLO_Message *) temp_hdr,
- &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 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;
- }
- }
-
- //"receive" the message
-
-
- GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session,
- (const char *) temp_hdr,
- ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO);
-
- return;
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "wlan_data_message_handler got wrong message type\n");
- return;
- }
-}
-
-/**
- * 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_rx_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;
- //TODO CLEANUP
- //int aktnum;
- 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 (rx_message->frag_tail->num == ffsl(rx_message->received_fragments))
- // {
- bitfield = ~bitfield;
- bitfield = bitfield >> (63 - rx_message->frag_tail->num);
- if (rx_message->received_fragments == bitfield)
- {
- sum = 0;
- 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 cleanup
-
- //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;
- }*/
-
- while (rx_frag != NULL)
- {
- if (rx_frag->next != NULL)
- {
- GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer,
- session_light, rx_frag->msg, rx_frag->size, GNUNET_NO,
- GNUNET_NO);
- }
- else
- {
- //if it is the last fragment just kill all leftover
- GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer,
- session_light, rx_frag->msg, rx_frag->size, GNUNET_YES,
- GNUNET_NO);
- }
- rx_frag = rx_frag->next;
- }
- session->message_id_backlog[session->message_id_backlog_pos] = rx_message->message_id_in;
- session->message_id_backlog_pos = (session->message_id_backlog_pos + 1) % MESSAGE_ID_BACKLOG_SIZE;
- free_receive_message(plugin, rx_message);
- //call wlan_process_helper to process the message
- //wlan_data_message_handler(plugin, session_light,
- // (struct GNUNET_MessageHeader*) msg);
- //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
-
- //GNUNET_free(msg);
- }
- }
- // }
-}
-
-//TODO DOXIGEN
-static void
-process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)