/**
* peer mac address
*/
- uint8_t addr[6];
+ struct MacAddress addr;
};
/**
/**
* peer mac address
*/
- char addr[6];
+ struct MacAddress addr;
/**
* Address of the other peer (either based on our 'connect'
};
-int
-getRadiotapHeader(struct Plugin * plugin, struct Session * session,
- struct Radiotap_Send * Header);
-
-int
-getWlanHeader(struct ieee80211_frame * Header, const char * to_mac_addr,
- struct Plugin * plugin);
-
-static int
-wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen);
-
-uint16_t
-getcrc16(const char *msgbuf, size_t msgbuf_size);
-
-static void
-do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-static void
-check_fragment_queue(struct Plugin * plugin);
-
-uint32_t
-getcrc32(const char *msgbuf, size_t msgbuf_size);
-
-static void
-free_receive_message(struct Plugin* plugin,
- struct Receive_Message_Queue * rx_message);
-
-struct Receive_Message_Queue *
-get_receive_message_from_session(struct Plugin * plugin,
- struct Session * session);
-
-static void
-wlan_data_helper(void *cls, struct Session_light * session_light,
- const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo);
-
static void
-wlan_process_helper(void *cls, void *client,
- const struct GNUNET_MessageHeader *hdr);
-
-static void
-finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-static void
-wlan_data_massage_handler(struct Plugin * plugin,
- struct Session_light * session_light,
- const struct GNUNET_MessageHeader * hdr);
-
-static const char *
-wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen);
+do_transmit(void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
-struct Receive_Message_Queue *
-get_receive_message(struct Plugin * plugin, struct Session * session,
- uint32_t message_id);
-
-static uint64_t
-htonll(uint64_t input)
-{
- return input;
-}
-static uint64_t
-ntohll(uint64_t input)
-{
- return input;
-}
/**
* Sets a bit active in the bitArray. Increment bit-specific
bitArray[arraySlot] |= targetBit;
}
-/**
- * Clears a bit from bitArray. Bit is cleared from the array
- * only if the respective usage counter on the disk hits/is zero.
- *
- * @param bitArray memory area to set the bit in
- * @param bitIdx which bit to unset
- */
-/*static void
- clearBit(char *bitArray, unsigned int bitIdx)
- {
- size_t slot;
- unsigned int targetBit;
-
- slot = bitIdx / 8;
- targetBit = (1L << (bitIdx % 8));
- bitArray[slot] = bitArray[slot] & (~targetBit);
- }*/
/**
* Checks if a bit is active in the bitArray
targetBit = (1L << (bitIdx % 8));
if (bitArray[slot] & targetBit)
return GNUNET_YES;
- else
- return GNUNET_NO;
+ return GNUNET_NO;
}
/**
* get the next message number, at the moment just a random one
* @return returns the next valid message-number for sending packets
*/
-uint32_t
+static uint32_t
get_next_message_id()
{
- return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
+ return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
}
-/**
- * start next message number generator
- * (not necessary at the moment)
- */
-void
-start_next_message_id()
-{
- //GNUNET_CRYPTO_random_init;
-}
/**
* search for a session with the addr
* @param addr pointer to the mac address of the peer
* @return returns the session
*/
-
static struct Session *
-search_session(struct Plugin *plugin, const uint8_t * addr)
+search_session(struct Plugin *plugin,
+ const struct MacAddress *addr)
{
struct Sessionqueue * queue = plugin->sessions;
- struct Sessionqueue * lastitem = NULL;
- //just look at all the session for the needed one
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;
- }
- // try next
- lastitem = queue;
+ if (memcmp(addr, &queue->content->addr, sizeof (struct MacAddress)) == 0)
+ return queue->content; /* session found */
queue = queue->next;
}
return NULL;
*/
static struct Session *
-create_session(struct Plugin *plugin, const uint8_t * addr)
+create_session(struct Plugin *plugin,
+ const struct MacAddress * addr)
{
struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue));
queue->content = GNUNET_malloc (sizeof (struct Session));
queue->content->plugin = plugin;
- memcpy(queue->content->addr, addr, 6);
+ queue->content->addr = *addr;
queue->content->fragment_messages_out_count = 0;
queue->content->fragment_messages_in_count = 0;
return queue->content;
}
+
/**
- * get Session from address, create if no session exists
+ * Get session from address, create if no session exists
*
* @param plugin pointer to the plugin struct
* @param addr pointer to the mac address of the peer
* @return returns the session
*/
-//TODO add other possibilities to find the right session (are there other?)
static struct Session *
-get_Session(struct Plugin *plugin, const uint8_t * addr)
+get_Session (struct Plugin *plugin,
+ const struct MacAddress *addr)
{
struct Session * session = search_session(plugin, addr);
if (session != NULL)
- {
- return session;
- }
- // new session
+ return session;
return create_session(plugin, addr);
-
- /* -- not needed, layer above already has it--
- //queue welcome message for new sessions, not realy needed
- //struct WelcomeMessage welcome;
- struct PendingMessage *pm;
- pm = GNUNET_malloc (sizeof (struct PendingMessage));
- pm->msg = GNUNET_malloc(GNUNET_HELLO_size(* (plugin->env->our_hello)));
- pm->message_size = GNUNET_HELLO_size(* (plugin->env->our_hello));
- //welcome.header.size = htons (GNUNET_HELLO_size(* (plugin->env->our_hello)));
- //welcome.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
- //welcome.clientIdentity = *plugin->env->my_identity;
- memcpy ( (pm->msg), * plugin->env->our_hello, GNUNET_HELLO_size(* (plugin->env->our_hello)));
- pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
- queue->content->pending_message = pm;
- plugin->pendingsessions ++;
- GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions, plugin->pending_Sessions_tail, queue);
-
- check_fragment_queue(plugin);
- */
}
+
/**
* Queue the session to send data
*/
* @param fm use this FragmentMessage
*/
-void
+static void
set_next_message_fragment_pos(struct FragmentMessage * fm)
{
}
-void
+int
+getRadiotapHeader(struct Plugin * plugin, struct Session * session,
+ struct Radiotap_Send * header)
+{
+
+ if (session != NULL)
+ {
+ header->rate = session->rate;
+ header->tx_power = session->tx_power;
+ header->antenna = session->antenna;
+ }
+ else
+ {
+ header->rate = 255;
+ header->tx_power = 0;
+ header->antenna = 0;
+ }
+
+ 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 struct MacAddress * to_mac_addr,
+ struct Plugin * plugin)
+{
+ Header->i_fc[0] = 0x80;
+ Header->i_fc[1] = 0x00;
+ 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;
+}
+
+
+static void
send_hello_beacon(struct Plugin * plugin)
{
radioHeader = (struct Radiotap_Send*) &msgheader[1];
getRadiotapHeader(plugin, NULL, radioHeader);
ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
- getWlanHeader(ieeewlanheader, bc_all_mac, plugin);
+ getWlanHeader(ieeewlanheader, &bc_all_mac, plugin);
msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello))
radioHeader = (struct Radiotap_Send*) &msgheader[1];
getRadiotapHeader(plugin, ack->session, radioHeader);
ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
- getWlanHeader(ieeewlanheader, ack->session->addr, plugin);
+ getWlanHeader(ieeewlanheader, &ack->session->addr, plugin);
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 = htonll(ack->fragments_field);
+ msgheader2->fragment_field = GNUNET_htonll(ack->fragments_field);
bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
if (bytes == GNUNET_SYSERR)
check_next_fragment_timeout(plugin);
}
+static void
+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->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);
+ }
+
+}
+
+
+
/**
* 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)
{
getRadiotapHeader(plugin, session, radioHeader);
ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
- getWlanHeader(ieeewlanheader, fm->session->addr, plugin);
+ getWlanHeader(ieeewlanheader, &fm->session->addr, plugin);
//could be faster if content is just send and not copyed before
//fragmentheader is needed
"do_transmit did nothing, should not happen!\n");
}
-static void
-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);
+/**
+ * Another peer has suggested an address for this
+ * peer and transport plugin. Check that this could be a valid
+ * address. If so, consider adding it to the list
+ * of addresses.
+ *
+ * @param cls closure
+ * @param addr pointer to the address
+ * @param addrlen length of addr
+ * @return GNUNET_OK if this is a plausible address for this peer
+ * and transport
+ */
+static int
+wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
+{
+ //struct Plugin *plugin = cls;
- GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
- if (bytes != finish->size)
- {
+ /* check if the address is plausible; if so,
+ add it to our list! */
- 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_assert(cls !=NULL);
+ //FIXME mitm is not checked
+ //Mac Address has 6 bytes
+ if (addrlen == 6)
{
- GNUNET_free(finish->msgstart);
- GNUNET_free(finish);
- check_next_fragment_timeout(plugin);
+ /* TODO check for bad addresses like multicast, broadcast, etc */
+ return GNUNET_OK;
}
+ return GNUNET_SYSERR;
}
-int
-getRadiotapHeader(struct Plugin * plugin, struct Session * session,
- struct Radiotap_Send * header)
-{
-
- if (session != NULL)
- {
- header->rate = session->rate;
- header->tx_power = session->tx_power;
- header->antenna = session->antenna;
- }
- else
- {
- header->rate = 255;
- header->tx_power = 0;
- header->antenna = 0;
- }
- 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)
-{
- Header->i_fc[0] = 0x80;
- Header->i_fc[1] = 0x00;
- 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
return NULL;
}
+
+/**
+ * function to get the receive message of a session
+ * @param plugin pointer to the plugin struct
+ * @param session session this fragment belongs to
+ */
+struct Receive_Message_Queue *
+get_receive_message_from_session(struct Plugin * plugin,
+ struct Session * session)
+{
+ struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
+ while (rec_message != NULL)
+ {
+ if (rec_message->session == session)
+ {
+ return rec_message;
+ }
+ rec_message = rec_message->next;
+ }
+ return NULL;
+}
+
+
+/**
+ * Function to dispose the fragments received for a message and the message
+ * @param plugin pointer to the plugin struct
+ * @param rec_message pointer to the struct holding the message which should be freed
+ */
+static void
+free_receive_message(struct Plugin* plugin,
+ struct Receive_Message_Queue * rx_message)
+{
+ GNUNET_assert(rx_message !=NULL);
+ struct Receive_Fragment_Queue * rec_queue = rx_message->frag_head;
+ struct Receive_Fragment_Queue * rec_queue2;
+
+ while (rec_queue != NULL)
+ {
+ rec_queue2 = rec_queue;
+ rec_queue = rec_queue->next;
+ GNUNET_free(rec_queue2);
+ }
+
+ GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message);
+
+ GNUNET_assert(plugin->pending_receive_messages > 0);
+ GNUNET_assert(rx_message->session->fragment_messages_in_count > 0);
+
+ plugin->pending_receive_messages--;
+ rx_message->session->fragment_messages_in_count--;
+ GNUNET_free(rx_message);
+}
+
+
/**
* Function that can be used to force the plugin to disconnect
* from the given peer and cancel all previous transmissions
asc(asc_cls, ret);
}
-/**
- * Another peer has suggested an address for this
- * peer and transport plugin. Check that this could be a valid
- * address. If so, consider adding it to the list
- * of addresses.
- *
- * @param cls closure
- * @param addr pointer to the address
- * @param addrlen length of addr
- * @return GNUNET_OK if this is a plausible address for this peer
- * and transport
- */
-static int
-wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
-{
- //struct Plugin *plugin = cls;
-
- /* check if the address is plausible; if so,
- add it to our list! */
-
- GNUNET_assert(cls !=NULL);
- //FIXME mitm is not checked
- //Mac Address has 6 bytes
- if (addrlen == 6)
- {
- /* TODO check for bad addresses like multicast, broadcast, etc */
- return GNUNET_OK;
- }
-
- return GNUNET_SYSERR;
-}
/**
* Function called for a quick conversion of the binary address to
setBit((char *) &rx_message->received_fragments, rx_frag->num);
}
-/**
- * Function to dispose the fragments received for a message and the message
- * @param plugin pointer to the plugin struct
- * @param rec_message pointer to the struct holding the message which should be freed
- */
-
-static void
-free_receive_message(struct Plugin* plugin,
- struct Receive_Message_Queue * rx_message)
-{
- GNUNET_assert(rx_message !=NULL);
- struct Receive_Fragment_Queue * rec_queue = rx_message->frag_head;
- struct Receive_Fragment_Queue * rec_queue2;
-
- while (rec_queue != NULL)
- {
- rec_queue2 = rec_queue;
- rec_queue = rec_queue->next;
- GNUNET_free(rec_queue2);
- }
-
- GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message);
-
- GNUNET_assert(plugin->pending_receive_messages > 0);
- GNUNET_assert(rx_message->session->fragment_messages_in_count > 0);
-
- plugin->pending_receive_messages--;
- rx_message->session->fragment_messages_in_count--;
- GNUNET_free(rx_message);
-}
-
-/**
- * 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_rec_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 = 0;
- int aktnum = 0;
- 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 DEBUG_wlan
- check_message_fragment_bitfield(rx_message);
-#endif
-
- // 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)
- {
-
- 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 use mst
- //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;
- }
-
- free_receive_message(plugin, rx_message);
- //call wlan_process_helper to process the message
- wlan_data_massage_handler(plugin, session_light,
- (struct GNUNET_MessageHeader*) msg);
- //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
-
- GNUNET_free(msg);
- }
- }
- // }
-}
-
-static void
-process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
-{
- GNUNET_assert(client != NULL);
- GNUNET_assert(cls != NULL);
- struct Session * session = (struct Session *) client;
- struct Plugin * plugin = (struct Plugin *) cls;
- struct GNUNET_TRANSPORT_ATS_Information distance[2];
- distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
- distance[0].value = htonl(1);
- distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- distance[1].value = htonl(0);
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
- wlan_plugin_address_to_string(NULL, session->addr, 6), htons(hdr->size));
-#endif
-
- plugin->env->receive(plugin->env->cls, &(session->target), hdr,
- (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
- session->addr, sizeof(session->addr));
-}
/**
* handels the data after all fragments are put together
GNUNET_assert(session_light != NULL);
if (session_light->session == NULL)
{
- session_light->session = search_session(plugin, session_light->addr);
+ session_light->session = search_session(plugin, &session_light->addr);
}
session = session_light->session;
wlanheader = (struct WlanHeader *) hdr;
(const struct GNUNET_HELLO_Message *) temp_hdr,
&tmptarget) == GNUNET_OK)
{
- session = create_session(plugin, session_light->addr);
+ session = create_session(plugin, &session_light->addr);
session_light->session = session;
memcpy(&session->target, &tmptarget,
sizeof(struct GNUNET_PeerIdentity));
}
}
+
+
+/**
+ * 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_rec_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 = 0;
+ int aktnum = 0;
+ 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 DEBUG_wlan
+ check_message_fragment_bitfield(rx_message);
+#endif
+
+ // 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)
+ {
+
+ 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 use mst
+ //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;
+ }
+
+ free_receive_message(plugin, rx_message);
+ //call wlan_process_helper to process the message
+ wlan_data_massage_handler(plugin, session_light,
+ (struct GNUNET_MessageHeader*) msg);
+ //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
+
+ GNUNET_free(msg);
+ }
+ }
+ // }
+}
+
+static void
+process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+{
+
+ GNUNET_assert(client != NULL);
+ GNUNET_assert(cls != NULL);
+ struct Session * session = (struct Session *) client;
+ struct Plugin * plugin = (struct Plugin *) cls;
+
+ struct GNUNET_TRANSPORT_ATS_Information distance[2];
+ distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ distance[0].value = htonl(1);
+ distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ distance[1].value = htonl(0);
+
+#if DEBUG_wlan
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
+ wlan_plugin_address_to_string(NULL, session->addr, 6), htons(hdr->size));
+#endif
+
+ plugin->env->receive(plugin->env->cls, &(session->target), hdr,
+ (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
+ (const char*) &session->addr, sizeof(session->addr));
+}
+
/**
* function to add an ack to send it for a received fragment
* @param plugin pointer to the global plugin structure
return NULL;
}
-/**
- * function to get the receive message of a session
- * @param plugin pointer to the plugin struct
- * @param session session this fragment belongs to
- */
-struct Receive_Message_Queue *
-get_receive_message_from_session(struct Plugin * plugin,
- struct Session * session)
-{
- struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
- while (rec_message != NULL)
- {
- if (rec_message->session == session)
- {
- return rec_message;
- }
- rec_message = rec_message->next;
- }
- return NULL;
-}
/**
* function to insert a received fragment into the right fragment queue of the right message
if (session_light->session == NULL)
{
- session_light->session = get_Session(plugin, session_light->addr);
+ session_light->session = get_Session(plugin, &session_light->addr);
}
GNUNET_assert(GNUNET_HELLO_get_id(
(const struct GNUNET_HELLO_Message *) &hdr[1],
GNUNET_assert(session_light != NULL);
if (session_light->session == NULL)
{
- session_light->session = search_session(plugin, session_light->addr);
+ session_light->session = search_session(plugin, &session_light->addr);
}
session = session_light->session;
GNUNET_assert(session_light != NULL);
if (session_light->session == NULL)
{
- session_light->session = search_session(plugin, session_light->addr);
+ session_light->session = search_session(plugin, &session_light->addr);
GNUNET_assert(session_light->session != NULL);
}
session = session_light->session;
if (fm != NULL)
{
- fm->ack_bitfield = fm->ack_bitfield | ntohll(fah->fragment_field);
+ fm->ack_bitfield = fm->ack_bitfield | GNUNET_ntohll(fah->fragment_field);
check_finished_fragment(plugin, fm);
}
else
//process only if it is an broadcast or for this computer both with the gnunet bssid
//check for bssid
- if (memcmp(&(wlanIeeeHeader->i_addr3), mac_bssid, sizeof(struct MacAddress))
+ if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, sizeof(struct MacAddress))
== 0)
{
//check for broadcast or mac
- if (memcmp(&(wlanIeeeHeader->i_addr1), bc_all_mac,
+ if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac,
sizeof(struct MacAddress) == 0) || memcmp(
&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
sizeof(struct MacAddress)) == 0)
- sizeof(struct Radiotap_rx);
session_light = GNUNET_malloc(sizeof(struct Session_light));
- memcpy(session_light->addr, &(wlanIeeeHeader->i_addr2),
- sizeof(struct MacAddress));
+ memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2),
+ sizeof(struct MacAddress));
//session_light->session = search_session(plugin,session_light->addr);
pos = 0;
wlan_transport_start_wlan_helper(plugin, testmode);
- start_next_message_id();
-
#if DEBUG_wlan
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "wlan init finished\n");
#endif