diff options
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 169 |
1 files changed, 152 insertions, 17 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index ad6810233..7717966dc 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -80,19 +80,72 @@ | |||
80 | */ | 80 | */ |
81 | #include "wlan/ieee80211_radiotap.h" | 81 | #include "wlan/ieee80211_radiotap.h" |
82 | #include "wlan/crctable_osdep.h" | 82 | #include "wlan/crctable_osdep.h" |
83 | #include "wlan/loopback_helper.h" | 83 | //#include "wlan/loopback_helper.h" |
84 | #include "wlan/ieee80211.h" | 84 | //#include "wlan/ieee80211.h" |
85 | #include "wlan/helper_common.h" | ||
85 | 86 | ||
86 | #define ARPHRD_IEEE80211 801 | 87 | #define ARPHRD_IEEE80211 801 |
87 | #define ARPHRD_IEEE80211_PRISM 802 | 88 | #define ARPHRD_IEEE80211_PRISM 802 |
88 | #define ARPHRD_IEEE80211_FULL 803 | 89 | #define ARPHRD_IEEE80211_FULL 803 |
89 | 90 | ||
90 | #include "wlan/loopback_helper.h" | ||
91 | |||
92 | #define DEBUG 1 | 91 | #define DEBUG 1 |
93 | 92 | ||
94 | #define MAC_ADDR_SIZE 6 | 93 | #define MAC_ADDR_SIZE 6 |
95 | 94 | ||
95 | //Part taken from file ieee80211.h | ||
96 | /*- | ||
97 | * Copyright (c) 2001 Atsushi Onoe | ||
98 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting | ||
99 | * All rights reserved. | ||
100 | * | ||
101 | * Redistribution and use in source and binary forms, with or without | ||
102 | * modification, are permitted provided that the following conditions | ||
103 | * are met: | ||
104 | * 1. Redistributions of source code must retain the above copyright | ||
105 | * notice, this list of conditions and the following disclaimer. | ||
106 | * 2. Redistributions in binary form must reproduce the above copyright | ||
107 | * notice, this list of conditions and the following disclaimer in the | ||
108 | * documentation and/or other materials provided with the distribution. | ||
109 | * 3. The name of the author may not be used to endorse or promote products | ||
110 | * derived from this software without specific prior written permission. | ||
111 | * | ||
112 | * Alternatively, this software may be distributed under the terms of the | ||
113 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
114 | * Software Foundation. | ||
115 | * | ||
116 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
117 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
118 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
119 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
120 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
121 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
122 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
123 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
124 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
125 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
126 | * | ||
127 | * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.12 2006/12/01 18:40:51 imp Exp $ | ||
128 | */ | ||
129 | |||
130 | #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ | ||
131 | |||
132 | /* | ||
133 | * generic definitions for IEEE 802.11 frames | ||
134 | */ | ||
135 | struct ieee80211_frame | ||
136 | { | ||
137 | u_int8_t i_fc[2]; | ||
138 | u_int8_t i_dur[2]; | ||
139 | u_int8_t i_addr1[IEEE80211_ADDR_LEN]; | ||
140 | u_int8_t i_addr2[IEEE80211_ADDR_LEN]; | ||
141 | u_int8_t i_addr3[IEEE80211_ADDR_LEN]; | ||
142 | u_int8_t i_seq[2]; | ||
143 | /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ | ||
144 | /* see below */ | ||
145 | } GNUNET_PACKED; | ||
146 | |||
147 | // End taken part | ||
148 | |||
96 | struct Hardware_Infos | 149 | struct Hardware_Infos |
97 | { | 150 | { |
98 | 151 | ||
@@ -107,6 +160,14 @@ struct Hardware_Infos | |||
107 | unsigned char pl_mac[MAC_ADDR_SIZE]; | 160 | unsigned char pl_mac[MAC_ADDR_SIZE]; |
108 | }; | 161 | }; |
109 | 162 | ||
163 | struct RadioTapheader | ||
164 | { | ||
165 | struct ieee80211_radiotap_header header; | ||
166 | u8 rate; | ||
167 | u8 pad1; | ||
168 | u16 txflags; | ||
169 | }; | ||
170 | |||
110 | // FIXME: inline? | 171 | // FIXME: inline? |
111 | int | 172 | int |
112 | getChannelFromFrequency (int frequency); | 173 | getChannelFromFrequency (int frequency); |
@@ -126,6 +187,7 @@ calc_crc_osdep (unsigned char *buf, int len) | |||
126 | /* CRC checksum verification routine */ | 187 | /* CRC checksum verification routine */ |
127 | 188 | ||
128 | // FIXME: make nice... | 189 | // FIXME: make nice... |
190 | // fixme doxigen | ||
129 | static int | 191 | static int |
130 | check_crc_buf_osdep (unsigned char *buf, int len) | 192 | check_crc_buf_osdep (unsigned char *buf, int len) |
131 | { | 193 | { |
@@ -142,6 +204,7 @@ check_crc_buf_osdep (unsigned char *buf, int len) | |||
142 | 204 | ||
143 | 205 | ||
144 | // FIXME: make nice... | 206 | // FIXME: make nice... |
207 | //fixme doxigen | ||
145 | static int | 208 | static int |
146 | linux_get_channel (struct Hardware_Infos *dev) | 209 | linux_get_channel (struct Hardware_Infos *dev) |
147 | { | 210 | { |
@@ -173,6 +236,7 @@ linux_get_channel (struct Hardware_Infos *dev) | |||
173 | 236 | ||
174 | 237 | ||
175 | // FIXME: make nice... | 238 | // FIXME: make nice... |
239 | //FIXME doxigen | ||
176 | static ssize_t | 240 | static ssize_t |
177 | linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */ | 241 | linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */ |
178 | size_t buf_size, struct Radiotap_rx *ri) | 242 | size_t buf_size, struct Radiotap_rx *ri) |
@@ -356,7 +420,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? | |||
356 | return caplen; | 420 | return caplen; |
357 | } | 421 | } |
358 | 422 | ||
359 | 423 | //FIXME doxigen | |
360 | /** | 424 | /** |
361 | * @return 0 on success | 425 | * @return 0 on success |
362 | */ | 426 | */ |
@@ -551,14 +615,7 @@ mac_set (struct ieee80211_frame *u8aIeeeHeader, | |||
551 | 615 | ||
552 | } | 616 | } |
553 | 617 | ||
554 | struct RadioTapheader | 618 | //FIXME: doxigen |
555 | { | ||
556 | struct ieee80211_radiotap_header header; | ||
557 | u8 rate; | ||
558 | u8 pad1; | ||
559 | u16 txflags; | ||
560 | }; | ||
561 | |||
562 | static void | 619 | static void |
563 | stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 620 | stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
564 | { | 621 | { |
@@ -590,7 +647,7 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
590 | if (sendsize < | 647 | if (sendsize < |
591 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) | 648 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) |
592 | { | 649 | { |
593 | fprintf (stderr, "Function stdin_send_hw: mailformed packet (too small)\n"); | 650 | fprintf (stderr, "Function stdin_send_hw: malformed packet (too small)\n"); |
594 | exit (1); | 651 | exit (1); |
595 | } | 652 | } |
596 | sendsize -= | 653 | sendsize -= |
@@ -705,19 +762,21 @@ maketest (unsigned char *buf, struct Hardware_Infos *dev) | |||
705 | * @return number of bytes written | 762 | * @return number of bytes written |
706 | */ | 763 | */ |
707 | // FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file) | 764 | // FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file) |
765 | /* | ||
708 | static int | 766 | static int |
709 | send_mac_to_plugin (char *buffer, uint8_t * mac) | 767 | send_mac_to_plugin (char *buffer, struct MacAddress * mac) |
710 | { | 768 | { |
711 | struct Wlan_Helper_Control_Message macmsg; | 769 | struct Wlan_Helper_Control_Message macmsg; |
712 | 770 | ||
713 | macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message)); | 771 | macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message)); |
714 | macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); | 772 | macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); |
715 | memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress)); | 773 | memcpy (macmsg.mac, mac, sizeof (struct MacAddress)); |
716 | memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message)); | 774 | memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message)); |
717 | return sizeof (struct Wlan_Helper_Control_Message); | 775 | return sizeof (struct Wlan_Helper_Control_Message); |
718 | } | 776 | } |
777 | */ | ||
719 | 778 | ||
720 | 779 | //FIXME: doxigen | |
721 | static int | 780 | static int |
722 | hardwaremode (int argc, char *argv[]) | 781 | hardwaremode (int argc, char *argv[]) |
723 | { | 782 | { |
@@ -892,3 +951,79 @@ main (int argc, char *argv[]) | |||
892 | } | 951 | } |
893 | return hardwaremode (argc, argv); | 952 | return hardwaremode (argc, argv); |
894 | } | 953 | } |
954 | |||
955 | /* | ||
956 | * Copyright (c) 2008, Thomas d'Otreppe | ||
957 | * | ||
958 | * Common OSdep stuff | ||
959 | * | ||
960 | * This program is free software; you can redistribute it and/or modify | ||
961 | * it under the terms of the GNU General Public License as published by | ||
962 | * the Free Software Foundation; either version 2 of the License, or | ||
963 | * (at your option) any later version. | ||
964 | * | ||
965 | * This program is distributed in the hope that it will be useful, | ||
966 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
967 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
968 | * GNU General Public License for more details. | ||
969 | * | ||
970 | * You should have received a copy of the GNU General Public License | ||
971 | * along with this program; if not, write to the Free Software | ||
972 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
973 | */ | ||
974 | |||
975 | /** | ||
976 | * Return the frequency in Mhz from a channel number | ||
977 | */ | ||
978 | int | ||
979 | getFrequencyFromChannel (int channel) | ||
980 | { | ||
981 | static int frequencies[] = { | ||
982 | -1, // No channel 0 | ||
983 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, | ||
984 | 2472, 2484, | ||
985 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive) | ||
986 | 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, | ||
987 | 5230, 5235, 5240, 5245, | ||
988 | 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, | ||
989 | 5310, 5315, 5320, 5325, | ||
990 | 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, | ||
991 | 5390, 5395, 5400, 5405, | ||
992 | 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, | ||
993 | 5470, 5475, 5480, 5485, | ||
994 | 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, | ||
995 | 5550, 5555, 5560, 5565, | ||
996 | 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, | ||
997 | 5630, 5635, 5640, 5645, | ||
998 | 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, | ||
999 | 5710, 5715, 5720, 5725, | ||
1000 | 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, | ||
1001 | 5790, 5795, 5800, 5805, | ||
1002 | 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, | ||
1003 | 5870, 5875, 5880, 5885, | ||
1004 | 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, | ||
1005 | 5950, 5955, 5960, 5965, | ||
1006 | 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, | ||
1007 | 6030, 6035, 6040, 6045, | ||
1008 | 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100 | ||
1009 | }; | ||
1010 | |||
1011 | return (channel > 0 && channel <= 221) ? frequencies[channel] : -1; | ||
1012 | } | ||
1013 | |||
1014 | /** | ||
1015 | * Return the channel from the frequency (in Mhz) | ||
1016 | */ | ||
1017 | int | ||
1018 | getChannelFromFrequency (int frequency) | ||
1019 | { | ||
1020 | if (frequency >= 2412 && frequency <= 2472) | ||
1021 | return (frequency - 2407) / 5; | ||
1022 | else if (frequency == 2484) | ||
1023 | return 14; | ||
1024 | else if (frequency >= 5000 && frequency <= 6100) | ||
1025 | return (frequency - 5000) / 5; | ||
1026 | else | ||
1027 | return -1; | ||
1028 | } | ||
1029 | |||