-
-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 (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
-
- struct Session * session = NULL;
- struct FragmentMessage * fm = NULL;
- struct ieee80211_frame * ieeewlanheader = NULL;
- struct Radiotap_Send * radioHeader = NULL;
- struct GNUNET_MessageHeader * msgheader = NULL;
-
- 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;
-
- 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 = plugin->pending_Fragment_Messages_head;
- 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
-
- check_fragment_queue(plugin);
- free_fragment_message(plugin, fm);
-
- }
- else
- {
-
- //if (fm->message_size > WLAN_MTU)
- // {
- size += sizeof(struct FragmentationHeader);
-
- set_next_message_fragment_pos(fm);
-
- copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader))
- * fm->message_pos;
-
-#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
-
- 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 (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);
- //FIXME remove later
- GNUNET_assert(copystart < fm->msg + fm->message_size);
-
- fragheader.header.size = htons(copysize
- + sizeof(struct FragmentationHeader));
- fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
-
- /* }
- else
- {
- // there is no need to split
- copystart = fm->msg;
- copysize = fm->message_size;
- }*/
-
- 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);
-
- //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);
- }*/
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- }
-
- }
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "do_transmit did nothing, should not happen!\n");
-}
-