diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 71 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 346 | ||||
-rwxr-xr-x | src/transport/test_transport_api_wlan | 148 |
3 files changed, 426 insertions, 139 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 05fab4758..15fe21cfd 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "plugin_transport_wlan.h" | 38 | #include "plugin_transport_wlan.h" |
39 | #include "gnunet_common.h" | 39 | #include "gnunet_common.h" |
40 | #include "gnunet-transport-wlan-helper.h" | 40 | #include "gnunet-transport-wlan-helper.h" |
41 | #include "gnunet_crypto_lib.h" | ||
41 | #include "ieee80211_radiotap.h" | 42 | #include "ieee80211_radiotap.h" |
42 | #include <pcap.h> | 43 | #include <pcap.h> |
43 | #include <stdio.h> | 44 | #include <stdio.h> |
@@ -395,7 +396,7 @@ int ieee80211_radiotap_iterator_next( | |||
395 | 396 | ||
396 | #define FIFO_FILE1 "/tmp/MYFIFOin" | 397 | #define FIFO_FILE1 "/tmp/MYFIFOin" |
397 | #define FIFO_FILE2 "/tmp/MYFIFOout" | 398 | #define FIFO_FILE2 "/tmp/MYFIFOout" |
398 | #define MAXLINE 20 | 399 | #define MAXLINE 4096 |
399 | 400 | ||
400 | static int first; | 401 | static int first; |
401 | static int closeprog; | 402 | static int closeprog; |
@@ -420,22 +421,36 @@ stdin_send (void *cls, | |||
420 | const struct GNUNET_MessageHeader *hdr) | 421 | const struct GNUNET_MessageHeader *hdr) |
421 | { | 422 | { |
422 | struct sendbuf *write_pout = cls; | 423 | struct sendbuf *write_pout = cls; |
423 | int sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ; | 424 | int sendsize; |
424 | struct GNUNET_MessageHeader newheader; | 425 | struct GNUNET_MessageHeader newheader; |
426 | char * from; | ||
427 | char * to; | ||
425 | 428 | ||
426 | GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type)); | 429 | sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ; |
427 | GNUNET_assert (sendsize + write_pout->size < MAXLINE *2); | 430 | |
431 | |||
432 | if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){ | ||
433 | fprintf(stderr, "Function stdin_send: wrong packet type\n"); | ||
434 | exit(1); | ||
435 | } | ||
436 | if((sendsize + write_pout->size) > MAXLINE * 2){ | ||
437 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); | ||
438 | exit(1); | ||
439 | } | ||
428 | 440 | ||
429 | 441 | ||
430 | newheader.size = htons(sendsize); | 442 | newheader.size = htons(sendsize); |
431 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 443 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
432 | 444 | ||
433 | 445 | ||
434 | memcpy(write_pout->buf + write_pout->size, &newheader, sizeof(struct GNUNET_MessageHeader)); | 446 | to = write_pout->buf + write_pout->size; |
447 | memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader)); | ||
435 | write_pout->size += sizeof(struct GNUNET_MessageHeader); | 448 | write_pout->size += sizeof(struct GNUNET_MessageHeader); |
436 | 449 | ||
437 | memcpy(write_pout->buf + write_pout->size, hdr + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader), sizeof(struct GNUNET_MessageHeader)); | 450 | from = (char *) hdr + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader); |
438 | write_pout->size += sendsize; | 451 | to = write_pout->buf + write_pout->size; |
452 | memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader)); | ||
453 | write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader); | ||
439 | } | 454 | } |
440 | 455 | ||
441 | static void | 456 | static void |
@@ -444,10 +459,18 @@ file_in_send (void *cls, | |||
444 | const struct GNUNET_MessageHeader *hdr) | 459 | const struct GNUNET_MessageHeader *hdr) |
445 | { | 460 | { |
446 | struct sendbuf * write_std = cls; | 461 | struct sendbuf * write_std = cls; |
447 | int sendsize = ntohs(hdr->size); | 462 | int sendsize; |
463 | |||
464 | sendsize = ntohs(hdr->size); | ||
448 | 465 | ||
449 | GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type)); | 466 | if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){ |
450 | GNUNET_assert (sendsize + write_std->size < MAXLINE *2); | 467 | fprintf(stderr, "Function file_in_send: wrong packet type\n"); |
468 | exit(1); | ||
469 | } | ||
470 | if((sendsize + write_std->size) > MAXLINE * 2){ | ||
471 | fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); | ||
472 | exit(1); | ||
473 | } | ||
451 | 474 | ||
452 | memcpy(write_std->buf + write_std->size, hdr, sendsize); | 475 | memcpy(write_std->buf + write_std->size, hdr, sendsize); |
453 | write_std->size += sendsize; | 476 | write_std->size += sendsize; |
@@ -470,7 +493,7 @@ testmode(int argc, char *argv[]) | |||
470 | { | 493 | { |
471 | if (0 == stat(FIFO_FILE2, &st)) | 494 | if (0 == stat(FIFO_FILE2, &st)) |
472 | { | 495 | { |
473 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not"); | 496 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); |
474 | exit(1); | 497 | exit(1); |
475 | } | 498 | } |
476 | 499 | ||
@@ -484,7 +507,7 @@ testmode(int argc, char *argv[]) | |||
484 | 507 | ||
485 | if (0 != stat(FIFO_FILE2, &st)) | 508 | if (0 != stat(FIFO_FILE2, &st)) |
486 | { | 509 | { |
487 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not"); | 510 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); |
488 | exit(1); | 511 | exit(1); |
489 | } | 512 | } |
490 | 513 | ||
@@ -497,12 +520,12 @@ testmode(int argc, char *argv[]) | |||
497 | fpin = fopen(FIFO_FILE1, "r"); | 520 | fpin = fopen(FIFO_FILE1, "r"); |
498 | if (NULL == fpin) | 521 | if (NULL == fpin) |
499 | { | 522 | { |
500 | fprintf(stderr, "fopen of read FIFO_FILE1"); | 523 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); |
501 | exit(1); | 524 | exit(1); |
502 | } | 525 | } |
503 | if (NULL == (fpout = fopen(FIFO_FILE2, "w"))) | 526 | if (NULL == (fpout = fopen(FIFO_FILE2, "w"))) |
504 | { | 527 | { |
505 | fprintf(stderr, "fopen of write FIFO_FILE2"); | 528 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); |
506 | exit(1); | 529 | exit(1); |
507 | } | 530 | } |
508 | 531 | ||
@@ -513,12 +536,12 @@ testmode(int argc, char *argv[]) | |||
513 | //fprintf(stderr, "Second\n"); | 536 | //fprintf(stderr, "Second\n"); |
514 | if (NULL == (fpout = fopen(FIFO_FILE1, "w"))) | 537 | if (NULL == (fpout = fopen(FIFO_FILE1, "w"))) |
515 | { | 538 | { |
516 | fprintf(stderr, "fopen of write FIFO_FILE1"); | 539 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); |
517 | exit(1); | 540 | exit(1); |
518 | } | 541 | } |
519 | if (NULL == (fpin = fopen(FIFO_FILE2, "r"))) | 542 | if (NULL == (fpin = fopen(FIFO_FILE2, "r"))) |
520 | { | 543 | { |
521 | fprintf(stderr, "fopen of read FIFO_FILE2"); | 544 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); |
522 | exit(1); | 545 | exit(1); |
523 | } | 546 | } |
524 | 547 | ||
@@ -581,8 +604,8 @@ testmode(int argc, char *argv[]) | |||
581 | macmsg.mac.mac[1] = 0x22; | 604 | macmsg.mac.mac[1] = 0x22; |
582 | macmsg.mac.mac[2] = 0x33; | 605 | macmsg.mac.mac[2] = 0x33; |
583 | macmsg.mac.mac[3] = 0x44; | 606 | macmsg.mac.mac[3] = 0x44; |
584 | macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | 607 | macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); |
585 | macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | 608 | macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); |
586 | macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); | 609 | macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); |
587 | macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); | 610 | macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); |
588 | 611 | ||
@@ -690,7 +713,7 @@ testmode(int argc, char *argv[]) | |||
690 | if (0 > ret) | 713 | if (0 > ret) |
691 | { | 714 | { |
692 | closeprog = 1; | 715 | closeprog = 1; |
693 | fprintf(stderr, "Write ERROR to STDOUT"); | 716 | fprintf(stderr, "Write ERROR to STDOUT\n"); |
694 | exit(1); | 717 | exit(1); |
695 | } | 718 | } |
696 | else | 719 | else |
@@ -713,7 +736,7 @@ testmode(int argc, char *argv[]) | |||
713 | if (0 > ret) | 736 | if (0 > ret) |
714 | { | 737 | { |
715 | closeprog = 1; | 738 | closeprog = 1; |
716 | fprintf(stderr, "Write ERROR to fdpout"); | 739 | fprintf(stderr, "Write ERROR to fdpout\n"); |
717 | exit(1); | 740 | exit(1); |
718 | } | 741 | } |
719 | else | 742 | else |
@@ -735,10 +758,10 @@ testmode(int argc, char *argv[]) | |||
735 | if (0 > readsize) | 758 | if (0 > readsize) |
736 | { | 759 | { |
737 | closeprog = 1; | 760 | closeprog = 1; |
738 | fprintf(stderr, "Read ERROR to STDIN_FILENO"); | 761 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); |
739 | exit(1); | 762 | exit(1); |
740 | } | 763 | } |
741 | else | 764 | else if (0 < readsize) |
742 | { | 765 | { |
743 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, | 766 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, |
744 | GNUNET_NO, GNUNET_NO); | 767 | GNUNET_NO, GNUNET_NO); |
@@ -753,10 +776,10 @@ testmode(int argc, char *argv[]) | |||
753 | if (0 > readsize) | 776 | if (0 > readsize) |
754 | { | 777 | { |
755 | closeprog = 1; | 778 | closeprog = 1; |
756 | fprintf(stderr, "Read ERROR to fdpin"); | 779 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); |
757 | exit(1); | 780 | exit(1); |
758 | } | 781 | } |
759 | else | 782 | else if (0 < readsize) |
760 | { | 783 | { |
761 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, | 784 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, |
762 | GNUNET_NO, GNUNET_NO); | 785 | GNUNET_NO, GNUNET_NO); |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 9f91cbfb6..e8d4d11c5 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -206,6 +206,14 @@ struct Plugin | |||
206 | 206 | ||
207 | }; | 207 | }; |
208 | 208 | ||
209 | struct Finish_send | ||
210 | { | ||
211 | struct Plugin * plugin; | ||
212 | char * msgheader; | ||
213 | struct GNUNET_MessageHeader * msgstart; | ||
214 | ssize_t size; | ||
215 | }; | ||
216 | |||
209 | /** | 217 | /** |
210 | * Queue of sessions, for the general session queue and the pending session queue | 218 | * Queue of sessions, for the general session queue and the pending session queue |
211 | */ | 219 | */ |
@@ -555,6 +563,9 @@ wlan_process_helper (void *cls, | |||
555 | void *client, | 563 | void *client, |
556 | const struct GNUNET_MessageHeader *hdr); | 564 | const struct GNUNET_MessageHeader *hdr); |
557 | 565 | ||
566 | static void | ||
567 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
568 | |||
558 | /** | 569 | /** |
559 | * get the next message number, at the moment just a random one | 570 | * get the next message number, at the moment just a random one |
560 | * @return returns the next valid message-number for sending packets | 571 | * @return returns the next valid message-number for sending packets |
@@ -562,7 +573,7 @@ wlan_process_helper (void *cls, | |||
562 | uint32_t | 573 | uint32_t |
563 | get_next_message_id() | 574 | get_next_message_id() |
564 | { | 575 | { |
565 | return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 576 | return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
566 | } | 577 | } |
567 | 578 | ||
568 | /** | 579 | /** |
@@ -1006,14 +1017,14 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm){ | |||
1006 | } | 1017 | } |
1007 | 1018 | ||
1008 | /** | 1019 | /** |
1009 | * Function called to when wlan helper is ready to get some data | 1020 | * Function called when wlan helper is ready to get some data |
1010 | * | 1021 | * |
1011 | * @param cls closure | 1022 | * @param cls closure |
1012 | * @param tc GNUNET_SCHEDULER_TaskContext | 1023 | * @param tc GNUNET_SCHEDULER_TaskContext |
1013 | */ | 1024 | */ |
1014 | 1025 | ||
1015 | static void | 1026 | static void |
1016 | do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1027 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1017 | { | 1028 | { |
1018 | 1029 | ||
1019 | struct Plugin * plugin = cls; | 1030 | struct Plugin * plugin = cls; |
@@ -1032,6 +1043,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1032 | struct GNUNET_MessageHeader * msgheader2 = NULL; | 1043 | struct GNUNET_MessageHeader * msgheader2 = NULL; |
1033 | struct FragmentationHeader fragheader; | 1044 | struct FragmentationHeader fragheader; |
1034 | struct FragmentationHeader * fragheaderptr = NULL; | 1045 | struct FragmentationHeader * fragheaderptr = NULL; |
1046 | struct Finish_send * finish = NULL; | ||
1035 | uint16_t size = 0; | 1047 | uint16_t size = 0; |
1036 | const char * copystart = NULL; | 1048 | const char * copystart = NULL; |
1037 | uint16_t copysize = 0; | 1049 | uint16_t copysize = 0; |
@@ -1060,159 +1072,261 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1060 | getWlanHeader(ieeewlanheader); | 1072 | getWlanHeader(ieeewlanheader); |
1061 | 1073 | ||
1062 | msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1]; | 1074 | msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1]; |
1063 | msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) + sizeof(struct GNUNET_MessageHeader)); | 1075 | msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) |
1076 | + sizeof(struct GNUNET_MessageHeader)); | ||
1064 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); | 1077 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); |
1065 | 1078 | ||
1066 | memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( | 1079 | memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( |
1067 | *(plugin->env->our_hello))); | 1080 | *(plugin->env->our_hello))); |
1068 | 1081 | ||
1069 | |||
1070 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, | 1082 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, |
1071 | size); | 1083 | size); |
1084 | if (bytes == GNUNET_SYSERR) | ||
1085 | { | ||
1086 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1087 | _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), | ||
1088 | errno, strerror(errno)); | ||
1089 | |||
1090 | } | ||
1091 | GNUNET_assert(bytes != GNUNET_SYSERR); | ||
1072 | GNUNET_assert(bytes == size); | 1092 | GNUNET_assert(bytes == size); |
1073 | 1093 | ||
1094 | GNUNET_free(msgheader); | ||
1095 | |||
1074 | set_next_beacon_time(plugin); | 1096 | set_next_beacon_time(plugin); |
1075 | check_next_fragment_timeout(plugin); | 1097 | check_next_fragment_timeout(plugin); |
1098 | |||
1076 | return; | 1099 | return; |
1077 | 1100 | ||
1078 | } | 1101 | } |
1079 | 1102 | ||
1080 | |||
1081 | fm = plugin->pending_Fragment_Messages_head; | 1103 | fm = plugin->pending_Fragment_Messages_head; |
1082 | GNUNET_assert(fm != NULL); | 1104 | GNUNET_assert(fm != NULL); |
1083 | session = fm->session; | 1105 | session = fm->session; |
1084 | GNUNET_assert(session != NULL); | 1106 | GNUNET_assert(session != NULL); |
1085 | 1107 | ||
1086 | // test if message timed out | 1108 | // test if message timed out |
1087 | if (GNUNET_TIME_absolute_get_remaining(fm->timeout).rel_value == 0){ | 1109 | if (GNUNET_TIME_absolute_get_remaining(fm->timeout).rel_value == 0) |
1088 | free_acks(fm); | 1110 | { |
1089 | GNUNET_assert(plugin->pending_fragment_messages > 0); | 1111 | free_acks(fm); |
1090 | plugin->pending_fragment_messages --; | 1112 | GNUNET_assert(plugin->pending_fragment_messages > 0); |
1091 | GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head, | 1113 | plugin->pending_fragment_messages--; |
1092 | plugin->pending_Fragment_Messages_tail, fm); | 1114 | GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head, |
1115 | plugin->pending_Fragment_Messages_tail, fm); | ||
1093 | 1116 | ||
1094 | GNUNET_free(fm->msg); | 1117 | GNUNET_free(fm->msg); |
1095 | 1118 | ||
1096 | GNUNET_free(fm); | 1119 | GNUNET_free(fm); |
1097 | check_fragment_queue(plugin); | 1120 | check_fragment_queue(plugin); |
1098 | } else { | 1121 | } |
1122 | else | ||
1123 | { | ||
1099 | 1124 | ||
1100 | if (fm->message_size > WLAN_MTU) { | 1125 | if (fm->message_size > WLAN_MTU) |
1101 | size += sizeof(struct FragmentationHeader); | 1126 | { |
1102 | // check/set for retransmission | 1127 | size += sizeof(struct FragmentationHeader); |
1103 | if (GNUNET_TIME_absolute_get_duration(fm->next_ack).rel_value == 0) { | 1128 | // check/set for retransmission |
1129 | if (GNUNET_TIME_absolute_get_duration(fm->next_ack).rel_value == 0) | ||
1130 | { | ||
1104 | 1131 | ||
1105 | // be positive and try again later :-D | 1132 | // be positive and try again later :-D |
1106 | fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(fm)); | 1133 | fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout( |
1107 | // find first missing fragment | 1134 | fm)); |
1108 | akt = fm->head; | 1135 | // find first missing fragment |
1109 | fm->message_pos = 0; | 1136 | akt = fm->head; |
1137 | fm->message_pos = 0; | ||
1110 | 1138 | ||
1111 | //test if ack 0 was already received | 1139 | //test if ack 0 was already received |
1112 | while (akt != NULL){ | 1140 | while (akt != NULL) |
1113 | //if fragment is present, take next | 1141 | { |
1114 | if (akt->fragment_num == fm->message_pos) { | 1142 | //if fragment is present, take next |
1115 | fm->message_pos ++; | 1143 | if (akt->fragment_num == fm->message_pos) |
1116 | } | 1144 | { |
1117 | //next ack is bigger then the fragment number | 1145 | fm->message_pos++; |
1118 | //in case there is something like this: (acks) 1, 2, 5, 6, ... | 1146 | } |
1119 | //and we send 3 again, the next number should be 4 | 1147 | //next ack is bigger then the fragment number |
1120 | else if (akt->fragment_num > fm->message_pos) { | 1148 | //in case there is something like this: (acks) 1, 2, 5, 6, ... |
1121 | break; | 1149 | //and we send 3 again, the next number should be 4 |
1122 | } | 1150 | else if (akt->fragment_num > fm->message_pos) |
1123 | 1151 | { | |
1124 | akt = akt->next; | 1152 | break; |
1153 | } | ||
1125 | 1154 | ||
1126 | } | 1155 | akt = akt->next; |
1127 | 1156 | ||
1157 | } | ||
1128 | 1158 | ||
1129 | } | 1159 | } |
1130 | 1160 | ||
1131 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) * fm->message_pos; | 1161 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) |
1132 | fragheader.fragment_off_or_num = htons(fm->message_pos); | 1162 | * fm->message_pos; |
1133 | fragheader.message_id = htonl(session->message_id_out); | 1163 | fragheader.fragment_off_or_num = htons(fm->message_pos); |
1164 | fragheader.message_id = htonl(session->message_id_out); | ||
1165 | |||
1166 | // start should be smaller then the packet size | ||
1167 | GNUNET_assert(copyoffset < fm->message_size); | ||
1168 | copystart = fm->msg + copyoffset; | ||
1169 | |||
1170 | //size of the fragment is either the MTU - overhead | ||
1171 | //or the missing part of the message in case this is the last fragment | ||
1172 | copysize = GNUNET_MIN(fm->message_size - copyoffset, | ||
1173 | WLAN_MTU - sizeof(struct FragmentationHeader)); | ||
1174 | fragheader.header.size = htons(copysize | ||
1175 | + sizeof(struct FragmentationHeader)); | ||
1176 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); | ||
1177 | |||
1178 | //get the next missing fragment | ||
1179 | akt = fm->head; | ||
1180 | fm->message_pos++; | ||
1181 | |||
1182 | //test if ack was already received | ||
1183 | while (akt != NULL) | ||
1184 | { | ||
1185 | //if fragment is present, take next | ||
1186 | if (akt->fragment_num == fm->message_pos) | ||
1187 | { | ||
1188 | fm->message_pos++; | ||
1189 | } | ||
1190 | //next ack is bigger then the fragment number | ||
1191 | //in case there is something like this: (acks) 1, 2, 5, 6, ... | ||
1192 | //and we send 3 again, the next number should be 4 | ||
1193 | else if (akt->fragment_num > fm->message_pos) | ||
1194 | { | ||
1195 | break; | ||
1196 | } | ||
1134 | 1197 | ||
1135 | // start should be smaller then the packet size | 1198 | akt = akt->next; |
1136 | GNUNET_assert(copyoffset < fm->message_size); | 1199 | } |
1137 | copystart = fm->msg + copyoffset; | 1200 | } |
1201 | else | ||
1202 | { | ||
1203 | // there is no need to split | ||
1204 | copystart = fm->msg; | ||
1205 | copysize = fm->message_size; | ||
1206 | } | ||
1138 | 1207 | ||
1139 | //size of the fragment is either the MTU - overhead | 1208 | size += copysize; |
1140 | //or the missing part of the message in case this is the last fragment | 1209 | size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader) |
1141 | copysize = GNUNET_MIN(fm->message_size - copyoffset, | 1210 | + sizeof(struct GNUNET_MessageHeader); |
1142 | WLAN_MTU - sizeof(struct FragmentationHeader)); | 1211 | msgheader = GNUNET_malloc(size); |
1143 | fragheader.header.size = htons(copysize + sizeof(struct FragmentationHeader)); | 1212 | msgheader->size = htons(size); |
1144 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); | 1213 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
1145 | 1214 | ||
1215 | radioHeader = (struct RadiotapHeader*) &msgheader[1]; | ||
1216 | getRadiotapHeader(radioHeader); | ||
1146 | 1217 | ||
1147 | //get the next missing fragment | 1218 | ieeewlanheader = (struct IeeeHeader *) &radioHeader[1]; |
1148 | akt = fm->head; | 1219 | getWlanHeader(ieeewlanheader); |
1149 | fm->message_pos ++; | ||
1150 | 1220 | ||
1151 | //test if ack was already received | 1221 | //could be faster if content is just send and not copyed before |
1152 | while (akt != NULL){ | 1222 | //fragmentheader is needed |
1153 | //if fragment is present, take next | 1223 | if (fm->message_size > WLAN_MTU) |
1154 | if (akt->fragment_num == fm->message_pos) { | 1224 | { |
1155 | fm->message_pos ++; | 1225 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); |
1156 | } | 1226 | memcpy(&ieeewlanheader[1], &fragheader, |
1157 | //next ack is bigger then the fragment number | 1227 | sizeof(struct FragmentationHeader)); |
1158 | //in case there is something like this: (acks) 1, 2, 5, 6, ... | 1228 | fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1]; |
1159 | //and we send 3 again, the next number should be 4 | 1229 | memcpy(&fragheaderptr[1], copystart, copysize); |
1160 | else if (akt->fragment_num > fm->message_pos) { | 1230 | } |
1161 | break; | 1231 | else |
1162 | } | 1232 | { |
1233 | memcpy(&ieeewlanheader[1], copystart, copysize); | ||
1234 | } | ||
1163 | 1235 | ||
1164 | akt = akt->next; | 1236 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); |
1165 | } | 1237 | if (bytes == GNUNET_SYSERR){ |
1166 | } else { | 1238 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1167 | // there is no need to split | 1239 | _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), errno, strerror(errno) ); |
1168 | copystart = fm->msg; | ||
1169 | copysize = fm->message_size; | ||
1170 | } | ||
1171 | |||
1172 | size += copysize; | ||
1173 | size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader) | ||
1174 | + sizeof(struct GNUNET_MessageHeader); | ||
1175 | msgheader = GNUNET_malloc(size); | ||
1176 | msgheader->size = htons(size); | ||
1177 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | ||
1178 | |||
1179 | radioHeader = (struct RadiotapHeader*) &msgheader[1]; | ||
1180 | getRadiotapHeader(radioHeader); | ||
1181 | |||
1182 | ieeewlanheader = (struct IeeeHeader *) &radioHeader[1]; | ||
1183 | getWlanHeader(ieeewlanheader); | ||
1184 | |||
1185 | |||
1186 | //could be faster if content is just send and not copyed before | ||
1187 | //fragmentheader is needed | ||
1188 | if (fm->message_size > WLAN_MTU){ | ||
1189 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); | ||
1190 | memcpy(&ieeewlanheader[1],&fragheader, sizeof(struct FragmentationHeader)); | ||
1191 | fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1]; | ||
1192 | memcpy(&fragheaderptr[1],copystart,copysize); | ||
1193 | } else { | ||
1194 | memcpy(&ieeewlanheader[1],copystart,copysize); | ||
1195 | } | ||
1196 | 1240 | ||
1197 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); | 1241 | } |
1198 | GNUNET_assert(bytes == size); | 1242 | GNUNET_assert(bytes != GNUNET_SYSERR); |
1199 | 1243 | ||
1200 | //check if this was the last fragment of this message, if true then queue at the end of the list | 1244 | if (bytes != size) |
1201 | if (copysize + copyoffset >= fm->message_size){ | 1245 | { |
1202 | GNUNET_assert(copysize + copyoffset == fm->message_size); | 1246 | finish = GNUNET_malloc(sizeof( struct Finish_send)); |
1247 | finish->plugin = plugin; | ||
1248 | finish->msgheader = (char * ) msgheader + bytes; | ||
1249 | finish->size = size - bytes; | ||
1250 | finish->msgstart = msgheader; | ||
1203 | 1251 | ||
1204 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, | 1252 | GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); |
1205 | plugin->pending_Fragment_Messages_tail, fm); | ||
1206 | 1253 | ||
1207 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head, | 1254 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( |
1208 | plugin->pending_Fragment_Messages_tail, fm); | 1255 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, |
1209 | // if fragments have opimized timeouts | 1256 | &finish_sending, finish); |
1210 | //sort_fragment_into_queue(plugin,fm); | ||
1211 | 1257 | ||
1212 | } | 1258 | } |
1213 | check_next_fragment_timeout(plugin); | 1259 | else |
1260 | { | ||
1261 | GNUNET_assert(bytes == size); | ||
1262 | |||
1263 | GNUNET_free(msgheader); | ||
1264 | check_next_fragment_timeout(plugin); | ||
1265 | } | ||
1266 | |||
1267 | //check if this was the last fragment of this message, if true then queue at the end of the list | ||
1268 | if (copysize + copyoffset >= fm->message_size) | ||
1269 | { | ||
1270 | GNUNET_assert(copysize + copyoffset == fm->message_size); | ||
1271 | |||
1272 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, | ||
1273 | plugin->pending_Fragment_Messages_tail, fm); | ||
1274 | |||
1275 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head, | ||
1276 | plugin->pending_Fragment_Messages_tail, fm); | ||
1277 | // if fragments have opimized timeouts | ||
1278 | //sort_fragment_into_queue(plugin,fm); | ||
1279 | |||
1280 | } | ||
1281 | |||
1282 | } | ||
1283 | } | ||
1284 | |||
1285 | |||
1286 | static void | ||
1287 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1288 | { | ||
1289 | struct Finish_send * finish; | ||
1290 | struct Plugin * plugin; | ||
1291 | ssize_t bytes; | ||
1292 | |||
1293 | finish = cls; | ||
1294 | plugin = finish->plugin; | ||
1295 | |||
1296 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; | ||
1297 | |||
1298 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, finish->msgheader, finish->size); | ||
1299 | GNUNET_assert(bytes != GNUNET_SYSERR); | ||
1300 | |||
1301 | GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); | ||
1302 | if (bytes != finish->size) | ||
1303 | { | ||
1304 | |||
1305 | finish->plugin = plugin; | ||
1306 | finish->msgheader = finish->msgheader + bytes; | ||
1307 | finish->size = finish->size - bytes; | ||
1308 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( | ||
1309 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, | ||
1310 | &finish_sending, finish); | ||
1311 | } | ||
1312 | else | ||
1313 | { | ||
1314 | GNUNET_free(finish->msgstart); | ||
1315 | GNUNET_free(finish); | ||
1316 | check_next_fragment_timeout(plugin); | ||
1317 | } | ||
1214 | 1318 | ||
1215 | } | 1319 | } |
1320 | |||
1321 | int | ||
1322 | getRadiotapHeader(struct RadiotapHeader * Header){ | ||
1323 | return GNUNET_YES; | ||
1324 | }; | ||
1325 | |||
1326 | int | ||
1327 | getWlanHeader(struct IeeeHeader * Header){ | ||
1328 | |||
1329 | return GNUNET_YES; | ||
1216 | } | 1330 | } |
1217 | 1331 | ||
1218 | 1332 | ||
@@ -1746,7 +1860,7 @@ wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * h | |||
1746 | session_light->session = search_session(plugin, session_light->addr); | 1860 | session_light->session = search_session(plugin, session_light->addr); |
1747 | } | 1861 | } |
1748 | session = session_light->session; | 1862 | session = session_light->session; |
1749 | wlanheader = (struct WlanHeader *) &hdr[1]; | 1863 | wlanheader = (struct WlanHeader *) &hdr; |
1750 | tempmsg = (char*) &wlanheader[1]; | 1864 | tempmsg = (char*) &wlanheader[1]; |
1751 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; | 1865 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; |
1752 | 1866 | ||
@@ -2149,6 +2263,8 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) | |||
2149 | "Adding server_read_task for the wlan-helper\n"); | 2263 | "Adding server_read_task for the wlan-helper\n"); |
2150 | #endif | 2264 | #endif |
2151 | 2265 | ||
2266 | sleep(2); | ||
2267 | |||
2152 | plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( | 2268 | plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( |
2153 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, | 2269 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, |
2154 | &wlan_plugin_helper_read, plugin); | 2270 | &wlan_plugin_helper_read, plugin); |
diff --git a/src/transport/test_transport_api_wlan b/src/transport/test_transport_api_wlan new file mode 100755 index 000000000..49f205d3b --- /dev/null +++ b/src/transport/test_transport_api_wlan | |||
@@ -0,0 +1,148 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | # test_transport_api_wlan - temporary wrapper script for .libs/test_transport_api_wlan | ||
4 | # Generated by ltmain.sh (GNU libtool) 2.2.6b | ||
5 | # | ||
6 | # The test_transport_api_wlan program cannot be directly executed until all the libtool | ||
7 | # libraries that it depends on are installed. | ||
8 | # | ||
9 | # This wrapper script should never be moved out of the build directory. | ||
10 | # If it is, it will not operate correctly. | ||
11 | |||
12 | # Sed substitution that helps us do robust quoting. It backslashifies | ||
13 | # metacharacters that are still active within double-quoted strings. | ||
14 | Xsed='/bin/sed -e 1s/^X//' | ||
15 | sed_quote_subst='s/\([`"$\\]\)/\\\1/g' | ||
16 | |||
17 | # Be Bourne compatible | ||
18 | if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then | ||
19 | emulate sh | ||
20 | NULLCMD=: | ||
21 | # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which | ||
22 | # is contrary to our usage. Disable this feature. | ||
23 | alias -g '${1+"$@"}'='"$@"' | ||
24 | setopt NO_GLOB_SUBST | ||
25 | else | ||
26 | case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac | ||
27 | fi | ||
28 | BIN_SH=xpg4; export BIN_SH # for Tru64 | ||
29 | DUALCASE=1; export DUALCASE # for MKS sh | ||
30 | |||
31 | # The HP-UX ksh and POSIX shell print the target directory to stdout | ||
32 | # if CDPATH is set. | ||
33 | (unset CDPATH) >/dev/null 2>&1 && unset CDPATH | ||
34 | |||
35 | relink_command="(cd /home/david/Dokumente/gnunet/src/transport; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/david/bin; export PATH; gcc -fno-strict-aliasing -Wall -g -O2 -o \$progdir/\$file test_transport_api.o -L/home/david/lib ../../src/transport/.libs/libgnunettransport.so /home/david/Dokumente/gnunet/src/hello/.libs/libgnunethello.so /home/david/Dokumente/gnunet/src/util/.libs/libgnunetutil.so ../../src/util/.libs/libgnunetutil.so -lgcrypt -lgpg-error -lltdl -lz -lm -ldl -Wl,-rpath -Wl,/home/david/Dokumente/gnunet/src/transport/.libs -Wl,-rpath -Wl,/home/david/Dokumente/gnunet/src/hello/.libs -Wl,-rpath -Wl,/home/david/Dokumente/gnunet/src/util/.libs -Wl,-rpath -Wl,/home/david/lib)" | ||
36 | |||
37 | # This environment variable determines our operation mode. | ||
38 | if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then | ||
39 | # install mode needs the following variables: | ||
40 | generated_by_libtool_version='2.2.6b' | ||
41 | notinst_deplibs=' ../../src/transport/libgnunettransport.la /home/david/Dokumente/gnunet/src/hello/libgnunethello.la /home/david/Dokumente/gnunet/src/util/libgnunetutil.la ../../src/util/libgnunetutil.la' | ||
42 | else | ||
43 | # When we are sourced in execute mode, $file and $ECHO are already set. | ||
44 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
45 | ECHO="echo" | ||
46 | file="$0" | ||
47 | # Make sure echo works. | ||
48 | if test "X$1" = X--no-reexec; then | ||
49 | # Discard the --no-reexec flag, and continue. | ||
50 | shift | ||
51 | elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then | ||
52 | # Yippee, $ECHO works! | ||
53 | : | ||
54 | else | ||
55 | # Restart under the correct shell, and then maybe $ECHO will work. | ||
56 | exec /bin/sh "$0" --no-reexec ${1+"$@"} | ||
57 | fi | ||
58 | fi | ||
59 | |||
60 | # Find the directory that this script lives in. | ||
61 | thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` | ||
62 | test "x$thisdir" = "x$file" && thisdir=. | ||
63 | |||
64 | # Follow symbolic links until we get to the real thisdir. | ||
65 | file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` | ||
66 | while test -n "$file"; do | ||
67 | destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` | ||
68 | |||
69 | # If there was a directory component, then change thisdir. | ||
70 | if test "x$destdir" != "x$file"; then | ||
71 | case "$destdir" in | ||
72 | [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; | ||
73 | *) thisdir="$thisdir/$destdir" ;; | ||
74 | esac | ||
75 | fi | ||
76 | |||
77 | file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` | ||
78 | file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` | ||
79 | done | ||
80 | |||
81 | |||
82 | # Usually 'no', except on cygwin/mingw when embedded into | ||
83 | # the cwrapper. | ||
84 | WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no | ||
85 | if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then | ||
86 | # special case for '.' | ||
87 | if test "$thisdir" = "."; then | ||
88 | thisdir=`pwd` | ||
89 | fi | ||
90 | # remove .libs from thisdir | ||
91 | case "$thisdir" in | ||
92 | *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; | ||
93 | .libs ) thisdir=. ;; | ||
94 | esac | ||
95 | fi | ||
96 | |||
97 | # Try to get the absolute directory name. | ||
98 | absdir=`cd "$thisdir" && pwd` | ||
99 | test -n "$absdir" && thisdir="$absdir" | ||
100 | |||
101 | program=lt-'test_transport_api_wlan' | ||
102 | progdir="$thisdir/.libs" | ||
103 | |||
104 | if test ! -f "$progdir/$program" || | ||
105 | { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ | ||
106 | test "X$file" != "X$progdir/$program"; }; then | ||
107 | |||
108 | file="$$-$program" | ||
109 | |||
110 | if test ! -d "$progdir"; then | ||
111 | mkdir "$progdir" | ||
112 | else | ||
113 | rm -f "$progdir/$file" | ||
114 | fi | ||
115 | |||
116 | # relink executable if necessary | ||
117 | if test -n "$relink_command"; then | ||
118 | if relink_command_output=`eval $relink_command 2>&1`; then : | ||
119 | else | ||
120 | echo "$relink_command_output" >&2 | ||
121 | rm -f "$progdir/$file" | ||
122 | exit 1 | ||
123 | fi | ||
124 | fi | ||
125 | |||
126 | mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || | ||
127 | { rm -f "$progdir/$program"; | ||
128 | mv -f "$progdir/$file" "$progdir/$program"; } | ||
129 | rm -f "$progdir/$file" | ||
130 | fi | ||
131 | |||
132 | if test -f "$progdir/$program"; then | ||
133 | if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then | ||
134 | # Run the actual program with our arguments. | ||
135 | |||
136 | exec "$progdir/$program" ${1+"$@"} | ||
137 | |||
138 | $ECHO "$0: cannot exec $program $*" 1>&2 | ||
139 | exit 1 | ||
140 | fi | ||
141 | else | ||
142 | # The program doesn't exist. | ||
143 | $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 | ||
144 | $ECHO "This script is just a wrapper for $program." 1>&2 | ||
145 | echo "See the libtool documentation for more information." 1>&2 | ||
146 | exit 1 | ||
147 | fi | ||
148 | fi | ||