2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_wlan.c
23 * @brief transport plugin for wlan
24 * @author David Brodski
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet_transport_service.h"
33 #include "gnunet_transport_plugin.h"
34 #include "plugin_transport_wlan.h"
35 #include "gnunet_common.h"
36 #include "gnunet_crypto_lib.h"
38 #define PROTOCOL_PREFIX "wlan"
41 * Max size of packet from helper
46 * Time until retransmission of a fragment in ms
48 #define FRAGMENT_TIMEOUT GNUNET_TIME_UNIT_SECONDS
50 #define FRAGMENT_QUEUE_SIZE 10
52 #define HALLO_BEACON_SCALING_FACTOR 900
54 #define DEBUG_wlan GNUNET_YES
56 #define MESSAGE_LENGHT_UNKNOWN -1
57 #define NO_MESSAGE_OR_MESSAGE_FINISHED -2
60 * After how long do we expire an address that we
61 * learned from another peer if it is not reconfirmed
64 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
67 * Initial handshake message for a session.
72 * Type is GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME.
74 struct GNUNET_MessageHeader header;
77 * Identit*mac_y of the node connecting (TCP client)
79 struct GNUNET_PeerIdentity clientIdentity;
84 * Encapsulation of all of the state of the plugin.
91 struct GNUNET_TRANSPORT_PluginEnvironment *env;
94 * List of open sessions. head
96 struct Sessionqueue *sessions;
99 * List of open sessions. tail
101 struct Sessionqueue *sessions_tail;
110 * encapsulation to the local wlan server prog
113 struct GNUNET_SERVER_MessageStreamTokenizer * consoltoken;
116 * stdout pipe handle for the gnunet-wlan-helper process
118 struct GNUNET_DISK_PipeHandle *server_stdout;
121 * stdout file handle for the gnunet-wlan-helper process
123 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
126 * stdin pipe handle for the gnunet-wlan-helper process
128 struct GNUNET_DISK_PipeHandle *server_stdin;
131 * stdin file handle for the gnunet-wlan-helper process
133 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
136 * ID of the gnunet-wlan-server std read task
138 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
141 * ID of the gnunet-wlan-server std read task
143 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
146 * ID of the delay task for writing
148 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
151 * The process id of the wlan process
153 struct GNUNET_OS_Process *server_proc;
156 * The interface of the wlan card given to us by the user.
161 * The mac_address of the wlan card given to us by the helper.
163 struct MacAddress mac_address;
166 * Sessions currently pending for transmission
167 * to this peer, if any.
169 struct Sessionqueue * pending_Sessions;
172 * Sessions currently pending for transmission
173 * to this peer (tail), if any.
175 struct Sessionqueue * pending_Sessions_tail;
178 * number of pending sessions
180 unsigned int pendingsessions;
183 * Messages in the fragmentation queue, head
186 struct FragmentMessage * pending_Fragment_Messages_head;
189 * Messages in the fragmentation queue, tail
192 struct FragmentMessage * pending_Fragment_Messages_tail;
195 * number of pending fragment message
198 unsigned int pending_fragment_messages;
201 * time of the next "hello-beacon"
204 struct GNUNET_TIME_Absolute beacon_time;
207 * queue to send acks for received fragments
210 struct AckSendQueue * ack_send_queue_head;
212 struct AckSendQueue * ack_send_queue_tail;
218 struct Plugin * plugin;
220 struct GNUNET_MessageHeader * msgstart;
225 * Queue of sessions, for the general session queue and the pending session queue
230 struct Sessionqueue * next;
231 struct Sessionqueue * prev;
232 struct Session * content;
236 * Queue of ack received for messages send
241 struct AckQueue * next;
242 struct AckQueue * prev;
243 int fragment_num; //TODO change it to offset if better
247 * Queue for the fragments received
252 struct RecQueue * next;
253 struct RecQueue * prev;
260 * Information kept for each message that is yet to
263 struct PendingMessage
267 * The pending message
272 * Size of the message
277 * Continuation function to call once the message
278 * has been sent. Can be NULL if there is no
279 * continuation to call.
281 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
284 * Cls for transmit_cont
286 void * transmit_cont_cls;
289 * Timeout value for the pending message.
291 struct GNUNET_TIME_Absolute timeout;
296 * Queue for acks to send for fragments recived
302 struct AckSendQueue * next;
303 struct AckSendQueue * prev;
305 struct Session * session;
307 * ID of message, to distinguish between the messages, picked randomly.
309 uint32_t message_id GNUNET_PACKED;
312 * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD)
314 uint16_t fragment_off_or_num GNUNET_PACKED;
319 * Session infos gathered from a messages
325 * the session this message belongs to
327 struct Session * session;
335 * Session handle for connections.
343 struct SessionHeader header;
346 * Pointer to the global plugin struct.
348 struct Plugin *plugin;
351 * Message currently pending for transmission
352 * to this peer, if any.
354 struct PendingMessage *pending_message;
357 * To whom are we talking to (set to our identity
358 * if we are still waiting for the welcome message)
360 struct GNUNET_PeerIdentity target;
363 * encapsulation of the receive data
365 //struct GNUNET_SERVER_MessageStreamTokenizer * receive_token;
368 * offset of the next fragment for the receive_token, -1 means last message finished
374 * size of the message received,
375 * MESSAGE_LENGHT_UNKNOWN means that the size is not known,
376 * NO_MESSAGE_OR_MESSAGE_FINISHED means no message received
382 * Sorted queue with the fragments received; head
385 struct RecQueue * frag_head;
388 * Sorted queue with the fragments received; tail
391 struct RecQueue * frag_tail;
399 * Address of the other peer (either based on our 'connect'
400 * call or on our 'accept' call).
405 * Last activity on this connection. Used to select preferred
408 struct GNUNET_TIME_Absolute last_activity;
411 * current number for message incoming, to distinguish between the messages
413 uint32_t message_id_in;
416 * current number for message outgoing, to distinguish between the messages
418 uint32_t message_id_out;
421 * does this session have a message in the fragment queue
429 * Struct for Messages in the fragment queue
432 struct FragmentMessage
435 * Session this message belongs to
438 struct Session *session;
441 * This is a doubly-linked list.
443 struct FragmentMessage *next;
446 * This is a doubly-linked list.
448 struct FragmentMessage *prev;
451 * The pending message
456 * Timeout value for the pending message.
458 struct GNUNET_TIME_Absolute timeout;
461 * Timeout value for the pending fragments.
462 * Stores the time when the next msg fragment ack has to be received
464 struct GNUNET_TIME_Absolute next_ack;
467 * Sorted queue with the acks received for fragments; head
470 struct AckQueue * head;
473 * Sorted queue with the acks received for fragments; tail
476 struct AckQueue * tail;
479 * Size of the message
484 * pos / next fragment number in the message, for fragmentation/segmentation,
485 * some acks can be missing but there is still time
487 uint32_t message_pos;
492 * Header for messages which need fragmentation
497 struct GNUNET_MessageHeader header;
500 * checksum/error correction
502 uint32_t crc GNUNET_PACKED;
505 * To whom are we talking to (set to our identity
506 * if we are still waiting for the welcome message)
508 struct GNUNET_PeerIdentity target;
510 // followed by payload
515 * Header for messages which need fragmentation
517 struct FragmentationHeader
520 struct GNUNET_MessageHeader header;
523 * To whom are we talking to (set to our identity
524 * if we are still waiting for the welcome message)
526 // struct GNUNET_PeerIdentity target GNUNET_PACKED;
529 * ID of message, to distinguish between the messages, picked randomly.
531 uint32_t message_id GNUNET_PACKED;
534 * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD)
536 uint16_t fragment_off_or_num GNUNET_PACKED;
539 * CRC of fragment (for error checking)
541 uint16_t message_crc GNUNET_PACKED;
545 * // 0x1 ack => Use two different message types in header.type! (FRAG_MESSAGE; FRAG_ACK)
546 * // 0x2 has data (not only ack)
547 * // 0x4 last fragment of message
550 // uint32_t flags GNUNET_PACKED;
553 * checksum/error correction
555 // uint32_t crc GNUNET_PACKED;
557 // followed by payload unless ACK
562 getRadiotapHeader(struct RadiotapHeader * Header);
565 getWlanHeader(struct IeeeHeader * Header,const char * to_mac_addr,
566 struct Plugin * plugin);
569 wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen);
572 getcrc16(const char *msgbuf, size_t msgbuf_size);
575 do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
578 check_fragment_queue(struct Plugin * plugin);
581 getcrc32(const char *msgbuf, size_t msgbuf_size);
584 free_rec_frag_queue(struct Session * session);
587 wlan_data_helper(void *cls, struct Session_light * session_light,
588 const struct GNUNET_MessageHeader * hdr);
591 wlan_process_helper(void *cls, void *client,
592 const struct GNUNET_MessageHeader *hdr);
595 finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
598 wlan_data_massage_handler(struct Plugin * plugin,
599 struct Session_light * session_light,
600 const struct GNUNET_MessageHeader * hdr);
603 * get the next message number, at the moment just a random one
604 * @return returns the next valid message-number for sending packets
607 get_next_message_id()
609 return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
613 * start next message number generator
614 * (not necessary at the moment)
617 start_next_message_id()
619 //GNUNET_CRYPTO_random_init;
623 * search for a session with the addr
625 * @param plugin pointer to the plugin struct
626 * @param addr pointer to the mac address of the peer
627 * @return returns the session
630 static struct Session *
631 search_session(struct Plugin *plugin, const uint8_t * addr)
633 struct Sessionqueue * queue = plugin->sessions;
634 struct Sessionqueue * lastitem = NULL;
636 //just look at all the session for the needed one
637 while (queue != NULL)
639 // content is never NULL
640 GNUNET_assert (queue->content != NULL);
641 char * addr2 = queue->content->addr;
642 if (memcmp(addr, addr2, 6) == 0)
645 return queue->content;
655 * create a new session
657 * @param plugin pointer to the plugin struct
658 * @param addr pointer to the mac address of the peer
659 * @return returns the session
662 static struct Session *
663 create_session(struct Plugin *plugin, const uint8_t * addr)
665 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue));
667 GNUNET_CONTAINER_DLL_insert_tail(plugin->sessions, plugin->sessions_tail, queue);
669 queue->content = GNUNET_malloc (sizeof (struct Session));
670 queue->content->plugin = plugin;
671 memcpy(queue->content->addr, addr, 6);
672 queue->content->message_id_out = get_next_message_id();
673 queue->content->has_fragment = 0;
674 queue->content->rec_size = NO_MESSAGE_OR_MESSAGE_FINISHED;
676 plugin->session_count++;
677 return queue->content;
681 * get Session from address, create if no session exists
683 * @param plugin pointer to the plugin struct
684 * @param addr pointer to the mac address of the peer
685 * @return returns the session
687 //TODO add other possibilities to find the right session (are there other?)
688 static struct Session *
689 get_Session(struct Plugin *plugin, const uint8_t * addr)
691 struct Session * session = search_session(plugin, addr);
697 return create_session(plugin, addr);
699 /* -- not needed, layer above already has it--
700 //queue welcome message for new sessions, not realy needed
701 //struct WelcomeMessage welcome;
702 struct PendingMessage *pm;
703 pm = GNUNET_malloc (sizeof (struct PendingMessage));
704 pm->msg = GNUNET_malloc(GNUNET_HELLO_size(* (plugin->env->our_hello)));
705 pm->message_size = GNUNET_HELLO_size(* (plugin->env->our_hello));
706 //welcome.header.size = htons (GNUNET_HELLO_size(* (plugin->env->our_hello)));
707 //welcome.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
708 //welcome.clientIdentity = *plugin->env->my_identity;
709 memcpy ( (pm->msg), * plugin->env->our_hello, GNUNET_HELLO_size(* (plugin->env->our_hello)));
710 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
711 queue->content->pending_message = pm;
712 plugin->pendingsessions ++;
713 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions, plugin->pending_Sessions_tail, queue);
715 check_fragment_queue(plugin);
720 * Queue the session to send data
724 queue_Session(struct Plugin *plugin, struct Session * session)
726 struct Sessionqueue * queue = plugin->pending_Sessions;
727 struct Sessionqueue * lastitem = NULL;
729 while (queue != NULL)
731 // content is never NULL
732 GNUNET_assert (queue->content != NULL);
733 // is session already in queue?
734 if (session == queue->content)
743 // Session is not in the queue
745 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
746 queue->content = session;
749 GNUNET_CONTAINER_DLL_insert_after (plugin->pending_Sessions,
750 plugin->pending_Sessions_tail,
751 plugin->pending_Sessions_tail, queue);
752 plugin->pendingsessions++;
758 free_acks(struct FragmentMessage * fm)
760 struct AckQueue * fq;
761 while (fm->head != NULL)
764 GNUNET_CONTAINER_DLL_remove(fm->head, fm->tail, fq);
774 * Function to schedule the write task, executed after a delay
777 delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
779 struct Plugin * plugin = cls;
780 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
782 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
785 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
786 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
788 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
789 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
790 &do_transmit, plugin);
796 * Function to calculate the time of the next periodic "hello-beacon"
799 set_next_beacon_time(struct Plugin * const plugin)
801 //under 10 known peers: once a second
802 if (plugin->session_count < 10)
804 plugin->beacon_time = GNUNET_TIME_absolute_add(
805 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
806 GNUNET_TIME_UNIT_SECONDS, HALLO_BEACON_SCALING_FACTOR));
808 //under 30 known peers: every 10 seconds
809 else if (plugin->session_count < 30)
811 plugin->beacon_time = GNUNET_TIME_absolute_add(
812 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
813 GNUNET_TIME_UNIT_SECONDS, 10 * HALLO_BEACON_SCALING_FACTOR));
815 //over 30 known peers: once a minute
818 plugin->beacon_time = GNUNET_TIME_absolute_add(
819 GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(
820 GNUNET_TIME_UNIT_MINUTES, HALLO_BEACON_SCALING_FACTOR));
825 struct GNUNET_TIME_Relative
826 get_next_frag_timeout(struct FragmentMessage * fm)
828 return GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(
829 fm->next_ack), GNUNET_TIME_absolute_get_remaining(fm->timeout));
834 * Function to get the timeout value for acks for this session
837 struct GNUNET_TIME_Relative
838 get_ack_timeout(struct FragmentMessage * fm)
840 return FRAGMENT_TIMEOUT;
844 * Function to set the timer for the next timeout of the fragment queue
845 * @param plugin the handle to the plugin struct
848 check_next_fragment_timeout(struct Plugin * const plugin)
850 struct FragmentMessage * fm;
851 struct GNUNET_TIME_Relative next_send;
853 next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time);
856 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
858 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task);
859 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
861 fm = plugin->pending_Fragment_Messages_head;
863 GNUNET_assert(plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK);
865 //check if some acks are in the queue
866 if (plugin->ack_send_queue_head != NULL)
868 next_send = GNUNET_TIME_relative_get_zero();
870 //check if there are some fragments in the queue
874 = GNUNET_TIME_relative_min(next_send, get_next_frag_timeout(fm));
876 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send,
877 &delay_fragment_task, plugin);
882 * Function to get the next queued Session, removes the session from the queue
885 static struct Session *
886 get_next_queue_Session(struct Plugin * plugin)
888 struct Session * session;
889 struct Sessionqueue * sessionqueue;
890 struct Sessionqueue * sessionqueue_alt;
891 struct PendingMessage * pm;
892 sessionqueue = plugin->pending_Sessions;
893 while (sessionqueue != NULL)
895 session = sessionqueue->content;
896 pm = session->pending_message;
898 //check for message timeout
899 if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0)
901 //check if session has no message in the fragment queue
902 if (!session->has_fragment)
904 plugin->pendingsessions--;
905 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
906 plugin->pending_Sessions_tail, sessionqueue);
907 GNUNET_free(sessionqueue);
913 sessionqueue = sessionqueue->next;
919 session->pending_message = NULL;
920 //call the cont func that it did not work
921 if (pm->transmit_cont != NULL)
922 pm->transmit_cont(pm->transmit_cont_cls, &(session->target),
924 GNUNET_free(pm->msg);
927 sessionqueue_alt = sessionqueue;
928 sessionqueue = sessionqueue->next;
929 plugin->pendingsessions--;
930 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
931 plugin->pending_Sessions_tail, sessionqueue_alt);
933 GNUNET_free(sessionqueue_alt);
942 * Function to sort the message into the message fragment queue
943 * @param plugin the plugin struct
944 * @param fm message to sort into the queue
947 sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm)
949 struct FragmentMessage * fm2;
950 //sort into the list at the right position
952 fm2 = plugin->pending_Fragment_Messages_head;
956 if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, fm->next_ack).rel_value
967 GNUNET_CONTAINER_DLL_insert_after(plugin->pending_Fragment_Messages_head,
968 plugin->pending_Fragment_Messages_tail,fm2,fm);
972 * frees the space of a message in the fragment queue (send queue)
973 * @param plugin the plugin struct
974 * @param fm message to free
977 free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
982 GNUNET_free_non_null(fm->msg);
983 GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head,
984 plugin->pending_Fragment_Messages_tail, fm);
986 plugin->pending_fragment_messages--;
987 check_fragment_queue(plugin);
990 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Pending fragment messages: %u\n", plugin->pending_fragment_messages);
996 * Function to check if there is some space in the fragment queue
997 * inserts a message if space is available
998 * @param plugin the plugin struct
1002 check_fragment_queue(struct Plugin * plugin)
1004 struct Session * session;
1005 struct FragmentMessage * fm;
1006 struct GNUNET_PeerIdentity pid;
1008 struct PendingMessage * pm;
1010 if (plugin->pending_fragment_messages < FRAGMENT_QUEUE_SIZE)
1012 session = get_next_queue_Session(plugin);
1013 if (session != NULL)
1015 pm = session->pending_message;
1016 session->pending_message = NULL;
1017 session->has_fragment = 1;
1018 GNUNET_assert(pm != NULL);
1020 fm = GNUNET_malloc(sizeof(struct FragmentMessage));
1021 fm->message_size = pm->message_size;
1023 fm->session = session;
1024 fm->timeout.abs_value = pm->timeout.abs_value;
1025 fm->message_pos = 0;
1026 fm->next_ack = GNUNET_TIME_absolute_get();
1028 if (pm->transmit_cont != NULL) {
1029 pid = session->target;
1030 pm->transmit_cont(pm->transmit_cont_cls, &pid,
1033 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "called pm->transmit_cont\n");
1039 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "no pm->transmit_cont\n");
1044 sort_fragment_into_queue(plugin, fm);
1045 plugin->pending_fragment_messages++;
1047 //generate new message id
1048 session->message_id_out = get_next_message_id();
1050 //check if timeout changed
1051 check_next_fragment_timeout(plugin);
1057 * Funktion to check if all fragments where send and the acks received
1058 * frees the space if finished
1059 * @param plugin the plugin struct
1060 * @param fm the message to check
1063 check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
1065 struct AckQueue * ack;
1068 if (fm->message_size >= (WLAN_MTU - sizeof(struct FragmentationHeader))
1069 * fm->tail->fragment_num)
1073 //check if all acks are present
1076 if (counter == ack->fragment_num)
1087 fm->session->has_fragment = 0;
1088 free_fragment_message(plugin, fm);
1091 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished a fragmented message\n");
1095 check_next_fragment_timeout(plugin);
1101 * Function to set the next fragment number
1102 * @param fm use this FragmentMessage
1106 set_next_message_fragment_pos(struct FragmentMessage * fm)
1108 struct AckQueue * akt = NULL;
1109 //check if retransmit is needed
1110 if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0)
1113 // be positive and try again later :-D
1114 fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(fm));
1115 // find first missing fragment
1117 fm->message_pos = 0;
1121 //test if ack 0 (or X) was already received
1124 //if fragment is present, take next
1125 if (akt->fragment_num == fm->message_pos)
1129 //next ack is bigger then the fragment number
1130 //in case there is something like this: (acks) 1, 2, 5, 6, ...
1131 //and we send 3 again, the next number should be 4
1132 else if (akt->fragment_num > fm->message_pos)
1144 send_hello_beacon(struct Plugin * plugin)
1148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello beacon\n");
1153 struct GNUNET_MessageHeader * msgheader = NULL;
1154 struct IeeeHeader * ieeewlanheader = NULL;
1155 struct RadiotapHeader * radioHeader = NULL;
1156 struct GNUNET_MessageHeader * msgheader2 = NULL;
1158 GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size(
1159 *(plugin->env->our_hello)) <= WLAN_MTU);
1160 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader)
1161 + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader)
1162 + GNUNET_HELLO_size(*(plugin->env->our_hello));
1164 msgheader = GNUNET_malloc(size);
1165 msgheader->size = htons(size);
1166 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1168 radioHeader = (struct RadiotapHeader*) &msgheader[1];
1169 getRadiotapHeader(radioHeader);
1170 ieeewlanheader = (struct IeeeHeader*) &radioHeader[1];
1171 getWlanHeader(ieeewlanheader, bc_all_mac, plugin);
1173 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
1174 msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello))
1175 + sizeof(struct GNUNET_MessageHeader));
1177 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
1178 memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size(
1179 *(plugin->env->our_hello)));
1181 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
1183 if (bytes == GNUNET_SYSERR)
1185 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1186 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1187 errno, strerror(errno));
1190 GNUNET_assert(bytes != GNUNET_SYSERR);
1191 GNUNET_assert(bytes == size);
1192 GNUNET_free(msgheader);
1194 set_next_beacon_time(plugin);
1195 check_next_fragment_timeout(plugin);
1199 send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1204 struct GNUNET_MessageHeader * msgheader = NULL;
1205 struct IeeeHeader * ieeewlanheader = NULL;
1206 struct RadiotapHeader * radioHeader = NULL;
1207 struct FragmentationHeader * msgheader2 = NULL;
1209 GNUNET_assert(sizeof(struct FragmentationHeader) <= WLAN_MTU);
1212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1213 "Sending ack for message_id %u with fragment number %u\n",
1214 ack->message_id, ack->fragment_off_or_num);
1217 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader)
1218 + sizeof(struct IeeeHeader) + sizeof(struct FragmentationHeader);
1219 msgheader = GNUNET_malloc(size);
1220 msgheader->size = htons(size);
1221 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1223 radioHeader = (struct RadiotapHeader*) &msgheader[1];
1224 getRadiotapHeader(radioHeader);
1225 ieeewlanheader = (struct IeeeHeader*) &radioHeader[1];
1226 getWlanHeader(ieeewlanheader, ack->session->addr, plugin);
1228 msgheader2 = (struct FragmentationHeader*) &ieeewlanheader[1];
1229 msgheader2->header.size = htons(sizeof(struct FragmentationHeader));
1230 msgheader2->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK);
1231 msgheader2->message_id = htonl(ack->message_id);
1232 msgheader2->fragment_off_or_num = htons(ack->fragment_off_or_num);
1234 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
1235 if (bytes == GNUNET_SYSERR)
1237 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1238 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1239 errno, strerror(errno));
1242 GNUNET_assert(bytes != GNUNET_SYSERR);
1243 GNUNET_assert(bytes == size);
1244 GNUNET_free(msgheader);
1245 check_next_fragment_timeout(plugin);
1249 * Function called when wlan helper is ready to get some data
1251 * @param cls closure
1252 * @param tc GNUNET_SCHEDULER_TaskContext
1256 do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1259 struct Plugin * plugin = cls;
1260 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1262 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1265 struct Session * session = NULL;
1266 struct FragmentMessage * fm = NULL;
1267 struct IeeeHeader * ieeewlanheader = NULL;
1268 struct RadiotapHeader * radioHeader = NULL;
1269 struct GNUNET_MessageHeader * msgheader = NULL;
1271 struct FragmentationHeader fragheader;
1272 struct FragmentationHeader * fragheaderptr = NULL;
1273 struct Finish_send * finish = NULL;
1274 struct AckSendQueue * ack;
1277 const char * copystart = NULL;
1278 uint16_t copysize = 0;
1279 uint copyoffset = 0;
1281 if (plugin->ack_send_queue_head != NULL)
1283 ack = plugin->ack_send_queue_head;
1284 GNUNET_CONTAINER_DLL_remove(plugin->ack_send_queue_head,
1285 plugin->ack_send_queue_tail, ack);
1286 send_ack(plugin, ack);
1291 //test if a "hello-beacon" has to be send
1292 if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0)
1294 send_hello_beacon(plugin);
1300 fm = plugin->pending_Fragment_Messages_head;
1303 session = fm->session;
1304 GNUNET_assert(session != NULL);
1306 // test if message timed out
1307 if (GNUNET_TIME_absolute_get_remaining(fm->timeout).rel_value == 0)
1310 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n");
1313 GNUNET_assert(plugin->pending_fragment_messages > 0);
1314 plugin->pending_fragment_messages--;
1315 GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head,
1316 plugin->pending_Fragment_Messages_tail, fm);
1318 GNUNET_free(fm->msg);
1321 check_fragment_queue(plugin);
1326 //if (fm->message_size > WLAN_MTU)
1328 size += sizeof(struct FragmentationHeader);
1330 set_next_message_fragment_pos(fm);
1332 copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader))
1334 fragheader.fragment_off_or_num = htons(fm->message_pos);
1335 fragheader.message_id = htonl(session->message_id_out);
1336 GNUNET_assert(copyoffset < fm->message_size);
1337 copystart = fm->msg + copyoffset;
1338 copysize = GNUNET_MIN(fm->message_size - copyoffset,
1339 WLAN_MTU - sizeof(struct FragmentationHeader));
1340 fragheader.header.size = htons(copysize
1341 + sizeof(struct FragmentationHeader));
1342 fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
1347 // there is no need to split
1348 copystart = fm->msg;
1349 copysize = fm->message_size;
1354 GNUNET_ERROR_TYPE_DEBUG,
1355 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, time until timeout %u\n",
1356 session->message_id_out, fm->message_pos, copysize
1357 + sizeof(struct FragmentationHeader),
1358 GNUNET_TIME_absolute_get_remaining(fm->timeout));
1362 size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader)
1363 + sizeof(struct GNUNET_MessageHeader);
1364 msgheader = GNUNET_malloc(size);
1365 msgheader->size = htons(size);
1366 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1368 radioHeader = (struct RadiotapHeader*) &msgheader[1];
1369 getRadiotapHeader(radioHeader);
1371 ieeewlanheader = (struct IeeeHeader *) &radioHeader[1];
1372 getWlanHeader(ieeewlanheader, fm->session->addr, plugin);
1374 //could be faster if content is just send and not copyed before
1375 //fragmentheader is needed
1376 //if (fm->message_size > WLAN_MTU)
1378 fragheader.message_crc = htons(getcrc16(copystart, copysize));
1379 memcpy(&ieeewlanheader[1], &fragheader,
1380 sizeof(struct FragmentationHeader));
1381 fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1];
1382 memcpy(&fragheaderptr[1], copystart, copysize);
1386 memcpy(&ieeewlanheader[1], copystart, copysize);
1389 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
1391 if (bytes == GNUNET_SYSERR)
1394 GNUNET_ERROR_TYPE_ERROR,
1395 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1396 errno, strerror(errno));
1399 GNUNET_assert(bytes != GNUNET_SYSERR);
1403 finish = GNUNET_malloc(sizeof( struct Finish_send));
1404 finish->plugin = plugin;
1405 finish->msgheader = (char *) msgheader + bytes;
1406 finish->size = size - bytes;
1407 finish->msgstart = msgheader;
1409 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1411 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
1412 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
1413 &finish_sending, finish);
1418 GNUNET_assert(bytes == size);
1420 GNUNET_free(msgheader);
1421 check_next_fragment_timeout(plugin);
1424 //check if this was the last fragment of this message, if true then queue at the end of the list
1425 if (copysize + copyoffset >= fm->message_size)
1427 GNUNET_assert(copysize + copyoffset == fm->message_size);
1429 GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head,
1430 plugin->pending_Fragment_Messages_tail, fm);
1432 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head,
1433 plugin->pending_Fragment_Messages_tail, fm);
1434 // if fragments have opimized timeouts
1435 //sort_fragment_into_queue(plugin,fm);
1442 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1443 "do_transmit did nothing, should not happen!\n");
1447 finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1449 struct Finish_send * finish;
1450 struct Plugin * plugin;
1454 plugin = finish->plugin;
1456 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1458 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
1459 finish->msgheader, finish->size);
1460 GNUNET_assert(bytes != GNUNET_SYSERR);
1462 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1463 if (bytes != finish->size)
1466 finish->plugin = plugin;
1467 finish->msgheader = finish->msgheader + bytes;
1468 finish->size = finish->size - bytes;
1469 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
1470 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
1471 &finish_sending, finish);
1475 GNUNET_free(finish->msgstart);
1476 GNUNET_free(finish);
1477 check_next_fragment_timeout(plugin);
1483 getRadiotapHeader(struct RadiotapHeader * Header)
1490 * function to generate the wlan hardware header for one packet
1491 * @param Header address to write the header to
1492 * @param to_mac_addr address of the recipient
1493 * @param plugin pointer to the plugin struct
1494 * @return GNUNET_YES if there was no error
1498 getWlanHeader(struct IeeeHeader * Header,const char * const to_mac_addr,
1499 struct Plugin * plugin)
1501 memcpy(&Header->mac2, macbc, sizeof(macbc));
1502 memcpy(&Header->mac3, plugin->mac_address.mac, sizeof(plugin->mac_address));
1503 memcpy(&Header->mac1, to_mac_addr, sizeof(plugin->mac_address));
1510 * @param msgbuf pointer tor the data
1511 * @param msgbuf_size size of the data
1513 * @return 32bit crc value
1517 getcrc32(const char *msgbuf, size_t msgbuf_size)
1519 //TODO calc some crc
1526 * @param msgbuf pointer tor the data
1527 * @param msgbuf_size size of the data
1529 * @return 16bit crc value
1533 getcrc16(const char *msgbuf, size_t msgbuf_size)
1535 //TODO calc some crc
1540 * Function that can be used by the transport service to transmit
1541 * a message using the plugin.
1543 * @param cls closure
1544 * @param target who should receive this message
1545 * @param priority how important is the message
1546 * @param msgbuf the message to transmit
1547 * @param msgbuf_size number of bytes in 'msgbuf'
1548 * @param timeout when should we time out
1549 * @param session which session must be used (or NULL for "any")
1550 * @param addr the address to use (can be NULL if the plugin
1551 * is "on its own" (i.e. re-use existing TCP connection))
1552 * @param addrlen length of the address in bytes
1553 * @param force_address GNUNET_YES if the plugin MUST use the given address,
1554 * otherwise the plugin may use other addresses or
1555 * existing connections (if available)
1556 * @param cont continuation to call once the message has
1557 * been transmitted (or if the transport is ready
1558 * for the next transmission call; or if the
1559 * peer disconnected...)
1560 * @param cont_cls closure for cont
1561 * @return number of bytes used (on the physical network, with overheads);
1562 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1563 * and does NOT mean that the message was not transmitted (DV)
1566 wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1567 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
1568 struct GNUNET_TIME_Relative timeout, struct Session *session,
1569 const void *addr, size_t addrlen, int force_address,
1570 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1572 struct Plugin * plugin = cls;
1573 struct PendingMessage * newmsg = NULL;
1574 struct WlanHeader * wlanheader = NULL;
1575 struct GNUNET_MessageHeader * innermsg =
1576 (struct GNUNET_MessageHeader *) msgbuf;
1578 //check if msglen > 0
1579 GNUNET_assert(msgbuf_size > 0);
1581 //get session if needed
1582 if (session == NULL)
1584 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK)
1586 session = get_Session(plugin, addr);
1590 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1591 _("Wlan Address len %d is wrong\n"), addrlen);
1598 GNUNET_ERROR_TYPE_DEBUG,
1599 "wlan_plugin_send got %u bytes data, packet says it has %u bytes for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
1600 msgbuf_size, ntohs(innermsg->size), session->addr[0], session->addr[1],
1601 session->addr[2], session->addr[3], session->addr[4], session->addr[5]);
1604 //TODO target "problem" not solved
1605 session->target = *target;
1608 //first queue session
1609 queue_Session(plugin, session);
1611 //queue message in session
1612 //test if there is no other message in the "queue"
1613 //FIXME: to many send requests
1614 //GNUNET_assert (session->pending_message == NULL);
1615 if (session->pending_message != NULL)
1617 newmsg = session->pending_message;
1619 GNUNET_ERROR_TYPE_ERROR,
1620 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u\n",
1621 GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value);
1625 newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
1626 (newmsg->msg) = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader));
1627 wlanheader = (struct WlanHeader *) newmsg->msg;
1628 //copy msg to buffer, not fragmented / segmented yet, but with message header
1629 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
1630 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
1631 memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity));
1632 wlanheader->crc = htonl(getcrc32(msgbuf, msgbuf_size));
1633 memcpy(&wlanheader[1], msgbuf, msgbuf_size);
1634 newmsg->transmit_cont = cont;
1635 newmsg->transmit_cont_cls = cont_cls;
1636 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
1638 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
1640 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader);
1642 session->pending_message = newmsg;
1644 check_fragment_queue(plugin);
1645 //FIXME not the correct size
1651 static struct FragmentMessage *
1652 get_fragment_message_from_session(struct Session * session)
1654 struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head;
1657 if (fm->session == session)
1667 * Function that can be used to force the plugin to disconnect
1668 * from the given peer and cancel all previous transmissions
1669 * (and their continuation).
1671 * @param cls closure
1672 * @param target peer from which to disconnect
1675 wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
1677 struct Plugin *plugin = cls;
1678 struct Sessionqueue * queue = plugin->sessions;
1679 struct Sessionqueue * pendingsession = plugin->pending_Sessions;
1680 struct PendingMessage * pm = NULL;
1681 struct FragmentMessage * fm;
1683 // just look at all the session for the needed one
1684 while (queue != NULL)
1686 // content is never NULL
1687 GNUNET_assert (queue->content != NULL);
1688 if (memcmp(target, &(queue->content->target),
1689 sizeof(struct GNUNET_PeerIdentity)) == 0)
1692 //is this session pending for send
1693 while (pendingsession != NULL)
1695 if (pendingsession->content == queue->content)
1697 plugin->pendingsessions--;
1698 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
1699 plugin->pending_Sessions_tail, pendingsession);
1700 GNUNET_free(pendingsession);
1703 pendingsession = pendingsession->next;
1706 //is something of this session in the fragment queue?
1707 fm = get_fragment_message_from_session(queue->content);
1708 free_fragment_message(plugin, fm);
1710 //dispose all received fragments
1711 free_rec_frag_queue(queue->content);
1713 // remove PendingMessage
1714 pm = queue->content->pending_message;
1717 GNUNET_free_non_null(pm->msg);
1721 GNUNET_free(queue->content);
1722 GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue);
1724 plugin->session_count--;
1729 queue = queue->next;
1734 * Convert the transports address to a nice, human-readable
1737 * @param cls closure
1738 * @param type name of the transport that generated the address
1739 * @param addr one of the addresses of the host, NULL for the last address
1740 * the specific address format depends on the transport
1741 * @param addrlen length of the address
1742 * @param numeric should (IP) addresses be displayed in numeric form?
1743 * @param timeout after how long should we give up?
1744 * @param asc function to call on each string
1745 * @param asc_cls closure for asc
1748 wlan_plugin_address_pretty_printer(void *cls, const char *type,
1749 const void *addr, size_t addrlen, int numeric,
1750 struct GNUNET_TIME_Relative timeout,
1751 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
1754 const unsigned char * input;
1756 GNUNET_assert(cls !=NULL);
1759 /* invalid address (MAC addresses have 6 bytes) */
1764 input = (const unsigned char*) addr;
1765 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Adress %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
1766 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4],
1772 * Another peer has suggested an address for this
1773 * peer and transport plugin. Check that this could be a valid
1774 * address. If so, consider adding it to the list
1777 * @param cls closure
1778 * @param addr pointer to the address
1779 * @param addrlen length of addr
1780 * @return GNUNET_OK if this is a plausible address for this peer
1785 wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
1787 //struct Plugin *plugin = cls;
1789 /* check if the address is plausible; if so,
1790 add it to our list! */
1792 GNUNET_assert(cls !=NULL);
1793 //FIXME mitm is not checked
1794 //Mac Adress has 6 bytes
1797 /* TODO check for bad addresses like multicast, broadcast, etc */
1802 return GNUNET_SYSERR;
1805 return GNUNET_SYSERR;
1809 * Function called for a quick conversion of the binary address to
1810 * a numeric address. Note that the caller must not free the
1811 * address and that the next call to this function is allowed
1812 * to override the address again.
1814 * @param cls closure
1815 * @param addr binary address
1816 * @param addrlen length of the address
1817 * @return string representing the same address
1820 wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
1822 static char ret[40];
1823 const unsigned char * input;
1825 GNUNET_assert(cls !=NULL);
1828 /* invalid address (MAC addresses have 6 bytes) */
1832 input = (const unsigned char*) addr;
1833 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Adress %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
1834 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4],
1840 * Function to test if fragment number already exists in the fragments received
1842 * @param session session the fragment belongs to
1843 * @param fh Fragmentheader of the fragment
1844 * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session
1848 is_double_msg(struct Session * session, struct FragmentationHeader * fh)
1850 struct RecQueue * rec_queue = session->frag_head;
1851 while (rec_queue != NULL)
1853 if (rec_queue->num == fh->fragment_off_or_num)
1857 rec_queue = rec_queue->next;
1864 * Function to insert a fragment in a queue of a session
1865 * @param session session the fragment belongs to
1866 * @param rec_queue fragment to add
1870 insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue)
1872 struct RecQueue * rec_queue2 = session->frag_head;
1873 struct WlanHeader * wlanheader = NULL;
1874 //first received fragment of message
1875 if (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED)
1877 session->rec_size = MESSAGE_LENGHT_UNKNOWN;
1879 //this is the first fragment of the message (fragment id 0)
1880 if (rec_queue->num == 0)
1882 wlanheader = (struct WlanHeader *) rec_queue->msg;
1883 session->rec_size = ntohs(wlanheader->header.size);
1887 while (rec_queue2 != NULL)
1889 if (rec_queue2->num > rec_queue->num)
1891 //next element number is grater than the current num
1892 GNUNET_CONTAINER_DLL_insert_before(session->frag_head, session->frag_tail, rec_queue2, rec_queue);
1895 rec_queue = rec_queue->next;
1897 //no element has a grater number
1898 GNUNET_CONTAINER_DLL_insert_tail(session->frag_head, session->frag_tail, rec_queue);
1902 * Function to dispose the fragments received for a message
1903 * @param session session to free the fragments from
1907 free_rec_frag_queue(struct Session * session)
1909 struct RecQueue * rec_queue = session->frag_head;
1910 struct RecQueue * rec_queue2;
1911 while (rec_queue != NULL)
1913 rec_queue2 = rec_queue;
1914 rec_queue = rec_queue->next;
1915 GNUNET_free(rec_queue2);
1917 session->frag_head = NULL;
1918 session->frag_tail = NULL;
1919 session->rec_size = NO_MESSAGE_OR_MESSAGE_FINISHED;
1923 * Function to check if all fragments of a message have been received
1924 * @param plugin the plugin handle
1925 * @param session_light information of the message sender
1926 * @param session session the message belongs to
1930 check_rec_finished_msg(struct Plugin* plugin,
1931 struct Session_light * session_light, struct Session * session)
1933 struct RecQueue * rec_queue = session->frag_head;
1934 int packetsize = session->rec_size;
1938 //some fragment should be received
1939 GNUNET_assert(session->rec_size != NO_MESSAGE_OR_MESSAGE_FINISHED);
1940 //check if first fragment is present
1941 if (session->rec_size == MESSAGE_LENGHT_UNKNOWN)
1945 while (rec_queue != NULL)
1947 sum += rec_queue->size;
1948 //check if all fragment numbers are present
1949 if (rec_queue->num != aktnum)
1954 rec_queue = rec_queue->next;
1956 //sum should always be smaller or equal of
1957 GNUNET_assert(sum <= packetsize);
1958 if (sum == packetsize)
1962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1963 "check_rec_finished_msg: A message with fragments is complete\n");
1966 //copy fragments together
1967 msg = GNUNET_malloc(packetsize);
1968 rec_queue = session->frag_head;
1970 while (rec_queue != NULL)
1972 memcpy(msg + aktnum, rec_queue->msg, rec_queue->size);
1973 aktnum += rec_queue->size;
1974 rec_queue = rec_queue->next;
1976 free_rec_frag_queue(session);
1977 //call wlan_process_helper to process the message
1978 wlan_data_massage_handler(plugin, session_light,
1979 (struct GNUNET_MessageHeader*) msg);
1980 //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
1987 wlan_data_massage_handler(struct Plugin * plugin,
1988 struct Session_light * session_light,
1989 const struct GNUNET_MessageHeader * hdr)
1991 struct WlanHeader * wlanheader = NULL;
1992 struct Session * session = NULL;
1993 const char * tempmsg = NULL;
1994 const struct GNUNET_MessageHeader * temp_hdr = NULL;
1995 struct GNUNET_PeerIdentity tmptarget;
1997 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2002 GNUNET_ERROR_TYPE_DEBUG,
2003 "Func wlan_data_massage_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2007 GNUNET_assert(session_light != NULL);
2008 if (session_light->session == NULL)
2010 session_light->session = search_session(plugin, session_light->addr);
2012 session = session_light->session;
2013 wlanheader = (struct WlanHeader *) hdr;
2014 tempmsg = (char*) &wlanheader[1];
2015 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2017 if (getcrc32(tempmsg, ntohs(wlanheader->header.size)) != ntohl(
2020 //wrong crc, dispose message
2021 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2022 "Wlan message Header crc was wrong\n");
2026 //if not in session list
2027 if (session == NULL)
2031 GNUNET_ERROR_TYPE_DEBUG,
2032 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2033 ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
2034 sizeof(struct WlanHeader));
2036 //try if it is a hello message
2037 if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size)
2038 + sizeof(struct WlanHeader))
2040 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2042 if (GNUNET_HELLO_get_id(
2043 (const struct GNUNET_HELLO_Message *) temp_hdr,
2044 &tmptarget) == GNUNET_OK)
2046 session = create_session(plugin, session_light->addr);
2047 session_light->session = session;
2048 memcpy(&session->target, &tmptarget,
2049 sizeof(struct GNUNET_PeerIdentity));
2053 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2054 "WLAN client not in session list and hello message not okay\n");
2061 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2062 "WLAN client not in session list and not a hello message\n");
2069 GNUNET_ERROR_TYPE_WARNING,
2070 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2071 ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
2072 sizeof(struct WlanHeader));
2077 //"receive" the message
2078 struct GNUNET_TRANSPORT_ATS_Information distance[2];
2079 distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2080 distance[0].value = htonl(1);
2081 distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2082 distance[1].value = htonl(0);
2086 GNUNET_ERROR_TYPE_DEBUG,
2087 "Calling plugin->env->receive\n");
2089 plugin->env->receive(plugin->env->cls, &(session->target), temp_hdr,
2090 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
2091 session, session->addr, sizeof(session->addr));
2096 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2097 "wlan_data_massage_handler got wrong message type\n");
2103 * function to add an ack to send it for a received fragment
2104 * @param plugin pointer to the global plugin structure
2105 * @param session pointer to the session this ack belongs to
2106 * @param fh pointer to the fragmentation header which we would like to acknolage
2110 add_ack_for_send(struct Plugin * plugin, struct Session * session,
2111 struct FragmentationHeader * fh)
2113 struct AckSendQueue * ack;
2115 GNUNET_assert(plugin != NULL);
2116 GNUNET_assert(session != NULL);
2117 GNUNET_assert(fh != NULL);
2119 ack = GNUNET_malloc(sizeof(struct AckSendQueue));
2120 ack->fragment_off_or_num = ntohs(fh->fragment_off_or_num);
2121 ack->message_id = ntohl(fh->message_id);
2122 ack->session = session;
2124 GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head,
2125 plugin->ack_send_queue_tail, ack);
2130 * Function used for to process the data received from the wlan interface
2132 * @param cls the plugin handle
2133 * @param client client which send the data (not used)
2134 * @param hdr hdr of the GNUNET_MessageHeader
2137 wlan_data_helper(void *cls, struct Session_light * session_light,
2138 const struct GNUNET_MessageHeader * hdr)
2140 struct Plugin *plugin = cls;
2141 struct Session * session = NULL;
2143 struct FragmentationHeader * fh = NULL;
2144 struct FragmentMessage * fm = NULL;
2146 const char * tempmsg = NULL;
2148 struct AckQueue * ack = NULL;
2149 struct AckQueue * ack2 = NULL;
2151 struct RecQueue * rec_queue = NULL;
2153 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
2157 GNUNET_ERROR_TYPE_DEBUG,
2158 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u\n",
2162 //TODO better DOS protection, error handling
2163 GNUNET_assert(session_light != NULL);
2164 if (session_light->session == NULL)
2166 session_light->session = get_Session(plugin, session_light->addr);
2168 GNUNET_assert(GNUNET_HELLO_get_id(
2169 (const struct GNUNET_HELLO_Message *) &hdr[1],
2170 &(session_light->session->target) ) != GNUNET_SYSERR);
2175 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
2178 GNUNET_assert(session_light != NULL);
2179 if (session_light->session == NULL)
2181 session_light->session = search_session(plugin, session_light->addr);
2183 session = session_light->session;
2185 fh = (struct FragmentationHeader *) hdr;
2186 tempmsg = (char*) &fh[1];
2190 GNUNET_ERROR_TYPE_DEBUG,
2191 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u\n",
2192 ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs(
2196 if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc))
2198 //wrong crc, dispose message
2199 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN fragment crc was wrong\n");
2203 //if in the session list
2204 if (session != NULL)
2206 //TODO fragments do not timeout
2207 //check if message_id is right or it is a new msg
2208 if ((session->message_id_in == ntohs(fh->message_id))
2209 || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
2211 session->message_id_in = ntohs(fh->message_id);
2212 if (is_double_msg(session, fh) != GNUNET_YES)
2215 //TODO ask if it is right like this
2216 if (plugin->env->traffic_report != NULL)
2218 plugin->env->traffic_report(plugin->env->cls,
2219 &session->target, ntohs(fh->header.size));
2222 = GNUNET_malloc(sizeof (struct RecQueue) +
2223 ntohs(fh->header.size) - sizeof(struct FragmentationHeader));
2224 rec_queue->size = ntohs(fh->header.size)
2225 - sizeof(struct FragmentationHeader);
2226 rec_queue->num = ntohs(fh->fragment_off_or_num);
2227 rec_queue->msg = (char*) &rec_queue[1];
2228 //copy msg to buffer
2229 memcpy((char *) rec_queue->msg, tempmsg, rec_queue->size);
2230 insert_fragment_in_queue(session, rec_queue);
2231 check_rec_finished_msg(plugin, session_light, session);
2235 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2236 "WLAN fragment is a clone\n");
2243 GNUNET_ERROR_TYPE_INFO,
2244 "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n");
2250 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2251 "WLAN client not in session list and it is a fragment message\n");
2252 wlan_data_massage_handler(plugin, session_light,
2253 (struct GNUNET_MessageHeader *) tempmsg);
2254 session = session_light->session;
2255 //test if a session was created
2256 if (session == NULL)
2262 //TODO make and send ack
2263 add_ack_for_send(plugin, session, fh);
2264 check_next_fragment_timeout(plugin);
2269 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
2274 GNUNET_ERROR_TYPE_DEBUG,
2275 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u\n",
2279 GNUNET_assert(session_light != NULL);
2280 if (session_light->session == NULL)
2282 session_light->session = search_session(plugin, session_light->addr);
2283 GNUNET_assert(session_light->session != NULL);
2285 session = session_light->session;
2286 fh = (struct FragmentationHeader *) hdr;
2287 if (session->message_id_out == ntohl(fh->message_id))
2289 fm = get_fragment_message_from_session(session);
2294 while (ack2 != NULL)
2297 if (ack2->fragment_num != ntohs(fh->fragment_off_or_num))
2299 // check if next ack has bigger number
2300 if (ack2->fragment_num > ntohs(fh->fragment_off_or_num))
2302 ack = GNUNET_malloc(sizeof(struct AckQueue));
2303 ack->fragment_num = ntohs(fh->fragment_off_or_num);
2304 GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack);
2306 check_finished_fragment(plugin, fm);
2315 GNUNET_ERROR_TYPE_DEBUG,
2316 "WLAN got double ack for message id %u and fragment num %u\n",
2317 session->message_id_out, ack2->fragment_num);
2324 //all acks are have smaller numbers
2325 ack = GNUNET_malloc(sizeof(struct AckQueue));
2326 ack->fragment_num = ntohs(fh->fragment_off_or_num);
2327 GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
2328 check_finished_fragment(plugin, fm);
2333 GNUNET_ERROR_TYPE_WARNING,
2334 "WLAN fragment not in fragment list but id %u of ack is right\n",
2335 ntohl(fh->message_id));
2344 GNUNET_ERROR_TYPE_DEBUG,
2345 _("WLAN got ack but session->message_id_out %u and fragment id %u mismatch\n"),
2346 session->message_id_out, ntohl(fh->message_id));
2354 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2355 "WLAN packet inside the WLAN helper packet has not the right type\n");
2360 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2361 "Helper finished\n");
2367 * Function used for to process the data from the suid process
2369 * @param cls the plugin handle
2370 * @param client which send the data (not used)
2371 * @param hdr of the GNUNET_MessageHeader
2375 wlan_process_helper(void *cls, void *client,
2376 const struct GNUNET_MessageHeader *hdr)
2378 struct Plugin *plugin = cls;
2379 struct IeeeHeader * wlanIeeeHeader = NULL;
2380 struct Session_light * session_light = NULL;
2381 const struct GNUNET_MessageHeader * temp_hdr = NULL;
2386 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA)
2390 GNUNET_ERROR_TYPE_DEBUG,
2391 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
2395 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2396 GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader));
2397 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1];
2398 datasize = ntohs(hdr->size) - sizeof(struct IeeeHeader)
2399 - sizeof(struct GNUNET_MessageHeader);
2401 session_light = GNUNET_malloc(sizeof(struct Session_light));
2402 memcpy(session_light->addr, &(wlanIeeeHeader->mac3),
2403 sizeof(struct MacAddress));
2404 session_light->session = search_session(plugin, session_light->addr);
2406 //process only if it is an broadcast or for this computer both with the gnunet bssid
2409 if (memcmp(&(wlanIeeeHeader->mac2), macbc, sizeof(struct MacAddress))
2412 //check for broadcast or mac
2413 if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac,
2414 sizeof(struct MacAddress) == 0) || memcmp(
2415 &(wlanIeeeHeader->mac1), &(plugin->mac_address),
2416 sizeof(struct MacAddress)) == 0)
2418 // process the inner data
2420 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1];
2421 while (pos < datasize)
2423 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]
2426 wlan_data_helper(plugin, session_light, temp_hdr);
2427 pos += ntohs(temp_hdr->size);
2434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2435 "Func wlan_process_helper got wrong MAC: %s\n",
2436 wlanIeeeHeader->mac1);
2443 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2444 "Func wlan_process_helper got wrong BSSID: %s\n",
2445 wlanIeeeHeader->mac2);
2450 GNUNET_free(session_light);
2454 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL)
2459 GNUNET_ERROR_TYPE_DEBUG,
2460 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL size: %u\n",
2464 //TODO more control messages
2465 //TODO use struct wlan_helper_control
2466 if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message))
2468 //plugin->mac_address = GNUNET_malloc(sizeof(struct MacAddress));
2469 memcpy(&(plugin->mac_address), &hdr[1], sizeof(struct MacAddress));
2470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2471 "Notifying transport of address %s\n",
2472 wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs(
2473 hdr->size) - sizeof(struct GNUNET_MessageHeader)));
2474 plugin->env->notify_address(plugin->env->cls, "wlan",
2475 &plugin->mac_address, sizeof(struct MacAddress),
2476 GNUNET_TIME_UNIT_FOREVER_REL);
2480 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n",
2481 plugin->mac_address);
2489 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2490 "WLAN helper packet has not the right type\n");
2496 * We have been notified that wlan-helper has written something to stdout.
2497 * Handle the output, then reschedule this function to be called again once
2498 * more is available.
2500 * @param cls the plugin handle
2501 * @param tc the scheduling context
2505 wlan_plugin_helper_read(void *cls,
2506 const struct GNUNET_SCHEDULER_TaskContext *tc)
2508 struct Plugin *plugin = cls;
2509 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2514 "Start reading from STDIN\n");
2517 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2520 char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)];
2523 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, mybuf,
2528 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2529 _("Finished reading from wlan-helper stdout with code: %d\n"),
2534 GNUNET_SERVER_mst_receive(plugin->consoltoken, NULL, mybuf, bytes, GNUNET_NO,
2537 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2538 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
2539 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
2540 &wlan_plugin_helper_read, plugin);
2544 * Start the gnunet-wlan-helper process.
2546 * @param plugin the transport plugin
2547 * @param testmode should we use the dummy driver for testing?
2548 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
2551 wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2553 const char * filename = "gnunet-transport-wlan-helper";
2554 plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES);
2555 if (plugin->server_stdout == NULL)
2556 return GNUNET_SYSERR;
2558 plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO);
2559 if (plugin->server_stdin == NULL)
2560 return GNUNET_SYSERR;
2563 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2564 "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filename,
2565 plugin->interface, testmode);
2567 /* Start the server process */
2569 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
2570 plugin->server_stdout, filename, filename, plugin->interface, ((testmode
2571 == 1) ? "1" : (testmode == 2) ? "2" : "0"), NULL);
2572 if (plugin->server_proc == NULL)
2575 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2576 "Failed to start gnunet-wlan-helper process\n");
2578 return GNUNET_SYSERR;
2581 /* Close the write end of the read pipe */
2582 GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
2584 /* Close the read end of the write pipe */
2585 GNUNET_DISK_pipe_close_end(plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
2587 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout,
2588 GNUNET_DISK_PIPE_END_READ);
2589 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle(plugin->server_stdin,
2590 GNUNET_DISK_PIPE_END_WRITE);
2592 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2595 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2596 "Adding server_read_task for the wlan-helper\n");
2601 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
2602 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
2603 &wlan_plugin_helper_read, plugin);
2609 * Exit point from the plugin.
2610 * @param cls pointer to the api struct
2615 libgnunet_plugin_transport_wlan_done(void *cls)
2617 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2618 struct Plugin *plugin = api->cls;
2621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2622 "libgnunet_plugin_transport_wlan_done started\n");
2625 GNUNET_assert(cls !=NULL);
2627 if (plugin->consoltoken != NULL)
2628 GNUNET_SERVER_mst_destroy(plugin->consoltoken);
2630 GNUNET_free_non_null(plugin->interface);
2631 GNUNET_free (plugin);
2637 * Entry point for the plugin.
2639 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
2640 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
2643 libgnunet_plugin_transport_wlan_init(void *cls)
2645 //struct GNUNET_SERVICE_Context *service;
2646 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2647 struct GNUNET_TRANSPORT_PluginFunctions *api;
2648 struct Plugin *plugin;
2649 static unsigned long long testmode = 0;
2651 GNUNET_assert(cls !=NULL);
2653 plugin = GNUNET_malloc (sizeof (struct Plugin));
2655 plugin->pendingsessions = 0;
2656 plugin->session_count = 0;
2657 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2658 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2659 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2661 set_next_beacon_time(plugin);
2663 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE"))
2665 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg,
2666 "transport-wlan", "TESTMODE", &testmode))
2670 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE"))
2672 if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan",
2673 "INTERFACE", &(plugin->interface)) != GNUNET_YES)
2675 libgnunet_plugin_transport_wlan_done(plugin);
2680 wlan_transport_start_wlan_helper(plugin, testmode);
2681 plugin->consoltoken = GNUNET_SERVER_mst_create(&wlan_process_helper, plugin);
2683 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
2684 //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
2686 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2688 api->send = &wlan_plugin_send;
2689 api->disconnect = &wlan_plugin_disconnect;
2690 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
2691 api->check_address = &wlan_plugin_address_suggested;
2692 api->address_to_string = &wlan_plugin_address_to_string;
2694 start_next_message_id();
2697 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "wlan init finished\n");
2703 /* end of plugin_transport_wlan.c */