* gnunet
*/
+/**
+ * parts taken from aircrack-ng, parts changend.
+ */
+
#define _GNU_SOURCE
#include <sys/socket.h>
#include <sys/ioctl.h>
#define MAC_ADDR_SIZE 6
-//Part taken from file ieee80211.h
-/*-
- * Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.12 2006/12/01 18:40:51 imp Exp $
- */
#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
/* see below */
} GNUNET_PACKED;
-// End taken part
-
+/**
+ * struct for storing the information of the hardware
+ */
struct Hardware_Infos
{
+ /**
+ * send buffer
+ */
struct sendbuf write_pout;
+ /**
+ * file descriptor for the raw socket
+ */
int fd_raw;
+
int arptype_in;
/**
getChannelFromFrequency (int frequency);
// FIXME: make nice...
+/**
+ * function to calculate the crc, the start of the calculation
+ * @param buf buffer to calc the crc
+ * @param len len of the buffer
+ * @return crc sum
+ */
static unsigned long
calc_crc_osdep (unsigned char *buf, int len)
{
/* CRC checksum verification routine */
// FIXME: make nice...
-// fixme doxigen
+/**
+ * Function to check crc of the wlan packet
+ * @param buf buffer of the packet
+ * @param len len of the data
+ * @return crc sum of the data
+ */
static int
check_crc_buf_osdep (unsigned char *buf, int len)
{
// FIXME: make nice...
-//fixme doxigen
+/**
+ * function to get the channel of a specific wlan card
+ * @param dev pointer to the dev struct of the card
+ * @return channel number
+ */
static int
linux_get_channel (struct Hardware_Infos *dev)
{
// FIXME: make nice...
-//FIXME doxigen
+/**
+ * function to read from a wlan card
+ * @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
+ * @return size read from the buffer
+ */
static ssize_t
linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */
size_t buf_size, struct Radiotap_rx *ri)
return caplen;
}
-//FIXME doxigen
/**
+ * function to open the device for read/write
+ * @param dev pointer to the device struct
* @return 0 on success
*/
static int
}
/**
+ * function to prepare the helper, e.g. sockets, device...
+ * @param dev struct for the device
+ * @param iface name of the interface
* @return 0 on success
*/
static int
}
-//FIXME: doxigen
+/**
+ * function to process the data from the stdin
+ * @param cls pointer to the device struct
+ * @param client not used
+ * @param hdr pointer to the start of the packet
+ */
static void
stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
}
#if 0
+/**
+ * Function to make test packets with special options
+ * @param buf buffer to write the data to
+ * @param dev device to send the data from
+ * @return size of packet (what should be send)
+ */
static int
maketest (unsigned char *buf, struct Hardware_Infos *dev)
{
/**
- * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin
- * @param buffer pointer to buffer for the message
- * @param mac pointer to the mac address
- * @return number of bytes written
+ * Function to start the hardware for the wlan helper
+ * @param argc number of arguments
+ * @param argv arguments
+ * @return returns one on error
*/
-// FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file)
-/*
-static int
-send_mac_to_plugin (char *buffer, struct MacAddress * mac)
-{
- struct Wlan_Helper_Control_Message macmsg;
-
- macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
- macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- memcpy (macmsg.mac, mac, sizeof (struct MacAddress));
- memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
- return sizeof (struct Wlan_Helper_Control_Message);
-}
-*/
-
-//FIXME: doxigen
static int
hardwaremode (int argc, char *argv[])
{
return 1;
}
+/**
+ * main function of the helper
+ * @param argc number of arguments
+ * @param argv arguments
+ * @return 0 on success, 1 on error
+ */
int
main (int argc, char *argv[])
{
/**
* Return the frequency in Mhz from a channel number
+ * @param channel number of the channel
+ * @return frequency of the channel
*/
int
getFrequencyFromChannel (int channel)
/**
* Return the channel from the frequency (in Mhz)
+ * @param frequency of the channel
+ * @return number of the channel
*/
int
getChannelFromFrequency (int frequency)
+/*
+ This file is part of GNUnet
+ (C) 2011 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 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.
+ */
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#define WLAN_MTU 1500
+/**
+ * @file transport/gnunet_wlan_sender.c
+ * @brief program to send via WLAN as much as possible
+ * @author David Brodski
+ */
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
#include <unistd.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <netpacket/packet.h>
-#include <linux/if_ether.h>
-#include <linux/if.h>
-#include <linux/wireless.h>
-#include <netinet/in.h>
-#include <linux/if_tun.h>
#include <stdio.h>
#include <stdlib.h>
+#include <netinet/in.h>
#include <string.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <dirent.h>
-//#include <sys/utsname.h>
-#include <sys/param.h>
-
#include <time.h>
-
-
#include "gnunet/gnunet_protocols.h"
#include "plugin_transport_wlan.h"
+#define WLAN_MTU 1500
+
/**
* LLC fields for better compatibility
*/
/**
* function to fill the radiotap header
- * @param plugin pointer to the plugin struct
- * @param endpoint pointer to the endpoint
* @param header pointer to the radiotap header
* @return GNUNET_YES at success
*/
/**
* 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
+ * @param to_mac_addr pointer to the address of the recipient
+ * @param mac pointer to the mac address to send from (normally overwritten over by helper)
* @param size size of the whole packet, needed to calculate the time to send the packet
* @return GNUNET_YES if there was no error
*/
Header->llc[0] = WLAN_LLC_DSAP_FIELD;
Header->llc[1] = WLAN_LLC_SSAP_FIELD;
-#if DEBUG_wlan_ip_udp_packets_on_air > 1
- uint crc = 0;
- uint16_t *x;
- int count;
-
- Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
- Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
- Header->ip.ip_v = 4;
- Header->ip.ip_hl = 5;
- Header->ip.ip_p = 17;
- Header->ip.ip_ttl = 1;
- Header->ip.ip_len = htons (size + 8);
- Header->ip.ip_sum = 0;
- x = (uint16_t *) & Header->ip;
- count = sizeof (struct iph);
- while (count > 1)
- {
- /* This is the inner loop */
- crc += (unsigned short) *x++;
- count -= 2;
- }
- /* Add left-over byte, if any */
- if (count > 0)
- crc += *(unsigned char *) x;
- crc = (crc & 0xffff) + (crc >> 16);
- Header->ip.ip_sum = htons (~(unsigned short) crc);
- Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
-
-#endif
-
return GNUNET_YES;
}
int main(int argc, char *argv[]){
struct GNUNET_MessageHeader *msg;
- struct GNUNET_MessageHeader *msg2;
struct ieee80211_frame *wlan_header;
struct Radiotap_Send *radiotap;
+ unsigned int temp[6];
char inmac[6];
char outmac[6];
int pos;
double bytes_per_s;
time_t start;
time_t akt;
+ int i;
if (4 != argc) {
fprintf(
stderr,
"This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n",
__TIMESTAMP__);
- fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "\n");
+ fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
return 1;
}
pid_t pid;
- int rv;
int commpipe[2]; /* This holds the fd for the input & output of the pipe */
/* Setup communication pipeline first */
if(pid){
/* A positive (non-negative) PID indicates the parent process */
- //dup2(commpipe[1],1); /* Replace stdout with out side of the pipe */
close(commpipe[0]); /* Close unused side of pipe (in side) */
setvbuf(stdout,(char*)NULL,_IONBF,0); /* Set non-buffered output on stdout */
- sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &inmac[0],&inmac[1],&inmac[2],&inmac[3],&inmac[4],&inmac[5]);
- sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &outmac[0],&outmac[1],&outmac[2],&outmac[3],&outmac[4],&outmac[5]);
+ sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5]);
+ for (i = 0; i < 6; i++){
+ inmac[i] = temp[i];
+ }
+ sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5]);
+ for (i = 0; i < 6; i++){
+ outmac[i] = temp[i];
+ }
msg = malloc(WLAN_MTU);
msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
}
}
- /*
- sleep(2);
- printf("Hello\n");
- sleep(2);
- printf("Goodbye\n");
- sleep(2);
- printf("exit\n");
- */
- //wait(&rv); /* Wait for child process to end */
- //fprintf(stderr,"Child exited with a %d value\n",rv);
}
else{
/* A zero PID indicates that this is the child process */
close(commpipe[1]); /* Close unused side of pipe (out side) */
/* Replace the child fork with a new process */
if(execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1){
- fprintf(stderr,"execl Error!");
+ fprintf(stderr,"Could not start gnunet-transport-wlan-helper!");
exit(1);
}
}
/*
This file is part of GNUnet
- (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2010 2011 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
(session->mac->fragment_messages_out_count)--;
session->fragment_messages_out_count--;
plugin->pending_Fragment_Messages--;
+ GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
endpoint->sending_messages_tail, fm);
GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
uint16_t size;
#if DEBUG_wlan_retransmission > 1
- GNUNET_loHELLO_BEACON_SCALING_FACTORg_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
fm, fm->session, endpoint, hdr->type);
#endif
session->mac->fragment_messages_out_count++;
session->fragment_messages_out_count++;
plugin->pending_Fragment_Messages++;
+ GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
fm = GNUNET_malloc (sizeof (struct FragmentMessage));
fm->session = session;
* @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
+ * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
*/
static void
wlan_data_helper (void *cls, struct Session_light *session_light,
memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
sizeof (struct MacAddress));
//session_light->session = search_session(plugin,session_light->addr);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messaged for this client received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO);
pos = 0;
while (pos < datasize)
temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
if (ntohs(temp_hdr->size) <= datasize + pos)
{
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messaged inside WLAN_HELPER_DATA received"), 1, GNUNET_NO);
+ 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);
}
else
/*
This file is part of GNUnet
- (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2010, 2011 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
#define has_channel 4
/**
- * struct to represent infos gathered form the radiotap fields
+ * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
*/
struct Radiotap_rx
{
uint32_t ri_present;
+ /**
+ * IEEE80211_RADIOTAP_TSFT
+ */
uint64_t ri_mactime;
+ /**
+ * from radiotap
+ * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL
+ * or IEEE80211_RADIOTAP_DB_ANTSIGNAL
+ */
int32_t ri_power;
+ /**
+ * either IEEE80211_RADIOTAP_DBM_ANTNOISE
+ * or IEEE80211_RADIOTAP_DB_ANTNOISE
+ */
int32_t ri_noise;
+ /**
+ * IEEE80211_RADIOTAP_CHANNEL
+ */
uint32_t ri_channel;
+
uint32_t ri_freq;
+ /**
+ * IEEE80211_RADIOTAP_RATE * 50000
+ */
uint32_t ri_rate;
+ /**
+ * IEEE80211_RADIOTAP_ANTENNA
+ */
uint32_t ri_antenna;
};