diff options
author | David Brodski <david@brodski.eu> | 2011-04-20 04:51:01 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-04-20 04:51:01 +0000 |
commit | d0d88da8754bd5184be826dc4d271c5abeece0c5 (patch) | |
tree | 610d7d600a82d464dd4cb56b2dee5c3890f18d3e /src/transport | |
parent | ff74c423c7528e4920a7591e0e64b0b282a81bec (diff) | |
download | gnunet-d0d88da8754bd5184be826dc4d271c5abeece0c5.tar.gz gnunet-d0d88da8754bd5184be826dc4d271c5abeece0c5.zip |
More cleanup, some errors, message in timeout implemented
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 548 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 261 | ||||
-rw-r--r-- | src/transport/test_transport_api_wlan_peer1.conf | 4 | ||||
-rw-r--r-- | src/transport/test_transport_api_wlan_peer2.conf | 4 |
4 files changed, 193 insertions, 624 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 2cb14b4c6..633b2776c 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -131,37 +131,14 @@ struct Hardware_Infos | |||
131 | struct sendbuf *write_pout; | 131 | struct sendbuf *write_pout; |
132 | int fd_in, arptype_in; | 132 | int fd_in, arptype_in; |
133 | int fd_out; | 133 | int fd_out; |
134 | //int arptype_out; | ||
135 | //int fd_main; | ||
136 | //int fd_rtc; | ||
137 | 134 | ||
138 | DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ | 135 | DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ |
139 | 136 | ||
140 | //FILE *f_cap_in; | ||
141 | |||
142 | //struct pcap_file_header pfh_in; | ||
143 | |||
144 | //int sysfs_inject; | ||
145 | //int channel; | ||
146 | //int freq; | ||
147 | //int rate; | ||
148 | //int tx_power; | ||
149 | //char *wlanctlng; /* XXX never set */ | ||
150 | //char *iwpriv; | ||
151 | //char *iwconfig; | ||
152 | //char *ifconfig; | ||
153 | char *iface; | 137 | char *iface; |
154 | //char *main_if; | ||
155 | unsigned char pl_mac[6]; | 138 | unsigned char pl_mac[6]; |
156 | //int inject_wlanng; | ||
157 | }; | 139 | }; |
158 | 140 | ||
159 | //#include "radiotap.h" | ||
160 | 141 | ||
161 | // mac of this node | ||
162 | /*char mac[] = | ||
163 | { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 }; | ||
164 | */ | ||
165 | /* wifi bitrate to use in 500kHz units */ | 142 | /* wifi bitrate to use in 500kHz units */ |
166 | 143 | ||
167 | /* | 144 | /* |
@@ -171,87 +148,13 @@ struct Hardware_Infos | |||
171 | 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5 | 148 | 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5 |
172 | 2 * 2, 1 * 2 }; | 149 | 2 * 2, 1 * 2 }; |
173 | 150 | ||
174 | #define OFFSET_FLAGS 0x10 | 151 | */ |
175 | #define OFFSET_RATE 0x11 | ||
176 | */ | ||
177 | // this is where we store a summary of the | ||
178 | // information from the radiotap header | ||
179 | |||
180 | /* | ||
181 | typedef struct | ||
182 | { | ||
183 | int m_nChannel; | ||
184 | int m_nChannelFlags; | ||
185 | int m_nRate; | ||
186 | int m_nAntenna; | ||
187 | int m_nRadiotapFlags; | ||
188 | }__attribute__((packed)) PENUMBRA_RADIOTAP_DATA; | ||
189 | */ | ||
190 | static void | 152 | static void |
191 | sigfunc_hw(int sig) | 153 | sigfunc_hw(int sig) |
192 | { | 154 | { |
193 | closeprog = 1; | 155 | closeprog = 1; |
194 | } | 156 | } |
195 | 157 | ||
196 | /* | ||
197 | void | ||
198 | Dump(u8 * pu8, int nLength) | ||
199 | { | ||
200 | char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1; | ||
201 | unsigned char baaLast[2][16]; | ||
202 | uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0; | ||
203 | |||
204 | buf = szBuf; | ||
205 | szChar[0] = '\0'; | ||
206 | |||
207 | for (n = 0; n < nLength; n++) | ||
208 | { | ||
209 | baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n]; | ||
210 | if ((pu8[n] < 32) || (pu8[n] >= 0x7f)) | ||
211 | szChar[n & 0xf] = '.'; | ||
212 | else | ||
213 | szChar[n & 0xf] = pu8[n]; | ||
214 | szChar[(n & 0xf) + 1] = '\0'; | ||
215 | nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]); | ||
216 | if ((n & 15) != 15) | ||
217 | continue; | ||
218 | if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) | ||
219 | { | ||
220 | nSameCount++; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | if (nSameCount) | ||
225 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); | ||
226 | buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar); | ||
227 | nSameCount = 0; | ||
228 | printf("%s", szBuf); | ||
229 | buf = szBuf; | ||
230 | } | ||
231 | nPos = 0; | ||
232 | nStart = n + 1; | ||
233 | nLine++; | ||
234 | fFirst = 0; | ||
235 | sz[0] = '\0'; | ||
236 | szChar[0] = '\0'; | ||
237 | } | ||
238 | if (nSameCount) | ||
239 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); | ||
240 | |||
241 | buf += sprintf(buf, "%04x: %s", nStart, sz); | ||
242 | if (n & 0xf) | ||
243 | { | ||
244 | *buf++ = ' '; | ||
245 | while (n & 0xf) | ||
246 | { | ||
247 | buf += sprintf(buf, " "); | ||
248 | n++; | ||
249 | } | ||
250 | } | ||
251 | buf += sprintf(buf, "%s\n", szChar); | ||
252 | printf("%s", szBuf); | ||
253 | } | ||
254 | */ | ||
255 | static void | 158 | static void |
256 | usage() | 159 | usage() |
257 | { | 160 | { |
@@ -280,7 +183,7 @@ check_crc_buf_osdep(unsigned char *buf, int len) | |||
280 | { | 183 | { |
281 | unsigned long crc; | 184 | unsigned long crc; |
282 | 185 | ||
283 | if (len < 0) | 186 | if (0 > len) |
284 | return 0; | 187 | return 0; |
285 | 188 | ||
286 | crc = calc_crc_osdep(buf, len); | 189 | crc = calc_crc_osdep(buf, len); |
@@ -289,88 +192,6 @@ check_crc_buf_osdep(unsigned char *buf, int len) | |||
289 | >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); | 192 | >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); |
290 | } | 193 | } |
291 | 194 | ||
292 | /* Search a file recursively */ | ||
293 | /* | ||
294 | static char * | ||
295 | searchInside(const char * dir, const char * filename) | ||
296 | { | ||
297 | char * ret; | ||
298 | char * curfile; | ||
299 | struct stat sb; | ||
300 | int len, lentot; | ||
301 | DIR *dp; | ||
302 | struct dirent *ep; | ||
303 | |||
304 | dp = opendir(dir); | ||
305 | if (dp == NULL) | ||
306 | { | ||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | len = strlen(filename); | ||
311 | lentot = strlen(dir) + 256 + 2; | ||
312 | curfile = (char *) calloc(1, lentot); | ||
313 | |||
314 | while ((ep = readdir(dp)) != NULL) | ||
315 | { | ||
316 | |||
317 | memset(curfile, 0, lentot); | ||
318 | sprintf(curfile, "%s/%s", dir, ep->d_name); | ||
319 | |||
320 | //Checking if it's the good file | ||
321 | if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename)) | ||
322 | { | ||
323 | (void) closedir(dp); | ||
324 | return curfile; | ||
325 | } | ||
326 | lstat(curfile, &sb); | ||
327 | |||
328 | //If it's a directory and not a link, try to go inside to search | ||
329 | if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) | ||
330 | { | ||
331 | //Check if the directory isn't "." or ".." | ||
332 | if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) | ||
333 | { | ||
334 | //Recursive call | ||
335 | ret = searchInside(curfile, filename); | ||
336 | if (ret != NULL) | ||
337 | { | ||
338 | (void) closedir(dp); | ||
339 | free(curfile); | ||
340 | return ret; | ||
341 | } | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | (void) closedir(dp); | ||
346 | free(curfile); | ||
347 | return NULL; | ||
348 | } | ||
349 | */ | ||
350 | /* Search a wireless tool and return its path */ | ||
351 | /* | ||
352 | static char * | ||
353 | wiToolsPath(const char * tool) | ||
354 | { | ||
355 | char * path; | ||
356 | int i, nbelems; | ||
357 | static const char * paths[] = | ||
358 | { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin", | ||
359 | "/usr/local/bin", "/tmp" }; | ||
360 | |||
361 | nbelems = sizeof(paths) / sizeof(char *); | ||
362 | |||
363 | for (i = 0; i < nbelems; i++) | ||
364 | { | ||
365 | path = searchInside(paths[i], tool); | ||
366 | if (path != NULL) | ||
367 | return path; | ||
368 | } | ||
369 | |||
370 | return NULL; | ||
371 | } | ||
372 | */ | ||
373 | |||
374 | static int | 195 | static int |
375 | linux_get_channel(struct Hardware_Infos *dev) | 196 | linux_get_channel(struct Hardware_Infos *dev) |
376 | { | 197 | { |
@@ -380,27 +201,19 @@ linux_get_channel(struct Hardware_Infos *dev) | |||
380 | 201 | ||
381 | memset(&wrq, 0, sizeof(struct iwreq)); | 202 | memset(&wrq, 0, sizeof(struct iwreq)); |
382 | 203 | ||
383 | /* | ||
384 | if (dev->main_if) | ||
385 | strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ ); | ||
386 | else*/ | ||
387 | strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); | 204 | strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); |
388 | 205 | ||
389 | fd = dev->fd_in; | 206 | fd = dev->fd_in; |
390 | /* | 207 | if (0 > ioctl(fd, SIOCGIWFREQ, &wrq)) |
391 | if (dev->drivertype == DT_IPW2200) | ||
392 | fd = dev->fd_main; | ||
393 | */ | ||
394 | if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) | ||
395 | return (-1); | 208 | return (-1); |
396 | 209 | ||
397 | frequency = wrq.u.freq.m; | 210 | frequency = wrq.u.freq.m; |
398 | if (frequency > 100000000) | 211 | if (100000000 < frequency ) |
399 | frequency /= 100000; | 212 | frequency /= 100000; |
400 | else if (frequency > 1000000) | 213 | else if (1000000 < frequency ) |
401 | frequency /= 1000; | 214 | frequency /= 1000; |
402 | 215 | ||
403 | if (frequency > 1000) | 216 | if (1000 < frequency) |
404 | chan = getChannelFromFrequency(frequency); | 217 | chan = getChannelFromFrequency(frequency); |
405 | else | 218 | else |
406 | chan = frequency; | 219 | chan = frequency; |
@@ -423,7 +236,7 @@ linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, | |||
423 | caplen = read(dev->fd_in, tmpbuf, count); | 236 | caplen = read(dev->fd_in, tmpbuf, count); |
424 | if (0 > caplen) | 237 | if (0 > caplen) |
425 | { | 238 | { |
426 | if (errno == EAGAIN) | 239 | if (EAGAIN == errno) |
427 | return (0); | 240 | return (0); |
428 | 241 | ||
429 | perror("read failed"); | 242 | perror("read failed"); |
@@ -432,11 +245,10 @@ linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, | |||
432 | 245 | ||
433 | memset(buf, 0, sizeof(buf)); | 246 | memset(buf, 0, sizeof(buf)); |
434 | 247 | ||
435 | /* XXX */ | ||
436 | if (ri) | 248 | if (ri) |
437 | memset(ri, 0, sizeof(*ri)); | 249 | memset(ri, 0, sizeof(*ri)); |
438 | 250 | ||
439 | if (dev->arptype_in == ARPHRD_IEEE80211_PRISM) | 251 | if (ARPHRD_IEEE80211_PRISM == dev->arptype_in ) |
440 | { | 252 | { |
441 | /* skip the prism header */ | 253 | /* skip the prism header */ |
442 | if (tmpbuf[7] == 0x40) | 254 | if (tmpbuf[7] == 0x40) |
@@ -476,7 +288,7 @@ linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, | |||
476 | return (0); | 288 | return (0); |
477 | } | 289 | } |
478 | 290 | ||
479 | if (dev->arptype_in == ARPHRD_IEEE80211_FULL) | 291 | if (ARPHRD_IEEE80211_FULL == dev->arptype_in) |
480 | { | 292 | { |
481 | struct ieee80211_radiotap_iterator iterator; | 293 | struct ieee80211_radiotap_iterator iterator; |
482 | struct ieee80211_radiotap_header *rthdr; | 294 | struct ieee80211_radiotap_header *rthdr; |
@@ -588,7 +400,7 @@ linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, | |||
588 | caplen -= n; | 400 | caplen -= n; |
589 | 401 | ||
590 | //detect fcs at the end, even if the flag wasn't set and remove it | 402 | //detect fcs at the end, even if the flag wasn't set and remove it |
591 | if (fcs_removed == 0 && check_crc_buf_osdep(tmpbuf + n, caplen - 4) == 1) | 403 | if (0 == fcs_removed && 1== check_crc_buf_osdep(tmpbuf + n, caplen - 4)) |
592 | { | 404 | { |
593 | caplen -= 4; | 405 | caplen -= 4; |
594 | } | 406 | } |
@@ -615,7 +427,7 @@ linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count) | |||
615 | //usedrtap = 0; | 427 | //usedrtap = 0; |
616 | ret = write(dev->fd_out, buf, count); | 428 | ret = write(dev->fd_out, buf, count); |
617 | 429 | ||
618 | if (ret < 0) | 430 | if (0 > ret) |
619 | { | 431 | { |
620 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno | 432 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno |
621 | == ENOMEM) | 433 | == ENOMEM) |
@@ -632,7 +444,7 @@ linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count) | |||
632 | /*if (usedrtap) | 444 | /*if (usedrtap) |
633 | ret -= letoh16(*p_rtlen); | 445 | ret -= letoh16(*p_rtlen); |
634 | 446 | ||
635 | if (ret < 0) | 447 | if (0 > ret) |
636 | { | 448 | { |
637 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno | 449 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno |
638 | == ENOMEM) | 450 | == ENOMEM) |
@@ -662,7 +474,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
662 | memset(&ifr, 0, sizeof(ifr)); | 474 | memset(&ifr, 0, sizeof(ifr)); |
663 | strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1); | 475 | strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1); |
664 | 476 | ||
665 | if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) | 477 | if (0 > ioctl(fd, SIOCGIFINDEX, &ifr)) |
666 | { | 478 | { |
667 | printf("Interface %s: \n", iface); | 479 | printf("Interface %s: \n", iface); |
668 | perror("ioctl(SIOCGIFINDEX) failed"); | 480 | perror("ioctl(SIOCGIFINDEX) failed"); |
@@ -677,7 +489,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
677 | 489 | ||
678 | /* lookup the hardware type */ | 490 | /* lookup the hardware type */ |
679 | 491 | ||
680 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) | 492 | if (0 > ioctl(fd, SIOCGIFHWADDR, &ifr)) |
681 | { | 493 | { |
682 | printf("Interface %s: \n", iface); | 494 | printf("Interface %s: \n", iface); |
683 | perror("ioctl(SIOCGIFHWADDR) failed"); | 495 | perror("ioctl(SIOCGIFHWADDR) failed"); |
@@ -688,7 +500,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
688 | memset(&wrq, 0, sizeof(struct iwreq)); | 500 | memset(&wrq, 0, sizeof(struct iwreq)); |
689 | strncpy(wrq.ifr_name, iface, IFNAMSIZ); | 501 | strncpy(wrq.ifr_name, iface, IFNAMSIZ); |
690 | 502 | ||
691 | if (ioctl(fd, SIOCGIWMODE, &wrq) < 0) | 503 | if (0 > ioctl(fd, SIOCGIWMODE, &wrq)) |
692 | { | 504 | { |
693 | /* most probably not supported (ie for rtap ipw interface) * | 505 | /* most probably not supported (ie for rtap ipw interface) * |
694 | * so just assume its correctly set... */ | 506 | * so just assume its correctly set... */ |
@@ -717,7 +529,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
717 | } | 529 | } |
718 | /* bind the raw socket to the interface */ | 530 | /* bind the raw socket to the interface */ |
719 | 531 | ||
720 | if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0) | 532 | if (0 > bind(fd, (struct sockaddr *) &sll, sizeof(sll))) |
721 | { | 533 | { |
722 | printf("Interface %s: \n", iface); | 534 | printf("Interface %s: \n", iface); |
723 | perror("bind(ETH_P_ALL) failed"); | 535 | perror("bind(ETH_P_ALL) failed"); |
@@ -726,7 +538,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
726 | 538 | ||
727 | /* lookup the hardware type */ | 539 | /* lookup the hardware type */ |
728 | 540 | ||
729 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) | 541 | if (0 > ioctl(fd, SIOCGIFHWADDR, &ifr)) |
730 | { | 542 | { |
731 | printf("Interface %s: \n", iface); | 543 | printf("Interface %s: \n", iface); |
732 | perror("ioctl(SIOCGIFHWADDR) failed"); | 544 | perror("ioctl(SIOCGIFHWADDR) failed"); |
@@ -741,7 +553,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
741 | != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family | 553 | != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family |
742 | != ARPHRD_IEEE80211_FULL) | 554 | != ARPHRD_IEEE80211_FULL) |
743 | { | 555 | { |
744 | if (ifr.ifr_hwaddr.sa_family == 1) | 556 | if (1 == ifr.ifr_hwaddr.sa_family) |
745 | fprintf(stderr, "\nARP linktype is set to 1 (Ethernet) "); | 557 | fprintf(stderr, "\nARP linktype is set to 1 (Ethernet) "); |
746 | else | 558 | else |
747 | fprintf(stderr, "\nUnsupported hardware link type %4d ", | 559 | fprintf(stderr, "\nUnsupported hardware link type %4d ", |
@@ -773,46 +585,8 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, | |||
773 | int | 585 | int |
774 | wlaninit(struct Hardware_Infos * dev, char *iface) | 586 | wlaninit(struct Hardware_Infos * dev, char *iface) |
775 | { | 587 | { |
776 | |||
777 | //char *iwpriv; | ||
778 | char strbuf[512]; | 588 | char strbuf[512]; |
779 | //dev->inject_wlanng = 1; | ||
780 | //dev->rate = 2; /* default to 1Mbps if nothing is set */ | ||
781 | 589 | ||
782 | /* open raw socks */ | ||
783 | /* | ||
784 | dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | ||
785 | if (0 > dev->fd_in) | ||
786 | { | ||
787 | perror("socket(PF_PACKET) failed at fd_in"); | ||
788 | if (getuid() != 0) | ||
789 | fprintf(stderr, "This program requires root privileges.\n"); | ||
790 | return (1); | ||
791 | } | ||
792 | */ | ||
793 | /* | ||
794 | dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ); | ||
795 | if (0 > dev->fd_main) | ||
796 | { | ||
797 | perror("socket(PF_PACKET) failed at fd_main"); | ||
798 | if (getuid() != 0) | ||
799 | fprintf(stderr, "This program requires root privileges.\n"); | ||
800 | return (1); | ||
801 | } | ||
802 | */ | ||
803 | /* Check iwpriv existence */ | ||
804 | /* | ||
805 | iwpriv = wiToolsPath("iwpriv"); | ||
806 | dev->iwpriv = iwpriv; | ||
807 | dev->iwconfig = wiToolsPath("iwconfig"); | ||
808 | dev->ifconfig = wiToolsPath("ifconfig"); | ||
809 | |||
810 | if (!iwpriv) | ||
811 | { | ||
812 | fprintf(stderr, "Can't find wireless tools, exiting.\n"); | ||
813 | goto close_in; | ||
814 | } | ||
815 | */ | ||
816 | dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | 590 | dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
817 | if (0 > dev->fd_out) | 591 | if (0 > dev->fd_out) |
818 | { | 592 | { |
@@ -836,7 +610,7 @@ wlaninit(struct Hardware_Infos * dev, char *iface) | |||
836 | snprintf(strbuf, sizeof(strbuf) - 1, | 610 | snprintf(strbuf, sizeof(strbuf) - 1, |
837 | "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface); | 611 | "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface); |
838 | 612 | ||
839 | if (system(strbuf) == 0) | 613 | if (0 == system(strbuf)) |
840 | dev->drivertype = DT_MAC80211_RT; | 614 | dev->drivertype = DT_MAC80211_RT; |
841 | 615 | ||
842 | else | 616 | else |
@@ -860,7 +634,6 @@ wlaninit(struct Hardware_Infos * dev, char *iface) | |||
860 | dev->iface = GNUNET_malloc(sizeof(char) *6); | 634 | dev->iface = GNUNET_malloc(sizeof(char) *6); |
861 | strncpy(dev->iface, iface, sizeof(char) * 6); | 635 | strncpy(dev->iface, iface, sizeof(char) * 6); |
862 | 636 | ||
863 | //dev->arptype_out = dev->arptype_in; | ||
864 | 637 | ||
865 | return 0; | 638 | return 0; |
866 | close_out: close(dev->fd_out); | 639 | close_out: close(dev->fd_out); |
@@ -938,7 +711,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
938 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) | 711 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) |
939 | - sizeof(struct GNUNET_MessageHeader); | 712 | - sizeof(struct GNUNET_MessageHeader); |
940 | 713 | ||
941 | if ((sendsize) > MAXLINE * 2) | 714 | if (MAXLINE * 2 < sendsize) |
942 | { | 715 | { |
943 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); | 716 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); |
944 | exit(1); | 717 | exit(1); |
@@ -950,8 +723,8 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
950 | exit(1); | 723 | exit(1); |
951 | } | 724 | } |
952 | 725 | ||
953 | if (sendsize < sizeof(struct ieee80211_frame) | 726 | if ( sizeof(struct ieee80211_frame) |
954 | + sizeof(struct GNUNET_MessageHeader)) | 727 | + sizeof(struct GNUNET_MessageHeader) > sendsize) |
955 | { | 728 | { |
956 | fprintf(stderr, "Function stdin_send: packet too small\n"); | 729 | fprintf(stderr, "Function stdin_send: packet too small\n"); |
957 | exit(1); | 730 | exit(1); |
@@ -1034,7 +807,7 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev) | |||
1034 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid | 807 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid |
1035 | 0x10, 0x86, //Sequence Control | 808 | 0x10, 0x86, //Sequence Control |
1036 | }; | 809 | }; |
1037 | if (first == 0) | 810 | if (0 == first) |
1038 | { | 811 | { |
1039 | memcpy(&u8aIeeeHeader, u8aIeeeHeader_def, sizeof(struct ieee80211_frame)); | 812 | memcpy(&u8aIeeeHeader, u8aIeeeHeader_def, sizeof(struct ieee80211_frame)); |
1040 | memcpy(u8aIeeeHeader.i_addr2, dev->pl_mac, 6); | 813 | memcpy(u8aIeeeHeader.i_addr2, dev->pl_mac, 6); |
@@ -1062,7 +835,6 @@ hardwaremode(int argc, char *argv[]) | |||
1062 | 835 | ||
1063 | uid_t uid; | 836 | uid_t uid; |
1064 | struct Hardware_Infos dev; | 837 | struct Hardware_Infos dev; |
1065 | //struct ifreq ifreq; | ||
1066 | struct Radiotap_rx * rxinfo; | 838 | struct Radiotap_rx * rxinfo; |
1067 | uint8_t * mac = dev.pl_mac; | 839 | uint8_t * mac = dev.pl_mac; |
1068 | int fdpin, fdpout; | 840 | int fdpin, fdpout; |
@@ -1084,12 +856,6 @@ hardwaremode(int argc, char *argv[]) | |||
1084 | /* not critical, continue anyway */ | 856 | /* not critical, continue anyway */ |
1085 | //} | 857 | //} |
1086 | 858 | ||
1087 | /*printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", | ||
1088 | ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3], | ||
1089 | (int) mac[4], (int) mac[5]);*/ | ||
1090 | |||
1091 | //return 0; | ||
1092 | |||
1093 | unsigned char * datastart; | 859 | unsigned char * datastart; |
1094 | char readbuf[MAXLINE]; | 860 | char readbuf[MAXLINE]; |
1095 | int readsize = 0; | 861 | int readsize = 0; |
@@ -1293,11 +1059,6 @@ hardwaremode(int argc, char *argv[]) | |||
1293 | 1059 | ||
1294 | } | 1060 | } |
1295 | } | 1061 | } |
1296 | else | ||
1297 | { | ||
1298 | //eof | ||
1299 | //closeprog = 1; | ||
1300 | } | ||
1301 | } | 1062 | } |
1302 | 1063 | ||
1303 | } | 1064 | } |
@@ -1334,269 +1095,6 @@ main(int argc, char *argv[]) | |||
1334 | ret = hardwaremode(argc, argv); | 1095 | ret = hardwaremode(argc, argv); |
1335 | } | 1096 | } |
1336 | 1097 | ||
1337 | #if 0 | ||
1338 | u8 u8aSendBuffer[500]; | ||
1339 | char szErrbuf[PCAP_ERRBUF_SIZE]; | ||
1340 | int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0; | ||
1341 | int nOrdinal = 0, r, nDelay = 100000; | ||
1342 | int nRateIndex = 0, retval, bytes; | ||
1343 | pcap_t *ppcap = NULL; | ||
1344 | struct bpf_program bpfprogram; | ||
1345 | char * szProgram = "", fBrokenSocket = 0; | ||
1346 | u16 u16HeaderLen; | ||
1347 | char szHostname[PATH_MAX]; | ||
1348 | |||
1349 | if (gethostname(szHostname, sizeof (szHostname) - 1)) | ||
1350 | { | ||
1351 | perror("unable to get hostname"); | ||
1352 | } | ||
1353 | szHostname[sizeof (szHostname) - 1] = '\0'; | ||
1354 | |||
1355 | printf("Packetspammer (c)2007 Andy Green <andy@warmcat.com> GPL2\n"); | ||
1356 | |||
1357 | while (1) | ||
1358 | { | ||
1359 | int nOptionIndex; | ||
1360 | static const struct option optiona[] = | ||
1361 | { | ||
1362 | { "delay", required_argument, NULL, 'd'}, | ||
1363 | { "fcs", no_argument, &flagMarkWithFCS, 1}, | ||
1364 | { "help", no_argument, &flagHelp, 1}, | ||
1365 | { "verbose", no_argument, &flagVerbose, 1}, | ||
1366 | { 0, 0, 0, 0} | ||
1367 | }; | ||
1368 | int c = getopt_long(argc, argv, "d:hf", | ||
1369 | optiona, &nOptionIndex); | ||
1370 | |||
1371 | if (c == -1) | ||
1372 | break; | ||
1373 | switch (c) | ||
1374 | { | ||
1375 | case 0: // long option | ||
1376 | break; | ||
1377 | |||
1378 | case 'h': // help | ||
1379 | usage(); | ||
1380 | |||
1381 | case 'd': // delay | ||
1382 | nDelay = atoi(optarg); | ||
1383 | break; | ||
1384 | |||
1385 | case 'f': // mark as FCS attached | ||
1386 | flagMarkWithFCS = 1; | ||
1387 | break; | ||
1388 | |||
1389 | case 'v': //Verbose / readable output to cout | ||
1390 | flagVerbose = 1; | ||
1391 | break; | ||
1392 | |||
1393 | default: | ||
1394 | printf("unknown switch %c\n", c); | ||
1395 | usage(); | ||
1396 | break; | ||
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | if (optind >= argc) | ||
1401 | usage(); | ||
1402 | |||
1403 | // open the interface in pcap | ||
1404 | |||
1405 | szErrbuf[0] = '\0'; | ||
1406 | ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf); | ||
1407 | if (ppcap == NULL) | ||
1408 | { | ||
1409 | printf("Unable to open interface %s in pcap: %s\n", | ||
1410 | argv[optind], szErrbuf); | ||
1411 | return (1); | ||
1412 | } | ||
1413 | |||
1414 | //get mac from interface | ||
1415 | |||
1416 | /*int sock, j, k; | ||
1417 | char mac[32]; | ||
1418 | |||
1419 | sock=socket(PF_INET, SOCK_STREAM, 0); | ||
1420 | if (-1==sock) { | ||
1421 | perror("can not open socket\n"); | ||
1422 | return 1; | ||
1423 | } | ||
1424 | |||
1425 | if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) { | ||
1426 | perror("ioctl(SIOCGIFHWADDR) "); | ||
1427 | return 1; | ||
1428 | } | ||
1429 | for (j=0, k=0; j<6; j++) { | ||
1430 | k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X", | ||
1431 | (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]); | ||
1432 | } | ||
1433 | mac[sizeof(mac)-1]='\0'; | ||
1434 | */ | ||
1435 | |||
1436 | //get header type | ||
1437 | nLinkEncap = pcap_datalink(ppcap); | ||
1438 | nCaptureHeaderLength = 0; | ||
1439 | |||
1440 | switch (nLinkEncap) | ||
1441 | { | ||
1442 | |||
1443 | case DLT_PRISM_HEADER: | ||
1444 | printf("DLT_PRISM_HEADER Encap\n"); | ||
1445 | nCaptureHeaderLength = 0x40; | ||
1446 | n80211HeaderLength = 0x20; // ieee80211 comes after this | ||
1447 | szProgram = "radio[0x4a:4]==0x13223344"; | ||
1448 | break; | ||
1449 | |||
1450 | case DLT_IEEE802_11_RADIO: | ||
1451 | printf("DLT_IEEE802_11_RADIO Encap\n"); | ||
1452 | nCaptureHeaderLength = 0x40; | ||
1453 | n80211HeaderLength = 0x18; // ieee80211 comes after this | ||
1454 | szProgram = "ether[0x0a:4]==0x13223344"; | ||
1455 | break; | ||
1456 | |||
1457 | default: | ||
1458 | printf("!!! unknown encapsulation on %s !\n", argv[1]); | ||
1459 | return (1); | ||
1460 | |||
1461 | } | ||
1462 | |||
1463 | if (pcap_compile(ppcap, &bpfprogram, szProgram, 1, 0) == -1) | ||
1464 | { | ||
1465 | puts(szProgram); | ||
1466 | puts(pcap_geterr(ppcap)); | ||
1467 | return (1); | ||
1468 | } | ||
1469 | else | ||
1470 | { | ||
1471 | if (pcap_setfilter(ppcap, &bpfprogram) == -1) | ||
1472 | { | ||
1473 | puts(szProgram); | ||
1474 | puts(pcap_geterr(ppcap)); | ||
1475 | } | ||
1476 | else | ||
1477 | { | ||
1478 | printf("RX Filter applied\n"); | ||
1479 | } | ||
1480 | pcap_freecode(&bpfprogram); | ||
1481 | } | ||
1482 | |||
1483 | pcap_setnonblock(ppcap, 1, szErrbuf); | ||
1484 | |||
1485 | printf(" (delay between packets %dus)\n", nDelay); | ||
1486 | |||
1487 | memset(u8aSendBuffer, 0, sizeof(u8aSendBuffer)); | ||
1488 | |||
1489 | while (!fBrokenSocket) | ||
1490 | { | ||
1491 | u8 * pu8 = u8aSendBuffer; | ||
1492 | struct pcap_pkthdr * ppcapPacketHeader = NULL; | ||
1493 | struct ieee80211_radiotap_iterator rti; | ||
1494 | PENUMBRA_RADIOTAP_DATA prd; | ||
1495 | //init of the values | ||
1496 | prd.m_nRate = 255; | ||
1497 | prd.m_nChannel = 255; | ||
1498 | prd.m_nAntenna = 255; | ||
1499 | prd.m_nRadiotapFlags = 255; | ||
1500 | u8 * pu8Payload = u8aSendBuffer; | ||
1501 | int n, nRate; | ||
1502 | |||
1503 | // receive | ||
1504 | |||
1505 | retval = pcap_next_ex(ppcap, &ppcapPacketHeader, | ||
1506 | (const u_char**) &pu8Payload); | ||
1507 | |||
1508 | if (retval < 0) | ||
1509 | { | ||
1510 | fBrokenSocket = 1; | ||
1511 | continue; | ||
1512 | } | ||
1513 | |||
1514 | if (retval != 1) | ||
1515 | goto do_tx; | ||
1516 | |||
1517 | u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8)); | ||
1518 | |||
1519 | printf("rtap: "); | ||
1520 | Dump(pu8Payload, u16HeaderLen); | ||
1521 | |||
1522 | if (ppcapPacketHeader->len < (u16HeaderLen + n80211HeaderLength)) | ||
1523 | continue; | ||
1524 | |||
1525 | bytes = ppcapPacketHeader->len - (u16HeaderLen + n80211HeaderLength); | ||
1526 | if (bytes < 0) | ||
1527 | continue; | ||
1528 | |||
1529 | if (ieee80211_radiotap_iterator_init(&rti, | ||
1530 | (struct ieee80211_radiotap_header *) pu8Payload, bytes) < 0) | ||
1531 | continue; | ||
1532 | |||
1533 | while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0) | ||
1534 | { | ||
1535 | |||
1536 | switch (rti.this_arg_index) | ||
1537 | { | ||
1538 | case IEEE80211_RADIOTAP_RATE: | ||
1539 | prd.m_nRate = (*rti.this_arg); | ||
1540 | break; | ||
1541 | |||
1542 | case IEEE80211_RADIOTAP_CHANNEL: | ||
1543 | prd.m_nChannel = le16_to_cpu(*((u16 *)rti.this_arg)); | ||
1544 | prd.m_nChannelFlags = le16_to_cpu(*((u16 *)(rti.this_arg + 2))); | ||
1545 | break; | ||
1546 | |||
1547 | case IEEE80211_RADIOTAP_ANTENNA: | ||
1548 | prd.m_nAntenna = (*rti.this_arg) + 1; | ||
1549 | break; | ||
1550 | |||
1551 | case IEEE80211_RADIOTAP_FLAGS: | ||
1552 | prd.m_nRadiotapFlags = *rti.this_arg; | ||
1553 | break; | ||
1554 | |||
1555 | } | ||
1556 | } | ||
1557 | |||
1558 | pu8Payload += u16HeaderLen + n80211HeaderLength; | ||
1559 | |||
1560 | if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS) | ||
1561 | bytes -= 4; | ||
1562 | |||
1563 | printf("RX: Rate: %2d.%dMbps, Freq: %d.%dGHz, " | ||
1564 | "Ant: %d, Flags: 0x%X\n", prd.m_nRate / 2, 5 * (prd.m_nRate & 1), | ||
1565 | prd.m_nChannel / 1000, prd.m_nChannel - ((prd.m_nChannel / 1000) | ||
1566 | * 1000), prd.m_nAntenna, prd.m_nRadiotapFlags); | ||
1567 | |||
1568 | Dump(pu8Payload, bytes); | ||
1569 | |||
1570 | do_tx: | ||
1571 | |||
1572 | // transmit | ||
1573 | |||
1574 | memcpy(u8aSendBuffer, u8aRadiotapHeader, sizeof(u8aRadiotapHeader)); | ||
1575 | if (flagMarkWithFCS) | ||
1576 | pu8[OFFSET_FLAGS] |= IEEE80211_RADIOTAP_F_FCS; | ||
1577 | nRate = pu8[OFFSET_RATE] = u8aRatesToUse[nRateIndex++]; | ||
1578 | if (nRateIndex >= sizeof(u8aRatesToUse)) | ||
1579 | nRateIndex = 0; | ||
1580 | pu8 += sizeof(u8aRadiotapHeader); | ||
1581 | |||
1582 | memcpy(pu8, u8aIeeeHeader, sizeof(u8aIeeeHeader)); | ||
1583 | pu8 += sizeof(u8aIeeeHeader); | ||
1584 | |||
1585 | pu8 += sprintf((char *) u8aSendBuffer, "Packetspammer %02d" | ||
1586 | "broadcast packet" | ||
1587 | "#%05d -- :-D --%s ----", nRate / 2, nOrdinal++, szHostname); | ||
1588 | r = pcap_inject(ppcap, u8aSendBuffer, pu8 - u8aSendBuffer); | ||
1589 | if (r != (pu8 - u8aSendBuffer)) | ||
1590 | { | ||
1591 | perror("Trouble injecting packet"); | ||
1592 | return (1); | ||
1593 | } | ||
1594 | if (nDelay) | ||
1595 | usleep(nDelay); | ||
1596 | } | ||
1597 | |||
1598 | #endif | ||
1599 | |||
1600 | return ret; | 1098 | return ret; |
1601 | maketest(NULL, NULL); | 1099 | maketest(NULL, NULL); |
1602 | } | 1100 | } |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index f8178f101..f53e4b648 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -60,7 +60,7 @@ | |||
60 | 60 | ||
61 | #define HALLO_BEACON_SCALING_FACTOR 900 | 61 | #define HALLO_BEACON_SCALING_FACTOR 900 |
62 | 62 | ||
63 | #define DEBUG_wlan GNUNET_YES | 63 | #define DEBUG_wlan GNUNET_NO |
64 | #define DEBUG_wlan_retransmission GNUNET_NO | 64 | #define DEBUG_wlan_retransmission GNUNET_NO |
65 | 65 | ||
66 | #define MESSAGE_LENGHT_UNKNOWN -1 | 66 | #define MESSAGE_LENGHT_UNKNOWN -1 |
@@ -121,9 +121,13 @@ struct Plugin | |||
121 | struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer; | 121 | struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * encapsulation of packets received | 124 | * encapsulation of packets received from the wlan helper |
125 | */ | 125 | */ |
126 | struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer; | 126 | struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer; |
127 | /** | ||
128 | * encapsulation of packets received | ||
129 | */ | ||
130 | struct GNUNET_SERVER_MessageStreamTokenizer * fragment_tokenizer; | ||
127 | 131 | ||
128 | /** | 132 | /** |
129 | * stdout pipe handle for the gnunet-wlan-helper process | 133 | * stdout pipe handle for the gnunet-wlan-helper process |
@@ -179,7 +183,7 @@ struct Plugin | |||
179 | * Sessions currently pending for transmission | 183 | * Sessions currently pending for transmission |
180 | * to this peer, if any. | 184 | * to this peer, if any. |
181 | */ | 185 | */ |
182 | struct Sessionqueue * pending_Sessions; | 186 | struct Sessionqueue * pending_Sessions_head; |
183 | 187 | ||
184 | /** | 188 | /** |
185 | * Sessions currently pending for transmission | 189 | * Sessions currently pending for transmission |
@@ -244,7 +248,7 @@ struct Finish_send | |||
244 | /** | 248 | /** |
245 | * Queue of sessions, for the general session queue and the pending session queue | 249 | * Queue of sessions, for the general session queue and the pending session queue |
246 | */ | 250 | */ |
247 | 251 | //TODO DOXIGEN | |
248 | struct Sessionqueue | 252 | struct Sessionqueue |
249 | { | 253 | { |
250 | struct Sessionqueue * next; | 254 | struct Sessionqueue * next; |
@@ -255,6 +259,7 @@ struct Sessionqueue | |||
255 | /** | 259 | /** |
256 | * Queue for the fragments received | 260 | * Queue for the fragments received |
257 | */ | 261 | */ |
262 | //TODO DOXIGEN | ||
258 | struct Receive_Fragment_Queue | 263 | struct Receive_Fragment_Queue |
259 | { | 264 | { |
260 | struct Receive_Fragment_Queue * next; | 265 | struct Receive_Fragment_Queue * next; |
@@ -265,12 +270,15 @@ struct Receive_Fragment_Queue | |||
265 | struct Radiotap_rx rxinfo; | 270 | struct Radiotap_rx rxinfo; |
266 | }; | 271 | }; |
267 | 272 | ||
268 | struct Session_id_pair | 273 | //TODO DOXIGEN |
274 | struct Session_id_fragment_triple | ||
269 | { | 275 | { |
270 | struct Session * session; | 276 | struct Session * session; |
271 | uint32_t message_id; | 277 | uint32_t message_id; |
278 | struct FragmentMessage * fm; | ||
272 | }; | 279 | }; |
273 | 280 | ||
281 | //TODO DOXIGEN | ||
274 | struct Plugin_Session_pair | 282 | struct Plugin_Session_pair |
275 | { | 283 | { |
276 | struct Plugin * plugin; | 284 | struct Plugin * plugin; |
@@ -367,13 +375,20 @@ struct PendingMessage | |||
367 | /** | 375 | /** |
368 | * Queue for acks to send for fragments recived | 376 | * Queue for acks to send for fragments recived |
369 | */ | 377 | */ |
370 | //TODO comments | ||
371 | struct AckSendQueue | 378 | struct AckSendQueue |
372 | { | 379 | { |
373 | 380 | ||
381 | /** | ||
382 | * next ack in the ack send queue | ||
383 | */ | ||
374 | struct AckSendQueue * next; | 384 | struct AckSendQueue * next; |
385 | /** | ||
386 | * previous ack in the ack send queue | ||
387 | */ | ||
375 | struct AckSendQueue * prev; | 388 | struct AckSendQueue * prev; |
376 | 389 | /** | |
390 | * pointer to the session this ack belongs to | ||
391 | */ | ||
377 | struct Session * session; | 392 | struct Session * session; |
378 | /** | 393 | /** |
379 | * ID of message, to distinguish between the messages, picked randomly. | 394 | * ID of message, to distinguish between the messages, picked randomly. |
@@ -565,8 +580,6 @@ struct FragmentationAckHeader | |||
565 | 580 | ||
566 | }; | 581 | }; |
567 | 582 | ||
568 | static struct FragmentMessage * return_val; | ||
569 | |||
570 | static void | 583 | static void |
571 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 584 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
572 | 585 | ||
@@ -726,8 +739,7 @@ get_session(struct Plugin *plugin, const struct MacAddress *addr) | |||
726 | static void | 739 | static void |
727 | queue_session(struct Plugin *plugin, struct Session * session) | 740 | queue_session(struct Plugin *plugin, struct Session * session) |
728 | { | 741 | { |
729 | struct Sessionqueue * queue = plugin->pending_Sessions; | 742 | struct Sessionqueue * queue = plugin->pending_Sessions_head; |
730 | struct Sessionqueue * lastitem = NULL; | ||
731 | 743 | ||
732 | if (session->pending_message != NULL) | 744 | if (session->pending_message != NULL) |
733 | { | 745 | { |
@@ -741,7 +753,6 @@ queue_session(struct Plugin *plugin, struct Session * session) | |||
741 | return; | 753 | return; |
742 | } | 754 | } |
743 | // try next | 755 | // try next |
744 | lastitem = queue; | ||
745 | queue = queue->next; | 756 | queue = queue->next; |
746 | } | 757 | } |
747 | 758 | ||
@@ -751,16 +762,17 @@ queue_session(struct Plugin *plugin, struct Session * session) | |||
751 | queue->content = session; | 762 | queue->content = session; |
752 | 763 | ||
753 | //insert at the tail | 764 | //insert at the tail |
754 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions, | 765 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions_head, |
755 | plugin->pending_Sessions_tail, queue); | 766 | plugin->pending_Sessions_tail, queue); |
756 | plugin->pendingsessions++; | 767 | plugin->pendingsessions++; |
757 | } | 768 | } |
758 | 769 | ||
759 | } | 770 | } |
760 | 771 | ||
761 | //TODO doxigen | ||
762 | /** | 772 | /** |
763 | * Function to schedule the write task, executed after a delay | 773 | * Function to schedule the write task, executed after a delay |
774 | * @param cls pointer to the plugin struct | ||
775 | * @param tc GNUNET_SCHEDULER_TaskContext pointer | ||
764 | */ | 776 | */ |
765 | static void | 777 | static void |
766 | delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 778 | delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -780,10 +792,11 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
780 | } | 792 | } |
781 | } | 793 | } |
782 | 794 | ||
783 | //TODO doxigen | ||
784 | /** | 795 | /** |
785 | * Function to calculate the time of the next periodic "hello-beacon" | 796 | * Function to calculate the time of the next periodic "hello-beacon" |
797 | * @param plugin pointer to the plugin struct | ||
786 | */ | 798 | */ |
799 | |||
787 | static void | 800 | static void |
788 | set_next_beacon_time(struct Plugin * const plugin) | 801 | set_next_beacon_time(struct Plugin * const plugin) |
789 | { | 802 | { |
@@ -810,21 +823,11 @@ set_next_beacon_time(struct Plugin * const plugin) | |||
810 | } | 823 | } |
811 | } | 824 | } |
812 | 825 | ||
813 | //TODO doxigen | ||
814 | /* | ||
815 | static struct GNUNET_TIME_Relative | ||
816 | get_next_frag_timeout(struct FragmentMessage * fm) | ||
817 | { | ||
818 | return GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining( | ||
819 | fm->next_ack), GNUNET_TIME_absolute_get_remaining(fm->timeout)); | ||
820 | } | ||
821 | */ | ||
822 | |||
823 | //TODO doxigen | ||
824 | /** | 826 | /** |
825 | * Function to get the timeout value for acks for this session | 827 | * Function to get the timeout value for acks for this session |
828 | * @param fm pointer to the FragmentMessage to get the next timeout | ||
829 | * @return time until the next ack should be received, in GNUNET_TIME_Relative | ||
826 | */ | 830 | */ |
827 | |||
828 | static struct GNUNET_TIME_Relative | 831 | static struct GNUNET_TIME_Relative |
829 | get_ack_timeout(struct FragmentMessage * fm) | 832 | get_ack_timeout(struct FragmentMessage * fm) |
830 | { | 833 | { |
@@ -879,9 +882,20 @@ set_next_send(struct Plugin * const plugin) | |||
879 | 882 | ||
880 | #endif | 883 | #endif |
881 | 884 | ||
882 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, | 885 | if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value) |
883 | &delay_fragment_task, plugin); | 886 | { |
884 | 887 | if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK) | |
888 | { | ||
889 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( | ||
890 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, | ||
891 | &do_transmit, plugin); | ||
892 | } | ||
893 | } | ||
894 | else | ||
895 | { | ||
896 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, | ||
897 | &delay_fragment_task, plugin); | ||
898 | } | ||
885 | } | 899 | } |
886 | 900 | ||
887 | /** | 901 | /** |
@@ -896,15 +910,19 @@ get_next_queue_session(struct Plugin * plugin) | |||
896 | struct Sessionqueue * sessionqueue; | 910 | struct Sessionqueue * sessionqueue; |
897 | struct Sessionqueue * sessionqueue_alt; | 911 | struct Sessionqueue * sessionqueue_alt; |
898 | struct PendingMessage * pm; | 912 | struct PendingMessage * pm; |
899 | sessionqueue = plugin->pending_Sessions; | 913 | sessionqueue = plugin->pending_Sessions_head; |
900 | 914 | ||
901 | while (sessionqueue != NULL) | 915 | while (sessionqueue != NULL) |
902 | { | 916 | { |
903 | session = sessionqueue->content; | 917 | session = sessionqueue->content; |
904 | 918 | ||
905 | GNUNET_assert(session != NULL); | 919 | GNUNET_assert(session != NULL); |
920 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
921 | "Found session %p from pending session queue\n", session | ||
922 | ); | ||
906 | pm = session->pending_message; | 923 | pm = session->pending_message; |
907 | 924 | ||
925 | |||
908 | #if DEBUG_wlan | 926 | #if DEBUG_wlan |
909 | if (pm == NULL) | 927 | if (pm == NULL) |
910 | { | 928 | { |
@@ -924,7 +942,7 @@ get_next_queue_session(struct Plugin * plugin) | |||
924 | < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION) | 942 | < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION) |
925 | { | 943 | { |
926 | plugin->pendingsessions--; | 944 | plugin->pendingsessions--; |
927 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | 945 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, |
928 | plugin->pending_Sessions_tail, sessionqueue); | 946 | plugin->pending_Sessions_tail, sessionqueue); |
929 | GNUNET_free(sessionqueue); | 947 | GNUNET_free(sessionqueue); |
930 | 948 | ||
@@ -953,7 +971,7 @@ get_next_queue_session(struct Plugin * plugin) | |||
953 | sessionqueue_alt = sessionqueue; | 971 | sessionqueue_alt = sessionqueue; |
954 | sessionqueue = sessionqueue->next; | 972 | sessionqueue = sessionqueue->next; |
955 | plugin->pendingsessions--; | 973 | plugin->pendingsessions--; |
956 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | 974 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, |
957 | plugin->pending_Sessions_tail, sessionqueue_alt); | 975 | plugin->pending_Sessions_tail, sessionqueue_alt); |
958 | 976 | ||
959 | GNUNET_free(sessionqueue_alt); | 977 | GNUNET_free(sessionqueue_alt); |
@@ -1082,9 +1100,9 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1082 | 1100 | ||
1083 | #if DEBUG_wlan | 1101 | #if DEBUG_wlan |
1084 | if (maxack != 63) | 1102 | if (maxack != 63) |
1085 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1086 | "Test bitfields %X and %X, maxack is %u, fm size %u\n", | 1104 | "Test bitfields %X and %X, maxack is %u, fm size %u\n", |
1087 | fm->ack_bitfield, tmpfield, maxack, fm->message_size); | 1105 | fm->ack_bitfield, tmpfield, maxack, fm->message_size); |
1088 | #endif | 1106 | #endif |
1089 | 1107 | ||
1090 | if (fm->ack_bitfield == tmpfield) | 1108 | if (fm->ack_bitfield == tmpfield) |
@@ -1143,6 +1161,7 @@ set_next_message_fragment_pos(struct Plugin * plugin, | |||
1143 | 1161 | ||
1144 | } | 1162 | } |
1145 | 1163 | ||
1164 | //TODO DOXIGEN | ||
1146 | static int | 1165 | static int |
1147 | getRadiotapHeader(struct Plugin * plugin, struct Session * session, | 1166 | getRadiotapHeader(struct Plugin * plugin, struct Session * session, |
1148 | struct Radiotap_Send * header) | 1167 | struct Radiotap_Send * header) |
@@ -1223,6 +1242,7 @@ getcrc16(const char *msgbuf, size_t msgbuf_size) | |||
1223 | return 0; | 1242 | return 0; |
1224 | } | 1243 | } |
1225 | 1244 | ||
1245 | //TODO DOXIGEN | ||
1226 | static void | 1246 | static void |
1227 | send_hello_beacon(struct Plugin * plugin) | 1247 | send_hello_beacon(struct Plugin * plugin) |
1228 | { | 1248 | { |
@@ -1278,6 +1298,7 @@ send_hello_beacon(struct Plugin * plugin) | |||
1278 | set_next_send(plugin); | 1298 | set_next_send(plugin); |
1279 | } | 1299 | } |
1280 | 1300 | ||
1301 | //TODO DOXIGEN | ||
1281 | static void | 1302 | static void |
1282 | send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | 1303 | send_ack(struct Plugin * plugin, struct AckSendQueue * ack) |
1283 | { | 1304 | { |
@@ -1298,7 +1319,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1299 | "Sending ack for message_id %u with fragment field %u, size %u\n", | 1320 | "Sending ack for message_id %u with fragment field %u, size %u\n", |
1300 | ack->message_id, ack->fragments_field, size | 1321 | ack->message_id, ack->fragments_field, size |
1301 | - sizeof(struct Radiotap_Send)); | 1322 | - sizeof(struct Radiotap_Send)); |
1302 | #endif | 1323 | #endif |
1303 | 1324 | ||
1304 | msgheader = GNUNET_malloc(size); | 1325 | msgheader = GNUNET_malloc(size); |
@@ -1330,6 +1351,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1330 | set_next_send(plugin); | 1351 | set_next_send(plugin); |
1331 | } | 1352 | } |
1332 | 1353 | ||
1354 | //TODO DOXIGEN | ||
1333 | static void | 1355 | static void |
1334 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1356 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1335 | { | 1357 | { |
@@ -1459,7 +1481,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1459 | GNUNET_ERROR_TYPE_DEBUG, | 1481 | GNUNET_ERROR_TYPE_DEBUG, |
1460 | "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n", | 1482 | "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n", |
1461 | fm->message_id_out, fm->message_pos, copysize | 1483 | fm->message_id_out, fm->message_pos, copysize |
1462 | + sizeof(struct FragmentationHeader), copyoffset, | 1484 | + sizeof(struct FragmentationHeader), copyoffset, |
1463 | GNUNET_TIME_absolute_get_remaining(fm->timeout)); | 1485 | GNUNET_TIME_absolute_get_remaining(fm->timeout)); |
1464 | #endif | 1486 | #endif |
1465 | 1487 | ||
@@ -1473,21 +1495,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1473 | fm->message_pos); | 1495 | fm->message_pos); |
1474 | } | 1496 | } |
1475 | GNUNET_assert(copyoffset < fm->message_size); | 1497 | GNUNET_assert(copyoffset < fm->message_size); |
1476 | //FIXME remove later | ||
1477 | GNUNET_assert(copystart < fm->msg + fm->message_size); | ||
1478 | 1498 | ||
1479 | fragheader.header.size = htons(copysize | 1499 | fragheader.header.size = htons(copysize |
1480 | + sizeof(struct FragmentationHeader)); | 1500 | + sizeof(struct FragmentationHeader)); |
1481 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); | 1501 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); |
1482 | 1502 | ||
1483 | /* } | ||
1484 | else | ||
1485 | { | ||
1486 | // there is no need to split | ||
1487 | copystart = fm->msg; | ||
1488 | copysize = fm->message_size; | ||
1489 | }*/ | ||
1490 | |||
1491 | size += copysize; | 1503 | size += copysize; |
1492 | size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame) | 1504 | size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame) |
1493 | + sizeof(struct GNUNET_MessageHeader); | 1505 | + sizeof(struct GNUNET_MessageHeader); |
@@ -1503,18 +1515,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1503 | 1515 | ||
1504 | //could be faster if content is just send and not copyed before | 1516 | //could be faster if content is just send and not copyed before |
1505 | //fragmentheader is needed | 1517 | //fragmentheader is needed |
1506 | //if (fm->message_size > WLAN_MTU) | ||
1507 | // { | ||
1508 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); | 1518 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); |
1509 | memcpy(&ieeewlanheader[1], &fragheader, | 1519 | memcpy(&ieeewlanheader[1], &fragheader, |
1510 | sizeof(struct FragmentationHeader)); | 1520 | sizeof(struct FragmentationHeader)); |
1511 | fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1]; | 1521 | fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1]; |
1512 | memcpy(&fragheaderptr[1], copystart, copysize); | 1522 | memcpy(&fragheaderptr[1], copystart, copysize); |
1513 | /* } | ||
1514 | else | ||
1515 | { | ||
1516 | memcpy(&ieeewlanheader[1], copystart, copysize); | ||
1517 | }*/ | ||
1518 | 1523 | ||
1519 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, | 1524 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, |
1520 | msgheader, size); | 1525 | msgheader, size); |
@@ -1581,6 +1586,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1581 | } | 1586 | } |
1582 | return; | 1587 | return; |
1583 | } | 1588 | } |
1589 | |||
1584 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1590 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1585 | "do_transmit did nothing, should not happen!\n"); | 1591 | "do_transmit did nothing, should not happen!\n"); |
1586 | } | 1592 | } |
@@ -1786,13 +1792,14 @@ search_fragment_message_from_session_and_id(void *cls, | |||
1786 | struct GNUNET_CONTAINER_HeapNode *node, void *element, | 1792 | struct GNUNET_CONTAINER_HeapNode *node, void *element, |
1787 | GNUNET_CONTAINER_HeapCostType cost) | 1793 | GNUNET_CONTAINER_HeapCostType cost) |
1788 | { | 1794 | { |
1789 | struct Session_id_pair * pair = (struct Session_id_pair *) cls; | 1795 | struct Session_id_fragment_triple * triple = |
1796 | (struct Session_id_fragment_triple *) cls; | ||
1790 | struct FragmentMessage * fm = (struct FragmentMessage*) element; | 1797 | struct FragmentMessage * fm = (struct FragmentMessage*) element; |
1791 | 1798 | ||
1792 | if ((fm->session == pair->session) | 1799 | if ((fm->session == triple->session) && (fm->message_id_out |
1793 | && (fm->message_id_out == pair->message_id)) | 1800 | == triple->message_id)) |
1794 | { | 1801 | { |
1795 | return_val = fm; | 1802 | triple->fm = fm; |
1796 | return GNUNET_NO; | 1803 | return GNUNET_NO; |
1797 | } | 1804 | } |
1798 | return GNUNET_YES; | 1805 | return GNUNET_YES; |
@@ -1809,12 +1816,12 @@ static struct FragmentMessage * | |||
1809 | get_fragment_message_from_session_and_id(struct Plugin * plugin, | 1816 | get_fragment_message_from_session_and_id(struct Plugin * plugin, |
1810 | struct Session * session, uint32_t message_id) | 1817 | struct Session * session, uint32_t message_id) |
1811 | { | 1818 | { |
1812 | struct Session_id_pair pair; | 1819 | struct Session_id_fragment_triple triple; |
1813 | pair.session = session; | 1820 | triple.session = session; |
1814 | pair.message_id = message_id; | 1821 | triple.message_id = message_id; |
1815 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, | 1822 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, |
1816 | &search_fragment_message_from_session_and_id, &pair); | 1823 | &search_fragment_message_from_session_and_id, &triple); |
1817 | return return_val; | 1824 | return triple.fm; |
1818 | } | 1825 | } |
1819 | 1826 | ||
1820 | /** | 1827 | /** |
@@ -1822,7 +1829,7 @@ get_fragment_message_from_session_and_id(struct Plugin * plugin, | |||
1822 | * @param plugin pointer to the plugin struct | 1829 | * @param plugin pointer to the plugin struct |
1823 | * @param session session this fragment belongs to | 1830 | * @param session session this fragment belongs to |
1824 | */ | 1831 | */ |
1825 | struct Receive_Message_Queue * | 1832 | static struct Receive_Message_Queue * |
1826 | get_receive_message_from_session(struct Plugin * plugin, | 1833 | get_receive_message_from_session(struct Plugin * plugin, |
1827 | struct Session * session) | 1834 | struct Session * session) |
1828 | { | 1835 | { |
@@ -1868,28 +1875,59 @@ free_receive_message(struct Plugin* plugin, | |||
1868 | GNUNET_free(rx_message); | 1875 | GNUNET_free(rx_message); |
1869 | } | 1876 | } |
1870 | 1877 | ||
1878 | /** | ||
1879 | * function to get the receive message of a session | ||
1880 | * @param plugin pointer to the plugin struct | ||
1881 | * @param session session this fragment belongs to | ||
1882 | */ | ||
1883 | static void | ||
1884 | check_receive_message_timeouts(struct Plugin * plugin, struct Session * session) | ||
1885 | { | ||
1886 | struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; | ||
1887 | while (rec_message != NULL) | ||
1888 | { | ||
1889 | if (GNUNET_TIME_absolute_get_remaining(rec_message->timeout).rel_value | ||
1890 | == 0) | ||
1891 | { | ||
1892 | free_receive_message(plugin, rec_message); | ||
1893 | } | ||
1894 | rec_message = rec_message->next; | ||
1895 | } | ||
1896 | |||
1897 | } | ||
1898 | |||
1899 | //TODO DOXIGEN | ||
1871 | static void | 1900 | static void |
1872 | free_session(struct Plugin * plugin, struct Sessionqueue * queue) | 1901 | free_session(struct Plugin * plugin, struct Sessionqueue * queue) |
1873 | { | 1902 | { |
1874 | struct Sessionqueue * pendingsession = plugin->pending_Sessions; | 1903 | struct Sessionqueue * pendingsession; |
1904 | struct Sessionqueue * pendingsession_tmp; | ||
1875 | struct PendingMessage * pm; | 1905 | struct PendingMessage * pm; |
1876 | struct Receive_Message_Queue * receive_queue; | 1906 | struct Receive_Message_Queue * receive_queue; |
1877 | struct Plugin_Session_pair pair; | 1907 | struct Plugin_Session_pair pair; |
1878 | int check = 0; | 1908 | int check = 0; |
1879 | 1909 | ||
1880 | GNUNET_assert(queue != NULL); | 1910 | GNUNET_assert(queue != NULL); |
1911 | GNUNET_assert(queue->content != NULL); | ||
1881 | 1912 | ||
1882 | //session found | 1913 | //session found |
1883 | //is this session pending for send | 1914 | //is this session pending for send |
1915 | pendingsession = plugin->pending_Sessions_head; | ||
1884 | while (pendingsession != NULL) | 1916 | while (pendingsession != NULL) |
1885 | { | 1917 | { |
1918 | pendingsession_tmp = pendingsession->next; | ||
1886 | if (pendingsession->content == queue->content) | 1919 | if (pendingsession->content == queue->content) |
1887 | { | 1920 | { |
1888 | plugin->pendingsessions--; | 1921 | plugin->pendingsessions--; |
1889 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | 1922 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, |
1890 | plugin->pending_Sessions_tail, pendingsession); | 1923 | plugin->pending_Sessions_tail, pendingsession); |
1891 | GNUNET_free(pendingsession); | 1924 | GNUNET_free(pendingsession); |
1892 | 1925 | ||
1926 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1927 | "Remove session %p from pending session queue\n", queue->content | ||
1928 | ); | ||
1929 | |||
1930 | |||
1893 | if (check == 1) | 1931 | if (check == 1) |
1894 | { | 1932 | { |
1895 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1933 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
@@ -1898,7 +1936,7 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) | |||
1898 | 1936 | ||
1899 | check = 1; | 1937 | check = 1; |
1900 | } | 1938 | } |
1901 | pendingsession = pendingsession->next; | 1939 | pendingsession = pendingsession_tmp; |
1902 | } | 1940 | } |
1903 | 1941 | ||
1904 | //is something of this session in the fragment queue? | 1942 | //is something of this session in the fragment queue? |
@@ -2099,10 +2137,11 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, | |||
2099 | * @param hdr pointer to the data | 2137 | * @param hdr pointer to the data |
2100 | */ | 2138 | */ |
2101 | static void | 2139 | static void |
2102 | wlan_data_message_handler(struct Plugin * plugin, | 2140 | wlan_data_message_handler(void *cls, void *client, |
2103 | struct Session_light * session_light, | 2141 | const struct GNUNET_MessageHeader *hdr) |
2104 | const struct GNUNET_MessageHeader * hdr) | ||
2105 | { | 2142 | { |
2143 | struct Plugin * plugin = (struct Plugin*) cls; | ||
2144 | struct Session_light * session_light = (struct Session_light *) client; | ||
2106 | struct WlanHeader * wlanheader; | 2145 | struct WlanHeader * wlanheader; |
2107 | struct Session * session; | 2146 | struct Session * session; |
2108 | const char * tempmsg; | 2147 | const char * tempmsg; |
@@ -2232,9 +2271,10 @@ check_rx_finished_msg(struct Plugin* plugin, | |||
2232 | struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; | 2271 | struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; |
2233 | int packetsize = rx_message->rec_size; | 2272 | int packetsize = rx_message->rec_size; |
2234 | int sum; | 2273 | int sum; |
2235 | int aktnum; | 2274 | //TODO CLEANUP |
2275 | //int aktnum; | ||
2236 | uint64_t bitfield = 0; | 2276 | uint64_t bitfield = 0; |
2237 | char * msg; | 2277 | //char * msg; |
2238 | 2278 | ||
2239 | //check if first fragment is present | 2279 | //check if first fragment is present |
2240 | if (packetsize == MESSAGE_LENGHT_UNKNOWN) | 2280 | if (packetsize == MESSAGE_LENGHT_UNKNOWN) |
@@ -2279,31 +2319,50 @@ check_rx_finished_msg(struct Plugin* plugin, | |||
2279 | "check_rec_finished_msg: A message for %p is complete\n", session); | 2319 | "check_rec_finished_msg: A message for %p is complete\n", session); |
2280 | #endif | 2320 | #endif |
2281 | 2321 | ||
2282 | //TODO use mst | 2322 | //TODO cleanup |
2323 | |||
2283 | //copy fragments together | 2324 | //copy fragments together |
2284 | msg = GNUNET_malloc(packetsize); | 2325 | //msg = GNUNET_malloc(packetsize); |
2285 | rx_frag = rx_message->frag_head; | 2326 | rx_frag = rx_message->frag_head; |
2286 | aktnum = 0; | 2327 | //aktnum = 0; |
2328 | /*while (rx_frag != NULL) | ||
2329 | { | ||
2330 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY | ||
2331 | memcpy(msg + aktnum, rx_frag->msg, rx_frag->size); | ||
2332 | aktnum += rx_frag->size; | ||
2333 | rx_frag = rx_frag->next; | ||
2334 | }*/ | ||
2335 | |||
2287 | while (rx_frag != NULL) | 2336 | while (rx_frag != NULL) |
2288 | { | 2337 | { |
2289 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY | 2338 | if (rx_frag->next != NULL) |
2290 | memcpy(msg + aktnum, rx_frag->msg, rx_frag->size); | 2339 | { |
2291 | aktnum += rx_frag->size; | 2340 | GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer, |
2341 | session_light, rx_frag->msg, rx_frag->size, GNUNET_NO, | ||
2342 | GNUNET_NO); | ||
2343 | } | ||
2344 | else | ||
2345 | { | ||
2346 | //if it is the last fragment just kill all leftover | ||
2347 | GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer, | ||
2348 | session_light, rx_frag->msg, rx_frag->size, GNUNET_YES, | ||
2349 | GNUNET_NO); | ||
2350 | } | ||
2292 | rx_frag = rx_frag->next; | 2351 | rx_frag = rx_frag->next; |
2293 | } | 2352 | } |
2294 | |||
2295 | free_receive_message(plugin, rx_message); | 2353 | free_receive_message(plugin, rx_message); |
2296 | //call wlan_process_helper to process the message | 2354 | //call wlan_process_helper to process the message |
2297 | wlan_data_message_handler(plugin, session_light, | 2355 | //wlan_data_message_handler(plugin, session_light, |
2298 | (struct GNUNET_MessageHeader*) msg); | 2356 | // (struct GNUNET_MessageHeader*) msg); |
2299 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | 2357 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); |
2300 | 2358 | ||
2301 | GNUNET_free(msg); | 2359 | //GNUNET_free(msg); |
2302 | } | 2360 | } |
2303 | } | 2361 | } |
2304 | // } | 2362 | // } |
2305 | } | 2363 | } |
2306 | 2364 | ||
2365 | //TODO DOXIGEN | ||
2307 | static void | 2366 | static void |
2308 | process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 2367 | process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
2309 | { | 2368 | { |
@@ -2412,14 +2471,17 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2412 | { | 2471 | { |
2413 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) | 2472 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) |
2414 | { | 2473 | { |
2474 | check_receive_message_timeouts(plugin, session); | ||
2475 | } | ||
2476 | |||
2477 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) | ||
2478 | { | ||
2415 | 2479 | ||
2416 | //new message incoming | 2480 | //new message incoming |
2417 | rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); | 2481 | rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); |
2418 | rx_message->message_id_in = ntohl(fh->message_id); | 2482 | rx_message->message_id_in = ntohl(fh->message_id); |
2419 | rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN; | 2483 | rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN; |
2420 | rx_message->session = session; | 2484 | rx_message->session = session; |
2421 | rx_message->timeout = GNUNET_TIME_absolute_add( | ||
2422 | GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT); | ||
2423 | rx_message->received_fragments = 0; | 2485 | rx_message->received_fragments = 0; |
2424 | 2486 | ||
2425 | GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message); | 2487 | GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message); |
@@ -2447,6 +2509,11 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2447 | } | 2509 | } |
2448 | } | 2510 | } |
2449 | 2511 | ||
2512 | //reset timeout | ||
2513 | rx_message->timeout = GNUNET_TIME_absolute_add( | ||
2514 | GNUNET_TIME_absolute_get(), | ||
2515 | MESSAGE_IN_TIMEOUT); | ||
2516 | |||
2450 | if (is_double_msg(rx_message, fh) != GNUNET_YES) | 2517 | if (is_double_msg(rx_message, fh) != GNUNET_YES) |
2451 | { | 2518 | { |
2452 | 2519 | ||
@@ -2576,8 +2643,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2576 | GNUNET_ERROR_TYPE_INFO, | 2643 | GNUNET_ERROR_TYPE_INFO, |
2577 | "WLAN client not in session list, fragment num %u, message id %u\n", | 2644 | "WLAN client not in session list, fragment num %u, message id %u\n", |
2578 | ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); | 2645 | ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); |
2579 | wlan_data_message_handler(plugin, session_light, | 2646 | |
2580 | (struct GNUNET_MessageHeader *) tempmsg); | 2647 | GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer, session_light, |
2648 | tempmsg, ntohs(hdr->size) - sizeof(struct FragmentationHeader), | ||
2649 | GNUNET_YES, GNUNET_NO); | ||
2650 | //wlan_data_message_handler(plugin, session_light, | ||
2651 | // (struct GNUNET_MessageHeader *) tempmsg); | ||
2581 | session = session_light->session; | 2652 | session = session_light->session; |
2582 | //test if a session was created | 2653 | //test if a session was created |
2583 | if (session == NULL) | 2654 | if (session == NULL) |
@@ -2658,6 +2729,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2658 | 2729 | ||
2659 | } | 2730 | } |
2660 | 2731 | ||
2732 | //TODO DOXIGEN | ||
2661 | const char * | 2733 | const char * |
2662 | macprinter(const u_int8_t * mac) | 2734 | macprinter(const u_int8_t * mac) |
2663 | { | 2735 | { |
@@ -2706,7 +2778,7 @@ wlan_process_helper(void *cls, void *client, | |||
2706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2778 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2707 | "Size of packet is too small; size: %u min size: %u\n", ntohs( | 2779 | "Size of packet is too small; size: %u min size: %u\n", ntohs( |
2708 | hdr->size), sizeof(struct ieee80211_frame) | 2780 | hdr->size), sizeof(struct ieee80211_frame) |
2709 | + sizeof(struct GNUNET_MessageHeader)); | 2781 | + sizeof(struct GNUNET_MessageHeader)); |
2710 | #endif | 2782 | #endif |
2711 | //GNUNET_break (0); | 2783 | //GNUNET_break (0); |
2712 | /* FIXME: restart SUID process */ | 2784 | /* FIXME: restart SUID process */ |
@@ -2812,12 +2884,6 @@ wlan_plugin_helper_read(void *cls, | |||
2812 | struct Plugin *plugin = cls; | 2884 | struct Plugin *plugin = cls; |
2813 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 2885 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
2814 | 2886 | ||
2815 | /* | ||
2816 | #if DEBUG_wlan | ||
2817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2818 | "Start reading from STDIN\n"); | ||
2819 | #endif | ||
2820 | */ | ||
2821 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 2887 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
2822 | return; | 2888 | return; |
2823 | 2889 | ||
@@ -2935,6 +3001,9 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2935 | if (plugin->data_tokenizer != NULL) | 3001 | if (plugin->data_tokenizer != NULL) |
2936 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); | 3002 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); |
2937 | 3003 | ||
3004 | if (plugin->fragment_tokenizer != NULL) | ||
3005 | GNUNET_SERVER_mst_destroy(plugin->fragment_tokenizer); | ||
3006 | |||
2938 | fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek( | 3007 | fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek( |
2939 | plugin->pending_Fragment_Messages); | 3008 | plugin->pending_Fragment_Messages); |
2940 | 3009 | ||
@@ -2992,9 +3061,11 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
2992 | plugin); | 3061 | plugin); |
2993 | 3062 | ||
2994 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); | 3063 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); |
3064 | plugin->fragment_tokenizer = GNUNET_SERVER_mst_create( | ||
3065 | &wlan_data_message_handler, plugin); | ||
2995 | 3066 | ||
2996 | //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | 3067 | //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); |
2997 | //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | 3068 | //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue)); |
2998 | 3069 | ||
2999 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3070 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
3000 | api->cls = plugin; | 3071 | api->cls = plugin; |
diff --git a/src/transport/test_transport_api_wlan_peer1.conf b/src/transport/test_transport_api_wlan_peer1.conf index 683093ff7..b33abd243 100644 --- a/src/transport/test_transport_api_wlan_peer1.conf +++ b/src/transport/test_transport_api_wlan_peer1.conf | |||
@@ -9,7 +9,7 @@ AUTOSTART = NO | |||
9 | 9 | ||
10 | [transport-wlan] | 10 | [transport-wlan] |
11 | INTERFACE = mon0 | 11 | INTERFACE = mon0 |
12 | TESTMODE = 0 | 12 | TESTMODE = 1 |
13 | #PREFIX = gdbserver :2345 | 13 | #PREFIX = gdbserver :2345 |
14 | 14 | ||
15 | [hostlist] | 15 | [hostlist] |
@@ -46,7 +46,7 @@ UNIXPATH = /tmp/gnunet-p1-service-transport.sock | |||
46 | #PREFIX = xterm -T transport2 -e gdb --command=cmd --args | 46 | #PREFIX = xterm -T transport2 -e gdb --command=cmd --args |
47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 | 47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 |
48 | #PREFIX = valgrind --leak-check=full --show-reachable=yes | 48 | #PREFIX = valgrind --leak-check=full --show-reachable=yes |
49 | #PREFIX = valgrind --leak-check=full | 49 | PREFIX = valgrind --leak-check=full |
50 | #PREFIX = valgrind --tool=massif | 50 | #PREFIX = valgrind --tool=massif |
51 | #PREFIX = gdbserver :2345 | 51 | #PREFIX = gdbserver :2345 |
52 | 52 | ||
diff --git a/src/transport/test_transport_api_wlan_peer2.conf b/src/transport/test_transport_api_wlan_peer2.conf index 22824e090..c422b3dc9 100644 --- a/src/transport/test_transport_api_wlan_peer2.conf +++ b/src/transport/test_transport_api_wlan_peer2.conf | |||
@@ -9,7 +9,7 @@ AUTOSTART = NO | |||
9 | 9 | ||
10 | [transport-wlan] | 10 | [transport-wlan] |
11 | INTERFACE = mon1 | 11 | INTERFACE = mon1 |
12 | TESTMODE = 0 | 12 | TESTMODE = 2 |
13 | #PREFIX = gdbserver :2346 | 13 | #PREFIX = gdbserver :2346 |
14 | 14 | ||
15 | [hostlist] | 15 | [hostlist] |
@@ -46,7 +46,7 @@ UNIXPATH = /tmp/gnunet-p2-service-transport.sock | |||
46 | #PREFIX = xterm -T transport1 -e gdb --command=cmd --args | 46 | #PREFIX = xterm -T transport1 -e gdb --command=cmd --args |
47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 | 47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 |
48 | #PREFIX = valgrind --leak-check=full --show-reachable=yes | 48 | #PREFIX = valgrind --leak-check=full --show-reachable=yes |
49 | #PREFIX = valgrind --leak-check=full | 49 | PREFIX = valgrind --leak-check=full |
50 | #PREFIX = valgrind --tool=massif | 50 | #PREFIX = valgrind --tool=massif |
51 | #PREFIX = gdbserver :2346 | 51 | #PREFIX = gdbserver :2346 |
52 | 52 | ||