From c307dc2bda434d1243422a6a102ac5dbb6fa00a2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 16 Mar 2012 15:33:26 +0000 Subject: -more cleanup for #1939 --- src/transport/gnunet-helper-transport-wlan-dummy.c | 56 ++-- src/transport/gnunet-helper-transport-wlan.c | 68 +++-- src/transport/plugin_transport_wlan.c | 283 +++++++-------------- src/transport/plugin_transport_wlan.h | 78 +++--- 4 files changed, 189 insertions(+), 296 deletions(-) (limited to 'src') diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index 3f17b04dd..cd545af65 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c @@ -77,49 +77,35 @@ static void stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct sendbuf *write_pout = cls; - int sendsize; - struct GNUNET_MessageHeader newheader; - char *to_data; - char *to_radiotap; - char *to_start; + const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; + size_t payload_size; + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; - sendsize = - ntohs (hdr->size) - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + - sizeof (struct Radiotap_rx) + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + - sizeof (struct GNUNET_MessageHeader); - - if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) + in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; + if ( (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) || + (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) < ntohs (hdr->size)) ) { - fprintf (stderr, "Function stdin_send: wrong packet type\n"); + fprintf (stderr, "Function stdin_send: wrong packet type or size\n"); exit (1); } - if ((sendsize + write_pout->size) > MAXLINE * 2) + payload_size = ntohs (hdr->size) - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); + if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) { fprintf (stderr, "Function stdin_send: Packet too big for buffer\n"); exit (1); } - - newheader.size = htons (sendsize); - newheader.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); - - to_start = write_pout->buf + write_pout->size; - memcpy (to_start, &newheader, sizeof (struct GNUNET_MessageHeader)); - write_pout->size += sizeof (struct GNUNET_MessageHeader); - - to_radiotap = to_start + sizeof (struct GNUNET_MessageHeader); - memset (to_radiotap, 0, sizeof (struct Radiotap_rx)); - write_pout->size += sizeof (struct Radiotap_rx); - - to_data = to_radiotap + sizeof (struct Radiotap_rx); - memcpy (to_data, - ((char *) hdr) + - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - - - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), - ntohs (hdr->size) - (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame))); - write_pout->size += - ntohs (hdr->size) - (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); + memset (&newheader, 0, sizeof (newheader)); + newheader.header.size = htons (payload_size + sizeof (newheader)); + newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); + newheader.frame = in->frame; + memcpy (write_pout->buf + write_pout->size, + &newheader, + sizeof (newheader)); + write_pout->size += sizeof (newheader); + memcpy (write_pout->buf + write_pout->size, + &in[1], + payload_size); + write_pout->size += payload_size; } diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c index 51b9ba32d..2ed81a24d 100644 --- a/src/transport/gnunet-helper-transport-wlan.c +++ b/src/transport/gnunet-helper-transport-wlan.c @@ -70,10 +70,10 @@ * Modifications to fit into the linux IEEE 802.11 stack, * Mike Kershaw (dragorn@kismetwireless.net) */ - -/** +/* * parts taken from aircrack-ng, parts changend. */ + #define _GNU_SOURCE #include #include @@ -106,10 +106,6 @@ #define ARPHRD_IEEE80211_PRISM 802 #define ARPHRD_IEEE80211_FULL 803 -/** - * size of 802.11 address - */ -#define IEEE80211_ADDR_LEN 6 /** * Maximum size of a message allowed in either direction. @@ -368,18 +364,6 @@ struct SendBuffer char buf[MAXLINE * 2]; }; -/** - * Buffer for data read from stdin to be transmitted to the wirless card. - */ -static struct SendBuffer write_pout; - -/** - * Buffer for data read from the wireless card to be transmitted to stdout. - */ -static struct SendBuffer write_std; - - - /** * struct for storing the information of the hardware @@ -458,6 +442,17 @@ struct ieee80211_radiotap_iterator }; +/** + * Buffer for data read from stdin to be transmitted to the wirless card. + */ +static struct SendBuffer write_pout; + +/** + * Buffer for data read from the wireless card to be transmitted to stdout. + */ +static struct SendBuffer write_std; + + /* specialized version of server_mst.c begins here */ @@ -520,7 +515,6 @@ struct MessageStreamTokenizer }; - /** * Create a message stream tokenizer. * @@ -1095,12 +1089,13 @@ linux_get_channel (const struct HardwareInfos *dev) * @param dev pointer to the struct of the wlan card * @param buf buffer to read to * @param buf_size size of the buffer - * @param ri radiotap_rx info + * @param ri where to write radiotap_rx info * @return size read from the buffer */ static ssize_t -linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size, - struct Radiotap_rx *ri) +linux_read (struct HardwareInfos *dev, + unsigned char *buf, size_t buf_size, + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) { unsigned char tmpbuf[buf_size]; ssize_t caplen; @@ -1701,33 +1696,30 @@ main (int argc, char *argv[]) if (FD_ISSET (dev.fd_raw, &rfds)) { - struct GNUNET_MessageHeader *header; - struct Radiotap_rx *rxinfo; - struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *datastart; + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; ssize_t ret; - header = (struct GNUNET_MessageHeader *) write_std.buf; - rxinfo = (struct Radiotap_rx *) &header[1]; - datastart = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &rxinfo[1]; + rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf; ret = - linux_read (&dev, (unsigned char *) datastart, - sizeof (write_std.buf) - sizeof (struct Radiotap_rx) - - sizeof (struct GNUNET_MessageHeader), rxinfo); + linux_read (&dev, (unsigned char *) &rrm->frame, + sizeof (write_std.buf) + - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), + rrm); if (0 > ret) { fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno)); break; } - if ((0 < ret) && (0 == mac_test (datastart, &dev))) + if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev))) { - write_std.size = - ret + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct Radiotap_rx); - header->size = htons (write_std.size); - header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); + write_std.size = ret + + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); + rrm->header.size = htons (write_std.size); + rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); } } - } /* Error handling, try to clean up a bit at least */ mst_destroy (stdin_mst); diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 1dc2713ed..7b709ce9d 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1,27 +1,28 @@ /* - This file is part of GNUnet - (C) 2010 2011 Christian Grothoff (and other contributing authors) + This file is part of GNUnet + (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors) - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ /** * @file transport/plugin_transport_wlan.c * @brief transport plugin for wlan * @author David Brodski + * @author Christian Grothoff */ //TODO split rx and tx structures for better handling @@ -294,7 +295,7 @@ struct Finish_send /** * Queue of sessions, for the general session queue and the pending session queue */ -//TODO DOXIGEN +//TODO DOXYGEN struct Sessionqueue { struct Sessionqueue *next; @@ -305,10 +306,11 @@ struct Sessionqueue #endif }; + /** * Queue of fragmented messages, for the sending queue of the plugin */ -//TODO DOXIGEN +//TODO DOXYGEN struct FragmentMessage_queue { struct FragmentMessage_queue *next; @@ -316,21 +318,24 @@ struct FragmentMessage_queue struct FragmentMessage *content; }; + /** * Queue for the fragments received */ -//TODO DOXIGEN +//TODO DOXYGEN struct Receive_Fragment_Queue { struct Receive_Fragment_Queue *next; struct Receive_Fragment_Queue *prev; + uint16_t num; - const char *msg; - uint16_t size; - struct Radiotap_rx rxinfo; + // const char *msg; + // uint16_t size; + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rx_msg; }; -//TODO DOXIGEN + +//TODO DOXYGEN struct MacEndpoint_id_fragment_triple { struct MacEndpoint *endpoint; @@ -338,7 +343,7 @@ struct MacEndpoint_id_fragment_triple struct FragmentMessage *fm; }; -//TODO DOXIGEN +//TODO DOXYGEN struct Plugin_Session_pair { struct Plugin *plugin; @@ -354,6 +359,9 @@ GNUNET_NETWORK_STRUCT_BEGIN struct WlanHeader { + /** + * Message type is GNUNET_MESSAGE_TYPE_WLAN_DATA. + */ struct GNUNET_MessageHeader header; /** @@ -456,26 +464,6 @@ struct AckSendQueue }; -/** - * Session infos gathered from a messages - */ -struct Session_light -{ - /** - * the session this message belongs to - */ - struct Session *session; - /** - * peer mac address - */ - struct GNUNET_TRANSPORT_WLAN_MacAddress addr; - - /** - * mac endpoint - */ - struct MacEndpoint *macendpoint; -}; - /** * Session handle for connections. */ @@ -592,7 +580,7 @@ struct MacEndpoint */ int fragment_messages_out_count; - //TODO DOXIGEN + //TODO DOXYGEN uint8_t rate; uint16_t tx_power; uint8_t antenna; @@ -2573,132 +2561,82 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) * Function used for to process the data received from the wlan interface * * @param cls the plugin handle - * @param session_light pointer to the struct holding known informations * @param hdr hdr of the GNUNET_MessageHeader - * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info + * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS info */ static void -wlan_data_helper (void *cls, struct Session_light *session_light, +wlan_data_helper (void *cls, const struct GNUNET_MessageHeader *hdr, - const struct Radiotap_rx *rxinfo) + const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo) { struct Plugin *plugin = cls; struct FragmentMessage *fm; struct FragmentMessage *fm2; struct GNUNET_PeerIdentity tmpsource; + struct MacEndpoint *macendpoint; + struct Session *session; - GNUNET_assert (plugin != NULL); + // NOTE: session_light->addr = rxinfo->frame.addr2; + macendpoint = get_macendpoint (plugin, &rxinfo->frame.addr2, GNUNET_YES); - //ADVERTISEMENT - if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) + switch (ntohs (hdr->type)) { - + case GNUNET_MESSAGE_TYPE_HELLO: + //ADVERTISEMENT //TODO better DOS protection, error handling - //TODO test first than create session - GNUNET_assert (session_light != NULL); - - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n", - ntohs (hdr->size), wlan_plugin_address_to_string (NULL, - session_light->addr. - mac, 6)); - if (session_light->macendpoint == NULL) - { - session_light->macendpoint = - get_macendpoint (plugin, &session_light->addr, GNUNET_YES); - } - - + //TODO test first then create session if (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK) { - session_light->session = - search_session (plugin, session_light->macendpoint, &tmpsource); - if (session_light->session == NULL) + session = search_session (plugin, macendpoint, &tmpsource); + if (session == NULL) { - session_light->session = - create_session (plugin, session_light->macendpoint, &tmpsource); + session = create_session (plugin, macendpoint, &tmpsource); } GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello messages received"), 1, GNUNET_NO); - plugin->env->receive (plugin->env->cls, &session_light->session->target, - hdr, NULL, 0, session_light->session, - (const char *) &session_light->session->mac->addr, - sizeof (session_light->session->mac->addr)); + plugin->env->receive (plugin->env->cls, &session->target, + hdr, NULL, 0, session, + (const char *) &session->mac->addr, + sizeof (session->mac->addr)); } else { GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, - "WLAN client not in session list and hello message is not okay\n"); + "WLAN client not in session list and HELLO message is not okay\n"); return; } - } - - //FRAGMENT - - else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT) - { - - GNUNET_assert (session_light != NULL); - if (session_light->macendpoint == NULL) - { - session_light->macendpoint = - get_macendpoint (plugin, &session_light->addr, GNUNET_YES); - } - - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n", - ntohs (hdr->size), session_light->macendpoint, - wlan_plugin_address_to_string (NULL, - session_light->addr.mac, - 6)); + break; + case GNUNET_MESSAGE_TYPE_FRAGMENT: + macendpoint = get_macendpoint (plugin, &rxinfo->frame.addr2, GNUNET_YES); GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments received"), 1, GNUNET_NO); int ret = - GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag, + GNUNET_DEFRAGMENT_process_fragment (macendpoint->defrag, hdr); if (ret == GNUNET_NO) { - session_light->macendpoint->dups++; + macendpoint->dups++; } else if (ret == GNUNET_OK) { - session_light->macendpoint->fragc++; + macendpoint->fragc++; } set_next_send (plugin); - - } - - //ACK - - else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK) - { - GNUNET_assert (session_light != NULL); - if (session_light->macendpoint == NULL) - { - session_light->macendpoint = - get_macendpoint (plugin, &session_light->addr, GNUNET_NO); - } - - if (session_light->macendpoint == NULL) + break; + case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK: + if (NULL == macendpoint) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n", ntohs (hdr->size), wlan_plugin_address_to_string (NULL, - session_light->addr.mac, + &rxinfo->frame.addr2.mac, 6)); return; } - - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n", - ntohs (hdr->size), session_light->macendpoint, - wlan_plugin_address_to_string (NULL, - session_light->addr.mac, - 6)); - fm = session_light->macendpoint->sending_messages_head; + fm = macendpoint->sending_messages_head; while (fm != NULL) { fm2 = fm->next; @@ -2710,9 +2648,9 @@ wlan_data_helper (void *cls, struct Session_light *session_light, { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Got last ack, finished fragment message %p\n", fm); - session_light->macendpoint->acks++; + macendpoint->acks++; fm->session->last_activity = GNUNET_TIME_absolute_get (); - session_light->macendpoint->last_activity = fm->session->last_activity; + macendpoint->last_activity = fm->session->last_activity; free_fragment_message (plugin, fm); check_fragment_queue (plugin); return; @@ -2721,24 +2659,15 @@ wlan_data_helper (void *cls, struct Session_light *session_light, { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Got ack for: %p\n", fm); - session_light->macendpoint->acks++; + macendpoint->acks++; return; } - if (ret == GNUNET_SYSERR) - { - - } - fm = fm2; } - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "WLAN fragment not in fragment list\n"); return; - - } - else - { + default: // TODO Wrong data? GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", @@ -2746,12 +2675,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light, GNUNET_break (0); return; } - -#if 0 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Helper finished\n"); -#endif - } /** @@ -2853,11 +2778,10 @@ wlan_process_helper (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; - const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *wlanIeeeHeader; - struct Session_light *session_light = NULL; - const struct Radiotap_rx *rxinfo; + const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; + const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; const struct GNUNET_MessageHeader *temp_hdr = NULL; - + const char *end; int datasize = 0; int pos; @@ -2872,96 +2796,79 @@ wlan_process_helper (void *cls, void *client, _("# wlan WLAN_HELPER_DATA received"), 1, GNUNET_NO); //call wlan_process_helper with the message inside, later with wlan: analyze signal - if (ntohs (hdr->size) < - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + - 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx)) + if (ntohs (hdr->size) < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, - "Size of packet is too small; size: %u min size: %u\n", - ntohs (hdr->size), - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + - sizeof (struct GNUNET_MessageHeader)); - //GNUNET_break (0); + "Size of packet is too small; size: %u\n", + ntohs (hdr->size)); + GNUNET_break (0); /* FIXME: restart SUID process */ return; } - rxinfo = (const struct Radiotap_rx *) &hdr[1]; - wlanIeeeHeader = (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &rxinfo[1]; - + rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr; //process only if it is an broadcast or for this computer both with the gnunet bssid - //check for bssid if (memcmp - (&wlanIeeeHeader->addr3, &mac_bssid_gnunet, + (&rxinfo->frame.addr3, &mac_bssid_gnunet, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) { //check for broadcast or mac if ((memcmp - (&wlanIeeeHeader->addr1, &bc_all_mac, + (&rxinfo->frame.addr1, &bc_all_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) || (memcmp - (&wlanIeeeHeader->addr1, &(plugin->mac_address), + (&rxinfo->frame.addr1, &plugin->mac_address, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)) { //if packet is from us return if ((memcmp - (&wlanIeeeHeader->addr2, &(plugin->mac_address), + (&rxinfo->frame.addr2, &plugin->mac_address, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)) { + /* not for us */ return; } - // process the inner data - - - datasize = - ntohs (hdr->size) - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) - - sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx); - - session_light = GNUNET_malloc (sizeof (struct Session_light)); - session_light->addr = wlanIeeeHeader->addr2; - //session_light->session = search_session(plugin,session_light->addr); + datasize = ntohs (hdr->size) - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage); GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO); - + // FIXME: this is a job for SERVER_mst -- + // what we are doing here is not good for alignment... pos = 0; - while (pos < datasize) + end = (const char*) &rxinfo[1]; + while (pos < datasize - sizeof (struct GNUNET_MessageHeader)) { - temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos; - if (ntohs (temp_hdr->size) <= datasize + pos) + temp_hdr = (struct GNUNET_MessageHeader *) &end[pos]; + if (ntohs (temp_hdr->size) <= datasize - pos) { GNUNET_STATISTICS_update (plugin->env->stats, _ ("# wlan messages inside WLAN_HELPER_DATA received"), 1, GNUNET_NO); - wlan_data_helper (plugin, session_light, temp_hdr, rxinfo); + wlan_data_helper (plugin, temp_hdr, rxinfo); } else { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Size of packet is too small; size: %u > size of packet: %u\n", - ntohs (temp_hdr->size), datasize + pos); + ntohs (temp_hdr->size), datasize - pos); } pos += ntohs (temp_hdr->size); - } - - //clean up - GNUNET_free (session_light); } else { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Func wlan_process_helper got wrong MAC: %s\n", - macprinter (&wlanIeeeHeader->addr1)); + macprinter (&rxinfo->frame.addr1)); } } else { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Func wlan_process_helper got wrong BSSID: %s\n", - macprinter (&wlanIeeeHeader->addr2)); + macprinter (&rxinfo->frame.addr2)); } break; case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: @@ -2972,7 +2879,8 @@ wlan_process_helper (void *cls, void *client, /* FIXME: restart SUID process */ return; } - memcpy (&plugin->mac_address, &hdr[1], sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); + cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr; + plugin->mac_address = cm->mac; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Received WLAN_HELPER_CONTROL message with transport of address %s\n", wlan_plugin_address_to_string (cls, &plugin->mac_address, @@ -2985,10 +2893,6 @@ wlan_process_helper (void *cls, void *client, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Func wlan_process_helper got unknown message with number %u, size %u\n", ntohs (hdr->type), ntohs (hdr->size)); - -#if DEBUG_WLAN > 1 - hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256)); -#endif GNUNET_break (0); return; } @@ -3000,7 +2904,6 @@ wlan_process_helper (void *cls, void *client, * Exit point from the plugin. * @param cls pointer to the api struct */ - //FIXME cleanup void * libgnunet_plugin_transport_wlan_done (void *cls) @@ -3029,8 +2932,6 @@ libgnunet_plugin_transport_wlan_done (void *cls) endpoint = endpoint_next; } - - if (plugin->suid_tokenizer != NULL) GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer); diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h index c220c829d..3f8e82404 100644 --- a/src/transport/plugin_transport_wlan.h +++ b/src/transport/plugin_transport_wlan.h @@ -35,6 +35,7 @@ #define MAC_ADDR_SIZE 6 GNUNET_NETWORK_STRUCT_BEGIN + /** * A MAC Address. */ @@ -59,24 +60,7 @@ struct GNUNET_TRANSPORT_WLAN_HelperControlMessage */ struct GNUNET_TRANSPORT_WLAN_MacAddress mac; }; -GNUNET_NETWORK_STRUCT_END - -/** - * GNUnet bssid - */ -static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = { - {0x13, 0x22, 0x33, 0x44, 0x55, 0x66} -}; - - -/** - * Broadcast MAC - */ -static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = { - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} -}; -GNUNET_NETWORK_STRUCT_BEGIN /** * generic definitions for IEEE 802.11 frames @@ -86,12 +70,12 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame /** * 802.11 Frame Control field, */ - uint16_t frame_control; + uint16_t frame_control GNUNET_PACKED; /** * Microseconds to reserve link (duration), 0 by default */ - uint16_t duration; + uint16_t duration GNUNET_PACKED; /** * Address 1: destination address in ad-hoc mode or AP, BSSID if station, @@ -111,7 +95,7 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame /** * 802.11 sequence control field. */ - uint16_t sequence_control; + uint16_t sequence_control GNUNET_PACKED; /** * Link layer control (LLC). Set to a GNUnet-specific value. @@ -150,7 +134,7 @@ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage * Transmit power expressed as unitless distance from max power set at factory calibration. * 0 is max power. Monotonically nondecreasing with lower power levels. */ - uint16_t tx_power; + uint16_t tx_power GNUNET_PACKED; /** * IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not @@ -161,59 +145,89 @@ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage /* actual payload follows */ }; -GNUNET_NETWORK_STRUCT_END - +/** + * Message from the WLAN helper to the plugin: we have received the given message with the + * given performance characteristics. + */ /** * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos */ -struct Radiotap_rx +struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage { + + /** + * Type is 'GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA'. + */ + struct GNUNET_MessageHeader header; + /** * FIXME: not initialized properly so far. (supposed to contain * information about which of the fields below are actually valid). */ - uint32_t ri_present; + uint32_t ri_present GNUNET_PACKED; /** * IEEE80211_RADIOTAP_TSFT */ - uint64_t ri_mactime; + uint64_t ri_mactime GNUNET_PACKED; /** * from radiotap * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL * or IEEE80211_RADIOTAP_DB_ANTSIGNAL */ - int32_t ri_power; + int32_t ri_power GNUNET_PACKED; /** * either IEEE80211_RADIOTAP_DBM_ANTNOISE * or IEEE80211_RADIOTAP_DB_ANTNOISE */ - int32_t ri_noise; + int32_t ri_noise GNUNET_PACKED; /** * IEEE80211_RADIOTAP_CHANNEL */ - uint32_t ri_channel; + uint32_t ri_channel GNUNET_PACKED; /** * Frequency we use. FIXME: not properly initialized so far! */ - uint32_t ri_freq; + uint32_t ri_freq GNUNET_PACKED; /** * IEEE80211_RADIOTAP_RATE * 50000 */ - uint32_t ri_rate; + uint32_t ri_rate GNUNET_PACKED; /** * IEEE80211_RADIOTAP_ANTENNA */ - uint32_t ri_antenna; + uint32_t ri_antenna GNUNET_PACKED; + + /** + * IEEE Frame. + */ + struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame; + + /* followed by payload */ +}; + +GNUNET_NETWORK_STRUCT_END + +/** + * GNUnet bssid + */ +static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = { + {0x13, 0x22, 0x33, 0x44, 0x55, 0x66} }; +/** + * Broadcast MAC + */ +static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = { + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} +}; #endif -- cgit v1.2.3