aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-01-18 09:51:23 +0000
committerDavid Brodski <david@brodski.eu>2011-01-18 09:51:23 +0000
commitf1e46a71318eea0fc45e8142c7c6dbdfa0436c8a (patch)
tree55b01893d260a2b82db8736c2df8e75a4be3c606 /src
parentbd22cdc0099f039ca6bb9cc37a9a6b30f505354b (diff)
downloadgnunet-f1e46a71318eea0fc45e8142c7c6dbdfa0436c8a.tar.gz
gnunet-f1e46a71318eea0fc45e8142c7c6dbdfa0436c8a.zip
wlan helper should work now for loopback, test configurations changed accordingly
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c334
-rw-r--r--src/transport/test_transport_api_wlan_peer1.conf2
-rw-r--r--src/transport/test_transport_api_wlan_peer2.conf2
3 files changed, 213 insertions, 125 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 7ac2915b4..05fab4758 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -420,9 +420,22 @@ stdin_send (void *cls,
420 const struct GNUNET_MessageHeader *hdr) 420 const struct GNUNET_MessageHeader *hdr)
421{ 421{
422 struct sendbuf *write_pout = cls; 422 struct sendbuf *write_pout = cls;
423 GNUNET_assert (hdr->size + write_pout->size < MAXLINE *2); 423 int sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ;
424 memcpy(write_pout->buf + write_pout->size, hdr, hdr->size); 424 struct GNUNET_MessageHeader newheader;
425 write_pout->size += hdr->size; 425
426 GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type));
427 GNUNET_assert (sendsize + write_pout->size < MAXLINE *2);
428
429
430 newheader.size = htons(sendsize);
431 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
432
433
434 memcpy(write_pout->buf + write_pout->size, &newheader, sizeof(struct GNUNET_MessageHeader));
435 write_pout->size += sizeof(struct GNUNET_MessageHeader);
436
437 memcpy(write_pout->buf + write_pout->size, hdr + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader), sizeof(struct GNUNET_MessageHeader));
438 write_pout->size += sendsize;
426} 439}
427 440
428static void 441static void
@@ -431,9 +444,13 @@ file_in_send (void *cls,
431 const struct GNUNET_MessageHeader *hdr) 444 const struct GNUNET_MessageHeader *hdr)
432{ 445{
433 struct sendbuf * write_std = cls; 446 struct sendbuf * write_std = cls;
434 GNUNET_assert (hdr->size + write_std->size < MAXLINE *2); 447 int sendsize = ntohs(hdr->size);
435 memcpy(write_std->buf + write_std->size, hdr, hdr->size); 448
436 write_std->size += hdr->size; 449 GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type));
450 GNUNET_assert (sendsize + write_std->size < MAXLINE *2);
451
452 memcpy(write_std->buf + write_std->size, hdr, sendsize);
453 write_std->size += sendsize;
437} 454}
438 455
439int 456int
@@ -448,14 +465,12 @@ testmode(int argc, char *argv[])
448 int fdpin; 465 int fdpin;
449 int fdpout; 466 int fdpout;
450 467
451
452
453 //make the fifos if needed 468 //make the fifos if needed
454 if (stat(FIFO_FILE1, &st) != 0) 469 if (0 != stat(FIFO_FILE1, &st))
455 { 470 {
456 if (stat(FIFO_FILE2, &st) == 0) 471 if (0 == stat(FIFO_FILE2, &st))
457 { 472 {
458 perror("FIFO 2 exists, but FIFO 1 not"); 473 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not");
459 exit(1); 474 exit(1);
460 } 475 }
461 476
@@ -463,52 +478,70 @@ testmode(int argc, char *argv[])
463 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); 478 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
464 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); 479 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
465 480
466
467 } 481 }
468 else 482 else
469 { 483 {
470 484
471 if (stat(FIFO_FILE2, &st) != 0) 485 if (0 != stat(FIFO_FILE2, &st))
472 { 486 {
473 perror("FIFO 1 exists, but FIFO 2 not"); 487 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not");
474 exit(1); 488 exit(1);
475 } 489 }
476 490
477
478 } 491 }
479 492
480 if (strstr(argv[2],"1")) { 493 if (strstr(argv[2], "1"))
481 first = 1; 494 {
482 fpin = fopen(FIFO_FILE1, "r"); 495 //fprintf(stderr, "First\n");
483 if (fpin == NULL) 496 first = 1;
484 { 497 fpin = fopen(FIFO_FILE1, "r");
485 perror("fopen"); 498 if (NULL == fpin)
486 exit(1); 499 {
487 } 500 fprintf(stderr, "fopen of read FIFO_FILE1");
488 if ((fpout = fopen(FIFO_FILE2, "w")) == NULL) 501 exit(1);
489 { 502 }
490 perror("fopen"); 503 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
491 exit(1); 504 {
492 } 505 fprintf(stderr, "fopen of write FIFO_FILE2");
493 506 exit(1);
494 } else { 507 }
495 first = 0;
496 if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
497 {
498 perror("fopen");
499 exit(1);
500 }
501 if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
502 {
503 perror("fopen");
504 exit(1);
505 }
506 508
509 }
510 else
511 {
512 first = 0;
513 //fprintf(stderr, "Second\n");
514 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
515 {
516 fprintf(stderr, "fopen of write FIFO_FILE1");
517 exit(1);
518 }
519 if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
520 {
521 fprintf(stderr, "fopen of read FIFO_FILE2");
522 exit(1);
523 }
507 524
508 } 525 }
509 526
510 fdpin = fileno(fpin); 527 fdpin = fileno(fpin);
528 if (fdpin >= FD_SETSIZE)
529 {
530 fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
531 (unsigned int) FD_SETSIZE);
532 close(fdpin);
533 return -1;
534 }
535
511 fdpout = fileno(fpout); 536 fdpout = fileno(fpout);
537 if (fdpout >= FD_SETSIZE)
538 {
539 fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
540 (unsigned int) FD_SETSIZE);
541 close(fdpout);
542 return -1;
543
544 }
512 545
513 signal(SIGINT, &sigfunc); 546 signal(SIGINT, &sigfunc);
514 signal(SIGTERM, &sigfunc); 547 signal(SIGTERM, &sigfunc);
@@ -525,8 +558,6 @@ testmode(int argc, char *argv[])
525 558
526 int ret = 0; 559 int ret = 0;
527 int maxfd = 0; 560 int maxfd = 0;
528 int to_write_stdout = 0;
529 int to_write_fpout = 0;
530 561
531 fd_set rfds; 562 fd_set rfds;
532 fd_set wfds; 563 fd_set wfds;
@@ -535,10 +566,6 @@ testmode(int argc, char *argv[])
535 566
536 567
537 568
538 maxfd = MAX(fdpout, fdpin);
539 maxfd = MAX(maxfd, STDOUT_FILENO);
540 maxfd++;
541
542 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; 569 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
543 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; 570 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
544 571
@@ -556,54 +583,114 @@ testmode(int argc, char *argv[])
556 macmsg.mac.mac[3] = 0x44; 583 macmsg.mac.mac[3] = 0x44;
557 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); 584 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
558 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); 585 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
559 macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message); 586 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
560 macmsg.hdr.type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL; 587 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
588
589 memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
590 write_std.size = sizeof(struct Wlan_Helper_Control_Message);
591
592 /*
593 //wait
594 tv.tv_sec = 2;
595 tv.tv_usec = 0;
596 retval = select(0, NULL, NULL, NULL, &tv);
597
598
599 tv.tv_sec = 3;
600 tv.tv_usec = 0;
601 // if there is something to write
602 FD_ZERO(&wfds);
603 FD_SET(STDOUT_FILENO, &wfds);
604
605 retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv);
606
607 if (FD_ISSET(STDOUT_FILENO, &wfds))
608 {
609 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size
610 - write_std.pos);
611
612 if (0 > ret)
613 {
614 closeprog = 1;
615 fprintf(stderr, "Write ERROR to STDOUT");
616 exit(1);
617 }
618 else
619 {
620 write_std.pos += ret;
621 // check if finished
622 if (write_std.pos == write_std.size)
623 {
624 write_std.pos = 0;
625 write_std.size = 0;
626 }
627 }
628 }
561 629
562 memcpy(&write_std.buf, &macmsg, macmsg.hdr.size); 630 memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
563 write_std.size = macmsg.hdr.size; 631 write_std.size = sizeof(struct Wlan_Helper_Control_Message);
632 */
564 633
634 //wait
635 tv.tv_sec = 2;
636 tv.tv_usec = 0;
637 retval = select(0, NULL, NULL, NULL, &tv);
565 638
566 while (closeprog == 0) 639 while (0 == closeprog)
567 { 640 {
568 641
642 maxfd = 0;
643
569 //set timeout 644 //set timeout
570 tv.tv_sec = 5; 645 tv.tv_sec = 5;
571 tv.tv_usec = 0; 646 tv.tv_usec = 0;
572 647
573 FD_ZERO(&rfds); 648 FD_ZERO(&rfds);
574 // if output queue is emty 649 // if output queue is empty
575 if (to_write_fpout == 0) 650 if (0 == write_pout.size)
576 FD_SET(STDIN_FILENO, &rfds); 651 {
577 if (to_write_stdout == 0) 652 FD_SET(STDIN_FILENO, &rfds);
578 FD_SET(fdpin, &rfds);
579 653
654 }
655 if (0 == write_std.size)
656 {
657 FD_SET(fdpin, &rfds);
658 maxfd = fdpin;
659 }
580 FD_ZERO(&wfds); 660 FD_ZERO(&wfds);
581 // if there is something to write 661 // if there is something to write
582 if (to_write_stdout > 0) 662 if (0 < write_std.size){
583 FD_SET(STDOUT_FILENO, &wfds); 663 FD_SET(STDOUT_FILENO, &wfds);
584 if (to_write_fpout > 0) 664 maxfd = MAX(maxfd, STDOUT_FILENO);
665 }
666
667 if (0 < write_pout.size){
585 FD_SET(fdpout, &wfds); 668 FD_SET(fdpout, &wfds);
669 maxfd = MAX(maxfd, fdpout);
670 }
586 671
587 retval = select(maxfd, &rfds, &wfds, NULL, &tv);
588 672
673 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
589 674
590 if (retval == -1 && errno == EINTR){ 675 if (-1 == retval && EINTR == errno)
591 continue; 676 {
592 } 677 continue;
593 if (retval < 0){ 678 }
594 perror("select()"); 679 if (0 > retval)
595 exit(1); 680 {
596 } 681 fprintf(stderr, "select failed: %s\n", strerror(errno));
682 exit(1);
683 }
597 684
598 if (FD_ISSET(STDOUT_FILENO, &wfds)) 685 if (FD_ISSET(STDOUT_FILENO, &wfds))
599 { 686 {
600 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, 687 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
601 write_std.size - write_std.pos); 688 write_std.size - write_std.pos);
602 689
603 if (ret < 0) 690 if (0 > ret)
604 { 691 {
605 closeprog = 1; 692 closeprog = 1;
606 perror("Write ERROR to STDOUT"); 693 fprintf(stderr, "Write ERROR to STDOUT");
607 exit(1); 694 exit(1);
608 } 695 }
609 else 696 else
@@ -620,13 +707,13 @@ testmode(int argc, char *argv[])
620 707
621 if (FD_ISSET(fdpout, &wfds)) 708 if (FD_ISSET(fdpout, &wfds))
622 { 709 {
623 ret = write(fdpout, write_pout.buf + write_pout.pos, 710 ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
624 write_pout.size - write_pout.pos); 711 - write_pout.pos);
625 712
626 if (ret < 0) 713 if (0 > ret)
627 { 714 {
628 closeprog = 1; 715 closeprog = 1;
629 perror("Write ERROR to fdpout"); 716 fprintf(stderr, "Write ERROR to fdpout");
630 exit(1); 717 exit(1);
631 } 718 }
632 else 719 else
@@ -635,64 +722,59 @@ testmode(int argc, char *argv[])
635 // check if finished 722 // check if finished
636 if (write_pout.pos == write_pout.size) 723 if (write_pout.pos == write_pout.size)
637 { 724 {
638 write_pout.pos = 0; 725 write_pout.pos = 0;
639 write_pout.size = 0; 726 write_pout.size = 0;
640 } 727 }
641 } 728 }
642 } 729 }
643 730
644 if (FD_ISSET(STDIN_FILENO, &rfds)) 731 if (FD_ISSET(STDIN_FILENO, &rfds))
645 { 732 {
646 readsize = read(STDIN_FILENO, readbuf, 733 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
647 sizeof(readbuf));
648
649 if (readsize < 0)
650 {
651 closeprog = 1;
652 perror("Write ERROR to STDIN_FILENO");
653 exit(1);
654 }
655 else
656 {
657 GNUNET_SERVER_mst_receive(stdin_mst, NULL,
658 readbuf, readsize, GNUNET_NO, GNUNET_NO);
659
660 }
661 }
662 734
663 if (FD_ISSET(fdpin, &rfds)) 735 if (0 > readsize)
664 { 736 {
665 readsize = read(fdpin, readbuf, 737 closeprog = 1;
666 sizeof(readbuf)); 738 fprintf(stderr, "Read ERROR to STDIN_FILENO");
739 exit(1);
740 }
741 else
742 {
743 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
744 GNUNET_NO, GNUNET_NO);
667 745
668 if (readsize < 0) 746 }
669 { 747 }
670 closeprog = 1;
671 perror("Write ERROR to STDIN_FILENO");
672 exit(1);
673 }
674 else
675 {
676 GNUNET_SERVER_mst_receive(file_in_mst, NULL,
677 readbuf, readsize, GNUNET_NO, GNUNET_NO);
678 748
679 } 749 if (FD_ISSET(fdpin, &rfds))
680 } 750 {
751 readsize = read(fdpin, readbuf, sizeof(readbuf));
681 752
753 if (0 > readsize)
754 {
755 closeprog = 1;
756 fprintf(stderr, "Read ERROR to fdpin");
757 exit(1);
758 }
759 else
760 {
761 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
762 GNUNET_NO, GNUNET_NO);
682 763
764 }
683 } 765 }
684 766
685 //clean up 767 }
686 fclose(fpout);
687 fclose(fpin);
688 perror("Write ERROR to STDIN_FILENO");
689 768
690 if (first == 1) 769 //clean up
691 { 770 fclose(fpout);
692 unlink(FIFO_FILE1); 771 fclose(fpin);
693 unlink(FIFO_FILE2);
694 }
695 772
773 if (1 == first)
774 {
775 unlink(FIFO_FILE1);
776 unlink(FIFO_FILE2);
777 }
696 778
697 return (0); 779 return (0);
698} 780}
@@ -701,14 +783,20 @@ testmode(int argc, char *argv[])
701int 783int
702main(int argc, char *argv[]) 784main(int argc, char *argv[])
703{ 785{
704 if (argc == 3) 786 if (3 != argc)
705 { 787 {
706 if (strstr(argv[2], "1") || strstr(argv[2], "2")) 788 fprintf(
707 { 789 stderr,
790 "This program must be started with the interface and the operating mode as argument.\n");
791 return 1;
792 }
708 793
709 return testmode(argc, argv); 794 if (strstr(argv[2], "1") || strstr(argv[2], "2"))
710 } 795 {
796
797 return testmode(argc, argv);
711 } 798 }
799
712#if 0 800#if 0
713 u8 u8aSendBuffer[500]; 801 u8 u8aSendBuffer[500];
714 char szErrbuf[PCAP_ERRBUF_SIZE]; 802 char szErrbuf[PCAP_ERRBUF_SIZE];
diff --git a/src/transport/test_transport_api_wlan_peer1.conf b/src/transport/test_transport_api_wlan_peer1.conf
index c273d9482..62c10748a 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]
11INTERFACE = wlan0 11INTERFACE = wlan0
12TESTMODE = YES 12TESTMODE = 1
13 13
14[hostlist] 14[hostlist]
15HTTP-PROXY = 15HTTP-PROXY =
diff --git a/src/transport/test_transport_api_wlan_peer2.conf b/src/transport/test_transport_api_wlan_peer2.conf
index 7ed039f79..ce80062b3 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]
11INTERFACE = wlan1 11INTERFACE = wlan1
12TESTMODE = YES 12TESTMODE = 2
13 13
14[hostlist] 14[hostlist]
15HTTP-PROXY = 15HTTP-PROXY =