#include "gnunet_common.h"
#define PROTOCOL_PREFIX "wlan"
+
+/**
+ * Max size of packet from helper
+ */
#define WLAN_MTU 3000
#define DEBUG_wlan GNUNET_NO
* To whom are we talking to (set to our identity
* if we are still waiting for the welcome message)
*/
- struct GNUNET_PeerIdentity * target;
+ struct GNUNET_PeerIdentity target;
/**
* encapsulation of the data
*/
const char *msg;
-
/**
* Continuation function to call once the message
* has been sent. Can be NULL if there is no
/**
* Header for messages which need fragmentation
*/
-
-struct FragmentationHeader
+struct WlanHeader
{
+ struct GNUNET_MessageHeader header;
+
/**
- * To whom are we talking to (set to our identity
- * if we are still waiting for the welcome message)
+ * checksum/error correction
*/
- struct GNUNET_PeerIdentity * target GNUNET_PACKED;
+ uint32_t crc GNUNET_PACKED;
/**
- * number of message, to distinguish between the messages
+ * To whom are we talking to (set to our identity
+ * if we are still waiting for the welcome message)
*/
+ struct GNUNET_PeerIdentity target;
+
+ // followed by payload
+
+};
+
+/**
+ * Header for messages which need fragmentation
+ */
+struct FragmentationHeader
+{
- uint16_t message_num GNUNET_PACKED;
+ struct GNUNET_MessageHeader header;
/**
- * number of this fragment, for fragmentation/segmentation
+ * To whom are we talking to (set to our identity
+ * if we are still waiting for the welcome message)
*/
- uint16_t fregment_num GNUNET_PACKED;
-
+ // struct GNUNET_PeerIdentity target GNUNET_PACKED;
/**
- * number of fregments in this message
+ * ID of message, to distinguish between the messages, picked randomly.
*/
- uint16_t ack_message_num GNUNET_PACKED;
+ uint32_t message_id GNUNET_PACKED;
/**
* number of this fragment, for fragmentation/segmentation
*/
- uint16_t ack_fregment_num GNUNET_PACKED;
+ uint16_t fragment_num GNUNET_PACKED;
/**
- * Flags
- * 0x1 ack
- * 0x2 has data (not only ack)
- * 0x4 last fragment of message
- * 0x8 new message
+ * CRC of fragment (for error checking)
*/
+ uint16_t message_crc GNUNET_PACKED;
- uint32_t flags GNUNET_PACKED;
-
+ /**
+ * Flags
+ * // 0x1 ack => Use two different message types in header.type! (FRAG_MESSAGE; FRAG_ACK)
+ * // 0x2 has data (not only ack)
+ * // 0x4 last fragment of message
+ * // 0x8 new message
+ */
+ // uint32_t flags GNUNET_PACKED;
/**
* checksum/error correction
*/
+ // uint32_t crc GNUNET_PACKED;
+
+ // followed by payload unless ACK
- uint32_t crc GNUNET_PACKED;
};
enum { ACK_FRAGMENT = 1, DATA_FRAGMENT = 2, LAST_FRAGMENT = 4, NEW_MESSAGE = 8 };
//TODO add other possibilities to find the right session (are there other?)
static struct Session *
get_Session (struct Plugin *plugin,
- char * addr)
+ const char * addr)
{
struct Sessionqueue * queue = plugin->all_Sessions;
struct Sessionqueue * lastitem = NULL;
while (queue != NULL){
// content is never NULL
GNUNET_assert (queue->content == NULL);
- char * addr2 = (queue->content)->addr;
- if (memcmp(addr, addr2, 6) == 0){
- //sesion found
- return queue->content;
- }
+ char * addr2 = queue->content->addr;
+ if (memcmp(addr, addr2, 6) == 0)
+ {
+ //sesion found
+ return queue->content;
+ }
// try next
lastitem = queue;
queue = queue->next;
}
queue->content = GNUNET_malloc (sizeof (struct Session));
- (queue->content)->plugin = plugin;
- memcpy((queue->content)->addr, addr, 6);
+ queue->content->plugin = plugin;
+ memcpy(queue->content->addr, addr, 6);
//queue welcome
struct WelcomeMessage welcome;
do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin * plugin = cls;
- char * msg;
ssize_t bytes;
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
struct Sessionqueue * queue;
struct PendingMessage * pm;
struct IeeeHeader * wlanheader;
- struct RadiotapHeader * RadioHeader;
+ struct RadiotapHeader * radioHeader;
struct GNUNET_MessageHeader * msgheader;
uint16_t size = 0;
size = pm->message_size + sizeof(struct RadiotapHeader)
+ sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader)
+ sizeof(struct FragmentationHeader);
- msg = GNUNET_malloc(size);
-
- msgheader = msg;
+ msgheader = GNUNET_malloc(size);
msgheader->size = pm->message_size + sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader);
msgheader->type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA;
- RadioHeader = &msgheader[1];
- getRadiotapHeader(RadioHeader);
+ radioHeader = (struct RadiotapHeader*) &msgheader[1];
+ getRadiotapHeader(radioHeader);
- wlanheader = &RadioHeader[1];
+ wlanheader = (struct IeeeHeader *) &radioHeader[1];
getWlanHeader(wlanheader);
- bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msg, size);
+ bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
} else {
//remove message
GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
session->pending_messages_tail,
pm);
- GNUNET_free(pm->msg);
GNUNET_free(pm);
}
*/
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)
+ 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)
{
- int bytes_sent = 0;
- char * msg;
-
struct Plugin * plugin = cls;
-
struct PendingMessage * newmsg = NULL;
//check if msglen > 0
}
//TODO target "problem" not solved
- session->target = target;
+ session->target = *target;
//queue message:
//first queue session
queue_Session(plugin, session);
//queue message in session
- newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
- newmsg->msg = GNUNET_malloc(msgbuf_size);
+ newmsg = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size);
+ newmsg->msg = (const char*) &newmsg[1];
//copy msg to buffer, not fragmented / segmented yet
- memcpy(newmsg->msg, msgbuf, msgbuf_size);
+ memcpy(&newmsg[1], msgbuf, msgbuf_size);
newmsg->transmit_cont = cont;
newmsg->transmit_cont_cls = cont_cls;
newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
static void
-wlan_plugin_helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+wlan_plugin_helper_read (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
- char mybuf[WLAN_MTU]; //max size of packet from helper
+ char mybuf[WLAN_MTU];
ssize_t bytes;
- //memset(&mybuf, 0, sizeof(mybuf)); //?
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
return;
-
- bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, sizeof(mybuf));
-
- if (bytes < 1)
+ bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle,
+ mybuf, sizeof(mybuf));
+ if (bytes <= 0)
{
#if DEBUG_TCP_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
#endif
return;
}
-
- GNUNET_SERVER_mst_receive(plugin->consoltoken,NULL,&mybuf,bytes,0, GNUNET_NO);
+ GNUNET_SERVER_mst_receive(plugin->consoltoken, NULL,
+ mybuf, bytes, 0, GNUNET_NO);
}
wlan_transport_start_wlan_helper(struct Plugin *plugin)
{
- plugin->server_stdout = (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (plugin->server_stdout == NULL)
return GNUNET_SYSERR;
- plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
if (plugin->server_stdin == NULL)
return GNUNET_SYSERR;
typedef unsigned short uint16_t;
/* Wlan IEEE80211 header default */
-static const uint8_t u8aIeeeHeader[] = {
- 0x08, 0x01, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
- 0x10, 0x86,
-};
+static const uint8_t u8aIeeeHeader[] =
+ {
+ 0x08, 0x01, 0x00, 0x00,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
+ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
+ 0x10, 0x86,
+ };
/**
* Wlan header
struct IeeeHeader
{
- /**
- * Wlan flags
- */
- uint8_t flags[4] GNUNET_PACKED;
-
- /**
- * first mac
- */
- uint8_t mac1[6] GNUNET_PACKED;
-
- /**
- * second mac
- */
- uint8_t mac2[6] GNUNET_PACKED;
-
- /**
- * third mac
- */
- uint8_t mac3[6] GNUNET_PACKED;
-
- /**
- * Wlan flags2
- */
- uint8_t flags2[2] GNUNET_PACKED;
+ /**
+ * Wlan flags
+ */
+ uint32_t flags;
+
+ /**
+ * first mac
+ */
+ uint8_t mac1[6];
+
+ /**
+ * second mac
+ */
+ uint8_t mac2[6];
+
+ /**
+ * third mac
+ */
+ uint8_t mac3[6];
+
+ /**
+ * Wlan flags2
+ */
+ uint16_t flags2;
};
/* this is the template radiotap header we send packets out with */
-static const uint8_t u8aRadiotapHeader[] = {
-
- 0x00, 0x00, // <-- radiotap version
- 0x19, 0x00, // <- radiotap header length
- 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
- 0x00, // <-- flags (Offset +0x10)
- 0x6c, // <-- rate (0ffset +0x11)
- 0x71, 0x09, 0xc0, 0x00, // <-- channel
- 0xde, // <-- antsignal
- 0x00, // <-- antnoise
- 0x01, // <-- antenna
-
+static const uint8_t u8aRadiotapHeader[] =
+ {
+ 0x00, 0x00, // <-- radiotap version
+ 0x19, 0x00, // <- radiotap header length
+ 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
+ 0x00, // <-- flags (Offset +0x10)
+ 0x6c, // <-- rate (0ffset +0x11)
+ 0x71, 0x09, 0xc0, 0x00, // <-- channel
+ 0xde, // <-- antsignal
+ 0x00, // <-- antnoise
+ 0x01, // <-- antenna
};
/**
* Radiotap Header
*/
-
struct RadiotapHeader
{
- /**
- * radiotap version
- */
- uint8_t version[2] GNUNET_PACKED;
-
- /**
- * radiotap header length
- */
- uint8_t lenght[2] GNUNET_PACKED;
-
- /**
- * bitmap
- */
- uint8_t bitmap[4] GNUNET_PACKED;
-
- /**
- * timestamp
- */
- uint8_t timestamp[8] GNUNET_PACKED;
-
- /**
- * radiotap flags
- */
- uint8_t flags GNUNET_PACKED;
-
- /**
- * wlan send rate
- */
- uint8_t rate GNUNET_PACKED;
-
- /**
- * Wlan channel
- */
- uint8_t channel[4] GNUNET_PACKED;
-
- /**
- * antsignal
- */
- uint8_t antsignal GNUNET_PACKED;
-
- /**
- * antnoise
- */
- uint8_t antnoise GNUNET_PACKED;
-
- /**
- * antenna
- */
- uint8_t antenna GNUNET_PACKED;
+ /**
+ * radiotap version
+ */
+ uint16_t version GNUNET_PACKED;
+
+ /**
+ * radiotap header length
+ */
+ uint16_t length GNUNET_PACKED;
+
+ /**
+ * bitmap
+ */
+ uint32_t bitmap GNUNET_PACKED;
+
+ /**
+ * timestamp
+ */
+ uint64_t timestamp GNUNET_PACKED;
+
+ /**
+ * radiotap flags
+ */
+ uint8_t flags;
+
+ /**
+ * wlan send rate
+ */
+ uint8_t rate;
+
+ // FIXME: unaligned here, is this OK?
+ /**
+ * Wlan channel
+ */
+ uint32_t channel GNUNET_PACKED;
+
+ /**
+ * antsignal
+ */
+ uint8_t antsignal;
+
+ /**
+ * antnoise
+ */
+ uint8_t antnoise;
+
+ /**
+ * antenna
+ */
+ uint8_t antenna;
};