aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-helper.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-04-12 23:33:44 +0000
committerDavid Brodski <david@brodski.eu>2011-04-12 23:33:44 +0000
commitd47e8be9228c131f93441743c8e90b360d554e9d (patch)
tree9a5d82775a5e7c46ac4ba01784f129a2c8db387c /src/transport/gnunet-transport-wlan-helper.c
parentd8cd4422e9d88a0c8180976179662ae2e890db6d (diff)
downloadgnunet-d47e8be9228c131f93441743c8e90b360d554e9d.tar.gz
gnunet-d47e8be9228c131f93441743c8e90b360d554e9d.zip
Big cleanup and heap used for fragments send and with the timeouts
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c456
1 files changed, 236 insertions, 220 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index e18a6e7c8..aaa34284d 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -92,7 +92,6 @@
92#define ARPHRD_IEEE80211_PRISM 802 92#define ARPHRD_IEEE80211_PRISM 802
93#define ARPHRD_IEEE80211_FULL 803 93#define ARPHRD_IEEE80211_FULL 803
94 94
95int first;
96int closeprog; 95int closeprog;
97 96
98#include "wlan/helper_common.h" 97#include "wlan/helper_common.h"
@@ -130,125 +129,129 @@ struct Hardware_Infos
130 129
131 struct sendbuf *write_pout; 130 struct sendbuf *write_pout;
132 int fd_in, arptype_in; 131 int fd_in, arptype_in;
133 int fd_out, arptype_out; 132 int fd_out;
134 int fd_main; 133 //int arptype_out;
135 int fd_rtc; 134 //int fd_main;
135 //int fd_rtc;
136 136
137 DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ 137 DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */
138 138
139 FILE *f_cap_in; 139 //FILE *f_cap_in;
140 140
141 struct pcap_file_header pfh_in; 141 //struct pcap_file_header pfh_in;
142 142
143 int sysfs_inject; 143 //int sysfs_inject;
144 int channel; 144 //int channel;
145 int freq; 145 //int freq;
146 int rate; 146 //int rate;
147 int tx_power; 147 //int tx_power;
148 char *wlanctlng; /* XXX never set */ 148 //char *wlanctlng; /* XXX never set */
149 char *iwpriv; 149 //char *iwpriv;
150 char *iwconfig; 150 //char *iwconfig;
151 char *ifconfig; 151 //char *ifconfig;
152 char *iface; 152 char *iface;
153 char *main_if; 153 //char *main_if;
154 unsigned char pl_mac[6]; 154 unsigned char pl_mac[6];
155 int inject_wlanng; 155//int inject_wlanng;
156}; 156};
157 157
158//#include "radiotap.h" 158//#include "radiotap.h"
159 159
160// mac of this node 160// mac of this node
161char mac[] = 161/*char mac[] =
162 { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 }; 162 { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 };
163 163 */
164/* wifi bitrate to use in 500kHz units */ 164/* wifi bitrate to use in 500kHz units */
165 165
166static const u8 u8aRatesToUse[] = 166/*
167 { 167 static const u8 u8aRatesToUse[] =
168 168 {
169 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5
170 2 * 2, 1 * 2 };
171 169
172#define OFFSET_FLAGS 0x10 170 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5
173#define OFFSET_RATE 0x11 171 2 * 2, 1 * 2 };
174 172
173 #define OFFSET_FLAGS 0x10
174 #define OFFSET_RATE 0x11
175 */
175// this is where we store a summary of the 176// this is where we store a summary of the
176// information from the radiotap header 177// information from the radiotap header
177 178
178typedef struct 179/*
179{ 180 typedef struct
180 int m_nChannel; 181 {
181 int m_nChannelFlags; 182 int m_nChannel;
182 int m_nRate; 183 int m_nChannelFlags;
183 int m_nAntenna; 184 int m_nRate;
184 int m_nRadiotapFlags; 185 int m_nAntenna;
185}__attribute__((packed)) PENUMBRA_RADIOTAP_DATA; 186 int m_nRadiotapFlags;
186 187 }__attribute__((packed)) PENUMBRA_RADIOTAP_DATA;
188 */
187static void 189static void
188sigfunc_hw(int sig) 190sigfunc_hw(int sig)
189{ 191{
190 closeprog = 1; 192 closeprog = 1;
191} 193}
192 194
193void 195/*
194Dump(u8 * pu8, int nLength) 196 void
195{ 197 Dump(u8 * pu8, int nLength)
196 char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1; 198 {
197 unsigned char baaLast[2][16]; 199 char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1;
198 uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0; 200 unsigned char baaLast[2][16];
199 201 uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0;
200 buf = szBuf; 202
201 szChar[0] = '\0'; 203 buf = szBuf;
202 204 szChar[0] = '\0';
203 for (n = 0; n < nLength; n++) 205
204 { 206 for (n = 0; n < nLength; n++)
205 baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n]; 207 {
206 if ((pu8[n] < 32) || (pu8[n] >= 0x7f)) 208 baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n];
207 szChar[n & 0xf] = '.'; 209 if ((pu8[n] < 32) || (pu8[n] >= 0x7f))
208 else 210 szChar[n & 0xf] = '.';
209 szChar[n & 0xf] = pu8[n]; 211 else
210 szChar[(n & 0xf) + 1] = '\0'; 212 szChar[n & 0xf] = pu8[n];
211 nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]); 213 szChar[(n & 0xf) + 1] = '\0';
212 if ((n & 15) != 15) 214 nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]);
213 continue; 215 if ((n & 15) != 15)
214 if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) 216 continue;
215 { 217 if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst))
216 nSameCount++; 218 {
217 } 219 nSameCount++;
218 else 220 }
219 { 221 else
220 if (nSameCount) 222 {
221 buf += sprintf(buf, "(repeated %d times)\n", nSameCount); 223 if (nSameCount)
222 buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar); 224 buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
223 nSameCount = 0; 225 buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar);
224 printf("%s", szBuf); 226 nSameCount = 0;
225 buf = szBuf; 227 printf("%s", szBuf);
226 } 228 buf = szBuf;
227 nPos = 0; 229 }
228 nStart = n + 1; 230 nPos = 0;
229 nLine++; 231 nStart = n + 1;
230 fFirst = 0; 232 nLine++;
231 sz[0] = '\0'; 233 fFirst = 0;
232 szChar[0] = '\0'; 234 sz[0] = '\0';
233 } 235 szChar[0] = '\0';
234 if (nSameCount) 236 }
235 buf += sprintf(buf, "(repeated %d times)\n", nSameCount); 237 if (nSameCount)
236 238 buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
237 buf += sprintf(buf, "%04x: %s", nStart, sz); 239
238 if (n & 0xf) 240 buf += sprintf(buf, "%04x: %s", nStart, sz);
239 { 241 if (n & 0xf)
240 *buf++ = ' '; 242 {
241 while (n & 0xf) 243 *buf++ = ' ';
242 { 244 while (n & 0xf)
243 buf += sprintf(buf, " "); 245 {
244 n++; 246 buf += sprintf(buf, " ");
245 } 247 n++;
246 } 248 }
247 buf += sprintf(buf, "%s\n", szChar); 249 }
248 printf("%s", szBuf); 250 buf += sprintf(buf, "%s\n", szChar);
249} 251 printf("%s", szBuf);
250 252 }
251void 253 */
254static void
252usage() 255usage()
253{ 256{
254 printf("Usage: interface-name options\n" 257 printf("Usage: interface-name options\n"
@@ -259,7 +262,7 @@ usage()
259 exit(1); 262 exit(1);
260} 263}
261 264
262unsigned long 265static unsigned long
263calc_crc_osdep(unsigned char * buf, int len) 266calc_crc_osdep(unsigned char * buf, int len)
264{ 267{
265 unsigned long crc = 0xFFFFFFFF; 268 unsigned long crc = 0xFFFFFFFF;
@@ -272,7 +275,7 @@ calc_crc_osdep(unsigned char * buf, int len)
272 275
273/* CRC checksum verification routine */ 276/* CRC checksum verification routine */
274 277
275int 278static int
276check_crc_buf_osdep(unsigned char *buf, int len) 279check_crc_buf_osdep(unsigned char *buf, int len)
277{ 280{
278 unsigned long crc; 281 unsigned long crc;
@@ -287,83 +290,86 @@ check_crc_buf_osdep(unsigned char *buf, int len)
287} 290}
288 291
289/* Search a file recursively */ 292/* Search a file recursively */
290static char * 293/*
291searchInside(const char * dir, const char * filename) 294 static char *
292{ 295 searchInside(const char * dir, const char * filename)
293 char * ret; 296 {
294 char * curfile; 297 char * ret;
295 struct stat sb; 298 char * curfile;
296 int len, lentot; 299 struct stat sb;
297 DIR *dp; 300 int len, lentot;
298 struct dirent *ep; 301 DIR *dp;
299 302 struct dirent *ep;
300 dp = opendir(dir); 303
301 if (dp == NULL) 304 dp = opendir(dir);
302 { 305 if (dp == NULL)
303 return NULL; 306 {
304 } 307 return NULL;
305 308 }
306 len = strlen(filename); 309
307 lentot = strlen(dir) + 256 + 2; 310 len = strlen(filename);
308 curfile = (char *) calloc(1, lentot); 311 lentot = strlen(dir) + 256 + 2;
309 312 curfile = (char *) calloc(1, lentot);
310 while ((ep = readdir(dp)) != NULL) 313
311 { 314 while ((ep = readdir(dp)) != NULL)
312 315 {
313 memset(curfile, 0, lentot); 316
314 sprintf(curfile, "%s/%s", dir, ep->d_name); 317 memset(curfile, 0, lentot);
315 318 sprintf(curfile, "%s/%s", dir, ep->d_name);
316 //Checking if it's the good file 319
317 if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename)) 320 //Checking if it's the good file
318 { 321 if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename))
319 (void) closedir(dp); 322 {
320 return curfile; 323 (void) closedir(dp);
321 } 324 return curfile;
322 lstat(curfile, &sb); 325 }
323 326 lstat(curfile, &sb);
324 //If it's a directory and not a link, try to go inside to search 327
325 if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) 328 //If it's a directory and not a link, try to go inside to search
326 { 329 if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode))
327 //Check if the directory isn't "." or ".." 330 {
328 if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) 331 //Check if the directory isn't "." or ".."
329 { 332 if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name))
330 //Recursive call 333 {
331 ret = searchInside(curfile, filename); 334 //Recursive call
332 if (ret != NULL) 335 ret = searchInside(curfile, filename);
333 { 336 if (ret != NULL)
334 (void) closedir(dp); 337 {
335 free(curfile); 338 (void) closedir(dp);
336 return ret; 339 free(curfile);
337 } 340 return ret;
338 } 341 }
339 } 342 }
340 } 343 }
341 (void) closedir(dp); 344 }
342 free(curfile); 345 (void) closedir(dp);
343 return NULL; 346 free(curfile);
344} 347 return NULL;
345 348 }
349 */
346/* Search a wireless tool and return its path */ 350/* Search a wireless tool and return its path */
347static char * 351/*
348wiToolsPath(const char * tool) 352 static char *
349{ 353 wiToolsPath(const char * tool)
350 char * path; 354 {
351 int i, nbelems; 355 char * path;
352 static const char * paths[] = 356 int i, nbelems;
353 { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin", 357 static const char * paths[] =
354 "/usr/local/bin", "/tmp" }; 358 { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin",
355 359 "/usr/local/bin", "/tmp" };
356 nbelems = sizeof(paths) / sizeof(char *); 360
357 361 nbelems = sizeof(paths) / sizeof(char *);
358 for (i = 0; i < nbelems; i++) 362
359 { 363 for (i = 0; i < nbelems; i++)
360 path = searchInside(paths[i], tool); 364 {
361 if (path != NULL) 365 path = searchInside(paths[i], tool);
362 return path; 366 if (path != NULL)
363 } 367 return path;
364 368 }
365 return NULL; 369
366} 370 return NULL;
371 }
372 */
367 373
368static int 374static int
369linux_get_channel(struct Hardware_Infos *dev) 375linux_get_channel(struct Hardware_Infos *dev)
@@ -374,15 +380,17 @@ linux_get_channel(struct Hardware_Infos *dev)
374 380
375 memset(&wrq, 0, sizeof(struct iwreq)); 381 memset(&wrq, 0, sizeof(struct iwreq));
376 382
377 if (dev->main_if) 383 /*
378 strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ ); 384 if (dev->main_if)
379 else 385 strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ );
380 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); 386 else*/
387 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ );
381 388
382 fd = dev->fd_in; 389 fd = dev->fd_in;
383 if (dev->drivertype == DT_IPW2200) 390 /*
384 fd = dev->fd_main; 391 if (dev->drivertype == DT_IPW2200)
385 392 fd = dev->fd_main;
393 */
386 if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) 394 if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0)
387 return (-1); 395 return (-1);
388 396
@@ -770,43 +778,45 @@ int
770wlaninit(struct Hardware_Infos * dev, char *iface) 778wlaninit(struct Hardware_Infos * dev, char *iface)
771{ 779{
772 780
773 char *iwpriv; 781 //char *iwpriv;
774 char strbuf[512]; 782 char strbuf[512];
775 dev->inject_wlanng = 1; 783 //dev->inject_wlanng = 1;
776 dev->rate = 2; /* default to 1Mbps if nothing is set */ 784 //dev->rate = 2; /* default to 1Mbps if nothing is set */
777 785
778 /* open raw socks */ 786 /* open raw socks */
779 dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 787 /*
780 if (0 > dev->fd_in) 788 dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
781 { 789 if (0 > dev->fd_in)
782 perror("socket(PF_PACKET) failed at fd_in"); 790 {
783 if (getuid() != 0) 791 perror("socket(PF_PACKET) failed at fd_in");
784 fprintf(stderr, "This program requires root privileges.\n"); 792 if (getuid() != 0)
785 return (1); 793 fprintf(stderr, "This program requires root privileges.\n");
786 } 794 return (1);
787 795 }
788 dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ); 796 */
789 if (0 > dev->fd_main) 797 /*
790 { 798 dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) );
791 perror("socket(PF_PACKET) failed at fd_main"); 799 if (0 > dev->fd_main)
792 if (getuid() != 0) 800 {
793 fprintf(stderr, "This program requires root privileges.\n"); 801 perror("socket(PF_PACKET) failed at fd_main");
794 return (1); 802 if (getuid() != 0)
795 } 803 fprintf(stderr, "This program requires root privileges.\n");
796 804 return (1);
805 }
806 */
797 /* Check iwpriv existence */ 807 /* Check iwpriv existence */
808 /*
809 iwpriv = wiToolsPath("iwpriv");
810 dev->iwpriv = iwpriv;
811 dev->iwconfig = wiToolsPath("iwconfig");
812 dev->ifconfig = wiToolsPath("ifconfig");
798 813
799 iwpriv = wiToolsPath("iwpriv"); 814 if (!iwpriv)
800 dev->iwpriv = iwpriv; 815 {
801 dev->iwconfig = wiToolsPath("iwconfig"); 816 fprintf(stderr, "Can't find wireless tools, exiting.\n");
802 dev->ifconfig = wiToolsPath("ifconfig"); 817 goto close_in;
803 818 }
804 if (!iwpriv) 819 */
805 {
806 fprintf(stderr, "Can't find wireless tools, exiting.\n");
807 goto close_in;
808 }
809
810 dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 820 dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
811 if (0 > dev->fd_out) 821 if (0 > dev->fd_out)
812 { 822 {
@@ -836,6 +846,7 @@ wlaninit(struct Hardware_Infos * dev, char *iface)
836 else 846 else
837 { 847 {
838 // At the moment only mac80211 tested 848 // At the moment only mac80211 tested
849 fprintf(stderr, "only mac80211 stack supported, exiting.\n");
839 return 1; 850 return 1;
840 } 851 }
841 852
@@ -844,14 +855,16 @@ wlaninit(struct Hardware_Infos * dev, char *iface)
844 szaDriverTypes[dev->drivertype]); 855 szaDriverTypes[dev->drivertype]);
845#endif 856#endif
846 857
847 if (openraw(dev, iface, dev->fd_out, &dev->arptype_out, dev->pl_mac) != 0) 858 if (openraw(dev, iface, dev->fd_out, &dev->arptype_in, dev->pl_mac) != 0)
848 { 859 {
849 goto close_out; 860 goto close_out;
850 } 861 }
851 862
852 dev->fd_in = dev->fd_out; 863 dev->fd_in = dev->fd_out;
864 dev->iface = GNUNET_malloc(sizeof(char) *6);
865 strncpy(dev->iface, iface, sizeof(char) * 6);
853 866
854 dev->arptype_in = dev->arptype_out; 867 //dev->arptype_out = dev->arptype_in;
855 868
856 return 0; 869 return 0;
857 close_out: close(dev->fd_out); 870 close_out: close(dev->fd_out);
@@ -961,7 +974,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
961 + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), 974 + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader),
962 sendsize); 975 sendsize);
963 976
964 wlanheader = write_pout->buf + sizeof(u8aRadiotap); 977 wlanheader = write_pout->buf + sizeof(u8aRadiotap);
965 mac_set(wlanheader, dev); 978 mac_set(wlanheader, dev);
966 979
967 sendsize += sizeof(u8aRadiotap); 980 sendsize += sizeof(u8aRadiotap);
@@ -974,7 +987,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
974 write_pout->size = sendsize; 987 write_pout->size = sendsize;
975} 988}
976 989
977int 990static int
978maketest(unsigned char * buf, struct Hardware_Infos * dev) 991maketest(unsigned char * buf, struct Hardware_Infos * dev)
979{ 992{
980 uint16_t * tmp16; 993 uint16_t * tmp16;
@@ -1024,8 +1037,8 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev)
1024 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver 1037 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
1025 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver 1038 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
1026 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender 1039 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
1027 0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4, 1040 //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
1028 //0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid 1041 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
1029 0x10, 0x86, //Sequence Control 1042 0x10, 0x86, //Sequence Control
1030 }; 1043 };
1031 if (first == 0) 1044 if (first == 0)
@@ -1117,7 +1130,7 @@ hardwaremode(int argc, char *argv[])
1117 write_pout.size = maketest(write_pout.buf, &dev); 1130 write_pout.size = maketest(write_pout.buf, &dev);
1118 tv.tv_sec = 2; 1131 tv.tv_sec = 2;
1119 tv.tv_usec = 0; 1132 tv.tv_usec = 0;
1120 retval = select(0, NULL, NULL, NULL, &tv); 1133 select(0, NULL, NULL, NULL, &tv);
1121 1134
1122 maxfd = 0; 1135 maxfd = 0;
1123 1136
@@ -1172,7 +1185,7 @@ hardwaremode(int argc, char *argv[])
1172 { 1185 {
1173 closeprog = 1; 1186 closeprog = 1;
1174 fprintf(stderr, "Write ERROR to STDOUT\n"); 1187 fprintf(stderr, "Write ERROR to STDOUT\n");
1175 exit(1); 1188 goto end;
1176 } 1189 }
1177 else 1190 else
1178 { 1191 {
@@ -1276,6 +1289,9 @@ hardwaremode(int argc, char *argv[])
1276 GNUNET_SERVER_mst_destroy(stdin_mst); 1289 GNUNET_SERVER_mst_destroy(stdin_mst);
1277 return 0; 1290 return 0;
1278 1291
1292 end: GNUNET_SERVER_mst_destroy(stdin_mst);
1293 return 1;
1294
1279} 1295}
1280 1296
1281int 1297int