-//TODO DOXIGEN
-static void
-send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
-{
-
- uint16_t size;
- ssize_t bytes;
- struct GNUNET_MessageHeader * msgheader;
- struct ieee80211_frame * ieeewlanheader;
- struct Radiotap_Send * radioHeader;
- struct FragmentationAckHeader * msgheader2;
-
- GNUNET_assert(sizeof(struct FragmentationAckHeader) <= WLAN_MTU);
-
- size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
- + sizeof(struct ieee80211_frame) + sizeof(struct FragmentationAckHeader);
-
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending ack for message_id %u with fragment field %u, size %u\n",
- ack->message_id, ack->fragments_field, size
- - sizeof(struct Radiotap_Send));
-#endif
-
- msgheader = GNUNET_malloc(size);
- msgheader->size = htons(size);
- msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
-
- radioHeader = (struct Radiotap_Send*) &msgheader[1];
- getRadiotapHeader(plugin, ack->session, radioHeader);
- ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
- getWlanHeader(ieeewlanheader, &ack->session->addr, plugin, size);
-
- msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1];
- msgheader2->header.size = htons(sizeof(struct FragmentationAckHeader));
- msgheader2->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK);
- msgheader2->message_id = htonl(ack->message_id);
- msgheader2->fragment_field = GNUNET_htonll(ack->fragments_field);
-
- 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_send(plugin);
-}
-
-//TODO DOXIGEN
-static void
-finish_sending(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Finish_send * finish = cls;
- struct Plugin * plugin;
- ssize_t bytes;
-
- plugin = finish->plugin;
- plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
-
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (finish->msgstart);
- GNUNET_free (finish);
- return;
- }
- bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle,
- finish->msgheader,
- finish->size);
- GNUNET_assert (bytes != GNUNET_SYSERR);
-
- if (bytes != finish->size)
- {
- finish->msgheader = finish->msgheader + bytes;
- finish->size = finish->size - bytes;
- plugin->server_write_task
- = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL,
- plugin->server_stdin_handle,
- &finish_sending, finish);
- }
- else
- {
- GNUNET_free(finish->msgstart);
- GNUNET_free(finish);
- set_next_send(plugin);
- }
-}
-
-/**
- * Function called when wlan helper is ready to get some data
- *
- * @param cls closure
- * @param tc GNUNET_SCHEDULER_TaskContext
- */
-static void
-do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Plugin * plugin = cls;
-
- plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- struct Session * session;
- struct FragmentMessage * fm;
- struct ieee80211_frame * ieeewlanheader;
- struct Radiotap_Send * radioHeader;
- struct GNUNET_MessageHeader * msgheader;
- struct FragmentationHeader fragheader;
- struct FragmentationHeader * fragheaderptr;
- struct Finish_send * finish;
- struct AckSendQueue * ack;
- uint16_t size;
- ssize_t bytes;
- const char * copystart;
- uint16_t copysize;
- uint copyoffset;
- struct GNUNET_TIME_Absolute next_send;
-
- 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;
- }
-
- //test if a "hello-beacon" has to be send
- if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0)
- {
- send_hello_beacon(plugin);
- return;
- }
-
- fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages);
-
- if (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 DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n");
-#endif
-
- free_fragment_message(plugin, fm);
- check_fragment_queue(plugin);
-
- }
- else
- {
-
- //if (fm->message_size > WLAN_MTU)
- // {
- size = sizeof(struct FragmentationHeader);
-
- set_next_message_fragment_pos(plugin, fm);
-
- copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader))
- * fm->message_pos;
-
- fragheader.fragment_off_or_num = htons(fm->message_pos);
- fragheader.message_id = htonl(fm->message_id_out);
- copystart = fm->msg + copyoffset;
- copysize = GNUNET_MIN(fm->message_size - copyoffset,
- WLAN_MTU - sizeof(struct FragmentationHeader));
-
-#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, offset %u, time until timeout %u\n",
- fm->message_id_out, fm->message_pos, copysize
- + sizeof(struct FragmentationHeader), copyoffset,
- GNUNET_TIME_absolute_get_remaining(fm->timeout));
-#endif
-
- if (copyoffset >= fm->message_size)
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- "offset in message for fragment too large, offset %u, size %u, max size %u, copysize %u, message_pos %u,\n",
- copyoffset, fm->message_size, WLAN_MTU
- - sizeof(struct FragmentationHeader), copysize,
- fm->message_pos);
- }
- GNUNET_assert(copyoffset < fm->message_size);
-
- fragheader.header.size = htons(copysize
- + sizeof(struct FragmentationHeader));
- fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
-
- size += copysize;
- size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame)
- + sizeof(struct GNUNET_MessageHeader);
- msgheader = GNUNET_malloc(size);
- msgheader->size = htons(size);
- msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
-
- radioHeader = (struct Radiotap_Send*) &msgheader[1];
- getRadiotapHeader(plugin, session, radioHeader);
-
- ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
- getWlanHeader(ieeewlanheader, &(fm->session->addr), plugin, size);
-
- //could be faster if content is just send and not copyed before
- //fragmentheader is needed
- fragheader.message_crc = htons(getcrc16(copystart, copysize));
- memcpy(&ieeewlanheader[1], &fragheader,
- sizeof(struct FragmentationHeader));
- fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1];
- memcpy(&fragheaderptr[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));
-
- }
- GNUNET_assert(bytes != GNUNET_SYSERR);
-
- //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_heap_update_cost(
- plugin->pending_Fragment_Messages, fm->node, MIN(
- fm->timeout.abs_value, fm->next_ack.abs_value));
- // if fragments have opimized timeouts
- //sort_fragment_into_queue(plugin,fm);
-
-
-#if DEBUG_wlan_retransmission
- GNUNET_log(
- GNUNET_ERROR_TYPE_DEBUG,
- "Finished sending all fragments waiting for acks; message_id %u; message_id %u; fragment number %i, size: %u, time until timeout %u\n",
- fm->message_id_out, fm->message_id_out, fm->message_pos,
- fm->message_size, GNUNET_TIME_absolute_get_remaining(
- fm->timeout));
-#endif
- }
- else
- {
- GNUNET_CONTAINER_heap_update_cost(
- plugin->pending_Fragment_Messages, fm->node,
- GNUNET_TIME_absolute_get().abs_value);
- }
-
- 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;
- finish ->next_send = next_send;
-
- 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);
-
- }
- else
- {
- GNUNET_free(msgheader);
- set_next_send(plugin);
- }
-
- }
- return;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "do_transmit did nothing, should not happen!\n");
-}