aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-07-12 21:34:34 +0000
committerDavid Brodski <david@brodski.eu>2011-07-12 21:34:34 +0000
commitc584d8950bda4b27ccc2fa03de2cee23a8ae56d2 (patch)
tree8156e7a7557b9578f99f973805fa329b5dfeeb81 /src/transport
parentad04126c71ef4de17657391ecc656d5bfd32f5fd (diff)
downloadgnunet-c584d8950bda4b27ccc2fa03de2cee23a8ae56d2.tar.gz
gnunet-c584d8950bda4b27ccc2fa03de2cee23a8ae56d2.zip
one wlan card is now usable with more than one peer, wlan header format changed so be careful and do not mix protocol versions. Some cleanup and formating.
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_wlan.c900
-rw-r--r--src/transport/plugin_transport_wlan.h157
2 files changed, 615 insertions, 442 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 90a807fbe..13c16d9d7 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -110,28 +110,28 @@
110 * Structure of an internet header, naked of options. 110 * Structure of an internet header, naked of options.
111 */ 111 */
112struct iph 112struct iph
113 { 113{
114#if __BYTE_ORDER == __LITTLE_ENDIAN 114#if __BYTE_ORDER == __LITTLE_ENDIAN
115 unsigned int ip_hl:4; /* header length */ 115 unsigned int ip_hl :4; /* header length */
116 unsigned int ip_v:4; /* version */ 116 unsigned int ip_v :4; /* version */
117#endif 117#endif
118#if __BYTE_ORDER == __BIG_ENDIAN 118#if __BYTE_ORDER == __BIG_ENDIAN
119 unsigned int ip_v:4; /* version */ 119 unsigned int ip_v:4; /* version */
120 unsigned int ip_hl:4; /* header length */ 120 unsigned int ip_hl:4; /* header length */
121#endif 121#endif
122 u_int8_t ip_tos; /* type of service */ 122 u_int8_t ip_tos; /* type of service */
123 u_short ip_len; /* total length */ 123 u_short ip_len; /* total length */
124 u_short ip_id; /* identification */ 124 u_short ip_id; /* identification */
125 u_short ip_off; /* fragment offset field */ 125 u_short ip_off; /* fragment offset field */
126#define IP_RF 0x8000 /* reserved fragment flag */ 126#define IP_RF 0x8000 /* reserved fragment flag */
127#define IP_DF 0x4000 /* dont fragment flag */ 127#define IP_DF 0x4000 /* dont fragment flag */
128#define IP_MF 0x2000 /* more fragments flag */ 128#define IP_MF 0x2000 /* more fragments flag */
129#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 129#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
130 u_int8_t ip_ttl; /* time to live */ 130 u_int8_t ip_ttl; /* time to live */
131 u_int8_t ip_p; /* protocol */ 131 u_int8_t ip_p; /* protocol */
132 u_short ip_sum; /* checksum */ 132 u_short ip_sum; /* checksum */
133 struct in_addr ip_src, ip_dst; /* source and dest address */ 133 struct in_addr ip_src, ip_dst; /* source and dest address */
134 }; 134};
135 135
136struct udphdr 136struct udphdr
137{ 137{
@@ -144,19 +144,20 @@ struct udphdr
144/* 144/*
145 * generic definitions for IEEE 802.11 frames 145 * generic definitions for IEEE 802.11 frames
146 */ 146 */
147struct ieee80211_frame { 147struct ieee80211_frame
148 u_int8_t i_fc[2]; 148{
149 u_int8_t i_dur[2]; 149 u_int8_t i_fc[2];
150 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 150 u_int8_t i_dur[2];
151 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 151 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
152 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 152 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
153 u_int8_t i_seq[2]; 153 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
154 u_int8_t i_seq[2];
154#if DEBUG_wlan_ip_udp_packets_on_air 155#if DEBUG_wlan_ip_udp_packets_on_air
155 u_int8_t llc[4]; 156u_int8_t llc[4];
156 struct iph ip; 157struct iph ip;
157 struct udphdr udp; 158struct udphdr udp;
158#endif 159#endif
159} GNUNET_PACKED; 160}GNUNET_PACKED;
160/** 161/**
161 * Initial handshake message for a session. 162 * Initial handshake message for a session.
162 */ 163 */
@@ -185,19 +186,19 @@ struct Plugin
185 struct GNUNET_TRANSPORT_PluginEnvironment *env; 186 struct GNUNET_TRANSPORT_PluginEnvironment *env;
186 187
187 /** 188 /**
188 * List of open sessions. head 189 * List of open connections. head
189 */ 190 */
190 struct Sessionqueue *sessions; 191 struct MacEndpoint * mac_head;
191 192
192 /** 193 /**
193 * List of open sessions. tail 194 * List of open connections. tail
194 */ 195 */
195 struct Sessionqueue *sessions_tail; 196 struct MacEndpoint * mac_tail;
196 197
197 /** 198 /**
198 * Number of sessions 199 * Number of connections
199 */ 200 */
200 unsigned int session_count; 201 unsigned int mac_count;
201 202
202 /** 203 /**
203 * encapsulation of data from the local wlan helper program 204 * encapsulation of data from the local wlan helper program
@@ -353,9 +354,9 @@ struct Receive_Fragment_Queue
353}; 354};
354 355
355//TODO DOXIGEN 356//TODO DOXIGEN
356struct Session_id_fragment_triple 357struct MacEndpoint_id_fragment_triple
357{ 358{
358 struct Session * session; 359 struct MacEndpoint * endpoint;
359 uint32_t message_id; 360 uint32_t message_id;
360 struct FragmentMessage * fm; 361 struct FragmentMessage * fm;
361}; 362};
@@ -404,7 +405,13 @@ struct Receive_Message_Queue
404 * Session this fragment belongs to 405 * Session this fragment belongs to
405 */ 406 */
406 407
407 struct Session * session; 408 //struct Session * session;
409
410 /**
411 * Mac enddpoint this fragment belongs to
412 */
413
414 struct MacEndpoint * endpoint;
408 415
409 /** 416 /**
410 * Timeout value for the pending message. 417 * Timeout value for the pending message.
@@ -424,6 +431,14 @@ struct Receive_Message_Queue
424 */ 431 */
425struct PendingMessage 432struct PendingMessage
426{ 433{
434 /**
435 * dll next
436 */
437 struct PendingMessage * next;
438 /**
439 * dll prev
440 */
441 struct PendingMessage * prev;
427 442
428 /** 443 /**
429 * The pending message 444 * The pending message
@@ -471,7 +486,7 @@ struct AckSendQueue
471 /** 486 /**
472 * pointer to the session this ack belongs to 487 * pointer to the session this ack belongs to
473 */ 488 */
474 struct Session * session; 489 struct MacEndpoint * endpoint;
475 /** 490 /**
476 * ID of message, to distinguish between the messages, picked randomly. 491 * ID of message, to distinguish between the messages, picked randomly.
477 */ 492 */
@@ -498,6 +513,11 @@ struct Session_light
498 * peer mac address 513 * peer mac address
499 */ 514 */
500 struct MacAddress addr; 515 struct MacAddress addr;
516
517 /**
518 * mac endpoint
519 */
520 struct MacEndpoint * macendpoint;
501}; 521};
502 522
503/** 523/**
@@ -512,21 +532,16 @@ struct Session
512 struct SessionHeader header; 532 struct SessionHeader header;
513 533
514 /** 534 /**
515 * Pointer to the global plugin struct.
516 */
517 struct Plugin *plugin;
518
519 /**
520 * Message currently pending for transmission 535 * Message currently pending for transmission
521 * to this peer, if any. 536 * to this peer, if any. head
522 */ 537 */
523 struct PendingMessage *pending_message; 538 struct PendingMessage * pending_message_head;
524 539
525 /** 540 /**
526 * Message currently pending for transmission 541 * Message currently pending for transmission
527 * to this peer, if any. 542 * to this peer, if any. tail
528 */ 543 */
529 struct PendingMessage *pending_message2; 544 struct PendingMessage * pending_message_tail;
530 545
531 /** 546 /**
532 * To whom are we talking to (set to our identity 547 * To whom are we talking to (set to our identity
@@ -535,11 +550,6 @@ struct Session
535 struct GNUNET_PeerIdentity target; 550 struct GNUNET_PeerIdentity target;
536 551
537 /** 552 /**
538 * peer mac address
539 */
540 struct MacAddress addr;
541
542 /**
543 * Address of the other peer (either based on our 'connect' 553 * Address of the other peer (either based on our 'connect'
544 * call or on our 'accept' call). 554 * call or on our 'accept' call).
545 */ 555 */
@@ -552,6 +562,44 @@ struct Session
552 struct GNUNET_TIME_Absolute last_activity; 562 struct GNUNET_TIME_Absolute last_activity;
553 563
554 /** 564 /**
565 * peer connection
566 */
567 struct MacEndpoint * mac;
568
569};
570
571/**
572 * Struct to represent one network card connection
573 */
574struct MacEndpoint
575{
576 /**
577 * Pointer to the global plugin struct.
578 */
579 struct Plugin *plugin;
580 /**
581 * Struct to hold the session reachable over this mac; head
582 */
583 struct Sessionqueue * sessions_head;
584 /**
585 * Struct to hold the session reachable over this mac; tail
586 */
587 struct Sessionqueue * sessions_tail;
588 /**
589 * dll next
590 */
591 struct MacEndpoint *next;
592 /**
593 * dll prev
594 */
595 struct MacEndpoint *prev;
596
597 /**
598 * peer mac address
599 */
600 struct MacAddress addr;
601
602 /**
555 * count of messages in the fragment out queue for this session 603 * count of messages in the fragment out queue for this session
556 */ 604 */
557 605
@@ -568,7 +616,6 @@ struct Session
568 uint16_t tx_power; 616 uint16_t tx_power;
569 uint8_t antenna; 617 uint8_t antenna;
570 618
571
572 /** 619 /**
573 * backlog for incoming message ids 620 * backlog for incoming message ids
574 */ 621 */
@@ -673,6 +720,9 @@ struct FragmentationAckHeader
673 720
674static void 721static void
675do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 722do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
723static void
724free_session(struct Plugin * plugin, struct Sessionqueue * queue,
725 int do_free_macendpoint);
676 726
677/** 727/**
678 * Generates a nice hexdump of a memory area. 728 * Generates a nice hexdump of a memory area.
@@ -680,46 +730,52 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
680 * \param mem pointer to memory to dump 730 * \param mem pointer to memory to dump
681 * \param length how many bytes to dump 731 * \param length how many bytes to dump
682 */ 732 */
683void hexdump(void *mem, unsigned length) 733void
734hexdump(void *mem, unsigned length)
684{ 735{
685 char line[80]; 736 char line[80];
686 char *src = (char*)mem; 737 char *src = (char*) mem;
687 738
688 printf( 739 printf(
689 "dumping %u bytes from %p\r\n" 740 "dumping %u bytes from %p\r\n"
690 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n" 741 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
691 , length, src 742 length, src);
692 );
693 unsigned i; 743 unsigned i;
694 int j; 744 int j;
695 745
696 for (i=0; i<length; i+=16, src+=16) { 746 for (i = 0; i < length; i += 16, src += 16)
697 char *t = line; 747 {
748 char *t = line;
749
750 t += sprintf(t, "%04x: ", i);
751 for (j = 0; j < 16; j++)
752 {
753 if (i + j < length)
754 t += sprintf(t, "%02X", src[j] & 0xff);
755 else
756 t += sprintf(t, " ");
757 t += sprintf(t, j % 2 ? " " : "-");
758 }
698 759
699 t += sprintf(t, "%04x: ", i); 760 t += sprintf(t, " ");
700 for ( j=0; j<16; j++) { 761 for (j = 0; j < 16; j++)
701 if (i+j < length) 762 {
702 t += sprintf(t, "%02X", src[j] & 0xff); 763 if (i + j < length)
703 else 764 {
704 t += sprintf(t, " "); 765 if (isprint((unsigned char)src[j]))
705 t += sprintf(t, j%2 ? " " : "-"); 766 t += sprintf(t, "%c", src[j]);
706 } 767 else
768 t += sprintf(t, ".");
769 }
770 else
771 {
772 t += sprintf(t, " ");
773 }
774 }
707 775
708 t += sprintf(t, " "); 776 t += sprintf(t, "\r\n");
709 for (j=0; j<16; j++) { 777 printf("%s", line);
710 if (i+j < length) {
711 if (isprint((unsigned char)src[j]))
712 t += sprintf(t, "%c", src[j]);
713 else
714 t += sprintf(t, ".");
715 } else {
716 t += sprintf(t, " ");
717 }
718 } 778 }
719
720 t += sprintf(t, "\r\n");
721 printf("%s", line);
722 }
723} 779}
724 780
725/** 781/**
@@ -770,22 +826,77 @@ get_next_message_id()
770 return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 826 return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
771} 827}
772 828
829static struct MacEndpoint *
830create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr)
831{
832 struct MacEndpoint * newend = GNUNET_malloc(sizeof (struct MacEndpoint));
833 newend->addr = *addr;
834 newend->plugin = plugin;
835 newend->addr = *addr;
836 newend->fragment_messages_out_count = 0;
837 newend->fragment_messages_in_count = 0;
838 newend->message_id_backlog_pos = 0;
839
840 plugin->mac_count++;
841 GNUNET_CONTAINER_DLL_insert_tail(plugin->mac_head, plugin->mac_tail, newend);
842
843 return newend;
844}
845
773/** 846/**
774 * search for a session with the addr 847 * Function to find a MacEndpoint with a specific mac addr
848 * @param plugin pointer to the plugin struct
849 * @param addr pointer to the mac address
850 * @param create_new GNUNET_YES if a new end point should be created
851 * @return
852 */
853static struct MacEndpoint *
854get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr,
855 int create_new)
856{
857 struct MacEndpoint * queue = plugin->mac_head;
858 while (queue != NULL)
859 {
860 GNUNET_assert (queue->sessions_head != NULL);
861 if (memcmp(addr, &queue->addr, sizeof(struct MacAddress)) == 0)
862 return queue; /* session found */
863 queue = queue->next;
864 }
865
866 if (create_new == GNUNET_YES)
867 {
868 return create_macendpoint(plugin, addr);
869 }
870 else
871 {
872 return NULL;
873 }
874
875}
876/**
877 * search for a session with the addr and peer id
775 * 878 *
776 * @param plugin pointer to the plugin struct 879 * @param plugin pointer to the plugin struct
777 * @param addr pointer to the mac address of the peer 880 * @param addr pointer to the mac address of the peer
881 * @param peer pointer to the peerid
778 * @return returns the session 882 * @return returns the session
779 */ 883 */
780static struct Session * 884static struct Session *
781search_session(struct Plugin *plugin, const struct MacAddress *addr) 885search_session(struct Plugin *plugin, const struct MacAddress *addr,
886 const struct GNUNET_PeerIdentity * peer)
782{ 887{
783 struct Sessionqueue * queue = plugin->sessions; 888 struct MacEndpoint * endpoint = get_macendpoint(plugin, addr, GNUNET_NO);
889 if (endpoint == NULL)
890 {
891 return NULL;
892 }
893 struct Sessionqueue * queue = endpoint->sessions_head;
784 894
785 while (queue != NULL) 895 while (queue != NULL)
786 { 896 {
787 GNUNET_assert (queue->content != NULL); 897 GNUNET_assert (queue->content != NULL);
788 if (memcmp(addr, &queue->content->addr, sizeof(struct MacAddress)) == 0) 898 if (memcmp(peer, &queue->content->target,
899 sizeof(struct GNUNET_PeerIdentity)) == 0)
789 return queue->content; /* session found */ 900 return queue->content; /* session found */
790 queue = queue->next; 901 queue = queue->next;
791 } 902 }
@@ -825,29 +936,27 @@ wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
825 * create a new session 936 * create a new session
826 * 937 *
827 * @param plugin pointer to the plugin struct 938 * @param plugin pointer to the plugin struct
828 * @param addr pointer to the mac address of the peer 939 * @param addr pointer to the mac endpoint of the peer
829 * @return returns the session 940 * @return returns the session
830 */ 941 */
831 942
832static struct Session * 943static struct Session *
833create_session(struct Plugin *plugin, const struct MacAddress * addr) 944create_session(struct Plugin *plugin, struct MacEndpoint * endpoint,
945 const struct GNUNET_PeerIdentity * peer)
834{ 946{
947 GNUNET_assert(endpoint != NULL);
835 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue)); 948 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue));
836 949
837 GNUNET_CONTAINER_DLL_insert_tail(plugin->sessions, plugin->sessions_tail, queue); 950 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head, endpoint->sessions_tail, queue);
838 951
839 queue->content = GNUNET_malloc (sizeof (struct Session)); 952 queue->content = GNUNET_malloc (sizeof (struct Session));
840 queue->content->plugin = plugin; 953 queue->content->mac = endpoint;
841 queue->content->addr = *addr; 954 memcpy(&(queue->content->target), peer, sizeof(struct GNUNET_PeerIdentity));
842 queue->content->fragment_messages_out_count = 0;
843 queue->content->fragment_messages_in_count = 0;
844 queue->content->message_id_backlog_pos = 0;
845
846 plugin->session_count++;
847 955
848#if DEBUG_wlan 956#if DEBUG_wlan
849 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New session %p with %s\n", 957 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New session %p with %s\n",
850 queue->content, wlan_plugin_address_to_string(NULL, addr, 6)); 958 queue->content,
959 wlan_plugin_address_to_string(NULL, endpoint->addr.mac, 6));
851#endif 960#endif
852 961
853 return queue->content; 962 return queue->content;
@@ -858,15 +967,19 @@ create_session(struct Plugin *plugin, const struct MacAddress * addr)
858 * 967 *
859 * @param plugin pointer to the plugin struct 968 * @param plugin pointer to the plugin struct
860 * @param addr pointer to the mac address of the peer 969 * @param addr pointer to the mac address of the peer
970 * @param peer pointer to the peerid
861 * @return returns the session 971 * @return returns the session
862 */ 972 */
863static struct Session * 973static struct Session *
864get_session(struct Plugin *plugin, const struct MacAddress *addr) 974get_session(struct Plugin *plugin, const struct MacAddress *addr,
975 const struct GNUNET_PeerIdentity * peer)
865{ 976{
866 struct Session * session = search_session(plugin, addr); 977 struct Session * session = search_session(plugin, addr, peer);
978 struct MacEndpoint * mac;
867 if (session != NULL) 979 if (session != NULL)
868 return session; 980 return session;
869 return create_session(plugin, addr); 981 mac = get_macendpoint(plugin, addr, GNUNET_YES);
982 return create_session(plugin, mac, peer);
870} 983}
871 984
872/** 985/**
@@ -881,7 +994,7 @@ queue_session(struct Plugin *plugin, struct Session * session)
881{ 994{
882 struct Sessionqueue * queue = plugin->pending_Sessions_head; 995 struct Sessionqueue * queue = plugin->pending_Sessions_head;
883 996
884 if (session->pending_message != NULL) 997 if (session->pending_message_head != NULL)
885 { 998 {
886 while (queue != NULL) 999 while (queue != NULL)
887 { 1000 {
@@ -941,25 +1054,28 @@ static void
941set_next_beacon_time(struct Plugin * const plugin) 1054set_next_beacon_time(struct Plugin * const plugin)
942{ 1055{
943 //under 10 known peers: once a second 1056 //under 10 known peers: once a second
944 if (plugin->session_count < 10) 1057 if (plugin->mac_count < 10)
945 { 1058 {
946 plugin->beacon_time = GNUNET_TIME_absolute_add( 1059 plugin->beacon_time = GNUNET_TIME_absolute_add(
947 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply( 1060 GNUNET_TIME_absolute_get(),
948 GNUNET_TIME_UNIT_SECONDS, HALLO_BEACON_SCALING_FACTOR)); 1061 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1062 HALLO_BEACON_SCALING_FACTOR));
949 } 1063 }
950 //under 30 known peers: every 10 seconds 1064 //under 30 known peers: every 10 seconds
951 else if (plugin->session_count < 30) 1065 else if (plugin->mac_count < 30)
952 { 1066 {
953 plugin->beacon_time = GNUNET_TIME_absolute_add( 1067 plugin->beacon_time = GNUNET_TIME_absolute_add(
954 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply( 1068 GNUNET_TIME_absolute_get(),
955 GNUNET_TIME_UNIT_SECONDS, 10 * HALLO_BEACON_SCALING_FACTOR)); 1069 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1070 10 * HALLO_BEACON_SCALING_FACTOR));
956 } 1071 }
957 //over 30 known peers: once a minute 1072 //over 30 known peers: once a minute
958 else 1073 else
959 { 1074 {
960 plugin->beacon_time = GNUNET_TIME_absolute_add( 1075 plugin->beacon_time = GNUNET_TIME_absolute_add(
961 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply( 1076 GNUNET_TIME_absolute_get(),
962 GNUNET_TIME_UNIT_MINUTES, HALLO_BEACON_SCALING_FACTOR)); 1077 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES,
1078 HALLO_BEACON_SCALING_FACTOR));
963 } 1079 }
964} 1080}
965 1081
@@ -1057,7 +1173,7 @@ get_next_queue_session(struct Plugin * plugin)
1057 session = sessionqueue->content; 1173 session = sessionqueue->content;
1058 1174
1059 GNUNET_assert(session != NULL); 1175 GNUNET_assert(session != NULL);
1060 pm = session->pending_message; 1176 pm = session->pending_message_head;
1061 1177
1062#if DEBUG_wlan 1178#if DEBUG_wlan
1063 if (pm == NULL) 1179 if (pm == NULL)
@@ -1074,7 +1190,7 @@ get_next_queue_session(struct Plugin * plugin)
1074 if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0) 1190 if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0)
1075 { 1191 {
1076 //check if session has no message in the fragment queue 1192 //check if session has no message in the fragment queue
1077 if (session->fragment_messages_out_count 1193 if (session->mac->fragment_messages_out_count
1078 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION) 1194 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)
1079 { 1195 {
1080 plugin->pendingsessions--; 1196 plugin->pendingsessions--;
@@ -1091,9 +1207,7 @@ get_next_queue_session(struct Plugin * plugin)
1091 } 1207 }
1092 else 1208 else
1093 { 1209 {
1094 1210 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm);
1095 session->pending_message = session->pending_message2;
1096 session->pending_message2 = NULL;
1097 1211
1098 //call the cont func that it did not work 1212 //call the cont func that it did not work
1099 if (pm->transmit_cont != NULL) 1213 if (pm->transmit_cont != NULL)
@@ -1102,7 +1216,7 @@ get_next_queue_session(struct Plugin * plugin)
1102 GNUNET_free(pm->msg); 1216 GNUNET_free(pm->msg);
1103 GNUNET_free(pm); 1217 GNUNET_free(pm);
1104 1218
1105 if (session->pending_message == NULL) 1219 if (session->pending_message_head == NULL)
1106 { 1220 {
1107 sessionqueue_alt = sessionqueue; 1221 sessionqueue_alt = sessionqueue;
1108 sessionqueue = sessionqueue->next; 1222 sessionqueue = sessionqueue->next;
@@ -1112,7 +1226,6 @@ get_next_queue_session(struct Plugin * plugin)
1112 1226
1113 GNUNET_free(sessionqueue_alt); 1227 GNUNET_free(sessionqueue_alt);
1114 } 1228 }
1115
1116 } 1229 }
1117 1230
1118 } 1231 }
@@ -1131,7 +1244,7 @@ free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
1131 1244
1132 if (fm != NULL) 1245 if (fm != NULL)
1133 { 1246 {
1134 (session->fragment_messages_out_count)--; 1247 (session->mac->fragment_messages_out_count)--;
1135 GNUNET_free_non_null(fm->msg); 1248 GNUNET_free_non_null(fm->msg);
1136 GNUNET_CONTAINER_heap_remove_node(fm->node); 1249 GNUNET_CONTAINER_heap_remove_node(fm->node);
1137 GNUNET_free(fm); 1250 GNUNET_free(fm);
@@ -1166,9 +1279,9 @@ check_fragment_queue(struct Plugin * plugin)
1166 session = get_next_queue_session(plugin); 1279 session = get_next_queue_session(plugin);
1167 if (session != NULL) 1280 if (session != NULL)
1168 { 1281 {
1169 pm = session->pending_message; 1282 pm = session->pending_message_head;
1170 session->pending_message = NULL; 1283 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm);
1171 session->fragment_messages_out_count++; 1284 session->mac->fragment_messages_out_count++;
1172 GNUNET_assert(pm != NULL); 1285 GNUNET_assert(pm != NULL);
1173 1286
1174 fm = GNUNET_malloc(sizeof(struct FragmentMessage)); 1287 fm = GNUNET_malloc(sizeof(struct FragmentMessage));
@@ -1204,10 +1317,8 @@ check_fragment_queue(struct Plugin * plugin)
1204 } 1317 }
1205 GNUNET_free(pm); 1318 GNUNET_free(pm);
1206 1319
1207 if (session->pending_message2 != NULL) 1320 if (session->pending_message_head != NULL)
1208 { 1321 {
1209 session->pending_message = session->pending_message2;
1210 session->pending_message2 = NULL;
1211 //requeue session 1322 //requeue session
1212 queue_session(plugin, session); 1323 queue_session(plugin, session);
1213 } 1324 }
@@ -1236,9 +1347,9 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
1236 1347
1237#if DEBUG_wlan 1348#if DEBUG_wlan
1238 if (maxack != 63) 1349 if (maxack != 63)
1239 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1350 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1240 "Test bitfields %X and %X, maxack is %u, fm size %u\n", 1351 "Test bitfields %X and %X, maxack is %u, fm size %u\n",
1241 fm->ack_bitfield, tmpfield, maxack, fm->message_size); 1352 fm->ack_bitfield, tmpfield, maxack, fm->message_size);
1242#endif 1353#endif
1243 1354
1244 if (fm->ack_bitfield == tmpfield) 1355 if (fm->ack_bitfield == tmpfield)
@@ -1297,17 +1408,23 @@ set_next_message_fragment_pos(struct Plugin * plugin,
1297 1408
1298} 1409}
1299 1410
1300//TODO DOXIGEN 1411/**
1412 * function to fill the radiotap header
1413 * @param plugin pointer to the plugin struct
1414 * @param endpoint pointer to the endpoint
1415 * @param header pointer to the radiotap header
1416 * @return GNUNET_YES at success
1417 */
1301static int 1418static int
1302getRadiotapHeader(struct Plugin * plugin, struct Session * session, 1419getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint,
1303 struct Radiotap_Send * header) 1420 struct Radiotap_Send * header)
1304{ 1421{
1305 1422
1306 if (session != NULL) 1423 if (endpoint != NULL)
1307 { 1424 {
1308 header->rate = session->rate; 1425 header->rate = endpoint->rate;
1309 header->tx_power = session->tx_power; 1426 header->tx_power = endpoint->tx_power;
1310 header->antenna = session->antenna; 1427 header->antenna = endpoint->antenna;
1311 } 1428 }
1312 else 1429 else
1313 { 1430 {
@@ -1355,16 +1472,17 @@ getWlanHeader(struct ieee80211_frame * Header,
1355 Header->ip.ip_ttl = 1; 1472 Header->ip.ip_ttl = 1;
1356 Header->ip.ip_len = htons(size + 8); 1473 Header->ip.ip_len = htons(size + 8);
1357 Header->ip.ip_sum = 0; 1474 Header->ip.ip_sum = 0;
1358 x =(uint16_t *) &Header->ip; 1475 x =(uint16_t *) &Header->ip;
1359 count = sizeof(struct iph); 1476 count = sizeof(struct iph);
1360 while (count > 1) { 1477 while (count > 1)
1361 /* This is the inner loop */ 1478 {
1362 crc += (unsigned short) * x++; 1479 /* This is the inner loop */
1363 count -= 2; 1480 crc += (unsigned short) * x++;
1364 } 1481 count -= 2;
1482 }
1365 /* Add left-over byte, if any */ 1483 /* Add left-over byte, if any */
1366 if( count > 0 ) 1484 if( count > 0 )
1367 crc += * (unsigned char *) x; 1485 crc += * (unsigned char *) x;
1368 crc = (crc & 0xffff) + (crc >> 16); 1486 crc = (crc & 0xffff) + (crc >> 16);
1369 Header->ip.ip_sum = htons(~ (unsigned short) crc); 1487 Header->ip.ip_sum = htons(~ (unsigned short) crc);
1370 Header->llc[0] = 6; 1488 Header->llc[0] = 6;
@@ -1441,8 +1559,9 @@ send_hello_beacon(struct Plugin * plugin)
1441 getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size); 1559 getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size);
1442 1560
1443 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; 1561 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
1444 msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) 1562 msgheader2->size = htons(
1445 + sizeof(struct GNUNET_MessageHeader)); 1563 GNUNET_HELLO_size(*(plugin->env->our_hello))
1564 + sizeof(struct GNUNET_MessageHeader));
1446 1565
1447 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); 1566 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
1448 memcpy(&msgheader2[1], *plugin->env->our_hello, hallo_size); 1567 memcpy(&msgheader2[1], *plugin->env->our_hello, hallo_size);
@@ -1484,8 +1603,8 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1484#if DEBUG_wlan 1603#if DEBUG_wlan
1485 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1604 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1486 "Sending ack for message_id %u with fragment field %u, size %u\n", 1605 "Sending ack for message_id %u with fragment field %u, size %u\n",
1487 ack->message_id, ack->fragments_field, size 1606 ack->message_id, ack->fragments_field,
1488 - sizeof(struct Radiotap_Send)); 1607 size - sizeof(struct Radiotap_Send));
1489#endif 1608#endif
1490 1609
1491 msgheader = GNUNET_malloc(size); 1610 msgheader = GNUNET_malloc(size);
@@ -1493,9 +1612,9 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1493 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1612 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1494 1613
1495 radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1614 radioHeader = (struct Radiotap_Send*) &msgheader[1];
1496 getRadiotapHeader(plugin, ack->session, radioHeader); 1615 getRadiotapHeader(plugin, ack->endpoint, radioHeader);
1497 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1]; 1616 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
1498 getWlanHeader(ieeewlanheader, &ack->session->addr, plugin, size); 1617 getWlanHeader(ieeewlanheader, &ack->endpoint->addr, plugin, size);
1499 1618
1500 msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1]; 1619 msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1];
1501 msgheader2->header.size = htons(sizeof(struct FragmentationAckHeader)); 1620 msgheader2->header.size = htons(sizeof(struct FragmentationAckHeader));
@@ -1641,8 +1760,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1641 GNUNET_log( 1760 GNUNET_log(
1642 GNUNET_ERROR_TYPE_DEBUG, 1761 GNUNET_ERROR_TYPE_DEBUG,
1643 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n", 1762 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n",
1644 fm->message_id_out, fm->message_pos, copysize 1763 fm->message_id_out, fm->message_pos,
1645 + sizeof(struct FragmentationHeader), copyoffset, 1764 copysize + sizeof(struct FragmentationHeader), copyoffset,
1646 GNUNET_TIME_absolute_get_remaining(fm->timeout)); 1765 GNUNET_TIME_absolute_get_remaining(fm->timeout));
1647#endif 1766#endif
1648 1767
@@ -1651,14 +1770,14 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1651 GNUNET_log( 1770 GNUNET_log(
1652 GNUNET_ERROR_TYPE_ERROR, 1771 GNUNET_ERROR_TYPE_ERROR,
1653 "offset in message for fragment too large, offset %u, size %u, max size %u, copysize %u, message_pos %u,\n", 1772 "offset in message for fragment too large, offset %u, size %u, max size %u, copysize %u, message_pos %u,\n",
1654 copyoffset, fm->message_size, WLAN_MTU 1773 copyoffset, fm->message_size,
1655 - sizeof(struct FragmentationHeader), copysize, 1774 WLAN_MTU - sizeof(struct FragmentationHeader), copysize,
1656 fm->message_pos); 1775 fm->message_pos);
1657 } 1776 }
1658 GNUNET_assert(copyoffset < fm->message_size); 1777 GNUNET_assert(copyoffset < fm->message_size);
1659 1778
1660 fragheader.header.size = htons(copysize 1779 fragheader.header.size = htons(
1661 + sizeof(struct FragmentationHeader)); 1780 copysize + sizeof(struct FragmentationHeader));
1662 fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); 1781 fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
1663 1782
1664 size += copysize; 1783 size += copysize;
@@ -1669,11 +1788,10 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1669 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1788 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1670 1789
1671 radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1790 radioHeader = (struct Radiotap_Send*) &msgheader[1];
1672 getRadiotapHeader(plugin, session, radioHeader); 1791 getRadiotapHeader(plugin, session->mac, radioHeader);
1673 1792
1674 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1]; 1793 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1675 getWlanHeader(ieeewlanheader, &(fm->session->addr), plugin, size); 1794 getWlanHeader(ieeewlanheader, &(fm->session->mac->addr), plugin, size);
1676
1677 1795
1678 //could be faster if content is just send and not copyed before 1796 //could be faster if content is just send and not copyed before
1679 //fragmentheader is needed 1797 //fragmentheader is needed
@@ -1701,8 +1819,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1701 GNUNET_assert(copysize + copyoffset == fm->message_size); 1819 GNUNET_assert(copysize + copyoffset == fm->message_size);
1702 1820
1703 GNUNET_CONTAINER_heap_update_cost( 1821 GNUNET_CONTAINER_heap_update_cost(
1704 plugin->pending_Fragment_Messages, fm->node, MIN( 1822 plugin->pending_Fragment_Messages, fm->node,
1705 fm->timeout.abs_value, fm->next_ack.abs_value)); 1823 MIN(fm->timeout.abs_value, fm->next_ack.abs_value));
1706 // if fragments have opimized timeouts 1824 // if fragments have opimized timeouts
1707 //sort_fragment_into_queue(plugin,fm); 1825 //sort_fragment_into_queue(plugin,fm);
1708 1826
@@ -1712,8 +1830,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1712 GNUNET_ERROR_TYPE_DEBUG, 1830 GNUNET_ERROR_TYPE_DEBUG,
1713 "Finished sending all fragments waiting for acks; message_id %u; message_id %u; fragment number %i, size: %u, time until timeout %u\n", 1831 "Finished sending all fragments waiting for acks; message_id %u; message_id %u; fragment number %i, size: %u, time until timeout %u\n",
1714 fm->message_id_out, fm->message_id_out, fm->message_pos, 1832 fm->message_id_out, fm->message_id_out, fm->message_pos,
1715 fm->message_size, GNUNET_TIME_absolute_get_remaining( 1833 fm->message_size,
1716 fm->timeout)); 1834 GNUNET_TIME_absolute_get_remaining(fm->timeout));
1717#endif 1835#endif
1718 } 1836 }
1719 else 1837 else
@@ -1829,7 +1947,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1829 { 1947 {
1830 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) 1948 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK)
1831 { 1949 {
1832 session = get_session(plugin, addr); 1950 session = get_session(plugin, addr, target);
1833 } 1951 }
1834 else 1952 else
1835 { 1953 {
@@ -1839,35 +1957,19 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1839 } 1957 }
1840 } 1958 }
1841 1959
1842 //TODO target "problem" not solved
1843 //if (session->target != NULL){
1844 // GNUNET_assert(session->target == *target);
1845 //} else {
1846 session->target = *target;
1847 //}
1848
1849
1850 //queue message: 1960 //queue message:
1851 1961
1852 //queue message in session 1962 //queue message in session
1853 //test if there is no other message in the "queue" 1963 //test if there is no other message in the "queue"
1854 //FIXME: to many send requests 1964 //FIXME: to many send requests
1855 //GNUNET_assert (session->pending_message == NULL); 1965 if (session->pending_message_head != NULL)
1856 if (session->pending_message != NULL)
1857 { 1966 {
1858 newmsg = session->pending_message; 1967 newmsg = session->pending_message_head;
1859 GNUNET_log( 1968 GNUNET_log(
1860 GNUNET_ERROR_TYPE_ERROR, 1969 GNUNET_ERROR_TYPE_ERROR,
1861 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages %u\n", 1970 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n",
1862 GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value, 1971 GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value,
1863 session->fragment_messages_out_count); 1972 session->mac->fragment_messages_out_count);
1864 if (session->pending_message2 != NULL)
1865 {
1866 GNUNET_log(
1867 GNUNET_ERROR_TYPE_ERROR,
1868 "wlan_plugin_send: two pending messages are already in the queue for this client\n");
1869 return -1;
1870 }
1871 } 1973 }
1872 1974
1873 newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); 1975 newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
@@ -1877,9 +1979,11 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1877 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); 1979 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
1878 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); 1980 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
1879 memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity)); 1981 memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity));
1982 memcpy(&(wlanheader->source), plugin->env->my_identity , sizeof(struct GNUNET_PeerIdentity));
1880 wlanheader->crc = 0; 1983 wlanheader->crc = 0;
1881 memcpy(&wlanheader[1], msgbuf, msgbuf_size); 1984 memcpy(&wlanheader[1], msgbuf, msgbuf_size);
1882 wlanheader->crc = htonl(getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader))); 1985 wlanheader->crc = htonl(
1986 getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)));
1883 //GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc); 1987 //GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc);
1884 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader)); 1988 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
1885 1989
@@ -1891,14 +1995,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1891 1995
1892 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); 1996 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader);
1893 1997
1894 if (session->pending_message == NULL) 1998 GNUNET_CONTAINER_DLL_insert_tail(session->pending_message_head, session->pending_message_tail, newmsg);
1895 {
1896 session->pending_message = newmsg;
1897 }
1898 else
1899 {
1900 session->pending_message2 = newmsg;
1901 }
1902 1999
1903#if DEBUG_wlan 2000#if DEBUG_wlan
1904 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2001 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -1953,15 +2050,15 @@ free_fragment_message_from_session(void *cls,
1953 * GNUNET_NO if not. 2050 * GNUNET_NO if not.
1954 */ 2051 */
1955static int 2052static int
1956search_fragment_message_from_session_and_id(void *cls, 2053search_fragment_message_from_endpoint_and_id(void *cls,
1957 struct GNUNET_CONTAINER_HeapNode *node, void *element, 2054 struct GNUNET_CONTAINER_HeapNode *node, void *element,
1958 GNUNET_CONTAINER_HeapCostType cost) 2055 GNUNET_CONTAINER_HeapCostType cost)
1959{ 2056{
1960 struct Session_id_fragment_triple * triple = 2057 struct MacEndpoint_id_fragment_triple * triple =
1961 (struct Session_id_fragment_triple *) cls; 2058 (struct MacEndpoint_id_fragment_triple *) cls;
1962 struct FragmentMessage * fm = (struct FragmentMessage*) element; 2059 struct FragmentMessage * fm = (struct FragmentMessage*) element;
1963 2060
1964 if ((fm->session == triple->session) && (fm->message_id_out 2061 if ((fm->session->mac == triple->endpoint) && (fm->message_id_out
1965 == triple->message_id)) 2062 == triple->message_id))
1966 { 2063 {
1967 triple->fm = fm; 2064 triple->fm = fm;
@@ -1978,31 +2075,33 @@ search_fragment_message_from_session_and_id(void *cls,
1978 * @return pointer to the struct FragmentMessage 2075 * @return pointer to the struct FragmentMessage
1979 */ 2076 */
1980static struct FragmentMessage * 2077static struct FragmentMessage *
1981get_fragment_message_from_session_and_id(struct Plugin * plugin, 2078get_fragment_message_from_endpoint_and_id(struct Plugin * plugin,
1982 struct Session * session, uint32_t message_id) 2079 struct MacEndpoint * endpoint, uint32_t message_id)
1983{ 2080{
1984 struct Session_id_fragment_triple triple; 2081 struct MacEndpoint_id_fragment_triple triple;
1985 triple.session = session; 2082 triple.endpoint = endpoint;
1986 triple.message_id = message_id; 2083 triple.message_id = message_id;
1987 triple.fm = NULL; 2084 triple.fm = NULL;
1988 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, 2085 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages,
1989 &search_fragment_message_from_session_and_id, &triple); 2086 &search_fragment_message_from_endpoint_and_id, &triple);
1990 return triple.fm; 2087 return triple.fm;
1991} 2088}
1992 2089
1993/** 2090/**
1994 * function to get the receive message of a session 2091 * function to get the receive message of a session
1995 * @param plugin pointer to the plugin struct 2092 * @param plugin pointer to the plugin struct
1996 * @param session session this fragment belongs to 2093 * @param endpoint MacEndpoint this fragment belongs to
2094 * @param message_id id of the message
1997 */ 2095 */
1998static struct Receive_Message_Queue * 2096static struct Receive_Message_Queue *
1999get_receive_message_from_session(struct Plugin * plugin, 2097get_receive_message(struct Plugin * plugin, struct MacEndpoint * endpoint,
2000 struct Session * session) 2098 uint32_t message_id)
2001{ 2099{
2002 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; 2100 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
2003 while (rec_message != NULL) 2101 while (rec_message != NULL)
2004 { 2102 {
2005 if (rec_message->session == session) 2103 if (rec_message->endpoint == endpoint && message_id
2104 == rec_message->message_id_in)
2006 { 2105 {
2007 return rec_message; 2106 return rec_message;
2008 } 2107 }
@@ -2034,20 +2133,21 @@ free_receive_message(struct Plugin* plugin,
2034 GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message); 2133 GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message);
2035 2134
2036 GNUNET_assert(plugin->pending_receive_messages > 0); 2135 GNUNET_assert(plugin->pending_receive_messages > 0);
2037 GNUNET_assert(rx_message->session->fragment_messages_in_count > 0); 2136 GNUNET_assert(rx_message->endpoint != NULL);
2137 GNUNET_assert(rx_message->endpoint !=NULL);
2138 GNUNET_assert(rx_message->endpoint->fragment_messages_in_count > 0);
2038 2139
2039 plugin->pending_receive_messages--; 2140 plugin->pending_receive_messages--;
2040 rx_message->session->fragment_messages_in_count--; 2141 rx_message->endpoint->fragment_messages_in_count--;
2041 GNUNET_free(rx_message); 2142 GNUNET_free(rx_message);
2042} 2143}
2043 2144
2044/** 2145/**
2045 * function to get the receive message of a session 2146 * function to check for timeouts
2046 * @param plugin pointer to the plugin struct 2147 * @param plugin pointer to the plugin struct
2047 * @param session session this fragment belongs to
2048 */ 2148 */
2049static void 2149static void
2050check_receive_message_timeouts(struct Plugin * plugin, struct Session * session) 2150check_receive_message_timeouts(struct Plugin * plugin)
2051{ 2151{
2052 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; 2152 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
2053 while (rec_message != NULL) 2153 while (rec_message != NULL)
@@ -2062,15 +2162,46 @@ check_receive_message_timeouts(struct Plugin * plugin, struct Session * session)
2062 2162
2063} 2163}
2064 2164
2065//TODO DOXIGEN 2165/**
2166 * function to free a mac endpoint
2167 * @param plugin pointer to the plugin struct
2168 * @param endpoin pointer to the MacEndpoint to free
2169 */
2066static void 2170static void
2067free_session(struct Plugin * plugin, struct Sessionqueue * queue) 2171free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoin)
2172{
2173 struct Sessionqueue * sessions;
2174 struct Sessionqueue * sessions_next;
2175 GNUNET_assert(endpoin != NULL);
2176 sessions = endpoin->sessions_head;
2177 while (sessions != NULL)
2178 {
2179 sessions_next = sessions->next;
2180 free_session(plugin, sessions, GNUNET_NO);
2181 sessions = sessions_next;
2182 }
2183
2184 GNUNET_CONTAINER_DLL_remove(plugin->mac_head,plugin->mac_tail,endpoin);
2185 GNUNET_free(endpoin);
2186
2187}
2188
2189/**
2190 * function to free a session
2191 * @param plugin pointer to the plugin
2192 * @param queue pointer to the sessionqueue element to free
2193 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2194 */
2195static void
2196free_session(struct Plugin * plugin, struct Sessionqueue * queue,
2197 int do_free_macendpoint)
2068{ 2198{
2069 struct Sessionqueue * pendingsession; 2199 struct Sessionqueue * pendingsession;
2070 struct Sessionqueue * pendingsession_tmp; 2200 struct Sessionqueue * pendingsession_tmp;
2071 struct PendingMessage * pm; 2201 struct PendingMessage * pm;
2072 struct Receive_Message_Queue * receive_queue; 2202 //struct Receive_Message_Queue * receive_queue;
2073 struct Plugin_Session_pair pair; 2203 struct Plugin_Session_pair pair;
2204 struct MacEndpoint * endpoint;
2074 int check = 0; 2205 int check = 0;
2075 2206
2076 GNUNET_assert(queue != NULL); 2207 GNUNET_assert(queue != NULL);
@@ -2103,35 +2234,34 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue)
2103 &free_fragment_message_from_session, &pair); 2234 &free_fragment_message_from_session, &pair);
2104 2235
2105 //dispose all received fragments 2236 //dispose all received fragments
2106 receive_queue = get_receive_message_from_session(plugin, queue->content); 2237 /*receive_queue = get_receive_message_from_session(plugin, queue->content);
2107 while (receive_queue != NULL) 2238 while (receive_queue != NULL)
2108 { 2239 {
2109 free_receive_message(plugin, receive_queue); 2240 free_receive_message(plugin, receive_queue);
2110 receive_queue = get_receive_message_from_session(plugin, queue->content); 2241 receive_queue = get_receive_message_from_session(plugin, queue->content);
2111 } 2242 }*/
2112 2243
2113 // remove PendingMessage 2244 // remove PendingMessage
2114 pm = queue->content->pending_message; 2245 pm = queue->content->pending_message_head;
2115 if (pm != NULL) 2246 while (pm != NULL)
2116 { 2247 {
2248 GNUNET_CONTAINER_DLL_remove(queue->content->pending_message_head,queue->content->pending_message_tail,pm);
2117 GNUNET_free_non_null(pm->msg); 2249 GNUNET_free_non_null(pm->msg);
2118 GNUNET_free(pm); 2250 GNUNET_free(pm);
2251 pm = queue->content->pending_message_head;
2119 } 2252 }
2120 2253
2121 // remove PendingMessage 2254 endpoint = queue->content->mac;
2122 pm = queue->content->pending_message2; 2255 GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head ,
2123 if (pm != NULL) 2256 endpoint->sessions_tail,
2257 queue);
2258
2259 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2124 { 2260 {
2125 GNUNET_free_non_null(pm->msg); 2261 free_macendpoint(plugin, endpoint);
2126 GNUNET_free(pm);
2127 } 2262 }
2128
2129 GNUNET_CONTAINER_DLL_remove(plugin->sessions,
2130 plugin->sessions_tail,
2131 queue);
2132 GNUNET_free(queue->content); 2263 GNUNET_free(queue->content);
2133 GNUNET_free(queue); 2264 GNUNET_free(queue);
2134 plugin->session_count--;
2135 check_fragment_queue(plugin); 2265 check_fragment_queue(plugin);
2136} 2266}
2137 2267
@@ -2147,21 +2277,29 @@ static void
2147wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) 2277wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2148{ 2278{
2149 struct Plugin *plugin = cls; 2279 struct Plugin *plugin = cls;
2150 struct Sessionqueue * queue = plugin->sessions; 2280 struct Sessionqueue * queue;
2151 2281 struct Sessionqueue * queue_next;
2282 struct MacEndpoint * endpoint = plugin->mac_head;
2283 struct MacEndpoint * endpoint_next;
2152 // just look at all the session for the needed one 2284 // just look at all the session for the needed one
2153 while (queue != NULL) 2285 while (endpoint != NULL)
2154 { 2286 {
2155 // content is never NULL 2287 queue = endpoint->sessions_head;
2156 GNUNET_assert (queue->content != NULL); 2288 endpoint_next = endpoint->next;
2157 if (memcmp(target, &(queue->content->target), 2289 while (queue != NULL)
2158 sizeof(struct GNUNET_PeerIdentity)) == 0)
2159 { 2290 {
2160 free_session(plugin, queue); 2291 // content is never NULL
2161 return; 2292 GNUNET_assert (queue->content != NULL);
2293 queue_next = queue->next;
2294 if (memcmp(target, &(queue->content->target),
2295 sizeof(struct GNUNET_PeerIdentity)) == 0)
2296 {
2297 free_session(plugin, queue, GNUNET_YES);
2298 }
2299 // try next
2300 queue = queue_next;
2162 } 2301 }
2163 // try next 2302 endpoint = endpoint_next;
2164 queue = queue->next;
2165 } 2303 }
2166} 2304}
2167 2305
@@ -2191,8 +2329,7 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type,
2191 //GNUNET_assert(cls !=NULL); 2329 //GNUNET_assert(cls !=NULL);
2192 if (addrlen != 6) 2330 if (addrlen != 6)
2193 { 2331 {
2194 /* invalid address (MAC addresses have 6 bytes) */ 2332 /* invalid address (MAC addresses have 6 bytes) */GNUNET_break (0);
2195 GNUNET_break (0);
2196 asc(asc_cls, NULL); 2333 asc(asc_cls, NULL);
2197 return; 2334 return;
2198 } 2335 }
@@ -2215,8 +2352,8 @@ is_double_msg(struct Receive_Message_Queue * rx_msg,
2215 struct FragmentationHeader * fh) 2352 struct FragmentationHeader * fh)
2216{ 2353{
2217 2354
2218 return testBit((char *) &rx_msg->received_fragments, ntohs( 2355 return testBit((char *) &rx_msg->received_fragments,
2219 fh->fragment_off_or_num)); 2356 ntohs(fh->fragment_off_or_num));
2220 2357
2221} 2358}
2222 2359
@@ -2277,7 +2414,7 @@ wlan_data_message_handler(void *cls, void *client,
2277 struct Session * session; 2414 struct Session * session;
2278 //const char * tempmsg; 2415 //const char * tempmsg;
2279 const struct GNUNET_MessageHeader * temp_hdr; 2416 const struct GNUNET_MessageHeader * temp_hdr;
2280 struct GNUNET_PeerIdentity tmptarget; 2417 struct GNUNET_PeerIdentity tmpsource;
2281 int crc; 2418 int crc;
2282 2419
2283 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) 2420 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
@@ -2298,12 +2435,14 @@ wlan_data_message_handler(void *cls, void *client,
2298 } 2435 }
2299 2436
2300 GNUNET_assert(session_light != NULL); 2437 GNUNET_assert(session_light != NULL);
2438 wlanheader = (struct WlanHeader *) hdr;
2439
2301 if (session_light->session == NULL) 2440 if (session_light->session == NULL)
2302 { 2441 {
2303 session_light->session = search_session(plugin, &session_light->addr); 2442 session_light->session = search_session(plugin, &session_light->addr,
2443 &wlanheader->source);
2304 } 2444 }
2305 session = session_light->session; 2445 session = session_light->session;
2306 wlanheader = (struct WlanHeader *) hdr;
2307 2446
2308 //tempmsg = (char*) &wlanheader[1]; 2447 //tempmsg = (char*) &wlanheader[1];
2309 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; 2448 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
@@ -2313,8 +2452,10 @@ wlan_data_message_handler(void *cls, void *client,
2313 { 2452 {
2314 //wrong crc, dispose message 2453 //wrong crc, dispose message
2315 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2454 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2316 "Wlan message Header crc was wrong: %u != %u\n",getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)), crc); 2455 "Wlan message Header crc was wrong: %u != %u\n",
2317 hexdump((void *)hdr, ntohs(hdr->size)); 2456 getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)),
2457 crc);
2458 hexdump((void *) hdr, ntohs(hdr->size));
2318 return; 2459 return;
2319 } 2460 }
2320 2461
@@ -2336,17 +2477,19 @@ wlan_data_message_handler(void *cls, void *client,
2336 { 2477 {
2337 if (GNUNET_HELLO_get_id( 2478 if (GNUNET_HELLO_get_id(
2338 (const struct GNUNET_HELLO_Message *) temp_hdr, 2479 (const struct GNUNET_HELLO_Message *) temp_hdr,
2339 &tmptarget) == GNUNET_OK) 2480 &tmpsource) == GNUNET_OK)
2340 { 2481 {
2341 session = create_session(plugin, &session_light->addr); 2482 session_light->macendpoint = get_macendpoint(plugin,
2483 &session_light->addr, GNUNET_YES);
2484 session = create_session(plugin,
2485 session_light->macendpoint, &tmpsource);
2342 session_light->session = session; 2486 session_light->session = session;
2343 memcpy(&session->target, &tmptarget, 2487
2344 sizeof(struct GNUNET_PeerIdentity));
2345 } 2488 }
2346 else 2489 else
2347 { 2490 {
2348 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2491 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2349 "WLAN client not in session list and hello message not okay\n"); 2492 "WLAN client not in session list and hello message is not okay\n");
2350 return; 2493 return;
2351 } 2494 }
2352 2495
@@ -2371,6 +2514,29 @@ wlan_data_message_handler(void *cls, void *client,
2371 2514
2372 //"receive" the message 2515 //"receive" the message
2373 2516
2517 if (memcmp(&wlanheader->source, &session->target,
2518 sizeof(struct GNUNET_PeerIdentity)) != 0)
2519 {
2520 //wrong peer id
2521#if DEBUG_wlan
2522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2523 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2524 session);
2525#endif
2526 return;
2527 }
2528
2529 if (memcmp(&wlanheader->target, plugin->env->my_identity,
2530 sizeof(struct GNUNET_PeerIdentity)) != 0)
2531 {
2532 //wrong peer id
2533#if DEBUG_wlan
2534 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2535 "WLAN peer target id doesn't match our peer id: session %p\n",
2536 session);
2537#endif
2538 return;
2539 }
2374 2540
2375 GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session, 2541 GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session,
2376 (const char *) temp_hdr, 2542 (const char *) temp_hdr,
@@ -2390,13 +2556,12 @@ wlan_data_message_handler(void *cls, void *client,
2390 * Function to check if all fragments of a message have been received 2556 * Function to check if all fragments of a message have been received
2391 * @param plugin the plugin handle 2557 * @param plugin the plugin handle
2392 * @param session_light information of the message sender 2558 * @param session_light information of the message sender
2393 * @param session session the message belongs to
2394 * @param rec_message pointer to the message that should be checked 2559 * @param rec_message pointer to the message that should be checked
2395 */ 2560 */
2396 2561
2397static void 2562static void
2398check_rx_finished_msg(struct Plugin* plugin, 2563check_rx_finished_msg(struct Plugin* plugin,
2399 struct Session_light * session_light, struct Session * session, 2564 struct Session_light * session_light,
2400 struct Receive_Message_Queue * rx_message) 2565 struct Receive_Message_Queue * rx_message)
2401{ 2566{
2402 GNUNET_assert(rx_message !=NULL); 2567 GNUNET_assert(rx_message !=NULL);
@@ -2444,8 +2609,10 @@ check_rx_finished_msg(struct Plugin* plugin,
2444 { 2609 {
2445 2610
2446#if DEBUG_wlan 2611#if DEBUG_wlan
2447 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2612 GNUNET_log(
2448 "check_rec_finished_msg: A message for %p is complete\n", session); 2613 GNUNET_ERROR_TYPE_DEBUG,
2614 "check_rec_finished_msg: A message for endpoint %p is complete\n",
2615 rx_message->endpoint);
2449#endif 2616#endif
2450 2617
2451 //TODO cleanup 2618 //TODO cleanup
@@ -2479,8 +2646,11 @@ check_rx_finished_msg(struct Plugin* plugin,
2479 } 2646 }
2480 rx_frag = rx_frag->next; 2647 rx_frag = rx_frag->next;
2481 } 2648 }
2482 session->message_id_backlog[session->message_id_backlog_pos] = rx_message->message_id_in; 2649 session_light->macendpoint->message_id_backlog[session_light->macendpoint->message_id_backlog_pos]
2483 session->message_id_backlog_pos = (session->message_id_backlog_pos + 1) % MESSAGE_ID_BACKLOG_SIZE; 2650 = rx_message->message_id_in;
2651 session_light->macendpoint->message_id_backlog_pos
2652 = (session_light->macendpoint->message_id_backlog_pos + 1)
2653 % MESSAGE_ID_BACKLOG_SIZE;
2484 free_receive_message(plugin, rx_message); 2654 free_receive_message(plugin, rx_message);
2485 //call wlan_process_helper to process the message 2655 //call wlan_process_helper to process the message
2486 //wlan_data_message_handler(plugin, session_light, 2656 //wlan_data_message_handler(plugin, session_light,
@@ -2512,37 +2682,37 @@ process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2512#if DEBUG_wlan 2682#if DEBUG_wlan
2513 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2683 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2514 "Calling plugin->env->receive for session %p; %s; size: %u\n", session, 2684 "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
2515 wlan_plugin_address_to_string(NULL, session->addr.mac, 6), htons( 2685 wlan_plugin_address_to_string(NULL, session->mac->addr.mac, 6),
2516 hdr->size)); 2686 htons(hdr->size));
2517#endif 2687#endif
2518 2688
2519 plugin->env->receive(plugin->env->cls, &(session->target), hdr, 2689 plugin->env->receive(plugin->env->cls, &(session->target), hdr,
2520 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, 2690 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
2521 (const char*) &session->addr, sizeof(session->addr)); 2691 (const char*) &session->mac->addr, sizeof(session->mac->addr));
2522} 2692}
2523 2693
2524/** 2694/**
2525 * function to add an ack to send it for a received fragment 2695 * function to add an ack to send it for a received fragment
2526 * @param plugin pointer to the global plugin structure 2696 * @param plugin pointer to the global plugin structure
2527 * @param session pointer to the session this ack belongs to 2697 * @param endpoint pointer to the MacEndpoint this ack belongs to
2528 * @param bitfield bitfield to send 2698 * @param bitfield bitfield to send
2529 * @param fh pointer to the fragmentation header which we would like to acknolage 2699 * @param fh pointer to the fragmentation header which we would like to acknolage
2530 */ 2700 */
2531 2701
2532void 2702void
2533add_ack_for_send(struct Plugin * plugin, struct Session * session, 2703add_ack_for_send(struct Plugin * plugin, struct MacEndpoint * endpoint,
2534 uint64_t bitfield, struct FragmentationHeader * fh) 2704 uint64_t bitfield, struct FragmentationHeader * fh)
2535{ 2705{
2536 struct AckSendQueue * ack; 2706 struct AckSendQueue * ack;
2537 2707
2538 GNUNET_assert(plugin != NULL); 2708 GNUNET_assert(plugin != NULL);
2539 GNUNET_assert(session != NULL); 2709 GNUNET_assert(endpoint != NULL);
2540 GNUNET_assert(fh != NULL); 2710 GNUNET_assert(fh != NULL);
2541 2711
2542 ack = GNUNET_malloc(sizeof(struct AckSendQueue)); 2712 ack = GNUNET_malloc(sizeof(struct AckSendQueue));
2543 ack->fragments_field = bitfield; 2713 ack->fragments_field = bitfield;
2544 ack->message_id = ntohl(fh->message_id); 2714 ack->message_id = ntohl(fh->message_id);
2545 ack->session = session; 2715 ack->endpoint = endpoint;
2546 2716
2547 GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head, 2717 GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head,
2548 plugin->ack_send_queue_tail, ack); 2718 plugin->ack_send_queue_tail, ack);
@@ -2552,43 +2722,43 @@ add_ack_for_send(struct Plugin * plugin, struct Session * session,
2552/** 2722/**
2553 * function to get the receive message from the message id and the session 2723 * function to get the receive message from the message id and the session
2554 * @param plugin pointer to the plugin struct 2724 * @param plugin pointer to the plugin struct
2555 * @param session session this fragment belongs to 2725 * @param endpoint MacEndpoint this fragment belongs to
2556 * @param message_id id of the message 2726 * @param message_id id of the message
2557 */ 2727 */
2558 2728
2559struct Receive_Message_Queue * 2729/*struct Receive_Message_Queue *
2560get_receive_message(struct Plugin * plugin, struct Session * session, 2730 get_receive_message(struct Plugin * plugin, struct MacEndpoint * endpoint,
2561 uint32_t message_id) 2731 uint32_t message_id)
2562{ 2732 {
2563 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; 2733 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
2564 while (rec_message != NULL) 2734 while (rec_message != NULL)
2565 { 2735 {
2566 if ((rec_message->message_id_in == message_id) && (rec_message->session 2736 if ((rec_message->message_id_in == message_id) && (rec_message->endpoint
2567 == session)) 2737 == endpoint))
2568 { 2738 {
2569 return rec_message; 2739 return rec_message;
2570 } 2740 }
2571 rec_message = rec_message->next; 2741 rec_message = rec_message->next;
2572 } 2742 }
2573 return NULL; 2743 return NULL;
2574} 2744 }*/
2575 2745
2576/** 2746/**
2577 * function to insert a received fragment into the right fragment queue of the right message 2747 * function to insert a received fragment into the right fragment queue of the right message
2578 * @param plugin pointer to the plugin struct 2748 * @param plugin pointer to the plugin struct
2579 * @param session_light pointer to the session_light struct of this message 2749 * @param session_light pointer to the session_light struct of this message
2580 * @param session session this fragment belongs to
2581 * @param fh pointer to the header of the fragment 2750 * @param fh pointer to the header of the fragment
2582 * @return new fragment bitfield for the message 2751 * @return new fragment bitfield for the message
2583 */ 2752 */
2584 2753
2585uint64_t 2754uint64_t
2586insert_fragment_in_in_message_queue(struct Plugin * plugin, 2755insert_fragment_in_in_message_queue(struct Plugin * plugin,
2587 struct Session_light * session_light, struct Session * session, 2756 struct Session_light * session_light, struct FragmentationHeader * fh,
2588 struct FragmentationHeader * fh, const struct Radiotap_rx * rxinfo) 2757 const struct Radiotap_rx * rxinfo)
2589{ 2758{
2590 struct Receive_Fragment_Queue * rx_frag = NULL; 2759 struct Receive_Fragment_Queue * rx_frag = NULL;
2591 struct Receive_Message_Queue * rx_message; 2760 struct Receive_Message_Queue * rx_message;
2761 struct MacEndpoint * endpoint = session_light->macendpoint;
2592 const char * tempmsg = (char*) &fh[1]; 2762 const char * tempmsg = (char*) &fh[1];
2593 uint64_t retval = 0; 2763 uint64_t retval = 0;
2594 int i; 2764 int i;
@@ -2598,43 +2768,45 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2598 GNUNET_assert(fh != NULL); 2768 GNUNET_assert(fh != NULL);
2599 2769
2600 //check for receive of old messages 2770 //check for receive of old messages
2601 for (i = 0; i< MESSAGE_ID_BACKLOG_SIZE; i++) 2771 for (i = 0; i < MESSAGE_ID_BACKLOG_SIZE; i++)
2602 { 2772 {
2603 if (session->message_id_backlog[i] == ntohl(fh->message_id) ){ 2773 if (endpoint->message_id_backlog[i] == ntohl(fh->message_id))
2774 {
2604 setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); 2775 setBit((char *) &retval, ntohs(fh->fragment_off_or_num));
2605 return retval; 2776 return retval;
2606 } 2777 }
2607 } 2778 }
2608 2779
2609 rx_message = get_receive_message(plugin, session, ntohl(fh->message_id)); 2780 rx_message = get_receive_message(plugin, endpoint, ntohl(fh->message_id));
2610 2781
2611 if (rx_message == NULL) 2782 if (rx_message == NULL)
2612 { 2783 {
2613 if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) 2784 if (endpoint->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION)
2614 { 2785 {
2615 check_receive_message_timeouts(plugin, session); 2786 check_receive_message_timeouts(plugin);
2616 } 2787 }
2617 2788
2618 if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) 2789 if (endpoint->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION)
2619 { 2790 {
2620 2791
2621 //new message incoming 2792 //new message incoming
2622 rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); 2793 rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue));
2623 rx_message->message_id_in = ntohl(fh->message_id); 2794 rx_message->message_id_in = ntohl(fh->message_id);
2624 rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN; 2795 rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN;
2625 rx_message->session = session; 2796 rx_message->endpoint = endpoint;
2626 rx_message->received_fragments = 0; 2797 rx_message->received_fragments = 0;
2627 2798
2628 GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message); 2799 GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message);
2629 2800
2630 session->fragment_messages_in_count++; 2801 endpoint->fragment_messages_in_count++;
2631 plugin->pending_receive_messages++; 2802 plugin->pending_receive_messages++;
2632 2803
2633#if DEBUG_wlan 2804#if DEBUG_wlan
2634 GNUNET_log( 2805 GNUNET_log(
2635 GNUNET_ERROR_TYPE_DEBUG, 2806 GNUNET_ERROR_TYPE_DEBUG,
2636 "New fragmented message started: message id %u, messages in for this session %u, messages in %u\n", 2807 "New fragmented message started: message id %u, messages in for this session %u, messages in %u\n",
2637 rx_message->message_id_in, session->fragment_messages_in_count, 2808 rx_message->message_id_in,
2809 rx_message->endpoint->fragment_messages_in_count,
2638 plugin->pending_receive_messages); 2810 plugin->pending_receive_messages);
2639#endif 2811#endif
2640 } 2812 }
@@ -2643,16 +2815,14 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2643 2815
2644 GNUNET_log( 2816 GNUNET_log(
2645 GNUNET_ERROR_TYPE_INFO, 2817 GNUNET_ERROR_TYPE_INFO,
2646 "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached, akt in message_id %u\n", 2818 "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached\n");
2647 get_receive_message_from_session(plugin, session)->message_id_in);
2648 setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); 2819 setBit((char *) &retval, ntohs(fh->fragment_off_or_num));
2649 return retval; 2820 return retval;
2650 } 2821 }
2651 } 2822 }
2652 2823
2653 //reset timeout 2824 //reset timeout
2654 rx_message->timeout = GNUNET_TIME_absolute_add( 2825 rx_message->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
2655 GNUNET_TIME_absolute_get(),
2656 MESSAGE_IN_TIMEOUT); 2826 MESSAGE_IN_TIMEOUT);
2657 2827
2658 if (is_double_msg(rx_message, fh) != GNUNET_YES) 2828 if (is_double_msg(rx_message, fh) != GNUNET_YES)
@@ -2675,12 +2845,12 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2675#if DEBUG_wlan 2845#if DEBUG_wlan
2676 GNUNET_log( 2846 GNUNET_log(
2677 GNUNET_ERROR_TYPE_DEBUG, 2847 GNUNET_ERROR_TYPE_DEBUG,
2678 "New fragment: size %u, fragsize %u, message id %u, bitfield %X, session %u\n", 2848 "New fragment: size %u, fragsize %u, message id %u, bitfield %X, endpoint %p\n",
2679 rx_message->rec_size, rx_frag->size, rx_message->message_id_in, 2849 rx_message->rec_size, rx_frag->size, rx_message->message_id_in,
2680 rx_message->received_fragments, session); 2850 rx_message->received_fragments, rx_message->endpoint);
2681#endif 2851#endif
2682 2852
2683 check_rx_finished_msg(plugin, session_light, session, rx_message); 2853 check_rx_finished_msg(plugin, session_light, rx_message);
2684 } 2854 }
2685 else 2855 else
2686 { 2856 {
@@ -2704,7 +2874,6 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2704 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) 2874 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo)
2705{ 2875{
2706 struct Plugin *plugin = cls; 2876 struct Plugin *plugin = cls;
2707 struct Session * session;
2708 2877
2709 struct FragmentationHeader * fh; 2878 struct FragmentationHeader * fh;
2710 struct FragmentationAckHeader * fah; 2879 struct FragmentationAckHeader * fah;
@@ -2726,13 +2895,14 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2726 GNUNET_log( 2895 GNUNET_log(
2727 GNUNET_ERROR_TYPE_DEBUG, 2896 GNUNET_ERROR_TYPE_DEBUG,
2728 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", 2897 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
2729 ntohs(hdr->size), wlan_plugin_address_to_string(NULL, 2898 ntohs(hdr->size),
2730 session_light->addr.mac, 6)); 2899 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
2731#endif 2900#endif
2732 2901
2733 if (session_light->session == NULL) 2902 if (session_light->macendpoint == NULL)
2734 { 2903 {
2735 session_light->session = get_session(plugin, &session_light->addr); 2904 session_light->macendpoint = get_macendpoint(plugin,
2905 &session_light->addr, GNUNET_NO);
2736 } 2906 }
2737 GNUNET_assert(GNUNET_HELLO_get_id( 2907 GNUNET_assert(GNUNET_HELLO_get_id(
2738 (const struct GNUNET_HELLO_Message *) &hdr[1], 2908 (const struct GNUNET_HELLO_Message *) &hdr[1],
@@ -2746,11 +2916,11 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2746 { 2916 {
2747 2917
2748 GNUNET_assert(session_light != NULL); 2918 GNUNET_assert(session_light != NULL);
2749 if (session_light->session == NULL) 2919 if (session_light->macendpoint == NULL)
2750 { 2920 {
2751 session_light->session = search_session(plugin, &session_light->addr); 2921 session_light->macendpoint = get_macendpoint(plugin,
2922 &session_light->addr, GNUNET_NO);
2752 } 2923 }
2753 session = session_light->session;
2754 2924
2755 fh = (struct FragmentationHeader *) hdr; 2925 fh = (struct FragmentationHeader *) hdr;
2756 tempmsg = (char*) &fh[1]; 2926 tempmsg = (char*) &fh[1];
@@ -2759,9 +2929,9 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2759 GNUNET_log( 2929 GNUNET_log(
2760 GNUNET_ERROR_TYPE_DEBUG, 2930 GNUNET_ERROR_TYPE_DEBUG,
2761 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", 2931 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n",
2762 ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( 2932 ntohl(fh->message_id), ntohs(fh->fragment_off_or_num),
2763 hdr->size), wlan_plugin_address_to_string(NULL, 2933 ntohs(hdr->size),
2764 session_light->addr.mac, 6)); 2934 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
2765#endif 2935#endif
2766 2936
2767 if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) 2937 if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc))
@@ -2772,10 +2942,10 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2772 } 2942 }
2773 2943
2774 //if in the session list 2944 //if in the session list
2775 if (session != NULL) 2945 if (session_light->macendpoint != NULL)
2776 { 2946 {
2777 fragment_bitfield = insert_fragment_in_in_message_queue(plugin, 2947 fragment_bitfield = insert_fragment_in_in_message_queue(plugin,
2778 session_light, session, fh, rxinfo); 2948 session_light, fh, rxinfo);
2779 } 2949 }
2780 else 2950 else
2781 { 2951 {
@@ -2790,16 +2960,16 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2790 GNUNET_YES, GNUNET_NO); 2960 GNUNET_YES, GNUNET_NO);
2791 //wlan_data_message_handler(plugin, session_light, 2961 //wlan_data_message_handler(plugin, session_light,
2792 // (struct GNUNET_MessageHeader *) tempmsg); 2962 // (struct GNUNET_MessageHeader *) tempmsg);
2793 session = session_light->session;
2794 //test if a session was created 2963 //test if a session was created
2795 if (session == NULL) 2964 if (session_light->session == NULL)
2796 { 2965 {
2797 return; 2966 return;
2798 } 2967 }
2799 setBit((char *) &fragment_bitfield, ntohs(fh->fragment_off_or_num)); 2968 setBit((char *) &fragment_bitfield, ntohs(fh->fragment_off_or_num));
2800 } 2969 }
2801 2970
2802 add_ack_for_send(plugin, session, fragment_bitfield, fh); 2971 add_ack_for_send(plugin, session_light->macendpoint, fragment_bitfield,
2972 fh);
2803 set_next_send(plugin); 2973 set_next_send(plugin);
2804 2974
2805 } 2975 }
@@ -2813,20 +2983,20 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2813 GNUNET_log( 2983 GNUNET_log(
2814 GNUNET_ERROR_TYPE_DEBUG, 2984 GNUNET_ERROR_TYPE_DEBUG,
2815 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", 2985 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n",
2816 ntohs(hdr->size), wlan_plugin_address_to_string(NULL, 2986 ntohs(hdr->size),
2817 session_light->addr.mac, 6)); 2987 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
2818#endif 2988#endif
2819 2989
2820 GNUNET_assert(session_light != NULL); 2990 GNUNET_assert(session_light != NULL);
2821 if (session_light->session == NULL) 2991 if (session_light->macendpoint == NULL)
2822 { 2992 {
2823 session_light->session = search_session(plugin, &session_light->addr); 2993 session_light->macendpoint = get_macendpoint(plugin,
2824 GNUNET_assert(session_light->session != NULL); 2994 &session_light->addr, GNUNET_NO);
2825 } 2995 }
2826 session = session_light->session; 2996
2827 fah = (struct FragmentationAckHeader *) hdr; 2997 fah = (struct FragmentationAckHeader *) hdr;
2828 fm = get_fragment_message_from_session_and_id(plugin, session, ntohl( 2998 fm = get_fragment_message_from_endpoint_and_id(plugin,
2829 fah->message_id)); 2999 session_light->macendpoint, ntohl(fah->message_id));
2830 3000
2831 if (fm != NULL) 3001 if (fm != NULL)
2832 { 3002 {
@@ -2847,7 +3017,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2847 { 3017 {
2848 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3018 //GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2849 // "WLAN fragment not in fragment list with id %u of ack\n", ntohl( 3019 // "WLAN fragment not in fragment list with id %u of ack\n", ntohl(
2850 // fah->message_id)); 3020 // fah->message_id));
2851 return; 3021 return;
2852 } 3022 }
2853 3023
@@ -2916,10 +3086,12 @@ wlan_process_helper(void *cls, void *client,
2916 + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx)) 3086 + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx))
2917 { 3087 {
2918#if DEBUG_wlan 3088#if DEBUG_wlan
2919 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3089 GNUNET_log(
2920 "Size of packet is too small; size: %u min size: %u\n", ntohs( 3090 GNUNET_ERROR_TYPE_DEBUG,
2921 hdr->size), sizeof(struct ieee80211_frame) 3091 "Size of packet is too small; size: %u min size: %u\n",
2922 + sizeof(struct GNUNET_MessageHeader)); 3092 ntohs(hdr->size),
3093 sizeof(struct ieee80211_frame)
3094 + sizeof(struct GNUNET_MessageHeader));
2923#endif 3095#endif
2924 //GNUNET_break (0); 3096 //GNUNET_break (0);
2925 /* FIXME: restart SUID process */ 3097 /* FIXME: restart SUID process */
@@ -2971,8 +3143,8 @@ wlan_process_helper(void *cls, void *client,
2971 { 3143 {
2972#if DEBUG_wlan 3144#if DEBUG_wlan
2973 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2974 "Func wlan_process_helper got wrong MAC: %s\n", macprinter( 3146 "Func wlan_process_helper got wrong MAC: %s\n",
2975 wlanIeeeHeader->i_addr1)); 3147 macprinter(wlanIeeeHeader->i_addr1));
2976#endif 3148#endif
2977 } 3149 }
2978 } 3150 }
@@ -2980,8 +3152,8 @@ wlan_process_helper(void *cls, void *client,
2980 { 3152 {
2981#if DEBUG_wlan 3153#if DEBUG_wlan
2982 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3154 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2983 "Func wlan_process_helper got wrong BSSID: %s\n", macprinter( 3155 "Func wlan_process_helper got wrong BSSID: %s\n",
2984 wlanIeeeHeader->i_addr2)); 3156 macprinter(wlanIeeeHeader->i_addr2));
2985#endif 3157#endif
2986 } 3158 }
2987 break; 3159 break;
@@ -2996,14 +3168,14 @@ wlan_process_helper(void *cls, void *client,
2996 } 3168 }
2997 memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress)); 3169 memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress));
2998#if DEBUG_wlan 3170#if DEBUG_wlan
2999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3171 GNUNET_log(
3172 GNUNET_ERROR_TYPE_DEBUG,
3000 "Received WLAN_HELPER_CONTROL message with transport of address %s\n", 3173 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3001 wlan_plugin_address_to_string(cls, &plugin->mac_address, 3174 wlan_plugin_address_to_string(cls, &plugin->mac_address,
3002 sizeof(struct MacAddress))); 3175 sizeof(struct MacAddress)));
3003#endif 3176#endif
3004 plugin->env->notify_address(plugin->env->cls, 3177 plugin->env->notify_address(plugin->env->cls, GNUNET_YES,
3005 GNUNET_YES, 3178 &plugin->mac_address, sizeof(struct MacAddress));
3006 &plugin->mac_address, sizeof(struct MacAddress));
3007 break; 3179 break;
3008 default: 3180 default:
3009 GNUNET_break (0); 3181 GNUNET_break (0);
@@ -3072,43 +3244,43 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
3072 if (plugin->server_stdin == NULL) 3244 if (plugin->server_stdin == NULL)
3073 return GNUNET_SYSERR; 3245 return GNUNET_SYSERR;
3074 3246
3075
3076 /* Start the server process */ 3247 /* Start the server process */
3077 3248
3078 if (testmode == 0) 3249 if (testmode == 0)
3079 { 3250 {
3080 3251
3081#if DEBUG_wlan 3252#if DEBUG_wlan
3082 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3083 "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw, 3254 "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw,
3084 plugin->interface, testmode); 3255 plugin->interface, testmode);
3085#endif 3256#endif
3086 3257
3087 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 3258 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
3088 plugin->server_stdout, filenamehw, filenamehw, plugin->interface, NULL); 3259 plugin->server_stdout, filenamehw, filenamehw, plugin->interface,
3260 NULL);
3089 } 3261 }
3090 else if (testmode == 1) 3262 else if (testmode == 1)
3091 { 3263 {
3092 3264
3093#if DEBUG_wlan 3265#if DEBUG_wlan
3094 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3266 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3095 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", filenameloopback, 3267 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
3096 plugin->interface, testmode); 3268 filenameloopback, plugin->interface, testmode);
3097#endif 3269#endif
3098 3270
3099 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 3271 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
3100 plugin->server_stdout, filenameloopback, filenameloopback, "1", NULL); 3272 plugin->server_stdout, filenameloopback, filenameloopback, "1", NULL);
3101 } 3273 }
3102 else if (testmode == 2) 3274 else if (testmode == 2)
3103 { 3275 {
3104#if DEBUG_wlan 3276#if DEBUG_wlan
3105 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3277 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3106 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n", filenameloopback, 3278 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
3107 plugin->interface, testmode); 3279 filenameloopback, plugin->interface, testmode);
3108#endif 3280#endif
3109 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 3281 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
3110 plugin->server_stdout, filenameloopback, filenameloopback, "2", NULL); 3282 plugin->server_stdout, filenameloopback, filenameloopback, "2", NULL);
3111 } 3283 }
3112 if (plugin->server_proc == NULL) 3284 if (plugin->server_proc == NULL)
3113 { 3285 {
3114#if DEBUG_wlan 3286#if DEBUG_wlan
@@ -3154,8 +3326,8 @@ libgnunet_plugin_transport_wlan_done(void *cls)
3154{ 3326{
3155 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3327 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3156 struct Plugin *plugin = api->cls; 3328 struct Plugin *plugin = api->cls;
3157 struct Sessionqueue * queue = plugin->sessions; 3329 struct MacEndpoint * endpoint = plugin->mac_head;
3158 struct Sessionqueue * queue_next; 3330 struct MacEndpoint * endpoint_next;
3159 struct FragmentMessage * fm; 3331 struct FragmentMessage * fm;
3160 3332
3161#if DEBUG_wlan 3333#if DEBUG_wlan
@@ -3163,20 +3335,18 @@ libgnunet_plugin_transport_wlan_done(void *cls)
3163 "libgnunet_plugin_transport_wlan_done started\n"); 3335 "libgnunet_plugin_transport_wlan_done started\n");
3164#endif 3336#endif
3165 3337
3166
3167 GNUNET_DISK_pipe_close(plugin->server_stdout); 3338 GNUNET_DISK_pipe_close(plugin->server_stdout);
3168 GNUNET_DISK_pipe_close(plugin->server_stdin); 3339 GNUNET_DISK_pipe_close(plugin->server_stdin);
3169 GNUNET_OS_process_kill(plugin->server_proc,9); 3340 GNUNET_OS_process_kill(plugin->server_proc, 9);
3170 GNUNET_OS_process_close(plugin->server_proc); 3341 GNUNET_OS_process_close(plugin->server_proc);
3171 3342
3172
3173 GNUNET_assert (cls !=NULL); 3343 GNUNET_assert (cls !=NULL);
3174 //free sessions 3344 //free sessions
3175 while (queue != NULL) 3345 while (endpoint != NULL)
3176 { 3346 {
3177 queue_next = queue->next; 3347 endpoint_next = endpoint->next;
3178 free_session(plugin, queue); 3348 free_macendpoint(plugin, endpoint);
3179 queue = queue_next; 3349 endpoint = endpoint_next;
3180 3350
3181 } 3351 }
3182 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 3352 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
@@ -3241,7 +3411,7 @@ libgnunet_plugin_transport_wlan_init(void *cls)
3241 plugin = GNUNET_malloc (sizeof (struct Plugin)); 3411 plugin = GNUNET_malloc (sizeof (struct Plugin));
3242 plugin->env = env; 3412 plugin->env = env;
3243 plugin->pendingsessions = 0; 3413 plugin->pendingsessions = 0;
3244 plugin->session_count = 0; 3414 plugin->mac_count = 0;
3245 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 3415 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3246 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 3416 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3247 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 3417 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index 3baa4d79d..5c86c5bd0 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_wlan.h 22 * @file transport/plugin_transport_wlan.h
@@ -30,8 +30,6 @@
30#include <stdint.h> 30#include <stdint.h>
31#include "gnunet_common.h" 31#include "gnunet_common.h"
32 32
33
34
35struct MacAddress 33struct MacAddress
36{ 34{
37 u_int8_t mac[6]; 35 u_int8_t mac[6];
@@ -89,67 +87,71 @@ struct WlanHeader
89 */ 87 */
90 struct GNUNET_PeerIdentity target; 88 struct GNUNET_PeerIdentity target;
91 89
90 /**
91 * Where the packet came from
92 */
93 struct GNUNET_PeerIdentity source;
94
92// followed by payload 95// followed by payload
93 96
94}; 97};
95 98
96/* Wlan IEEE80211 header default */ 99/* Wlan IEEE80211 header default */
97//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html 100//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html
98static const uint8_t u8aIeeeHeader[] = 101static const uint8_t u8aIeeeHeader[] =
99 { 102 { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
100 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; 103 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
101 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data 104 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
102 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; 105 0x00, 0x00, // Duration/ID
103 0x00, 0x00, // Duration/ID 106 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
104 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver 107 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
105 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender 108 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
106 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid 109 0x10, 0x86, //Sequence Control
107 0x10, 0x86, //Sequence Control 110 };
108 };
109 111
110// gnunet bssid 112// gnunet bssid
111static const struct MacAddress mac_bssid = 113static const struct MacAddress mac_bssid =
112 { { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 } } ; 114 {
115 { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 } };
113 116
114// broadcast mac 117// broadcast mac
115static const struct MacAddress bc_all_mac = 118static const struct MacAddress bc_all_mac =
116 { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; 119 {
117 120 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
118 121
119/* this is the template radiotap header we send packets out with */ 122/* this is the template radiotap header we send packets out with */
120 123
121static const uint8_t u8aRadiotapHeader[] = 124static const uint8_t u8aRadiotapHeader[] =
122 { 125 { 0x00, 0x00, // <-- radiotap version
123 0x00, 0x00, // <-- radiotap version 126 0x19, 0x00, // <- radiotap header length
124 0x19, 0x00, // <- radiotap header length 127 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
125 0x6f, 0x08, 0x00, 0x00, // <-- bitmap 128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp 129 0x00, // <-- flags (Offset +0x10)
127 0x00, // <-- flags (Offset +0x10) 130 0x6c, // <-- rate (0ffset +0x11)
128 0x6c, // <-- rate (0ffset +0x11) 131 0x71, 0x09, 0xc0, 0x00, // <-- channel
129 0x71, 0x09, 0xc0, 0x00, // <-- channel 132 0xde, // <-- antsignal
130 0xde, // <-- antsignal 133 0x00, // <-- antnoise
131 0x00, // <-- antnoise 134 0x01, // <-- antenna
132 0x01, // <-- antenna 135 };
133};
134 136
135struct Radiotap_Send 137struct Radiotap_Send
136{ 138{
137 /** 139 /**
138 * wlan send rate 140 * wlan send rate
139 */ 141 */
140 uint8_t rate; 142 uint8_t rate;
141 143
142 /** 144 /**
143 * antenna 145 * antenna
144 */ 146 */
145 uint8_t antenna; 147 uint8_t antenna;
146 148
147 /** 149 /**
148 * Transmit power expressed as unitless distance from max power set at factory calibration. 150 * Transmit power expressed as unitless distance from max power set at factory calibration.
149 * 0 is max power. Monotonically nondecreasing with lower power levels. 151 * 0 is max power. Monotonically nondecreasing with lower power levels.
150 */ 152 */
151 153
152 uint16_t tx_power; 154 uint16_t tx_power;
153}; 155};
154 156
155// bit field defines for ri_present 157// bit field defines for ri_present
@@ -162,15 +164,16 @@ struct Radiotap_Send
162 * struct to represent infos gathered form the radiotap fields 164 * struct to represent infos gathered form the radiotap fields
163 */ 165 */
164 166
165struct Radiotap_rx { 167struct Radiotap_rx
166 uint32_t ri_present; 168{
167 uint64_t ri_mactime; 169 uint32_t ri_present;
168 int32_t ri_power; 170 uint64_t ri_mactime;
169 int32_t ri_noise; 171 int32_t ri_power;
170 uint32_t ri_channel; 172 int32_t ri_noise;
171 uint32_t ri_freq; 173 uint32_t ri_channel;
172 uint32_t ri_rate; 174 uint32_t ri_freq;
173 uint32_t ri_antenna; 175 uint32_t ri_rate;
176 uint32_t ri_antenna;
174}; 177};
175 178
176/** 179/**
@@ -184,48 +187,48 @@ struct RadiotapHeader
184 u_int8_t version; 187 u_int8_t version;
185 188
186 u_int8_t pad_version; 189 u_int8_t pad_version;
187 190
188 /** 191 /**
189 * radiotap header length 192 * radiotap header length
190 */ 193 */
191 uint16_t length GNUNET_PACKED; 194 uint16_t length GNUNET_PACKED;
192 195
193 /** 196 /**
194 * bitmap, fields present 197 * bitmap, fields present
195 */ 198 */
196 uint32_t bitmap GNUNET_PACKED; 199 uint32_t bitmap GNUNET_PACKED;
197 200
198 /** 201 /**
199 * timestamp 202 * timestamp
200 */ 203 */
201 uint64_t timestamp GNUNET_PACKED; 204 uint64_t timestamp GNUNET_PACKED;
202 205
203 /** 206 /**
204 * radiotap flags 207 * radiotap flags
205 */ 208 */
206 uint8_t flags; 209 uint8_t flags;
207 210
208 /** 211 /**
209 * wlan send rate 212 * wlan send rate
210 */ 213 */
211 uint8_t rate; 214 uint8_t rate;
212 215
213 // FIXME: unaligned here, is this OK? 216 // FIXME: unaligned here, is this OK?
214 /** 217 /**
215 * Wlan channel 218 * Wlan channel
216 */ 219 */
217 uint32_t channel GNUNET_PACKED; 220 uint32_t channel GNUNET_PACKED;
218 221
219 /** 222 /**
220 * antsignal 223 * antsignal
221 */ 224 */
222 uint8_t antsignal; 225 uint8_t antsignal;
223 226
224 /** 227 /**
225 * antnoise 228 * antnoise
226 */ 229 */
227 uint8_t antnoise; 230 uint8_t antnoise;
228 231
229 /** 232 /**
230 * antenna 233 * antenna
231 */ 234 */