Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/**
+ * @file src/transport/gnunet-helper-transport-wlan.c
+ * @brief wlan layer two server; must run as root (SUID will do)
+ * This code will work under GNU/Linux only.
+ * @author David Brodski
+ *
+ * This program serves as the mediator between the wlan interface and
+ * gnunet
+ */
+
/*-
* we use our local copy of ieee80211_radiotap.h
*
* Mike Kershaw (dragorn@kismetwireless.net)
*/
-/**
- * @file src/transport/gnunet-helper-transport-wlan.c
- * @brief wlan layer two server; must run as root (SUID will do)
- * This code will work under GNU/Linux only.
- * @author David Brodski
- *
- * This program serves as the mediator between the wlan interface and
- * gnunet
- */
-
/**
* parts taken from aircrack-ng, parts changend.
*/
*/
#define IEEE80211_ADDR_LEN 6
+/**
+ * Maximum size of a message allowed in either direction.
+ */
#define MAXLINE 4096
+
#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
uint32_t it_present;
};
+/**
+ *
+ */
struct RadioTapheader
{
+ /**
+ *
+ */
struct ieee80211_radiotap_header header;
+
+ /**
+ *
+ */
uint8_t rate;
+
+ /**
+ *
+ */
uint8_t pad1;
+
+ /**
+ *
+ */
uint16_t txflags;
};
/**
- * FIXME.
+ * IO buffer used for buffering data in transit (to wireless or to stdout).
*/
struct SendBuffer
{
- unsigned int pos;
- unsigned int size;
+ /**
+ * How many bytes of data are stored in 'buf' for transmission right now?
+ * Data always starts at offset 0 and extends to 'size'.
+ */
+ size_t size;
+
+ /**
+ * How many bytes that were stored in 'buf' did we already write to the
+ * destination? Always smaller than 'size'.
+ */
+ size_t pos;
+
+ /**
+ * Buffered data; twice the maximum allowed message size as we add some
+ * headers.
+ */
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;
+
+
GNUNET_NETWORK_STRUCT_BEGIN
/**
} GNUNET_PACKED;
GNUNET_NETWORK_STRUCT_END
+
/**
* struct for storing the information of the hardware
*/
struct HardwareInfos
{
- /**
- * send buffer
- */
- struct SendBuffer write_pout;
-
/**
* file descriptor for the raw socket
*/
int fd_raw;
+ /**
+ * Which format has the header that we're getting when receiving packets?
+ * Some ARPHRD_IEEE80211_XXX-value.
+ */
int arptype_in;
/**
*/
char iface[IFNAMSIZ];
- struct MacAddress pl_mac;
+ /**
+ * MAC address of our own WLAN interface.
+ */
+ struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac;
};
-
-
- /* *INDENT-OFF* */
-#define ___my_swab16(x) \
-((u_int16_t)( \
- (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
- (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
-
-#define ___my_swab32(x) \
-((u_int32_t)( \
- (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
- (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
- (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
- (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
-#define ___my_swab64(x) \
-((u_int64_t)( \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
- (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
- /* *INDENT-ON* */
-
-
/**
- * struct ieee80211_radiotap_iterator - tracks walk through present radiotap args
+ * struct ieee80211_radiotap_iterator - tracks walk through present radiotap arguments
+ * in the radiotap header.
*/
struct ieee80211_radiotap_iterator
{
}
-/**
- * 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
- */
-static int
-send_mac_to_plugin (char *buffer, struct MacAddress *mac)
-{
- struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
-
- memcpy (&macmsg.mac, (char *) mac, sizeof (struct MacAddress));
- macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
- macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- memcpy (buffer, &macmsg, sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
- return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
-}
-
-
/**
* Return the channel from the frequency (in Mhz)
* @param frequency of the channel
/**
* 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
/**
- * 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
+ * Function to calculate and check crc of the wlan packet
+ *
+ * @param buf buffer of the packet, with len + 4 bytes of data,
+ * the last 4 bytes being the checksum
+ * @param len length of the payload in data
+ * @return 0 on success (checksum matches), 1 on error
*/
static int
check_crc_buf_osdep (const unsigned char *buf, size_t len)
crc = calc_crc_osdep (buf, len);
buf += len;
- return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
- ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
+ if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
+ ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
+ return 0;
+ return 1;
}
/**
- * function to get the channel of a specific wlan card
+ * Get the channel used by our WLAN interface.
+ *
* @param dev pointer to the dev struct of the card
- * @return channel number
+ * @return channel number, -1 on error
*/
static int
linux_get_channel (const struct HardwareInfos *dev)
caplen -= n;
//detect fcs at the end, even if the flag wasn't set and remove it
- if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4)))
+ if ((0 == fcs_removed) && (0 == check_crc_buf_osdep (tmpbuf + n, caplen - 4)))
{
caplen -= 4;
}
/**
- * function to open the device for read/write
+ * Open the wireless network interface for reading/writing.
+ *
* @param dev pointer to the device struct
* @return 0 on success
*/
/**
- * function to prepare the helper, e.g. sockets, device...
- * @param dev struct for the device
+ * Test if the given interface name really corresponds to a wireless
+ * device.
+ *
* @param iface name of the interface
- * @return 0 on success
+ * @return 0 on success, 1 on error
*/
static int
-wlan_initialize (struct HardwareInfos *dev, const char *iface)
+test_wlan_interface (const char *iface)
{
char strbuf[512];
struct stat sbuf;
int ret;
- if (dev->fd_raw >= FD_SETSIZE)
- {
- fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
- dev->fd_raw, FD_SETSIZE);
- close (dev->fd_raw);
- return 1;
- }
-
/* mac80211 stack detection */
ret =
snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem",
if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
{
fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
- close (dev->fd_raw);
- return 1;
- }
- strncpy (dev->iface, iface, IFNAMSIZ);
- if (0 != open_device_raw (dev))
- {
- close (dev->fd_raw);
return 1;
}
return 0;
stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct HardwareInfos *dev = cls;
- struct SendBuffer *write_pout = &dev->write_pout;
struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
struct ieee80211_frame *wlanheader;
size_t sendsize;
rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader));
rtheader.rate = header->rate;
- memcpy (write_pout->buf, &rtheader, sizeof (rtheader));
- memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize);
+ memcpy (write_pout.buf, &rtheader, sizeof (rtheader));
+ memcpy (write_pout.buf + sizeof (rtheader), &header[1], sendsize);
/* payload contains MAC address, but we don't trust it, so we'll
* overwrite it with OUR MAC address again to prevent mischief */
- wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader));
+ wlanheader = (struct ieee80211_frame *) (write_pout.buf + sizeof (rtheader));
mac_set (wlanheader, dev);
- write_pout->size = sendsize + sizeof (rtheader);
+ write_pout.size = sendsize + sizeof (rtheader);
}
/**
- * main function of the helper
- * @param argc number of arguments
- * @param argv arguments
- * @return 0 on success, 1 on error
+ * Main function of the helper. This code accesses a WLAN interface
+ * in monitoring mode (layer 2) and then forwards traffic in both
+ * directions between the WLAN interface and stdin/stdout of this
+ * process. Error messages are written to stdout.
+ *
+ * @param argc number of arguments, must be 2
+ * @param argv arguments only argument is the name of the interface (i.e. 'mon0')
+ * @return 0 on success (never happens, as we don't return unless aborted), 1 on error
*/
int
main (int argc, char *argv[])
{
- uid_t uid;
struct HardwareInfos dev;
char readbuf[MAXLINE];
- struct SendBuffer write_std;
- ssize_t ret;
int maxfd;
fd_set rfds;
fd_set wfds;
- int retval;
int stdin_open;
struct MessageStreamTokenizer *stdin_mst;
int raw_eno;
+ memset (&dev, 0, sizeof (dev));
dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
raw_eno = errno; /* remember for later */
- uid = getuid ();
-#ifdef HAVE_SETRESUID
- if (0 != setresuid (uid, uid, uid))
+
+ /* drop privs */
{
- fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
- if (-1 != dev.fd_raw)
- (void) close (dev.fd_raw);
- return 1;
- }
+ uid_t uid = getuid ();
+#ifdef HAVE_SETRESUID
+ if (0 != setresuid (uid, uid, uid))
+ {
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_raw)
+ (void) close (dev.fd_raw);
+ return 1;
+ }
#else
- if (0 != (setuid (uid) | seteuid (uid)))
- {
- fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
- if (-1 != dev.fd_raw)
- (void) close (dev.fd_raw);
- return 1;
+ if (0 != (setuid (uid) | seteuid (uid)))
+ {
+ fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_raw)
+ (void) close (dev.fd_raw);
+ return 1;
+ }
}
#endif
fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno));
return 1;
}
- if (0 != wlan_initialize (&dev, argv[1]))
+ if (dev.fd_raw >= FD_SETSIZE)
+ {
+ fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
+ dev.fd_raw, FD_SETSIZE);
+ (void) close (dev.fd_raw);
return 1;
- dev.write_pout.size = 0;
- dev.write_pout.pos = 0;
- stdin_mst = mst_create (&stdin_send_hw, &dev);
+ }
+ if (0 != test_wlan_interface (argv[1]))
+ {
+ (void) close (dev.fd_raw);
+ return 1;
+ }
+ strncpy (dev.iface, argv[1], IFNAMSIZ);
+ if (0 != open_device_raw (&dev))
+ {
+ (void) close (dev.fd_raw);
+ return 1;
+ }
- /* send mac to STDOUT first */
- write_std.pos = 0;
- write_std.size = send_mac_to_plugin ((char *) &write_std.buf, &dev.pl_mac);
- stdin_open = 1;
+ /* send MAC address of the WLAN interface to STDOUT first */
+ {
+ struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
+
+ macmsg.hdr.size = htons (sizeof (macmsg));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ memcpy (write_std.buf, &macmsg, sizeof (macmsg));
+ write_std.size = sizeof (macmsg);
+ }
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
+ stdin_open = 1;
while (1)
{
maxfd = -1;
FD_ZERO (&rfds);
- if ((0 == dev.write_pout.size) && (1 == stdin_open))
+ if ((0 == write_pout.size) && (1 == stdin_open))
{
FD_SET (STDIN_FILENO, &rfds);
maxfd = MAX (maxfd, STDIN_FILENO);
FD_SET (STDOUT_FILENO, &wfds);
maxfd = MAX (maxfd, STDOUT_FILENO);
}
- if (0 < dev.write_pout.size)
+ if (0 < write_pout.size)
{
FD_SET (dev.fd_raw, &wfds);
maxfd = MAX (maxfd, dev.fd_raw);
}
- retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
- if ((-1 == retval) && (EINTR == errno))
- continue;
- if (0 > retval)
{
- fprintf (stderr, "select failed: %s\n", strerror (errno));
- break;
+ int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
+ if ((-1 == retval) && (EINTR == errno))
+ continue;
+ if (0 > retval)
+ {
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
+ }
}
if (FD_ISSET (STDOUT_FILENO, &wfds))
{
- ret =
+ ssize_t ret =
write (STDOUT_FILENO, write_std.buf + write_std.pos,
write_std.size - write_std.pos);
if (0 > ret)
}
if (FD_ISSET (dev.fd_raw, &wfds))
{
- ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size);
+ ssize_t ret =
+ write (dev.fd_raw, write_pout.buf + write_std.pos,
+ write_pout.size - write_pout.pos);
if (0 > ret)
{
fprintf (stderr, "Failed to write to WLAN device: %s\n",
strerror (errno));
break;
}
- dev.write_pout.pos += ret;
- if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0))
+ write_pout.pos += ret;
+ if ((write_pout.pos != write_pout.size) && (0 != ret))
{
/* we should not get partial sends with packet-oriented devices... */
fprintf (stderr, "Write error, partial send: %u/%u\n",
- dev.write_pout.pos, dev.write_pout.size);
+ (unsigned int) write_pout.pos,
+ (unsigned int) write_pout.size);
break;
}
- if (dev.write_pout.pos == dev.write_pout.size)
+ if (write_pout.pos == write_pout.size)
{
- dev.write_pout.pos = 0;
- dev.write_pout.size = 0;
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
}
if (FD_ISSET (STDIN_FILENO, &rfds))
{
- ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
+ ssize_t ret =
+ read (STDIN_FILENO, readbuf, sizeof (readbuf));
if (0 > ret)
{
fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
struct GNUNET_MessageHeader *header;
struct Radiotap_rx *rxinfo;
struct ieee80211_frame *datastart;
+ ssize_t ret;
header = (struct GNUNET_MessageHeader *) write_std.buf;
rxinfo = (struct Radiotap_rx *) &header[1];
#include "gnunet_fragmentation_lib.h"
#include "gnunet_constants.h"
-#include <string.h>
+/**
+ * DEBUG switch
+ */
+#define DEBUG_WLAN GNUNET_EXTRA_LOGGING
+
#define PROTOCOL_PREFIX "wlan"
#define WLAN_LLC_SSAP_FIELD 0x1f
-/**
- * DEBUG switch
- */
-#define DEBUG_wlan GNUNET_EXTRA_LOGGING
-#define DEBUG_wlan_retransmission GNUNET_EXTRA_LOGGING
-#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
-#define DEBUG_wlan_msg_dump GNUNET_EXTRA_LOGGING
-
-
#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
#define IEEE80211_FC0_VERSION_MASK 0x03
/**
* The mac_address of the wlan card given to us by the helper.
*/
- struct MacAddress mac_address;
+ struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address;
/**
* Sessions currently pending for transmission
/**
* peer mac address
*/
- struct MacAddress addr;
+ struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
/**
* mac endpoint
/**
* peer mac address
*/
- struct MacAddress addr;
+ struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
/**
* Defrag context for this mac endpoint
int do_free_macendpoint);
static struct MacEndpoint *
-create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr);
+create_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr);
static void
finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
* @return
*/
static struct MacEndpoint *
-get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
+get_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr,
int create_new)
{
struct MacEndpoint *queue = plugin->mac_head;
while (queue != NULL)
{
//GNUNET_assert (queue->sessions_head != NULL);
- if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
+ if (memcmp (addr, &queue->addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
return queue; /* session found */
queue = queue->next;
}
wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char ret[40];
- const struct MacAddress *mac;
+ const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
- if (addrlen != sizeof (struct MacAddress))
+ if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
{
GNUNET_break (0);
return NULL;
queue->content->timeout_task =
GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"New session %p with endpoint %p: %s\n", queue->content,
endpoint, wlan_plugin_address_to_string (NULL,
endpoint->addr.mac,
6));
-#endif
-
return queue->content;
}
* @return returns the session
*/
static struct Session *
-get_session (struct Plugin *plugin, const struct MacAddress *addr,
+get_session (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr,
const struct GNUNET_PeerIdentity *peer)
{
struct MacEndpoint *mac;
next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
}
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Next packet is send in: %u\n", next_send.rel_value);
-#endif
-
if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
{
if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
if (pm == NULL)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
"pending message is empty, should not happen. session %p\n",
session);
-#endif
sessionqueue_alt = sessionqueue;
sessionqueue = sessionqueue->next;
plugin->pendingsessions--;
GNUNET_free (fm);
queue_session (plugin, session);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Free pending fragment messages %p, session %p\n", fm,
session);
-#endif
}
/**
*/
static int
getWlanHeader (struct ieee80211_frame *Header,
- const struct MacAddress *to_mac_addr, struct Plugin *plugin,
+ const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, struct Plugin *plugin,
unsigned int size)
{
uint16_t *tmp16;
memcpy (&Header->i_addr3, &mac_bssid_gnunet, sizeof (mac_bssid_gnunet));
memcpy (&Header->i_addr2, plugin->mac_address.mac,
sizeof (plugin->mac_address));
- memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
+ memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
tmp16 = (uint16_t *) Header->i_dur;
*tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
struct GNUNET_MessageHeader *msgheader2;
uint16_t size;
-#if DEBUG_wlan_retransmission > 1
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
-
size =
sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
sizeof (struct ieee80211_frame) + ntohs (hdr->size);
sizeof (mybuf));
if (bytes <= 0)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
_
("Finished reading from gnunet-helper-transport-wlan stdout with code: %d\n"),
bytes);
-#endif
return;
}
GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
if (plugin->helper_is_running == GNUNET_YES)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_transport_start_wlan_helper not needed, helper already running!");
-#endif
return GNUNET_YES;
}
if (plugin->testmode == 0)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Starting gnunet-helper-transport-wlan process cmd: %s %s %i\n",
filenamehw, plugin->interface, plugin->testmode);
-#endif
-
if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
{
plugin->server_proc =
else if (plugin->testmode == 1)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
"Starting gnunet-helper-transport-wlan-dummy loopback 1 process cmd: %s %s %i\n",
absolute_filename, plugin->interface, plugin->testmode);
-#endif
plugin->server_proc =
GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
absolute_filename, absolute_filename, "1",
}
else if (plugin->testmode == 2)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
"Starting gnunet-helper-transport-wlan-dummy loopback 2 process cmd: %s %s %i\n",
absolute_filename, plugin->interface, plugin->testmode);
-#endif
-
plugin->server_proc =
GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
absolute_filename, absolute_filename, "2",
GNUNET_free (absolute_filename);
if (plugin->server_proc == NULL)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Failed to start gnunet-helper-transport-wlan process\n");
-#endif
return GNUNET_SYSERR;
}
GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Adding server_read_task for the gnunet-helper-transport-wlan\n");
-#endif
-
plugin->server_read_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->server_stdout_handle,
static int
wlan_transport_stop_wlan_helper (struct Plugin *plugin)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Stoping WLAN helper process\n");
-#endif
if (plugin->helper_is_running == GNUNET_NO)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_transport_stop_wlan_helper not needed, helper already stopped!");
-#endif
return GNUNET_YES;
}
static void
send_hello_beacon (struct Plugin *plugin)
{
-
-#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Sending hello beacon\n");
-#endif
-
uint16_t size;
ssize_t bytes;
uint16_t hello_size;
const struct GNUNET_MessageHeader *hello;
struct Finish_send *finish;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Sending hello beacon\n");
+
GNUNET_assert (plugin != NULL);
GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
plugin->ack_send_queue_tail, ack);
-#if DEBUG_wlan_retransmission > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
msg_id, ack, endpoint);
-#endif
-
set_next_send (plugin);
}
{
pid = session->target;
pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"called pm->transmit_cont for %p\n", session);
-#endif
}
else
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"no pm->transmit_cont for %p\n", session);
-#endif
}
GNUNET_free (pm);
struct Finish_send *finish;
ack = plugin->ack_send_queue_head;
-
-
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Sending ack for message_id %u for mac endpoint %p, size %u\n",
ack->message_id, ack->endpoint,
ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
-#endif
-
GNUNET_assert (plugin != NULL);
GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
GNUNET_NO);
session = fm->session;
GNUNET_assert (session != NULL);
-
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
fm, fm->size);
-#endif
-
getRadiotapHeader (plugin, session->mac, fm->radioHeader);
getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
fm->size);
if (addrlen == 6)
{
/* TODO check for bad addresses like multicast, broadcast, etc */
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_plugin_address_suggested got good address, size %u!\n",
addrlen);
-#endif
return GNUNET_OK;
}
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_plugin_address_suggested got bad address, size %u!\n",
addrlen);
-#endif
return GNUNET_SYSERR;
}
GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
session->pending_message_tail, newmsg);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"New message for %p with size (incl wlan header) %u added\n",
session, newmsg->message_size);
-#endif
-#if DEBUG_wlan_msg_dump > 1
+#if DEBUG_WLAN > 1
hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
#endif
//queue session
const unsigned char *input;
//GNUNET_assert(cls !=NULL);
- if (addrlen != sizeof (struct MacAddress))
+ if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
{
/* invalid address (MAC addresses have 6 bytes) */
//GNUNET_break (0);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
addrlen);
-#endif
asc (asc_cls, NULL);
return;
}
"Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
type, PROTOCOL_PREFIX, input[0], input[1], input[2],
input[3], input[4], input[5]);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
addrlen, numeric, type, ret);
-#endif
asc (asc_cls, ret);
//only one mac address per plugin
asc (asc_cls, NULL);
if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
ntohs (hdr->size));
-#endif
if (ntohs (hdr->size) <
sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
//if not in session list
if (session == NULL)
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
sizeof (struct WlanHeader));
-#endif
//try if it is a hello message
if (ntohs (wlanheader->header.size) >=
ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
sizeof (struct GNUNET_PeerIdentity)) != 0)
{
//wrong peer id
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"WLAN peer source id doesn't match packet peer source id: session %p\n",
session);
-#endif
return;
}
sizeof (struct GNUNET_PeerIdentity)) != 0)
{
//wrong peer id
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"WLAN peer target id doesn't match our peer id: session %p\n",
session);
-#endif
return;
}
ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Calling plugin->env->receive for session %p; %s; size: %u\n",
session, wlan_plugin_address_to_string (NULL,
session->mac->
addr.mac, 6),
htons (hdr->size));
-#endif
-
plugin->env->receive (plugin->env->cls, &(session->target), hdr,
(const struct GNUNET_ATS_Information *) &ats, 2,
session, (const char *) &session->mac->addr,
//TODO test first than create session
GNUNET_assert (session_light != NULL);
-#if DEBUG_wlan
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));
-#endif
-
if (session_light->macendpoint == NULL)
{
session_light->macendpoint =
get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
}
-#if DEBUG_wlan
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));
-#endif
-
GNUNET_STATISTICS_update (plugin->env->stats,
_("# wlan fragments received"), 1, GNUNET_NO);
int ret =
if (session_light->macendpoint == NULL)
{
-#if DEBUG_wlan
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,
6));
-#endif
return;
}
-#if DEBUG_wlan
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));
-#endif
fm = session_light->macendpoint->sending_messages_head;
while (fm != NULL)
{
if (ret == GNUNET_OK)
{
-#if DEBUG_wlan_retransmission > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Got last ack, finished fragment message %p\n", fm);
-#endif
session_light->macendpoint->acks++;
fm->session->last_activity = GNUNET_TIME_absolute_get ();
session_light->macendpoint->last_activity = fm->session->last_activity;
}
if (ret == GNUNET_NO)
{
-#if DEBUG_wlan_retransmission > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Got ack for: %p\n", fm);
-#endif
session_light->macendpoint->acks++;
return;
}
fm = fm2;
}
-#if DEBUG_wlan_retransmission > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"WLAN fragment not in fragment list\n");
-#endif
return;
}
}
-#if DEBUG_wlan
/**
* Function to print mac addresses nice *
* @param pointer to 6 byte with the mac address
mac[2], mac[3], mac[4], mac[5]);
return macstr;
}
-#endif
/**
* Function for the scheduler if a mac endpoint times out
* @return returns a macendpoint
*/
static struct MacEndpoint *
-create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
+create_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr)
{
struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
plugin->mac_count, GNUNET_NO);
GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"New Mac Endpoint %p: %s\n", newend,
wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
-#endif
return newend;
}
switch (ntohs (hdr->type))
{
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
ntohs (hdr->size));
-#endif
-
GNUNET_STATISTICS_update (plugin->env->stats,
_("# wlan WLAN_HELPER_DATA received"), 1,
GNUNET_NO);
sizeof (struct ieee80211_frame) +
2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
{
-#if DEBUG_wlan
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 ieee80211_frame) +
sizeof (struct GNUNET_MessageHeader));
-#endif
//GNUNET_break (0);
/* FIXME: restart SUID process */
return;
//check for bssid
if (memcmp
(&(wlanIeeeHeader->i_addr3), &mac_bssid_gnunet,
- sizeof (struct MacAddress)) == 0)
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
{
//check for broadcast or mac
if ((memcmp
(&(wlanIeeeHeader->i_addr1), &bc_all_mac,
- sizeof (struct MacAddress)) == 0) ||
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) ||
(memcmp
(&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
- sizeof (struct MacAddress)) == 0))
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0))
{
//if packet is from us return
if ((memcmp
(&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
- sizeof (struct MacAddress)) == 0))
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0))
{
return;
}
session_light = GNUNET_malloc (sizeof (struct Session_light));
memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
- sizeof (struct MacAddress));
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
//session_light->session = search_session(plugin,session_light->addr);
GNUNET_STATISTICS_update (plugin->env->stats,
_("# wlan messages for this client received"),
}
else
{
-#if DEBUG_wlan
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);
-#endif
}
pos += ntohs (temp_hdr->size);
}
else
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_process_helper got wrong MAC: %s\n",
macprinter (wlanIeeeHeader->i_addr1));
-#endif
}
}
else
{
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_process_helper got wrong BSSID: %s\n",
macprinter (wlanIeeeHeader->i_addr2));
-#endif
}
break;
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
/* FIXME: restart SUID process */
return;
}
- memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
-#if DEBUG_wlan
+ memcpy (&plugin->mac_address, &hdr[1], sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
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,
- sizeof (struct
- MacAddress)));
-#endif
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)));
plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
&plugin->mac_address,
- sizeof (struct MacAddress));
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
break;
default:
-#if DEBUG_wlan
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));
-#endif
-#if DEBUG_wlan_msg_dump > 1
+#if DEBUG_WLAN > 1
hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
#endif
GNUNET_break (0);
struct MacEndpoint *endpoint = plugin->mac_head;
struct MacEndpoint *endpoint_next;
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"libgnunet_plugin_transport_wlan_done started\n");
-#endif
-
wlan_transport_stop_wlan_helper (plugin);
GNUNET_assert (cls != NULL);
wlan_transport_start_wlan_helper (plugin);
set_next_beacon_time (plugin);
set_next_send (plugin);
-#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan init finished\n");
-#endif
-
return api;
}