2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file src/transport/gnunet-transport-wlan-helper.c
23 * @brief wlan layer two server; must run as root (SUID will do)
24 * This code will work under GNU/Linux only.
25 * @author David Brodski
27 * This program serves as the mediator between the wlan interface and
32 #include <sys/socket.h>
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
39 #include <netpacket/packet.h>
40 #include <linux/if_ether.h>
42 #include <linux/wireless.h>
43 #include <netinet/in.h>
44 #include <linux/if_tun.h>
52 //#include <sys/utsname.h>
53 #include <sys/param.h>
61 //#include "platform.h"
62 #include "gnunet_constants.h"
63 #include "gnunet_os_lib.h"
64 #include "gnunet_transport_plugin.h"
65 #include "transport.h"
66 #include "gnunet_util_lib.h"
67 #include "plugin_transport_wlan.h"
68 #include "gnunet_common.h"
69 #include "gnunet-transport-wlan-helper.h"
70 #include "gnunet_crypto_lib.h"
72 #include "wlan/radiotap-parser.h"
73 /* radiotap-parser defines types like u8 that
74 * ieee80211_radiotap.h needs
76 * we use our local copy of ieee80211_radiotap.h
78 * - since we can't support extensions we don't understand
79 * - since linux does not include it in userspace headers
81 #include "wlan/ieee80211_radiotap.h"
82 #include "wlan/crctable_osdep.h"
83 #include "wlan/loopback_helper.h"
84 #include "wlan/ieee80211.h"
86 #define ARPHRD_IEEE80211 801
87 #define ARPHRD_IEEE80211_PRISM 802
88 #define ARPHRD_IEEE80211_FULL 803
90 #include "wlan/loopback_helper.h"
94 #define MAC_ADDR_SIZE 6
99 struct sendbuf write_pout;
104 * Name of the interface, not necessarily 0-terminated (!).
106 char iface[IFNAMSIZ];
107 unsigned char pl_mac[MAC_ADDR_SIZE];
111 int getChannelFromFrequency (int frequency);
113 // FIXME: make nice...
115 calc_crc_osdep (unsigned char *buf, int len)
117 unsigned long crc = 0xFFFFFFFF;
119 for (; len > 0; len--, buf++)
120 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
125 /* CRC checksum verification routine */
127 // FIXME: make nice...
129 check_crc_buf_osdep (unsigned char *buf, int len)
136 crc = calc_crc_osdep (buf, len);
138 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
139 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
143 // FIXME: make nice...
145 linux_get_channel (struct Hardware_Infos *dev)
151 memset (&wrq, 0, sizeof (struct iwreq));
153 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
156 if (0 > ioctl (fd, SIOCGIWFREQ, &wrq))
159 frequency = wrq.u.freq.m;
160 if (100000000 < frequency)
162 else if (1000000 < frequency)
165 if (1000 < frequency)
166 chan = getChannelFromFrequency (frequency);
174 // FIXME: make nice...
176 linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */
177 size_t buf_size, struct Radiotap_rx *ri)
179 unsigned char tmpbuf[buf_size];
181 int n, got_signal, got_noise, got_channel, fcs_removed;
183 n = got_signal = got_noise = got_channel = fcs_removed = 0;
185 caplen = read (dev->fd_raw, tmpbuf, buf_size);
190 fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
194 memset (buf, 0, buf_size);
195 memset (ri, 0, sizeof (*ri));
197 switch (dev->arptype_in)
199 case ARPHRD_IEEE80211_PRISM:
201 /* skip the prism header */
202 if (tmpbuf[7] == 0x40)
204 /* prism54 uses a different format */
205 ri->ri_power = tmpbuf[0x33];
206 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
207 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
214 ri->ri_mactime = *(u_int64_t *) (tmpbuf + 0x5C - 48);
215 ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
216 ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
217 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
218 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
222 n = *(int *) (tmpbuf + 4);
225 if (n < 8 || n >= caplen)
230 case ARPHRD_IEEE80211_FULL:
232 struct ieee80211_radiotap_iterator iterator;
233 struct ieee80211_radiotap_header *rthdr;
235 rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
237 if (ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen) < 0)
240 /* go through the radiotap arguments we have been given
244 while (ieee80211_radiotap_iterator_next (&iterator) >= 0)
247 switch (iterator.this_arg_index)
250 case IEEE80211_RADIOTAP_TSFT:
251 ri->ri_mactime = le64_to_cpu (*((uint64_t *) iterator.this_arg));
254 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
257 if (*iterator.this_arg < 127)
258 ri->ri_power = *iterator.this_arg;
260 ri->ri_power = *iterator.this_arg - 255;
266 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
269 if (*iterator.this_arg < 127)
270 ri->ri_power = *iterator.this_arg;
272 ri->ri_power = *iterator.this_arg - 255;
278 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
281 if (*iterator.this_arg < 127)
282 ri->ri_noise = *iterator.this_arg;
284 ri->ri_noise = *iterator.this_arg - 255;
290 case IEEE80211_RADIOTAP_DB_ANTNOISE:
293 if (*iterator.this_arg < 127)
294 ri->ri_noise = *iterator.this_arg;
296 ri->ri_noise = *iterator.this_arg - 255;
302 case IEEE80211_RADIOTAP_ANTENNA:
303 ri->ri_antenna = *iterator.this_arg;
306 case IEEE80211_RADIOTAP_CHANNEL:
307 ri->ri_channel = *iterator.this_arg;
311 case IEEE80211_RADIOTAP_RATE:
312 ri->ri_rate = (*iterator.this_arg) * 500000;
315 case IEEE80211_RADIOTAP_FLAGS:
316 /* is the CRC visible at the end?
319 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
325 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
331 n = le16_to_cpu (rthdr->it_len);
332 if (n <= 0 || n >= caplen)
336 case ARPHRD_IEEE80211:
346 //detect fcs at the end, even if the flag wasn't set and remove it
347 if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4)))
351 memcpy (buf, tmpbuf + n, caplen);
353 ri->ri_channel = linux_get_channel (dev);
360 * @return 0 on success
363 openraw (struct Hardware_Infos *dev)
367 struct packet_mreq mr;
368 struct sockaddr_ll sll;
370 /* find the interface index */
371 memset (&ifr, 0, sizeof (ifr));
372 strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
373 if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
376 "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
377 IFNAMSIZ, dev->iface, strerror (errno));
381 /* lookup the hardware type */
382 memset (&sll, 0, sizeof (sll));
383 sll.sll_family = AF_PACKET;
384 sll.sll_ifindex = ifr.ifr_ifindex;
385 sll.sll_protocol = htons (ETH_P_ALL);
386 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
388 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
389 IFNAMSIZ, dev->iface, strerror (errno));
394 memset (&wrq, 0, sizeof (struct iwreq));
395 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
396 if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
398 /* most probably not supported (ie for rtap ipw interface) *
399 * so just assume its correctly set... */
400 wrq.u.mode = IW_MODE_MONITOR;
403 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
404 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
405 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) ||
406 (wrq.u.mode != IW_MODE_MONITOR))
408 fprintf (stderr, "Error: interface `%.*s' is not in monitor mode\n",
409 IFNAMSIZ, dev->iface);
413 /* Is interface st to up, broadcast & running ? */
414 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
416 /* Bring interface up */
417 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
419 if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
422 "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
423 IFNAMSIZ, dev->iface, strerror (errno));
428 /* bind the raw socket to the interface */
429 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll)))
431 fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
432 dev->iface, strerror (errno));
436 /* lookup the hardware type */
437 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
440 "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
441 IFNAMSIZ, dev->iface, strerror (errno));
445 memcpy (dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
446 dev->arptype_in = ifr.ifr_hwaddr.sa_family;
447 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
448 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
449 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
451 fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
452 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
456 /* enable promiscuous mode */
457 memset (&mr, 0, sizeof (mr));
458 mr.mr_ifindex = sll.sll_ifindex;
459 mr.mr_type = PACKET_MR_PROMISC;
461 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
464 fprintf (stderr, "Failed to enable promiscuous mode on interface `%.*s'\n",
465 IFNAMSIZ, dev->iface);
473 * @return 0 on success
476 wlaninit (struct Hardware_Infos *dev, const char *iface)
482 dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
485 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (errno));
488 if (dev->fd_raw >= FD_SETSIZE)
490 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
491 dev->fd_raw, FD_SETSIZE);
496 /* mac80211 stack detection */
498 snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem",
500 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
502 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
506 strncpy (dev->iface, iface, IFNAMSIZ);
507 if (0 != openraw (dev))
517 * Function to test incoming packets mac for being our own.
519 * @param u8aIeeeHeader buffer of the packet
520 * @param dev the Hardware_Infos struct
521 * @return 0 if mac belongs to us, 1 if mac is for another target
524 mac_test (const struct ieee80211_frame *u8aIeeeHeader,
525 const struct Hardware_Infos *dev)
527 if (0 != memcmp (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
529 if (0 == memcmp (u8aIeeeHeader->i_addr1, dev->pl_mac, MAC_ADDR_SIZE))
531 if (0 == memcmp (u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE))
538 * function to set the wlan header to make attacks more difficult
539 * @param buf buffer of the packet
540 * @param dev pointer to the Hardware_Infos struct
543 mac_set (struct ieee80211_frame *u8aIeeeHeader,
544 const struct Hardware_Infos *dev)
546 u8aIeeeHeader->i_fc[0] = 0x08;
547 u8aIeeeHeader->i_fc[1] = 0x00;
548 memcpy (u8aIeeeHeader->i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
549 memcpy (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE);
553 struct RadioTapheader
555 struct ieee80211_radiotap_header header;
562 stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
564 struct Hardware_Infos *dev = cls;
565 struct sendbuf *write_pout = &dev->write_pout;
566 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
567 struct ieee80211_frame *wlanheader;
570 // struct? // FIXME: make nice...
571 struct RadioTapheader rtheader;
573 rtheader.header.it_version = 0;
574 rtheader.header.it_len = htole16 (0x0c);
575 rtheader.header.it_present = htole32 (0x00008004);
576 rtheader.rate = 0x00;
578 htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
580 /* { 0x00, 0x00, <-- radiotap version
581 * 0x0c, 0x00, <- radiotap header length
582 * 0x04, 0x80, 0x00, 0x00, <-- bitmap
584 * 0x00, <-- padding for natural alignment
585 * 0x18, 0x00, <-- TX flags
588 sendsize = ntohs (hdr->size);
590 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader))
592 fprintf (stderr, "Function stdin_send_hw: mailformed packet (too small)\n");
596 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader);
598 if (MAXLINE < sendsize)
600 fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n");
603 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
605 fprintf (stderr, "Function stdin_send: wrong packet type\n");
609 rtheader.header.it_len = htole16 (sizeof (rtheader));
610 rtheader.rate = header->rate;
611 memcpy (write_pout->buf, &rtheader, sizeof (rtheader));
612 memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize);
613 /* payload contains MAC address, but we don't trust it, so we'll
614 * overwrite it with OUR MAC address again to prevent mischief */
615 wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader));
616 mac_set (wlanheader, dev);
617 write_pout->size = sendsize + sizeof (rtheader);
622 maketest (unsigned char *buf, struct Hardware_Infos *dev)
625 static uint16_t seqenz = 0;
626 static int first = 0;
628 const int rate = 11000000;
629 static const char txt[] =
630 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
632 unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version
633 0x00, 0x00, // <- radiotap header length
634 0x04, 0x80, 0x02, 0x00, // <-- bitmap
636 0x00, // <-- padding for natural alignment
637 0x10, 0x00, // <-- TX flags
641 /*uint8_t u8aRadiotap[] =
643 * 0x00, 0x00, // <-- radiotap version
644 * 0x19, 0x00, // <- radiotap header length
645 * 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
646 * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
647 * 0x00, // <-- flags (Offset +0x10)
648 * 0x6c, // <-- rate (0ffset +0x11)
649 * 0x71, 0x09, 0xc0, 0x00, // <-- channel
650 * 0xde, // <-- antsignal
651 * 0x00, // <-- antnoise
652 * 0x01, // <-- antenna
655 u8aRadiotap[8] = (rate / 500000);
656 u8aRadiotap[2] = htole16 (sizeof (u8aRadiotap));
658 static struct ieee80211_frame u8aIeeeHeader;
660 uint8_t u8aIeeeHeader_def[] = { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
661 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
662 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
663 0x00, 0x00, // Duration/ID
665 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
666 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
667 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
668 //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
669 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
670 0x10, 0x86, //Sequence Control
674 memcpy (&u8aIeeeHeader, u8aIeeeHeader_def, sizeof (struct ieee80211_frame));
675 memcpy (u8aIeeeHeader.i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
679 tmp16 = (uint16_t *) u8aIeeeHeader.i_dur;
682 htole16 ((sizeof (txt) +
683 sizeof (struct ieee80211_frame) * 1000000) / rate + 290);
684 tmp16 = (uint16_t *) u8aIeeeHeader.i_seq;
686 (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz) <<
687 IEEE80211_SEQ_SEQ_SHIFT);
690 memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap));
691 memcpy (buf + sizeof (u8aRadiotap), &u8aIeeeHeader, sizeof (u8aIeeeHeader));
692 memcpy (buf + sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader), txt,
694 return sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader) + sizeof (txt);
701 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin
702 * @param buffer pointer to buffer for the message
703 * @param mac pointer to the mac address
704 * @return number of bytes written
706 // FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file)
708 send_mac_to_plugin (char *buffer, uint8_t * mac)
710 struct Wlan_Helper_Control_Message macmsg;
712 macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
713 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
714 memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress));
715 memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
716 return sizeof (struct Wlan_Helper_Control_Message);
721 hardwaremode (int argc, char *argv[])
724 struct Hardware_Infos dev;
725 char readbuf[MAXLINE];
726 struct sendbuf write_std;
733 struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
735 if (0 != wlaninit (&dev, argv[1]))
738 if (0 != setresuid (uid, uid, uid))
740 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
741 /* not critical, continue anyway */
744 dev.write_pout.size = 0;
745 dev.write_pout.pos = 0;
746 stdin_mst = GNUNET_SERVER_mst_create (&stdin_send_hw, &dev);
748 /* send mac to STDOUT first */
750 write_std.size = send_mac_to_plugin ((char *) &write_std.buf, dev.pl_mac);
757 if ((0 == dev.write_pout.size) && (1 == stdin_open))
759 FD_SET (STDIN_FILENO, &rfds);
760 maxfd = MAX (maxfd, STDIN_FILENO);
762 if (0 == write_std.size)
764 FD_SET (dev.fd_raw, &rfds);
765 maxfd = MAX (maxfd, dev.fd_raw);
768 if (0 < write_std.size)
770 FD_SET (STDOUT_FILENO, &wfds);
771 maxfd = MAX (maxfd, STDOUT_FILENO);
773 if (0 < dev.write_pout.size)
775 FD_SET (dev.fd_raw, &wfds);
776 maxfd = MAX (maxfd, dev.fd_raw);
778 retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
779 if ((-1 == retval) && (EINTR == errno))
783 fprintf (stderr, "select failed: %s\n", strerror (errno));
787 if (FD_ISSET (STDOUT_FILENO, &wfds))
790 write (STDOUT_FILENO, write_std.buf + write_std.pos,
791 write_std.size - write_std.pos);
794 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
797 write_std.pos += ret;
798 if (write_std.pos == write_std.size)
805 if (FD_ISSET (dev.fd_raw, &wfds))
807 ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size);
811 "Line %u: Failed to write to WLAN device: %s, Message-Size: %u\n",
812 __LINE__, strerror (errno), dev.write_pout.size);
815 dev.write_pout.pos += ret;
816 if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0))
818 fprintf (stderr, "Line %u: Write error, partial send: %u/%u\n",
819 __LINE__, dev.write_pout.pos, dev.write_pout.size);
822 if (dev.write_pout.pos == dev.write_pout.size)
824 dev.write_pout.pos = 0;
825 dev.write_pout.size = 0;
829 if (FD_ISSET (STDIN_FILENO, &rfds))
831 ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
834 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
839 /* stop reading... */
842 GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, ret, GNUNET_NO,
846 if (FD_ISSET (dev.fd_raw, &rfds))
848 struct GNUNET_MessageHeader *header;
849 struct Radiotap_rx *rxinfo;
850 struct ieee80211_frame *datastart;
852 header = (struct GNUNET_MessageHeader *) write_std.buf;
853 rxinfo = (struct Radiotap_rx *) &header[1];
854 datastart = (struct ieee80211_frame *) &rxinfo[1];
856 linux_read (&dev, (unsigned char *) datastart,
857 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) -
858 sizeof (struct GNUNET_MessageHeader), rxinfo);
861 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
864 if ((0 < ret) && (0 == mac_test (datastart, &dev)))
867 ret + sizeof (struct GNUNET_MessageHeader) +
868 sizeof (struct Radiotap_rx);
869 header->size = htons (write_std.size);
870 header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
875 /* Error handling, try to clean up a bit at least */
876 GNUNET_SERVER_mst_destroy (stdin_mst);
882 main (int argc, char *argv[])
887 "This program must be started with the interface as argument.\nThis program was compiled at ----- %s ----\n",
889 fprintf (stderr, "Usage: interface-name\n" "\n");
892 return hardwaremode (argc, argv);