aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_wlan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r--src/transport/plugin_transport_wlan.c2517
1 files changed, 1309 insertions, 1208 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 80b6f2d6f..6ed367293 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -96,7 +96,7 @@
96#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO 96#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
97 97
98 98
99#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ 99#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
100 100
101#define IEEE80211_FC0_VERSION_MASK 0x03 101#define IEEE80211_FC0_VERSION_MASK 0x03
102#define IEEE80211_FC0_VERSION_SHIFT 0 102#define IEEE80211_FC0_VERSION_SHIFT 0
@@ -113,25 +113,25 @@
113struct iph 113struct iph
114{ 114{
115#if __BYTE_ORDER == __LITTLE_ENDIAN 115#if __BYTE_ORDER == __LITTLE_ENDIAN
116 unsigned int ip_hl :4; /* header length */ 116 unsigned int ip_hl:4; /* header length */
117 unsigned int ip_v :4; /* version */ 117 unsigned int ip_v:4; /* version */
118#endif 118#endif
119#if __BYTE_ORDER == __BIG_ENDIAN 119#if __BYTE_ORDER == __BIG_ENDIAN
120 unsigned int ip_v:4; /* version */ 120 unsigned int ip_v:4; /* version */
121 unsigned int ip_hl:4; /* header length */ 121 unsigned int ip_hl:4; /* header length */
122#endif 122#endif
123 u_int8_t ip_tos; /* type of service */ 123 u_int8_t ip_tos; /* type of service */
124 u_short ip_len; /* total length */ 124 u_short ip_len; /* total length */
125 u_short ip_id; /* identification */ 125 u_short ip_id; /* identification */
126 u_short ip_off; /* fragment offset field */ 126 u_short ip_off; /* fragment offset field */
127#define IP_RF 0x8000 /* reserved fragment flag */ 127#define IP_RF 0x8000 /* reserved fragment flag */
128#define IP_DF 0x4000 /* dont fragment flag */ 128#define IP_DF 0x4000 /* dont fragment flag */
129#define IP_MF 0x2000 /* more fragments flag */ 129#define IP_MF 0x2000 /* more fragments flag */
130#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 130#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
131 u_int8_t ip_ttl; /* time to live */ 131 u_int8_t ip_ttl; /* time to live */
132 u_int8_t ip_p; /* protocol */ 132 u_int8_t ip_p; /* protocol */
133 u_short ip_sum; /* checksum */ 133 u_short ip_sum; /* checksum */
134 struct in_addr ip_src, ip_dst; /* source and dest address */ 134 struct in_addr ip_src, ip_dst; /* source and dest address */
135}; 135};
136 136
137struct udphdr 137struct udphdr
@@ -154,11 +154,11 @@ struct ieee80211_frame
154 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 154 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
155 u_int8_t i_seq[2]; 155 u_int8_t i_seq[2];
156#if DEBUG_wlan_ip_udp_packets_on_air 156#if DEBUG_wlan_ip_udp_packets_on_air
157u_int8_t llc[4]; 157 u_int8_t llc[4];
158struct iph ip; 158 struct iph ip;
159struct udphdr udp; 159 struct udphdr udp;
160#endif 160#endif
161}GNUNET_PACKED; 161} GNUNET_PACKED;
162 162
163/** 163/**
164 * Encapsulation of all of the state of the plugin. 164 * Encapsulation of all of the state of the plugin.
@@ -173,12 +173,12 @@ struct Plugin
173 /** 173 /**
174 * List of open connections. head 174 * List of open connections. head
175 */ 175 */
176 struct MacEndpoint * mac_head; 176 struct MacEndpoint *mac_head;
177 177
178 /** 178 /**
179 * List of open connections. tail 179 * List of open connections. tail
180 */ 180 */
181 struct MacEndpoint * mac_tail; 181 struct MacEndpoint *mac_tail;
182 182
183 /** 183 /**
184 * Number of connections 184 * Number of connections
@@ -188,12 +188,12 @@ struct Plugin
188 /** 188 /**
189 * encapsulation of data from the local wlan helper program 189 * encapsulation of data from the local wlan helper program
190 */ 190 */
191 struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer; 191 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
192 192
193 /** 193 /**
194 * encapsulation of packets received from the wlan helper 194 * encapsulation of packets received from the wlan helper
195 */ 195 */
196 struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer; 196 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
197 197
198 /** 198 /**
199 * stdout pipe handle for the gnunet-wlan-helper process 199 * stdout pipe handle for the gnunet-wlan-helper process
@@ -249,13 +249,13 @@ struct Plugin
249 * Sessions currently pending for transmission 249 * Sessions currently pending for transmission
250 * to a peer, if any. 250 * to a peer, if any.
251 */ 251 */
252 struct Sessionqueue * pending_Sessions_head; 252 struct Sessionqueue *pending_Sessions_head;
253 253
254 /** 254 /**
255 * Sessions currently pending for transmission 255 * Sessions currently pending for transmission
256 * to a peer (tail), if any. 256 * to a peer (tail), if any.
257 */ 257 */
258 struct Sessionqueue * pending_Sessions_tail; 258 struct Sessionqueue *pending_Sessions_tail;
259 259
260 /** 260 /**
261 * number of pending sessions 261 * number of pending sessions
@@ -270,11 +270,11 @@ struct Plugin
270 /** 270 /**
271 * messages ready for send, head 271 * messages ready for send, head
272 */ 272 */
273 struct FragmentMessage_queue * sending_messages_head; 273 struct FragmentMessage_queue *sending_messages_head;
274 /** 274 /**
275 * messages ready for send, tail 275 * messages ready for send, tail
276 */ 276 */
277 struct FragmentMessage_queue * sending_messages_tail; 277 struct FragmentMessage_queue *sending_messages_tail;
278 /** 278 /**
279 * time of the next "hello-beacon" 279 * time of the next "hello-beacon"
280 */ 280 */
@@ -283,12 +283,12 @@ struct Plugin
283 /** 283 /**
284 * queue to send acks for received fragments (head) 284 * queue to send acks for received fragments (head)
285 */ 285 */
286 struct AckSendQueue * ack_send_queue_head; 286 struct AckSendQueue *ack_send_queue_head;
287 287
288 /** 288 /**
289 * queue to send acks for received fragments (tail) 289 * queue to send acks for received fragments (tail)
290 */ 290 */
291 struct AckSendQueue * ack_send_queue_tail; 291 struct AckSendQueue *ack_send_queue_tail;
292 292
293 /** 293 /**
294 * Tracker for bandwidth limit 294 * Tracker for bandwidth limit
@@ -301,9 +301,9 @@ struct Plugin
301 */ 301 */
302struct Finish_send 302struct Finish_send
303{ 303{
304 struct Plugin * plugin; 304 struct Plugin *plugin;
305 char * msgheader; 305 char *msgheader;
306 struct GNUNET_MessageHeader * msgstart; 306 struct GNUNET_MessageHeader *msgstart;
307 ssize_t size; 307 ssize_t size;
308}; 308};
309 309
@@ -313,9 +313,9 @@ struct Finish_send
313//TODO DOXIGEN 313//TODO DOXIGEN
314struct Sessionqueue 314struct Sessionqueue
315{ 315{
316 struct Sessionqueue * next; 316 struct Sessionqueue *next;
317 struct Sessionqueue * prev; 317 struct Sessionqueue *prev;
318 struct Session * content; 318 struct Session *content;
319}; 319};
320 320
321/** 321/**
@@ -324,9 +324,9 @@ struct Sessionqueue
324//TODO DOXIGEN 324//TODO DOXIGEN
325struct FragmentMessage_queue 325struct FragmentMessage_queue
326{ 326{
327 struct FragmentMessage_queue * next; 327 struct FragmentMessage_queue *next;
328 struct FragmentMessage_queue * prev; 328 struct FragmentMessage_queue *prev;
329 struct FragmentMessage * content; 329 struct FragmentMessage *content;
330}; 330};
331 331
332/** 332/**
@@ -335,10 +335,10 @@ struct FragmentMessage_queue
335//TODO DOXIGEN 335//TODO DOXIGEN
336struct Receive_Fragment_Queue 336struct Receive_Fragment_Queue
337{ 337{
338 struct Receive_Fragment_Queue * next; 338 struct Receive_Fragment_Queue *next;
339 struct Receive_Fragment_Queue * prev; 339 struct Receive_Fragment_Queue *prev;
340 uint16_t num; 340 uint16_t num;
341 const char * msg; 341 const char *msg;
342 uint16_t size; 342 uint16_t size;
343 struct Radiotap_rx rxinfo; 343 struct Radiotap_rx rxinfo;
344}; 344};
@@ -346,16 +346,16 @@ struct Receive_Fragment_Queue
346//TODO DOXIGEN 346//TODO DOXIGEN
347struct MacEndpoint_id_fragment_triple 347struct MacEndpoint_id_fragment_triple
348{ 348{
349 struct MacEndpoint * endpoint; 349 struct MacEndpoint *endpoint;
350 uint32_t message_id; 350 uint32_t message_id;
351 struct FragmentMessage * fm; 351 struct FragmentMessage *fm;
352}; 352};
353 353
354//TODO DOXIGEN 354//TODO DOXIGEN
355struct Plugin_Session_pair 355struct Plugin_Session_pair
356{ 356{
357 struct Plugin * plugin; 357 struct Plugin *plugin;
358 struct Session * session; 358 struct Session *session;
359}; 359};
360 360
361/** 361/**
@@ -367,11 +367,11 @@ struct PendingMessage
367 /** 367 /**
368 * dll next 368 * dll next
369 */ 369 */
370 struct PendingMessage * next; 370 struct PendingMessage *next;
371 /** 371 /**
372 * dll prev 372 * dll prev
373 */ 373 */
374 struct PendingMessage * prev; 374 struct PendingMessage *prev;
375 375
376 /** 376 /**
377 * The pending message 377 * The pending message
@@ -393,7 +393,7 @@ struct PendingMessage
393 /** 393 /**
394 * Cls for transmit_cont 394 * Cls for transmit_cont
395 */ 395 */
396 void * transmit_cont_cls; 396 void *transmit_cont_cls;
397 397
398 /** 398 /**
399 * Timeout value for the pending message. 399 * Timeout value for the pending message.
@@ -411,15 +411,15 @@ struct AckSendQueue
411 /** 411 /**
412 * next ack in the ack send queue 412 * next ack in the ack send queue
413 */ 413 */
414 struct AckSendQueue * next; 414 struct AckSendQueue *next;
415 /** 415 /**
416 * previous ack in the ack send queue 416 * previous ack in the ack send queue
417 */ 417 */
418 struct AckSendQueue * prev; 418 struct AckSendQueue *prev;
419 /** 419 /**
420 * pointer to the session this ack belongs to 420 * pointer to the session this ack belongs to
421 */ 421 */
422 struct MacEndpoint * endpoint; 422 struct MacEndpoint *endpoint;
423 /** 423 /**
424 * ID of message, to distinguish between the messages, picked randomly. 424 * ID of message, to distinguish between the messages, picked randomly.
425 */ 425 */
@@ -428,15 +428,15 @@ struct AckSendQueue
428 /** 428 /**
429 * msg to send 429 * msg to send
430 */ 430 */
431 struct GNUNET_MessageHeader * hdr; 431 struct GNUNET_MessageHeader *hdr;
432 /** 432 /**
433 * pointer to the ieee wlan header 433 * pointer to the ieee wlan header
434 */ 434 */
435 struct ieee80211_frame * ieeewlanheader; 435 struct ieee80211_frame *ieeewlanheader;
436 /** 436 /**
437 * pointer to the radiotap header 437 * pointer to the radiotap header
438 */ 438 */
439 struct Radiotap_Send * radioHeader; 439 struct Radiotap_Send *radioHeader;
440}; 440};
441 441
442/** 442/**
@@ -448,7 +448,7 @@ struct Session_light
448 /** 448 /**
449 * the session this message belongs to 449 * the session this message belongs to
450 */ 450 */
451 struct Session * session; 451 struct Session *session;
452 /** 452 /**
453 * peer mac address 453 * peer mac address
454 */ 454 */
@@ -457,7 +457,7 @@ struct Session_light
457 /** 457 /**
458 * mac endpoint 458 * mac endpoint
459 */ 459 */
460 struct MacEndpoint * macendpoint; 460 struct MacEndpoint *macendpoint;
461}; 461};
462 462
463/** 463/**
@@ -475,13 +475,13 @@ struct Session
475 * Message currently pending for transmission 475 * Message currently pending for transmission
476 * to this peer, if any. head 476 * to this peer, if any. head
477 */ 477 */
478 struct PendingMessage * pending_message_head; 478 struct PendingMessage *pending_message_head;
479 479
480 /** 480 /**
481 * Message currently pending for transmission 481 * Message currently pending for transmission
482 * to this peer, if any. tail 482 * to this peer, if any. tail
483 */ 483 */
484 struct PendingMessage * pending_message_tail; 484 struct PendingMessage *pending_message_tail;
485 485
486 /** 486 /**
487 * To whom are we talking to (set to our identity 487 * To whom are we talking to (set to our identity
@@ -509,7 +509,7 @@ struct Session
509 /** 509 /**
510 * peer connection 510 * peer connection
511 */ 511 */
512 struct MacEndpoint * mac; 512 struct MacEndpoint *mac;
513 513
514 /** 514 /**
515 * count of messages in the fragment out queue for this session 515 * count of messages in the fragment out queue for this session
@@ -531,22 +531,22 @@ struct MacEndpoint
531 /** 531 /**
532 * Struct to hold the session reachable over this mac; head 532 * Struct to hold the session reachable over this mac; head
533 */ 533 */
534 struct Sessionqueue * sessions_head; 534 struct Sessionqueue *sessions_head;
535 /** 535 /**
536 * Struct to hold the session reachable over this mac; tail 536 * Struct to hold the session reachable over this mac; tail
537 */ 537 */
538 struct Sessionqueue * sessions_tail; 538 struct Sessionqueue *sessions_tail;
539 /** 539 /**
540 * Messages currently sending 540 * Messages currently sending
541 * to a peer, if any. 541 * to a peer, if any.
542 */ 542 */
543 struct FragmentMessage * sending_messages_head; 543 struct FragmentMessage *sending_messages_head;
544 544
545 /** 545 /**
546 * Messages currently sending 546 * Messages currently sending
547 * to a peer (tail), if any. 547 * to a peer (tail), if any.
548 */ 548 */
549 struct FragmentMessage * sending_messages_tail; 549 struct FragmentMessage *sending_messages_tail;
550 /** 550 /**
551 * dll next 551 * dll next
552 */ 552 */
@@ -564,7 +564,7 @@ struct MacEndpoint
564 /** 564 /**
565 * Defrag context for this mac endpoint 565 * Defrag context for this mac endpoint
566 */ 566 */
567 struct GNUNET_DEFRAGMENT_Context * defrag; 567 struct GNUNET_DEFRAGMENT_Context *defrag;
568 568
569 /** 569 /**
570 * count of messages in the fragment out queue for this mac endpoint 570 * count of messages in the fragment out queue for this mac endpoint
@@ -630,7 +630,7 @@ struct FragmentMessage
630 /** 630 /**
631 * Fragmentation context 631 * Fragmentation context
632 */ 632 */
633 struct GNUNET_FRAGMENT_Context * fragcontext; 633 struct GNUNET_FRAGMENT_Context *fragcontext;
634 634
635 /** 635 /**
636 * Timeout value for the message. 636 * Timeout value for the message.
@@ -645,7 +645,7 @@ struct FragmentMessage
645 /** 645 /**
646 * Fragment to send 646 * Fragment to send
647 */ 647 */
648 char * frag; 648 char *frag;
649 649
650 /** 650 /**
651 * size of message 651 * size of message
@@ -655,20 +655,20 @@ struct FragmentMessage
655 /** 655 /**
656 * pointer to the ieee wlan header 656 * pointer to the ieee wlan header
657 */ 657 */
658 struct ieee80211_frame * ieeewlanheader; 658 struct ieee80211_frame *ieeewlanheader;
659 /** 659 /**
660 * pointer to the radiotap header 660 * pointer to the radiotap header
661 */ 661 */
662 struct Radiotap_Send * radioHeader; 662 struct Radiotap_Send *radioHeader;
663}; 663};
664 664
665static void 665static void
666do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 666do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
667static void 667static void
668free_session(struct Plugin * plugin, struct Sessionqueue * queue, 668free_session (struct Plugin *plugin, struct Sessionqueue *queue,
669 int do_free_macendpoint); 669 int do_free_macendpoint);
670static struct MacEndpoint * 670static struct MacEndpoint *create_macendpoint (struct Plugin *plugin,
671create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr); 671 const struct MacAddress *addr);
672 672
673/** 673/**
674 * Generates a nice hexdump of a memory area. 674 * Generates a nice hexdump of a memory area.
@@ -677,51 +677,50 @@ create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr);
677 * \param length how many bytes to dump 677 * \param length how many bytes to dump
678 */ 678 */
679void 679void
680hexdump(void *mem, unsigned length) 680hexdump (void *mem, unsigned length)
681{ 681{
682 char line[80]; 682 char line[80];
683 char *src = (char*) mem; 683 char *src = (char *) mem;
684 684
685 printf( 685 printf ("dumping %u bytes from %p\r\n"
686 "dumping %u bytes from %p\r\n" 686 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
687 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n", 687 length, src);
688 length, src);
689 unsigned i; 688 unsigned i;
690 int j; 689 int j;
691 690
692 for (i = 0; i < length; i += 16, src += 16) 691 for (i = 0; i < length; i += 16, src += 16)
693 { 692 {
694 char *t = line; 693 char *t = line;
695 694
696 t += sprintf(t, "%04x: ", i); 695 t += sprintf (t, "%04x: ", i);
697 for (j = 0; j < 16; j++) 696 for (j = 0; j < 16; j++)
698 { 697 {
699 if (i + j < length) 698 if (i + j < length)
700 t += sprintf(t, "%02X", src[j] & 0xff); 699 t += sprintf (t, "%02X", src[j] & 0xff);
701 else 700 else
702 t += sprintf(t, " "); 701 t += sprintf (t, " ");
703 t += sprintf(t, j % 2 ? " " : "-"); 702 t += sprintf (t, j % 2 ? " " : "-");
704 } 703 }
705
706 t += sprintf(t, " ");
707 for (j = 0; j < 16; j++)
708 {
709 if (i + j < length)
710 {
711 if (isprint((unsigned char)src[j]))
712 t += sprintf(t, "%c", src[j]);
713 else
714 t += sprintf(t, ".");
715 }
716 else
717 {
718 t += sprintf(t, " ");
719 }
720 }
721 704
722 t += sprintf(t, "\r\n"); 705 t += sprintf (t, " ");
723 printf("%s", line); 706 for (j = 0; j < 16; j++)
707 {
708 if (i + j < length)
709 {
710 if (isprint ((unsigned char) src[j]))
711 t += sprintf (t, "%c", src[j]);
712 else
713 t += sprintf (t, ".");
714 }
715 else
716 {
717 t += sprintf (t, " ");
718 }
724 } 719 }
720
721 t += sprintf (t, "\r\n");
722 printf ("%s", line);
723 }
725} 724}
726 725
727/** 726/**
@@ -732,28 +731,30 @@ hexdump(void *mem, unsigned length)
732 * @return 731 * @return
733 */ 732 */
734static struct MacEndpoint * 733static struct MacEndpoint *
735get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr, 734get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
736 int create_new) 735 int create_new)
737{ 736{
738 struct MacEndpoint * queue = plugin->mac_head; 737 struct MacEndpoint *queue = plugin->mac_head;
738
739 while (queue != NULL) 739 while (queue != NULL)
740 { 740 {
741 GNUNET_assert (queue->sessions_head != NULL); 741 GNUNET_assert (queue->sessions_head != NULL);
742 if (memcmp(addr, &queue->addr, sizeof(struct MacAddress)) == 0) 742 if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
743 return queue; /* session found */ 743 return queue; /* session found */
744 queue = queue->next; 744 queue = queue->next;
745 } 745 }
746 746
747 if (create_new == GNUNET_YES) 747 if (create_new == GNUNET_YES)
748 { 748 {
749 return create_macendpoint(plugin, addr); 749 return create_macendpoint (plugin, addr);
750 } 750 }
751 else 751 else
752 { 752 {
753 return NULL; 753 return NULL;
754 } 754 }
755 755
756} 756}
757
757/** 758/**
758 * search for a session with the addr and peer id 759 * search for a session with the addr and peer id
759 * 760 *
@@ -763,20 +764,20 @@ get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr,
763 * @return returns the session 764 * @return returns the session
764 */ 765 */
765static struct Session * 766static struct Session *
766search_session(struct Plugin *plugin, const struct MacEndpoint * endpoint, 767search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
767 const struct GNUNET_PeerIdentity * peer) 768 const struct GNUNET_PeerIdentity *peer)
768{ 769{
769 GNUNET_assert(endpoint != NULL); 770 GNUNET_assert (endpoint != NULL);
770 struct Sessionqueue * queue = endpoint->sessions_head; 771 struct Sessionqueue *queue = endpoint->sessions_head;
771 772
772 while (queue != NULL) 773 while (queue != NULL)
773 { 774 {
774 GNUNET_assert (queue->content != NULL); 775 GNUNET_assert (queue->content != NULL);
775 if (memcmp(peer, &queue->content->target, 776 if (memcmp (peer, &queue->content->target,
776 sizeof(struct GNUNET_PeerIdentity)) == 0) 777 sizeof (struct GNUNET_PeerIdentity)) == 0)
777 return queue->content; /* session found */ 778 return queue->content; /* session found */
778 queue = queue->next; 779 queue = queue->next;
779 } 780 }
780 return NULL; 781 return NULL;
781} 782}
782 783
@@ -791,21 +792,21 @@ search_session(struct Plugin *plugin, const struct MacEndpoint * endpoint,
791 * @param addrlen length of the address 792 * @param addrlen length of the address
792 * @return string representing the same address 793 * @return string representing the same address
793 */ 794 */
794static const char* 795static const char *
795wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 796wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
796{ 797{
797 static char ret[40]; 798 static char ret[40];
798 const struct MacAddress *mac; 799 const struct MacAddress *mac;
799 800
800 if (addrlen != sizeof(struct MacAddress)) 801 if (addrlen != sizeof (struct MacAddress))
801 { 802 {
802 GNUNET_break (0); 803 GNUNET_break (0);
803 return NULL; 804 return NULL;
804 } 805 }
805 mac = addr; 806 mac = addr;
806 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X", 807 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
807 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], 808 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
808 mac->mac[4], mac->mac[5]); 809 mac->mac[3], mac->mac[4], mac->mac[5]);
809 return ret; 810 return ret;
810} 811}
811 812
@@ -815,25 +816,27 @@ wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
815 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 816 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
816 */ 817 */
817static void 818static void
818session_timeout (void *cls, 819session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
819 const struct GNUNET_SCHEDULER_TaskContext *tc){ 820{
820 struct Sessionqueue * queue = cls; 821 struct Sessionqueue *queue = cls;
821 GNUNET_assert(queue != NULL); 822
823 GNUNET_assert (queue != NULL);
822 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK; 824 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
823 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 825 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
824 return; 826 {
827 return;
828 }
829 if (GNUNET_TIME_absolute_get_remaining
830 (GNUNET_TIME_absolute_add
831 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
832 {
833 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
825 } 834 }
826 if (GNUNET_TIME_absolute_get_remaining(
827 GNUNET_TIME_absolute_add(queue->content->last_activity, SESSION_TIMEOUT)).rel_value
828 == 0)
829 {
830 free_session(queue->content->mac->plugin,queue,GNUNET_YES);
831 }
832 else 835 else
833 { 836 {
834 queue->content->timeout_task = GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT, 837 queue->content->timeout_task =
835 &session_timeout, queue); 838 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
836 } 839 }
837} 840}
838 841
839/** 842/**
@@ -845,24 +848,29 @@ session_timeout (void *cls,
845 */ 848 */
846 849
847static struct Session * 850static struct Session *
848create_session(struct Plugin *plugin, struct MacEndpoint * endpoint, 851create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
849 const struct GNUNET_PeerIdentity * peer) 852 const struct GNUNET_PeerIdentity *peer)
850{ 853{
851 GNUNET_assert(endpoint != NULL); 854 GNUNET_assert (endpoint != NULL);
852 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session)); 855 struct Sessionqueue *queue =
856 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
853 857
854 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head, endpoint->sessions_tail, queue); 858 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
859 endpoint->sessions_tail, queue);
855 860
856 queue->content = (struct Session *) &queue[1]; 861 queue->content = (struct Session *) &queue[1];
857 queue->content->mac = endpoint; 862 queue->content->mac = endpoint;
858 memcpy(&(queue->content->target), peer, sizeof(struct GNUNET_PeerIdentity)); 863 memcpy (&(queue->content->target), peer, sizeof (struct GNUNET_PeerIdentity));
859 queue->content->last_activity = GNUNET_TIME_absolute_get(); 864 queue->content->last_activity = GNUNET_TIME_absolute_get ();
860 queue->content->timeout_task = GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT,&session_timeout, queue); 865 queue->content->timeout_task =
866 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
861 867
862#if DEBUG_wlan 868#if DEBUG_wlan
863 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "New session %p with endpoint %p: %s\n", 869 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
864 queue->content, endpoint, 870 "New session %p with endpoint %p: %s\n", queue->content,
865 wlan_plugin_address_to_string(NULL, endpoint->addr.mac, 6)); 871 endpoint, wlan_plugin_address_to_string (NULL,
872 endpoint->addr.mac,
873 6));
866#endif 874#endif
867 875
868 return queue->content; 876 return queue->content;
@@ -877,16 +885,17 @@ create_session(struct Plugin *plugin, struct MacEndpoint * endpoint,
877 * @return returns the session 885 * @return returns the session
878 */ 886 */
879static struct Session * 887static struct Session *
880get_session(struct Plugin *plugin, const struct MacAddress *addr, 888get_session (struct Plugin *plugin, const struct MacAddress *addr,
881 const struct GNUNET_PeerIdentity * peer) 889 const struct GNUNET_PeerIdentity *peer)
882{ 890{
883 struct MacEndpoint * mac; 891 struct MacEndpoint *mac;
884 mac = get_macendpoint(plugin, addr, GNUNET_YES); 892
885 struct Session * session = search_session(plugin, mac, peer); 893 mac = get_macendpoint (plugin, addr, GNUNET_YES);
894 struct Session *session = search_session (plugin, mac, peer);
886 895
887 if (session != NULL) 896 if (session != NULL)
888 return session; 897 return session;
889 return create_session(plugin, mac, peer); 898 return create_session (plugin, mac, peer);
890} 899}
891 900
892/** 901/**
@@ -897,35 +906,35 @@ get_session(struct Plugin *plugin, const struct MacAddress *addr,
897 * @param session pointer to the session to add 906 * @param session pointer to the session to add
898 */ 907 */
899static void 908static void
900queue_session(struct Plugin *plugin, struct Session * session) 909queue_session (struct Plugin *plugin, struct Session *session)
901{ 910{
902 struct Sessionqueue * queue = plugin->pending_Sessions_head; 911 struct Sessionqueue *queue = plugin->pending_Sessions_head;
903 912
904 if (session->pending_message_head != NULL) 913 if (session->pending_message_head != NULL)
914 {
915 while (queue != NULL)
905 { 916 {
906 while (queue != NULL) 917 // content is never NULL
907 { 918 GNUNET_assert (queue->content != NULL);
908 // content is never NULL 919 // is session already in queue?
909 GNUNET_assert (queue->content != NULL); 920 if (session == queue->content)
910 // is session already in queue? 921 {
911 if (session == queue->content) 922 return;
912 { 923 }
913 return; 924 // try next
914 } 925 queue = queue->next;
915 // try next 926 }
916 queue = queue->next;
917 }
918 927
919 // Session is not in the queue 928 // Session is not in the queue
920 929
921 queue = GNUNET_malloc (sizeof (struct Sessionqueue)); 930 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
922 queue->content = session; 931 queue->content = session;
923 932
924 //insert at the tail 933 //insert at the tail
925 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions_head, 934 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
926 plugin->pending_Sessions_tail, queue); 935 plugin->pending_Sessions_tail, queue);
927 plugin->pendingsessions++; 936 plugin->pendingsessions++;
928 } 937 }
929 938
930} 939}
931 940
@@ -935,9 +944,10 @@ queue_session(struct Plugin *plugin, struct Session * session)
935 * @param tc GNUNET_SCHEDULER_TaskContext pointer 944 * @param tc GNUNET_SCHEDULER_TaskContext pointer
936 */ 945 */
937static void 946static void
938delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 947delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
939{ 948{
940 struct Plugin * plugin = cls; 949 struct Plugin *plugin = cls;
950
941 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 951 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
942 952
943 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 953 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -945,11 +955,12 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
945 955
946 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg 956 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
947 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK) 957 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
948 { 958 {
949 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 959 plugin->server_write_task =
950 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 960 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
951 &do_transmit, plugin); 961 plugin->server_stdin_handle,
952 } 962 &do_transmit, plugin);
963 }
953} 964}
954 965
955/** 966/**
@@ -958,32 +969,33 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
958 */ 969 */
959 970
960static void 971static void
961set_next_beacon_time(struct Plugin * const plugin) 972set_next_beacon_time (struct Plugin *const plugin)
962{ 973{
963 //under 10 known peers: once a second 974 //under 10 known peers: once a second
964 if (plugin->mac_count < 10) 975 if (plugin->mac_count < 10)
965 { 976 {
966 plugin->beacon_time = GNUNET_TIME_absolute_add( 977 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
967 GNUNET_TIME_absolute_get(), 978 GNUNET_TIME_relative_multiply
968 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 979 (GNUNET_TIME_UNIT_SECONDS,
969 HALLO_BEACON_SCALING_FACTOR)); 980 HALLO_BEACON_SCALING_FACTOR));
970 } 981 }
971 //under 30 known peers: every 10 seconds 982 //under 30 known peers: every 10 seconds
972 else if (plugin->mac_count < 30) 983 else if (plugin->mac_count < 30)
973 { 984 {
974 plugin->beacon_time = GNUNET_TIME_absolute_add( 985 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
975 GNUNET_TIME_absolute_get(), 986 GNUNET_TIME_relative_multiply
976 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 987 (GNUNET_TIME_UNIT_SECONDS,
977 10 * HALLO_BEACON_SCALING_FACTOR)); 988 10 *
978 } 989 HALLO_BEACON_SCALING_FACTOR));
990 }
979 //over 30 known peers: once a minute 991 //over 30 known peers: once a minute
980 else 992 else
981 { 993 {
982 plugin->beacon_time = GNUNET_TIME_absolute_add( 994 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
983 GNUNET_TIME_absolute_get(), 995 GNUNET_TIME_relative_multiply
984 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 996 (GNUNET_TIME_UNIT_MINUTES,
985 HALLO_BEACON_SCALING_FACTOR)); 997 HALLO_BEACON_SCALING_FACTOR));
986 } 998 }
987} 999}
988 1000
989/** 1001/**
@@ -992,55 +1004,57 @@ set_next_beacon_time(struct Plugin * const plugin)
992 */ 1004 */
993 1005
994static void 1006static void
995set_next_send(struct Plugin * const plugin) 1007set_next_send (struct Plugin *const plugin)
996{ 1008{
997 struct GNUNET_TIME_Relative next_send; 1009 struct GNUNET_TIME_Relative next_send;
998 1010
999 //cancel old task 1011 //cancel old task
1000 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 1012 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1001 { 1013 {
1002 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); 1014 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1003 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 1015 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1004 } 1016 }
1005 1017
1006 //check if some acks are in the queue 1018 //check if some acks are in the queue
1007 if (plugin->ack_send_queue_head != NULL) 1019 if (plugin->ack_send_queue_head != NULL)
1008 { 1020 {
1009 next_send = GNUNET_TIME_UNIT_ZERO; 1021 next_send = GNUNET_TIME_UNIT_ZERO;
1010 } 1022 }
1011 1023
1012 //check if there are some fragments in the queue 1024 //check if there are some fragments in the queue
1013 else if (plugin->sending_messages_head != NULL) 1025 else if (plugin->sending_messages_head != NULL)
1014 { 1026 {
1015 next_send = GNUNET_TIME_UNIT_ZERO; 1027 next_send = GNUNET_TIME_UNIT_ZERO;
1016 } 1028 }
1017 else 1029 else
1018 { 1030 {
1019 next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); 1031 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1020 } 1032 }
1021 1033
1022#if DEBUG_wlan 1034#if DEBUG_wlan
1023 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Next packet is send in: %u\n", 1035 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1024 next_send.rel_value); 1036 "Next packet is send in: %u\n", next_send.rel_value);
1025#endif 1037#endif
1026 1038
1027 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value) 1039 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1040 {
1041 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1028 { 1042 {
1029 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK) 1043 plugin->server_write_task =
1030 { 1044 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1031 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1045 plugin->server_stdin_handle,
1032 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1046 &do_transmit, plugin);
1033 &do_transmit, plugin);
1034 }
1035 } 1047 }
1048 }
1036 else 1049 else
1050 {
1051 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1037 { 1052 {
1038 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK) 1053 plugin->server_write_delay_task =
1039 { 1054 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1040 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed( 1055 plugin);
1041 next_send, &delay_fragment_task, plugin);
1042 }
1043 } 1056 }
1057 }
1044} 1058}
1045 1059
1046/** 1060/**
@@ -1049,77 +1063,81 @@ set_next_send(struct Plugin * const plugin)
1049 * @return pointer to the session found, returns NULL if there is now session in the queue 1063 * @return pointer to the session found, returns NULL if there is now session in the queue
1050 */ 1064 */
1051static struct Session * 1065static struct Session *
1052get_next_queue_session(struct Plugin * plugin) 1066get_next_queue_session (struct Plugin *plugin)
1053{ 1067{
1054 struct Session * session; 1068 struct Session *session;
1055 struct Sessionqueue * sessionqueue; 1069 struct Sessionqueue *sessionqueue;
1056 struct Sessionqueue * sessionqueue_alt; 1070 struct Sessionqueue *sessionqueue_alt;
1057 struct PendingMessage * pm; 1071 struct PendingMessage *pm;
1072
1058 sessionqueue = plugin->pending_Sessions_head; 1073 sessionqueue = plugin->pending_Sessions_head;
1059 1074
1060 while (sessionqueue != NULL) 1075 while (sessionqueue != NULL)
1061 { 1076 {
1062 session = sessionqueue->content; 1077 session = sessionqueue->content;
1063 1078
1064 GNUNET_assert(session != NULL); 1079 GNUNET_assert (session != NULL);
1065 pm = session->pending_message_head; 1080 pm = session->pending_message_head;
1066 1081
1067#if DEBUG_wlan 1082#if DEBUG_wlan
1068 if (pm == NULL) 1083 if (pm == NULL)
1069 { 1084 {
1070 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1085 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1071 "pending message is empty, should not happen. session %p\n", 1086 "pending message is empty, should not happen. session %p\n",
1072 session); 1087 session);
1073 } 1088 }
1074#endif 1089#endif
1075 1090
1076 GNUNET_assert(pm != NULL); 1091 GNUNET_assert (pm != NULL);
1077 1092
1078 //check for message timeout 1093 //check for message timeout
1079 if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0) 1094 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1080 { 1095 {
1081 //check if session has no message in the fragment queue 1096 //check if session has no message in the fragment queue
1082 if ((session->mac->fragment_messages_out_count 1097 if ((session->mac->fragment_messages_out_count
1083 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) 1098 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT)
1084 && (session->fragment_messages_out_count 1099 && (session->fragment_messages_out_count
1085 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)) 1100 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1086 { 1101 {
1087 plugin->pendingsessions--; 1102 plugin->pendingsessions--;
1088 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1103 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1089 plugin->pending_Sessions_tail, sessionqueue); 1104 plugin->pending_Sessions_tail,
1090 GNUNET_free(sessionqueue); 1105 sessionqueue);
1091 1106 GNUNET_free (sessionqueue);
1092 return session; 1107
1093 } 1108 return session;
1094 else 1109 }
1095 {
1096 sessionqueue = sessionqueue->next;
1097 }
1098 }
1099 else 1110 else
1100 { 1111 {
1101 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm); 1112 sessionqueue = sessionqueue->next;
1102 1113 }
1103 //call the cont func that it did not work 1114 }
1104 if (pm->transmit_cont != NULL) 1115 else
1105 pm->transmit_cont(pm->transmit_cont_cls, &(session->target), 1116 {
1106 GNUNET_SYSERR); 1117 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1107 GNUNET_free(pm->msg); 1118 session->pending_message_tail, pm);
1108 GNUNET_free(pm);
1109
1110 if (session->pending_message_head == NULL)
1111 {
1112 sessionqueue_alt = sessionqueue;
1113 sessionqueue = sessionqueue->next;
1114 plugin->pendingsessions--;
1115 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1116 plugin->pending_Sessions_tail, sessionqueue_alt);
1117
1118 GNUNET_free(sessionqueue_alt);
1119 }
1120 }
1121 1119
1120 //call the cont func that it did not work
1121 if (pm->transmit_cont != NULL)
1122 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1123 GNUNET_SYSERR);
1124 GNUNET_free (pm->msg);
1125 GNUNET_free (pm);
1126
1127 if (session->pending_message_head == NULL)
1128 {
1129 sessionqueue_alt = sessionqueue;
1130 sessionqueue = sessionqueue->next;
1131 plugin->pendingsessions--;
1132 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1133 plugin->pending_Sessions_tail,
1134 sessionqueue_alt);
1135
1136 GNUNET_free (sessionqueue_alt);
1137 }
1122 } 1138 }
1139
1140 }
1123 return NULL; 1141 return NULL;
1124} 1142}
1125 1143
@@ -1129,42 +1147,45 @@ get_next_queue_session(struct Plugin * plugin)
1129 * @param fm message to free 1147 * @param fm message to free
1130 */ 1148 */
1131static void 1149static void
1132free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) 1150free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1133{ 1151{
1134 struct Session * session = fm->session; 1152 struct Session *session = fm->session;
1135 struct MacEndpoint * endpoint = session->mac; 1153 struct MacEndpoint *endpoint = session->mac;
1136 struct FragmentMessage_queue * fmq; 1154 struct FragmentMessage_queue *fmq;
1137 struct FragmentMessage_queue * fmq_next; 1155 struct FragmentMessage_queue *fmq_next;
1138 1156
1139 if (fm != NULL) 1157 if (fm != NULL)
1158 {
1159 fmq = plugin->sending_messages_head;
1160 while (fmq != NULL)
1140 { 1161 {
1141 fmq = plugin->sending_messages_head; 1162 fmq_next = fmq->next;
1142 while (fmq != NULL) 1163 if (fmq->content == fm)
1143 { 1164 {
1144 fmq_next = fmq->next; 1165 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1145 if (fmq->content == fm) 1166 plugin->sending_messages_tail, fmq);
1146 { 1167 GNUNET_free (fmq);
1147 GNUNET_CONTAINER_DLL_remove(plugin->sending_messages_head,plugin->sending_messages_tail, fmq); 1168 }
1148 GNUNET_free(fmq); 1169 fmq = fmq_next;
1149 } 1170 }
1150 fmq = fmq_next;
1151 }
1152
1153 (session->mac->fragment_messages_out_count)--;
1154 session->fragment_messages_out_count--;
1155 plugin->pending_Fragment_Messages--;
1156 GNUNET_CONTAINER_DLL_remove(endpoint->sending_messages_head,endpoint->sending_messages_tail, fm);
1157 GNUNET_FRAGMENT_context_destroy(fm->fragcontext);
1158 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1159 GNUNET_SCHEDULER_cancel(fm->timeout_task);
1160 GNUNET_free(fm);
1161 1171
1162 queue_session(plugin, session); 1172 (session->mac->fragment_messages_out_count)--;
1173 session->fragment_messages_out_count--;
1174 plugin->pending_Fragment_Messages--;
1175 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1176 endpoint->sending_messages_tail, fm);
1177 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1178 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1179 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1180 GNUNET_free (fm);
1181
1182 queue_session (plugin, session);
1163#if DEBUG_wlan 1183#if DEBUG_wlan
1164 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1184 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1165 "Free pending fragment messages %p, session %p\n", fm, session); 1185 "Free pending fragment messages %p, session %p\n", fm,
1186 session);
1166#endif 1187#endif
1167 } 1188 }
1168} 1189}
1169 1190
1170/** 1191/**
@@ -1175,22 +1196,22 @@ free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
1175 * @return GNUNET_YES at success 1196 * @return GNUNET_YES at success
1176 */ 1197 */
1177static int 1198static int
1178getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint, 1199getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1179 struct Radiotap_Send * header) 1200 struct Radiotap_Send *header)
1180{ 1201{
1181 1202
1182 if (endpoint != NULL) 1203 if (endpoint != NULL)
1183 { 1204 {
1184 header->rate = endpoint->rate; 1205 header->rate = endpoint->rate;
1185 header->tx_power = endpoint->tx_power; 1206 header->tx_power = endpoint->tx_power;
1186 header->antenna = endpoint->antenna; 1207 header->antenna = endpoint->antenna;
1187 } 1208 }
1188 else 1209 else
1189 { 1210 {
1190 header->rate = 255; 1211 header->rate = 255;
1191 header->tx_power = 0; 1212 header->tx_power = 0;
1192 header->antenna = 0; 1213 header->antenna = 0;
1193 } 1214 }
1194 1215
1195 return GNUNET_YES; 1216 return GNUNET_YES;
1196} 1217}
@@ -1203,50 +1224,52 @@ getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint,
1203 * @return GNUNET_YES if there was no error 1224 * @return GNUNET_YES if there was no error
1204 */ 1225 */
1205static int 1226static int
1206getWlanHeader(struct ieee80211_frame * Header, 1227getWlanHeader (struct ieee80211_frame *Header,
1207 const struct MacAddress * to_mac_addr, struct Plugin * plugin, 1228 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1208 unsigned int size) 1229 unsigned int size)
1209{ 1230{
1210 uint16_t * tmp16; 1231 uint16_t *tmp16;
1211 const int rate = 11000000; 1232 const int rate = 11000000;
1212 1233
1213 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; 1234 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1214 Header->i_fc[1] = 0x00; 1235 Header->i_fc[1] = 0x00;
1215 memcpy(&Header->i_addr3, &mac_bssid, sizeof(mac_bssid)); 1236 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
1216 memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); 1237 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1217 memcpy(&Header->i_addr1, to_mac_addr, sizeof(struct MacAddress)); 1238 sizeof (plugin->mac_address));
1239 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1218 1240
1219 tmp16 = (uint16_t*) Header->i_dur; 1241 tmp16 = (uint16_t *) Header->i_dur;
1220 *tmp16 = (uint16_t) htole16((size * 1000000) / rate + 290); 1242 *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
1221 1243
1222#if DEBUG_wlan_ip_udp_packets_on_air 1244#if DEBUG_wlan_ip_udp_packets_on_air
1223 uint crc = 0; 1245 uint crc = 0;
1224 uint16_t * x; 1246 uint16_t *x;
1225 int count; 1247 int count;
1226 Header->ip.ip_dst.s_addr = *((uint32_t*) &to_mac_addr->mac[2]); 1248
1227 Header->ip.ip_src.s_addr = *((uint32_t*) &plugin->mac_address.mac[2]); 1249 Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
1250 Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
1228 Header->ip.ip_v = 4; 1251 Header->ip.ip_v = 4;
1229 Header->ip.ip_hl = 5; 1252 Header->ip.ip_hl = 5;
1230 Header->ip.ip_p = 17; 1253 Header->ip.ip_p = 17;
1231 Header->ip.ip_ttl = 1; 1254 Header->ip.ip_ttl = 1;
1232 Header->ip.ip_len = htons(size + 8); 1255 Header->ip.ip_len = htons (size + 8);
1233 Header->ip.ip_sum = 0; 1256 Header->ip.ip_sum = 0;
1234 x =(uint16_t *) &Header->ip; 1257 x = (uint16_t *) & Header->ip;
1235 count = sizeof(struct iph); 1258 count = sizeof (struct iph);
1236 while (count > 1) 1259 while (count > 1)
1237 { 1260 {
1238 /* This is the inner loop */ 1261 /* This is the inner loop */
1239 crc += (unsigned short) * x++; 1262 crc += (unsigned short) *x++;
1240 count -= 2; 1263 count -= 2;
1241 } 1264 }
1242 /* Add left-over byte, if any */ 1265 /* Add left-over byte, if any */
1243 if( count > 0 ) 1266 if (count > 0)
1244 crc += * (unsigned char *) x; 1267 crc += *(unsigned char *) x;
1245 crc = (crc & 0xffff) + (crc >> 16); 1268 crc = (crc & 0xffff) + (crc >> 16);
1246 Header->ip.ip_sum = htons(~ (unsigned short) crc); 1269 Header->ip.ip_sum = htons (~(unsigned short) crc);
1247 Header->llc[0] = 6; 1270 Header->llc[0] = 6;
1248 Header->llc[1] = 6; 1271 Header->llc[1] = 6;
1249 Header->udp.len = htons(size - sizeof(struct ieee80211_frame)); 1272 Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
1250 1273
1251#endif 1274#endif
1252 1275
@@ -1263,10 +1286,10 @@ getWlanHeader(struct ieee80211_frame * Header,
1263 */ 1286 */
1264 1287
1265uint32_t 1288uint32_t
1266getcrc32(const char *msgbuf, size_t msgbuf_size) 1289getcrc32 (const char *msgbuf, size_t msgbuf_size)
1267{ 1290{
1268 1291
1269 return GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size);; 1292 return GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size);;
1270} 1293}
1271 1294
1272/** 1295/**
@@ -1279,7 +1302,7 @@ getcrc32(const char *msgbuf, size_t msgbuf_size)
1279 */ 1302 */
1280 1303
1281uint16_t 1304uint16_t
1282getcrc16(const char *msgbuf, size_t msgbuf_size) 1305getcrc16 (const char *msgbuf, size_t msgbuf_size)
1283{ 1306{
1284 //TODO calc some crc 1307 //TODO calc some crc
1285 return 0; 1308 return 0;
@@ -1292,46 +1315,46 @@ getcrc16(const char *msgbuf, size_t msgbuf_size)
1292 */ 1315 */
1293 1316
1294void 1317void
1295add_message_for_send(void *cls, const struct GNUNET_MessageHeader *hdr) 1318add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1296{ 1319{
1297 1320
1298 struct FragmentMessage * fm = cls; 1321 struct FragmentMessage *fm = cls;
1299 struct FragmentMessage_queue * fmqueue; 1322 struct FragmentMessage_queue *fmqueue;
1300 1323
1301 GNUNET_assert(cls != NULL); 1324 GNUNET_assert (cls != NULL);
1302 GNUNET_assert(fm->frag == NULL); 1325 GNUNET_assert (fm->frag == NULL);
1303 struct MacEndpoint * endpoint = fm->session->mac; 1326 struct MacEndpoint *endpoint = fm->session->mac;
1304 struct Plugin * plugin = endpoint->plugin; 1327 struct Plugin *plugin = endpoint->plugin;
1305 struct GNUNET_MessageHeader * msgheader; 1328 struct GNUNET_MessageHeader *msgheader;
1306 struct GNUNET_MessageHeader * msgheader2; 1329 struct GNUNET_MessageHeader *msgheader2;
1307 uint16_t size; 1330 uint16_t size;
1308 1331
1309#if DEBUG_wlan_retransmission 1332#if DEBUG_wlan_retransmission
1310 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1333 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1311 "Adding fragment of message %p to send, session %p, endpoint %p\n", fm, 1334 "Adding fragment of message %p to send, session %p, endpoint %p\n",
1312 fm->session, endpoint); 1335 fm, fm->session, endpoint);
1313#endif 1336#endif
1314 1337
1315 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1338 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1316 + sizeof(struct ieee80211_frame) + ntohs(hdr->size); 1339 + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1317 fm->frag = GNUNET_malloc(size); 1340 fm->frag = GNUNET_malloc (size);
1318 fm->size = size; 1341 fm->size = size;
1319 1342
1320 msgheader = (struct GNUNET_MessageHeader *) fm->frag; 1343 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1321 msgheader->size = htons(size); 1344 msgheader->size = htons (size);
1322 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1345 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1323 1346
1324 fm->radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1347 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1325 fm->ieeewlanheader = (struct ieee80211_frame*) &fm->radioHeader[1]; 1348 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1326 msgheader2 = (struct GNUNET_MessageHeader*) &fm->ieeewlanheader[1]; 1349 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1327 memcpy(msgheader2, hdr, ntohs(hdr->size)); 1350 memcpy (msgheader2, hdr, ntohs (hdr->size));
1328 1351
1329 fmqueue = GNUNET_malloc(sizeof(struct FragmentMessage_queue)); 1352 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1330 fmqueue->content = fm; 1353 fmqueue->content = fm;
1331 1354
1332 GNUNET_CONTAINER_DLL_insert_tail(plugin->sending_messages_head, 1355 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1333 plugin->sending_messages_tail, fmqueue); 1356 plugin->sending_messages_tail, fmqueue);
1334 set_next_send(plugin); 1357 set_next_send (plugin);
1335} 1358}
1336 1359
1337/** 1360/**
@@ -1339,60 +1362,63 @@ add_message_for_send(void *cls, const struct GNUNET_MessageHeader *hdr)
1339 * @param plugin pointer to the plugin struct 1362 * @param plugin pointer to the plugin struct
1340 */ 1363 */
1341static void 1364static void
1342send_hello_beacon(struct Plugin * plugin) 1365send_hello_beacon (struct Plugin *plugin)
1343{ 1366{
1344 1367
1345#if DEBUG_wlan 1368#if DEBUG_wlan
1346 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Sending hello beacon\n"); 1369 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1370 "Sending hello beacon\n");
1347#endif 1371#endif
1348 1372
1349 uint16_t size; 1373 uint16_t size;
1350 ssize_t bytes; 1374 ssize_t bytes;
1351 uint16_t hallo_size; 1375 uint16_t hallo_size;
1352 struct GNUNET_MessageHeader * msgheader; 1376 struct GNUNET_MessageHeader *msgheader;
1353 struct ieee80211_frame * ieeewlanheader; 1377 struct ieee80211_frame *ieeewlanheader;
1354 struct Radiotap_Send * radioHeader; 1378 struct Radiotap_Send *radioHeader;
1355 struct GNUNET_MessageHeader * msgheader2; 1379 struct GNUNET_MessageHeader *msgheader2;
1356 const struct GNUNET_MessageHeader *hello; 1380 const struct GNUNET_MessageHeader *hello;
1357 1381
1358 hello = plugin->env->get_our_hello (); 1382 hello = plugin->env->get_our_hello ();
1359 hallo_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message*)hello); 1383 hallo_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1360 GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU); 1384 GNUNET_assert (sizeof (struct WlanHeader) + hallo_size <= WLAN_MTU);
1361 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1385 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1362 + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader) 1386 + sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader)
1363 + hallo_size; 1387 + hallo_size;
1364 1388
1365 msgheader = GNUNET_malloc(size); 1389 msgheader = GNUNET_malloc (size);
1366 msgheader->size = htons(size); 1390 msgheader->size = htons (size);
1367 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1391 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1368 1392
1369 radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1393 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1370 getRadiotapHeader(plugin, NULL, radioHeader); 1394 getRadiotapHeader (plugin, NULL, radioHeader);
1371 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1]; 1395 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1372 getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size); 1396 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1373 1397
1374 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; 1398 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1375 msgheader2->size = htons(GNUNET_HELLO_size((struct GNUNET_HELLO_Message*)hello) 1399 msgheader2->size =
1376 + sizeof(struct GNUNET_MessageHeader)); 1400 htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1401 sizeof (struct GNUNET_MessageHeader));
1377 1402
1378 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); 1403 msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
1379 memcpy(&msgheader2[1], hello, hallo_size); 1404 memcpy (&msgheader2[1], hello, hallo_size);
1380 1405
1381 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); 1406 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1382 1407
1383 if (bytes == GNUNET_SYSERR) 1408 if (bytes == GNUNET_SYSERR)
1384 { 1409 {
1385 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1410 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1386 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1411 _
1387 errno, strerror(errno)); 1412 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1413 errno, strerror (errno));
1388 1414
1389 } 1415 }
1390 GNUNET_assert(bytes != GNUNET_SYSERR); 1416 GNUNET_assert (bytes != GNUNET_SYSERR);
1391 GNUNET_assert(bytes == size); 1417 GNUNET_assert (bytes == size);
1392 GNUNET_free(msgheader); 1418 GNUNET_free (msgheader);
1393 1419
1394 set_next_beacon_time(plugin); 1420 set_next_beacon_time (plugin);
1395 set_next_send(plugin); 1421 set_next_send (plugin);
1396} 1422}
1397 1423
1398/** 1424/**
@@ -1404,50 +1430,50 @@ send_hello_beacon(struct Plugin * plugin)
1404 */ 1430 */
1405 1431
1406static void 1432static void
1407add_ack_for_send(void *cls, uint32_t msg_id, 1433add_ack_for_send (void *cls, uint32_t msg_id,
1408 const struct GNUNET_MessageHeader *hdr) 1434 const struct GNUNET_MessageHeader *hdr)
1409{ 1435{
1410 1436
1411 struct AckSendQueue * ack; 1437 struct AckSendQueue *ack;
1412 1438
1413 GNUNET_assert(cls != NULL); 1439 GNUNET_assert (cls != NULL);
1414 struct MacEndpoint * endpoint = cls; 1440 struct MacEndpoint *endpoint = cls;
1415 struct Plugin * plugin = endpoint->plugin; 1441 struct Plugin *plugin = endpoint->plugin;
1416 struct GNUNET_MessageHeader * msgheader; 1442 struct GNUNET_MessageHeader *msgheader;
1417 struct GNUNET_MessageHeader * msgheader2; 1443 struct GNUNET_MessageHeader *msgheader2;
1418 uint16_t size; 1444 uint16_t size;
1419 1445
1420 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1446 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1421 + sizeof(struct ieee80211_frame) + ntohs(hdr->size) 1447 + sizeof (struct ieee80211_frame) + ntohs (hdr->size)
1422 + sizeof(struct AckSendQueue); 1448 + sizeof (struct AckSendQueue);
1423 1449
1424 ack = GNUNET_malloc(size); 1450 ack = GNUNET_malloc (size);
1425 ack->message_id = msg_id; 1451 ack->message_id = msg_id;
1426 ack->endpoint = endpoint; 1452 ack->endpoint = endpoint;
1427 1453
1428 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1454 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1429 + sizeof(struct ieee80211_frame) + ntohs(hdr->size); 1455 + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1430 1456
1431 msgheader = (struct GNUNET_MessageHeader *) &ack[1]; 1457 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1432 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1]; 1458 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1433 msgheader->size = htons(size); 1459 msgheader->size = htons (size);
1434 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1460 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1435 1461
1436 ack->radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1462 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1437 ack->ieeewlanheader = (struct ieee80211_frame*) &(ack->radioHeader)[1]; 1463 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1438 msgheader2 = (struct GNUNET_MessageHeader*) &(ack->ieeewlanheader)[1]; 1464 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1439 memcpy(msgheader2, hdr, ntohs(hdr->size)); 1465 memcpy (msgheader2, hdr, ntohs (hdr->size));
1440 1466
1441 GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head, 1467 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1442 plugin->ack_send_queue_tail, ack); 1468 plugin->ack_send_queue_tail, ack);
1443 1469
1444#if DEBUG_wlan_retransmission 1470#if DEBUG_wlan_retransmission
1445 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1446 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n", 1472 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1447 msg_id, ack, endpoint); 1473 msg_id, ack, endpoint);
1448#endif 1474#endif
1449 1475
1450 set_next_send(plugin); 1476 set_next_send (plugin);
1451} 1477}
1452 1478
1453/** 1479/**
@@ -1457,14 +1483,17 @@ add_ack_for_send(void *cls, uint32_t msg_id,
1457 */ 1483 */
1458static void 1484static void
1459fragmentmessage_timeout (void *cls, 1485fragmentmessage_timeout (void *cls,
1460 const struct GNUNET_SCHEDULER_TaskContext *tc){ 1486 const struct GNUNET_SCHEDULER_TaskContext *tc)
1461 struct FragmentMessage * fm = cls; 1487{
1462 GNUNET_assert(fm != NULL); 1488 struct FragmentMessage *fm = cls;
1489
1490 GNUNET_assert (fm != NULL);
1463 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1491 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1464 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 1492 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1465 return; 1493 {
1494 return;
1466 } 1495 }
1467 free_fragment_message(fm->session->mac->plugin,fm); 1496 free_fragment_message (fm->session->mac->plugin, fm);
1468} 1497}
1469 1498
1470/** 1499/**
@@ -1474,66 +1503,75 @@ fragmentmessage_timeout (void *cls,
1474 */ 1503 */
1475 1504
1476static void 1505static void
1477check_fragment_queue(struct Plugin * plugin) 1506check_fragment_queue (struct Plugin *plugin)
1478{ 1507{
1479 struct Session * session; 1508 struct Session *session;
1480 struct FragmentMessage * fm; 1509 struct FragmentMessage *fm;
1481 struct GNUNET_PeerIdentity pid; 1510 struct GNUNET_PeerIdentity pid;
1482 1511
1483 struct PendingMessage * pm; 1512 struct PendingMessage *pm;
1484 1513
1485 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE) 1514 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1515 {
1516 session = get_next_queue_session (plugin);
1517 if (session != NULL)
1486 { 1518 {
1487 session = get_next_queue_session(plugin); 1519 pm = session->pending_message_head;
1488 if (session != NULL) 1520 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1489 { 1521 session->pending_message_tail, pm);
1490 pm = session->pending_message_head; 1522 session->mac->fragment_messages_out_count++;
1491 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm); 1523 session->fragment_messages_out_count++;
1492 session->mac->fragment_messages_out_count++; 1524 plugin->pending_Fragment_Messages++;
1493 session->fragment_messages_out_count++; 1525 GNUNET_assert (pm != NULL);
1494 plugin->pending_Fragment_Messages++; 1526
1495 GNUNET_assert(pm != NULL); 1527 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1496 1528 fm->session = session;
1497 fm = GNUNET_malloc(sizeof(struct FragmentMessage)); 1529 fm->timeout.abs_value = pm->timeout.abs_value;
1498 fm->session = session; 1530 fm->frag = NULL;
1499 fm->timeout.abs_value = pm->timeout.abs_value; 1531 fm->fragcontext = GNUNET_FRAGMENT_context_create (plugin->env->stats,
1500 fm->frag = NULL; 1532 WLAN_MTU,
1501 fm->fragcontext = GNUNET_FRAGMENT_context_create(plugin->env->stats, 1533 &plugin->tracker,
1502 WLAN_MTU, &plugin->tracker, GNUNET_TIME_UNIT_SECONDS, 1534 GNUNET_TIME_UNIT_SECONDS,
1503 &(pm->msg->header), &add_message_for_send, 1535 &(pm->msg->header),
1504 fm); 1536 &add_message_for_send,
1505 fm->timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_absolute_get_remaining(fm->timeout),fragmentmessage_timeout,fm); 1537 fm);
1506 GNUNET_CONTAINER_DLL_insert_tail(session->mac->sending_messages_head,session->mac->sending_messages_tail,fm); 1538 fm->timeout_task =
1507 1539 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1508 if (pm->transmit_cont != NULL) 1540 (fm->timeout), fragmentmessage_timeout,
1509 { 1541 fm);
1510 pid = session->target; 1542 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1511 pm->transmit_cont(pm->transmit_cont_cls, &pid, GNUNET_OK); 1543 session->mac->sending_messages_tail,
1544 fm);
1545
1546 if (pm->transmit_cont != NULL)
1547 {
1548 pid = session->target;
1549 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1512#if DEBUG_wlan 1550#if DEBUG_wlan
1513 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1551 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1514 "called pm->transmit_cont for %p\n", session); 1552 "called pm->transmit_cont for %p\n", session);
1515#endif 1553#endif
1516 } 1554 }
1517 else 1555 else
1518 { 1556 {
1519#if DEBUG_wlan 1557#if DEBUG_wlan
1520 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1558 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1521 "no pm->transmit_cont for %p\n", session); 1559 "no pm->transmit_cont for %p\n", session);
1522#endif 1560#endif
1523 } 1561 }
1524 GNUNET_free(pm); 1562 GNUNET_free (pm);
1525 1563
1526 if (session->pending_message_head != NULL) 1564 if (session->pending_message_head != NULL)
1527 { 1565 {
1528 //requeue session 1566 //requeue session
1529 queue_session(plugin, session); 1567 queue_session (plugin, session);
1530 } 1568 }
1531 1569
1532 }
1533 } 1570 }
1571 }
1534 1572
1535 //check if timeout changed 1573 //check if timeout changed
1536 set_next_send(plugin); 1574 set_next_send (plugin);
1537} 1575}
1538 1576
1539/** 1577/**
@@ -1542,34 +1580,35 @@ check_fragment_queue(struct Plugin * plugin)
1542 * @param ack pointer to the ack to send 1580 * @param ack pointer to the ack to send
1543 */ 1581 */
1544static void 1582static void
1545send_ack(struct Plugin * plugin, struct AckSendQueue * ack) 1583send_ack (struct Plugin *plugin, struct AckSendQueue *ack)
1546{ 1584{
1547 1585
1548 ssize_t bytes; 1586 ssize_t bytes;
1549 1587
1550#if DEBUG_wlan 1588#if DEBUG_wlan
1551 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1589 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1552 "Sending ack for message_id %u for mac endpoint %p, size %u\n", 1590 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
1553 ack->message_id, ack->endpoint, 1591 ack->message_id, ack->endpoint,
1554 ntohs(ack->hdr->size) - sizeof(struct Radiotap_Send)); 1592 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
1555#endif 1593#endif
1556 1594
1557 getRadiotapHeader(plugin, ack->endpoint, ack->radioHeader); 1595 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
1558 getWlanHeader(ack->ieeewlanheader, &ack->endpoint->addr, plugin, 1596 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
1559 ntohs(ack->hdr->size)); 1597 ntohs (ack->hdr->size));
1560 1598
1561 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, ack->hdr, 1599 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
1562 ntohs(ack->hdr->size)); 1600 ntohs (ack->hdr->size));
1563 if (bytes == GNUNET_SYSERR) 1601 if (bytes == GNUNET_SYSERR)
1564 { 1602 {
1565 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1603 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1566 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1604 _
1567 errno, strerror(errno)); 1605 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1606 errno, strerror (errno));
1568 1607
1569 } 1608 }
1570 GNUNET_assert(bytes != GNUNET_SYSERR); 1609 GNUNET_assert (bytes != GNUNET_SYSERR);
1571 GNUNET_assert(bytes == ntohs(ack->hdr->size)); 1610 GNUNET_assert (bytes == ntohs (ack->hdr->size));
1572 set_next_send(plugin); 1611 set_next_send (plugin);
1573} 1612}
1574 1613
1575/** 1614/**
@@ -1578,39 +1617,40 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1578 * @param tc TaskContext 1617 * @param tc TaskContext
1579 */ 1618 */
1580static void 1619static void
1581finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1620finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1582{ 1621{
1583 struct Finish_send * finish = cls; 1622 struct Finish_send *finish = cls;
1584 struct Plugin * plugin; 1623 struct Plugin *plugin;
1585 ssize_t bytes; 1624 ssize_t bytes;
1586 1625
1587 plugin = finish->plugin; 1626 plugin = finish->plugin;
1588 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1627 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1589 1628
1590 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 1629 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1591 { 1630 {
1592 GNUNET_free (finish->msgstart); 1631 GNUNET_free (finish->msgstart);
1593 GNUNET_free (finish); 1632 GNUNET_free (finish);
1594 return; 1633 return;
1595 } 1634 }
1596 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, 1635 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle,
1597 finish->msgheader, finish->size); 1636 finish->msgheader, finish->size);
1598 GNUNET_assert (bytes != GNUNET_SYSERR); 1637 GNUNET_assert (bytes != GNUNET_SYSERR);
1599 1638
1600 if (bytes != finish->size) 1639 if (bytes != finish->size)
1601 { 1640 {
1602 finish->msgheader = finish->msgheader + bytes; 1641 finish->msgheader = finish->msgheader + bytes;
1603 finish->size = finish->size - bytes; 1642 finish->size = finish->size - bytes;
1604 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1643 plugin->server_write_task =
1605 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1644 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1606 &finish_sending, finish); 1645 plugin->server_stdin_handle,
1607 } 1646 &finish_sending, finish);
1647 }
1608 else 1648 else
1609 { 1649 {
1610 GNUNET_free(finish->msgstart); 1650 GNUNET_free (finish->msgstart);
1611 GNUNET_free(finish); 1651 GNUNET_free (finish);
1612 set_next_send(plugin); 1652 set_next_send (plugin);
1613 } 1653 }
1614} 1654}
1615 1655
1616/** 1656/**
@@ -1620,96 +1660,99 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1620 * @param tc GNUNET_SCHEDULER_TaskContext 1660 * @param tc GNUNET_SCHEDULER_TaskContext
1621 */ 1661 */
1622static void 1662static void
1623do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1663do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1624{ 1664{
1625 struct Plugin * plugin = cls; 1665 struct Plugin *plugin = cls;
1626 1666
1627 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1667 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1628 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1668 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1629 return; 1669 return;
1630 1670
1631 struct Session * session; 1671 struct Session *session;
1632 struct FragmentMessage * fm; 1672 struct FragmentMessage *fm;
1633 struct Finish_send * finish; 1673 struct Finish_send *finish;
1634 struct FragmentMessage_queue * fmq; 1674 struct FragmentMessage_queue *fmq;
1635 struct AckSendQueue * ack; 1675 struct AckSendQueue *ack;
1636 ssize_t bytes; 1676 ssize_t bytes;
1637 1677
1638 if (plugin->ack_send_queue_head != NULL) 1678 if (plugin->ack_send_queue_head != NULL)
1639 { 1679 {
1640 ack = plugin->ack_send_queue_head; 1680 ack = plugin->ack_send_queue_head;
1641 GNUNET_CONTAINER_DLL_remove(plugin->ack_send_queue_head, 1681 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
1642 plugin->ack_send_queue_tail, ack); 1682 plugin->ack_send_queue_tail, ack);
1643 send_ack(plugin, ack); 1683 send_ack (plugin, ack);
1644 GNUNET_free(ack); 1684 GNUNET_free (ack);
1645 return; 1685 return;
1646 } 1686 }
1647 1687
1648 //test if a "hello-beacon" has to be send 1688 //test if a "hello-beacon" has to be send
1649 if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0) 1689 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
1650 { 1690 {
1651 send_hello_beacon(plugin); 1691 send_hello_beacon (plugin);
1652 return; 1692 return;
1653 } 1693 }
1654 1694
1655 if (plugin->sending_messages_head != NULL) 1695 if (plugin->sending_messages_head != NULL)
1656 { 1696 {
1657 fmq = plugin->sending_messages_head; 1697 fmq = plugin->sending_messages_head;
1658 fm = fmq->content; 1698 fm = fmq->content;
1659 GNUNET_CONTAINER_DLL_remove(plugin->sending_messages_head,plugin->sending_messages_tail,fmq); 1699 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1660 GNUNET_free(fmq); 1700 plugin->sending_messages_tail, fmq);
1701 GNUNET_free (fmq);
1661 1702
1662 session = fm->session; 1703 session = fm->session;
1663 GNUNET_assert(session != NULL); 1704 GNUNET_assert (session != NULL);
1664 1705
1665#if DEBUG_wlan 1706#if DEBUG_wlan
1666 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,PLUGIN_LOG_NAME, 1707 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1667 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n", 1708 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
1668 fm, fm->size); 1709 fm, fm->size);
1669#endif 1710#endif
1670 1711
1671 getRadiotapHeader(plugin, session->mac, fm->radioHeader); 1712 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
1672 getWlanHeader(fm->ieeewlanheader, &(fm->session->mac->addr), plugin, 1713 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
1673 fm->size); 1714 fm->size);
1674 1715
1675 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, fm->frag, 1716 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
1676 fm->size); 1717 fm->size);
1677 if (bytes == GNUNET_SYSERR) 1718 if (bytes == GNUNET_SYSERR)
1678 { 1719 {
1679 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1720 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1680 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1721 _
1681 errno, strerror(errno)); 1722 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1723 errno, strerror (errno));
1682 1724
1683 } 1725 }
1684 GNUNET_assert(bytes != GNUNET_SYSERR); 1726 GNUNET_assert (bytes != GNUNET_SYSERR);
1685 1727
1686 if (bytes != fm->size) 1728 if (bytes != fm->size)
1687 { 1729 {
1688 finish = GNUNET_malloc(sizeof( struct Finish_send)); 1730 finish = GNUNET_malloc (sizeof (struct Finish_send));
1689 finish->plugin = plugin; 1731 finish->plugin = plugin;
1690 finish->msgheader = fm->frag + bytes; 1732 finish->msgheader = fm->frag + bytes;
1691 finish->size = fm->size - bytes; 1733 finish->size = fm->size - bytes;
1692 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag; 1734 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
1693 1735
1694 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); 1736 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1695 1737
1696 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1738 plugin->server_write_task =
1697 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1739 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1698 &finish_sending, finish); 1740 plugin->server_stdin_handle,
1699 fm->frag = NULL; 1741 &finish_sending, finish);
1700 } 1742 fm->frag = NULL;
1701 else 1743 }
1702 { 1744 else
1703 GNUNET_free(fm->frag); 1745 {
1704 fm->frag = NULL; 1746 GNUNET_free (fm->frag);
1705 set_next_send(plugin); 1747 fm->frag = NULL;
1706 } 1748 set_next_send (plugin);
1707 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
1708 return;
1709 } 1749 }
1750 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
1751 return;
1752 }
1710 1753
1711 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 1754 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
1712 "do_transmit did nothing, should not happen!\n"); 1755 "do_transmit did nothing, should not happen!\n");
1713} 1756}
1714 1757
1715/** 1758/**
@@ -1725,21 +1768,21 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1725 * and transport 1768 * and transport
1726 */ 1769 */
1727static int 1770static int
1728wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) 1771wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1729{ 1772{
1730 //struct Plugin *plugin = cls; 1773 //struct Plugin *plugin = cls;
1731 1774
1732 /* check if the address is plausible; if so, 1775 /* check if the address is plausible; if so,
1733 add it to our list! */ 1776 * add it to our list! */
1734 1777
1735 GNUNET_assert(cls !=NULL); 1778 GNUNET_assert (cls != NULL);
1736 //FIXME mitm is not checked 1779 //FIXME mitm is not checked
1737 //Mac Address has 6 bytes 1780 //Mac Address has 6 bytes
1738 if (addrlen == 6) 1781 if (addrlen == 6)
1739 { 1782 {
1740 /* TODO check for bad addresses like multicast, broadcast, etc */ 1783 /* TODO check for bad addresses like multicast, broadcast, etc */
1741 return GNUNET_OK; 1784 return GNUNET_OK;
1742 } 1785 }
1743 1786
1744 return GNUNET_SYSERR; 1787 return GNUNET_SYSERR;
1745} 1788}
@@ -1771,33 +1814,33 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
1771 * and does NOT mean that the message was not transmitted (DV) 1814 * and does NOT mean that the message was not transmitted (DV)
1772 */ 1815 */
1773static ssize_t 1816static ssize_t
1774wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, 1817wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1775 const char *msgbuf, size_t msgbuf_size, unsigned int priority, 1818 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
1776 struct GNUNET_TIME_Relative timeout, struct Session *session, 1819 struct GNUNET_TIME_Relative timeout, struct Session *session,
1777 const void *addr, size_t addrlen, int force_address, 1820 const void *addr, size_t addrlen, int force_address,
1778 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1821 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1779{ 1822{
1780 struct Plugin * plugin = cls; 1823 struct Plugin *plugin = cls;
1781 struct PendingMessage * newmsg; 1824 struct PendingMessage *newmsg;
1782 struct WlanHeader * wlanheader; 1825 struct WlanHeader *wlanheader;
1783 1826
1784 //check if msglen > 0 1827 //check if msglen > 0
1785 GNUNET_assert(msgbuf_size > 0); 1828 GNUNET_assert (msgbuf_size > 0);
1786 1829
1787 //get session if needed 1830 //get session if needed
1788 if (session == NULL) 1831 if (session == NULL)
1832 {
1833 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
1789 { 1834 {
1790 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) 1835 session = get_session (plugin, addr, target);
1791 { 1836 }
1792 session = get_session(plugin, addr, target); 1837 else
1793 } 1838 {
1794 else 1839 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1795 { 1840 _("Wlan Address len %d is wrong\n"), addrlen);
1796 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1841 return -1;
1797 _("Wlan Address len %d is wrong\n"), addrlen);
1798 return -1;
1799 }
1800 } 1842 }
1843 }
1801 1844
1802 //queue message: 1845 //queue message:
1803 1846
@@ -1805,50 +1848,53 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1805 //test if there is no other message in the "queue" 1848 //test if there is no other message in the "queue"
1806 //FIXME: to many send requests 1849 //FIXME: to many send requests
1807 if (session->pending_message_head != NULL) 1850 if (session->pending_message_head != NULL)
1808 { 1851 {
1809 newmsg = session->pending_message_head; 1852 newmsg = session->pending_message_head;
1810 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1853 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1811 "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", 1854 "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",
1812 GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value, 1855 GNUNET_TIME_absolute_get_remaining (newmsg->
1813 session->mac->fragment_messages_out_count); 1856 timeout).rel_value,
1814 } 1857 session->mac->fragment_messages_out_count);
1858 }
1815 1859
1816 newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); 1860 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
1817 newmsg->msg = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader)); 1861 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
1818 wlanheader = newmsg->msg; 1862 wlanheader = newmsg->msg;
1819 //copy msg to buffer, not fragmented / segmented yet, but with message header 1863 //copy msg to buffer, not fragmented / segmented yet, but with message header
1820 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); 1864 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
1821 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); 1865 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1822 memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity)); 1866 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
1823 memcpy(&(wlanheader->source), plugin->env->my_identity, 1867 memcpy (&(wlanheader->source), plugin->env->my_identity,
1824 sizeof(struct GNUNET_PeerIdentity)); 1868 sizeof (struct GNUNET_PeerIdentity));
1825 wlanheader->crc = 0; 1869 wlanheader->crc = 0;
1826 memcpy(&wlanheader[1], msgbuf, msgbuf_size); 1870 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
1827 wlanheader->crc = htonl( 1871 wlanheader->crc =
1828 getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader))); 1872 htonl (getcrc32
1873 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
1829 //GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc); 1874 //GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc);
1830 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader)); 1875 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
1831 1876
1832 newmsg->transmit_cont = cont; 1877 newmsg->transmit_cont = cont;
1833 newmsg->transmit_cont_cls = cont_cls; 1878 newmsg->transmit_cont_cls = cont_cls;
1834 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1879 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1835 1880
1836 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500; 1881 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
1837 1882
1838 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); 1883 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
1839 1884
1840 GNUNET_CONTAINER_DLL_insert_tail(session->pending_message_head, session->pending_message_tail, newmsg); 1885 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
1886 session->pending_message_tail, newmsg);
1841 1887
1842#if DEBUG_wlan 1888#if DEBUG_wlan
1843 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1889 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1844 "New message for %p with size (incl wlan header) %u added\n", session, 1890 "New message for %p with size (incl wlan header) %u added\n",
1845 newmsg->message_size); 1891 session, newmsg->message_size);
1846#endif 1892#endif
1847 1893
1848 //queue session 1894 //queue session
1849 queue_session(plugin, session); 1895 queue_session (plugin, session);
1850 1896
1851 check_fragment_queue(plugin); 1897 check_fragment_queue (plugin);
1852 //FIXME not the correct size 1898 //FIXME not the correct size
1853 return msgbuf_size; 1899 return msgbuf_size;
1854 1900
@@ -1860,24 +1906,25 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1860 * @param endpoin pointer to the MacEndpoint to free 1906 * @param endpoin pointer to the MacEndpoint to free
1861 */ 1907 */
1862static void 1908static void
1863free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoint) 1909free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
1864{ 1910{
1865 struct Sessionqueue * sessions; 1911 struct Sessionqueue *sessions;
1866 struct Sessionqueue * sessions_next; 1912 struct Sessionqueue *sessions_next;
1867 GNUNET_assert(endpoint != NULL); 1913
1914 GNUNET_assert (endpoint != NULL);
1868 1915
1869 sessions = endpoint->sessions_head; 1916 sessions = endpoint->sessions_head;
1870 while (sessions != NULL) 1917 while (sessions != NULL)
1871 { 1918 {
1872 sessions_next = sessions->next; 1919 sessions_next = sessions->next;
1873 free_session(plugin, sessions, GNUNET_NO); 1920 free_session (plugin, sessions, GNUNET_NO);
1874 sessions = sessions_next; 1921 sessions = sessions_next;
1875 } 1922 }
1876 1923
1877 GNUNET_CONTAINER_DLL_remove(plugin->mac_head,plugin->mac_tail,endpoint); 1924 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
1878 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1925 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1879 GNUNET_SCHEDULER_cancel(endpoint->timeout_task); 1926 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
1880 GNUNET_free(endpoint); 1927 GNUNET_free (endpoint);
1881 1928
1882} 1929}
1883 1930
@@ -1888,75 +1935,75 @@ free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoint)
1888 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint 1935 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
1889 */ 1936 */
1890static void 1937static void
1891free_session(struct Plugin * plugin, struct Sessionqueue * queue, 1938free_session (struct Plugin *plugin, struct Sessionqueue *queue,
1892 int do_free_macendpoint) 1939 int do_free_macendpoint)
1893{ 1940{
1894 struct Sessionqueue * pendingsession; 1941 struct Sessionqueue *pendingsession;
1895 struct Sessionqueue * pendingsession_tmp; 1942 struct Sessionqueue *pendingsession_tmp;
1896 struct PendingMessage * pm; 1943 struct PendingMessage *pm;
1897 struct MacEndpoint * endpoint; 1944 struct MacEndpoint *endpoint;
1898 struct FragmentMessage * fm; 1945 struct FragmentMessage *fm;
1899 struct FragmentMessage * fmnext; 1946 struct FragmentMessage *fmnext;
1900 int check = 0; 1947 int check = 0;
1901 1948
1902 GNUNET_assert(queue != NULL); 1949 GNUNET_assert (queue != NULL);
1903 GNUNET_assert(queue->content != NULL); 1950 GNUNET_assert (queue->content != NULL);
1904 1951
1905 //session found 1952 //session found
1906 //is this session pending for send 1953 //is this session pending for send
1907 pendingsession = plugin->pending_Sessions_head; 1954 pendingsession = plugin->pending_Sessions_head;
1908 while (pendingsession != NULL) 1955 while (pendingsession != NULL)
1956 {
1957 pendingsession_tmp = pendingsession->next;
1958 if (pendingsession->content == queue->content)
1909 { 1959 {
1910 pendingsession_tmp = pendingsession->next; 1960 plugin->pendingsessions--;
1911 if (pendingsession->content == queue->content) 1961 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1912 { 1962 plugin->pending_Sessions_tail,
1913 plugin->pendingsessions--; 1963 pendingsession);
1914 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1964 GNUNET_free (pendingsession);
1915 plugin->pending_Sessions_tail, 1965
1916 pendingsession); 1966 GNUNET_assert (check == 0);
1917 GNUNET_free(pendingsession); 1967 check = 1;
1918
1919 GNUNET_assert (check == 0);
1920 check = 1;
1921 }
1922 pendingsession = pendingsession_tmp;
1923 } 1968 }
1969 pendingsession = pendingsession_tmp;
1970 }
1924 1971
1925 endpoint = queue->content->mac; 1972 endpoint = queue->content->mac;
1926 fm = endpoint->sending_messages_head; 1973 fm = endpoint->sending_messages_head;
1927 while (fm != NULL) 1974 while (fm != NULL)
1975 {
1976 fmnext = fm->next;
1977 if (fm->session == queue->content)
1928 { 1978 {
1929 fmnext = fm->next; 1979 free_fragment_message (plugin, fm);
1930 if (fm->session == queue->content)
1931 {
1932 free_fragment_message(plugin, fm);
1933 }
1934 fm = fmnext;
1935 } 1980 }
1981 fm = fmnext;
1982 }
1936 1983
1937 // remove PendingMessage 1984 // remove PendingMessage
1938 pm = queue->content->pending_message_head; 1985 pm = queue->content->pending_message_head;
1939 while (pm != NULL) 1986 while (pm != NULL)
1940 { 1987 {
1941 GNUNET_CONTAINER_DLL_remove(queue->content->pending_message_head,queue->content->pending_message_tail,pm); 1988 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
1942 GNUNET_free(pm->msg); 1989 queue->content->pending_message_tail, pm);
1943 GNUNET_free(pm); 1990 GNUNET_free (pm->msg);
1944 pm = queue->content->pending_message_head; 1991 GNUNET_free (pm);
1945 } 1992 pm = queue->content->pending_message_head;
1993 }
1946 1994
1947 GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head , 1995 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
1948 endpoint->sessions_tail, 1996 endpoint->sessions_tail, queue);
1949 queue);
1950 1997
1951 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES) 1998 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
1952 { 1999 {
1953 free_macendpoint(plugin, endpoint); 2000 free_macendpoint (plugin, endpoint);
1954 } 2001 }
1955 2002
1956 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2003 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1957 GNUNET_SCHEDULER_cancel(queue->content->timeout_task); 2004 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
1958 GNUNET_free(queue); 2005 GNUNET_free (queue);
1959 check_fragment_queue(plugin); 2006 check_fragment_queue (plugin);
1960} 2007}
1961 2008
1962/** 2009/**
@@ -1968,33 +2015,34 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue,
1968 * @param target peer from which to disconnect 2015 * @param target peer from which to disconnect
1969 */ 2016 */
1970static void 2017static void
1971wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) 2018wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1972{ 2019{
1973 struct Plugin *plugin = cls; 2020 struct Plugin *plugin = cls;
1974 struct Sessionqueue * queue; 2021 struct Sessionqueue *queue;
1975 struct Sessionqueue * queue_next; 2022 struct Sessionqueue *queue_next;
1976 struct MacEndpoint * endpoint = plugin->mac_head; 2023 struct MacEndpoint *endpoint = plugin->mac_head;
1977 struct MacEndpoint * endpoint_next; 2024 struct MacEndpoint *endpoint_next;
2025
1978 // just look at all the session for the needed one 2026 // just look at all the session for the needed one
1979 while (endpoint != NULL) 2027 while (endpoint != NULL)
2028 {
2029 queue = endpoint->sessions_head;
2030 endpoint_next = endpoint->next;
2031 while (queue != NULL)
1980 { 2032 {
1981 queue = endpoint->sessions_head; 2033 // content is never NULL
1982 endpoint_next = endpoint->next; 2034 GNUNET_assert (queue->content != NULL);
1983 while (queue != NULL) 2035 queue_next = queue->next;
1984 { 2036 if (memcmp (target, &(queue->content->target),
1985 // content is never NULL 2037 sizeof (struct GNUNET_PeerIdentity)) == 0)
1986 GNUNET_assert (queue->content != NULL); 2038 {
1987 queue_next = queue->next; 2039 free_session (plugin, queue, GNUNET_YES);
1988 if (memcmp(target, &(queue->content->target), 2040 }
1989 sizeof(struct GNUNET_PeerIdentity)) == 0) 2041 // try next
1990 { 2042 queue = queue_next;
1991 free_session(plugin, queue, GNUNET_YES);
1992 }
1993 // try next
1994 queue = queue_next;
1995 }
1996 endpoint = endpoint_next;
1997 } 2043 }
2044 endpoint = endpoint_next;
2045 }
1998} 2046}
1999 2047
2000/** 2048/**
@@ -2012,26 +2060,29 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2012 * @param asc_cls closure for asc 2060 * @param asc_cls closure for asc
2013 */ 2061 */
2014static void 2062static void
2015wlan_plugin_address_pretty_printer(void *cls, const char *type, 2063wlan_plugin_address_pretty_printer (void *cls, const char *type,
2016 const void *addr, size_t addrlen, int numeric, 2064 const void *addr, size_t addrlen,
2017 struct GNUNET_TIME_Relative timeout, 2065 int numeric,
2018 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 2066 struct GNUNET_TIME_Relative timeout,
2067 GNUNET_TRANSPORT_AddressStringCallback asc,
2068 void *asc_cls)
2019{ 2069{
2020 char ret[92]; 2070 char ret[92];
2021 const unsigned char * input; 2071 const unsigned char *input;
2022 2072
2023 //GNUNET_assert(cls !=NULL); 2073 //GNUNET_assert(cls !=NULL);
2024 if (addrlen != 6) 2074 if (addrlen != 6)
2025 { 2075 {
2026 /* invalid address (MAC addresses have 6 bytes) */GNUNET_break (0); 2076 /* invalid address (MAC addresses have 6 bytes) */ GNUNET_break (0);
2027 asc(asc_cls, NULL); 2077 asc (asc_cls, NULL);
2028 return; 2078 return;
2029 } 2079 }
2030 input = (const unsigned char*) addr; 2080 input = (const unsigned char *) addr;
2031 GNUNET_snprintf(ret, sizeof(ret), 2081 GNUNET_snprintf (ret, sizeof (ret),
2032 "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", PROTOCOL_PREFIX, 2082 "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2033 input[0], input[1], input[2], input[3], input[4], input[5]); 2083 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3],
2034 asc(asc_cls, ret); 2084 input[4], input[5]);
2085 asc (asc_cls, ret);
2035} 2086}
2036 2087
2037/** 2088/**
@@ -2041,136 +2092,137 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type,
2041 * @param hdr pointer to the data 2092 * @param hdr pointer to the data
2042 */ 2093 */
2043static void 2094static void
2044wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr) 2095wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2045{ 2096{
2046 struct MacEndpoint * endpoint = (struct MacEndpoint *) cls; 2097 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2047 struct Plugin * plugin = endpoint->plugin; 2098 struct Plugin *plugin = endpoint->plugin;
2048 struct WlanHeader * wlanheader; 2099 struct WlanHeader *wlanheader;
2049 struct Session * session; 2100 struct Session *session;
2101
2050 //const char * tempmsg; 2102 //const char * tempmsg;
2051 const struct GNUNET_MessageHeader * temp_hdr; 2103 const struct GNUNET_MessageHeader *temp_hdr;
2052 struct GNUNET_PeerIdentity tmpsource; 2104 struct GNUNET_PeerIdentity tmpsource;
2053 int crc; 2105 int crc;
2054 2106
2055 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) 2107 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2056 { 2108 {
2057 2109
2058#if DEBUG_wlan 2110#if DEBUG_wlan
2059 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2111 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2060 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n", 2112 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2061 ntohs(hdr->size)); 2113 ntohs (hdr->size));
2062#endif 2114#endif
2063 2115
2064 if (ntohs(hdr->size) < sizeof(struct WlanHeader) 2116 if (ntohs (hdr->size) < sizeof (struct WlanHeader)
2065 + sizeof(struct GNUNET_MessageHeader)) 2117 + sizeof (struct GNUNET_MessageHeader))
2066 { 2118 {
2067 //packet not big enought 2119 //packet not big enought
2068 return; 2120 return;
2069 } 2121 }
2070 2122
2071 wlanheader = (struct WlanHeader *) hdr; 2123 wlanheader = (struct WlanHeader *) hdr;
2072 2124
2073 session = search_session(plugin, endpoint, &wlanheader->source); 2125 session = search_session (plugin, endpoint, &wlanheader->source);
2074 2126
2075 //tempmsg = (char*) &wlanheader[1]; 2127 //tempmsg = (char*) &wlanheader[1];
2076 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; 2128 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2077 crc = ntohl(wlanheader->crc); 2129 crc = ntohl (wlanheader->crc);
2078 wlanheader->crc = 0; 2130 wlanheader->crc = 0;
2079 if (getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)) != crc) 2131 if (getcrc32 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2080 { 2132 {
2081 //wrong crc, dispose message 2133 //wrong crc, dispose message
2082 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, 2134 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2083 "Wlan message header crc was wrong: %u != %u\n", 2135 "Wlan message header crc was wrong: %u != %u\n",
2084 getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)), 2136 getcrc32 ((char *) wlanheader,
2085 crc); 2137 ntohs (wlanheader->header.size)), crc);
2086 hexdump((void *) hdr, ntohs(hdr->size)); 2138 hexdump ((void *) hdr, ntohs (hdr->size));
2087 return; 2139 return;
2088 } 2140 }
2089 2141
2090 //if not in session list 2142 //if not in session list
2091 if (session == NULL) 2143 if (session == NULL)
2092 { 2144 {
2093#if DEBUG_wlan 2145#if DEBUG_wlan
2094 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2146 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2095 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n", 2147 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2096 ntohs(wlanheader->header.size), ntohs(temp_hdr->size), 2148 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2097 sizeof(struct WlanHeader)); 2149 sizeof (struct WlanHeader));
2098#endif 2150#endif
2099 //try if it is a hello message 2151 //try if it is a hello message
2100 if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size) 2152 if (ntohs (wlanheader->header.size) >= ntohs (temp_hdr->size)
2101 + sizeof(struct WlanHeader)) 2153 + sizeof (struct WlanHeader))
2102 { 2154 {
2103 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) 2155 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2104 { 2156 {
2105 if (GNUNET_HELLO_get_id( 2157 if (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
2106 (const struct GNUNET_HELLO_Message *) temp_hdr, 2158 temp_hdr, &tmpsource) == GNUNET_OK)
2107 &tmpsource) == GNUNET_OK) 2159 {
2108 { 2160 session = create_session (plugin, endpoint, &tmpsource);
2109 session = create_session(plugin, endpoint, &tmpsource); 2161 }
2110 }
2111 else
2112 {
2113 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2114 "WLAN client not in session list and hello message is not okay\n");
2115 return;
2116 }
2117
2118 }
2119 else
2120 {
2121 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2122 "WLAN client not in session list and not a hello message\n");
2123 return;
2124 }
2125 }
2126 else 2162 else
2127 { 2163 {
2128 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 2164 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2129 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n", 2165 "WLAN client not in session list and hello message is not okay\n");
2130 ntohs(wlanheader->header.size), ntohs(temp_hdr->size), 2166 return;
2131 sizeof(struct WlanHeader)); 2167 }
2132 return;
2133 }
2134 }
2135
2136 //"receive" the message
2137 2168
2138 if (memcmp(&wlanheader->source, &session->target,
2139 sizeof(struct GNUNET_PeerIdentity)) != 0)
2140 {
2141 //wrong peer id
2142#if DEBUG_wlan
2143 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2144 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2145 session);
2146#endif
2147 return;
2148 } 2169 }
2149 2170 else
2150 if (memcmp(&wlanheader->target, plugin->env->my_identity,
2151 sizeof(struct GNUNET_PeerIdentity)) != 0)
2152 { 2171 {
2153 //wrong peer id 2172 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2154#if DEBUG_wlan 2173 "WLAN client not in session list and not a hello message\n");
2155 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2156 "WLAN peer target id doesn't match our peer id: session %p\n",
2157 session);
2158#endif
2159 return; 2174 return;
2160 } 2175 }
2176 }
2177 else
2178 {
2179 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2180 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2181 ntohs (wlanheader->header.size),
2182 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2183 return;
2184 }
2185 }
2161 2186
2162 GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session, 2187 //"receive" the message
2163 (const char *) temp_hdr,
2164 ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO);
2165 2188
2189 if (memcmp (&wlanheader->source, &session->target,
2190 sizeof (struct GNUNET_PeerIdentity)) != 0)
2191 {
2192 //wrong peer id
2193#if DEBUG_wlan
2194 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2195 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2196 session);
2197#endif
2166 return; 2198 return;
2167 } 2199 }
2168 else 2200
2201 if (memcmp (&wlanheader->target, plugin->env->my_identity,
2202 sizeof (struct GNUNET_PeerIdentity)) != 0)
2169 { 2203 {
2170 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 2204 //wrong peer id
2171 "wlan_data_message_handler got wrong message type\n"); 2205#if DEBUG_wlan
2206 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2207 "WLAN peer target id doesn't match our peer id: session %p\n",
2208 session);
2209#endif
2172 return; 2210 return;
2173 } 2211 }
2212
2213 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2214 (const char *) temp_hdr,
2215 ntohs (hdr->size) - sizeof (struct WlanHeader),
2216 GNUNET_YES, GNUNET_NO);
2217
2218 return;
2219 }
2220 else
2221 {
2222 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2223 "wlan_data_message_handler got wrong message type\n");
2224 return;
2225 }
2174} 2226}
2175 2227
2176/** 2228/**
@@ -2181,30 +2233,35 @@ wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr)
2181 */ 2233 */
2182//TODO ATS informations 2234//TODO ATS informations
2183static void 2235static void
2184process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 2236process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2185{ 2237{
2186 2238
2187 GNUNET_assert(client != NULL); 2239 GNUNET_assert (client != NULL);
2188 GNUNET_assert(cls != NULL); 2240 GNUNET_assert (cls != NULL);
2189 struct Session * session = (struct Session *) client; 2241 struct Session *session = (struct Session *) client;
2190 struct Plugin * plugin = (struct Plugin *) cls; 2242 struct Plugin *plugin = (struct Plugin *) cls;
2191 2243
2192 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 2244 struct GNUNET_TRANSPORT_ATS_Information distance[2];
2193 distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 2245
2194 distance[0].value = htonl(1); 2246 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2195 distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 2247 distance[0].value = htonl (1);
2196 distance[1].value = htonl(0); 2248 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2249 distance[1].value = htonl (0);
2197 2250
2198#if DEBUG_wlan 2251#if DEBUG_wlan
2199 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2252 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2200 "Calling plugin->env->receive for session %p; %s; size: %u\n", session, 2253 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2201 wlan_plugin_address_to_string(NULL, session->mac->addr.mac, 6), 2254 session, wlan_plugin_address_to_string (NULL,
2202 htons(hdr->size)); 2255 session->mac->
2256 addr.mac, 6),
2257 htons (hdr->size));
2203#endif 2258#endif
2204 2259
2205 plugin->env->receive(plugin->env->cls, &(session->target), hdr, 2260 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2206 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, 2261 (const struct GNUNET_TRANSPORT_ATS_Information *)
2207 (const char*) &session->mac->addr, sizeof(session->mac->addr)); 2262 &distance, 2, session,
2263 (const char *) &session->mac->addr,
2264 sizeof (session->mac->addr));
2208} 2265}
2209 2266
2210/** 2267/**
@@ -2215,166 +2272,183 @@ process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2215 * @param hdr hdr of the GNUNET_MessageHeader 2272 * @param hdr hdr of the GNUNET_MessageHeader
2216 */ 2273 */
2217static void 2274static void
2218wlan_data_helper(void *cls, struct Session_light * session_light, 2275wlan_data_helper (void *cls, struct Session_light *session_light,
2219 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) 2276 const struct GNUNET_MessageHeader *hdr,
2277 const struct Radiotap_rx *rxinfo)
2220{ 2278{
2221 struct Plugin *plugin = cls; 2279 struct Plugin *plugin = cls;
2222 struct FragmentMessage * fm; 2280 struct FragmentMessage *fm;
2223 struct FragmentMessage * fm2; 2281 struct FragmentMessage *fm2;
2224 2282
2225 //ADVERTISEMENT 2283 //ADVERTISEMENT
2226 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT) 2284 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
2227 { 2285 {
2228 2286
2229 //TODO better DOS protection, error handling 2287 //TODO better DOS protection, error handling
2230 //TODO test first than create session 2288 //TODO test first than create session
2231 GNUNET_assert(session_light != NULL); 2289 GNUNET_assert (session_light != NULL);
2232 2290
2233#if DEBUG_wlan 2291#if DEBUG_wlan
2234 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2292 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2235 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", 2293 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
2236 ntohs(hdr->size), 2294 ntohs (hdr->size),
2237 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2295 wlan_plugin_address_to_string (NULL,
2296 session_light->addr.mac,
2297 6));
2238#endif 2298#endif
2239 2299
2240 if (session_light->macendpoint == NULL) 2300 if (session_light->macendpoint == NULL)
2241 { 2301 {
2242 session_light->macendpoint = get_macendpoint(plugin, 2302 session_light->macendpoint = get_macendpoint (plugin,
2243 &session_light->addr, GNUNET_NO); 2303 &session_light->addr,
2244 } 2304 GNUNET_NO);
2245 GNUNET_assert(GNUNET_HELLO_get_id(
2246 (const struct GNUNET_HELLO_Message *) &hdr[1],
2247 &(session_light->session->target) ) != GNUNET_SYSERR);
2248
2249 } 2305 }
2306 GNUNET_assert (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
2307 &hdr[1],
2308 &(session_light->session->target)) !=
2309 GNUNET_SYSERR);
2310
2311 }
2250 2312
2251 //FRAGMENT 2313 //FRAGMENT
2252 2314
2253 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT) 2315 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2254 { 2316 {
2255 2317
2256 GNUNET_assert(session_light != NULL); 2318 GNUNET_assert (session_light != NULL);
2257 if (session_light->macendpoint == NULL) 2319 if (session_light->macendpoint == NULL)
2258 { 2320 {
2259 session_light->macendpoint = get_macendpoint(plugin, 2321 session_light->macendpoint = get_macendpoint (plugin,
2260 &session_light->addr, GNUNET_YES); 2322 &session_light->addr,
2261 } 2323 GNUNET_YES);
2324 }
2262 2325
2263#if DEBUG_wlan 2326#if DEBUG_wlan
2264 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2327 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2265 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n", 2328 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2266 ntohs(hdr->size), session_light->macendpoint, 2329 ntohs (hdr->size), session_light->macendpoint,
2267 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2330 wlan_plugin_address_to_string (NULL,
2331 session_light->addr.mac,
2332 6));
2268#endif 2333#endif
2269 2334
2270 int ret = GNUNET_DEFRAGMENT_process_fragment( 2335 int ret =
2271 session_light->macendpoint->defrag, hdr); 2336 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2272 if (ret == GNUNET_NO) 2337 hdr);
2273 {
2274 session_light->macendpoint->dups++;
2275 }
2276 else if (ret == GNUNET_OK)
2277 {
2278 session_light->macendpoint->fragc++;
2279 }
2280 set_next_send(plugin);
2281 2338
2339 if (ret == GNUNET_NO)
2340 {
2341 session_light->macendpoint->dups++;
2342 }
2343 else if (ret == GNUNET_OK)
2344 {
2345 session_light->macendpoint->fragc++;
2282 } 2346 }
2347 set_next_send (plugin);
2348
2349 }
2283 2350
2284 //ACK 2351 //ACK
2285 2352
2286 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK) 2353 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2354 {
2355 GNUNET_assert (session_light != NULL);
2356 if (session_light->macendpoint == NULL)
2287 { 2357 {
2288 GNUNET_assert(session_light != NULL); 2358 session_light->macendpoint = get_macendpoint (plugin,
2289 if (session_light->macendpoint == NULL) 2359 &session_light->addr,
2290 { 2360 GNUNET_NO);
2291 session_light->macendpoint = get_macendpoint(plugin, 2361 }
2292 &session_light->addr, GNUNET_NO);
2293 }
2294 2362
2295 if (session_light->macendpoint == NULL) 2363 if (session_light->macendpoint == NULL)
2296 { 2364 {
2297#if DEBUG_wlan 2365#if DEBUG_wlan
2298 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2366 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2299 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n", 2367 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2300 ntohs(hdr->size), 2368 ntohs (hdr->size),
2301 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2369 wlan_plugin_address_to_string (NULL,
2370 session_light->addr.mac,
2371 6));
2302#endif 2372#endif
2303 return; 2373 return;
2304 } 2374 }
2305 2375
2306#if DEBUG_wlan 2376#if DEBUG_wlan
2307 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2377 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2308 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n", 2378 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2309 ntohs(hdr->size), session_light->macendpoint, 2379 ntohs (hdr->size), session_light->macendpoint,
2310 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2380 wlan_plugin_address_to_string (NULL,
2381 session_light->addr.mac,
2382 6));
2311#endif 2383#endif
2312 fm = session_light->macendpoint->sending_messages_head; 2384 fm = session_light->macendpoint->sending_messages_head;
2313 while (fm != NULL) 2385 while (fm != NULL)
2314 { 2386 {
2315 fm2 = fm->next; 2387 fm2 = fm->next;
2316 int ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr); 2388 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2317 if (ret == GNUNET_OK) 2389
2318 { 2390 if (ret == GNUNET_OK)
2391 {
2319#if DEBUG_wlan_retransmission 2392#if DEBUG_wlan_retransmission
2320 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2393 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2321 "Got last ack, finished fragment message %p\n", fm); 2394 "Got last ack, finished fragment message %p\n", fm);
2322#endif 2395#endif
2323 session_light->macendpoint->acks++; 2396 session_light->macendpoint->acks++;
2324 fm->session->last_activity = GNUNET_TIME_absolute_get(); 2397 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2325 session_light->macendpoint->last_activity = fm->session->last_activity; 2398 session_light->macendpoint->last_activity = fm->session->last_activity;
2326 free_fragment_message(plugin, fm); 2399 free_fragment_message (plugin, fm);
2327 check_fragment_queue(plugin); 2400 check_fragment_queue (plugin);
2328 return; 2401 return;
2329 } 2402 }
2330 if (ret == GNUNET_NO) 2403 if (ret == GNUNET_NO)
2331 { 2404 {
2332#if DEBUG_wlan_retransmission 2405#if DEBUG_wlan_retransmission
2333 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Got ack for: %p\n", fm); 2406 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2407 "Got ack for: %p\n", fm);
2334#endif 2408#endif
2335 session_light->macendpoint->acks++; 2409 session_light->macendpoint->acks++;
2336 return; 2410 return;
2337 } 2411 }
2338 if (ret == GNUNET_SYSERR) 2412 if (ret == GNUNET_SYSERR)
2339 { 2413 {
2340 2414
2341 } 2415 }
2342 2416
2343 fm = fm2; 2417 fm = fm2;
2344 } 2418 }
2345 2419
2346#if DEBUG_wlan_retransmission 2420#if DEBUG_wlan_retransmission
2347 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2421 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2348 "WLAN fragment not in fragment list\n"); 2422 "WLAN fragment not in fragment list\n");
2349#endif 2423#endif
2350 return; 2424 return;
2351 2425
2352 } 2426 }
2353 else 2427 else
2354 { 2428 {
2355 // TODO Wrong data? 2429 // TODO Wrong data?
2356 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, 2430 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2357 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", 2431 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2358 ntohs(hdr->type), ntohs(hdr->size)); 2432 ntohs (hdr->type), ntohs (hdr->size));
2359 GNUNET_break(0); 2433 GNUNET_break (0);
2360 return; 2434 return;
2361 } 2435 }
2362 2436
2363#if 0 2437#if 0
2364 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2438 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2365 "Helper finished\n"); 2439 "Helper finished\n");
2366#endif 2440#endif
2367 2441
2368} 2442}
2369 2443
2370//TODO DOXIGEN 2444//TODO DOXIGEN
2371const char * 2445const char *
2372macprinter(const u_int8_t * mac) 2446macprinter (const u_int8_t * mac)
2373{ 2447{
2374 static char macstr[20]; 2448 static char macstr[20];
2375 2449
2376 GNUNET_snprintf(macstr, sizeof(macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1], 2450 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2377 mac[2], mac[3], mac[4], mac[5]); 2451 mac[2], mac[3], mac[4], mac[5]);
2378 return macstr; 2452 return macstr;
2379} 2453}
2380 2454
@@ -2384,25 +2458,28 @@ macprinter(const u_int8_t * mac)
2384 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 2458 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
2385 */ 2459 */
2386static void 2460static void
2387macendpoint_timeout (void *cls, 2461macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2388 const struct GNUNET_SCHEDULER_TaskContext *tc){ 2462{
2389 struct MacEndpoint * endpoint = cls; 2463 struct MacEndpoint *endpoint = cls;
2390 GNUNET_assert(endpoint != NULL); 2464
2465 GNUNET_assert (endpoint != NULL);
2391 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2466 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2392 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 2467 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2393 return; 2468 {
2469 return;
2470 }
2471 if (GNUNET_TIME_absolute_get_remaining
2472 (GNUNET_TIME_absolute_add
2473 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2474 {
2475 free_macendpoint (endpoint->plugin, endpoint);
2394 } 2476 }
2395 if (GNUNET_TIME_absolute_get_remaining(
2396 GNUNET_TIME_absolute_add(endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value
2397 == 0)
2398 {
2399 free_macendpoint(endpoint->plugin,endpoint);
2400 }
2401 else 2477 else
2402 { 2478 {
2403 endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, 2479 endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
2404 &macendpoint_timeout, endpoint); 2480 &macendpoint_timeout,
2405 } 2481 endpoint);
2482 }
2406} 2483}
2407 2484
2408/** 2485/**
@@ -2412,25 +2489,31 @@ macendpoint_timeout (void *cls,
2412 * @return returns a macendpoint 2489 * @return returns a macendpoint
2413 */ 2490 */
2414static struct MacEndpoint * 2491static struct MacEndpoint *
2415create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr) 2492create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2416{ 2493{
2417 struct MacEndpoint * newend = GNUNET_malloc(sizeof (struct MacEndpoint)); 2494 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
2495
2418 newend->addr = *addr; 2496 newend->addr = *addr;
2419 newend->plugin = plugin; 2497 newend->plugin = plugin;
2420 newend->addr = *addr; 2498 newend->addr = *addr;
2421 newend->fragment_messages_out_count = 0; 2499 newend->fragment_messages_out_count = 0;
2422 newend->defrag = GNUNET_DEFRAGMENT_context_create(plugin->env->stats, 2500 newend->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
2423 WLAN_MTU, MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, newend, 2501 WLAN_MTU,
2424 &wlan_data_message_handler, &add_ack_for_send); 2502 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
2425 newend->last_activity = GNUNET_TIME_absolute_get(); 2503 newend,
2426 newend->timeout_task = GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, 2504 &wlan_data_message_handler,
2427 &macendpoint_timeout, newend); 2505 &add_ack_for_send);
2506 newend->last_activity = GNUNET_TIME_absolute_get ();
2507 newend->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
2508 &macendpoint_timeout,
2509 newend);
2428 2510
2429 plugin->mac_count++; 2511 plugin->mac_count++;
2430 GNUNET_CONTAINER_DLL_insert_tail(plugin->mac_head, plugin->mac_tail, newend); 2512 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
2431#if DEBUG_wlan 2513#if DEBUG_wlan
2432 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "New Mac Endpoint %p: %s\n", newend, 2514 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2433 wlan_plugin_address_to_string(NULL, newend->addr.mac, 6)); 2515 "New Mac Endpoint %p: %s\n", newend,
2516 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
2434#endif 2517#endif
2435 return newend; 2518 return newend;
2436} 2519}
@@ -2443,125 +2526,126 @@ create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr)
2443 * @param hdr header of the GNUNET_MessageHeader 2526 * @param hdr header of the GNUNET_MessageHeader
2444 */ 2527 */
2445static void 2528static void
2446wlan_process_helper(void *cls, void *client, 2529wlan_process_helper (void *cls, void *client,
2447 const struct GNUNET_MessageHeader *hdr) 2530 const struct GNUNET_MessageHeader *hdr)
2448{ 2531{
2449 struct Plugin *plugin = cls; 2532 struct Plugin *plugin = cls;
2450 struct ieee80211_frame * wlanIeeeHeader = NULL; 2533 struct ieee80211_frame *wlanIeeeHeader = NULL;
2451 struct Session_light * session_light = NULL; 2534 struct Session_light *session_light = NULL;
2452 struct Radiotap_rx * rxinfo; 2535 struct Radiotap_rx *rxinfo;
2453 const struct GNUNET_MessageHeader * temp_hdr = NULL; 2536 const struct GNUNET_MessageHeader *temp_hdr = NULL;
2454 2537
2455 int datasize = 0; 2538 int datasize = 0;
2456 int pos; 2539 int pos;
2457 2540
2458 switch (ntohs(hdr->type)) 2541 switch (ntohs (hdr->type))
2459 { 2542 {
2460 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: 2543 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
2461#if DEBUG_wlan 2544#if DEBUG_wlan
2462 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2545 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2463 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n", 2546 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
2464 ntohs(hdr->size)); 2547 ntohs (hdr->size));
2465#endif 2548#endif
2466 2549
2467 //call wlan_process_helper with the message inside, later with wlan: analyze signal 2550 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2468 if (ntohs(hdr->size) < sizeof(struct ieee80211_frame) 2551 if (ntohs (hdr->size) < sizeof (struct ieee80211_frame)
2469 + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx)) 2552 + sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
2470 { 2553 {
2471#if DEBUG_wlan 2554#if DEBUG_wlan
2472 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2555 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2473 "Size of packet is too small; size: %u min size: %u\n", 2556 "Size of packet is too small; size: %u min size: %u\n",
2474 ntohs(hdr->size), 2557 ntohs (hdr->size),
2475 sizeof(struct ieee80211_frame) 2558 sizeof (struct ieee80211_frame)
2476 + sizeof(struct GNUNET_MessageHeader)); 2559 + sizeof (struct GNUNET_MessageHeader));
2477#endif 2560#endif
2478 //GNUNET_break (0); 2561 //GNUNET_break (0);
2479 /* FIXME: restart SUID process */ 2562 /* FIXME: restart SUID process */
2480 return; 2563 return;
2481 } 2564 }
2482 rxinfo = (struct Radiotap_rx *) &hdr[1]; 2565 rxinfo = (struct Radiotap_rx *) &hdr[1];
2483 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1]; 2566 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
2484 2567
2485 //process only if it is an broadcast or for this computer both with the gnunet bssid 2568 //process only if it is an broadcast or for this computer both with the gnunet bssid
2486 2569
2487 //check for bssid 2570 //check for bssid
2488 if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, 2571 if (memcmp (&(wlanIeeeHeader->i_addr3), &mac_bssid,
2489 sizeof(struct MacAddress)) == 0) 2572 sizeof (struct MacAddress)) == 0)
2573 {
2574 //check for broadcast or mac
2575 if (memcmp (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2576 sizeof (struct MacAddress) == 0) ||
2577 memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2578 sizeof (struct MacAddress)) == 0)
2490 { 2579 {
2491 //check for broadcast or mac
2492 if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2493 sizeof(struct MacAddress) == 0) || memcmp(
2494 &(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2495 sizeof(struct MacAddress)) == 0)
2496 {
2497 2580
2498 // process the inner data 2581 // process the inner data
2499 2582
2500 2583
2501 datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame) 2584 datasize = ntohs (hdr->size) - sizeof (struct ieee80211_frame)
2502 - sizeof(struct GNUNET_MessageHeader) 2585 - sizeof (struct GNUNET_MessageHeader)
2503 - sizeof(struct Radiotap_rx); 2586 - sizeof (struct Radiotap_rx);
2504 2587
2505 session_light = GNUNET_malloc(sizeof(struct Session_light)); 2588 session_light = GNUNET_malloc (sizeof (struct Session_light));
2506 memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2), 2589 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
2507 sizeof(struct MacAddress)); 2590 sizeof (struct MacAddress));
2508 //session_light->session = search_session(plugin,session_light->addr); 2591 //session_light->session = search_session(plugin,session_light->addr);
2509 2592
2510 pos = 0; 2593 pos = 0;
2511 while (pos < datasize) 2594 while (pos < datasize)
2512 { 2595 {
2513 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] 2596 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
2514 + pos;
2515 2597
2516 wlan_data_helper(plugin, session_light, temp_hdr, rxinfo); 2598 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
2517 pos += ntohs(temp_hdr->size); 2599 pos += ntohs (temp_hdr->size);
2518 2600
2519 } 2601 }
2520 2602
2521 //clean up 2603 //clean up
2522 GNUNET_free(session_light); 2604 GNUNET_free (session_light);
2523 } 2605 }
2524 else 2606 else
2525 { 2607 {
2526#if DEBUG_wlan 2608#if DEBUG_wlan
2527 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2609 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2528 "Func wlan_process_helper got wrong MAC: %s\n", 2610 "Func wlan_process_helper got wrong MAC: %s\n",
2529 macprinter(wlanIeeeHeader->i_addr1)); 2611 macprinter (wlanIeeeHeader->i_addr1));
2530#endif 2612#endif
2531 }
2532 } 2613 }
2614 }
2533 else 2615 else
2534 { 2616 {
2535#if DEBUG_wlan 2617#if DEBUG_wlan
2536 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2618 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2537 "Func wlan_process_helper got wrong BSSID: %s\n", 2619 "Func wlan_process_helper got wrong BSSID: %s\n",
2538 macprinter(wlanIeeeHeader->i_addr2)); 2620 macprinter (wlanIeeeHeader->i_addr2));
2539#endif 2621#endif
2540 } 2622 }
2541 break; 2623 break;
2542 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: 2624 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
2543 //TODO more control messages 2625 //TODO more control messages
2544 //TODO use struct wlan_helper_control 2626 //TODO use struct wlan_helper_control
2545 if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message)) 2627 if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
2546 { 2628 {
2547 GNUNET_break (0); 2629 GNUNET_break (0);
2548 /* FIXME: restart SUID process */ 2630 /* FIXME: restart SUID process */
2549 return; 2631 return;
2550 } 2632 }
2551 memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress)); 2633 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
2552#if DEBUG_wlan 2634#if DEBUG_wlan
2553 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2635 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2554 "Received WLAN_HELPER_CONTROL message with transport of address %s\n", 2636 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
2555 wlan_plugin_address_to_string(cls, &plugin->mac_address, 2637 wlan_plugin_address_to_string (cls, &plugin->mac_address,
2556 sizeof(struct MacAddress))); 2638 sizeof (struct
2639 MacAddress)));
2557#endif 2640#endif
2558 plugin->env->notify_address(plugin->env->cls, GNUNET_YES, 2641 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
2559 &plugin->mac_address, sizeof(struct MacAddress)); 2642 &plugin->mac_address,
2643 sizeof (struct MacAddress));
2560 break; 2644 break;
2561 default: 2645 default:
2562 GNUNET_break (0); 2646 GNUNET_break (0);
2563 return; 2647 return;
2564 } 2648 }
2565} 2649}
2566 2650
2567/** 2651/**
@@ -2573,36 +2657,39 @@ wlan_process_helper(void *cls, void *client,
2573 * @param tc the scheduling context 2657 * @param tc the scheduling context
2574 */ 2658 */
2575static void 2659static void
2576wlan_plugin_helper_read(void *cls, 2660wlan_plugin_helper_read (void *cls,
2577 const struct GNUNET_SCHEDULER_TaskContext *tc) 2661 const struct GNUNET_SCHEDULER_TaskContext *tc)
2578{ 2662{
2579 struct Plugin *plugin = cls; 2663 struct Plugin *plugin = cls;
2664
2580 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2665 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2581 2666
2582 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 2667 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2583 return; 2668 return;
2584 2669
2585 char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)]; 2670 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
2586 ssize_t bytes; 2671 ssize_t bytes;
2587 2672
2588 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, mybuf, 2673 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
2589 sizeof(mybuf)); 2674 sizeof (mybuf));
2590 if (bytes <= 0) 2675 if (bytes <= 0)
2591 { 2676 {
2592#if DEBUG_wlan 2677#if DEBUG_wlan
2593 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2678 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2594 _("Finished reading from wlan-helper stdout with code: %d\n"), 2679 _
2595 bytes); 2680 ("Finished reading from wlan-helper stdout with code: %d\n"),
2681 bytes);
2596#endif 2682#endif
2597 return; 2683 return;
2598 } 2684 }
2599 GNUNET_SERVER_mst_receive(plugin->suid_tokenizer, NULL, mybuf, bytes, 2685 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
2600 GNUNET_NO, GNUNET_NO); 2686 GNUNET_NO, GNUNET_NO);
2601 2687
2602 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2688 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2603 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( 2689 plugin->server_read_task =
2604 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, 2690 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2605 &wlan_plugin_helper_read, plugin); 2691 plugin->server_stdout_handle,
2692 &wlan_plugin_helper_read, plugin);
2606} 2693}
2607 2694
2608/** 2695/**
@@ -2613,85 +2700,93 @@ wlan_plugin_helper_read(void *cls,
2613 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error 2700 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
2614 */ 2701 */
2615static int 2702static int
2616wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) 2703wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2617{ 2704{
2618 const char * filenamehw = "gnunet-transport-wlan-helper"; 2705 const char *filenamehw = "gnunet-transport-wlan-helper";
2619 const char * filenameloopback = "gnunet-transport-wlan-helper-dummy"; 2706 const char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
2620 plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES); 2707
2708 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
2621 if (plugin->server_stdout == NULL) 2709 if (plugin->server_stdout == NULL)
2622 return GNUNET_SYSERR; 2710 return GNUNET_SYSERR;
2623 2711
2624 plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO); 2712 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
2625 if (plugin->server_stdin == NULL) 2713 if (plugin->server_stdin == NULL)
2626 return GNUNET_SYSERR; 2714 return GNUNET_SYSERR;
2627 2715
2628 /* Start the server process */ 2716 /* Start the server process */
2629 2717
2630 if (testmode == 0) 2718 if (testmode == 0)
2631 { 2719 {
2632 2720
2633#if DEBUG_wlan 2721#if DEBUG_wlan
2634 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2722 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2635 "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw, 2723 "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
2636 plugin->interface, testmode); 2724 filenamehw, plugin->interface, testmode);
2637#endif 2725#endif
2638 2726
2639 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2727 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2640 plugin->server_stdout, filenamehw, filenamehw, plugin->interface, 2728 plugin->server_stdout,
2641 NULL); 2729 filenamehw, filenamehw,
2642 } 2730 plugin->interface, NULL);
2731 }
2643 else if (testmode == 1) 2732 else if (testmode == 1)
2644 { 2733 {
2645 2734
2646#if DEBUG_wlan 2735#if DEBUG_wlan
2647 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2736 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2648 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", 2737 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
2649 filenameloopback, plugin->interface, testmode); 2738 filenameloopback, plugin->interface, testmode);
2650#endif 2739#endif
2651 2740
2652 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2741 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2653 plugin->server_stdout, filenameloopback, filenameloopback, "1", NULL); 2742 plugin->server_stdout,
2654 } 2743 filenameloopback,
2744 filenameloopback, "1", NULL);
2745 }
2655 else if (testmode == 2) 2746 else if (testmode == 2)
2656 { 2747 {
2657#if DEBUG_wlan 2748#if DEBUG_wlan
2658 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2749 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2659 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n", 2750 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
2660 filenameloopback, plugin->interface, testmode); 2751 filenameloopback, plugin->interface, testmode);
2661#endif 2752#endif
2662 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2753 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2663 plugin->server_stdout, filenameloopback, filenameloopback, "2", NULL); 2754 plugin->server_stdout,
2664 } 2755 filenameloopback,
2756 filenameloopback, "2", NULL);
2757 }
2665 if (plugin->server_proc == NULL) 2758 if (plugin->server_proc == NULL)
2666 { 2759 {
2667#if DEBUG_wlan 2760#if DEBUG_wlan
2668 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2761 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2669 "Failed to start gnunet-wlan-helper process\n"); 2762 "Failed to start gnunet-wlan-helper process\n");
2670#endif 2763#endif
2671 return GNUNET_SYSERR; 2764 return GNUNET_SYSERR;
2672 } 2765 }
2673 2766
2674 /* Close the write end of the read pipe */ 2767 /* Close the write end of the read pipe */
2675 GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE); 2768 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
2769 GNUNET_DISK_PIPE_END_WRITE);
2676 2770
2677 /* Close the read end of the write pipe */ 2771 /* Close the read end of the write pipe */
2678 GNUNET_DISK_pipe_close_end(plugin->server_stdin, GNUNET_DISK_PIPE_END_READ); 2772 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
2679 2773
2680 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout, 2774 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle (plugin->server_stdout,
2681 GNUNET_DISK_PIPE_END_READ); 2775 GNUNET_DISK_PIPE_END_READ);
2682 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle(plugin->server_stdin, 2776 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle (plugin->server_stdin,
2683 GNUNET_DISK_PIPE_END_WRITE); 2777 GNUNET_DISK_PIPE_END_WRITE);
2684 2778
2685 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2779 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2686 2780
2687#if DEBUG_wlan 2781#if DEBUG_wlan
2688 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2782 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2689 "Adding server_read_task for the wlan-helper\n"); 2783 "Adding server_read_task for the wlan-helper\n");
2690#endif 2784#endif
2691 2785
2692 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( 2786 plugin->server_read_task =
2693 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, 2787 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2694 &wlan_plugin_helper_read, plugin); 2788 plugin->server_stdout_handle,
2789 &wlan_plugin_helper_read, plugin);
2695 2790
2696 return GNUNET_YES; 2791 return GNUNET_YES;
2697} 2792}
@@ -2703,55 +2798,55 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2703 2798
2704//FIXME cleanup 2799//FIXME cleanup
2705void * 2800void *
2706libgnunet_plugin_transport_wlan_done(void *cls) 2801libgnunet_plugin_transport_wlan_done (void *cls)
2707{ 2802{
2708 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2803 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2709 struct Plugin *plugin = api->cls; 2804 struct Plugin *plugin = api->cls;
2710 struct MacEndpoint * endpoint = plugin->mac_head; 2805 struct MacEndpoint *endpoint = plugin->mac_head;
2711 struct MacEndpoint * endpoint_next; 2806 struct MacEndpoint *endpoint_next;
2712 2807
2713#if DEBUG_wlan 2808#if DEBUG_wlan
2714 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2809 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2715 "libgnunet_plugin_transport_wlan_done started\n"); 2810 "libgnunet_plugin_transport_wlan_done started\n");
2716#endif 2811#endif
2717 2812
2718 GNUNET_DISK_pipe_close(plugin->server_stdout); 2813 GNUNET_DISK_pipe_close (plugin->server_stdout);
2719 GNUNET_DISK_pipe_close(plugin->server_stdin); 2814 GNUNET_DISK_pipe_close (plugin->server_stdin);
2720 GNUNET_OS_process_kill(plugin->server_proc, 9); 2815 GNUNET_OS_process_kill (plugin->server_proc, 9);
2721 GNUNET_OS_process_close(plugin->server_proc); 2816 GNUNET_OS_process_close (plugin->server_proc);
2722 2817
2723 GNUNET_assert (cls !=NULL); 2818 GNUNET_assert (cls != NULL);
2724 //free sessions 2819 //free sessions
2725 while (endpoint != NULL) 2820 while (endpoint != NULL)
2726 { 2821 {
2727 endpoint_next = endpoint->next; 2822 endpoint_next = endpoint->next;
2728 free_macendpoint(plugin, endpoint); 2823 free_macendpoint (plugin, endpoint);
2729 endpoint = endpoint_next; 2824 endpoint = endpoint_next;
2730 2825
2731 } 2826 }
2732 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 2827 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
2733 { 2828 {
2734 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); 2829 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
2735 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2830 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2736 } 2831 }
2737 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK) 2832 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
2738 { 2833 {
2739 GNUNET_SCHEDULER_cancel(plugin->server_write_task); 2834 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
2740 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2835 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2741 } 2836 }
2742 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK) 2837 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
2743 { 2838 {
2744 GNUNET_SCHEDULER_cancel(plugin->server_read_task); 2839 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
2745 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2840 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2746 } 2841 }
2747 2842
2748 if (plugin->suid_tokenizer != NULL) 2843 if (plugin->suid_tokenizer != NULL)
2749 GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); 2844 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
2750 2845
2751 if (plugin->data_tokenizer != NULL) 2846 if (plugin->data_tokenizer != NULL)
2752 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); 2847 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
2753 2848
2754 GNUNET_free_non_null(plugin->interface); 2849 GNUNET_free_non_null (plugin->interface);
2755 GNUNET_free (plugin); 2850 GNUNET_free (plugin);
2756 GNUNET_free (api); 2851 GNUNET_free (api);
2757 return NULL; 2852 return NULL;
@@ -2764,7 +2859,7 @@ libgnunet_plugin_transport_wlan_done(void *cls)
2764 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error 2859 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
2765 */ 2860 */
2766void * 2861void *
2767libgnunet_plugin_transport_wlan_init(void *cls) 2862libgnunet_plugin_transport_wlan_init (void *cls)
2768{ 2863{
2769 //struct GNUNET_SERVICE_Context *service; 2864 //struct GNUNET_SERVICE_Context *service;
2770 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2865 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
@@ -2772,7 +2867,7 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2772 struct Plugin *plugin; 2867 struct Plugin *plugin;
2773 static unsigned long long testmode = 0; 2868 static unsigned long long testmode = 0;
2774 2869
2775 GNUNET_assert(cls !=NULL); 2870 GNUNET_assert (cls != NULL);
2776 2871
2777 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2872 plugin = GNUNET_malloc (sizeof (struct Plugin));
2778 plugin->env = env; 2873 plugin->env = env;
@@ -2781,13 +2876,14 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2781 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2876 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2782 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2877 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2783 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2878 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2784 GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, 2879 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
2785 GNUNET_BANDWIDTH_value_init(100 * 1024 * 1024 / 8), 100); 2880 GNUNET_BANDWIDTH_value_init (100 * 1024 *
2881 1024 / 8), 100);
2786 2882
2787 plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, 2883 plugin->suid_tokenizer = GNUNET_SERVER_mst_create (&wlan_process_helper,
2788 plugin); 2884 plugin);
2789 2885
2790 plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); 2886 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
2791 2887
2792 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); 2888 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
2793 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue)); 2889 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
@@ -2801,30 +2897,35 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2801 api->address_to_string = &wlan_plugin_address_to_string; 2897 api->address_to_string = &wlan_plugin_address_to_string;
2802 //read config 2898 //read config
2803 2899
2804 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) 2900 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
2805 { 2901 {
2806 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, 2902 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (env->cfg,
2807 "transport-wlan", "TESTMODE", &testmode)) 2903 "transport-wlan",
2808 testmode = 0; //default value 2904 "TESTMODE",
2809 } 2905 &testmode))
2906 testmode = 0; //default value
2907 }
2810 2908
2811 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE")) 2909 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
2910 {
2911 if (GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-wlan",
2912 "INTERFACE",
2913 &(plugin->interface)) !=
2914 GNUNET_YES)
2812 { 2915 {
2813 if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan", 2916 libgnunet_plugin_transport_wlan_done (api);
2814 "INTERFACE", &(plugin->interface)) != GNUNET_YES) 2917 return NULL;
2815 {
2816 libgnunet_plugin_transport_wlan_done(api);
2817 return NULL;
2818 }
2819 } 2918 }
2919 }
2820 2920
2821 //start the plugin 2921 //start the plugin
2822 set_next_beacon_time(plugin); 2922 set_next_beacon_time (plugin);
2823 2923
2824 wlan_transport_start_wlan_helper(plugin, testmode); 2924 wlan_transport_start_wlan_helper (plugin, testmode);
2825 2925
2826#if DEBUG_wlan 2926#if DEBUG_wlan
2827 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "wlan init finished\n"); 2927 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2928 "wlan init finished\n");
2828#endif 2929#endif
2829 2930
2830 return api; 2931 return api;