-finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Finish_send * finish;
- struct Plugin * plugin;
- ssize_t bytes;
-
- finish = cls;
- plugin = finish->plugin;
-
- plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
-
- 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);
- if (bytes != finish->size)
- {
-
- finish->plugin = plugin;
- 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);
- check_next_fragment_timeout(plugin);
- }
-
-}
-
-int
-getRadiotapHeader(struct Plugin * plugin, struct Session * session,
- struct Radiotap_Send * header)
-{
-
- header->rate = session->rate;
- header->tx_power = session->tx_power;
- header->antenna = session->antenna;
- 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 ieee80211_frame * Header, const char * const to_mac_addr,
- struct Plugin * plugin)
-{
- memcpy(&Header->i_addr3, mac_bssid, sizeof(mac_bssid));
- memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address));
- memcpy(&Header->i_addr1, to_mac_addr, sizeof(plugin->mac_address));
- return GNUNET_YES;
-}
-
-/**
- * 32bit CRC
- *
- * @param msgbuf pointer tor the data
- * @param msgbuf_size size of the data
- *
- * @return 32bit crc value
- */
-
-uint32_t
-getcrc32(const char *msgbuf, size_t msgbuf_size)
-{
- //TODO calc some crc
- return 0;
-}
-
-/**
- * 16bit CRC
- *
- * @param msgbuf pointer tor the data
- * @param msgbuf_size size of the data
- *
- * @return 16bit crc value
- */
-
-uint16_t
-getcrc16(const char *msgbuf, size_t msgbuf_size)
-{
- //TODO calc some crc
- return 0;
-}
-
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin.
- *
- * @param cls closure
- * @param target who should receive this message
- * @param priority how important is the message
- * @param msgbuf the message to transmit
- * @param msgbuf_size number of bytes in 'msgbuf'
- * @param timeout when should we time out
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * otherwise the plugin may use other addresses or
- * existing connections (if available)
- * @param cont continuation to call once the message has
- * been transmitted (or if the transport is ready
- * for the next transmission call; or if the
- * peer disconnected...)
- * @param cont_cls closure for cont
- * @return number of bytes used (on the physical network, with overheads);
- * -1 on hard errors (i.e. address invalid); 0 is a legal value
- * 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)
-{
- struct Plugin * plugin = cls;
- struct PendingMessage * newmsg = NULL;
- struct WlanHeader * wlanheader = NULL;
-
- //check if msglen > 0
- GNUNET_assert(msgbuf_size > 0);
-
- //get session if needed
- if (session == NULL)
- {
- if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK)
- {
- session = get_Session(plugin, addr);
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Wlan Address len %d is wrong\n"), addrlen);
- return -1;
- }
- }
-
- //TODO target "problem" not solved
- //if (session->target != NULL){
- // GNUNET_assert(session->target == *target);
- //} else {
- session->target = *target;
- //}
-
-
- //queue message:
-
- //queue message in session
- //test if there is no other message in the "queue"
- //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, queued fragment messages %u\n",
- GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value,
- session->fragment_messages_out_count);
- if (session->pending_message2 != NULL)
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- "wlan_plugin_send: two pending messages are already in the queue for this client\n");
- return -1;
- }
- }
-
- newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
- (newmsg->msg) = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader));
- wlanheader = (struct WlanHeader *) newmsg->msg;
- //copy msg to buffer, not fragmented / segmented yet, but with message header
- wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
- wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
- memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity));
- wlanheader->crc = htonl(getcrc32(msgbuf, msgbuf_size));
- memcpy(&wlanheader[1], msgbuf, msgbuf_size);
- 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);
-
- if (session->pending_message == NULL)
- {
- session->pending_message = newmsg;
- }
- else
- {
- session->pending_message2 = newmsg;
- }
-
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "New message for %p with size (incl wlan header) %u added\n", session,
- newmsg->message_size);
-#endif
-
- //queue session
- queue_Session(plugin, session);
-
- check_fragment_queue(plugin);
- //FIXME not the correct size
- return msgbuf_size;
-
-}
-
-/**
- * function to get the first message in the fragement queue (out) of a session
- * @param session pointer to the session
- * @return pointer to the struct FragmentMessage
- */
-static struct FragmentMessage *
-get_fragment_message_from_session(struct Session * session)