aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-20 08:40:40 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-20 08:40:40 +0000
commit0209c25ec477652312cfcafe33a78e1f7d9e21a5 (patch)
tree086773253064987cca2abb3ed9303c67e9911a43 /src
parentdd7f08beaa21ec75960e502a7c8971b4287b0171 (diff)
downloadgnunet-0209c25ec477652312cfcafe33a78e1f7d9e21a5.tar.gz
gnunet-0209c25ec477652312cfcafe33a78e1f7d9e21a5.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c96
1 files changed, 24 insertions, 72 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 633b2776c..7bfcf93ee 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -100,31 +100,6 @@ int closeprog;
100 100
101#define DEBUG 1 101#define DEBUG 1
102 102
103typedef enum
104{
105 DT_NULL = 0,
106 DT_WLANNG,
107 DT_HOSTAP,
108 DT_MADWIFI,
109 DT_MADWIFING,
110 DT_BCM43XX,
111 DT_ORINOCO,
112 DT_ZD1211RW,
113 DT_ACX,
114 DT_MAC80211_RT,
115 DT_AT76USB,
116 DT_IPW2200
117
118} DRIVER_TYPE;
119
120static const char * szaDriverTypes[] =
121 { [DT_NULL] = "Unknown", [DT_WLANNG] = "Wlan-NG", [DT_HOSTAP] = "HostAP",
122 [DT_MADWIFI] = "Madwifi", [DT_MADWIFING] = "Madwifi-NG",
123 [DT_BCM43XX] = "BCM43xx", [DT_ORINOCO] = "Orinoco",
124 [DT_ZD1211RW] = "ZD1211RW", [DT_ACX] = "ACX",
125 [DT_MAC80211_RT] = "Mac80211-Radiotap", [DT_AT76USB] = "Atmel 76_usb",
126 [DT_IPW2200] = "ipw2200" };
127
128struct Hardware_Infos 103struct Hardware_Infos
129{ 104{
130 105
@@ -132,23 +107,12 @@ struct Hardware_Infos
132 int fd_in, arptype_in; 107 int fd_in, arptype_in;
133 int fd_out; 108 int fd_out;
134 109
135 DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */
136
137 char *iface; 110 char *iface;
138 unsigned char pl_mac[6]; 111 unsigned char pl_mac[6];
139}; 112};
140 113
141 114
142/* wifi bitrate to use in 500kHz units */
143
144/*
145 static const u8 u8aRatesToUse[] =
146 {
147
148 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5
149 2 * 2, 1 * 2 };
150 115
151*/
152static void 116static void
153sigfunc_hw(int sig) 117sigfunc_hw(int sig)
154{ 118{
@@ -461,7 +425,8 @@ linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count)
461} 425}
462 426
463static int 427static int
464openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, 428openraw(struct Hardware_Infos * dev,
429 const char * iface, int fd, int * arptype,
465 uint8_t *mac) 430 uint8_t *mac)
466{ 431{
467 struct ifreq ifr; 432 struct ifreq ifr;
@@ -582,10 +547,12 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype,
582 return (0); 547 return (0);
583} 548}
584 549
585int 550static int
586wlaninit(struct Hardware_Infos * dev, char *iface) 551wlaninit(struct Hardware_Infos * dev, const char *iface)
587{ 552{
588 char strbuf[512]; 553 char strbuf[512];
554 struct stat sbuf;
555 int ret;
589 556
590 dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 557 dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
591 if (0 > dev->fd_out) 558 if (0 > dev->fd_out)
@@ -606,25 +573,20 @@ wlaninit(struct Hardware_Infos * dev, char *iface)
606 */ 573 */
607 574
608 /* mac80211 stack detection */ 575 /* mac80211 stack detection */
609 memset(strbuf, 0, sizeof(strbuf)); 576 ret = snprintf(strbuf,
610 snprintf(strbuf, sizeof(strbuf) - 1, 577 sizeof(strbuf),
611 "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface); 578 "/sys/class/net/%s/phy80211/subsystem",
612 579 iface);
613 if (0 == system(strbuf)) 580 if ( (ret < 0) ||
614 dev->drivertype = DT_MAC80211_RT; 581 (ret >= sizeof (strbuf)) ||
615 582 (0 != stat(strbuf, &sbuf)) )
616 else
617 { 583 {
618 // At the moment only mac80211 tested 584 fprintf(stderr,
619 fprintf(stderr, "only mac80211 stack supported, exiting.\n"); 585 "Did not find 802.11 interface `%s'. Exiting.\n",
586 iface);
620 return 1; 587 return 1;
621 } 588 }
622 589
623#ifdef DEBUG
624 fprintf(stderr, "Interface %s -> driver: %s\n", iface,
625 szaDriverTypes[dev->drivertype]);
626#endif
627
628 if (openraw(dev, iface, dev->fd_out, &dev->arptype_in, dev->pl_mac) != 0) 590 if (openraw(dev, iface, dev->fd_out, &dev->arptype_in, dev->pl_mac) != 0)
629 { 591 {
630 goto close_out; 592 goto close_out;
@@ -733,23 +695,13 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
733 u8aRadiotap[2] = htole16(sizeof(u8aRadiotap)); 695 u8aRadiotap[2] = htole16(sizeof(u8aRadiotap));
734 u8aRadiotap[8] = header->rate; 696 u8aRadiotap[8] = header->rate;
735 697
736 switch (dev->drivertype) 698 memcpy(write_pout->buf, u8aRadiotap, sizeof(u8aRadiotap));
737 { 699 memcpy(write_pout->buf + sizeof(u8aRadiotap), &header[1], sendsize);
738 700
739 case DT_MAC80211_RT: 701 wlanheader = write_pout->buf + sizeof(u8aRadiotap);
740 memcpy(write_pout->buf, u8aRadiotap, sizeof(u8aRadiotap)); 702 mac_set(wlanheader, dev);
741 memcpy(write_pout->buf + sizeof(u8aRadiotap), &header[1], sendsize); 703
742 704 sendsize += sizeof(u8aRadiotap);
743 wlanheader = write_pout->buf + sizeof(u8aRadiotap);
744 mac_set(wlanheader, dev);
745
746 sendsize += sizeof(u8aRadiotap);
747
748 break;
749 default:
750 break;
751 }
752
753 write_pout->size = sendsize; 705 write_pout->size = sendsize;
754} 706}
755 707